Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.58
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.58! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.57 2013/12/14 00:53:22 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1075.2.14 raeburn 75: use Authen::Captcha;
76: use Captcha::reCAPTCHA;
1.117 www 77:
1.517 raeburn 78: # ---------------------------------------------- Designs
79: use vars qw(%defaultdesign);
80:
1.22 www 81: my $readit;
82:
1.517 raeburn 83:
1.157 matthew 84: ##
85: ## Global Variables
86: ##
1.46 matthew 87:
1.643 foxr 88:
89: # ----------------------------------------------- SSI with retries:
90: #
91:
92: =pod
93:
1.648 raeburn 94: =head1 Server Side include with retries:
1.643 foxr 95:
96: =over 4
97:
1.648 raeburn 98: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 99:
100: Performs an ssi with some number of retries. Retries continue either
101: until the result is ok or until the retry count supplied by the
102: caller is exhausted.
103:
104: Inputs:
1.648 raeburn 105:
106: =over 4
107:
1.643 foxr 108: resource - Identifies the resource to insert.
1.648 raeburn 109:
1.643 foxr 110: retries - Count of the number of retries allowed.
1.648 raeburn 111:
1.643 foxr 112: form - Hash that identifies the rendering options.
113:
1.648 raeburn 114: =back
115:
116: Returns:
117:
118: =over 4
119:
1.643 foxr 120: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 121:
1.643 foxr 122: response - The response from the last attempt (which may or may not have been successful.
123:
1.648 raeburn 124: =back
125:
126: =back
127:
1.643 foxr 128: =cut
129:
130: sub ssi_with_retries {
131: my ($resource, $retries, %form) = @_;
132:
133:
134: my $ok = 0; # True if we got a good response.
135: my $content;
136: my $response;
137:
138: # Try to get the ssi done. within the retries count:
139:
140: do {
141: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
142: $ok = $response->is_success;
1.650 www 143: if (!$ok) {
144: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
145: }
1.643 foxr 146: $retries--;
147: } while (!$ok && ($retries > 0));
148:
149: if (!$ok) {
150: $content = ''; # On error return an empty content.
151: }
152: return ($content, $response);
153:
154: }
155:
156:
157:
1.20 www 158: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 159: my %language;
1.124 www 160: my %supported_language;
1.1048 foxr 161: my %latex_language; # For choosing hyphenation in <transl..>
162: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 163: my %cprtag;
1.192 taceyjo1 164: my %scprtag;
1.351 www 165: my %fe; my %fd; my %fm;
1.41 ng 166: my %category_extensions;
1.12 harris41 167:
1.46 matthew 168: # ---------------------------------------------- Thesaurus variables
1.144 matthew 169: #
170: # %Keywords:
171: # A hash used by &keyword to determine if a word is considered a keyword.
172: # $thesaurus_db_file
173: # Scalar containing the full path to the thesaurus database.
1.46 matthew 174:
175: my %Keywords;
176: my $thesaurus_db_file;
177:
1.144 matthew 178: #
179: # Initialize values from language.tab, copyright.tab, filetypes.tab,
180: # thesaurus.tab, and filecategories.tab.
181: #
1.18 www 182: BEGIN {
1.46 matthew 183: # Variable initialization
184: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
185: #
1.22 www 186: unless ($readit) {
1.12 harris41 187: # ------------------------------------------------------------------- languages
188: {
1.158 raeburn 189: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
190: '/language.tab';
191: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 192: while (my $line = <$fh>) {
193: next if ($line=~/^\#/);
194: chomp($line);
1.1048 foxr 195: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 196: $language{$key}=$val.' - '.$enc;
197: if ($sup) {
198: $supported_language{$key}=$sup;
199: }
1.1048 foxr 200: if ($latex) {
201: $latex_language_bykey{$key} = $latex;
202: $latex_language{$two} = $latex;
203: }
1.158 raeburn 204: }
205: close($fh);
206: }
1.12 harris41 207: }
208: # ------------------------------------------------------------------ copyrights
209: {
1.158 raeburn 210: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
211: '/copyright.tab';
212: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 213: while (my $line = <$fh>) {
214: next if ($line=~/^\#/);
215: chomp($line);
216: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 217: $cprtag{$key}=$val;
218: }
219: close($fh);
220: }
1.12 harris41 221: }
1.351 www 222: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 223: {
224: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
225: '/source_copyright.tab';
226: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 227: while (my $line = <$fh>) {
228: next if ($line =~ /^\#/);
229: chomp($line);
230: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 231: $scprtag{$key}=$val;
232: }
233: close($fh);
234: }
235: }
1.63 www 236:
1.517 raeburn 237: # -------------------------------------------------------------- default domain designs
1.63 www 238: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 239: my $designfile = $designdir.'/default.tab';
240: if ( open (my $fh,"<$designfile") ) {
241: while (my $line = <$fh>) {
242: next if ($line =~ /^\#/);
243: chomp($line);
244: my ($key,$val)=(split(/\=/,$line));
245: if ($val) { $defaultdesign{$key}=$val; }
246: }
247: close($fh);
1.63 www 248: }
249:
1.15 harris41 250: # ------------------------------------------------------------- file categories
251: {
1.158 raeburn 252: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
253: '/filecategories.tab';
254: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 255: while (my $line = <$fh>) {
256: next if ($line =~ /^\#/);
257: chomp($line);
258: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 259: push @{$category_extensions{lc($category)}},$extension;
260: }
261: close($fh);
262: }
263:
1.15 harris41 264: }
1.12 harris41 265: # ------------------------------------------------------------------ file types
266: {
1.158 raeburn 267: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
268: '/filetypes.tab';
269: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 270: while (my $line = <$fh>) {
271: next if ($line =~ /^\#/);
272: chomp($line);
273: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 274: if ($descr ne '') {
275: $fe{$ending}=lc($emb);
276: $fd{$ending}=$descr;
1.351 www 277: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 278: }
279: }
280: close($fh);
281: }
1.12 harris41 282: }
1.22 www 283: &Apache::lonnet::logthis(
1.705 tempelho 284: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 285: $readit=1;
1.46 matthew 286: } # end of unless($readit)
1.32 matthew 287:
288: }
1.112 bowersj2 289:
1.42 matthew 290: ###############################################################
291: ## HTML and Javascript Helper Functions ##
292: ###############################################################
293:
294: =pod
295:
1.112 bowersj2 296: =head1 HTML and Javascript Functions
1.42 matthew 297:
1.112 bowersj2 298: =over 4
299:
1.648 raeburn 300: =item * &browser_and_searcher_javascript()
1.112 bowersj2 301:
302: X<browsing, javascript>X<searching, javascript>Returns a string
303: containing javascript with two functions, C<openbrowser> and
304: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
305: tags.
1.42 matthew 306:
1.648 raeburn 307: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 308:
309: inputs: formname, elementname, only, omit
310:
311: formname and elementname indicate the name of the html form and name of
312: the element that the results of the browsing selection are to be placed in.
313:
314: Specifying 'only' will restrict the browser to displaying only files
1.185 www 315: with the given extension. Can be a comma separated list.
1.42 matthew 316:
317: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
1.648 raeburn 320: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 321:
322: Inputs: formname, elementname
323:
324: formname and elementname specify the name of the html form and the name
325: of the element the selection from the search results will be placed in.
1.542 raeburn 326:
1.42 matthew 327: =cut
328:
329: sub browser_and_searcher_javascript {
1.199 albertel 330: my ($mode)=@_;
331: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 332: my $resurl=&escape_single(&lastresurl());
1.42 matthew 333: return <<END;
1.219 albertel 334: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 335: var editbrowser = null;
1.135 albertel 336: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 337: var url = '$resurl/?';
1.42 matthew 338: if (editbrowser == null) {
339: url += 'launch=1&';
340: }
341: url += 'catalogmode=interactive&';
1.199 albertel 342: url += 'mode=$mode&';
1.611 albertel 343: url += 'inhibitmenu=yes&';
1.42 matthew 344: url += 'form=' + formname + '&';
345: if (only != null) {
346: url += 'only=' + only + '&';
1.217 albertel 347: } else {
348: url += 'only=&';
349: }
1.42 matthew 350: if (omit != null) {
351: url += 'omit=' + omit + '&';
1.217 albertel 352: } else {
353: url += 'omit=&';
354: }
1.135 albertel 355: if (titleelement != null) {
356: url += 'titleelement=' + titleelement + '&';
1.217 albertel 357: } else {
358: url += 'titleelement=&';
359: }
1.42 matthew 360: url += 'element=' + elementname + '';
361: var title = 'Browser';
1.435 albertel 362: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 363: options += ',width=700,height=600';
364: editbrowser = open(url,title,options,'1');
365: editbrowser.focus();
366: }
367: var editsearcher;
1.135 albertel 368: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 369: var url = '/adm/searchcat?';
370: if (editsearcher == null) {
371: url += 'launch=1&';
372: }
373: url += 'catalogmode=interactive&';
1.199 albertel 374: url += 'mode=$mode&';
1.42 matthew 375: url += 'form=' + formname + '&';
1.135 albertel 376: if (titleelement != null) {
377: url += 'titleelement=' + titleelement + '&';
1.217 albertel 378: } else {
379: url += 'titleelement=&';
380: }
1.42 matthew 381: url += 'element=' + elementname + '';
382: var title = 'Search';
1.435 albertel 383: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 384: options += ',width=700,height=600';
385: editsearcher = open(url,title,options,'1');
386: editsearcher.focus();
387: }
1.219 albertel 388: // END LON-CAPA Internal -->
1.42 matthew 389: END
1.170 www 390: }
391:
392: sub lastresurl {
1.258 albertel 393: if ($env{'environment.lastresurl'}) {
394: return $env{'environment.lastresurl'}
1.170 www 395: } else {
396: return '/res';
397: }
398: }
399:
400: sub storeresurl {
401: my $resurl=&Apache::lonnet::clutter(shift);
402: unless ($resurl=~/^\/res/) { return 0; }
403: $resurl=~s/\/$//;
404: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 405: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 406: return 1;
1.42 matthew 407: }
408:
1.74 www 409: sub studentbrowser_javascript {
1.111 www 410: unless (
1.258 albertel 411: (($env{'request.course.id'}) &&
1.302 albertel 412: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
413: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
414: '/'.$env{'request.course.sec'})
415: ))
1.258 albertel 416: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 417: ) { return ''; }
1.74 www 418: return (<<'ENDSTDBRW');
1.776 bisitz 419: <script type="text/javascript" language="Javascript">
1.824 bisitz 420: // <![CDATA[
1.74 www 421: var stdeditbrowser;
1.999 www 422: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 423: var url = '/adm/pickstudent?';
424: var filter;
1.558 albertel 425: if (!ignorefilter) {
426: eval('filter=document.'+formname+'.'+uname+'.value;');
427: }
1.74 www 428: if (filter != null) {
429: if (filter != '') {
430: url += 'filter='+filter+'&';
431: }
432: }
433: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 434: '&udomelement='+udom+
435: '&clicker='+clicker;
1.111 www 436: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 437: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 438: var title = 'Student_Browser';
1.74 www 439: var options = 'scrollbars=1,resizable=1,menubar=0';
440: options += ',width=700,height=600';
441: stdeditbrowser = open(url,title,options,'1');
442: stdeditbrowser.focus();
443: }
1.824 bisitz 444: // ]]>
1.74 www 445: </script>
446: ENDSTDBRW
447: }
1.42 matthew 448:
1.1003 www 449: sub resourcebrowser_javascript {
450: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 451: return (<<'ENDRESBRW');
1.1003 www 452: <script type="text/javascript" language="Javascript">
453: // <![CDATA[
454: var reseditbrowser;
1.1004 www 455: function openresbrowser(formname,reslink) {
1.1005 www 456: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 457: var title = 'Resource_Browser';
458: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 459: options += ',width=700,height=500';
1.1004 www 460: reseditbrowser = open(url,title,options,'1');
461: reseditbrowser.focus();
1.1003 www 462: }
463: // ]]>
464: </script>
1.1004 www 465: ENDRESBRW
1.1003 www 466: }
467:
1.74 www 468: sub selectstudent_link {
1.999 www 469: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
470: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
471: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
472: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 473: if ($env{'request.course.id'}) {
1.302 albertel 474: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
475: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
476: '/'.$env{'request.course.sec'})) {
1.111 www 477: return '';
478: }
1.999 www 479: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 480: if ($courseadvonly) {
481: $callargs .= ",'',1,1";
482: }
483: return '<span class="LC_nobreak">'.
484: '<a href="javascript:openstdbrowser('.$callargs.');">'.
485: &mt('Select User').'</a></span>';
1.74 www 486: }
1.258 albertel 487: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 488: $callargs .= ",'',1";
1.793 raeburn 489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.111 www 492: }
493: return '';
1.91 www 494: }
495:
1.1004 www 496: sub selectresource_link {
497: my ($form,$reslink,$arg)=@_;
498:
499: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
500: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
501: unless ($env{'request.course.id'}) { return $arg; }
502: return '<span class="LC_nobreak">'.
503: '<a href="javascript:openresbrowser('.$callargs.');">'.
504: $arg.'</a></span>';
505: }
506:
507:
508:
1.653 raeburn 509: sub authorbrowser_javascript {
510: return <<"ENDAUTHORBRW";
1.776 bisitz 511: <script type="text/javascript" language="JavaScript">
1.824 bisitz 512: // <![CDATA[
1.653 raeburn 513: var stdeditbrowser;
514:
515: function openauthorbrowser(formname,udom) {
516: var url = '/adm/pickauthor?';
517: url += 'form='+formname+'&roledom='+udom;
518: var title = 'Author_Browser';
519: var options = 'scrollbars=1,resizable=1,menubar=0';
520: options += ',width=700,height=600';
521: stdeditbrowser = open(url,title,options,'1');
522: stdeditbrowser.focus();
523: }
524:
1.824 bisitz 525: // ]]>
1.653 raeburn 526: </script>
527: ENDAUTHORBRW
528: }
529:
1.91 www 530: sub coursebrowser_javascript {
1.1075.2.31 raeburn 531: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
532: $credits_element) = @_;
1.932 raeburn 533: my $wintitle = 'Course_Browser';
1.931 raeburn 534: if ($crstype eq 'Community') {
1.932 raeburn 535: $wintitle = 'Community_Browser';
1.909 raeburn 536: }
1.876 raeburn 537: my $id_functions = &javascript_index_functions();
538: my $output = '
1.776 bisitz 539: <script type="text/javascript" language="JavaScript">
1.824 bisitz 540: // <![CDATA[
1.468 raeburn 541: var stdeditbrowser;'."\n";
1.876 raeburn 542:
543: $output .= <<"ENDSTDBRW";
1.909 raeburn 544: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 545: var url = '/adm/pickcourse?';
1.895 raeburn 546: var formid = getFormIdByName(formname);
1.876 raeburn 547: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 548: if (domainfilter != null) {
549: if (domainfilter != '') {
550: url += 'domainfilter='+domainfilter+'&';
551: }
552: }
1.91 www 553: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 554: '&cdomelement='+udom+
555: '&cnameelement='+desc;
1.468 raeburn 556: if (extra_element !=null && extra_element != '') {
1.594 raeburn 557: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 558: url += '&roleelement='+extra_element;
559: if (domainfilter == null || domainfilter == '') {
560: url += '&domainfilter='+extra_element;
561: }
1.234 raeburn 562: }
1.468 raeburn 563: else {
564: if (formname == 'portform') {
565: url += '&setroles='+extra_element;
1.800 raeburn 566: } else {
567: if (formname == 'rules') {
568: url += '&fixeddom='+extra_element;
569: }
1.468 raeburn 570: }
571: }
1.230 raeburn 572: }
1.909 raeburn 573: if (type != null && type != '') {
574: url += '&type='+type;
575: }
576: if (type_elem != null && type_elem != '') {
577: url += '&typeelement='+type_elem;
578: }
1.872 raeburn 579: if (formname == 'ccrs') {
580: var ownername = document.forms[formid].ccuname.value;
581: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
582: url += '&cloner='+ownername+':'+ownerdom;
583: }
1.293 raeburn 584: if (multflag !=null && multflag != '') {
585: url += '&multiple='+multflag;
586: }
1.909 raeburn 587: var title = '$wintitle';
1.91 www 588: var options = 'scrollbars=1,resizable=1,menubar=0';
589: options += ',width=700,height=600';
590: stdeditbrowser = open(url,title,options,'1');
591: stdeditbrowser.focus();
592: }
1.876 raeburn 593: $id_functions
594: ENDSTDBRW
1.1075.2.31 raeburn 595: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
596: $output .= &setsec_javascript($sec_element,$formname,$role_element,
597: $credits_element);
1.876 raeburn 598: }
599: $output .= '
600: // ]]>
601: </script>';
602: return $output;
603: }
604:
605: sub javascript_index_functions {
606: return <<"ENDJS";
607:
608: function getFormIdByName(formname) {
609: for (var i=0;i<document.forms.length;i++) {
610: if (document.forms[i].name == formname) {
611: return i;
612: }
613: }
614: return -1;
615: }
616:
617: function getIndexByName(formid,item) {
618: for (var i=0;i<document.forms[formid].elements.length;i++) {
619: if (document.forms[formid].elements[i].name == item) {
620: return i;
621: }
622: }
623: return -1;
624: }
1.468 raeburn 625:
1.876 raeburn 626: function getDomainFromSelectbox(formname,udom) {
627: var userdom;
628: var formid = getFormIdByName(formname);
629: if (formid > -1) {
630: var domid = getIndexByName(formid,udom);
631: if (domid > -1) {
632: if (document.forms[formid].elements[domid].type == 'select-one') {
633: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
634: }
635: if (document.forms[formid].elements[domid].type == 'hidden') {
636: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 637: }
638: }
639: }
1.876 raeburn 640: return userdom;
641: }
642:
643: ENDJS
1.468 raeburn 644:
1.876 raeburn 645: }
646:
1.1017 raeburn 647: sub javascript_array_indexof {
1.1018 raeburn 648: return <<ENDJS;
1.1017 raeburn 649: <script type="text/javascript" language="JavaScript">
650: // <![CDATA[
651:
652: if (!Array.prototype.indexOf) {
653: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
654: "use strict";
655: if (this === void 0 || this === null) {
656: throw new TypeError();
657: }
658: var t = Object(this);
659: var len = t.length >>> 0;
660: if (len === 0) {
661: return -1;
662: }
663: var n = 0;
664: if (arguments.length > 0) {
665: n = Number(arguments[1]);
666: if (n !== n) { // shortcut for verifying if it's NaN
667: n = 0;
668: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
669: n = (n > 0 || -1) * Math.floor(Math.abs(n));
670: }
671: }
672: if (n >= len) {
673: return -1;
674: }
675: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
676: for (; k < len; k++) {
677: if (k in t && t[k] === searchElement) {
678: return k;
679: }
680: }
681: return -1;
682: }
683: }
684:
685: // ]]>
686: </script>
687:
688: ENDJS
689:
690: }
691:
1.876 raeburn 692: sub userbrowser_javascript {
693: my $id_functions = &javascript_index_functions();
694: return <<"ENDUSERBRW";
695:
1.888 raeburn 696: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 697: var url = '/adm/pickuser?';
698: var userdom = getDomainFromSelectbox(formname,udom);
699: if (userdom != null) {
700: if (userdom != '') {
701: url += 'srchdom='+userdom+'&';
702: }
703: }
704: url += 'form=' + formname + '&unameelement='+uname+
705: '&udomelement='+udom+
706: '&ulastelement='+ulast+
707: '&ufirstelement='+ufirst+
708: '&uemailelement='+uemail+
1.881 raeburn 709: '&hideudomelement='+hideudom+
710: '&coursedom='+crsdom;
1.888 raeburn 711: if ((caller != null) && (caller != undefined)) {
712: url += '&caller='+caller;
713: }
1.876 raeburn 714: var title = 'User_Browser';
715: var options = 'scrollbars=1,resizable=1,menubar=0';
716: options += ',width=700,height=600';
717: var stdeditbrowser = open(url,title,options,'1');
718: stdeditbrowser.focus();
719: }
720:
1.888 raeburn 721: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 722: var formid = getFormIdByName(formname);
723: if (formid > -1) {
1.888 raeburn 724: var unameid = getIndexByName(formid,uname);
1.876 raeburn 725: var domid = getIndexByName(formid,udom);
726: var hidedomid = getIndexByName(formid,origdom);
727: if (hidedomid > -1) {
728: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 729: var unameval = document.forms[formid].elements[unameid].value;
730: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
731: if (domid > -1) {
732: var slct = document.forms[formid].elements[domid];
733: if (slct.type == 'select-one') {
734: var i;
735: for (i=0;i<slct.length;i++) {
736: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
737: }
738: }
739: if (slct.type == 'hidden') {
740: slct.value = fixeddom;
1.876 raeburn 741: }
742: }
1.468 raeburn 743: }
744: }
745: }
1.876 raeburn 746: return;
747: }
748:
749: $id_functions
750: ENDUSERBRW
1.468 raeburn 751: }
752:
753: sub setsec_javascript {
1.1075.2.31 raeburn 754: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 755: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
756: $communityrolestr);
757: if ($role_element ne '') {
758: my @allroles = ('st','ta','ep','in','ad');
759: foreach my $crstype ('Course','Community') {
760: if ($crstype eq 'Community') {
761: foreach my $role (@allroles) {
762: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
763: }
764: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
765: } else {
766: foreach my $role (@allroles) {
767: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
768: }
769: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
770: }
771: }
772: $rolestr = '"'.join('","',@allroles).'"';
773: $courserolestr = '"'.join('","',@courserolenames).'"';
774: $communityrolestr = '"'.join('","',@communityrolenames).'"';
775: }
1.468 raeburn 776: my $setsections = qq|
777: function setSect(sectionlist) {
1.629 raeburn 778: var sectionsArray = new Array();
779: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
780: sectionsArray = sectionlist.split(",");
781: }
1.468 raeburn 782: var numSections = sectionsArray.length;
783: document.$formname.$sec_element.length = 0;
784: if (numSections == 0) {
785: document.$formname.$sec_element.multiple=false;
786: document.$formname.$sec_element.size=1;
787: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
788: } else {
789: if (numSections == 1) {
790: document.$formname.$sec_element.multiple=false;
791: document.$formname.$sec_element.size=1;
792: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
793: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
794: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
795: } else {
796: for (var i=0; i<numSections; i++) {
797: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
798: }
799: document.$formname.$sec_element.multiple=true
800: if (numSections < 3) {
801: document.$formname.$sec_element.size=numSections;
802: } else {
803: document.$formname.$sec_element.size=3;
804: }
805: document.$formname.$sec_element.options[0].selected = false
806: }
807: }
1.91 www 808: }
1.905 raeburn 809:
810: function setRole(crstype) {
1.468 raeburn 811: |;
1.905 raeburn 812: if ($role_element eq '') {
813: $setsections .= ' return;
814: }
815: ';
816: } else {
817: $setsections .= qq|
818: var elementLength = document.$formname.$role_element.length;
819: var allroles = Array($rolestr);
820: var courserolenames = Array($courserolestr);
821: var communityrolenames = Array($communityrolestr);
822: if (elementLength != undefined) {
823: if (document.$formname.$role_element.options[5].value == 'cc') {
824: if (crstype == 'Course') {
825: return;
826: } else {
827: allroles[5] = 'co';
828: for (var i=0; i<6; i++) {
829: document.$formname.$role_element.options[i].value = allroles[i];
830: document.$formname.$role_element.options[i].text = communityrolenames[i];
831: }
832: }
833: } else {
834: if (crstype == 'Community') {
835: return;
836: } else {
837: allroles[5] = 'cc';
838: for (var i=0; i<6; i++) {
839: document.$formname.$role_element.options[i].value = allroles[i];
840: document.$formname.$role_element.options[i].text = courserolenames[i];
841: }
842: }
843: }
844: }
845: return;
846: }
847: |;
848: }
1.1075.2.31 raeburn 849: if ($credits_element) {
850: $setsections .= qq|
851: function setCredits(defaultcredits) {
852: document.$formname.$credits_element.value = defaultcredits;
853: return;
854: }
855: |;
856: }
1.468 raeburn 857: return $setsections;
858: }
859:
1.91 www 860: sub selectcourse_link {
1.909 raeburn 861: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
862: $typeelement) = @_;
863: my $type = $selecttype;
1.871 raeburn 864: my $linktext = &mt('Select Course');
865: if ($selecttype eq 'Community') {
1.909 raeburn 866: $linktext = &mt('Select Community');
1.906 raeburn 867: } elsif ($selecttype eq 'Course/Community') {
868: $linktext = &mt('Select Course/Community');
1.909 raeburn 869: $type = '';
1.1019 raeburn 870: } elsif ($selecttype eq 'Select') {
871: $linktext = &mt('Select');
872: $type = '';
1.871 raeburn 873: }
1.787 bisitz 874: return '<span class="LC_nobreak">'
875: ."<a href='"
876: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
877: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 878: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 879: ."'>".$linktext.'</a>'
1.787 bisitz 880: .'</span>';
1.74 www 881: }
1.42 matthew 882:
1.653 raeburn 883: sub selectauthor_link {
884: my ($form,$udom)=@_;
885: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
886: &mt('Select Author').'</a>';
887: }
888:
1.876 raeburn 889: sub selectuser_link {
1.881 raeburn 890: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 891: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 892: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 893: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 894: ');">'.$linktext.'</a>';
1.876 raeburn 895: }
896:
1.273 raeburn 897: sub check_uncheck_jscript {
898: my $jscript = <<"ENDSCRT";
899: function checkAll(field) {
900: if (field.length > 0) {
901: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 902: if (!field[i].disabled) {
903: field[i].checked = true;
904: }
1.273 raeburn 905: }
906: } else {
1.1075.2.14 raeburn 907: if (!field.disabled) {
908: field.checked = true;
909: }
1.273 raeburn 910: }
911: }
912:
913: function uncheckAll(field) {
914: if (field.length > 0) {
915: for (i = 0; i < field.length; i++) {
916: field[i].checked = false ;
1.543 albertel 917: }
918: } else {
1.273 raeburn 919: field.checked = false ;
920: }
921: }
922: ENDSCRT
923: return $jscript;
924: }
925:
1.656 www 926: sub select_timezone {
1.659 raeburn 927: my ($name,$selected,$onchange,$includeempty)=@_;
928: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
929: if ($includeempty) {
930: $output .= '<option value=""';
931: if (($selected eq '') || ($selected eq 'local')) {
932: $output .= ' selected="selected" ';
933: }
934: $output .= '> </option>';
935: }
1.657 raeburn 936: my @timezones = DateTime::TimeZone->all_names;
937: foreach my $tzone (@timezones) {
938: $output.= '<option value="'.$tzone.'"';
939: if ($tzone eq $selected) {
940: $output.=' selected="selected"';
941: }
942: $output.=">$tzone</option>\n";
1.656 www 943: }
944: $output.="</select>";
945: return $output;
946: }
1.273 raeburn 947:
1.687 raeburn 948: sub select_datelocale {
949: my ($name,$selected,$onchange,$includeempty)=@_;
950: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
951: if ($includeempty) {
952: $output .= '<option value=""';
953: if ($selected eq '') {
954: $output .= ' selected="selected" ';
955: }
956: $output .= '> </option>';
957: }
958: my (@possibles,%locale_names);
959: my @locales = DateTime::Locale::Catalog::Locales;
960: foreach my $locale (@locales) {
961: if (ref($locale) eq 'HASH') {
962: my $id = $locale->{'id'};
963: if ($id ne '') {
964: my $en_terr = $locale->{'en_territory'};
965: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 966: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 967: if (grep(/^en$/,@languages) || !@languages) {
968: if ($en_terr ne '') {
969: $locale_names{$id} = '('.$en_terr.')';
970: } elsif ($native_terr ne '') {
971: $locale_names{$id} = $native_terr;
972: }
973: } else {
974: if ($native_terr ne '') {
975: $locale_names{$id} = $native_terr.' ';
976: } elsif ($en_terr ne '') {
977: $locale_names{$id} = '('.$en_terr.')';
978: }
979: }
980: push (@possibles,$id);
981: }
982: }
983: }
984: foreach my $item (sort(@possibles)) {
985: $output.= '<option value="'.$item.'"';
986: if ($item eq $selected) {
987: $output.=' selected="selected"';
988: }
989: $output.=">$item";
990: if ($locale_names{$item} ne '') {
991: $output.=" $locale_names{$item}</option>\n";
992: }
993: $output.="</option>\n";
994: }
995: $output.="</select>";
996: return $output;
997: }
998:
1.792 raeburn 999: sub select_language {
1000: my ($name,$selected,$includeempty) = @_;
1001: my %langchoices;
1002: if ($includeempty) {
1.1075.2.32 raeburn 1003: %langchoices = ('' => 'No language preference');
1.792 raeburn 1004: }
1005: foreach my $id (&languageids()) {
1006: my $code = &supportedlanguagecode($id);
1007: if ($code) {
1008: $langchoices{$code} = &plainlanguagedescription($id);
1009: }
1010: }
1.1075.2.32 raeburn 1011: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1012: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1013: }
1014:
1.42 matthew 1015: =pod
1.36 matthew 1016:
1.648 raeburn 1017: =item * &linked_select_forms(...)
1.36 matthew 1018:
1019: linked_select_forms returns a string containing a <script></script> block
1020: and html for two <select> menus. The select menus will be linked in that
1021: changing the value of the first menu will result in new values being placed
1022: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1023: order unless a defined order is provided.
1.36 matthew 1024:
1025: linked_select_forms takes the following ordered inputs:
1026:
1027: =over 4
1028:
1.112 bowersj2 1029: =item * $formname, the name of the <form> tag
1.36 matthew 1030:
1.112 bowersj2 1031: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1032:
1.112 bowersj2 1033: =item * $firstdefault, the default value for the first menu
1.36 matthew 1034:
1.112 bowersj2 1035: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1036:
1.112 bowersj2 1037: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1038:
1.112 bowersj2 1039: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1040:
1.609 raeburn 1041: =item * $menuorder, the order of values in the first menu
1042:
1.1075.2.31 raeburn 1043: =item * $onchangefirst, additional javascript call to execute for an onchange
1044: event for the first <select> tag
1045:
1046: =item * $onchangesecond, additional javascript call to execute for an onchange
1047: event for the second <select> tag
1048:
1.41 ng 1049: =back
1050:
1.36 matthew 1051: Below is an example of such a hash. Only the 'text', 'default', and
1052: 'select2' keys must appear as stated. keys(%menu) are the possible
1053: values for the first select menu. The text that coincides with the
1.41 ng 1054: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1055: and text for the second menu are given in the hash pointed to by
1056: $menu{$choice1}->{'select2'}.
1057:
1.112 bowersj2 1058: my %menu = ( A1 => { text =>"Choice A1" ,
1059: default => "B3",
1060: select2 => {
1061: B1 => "Choice B1",
1062: B2 => "Choice B2",
1063: B3 => "Choice B3",
1064: B4 => "Choice B4"
1.609 raeburn 1065: },
1066: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1067: },
1068: A2 => { text =>"Choice A2" ,
1069: default => "C2",
1070: select2 => {
1071: C1 => "Choice C1",
1072: C2 => "Choice C2",
1073: C3 => "Choice C3"
1.609 raeburn 1074: },
1075: order => ['C2','C1','C3'],
1.112 bowersj2 1076: },
1077: A3 => { text =>"Choice A3" ,
1078: default => "D6",
1079: select2 => {
1080: D1 => "Choice D1",
1081: D2 => "Choice D2",
1082: D3 => "Choice D3",
1083: D4 => "Choice D4",
1084: D5 => "Choice D5",
1085: D6 => "Choice D6",
1086: D7 => "Choice D7"
1.609 raeburn 1087: },
1088: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1089: }
1090: );
1.36 matthew 1091:
1092: =cut
1093:
1094: sub linked_select_forms {
1095: my ($formname,
1096: $middletext,
1097: $firstdefault,
1098: $firstselectname,
1099: $secondselectname,
1.609 raeburn 1100: $hashref,
1101: $menuorder,
1.1075.2.31 raeburn 1102: $onchangefirst,
1103: $onchangesecond
1.36 matthew 1104: ) = @_;
1105: my $second = "document.$formname.$secondselectname";
1106: my $first = "document.$formname.$firstselectname";
1107: # output the javascript to do the changing
1108: my $result = '';
1.776 bisitz 1109: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1110: $result.="// <![CDATA[\n";
1.36 matthew 1111: $result.="var select2data = new Object();\n";
1112: $" = '","';
1113: my $debug = '';
1114: foreach my $s1 (sort(keys(%$hashref))) {
1115: $result.="select2data.d_$s1 = new Object();\n";
1116: $result.="select2data.d_$s1.def = new String('".
1117: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1118: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1119: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1120: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1121: @s2values = @{$hashref->{$s1}->{'order'}};
1122: }
1.36 matthew 1123: $result.="\"@s2values\");\n";
1124: $result.="select2data.d_$s1.texts = new Array(";
1125: my @s2texts;
1126: foreach my $value (@s2values) {
1127: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1128: }
1129: $result.="\"@s2texts\");\n";
1130: }
1131: $"=' ';
1132: $result.= <<"END";
1133:
1134: function select1_changed() {
1135: // Determine new choice
1136: var newvalue = "d_" + $first.value;
1137: // update select2
1138: var values = select2data[newvalue].values;
1139: var texts = select2data[newvalue].texts;
1140: var select2def = select2data[newvalue].def;
1141: var i;
1142: // out with the old
1143: for (i = 0; i < $second.options.length; i++) {
1144: $second.options[i] = null;
1145: }
1146: // in with the nuclear
1147: for (i=0;i<values.length; i++) {
1148: $second.options[i] = new Option(values[i]);
1.143 matthew 1149: $second.options[i].value = values[i];
1.36 matthew 1150: $second.options[i].text = texts[i];
1151: if (values[i] == select2def) {
1152: $second.options[i].selected = true;
1153: }
1154: }
1155: }
1.824 bisitz 1156: // ]]>
1.36 matthew 1157: </script>
1158: END
1159: # output the initial values for the selection lists
1.1075.2.31 raeburn 1160: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1161: my @order = sort(keys(%{$hashref}));
1162: if (ref($menuorder) eq 'ARRAY') {
1163: @order = @{$menuorder};
1164: }
1165: foreach my $value (@order) {
1.36 matthew 1166: $result.=" <option value=\"$value\" ";
1.253 albertel 1167: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1168: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1169: }
1170: $result .= "</select>\n";
1171: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1172: $result .= $middletext;
1.1075.2.31 raeburn 1173: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1174: if ($onchangesecond) {
1175: $result .= ' onchange="'.$onchangesecond.'"';
1176: }
1177: $result .= ">\n";
1.36 matthew 1178: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1179:
1180: my @secondorder = sort(keys(%select2));
1181: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1182: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1183: }
1184: foreach my $value (@secondorder) {
1.36 matthew 1185: $result.=" <option value=\"$value\" ";
1.253 albertel 1186: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1187: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1188: }
1189: $result .= "</select>\n";
1190: # return $debug;
1191: return $result;
1192: } # end of sub linked_select_forms {
1193:
1.45 matthew 1194: =pod
1.44 bowersj2 1195:
1.973 raeburn 1196: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1197:
1.112 bowersj2 1198: Returns a string corresponding to an HTML link to the given help
1199: $topic, where $topic corresponds to the name of a .tex file in
1200: /home/httpd/html/adm/help/tex, with underscores replaced by
1201: spaces.
1202:
1203: $text will optionally be linked to the same topic, allowing you to
1204: link text in addition to the graphic. If you do not want to link
1205: text, but wish to specify one of the later parameters, pass an
1206: empty string.
1207:
1208: $stayOnPage is a value that will be interpreted as a boolean. If true,
1209: the link will not open a new window. If false, the link will open
1210: a new window using Javascript. (Default is false.)
1211:
1212: $width and $height are optional numerical parameters that will
1213: override the width and height of the popped up window, which may
1.973 raeburn 1214: be useful for certain help topics with big pictures included.
1215:
1216: $imgid is the id of the img tag used for the help icon. This may be
1217: used in a javascript call to switch the image src. See
1218: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1219:
1220: =cut
1221:
1222: sub help_open_topic {
1.973 raeburn 1223: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1224: $text = "" if (not defined $text);
1.44 bowersj2 1225: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1226: $width = 500 if (not defined $width);
1.44 bowersj2 1227: $height = 400 if (not defined $height);
1228: my $filename = $topic;
1229: $filename =~ s/ /_/g;
1230:
1.48 bowersj2 1231: my $template = "";
1232: my $link;
1.572 banghart 1233:
1.159 www 1234: $topic=~s/\W/\_/g;
1.44 bowersj2 1235:
1.572 banghart 1236: if (!$stayOnPage) {
1.1075.2.50 raeburn 1237: if ($env{'browser.mobile'}) {
1238: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1239: } else {
1240: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1241: }
1.1037 www 1242: } elsif ($stayOnPage eq 'popup') {
1243: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1244: } else {
1.48 bowersj2 1245: $link = "/adm/help/${filename}.hlp";
1246: }
1247:
1248: # Add the text
1.755 neumanie 1249: if ($text ne "") {
1.763 bisitz 1250: $template.='<span class="LC_help_open_topic">'
1251: .'<a target="_top" href="'.$link.'">'
1252: .$text.'</a>';
1.48 bowersj2 1253: }
1254:
1.763 bisitz 1255: # (Always) Add the graphic
1.179 matthew 1256: my $title = &mt('Online Help');
1.667 raeburn 1257: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1258: if ($imgid ne '') {
1259: $imgid = ' id="'.$imgid.'"';
1260: }
1.763 bisitz 1261: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1262: .'<img src="'.$helpicon.'" border="0"'
1263: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1264: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1265: .' /></a>';
1266: if ($text ne "") {
1267: $template.='</span>';
1268: }
1.44 bowersj2 1269: return $template;
1270:
1.106 bowersj2 1271: }
1272:
1273: # This is a quicky function for Latex cheatsheet editing, since it
1274: # appears in at least four places
1275: sub helpLatexCheatsheet {
1.1037 www 1276: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1277: my $out;
1.106 bowersj2 1278: my $addOther = '';
1.732 raeburn 1279: if ($topic) {
1.1037 www 1280: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1281: }
1282: $out = '<span>' # Start cheatsheet
1283: .$addOther
1284: .'<span>'
1.1037 www 1285: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1286: .'</span> <span>'
1.1037 www 1287: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1288: .'</span>';
1.732 raeburn 1289: unless ($not_author) {
1.763 bisitz 1290: $out .= ' <span>'
1.1037 www 1291: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1292: .'</span>';
1.732 raeburn 1293: }
1.763 bisitz 1294: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1295: return $out;
1.172 www 1296: }
1297:
1.430 albertel 1298: sub general_help {
1299: my $helptopic='Student_Intro';
1300: if ($env{'request.role'}=~/^(ca|au)/) {
1301: $helptopic='Authoring_Intro';
1.907 raeburn 1302: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1303: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1304: } elsif ($env{'request.role'}=~/^dc/) {
1305: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1306: }
1307: return $helptopic;
1308: }
1309:
1310: sub update_help_link {
1311: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1312: my $origurl = $ENV{'REQUEST_URI'};
1313: $origurl=~s|^/~|/priv/|;
1314: my $timestamp = time;
1315: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1316: $$datum = &escape($$datum);
1317: }
1318:
1319: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1320: my $output .= <<"ENDOUTPUT";
1321: <script type="text/javascript">
1.824 bisitz 1322: // <![CDATA[
1.430 albertel 1323: banner_link = '$banner_link';
1.824 bisitz 1324: // ]]>
1.430 albertel 1325: </script>
1326: ENDOUTPUT
1327: return $output;
1328: }
1329:
1330: # now just updates the help link and generates a blue icon
1.193 raeburn 1331: sub help_open_menu {
1.430 albertel 1332: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1333: = @_;
1.949 droeschl 1334: $stayOnPage = 1;
1.430 albertel 1335: my $output;
1336: if ($component_help) {
1337: if (!$text) {
1338: $output=&help_open_topic($component_help,undef,$stayOnPage,
1339: $width,$height);
1340: } else {
1341: my $help_text;
1342: $help_text=&unescape($topic);
1343: $output='<table><tr><td>'.
1344: &help_open_topic($component_help,$help_text,$stayOnPage,
1345: $width,$height).'</td></tr></table>';
1346: }
1347: }
1348: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1349: return $output.$banner_link;
1350: }
1351:
1352: sub top_nav_help {
1353: my ($text) = @_;
1.436 albertel 1354: $text = &mt($text);
1.949 droeschl 1355: my $stay_on_page = 1;
1356:
1.572 banghart 1357: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1358: : "javascript:helpMenu('open')";
1.572 banghart 1359: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1360:
1.201 raeburn 1361: my $title = &mt('Get help');
1.436 albertel 1362:
1363: return <<"END";
1364: $banner_link
1.1075.2.56 raeburn 1365: <a href="$link" title="$title">$text</a>
1.436 albertel 1366: END
1367: }
1368:
1369: sub help_menu_js {
1.1075.2.52 raeburn 1370: my ($httphost) = @_;
1.949 droeschl 1371: my $stayOnPage = 1;
1.436 albertel 1372: my $width = 620;
1373: my $height = 600;
1.430 albertel 1374: my $helptopic=&general_help();
1.1075.2.52 raeburn 1375: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1376: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1377: my $start_page =
1378: &Apache::loncommon::start_page('Help Menu', undef,
1379: {'frameset' => 1,
1380: 'js_ready' => 1,
1.1075.2.52 raeburn 1381: 'use_absolute' => $httphost,
1.331 albertel 1382: 'add_entries' => {
1383: 'border' => '0',
1.579 raeburn 1384: 'rows' => "110,*",},});
1.331 albertel 1385: my $end_page =
1386: &Apache::loncommon::end_page({'frameset' => 1,
1387: 'js_ready' => 1,});
1388:
1.436 albertel 1389: my $template .= <<"ENDTEMPLATE";
1390: <script type="text/javascript">
1.877 bisitz 1391: // <![CDATA[
1.253 albertel 1392: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1393: var banner_link = '';
1.243 raeburn 1394: function helpMenu(target) {
1395: var caller = this;
1396: if (target == 'open') {
1397: var newWindow = null;
1398: try {
1.262 albertel 1399: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1400: }
1401: catch(error) {
1402: writeHelp(caller);
1403: return;
1404: }
1405: if (newWindow) {
1406: caller = newWindow;
1407: }
1.193 raeburn 1408: }
1.243 raeburn 1409: writeHelp(caller);
1410: return;
1411: }
1412: function writeHelp(caller) {
1.1072 raeburn 1413: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1414: caller.document.close()
1415: caller.focus()
1.193 raeburn 1416: }
1.877 bisitz 1417: // END LON-CAPA Internal -->
1.253 albertel 1418: // ]]>
1.436 albertel 1419: </script>
1.193 raeburn 1420: ENDTEMPLATE
1421: return $template;
1422: }
1423:
1.172 www 1424: sub help_open_bug {
1425: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1426: unless ($env{'user.adv'}) { return ''; }
1.172 www 1427: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1428: $text = "" if (not defined $text);
1429: $stayOnPage=1;
1.184 albertel 1430: $width = 600 if (not defined $width);
1431: $height = 600 if (not defined $height);
1.172 www 1432:
1433: $topic=~s/\W+/\+/g;
1434: my $link='';
1435: my $template='';
1.379 albertel 1436: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1437: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1438: if (!$stayOnPage)
1439: {
1440: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1441: }
1442: else
1443: {
1444: $link = $url;
1445: }
1446: # Add the text
1447: if ($text ne "")
1448: {
1449: $template .=
1450: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1451: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1452: }
1453:
1454: # Add the graphic
1.179 matthew 1455: my $title = &mt('Report a Bug');
1.215 albertel 1456: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1457: $template .= <<"ENDTEMPLATE";
1.436 albertel 1458: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1459: ENDTEMPLATE
1460: if ($text ne '') { $template.='</td></tr></table>' };
1461: return $template;
1462:
1463: }
1464:
1465: sub help_open_faq {
1466: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1467: unless ($env{'user.adv'}) { return ''; }
1.172 www 1468: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1469: $text = "" if (not defined $text);
1470: $stayOnPage=1;
1471: $width = 350 if (not defined $width);
1472: $height = 400 if (not defined $height);
1473:
1474: $topic=~s/\W+/\+/g;
1475: my $link='';
1476: my $template='';
1477: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1478: if (!$stayOnPage)
1479: {
1480: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1481: }
1482: else
1483: {
1484: $link = $url;
1485: }
1486:
1487: # Add the text
1488: if ($text ne "")
1489: {
1490: $template .=
1.173 www 1491: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1492: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1493: }
1494:
1495: # Add the graphic
1.179 matthew 1496: my $title = &mt('View the FAQ');
1.215 albertel 1497: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1498: $template .= <<"ENDTEMPLATE";
1.436 albertel 1499: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1500: ENDTEMPLATE
1501: if ($text ne '') { $template.='</td></tr></table>' };
1502: return $template;
1503:
1.44 bowersj2 1504: }
1.37 matthew 1505:
1.180 matthew 1506: ###############################################################
1507: ###############################################################
1508:
1.45 matthew 1509: =pod
1510:
1.648 raeburn 1511: =item * &change_content_javascript():
1.256 matthew 1512:
1513: This and the next function allow you to create small sections of an
1514: otherwise static HTML page that you can update on the fly with
1515: Javascript, even in Netscape 4.
1516:
1517: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1518: must be written to the HTML page once. It will prove the Javascript
1519: function "change(name, content)". Calling the change function with the
1520: name of the section
1521: you want to update, matching the name passed to C<changable_area>, and
1522: the new content you want to put in there, will put the content into
1523: that area.
1524:
1525: B<Note>: Netscape 4 only reserves enough space for the changable area
1526: to contain room for the original contents. You need to "make space"
1527: for whatever changes you wish to make, and be B<sure> to check your
1528: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1529: it's adequate for updating a one-line status display, but little more.
1530: This script will set the space to 100% width, so you only need to
1531: worry about height in Netscape 4.
1532:
1533: Modern browsers are much less limiting, and if you can commit to the
1534: user not using Netscape 4, this feature may be used freely with
1535: pretty much any HTML.
1536:
1537: =cut
1538:
1539: sub change_content_javascript {
1540: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1541: if ($env{'browser.type'} eq 'netscape' &&
1542: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1543: return (<<NETSCAPE4);
1544: function change(name, content) {
1545: doc = document.layers[name+"___escape"].layers[0].document;
1546: doc.open();
1547: doc.write(content);
1548: doc.close();
1549: }
1550: NETSCAPE4
1551: } else {
1552: # Otherwise, we need to use semi-standards-compliant code
1553: # (technically, "innerHTML" isn't standard but the equivalent
1554: # is really scary, and every useful browser supports it
1555: return (<<DOMBASED);
1556: function change(name, content) {
1557: element = document.getElementById(name);
1558: element.innerHTML = content;
1559: }
1560: DOMBASED
1561: }
1562: }
1563:
1564: =pod
1565:
1.648 raeburn 1566: =item * &changable_area($name,$origContent):
1.256 matthew 1567:
1568: This provides a "changable area" that can be modified on the fly via
1569: the Javascript code provided in C<change_content_javascript>. $name is
1570: the name you will use to reference the area later; do not repeat the
1571: same name on a given HTML page more then once. $origContent is what
1572: the area will originally contain, which can be left blank.
1573:
1574: =cut
1575:
1576: sub changable_area {
1577: my ($name, $origContent) = @_;
1578:
1.258 albertel 1579: if ($env{'browser.type'} eq 'netscape' &&
1580: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1581: # If this is netscape 4, we need to use the Layer tag
1582: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1583: } else {
1584: return "<span id='$name'>$origContent</span>";
1585: }
1586: }
1587:
1588: =pod
1589:
1.648 raeburn 1590: =item * &viewport_geometry_js
1.590 raeburn 1591:
1592: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1593:
1594: =cut
1595:
1596:
1597: sub viewport_geometry_js {
1598: return <<"GEOMETRY";
1599: var Geometry = {};
1600: function init_geometry() {
1601: if (Geometry.init) { return };
1602: Geometry.init=1;
1603: if (window.innerHeight) {
1604: Geometry.getViewportHeight = function() { return window.innerHeight; };
1605: Geometry.getViewportWidth = function() { return window.innerWidth; };
1606: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1607: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1608: }
1609: else if (document.documentElement && document.documentElement.clientHeight) {
1610: Geometry.getViewportHeight =
1611: function() { return document.documentElement.clientHeight; };
1612: Geometry.getViewportWidth =
1613: function() { return document.documentElement.clientWidth; };
1614:
1615: Geometry.getHorizontalScroll =
1616: function() { return document.documentElement.scrollLeft; };
1617: Geometry.getVerticalScroll =
1618: function() { return document.documentElement.scrollTop; };
1619: }
1620: else if (document.body.clientHeight) {
1621: Geometry.getViewportHeight =
1622: function() { return document.body.clientHeight; };
1623: Geometry.getViewportWidth =
1624: function() { return document.body.clientWidth; };
1625: Geometry.getHorizontalScroll =
1626: function() { return document.body.scrollLeft; };
1627: Geometry.getVerticalScroll =
1628: function() { return document.body.scrollTop; };
1629: }
1630: }
1631:
1632: GEOMETRY
1633: }
1634:
1635: =pod
1636:
1.648 raeburn 1637: =item * &viewport_size_js()
1.590 raeburn 1638:
1639: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1640:
1641: =cut
1642:
1643: sub viewport_size_js {
1644: my $geometry = &viewport_geometry_js();
1645: return <<"DIMS";
1646:
1647: $geometry
1648:
1649: function getViewportDims(width,height) {
1650: init_geometry();
1651: width.value = Geometry.getViewportWidth();
1652: height.value = Geometry.getViewportHeight();
1653: return;
1654: }
1655:
1656: DIMS
1657: }
1658:
1659: =pod
1660:
1.648 raeburn 1661: =item * &resize_textarea_js()
1.565 albertel 1662:
1663: emits the needed javascript to resize a textarea to be as big as possible
1664:
1665: creates a function resize_textrea that takes two IDs first should be
1666: the id of the element to resize, second should be the id of a div that
1667: surrounds everything that comes after the textarea, this routine needs
1668: to be attached to the <body> for the onload and onresize events.
1669:
1.648 raeburn 1670: =back
1.565 albertel 1671:
1672: =cut
1673:
1674: sub resize_textarea_js {
1.590 raeburn 1675: my $geometry = &viewport_geometry_js();
1.565 albertel 1676: return <<"RESIZE";
1677: <script type="text/javascript">
1.824 bisitz 1678: // <![CDATA[
1.590 raeburn 1679: $geometry
1.565 albertel 1680:
1.588 albertel 1681: function getX(element) {
1682: var x = 0;
1683: while (element) {
1684: x += element.offsetLeft;
1685: element = element.offsetParent;
1686: }
1687: return x;
1688: }
1689: function getY(element) {
1690: var y = 0;
1691: while (element) {
1692: y += element.offsetTop;
1693: element = element.offsetParent;
1694: }
1695: return y;
1696: }
1697:
1698:
1.565 albertel 1699: function resize_textarea(textarea_id,bottom_id) {
1700: init_geometry();
1701: var textarea = document.getElementById(textarea_id);
1702: //alert(textarea);
1703:
1.588 albertel 1704: var textarea_top = getY(textarea);
1.565 albertel 1705: var textarea_height = textarea.offsetHeight;
1706: var bottom = document.getElementById(bottom_id);
1.588 albertel 1707: var bottom_top = getY(bottom);
1.565 albertel 1708: var bottom_height = bottom.offsetHeight;
1709: var window_height = Geometry.getViewportHeight();
1.588 albertel 1710: var fudge = 23;
1.565 albertel 1711: var new_height = window_height-fudge-textarea_top-bottom_height;
1712: if (new_height < 300) {
1713: new_height = 300;
1714: }
1715: textarea.style.height=new_height+'px';
1716: }
1.824 bisitz 1717: // ]]>
1.565 albertel 1718: </script>
1719: RESIZE
1720:
1721: }
1722:
1723: =pod
1724:
1.256 matthew 1725: =head1 Excel and CSV file utility routines
1726:
1727: =cut
1728:
1729: ###############################################################
1730: ###############################################################
1731:
1732: =pod
1733:
1.1075.2.56 raeburn 1734: =over 4
1735:
1.648 raeburn 1736: =item * &csv_translate($text)
1.37 matthew 1737:
1.185 www 1738: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1739: format.
1740:
1741: =cut
1742:
1.180 matthew 1743: ###############################################################
1744: ###############################################################
1.37 matthew 1745: sub csv_translate {
1746: my $text = shift;
1747: $text =~ s/\"/\"\"/g;
1.209 albertel 1748: $text =~ s/\n/ /g;
1.37 matthew 1749: return $text;
1750: }
1.180 matthew 1751:
1752: ###############################################################
1753: ###############################################################
1754:
1755: =pod
1756:
1.648 raeburn 1757: =item * &define_excel_formats()
1.180 matthew 1758:
1759: Define some commonly used Excel cell formats.
1760:
1761: Currently supported formats:
1762:
1763: =over 4
1764:
1765: =item header
1766:
1767: =item bold
1768:
1769: =item h1
1770:
1771: =item h2
1772:
1773: =item h3
1774:
1.256 matthew 1775: =item h4
1776:
1777: =item i
1778:
1.180 matthew 1779: =item date
1780:
1781: =back
1782:
1783: Inputs: $workbook
1784:
1785: Returns: $format, a hash reference.
1786:
1.1057 foxr 1787:
1.180 matthew 1788: =cut
1789:
1790: ###############################################################
1791: ###############################################################
1792: sub define_excel_formats {
1793: my ($workbook) = @_;
1794: my $format;
1795: $format->{'header'} = $workbook->add_format(bold => 1,
1796: bottom => 1,
1797: align => 'center');
1798: $format->{'bold'} = $workbook->add_format(bold=>1);
1799: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1800: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1801: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1802: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1803: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1804: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1805: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1806: return $format;
1807: }
1808:
1809: ###############################################################
1810: ###############################################################
1.113 bowersj2 1811:
1812: =pod
1813:
1.648 raeburn 1814: =item * &create_workbook()
1.255 matthew 1815:
1816: Create an Excel worksheet. If it fails, output message on the
1817: request object and return undefs.
1818:
1819: Inputs: Apache request object
1820:
1821: Returns (undef) on failure,
1822: Excel worksheet object, scalar with filename, and formats
1823: from &Apache::loncommon::define_excel_formats on success
1824:
1825: =cut
1826:
1827: ###############################################################
1828: ###############################################################
1829: sub create_workbook {
1830: my ($r) = @_;
1831: #
1832: # Create the excel spreadsheet
1833: my $filename = '/prtspool/'.
1.258 albertel 1834: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1835: time.'_'.rand(1000000000).'.xls';
1836: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1837: if (! defined($workbook)) {
1838: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1839: $r->print(
1840: '<p class="LC_error">'
1841: .&mt('Problems occurred in creating the new Excel file.')
1842: .' '.&mt('This error has been logged.')
1843: .' '.&mt('Please alert your LON-CAPA administrator.')
1844: .'</p>'
1845: );
1.255 matthew 1846: return (undef);
1847: }
1848: #
1.1014 foxr 1849: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1850: #
1851: my $format = &Apache::loncommon::define_excel_formats($workbook);
1852: return ($workbook,$filename,$format);
1853: }
1854:
1855: ###############################################################
1856: ###############################################################
1857:
1858: =pod
1859:
1.648 raeburn 1860: =item * &create_text_file()
1.113 bowersj2 1861:
1.542 raeburn 1862: Create a file to write to and eventually make available to the user.
1.256 matthew 1863: If file creation fails, outputs an error message on the request object and
1864: return undefs.
1.113 bowersj2 1865:
1.256 matthew 1866: Inputs: Apache request object, and file suffix
1.113 bowersj2 1867:
1.256 matthew 1868: Returns (undef) on failure,
1869: Filehandle and filename on success.
1.113 bowersj2 1870:
1871: =cut
1872:
1.256 matthew 1873: ###############################################################
1874: ###############################################################
1875: sub create_text_file {
1876: my ($r,$suffix) = @_;
1877: if (! defined($suffix)) { $suffix = 'txt'; };
1878: my $fh;
1879: my $filename = '/prtspool/'.
1.258 albertel 1880: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1881: time.'_'.rand(1000000000).'.'.$suffix;
1882: $fh = Apache::File->new('>/home/httpd'.$filename);
1883: if (! defined($fh)) {
1884: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1885: $r->print(
1886: '<p class="LC_error">'
1887: .&mt('Problems occurred in creating the output file.')
1888: .' '.&mt('This error has been logged.')
1889: .' '.&mt('Please alert your LON-CAPA administrator.')
1890: .'</p>'
1891: );
1.113 bowersj2 1892: }
1.256 matthew 1893: return ($fh,$filename)
1.113 bowersj2 1894: }
1895:
1896:
1.256 matthew 1897: =pod
1.113 bowersj2 1898:
1899: =back
1900:
1901: =cut
1.37 matthew 1902:
1903: ###############################################################
1.33 matthew 1904: ## Home server <option> list generating code ##
1905: ###############################################################
1.35 matthew 1906:
1.169 www 1907: # ------------------------------------------
1908:
1909: sub domain_select {
1910: my ($name,$value,$multiple)=@_;
1911: my %domains=map {
1.514 albertel 1912: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1913: } &Apache::lonnet::all_domains();
1.169 www 1914: if ($multiple) {
1915: $domains{''}=&mt('Any domain');
1.550 albertel 1916: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1917: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1918: } else {
1.550 albertel 1919: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1920: return &select_form($name,$value,\%domains);
1.169 www 1921: }
1922: }
1923:
1.282 albertel 1924: #-------------------------------------------
1925:
1926: =pod
1927:
1.519 raeburn 1928: =head1 Routines for form select boxes
1929:
1930: =over 4
1931:
1.648 raeburn 1932: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1933:
1934: Returns a string containing a <select> element int multiple mode
1935:
1936:
1937: Args:
1938: $name - name of the <select> element
1.506 raeburn 1939: $value - scalar or array ref of values that should already be selected
1.282 albertel 1940: $size - number of rows long the select element is
1.283 albertel 1941: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1942: (shown text should already have been &mt())
1.506 raeburn 1943: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1944:
1.282 albertel 1945: =cut
1946:
1947: #-------------------------------------------
1.169 www 1948: sub multiple_select_form {
1.284 albertel 1949: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1950: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1951: my $output='';
1.191 matthew 1952: if (! defined($size)) {
1953: $size = 4;
1.283 albertel 1954: if (scalar(keys(%$hash))<4) {
1955: $size = scalar(keys(%$hash));
1.191 matthew 1956: }
1957: }
1.734 bisitz 1958: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1959: my @order;
1.506 raeburn 1960: if (ref($order) eq 'ARRAY') {
1961: @order = @{$order};
1962: } else {
1963: @order = sort(keys(%$hash));
1.501 banghart 1964: }
1965: if (exists($$hash{'select_form_order'})) {
1966: @order = @{$$hash{'select_form_order'}};
1967: }
1968:
1.284 albertel 1969: foreach my $key (@order) {
1.356 albertel 1970: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1971: $output.='selected="selected" ' if ($selected{$key});
1972: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1973: }
1974: $output.="</select>\n";
1975: return $output;
1976: }
1977:
1.88 www 1978: #-------------------------------------------
1979:
1980: =pod
1981:
1.970 raeburn 1982: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1983:
1984: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1985: allow a user to select options from a ref to a hash containing:
1986: option_name => displayed text. An optional $onchange can include
1987: a javascript onchange item, e.g., onchange="this.form.submit();"
1988:
1.88 www 1989: See lonrights.pm for an example invocation and use.
1990:
1991: =cut
1992:
1993: #-------------------------------------------
1994: sub select_form {
1.970 raeburn 1995: my ($def,$name,$hashref,$onchange) = @_;
1996: return unless (ref($hashref) eq 'HASH');
1997: if ($onchange) {
1998: $onchange = ' onchange="'.$onchange.'"';
1999: }
2000: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2001: my @keys;
1.970 raeburn 2002: if (exists($hashref->{'select_form_order'})) {
2003: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2004: } else {
1.970 raeburn 2005: @keys=sort(keys(%{$hashref}));
1.128 albertel 2006: }
1.356 albertel 2007: foreach my $key (@keys) {
2008: $selectform.=
2009: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2010: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2011: ">".$hashref->{$key}."</option>\n";
1.88 www 2012: }
2013: $selectform.="</select>";
2014: return $selectform;
2015: }
2016:
1.475 www 2017: # For display filters
2018:
2019: sub display_filter {
1.1074 raeburn 2020: my ($context) = @_;
1.475 www 2021: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2022: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2023: my $phraseinput = 'hidden';
2024: my $includeinput = 'hidden';
2025: my ($checked,$includetypestext);
2026: if ($env{'form.displayfilter'} eq 'containing') {
2027: $phraseinput = 'text';
2028: if ($context eq 'parmslog') {
2029: $includeinput = 'checkbox';
2030: if ($env{'form.includetypes'}) {
2031: $checked = ' checked="checked"';
2032: }
2033: $includetypestext = &mt('Include parameter types');
2034: }
2035: } else {
2036: $includetypestext = ' ';
2037: }
2038: my ($additional,$secondid,$thirdid);
2039: if ($context eq 'parmslog') {
2040: $additional =
2041: '<label><input type="'.$includeinput.'" name="includetypes"'.
2042: $checked.' name="includetypes" value="1" id="includetypes" />'.
2043: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2044: '</label>';
2045: $secondid = 'includetypes';
2046: $thirdid = 'includetypestext';
2047: }
2048: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2049: '$secondid','$thirdid')";
2050: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2051: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2052: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2053: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2054: &mt('Filter: [_1]',
1.477 www 2055: &select_form($env{'form.displayfilter'},
2056: 'displayfilter',
1.970 raeburn 2057: {'currentfolder' => 'Current folder/page',
1.477 www 2058: 'containing' => 'Containing phrase',
1.1074 raeburn 2059: 'none' => 'None'},$onchange)).' '.
2060: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2061: &HTML::Entities::encode($env{'form.containingphrase'}).
2062: '" />'.$additional;
2063: }
2064:
2065: sub display_filter_js {
2066: my $includetext = &mt('Include parameter types');
2067: return <<"ENDJS";
2068:
2069: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2070: var firstType = 'hidden';
2071: if (setter.options[setter.selectedIndex].value == 'containing') {
2072: firstType = 'text';
2073: }
2074: firstObject = document.getElementById(firstid);
2075: if (typeof(firstObject) == 'object') {
2076: if (firstObject.type != firstType) {
2077: changeInputType(firstObject,firstType);
2078: }
2079: }
2080: if (context == 'parmslog') {
2081: var secondType = 'hidden';
2082: if (firstType == 'text') {
2083: secondType = 'checkbox';
2084: }
2085: secondObject = document.getElementById(secondid);
2086: if (typeof(secondObject) == 'object') {
2087: if (secondObject.type != secondType) {
2088: changeInputType(secondObject,secondType);
2089: }
2090: }
2091: var textItem = document.getElementById(thirdid);
2092: var currtext = textItem.innerHTML;
2093: var newtext;
2094: if (firstType == 'text') {
2095: newtext = '$includetext';
2096: } else {
2097: newtext = ' ';
2098: }
2099: if (currtext != newtext) {
2100: textItem.innerHTML = newtext;
2101: }
2102: }
2103: return;
2104: }
2105:
2106: function changeInputType(oldObject,newType) {
2107: var newObject = document.createElement('input');
2108: newObject.type = newType;
2109: if (oldObject.size) {
2110: newObject.size = oldObject.size;
2111: }
2112: if (oldObject.value) {
2113: newObject.value = oldObject.value;
2114: }
2115: if (oldObject.name) {
2116: newObject.name = oldObject.name;
2117: }
2118: if (oldObject.id) {
2119: newObject.id = oldObject.id;
2120: }
2121: oldObject.parentNode.replaceChild(newObject,oldObject);
2122: return;
2123: }
2124:
2125: ENDJS
1.475 www 2126: }
2127:
1.167 www 2128: sub gradeleveldescription {
2129: my $gradelevel=shift;
2130: my %gradelevels=(0 => 'Not specified',
2131: 1 => 'Grade 1',
2132: 2 => 'Grade 2',
2133: 3 => 'Grade 3',
2134: 4 => 'Grade 4',
2135: 5 => 'Grade 5',
2136: 6 => 'Grade 6',
2137: 7 => 'Grade 7',
2138: 8 => 'Grade 8',
2139: 9 => 'Grade 9',
2140: 10 => 'Grade 10',
2141: 11 => 'Grade 11',
2142: 12 => 'Grade 12',
2143: 13 => 'Grade 13',
2144: 14 => '100 Level',
2145: 15 => '200 Level',
2146: 16 => '300 Level',
2147: 17 => '400 Level',
2148: 18 => 'Graduate Level');
2149: return &mt($gradelevels{$gradelevel});
2150: }
2151:
1.163 www 2152: sub select_level_form {
2153: my ($deflevel,$name)=@_;
2154: unless ($deflevel) { $deflevel=0; }
1.167 www 2155: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2156: for (my $i=0; $i<=18; $i++) {
2157: $selectform.="<option value=\"$i\" ".
1.253 albertel 2158: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2159: ">".&gradeleveldescription($i)."</option>\n";
2160: }
2161: $selectform.="</select>";
2162: return $selectform;
1.163 www 2163: }
1.167 www 2164:
1.35 matthew 2165: #-------------------------------------------
2166:
1.45 matthew 2167: =pod
2168:
1.1075.2.42 raeburn 2169: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2170:
2171: Returns a string containing a <select name='$name' size='1'> form to
2172: allow a user to select the domain to preform an operation in.
2173: See loncreateuser.pm for an example invocation and use.
2174:
1.90 www 2175: If the $includeempty flag is set, it also includes an empty choice ("no domain
2176: selected");
2177:
1.743 raeburn 2178: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2179:
1.910 raeburn 2180: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2181:
1.1075.2.36 raeburn 2182: The optional $incdoms is a reference to an array of domains which will be the only available options.
2183:
2184: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2185:
1.35 matthew 2186: =cut
2187:
2188: #-------------------------------------------
1.34 matthew 2189: sub select_dom_form {
1.1075.2.36 raeburn 2190: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2191: if ($onchange) {
1.874 raeburn 2192: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2193: }
1.1075.2.36 raeburn 2194: my (@domains,%exclude);
1.910 raeburn 2195: if (ref($incdoms) eq 'ARRAY') {
2196: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2197: } else {
2198: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2199: }
1.90 www 2200: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2201: if (ref($excdoms) eq 'ARRAY') {
2202: map { $exclude{$_} = 1; } @{$excdoms};
2203: }
1.743 raeburn 2204: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2205: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2206: next if ($exclude{$dom});
1.356 albertel 2207: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2208: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2209: if ($showdomdesc) {
2210: if ($dom ne '') {
2211: my $domdesc = &Apache::lonnet::domain($dom,'description');
2212: if ($domdesc ne '') {
2213: $selectdomain .= ' ('.$domdesc.')';
2214: }
2215: }
2216: }
2217: $selectdomain .= "</option>\n";
1.34 matthew 2218: }
2219: $selectdomain.="</select>";
2220: return $selectdomain;
2221: }
2222:
1.35 matthew 2223: #-------------------------------------------
2224:
1.45 matthew 2225: =pod
2226:
1.648 raeburn 2227: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2228:
1.586 raeburn 2229: input: 4 arguments (two required, two optional) -
2230: $domain - domain of new user
2231: $name - name of form element
2232: $default - Value of 'default' causes a default item to be first
2233: option, and selected by default.
2234: $hide - Value of 'hide' causes hiding of the name of the server,
2235: if 1 server found, or default, if 0 found.
1.594 raeburn 2236: output: returns 2 items:
1.586 raeburn 2237: (a) form element which contains either:
2238: (i) <select name="$name">
2239: <option value="$hostid1">$hostid $servers{$hostid}</option>
2240: <option value="$hostid2">$hostid $servers{$hostid}</option>
2241: </select>
2242: form item if there are multiple library servers in $domain, or
2243: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2244: if there is only one library server in $domain.
2245:
2246: (b) number of library servers found.
2247:
2248: See loncreateuser.pm for example of use.
1.35 matthew 2249:
2250: =cut
2251:
2252: #-------------------------------------------
1.586 raeburn 2253: sub home_server_form_item {
2254: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2255: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2256: my $result;
2257: my $numlib = keys(%servers);
2258: if ($numlib > 1) {
2259: $result .= '<select name="'.$name.'" />'."\n";
2260: if ($default) {
1.804 bisitz 2261: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2262: '</option>'."\n";
2263: }
2264: foreach my $hostid (sort(keys(%servers))) {
2265: $result.= '<option value="'.$hostid.'">'.
2266: $hostid.' '.$servers{$hostid}."</option>\n";
2267: }
2268: $result .= '</select>'."\n";
2269: } elsif ($numlib == 1) {
2270: my $hostid;
2271: foreach my $item (keys(%servers)) {
2272: $hostid = $item;
2273: }
2274: $result .= '<input type="hidden" name="'.$name.'" value="'.
2275: $hostid.'" />';
2276: if (!$hide) {
2277: $result .= $hostid.' '.$servers{$hostid};
2278: }
2279: $result .= "\n";
2280: } elsif ($default) {
2281: $result .= '<input type="hidden" name="'.$name.
2282: '" value="default" />';
2283: if (!$hide) {
2284: $result .= &mt('default');
2285: }
2286: $result .= "\n";
1.33 matthew 2287: }
1.586 raeburn 2288: return ($result,$numlib);
1.33 matthew 2289: }
1.112 bowersj2 2290:
2291: =pod
2292:
1.534 albertel 2293: =back
2294:
1.112 bowersj2 2295: =cut
1.87 matthew 2296:
2297: ###############################################################
1.112 bowersj2 2298: ## Decoding User Agent ##
1.87 matthew 2299: ###############################################################
2300:
2301: =pod
2302:
1.112 bowersj2 2303: =head1 Decoding the User Agent
2304:
2305: =over 4
2306:
2307: =item * &decode_user_agent()
1.87 matthew 2308:
2309: Inputs: $r
2310:
2311: Outputs:
2312:
2313: =over 4
2314:
1.112 bowersj2 2315: =item * $httpbrowser
1.87 matthew 2316:
1.112 bowersj2 2317: =item * $clientbrowser
1.87 matthew 2318:
1.112 bowersj2 2319: =item * $clientversion
1.87 matthew 2320:
1.112 bowersj2 2321: =item * $clientmathml
1.87 matthew 2322:
1.112 bowersj2 2323: =item * $clientunicode
1.87 matthew 2324:
1.112 bowersj2 2325: =item * $clientos
1.87 matthew 2326:
1.1075.2.42 raeburn 2327: =item * $clientmobile
2328:
2329: =item * $clientinfo
2330:
1.87 matthew 2331: =back
2332:
1.157 matthew 2333: =back
2334:
1.87 matthew 2335: =cut
2336:
2337: ###############################################################
2338: ###############################################################
2339: sub decode_user_agent {
1.247 albertel 2340: my ($r)=@_;
1.87 matthew 2341: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2342: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2343: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2344: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2345: my $clientbrowser='unknown';
2346: my $clientversion='0';
2347: my $clientmathml='';
2348: my $clientunicode='0';
1.1075.2.42 raeburn 2349: my $clientmobile=0;
1.87 matthew 2350: for (my $i=0;$i<=$#browsertype;$i++) {
2351: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2352: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2353: $clientbrowser=$bname;
2354: $httpbrowser=~/$vreg/i;
2355: $clientversion=$1;
2356: $clientmathml=($clientversion>=$minv);
2357: $clientunicode=($clientversion>=$univ);
2358: }
2359: }
2360: my $clientos='unknown';
1.1075.2.42 raeburn 2361: my $clientinfo;
1.87 matthew 2362: if (($httpbrowser=~/linux/i) ||
2363: ($httpbrowser=~/unix/i) ||
2364: ($httpbrowser=~/ux/i) ||
2365: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2366: if (($httpbrowser=~/vax/i) ||
2367: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2368: if ($httpbrowser=~/next/i) { $clientos='next'; }
2369: if (($httpbrowser=~/mac/i) ||
2370: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2371: if ($httpbrowser=~/win/i) { $clientos='win'; }
2372: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2373: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2374: $clientmobile=lc($1);
2375: }
2376: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2377: $clientinfo = 'firefox-'.$1;
2378: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2379: $clientinfo = 'chromeframe-'.$1;
2380: }
1.87 matthew 2381: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 2382: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2383: }
2384:
1.32 matthew 2385: ###############################################################
2386: ## Authentication changing form generation subroutines ##
2387: ###############################################################
2388: ##
2389: ## All of the authform_xxxxxxx subroutines take their inputs in a
2390: ## hash, and have reasonable default values.
2391: ##
2392: ## formname = the name given in the <form> tag.
1.35 matthew 2393: #-------------------------------------------
2394:
1.45 matthew 2395: =pod
2396:
1.112 bowersj2 2397: =head1 Authentication Routines
2398:
2399: =over 4
2400:
1.648 raeburn 2401: =item * &authform_xxxxxx()
1.35 matthew 2402:
2403: The authform_xxxxxx subroutines provide javascript and html forms which
2404: handle some of the conveniences required for authentication forms.
2405: This is not an optimal method, but it works.
2406:
2407: =over 4
2408:
1.112 bowersj2 2409: =item * authform_header
1.35 matthew 2410:
1.112 bowersj2 2411: =item * authform_authorwarning
1.35 matthew 2412:
1.112 bowersj2 2413: =item * authform_nochange
1.35 matthew 2414:
1.112 bowersj2 2415: =item * authform_kerberos
1.35 matthew 2416:
1.112 bowersj2 2417: =item * authform_internal
1.35 matthew 2418:
1.112 bowersj2 2419: =item * authform_filesystem
1.35 matthew 2420:
2421: =back
2422:
1.648 raeburn 2423: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2424:
1.35 matthew 2425: =cut
2426:
2427: #-------------------------------------------
1.32 matthew 2428: sub authform_header{
2429: my %in = (
2430: formname => 'cu',
1.80 albertel 2431: kerb_def_dom => '',
1.32 matthew 2432: @_,
2433: );
2434: $in{'formname'} = 'document.' . $in{'formname'};
2435: my $result='';
1.80 albertel 2436:
2437: #---------------------------------------------- Code for upper case translation
2438: my $Javascript_toUpperCase;
2439: unless ($in{kerb_def_dom}) {
2440: $Javascript_toUpperCase =<<"END";
2441: switch (choice) {
2442: case 'krb': currentform.elements[choicearg].value =
2443: currentform.elements[choicearg].value.toUpperCase();
2444: break;
2445: default:
2446: }
2447: END
2448: } else {
2449: $Javascript_toUpperCase = "";
2450: }
2451:
1.165 raeburn 2452: my $radioval = "'nochange'";
1.591 raeburn 2453: if (defined($in{'curr_authtype'})) {
2454: if ($in{'curr_authtype'} ne '') {
2455: $radioval = "'".$in{'curr_authtype'}."arg'";
2456: }
1.174 matthew 2457: }
1.165 raeburn 2458: my $argfield = 'null';
1.591 raeburn 2459: if (defined($in{'mode'})) {
1.165 raeburn 2460: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2461: if (defined($in{'curr_autharg'})) {
2462: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2463: $argfield = "'$in{'curr_autharg'}'";
2464: }
2465: }
2466: }
2467: }
2468:
1.32 matthew 2469: $result.=<<"END";
2470: var current = new Object();
1.165 raeburn 2471: current.radiovalue = $radioval;
2472: current.argfield = $argfield;
1.32 matthew 2473:
2474: function changed_radio(choice,currentform) {
2475: var choicearg = choice + 'arg';
2476: // If a radio button in changed, we need to change the argfield
2477: if (current.radiovalue != choice) {
2478: current.radiovalue = choice;
2479: if (current.argfield != null) {
2480: currentform.elements[current.argfield].value = '';
2481: }
2482: if (choice == 'nochange') {
2483: current.argfield = null;
2484: } else {
2485: current.argfield = choicearg;
2486: switch(choice) {
2487: case 'krb':
2488: currentform.elements[current.argfield].value =
2489: "$in{'kerb_def_dom'}";
2490: break;
2491: default:
2492: break;
2493: }
2494: }
2495: }
2496: return;
2497: }
1.22 www 2498:
1.32 matthew 2499: function changed_text(choice,currentform) {
2500: var choicearg = choice + 'arg';
2501: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2502: $Javascript_toUpperCase
1.32 matthew 2503: // clear old field
2504: if ((current.argfield != choicearg) && (current.argfield != null)) {
2505: currentform.elements[current.argfield].value = '';
2506: }
2507: current.argfield = choicearg;
2508: }
2509: set_auth_radio_buttons(choice,currentform);
2510: return;
1.20 www 2511: }
1.32 matthew 2512:
2513: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2514: var numauthchoices = currentform.login.length;
2515: if (typeof numauthchoices == "undefined") {
2516: return;
2517: }
1.32 matthew 2518: var i=0;
1.986 raeburn 2519: while (i < numauthchoices) {
1.32 matthew 2520: if (currentform.login[i].value == newvalue) { break; }
2521: i++;
2522: }
1.986 raeburn 2523: if (i == numauthchoices) {
1.32 matthew 2524: return;
2525: }
2526: current.radiovalue = newvalue;
2527: currentform.login[i].checked = true;
2528: return;
2529: }
2530: END
2531: return $result;
2532: }
2533:
1.1075.2.20 raeburn 2534: sub authform_authorwarning {
1.32 matthew 2535: my $result='';
1.144 matthew 2536: $result='<i>'.
2537: &mt('As a general rule, only authors or co-authors should be '.
2538: 'filesystem authenticated '.
2539: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2540: return $result;
2541: }
2542:
1.1075.2.20 raeburn 2543: sub authform_nochange {
1.32 matthew 2544: my %in = (
2545: formname => 'document.cu',
2546: kerb_def_dom => 'MSU.EDU',
2547: @_,
2548: );
1.1075.2.20 raeburn 2549: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2550: my $result;
1.1075.2.20 raeburn 2551: if (!$authnum) {
2552: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2553: } else {
2554: $result = '<label>'.&mt('[_1] Do not change login data',
2555: '<input type="radio" name="login" value="nochange" '.
2556: 'checked="checked" onclick="'.
1.281 albertel 2557: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2558: '</label>';
1.586 raeburn 2559: }
1.32 matthew 2560: return $result;
2561: }
2562:
1.591 raeburn 2563: sub authform_kerberos {
1.32 matthew 2564: my %in = (
2565: formname => 'document.cu',
2566: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2567: kerb_def_auth => 'krb4',
1.32 matthew 2568: @_,
2569: );
1.586 raeburn 2570: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2571: $autharg,$jscall);
1.1075.2.20 raeburn 2572: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2573: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2574: $check5 = ' checked="checked"';
1.80 albertel 2575: } else {
1.772 bisitz 2576: $check4 = ' checked="checked"';
1.80 albertel 2577: }
1.165 raeburn 2578: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2579: if (defined($in{'curr_authtype'})) {
2580: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2581: $krbcheck = ' checked="checked"';
1.623 raeburn 2582: if (defined($in{'mode'})) {
2583: if ($in{'mode'} eq 'modifyuser') {
2584: $krbcheck = '';
2585: }
2586: }
1.591 raeburn 2587: if (defined($in{'curr_kerb_ver'})) {
2588: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2589: $check5 = ' checked="checked"';
1.591 raeburn 2590: $check4 = '';
2591: } else {
1.772 bisitz 2592: $check4 = ' checked="checked"';
1.591 raeburn 2593: $check5 = '';
2594: }
1.586 raeburn 2595: }
1.591 raeburn 2596: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2597: $krbarg = $in{'curr_autharg'};
2598: }
1.586 raeburn 2599: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2600: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2601: $result =
2602: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2603: $in{'curr_autharg'},$krbver);
2604: } else {
2605: $result =
2606: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2607: }
2608: return $result;
2609: }
2610: }
2611: } else {
2612: if ($authnum == 1) {
1.784 bisitz 2613: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2614: }
2615: }
1.586 raeburn 2616: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2617: return;
1.587 raeburn 2618: } elsif ($authtype eq '') {
1.591 raeburn 2619: if (defined($in{'mode'})) {
1.587 raeburn 2620: if ($in{'mode'} eq 'modifycourse') {
2621: if ($authnum == 1) {
1.1075.2.20 raeburn 2622: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2623: }
2624: }
2625: }
1.586 raeburn 2626: }
2627: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2628: if ($authtype eq '') {
2629: $authtype = '<input type="radio" name="login" value="krb" '.
2630: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2631: $krbcheck.' />';
2632: }
2633: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2634: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2635: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2636: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2637: $in{'curr_authtype'} eq 'krb4')) {
2638: $result .= &mt
1.144 matthew 2639: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2640: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2641: '<label>'.$authtype,
1.281 albertel 2642: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2643: 'value="'.$krbarg.'" '.
1.144 matthew 2644: 'onchange="'.$jscall.'" />',
1.281 albertel 2645: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2646: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2647: '</label>');
1.586 raeburn 2648: } elsif ($can_assign{'krb4'}) {
2649: $result .= &mt
2650: ('[_1] Kerberos authenticated with domain [_2] '.
2651: '[_3] Version 4 [_4]',
2652: '<label>'.$authtype,
2653: '</label><input type="text" size="10" name="krbarg" '.
2654: 'value="'.$krbarg.'" '.
2655: 'onchange="'.$jscall.'" />',
2656: '<label><input type="hidden" name="krbver" value="4" />',
2657: '</label>');
2658: } elsif ($can_assign{'krb5'}) {
2659: $result .= &mt
2660: ('[_1] Kerberos authenticated with domain [_2] '.
2661: '[_3] Version 5 [_4]',
2662: '<label>'.$authtype,
2663: '</label><input type="text" size="10" name="krbarg" '.
2664: 'value="'.$krbarg.'" '.
2665: 'onchange="'.$jscall.'" />',
2666: '<label><input type="hidden" name="krbver" value="5" />',
2667: '</label>');
2668: }
1.32 matthew 2669: return $result;
2670: }
2671:
1.1075.2.20 raeburn 2672: sub authform_internal {
1.586 raeburn 2673: my %in = (
1.32 matthew 2674: formname => 'document.cu',
2675: kerb_def_dom => 'MSU.EDU',
2676: @_,
2677: );
1.586 raeburn 2678: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2679: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2680: if (defined($in{'curr_authtype'})) {
2681: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2682: if ($can_assign{'int'}) {
1.772 bisitz 2683: $intcheck = 'checked="checked" ';
1.623 raeburn 2684: if (defined($in{'mode'})) {
2685: if ($in{'mode'} eq 'modifyuser') {
2686: $intcheck = '';
2687: }
2688: }
1.591 raeburn 2689: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2690: $intarg = $in{'curr_autharg'};
2691: }
2692: } else {
2693: $result = &mt('Currently internally authenticated.');
2694: return $result;
1.165 raeburn 2695: }
2696: }
1.586 raeburn 2697: } else {
2698: if ($authnum == 1) {
1.784 bisitz 2699: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2700: }
2701: }
2702: if (!$can_assign{'int'}) {
2703: return;
1.587 raeburn 2704: } elsif ($authtype eq '') {
1.591 raeburn 2705: if (defined($in{'mode'})) {
1.587 raeburn 2706: if ($in{'mode'} eq 'modifycourse') {
2707: if ($authnum == 1) {
1.1075.2.20 raeburn 2708: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2709: }
2710: }
2711: }
1.165 raeburn 2712: }
1.586 raeburn 2713: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2714: if ($authtype eq '') {
2715: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2716: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2717: }
1.605 bisitz 2718: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2719: $intarg.'" onchange="'.$jscall.'" />';
2720: $result = &mt
1.144 matthew 2721: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2722: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2723: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2724: return $result;
2725: }
2726:
1.1075.2.20 raeburn 2727: sub authform_local {
1.32 matthew 2728: my %in = (
2729: formname => 'document.cu',
2730: kerb_def_dom => 'MSU.EDU',
2731: @_,
2732: );
1.586 raeburn 2733: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2734: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2735: if (defined($in{'curr_authtype'})) {
2736: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2737: if ($can_assign{'loc'}) {
1.772 bisitz 2738: $loccheck = 'checked="checked" ';
1.623 raeburn 2739: if (defined($in{'mode'})) {
2740: if ($in{'mode'} eq 'modifyuser') {
2741: $loccheck = '';
2742: }
2743: }
1.591 raeburn 2744: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2745: $locarg = $in{'curr_autharg'};
2746: }
2747: } else {
2748: $result = &mt('Currently using local (institutional) authentication.');
2749: return $result;
1.165 raeburn 2750: }
2751: }
1.586 raeburn 2752: } else {
2753: if ($authnum == 1) {
1.784 bisitz 2754: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2755: }
2756: }
2757: if (!$can_assign{'loc'}) {
2758: return;
1.587 raeburn 2759: } elsif ($authtype eq '') {
1.591 raeburn 2760: if (defined($in{'mode'})) {
1.587 raeburn 2761: if ($in{'mode'} eq 'modifycourse') {
2762: if ($authnum == 1) {
1.1075.2.20 raeburn 2763: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2764: }
2765: }
2766: }
1.165 raeburn 2767: }
1.586 raeburn 2768: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2769: if ($authtype eq '') {
2770: $authtype = '<input type="radio" name="login" value="loc" '.
2771: $loccheck.' onchange="'.$jscall.'" onclick="'.
2772: $jscall.'" />';
2773: }
2774: $autharg = '<input type="text" size="10" name="locarg" value="'.
2775: $locarg.'" onchange="'.$jscall.'" />';
2776: $result = &mt('[_1] Local Authentication with argument [_2]',
2777: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2778: return $result;
2779: }
2780:
1.1075.2.20 raeburn 2781: sub authform_filesystem {
1.32 matthew 2782: my %in = (
2783: formname => 'document.cu',
2784: kerb_def_dom => 'MSU.EDU',
2785: @_,
2786: );
1.586 raeburn 2787: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2788: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2789: if (defined($in{'curr_authtype'})) {
2790: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2791: if ($can_assign{'fsys'}) {
1.772 bisitz 2792: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2793: if (defined($in{'mode'})) {
2794: if ($in{'mode'} eq 'modifyuser') {
2795: $fsyscheck = '';
2796: }
2797: }
1.586 raeburn 2798: } else {
2799: $result = &mt('Currently Filesystem Authenticated.');
2800: return $result;
2801: }
2802: }
2803: } else {
2804: if ($authnum == 1) {
1.784 bisitz 2805: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2806: }
2807: }
2808: if (!$can_assign{'fsys'}) {
2809: return;
1.587 raeburn 2810: } elsif ($authtype eq '') {
1.591 raeburn 2811: if (defined($in{'mode'})) {
1.587 raeburn 2812: if ($in{'mode'} eq 'modifycourse') {
2813: if ($authnum == 1) {
1.1075.2.20 raeburn 2814: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2815: }
2816: }
2817: }
1.586 raeburn 2818: }
2819: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2820: if ($authtype eq '') {
2821: $authtype = '<input type="radio" name="login" value="fsys" '.
2822: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2823: $jscall.'" />';
2824: }
2825: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2826: ' onchange="'.$jscall.'" />';
2827: $result = &mt
1.144 matthew 2828: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2829: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2830: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2831: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2832: 'onchange="'.$jscall.'" />');
1.32 matthew 2833: return $result;
2834: }
2835:
1.586 raeburn 2836: sub get_assignable_auth {
2837: my ($dom) = @_;
2838: if ($dom eq '') {
2839: $dom = $env{'request.role.domain'};
2840: }
2841: my %can_assign = (
2842: krb4 => 1,
2843: krb5 => 1,
2844: int => 1,
2845: loc => 1,
2846: );
2847: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2848: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2849: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2850: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2851: my $context;
2852: if ($env{'request.role'} =~ /^au/) {
2853: $context = 'author';
2854: } elsif ($env{'request.role'} =~ /^dc/) {
2855: $context = 'domain';
2856: } elsif ($env{'request.course.id'}) {
2857: $context = 'course';
2858: }
2859: if ($context) {
2860: if (ref($authhash->{$context}) eq 'HASH') {
2861: %can_assign = %{$authhash->{$context}};
2862: }
2863: }
2864: }
2865: }
2866: my $authnum = 0;
2867: foreach my $key (keys(%can_assign)) {
2868: if ($can_assign{$key}) {
2869: $authnum ++;
2870: }
2871: }
2872: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2873: $authnum --;
2874: }
2875: return ($authnum,%can_assign);
2876: }
2877:
1.80 albertel 2878: ###############################################################
2879: ## Get Kerberos Defaults for Domain ##
2880: ###############################################################
2881: ##
2882: ## Returns default kerberos version and an associated argument
2883: ## as listed in file domain.tab. If not listed, provides
2884: ## appropriate default domain and kerberos version.
2885: ##
2886: #-------------------------------------------
2887:
2888: =pod
2889:
1.648 raeburn 2890: =item * &get_kerberos_defaults()
1.80 albertel 2891:
2892: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2893: version and domain. If not found, it defaults to version 4 and the
2894: domain of the server.
1.80 albertel 2895:
1.648 raeburn 2896: =over 4
2897:
1.80 albertel 2898: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2899:
1.648 raeburn 2900: =back
2901:
2902: =back
2903:
1.80 albertel 2904: =cut
2905:
2906: #-------------------------------------------
2907: sub get_kerberos_defaults {
2908: my $domain=shift;
1.641 raeburn 2909: my ($krbdef,$krbdefdom);
2910: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2911: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2912: $krbdef = $domdefaults{'auth_def'};
2913: $krbdefdom = $domdefaults{'auth_arg_def'};
2914: } else {
1.80 albertel 2915: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2916: my $krbdefdom=$1;
2917: $krbdefdom=~tr/a-z/A-Z/;
2918: $krbdef = "krb4";
2919: }
2920: return ($krbdef,$krbdefdom);
2921: }
1.112 bowersj2 2922:
1.32 matthew 2923:
1.46 matthew 2924: ###############################################################
2925: ## Thesaurus Functions ##
2926: ###############################################################
1.20 www 2927:
1.46 matthew 2928: =pod
1.20 www 2929:
1.112 bowersj2 2930: =head1 Thesaurus Functions
2931:
2932: =over 4
2933:
1.648 raeburn 2934: =item * &initialize_keywords()
1.46 matthew 2935:
2936: Initializes the package variable %Keywords if it is empty. Uses the
2937: package variable $thesaurus_db_file.
2938:
2939: =cut
2940:
2941: ###################################################
2942:
2943: sub initialize_keywords {
2944: return 1 if (scalar keys(%Keywords));
2945: # If we are here, %Keywords is empty, so fill it up
2946: # Make sure the file we need exists...
2947: if (! -e $thesaurus_db_file) {
2948: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2949: " failed because it does not exist");
2950: return 0;
2951: }
2952: # Set up the hash as a database
2953: my %thesaurus_db;
2954: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2955: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2956: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2957: $thesaurus_db_file);
2958: return 0;
2959: }
2960: # Get the average number of appearances of a word.
2961: my $avecount = $thesaurus_db{'average.count'};
2962: # Put keywords (those that appear > average) into %Keywords
2963: while (my ($word,$data)=each (%thesaurus_db)) {
2964: my ($count,undef) = split /:/,$data;
2965: $Keywords{$word}++ if ($count > $avecount);
2966: }
2967: untie %thesaurus_db;
2968: # Remove special values from %Keywords.
1.356 albertel 2969: foreach my $value ('total.count','average.count') {
2970: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2971: }
1.46 matthew 2972: return 1;
2973: }
2974:
2975: ###################################################
2976:
2977: =pod
2978:
1.648 raeburn 2979: =item * &keyword($word)
1.46 matthew 2980:
2981: Returns true if $word is a keyword. A keyword is a word that appears more
2982: than the average number of times in the thesaurus database. Calls
2983: &initialize_keywords
2984:
2985: =cut
2986:
2987: ###################################################
1.20 www 2988:
2989: sub keyword {
1.46 matthew 2990: return if (!&initialize_keywords());
2991: my $word=lc(shift());
2992: $word=~s/\W//g;
2993: return exists($Keywords{$word});
1.20 www 2994: }
1.46 matthew 2995:
2996: ###############################################################
2997:
2998: =pod
1.20 www 2999:
1.648 raeburn 3000: =item * &get_related_words()
1.46 matthew 3001:
1.160 matthew 3002: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3003: an array of words. If the keyword is not in the thesaurus, an empty array
3004: will be returned. The order of the words returned is determined by the
3005: database which holds them.
3006:
3007: Uses global $thesaurus_db_file.
3008:
1.1057 foxr 3009:
1.46 matthew 3010: =cut
3011:
3012: ###############################################################
3013: sub get_related_words {
3014: my $keyword = shift;
3015: my %thesaurus_db;
3016: if (! -e $thesaurus_db_file) {
3017: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3018: "failed because the file does not exist");
3019: return ();
3020: }
3021: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3022: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3023: return ();
3024: }
3025: my @Words=();
1.429 www 3026: my $count=0;
1.46 matthew 3027: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3028: # The first element is the number of times
3029: # the word appears. We do not need it now.
1.429 www 3030: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3031: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3032: my $threshold=$mostfrequentcount/10;
3033: foreach my $possibleword (@RelatedWords) {
3034: my ($word,$wordcount)=split(/\,/,$possibleword);
3035: if ($wordcount>$threshold) {
3036: push(@Words,$word);
3037: $count++;
3038: if ($count>10) { last; }
3039: }
1.20 www 3040: }
3041: }
1.46 matthew 3042: untie %thesaurus_db;
3043: return @Words;
1.14 harris41 3044: }
1.46 matthew 3045:
1.112 bowersj2 3046: =pod
3047:
3048: =back
3049:
3050: =cut
1.61 www 3051:
3052: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3053: =pod
3054:
1.112 bowersj2 3055: =head1 User Name Functions
3056:
3057: =over 4
3058:
1.648 raeburn 3059: =item * &plainname($uname,$udom,$first)
1.81 albertel 3060:
1.112 bowersj2 3061: Takes a users logon name and returns it as a string in
1.226 albertel 3062: "first middle last generation" form
3063: if $first is set to 'lastname' then it returns it as
3064: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3065:
3066: =cut
1.61 www 3067:
1.295 www 3068:
1.81 albertel 3069: ###############################################################
1.61 www 3070: sub plainname {
1.226 albertel 3071: my ($uname,$udom,$first)=@_;
1.537 albertel 3072: return if (!defined($uname) || !defined($udom));
1.295 www 3073: my %names=&getnames($uname,$udom);
1.226 albertel 3074: my $name=&Apache::lonnet::format_name($names{'firstname'},
3075: $names{'middlename'},
3076: $names{'lastname'},
3077: $names{'generation'},$first);
3078: $name=~s/^\s+//;
1.62 www 3079: $name=~s/\s+$//;
3080: $name=~s/\s+/ /g;
1.353 albertel 3081: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3082: return $name;
1.61 www 3083: }
1.66 www 3084:
3085: # -------------------------------------------------------------------- Nickname
1.81 albertel 3086: =pod
3087:
1.648 raeburn 3088: =item * &nickname($uname,$udom)
1.81 albertel 3089:
3090: Gets a users name and returns it as a string as
3091:
3092: ""nickname""
1.66 www 3093:
1.81 albertel 3094: if the user has a nickname or
3095:
3096: "first middle last generation"
3097:
3098: if the user does not
3099:
3100: =cut
1.66 www 3101:
3102: sub nickname {
3103: my ($uname,$udom)=@_;
1.537 albertel 3104: return if (!defined($uname) || !defined($udom));
1.295 www 3105: my %names=&getnames($uname,$udom);
1.68 albertel 3106: my $name=$names{'nickname'};
1.66 www 3107: if ($name) {
3108: $name='"'.$name.'"';
3109: } else {
3110: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3111: $names{'lastname'}.' '.$names{'generation'};
3112: $name=~s/\s+$//;
3113: $name=~s/\s+/ /g;
3114: }
3115: return $name;
3116: }
3117:
1.295 www 3118: sub getnames {
3119: my ($uname,$udom)=@_;
1.537 albertel 3120: return if (!defined($uname) || !defined($udom));
1.433 albertel 3121: if ($udom eq 'public' && $uname eq 'public') {
3122: return ('lastname' => &mt('Public'));
3123: }
1.295 www 3124: my $id=$uname.':'.$udom;
3125: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3126: if ($cached) {
3127: return %{$names};
3128: } else {
3129: my %loadnames=&Apache::lonnet::get('environment',
3130: ['firstname','middlename','lastname','generation','nickname'],
3131: $udom,$uname);
3132: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3133: return %loadnames;
3134: }
3135: }
1.61 www 3136:
1.542 raeburn 3137: # -------------------------------------------------------------------- getemails
1.648 raeburn 3138:
1.542 raeburn 3139: =pod
3140:
1.648 raeburn 3141: =item * &getemails($uname,$udom)
1.542 raeburn 3142:
3143: Gets a user's email information and returns it as a hash with keys:
3144: notification, critnotification, permanentemail
3145:
3146: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3147: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3148:
1.648 raeburn 3149:
1.542 raeburn 3150: =cut
3151:
1.648 raeburn 3152:
1.466 albertel 3153: sub getemails {
3154: my ($uname,$udom)=@_;
3155: if ($udom eq 'public' && $uname eq 'public') {
3156: return;
3157: }
1.467 www 3158: if (!$udom) { $udom=$env{'user.domain'}; }
3159: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3160: my $id=$uname.':'.$udom;
3161: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3162: if ($cached) {
3163: return %{$names};
3164: } else {
3165: my %loadnames=&Apache::lonnet::get('environment',
3166: ['notification','critnotification',
3167: 'permanentemail'],
3168: $udom,$uname);
3169: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3170: return %loadnames;
3171: }
3172: }
3173:
1.551 albertel 3174: sub flush_email_cache {
3175: my ($uname,$udom)=@_;
3176: if (!$udom) { $udom =$env{'user.domain'}; }
3177: if (!$uname) { $uname=$env{'user.name'}; }
3178: return if ($udom eq 'public' && $uname eq 'public');
3179: my $id=$uname.':'.$udom;
3180: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3181: }
3182:
1.728 raeburn 3183: # -------------------------------------------------------------------- getlangs
3184:
3185: =pod
3186:
3187: =item * &getlangs($uname,$udom)
3188:
3189: Gets a user's language preference and returns it as a hash with key:
3190: language.
3191:
3192: =cut
3193:
3194:
3195: sub getlangs {
3196: my ($uname,$udom) = @_;
3197: if (!$udom) { $udom =$env{'user.domain'}; }
3198: if (!$uname) { $uname=$env{'user.name'}; }
3199: my $id=$uname.':'.$udom;
3200: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3201: if ($cached) {
3202: return %{$langs};
3203: } else {
3204: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3205: $udom,$uname);
3206: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3207: return %loadlangs;
3208: }
3209: }
3210:
3211: sub flush_langs_cache {
3212: my ($uname,$udom)=@_;
3213: if (!$udom) { $udom =$env{'user.domain'}; }
3214: if (!$uname) { $uname=$env{'user.name'}; }
3215: return if ($udom eq 'public' && $uname eq 'public');
3216: my $id=$uname.':'.$udom;
3217: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3218: }
3219:
1.61 www 3220: # ------------------------------------------------------------------ Screenname
1.81 albertel 3221:
3222: =pod
3223:
1.648 raeburn 3224: =item * &screenname($uname,$udom)
1.81 albertel 3225:
3226: Gets a users screenname and returns it as a string
3227:
3228: =cut
1.61 www 3229:
3230: sub screenname {
3231: my ($uname,$udom)=@_;
1.258 albertel 3232: if ($uname eq $env{'user.name'} &&
3233: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3234: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3235: return $names{'screenname'};
1.62 www 3236: }
3237:
1.212 albertel 3238:
1.802 bisitz 3239: # ------------------------------------------------------------- Confirm Wrapper
3240: =pod
3241:
1.1075.2.42 raeburn 3242: =item * &confirmwrapper($message)
1.802 bisitz 3243:
3244: Wrap messages about completion of operation in box
3245:
3246: =cut
3247:
3248: sub confirmwrapper {
3249: my ($message)=@_;
3250: if ($message) {
3251: return "\n".'<div class="LC_confirm_box">'."\n"
3252: .$message."\n"
3253: .'</div>'."\n";
3254: } else {
3255: return $message;
3256: }
3257: }
3258:
1.62 www 3259: # ------------------------------------------------------------- Message Wrapper
3260:
3261: sub messagewrapper {
1.369 www 3262: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3263: return
1.441 albertel 3264: '<a href="/adm/email?compose=individual&'.
3265: 'recname='.$username.'&recdom='.$domain.
3266: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3267: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3268: }
1.802 bisitz 3269:
1.74 www 3270: # --------------------------------------------------------------- Notes Wrapper
3271:
3272: sub noteswrapper {
3273: my ($link,$un,$do)=@_;
3274: return
1.896 amueller 3275: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3276: }
1.802 bisitz 3277:
1.62 www 3278: # ------------------------------------------------------------- Aboutme Wrapper
3279:
3280: sub aboutmewrapper {
1.1070 raeburn 3281: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3282: if (!defined($username) && !defined($domain)) {
3283: return;
3284: }
1.1075.2.15 raeburn 3285: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3286: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3287: }
3288:
3289: # ------------------------------------------------------------ Syllabus Wrapper
3290:
3291: sub syllabuswrapper {
1.707 bisitz 3292: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3293: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3294: }
1.14 harris41 3295:
1.802 bisitz 3296: # -----------------------------------------------------------------------------
3297:
1.208 matthew 3298: sub track_student_link {
1.887 raeburn 3299: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3300: my $link ="/adm/trackstudent?";
1.208 matthew 3301: my $title = 'View recent activity';
3302: if (defined($sname) && $sname !~ /^\s*$/ &&
3303: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3304: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3305: $title .= ' of this student';
1.268 albertel 3306: }
1.208 matthew 3307: if (defined($target) && $target !~ /^\s*$/) {
3308: $target = qq{target="$target"};
3309: } else {
3310: $target = '';
3311: }
1.268 albertel 3312: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3313: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3314: $title = &mt($title);
3315: $linktext = &mt($linktext);
1.448 albertel 3316: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3317: &help_open_topic('View_recent_activity');
1.208 matthew 3318: }
3319:
1.781 raeburn 3320: sub slot_reservations_link {
3321: my ($linktext,$sname,$sdom,$target) = @_;
3322: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3323: my $title = 'View slot reservation history';
3324: if (defined($sname) && $sname !~ /^\s*$/ &&
3325: defined($sdom) && $sdom !~ /^\s*$/) {
3326: $link .= "&uname=$sname&udom=$sdom";
3327: $title .= ' of this student';
3328: }
3329: if (defined($target) && $target !~ /^\s*$/) {
3330: $target = qq{target="$target"};
3331: } else {
3332: $target = '';
3333: }
3334: $title = &mt($title);
3335: $linktext = &mt($linktext);
3336: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3337: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3338:
3339: }
3340:
1.508 www 3341: # ===================================================== Display a student photo
3342:
3343:
1.509 albertel 3344: sub student_image_tag {
1.508 www 3345: my ($domain,$user)=@_;
3346: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3347: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3348: return '<img src="'.$imgsrc.'" align="right" />';
3349: } else {
3350: return '';
3351: }
3352: }
3353:
1.112 bowersj2 3354: =pod
3355:
3356: =back
3357:
3358: =head1 Access .tab File Data
3359:
3360: =over 4
3361:
1.648 raeburn 3362: =item * &languageids()
1.112 bowersj2 3363:
3364: returns list of all language ids
3365:
3366: =cut
3367:
1.14 harris41 3368: sub languageids {
1.16 harris41 3369: return sort(keys(%language));
1.14 harris41 3370: }
3371:
1.112 bowersj2 3372: =pod
3373:
1.648 raeburn 3374: =item * &languagedescription()
1.112 bowersj2 3375:
3376: returns description of a specified language id
3377:
3378: =cut
3379:
1.14 harris41 3380: sub languagedescription {
1.125 www 3381: my $code=shift;
3382: return ($supported_language{$code}?'* ':'').
3383: $language{$code}.
1.126 www 3384: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3385: }
3386:
1.1048 foxr 3387: =pod
3388:
3389: =item * &plainlanguagedescription
3390:
3391: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3392: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3393:
3394: =cut
3395:
1.145 www 3396: sub plainlanguagedescription {
3397: my $code=shift;
3398: return $language{$code};
3399: }
3400:
1.1048 foxr 3401: =pod
3402:
3403: =item * &supportedlanguagecode
3404:
3405: Returns the supported language code (e.g. sptutf maps to pt) given a language
3406: code.
3407:
3408: =cut
3409:
1.145 www 3410: sub supportedlanguagecode {
3411: my $code=shift;
3412: return $supported_language{$code};
1.97 www 3413: }
3414:
1.112 bowersj2 3415: =pod
3416:
1.1048 foxr 3417: =item * &latexlanguage()
3418:
3419: Given a language key code returns the correspondnig language to use
3420: to select the correct hyphenation on LaTeX printouts. This is undef if there
3421: is no supported hyphenation for the language code.
3422:
3423: =cut
3424:
3425: sub latexlanguage {
3426: my $code = shift;
3427: return $latex_language{$code};
3428: }
3429:
3430: =pod
3431:
3432: =item * &latexhyphenation()
3433:
3434: Same as above but what's supplied is the language as it might be stored
3435: in the metadata.
3436:
3437: =cut
3438:
3439: sub latexhyphenation {
3440: my $key = shift;
3441: return $latex_language_bykey{$key};
3442: }
3443:
3444: =pod
3445:
1.648 raeburn 3446: =item * ©rightids()
1.112 bowersj2 3447:
3448: returns list of all copyrights
3449:
3450: =cut
3451:
3452: sub copyrightids {
3453: return sort(keys(%cprtag));
3454: }
3455:
3456: =pod
3457:
1.648 raeburn 3458: =item * ©rightdescription()
1.112 bowersj2 3459:
3460: returns description of a specified copyright id
3461:
3462: =cut
3463:
3464: sub copyrightdescription {
1.166 www 3465: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3466: }
1.197 matthew 3467:
3468: =pod
3469:
1.648 raeburn 3470: =item * &source_copyrightids()
1.192 taceyjo1 3471:
3472: returns list of all source copyrights
3473:
3474: =cut
3475:
3476: sub source_copyrightids {
3477: return sort(keys(%scprtag));
3478: }
3479:
3480: =pod
3481:
1.648 raeburn 3482: =item * &source_copyrightdescription()
1.192 taceyjo1 3483:
3484: returns description of a specified source copyright id
3485:
3486: =cut
3487:
3488: sub source_copyrightdescription {
3489: return &mt($scprtag{shift(@_)});
3490: }
1.112 bowersj2 3491:
3492: =pod
3493:
1.648 raeburn 3494: =item * &filecategories()
1.112 bowersj2 3495:
3496: returns list of all file categories
3497:
3498: =cut
3499:
3500: sub filecategories {
3501: return sort(keys(%category_extensions));
3502: }
3503:
3504: =pod
3505:
1.648 raeburn 3506: =item * &filecategorytypes()
1.112 bowersj2 3507:
3508: returns list of file types belonging to a given file
3509: category
3510:
3511: =cut
3512:
3513: sub filecategorytypes {
1.356 albertel 3514: my ($cat) = @_;
3515: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3516: }
3517:
3518: =pod
3519:
1.648 raeburn 3520: =item * &fileembstyle()
1.112 bowersj2 3521:
3522: returns embedding style for a specified file type
3523:
3524: =cut
3525:
3526: sub fileembstyle {
3527: return $fe{lc(shift(@_))};
1.169 www 3528: }
3529:
1.351 www 3530: sub filemimetype {
3531: return $fm{lc(shift(@_))};
3532: }
3533:
1.169 www 3534:
3535: sub filecategoryselect {
3536: my ($name,$value)=@_;
1.189 matthew 3537: return &select_form($value,$name,
1.970 raeburn 3538: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3539: }
3540:
3541: =pod
3542:
1.648 raeburn 3543: =item * &filedescription()
1.112 bowersj2 3544:
3545: returns description for a specified file type
3546:
3547: =cut
3548:
3549: sub filedescription {
1.188 matthew 3550: my $file_description = $fd{lc(shift())};
3551: $file_description =~ s:([\[\]]):~$1:g;
3552: return &mt($file_description);
1.112 bowersj2 3553: }
3554:
3555: =pod
3556:
1.648 raeburn 3557: =item * &filedescriptionex()
1.112 bowersj2 3558:
3559: returns description for a specified file type with
3560: extra formatting
3561:
3562: =cut
3563:
3564: sub filedescriptionex {
3565: my $ex=shift;
1.188 matthew 3566: my $file_description = $fd{lc($ex)};
3567: $file_description =~ s:([\[\]]):~$1:g;
3568: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3569: }
3570:
3571: # End of .tab access
3572: =pod
3573:
3574: =back
3575:
3576: =cut
3577:
3578: # ------------------------------------------------------------------ File Types
3579: sub fileextensions {
3580: return sort(keys(%fe));
3581: }
3582:
1.97 www 3583: # ----------------------------------------------------------- Display Languages
3584: # returns a hash with all desired display languages
3585: #
3586:
3587: sub display_languages {
3588: my %languages=();
1.695 raeburn 3589: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3590: $languages{$lang}=1;
1.97 www 3591: }
3592: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3593: if ($env{'form.displaylanguage'}) {
1.356 albertel 3594: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3595: $languages{$lang}=1;
1.97 www 3596: }
3597: }
3598: return %languages;
1.14 harris41 3599: }
3600:
1.582 albertel 3601: sub languages {
3602: my ($possible_langs) = @_;
1.695 raeburn 3603: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3604: if (!ref($possible_langs)) {
3605: if( wantarray ) {
3606: return @preferred_langs;
3607: } else {
3608: return $preferred_langs[0];
3609: }
3610: }
3611: my %possibilities = map { $_ => 1 } (@$possible_langs);
3612: my @preferred_possibilities;
3613: foreach my $preferred_lang (@preferred_langs) {
3614: if (exists($possibilities{$preferred_lang})) {
3615: push(@preferred_possibilities, $preferred_lang);
3616: }
3617: }
3618: if( wantarray ) {
3619: return @preferred_possibilities;
3620: }
3621: return $preferred_possibilities[0];
3622: }
3623:
1.742 raeburn 3624: sub user_lang {
3625: my ($touname,$toudom,$fromcid) = @_;
3626: my @userlangs;
3627: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3628: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3629: $env{'course.'.$fromcid.'.languages'}));
3630: } else {
3631: my %langhash = &getlangs($touname,$toudom);
3632: if ($langhash{'languages'} ne '') {
3633: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3634: } else {
3635: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3636: if ($domdefs{'lang_def'} ne '') {
3637: @userlangs = ($domdefs{'lang_def'});
3638: }
3639: }
3640: }
3641: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3642: my $user_lh = Apache::localize->get_handle(@languages);
3643: return $user_lh;
3644: }
3645:
3646:
1.112 bowersj2 3647: ###############################################################
3648: ## Student Answer Attempts ##
3649: ###############################################################
3650:
3651: =pod
3652:
3653: =head1 Alternate Problem Views
3654:
3655: =over 4
3656:
1.648 raeburn 3657: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3658: $getattempt, $regexp, $gradesub)
3659:
3660: Return string with previous attempt on problem. Arguments:
3661:
3662: =over 4
3663:
3664: =item * $symb: Problem, including path
3665:
3666: =item * $username: username of the desired student
3667:
3668: =item * $domain: domain of the desired student
1.14 harris41 3669:
1.112 bowersj2 3670: =item * $course: Course ID
1.14 harris41 3671:
1.112 bowersj2 3672: =item * $getattempt: Leave blank for all attempts, otherwise put
3673: something
1.14 harris41 3674:
1.112 bowersj2 3675: =item * $regexp: if string matches this regexp, the string will be
3676: sent to $gradesub
1.14 harris41 3677:
1.112 bowersj2 3678: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3679:
1.112 bowersj2 3680: =back
1.14 harris41 3681:
1.112 bowersj2 3682: The output string is a table containing all desired attempts, if any.
1.16 harris41 3683:
1.112 bowersj2 3684: =cut
1.1 albertel 3685:
3686: sub get_previous_attempt {
1.43 ng 3687: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3688: my $prevattempts='';
1.43 ng 3689: no strict 'refs';
1.1 albertel 3690: if ($symb) {
1.3 albertel 3691: my (%returnhash)=
3692: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3693: if ($returnhash{'version'}) {
3694: my %lasthash=();
3695: my $version;
3696: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3697: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3698: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3699: }
1.1 albertel 3700: }
1.596 albertel 3701: $prevattempts=&start_data_table().&start_data_table_header_row();
3702: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3703: my (%typeparts,%lasthidden);
1.945 raeburn 3704: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3705: foreach my $key (sort(keys(%lasthash))) {
3706: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3707: if ($#parts > 0) {
1.31 albertel 3708: my $data=$parts[-1];
1.989 raeburn 3709: next if ($data eq 'foilorder');
1.31 albertel 3710: pop(@parts);
1.1010 www 3711: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3712: if ($data eq 'type') {
3713: unless ($showsurv) {
3714: my $id = join(',',@parts);
3715: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3716: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3717: $lasthidden{$ign.'.'.$id} = 1;
3718: }
1.945 raeburn 3719: }
1.1010 www 3720: }
1.31 albertel 3721: } else {
1.41 ng 3722: if ($#parts == 0) {
3723: $prevattempts.='<th>'.$parts[0].'</th>';
3724: } else {
3725: $prevattempts.='<th>'.$ign.'</th>';
3726: }
1.31 albertel 3727: }
1.16 harris41 3728: }
1.596 albertel 3729: $prevattempts.=&end_data_table_header_row();
1.40 ng 3730: if ($getattempt eq '') {
3731: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3732: my @hidden;
3733: if (%typeparts) {
3734: foreach my $id (keys(%typeparts)) {
3735: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3736: push(@hidden,$id);
3737: }
3738: }
3739: }
3740: $prevattempts.=&start_data_table_row().
3741: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3742: if (@hidden) {
3743: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3744: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3745: my $hide;
3746: foreach my $id (@hidden) {
3747: if ($key =~ /^\Q$id\E/) {
3748: $hide = 1;
3749: last;
3750: }
3751: }
3752: if ($hide) {
3753: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3754: if (($data eq 'award') || ($data eq 'awarddetail')) {
3755: my $value = &format_previous_attempt_value($key,
3756: $returnhash{$version.':'.$key});
3757: $prevattempts.='<td>'.$value.' </td>';
3758: } else {
3759: $prevattempts.='<td> </td>';
3760: }
3761: } else {
3762: if ($key =~ /\./) {
3763: my $value = &format_previous_attempt_value($key,
3764: $returnhash{$version.':'.$key});
3765: $prevattempts.='<td>'.$value.' </td>';
3766: } else {
3767: $prevattempts.='<td> </td>';
3768: }
3769: }
3770: }
3771: } else {
3772: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3773: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3774: my $value = &format_previous_attempt_value($key,
3775: $returnhash{$version.':'.$key});
3776: $prevattempts.='<td>'.$value.' </td>';
3777: }
3778: }
3779: $prevattempts.=&end_data_table_row();
1.40 ng 3780: }
1.1 albertel 3781: }
1.945 raeburn 3782: my @currhidden = keys(%lasthidden);
1.596 albertel 3783: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3784: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3785: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3786: if (%typeparts) {
3787: my $hidden;
3788: foreach my $id (@currhidden) {
3789: if ($key =~ /^\Q$id\E/) {
3790: $hidden = 1;
3791: last;
3792: }
3793: }
3794: if ($hidden) {
3795: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3796: if (($data eq 'award') || ($data eq 'awarddetail')) {
3797: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3798: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3799: $value = &$gradesub($value);
3800: }
3801: $prevattempts.='<td>'.$value.' </td>';
3802: } else {
3803: $prevattempts.='<td> </td>';
3804: }
3805: } else {
3806: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3807: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3808: $value = &$gradesub($value);
3809: }
3810: $prevattempts.='<td>'.$value.' </td>';
3811: }
3812: } else {
3813: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3814: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3815: $value = &$gradesub($value);
3816: }
3817: $prevattempts.='<td>'.$value.' </td>';
3818: }
1.16 harris41 3819: }
1.596 albertel 3820: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3821: } else {
1.596 albertel 3822: $prevattempts=
3823: &start_data_table().&start_data_table_row().
3824: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3825: &end_data_table_row().&end_data_table();
1.1 albertel 3826: }
3827: } else {
1.596 albertel 3828: $prevattempts=
3829: &start_data_table().&start_data_table_row().
3830: '<td>'.&mt('No data.').'</td>'.
3831: &end_data_table_row().&end_data_table();
1.1 albertel 3832: }
1.10 albertel 3833: }
3834:
1.581 albertel 3835: sub format_previous_attempt_value {
3836: my ($key,$value) = @_;
1.1011 www 3837: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3838: $value = &Apache::lonlocal::locallocaltime($value);
3839: } elsif (ref($value) eq 'ARRAY') {
3840: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3841: } elsif ($key =~ /answerstring$/) {
3842: my %answers = &Apache::lonnet::str2hash($value);
3843: my @anskeys = sort(keys(%answers));
3844: if (@anskeys == 1) {
3845: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3846: if ($answer =~ m{\0}) {
3847: $answer =~ s{\0}{,}g;
1.988 raeburn 3848: }
3849: my $tag_internal_answer_name = 'INTERNAL';
3850: if ($anskeys[0] eq $tag_internal_answer_name) {
3851: $value = $answer;
3852: } else {
3853: $value = $anskeys[0].'='.$answer;
3854: }
3855: } else {
3856: foreach my $ans (@anskeys) {
3857: my $answer = $answers{$ans};
1.1001 raeburn 3858: if ($answer =~ m{\0}) {
3859: $answer =~ s{\0}{,}g;
1.988 raeburn 3860: }
3861: $value .= $ans.'='.$answer.'<br />';;
3862: }
3863: }
1.581 albertel 3864: } else {
3865: $value = &unescape($value);
3866: }
3867: return $value;
3868: }
3869:
3870:
1.107 albertel 3871: sub relative_to_absolute {
3872: my ($url,$output)=@_;
3873: my $parser=HTML::TokeParser->new(\$output);
3874: my $token;
3875: my $thisdir=$url;
3876: my @rlinks=();
3877: while ($token=$parser->get_token) {
3878: if ($token->[0] eq 'S') {
3879: if ($token->[1] eq 'a') {
3880: if ($token->[2]->{'href'}) {
3881: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3882: }
3883: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3884: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3885: } elsif ($token->[1] eq 'base') {
3886: $thisdir=$token->[2]->{'href'};
3887: }
3888: }
3889: }
3890: $thisdir=~s-/[^/]*$--;
1.356 albertel 3891: foreach my $link (@rlinks) {
1.726 raeburn 3892: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3893: ($link=~/^\//) ||
3894: ($link=~/^javascript:/i) ||
3895: ($link=~/^mailto:/i) ||
3896: ($link=~/^\#/)) {
3897: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3898: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3899: }
3900: }
3901: # -------------------------------------------------- Deal with Applet codebases
3902: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3903: return $output;
3904: }
3905:
1.112 bowersj2 3906: =pod
3907:
1.648 raeburn 3908: =item * &get_student_view()
1.112 bowersj2 3909:
3910: show a snapshot of what student was looking at
3911:
3912: =cut
3913:
1.10 albertel 3914: sub get_student_view {
1.186 albertel 3915: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3916: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3917: my (%form);
1.10 albertel 3918: my @elements=('symb','courseid','domain','username');
3919: foreach my $element (@elements) {
1.186 albertel 3920: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3921: }
1.186 albertel 3922: if (defined($moreenv)) {
3923: %form=(%form,%{$moreenv});
3924: }
1.236 albertel 3925: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3926: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3927: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3928: $userview=~s/\<body[^\>]*\>//gi;
3929: $userview=~s/\<\/body\>//gi;
3930: $userview=~s/\<html\>//gi;
3931: $userview=~s/\<\/html\>//gi;
3932: $userview=~s/\<head\>//gi;
3933: $userview=~s/\<\/head\>//gi;
3934: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3935: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3936: if (wantarray) {
3937: return ($userview,$response);
3938: } else {
3939: return $userview;
3940: }
3941: }
3942:
3943: sub get_student_view_with_retries {
3944: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3945:
3946: my $ok = 0; # True if we got a good response.
3947: my $content;
3948: my $response;
3949:
3950: # Try to get the student_view done. within the retries count:
3951:
3952: do {
3953: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3954: $ok = $response->is_success;
3955: if (!$ok) {
3956: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3957: }
3958: $retries--;
3959: } while (!$ok && ($retries > 0));
3960:
3961: if (!$ok) {
3962: $content = ''; # On error return an empty content.
3963: }
1.651 www 3964: if (wantarray) {
3965: return ($content, $response);
3966: } else {
3967: return $content;
3968: }
1.11 albertel 3969: }
3970:
1.112 bowersj2 3971: =pod
3972:
1.648 raeburn 3973: =item * &get_student_answers()
1.112 bowersj2 3974:
3975: show a snapshot of how student was answering problem
3976:
3977: =cut
3978:
1.11 albertel 3979: sub get_student_answers {
1.100 sakharuk 3980: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3981: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3982: my (%moreenv);
1.11 albertel 3983: my @elements=('symb','courseid','domain','username');
3984: foreach my $element (@elements) {
1.186 albertel 3985: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3986: }
1.186 albertel 3987: $moreenv{'grade_target'}='answer';
3988: %moreenv=(%form,%moreenv);
1.497 raeburn 3989: $feedurl = &Apache::lonnet::clutter($feedurl);
3990: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3991: return $userview;
1.1 albertel 3992: }
1.116 albertel 3993:
3994: =pod
3995:
3996: =item * &submlink()
3997:
1.242 albertel 3998: Inputs: $text $uname $udom $symb $target
1.116 albertel 3999:
4000: Returns: A link to grades.pm such as to see the SUBM view of a student
4001:
4002: =cut
4003:
4004: ###############################################
4005: sub submlink {
1.242 albertel 4006: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4007: if (!($uname && $udom)) {
4008: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4009: &Apache::lonnet::whichuser($symb);
1.116 albertel 4010: if (!$symb) { $symb=$cursymb; }
4011: }
1.254 matthew 4012: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4013: $symb=&escape($symb);
1.960 bisitz 4014: if ($target) { $target=" target=\"$target\""; }
4015: return
4016: '<a href="/adm/grades?command=submission'.
4017: '&symb='.$symb.
4018: '&student='.$uname.
4019: '&userdom='.$udom.'"'.
4020: $target.'>'.$text.'</a>';
1.242 albertel 4021: }
4022: ##############################################
4023:
4024: =pod
4025:
4026: =item * &pgrdlink()
4027:
4028: Inputs: $text $uname $udom $symb $target
4029:
4030: Returns: A link to grades.pm such as to see the PGRD view of a student
4031:
4032: =cut
4033:
4034: ###############################################
4035: sub pgrdlink {
4036: my $link=&submlink(@_);
4037: $link=~s/(&command=submission)/$1&showgrading=yes/;
4038: return $link;
4039: }
4040: ##############################################
4041:
4042: =pod
4043:
4044: =item * &pprmlink()
4045:
4046: Inputs: $text $uname $udom $symb $target
4047:
4048: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4049: student and a specific resource
1.242 albertel 4050:
4051: =cut
4052:
4053: ###############################################
4054: sub pprmlink {
4055: my ($text,$uname,$udom,$symb,$target)=@_;
4056: if (!($uname && $udom)) {
4057: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4058: &Apache::lonnet::whichuser($symb);
1.242 albertel 4059: if (!$symb) { $symb=$cursymb; }
4060: }
1.254 matthew 4061: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4062: $symb=&escape($symb);
1.242 albertel 4063: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4064: return '<a href="/adm/parmset?command=set&'.
4065: 'symb='.$symb.'&uname='.$uname.
4066: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4067: }
4068: ##############################################
1.37 matthew 4069:
1.112 bowersj2 4070: =pod
4071:
4072: =back
4073:
4074: =cut
4075:
1.37 matthew 4076: ###############################################
1.51 www 4077:
4078:
4079: sub timehash {
1.687 raeburn 4080: my ($thistime) = @_;
4081: my $timezone = &Apache::lonlocal::gettimezone();
4082: my $dt = DateTime->from_epoch(epoch => $thistime)
4083: ->set_time_zone($timezone);
4084: my $wday = $dt->day_of_week();
4085: if ($wday == 7) { $wday = 0; }
4086: return ( 'second' => $dt->second(),
4087: 'minute' => $dt->minute(),
4088: 'hour' => $dt->hour(),
4089: 'day' => $dt->day_of_month(),
4090: 'month' => $dt->month(),
4091: 'year' => $dt->year(),
4092: 'weekday' => $wday,
4093: 'dayyear' => $dt->day_of_year(),
4094: 'dlsav' => $dt->is_dst() );
1.51 www 4095: }
4096:
1.370 www 4097: sub utc_string {
4098: my ($date)=@_;
1.371 www 4099: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4100: }
4101:
1.51 www 4102: sub maketime {
4103: my %th=@_;
1.687 raeburn 4104: my ($epoch_time,$timezone,$dt);
4105: $timezone = &Apache::lonlocal::gettimezone();
4106: eval {
4107: $dt = DateTime->new( year => $th{'year'},
4108: month => $th{'month'},
4109: day => $th{'day'},
4110: hour => $th{'hour'},
4111: minute => $th{'minute'},
4112: second => $th{'second'},
4113: time_zone => $timezone,
4114: );
4115: };
4116: if (!$@) {
4117: $epoch_time = $dt->epoch;
4118: if ($epoch_time) {
4119: return $epoch_time;
4120: }
4121: }
1.51 www 4122: return POSIX::mktime(
4123: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4124: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4125: }
4126:
4127: #########################################
1.51 www 4128:
4129: sub findallcourses {
1.482 raeburn 4130: my ($roles,$uname,$udom) = @_;
1.355 albertel 4131: my %roles;
4132: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4133: my %courses;
1.51 www 4134: my $now=time;
1.482 raeburn 4135: if (!defined($uname)) {
4136: $uname = $env{'user.name'};
4137: }
4138: if (!defined($udom)) {
4139: $udom = $env{'user.domain'};
4140: }
4141: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4142: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4143: if (!%roles) {
4144: %roles = (
4145: cc => 1,
1.907 raeburn 4146: co => 1,
1.482 raeburn 4147: in => 1,
4148: ep => 1,
4149: ta => 1,
4150: cr => 1,
4151: st => 1,
4152: );
4153: }
4154: foreach my $entry (keys(%roleshash)) {
4155: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4156: if ($trole =~ /^cr/) {
4157: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4158: } else {
4159: next if (!exists($roles{$trole}));
4160: }
4161: if ($tend) {
4162: next if ($tend < $now);
4163: }
4164: if ($tstart) {
4165: next if ($tstart > $now);
4166: }
1.1058 raeburn 4167: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4168: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4169: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4170: if ($secpart eq '') {
4171: ($cnum,$role) = split(/_/,$cnumpart);
4172: $sec = 'none';
1.1058 raeburn 4173: $value .= $cnum.'/';
1.482 raeburn 4174: } else {
4175: $cnum = $cnumpart;
4176: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4177: $value .= $cnum.'/'.$sec;
4178: }
4179: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4180: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4181: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4182: }
4183: } else {
4184: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4185: }
1.482 raeburn 4186: }
4187: } else {
4188: foreach my $key (keys(%env)) {
1.483 albertel 4189: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4190: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4191: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4192: next if ($role eq 'ca' || $role eq 'aa');
4193: next if (%roles && !exists($roles{$role}));
4194: my ($starttime,$endtime)=split(/\./,$env{$key});
4195: my $active=1;
4196: if ($starttime) {
4197: if ($now<$starttime) { $active=0; }
4198: }
4199: if ($endtime) {
4200: if ($now>$endtime) { $active=0; }
4201: }
4202: if ($active) {
1.1058 raeburn 4203: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4204: if ($sec eq '') {
4205: $sec = 'none';
1.1058 raeburn 4206: } else {
4207: $value .= $sec;
4208: }
4209: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4210: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4211: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4212: }
4213: } else {
4214: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4215: }
1.474 raeburn 4216: }
4217: }
1.51 www 4218: }
4219: }
1.474 raeburn 4220: return %courses;
1.51 www 4221: }
1.37 matthew 4222:
1.54 www 4223: ###############################################
1.474 raeburn 4224:
4225: sub blockcheck {
1.1062 raeburn 4226: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4227:
4228: if (!defined($udom)) {
4229: $udom = $env{'user.domain'};
4230: }
4231: if (!defined($uname)) {
4232: $uname = $env{'user.name'};
4233: }
4234:
4235: # If uname and udom are for a course, check for blocks in the course.
4236:
4237: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4238: my ($startblock,$endblock,$triggerblock) =
4239: &get_blocks($setters,$activity,$udom,$uname,$url);
4240: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4241: }
1.474 raeburn 4242:
1.502 raeburn 4243: my $startblock = 0;
4244: my $endblock = 0;
1.1062 raeburn 4245: my $triggerblock = '';
1.482 raeburn 4246: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4247:
1.490 raeburn 4248: # If uname is for a user, and activity is course-specific, i.e.,
4249: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4250:
1.490 raeburn 4251: if (($activity eq 'boards' || $activity eq 'chat' ||
4252: $activity eq 'groups') && ($env{'request.course.id'})) {
4253: foreach my $key (keys(%live_courses)) {
4254: if ($key ne $env{'request.course.id'}) {
4255: delete($live_courses{$key});
4256: }
4257: }
4258: }
4259:
4260: my $otheruser = 0;
4261: my %own_courses;
4262: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4263: # Resource belongs to user other than current user.
4264: $otheruser = 1;
4265: # Gather courses for current user
4266: %own_courses =
4267: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4268: }
4269:
4270: # Gather active course roles - course coordinator, instructor,
4271: # exam proctor, ta, student, or custom role.
1.474 raeburn 4272:
4273: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4274: my ($cdom,$cnum);
4275: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4276: $cdom = $env{'course.'.$course.'.domain'};
4277: $cnum = $env{'course.'.$course.'.num'};
4278: } else {
1.490 raeburn 4279: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4280: }
4281: my $no_ownblock = 0;
4282: my $no_userblock = 0;
1.533 raeburn 4283: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4284: # Check if current user has 'evb' priv for this
4285: if (defined($own_courses{$course})) {
4286: foreach my $sec (keys(%{$own_courses{$course}})) {
4287: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4288: if ($sec ne 'none') {
4289: $checkrole .= '/'.$sec;
4290: }
4291: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4292: $no_ownblock = 1;
4293: last;
4294: }
4295: }
4296: }
4297: # if they have 'evb' priv and are currently not playing student
4298: next if (($no_ownblock) &&
4299: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4300: }
1.474 raeburn 4301: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4302: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4303: if ($sec ne 'none') {
1.482 raeburn 4304: $checkrole .= '/'.$sec;
1.474 raeburn 4305: }
1.490 raeburn 4306: if ($otheruser) {
4307: # Resource belongs to user other than current user.
4308: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4309: my (%allroles,%userroles);
4310: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4311: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4312: my ($trole,$tdom,$tnum,$tsec);
4313: if ($entry =~ /^cr/) {
4314: ($trole,$tdom,$tnum,$tsec) =
4315: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4316: } else {
4317: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4318: }
4319: my ($spec,$area,$trest);
4320: $area = '/'.$tdom.'/'.$tnum;
4321: $trest = $tnum;
4322: if ($tsec ne '') {
4323: $area .= '/'.$tsec;
4324: $trest .= '/'.$tsec;
4325: }
4326: $spec = $trole.'.'.$area;
4327: if ($trole =~ /^cr/) {
4328: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4329: $tdom,$spec,$trest,$area);
4330: } else {
4331: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4332: $tdom,$spec,$trest,$area);
4333: }
4334: }
4335: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4336: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4337: if ($1) {
4338: $no_userblock = 1;
4339: last;
4340: }
1.486 raeburn 4341: }
4342: }
1.490 raeburn 4343: } else {
4344: # Resource belongs to current user
4345: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4346: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4347: $no_ownblock = 1;
4348: last;
4349: }
1.474 raeburn 4350: }
4351: }
4352: # if they have the evb priv and are currently not playing student
1.482 raeburn 4353: next if (($no_ownblock) &&
1.491 albertel 4354: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4355: next if ($no_userblock);
1.474 raeburn 4356:
1.866 kalberla 4357: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4358: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4359:
1.1062 raeburn 4360: my ($start,$end,$trigger) =
4361: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4362: if (($start != 0) &&
4363: (($startblock == 0) || ($startblock > $start))) {
4364: $startblock = $start;
1.1062 raeburn 4365: if ($trigger ne '') {
4366: $triggerblock = $trigger;
4367: }
1.502 raeburn 4368: }
4369: if (($end != 0) &&
4370: (($endblock == 0) || ($endblock < $end))) {
4371: $endblock = $end;
1.1062 raeburn 4372: if ($trigger ne '') {
4373: $triggerblock = $trigger;
4374: }
1.502 raeburn 4375: }
1.490 raeburn 4376: }
1.1062 raeburn 4377: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4378: }
4379:
4380: sub get_blocks {
1.1062 raeburn 4381: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4382: my $startblock = 0;
4383: my $endblock = 0;
1.1062 raeburn 4384: my $triggerblock = '';
1.490 raeburn 4385: my $course = $cdom.'_'.$cnum;
4386: $setters->{$course} = {};
4387: $setters->{$course}{'staff'} = [];
4388: $setters->{$course}{'times'} = [];
1.1062 raeburn 4389: $setters->{$course}{'triggers'} = [];
4390: my (@blockers,%triggered);
4391: my $now = time;
4392: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4393: if ($activity eq 'docs') {
4394: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4395: foreach my $block (@blockers) {
4396: if ($block =~ /^firstaccess____(.+)$/) {
4397: my $item = $1;
4398: my $type = 'map';
4399: my $timersymb = $item;
4400: if ($item eq 'course') {
4401: $type = 'course';
4402: } elsif ($item =~ /___\d+___/) {
4403: $type = 'resource';
4404: } else {
4405: $timersymb = &Apache::lonnet::symbread($item);
4406: }
4407: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4408: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4409: $triggered{$block} = {
4410: start => $start,
4411: end => $end,
4412: type => $type,
4413: };
4414: }
4415: }
4416: } else {
4417: foreach my $block (keys(%commblocks)) {
4418: if ($block =~ m/^(\d+)____(\d+)$/) {
4419: my ($start,$end) = ($1,$2);
4420: if ($start <= time && $end >= time) {
4421: if (ref($commblocks{$block}) eq 'HASH') {
4422: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4423: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4424: unless(grep(/^\Q$block\E$/,@blockers)) {
4425: push(@blockers,$block);
4426: }
4427: }
4428: }
4429: }
4430: }
4431: } elsif ($block =~ /^firstaccess____(.+)$/) {
4432: my $item = $1;
4433: my $timersymb = $item;
4434: my $type = 'map';
4435: if ($item eq 'course') {
4436: $type = 'course';
4437: } elsif ($item =~ /___\d+___/) {
4438: $type = 'resource';
4439: } else {
4440: $timersymb = &Apache::lonnet::symbread($item);
4441: }
4442: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4443: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4444: if ($start && $end) {
4445: if (($start <= time) && ($end >= time)) {
4446: unless (grep(/^\Q$block\E$/,@blockers)) {
4447: push(@blockers,$block);
4448: $triggered{$block} = {
4449: start => $start,
4450: end => $end,
4451: type => $type,
4452: };
4453: }
4454: }
1.490 raeburn 4455: }
1.1062 raeburn 4456: }
4457: }
4458: }
4459: foreach my $blocker (@blockers) {
4460: my ($staff_name,$staff_dom,$title,$blocks) =
4461: &parse_block_record($commblocks{$blocker});
4462: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4463: my ($start,$end,$triggertype);
4464: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4465: ($start,$end) = ($1,$2);
4466: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4467: $start = $triggered{$blocker}{'start'};
4468: $end = $triggered{$blocker}{'end'};
4469: $triggertype = $triggered{$blocker}{'type'};
4470: }
4471: if ($start) {
4472: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4473: if ($triggertype) {
4474: push(@{$$setters{$course}{'triggers'}},$triggertype);
4475: } else {
4476: push(@{$$setters{$course}{'triggers'}},0);
4477: }
4478: if ( ($startblock == 0) || ($startblock > $start) ) {
4479: $startblock = $start;
4480: if ($triggertype) {
4481: $triggerblock = $blocker;
1.474 raeburn 4482: }
4483: }
1.1062 raeburn 4484: if ( ($endblock == 0) || ($endblock < $end) ) {
4485: $endblock = $end;
4486: if ($triggertype) {
4487: $triggerblock = $blocker;
4488: }
4489: }
1.474 raeburn 4490: }
4491: }
1.1062 raeburn 4492: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4493: }
4494:
4495: sub parse_block_record {
4496: my ($record) = @_;
4497: my ($setuname,$setudom,$title,$blocks);
4498: if (ref($record) eq 'HASH') {
4499: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4500: $title = &unescape($record->{'event'});
4501: $blocks = $record->{'blocks'};
4502: } else {
4503: my @data = split(/:/,$record,3);
4504: if (scalar(@data) eq 2) {
4505: $title = $data[1];
4506: ($setuname,$setudom) = split(/@/,$data[0]);
4507: } else {
4508: ($setuname,$setudom,$title) = @data;
4509: }
4510: $blocks = { 'com' => 'on' };
4511: }
4512: return ($setuname,$setudom,$title,$blocks);
4513: }
4514:
1.854 kalberla 4515: sub blocking_status {
1.1062 raeburn 4516: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4517: my %setters;
1.890 droeschl 4518:
1.1061 raeburn 4519: # check for active blocking
1.1062 raeburn 4520: my ($startblock,$endblock,$triggerblock) =
4521: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4522: my $blocked = 0;
4523: if ($startblock && $endblock) {
4524: $blocked = 1;
4525: }
1.890 droeschl 4526:
1.1061 raeburn 4527: # caller just wants to know whether a block is active
4528: if (!wantarray) { return $blocked; }
4529:
4530: # build a link to a popup window containing the details
4531: my $querystring = "?activity=$activity";
4532: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4533: if ($activity eq 'port') {
4534: $querystring .= "&udom=$udom" if $udom;
4535: $querystring .= "&uname=$uname" if $uname;
4536: } elsif ($activity eq 'docs') {
4537: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4538: }
1.1061 raeburn 4539:
4540: my $output .= <<'END_MYBLOCK';
4541: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4542: var options = "width=" + w + ",height=" + h + ",";
4543: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4544: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4545: var newWin = window.open(url, wdwName, options);
4546: newWin.focus();
4547: }
1.890 droeschl 4548: END_MYBLOCK
1.854 kalberla 4549:
1.1061 raeburn 4550: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4551:
1.1061 raeburn 4552: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4553: my $text = &mt('Communication Blocked');
4554: if ($activity eq 'docs') {
4555: $text = &mt('Content Access Blocked');
1.1063 raeburn 4556: } elsif ($activity eq 'printout') {
4557: $text = &mt('Printing Blocked');
1.1062 raeburn 4558: }
1.1061 raeburn 4559: $output .= <<"END_BLOCK";
1.867 kalberla 4560: <div class='LC_comblock'>
1.869 kalberla 4561: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4562: title='$text'>
4563: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4564: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4565: title='$text'>$text</a>
1.867 kalberla 4566: </div>
4567:
4568: END_BLOCK
1.474 raeburn 4569:
1.1061 raeburn 4570: return ($blocked, $output);
1.854 kalberla 4571: }
1.490 raeburn 4572:
1.60 matthew 4573: ###############################################
4574:
1.682 raeburn 4575: sub check_ip_acc {
4576: my ($acc)=@_;
4577: &Apache::lonxml::debug("acc is $acc");
4578: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4579: return 1;
4580: }
4581: my $allowed=0;
4582: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4583:
4584: my $name;
4585: foreach my $pattern (split(',',$acc)) {
4586: $pattern =~ s/^\s*//;
4587: $pattern =~ s/\s*$//;
4588: if ($pattern =~ /\*$/) {
4589: #35.8.*
4590: $pattern=~s/\*//;
4591: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4592: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4593: #35.8.3.[34-56]
4594: my $low=$2;
4595: my $high=$3;
4596: $pattern=$1;
4597: if ($ip =~ /^\Q$pattern\E/) {
4598: my $last=(split(/\./,$ip))[3];
4599: if ($last <=$high && $last >=$low) { $allowed=1; }
4600: }
4601: } elsif ($pattern =~ /^\*/) {
4602: #*.msu.edu
4603: $pattern=~s/\*//;
4604: if (!defined($name)) {
4605: use Socket;
4606: my $netaddr=inet_aton($ip);
4607: ($name)=gethostbyaddr($netaddr,AF_INET);
4608: }
4609: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4610: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4611: #127.0.0.1
4612: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4613: } else {
4614: #some.name.com
4615: if (!defined($name)) {
4616: use Socket;
4617: my $netaddr=inet_aton($ip);
4618: ($name)=gethostbyaddr($netaddr,AF_INET);
4619: }
4620: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4621: }
4622: if ($allowed) { last; }
4623: }
4624: return $allowed;
4625: }
4626:
4627: ###############################################
4628:
1.60 matthew 4629: =pod
4630:
1.112 bowersj2 4631: =head1 Domain Template Functions
4632:
4633: =over 4
4634:
4635: =item * &determinedomain()
1.60 matthew 4636:
4637: Inputs: $domain (usually will be undef)
4638:
1.63 www 4639: Returns: Determines which domain should be used for designs
1.60 matthew 4640:
4641: =cut
1.54 www 4642:
1.60 matthew 4643: ###############################################
1.63 www 4644: sub determinedomain {
4645: my $domain=shift;
1.531 albertel 4646: if (! $domain) {
1.60 matthew 4647: # Determine domain if we have not been given one
1.893 raeburn 4648: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4649: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4650: if ($env{'request.role.domain'}) {
4651: $domain=$env{'request.role.domain'};
1.60 matthew 4652: }
4653: }
1.63 www 4654: return $domain;
4655: }
4656: ###############################################
1.517 raeburn 4657:
1.518 albertel 4658: sub devalidate_domconfig_cache {
4659: my ($udom)=@_;
4660: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4661: }
4662:
4663: # ---------------------- Get domain configuration for a domain
4664: sub get_domainconf {
4665: my ($udom) = @_;
4666: my $cachetime=1800;
4667: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4668: if (defined($cached)) { return %{$result}; }
4669:
4670: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4671: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4672: my (%designhash,%legacy);
1.518 albertel 4673: if (keys(%domconfig) > 0) {
4674: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4675: if (keys(%{$domconfig{'login'}})) {
4676: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4677: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4678: if ($key eq 'loginvia') {
4679: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4680: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4681: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4682: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4683: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4684: $designhash{$udom.'.login.loginvia'} = $server;
4685: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4686:
4687: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4688: } else {
1.1013 raeburn 4689: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4690: }
4691: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4692: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4693: }
1.946 raeburn 4694: }
4695: }
4696: }
4697: }
4698: } else {
4699: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4700: $designhash{$udom.'.login.'.$key.'_'.$img} =
4701: $domconfig{'login'}{$key}{$img};
4702: }
1.699 raeburn 4703: }
4704: } else {
4705: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4706: }
1.632 raeburn 4707: }
4708: } else {
4709: $legacy{'login'} = 1;
1.518 albertel 4710: }
1.632 raeburn 4711: } else {
4712: $legacy{'login'} = 1;
1.518 albertel 4713: }
4714: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4715: if (keys(%{$domconfig{'rolecolors'}})) {
4716: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4717: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4718: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4719: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4720: }
1.518 albertel 4721: }
4722: }
1.632 raeburn 4723: } else {
4724: $legacy{'rolecolors'} = 1;
1.518 albertel 4725: }
1.632 raeburn 4726: } else {
4727: $legacy{'rolecolors'} = 1;
1.518 albertel 4728: }
1.948 raeburn 4729: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4730: if ($domconfig{'autoenroll'}{'co-owners'}) {
4731: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4732: }
4733: }
1.632 raeburn 4734: if (keys(%legacy) > 0) {
4735: my %legacyhash = &get_legacy_domconf($udom);
4736: foreach my $item (keys(%legacyhash)) {
4737: if ($item =~ /^\Q$udom\E\.login/) {
4738: if ($legacy{'login'}) {
4739: $designhash{$item} = $legacyhash{$item};
4740: }
4741: } else {
4742: if ($legacy{'rolecolors'}) {
4743: $designhash{$item} = $legacyhash{$item};
4744: }
1.518 albertel 4745: }
4746: }
4747: }
1.632 raeburn 4748: } else {
4749: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4750: }
4751: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4752: $cachetime);
4753: return %designhash;
4754: }
4755:
1.632 raeburn 4756: sub get_legacy_domconf {
4757: my ($udom) = @_;
4758: my %legacyhash;
4759: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4760: my $designfile = $designdir.'/'.$udom.'.tab';
4761: if (-e $designfile) {
4762: if ( open (my $fh,"<$designfile") ) {
4763: while (my $line = <$fh>) {
4764: next if ($line =~ /^\#/);
4765: chomp($line);
4766: my ($key,$val)=(split(/\=/,$line));
4767: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4768: }
4769: close($fh);
4770: }
4771: }
1.1026 raeburn 4772: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4773: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4774: }
4775: return %legacyhash;
4776: }
4777:
1.63 www 4778: =pod
4779:
1.112 bowersj2 4780: =item * &domainlogo()
1.63 www 4781:
4782: Inputs: $domain (usually will be undef)
4783:
4784: Returns: A link to a domain logo, if the domain logo exists.
4785: If the domain logo does not exist, a description of the domain.
4786:
4787: =cut
1.112 bowersj2 4788:
1.63 www 4789: ###############################################
4790: sub domainlogo {
1.517 raeburn 4791: my $domain = &determinedomain(shift);
1.518 albertel 4792: my %designhash = &get_domainconf($domain);
1.517 raeburn 4793: # See if there is a logo
4794: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4795: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4796: if ($imgsrc =~ m{^/(adm|res)/}) {
4797: if ($imgsrc =~ m{^/res/}) {
4798: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4799: &Apache::lonnet::repcopy($local_name);
4800: }
4801: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4802: }
4803: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4804: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4805: return &Apache::lonnet::domain($domain,'description');
1.59 www 4806: } else {
1.60 matthew 4807: return '';
1.59 www 4808: }
4809: }
1.63 www 4810: ##############################################
4811:
4812: =pod
4813:
1.112 bowersj2 4814: =item * &designparm()
1.63 www 4815:
4816: Inputs: $which parameter; $domain (usually will be undef)
4817:
4818: Returns: value of designparamter $which
4819:
4820: =cut
1.112 bowersj2 4821:
1.397 albertel 4822:
1.400 albertel 4823: ##############################################
1.397 albertel 4824: sub designparm {
4825: my ($which,$domain)=@_;
4826: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4827: return $env{'environment.color.'.$which};
1.96 www 4828: }
1.63 www 4829: $domain=&determinedomain($domain);
1.1016 raeburn 4830: my %domdesign;
4831: unless ($domain eq 'public') {
4832: %domdesign = &get_domainconf($domain);
4833: }
1.520 raeburn 4834: my $output;
1.517 raeburn 4835: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4836: $output = $domdesign{$domain.'.'.$which};
1.63 www 4837: } else {
1.520 raeburn 4838: $output = $defaultdesign{$which};
4839: }
4840: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4841: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4842: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4843: if ($output =~ m{^/res/}) {
4844: my $local_name = &Apache::lonnet::filelocation('',$output);
4845: &Apache::lonnet::repcopy($local_name);
4846: }
1.520 raeburn 4847: $output = &lonhttpdurl($output);
4848: }
1.63 www 4849: }
1.520 raeburn 4850: return $output;
1.63 www 4851: }
1.59 www 4852:
1.822 bisitz 4853: ##############################################
4854: =pod
4855:
1.832 bisitz 4856: =item * &authorspace()
4857:
1.1028 raeburn 4858: Inputs: $url (usually will be undef).
1.832 bisitz 4859:
1.1075.2.40 raeburn 4860: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4861: directory being viewed (or for which action is being taken).
4862: If $url is provided, and begins /priv/<domain>/<uname>
4863: the path will be that portion of the $context argument.
4864: Otherwise the path will be for the author space of the current
4865: user when the current role is author, or for that of the
4866: co-author/assistant co-author space when the current role
4867: is co-author or assistant co-author.
1.832 bisitz 4868:
4869: =cut
4870:
4871: sub authorspace {
1.1028 raeburn 4872: my ($url) = @_;
4873: if ($url ne '') {
4874: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4875: return $1;
4876: }
4877: }
1.832 bisitz 4878: my $caname = '';
1.1024 www 4879: my $cadom = '';
1.1028 raeburn 4880: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4881: ($cadom,$caname) =
1.832 bisitz 4882: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4883: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4884: $caname = $env{'user.name'};
1.1024 www 4885: $cadom = $env{'user.domain'};
1.832 bisitz 4886: }
1.1028 raeburn 4887: if (($caname ne '') && ($cadom ne '')) {
4888: return "/priv/$cadom/$caname/";
4889: }
4890: return;
1.832 bisitz 4891: }
4892:
4893: ##############################################
4894: =pod
4895:
1.822 bisitz 4896: =item * &head_subbox()
4897:
4898: Inputs: $content (contains HTML code with page functions, etc.)
4899:
4900: Returns: HTML div with $content
4901: To be included in page header
4902:
4903: =cut
4904:
4905: sub head_subbox {
4906: my ($content)=@_;
4907: my $output =
1.993 raeburn 4908: '<div class="LC_head_subbox">'
1.822 bisitz 4909: .$content
4910: .'</div>'
4911: }
4912:
4913: ##############################################
4914: =pod
4915:
4916: =item * &CSTR_pageheader()
4917:
1.1026 raeburn 4918: Input: (optional) filename from which breadcrumb trail is built.
4919: In most cases no input as needed, as $env{'request.filename'}
4920: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4921:
4922: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4923: To be included on Authoring Space pages
1.822 bisitz 4924:
4925: =cut
4926:
4927: sub CSTR_pageheader {
1.1026 raeburn 4928: my ($trailfile) = @_;
4929: if ($trailfile eq '') {
4930: $trailfile = $env{'request.filename'};
4931: }
4932:
4933: # this is for resources; directories have customtitle, and crumbs
4934: # and select recent are created in lonpubdir.pm
4935:
4936: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4937: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4938: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4939: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4940: $formaction =~ s{/+}{/}g;
1.822 bisitz 4941:
4942: my $parentpath = '';
4943: my $lastitem = '';
4944: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4945: $parentpath = $1;
4946: $lastitem = $2;
4947: } else {
4948: $lastitem = $thisdisfn;
4949: }
1.921 bisitz 4950:
4951: my $output =
1.822 bisitz 4952: '<div>'
4953: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4954: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4955: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4956: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4957: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4958:
4959: if ($lastitem) {
4960: $output .=
4961: '<span class="LC_filename">'
4962: .$lastitem
4963: .'</span>';
4964: }
4965: $output .=
4966: '<br />'
1.822 bisitz 4967: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4968: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4969: .'</form>'
4970: .&Apache::lonmenu::constspaceform()
4971: .'</div>';
1.921 bisitz 4972:
4973: return $output;
1.822 bisitz 4974: }
4975:
1.60 matthew 4976: ###############################################
4977: ###############################################
4978:
4979: =pod
4980:
1.112 bowersj2 4981: =back
4982:
1.549 albertel 4983: =head1 HTML Helpers
1.112 bowersj2 4984:
4985: =over 4
4986:
4987: =item * &bodytag()
1.60 matthew 4988:
4989: Returns a uniform header for LON-CAPA web pages.
4990:
4991: Inputs:
4992:
1.112 bowersj2 4993: =over 4
4994:
4995: =item * $title, A title to be displayed on the page.
4996:
4997: =item * $function, the current role (can be undef).
4998:
4999: =item * $addentries, extra parameters for the <body> tag.
5000:
5001: =item * $bodyonly, if defined, only return the <body> tag.
5002:
5003: =item * $domain, if defined, force a given domain.
5004:
5005: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5006: text interface only)
1.60 matthew 5007:
1.814 bisitz 5008: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5009: navigational links
1.317 albertel 5010:
1.338 albertel 5011: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5012:
1.1075.2.12 raeburn 5013: =item * $no_inline_link, if true and in remote mode, don't show the
5014: 'Switch To Inline Menu' link
5015:
1.460 albertel 5016: =item * $args, optional argument valid values are
5017: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5018: inherit_jsmath -> when creating popup window in a page,
5019: should it have jsmath forced on by the
5020: current page
1.460 albertel 5021:
1.1075.2.15 raeburn 5022: =item * $advtoolsref, optional argument, ref to an array containing
5023: inlineremote items to be added in "Functions" menu below
5024: breadcrumbs.
5025:
1.112 bowersj2 5026: =back
5027:
1.60 matthew 5028: Returns: A uniform header for LON-CAPA web pages.
5029: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5030: If $bodyonly is undef or zero, an html string containing a <body> tag and
5031: other decorations will be returned.
5032:
5033: =cut
5034:
1.54 www 5035: sub bodytag {
1.831 bisitz 5036: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5037: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5038:
1.954 raeburn 5039: my $public;
5040: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5041: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5042: $public = 1;
5043: }
1.460 albertel 5044: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5045: my $httphost = $args->{'use_absolute'};
1.339 albertel 5046:
1.183 matthew 5047: $function = &get_users_function() if (!$function);
1.339 albertel 5048: my $img = &designparm($function.'.img',$domain);
5049: my $font = &designparm($function.'.font',$domain);
5050: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5051:
1.803 bisitz 5052: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5053: 'bgcolor' => $pgbg,
1.339 albertel 5054: 'text' => $font,
5055: 'alink' => &designparm($function.'.alink',$domain),
5056: 'vlink' => &designparm($function.'.vlink',$domain),
5057: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5058: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5059:
1.63 www 5060: # role and realm
1.378 raeburn 5061: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5062: if ($role eq 'ca') {
1.479 albertel 5063: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5064: $realm = &plainname($rname,$rdom);
1.378 raeburn 5065: }
1.55 www 5066: # realm
1.258 albertel 5067: if ($env{'request.course.id'}) {
1.378 raeburn 5068: if ($env{'request.role'} !~ /^cr/) {
5069: $role = &Apache::lonnet::plaintext($role,&course_type());
5070: }
1.898 raeburn 5071: if ($env{'request.course.sec'}) {
5072: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5073: }
1.359 albertel 5074: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5075: } else {
5076: $role = &Apache::lonnet::plaintext($role);
1.54 www 5077: }
1.433 albertel 5078:
1.359 albertel 5079: if (!$realm) { $realm=' '; }
1.330 albertel 5080:
1.438 albertel 5081: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5082:
1.101 www 5083: # construct main body tag
1.359 albertel 5084: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5085: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5086:
1.1075.2.38 raeburn 5087: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5088:
5089: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5090: return $bodytag;
1.1075.2.38 raeburn 5091: }
1.359 albertel 5092:
1.954 raeburn 5093: if ($public) {
1.433 albertel 5094: undef($role);
5095: }
1.359 albertel 5096:
1.762 bisitz 5097: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5098: #
5099: # Extra info if you are the DC
5100: my $dc_info = '';
5101: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5102: $env{'course.'.$env{'request.course.id'}.
5103: '.domain'}.'/'})) {
5104: my $cid = $env{'request.course.id'};
1.917 raeburn 5105: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5106: $dc_info =~ s/\s+$//;
1.359 albertel 5107: }
5108:
1.898 raeburn 5109: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5110:
1.1075.2.13 raeburn 5111: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5112:
1.1075.2.38 raeburn 5113:
5114:
1.1075.2.21 raeburn 5115: my $funclist;
5116: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5117: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5118: Apache::lonmenu::serverform();
5119: my $forbodytag;
5120: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5121: $forcereg,$args->{'group'},
5122: $args->{'bread_crumbs'},
5123: $advtoolsref,'',\$forbodytag);
5124: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5125: $funclist = $forbodytag;
5126: }
5127: } else {
1.903 droeschl 5128:
5129: # if ($env{'request.state'} eq 'construct') {
5130: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5131: # }
5132:
1.1075.2.38 raeburn 5133: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5134: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5135:
1.1075.2.38 raeburn 5136: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5137:
1.916 droeschl 5138: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5139: if ($dc_info) {
5140: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5141: }
1.1075.2.38 raeburn 5142: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5143: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5144: return $bodytag;
5145: }
1.894 droeschl 5146:
1.927 raeburn 5147: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5148: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5149: }
1.916 droeschl 5150:
1.1075.2.38 raeburn 5151: $bodytag .= $right;
1.852 droeschl 5152:
1.917 raeburn 5153: if ($dc_info) {
5154: $dc_info = &dc_courseid_toggle($dc_info);
5155: }
5156: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5157:
1.903 droeschl 5158: #don't show menus for public users
1.954 raeburn 5159: if (!$public){
1.1075.2.52 raeburn 5160: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5161: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5162: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5163: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5164: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5165: $args->{'bread_crumbs'});
5166: } elsif ($forcereg) {
1.1075.2.22 raeburn 5167: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5168: $args->{'group'});
1.1075.2.15 raeburn 5169: } else {
1.1075.2.21 raeburn 5170: my $forbodytag;
5171: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5172: $forcereg,$args->{'group'},
5173: $args->{'bread_crumbs'},
5174: $advtoolsref,'',\$forbodytag);
5175: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5176: $bodytag .= $forbodytag;
5177: }
1.920 raeburn 5178: }
1.903 droeschl 5179: }else{
5180: # this is to seperate menu from content when there's no secondary
5181: # menu. Especially needed for public accessible ressources.
5182: $bodytag .= '<hr style="clear:both" />';
5183: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5184: }
1.903 droeschl 5185:
1.235 raeburn 5186: return $bodytag;
1.1075.2.12 raeburn 5187: }
5188:
5189: #
5190: # Top frame rendering, Remote is up
5191: #
5192:
5193: my $imgsrc = $img;
5194: if ($img =~ /^\/adm/) {
5195: $imgsrc = &lonhttpdurl($img);
5196: }
5197: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5198:
5199: # Explicit link to get inline menu
5200: my $menu= ($no_inline_link?''
5201: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5202:
5203: if ($dc_info) {
5204: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5205: }
5206:
1.1075.2.38 raeburn 5207: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5208: unless ($public) {
5209: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5210: undef,'LC_menubuttons_link');
5211: }
5212:
1.1075.2.12 raeburn 5213: unless ($env{'form.inhibitmenu'}) {
5214: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5215: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.12 raeburn 5216: <li>$menu</li>
5217: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5218: }
1.1075.2.13 raeburn 5219: if ($env{'request.state'} eq 'construct') {
5220: if (!$public){
5221: if ($env{'request.state'} eq 'construct') {
5222: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5223: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5224: &Apache::lonhtmlcommon::scripttag('','end').
5225: &Apache::lonmenu::innerregister($forcereg,
5226: $args->{'bread_crumbs'});
5227: }
5228: }
5229: }
1.1075.2.21 raeburn 5230: return $bodytag."\n".$funclist;
1.182 matthew 5231: }
5232:
1.917 raeburn 5233: sub dc_courseid_toggle {
5234: my ($dc_info) = @_;
1.980 raeburn 5235: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5236: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5237: &mt('(More ...)').'</a></span>'.
5238: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5239: }
5240:
1.330 albertel 5241: sub make_attr_string {
5242: my ($register,$attr_ref) = @_;
5243:
5244: if ($attr_ref && !ref($attr_ref)) {
5245: die("addentries Must be a hash ref ".
5246: join(':',caller(1))." ".
5247: join(':',caller(0))." ");
5248: }
5249:
5250: if ($register) {
1.339 albertel 5251: my ($on_load,$on_unload);
5252: foreach my $key (keys(%{$attr_ref})) {
5253: if (lc($key) eq 'onload') {
5254: $on_load.=$attr_ref->{$key}.';';
5255: delete($attr_ref->{$key});
5256:
5257: } elsif (lc($key) eq 'onunload') {
5258: $on_unload.=$attr_ref->{$key}.';';
5259: delete($attr_ref->{$key});
5260: }
5261: }
1.1075.2.12 raeburn 5262: if ($env{'environment.remote'} eq 'on') {
5263: $attr_ref->{'onload'} =
5264: &Apache::lonmenu::loadevents(). $on_load;
5265: $attr_ref->{'onunload'}=
5266: &Apache::lonmenu::unloadevents().$on_unload;
5267: } else {
5268: $attr_ref->{'onload'} = $on_load;
5269: $attr_ref->{'onunload'}= $on_unload;
5270: }
1.330 albertel 5271: }
1.339 albertel 5272:
1.330 albertel 5273: my $attr_string;
1.1075.2.56 raeburn 5274: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5275: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5276: }
5277: return $attr_string;
5278: }
5279:
5280:
1.182 matthew 5281: ###############################################
1.251 albertel 5282: ###############################################
5283:
5284: =pod
5285:
5286: =item * &endbodytag()
5287:
5288: Returns a uniform footer for LON-CAPA web pages.
5289:
1.635 raeburn 5290: Inputs: 1 - optional reference to an args hash
5291: If in the hash, key for noredirectlink has a value which evaluates to true,
5292: a 'Continue' link is not displayed if the page contains an
5293: internal redirect in the <head></head> section,
5294: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5295:
5296: =cut
5297:
5298: sub endbodytag {
1.635 raeburn 5299: my ($args) = @_;
1.1075.2.6 raeburn 5300: my $endbodytag;
5301: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5302: $endbodytag='</body>';
5303: }
1.269 albertel 5304: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5305: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5306: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5307: $endbodytag=
5308: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5309: &mt('Continue').'</a>'.
5310: $endbodytag;
5311: }
1.315 albertel 5312: }
1.251 albertel 5313: return $endbodytag;
5314: }
5315:
1.352 albertel 5316: =pod
5317:
5318: =item * &standard_css()
5319:
5320: Returns a style sheet
5321:
5322: Inputs: (all optional)
5323: domain -> force to color decorate a page for a specific
5324: domain
5325: function -> force usage of a specific rolish color scheme
5326: bgcolor -> override the default page bgcolor
5327:
5328: =cut
5329:
1.343 albertel 5330: sub standard_css {
1.345 albertel 5331: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5332: $function = &get_users_function() if (!$function);
5333: my $img = &designparm($function.'.img', $domain);
5334: my $tabbg = &designparm($function.'.tabbg', $domain);
5335: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5336: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5337: #second colour for later usage
1.345 albertel 5338: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5339: my $pgbg_or_bgcolor =
5340: $bgcolor ||
1.352 albertel 5341: &designparm($function.'.pgbg', $domain);
1.382 albertel 5342: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5343: my $alink = &designparm($function.'.alink', $domain);
5344: my $vlink = &designparm($function.'.vlink', $domain);
5345: my $link = &designparm($function.'.link', $domain);
5346:
1.602 albertel 5347: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5348: my $mono = 'monospace';
1.850 bisitz 5349: my $data_table_head = $sidebg;
5350: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5351: my $data_table_dark = '#E0E0E0';
1.470 banghart 5352: my $data_table_darker = '#CCCCCC';
1.349 albertel 5353: my $data_table_highlight = '#FFFF00';
1.352 albertel 5354: my $mail_new = '#FFBB77';
5355: my $mail_new_hover = '#DD9955';
5356: my $mail_read = '#BBBB77';
5357: my $mail_read_hover = '#999944';
5358: my $mail_replied = '#AAAA88';
5359: my $mail_replied_hover = '#888855';
5360: my $mail_other = '#99BBBB';
5361: my $mail_other_hover = '#669999';
1.391 albertel 5362: my $table_header = '#DDDDDD';
1.489 raeburn 5363: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5364: my $lg_border_color = '#C8C8C8';
1.952 onken 5365: my $button_hover = '#BF2317';
1.392 albertel 5366:
1.608 albertel 5367: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5368: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5369: : '0 3px 0 4px';
1.448 albertel 5370:
1.523 albertel 5371:
1.343 albertel 5372: return <<END;
1.947 droeschl 5373:
5374: /* needed for iframe to allow 100% height in FF */
5375: body, html {
5376: margin: 0;
5377: padding: 0 0.5%;
5378: height: 99%; /* to avoid scrollbars */
5379: }
5380:
1.795 www 5381: body {
1.911 bisitz 5382: font-family: $sans;
5383: line-height:130%;
5384: font-size:0.83em;
5385: color:$font;
1.795 www 5386: }
5387:
1.959 onken 5388: a:focus,
5389: a:focus img {
1.795 www 5390: color: red;
5391: }
1.698 harmsja 5392:
1.911 bisitz 5393: form, .inline {
5394: display: inline;
1.795 www 5395: }
1.721 harmsja 5396:
1.795 www 5397: .LC_right {
1.911 bisitz 5398: text-align:right;
1.795 www 5399: }
5400:
5401: .LC_middle {
1.911 bisitz 5402: vertical-align:middle;
1.795 www 5403: }
1.721 harmsja 5404:
1.1075.2.38 raeburn 5405: .LC_floatleft {
5406: float: left;
5407: }
5408:
5409: .LC_floatright {
5410: float: right;
5411: }
5412:
1.911 bisitz 5413: .LC_400Box {
5414: width:400px;
5415: }
1.721 harmsja 5416:
1.947 droeschl 5417: .LC_iframecontainer {
5418: width: 98%;
5419: margin: 0;
5420: position: fixed;
5421: top: 8.5em;
5422: bottom: 0;
5423: }
5424:
5425: .LC_iframecontainer iframe{
5426: border: none;
5427: width: 100%;
5428: height: 100%;
5429: }
5430:
1.778 bisitz 5431: .LC_filename {
5432: font-family: $mono;
5433: white-space:pre;
1.921 bisitz 5434: font-size: 120%;
1.778 bisitz 5435: }
5436:
5437: .LC_fileicon {
5438: border: none;
5439: height: 1.3em;
5440: vertical-align: text-bottom;
5441: margin-right: 0.3em;
5442: text-decoration:none;
5443: }
5444:
1.1008 www 5445: .LC_setting {
5446: text-decoration:underline;
5447: }
5448:
1.350 albertel 5449: .LC_error {
5450: color: red;
5451: }
1.795 www 5452:
1.1075.2.15 raeburn 5453: .LC_warning {
5454: color: darkorange;
5455: }
5456:
1.457 albertel 5457: .LC_diff_removed {
1.733 bisitz 5458: color: red;
1.394 albertel 5459: }
1.532 albertel 5460:
5461: .LC_info,
1.457 albertel 5462: .LC_success,
5463: .LC_diff_added {
1.350 albertel 5464: color: green;
5465: }
1.795 www 5466:
1.802 bisitz 5467: div.LC_confirm_box {
5468: background-color: #FAFAFA;
5469: border: 1px solid $lg_border_color;
5470: margin-right: 0;
5471: padding: 5px;
5472: }
5473:
5474: div.LC_confirm_box .LC_error img,
5475: div.LC_confirm_box .LC_success img {
5476: vertical-align: middle;
5477: }
5478:
1.440 albertel 5479: .LC_icon {
1.771 droeschl 5480: border: none;
1.790 droeschl 5481: vertical-align: middle;
1.771 droeschl 5482: }
5483:
1.543 albertel 5484: .LC_docs_spacer {
5485: width: 25px;
5486: height: 1px;
1.771 droeschl 5487: border: none;
1.543 albertel 5488: }
1.346 albertel 5489:
1.532 albertel 5490: .LC_internal_info {
1.735 bisitz 5491: color: #999999;
1.532 albertel 5492: }
5493:
1.794 www 5494: .LC_discussion {
1.1050 www 5495: background: $data_table_dark;
1.911 bisitz 5496: border: 1px solid black;
5497: margin: 2px;
1.794 www 5498: }
5499:
5500: .LC_disc_action_left {
1.1050 www 5501: background: $sidebg;
1.911 bisitz 5502: text-align: left;
1.1050 www 5503: padding: 4px;
5504: margin: 2px;
1.794 www 5505: }
5506:
5507: .LC_disc_action_right {
1.1050 www 5508: background: $sidebg;
1.911 bisitz 5509: text-align: right;
1.1050 www 5510: padding: 4px;
5511: margin: 2px;
1.794 www 5512: }
5513:
5514: .LC_disc_new_item {
1.911 bisitz 5515: background: white;
5516: border: 2px solid red;
1.1050 www 5517: margin: 4px;
5518: padding: 4px;
1.794 www 5519: }
5520:
5521: .LC_disc_old_item {
1.911 bisitz 5522: background: white;
1.1050 www 5523: margin: 4px;
5524: padding: 4px;
1.794 www 5525: }
5526:
1.458 albertel 5527: table.LC_pastsubmission {
5528: border: 1px solid black;
5529: margin: 2px;
5530: }
5531:
1.924 bisitz 5532: table#LC_menubuttons {
1.345 albertel 5533: width: 100%;
5534: background: $pgbg;
1.392 albertel 5535: border: 2px;
1.402 albertel 5536: border-collapse: separate;
1.803 bisitz 5537: padding: 0;
1.345 albertel 5538: }
1.392 albertel 5539:
1.801 tempelho 5540: table#LC_title_bar a {
5541: color: $fontmenu;
5542: }
1.836 bisitz 5543:
1.807 droeschl 5544: table#LC_title_bar {
1.819 tempelho 5545: clear: both;
1.836 bisitz 5546: display: none;
1.807 droeschl 5547: }
5548:
1.795 www 5549: table#LC_title_bar,
1.933 droeschl 5550: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5551: table#LC_title_bar.LC_with_remote {
1.359 albertel 5552: width: 100%;
1.392 albertel 5553: border-color: $pgbg;
5554: border-style: solid;
5555: border-width: $border;
1.379 albertel 5556: background: $pgbg;
1.801 tempelho 5557: color: $fontmenu;
1.392 albertel 5558: border-collapse: collapse;
1.803 bisitz 5559: padding: 0;
1.819 tempelho 5560: margin: 0;
1.359 albertel 5561: }
1.795 www 5562:
1.933 droeschl 5563: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5564: margin: 0;
5565: padding: 0;
1.933 droeschl 5566: position: relative;
5567: list-style: none;
1.913 droeschl 5568: }
1.933 droeschl 5569: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5570: display: inline;
5571: }
1.933 droeschl 5572:
5573: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5574: padding: 0;
1.933 droeschl 5575: margin: 0;
5576: float: left;
1.913 droeschl 5577: }
1.933 droeschl 5578: .LC_breadcrumb_tools_tools {
5579: padding: 0;
5580: margin: 0;
1.913 droeschl 5581: float: right;
5582: }
5583:
1.359 albertel 5584: table#LC_title_bar td {
5585: background: $tabbg;
5586: }
1.795 www 5587:
1.911 bisitz 5588: table#LC_menubuttons img {
1.803 bisitz 5589: border: none;
1.346 albertel 5590: }
1.795 www 5591:
1.842 droeschl 5592: .LC_breadcrumbs_component {
1.911 bisitz 5593: float: right;
5594: margin: 0 1em;
1.357 albertel 5595: }
1.842 droeschl 5596: .LC_breadcrumbs_component img {
1.911 bisitz 5597: vertical-align: middle;
1.777 tempelho 5598: }
1.795 www 5599:
1.383 albertel 5600: td.LC_table_cell_checkbox {
5601: text-align: center;
5602: }
1.795 www 5603:
5604: .LC_fontsize_small {
1.911 bisitz 5605: font-size: 70%;
1.705 tempelho 5606: }
5607:
1.844 bisitz 5608: #LC_breadcrumbs {
1.911 bisitz 5609: clear:both;
5610: background: $sidebg;
5611: border-bottom: 1px solid $lg_border_color;
5612: line-height: 2.5em;
1.933 droeschl 5613: overflow: hidden;
1.911 bisitz 5614: margin: 0;
5615: padding: 0;
1.995 raeburn 5616: text-align: left;
1.819 tempelho 5617: }
1.862 bisitz 5618:
1.1075.2.16 raeburn 5619: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5620: clear:both;
5621: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5622: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5623: margin: 0 0 10px 0;
1.966 bisitz 5624: padding: 3px;
1.995 raeburn 5625: text-align: left;
1.822 bisitz 5626: }
5627:
1.795 www 5628: .LC_fontsize_medium {
1.911 bisitz 5629: font-size: 85%;
1.705 tempelho 5630: }
5631:
1.795 www 5632: .LC_fontsize_large {
1.911 bisitz 5633: font-size: 120%;
1.705 tempelho 5634: }
5635:
1.346 albertel 5636: .LC_menubuttons_inline_text {
5637: color: $font;
1.698 harmsja 5638: font-size: 90%;
1.701 harmsja 5639: padding-left:3px;
1.346 albertel 5640: }
5641:
1.934 droeschl 5642: .LC_menubuttons_inline_text img{
5643: vertical-align: middle;
5644: }
5645:
1.1051 www 5646: li.LC_menubuttons_inline_text img {
1.951 onken 5647: cursor:pointer;
1.1002 droeschl 5648: text-decoration: none;
1.951 onken 5649: }
5650:
1.526 www 5651: .LC_menubuttons_link {
5652: text-decoration: none;
5653: }
1.795 www 5654:
1.522 albertel 5655: .LC_menubuttons_category {
1.521 www 5656: color: $font;
1.526 www 5657: background: $pgbg;
1.521 www 5658: font-size: larger;
5659: font-weight: bold;
5660: }
5661:
1.346 albertel 5662: td.LC_menubuttons_text {
1.911 bisitz 5663: color: $font;
1.346 albertel 5664: }
1.706 harmsja 5665:
1.346 albertel 5666: .LC_current_location {
5667: background: $tabbg;
5668: }
1.795 www 5669:
1.938 bisitz 5670: table.LC_data_table {
1.347 albertel 5671: border: 1px solid #000000;
1.402 albertel 5672: border-collapse: separate;
1.426 albertel 5673: border-spacing: 1px;
1.610 albertel 5674: background: $pgbg;
1.347 albertel 5675: }
1.795 www 5676:
1.422 albertel 5677: .LC_data_table_dense {
5678: font-size: small;
5679: }
1.795 www 5680:
1.507 raeburn 5681: table.LC_nested_outer {
5682: border: 1px solid #000000;
1.589 raeburn 5683: border-collapse: collapse;
1.803 bisitz 5684: border-spacing: 0;
1.507 raeburn 5685: width: 100%;
5686: }
1.795 www 5687:
1.879 raeburn 5688: table.LC_innerpickbox,
1.507 raeburn 5689: table.LC_nested {
1.803 bisitz 5690: border: none;
1.589 raeburn 5691: border-collapse: collapse;
1.803 bisitz 5692: border-spacing: 0;
1.507 raeburn 5693: width: 100%;
5694: }
1.795 www 5695:
1.911 bisitz 5696: table.LC_data_table tr th,
5697: table.LC_calendar tr th,
1.879 raeburn 5698: table.LC_prior_tries tr th,
5699: table.LC_innerpickbox tr th {
1.349 albertel 5700: font-weight: bold;
5701: background-color: $data_table_head;
1.801 tempelho 5702: color:$fontmenu;
1.701 harmsja 5703: font-size:90%;
1.347 albertel 5704: }
1.795 www 5705:
1.879 raeburn 5706: table.LC_innerpickbox tr th,
5707: table.LC_innerpickbox tr td {
5708: vertical-align: top;
5709: }
5710:
1.711 raeburn 5711: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5712: background-color: #CCCCCC;
1.711 raeburn 5713: font-weight: bold;
5714: text-align: left;
5715: }
1.795 www 5716:
1.912 bisitz 5717: table.LC_data_table tr.LC_odd_row > td {
5718: background-color: $data_table_light;
5719: padding: 2px;
5720: vertical-align: top;
5721: }
5722:
1.809 bisitz 5723: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5724: background-color: $data_table_light;
1.912 bisitz 5725: vertical-align: top;
5726: }
5727:
5728: table.LC_data_table tr.LC_even_row > td {
5729: background-color: $data_table_dark;
1.425 albertel 5730: padding: 2px;
1.900 bisitz 5731: vertical-align: top;
1.347 albertel 5732: }
1.795 www 5733:
1.809 bisitz 5734: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5735: background-color: $data_table_dark;
1.900 bisitz 5736: vertical-align: top;
1.347 albertel 5737: }
1.795 www 5738:
1.425 albertel 5739: table.LC_data_table tr.LC_data_table_highlight td {
5740: background-color: $data_table_darker;
5741: }
1.795 www 5742:
1.639 raeburn 5743: table.LC_data_table tr td.LC_leftcol_header {
5744: background-color: $data_table_head;
5745: font-weight: bold;
5746: }
1.795 www 5747:
1.451 albertel 5748: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5749: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5750: font-weight: bold;
5751: font-style: italic;
5752: text-align: center;
5753: padding: 8px;
1.347 albertel 5754: }
1.795 www 5755:
1.1075.2.30 raeburn 5756: table.LC_data_table tr.LC_empty_row td,
5757: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5758: background-color: $sidebg;
5759: }
5760:
5761: table.LC_nested tr.LC_empty_row td {
5762: background-color: #FFFFFF;
5763: }
5764:
1.890 droeschl 5765: table.LC_caption {
5766: }
5767:
1.507 raeburn 5768: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5769: padding: 4ex
5770: }
1.795 www 5771:
1.507 raeburn 5772: table.LC_nested_outer tr th {
5773: font-weight: bold;
1.801 tempelho 5774: color:$fontmenu;
1.507 raeburn 5775: background-color: $data_table_head;
1.701 harmsja 5776: font-size: small;
1.507 raeburn 5777: border-bottom: 1px solid #000000;
5778: }
1.795 www 5779:
1.507 raeburn 5780: table.LC_nested_outer tr td.LC_subheader {
5781: background-color: $data_table_head;
5782: font-weight: bold;
5783: font-size: small;
5784: border-bottom: 1px solid #000000;
5785: text-align: right;
1.451 albertel 5786: }
1.795 www 5787:
1.507 raeburn 5788: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5789: background-color: #CCCCCC;
1.451 albertel 5790: font-weight: bold;
5791: font-size: small;
1.507 raeburn 5792: text-align: center;
5793: }
1.795 www 5794:
1.589 raeburn 5795: table.LC_nested tr.LC_info_row td.LC_left_item,
5796: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5797: text-align: left;
1.451 albertel 5798: }
1.795 www 5799:
1.507 raeburn 5800: table.LC_nested td {
1.735 bisitz 5801: background-color: #FFFFFF;
1.451 albertel 5802: font-size: small;
1.507 raeburn 5803: }
1.795 www 5804:
1.507 raeburn 5805: table.LC_nested_outer tr th.LC_right_item,
5806: table.LC_nested tr.LC_info_row td.LC_right_item,
5807: table.LC_nested tr.LC_odd_row td.LC_right_item,
5808: table.LC_nested tr td.LC_right_item {
1.451 albertel 5809: text-align: right;
5810: }
5811:
1.507 raeburn 5812: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5813: background-color: #EEEEEE;
1.451 albertel 5814: }
5815:
1.473 raeburn 5816: table.LC_createuser {
5817: }
5818:
5819: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5820: font-size: small;
1.473 raeburn 5821: }
5822:
5823: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5824: background-color: #CCCCCC;
1.473 raeburn 5825: font-weight: bold;
5826: text-align: center;
5827: }
5828:
1.349 albertel 5829: table.LC_calendar {
5830: border: 1px solid #000000;
5831: border-collapse: collapse;
1.917 raeburn 5832: width: 98%;
1.349 albertel 5833: }
1.795 www 5834:
1.349 albertel 5835: table.LC_calendar_pickdate {
5836: font-size: xx-small;
5837: }
1.795 www 5838:
1.349 albertel 5839: table.LC_calendar tr td {
5840: border: 1px solid #000000;
5841: vertical-align: top;
1.917 raeburn 5842: width: 14%;
1.349 albertel 5843: }
1.795 www 5844:
1.349 albertel 5845: table.LC_calendar tr td.LC_calendar_day_empty {
5846: background-color: $data_table_dark;
5847: }
1.795 www 5848:
1.779 bisitz 5849: table.LC_calendar tr td.LC_calendar_day_current {
5850: background-color: $data_table_highlight;
1.777 tempelho 5851: }
1.795 www 5852:
1.938 bisitz 5853: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5854: background-color: $mail_new;
5855: }
1.795 www 5856:
1.938 bisitz 5857: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5858: background-color: $mail_new_hover;
5859: }
1.795 www 5860:
1.938 bisitz 5861: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5862: background-color: $mail_read;
5863: }
1.795 www 5864:
1.938 bisitz 5865: /*
5866: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5867: background-color: $mail_read_hover;
5868: }
1.938 bisitz 5869: */
1.795 www 5870:
1.938 bisitz 5871: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5872: background-color: $mail_replied;
5873: }
1.795 www 5874:
1.938 bisitz 5875: /*
5876: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5877: background-color: $mail_replied_hover;
5878: }
1.938 bisitz 5879: */
1.795 www 5880:
1.938 bisitz 5881: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5882: background-color: $mail_other;
5883: }
1.795 www 5884:
1.938 bisitz 5885: /*
5886: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5887: background-color: $mail_other_hover;
5888: }
1.938 bisitz 5889: */
1.494 raeburn 5890:
1.777 tempelho 5891: table.LC_data_table tr > td.LC_browser_file,
5892: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5893: background: #AAEE77;
1.389 albertel 5894: }
1.795 www 5895:
1.777 tempelho 5896: table.LC_data_table tr > td.LC_browser_file_locked,
5897: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5898: background: #FFAA99;
1.387 albertel 5899: }
1.795 www 5900:
1.777 tempelho 5901: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5902: background: #888888;
1.779 bisitz 5903: }
1.795 www 5904:
1.777 tempelho 5905: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5906: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5907: background: #F8F866;
1.777 tempelho 5908: }
1.795 www 5909:
1.696 bisitz 5910: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5911: background: #E0E8FF;
1.387 albertel 5912: }
1.696 bisitz 5913:
1.707 bisitz 5914: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5915: /* background: #77FF77; */
1.707 bisitz 5916: }
1.795 www 5917:
1.707 bisitz 5918: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5919: border-right: 8px solid #FFFF77;
1.707 bisitz 5920: }
1.795 www 5921:
1.707 bisitz 5922: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5923: border-right: 8px solid #FFAA77;
1.707 bisitz 5924: }
1.795 www 5925:
1.707 bisitz 5926: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5927: border-right: 8px solid #FF7777;
1.707 bisitz 5928: }
1.795 www 5929:
1.707 bisitz 5930: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5931: border-right: 8px solid #AAFF77;
1.707 bisitz 5932: }
1.795 www 5933:
1.707 bisitz 5934: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5935: border-right: 8px solid #11CC55;
1.707 bisitz 5936: }
5937:
1.388 albertel 5938: span.LC_current_location {
1.701 harmsja 5939: font-size:larger;
1.388 albertel 5940: background: $pgbg;
5941: }
1.387 albertel 5942:
1.1029 www 5943: span.LC_current_nav_location {
5944: font-weight:bold;
5945: background: $sidebg;
5946: }
5947:
1.395 albertel 5948: span.LC_parm_menu_item {
5949: font-size: larger;
5950: }
1.795 www 5951:
1.395 albertel 5952: span.LC_parm_scope_all {
5953: color: red;
5954: }
1.795 www 5955:
1.395 albertel 5956: span.LC_parm_scope_folder {
5957: color: green;
5958: }
1.795 www 5959:
1.395 albertel 5960: span.LC_parm_scope_resource {
5961: color: orange;
5962: }
1.795 www 5963:
1.395 albertel 5964: span.LC_parm_part {
5965: color: blue;
5966: }
1.795 www 5967:
1.911 bisitz 5968: span.LC_parm_folder,
5969: span.LC_parm_symb {
1.395 albertel 5970: font-size: x-small;
5971: font-family: $mono;
5972: color: #AAAAAA;
5973: }
5974:
1.977 bisitz 5975: ul.LC_parm_parmlist li {
5976: display: inline-block;
5977: padding: 0.3em 0.8em;
5978: vertical-align: top;
5979: width: 150px;
5980: border-top:1px solid $lg_border_color;
5981: }
5982:
1.795 www 5983: td.LC_parm_overview_level_menu,
5984: td.LC_parm_overview_map_menu,
5985: td.LC_parm_overview_parm_selectors,
5986: td.LC_parm_overview_restrictions {
1.396 albertel 5987: border: 1px solid black;
5988: border-collapse: collapse;
5989: }
1.795 www 5990:
1.396 albertel 5991: table.LC_parm_overview_restrictions td {
5992: border-width: 1px 4px 1px 4px;
5993: border-style: solid;
5994: border-color: $pgbg;
5995: text-align: center;
5996: }
1.795 www 5997:
1.396 albertel 5998: table.LC_parm_overview_restrictions th {
5999: background: $tabbg;
6000: border-width: 1px 4px 1px 4px;
6001: border-style: solid;
6002: border-color: $pgbg;
6003: }
1.795 www 6004:
1.398 albertel 6005: table#LC_helpmenu {
1.803 bisitz 6006: border: none;
1.398 albertel 6007: height: 55px;
1.803 bisitz 6008: border-spacing: 0;
1.398 albertel 6009: }
6010:
6011: table#LC_helpmenu fieldset legend {
6012: font-size: larger;
6013: }
1.795 www 6014:
1.397 albertel 6015: table#LC_helpmenu_links {
6016: width: 100%;
6017: border: 1px solid black;
6018: background: $pgbg;
1.803 bisitz 6019: padding: 0;
1.397 albertel 6020: border-spacing: 1px;
6021: }
1.795 www 6022:
1.397 albertel 6023: table#LC_helpmenu_links tr td {
6024: padding: 1px;
6025: background: $tabbg;
1.399 albertel 6026: text-align: center;
6027: font-weight: bold;
1.397 albertel 6028: }
1.396 albertel 6029:
1.795 www 6030: table#LC_helpmenu_links a:link,
6031: table#LC_helpmenu_links a:visited,
1.397 albertel 6032: table#LC_helpmenu_links a:active {
6033: text-decoration: none;
6034: color: $font;
6035: }
1.795 www 6036:
1.397 albertel 6037: table#LC_helpmenu_links a:hover {
6038: text-decoration: underline;
6039: color: $vlink;
6040: }
1.396 albertel 6041:
1.417 albertel 6042: .LC_chrt_popup_exists {
6043: border: 1px solid #339933;
6044: margin: -1px;
6045: }
1.795 www 6046:
1.417 albertel 6047: .LC_chrt_popup_up {
6048: border: 1px solid yellow;
6049: margin: -1px;
6050: }
1.795 www 6051:
1.417 albertel 6052: .LC_chrt_popup {
6053: border: 1px solid #8888FF;
6054: background: #CCCCFF;
6055: }
1.795 www 6056:
1.421 albertel 6057: table.LC_pick_box {
6058: border-collapse: separate;
6059: background: white;
6060: border: 1px solid black;
6061: border-spacing: 1px;
6062: }
1.795 www 6063:
1.421 albertel 6064: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6065: background: $sidebg;
1.421 albertel 6066: font-weight: bold;
1.900 bisitz 6067: text-align: left;
1.740 bisitz 6068: vertical-align: top;
1.421 albertel 6069: width: 184px;
6070: padding: 8px;
6071: }
1.795 www 6072:
1.579 raeburn 6073: table.LC_pick_box td.LC_pick_box_value {
6074: text-align: left;
6075: padding: 8px;
6076: }
1.795 www 6077:
1.579 raeburn 6078: table.LC_pick_box td.LC_pick_box_select {
6079: text-align: left;
6080: padding: 8px;
6081: }
1.795 www 6082:
1.424 albertel 6083: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6084: padding: 0;
1.421 albertel 6085: height: 1px;
6086: background: black;
6087: }
1.795 www 6088:
1.421 albertel 6089: table.LC_pick_box td.LC_pick_box_submit {
6090: text-align: right;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_evenrow_value {
6094: text-align: left;
6095: padding: 8px;
6096: background-color: $data_table_light;
6097: }
1.795 www 6098:
1.579 raeburn 6099: table.LC_pick_box td.LC_oddrow_value {
6100: text-align: left;
6101: padding: 8px;
6102: background-color: $data_table_light;
6103: }
1.795 www 6104:
1.579 raeburn 6105: span.LC_helpform_receipt_cat {
6106: font-weight: bold;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv_box {
6110: background: white;
6111: border: 1px solid black;
6112: border-spacing: 1px;
6113: }
1.795 www 6114:
1.424 albertel 6115: table.LC_group_priv_box td.LC_pick_box_title {
6116: background: $tabbg;
6117: font-weight: bold;
6118: text-align: right;
6119: width: 184px;
6120: }
1.795 www 6121:
1.424 albertel 6122: table.LC_group_priv_box td.LC_groups_fixed {
6123: background: $data_table_light;
6124: text-align: center;
6125: }
1.795 www 6126:
1.424 albertel 6127: table.LC_group_priv_box td.LC_groups_optional {
6128: background: $data_table_dark;
6129: text-align: center;
6130: }
1.795 www 6131:
1.424 albertel 6132: table.LC_group_priv_box td.LC_groups_functionality {
6133: background: $data_table_darker;
6134: text-align: center;
6135: font-weight: bold;
6136: }
1.795 www 6137:
1.424 albertel 6138: table.LC_group_priv td {
6139: text-align: left;
1.803 bisitz 6140: padding: 0;
1.424 albertel 6141: }
6142:
6143: .LC_navbuttons {
6144: margin: 2ex 0ex 2ex 0ex;
6145: }
1.795 www 6146:
1.423 albertel 6147: .LC_topic_bar {
6148: font-weight: bold;
6149: background: $tabbg;
1.918 wenzelju 6150: margin: 1em 0em 1em 2em;
1.805 bisitz 6151: padding: 3px;
1.918 wenzelju 6152: font-size: 1.2em;
1.423 albertel 6153: }
1.795 www 6154:
1.423 albertel 6155: .LC_topic_bar span {
1.918 wenzelju 6156: left: 0.5em;
6157: position: absolute;
1.423 albertel 6158: vertical-align: middle;
1.918 wenzelju 6159: font-size: 1.2em;
1.423 albertel 6160: }
1.795 www 6161:
1.423 albertel 6162: table.LC_course_group_status {
6163: margin: 20px;
6164: }
1.795 www 6165:
1.423 albertel 6166: table.LC_status_selector td {
6167: vertical-align: top;
6168: text-align: center;
1.424 albertel 6169: padding: 4px;
6170: }
1.795 www 6171:
1.599 albertel 6172: div.LC_feedback_link {
1.616 albertel 6173: clear: both;
1.829 kalberla 6174: background: $sidebg;
1.779 bisitz 6175: width: 100%;
1.829 kalberla 6176: padding-bottom: 10px;
6177: border: 1px $tabbg solid;
1.833 kalberla 6178: height: 22px;
6179: line-height: 22px;
6180: padding-top: 5px;
6181: }
6182:
6183: div.LC_feedback_link img {
6184: height: 22px;
1.867 kalberla 6185: vertical-align:middle;
1.829 kalberla 6186: }
6187:
1.911 bisitz 6188: div.LC_feedback_link a {
1.829 kalberla 6189: text-decoration: none;
1.489 raeburn 6190: }
1.795 www 6191:
1.867 kalberla 6192: div.LC_comblock {
1.911 bisitz 6193: display:inline;
1.867 kalberla 6194: color:$font;
6195: font-size:90%;
6196: }
6197:
6198: div.LC_feedback_link div.LC_comblock {
6199: padding-left:5px;
6200: }
6201:
6202: div.LC_feedback_link div.LC_comblock a {
6203: color:$font;
6204: }
6205:
1.489 raeburn 6206: span.LC_feedback_link {
1.858 bisitz 6207: /* background: $feedback_link_bg; */
1.599 albertel 6208: font-size: larger;
6209: }
1.795 www 6210:
1.599 albertel 6211: span.LC_message_link {
1.858 bisitz 6212: /* background: $feedback_link_bg; */
1.599 albertel 6213: font-size: larger;
6214: position: absolute;
6215: right: 1em;
1.489 raeburn 6216: }
1.421 albertel 6217:
1.515 albertel 6218: table.LC_prior_tries {
1.524 albertel 6219: border: 1px solid #000000;
6220: border-collapse: separate;
6221: border-spacing: 1px;
1.515 albertel 6222: }
1.523 albertel 6223:
1.515 albertel 6224: table.LC_prior_tries td {
1.524 albertel 6225: padding: 2px;
1.515 albertel 6226: }
1.523 albertel 6227:
6228: .LC_answer_correct {
1.795 www 6229: background: lightgreen;
6230: color: darkgreen;
6231: padding: 6px;
1.523 albertel 6232: }
1.795 www 6233:
1.523 albertel 6234: .LC_answer_charged_try {
1.797 www 6235: background: #FFAAAA;
1.795 www 6236: color: darkred;
6237: padding: 6px;
1.523 albertel 6238: }
1.795 www 6239:
1.779 bisitz 6240: .LC_answer_not_charged_try,
1.523 albertel 6241: .LC_answer_no_grade,
6242: .LC_answer_late {
1.795 www 6243: background: lightyellow;
1.523 albertel 6244: color: black;
1.795 www 6245: padding: 6px;
1.523 albertel 6246: }
1.795 www 6247:
1.523 albertel 6248: .LC_answer_previous {
1.795 www 6249: background: lightblue;
6250: color: darkblue;
6251: padding: 6px;
1.523 albertel 6252: }
1.795 www 6253:
1.779 bisitz 6254: .LC_answer_no_message {
1.777 tempelho 6255: background: #FFFFFF;
6256: color: black;
1.795 www 6257: padding: 6px;
1.779 bisitz 6258: }
1.795 www 6259:
1.779 bisitz 6260: .LC_answer_unknown {
6261: background: orange;
6262: color: black;
1.795 www 6263: padding: 6px;
1.777 tempelho 6264: }
1.795 www 6265:
1.529 albertel 6266: span.LC_prior_numerical,
6267: span.LC_prior_string,
6268: span.LC_prior_custom,
6269: span.LC_prior_reaction,
6270: span.LC_prior_math {
1.925 bisitz 6271: font-family: $mono;
1.523 albertel 6272: white-space: pre;
6273: }
6274:
1.525 albertel 6275: span.LC_prior_string {
1.925 bisitz 6276: font-family: $mono;
1.525 albertel 6277: white-space: pre;
6278: }
6279:
1.523 albertel 6280: table.LC_prior_option {
6281: width: 100%;
6282: border-collapse: collapse;
6283: }
1.795 www 6284:
1.911 bisitz 6285: table.LC_prior_rank,
1.795 www 6286: table.LC_prior_match {
1.528 albertel 6287: border-collapse: collapse;
6288: }
1.795 www 6289:
1.528 albertel 6290: table.LC_prior_option tr td,
6291: table.LC_prior_rank tr td,
6292: table.LC_prior_match tr td {
1.524 albertel 6293: border: 1px solid #000000;
1.515 albertel 6294: }
6295:
1.855 bisitz 6296: .LC_nobreak {
1.544 albertel 6297: white-space: nowrap;
1.519 raeburn 6298: }
6299:
1.576 raeburn 6300: span.LC_cusr_emph {
6301: font-style: italic;
6302: }
6303:
1.633 raeburn 6304: span.LC_cusr_subheading {
6305: font-weight: normal;
6306: font-size: 85%;
6307: }
6308:
1.861 bisitz 6309: div.LC_docs_entry_move {
1.859 bisitz 6310: border: 1px solid #BBBBBB;
1.545 albertel 6311: background: #DDDDDD;
1.861 bisitz 6312: width: 22px;
1.859 bisitz 6313: padding: 1px;
6314: margin: 0;
1.545 albertel 6315: }
6316:
1.861 bisitz 6317: table.LC_data_table tr > td.LC_docs_entry_commands,
6318: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6319: font-size: x-small;
6320: }
1.795 www 6321:
1.861 bisitz 6322: .LC_docs_entry_parameter {
6323: white-space: nowrap;
6324: }
6325:
1.544 albertel 6326: .LC_docs_copy {
1.545 albertel 6327: color: #000099;
1.544 albertel 6328: }
1.795 www 6329:
1.544 albertel 6330: .LC_docs_cut {
1.545 albertel 6331: color: #550044;
1.544 albertel 6332: }
1.795 www 6333:
1.544 albertel 6334: .LC_docs_rename {
1.545 albertel 6335: color: #009900;
1.544 albertel 6336: }
1.795 www 6337:
1.544 albertel 6338: .LC_docs_remove {
1.545 albertel 6339: color: #990000;
6340: }
6341:
1.547 albertel 6342: .LC_docs_reinit_warn,
6343: .LC_docs_ext_edit {
6344: font-size: x-small;
6345: }
6346:
1.545 albertel 6347: table.LC_docs_adddocs td,
6348: table.LC_docs_adddocs th {
6349: border: 1px solid #BBBBBB;
6350: padding: 4px;
6351: background: #DDDDDD;
1.543 albertel 6352: }
6353:
1.584 albertel 6354: table.LC_sty_begin {
6355: background: #BBFFBB;
6356: }
1.795 www 6357:
1.584 albertel 6358: table.LC_sty_end {
6359: background: #FFBBBB;
6360: }
6361:
1.589 raeburn 6362: table.LC_double_column {
1.803 bisitz 6363: border-width: 0;
1.589 raeburn 6364: border-collapse: collapse;
6365: width: 100%;
6366: padding: 2px;
6367: }
6368:
6369: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6370: top: 2px;
1.589 raeburn 6371: left: 2px;
6372: width: 47%;
6373: vertical-align: top;
6374: }
6375:
6376: table.LC_double_column tr td.LC_right_col {
6377: top: 2px;
1.779 bisitz 6378: right: 2px;
1.589 raeburn 6379: width: 47%;
6380: vertical-align: top;
6381: }
6382:
1.591 raeburn 6383: div.LC_left_float {
6384: float: left;
6385: padding-right: 5%;
1.597 albertel 6386: padding-bottom: 4px;
1.591 raeburn 6387: }
6388:
6389: div.LC_clear_float_header {
1.597 albertel 6390: padding-bottom: 2px;
1.591 raeburn 6391: }
6392:
6393: div.LC_clear_float_footer {
1.597 albertel 6394: padding-top: 10px;
1.591 raeburn 6395: clear: both;
6396: }
6397:
1.597 albertel 6398: div.LC_grade_show_user {
1.941 bisitz 6399: /* border-left: 5px solid $sidebg; */
6400: border-top: 5px solid #000000;
6401: margin: 50px 0 0 0;
1.936 bisitz 6402: padding: 15px 0 5px 10px;
1.597 albertel 6403: }
1.795 www 6404:
1.936 bisitz 6405: div.LC_grade_show_user_odd_row {
1.941 bisitz 6406: /* border-left: 5px solid #000000; */
6407: }
6408:
6409: div.LC_grade_show_user div.LC_Box {
6410: margin-right: 50px;
1.597 albertel 6411: }
6412:
6413: div.LC_grade_submissions,
6414: div.LC_grade_message_center,
1.936 bisitz 6415: div.LC_grade_info_links {
1.597 albertel 6416: margin: 5px;
6417: width: 99%;
6418: background: #FFFFFF;
6419: }
1.795 www 6420:
1.597 albertel 6421: div.LC_grade_submissions_header,
1.936 bisitz 6422: div.LC_grade_message_center_header {
1.705 tempelho 6423: font-weight: bold;
6424: font-size: large;
1.597 albertel 6425: }
1.795 www 6426:
1.597 albertel 6427: div.LC_grade_submissions_body,
1.936 bisitz 6428: div.LC_grade_message_center_body {
1.597 albertel 6429: border: 1px solid black;
6430: width: 99%;
6431: background: #FFFFFF;
6432: }
1.795 www 6433:
1.613 albertel 6434: table.LC_scantron_action {
6435: width: 100%;
6436: }
1.795 www 6437:
1.613 albertel 6438: table.LC_scantron_action tr th {
1.698 harmsja 6439: font-weight:bold;
6440: font-style:normal;
1.613 albertel 6441: }
1.795 www 6442:
1.779 bisitz 6443: .LC_edit_problem_header,
1.614 albertel 6444: div.LC_edit_problem_footer {
1.705 tempelho 6445: font-weight: normal;
6446: font-size: medium;
1.602 albertel 6447: margin: 2px;
1.1060 bisitz 6448: background-color: $sidebg;
1.600 albertel 6449: }
1.795 www 6450:
1.600 albertel 6451: div.LC_edit_problem_header,
1.602 albertel 6452: div.LC_edit_problem_header div,
1.614 albertel 6453: div.LC_edit_problem_footer,
6454: div.LC_edit_problem_footer div,
1.602 albertel 6455: div.LC_edit_problem_editxml_header,
6456: div.LC_edit_problem_editxml_header div {
1.600 albertel 6457: margin-top: 5px;
6458: }
1.795 www 6459:
1.600 albertel 6460: div.LC_edit_problem_header_title {
1.705 tempelho 6461: font-weight: bold;
6462: font-size: larger;
1.602 albertel 6463: background: $tabbg;
6464: padding: 3px;
1.1060 bisitz 6465: margin: 0 0 5px 0;
1.602 albertel 6466: }
1.795 www 6467:
1.602 albertel 6468: table.LC_edit_problem_header_title {
6469: width: 100%;
1.600 albertel 6470: background: $tabbg;
1.602 albertel 6471: }
6472:
6473: div.LC_edit_problem_discards {
6474: float: left;
6475: padding-bottom: 5px;
6476: }
1.795 www 6477:
1.602 albertel 6478: div.LC_edit_problem_saves {
6479: float: right;
6480: padding-bottom: 5px;
1.600 albertel 6481: }
1.795 www 6482:
1.1075.2.34 raeburn 6483: .LC_edit_opt {
6484: padding-left: 1em;
6485: white-space: nowrap;
6486: }
6487:
1.1075.2.57 raeburn 6488: .LC_edit_problem_latexhelper{
6489: text-align: right;
6490: }
6491:
6492: #LC_edit_problem_colorful div{
6493: margin-left: 40px;
6494: }
6495:
1.911 bisitz 6496: img.stift {
1.803 bisitz 6497: border-width: 0;
6498: vertical-align: middle;
1.677 riegler 6499: }
1.680 riegler 6500:
1.923 bisitz 6501: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6502: vertical-align: top;
1.777 tempelho 6503: }
1.795 www 6504:
1.716 raeburn 6505: div.LC_createcourse {
1.911 bisitz 6506: margin: 10px 10px 10px 10px;
1.716 raeburn 6507: }
6508:
1.917 raeburn 6509: .LC_dccid {
1.1075.2.38 raeburn 6510: float: right;
1.917 raeburn 6511: margin: 0.2em 0 0 0;
6512: padding: 0;
6513: font-size: 90%;
6514: display:none;
6515: }
6516:
1.897 wenzelju 6517: ol.LC_primary_menu a:hover,
1.721 harmsja 6518: ol#LC_MenuBreadcrumbs a:hover,
6519: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6520: ul#LC_secondary_menu a:hover,
1.721 harmsja 6521: .LC_FormSectionClearButton input:hover
1.795 www 6522: ul.LC_TabContent li:hover a {
1.952 onken 6523: color:$button_hover;
1.911 bisitz 6524: text-decoration:none;
1.693 droeschl 6525: }
6526:
1.779 bisitz 6527: h1 {
1.911 bisitz 6528: padding: 0;
6529: line-height:130%;
1.693 droeschl 6530: }
1.698 harmsja 6531:
1.911 bisitz 6532: h2,
6533: h3,
6534: h4,
6535: h5,
6536: h6 {
6537: margin: 5px 0 5px 0;
6538: padding: 0;
6539: line-height:130%;
1.693 droeschl 6540: }
1.795 www 6541:
6542: .LC_hcell {
1.911 bisitz 6543: padding:3px 15px 3px 15px;
6544: margin: 0;
6545: background-color:$tabbg;
6546: color:$fontmenu;
6547: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6548: }
1.795 www 6549:
1.840 bisitz 6550: .LC_Box > .LC_hcell {
1.911 bisitz 6551: margin: 0 -10px 10px -10px;
1.835 bisitz 6552: }
6553:
1.721 harmsja 6554: .LC_noBorder {
1.911 bisitz 6555: border: 0;
1.698 harmsja 6556: }
1.693 droeschl 6557:
1.721 harmsja 6558: .LC_FormSectionClearButton input {
1.911 bisitz 6559: background-color:transparent;
6560: border: none;
6561: cursor:pointer;
6562: text-decoration:underline;
1.693 droeschl 6563: }
1.763 bisitz 6564:
6565: .LC_help_open_topic {
1.911 bisitz 6566: color: #FFFFFF;
6567: background-color: #EEEEFF;
6568: margin: 1px;
6569: padding: 4px;
6570: border: 1px solid #000033;
6571: white-space: nowrap;
6572: /* vertical-align: middle; */
1.759 neumanie 6573: }
1.693 droeschl 6574:
1.911 bisitz 6575: dl,
6576: ul,
6577: div,
6578: fieldset {
6579: margin: 10px 10px 10px 0;
6580: /* overflow: hidden; */
1.693 droeschl 6581: }
1.795 www 6582:
1.838 bisitz 6583: fieldset > legend {
1.911 bisitz 6584: font-weight: bold;
6585: padding: 0 5px 0 5px;
1.838 bisitz 6586: }
6587:
1.813 bisitz 6588: #LC_nav_bar {
1.911 bisitz 6589: float: left;
1.995 raeburn 6590: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6591: margin: 0 0 2px 0;
1.807 droeschl 6592: }
6593:
1.916 droeschl 6594: #LC_realm {
6595: margin: 0.2em 0 0 0;
6596: padding: 0;
6597: font-weight: bold;
6598: text-align: center;
1.995 raeburn 6599: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6600: }
6601:
1.911 bisitz 6602: #LC_nav_bar em {
6603: font-weight: bold;
6604: font-style: normal;
1.807 droeschl 6605: }
6606:
1.897 wenzelju 6607: ol.LC_primary_menu {
1.934 droeschl 6608: margin: 0;
1.1075.2.2 raeburn 6609: padding: 0;
1.995 raeburn 6610: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6611: }
6612:
1.852 droeschl 6613: ol#LC_PathBreadcrumbs {
1.911 bisitz 6614: margin: 0;
1.693 droeschl 6615: }
6616:
1.897 wenzelju 6617: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6618: color: RGB(80, 80, 80);
6619: vertical-align: middle;
6620: text-align: left;
6621: list-style: none;
6622: float: left;
6623: }
6624:
6625: ol.LC_primary_menu li a {
6626: display: block;
6627: margin: 0;
6628: padding: 0 5px 0 10px;
6629: text-decoration: none;
6630: }
6631:
6632: ol.LC_primary_menu li ul {
6633: display: none;
6634: width: 10em;
6635: background-color: $data_table_light;
6636: }
6637:
6638: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6639: display: block;
6640: position: absolute;
6641: margin: 0;
6642: padding: 0;
1.1075.2.5 raeburn 6643: z-index: 2;
1.1075.2.2 raeburn 6644: }
6645:
6646: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6647: font-size: 90%;
1.911 bisitz 6648: vertical-align: top;
1.1075.2.2 raeburn 6649: float: none;
1.1075.2.5 raeburn 6650: border-left: 1px solid black;
6651: border-right: 1px solid black;
1.1075.2.2 raeburn 6652: }
6653:
6654: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6655: background-color:$data_table_light;
1.1075.2.2 raeburn 6656: }
6657:
6658: ol.LC_primary_menu li li a:hover {
6659: color:$button_hover;
6660: background-color:$data_table_dark;
1.693 droeschl 6661: }
6662:
1.897 wenzelju 6663: ol.LC_primary_menu li img {
1.911 bisitz 6664: vertical-align: bottom;
1.934 droeschl 6665: height: 1.1em;
1.1075.2.3 raeburn 6666: margin: 0.2em 0 0 0;
1.693 droeschl 6667: }
6668:
1.897 wenzelju 6669: ol.LC_primary_menu a {
1.911 bisitz 6670: color: RGB(80, 80, 80);
6671: text-decoration: none;
1.693 droeschl 6672: }
1.795 www 6673:
1.949 droeschl 6674: ol.LC_primary_menu a.LC_new_message {
6675: font-weight:bold;
6676: color: darkred;
6677: }
6678:
1.975 raeburn 6679: ol.LC_docs_parameters {
6680: margin-left: 0;
6681: padding: 0;
6682: list-style: none;
6683: }
6684:
6685: ol.LC_docs_parameters li {
6686: margin: 0;
6687: padding-right: 20px;
6688: display: inline;
6689: }
6690:
1.976 raeburn 6691: ol.LC_docs_parameters li:before {
6692: content: "\\002022 \\0020";
6693: }
6694:
6695: li.LC_docs_parameters_title {
6696: font-weight: bold;
6697: }
6698:
6699: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6700: content: "";
6701: }
6702:
1.897 wenzelju 6703: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6704: clear: right;
1.911 bisitz 6705: color: $fontmenu;
6706: background: $tabbg;
6707: list-style: none;
6708: padding: 0;
6709: margin: 0;
6710: width: 100%;
1.995 raeburn 6711: text-align: left;
1.1075.2.4 raeburn 6712: float: left;
1.808 droeschl 6713: }
6714:
1.897 wenzelju 6715: ul#LC_secondary_menu li {
1.911 bisitz 6716: font-weight: bold;
6717: line-height: 1.8em;
6718: border-right: 1px solid black;
6719: vertical-align: middle;
1.1075.2.4 raeburn 6720: float: left;
6721: }
6722:
6723: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6724: background-color: $data_table_light;
6725: }
6726:
6727: ul#LC_secondary_menu li a {
6728: padding: 0 0.8em;
6729: }
6730:
6731: ul#LC_secondary_menu li ul {
6732: display: none;
6733: }
6734:
6735: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6736: display: block;
6737: position: absolute;
6738: margin: 0;
6739: padding: 0;
6740: list-style:none;
6741: float: none;
6742: background-color: $data_table_light;
1.1075.2.5 raeburn 6743: z-index: 2;
1.1075.2.10 raeburn 6744: margin-left: -1px;
1.1075.2.4 raeburn 6745: }
6746:
6747: ul#LC_secondary_menu li ul li {
6748: font-size: 90%;
6749: vertical-align: top;
6750: border-left: 1px solid black;
6751: border-right: 1px solid black;
1.1075.2.33 raeburn 6752: background-color: $data_table_light;
1.1075.2.4 raeburn 6753: list-style:none;
6754: float: none;
6755: }
6756:
6757: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6758: background-color: $data_table_dark;
1.807 droeschl 6759: }
6760:
1.847 tempelho 6761: ul.LC_TabContent {
1.911 bisitz 6762: display:block;
6763: background: $sidebg;
6764: border-bottom: solid 1px $lg_border_color;
6765: list-style:none;
1.1020 raeburn 6766: margin: -1px -10px 0 -10px;
1.911 bisitz 6767: padding: 0;
1.693 droeschl 6768: }
6769:
1.795 www 6770: ul.LC_TabContent li,
6771: ul.LC_TabContentBigger li {
1.911 bisitz 6772: float:left;
1.741 harmsja 6773: }
1.795 www 6774:
1.897 wenzelju 6775: ul#LC_secondary_menu li a {
1.911 bisitz 6776: color: $fontmenu;
6777: text-decoration: none;
1.693 droeschl 6778: }
1.795 www 6779:
1.721 harmsja 6780: ul.LC_TabContent {
1.952 onken 6781: min-height:20px;
1.721 harmsja 6782: }
1.795 www 6783:
6784: ul.LC_TabContent li {
1.911 bisitz 6785: vertical-align:middle;
1.959 onken 6786: padding: 0 16px 0 10px;
1.911 bisitz 6787: background-color:$tabbg;
6788: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6789: border-left: solid 1px $font;
1.721 harmsja 6790: }
1.795 www 6791:
1.847 tempelho 6792: ul.LC_TabContent .right {
1.911 bisitz 6793: float:right;
1.847 tempelho 6794: }
6795:
1.911 bisitz 6796: ul.LC_TabContent li a,
6797: ul.LC_TabContent li {
6798: color:rgb(47,47,47);
6799: text-decoration:none;
6800: font-size:95%;
6801: font-weight:bold;
1.952 onken 6802: min-height:20px;
6803: }
6804:
1.959 onken 6805: ul.LC_TabContent li a:hover,
6806: ul.LC_TabContent li a:focus {
1.952 onken 6807: color: $button_hover;
1.959 onken 6808: background:none;
6809: outline:none;
1.952 onken 6810: }
6811:
6812: ul.LC_TabContent li:hover {
6813: color: $button_hover;
6814: cursor:pointer;
1.721 harmsja 6815: }
1.795 www 6816:
1.911 bisitz 6817: ul.LC_TabContent li.active {
1.952 onken 6818: color: $font;
1.911 bisitz 6819: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6820: border-bottom:solid 1px #FFFFFF;
6821: cursor: default;
1.744 ehlerst 6822: }
1.795 www 6823:
1.959 onken 6824: ul.LC_TabContent li.active a {
6825: color:$font;
6826: background:#FFFFFF;
6827: outline: none;
6828: }
1.1047 raeburn 6829:
6830: ul.LC_TabContent li.goback {
6831: float: left;
6832: border-left: none;
6833: }
6834:
1.870 tempelho 6835: #maincoursedoc {
1.911 bisitz 6836: clear:both;
1.870 tempelho 6837: }
6838:
6839: ul.LC_TabContentBigger {
1.911 bisitz 6840: display:block;
6841: list-style:none;
6842: padding: 0;
1.870 tempelho 6843: }
6844:
1.795 www 6845: ul.LC_TabContentBigger li {
1.911 bisitz 6846: vertical-align:bottom;
6847: height: 30px;
6848: font-size:110%;
6849: font-weight:bold;
6850: color: #737373;
1.841 tempelho 6851: }
6852:
1.957 onken 6853: ul.LC_TabContentBigger li.active {
6854: position: relative;
6855: top: 1px;
6856: }
6857:
1.870 tempelho 6858: ul.LC_TabContentBigger li a {
1.911 bisitz 6859: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6860: height: 30px;
6861: line-height: 30px;
6862: text-align: center;
6863: display: block;
6864: text-decoration: none;
1.958 onken 6865: outline: none;
1.741 harmsja 6866: }
1.795 www 6867:
1.870 tempelho 6868: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6869: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6870: color:$font;
1.744 ehlerst 6871: }
1.795 www 6872:
1.870 tempelho 6873: ul.LC_TabContentBigger li b {
1.911 bisitz 6874: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6875: display: block;
6876: float: left;
6877: padding: 0 30px;
1.957 onken 6878: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6879: }
6880:
1.956 onken 6881: ul.LC_TabContentBigger li:hover b {
6882: color:$button_hover;
6883: }
6884:
1.870 tempelho 6885: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6886: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6887: color:$font;
1.957 onken 6888: border: 0;
1.741 harmsja 6889: }
1.693 droeschl 6890:
1.870 tempelho 6891:
1.862 bisitz 6892: ul.LC_CourseBreadcrumbs {
6893: background: $sidebg;
1.1020 raeburn 6894: height: 2em;
1.862 bisitz 6895: padding-left: 10px;
1.1020 raeburn 6896: margin: 0;
1.862 bisitz 6897: list-style-position: inside;
6898: }
6899:
1.911 bisitz 6900: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6901: ol#LC_PathBreadcrumbs {
1.911 bisitz 6902: padding-left: 10px;
6903: margin: 0;
1.933 droeschl 6904: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6905: }
6906:
1.911 bisitz 6907: ol#LC_MenuBreadcrumbs li,
6908: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6909: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6910: display: inline;
1.933 droeschl 6911: white-space: normal;
1.693 droeschl 6912: }
6913:
1.823 bisitz 6914: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6915: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6916: text-decoration: none;
6917: font-size:90%;
1.693 droeschl 6918: }
1.795 www 6919:
1.969 droeschl 6920: ol#LC_MenuBreadcrumbs h1 {
6921: display: inline;
6922: font-size: 90%;
6923: line-height: 2.5em;
6924: margin: 0;
6925: padding: 0;
6926: }
6927:
1.795 www 6928: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6929: text-decoration:none;
6930: font-size:100%;
6931: font-weight:bold;
1.693 droeschl 6932: }
1.795 www 6933:
1.840 bisitz 6934: .LC_Box {
1.911 bisitz 6935: border: solid 1px $lg_border_color;
6936: padding: 0 10px 10px 10px;
1.746 neumanie 6937: }
1.795 www 6938:
1.1020 raeburn 6939: .LC_DocsBox {
6940: border: solid 1px $lg_border_color;
6941: padding: 0 0 10px 10px;
6942: }
6943:
1.795 www 6944: .LC_AboutMe_Image {
1.911 bisitz 6945: float:left;
6946: margin-right:10px;
1.747 neumanie 6947: }
1.795 www 6948:
6949: .LC_Clear_AboutMe_Image {
1.911 bisitz 6950: clear:left;
1.747 neumanie 6951: }
1.795 www 6952:
1.721 harmsja 6953: dl.LC_ListStyleClean dt {
1.911 bisitz 6954: padding-right: 5px;
6955: display: table-header-group;
1.693 droeschl 6956: }
6957:
1.721 harmsja 6958: dl.LC_ListStyleClean dd {
1.911 bisitz 6959: display: table-row;
1.693 droeschl 6960: }
6961:
1.721 harmsja 6962: .LC_ListStyleClean,
6963: .LC_ListStyleSimple,
6964: .LC_ListStyleNormal,
1.795 www 6965: .LC_ListStyleSpecial {
1.911 bisitz 6966: /* display:block; */
6967: list-style-position: inside;
6968: list-style-type: none;
6969: overflow: hidden;
6970: padding: 0;
1.693 droeschl 6971: }
6972:
1.721 harmsja 6973: .LC_ListStyleSimple li,
6974: .LC_ListStyleSimple dd,
6975: .LC_ListStyleNormal li,
6976: .LC_ListStyleNormal dd,
6977: .LC_ListStyleSpecial li,
1.795 www 6978: .LC_ListStyleSpecial dd {
1.911 bisitz 6979: margin: 0;
6980: padding: 5px 5px 5px 10px;
6981: clear: both;
1.693 droeschl 6982: }
6983:
1.721 harmsja 6984: .LC_ListStyleClean li,
6985: .LC_ListStyleClean dd {
1.911 bisitz 6986: padding-top: 0;
6987: padding-bottom: 0;
1.693 droeschl 6988: }
6989:
1.721 harmsja 6990: .LC_ListStyleSimple dd,
1.795 www 6991: .LC_ListStyleSimple li {
1.911 bisitz 6992: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6993: }
6994:
1.721 harmsja 6995: .LC_ListStyleSpecial li,
6996: .LC_ListStyleSpecial dd {
1.911 bisitz 6997: list-style-type: none;
6998: background-color: RGB(220, 220, 220);
6999: margin-bottom: 4px;
1.693 droeschl 7000: }
7001:
1.721 harmsja 7002: table.LC_SimpleTable {
1.911 bisitz 7003: margin:5px;
7004: border:solid 1px $lg_border_color;
1.795 www 7005: }
1.693 droeschl 7006:
1.721 harmsja 7007: table.LC_SimpleTable tr {
1.911 bisitz 7008: padding: 0;
7009: border:solid 1px $lg_border_color;
1.693 droeschl 7010: }
1.795 www 7011:
7012: table.LC_SimpleTable thead {
1.911 bisitz 7013: background:rgb(220,220,220);
1.693 droeschl 7014: }
7015:
1.721 harmsja 7016: div.LC_columnSection {
1.911 bisitz 7017: display: block;
7018: clear: both;
7019: overflow: hidden;
7020: margin: 0;
1.693 droeschl 7021: }
7022:
1.721 harmsja 7023: div.LC_columnSection>* {
1.911 bisitz 7024: float: left;
7025: margin: 10px 20px 10px 0;
7026: overflow:hidden;
1.693 droeschl 7027: }
1.721 harmsja 7028:
1.795 www 7029: table em {
1.911 bisitz 7030: font-weight: bold;
7031: font-style: normal;
1.748 schulted 7032: }
1.795 www 7033:
1.779 bisitz 7034: table.LC_tableBrowseRes,
1.795 www 7035: table.LC_tableOfContent {
1.911 bisitz 7036: border:none;
7037: border-spacing: 1px;
7038: padding: 3px;
7039: background-color: #FFFFFF;
7040: font-size: 90%;
1.753 droeschl 7041: }
1.789 droeschl 7042:
1.911 bisitz 7043: table.LC_tableOfContent {
7044: border-collapse: collapse;
1.789 droeschl 7045: }
7046:
1.771 droeschl 7047: table.LC_tableBrowseRes a,
1.768 schulted 7048: table.LC_tableOfContent a {
1.911 bisitz 7049: background-color: transparent;
7050: text-decoration: none;
1.753 droeschl 7051: }
7052:
1.795 www 7053: table.LC_tableOfContent img {
1.911 bisitz 7054: border: none;
7055: height: 1.3em;
7056: vertical-align: text-bottom;
7057: margin-right: 0.3em;
1.753 droeschl 7058: }
1.757 schulted 7059:
1.795 www 7060: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7061: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7062: }
7063:
1.795 www 7064: a#LC_content_toolbar_everything {
1.911 bisitz 7065: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7066: }
7067:
1.795 www 7068: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7069: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7070: }
7071:
1.795 www 7072: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7073: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7074: }
7075:
1.795 www 7076: a#LC_content_toolbar_changefolder {
1.911 bisitz 7077: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7078: }
7079:
1.795 www 7080: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7081: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7082: }
7083:
1.1043 raeburn 7084: a#LC_content_toolbar_edittoplevel {
7085: background-image:url(/res/adm/pages/edittoplevel.gif);
7086: }
7087:
1.795 www 7088: ul#LC_toolbar li a:hover {
1.911 bisitz 7089: background-position: bottom center;
1.757 schulted 7090: }
7091:
1.795 www 7092: ul#LC_toolbar {
1.911 bisitz 7093: padding: 0;
7094: margin: 2px;
7095: list-style:none;
7096: position:relative;
7097: background-color:white;
1.1075.2.9 raeburn 7098: overflow: auto;
1.757 schulted 7099: }
7100:
1.795 www 7101: ul#LC_toolbar li {
1.911 bisitz 7102: border:1px solid white;
7103: padding: 0;
7104: margin: 0;
7105: float: left;
7106: display:inline;
7107: vertical-align:middle;
1.1075.2.9 raeburn 7108: white-space: nowrap;
1.911 bisitz 7109: }
1.757 schulted 7110:
1.783 amueller 7111:
1.795 www 7112: a.LC_toolbarItem {
1.911 bisitz 7113: display:block;
7114: padding: 0;
7115: margin: 0;
7116: height: 32px;
7117: width: 32px;
7118: color:white;
7119: border: none;
7120: background-repeat:no-repeat;
7121: background-color:transparent;
1.757 schulted 7122: }
7123:
1.915 droeschl 7124: ul.LC_funclist {
7125: margin: 0;
7126: padding: 0.5em 1em 0.5em 0;
7127: }
7128:
1.933 droeschl 7129: ul.LC_funclist > li:first-child {
7130: font-weight:bold;
7131: margin-left:0.8em;
7132: }
7133:
1.915 droeschl 7134: ul.LC_funclist + ul.LC_funclist {
7135: /*
7136: left border as a seperator if we have more than
7137: one list
7138: */
7139: border-left: 1px solid $sidebg;
7140: /*
7141: this hides the left border behind the border of the
7142: outer box if element is wrapped to the next 'line'
7143: */
7144: margin-left: -1px;
7145: }
7146:
1.843 bisitz 7147: ul.LC_funclist li {
1.915 droeschl 7148: display: inline;
1.782 bisitz 7149: white-space: nowrap;
1.915 droeschl 7150: margin: 0 0 0 25px;
7151: line-height: 150%;
1.782 bisitz 7152: }
7153:
1.974 wenzelju 7154: .LC_hidden {
7155: display: none;
7156: }
7157:
1.1030 www 7158: .LCmodal-overlay {
7159: position:fixed;
7160: top:0;
7161: right:0;
7162: bottom:0;
7163: left:0;
7164: height:100%;
7165: width:100%;
7166: margin:0;
7167: padding:0;
7168: background:#999;
7169: opacity:.75;
7170: filter: alpha(opacity=75);
7171: -moz-opacity: 0.75;
7172: z-index:101;
7173: }
7174:
7175: * html .LCmodal-overlay {
7176: position: absolute;
7177: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7178: }
7179:
7180: .LCmodal-window {
7181: position:fixed;
7182: top:50%;
7183: left:50%;
7184: margin:0;
7185: padding:0;
7186: z-index:102;
7187: }
7188:
7189: * html .LCmodal-window {
7190: position:absolute;
7191: }
7192:
7193: .LCclose-window {
7194: position:absolute;
7195: width:32px;
7196: height:32px;
7197: right:8px;
7198: top:8px;
7199: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7200: text-indent:-99999px;
7201: overflow:hidden;
7202: cursor:pointer;
7203: }
7204:
1.1075.2.17 raeburn 7205: /*
7206: styles used by TTH when "Default set of options to pass to tth/m
7207: when converting TeX" in course settings has been set
7208:
7209: option passed: -t
7210:
7211: */
7212:
7213: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7214: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7215: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7216: td div.norm {line-height:normal;}
7217:
7218: /*
7219: option passed -y3
7220: */
7221:
7222: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7223: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7224: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7225:
1.343 albertel 7226: END
7227: }
7228:
1.306 albertel 7229: =pod
7230:
7231: =item * &headtag()
7232:
7233: Returns a uniform footer for LON-CAPA web pages.
7234:
1.307 albertel 7235: Inputs: $title - optional title for the head
7236: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7237: $args - optional arguments
1.319 albertel 7238: force_register - if is true call registerurl so the remote is
7239: informed
1.415 albertel 7240: redirect -> array ref of
7241: 1- seconds before redirect occurs
7242: 2- url to redirect to
7243: 3- whether the side effect should occur
1.315 albertel 7244: (side effect of setting
7245: $env{'internal.head.redirect'} to the url
7246: redirected too)
1.352 albertel 7247: domain -> force to color decorate a page for a specific
7248: domain
7249: function -> force usage of a specific rolish color scheme
7250: bgcolor -> override the default page bgcolor
1.460 albertel 7251: no_auto_mt_title
7252: -> prevent &mt()ing the title arg
1.464 albertel 7253:
1.306 albertel 7254: =cut
7255:
7256: sub headtag {
1.313 albertel 7257: my ($title,$head_extra,$args) = @_;
1.306 albertel 7258:
1.363 albertel 7259: my $function = $args->{'function'} || &get_users_function();
7260: my $domain = $args->{'domain'} || &determinedomain();
7261: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7262: my $httphost = $args->{'use_absolute'};
1.418 albertel 7263: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7264: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7265: #time(),
1.418 albertel 7266: $env{'environment.color.timestamp'},
1.363 albertel 7267: $function,$domain,$bgcolor);
7268:
1.369 www 7269: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7270:
1.308 albertel 7271: my $result =
7272: '<head>'.
1.1075.2.56 raeburn 7273: &font_settings($args);
1.319 albertel 7274:
1.1064 raeburn 7275: my $inhibitprint = &print_suppression();
7276:
1.461 albertel 7277: if (!$args->{'frameset'}) {
7278: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7279: }
1.1075.2.12 raeburn 7280: if ($args->{'force_register'}) {
7281: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7282: }
1.436 albertel 7283: if (!$args->{'no_nav_bar'}
7284: && !$args->{'only_body'}
7285: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7286: $result .= &help_menu_js($httphost);
1.1032 www 7287: $result.=&modal_window();
1.1038 www 7288: $result.=&togglebox_script();
1.1034 www 7289: $result.=&wishlist_window();
1.1041 www 7290: $result.=&LCprogressbarUpdate_script();
1.1034 www 7291: } else {
7292: if ($args->{'add_modal'}) {
7293: $result.=&modal_window();
7294: }
7295: if ($args->{'add_wishlist'}) {
7296: $result.=&wishlist_window();
7297: }
1.1038 www 7298: if ($args->{'add_togglebox'}) {
7299: $result.=&togglebox_script();
7300: }
1.1041 www 7301: if ($args->{'add_progressbar'}) {
7302: $result.=&LCprogressbarUpdate_script();
7303: }
1.436 albertel 7304: }
1.314 albertel 7305: if (ref($args->{'redirect'})) {
1.414 albertel 7306: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7307: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7308: if (!$inhibit_continue) {
7309: $env{'internal.head.redirect'} = $url;
7310: }
1.313 albertel 7311: $result.=<<ADDMETA
7312: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7313: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7314: ADDMETA
7315: }
1.306 albertel 7316: if (!defined($title)) {
7317: $title = 'The LearningOnline Network with CAPA';
7318: }
1.460 albertel 7319: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7320: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7321: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7322: .$inhibitprint
1.414 albertel 7323: .$head_extra;
1.1075.2.42 raeburn 7324: if ($env{'browser.mobile'}) {
7325: $result .= '
7326: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7327: <meta name="apple-mobile-web-app-capable" content="yes" />';
7328: }
1.962 droeschl 7329: return $result.'</head>';
1.306 albertel 7330: }
7331:
7332: =pod
7333:
1.340 albertel 7334: =item * &font_settings()
7335:
7336: Returns neccessary <meta> to set the proper encoding
7337:
1.1075.2.56 raeburn 7338: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7339:
7340: =cut
7341:
7342: sub font_settings {
1.1075.2.56 raeburn 7343: my ($args) = @_;
1.340 albertel 7344: my $headerstring='';
1.1075.2.56 raeburn 7345: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7346: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7347: $headerstring.=
1.1075.2.56 raeburn 7348: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
1.340 albertel 7349: }
7350: return $headerstring;
7351: }
7352:
1.341 albertel 7353: =pod
7354:
1.1064 raeburn 7355: =item * &print_suppression()
7356:
7357: In course context returns css which causes the body to be blank when media="print",
7358: if printout generation is unavailable for the current resource.
7359:
7360: This could be because:
7361:
7362: (a) printstartdate is in the future
7363:
7364: (b) printenddate is in the past
7365:
7366: (c) there is an active exam block with "printout"
7367: functionality blocked
7368:
7369: Users with pav, pfo or evb privileges are exempt.
7370:
7371: Inputs: none
7372:
7373: =cut
7374:
7375:
7376: sub print_suppression {
7377: my $noprint;
7378: if ($env{'request.course.id'}) {
7379: my $scope = $env{'request.course.id'};
7380: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7381: (&Apache::lonnet::allowed('pfo',$scope))) {
7382: return;
7383: }
7384: if ($env{'request.course.sec'} ne '') {
7385: $scope .= "/$env{'request.course.sec'}";
7386: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7387: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7388: return;
1.1064 raeburn 7389: }
7390: }
7391: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7392: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7393: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7394: if ($blocked) {
7395: my $checkrole = "cm./$cdom/$cnum";
7396: if ($env{'request.course.sec'} ne '') {
7397: $checkrole .= "/$env{'request.course.sec'}";
7398: }
7399: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7400: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7401: $noprint = 1;
7402: }
7403: }
7404: unless ($noprint) {
7405: my $symb = &Apache::lonnet::symbread();
7406: if ($symb ne '') {
7407: my $navmap = Apache::lonnavmaps::navmap->new();
7408: if (ref($navmap)) {
7409: my $res = $navmap->getBySymb($symb);
7410: if (ref($res)) {
7411: if (!$res->resprintable()) {
7412: $noprint = 1;
7413: }
7414: }
7415: }
7416: }
7417: }
7418: if ($noprint) {
7419: return <<"ENDSTYLE";
7420: <style type="text/css" media="print">
7421: body { display:none }
7422: </style>
7423: ENDSTYLE
7424: }
7425: }
7426: return;
7427: }
7428:
7429: =pod
7430:
1.341 albertel 7431: =item * &xml_begin()
7432:
7433: Returns the needed doctype and <html>
7434:
7435: Inputs: none
7436:
7437: =cut
7438:
7439: sub xml_begin {
7440: my $output='';
7441:
7442: if ($env{'browser.mathml'}) {
7443: $output='<?xml version="1.0"?>'
7444: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7445: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7446:
7447: # .'<!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">] >'
7448: .'<!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">'
7449: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7450: .'xmlns="http://www.w3.org/1999/xhtml">';
7451: } else {
1.1075.2.56 raeburn 7452: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n"
7453: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7454: }
7455: return $output;
7456: }
1.340 albertel 7457:
7458: =pod
7459:
1.306 albertel 7460: =item * &start_page()
7461:
7462: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7463:
1.648 raeburn 7464: Inputs:
7465:
7466: =over 4
7467:
7468: $title - optional title for the page
7469:
7470: $head_extra - optional extra HTML to incude inside the <head>
7471:
7472: $args - additional optional args supported are:
7473:
7474: =over 8
7475:
7476: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7477: arg on
1.814 bisitz 7478: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7479: add_entries -> additional attributes to add to the <body>
7480: domain -> force to color decorate a page for a
1.317 albertel 7481: specific domain
1.648 raeburn 7482: function -> force usage of a specific rolish color
1.317 albertel 7483: scheme
1.648 raeburn 7484: redirect -> see &headtag()
7485: bgcolor -> override the default page bg color
7486: js_ready -> return a string ready for being used in
1.317 albertel 7487: a javascript writeln
1.648 raeburn 7488: html_encode -> return a string ready for being used in
1.320 albertel 7489: a html attribute
1.648 raeburn 7490: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7491: $forcereg arg
1.648 raeburn 7492: frameset -> if true will start with a <frameset>
1.330 albertel 7493: rather than <body>
1.648 raeburn 7494: skip_phases -> hash ref of
1.338 albertel 7495: head -> skip the <html><head> generation
7496: body -> skip all <body> generation
1.1075.2.12 raeburn 7497: no_inline_link -> if true and in remote mode, don't show the
7498: 'Switch To Inline Menu' link
1.648 raeburn 7499: no_auto_mt_title -> prevent &mt()ing the title arg
7500: inherit_jsmath -> when creating popup window in a page,
7501: should it have jsmath forced on by the
7502: current page
1.867 kalberla 7503: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7504: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7505: group -> includes the current group, if page is for a
7506: specific group
1.361 albertel 7507:
1.648 raeburn 7508: =back
1.460 albertel 7509:
1.648 raeburn 7510: =back
1.562 albertel 7511:
1.306 albertel 7512: =cut
7513:
7514: sub start_page {
1.309 albertel 7515: my ($title,$head_extra,$args) = @_;
1.318 albertel 7516: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7517:
1.315 albertel 7518: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7519: my ($result,@advtools);
1.964 droeschl 7520:
1.338 albertel 7521: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7522: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7523: }
7524:
7525: if (! exists($args->{'skip_phases'}{'body'}) ) {
7526: if ($args->{'frameset'}) {
7527: my $attr_string = &make_attr_string($args->{'force_register'},
7528: $args->{'add_entries'});
7529: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7530: } else {
7531: $result .=
7532: &bodytag($title,
7533: $args->{'function'}, $args->{'add_entries'},
7534: $args->{'only_body'}, $args->{'domain'},
7535: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7536: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7537: $args, \@advtools);
1.831 bisitz 7538: }
1.330 albertel 7539: }
1.338 albertel 7540:
1.315 albertel 7541: if ($args->{'js_ready'}) {
1.713 kaisler 7542: $result = &js_ready($result);
1.315 albertel 7543: }
1.320 albertel 7544: if ($args->{'html_encode'}) {
1.713 kaisler 7545: $result = &html_encode($result);
7546: }
7547:
1.813 bisitz 7548: # Preparation for new and consistent functionlist at top of screen
7549: # if ($args->{'functionlist'}) {
7550: # $result .= &build_functionlist();
7551: #}
7552:
1.964 droeschl 7553: # Don't add anything more if only_body wanted or in const space
7554: return $result if $args->{'only_body'}
7555: || $env{'request.state'} eq 'construct';
1.813 bisitz 7556:
7557: #Breadcrumbs
1.758 kaisler 7558: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7559: &Apache::lonhtmlcommon::clear_breadcrumbs();
7560: #if any br links exists, add them to the breadcrumbs
7561: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7562: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7563: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7564: }
7565: }
1.1075.2.19 raeburn 7566: # if @advtools array contains items add then to the breadcrumbs
7567: if (@advtools > 0) {
7568: &Apache::lonmenu::advtools_crumbs(@advtools);
7569: }
1.758 kaisler 7570:
7571: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7572: if(exists($args->{'bread_crumbs_component'})){
7573: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7574: }else{
7575: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7576: }
1.1075.2.24 raeburn 7577: } elsif (($env{'environment.remote'} eq 'on') &&
7578: ($env{'form.inhibitmenu'} ne 'yes') &&
7579: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7580: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7581: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7582: }
1.315 albertel 7583: return $result;
1.306 albertel 7584: }
7585:
7586: sub end_page {
1.315 albertel 7587: my ($args) = @_;
7588: $env{'internal.end_page'}++;
1.330 albertel 7589: my $result;
1.335 albertel 7590: if ($args->{'discussion'}) {
7591: my ($target,$parser);
7592: if (ref($args->{'discussion'})) {
7593: ($target,$parser) =($args->{'discussion'}{'target'},
7594: $args->{'discussion'}{'parser'});
7595: }
7596: $result .= &Apache::lonxml::xmlend($target,$parser);
7597: }
1.330 albertel 7598: if ($args->{'frameset'}) {
7599: $result .= '</frameset>';
7600: } else {
1.635 raeburn 7601: $result .= &endbodytag($args);
1.330 albertel 7602: }
1.1075.2.6 raeburn 7603: unless ($args->{'notbody'}) {
7604: $result .= "\n</html>";
7605: }
1.330 albertel 7606:
1.315 albertel 7607: if ($args->{'js_ready'}) {
1.317 albertel 7608: $result = &js_ready($result);
1.315 albertel 7609: }
1.335 albertel 7610:
1.320 albertel 7611: if ($args->{'html_encode'}) {
7612: $result = &html_encode($result);
7613: }
1.335 albertel 7614:
1.315 albertel 7615: return $result;
7616: }
7617:
1.1034 www 7618: sub wishlist_window {
7619: return(<<'ENDWISHLIST');
1.1046 raeburn 7620: <script type="text/javascript">
1.1034 www 7621: // <![CDATA[
7622: // <!-- BEGIN LON-CAPA Internal
7623: function set_wishlistlink(title, path) {
7624: if (!title) {
7625: title = document.title;
7626: title = title.replace(/^LON-CAPA /,'');
7627: }
7628: if (!path) {
7629: path = location.pathname;
7630: }
7631: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7632: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7633: }
7634: // END LON-CAPA Internal -->
7635: // ]]>
7636: </script>
7637: ENDWISHLIST
7638: }
7639:
1.1030 www 7640: sub modal_window {
7641: return(<<'ENDMODAL');
1.1046 raeburn 7642: <script type="text/javascript">
1.1030 www 7643: // <![CDATA[
7644: // <!-- BEGIN LON-CAPA Internal
7645: var modalWindow = {
7646: parent:"body",
7647: windowId:null,
7648: content:null,
7649: width:null,
7650: height:null,
7651: close:function()
7652: {
7653: $(".LCmodal-window").remove();
7654: $(".LCmodal-overlay").remove();
7655: },
7656: open:function()
7657: {
7658: var modal = "";
7659: modal += "<div class=\"LCmodal-overlay\"></div>";
7660: 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;\">";
7661: modal += this.content;
7662: modal += "</div>";
7663:
7664: $(this.parent).append(modal);
7665:
7666: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7667: $(".LCclose-window").click(function(){modalWindow.close();});
7668: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7669: }
7670: };
1.1075.2.42 raeburn 7671: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7672: {
7673: modalWindow.windowId = "myModal";
7674: modalWindow.width = width;
7675: modalWindow.height = height;
1.1075.2.42 raeburn 7676: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7677: modalWindow.open();
7678: };
7679: // END LON-CAPA Internal -->
7680: // ]]>
7681: </script>
7682: ENDMODAL
7683: }
7684:
7685: sub modal_link {
1.1075.2.42 raeburn 7686: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7687: unless ($width) { $width=480; }
7688: unless ($height) { $height=400; }
1.1031 www 7689: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7690: unless ($transparency) { $transparency='true'; }
7691:
1.1074 raeburn 7692: my $target_attr;
7693: if (defined($target)) {
7694: $target_attr = 'target="'.$target.'"';
7695: }
7696: return <<"ENDLINK";
1.1075.2.42 raeburn 7697: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7698: $linktext</a>
7699: ENDLINK
1.1030 www 7700: }
7701:
1.1032 www 7702: sub modal_adhoc_script {
7703: my ($funcname,$width,$height,$content)=@_;
7704: return (<<ENDADHOC);
1.1046 raeburn 7705: <script type="text/javascript">
1.1032 www 7706: // <![CDATA[
7707: var $funcname = function()
7708: {
7709: modalWindow.windowId = "myModal";
7710: modalWindow.width = $width;
7711: modalWindow.height = $height;
7712: modalWindow.content = '$content';
7713: modalWindow.open();
7714: };
7715: // ]]>
7716: </script>
7717: ENDADHOC
7718: }
7719:
1.1041 www 7720: sub modal_adhoc_inner {
7721: my ($funcname,$width,$height,$content)=@_;
7722: my $innerwidth=$width-20;
7723: $content=&js_ready(
1.1042 www 7724: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7725: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7726: $content.
1.1041 www 7727: &end_scrollbox().
1.1075.2.42 raeburn 7728: &end_page()
1.1041 www 7729: );
7730: return &modal_adhoc_script($funcname,$width,$height,$content);
7731: }
7732:
7733: sub modal_adhoc_window {
7734: my ($funcname,$width,$height,$content,$linktext)=@_;
7735: return &modal_adhoc_inner($funcname,$width,$height,$content).
7736: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7737: }
7738:
7739: sub modal_adhoc_launch {
7740: my ($funcname,$width,$height,$content)=@_;
7741: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7742: <script type="text/javascript">
7743: // <![CDATA[
7744: $funcname();
7745: // ]]>
7746: </script>
7747: ENDLAUNCH
7748: }
7749:
7750: sub modal_adhoc_close {
7751: return (<<ENDCLOSE);
7752: <script type="text/javascript">
7753: // <![CDATA[
7754: modalWindow.close();
7755: // ]]>
7756: </script>
7757: ENDCLOSE
7758: }
7759:
1.1038 www 7760: sub togglebox_script {
7761: return(<<ENDTOGGLE);
7762: <script type="text/javascript">
7763: // <![CDATA[
7764: function LCtoggleDisplay(id,hidetext,showtext) {
7765: link = document.getElementById(id + "link").childNodes[0];
7766: with (document.getElementById(id).style) {
7767: if (display == "none" ) {
7768: display = "inline";
7769: link.nodeValue = hidetext;
7770: } else {
7771: display = "none";
7772: link.nodeValue = showtext;
7773: }
7774: }
7775: }
7776: // ]]>
7777: </script>
7778: ENDTOGGLE
7779: }
7780:
1.1039 www 7781: sub start_togglebox {
7782: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7783: unless ($heading) { $heading=''; } else { $heading.=' '; }
7784: unless ($showtext) { $showtext=&mt('show'); }
7785: unless ($hidetext) { $hidetext=&mt('hide'); }
7786: unless ($headerbg) { $headerbg='#FFFFFF'; }
7787: return &start_data_table().
7788: &start_data_table_header_row().
7789: '<td bgcolor="'.$headerbg.'">'.$heading.
7790: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7791: $showtext.'\')">'.$showtext.'</a>]</td>'.
7792: &end_data_table_header_row().
7793: '<tr id="'.$id.'" style="display:none""><td>';
7794: }
7795:
7796: sub end_togglebox {
7797: return '</td></tr>'.&end_data_table();
7798: }
7799:
1.1041 www 7800: sub LCprogressbar_script {
1.1045 www 7801: my ($id)=@_;
1.1041 www 7802: return(<<ENDPROGRESS);
7803: <script type="text/javascript">
7804: // <![CDATA[
1.1045 www 7805: \$('#progressbar$id').progressbar({
1.1041 www 7806: value: 0,
7807: change: function(event, ui) {
7808: var newVal = \$(this).progressbar('option', 'value');
7809: \$('.pblabel', this).text(LCprogressTxt);
7810: }
7811: });
7812: // ]]>
7813: </script>
7814: ENDPROGRESS
7815: }
7816:
7817: sub LCprogressbarUpdate_script {
7818: return(<<ENDPROGRESSUPDATE);
7819: <style type="text/css">
7820: .ui-progressbar { position:relative; }
7821: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7822: </style>
7823: <script type="text/javascript">
7824: // <![CDATA[
1.1045 www 7825: var LCprogressTxt='---';
7826:
7827: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7828: LCprogressTxt=progresstext;
1.1045 www 7829: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7830: }
7831: // ]]>
7832: </script>
7833: ENDPROGRESSUPDATE
7834: }
7835:
1.1042 www 7836: my $LClastpercent;
1.1045 www 7837: my $LCidcnt;
7838: my $LCcurrentid;
1.1042 www 7839:
1.1041 www 7840: sub LCprogressbar {
1.1042 www 7841: my ($r)=(@_);
7842: $LClastpercent=0;
1.1045 www 7843: $LCidcnt++;
7844: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7845: my $starting=&mt('Starting');
7846: my $content=(<<ENDPROGBAR);
1.1045 www 7847: <div id="progressbar$LCcurrentid">
1.1041 www 7848: <span class="pblabel">$starting</span>
7849: </div>
7850: ENDPROGBAR
1.1045 www 7851: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7852: }
7853:
7854: sub LCprogressbarUpdate {
1.1042 www 7855: my ($r,$val,$text)=@_;
7856: unless ($val) {
7857: if ($LClastpercent) {
7858: $val=$LClastpercent;
7859: } else {
7860: $val=0;
7861: }
7862: }
1.1041 www 7863: if ($val<0) { $val=0; }
7864: if ($val>100) { $val=0; }
1.1042 www 7865: $LClastpercent=$val;
1.1041 www 7866: unless ($text) { $text=$val.'%'; }
7867: $text=&js_ready($text);
1.1044 www 7868: &r_print($r,<<ENDUPDATE);
1.1041 www 7869: <script type="text/javascript">
7870: // <![CDATA[
1.1045 www 7871: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7872: // ]]>
7873: </script>
7874: ENDUPDATE
1.1035 www 7875: }
7876:
1.1042 www 7877: sub LCprogressbarClose {
7878: my ($r)=@_;
7879: $LClastpercent=0;
1.1044 www 7880: &r_print($r,<<ENDCLOSE);
1.1042 www 7881: <script type="text/javascript">
7882: // <![CDATA[
1.1045 www 7883: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7884: // ]]>
7885: </script>
7886: ENDCLOSE
1.1044 www 7887: }
7888:
7889: sub r_print {
7890: my ($r,$to_print)=@_;
7891: if ($r) {
7892: $r->print($to_print);
7893: $r->rflush();
7894: } else {
7895: print($to_print);
7896: }
1.1042 www 7897: }
7898:
1.320 albertel 7899: sub html_encode {
7900: my ($result) = @_;
7901:
1.322 albertel 7902: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7903:
7904: return $result;
7905: }
1.1044 www 7906:
1.317 albertel 7907: sub js_ready {
7908: my ($result) = @_;
7909:
1.323 albertel 7910: $result =~ s/[\n\r]/ /xmsg;
7911: $result =~ s/\\/\\\\/xmsg;
7912: $result =~ s/'/\\'/xmsg;
1.372 albertel 7913: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7914:
7915: return $result;
7916: }
7917:
1.315 albertel 7918: sub validate_page {
7919: if ( exists($env{'internal.start_page'})
1.316 albertel 7920: && $env{'internal.start_page'} > 1) {
7921: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7922: $env{'internal.start_page'}.' '.
1.316 albertel 7923: $ENV{'request.filename'});
1.315 albertel 7924: }
7925: if ( exists($env{'internal.end_page'})
1.316 albertel 7926: && $env{'internal.end_page'} > 1) {
7927: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7928: $env{'internal.end_page'}.' '.
1.316 albertel 7929: $env{'request.filename'});
1.315 albertel 7930: }
7931: if ( exists($env{'internal.start_page'})
7932: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7933: &Apache::lonnet::logthis('start_page called without end_page '.
7934: $env{'request.filename'});
1.315 albertel 7935: }
7936: if ( ! exists($env{'internal.start_page'})
7937: && exists($env{'internal.end_page'})) {
1.316 albertel 7938: &Apache::lonnet::logthis('end_page called without start_page'.
7939: $env{'request.filename'});
1.315 albertel 7940: }
1.306 albertel 7941: }
1.315 albertel 7942:
1.996 www 7943:
7944: sub start_scrollbox {
1.1075.2.56 raeburn 7945: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7946: unless ($outerwidth) { $outerwidth='520px'; }
7947: unless ($width) { $width='500px'; }
7948: unless ($height) { $height='200px'; }
1.1075 raeburn 7949: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7950: if ($id ne '') {
1.1075.2.42 raeburn 7951: $table_id = ' id="table_'.$id.'"';
7952: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7953: }
1.1075 raeburn 7954: if ($bgcolor ne '') {
7955: $tdcol = "background-color: $bgcolor;";
7956: }
1.1075.2.42 raeburn 7957: my $nicescroll_js;
7958: if ($env{'browser.mobile'}) {
7959: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7960: }
1.1075 raeburn 7961: return <<"END";
1.1075.2.42 raeburn 7962: $nicescroll_js
7963:
7964: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 7965: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 7966: END
1.996 www 7967: }
7968:
7969: sub end_scrollbox {
1.1036 www 7970: return '</div></td></tr></table>';
1.996 www 7971: }
7972:
1.1075.2.42 raeburn 7973: sub nicescroll_javascript {
7974: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7975: my %options;
7976: if (ref($cursor) eq 'HASH') {
7977: %options = %{$cursor};
7978: }
7979: unless ($options{'railalign'} =~ /^left|right$/) {
7980: $options{'railalign'} = 'left';
7981: }
7982: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7983: my $function = &get_users_function();
7984: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
7985: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7986: $options{'cursorcolor'} = '#00F';
7987: }
7988: }
7989: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7990: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
7991: $options{'cursoropacity'}='1.0';
7992: }
7993: } else {
7994: $options{'cursoropacity'}='1.0';
7995: }
7996: if ($options{'cursorfixedheight'} eq 'none') {
7997: delete($options{'cursorfixedheight'});
7998: } else {
7999: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8000: }
8001: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8002: delete($options{'railoffset'});
8003: }
8004: my @niceoptions;
8005: while (my($key,$value) = each(%options)) {
8006: if ($value =~ /^\{.+\}$/) {
8007: push(@niceoptions,$key.':'.$value);
8008: } else {
8009: push(@niceoptions,$key.':"'.$value.'"');
8010: }
8011: }
8012: my $nicescroll_js = '
8013: $(document).ready(
8014: function() {
8015: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8016: }
8017: );
8018: ';
8019: if ($framecheck) {
8020: $nicescroll_js .= '
8021: function expand_div(caller) {
8022: if (top === self) {
8023: document.getElementById("'.$id.'").style.width = "auto";
8024: document.getElementById("'.$id.'").style.height = "auto";
8025: } else {
8026: try {
8027: if (parent.frames) {
8028: if (parent.frames.length > 1) {
8029: var framesrc = parent.frames[1].location.href;
8030: var currsrc = framesrc.replace(/\#.*$/,"");
8031: if ((caller == "search") || (currsrc == "'.$location.'")) {
8032: document.getElementById("'.$id.'").style.width = "auto";
8033: document.getElementById("'.$id.'").style.height = "auto";
8034: }
8035: }
8036: }
8037: } catch (e) {
8038: return;
8039: }
8040: }
8041: return;
8042: }
8043: ';
8044: }
8045: if ($needjsready) {
8046: $nicescroll_js = '
8047: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8048: } else {
8049: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8050: }
8051: return $nicescroll_js;
8052: }
8053:
1.318 albertel 8054: sub simple_error_page {
1.1075.2.49 raeburn 8055: my ($r,$title,$msg,$args) = @_;
8056: if (ref($args) eq 'HASH') {
8057: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8058: } else {
8059: $msg = &mt($msg);
8060: }
8061:
1.318 albertel 8062: my $page =
8063: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8064: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8065: &Apache::loncommon::end_page();
8066: if (ref($r)) {
8067: $r->print($page);
1.327 albertel 8068: return;
1.318 albertel 8069: }
8070: return $page;
8071: }
1.347 albertel 8072:
8073: {
1.610 albertel 8074: my @row_count;
1.961 onken 8075:
8076: sub start_data_table_count {
8077: unshift(@row_count, 0);
8078: return;
8079: }
8080:
8081: sub end_data_table_count {
8082: shift(@row_count);
8083: return;
8084: }
8085:
1.347 albertel 8086: sub start_data_table {
1.1018 raeburn 8087: my ($add_class,$id) = @_;
1.422 albertel 8088: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8089: my $table_id;
8090: if (defined($id)) {
8091: $table_id = ' id="'.$id.'"';
8092: }
1.961 onken 8093: &start_data_table_count();
1.1018 raeburn 8094: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8095: }
8096:
8097: sub end_data_table {
1.961 onken 8098: &end_data_table_count();
1.389 albertel 8099: return '</table>'."\n";;
1.347 albertel 8100: }
8101:
8102: sub start_data_table_row {
1.974 wenzelju 8103: my ($add_class, $id) = @_;
1.610 albertel 8104: $row_count[0]++;
8105: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8106: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8107: $id = (' id="'.$id.'"') unless ($id eq '');
8108: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8109: }
1.471 banghart 8110:
8111: sub continue_data_table_row {
1.974 wenzelju 8112: my ($add_class, $id) = @_;
1.610 albertel 8113: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8114: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8115: $id = (' id="'.$id.'"') unless ($id eq '');
8116: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8117: }
1.347 albertel 8118:
8119: sub end_data_table_row {
1.389 albertel 8120: return '</tr>'."\n";;
1.347 albertel 8121: }
1.367 www 8122:
1.421 albertel 8123: sub start_data_table_empty_row {
1.707 bisitz 8124: # $row_count[0]++;
1.421 albertel 8125: return '<tr class="LC_empty_row" >'."\n";;
8126: }
8127:
8128: sub end_data_table_empty_row {
8129: return '</tr>'."\n";;
8130: }
8131:
1.367 www 8132: sub start_data_table_header_row {
1.389 albertel 8133: return '<tr class="LC_header_row">'."\n";;
1.367 www 8134: }
8135:
8136: sub end_data_table_header_row {
1.389 albertel 8137: return '</tr>'."\n";;
1.367 www 8138: }
1.890 droeschl 8139:
8140: sub data_table_caption {
8141: my $caption = shift;
8142: return "<caption class=\"LC_caption\">$caption</caption>";
8143: }
1.347 albertel 8144: }
8145:
1.548 albertel 8146: =pod
8147:
8148: =item * &inhibit_menu_check($arg)
8149:
8150: Checks for a inhibitmenu state and generates output to preserve it
8151:
8152: Inputs: $arg - can be any of
8153: - undef - in which case the return value is a string
8154: to add into arguments list of a uri
8155: - 'input' - in which case the return value is a HTML
8156: <form> <input> field of type hidden to
8157: preserve the value
8158: - a url - in which case the return value is the url with
8159: the neccesary cgi args added to preserve the
8160: inhibitmenu state
8161: - a ref to a url - no return value, but the string is
8162: updated to include the neccessary cgi
8163: args to preserve the inhibitmenu state
8164:
8165: =cut
8166:
8167: sub inhibit_menu_check {
8168: my ($arg) = @_;
8169: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8170: if ($arg eq 'input') {
8171: if ($env{'form.inhibitmenu'}) {
8172: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8173: } else {
8174: return
8175: }
8176: }
8177: if ($env{'form.inhibitmenu'}) {
8178: if (ref($arg)) {
8179: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8180: } elsif ($arg eq '') {
8181: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8182: } else {
8183: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8184: }
8185: }
8186: if (!ref($arg)) {
8187: return $arg;
8188: }
8189: }
8190:
1.251 albertel 8191: ###############################################
1.182 matthew 8192:
8193: =pod
8194:
1.549 albertel 8195: =back
8196:
8197: =head1 User Information Routines
8198:
8199: =over 4
8200:
1.405 albertel 8201: =item * &get_users_function()
1.182 matthew 8202:
8203: Used by &bodytag to determine the current users primary role.
8204: Returns either 'student','coordinator','admin', or 'author'.
8205:
8206: =cut
8207:
8208: ###############################################
8209: sub get_users_function {
1.815 tempelho 8210: my $function = 'norole';
1.818 tempelho 8211: if ($env{'request.role'}=~/^(st)/) {
8212: $function='student';
8213: }
1.907 raeburn 8214: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8215: $function='coordinator';
8216: }
1.258 albertel 8217: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8218: $function='admin';
8219: }
1.826 bisitz 8220: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8221: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8222: $function='author';
8223: }
8224: return $function;
1.54 www 8225: }
1.99 www 8226:
8227: ###############################################
8228:
1.233 raeburn 8229: =pod
8230:
1.821 raeburn 8231: =item * &show_course()
8232:
8233: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8234: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8235:
8236: Inputs:
8237: None
8238:
8239: Outputs:
8240: Scalar: 1 if 'Course' to be used, 0 otherwise.
8241:
8242: =cut
8243:
8244: ###############################################
8245: sub show_course {
8246: my $course = !$env{'user.adv'};
8247: if (!$env{'user.adv'}) {
8248: foreach my $env (keys(%env)) {
8249: next if ($env !~ m/^user\.priv\./);
8250: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8251: $course = 0;
8252: last;
8253: }
8254: }
8255: }
8256: return $course;
8257: }
8258:
8259: ###############################################
8260:
8261: =pod
8262:
1.542 raeburn 8263: =item * &check_user_status()
1.274 raeburn 8264:
8265: Determines current status of supplied role for a
8266: specific user. Roles can be active, previous or future.
8267:
8268: Inputs:
8269: user's domain, user's username, course's domain,
1.375 raeburn 8270: course's number, optional section ID.
1.274 raeburn 8271:
8272: Outputs:
8273: role status: active, previous or future.
8274:
8275: =cut
8276:
8277: sub check_user_status {
1.412 raeburn 8278: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8279: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8280: my @uroles = keys %userinfo;
8281: my $srchstr;
8282: my $active_chk = 'none';
1.412 raeburn 8283: my $now = time;
1.274 raeburn 8284: if (@uroles > 0) {
1.908 raeburn 8285: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8286: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8287: } else {
1.412 raeburn 8288: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8289: }
8290: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8291: my $role_end = 0;
8292: my $role_start = 0;
8293: $active_chk = 'active';
1.412 raeburn 8294: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8295: $role_end = $1;
8296: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8297: $role_start = $1;
1.274 raeburn 8298: }
8299: }
8300: if ($role_start > 0) {
1.412 raeburn 8301: if ($now < $role_start) {
1.274 raeburn 8302: $active_chk = 'future';
8303: }
8304: }
8305: if ($role_end > 0) {
1.412 raeburn 8306: if ($now > $role_end) {
1.274 raeburn 8307: $active_chk = 'previous';
8308: }
8309: }
8310: }
8311: }
8312: return $active_chk;
8313: }
8314:
8315: ###############################################
8316:
8317: =pod
8318:
1.405 albertel 8319: =item * &get_sections()
1.233 raeburn 8320:
8321: Determines all the sections for a course including
8322: sections with students and sections containing other roles.
1.419 raeburn 8323: Incoming parameters:
8324:
8325: 1. domain
8326: 2. course number
8327: 3. reference to array containing roles for which sections should
8328: be gathered (optional).
8329: 4. reference to array containing status types for which sections
8330: should be gathered (optional).
8331:
8332: If the third argument is undefined, sections are gathered for any role.
8333: If the fourth argument is undefined, sections are gathered for any status.
8334: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8335:
1.374 raeburn 8336: Returns section hash (keys are section IDs, values are
8337: number of users in each section), subject to the
1.419 raeburn 8338: optional roles filter, optional status filter
1.233 raeburn 8339:
8340: =cut
8341:
8342: ###############################################
8343: sub get_sections {
1.419 raeburn 8344: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8345: if (!defined($cdom) || !defined($cnum)) {
8346: my $cid = $env{'request.course.id'};
8347:
8348: return if (!defined($cid));
8349:
8350: $cdom = $env{'course.'.$cid.'.domain'};
8351: $cnum = $env{'course.'.$cid.'.num'};
8352: }
8353:
8354: my %sectioncount;
1.419 raeburn 8355: my $now = time;
1.240 albertel 8356:
1.1075.2.33 raeburn 8357: my $check_students = 1;
8358: my $only_students = 0;
8359: if (ref($possible_roles) eq 'ARRAY') {
8360: if (grep(/^st$/,@{$possible_roles})) {
8361: if (@{$possible_roles} == 1) {
8362: $only_students = 1;
8363: }
8364: } else {
8365: $check_students = 0;
8366: }
8367: }
8368:
8369: if ($check_students) {
1.276 albertel 8370: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8371: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8372: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8373: my $start_index = &Apache::loncoursedata::CL_START();
8374: my $end_index = &Apache::loncoursedata::CL_END();
8375: my $status;
1.366 albertel 8376: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8377: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8378: $data->[$status_index],
8379: $data->[$start_index],
8380: $data->[$end_index]);
8381: if ($stu_status eq 'Active') {
8382: $status = 'active';
8383: } elsif ($end < $now) {
8384: $status = 'previous';
8385: } elsif ($start > $now) {
8386: $status = 'future';
8387: }
8388: if ($section ne '-1' && $section !~ /^\s*$/) {
8389: if ((!defined($possible_status)) || (($status ne '') &&
8390: (grep/^\Q$status\E$/,@{$possible_status}))) {
8391: $sectioncount{$section}++;
8392: }
1.240 albertel 8393: }
8394: }
8395: }
1.1075.2.33 raeburn 8396: if ($only_students) {
8397: return %sectioncount;
8398: }
1.240 albertel 8399: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8400: foreach my $user (sort(keys(%courseroles))) {
8401: if ($user !~ /^(\w{2})/) { next; }
8402: my ($role) = ($user =~ /^(\w{2})/);
8403: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8404: my ($section,$status);
1.240 albertel 8405: if ($role eq 'cr' &&
8406: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8407: $section=$1;
8408: }
8409: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8410: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8411: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8412: if ($end == -1 && $start == -1) {
8413: next; #deleted role
8414: }
8415: if (!defined($possible_status)) {
8416: $sectioncount{$section}++;
8417: } else {
8418: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8419: $status = 'active';
8420: } elsif ($end < $now) {
8421: $status = 'future';
8422: } elsif ($start > $now) {
8423: $status = 'previous';
8424: }
8425: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8426: $sectioncount{$section}++;
8427: }
8428: }
1.233 raeburn 8429: }
1.366 albertel 8430: return %sectioncount;
1.233 raeburn 8431: }
8432:
1.274 raeburn 8433: ###############################################
1.294 raeburn 8434:
8435: =pod
1.405 albertel 8436:
8437: =item * &get_course_users()
8438:
1.275 raeburn 8439: Retrieves usernames:domains for users in the specified course
8440: with specific role(s), and access status.
8441:
8442: Incoming parameters:
1.277 albertel 8443: 1. course domain
8444: 2. course number
8445: 3. access status: users must have - either active,
1.275 raeburn 8446: previous, future, or all.
1.277 albertel 8447: 4. reference to array of permissible roles
1.288 raeburn 8448: 5. reference to array of section restrictions (optional)
8449: 6. reference to results object (hash of hashes).
8450: 7. reference to optional userdata hash
1.609 raeburn 8451: 8. reference to optional statushash
1.630 raeburn 8452: 9. flag if privileged users (except those set to unhide in
8453: course settings) should be excluded
1.609 raeburn 8454: Keys of top level results hash are roles.
1.275 raeburn 8455: Keys of inner hashes are username:domain, with
8456: values set to access type.
1.288 raeburn 8457: Optional userdata hash returns an array with arguments in the
8458: same order as loncoursedata::get_classlist() for student data.
8459:
1.609 raeburn 8460: Optional statushash returns
8461:
1.288 raeburn 8462: Entries for end, start, section and status are blank because
8463: of the possibility of multiple values for non-student roles.
8464:
1.275 raeburn 8465: =cut
1.405 albertel 8466:
1.275 raeburn 8467: ###############################################
1.405 albertel 8468:
1.275 raeburn 8469: sub get_course_users {
1.630 raeburn 8470: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8471: my %idx = ();
1.419 raeburn 8472: my %seclists;
1.288 raeburn 8473:
8474: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8475: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8476: $idx{end} = &Apache::loncoursedata::CL_END();
8477: $idx{start} = &Apache::loncoursedata::CL_START();
8478: $idx{id} = &Apache::loncoursedata::CL_ID();
8479: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8480: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8481: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8482:
1.290 albertel 8483: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8484: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8485: my $now = time;
1.277 albertel 8486: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8487: my $match = 0;
1.412 raeburn 8488: my $secmatch = 0;
1.419 raeburn 8489: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8490: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8491: if ($section eq '') {
8492: $section = 'none';
8493: }
1.291 albertel 8494: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8495: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8496: $secmatch = 1;
8497: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8498: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8499: $secmatch = 1;
8500: }
8501: } else {
1.419 raeburn 8502: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8503: $secmatch = 1;
8504: }
1.290 albertel 8505: }
1.412 raeburn 8506: if (!$secmatch) {
8507: next;
8508: }
1.419 raeburn 8509: }
1.275 raeburn 8510: if (defined($$types{'active'})) {
1.288 raeburn 8511: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8512: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8513: $match = 1;
1.275 raeburn 8514: }
8515: }
8516: if (defined($$types{'previous'})) {
1.609 raeburn 8517: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8518: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8519: $match = 1;
1.275 raeburn 8520: }
8521: }
8522: if (defined($$types{'future'})) {
1.609 raeburn 8523: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8524: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8525: $match = 1;
1.275 raeburn 8526: }
8527: }
1.609 raeburn 8528: if ($match) {
8529: push(@{$seclists{$student}},$section);
8530: if (ref($userdata) eq 'HASH') {
8531: $$userdata{$student} = $$classlist{$student};
8532: }
8533: if (ref($statushash) eq 'HASH') {
8534: $statushash->{$student}{'st'}{$section} = $status;
8535: }
1.288 raeburn 8536: }
1.275 raeburn 8537: }
8538: }
1.412 raeburn 8539: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8540: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8541: my $now = time;
1.609 raeburn 8542: my %displaystatus = ( previous => 'Expired',
8543: active => 'Active',
8544: future => 'Future',
8545: );
1.1075.2.36 raeburn 8546: my (%nothide,@possdoms);
1.630 raeburn 8547: if ($hidepriv) {
8548: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8549: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8550: if ($user !~ /:/) {
8551: $nothide{join(':',split(/[\@]/,$user))}=1;
8552: } else {
8553: $nothide{$user} = 1;
8554: }
8555: }
1.1075.2.36 raeburn 8556: my @possdoms = ($cdom);
8557: if ($coursehash{'checkforpriv'}) {
8558: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8559: }
1.630 raeburn 8560: }
1.439 raeburn 8561: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8562: my $match = 0;
1.412 raeburn 8563: my $secmatch = 0;
1.439 raeburn 8564: my $status;
1.412 raeburn 8565: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8566: $user =~ s/:$//;
1.439 raeburn 8567: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8568: if ($end == -1 || $start == -1) {
8569: next;
8570: }
8571: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8572: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8573: my ($uname,$udom) = split(/:/,$user);
8574: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8575: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8576: $secmatch = 1;
8577: } elsif ($usec eq '') {
1.420 albertel 8578: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8579: $secmatch = 1;
8580: }
8581: } else {
8582: if (grep(/^\Q$usec\E$/,@{$sections})) {
8583: $secmatch = 1;
8584: }
8585: }
8586: if (!$secmatch) {
8587: next;
8588: }
1.288 raeburn 8589: }
1.419 raeburn 8590: if ($usec eq '') {
8591: $usec = 'none';
8592: }
1.275 raeburn 8593: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8594: if ($hidepriv) {
1.1075.2.36 raeburn 8595: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8596: (!$nothide{$uname.':'.$udom})) {
8597: next;
8598: }
8599: }
1.503 raeburn 8600: if ($end > 0 && $end < $now) {
1.439 raeburn 8601: $status = 'previous';
8602: } elsif ($start > $now) {
8603: $status = 'future';
8604: } else {
8605: $status = 'active';
8606: }
1.277 albertel 8607: foreach my $type (keys(%{$types})) {
1.275 raeburn 8608: if ($status eq $type) {
1.420 albertel 8609: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8610: push(@{$$users{$role}{$user}},$type);
8611: }
1.288 raeburn 8612: $match = 1;
8613: }
8614: }
1.419 raeburn 8615: if (($match) && (ref($userdata) eq 'HASH')) {
8616: if (!exists($$userdata{$uname.':'.$udom})) {
8617: &get_user_info($udom,$uname,\%idx,$userdata);
8618: }
1.420 albertel 8619: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8620: push(@{$seclists{$uname.':'.$udom}},$usec);
8621: }
1.609 raeburn 8622: if (ref($statushash) eq 'HASH') {
8623: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8624: }
1.275 raeburn 8625: }
8626: }
8627: }
8628: }
1.290 albertel 8629: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8630: if ((defined($cdom)) && (defined($cnum))) {
8631: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8632: if ( defined($csettings{'internal.courseowner'}) ) {
8633: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8634: next if ($owner eq '');
8635: my ($ownername,$ownerdom);
8636: if ($owner =~ /^([^:]+):([^:]+)$/) {
8637: $ownername = $1;
8638: $ownerdom = $2;
8639: } else {
8640: $ownername = $owner;
8641: $ownerdom = $cdom;
8642: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8643: }
8644: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8645: if (defined($userdata) &&
1.609 raeburn 8646: !exists($$userdata{$owner})) {
8647: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8648: if (!grep(/^none$/,@{$seclists{$owner}})) {
8649: push(@{$seclists{$owner}},'none');
8650: }
8651: if (ref($statushash) eq 'HASH') {
8652: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8653: }
1.290 albertel 8654: }
1.279 raeburn 8655: }
8656: }
8657: }
1.419 raeburn 8658: foreach my $user (keys(%seclists)) {
8659: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8660: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8661: }
1.275 raeburn 8662: }
8663: return;
8664: }
8665:
1.288 raeburn 8666: sub get_user_info {
8667: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8668: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8669: &plainname($uname,$udom,'lastname');
1.291 albertel 8670: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8671: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8672: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8673: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8674: return;
8675: }
1.275 raeburn 8676:
1.472 raeburn 8677: ###############################################
8678:
8679: =pod
8680:
8681: =item * &get_user_quota()
8682:
1.1075.2.41 raeburn 8683: Retrieves quota assigned for storage of user files.
8684: Default is to report quota for portfolio files.
1.472 raeburn 8685:
8686: Incoming parameters:
8687: 1. user's username
8688: 2. user's domain
1.1075.2.41 raeburn 8689: 3. quota name - portfolio, author, or course
8690: (if no quota name provided, defaults to portfolio).
1.1075.2.42 raeburn 8691: 4. crstype - official, unofficial or community, if quota name is
8692: course
1.472 raeburn 8693:
8694: Returns:
1.1075.2.58! raeburn 8695: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8696: 2. (Optional) Type of setting: custom or default
8697: (individually assigned or default for user's
8698: institutional status).
8699: 3. (Optional) - User's institutional status (e.g., faculty, staff
8700: or student - types as defined in localenroll::inst_usertypes
8701: for user's domain, which determines default quota for user.
8702: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8703:
8704: If a value has been stored in the user's environment,
1.536 raeburn 8705: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8706: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8707:
8708: =cut
8709:
8710: ###############################################
8711:
8712:
8713: sub get_user_quota {
1.1075.2.42 raeburn 8714: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8715: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8716: if (!defined($udom)) {
8717: $udom = $env{'user.domain'};
8718: }
8719: if (!defined($uname)) {
8720: $uname = $env{'user.name'};
8721: }
8722: if (($udom eq '' || $uname eq '') ||
8723: ($udom eq 'public') && ($uname eq 'public')) {
8724: $quota = 0;
1.536 raeburn 8725: $quotatype = 'default';
8726: $defquota = 0;
1.472 raeburn 8727: } else {
1.536 raeburn 8728: my $inststatus;
1.1075.2.41 raeburn 8729: if ($quotaname eq 'course') {
8730: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8731: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8732: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8733: } else {
8734: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8735: $quota = $cenv{'internal.uploadquota'};
8736: }
1.536 raeburn 8737: } else {
1.1075.2.41 raeburn 8738: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8739: if ($quotaname eq 'author') {
8740: $quota = $env{'environment.authorquota'};
8741: } else {
8742: $quota = $env{'environment.portfolioquota'};
8743: }
8744: $inststatus = $env{'environment.inststatus'};
8745: } else {
8746: my %userenv =
8747: &Apache::lonnet::get('environment',['portfolioquota',
8748: 'authorquota','inststatus'],$udom,$uname);
8749: my ($tmp) = keys(%userenv);
8750: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8751: if ($quotaname eq 'author') {
8752: $quota = $userenv{'authorquota'};
8753: } else {
8754: $quota = $userenv{'portfolioquota'};
8755: }
8756: $inststatus = $userenv{'inststatus'};
8757: } else {
8758: undef(%userenv);
8759: }
8760: }
8761: }
8762: if ($quota eq '' || wantarray) {
8763: if ($quotaname eq 'course') {
8764: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.42 raeburn 8765: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8766: $defquota = $domdefs{$crstype.'quota'};
8767: }
8768: if ($defquota eq '') {
8769: $defquota = 500;
8770: }
1.1075.2.41 raeburn 8771: } else {
8772: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8773: }
8774: if ($quota eq '') {
8775: $quota = $defquota;
8776: $quotatype = 'default';
8777: } else {
8778: $quotatype = 'custom';
8779: }
1.472 raeburn 8780: }
8781: }
1.536 raeburn 8782: if (wantarray) {
8783: return ($quota,$quotatype,$settingstatus,$defquota);
8784: } else {
8785: return $quota;
8786: }
1.472 raeburn 8787: }
8788:
8789: ###############################################
8790:
8791: =pod
8792:
8793: =item * &default_quota()
8794:
1.536 raeburn 8795: Retrieves default quota assigned for storage of user portfolio files,
8796: given an (optional) user's institutional status.
1.472 raeburn 8797:
8798: Incoming parameters:
1.1075.2.42 raeburn 8799:
1.472 raeburn 8800: 1. domain
1.536 raeburn 8801: 2. (Optional) institutional status(es). This is a : separated list of
8802: status types (e.g., faculty, staff, student etc.)
8803: which apply to the user for whom the default is being retrieved.
8804: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8805: default quota will be returned.
8806: 3. quota name - portfolio, author, or course
8807: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8808:
8809: Returns:
1.1075.2.42 raeburn 8810:
1.1075.2.58! raeburn 8811: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8812: 2. (Optional) institutional type which determined the value of the
8813: default quota.
1.472 raeburn 8814:
8815: If a value has been stored in the domain's configuration db,
8816: it will return that, otherwise it returns 20 (for backwards
8817: compatibility with domains which have not set up a configuration
1.1075.2.58! raeburn 8818: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8819:
1.536 raeburn 8820: If the user's status includes multiple types (e.g., staff and student),
8821: the largest default quota which applies to the user determines the
8822: default quota returned.
8823:
1.472 raeburn 8824: =cut
8825:
8826: ###############################################
8827:
8828:
8829: sub default_quota {
1.1075.2.41 raeburn 8830: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8831: my ($defquota,$settingstatus);
8832: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8833: ['quotas'],$udom);
1.1075.2.41 raeburn 8834: my $key = 'defaultquota';
8835: if ($quotaname eq 'author') {
8836: $key = 'authorquota';
8837: }
1.622 raeburn 8838: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8839: if ($inststatus ne '') {
1.765 raeburn 8840: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8841: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8842: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8843: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8844: if ($defquota eq '') {
1.1075.2.41 raeburn 8845: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8846: $settingstatus = $item;
1.1075.2.41 raeburn 8847: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8848: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8849: $settingstatus = $item;
8850: }
8851: }
1.1075.2.41 raeburn 8852: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8853: if ($quotahash{'quotas'}{$item} ne '') {
8854: if ($defquota eq '') {
8855: $defquota = $quotahash{'quotas'}{$item};
8856: $settingstatus = $item;
8857: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8858: $defquota = $quotahash{'quotas'}{$item};
8859: $settingstatus = $item;
8860: }
1.536 raeburn 8861: }
8862: }
8863: }
8864: }
8865: if ($defquota eq '') {
1.1075.2.41 raeburn 8866: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8867: $defquota = $quotahash{'quotas'}{$key}{'default'};
8868: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8869: $defquota = $quotahash{'quotas'}{'default'};
8870: }
1.536 raeburn 8871: $settingstatus = 'default';
1.1075.2.42 raeburn 8872: if ($defquota eq '') {
8873: if ($quotaname eq 'author') {
8874: $defquota = 500;
8875: }
8876: }
1.536 raeburn 8877: }
8878: } else {
8879: $settingstatus = 'default';
1.1075.2.41 raeburn 8880: if ($quotaname eq 'author') {
8881: $defquota = 500;
8882: } else {
8883: $defquota = 20;
8884: }
1.536 raeburn 8885: }
8886: if (wantarray) {
8887: return ($defquota,$settingstatus);
1.472 raeburn 8888: } else {
1.536 raeburn 8889: return $defquota;
1.472 raeburn 8890: }
8891: }
8892:
1.1075.2.41 raeburn 8893: ###############################################
8894:
8895: =pod
8896:
1.1075.2.42 raeburn 8897: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8898:
8899: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8900: of existing file within authoring space will cause quota for the authoring
8901: space to be exceeded.
8902:
8903: Same, if upload of a file directly to a course/community via Course Editor
8904: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8905:
8906: Inputs: 6
1.1075.2.42 raeburn 8907: 1. username or coursenum
1.1075.2.41 raeburn 8908: 2. domain
1.1075.2.42 raeburn 8909: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8910: 4. filename of file for which action is being requested
8911: 5. filesize (kB) of file
8912: 6. action being taken: copy or upload.
8913:
8914: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8915: otherwise return null.
8916:
1.1075.2.42 raeburn 8917: =back
8918:
1.1075.2.41 raeburn 8919: =cut
8920:
1.1075.2.42 raeburn 8921: sub excess_filesize_warning {
8922: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8923: my $current_disk_usage = 0;
8924: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8925: if ($context eq 'author') {
8926: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8927: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8928: } else {
8929: foreach my $subdir ('docs','supplemental') {
8930: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8931: }
8932: }
1.1075.2.41 raeburn 8933: $disk_quota = int($disk_quota * 1000);
8934: if (($current_disk_usage + $filesize) > $disk_quota) {
8935: return '<p><span class="LC_warning">'.
8936: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8937: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8938: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8939: $disk_quota,$current_disk_usage).
8940: '</p>';
8941: }
8942: return;
8943: }
8944:
8945: ###############################################
8946:
8947:
1.384 raeburn 8948: sub get_secgrprole_info {
8949: my ($cdom,$cnum,$needroles,$type) = @_;
8950: my %sections_count = &get_sections($cdom,$cnum);
8951: my @sections = (sort {$a <=> $b} keys(%sections_count));
8952: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8953: my @groups = sort(keys(%curr_groups));
8954: my $allroles = [];
8955: my $rolehash;
8956: my $accesshash = {
8957: active => 'Currently has access',
8958: future => 'Will have future access',
8959: previous => 'Previously had access',
8960: };
8961: if ($needroles) {
8962: $rolehash = {'all' => 'all'};
1.385 albertel 8963: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8964: if (&Apache::lonnet::error(%user_roles)) {
8965: undef(%user_roles);
8966: }
8967: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8968: my ($role)=split(/\:/,$item,2);
8969: if ($role eq 'cr') { next; }
8970: if ($role =~ /^cr/) {
8971: $$rolehash{$role} = (split('/',$role))[3];
8972: } else {
8973: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8974: }
8975: }
8976: foreach my $key (sort(keys(%{$rolehash}))) {
8977: push(@{$allroles},$key);
8978: }
8979: push (@{$allroles},'st');
8980: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8981: }
8982: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8983: }
8984:
1.555 raeburn 8985: sub user_picker {
1.994 raeburn 8986: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8987: my $currdom = $dom;
8988: my %curr_selected = (
8989: srchin => 'dom',
1.580 raeburn 8990: srchby => 'lastname',
1.555 raeburn 8991: );
8992: my $srchterm;
1.625 raeburn 8993: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8994: if ($srch->{'srchby'} ne '') {
8995: $curr_selected{'srchby'} = $srch->{'srchby'};
8996: }
8997: if ($srch->{'srchin'} ne '') {
8998: $curr_selected{'srchin'} = $srch->{'srchin'};
8999: }
9000: if ($srch->{'srchtype'} ne '') {
9001: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9002: }
9003: if ($srch->{'srchdomain'} ne '') {
9004: $currdom = $srch->{'srchdomain'};
9005: }
9006: $srchterm = $srch->{'srchterm'};
9007: }
9008: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9009: 'usr' => 'Search criteria',
1.563 raeburn 9010: 'doma' => 'Domain/institution to search',
1.558 albertel 9011: 'uname' => 'username',
9012: 'lastname' => 'last name',
1.555 raeburn 9013: 'lastfirst' => 'last name, first name',
1.558 albertel 9014: 'crs' => 'in this course',
1.576 raeburn 9015: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9016: 'alc' => 'all LON-CAPA',
1.573 raeburn 9017: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9018: 'exact' => 'is',
9019: 'contains' => 'contains',
1.569 raeburn 9020: 'begins' => 'begins with',
1.571 raeburn 9021: 'youm' => "You must include some text to search for.",
9022: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9023: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9024: 'yomc' => "You must choose a domain when using an institutional directory search.",
9025: 'ymcd' => "You must choose a domain when using a domain search.",
9026: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9027: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9028: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9029: );
1.563 raeburn 9030: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9031: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9032:
9033: my @srchins = ('crs','dom','alc','instd');
9034:
9035: foreach my $option (@srchins) {
9036: # FIXME 'alc' option unavailable until
9037: # loncreateuser::print_user_query_page()
9038: # has been completed.
9039: next if ($option eq 'alc');
1.880 raeburn 9040: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9041: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9042: if ($curr_selected{'srchin'} eq $option) {
9043: $srchinsel .= '
9044: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9045: } else {
9046: $srchinsel .= '
9047: <option value="'.$option.'">'.$lt{$option}.'</option>';
9048: }
1.555 raeburn 9049: }
1.563 raeburn 9050: $srchinsel .= "\n </select>\n";
1.555 raeburn 9051:
9052: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9053: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9054: if ($curr_selected{'srchby'} eq $option) {
9055: $srchbysel .= '
9056: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9057: } else {
9058: $srchbysel .= '
9059: <option value="'.$option.'">'.$lt{$option}.'</option>';
9060: }
9061: }
9062: $srchbysel .= "\n </select>\n";
9063:
9064: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9065: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9066: if ($curr_selected{'srchtype'} eq $option) {
9067: $srchtypesel .= '
9068: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9069: } else {
9070: $srchtypesel .= '
9071: <option value="'.$option.'">'.$lt{$option}.'</option>';
9072: }
9073: }
9074: $srchtypesel .= "\n </select>\n";
9075:
1.558 albertel 9076: my ($newuserscript,$new_user_create);
1.994 raeburn 9077: my $context_dom = $env{'request.role.domain'};
9078: if ($context eq 'requestcrs') {
9079: if ($env{'form.coursedom'} ne '') {
9080: $context_dom = $env{'form.coursedom'};
9081: }
9082: }
1.556 raeburn 9083: if ($forcenewuser) {
1.576 raeburn 9084: if (ref($srch) eq 'HASH') {
1.994 raeburn 9085: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9086: if ($cancreate) {
9087: $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>';
9088: } else {
1.799 bisitz 9089: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9090: my %usertypetext = (
9091: official => 'institutional',
9092: unofficial => 'non-institutional',
9093: );
1.799 bisitz 9094: $new_user_create = '<p class="LC_warning">'
9095: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9096: .' '
9097: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9098: ,'<a href="'.$helplink.'">','</a>')
9099: .'</p><br />';
1.627 raeburn 9100: }
1.576 raeburn 9101: }
9102: }
9103:
1.556 raeburn 9104: $newuserscript = <<"ENDSCRIPT";
9105:
1.570 raeburn 9106: function setSearch(createnew,callingForm) {
1.556 raeburn 9107: if (createnew == 1) {
1.570 raeburn 9108: for (var i=0; i<callingForm.srchby.length; i++) {
9109: if (callingForm.srchby.options[i].value == 'uname') {
9110: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9111: }
9112: }
1.570 raeburn 9113: for (var i=0; i<callingForm.srchin.length; i++) {
9114: if ( callingForm.srchin.options[i].value == 'dom') {
9115: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9116: }
9117: }
1.570 raeburn 9118: for (var i=0; i<callingForm.srchtype.length; i++) {
9119: if (callingForm.srchtype.options[i].value == 'exact') {
9120: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9121: }
9122: }
1.570 raeburn 9123: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9124: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9125: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9126: }
9127: }
9128: }
9129: }
9130: ENDSCRIPT
1.558 albertel 9131:
1.556 raeburn 9132: }
9133:
1.555 raeburn 9134: my $output = <<"END_BLOCK";
1.556 raeburn 9135: <script type="text/javascript">
1.824 bisitz 9136: // <![CDATA[
1.570 raeburn 9137: function validateEntry(callingForm) {
1.558 albertel 9138:
1.556 raeburn 9139: var checkok = 1;
1.558 albertel 9140: var srchin;
1.570 raeburn 9141: for (var i=0; i<callingForm.srchin.length; i++) {
9142: if ( callingForm.srchin[i].checked ) {
9143: srchin = callingForm.srchin[i].value;
1.558 albertel 9144: }
9145: }
9146:
1.570 raeburn 9147: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9148: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9149: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9150: var srchterm = callingForm.srchterm.value;
9151: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9152: var msg = "";
9153:
9154: if (srchterm == "") {
9155: checkok = 0;
1.571 raeburn 9156: msg += "$lt{'youm'}\\n";
1.556 raeburn 9157: }
9158:
1.569 raeburn 9159: if (srchtype== 'begins') {
9160: if (srchterm.length < 2) {
9161: checkok = 0;
1.571 raeburn 9162: msg += "$lt{'thte'}\\n";
1.569 raeburn 9163: }
9164: }
9165:
1.556 raeburn 9166: if (srchtype== 'contains') {
9167: if (srchterm.length < 3) {
9168: checkok = 0;
1.571 raeburn 9169: msg += "$lt{'thet'}\\n";
1.556 raeburn 9170: }
9171: }
9172: if (srchin == 'instd') {
9173: if (srchdomain == '') {
9174: checkok = 0;
1.571 raeburn 9175: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9176: }
9177: }
9178: if (srchin == 'dom') {
9179: if (srchdomain == '') {
9180: checkok = 0;
1.571 raeburn 9181: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9182: }
9183: }
9184: if (srchby == 'lastfirst') {
9185: if (srchterm.indexOf(",") == -1) {
9186: checkok = 0;
1.571 raeburn 9187: msg += "$lt{'whus'}\\n";
1.556 raeburn 9188: }
9189: if (srchterm.indexOf(",") == srchterm.length -1) {
9190: checkok = 0;
1.571 raeburn 9191: msg += "$lt{'whse'}\\n";
1.556 raeburn 9192: }
9193: }
9194: if (checkok == 0) {
1.571 raeburn 9195: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9196: return;
9197: }
9198: if (checkok == 1) {
1.570 raeburn 9199: callingForm.submit();
1.556 raeburn 9200: }
9201: }
9202:
9203: $newuserscript
9204:
1.824 bisitz 9205: // ]]>
1.556 raeburn 9206: </script>
1.558 albertel 9207:
9208: $new_user_create
9209:
1.555 raeburn 9210: END_BLOCK
1.558 albertel 9211:
1.876 raeburn 9212: $output .= &Apache::lonhtmlcommon::start_pick_box().
9213: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9214: $domform.
9215: &Apache::lonhtmlcommon::row_closure().
9216: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9217: $srchbysel.
9218: $srchtypesel.
9219: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9220: $srchinsel.
9221: &Apache::lonhtmlcommon::row_closure(1).
9222: &Apache::lonhtmlcommon::end_pick_box().
9223: '<br />';
1.555 raeburn 9224: return $output;
9225: }
9226:
1.612 raeburn 9227: sub user_rule_check {
1.615 raeburn 9228: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9229: my $response;
9230: if (ref($usershash) eq 'HASH') {
9231: foreach my $user (keys(%{$usershash})) {
9232: my ($uname,$udom) = split(/:/,$user);
9233: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9234: my ($id,$newuser);
1.612 raeburn 9235: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9236: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9237: $id = $usershash->{$user}->{'id'};
9238: }
9239: my $inst_response;
9240: if (ref($checks) eq 'HASH') {
9241: if (defined($checks->{'username'})) {
1.615 raeburn 9242: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9243: &Apache::lonnet::get_instuser($udom,$uname);
9244: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9245: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9246: &Apache::lonnet::get_instuser($udom,undef,$id);
9247: }
1.615 raeburn 9248: } else {
9249: ($inst_response,%{$inst_results->{$user}}) =
9250: &Apache::lonnet::get_instuser($udom,$uname);
9251: return;
1.612 raeburn 9252: }
1.615 raeburn 9253: if (!$got_rules->{$udom}) {
1.612 raeburn 9254: my %domconfig = &Apache::lonnet::get_dom('configuration',
9255: ['usercreation'],$udom);
9256: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9257: foreach my $item ('username','id') {
1.612 raeburn 9258: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9259: $$curr_rules{$udom}{$item} =
9260: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9261: }
9262: }
9263: }
1.615 raeburn 9264: $got_rules->{$udom} = 1;
1.585 raeburn 9265: }
1.612 raeburn 9266: foreach my $item (keys(%{$checks})) {
9267: if (ref($$curr_rules{$udom}) eq 'HASH') {
9268: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9269: if (@{$$curr_rules{$udom}{$item}} > 0) {
9270: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9271: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9272: if ($rule_check{$rule}) {
9273: $$rulematch{$user}{$item} = $rule;
9274: if ($inst_response eq 'ok') {
1.615 raeburn 9275: if (ref($inst_results) eq 'HASH') {
9276: if (ref($inst_results->{$user}) eq 'HASH') {
9277: if (keys(%{$inst_results->{$user}}) == 0) {
9278: $$alerts{$item}{$udom}{$uname} = 1;
9279: }
1.612 raeburn 9280: }
9281: }
1.615 raeburn 9282: }
9283: last;
1.585 raeburn 9284: }
9285: }
9286: }
9287: }
9288: }
9289: }
9290: }
9291: }
1.612 raeburn 9292: return;
9293: }
9294:
9295: sub user_rule_formats {
9296: my ($domain,$domdesc,$curr_rules,$check) = @_;
9297: my %text = (
9298: 'username' => 'Usernames',
9299: 'id' => 'IDs',
9300: );
9301: my $output;
9302: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9303: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9304: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9305: $output = '<br />'.
9306: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9307: '<span class="LC_cusr_emph">','</span>',$domdesc).
9308: ' <ul>';
1.612 raeburn 9309: foreach my $rule (@{$ruleorder}) {
9310: if (ref($curr_rules) eq 'ARRAY') {
9311: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9312: if (ref($rules->{$rule}) eq 'HASH') {
9313: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9314: $rules->{$rule}{'desc'}.'</li>';
9315: }
9316: }
9317: }
9318: }
9319: $output .= '</ul>';
9320: }
9321: }
9322: return $output;
9323: }
9324:
9325: sub instrule_disallow_msg {
1.615 raeburn 9326: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9327: my $response;
9328: my %text = (
9329: item => 'username',
9330: items => 'usernames',
9331: match => 'matches',
9332: do => 'does',
9333: action => 'a username',
9334: one => 'one',
9335: );
9336: if ($count > 1) {
9337: $text{'item'} = 'usernames';
9338: $text{'match'} ='match';
9339: $text{'do'} = 'do';
9340: $text{'action'} = 'usernames',
9341: $text{'one'} = 'ones';
9342: }
9343: if ($checkitem eq 'id') {
9344: $text{'items'} = 'IDs';
9345: $text{'item'} = 'ID';
9346: $text{'action'} = 'an ID';
1.615 raeburn 9347: if ($count > 1) {
9348: $text{'item'} = 'IDs';
9349: $text{'action'} = 'IDs';
9350: }
1.612 raeburn 9351: }
1.674 bisitz 9352: $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 9353: if ($mode eq 'upload') {
9354: if ($checkitem eq 'username') {
9355: $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'}.");
9356: } elsif ($checkitem eq 'id') {
1.674 bisitz 9357: $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 9358: }
1.669 raeburn 9359: } elsif ($mode eq 'selfcreate') {
9360: if ($checkitem eq 'id') {
9361: $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.");
9362: }
1.615 raeburn 9363: } else {
9364: if ($checkitem eq 'username') {
9365: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9366: } elsif ($checkitem eq 'id') {
9367: $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.");
9368: }
1.612 raeburn 9369: }
9370: return $response;
1.585 raeburn 9371: }
9372:
1.624 raeburn 9373: sub personal_data_fieldtitles {
9374: my %fieldtitles = &Apache::lonlocal::texthash (
9375: id => 'Student/Employee ID',
9376: permanentemail => 'E-mail address',
9377: lastname => 'Last Name',
9378: firstname => 'First Name',
9379: middlename => 'Middle Name',
9380: generation => 'Generation',
9381: gen => 'Generation',
1.765 raeburn 9382: inststatus => 'Affiliation',
1.624 raeburn 9383: );
9384: return %fieldtitles;
9385: }
9386:
1.642 raeburn 9387: sub sorted_inst_types {
9388: my ($dom) = @_;
9389: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9390: my $othertitle = &mt('All users');
9391: if ($env{'request.course.id'}) {
1.668 raeburn 9392: $othertitle = &mt('Any users');
1.642 raeburn 9393: }
9394: my @types;
9395: if (ref($order) eq 'ARRAY') {
9396: @types = @{$order};
9397: }
9398: if (@types == 0) {
9399: if (ref($usertypes) eq 'HASH') {
9400: @types = sort(keys(%{$usertypes}));
9401: }
9402: }
9403: if (keys(%{$usertypes}) > 0) {
9404: $othertitle = &mt('Other users');
9405: }
9406: return ($othertitle,$usertypes,\@types);
9407: }
9408:
1.645 raeburn 9409: sub get_institutional_codes {
9410: my ($settings,$allcourses,$LC_code) = @_;
9411: # Get complete list of course sections to update
9412: my @currsections = ();
9413: my @currxlists = ();
9414: my $coursecode = $$settings{'internal.coursecode'};
9415:
9416: if ($$settings{'internal.sectionnums'} ne '') {
9417: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9418: }
9419:
9420: if ($$settings{'internal.crosslistings'} ne '') {
9421: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9422: }
9423:
9424: if (@currxlists > 0) {
9425: foreach (@currxlists) {
9426: if (m/^([^:]+):(\w*)$/) {
9427: unless (grep/^$1$/,@{$allcourses}) {
9428: push @{$allcourses},$1;
9429: $$LC_code{$1} = $2;
9430: }
9431: }
9432: }
9433: }
9434:
9435: if (@currsections > 0) {
9436: foreach (@currsections) {
9437: if (m/^(\w+):(\w*)$/) {
9438: my $sec = $coursecode.$1;
9439: my $lc_sec = $2;
9440: unless (grep/^$sec$/,@{$allcourses}) {
9441: push @{$allcourses},$sec;
9442: $$LC_code{$sec} = $lc_sec;
9443: }
9444: }
9445: }
9446: }
9447: return;
9448: }
9449:
1.971 raeburn 9450: sub get_standard_codeitems {
9451: return ('Year','Semester','Department','Number','Section');
9452: }
9453:
1.112 bowersj2 9454: =pod
9455:
1.780 raeburn 9456: =head1 Slot Helpers
9457:
9458: =over 4
9459:
9460: =item * sorted_slots()
9461:
1.1040 raeburn 9462: Sorts an array of slot names in order of an optional sort key,
9463: default sort is by slot start time (earliest first).
1.780 raeburn 9464:
9465: Inputs:
9466:
9467: =over 4
9468:
9469: slotsarr - Reference to array of unsorted slot names.
9470:
9471: slots - Reference to hash of hash, where outer hash keys are slot names.
9472:
1.1040 raeburn 9473: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9474:
1.549 albertel 9475: =back
9476:
1.780 raeburn 9477: Returns:
9478:
9479: =over 4
9480:
1.1040 raeburn 9481: sorted - An array of slot names sorted by a specified sort key
9482: (default sort key is start time of the slot).
1.780 raeburn 9483:
9484: =back
9485:
9486: =cut
9487:
9488:
9489: sub sorted_slots {
1.1040 raeburn 9490: my ($slotsarr,$slots,$sortkey) = @_;
9491: if ($sortkey eq '') {
9492: $sortkey = 'starttime';
9493: }
1.780 raeburn 9494: my @sorted;
9495: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9496: @sorted =
9497: sort {
9498: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9499: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9500: }
9501: if (ref($slots->{$a})) { return -1;}
9502: if (ref($slots->{$b})) { return 1;}
9503: return 0;
9504: } @{$slotsarr};
9505: }
9506: return @sorted;
9507: }
9508:
1.1040 raeburn 9509: =pod
9510:
9511: =item * get_future_slots()
9512:
9513: Inputs:
9514:
9515: =over 4
9516:
9517: cnum - course number
9518:
9519: cdom - course domain
9520:
9521: now - current UNIX time
9522:
9523: symb - optional symb
9524:
9525: =back
9526:
9527: Returns:
9528:
9529: =over 4
9530:
9531: sorted_reservable - ref to array of student_schedulable slots currently
9532: reservable, ordered by end date of reservation period.
9533:
9534: reservable_now - ref to hash of student_schedulable slots currently
9535: reservable.
9536:
9537: Keys in inner hash are:
9538: (a) symb: either blank or symb to which slot use is restricted.
9539: (b) endreserve: end date of reservation period.
9540:
9541: sorted_future - ref to array of student_schedulable slots reservable in
9542: the future, ordered by start date of reservation period.
9543:
9544: future_reservable - ref to hash of student_schedulable slots reservable
9545: in the future.
9546:
9547: Keys in inner hash are:
9548: (a) symb: either blank or symb to which slot use is restricted.
9549: (b) startreserve: start date of reservation period.
9550:
9551: =back
9552:
9553: =cut
9554:
9555: sub get_future_slots {
9556: my ($cnum,$cdom,$now,$symb) = @_;
9557: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9558: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9559: foreach my $slot (keys(%slots)) {
9560: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9561: if ($symb) {
9562: next if (($slots{$slot}->{'symb'} ne '') &&
9563: ($slots{$slot}->{'symb'} ne $symb));
9564: }
9565: if (($slots{$slot}->{'starttime'} > $now) &&
9566: ($slots{$slot}->{'endtime'} > $now)) {
9567: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9568: my $userallowed = 0;
9569: if ($slots{$slot}->{'allowedsections'}) {
9570: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9571: if (!defined($env{'request.role.sec'})
9572: && grep(/^No section assigned$/,@allowed_sec)) {
9573: $userallowed=1;
9574: } else {
9575: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9576: $userallowed=1;
9577: }
9578: }
9579: unless ($userallowed) {
9580: if (defined($env{'request.course.groups'})) {
9581: my @groups = split(/:/,$env{'request.course.groups'});
9582: foreach my $group (@groups) {
9583: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9584: $userallowed=1;
9585: last;
9586: }
9587: }
9588: }
9589: }
9590: }
9591: if ($slots{$slot}->{'allowedusers'}) {
9592: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9593: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9594: if (grep(/^\Q$user\E$/,@allowed_users)) {
9595: $userallowed = 1;
9596: }
9597: }
9598: next unless($userallowed);
9599: }
9600: my $startreserve = $slots{$slot}->{'startreserve'};
9601: my $endreserve = $slots{$slot}->{'endreserve'};
9602: my $symb = $slots{$slot}->{'symb'};
9603: if (($startreserve < $now) &&
9604: (!$endreserve || $endreserve > $now)) {
9605: my $lastres = $endreserve;
9606: if (!$lastres) {
9607: $lastres = $slots{$slot}->{'starttime'};
9608: }
9609: $reservable_now{$slot} = {
9610: symb => $symb,
9611: endreserve => $lastres
9612: };
9613: } elsif (($startreserve > $now) &&
9614: (!$endreserve || $endreserve > $startreserve)) {
9615: $future_reservable{$slot} = {
9616: symb => $symb,
9617: startreserve => $startreserve
9618: };
9619: }
9620: }
9621: }
9622: my @unsorted_reservable = keys(%reservable_now);
9623: if (@unsorted_reservable > 0) {
9624: @sorted_reservable =
9625: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9626: }
9627: my @unsorted_future = keys(%future_reservable);
9628: if (@unsorted_future > 0) {
9629: @sorted_future =
9630: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9631: }
9632: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9633: }
1.780 raeburn 9634:
9635: =pod
9636:
1.1057 foxr 9637: =back
9638:
1.549 albertel 9639: =head1 HTTP Helpers
9640:
9641: =over 4
9642:
1.648 raeburn 9643: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9644:
1.258 albertel 9645: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9646: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9647: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9648:
9649: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9650: $possible_names is an ref to an array of form element names. As an example:
9651: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9652: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9653:
9654: =cut
1.1 albertel 9655:
1.6 albertel 9656: sub get_unprocessed_cgi {
1.25 albertel 9657: my ($query,$possible_names)= @_;
1.26 matthew 9658: # $Apache::lonxml::debug=1;
1.356 albertel 9659: foreach my $pair (split(/&/,$query)) {
9660: my ($name, $value) = split(/=/,$pair);
1.369 www 9661: $name = &unescape($name);
1.25 albertel 9662: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9663: $value =~ tr/+/ /;
9664: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9665: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9666: }
1.16 harris41 9667: }
1.6 albertel 9668: }
9669:
1.112 bowersj2 9670: =pod
9671:
1.648 raeburn 9672: =item * &cacheheader()
1.112 bowersj2 9673:
9674: returns cache-controlling header code
9675:
9676: =cut
9677:
1.7 albertel 9678: sub cacheheader {
1.258 albertel 9679: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9680: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9681: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9682: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9683: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9684: return $output;
1.7 albertel 9685: }
9686:
1.112 bowersj2 9687: =pod
9688:
1.648 raeburn 9689: =item * &no_cache($r)
1.112 bowersj2 9690:
9691: specifies header code to not have cache
9692:
9693: =cut
9694:
1.9 albertel 9695: sub no_cache {
1.216 albertel 9696: my ($r) = @_;
9697: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9698: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9699: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9700: $r->no_cache(1);
9701: $r->header_out("Expires" => $date);
9702: $r->header_out("Pragma" => "no-cache");
1.123 www 9703: }
9704:
9705: sub content_type {
1.181 albertel 9706: my ($r,$type,$charset) = @_;
1.299 foxr 9707: if ($r) {
9708: # Note that printout.pl calls this with undef for $r.
9709: &no_cache($r);
9710: }
1.258 albertel 9711: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9712: unless ($charset) {
9713: $charset=&Apache::lonlocal::current_encoding;
9714: }
9715: if ($charset) { $type.='; charset='.$charset; }
9716: if ($r) {
9717: $r->content_type($type);
9718: } else {
9719: print("Content-type: $type\n\n");
9720: }
1.9 albertel 9721: }
1.25 albertel 9722:
1.112 bowersj2 9723: =pod
9724:
1.648 raeburn 9725: =item * &add_to_env($name,$value)
1.112 bowersj2 9726:
1.258 albertel 9727: adds $name to the %env hash with value
1.112 bowersj2 9728: $value, if $name already exists, the entry is converted to an array
9729: reference and $value is added to the array.
9730:
9731: =cut
9732:
1.25 albertel 9733: sub add_to_env {
9734: my ($name,$value)=@_;
1.258 albertel 9735: if (defined($env{$name})) {
9736: if (ref($env{$name})) {
1.25 albertel 9737: #already have multiple values
1.258 albertel 9738: push(@{ $env{$name} },$value);
1.25 albertel 9739: } else {
9740: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9741: my $first=$env{$name};
9742: undef($env{$name});
9743: push(@{ $env{$name} },$first,$value);
1.25 albertel 9744: }
9745: } else {
1.258 albertel 9746: $env{$name}=$value;
1.25 albertel 9747: }
1.31 albertel 9748: }
1.149 albertel 9749:
9750: =pod
9751:
1.648 raeburn 9752: =item * &get_env_multiple($name)
1.149 albertel 9753:
1.258 albertel 9754: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9755: values may be defined and end up as an array ref.
9756:
9757: returns an array of values
9758:
9759: =cut
9760:
9761: sub get_env_multiple {
9762: my ($name) = @_;
9763: my @values;
1.258 albertel 9764: if (defined($env{$name})) {
1.149 albertel 9765: # exists is it an array
1.258 albertel 9766: if (ref($env{$name})) {
9767: @values=@{ $env{$name} };
1.149 albertel 9768: } else {
1.258 albertel 9769: $values[0]=$env{$name};
1.149 albertel 9770: }
9771: }
9772: return(@values);
9773: }
9774:
1.660 raeburn 9775: sub ask_for_embedded_content {
9776: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9777: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9778: %currsubfile,%unused,$rem);
1.1071 raeburn 9779: my $counter = 0;
9780: my $numnew = 0;
1.987 raeburn 9781: my $numremref = 0;
9782: my $numinvalid = 0;
9783: my $numpathchg = 0;
9784: my $numexisting = 0;
1.1071 raeburn 9785: my $numunused = 0;
9786: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9787: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9788: my $heading = &mt('Upload embedded files');
9789: my $buttontext = &mt('Upload');
9790:
1.1075.2.11 raeburn 9791: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9792: if ($actionurl eq '/adm/dependencies') {
9793: $navmap = Apache::lonnavmaps::navmap->new();
9794: }
9795: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9796: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9797: }
1.1075.2.35 raeburn 9798: if (($actionurl eq '/adm/portfolio') ||
9799: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9800: my $current_path='/';
9801: if ($env{'form.currentpath'}) {
9802: $current_path = $env{'form.currentpath'};
9803: }
9804: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9805: $udom = $cdom;
9806: $uname = $cnum;
1.984 raeburn 9807: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9808: } else {
9809: $udom = $env{'user.domain'};
9810: $uname = $env{'user.name'};
9811: $url = '/userfiles/portfolio';
9812: }
1.987 raeburn 9813: $toplevel = $url.'/';
1.984 raeburn 9814: $url .= $current_path;
9815: $getpropath = 1;
1.987 raeburn 9816: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9817: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9818: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9819: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9820: $toplevel = $url;
1.984 raeburn 9821: if ($rest ne '') {
1.987 raeburn 9822: $url .= $rest;
9823: }
9824: } elsif ($actionurl eq '/adm/coursedocs') {
9825: if (ref($args) eq 'HASH') {
1.1071 raeburn 9826: $url = $args->{'docs_url'};
9827: $toplevel = $url;
1.1075.2.11 raeburn 9828: if ($args->{'context'} eq 'paste') {
9829: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9830: ($path) =
9831: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9832: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9833: $fileloc =~ s{^/}{};
9834: }
1.1071 raeburn 9835: }
9836: } elsif ($actionurl eq '/adm/dependencies') {
9837: if ($env{'request.course.id'} ne '') {
9838: if (ref($args) eq 'HASH') {
9839: $url = $args->{'docs_url'};
9840: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9841: $toplevel = $url;
9842: unless ($toplevel =~ m{^/}) {
9843: $toplevel = "/$url";
9844: }
1.1075.2.11 raeburn 9845: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9846: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9847: $path = $1;
9848: } else {
9849: ($path) =
9850: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9851: }
1.1071 raeburn 9852: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9853: $fileloc =~ s{^/}{};
9854: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9855: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9856: }
1.987 raeburn 9857: }
1.1075.2.35 raeburn 9858: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9859: $udom = $cdom;
9860: $uname = $cnum;
9861: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9862: $toplevel = $url;
9863: $path = $url;
9864: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9865: $fileloc =~ s{^/}{};
9866: }
9867: foreach my $file (keys(%{$allfiles})) {
9868: my $embed_file;
9869: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9870: $embed_file = $1;
9871: } else {
9872: $embed_file = $file;
9873: }
1.1075.2.55 raeburn 9874: my ($absolutepath,$cleaned_file);
9875: if ($embed_file =~ m{^\w+://}) {
9876: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9877: $newfiles{$cleaned_file} = 1;
9878: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9879: } else {
1.1075.2.55 raeburn 9880: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9881: if ($embed_file =~ m{^/}) {
9882: $absolutepath = $embed_file;
9883: }
1.1075.2.47 raeburn 9884: if ($cleaned_file =~ m{/}) {
9885: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9886: $path = &check_for_traversal($path,$url,$toplevel);
9887: my $item = $fname;
9888: if ($path ne '') {
9889: $item = $path.'/'.$fname;
9890: $subdependencies{$path}{$fname} = 1;
9891: } else {
9892: $dependencies{$item} = 1;
9893: }
9894: if ($absolutepath) {
9895: $mapping{$item} = $absolutepath;
9896: } else {
9897: $mapping{$item} = $embed_file;
9898: }
9899: } else {
9900: $dependencies{$embed_file} = 1;
9901: if ($absolutepath) {
1.1075.2.47 raeburn 9902: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9903: } else {
1.1075.2.47 raeburn 9904: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9905: }
9906: }
1.984 raeburn 9907: }
9908: }
1.1071 raeburn 9909: my $dirptr = 16384;
1.984 raeburn 9910: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9911: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9912: if (($actionurl eq '/adm/portfolio') ||
9913: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9914: my ($sublistref,$listerror) =
9915: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9916: if (ref($sublistref) eq 'ARRAY') {
9917: foreach my $line (@{$sublistref}) {
9918: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9919: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9920: }
1.984 raeburn 9921: }
1.987 raeburn 9922: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9923: if (opendir(my $dir,$url.'/'.$path)) {
9924: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9925: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9926: }
1.1075.2.11 raeburn 9927: } elsif (($actionurl eq '/adm/dependencies') ||
9928: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9929: ($args->{'context'} eq 'paste')) ||
9930: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9931: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9932: my $dir;
9933: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9934: $dir = $fileloc;
9935: } else {
9936: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9937: }
1.1071 raeburn 9938: if ($dir ne '') {
9939: my ($sublistref,$listerror) =
9940: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9941: if (ref($sublistref) eq 'ARRAY') {
9942: foreach my $line (@{$sublistref}) {
9943: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9944: undef,$mtime)=split(/\&/,$line,12);
9945: unless (($testdir&$dirptr) ||
9946: ($file_name =~ /^\.\.?$/)) {
9947: $currsubfile{$path}{$file_name} = [$size,$mtime];
9948: }
9949: }
9950: }
9951: }
1.984 raeburn 9952: }
9953: }
9954: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9955: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9956: my $item = $path.'/'.$file;
9957: unless ($mapping{$item} eq $item) {
9958: $pathchanges{$item} = 1;
9959: }
9960: $existing{$item} = 1;
9961: $numexisting ++;
9962: } else {
9963: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9964: }
9965: }
1.1071 raeburn 9966: if ($actionurl eq '/adm/dependencies') {
9967: foreach my $path (keys(%currsubfile)) {
9968: if (ref($currsubfile{$path}) eq 'HASH') {
9969: foreach my $file (keys(%{$currsubfile{$path}})) {
9970: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9971: next if (($rem ne '') &&
9972: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9973: (ref($navmap) &&
9974: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9975: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9976: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9977: $unused{$path.'/'.$file} = 1;
9978: }
9979: }
9980: }
9981: }
9982: }
1.984 raeburn 9983: }
1.987 raeburn 9984: my %currfile;
1.1075.2.35 raeburn 9985: if (($actionurl eq '/adm/portfolio') ||
9986: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9987: my ($dirlistref,$listerror) =
9988: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9989: if (ref($dirlistref) eq 'ARRAY') {
9990: foreach my $line (@{$dirlistref}) {
9991: my ($file_name,$rest) = split(/\&/,$line,2);
9992: $currfile{$file_name} = 1;
9993: }
1.984 raeburn 9994: }
1.987 raeburn 9995: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9996: if (opendir(my $dir,$url)) {
1.987 raeburn 9997: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9998: map {$currfile{$_} = 1;} @dir_list;
9999: }
1.1075.2.11 raeburn 10000: } elsif (($actionurl eq '/adm/dependencies') ||
10001: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10002: ($args->{'context'} eq 'paste')) ||
10003: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10004: if ($env{'request.course.id'} ne '') {
10005: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10006: if ($dir ne '') {
10007: my ($dirlistref,$listerror) =
10008: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10009: if (ref($dirlistref) eq 'ARRAY') {
10010: foreach my $line (@{$dirlistref}) {
10011: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10012: $size,undef,$mtime)=split(/\&/,$line,12);
10013: unless (($testdir&$dirptr) ||
10014: ($file_name =~ /^\.\.?$/)) {
10015: $currfile{$file_name} = [$size,$mtime];
10016: }
10017: }
10018: }
10019: }
10020: }
1.984 raeburn 10021: }
10022: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10023: if (exists($currfile{$file})) {
1.987 raeburn 10024: unless ($mapping{$file} eq $file) {
10025: $pathchanges{$file} = 1;
10026: }
10027: $existing{$file} = 1;
10028: $numexisting ++;
10029: } else {
1.984 raeburn 10030: $newfiles{$file} = 1;
10031: }
10032: }
1.1071 raeburn 10033: foreach my $file (keys(%currfile)) {
10034: unless (($file eq $filename) ||
10035: ($file eq $filename.'.bak') ||
10036: ($dependencies{$file})) {
1.1075.2.11 raeburn 10037: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10038: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10039: next if (($rem ne '') &&
10040: (($env{"httpref.$rem".$file} ne '') ||
10041: (ref($navmap) &&
10042: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10043: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10044: ($navmap->getResourceByUrl($rem.$1)))))));
10045: }
1.1075.2.11 raeburn 10046: }
1.1071 raeburn 10047: $unused{$file} = 1;
10048: }
10049: }
1.1075.2.11 raeburn 10050: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10051: ($args->{'context'} eq 'paste')) {
10052: $counter = scalar(keys(%existing));
10053: $numpathchg = scalar(keys(%pathchanges));
10054: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10055: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10056: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10057: $counter = scalar(keys(%existing));
10058: $numpathchg = scalar(keys(%pathchanges));
10059: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10060: }
1.984 raeburn 10061: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10062: if ($actionurl eq '/adm/dependencies') {
10063: next if ($embed_file =~ m{^\w+://});
10064: }
1.660 raeburn 10065: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10066: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10067: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10068: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10069: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10070: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10071: }
1.1075.2.35 raeburn 10072: $upload_output .= '</td>';
1.1071 raeburn 10073: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10074: $upload_output.='<td align="right">'.
10075: '<span class="LC_info LC_fontsize_medium">'.
10076: &mt("URL points to web address").'</span>';
1.987 raeburn 10077: $numremref++;
1.660 raeburn 10078: } elsif ($args->{'error_on_invalid_names'}
10079: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10080: $upload_output.='<td align="right"><span class="LC_warning">'.
10081: &mt('Invalid characters').'</span>';
1.987 raeburn 10082: $numinvalid++;
1.660 raeburn 10083: } else {
1.1075.2.35 raeburn 10084: $upload_output .= '<td>'.
10085: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10086: $embed_file,\%mapping,
1.1071 raeburn 10087: $allfiles,$codebase,'upload');
10088: $counter ++;
10089: $numnew ++;
1.987 raeburn 10090: }
10091: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10092: }
10093: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10094: if ($actionurl eq '/adm/dependencies') {
10095: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10096: $modify_output .= &start_data_table_row().
10097: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10098: '<img src="'.&icon($embed_file).'" border="0" />'.
10099: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10100: '<td>'.$size.'</td>'.
10101: '<td>'.$mtime.'</td>'.
10102: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10103: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10104: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10105: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10106: &embedded_file_element('upload_embedded',$counter,
10107: $embed_file,\%mapping,
10108: $allfiles,$codebase,'modify').
10109: '</div></td>'.
10110: &end_data_table_row()."\n";
10111: $counter ++;
10112: } else {
10113: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10114: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10115: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10116: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10117: &Apache::loncommon::end_data_table_row()."\n";
10118: }
10119: }
10120: my $delidx = $counter;
10121: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10122: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10123: $delete_output .= &start_data_table_row().
10124: '<td><img src="'.&icon($oldfile).'" />'.
10125: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10126: '<td>'.$size.'</td>'.
10127: '<td>'.$mtime.'</td>'.
10128: '<td><label><input type="checkbox" name="del_upload_dep" '.
10129: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10130: &embedded_file_element('upload_embedded',$delidx,
10131: $oldfile,\%mapping,$allfiles,
10132: $codebase,'delete').'</td>'.
10133: &end_data_table_row()."\n";
10134: $numunused ++;
10135: $delidx ++;
1.987 raeburn 10136: }
10137: if ($upload_output) {
10138: $upload_output = &start_data_table().
10139: $upload_output.
10140: &end_data_table()."\n";
10141: }
1.1071 raeburn 10142: if ($modify_output) {
10143: $modify_output = &start_data_table().
10144: &start_data_table_header_row().
10145: '<th>'.&mt('File').'</th>'.
10146: '<th>'.&mt('Size (KB)').'</th>'.
10147: '<th>'.&mt('Modified').'</th>'.
10148: '<th>'.&mt('Upload replacement?').'</th>'.
10149: &end_data_table_header_row().
10150: $modify_output.
10151: &end_data_table()."\n";
10152: }
10153: if ($delete_output) {
10154: $delete_output = &start_data_table().
10155: &start_data_table_header_row().
10156: '<th>'.&mt('File').'</th>'.
10157: '<th>'.&mt('Size (KB)').'</th>'.
10158: '<th>'.&mt('Modified').'</th>'.
10159: '<th>'.&mt('Delete?').'</th>'.
10160: &end_data_table_header_row().
10161: $delete_output.
10162: &end_data_table()."\n";
10163: }
1.987 raeburn 10164: my $applies = 0;
10165: if ($numremref) {
10166: $applies ++;
10167: }
10168: if ($numinvalid) {
10169: $applies ++;
10170: }
10171: if ($numexisting) {
10172: $applies ++;
10173: }
1.1071 raeburn 10174: if ($counter || $numunused) {
1.987 raeburn 10175: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10176: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10177: $state.'<h3>'.$heading.'</h3>';
10178: if ($actionurl eq '/adm/dependencies') {
10179: if ($numnew) {
10180: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10181: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10182: $upload_output.'<br />'."\n";
10183: }
10184: if ($numexisting) {
10185: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10186: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10187: $modify_output.'<br />'."\n";
10188: $buttontext = &mt('Save changes');
10189: }
10190: if ($numunused) {
10191: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10192: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10193: $delete_output.'<br />'."\n";
10194: $buttontext = &mt('Save changes');
10195: }
10196: } else {
10197: $output .= $upload_output.'<br />'."\n";
10198: }
10199: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10200: $counter.'" />'."\n";
10201: if ($actionurl eq '/adm/dependencies') {
10202: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10203: $numnew.'" />'."\n";
10204: } elsif ($actionurl eq '') {
1.987 raeburn 10205: $output .= '<input type="hidden" name="phase" value="three" />';
10206: }
10207: } elsif ($applies) {
10208: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10209: if ($applies > 1) {
10210: $output .=
1.1075.2.35 raeburn 10211: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10212: if ($numremref) {
10213: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10214: }
10215: if ($numinvalid) {
10216: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10217: }
10218: if ($numexisting) {
10219: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10220: }
10221: $output .= '</ul><br />';
10222: } elsif ($numremref) {
10223: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10224: } elsif ($numinvalid) {
10225: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10226: } elsif ($numexisting) {
10227: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10228: }
10229: $output .= $upload_output.'<br />';
10230: }
10231: my ($pathchange_output,$chgcount);
1.1071 raeburn 10232: $chgcount = $counter;
1.987 raeburn 10233: if (keys(%pathchanges) > 0) {
10234: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10235: if ($counter) {
1.987 raeburn 10236: $output .= &embedded_file_element('pathchange',$chgcount,
10237: $embed_file,\%mapping,
1.1071 raeburn 10238: $allfiles,$codebase,'change');
1.987 raeburn 10239: } else {
10240: $pathchange_output .=
10241: &start_data_table_row().
10242: '<td><input type ="checkbox" name="namechange" value="'.
10243: $chgcount.'" checked="checked" /></td>'.
10244: '<td>'.$mapping{$embed_file}.'</td>'.
10245: '<td>'.$embed_file.
10246: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10247: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10248: '</td>'.&end_data_table_row();
1.660 raeburn 10249: }
1.987 raeburn 10250: $numpathchg ++;
10251: $chgcount ++;
1.660 raeburn 10252: }
10253: }
1.1075.2.35 raeburn 10254: if (($counter) || ($numunused)) {
1.987 raeburn 10255: if ($numpathchg) {
10256: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10257: $numpathchg.'" />'."\n";
10258: }
10259: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10260: ($actionurl eq '/adm/imsimport')) {
10261: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10262: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10263: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10264: } elsif ($actionurl eq '/adm/dependencies') {
10265: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10266: }
1.1075.2.35 raeburn 10267: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10268: } elsif ($numpathchg) {
10269: my %pathchange = ();
10270: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10271: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10272: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10273: }
1.987 raeburn 10274: }
1.1071 raeburn 10275: return ($output,$counter,$numpathchg);
1.987 raeburn 10276: }
10277:
1.1075.2.47 raeburn 10278: =pod
10279:
10280: =item * clean_path($name)
10281:
10282: Performs clean-up of directories, subdirectories and filename in an
10283: embedded object, referenced in an HTML file which is being uploaded
10284: to a course or portfolio, where
10285: "Upload embedded images/multimedia files if HTML file" checkbox was
10286: checked.
10287:
10288: Clean-up is similar to replacements in lonnet::clean_filename()
10289: except each / between sub-directory and next level is preserved.
10290:
10291: =cut
10292:
10293: sub clean_path {
10294: my ($embed_file) = @_;
10295: $embed_file =~s{^/+}{};
10296: my @contents;
10297: if ($embed_file =~ m{/}) {
10298: @contents = split(/\//,$embed_file);
10299: } else {
10300: @contents = ($embed_file);
10301: }
10302: my $lastidx = scalar(@contents)-1;
10303: for (my $i=0; $i<=$lastidx; $i++) {
10304: $contents[$i]=~s{\\}{/}g;
10305: $contents[$i]=~s/\s+/\_/g;
10306: $contents[$i]=~s{[^/\w\.\-]}{}g;
10307: if ($i == $lastidx) {
10308: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10309: }
10310: }
10311: if ($lastidx > 0) {
10312: return join('/',@contents);
10313: } else {
10314: return $contents[0];
10315: }
10316: }
10317:
1.987 raeburn 10318: sub embedded_file_element {
1.1071 raeburn 10319: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10320: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10321: (ref($codebase) eq 'HASH'));
10322: my $output;
1.1071 raeburn 10323: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10324: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10325: }
10326: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10327: &escape($embed_file).'" />';
10328: unless (($context eq 'upload_embedded') &&
10329: ($mapping->{$embed_file} eq $embed_file)) {
10330: $output .='
10331: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10332: }
10333: my $attrib;
10334: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10335: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10336: }
10337: $output .=
10338: "\n\t\t".
10339: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10340: $attrib.'" />';
10341: if (exists($codebase->{$mapping->{$embed_file}})) {
10342: $output .=
10343: "\n\t\t".
10344: '<input name="codebase_'.$num.'" type="hidden" value="'.
10345: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10346: }
1.987 raeburn 10347: return $output;
1.660 raeburn 10348: }
10349:
1.1071 raeburn 10350: sub get_dependency_details {
10351: my ($currfile,$currsubfile,$embed_file) = @_;
10352: my ($size,$mtime,$showsize,$showmtime);
10353: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10354: if ($embed_file =~ m{/}) {
10355: my ($path,$fname) = split(/\//,$embed_file);
10356: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10357: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10358: }
10359: } else {
10360: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10361: ($size,$mtime) = @{$currfile->{$embed_file}};
10362: }
10363: }
10364: $showsize = $size/1024.0;
10365: $showsize = sprintf("%.1f",$showsize);
10366: if ($mtime > 0) {
10367: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10368: }
10369: }
10370: return ($showsize,$showmtime);
10371: }
10372:
10373: sub ask_embedded_js {
10374: return <<"END";
10375: <script type="text/javascript"">
10376: // <![CDATA[
10377: function toggleBrowse(counter) {
10378: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10379: var fileid = document.getElementById('embedded_item_'+counter);
10380: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10381: if (chkboxid.checked == true) {
10382: uploaddivid.style.display='block';
10383: } else {
10384: uploaddivid.style.display='none';
10385: fileid.value = '';
10386: }
10387: }
10388: // ]]>
10389: </script>
10390:
10391: END
10392: }
10393:
1.661 raeburn 10394: sub upload_embedded {
10395: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10396: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10397: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10398: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10399: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10400: my $orig_uploaded_filename =
10401: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10402: foreach my $type ('orig','ref','attrib','codebase') {
10403: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10404: $env{'form.embedded_'.$type.'_'.$i} =
10405: &unescape($env{'form.embedded_'.$type.'_'.$i});
10406: }
10407: }
1.661 raeburn 10408: my ($path,$fname) =
10409: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10410: # no path, whole string is fname
10411: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10412: $fname = &Apache::lonnet::clean_filename($fname);
10413: # See if there is anything left
10414: next if ($fname eq '');
10415:
10416: # Check if file already exists as a file or directory.
10417: my ($state,$msg);
10418: if ($context eq 'portfolio') {
10419: my $port_path = $dirpath;
10420: if ($group ne '') {
10421: $port_path = "groups/$group/$port_path";
10422: }
1.987 raeburn 10423: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10424: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10425: $dir_root,$port_path,$disk_quota,
10426: $current_disk_usage,$uname,$udom);
10427: if ($state eq 'will_exceed_quota'
1.984 raeburn 10428: || $state eq 'file_locked') {
1.661 raeburn 10429: $output .= $msg;
10430: next;
10431: }
10432: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10433: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10434: if ($state eq 'exists') {
10435: $output .= $msg;
10436: next;
10437: }
10438: }
10439: # Check if extension is valid
10440: if (($fname =~ /\.(\w+)$/) &&
10441: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10442: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10443: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10444: next;
10445: } elsif (($fname =~ /\.(\w+)$/) &&
10446: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10447: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10448: next;
10449: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10450: $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 10451: next;
10452: }
10453: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10454: my $subdir = $path;
10455: $subdir =~ s{/+$}{};
1.661 raeburn 10456: if ($context eq 'portfolio') {
1.984 raeburn 10457: my $result;
10458: if ($state eq 'existingfile') {
10459: $result=
10460: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10461: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10462: } else {
1.984 raeburn 10463: $result=
10464: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10465: $dirpath.
1.1075.2.35 raeburn 10466: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10467: if ($result !~ m|^/uploaded/|) {
10468: $output .= '<span class="LC_error">'
10469: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10470: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10471: .'</span><br />';
10472: next;
10473: } else {
1.987 raeburn 10474: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10475: $path.$fname.'</span>').'<br />';
1.984 raeburn 10476: }
1.661 raeburn 10477: }
1.1075.2.35 raeburn 10478: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10479: my $extendedsubdir = $dirpath.'/'.$subdir;
10480: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10481: my $result =
1.1075.2.35 raeburn 10482: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10483: if ($result !~ m|^/uploaded/|) {
10484: $output .= '<span class="LC_error">'
10485: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10486: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10487: .'</span><br />';
10488: next;
10489: } else {
10490: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10491: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10492: if ($context eq 'syllabus') {
10493: &Apache::lonnet::make_public_indefinitely($result);
10494: }
1.987 raeburn 10495: }
1.661 raeburn 10496: } else {
10497: # Save the file
10498: my $target = $env{'form.embedded_item_'.$i};
10499: my $fullpath = $dir_root.$dirpath.'/'.$path;
10500: my $dest = $fullpath.$fname;
10501: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10502: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10503: my $count;
10504: my $filepath = $dir_root;
1.1027 raeburn 10505: foreach my $subdir (@parts) {
10506: $filepath .= "/$subdir";
10507: if (!-e $filepath) {
1.661 raeburn 10508: mkdir($filepath,0770);
10509: }
10510: }
10511: my $fh;
10512: if (!open($fh,'>'.$dest)) {
10513: &Apache::lonnet::logthis('Failed to create '.$dest);
10514: $output .= '<span class="LC_error">'.
1.1071 raeburn 10515: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10516: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10517: '</span><br />';
10518: } else {
10519: if (!print $fh $env{'form.embedded_item_'.$i}) {
10520: &Apache::lonnet::logthis('Failed to write to '.$dest);
10521: $output .= '<span class="LC_error">'.
1.1071 raeburn 10522: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10523: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10524: '</span><br />';
10525: } else {
1.987 raeburn 10526: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10527: $url.'</span>').'<br />';
10528: unless ($context eq 'testbank') {
10529: $footer .= &mt('View embedded file: [_1]',
10530: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10531: }
10532: }
10533: close($fh);
10534: }
10535: }
10536: if ($env{'form.embedded_ref_'.$i}) {
10537: $pathchange{$i} = 1;
10538: }
10539: }
10540: if ($output) {
10541: $output = '<p>'.$output.'</p>';
10542: }
10543: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10544: $returnflag = 'ok';
1.1071 raeburn 10545: my $numpathchgs = scalar(keys(%pathchange));
10546: if ($numpathchgs > 0) {
1.987 raeburn 10547: if ($context eq 'portfolio') {
10548: $output .= '<p>'.&mt('or').'</p>';
10549: } elsif ($context eq 'testbank') {
1.1071 raeburn 10550: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10551: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10552: $returnflag = 'modify_orightml';
10553: }
10554: }
1.1071 raeburn 10555: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10556: }
10557:
10558: sub modify_html_form {
10559: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10560: my $end = 0;
10561: my $modifyform;
10562: if ($context eq 'upload_embedded') {
10563: return unless (ref($pathchange) eq 'HASH');
10564: if ($env{'form.number_embedded_items'}) {
10565: $end += $env{'form.number_embedded_items'};
10566: }
10567: if ($env{'form.number_pathchange_items'}) {
10568: $end += $env{'form.number_pathchange_items'};
10569: }
10570: if ($end) {
10571: for (my $i=0; $i<$end; $i++) {
10572: if ($i < $env{'form.number_embedded_items'}) {
10573: next unless($pathchange->{$i});
10574: }
10575: $modifyform .=
10576: &start_data_table_row().
10577: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10578: 'checked="checked" /></td>'.
10579: '<td>'.$env{'form.embedded_ref_'.$i}.
10580: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10581: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10582: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10583: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10584: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10585: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10586: '<td>'.$env{'form.embedded_orig_'.$i}.
10587: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10588: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10589: &end_data_table_row();
1.1071 raeburn 10590: }
1.987 raeburn 10591: }
10592: } else {
10593: $modifyform = $pathchgtable;
10594: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10595: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10596: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10597: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10598: }
10599: }
10600: if ($modifyform) {
1.1071 raeburn 10601: if ($actionurl eq '/adm/dependencies') {
10602: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10603: }
1.987 raeburn 10604: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10605: '<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".
10606: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10607: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10608: '</ol></p>'."\n".'<p>'.
10609: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10610: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10611: &start_data_table()."\n".
10612: &start_data_table_header_row().
10613: '<th>'.&mt('Change?').'</th>'.
10614: '<th>'.&mt('Current reference').'</th>'.
10615: '<th>'.&mt('Required reference').'</th>'.
10616: &end_data_table_header_row()."\n".
10617: $modifyform.
10618: &end_data_table().'<br />'."\n".$hiddenstate.
10619: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10620: '</form>'."\n";
10621: }
10622: return;
10623: }
10624:
10625: sub modify_html_refs {
1.1075.2.35 raeburn 10626: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10627: my $container;
10628: if ($context eq 'portfolio') {
10629: $container = $env{'form.container'};
10630: } elsif ($context eq 'coursedoc') {
10631: $container = $env{'form.primaryurl'};
1.1071 raeburn 10632: } elsif ($context eq 'manage_dependencies') {
10633: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10634: $container = "/$container";
1.1075.2.35 raeburn 10635: } elsif ($context eq 'syllabus') {
10636: $container = $url;
1.987 raeburn 10637: } else {
1.1027 raeburn 10638: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10639: }
10640: my (%allfiles,%codebase,$output,$content);
10641: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10642: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10643: if (wantarray) {
10644: return ('',0,0);
10645: } else {
10646: return;
10647: }
10648: }
10649: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10650: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10651: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10652: if (wantarray) {
10653: return ('',0,0);
10654: } else {
10655: return;
10656: }
10657: }
1.987 raeburn 10658: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10659: if ($content eq '-1') {
10660: if (wantarray) {
10661: return ('',0,0);
10662: } else {
10663: return;
10664: }
10665: }
1.987 raeburn 10666: } else {
1.1071 raeburn 10667: unless ($container =~ /^\Q$dir_root\E/) {
10668: if (wantarray) {
10669: return ('',0,0);
10670: } else {
10671: return;
10672: }
10673: }
1.987 raeburn 10674: if (open(my $fh,"<$container")) {
10675: $content = join('', <$fh>);
10676: close($fh);
10677: } else {
1.1071 raeburn 10678: if (wantarray) {
10679: return ('',0,0);
10680: } else {
10681: return;
10682: }
1.987 raeburn 10683: }
10684: }
10685: my ($count,$codebasecount) = (0,0);
10686: my $mm = new File::MMagic;
10687: my $mime_type = $mm->checktype_contents($content);
10688: if ($mime_type eq 'text/html') {
10689: my $parse_result =
10690: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10691: \%codebase,\$content);
10692: if ($parse_result eq 'ok') {
10693: foreach my $i (@changes) {
10694: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10695: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10696: if ($allfiles{$ref}) {
10697: my $newname = $orig;
10698: my ($attrib_regexp,$codebase);
1.1006 raeburn 10699: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10700: if ($attrib_regexp =~ /:/) {
10701: $attrib_regexp =~ s/\:/|/g;
10702: }
10703: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10704: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10705: $count += $numchg;
1.1075.2.35 raeburn 10706: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10707: delete($allfiles{$ref});
1.987 raeburn 10708: }
10709: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10710: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10711: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10712: $codebasecount ++;
10713: }
10714: }
10715: }
1.1075.2.35 raeburn 10716: my $skiprewrites;
1.987 raeburn 10717: if ($count || $codebasecount) {
10718: my $saveresult;
1.1071 raeburn 10719: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10720: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10721: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10722: if ($url eq $container) {
10723: my ($fname) = ($container =~ m{/([^/]+)$});
10724: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10725: $count,'<span class="LC_filename">'.
1.1071 raeburn 10726: $fname.'</span>').'</p>';
1.987 raeburn 10727: } else {
10728: $output = '<p class="LC_error">'.
10729: &mt('Error: update failed for: [_1].',
10730: '<span class="LC_filename">'.
10731: $container.'</span>').'</p>';
10732: }
1.1075.2.35 raeburn 10733: if ($context eq 'syllabus') {
10734: unless ($saveresult eq 'ok') {
10735: $skiprewrites = 1;
10736: }
10737: }
1.987 raeburn 10738: } else {
10739: if (open(my $fh,">$container")) {
10740: print $fh $content;
10741: close($fh);
10742: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10743: $count,'<span class="LC_filename">'.
10744: $container.'</span>').'</p>';
1.661 raeburn 10745: } else {
1.987 raeburn 10746: $output = '<p class="LC_error">'.
10747: &mt('Error: could not update [_1].',
10748: '<span class="LC_filename">'.
10749: $container.'</span>').'</p>';
1.661 raeburn 10750: }
10751: }
10752: }
1.1075.2.35 raeburn 10753: if (($context eq 'syllabus') && (!$skiprewrites)) {
10754: my ($actionurl,$state);
10755: $actionurl = "/public/$udom/$uname/syllabus";
10756: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10757: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10758: \%codebase,
10759: {'context' => 'rewrites',
10760: 'ignore_remote_references' => 1,});
10761: if (ref($mapping) eq 'HASH') {
10762: my $rewrites = 0;
10763: foreach my $key (keys(%{$mapping})) {
10764: next if ($key =~ m{^https?://});
10765: my $ref = $mapping->{$key};
10766: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10767: my $attrib;
10768: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10769: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10770: }
10771: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10772: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10773: $rewrites += $numchg;
10774: }
10775: }
10776: if ($rewrites) {
10777: my $saveresult;
10778: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10779: if ($url eq $container) {
10780: my ($fname) = ($container =~ m{/([^/]+)$});
10781: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10782: $count,'<span class="LC_filename">'.
10783: $fname.'</span>').'</p>';
10784: } else {
10785: $output .= '<p class="LC_error">'.
10786: &mt('Error: could not update links in [_1].',
10787: '<span class="LC_filename">'.
10788: $container.'</span>').'</p>';
10789:
10790: }
10791: }
10792: }
10793: }
1.987 raeburn 10794: } else {
10795: &logthis('Failed to parse '.$container.
10796: ' to modify references: '.$parse_result);
1.661 raeburn 10797: }
10798: }
1.1071 raeburn 10799: if (wantarray) {
10800: return ($output,$count,$codebasecount);
10801: } else {
10802: return $output;
10803: }
1.661 raeburn 10804: }
10805:
10806: sub check_for_existing {
10807: my ($path,$fname,$element) = @_;
10808: my ($state,$msg);
10809: if (-d $path.'/'.$fname) {
10810: $state = 'exists';
10811: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10812: } elsif (-e $path.'/'.$fname) {
10813: $state = 'exists';
10814: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10815: }
10816: if ($state eq 'exists') {
10817: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10818: }
10819: return ($state,$msg);
10820: }
10821:
10822: sub check_for_upload {
10823: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10824: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10825: my $filesize = length($env{'form.'.$element});
10826: if (!$filesize) {
10827: my $msg = '<span class="LC_error">'.
10828: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10829: '<span class="LC_filename">'.$fname.'</span>',
10830: $filesize).'<br />'.
1.1007 raeburn 10831: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10832: '</span>';
10833: return ('zero_bytes',$msg);
10834: }
10835: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10836: my $getpropath = 1;
1.1021 raeburn 10837: my ($dirlistref,$listerror) =
10838: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10839: my $found_file = 0;
10840: my $locked_file = 0;
1.991 raeburn 10841: my @lockers;
10842: my $navmap;
10843: if ($env{'request.course.id'}) {
10844: $navmap = Apache::lonnavmaps::navmap->new();
10845: }
1.1021 raeburn 10846: if (ref($dirlistref) eq 'ARRAY') {
10847: foreach my $line (@{$dirlistref}) {
10848: my ($file_name,$rest)=split(/\&/,$line,2);
10849: if ($file_name eq $fname){
10850: $file_name = $path.$file_name;
10851: if ($group ne '') {
10852: $file_name = $group.$file_name;
10853: }
10854: $found_file = 1;
10855: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10856: foreach my $lock (@lockers) {
10857: if (ref($lock) eq 'ARRAY') {
10858: my ($symb,$crsid) = @{$lock};
10859: if ($crsid eq $env{'request.course.id'}) {
10860: if (ref($navmap)) {
10861: my $res = $navmap->getBySymb($symb);
10862: foreach my $part (@{$res->parts()}) {
10863: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10864: unless (($slot_status == $res->RESERVED) ||
10865: ($slot_status == $res->RESERVED_LOCATION)) {
10866: $locked_file = 1;
10867: }
1.991 raeburn 10868: }
1.1021 raeburn 10869: } else {
10870: $locked_file = 1;
1.991 raeburn 10871: }
10872: } else {
10873: $locked_file = 1;
10874: }
10875: }
1.1021 raeburn 10876: }
10877: } else {
10878: my @info = split(/\&/,$rest);
10879: my $currsize = $info[6]/1000;
10880: if ($currsize < $filesize) {
10881: my $extra = $filesize - $currsize;
10882: if (($current_disk_usage + $extra) > $disk_quota) {
10883: my $msg = '<span class="LC_error">'.
10884: &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.',
10885: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10886: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10887: $disk_quota,$current_disk_usage);
10888: return ('will_exceed_quota',$msg);
10889: }
1.984 raeburn 10890: }
10891: }
1.661 raeburn 10892: }
10893: }
10894: }
10895: if (($current_disk_usage + $filesize) > $disk_quota){
10896: my $msg = '<span class="LC_error">'.
10897: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10898: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10899: return ('will_exceed_quota',$msg);
10900: } elsif ($found_file) {
10901: if ($locked_file) {
10902: my $msg = '<span class="LC_error">';
10903: $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>');
10904: $msg .= '</span><br />';
10905: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10906: return ('file_locked',$msg);
10907: } else {
10908: my $msg = '<span class="LC_error">';
1.984 raeburn 10909: $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 10910: $msg .= '</span>';
1.984 raeburn 10911: return ('existingfile',$msg);
1.661 raeburn 10912: }
10913: }
10914: }
10915:
1.987 raeburn 10916: sub check_for_traversal {
10917: my ($path,$url,$toplevel) = @_;
10918: my @parts=split(/\//,$path);
10919: my $cleanpath;
10920: my $fullpath = $url;
10921: for (my $i=0;$i<@parts;$i++) {
10922: next if ($parts[$i] eq '.');
10923: if ($parts[$i] eq '..') {
10924: $fullpath =~ s{([^/]+/)$}{};
10925: } else {
10926: $fullpath .= $parts[$i].'/';
10927: }
10928: }
10929: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10930: $cleanpath = $1;
10931: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10932: my $curr_toprel = $1;
10933: my @parts = split(/\//,$curr_toprel);
10934: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10935: my @urlparts = split(/\//,$url_toprel);
10936: my $doubledots;
10937: my $startdiff = -1;
10938: for (my $i=0; $i<@urlparts; $i++) {
10939: if ($startdiff == -1) {
10940: unless ($urlparts[$i] eq $parts[$i]) {
10941: $startdiff = $i;
10942: $doubledots .= '../';
10943: }
10944: } else {
10945: $doubledots .= '../';
10946: }
10947: }
10948: if ($startdiff > -1) {
10949: $cleanpath = $doubledots;
10950: for (my $i=$startdiff; $i<@parts; $i++) {
10951: $cleanpath .= $parts[$i].'/';
10952: }
10953: }
10954: }
10955: $cleanpath =~ s{(/)$}{};
10956: return $cleanpath;
10957: }
1.31 albertel 10958:
1.1053 raeburn 10959: sub is_archive_file {
10960: my ($mimetype) = @_;
10961: if (($mimetype eq 'application/octet-stream') ||
10962: ($mimetype eq 'application/x-stuffit') ||
10963: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10964: return 1;
10965: }
10966: return;
10967: }
10968:
10969: sub decompress_form {
1.1065 raeburn 10970: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10971: my %lt = &Apache::lonlocal::texthash (
10972: this => 'This file is an archive file.',
1.1067 raeburn 10973: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10974: itsc => 'Its contents are as follows:',
1.1053 raeburn 10975: youm => 'You may wish to extract its contents.',
10976: extr => 'Extract contents',
1.1067 raeburn 10977: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10978: proa => 'Process automatically?',
1.1053 raeburn 10979: yes => 'Yes',
10980: no => 'No',
1.1067 raeburn 10981: fold => 'Title for folder containing movie',
10982: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10983: );
1.1065 raeburn 10984: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10985: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10986: my $info = &list_archive_contents($fileloc,\@paths);
10987: if (@paths) {
10988: foreach my $path (@paths) {
10989: $path =~ s{^/}{};
1.1067 raeburn 10990: if ($path =~ m{^([^/]+)/$}) {
10991: $topdir = $1;
10992: }
1.1065 raeburn 10993: if ($path =~ m{^([^/]+)/}) {
10994: $toplevel{$1} = $path;
10995: } else {
10996: $toplevel{$path} = $path;
10997: }
10998: }
10999: }
1.1067 raeburn 11000: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
11001: my @camtasia = ("$topdir/","$topdir/index.html",
11002: "$topdir/media/",
11003: "$topdir/media/$topdir.mp4",
11004: "$topdir/media/FirstFrame.png",
11005: "$topdir/media/player.swf",
11006: "$topdir/media/swfobject.js",
11007: "$topdir/media/expressInstall.swf");
11008: my @diffs = &compare_arrays(\@paths,\@camtasia);
11009: if (@diffs == 0) {
11010: $is_camtasia = 1;
11011: }
11012: }
11013: my $output;
11014: if ($is_camtasia) {
11015: $output = <<"ENDCAM";
11016: <script type="text/javascript" language="Javascript">
11017: // <![CDATA[
11018:
11019: function camtasiaToggle() {
11020: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11021: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
11022: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
11023:
11024: document.getElementById('camtasia_titles').style.display='block';
11025: } else {
11026: document.getElementById('camtasia_titles').style.display='none';
11027: }
11028: }
11029: }
11030: return;
11031: }
11032:
11033: // ]]>
11034: </script>
11035: <p>$lt{'camt'}</p>
11036: ENDCAM
1.1065 raeburn 11037: } else {
1.1067 raeburn 11038: $output = '<p>'.$lt{'this'};
11039: if ($info eq '') {
11040: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11041: } else {
11042: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11043: '<div><pre>'.$info.'</pre></div>';
11044: }
1.1065 raeburn 11045: }
1.1067 raeburn 11046: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11047: my $duplicates;
11048: my $num = 0;
11049: if (ref($dirlist) eq 'ARRAY') {
11050: foreach my $item (@{$dirlist}) {
11051: if (ref($item) eq 'ARRAY') {
11052: if (exists($toplevel{$item->[0]})) {
11053: $duplicates .=
11054: &start_data_table_row().
11055: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11056: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11057: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11058: 'value="1" />'.&mt('Yes').'</label>'.
11059: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11060: '<td>'.$item->[0].'</td>';
11061: if ($item->[2]) {
11062: $duplicates .= '<td>'.&mt('Directory').'</td>';
11063: } else {
11064: $duplicates .= '<td>'.&mt('File').'</td>';
11065: }
11066: $duplicates .= '<td>'.$item->[3].'</td>'.
11067: '<td>'.
11068: &Apache::lonlocal::locallocaltime($item->[4]).
11069: '</td>'.
11070: &end_data_table_row();
11071: $num ++;
11072: }
11073: }
11074: }
11075: }
11076: my $itemcount;
11077: if (@paths > 0) {
11078: $itemcount = scalar(@paths);
11079: } else {
11080: $itemcount = 1;
11081: }
1.1067 raeburn 11082: if ($is_camtasia) {
11083: $output .= $lt{'auto'}.'<br />'.
11084: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
11085: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
11086: $lt{'yes'}.'</label> <label>'.
11087: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11088: $lt{'no'}.'</label></span><br />'.
11089: '<div id="camtasia_titles" style="display:block">'.
11090: &Apache::lonhtmlcommon::start_pick_box().
11091: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11092: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11093: &Apache::lonhtmlcommon::row_closure().
11094: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11095: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11096: &Apache::lonhtmlcommon::row_closure(1).
11097: &Apache::lonhtmlcommon::end_pick_box().
11098: '</div>';
11099: }
1.1065 raeburn 11100: $output .=
11101: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11102: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11103: "\n";
1.1065 raeburn 11104: if ($duplicates ne '') {
11105: $output .= '<p><span class="LC_warning">'.
11106: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11107: &start_data_table().
11108: &start_data_table_header_row().
11109: '<th>'.&mt('Overwrite?').'</th>'.
11110: '<th>'.&mt('Name').'</th>'.
11111: '<th>'.&mt('Type').'</th>'.
11112: '<th>'.&mt('Size').'</th>'.
11113: '<th>'.&mt('Last modified').'</th>'.
11114: &end_data_table_header_row().
11115: $duplicates.
11116: &end_data_table().
11117: '</p>';
11118: }
1.1067 raeburn 11119: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11120: if (ref($hiddenelements) eq 'HASH') {
11121: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11122: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11123: }
11124: }
11125: $output .= <<"END";
1.1067 raeburn 11126: <br />
1.1053 raeburn 11127: <input type="submit" name="decompress" value="$lt{'extr'}" />
11128: </form>
11129: $noextract
11130: END
11131: return $output;
11132: }
11133:
1.1065 raeburn 11134: sub decompression_utility {
11135: my ($program) = @_;
11136: my @utilities = ('tar','gunzip','bunzip2','unzip');
11137: my $location;
11138: if (grep(/^\Q$program\E$/,@utilities)) {
11139: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11140: '/usr/sbin/') {
11141: if (-x $dir.$program) {
11142: $location = $dir.$program;
11143: last;
11144: }
11145: }
11146: }
11147: return $location;
11148: }
11149:
11150: sub list_archive_contents {
11151: my ($file,$pathsref) = @_;
11152: my (@cmd,$output);
11153: my $needsregexp;
11154: if ($file =~ /\.zip$/) {
11155: @cmd = (&decompression_utility('unzip'),"-l");
11156: $needsregexp = 1;
11157: } elsif (($file =~ m/\.tar\.gz$/) ||
11158: ($file =~ /\.tgz$/)) {
11159: @cmd = (&decompression_utility('tar'),"-ztf");
11160: } elsif ($file =~ /\.tar\.bz2$/) {
11161: @cmd = (&decompression_utility('tar'),"-jtf");
11162: } elsif ($file =~ m|\.tar$|) {
11163: @cmd = (&decompression_utility('tar'),"-tf");
11164: }
11165: if (@cmd) {
11166: undef($!);
11167: undef($@);
11168: if (open(my $fh,"-|", @cmd, $file)) {
11169: while (my $line = <$fh>) {
11170: $output .= $line;
11171: chomp($line);
11172: my $item;
11173: if ($needsregexp) {
11174: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11175: } else {
11176: $item = $line;
11177: }
11178: if ($item ne '') {
11179: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11180: push(@{$pathsref},$item);
11181: }
11182: }
11183: }
11184: close($fh);
11185: }
11186: }
11187: return $output;
11188: }
11189:
1.1053 raeburn 11190: sub decompress_uploaded_file {
11191: my ($file,$dir) = @_;
11192: &Apache::lonnet::appenv({'cgi.file' => $file});
11193: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11194: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11195: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11196: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11197: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11198: my $decompressed = $env{'cgi.decompressed'};
11199: &Apache::lonnet::delenv('cgi.file');
11200: &Apache::lonnet::delenv('cgi.dir');
11201: &Apache::lonnet::delenv('cgi.decompressed');
11202: return ($decompressed,$result);
11203: }
11204:
1.1055 raeburn 11205: sub process_decompression {
11206: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11207: my ($dir,$error,$warning,$output);
11208: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34 raeburn 11209: $error = &mt('Filename not a supported archive file type.').
11210: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11211: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11212: } else {
11213: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11214: if ($docuhome eq 'no_host') {
11215: $error = &mt('Could not determine home server for course.');
11216: } else {
11217: my @ids=&Apache::lonnet::current_machine_ids();
11218: my $currdir = "$dir_root/$destination";
11219: if (grep(/^\Q$docuhome\E$/,@ids)) {
11220: $dir = &LONCAPA::propath($docudom,$docuname).
11221: "$dir_root/$destination";
11222: } else {
11223: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11224: "$dir_root/$docudom/$docuname/$destination";
11225: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11226: $error = &mt('Archive file not found.');
11227: }
11228: }
1.1065 raeburn 11229: my (@to_overwrite,@to_skip);
11230: if ($env{'form.archive_overwrite_total'} > 0) {
11231: my $total = $env{'form.archive_overwrite_total'};
11232: for (my $i=0; $i<$total; $i++) {
11233: if ($env{'form.archive_overwrite_'.$i} == 1) {
11234: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11235: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11236: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11237: }
11238: }
11239: }
11240: my $numskip = scalar(@to_skip);
11241: if (($numskip > 0) &&
11242: ($numskip == $env{'form.archive_itemcount'})) {
11243: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11244: } elsif ($dir eq '') {
1.1055 raeburn 11245: $error = &mt('Directory containing archive file unavailable.');
11246: } elsif (!$error) {
1.1065 raeburn 11247: my ($decompressed,$display);
11248: if ($numskip > 0) {
11249: my $tempdir = time.'_'.$$.int(rand(10000));
11250: mkdir("$dir/$tempdir",0755);
11251: system("mv $dir/$file $dir/$tempdir/$file");
11252: ($decompressed,$display) =
11253: &decompress_uploaded_file($file,"$dir/$tempdir");
11254: foreach my $item (@to_skip) {
11255: if (($item ne '') && ($item !~ /\.\./)) {
11256: if (-f "$dir/$tempdir/$item") {
11257: unlink("$dir/$tempdir/$item");
11258: } elsif (-d "$dir/$tempdir/$item") {
11259: system("rm -rf $dir/$tempdir/$item");
11260: }
11261: }
11262: }
11263: system("mv $dir/$tempdir/* $dir");
11264: rmdir("$dir/$tempdir");
11265: } else {
11266: ($decompressed,$display) =
11267: &decompress_uploaded_file($file,$dir);
11268: }
1.1055 raeburn 11269: if ($decompressed eq 'ok') {
1.1065 raeburn 11270: $output = '<p class="LC_info">'.
11271: &mt('Files extracted successfully from archive.').
11272: '</p>'."\n";
1.1055 raeburn 11273: my ($warning,$result,@contents);
11274: my ($newdirlistref,$newlisterror) =
11275: &Apache::lonnet::dirlist($currdir,$docudom,
11276: $docuname,1);
11277: my (%is_dir,%changes,@newitems);
11278: my $dirptr = 16384;
1.1065 raeburn 11279: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11280: foreach my $dir_line (@{$newdirlistref}) {
11281: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11282: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11283: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11284: push(@newitems,$item);
11285: if ($dirptr&$testdir) {
11286: $is_dir{$item} = 1;
11287: }
11288: $changes{$item} = 1;
11289: }
11290: }
11291: }
11292: if (keys(%changes) > 0) {
11293: foreach my $item (sort(@newitems)) {
11294: if ($changes{$item}) {
11295: push(@contents,$item);
11296: }
11297: }
11298: }
11299: if (@contents > 0) {
1.1067 raeburn 11300: my $wantform;
11301: unless ($env{'form.autoextract_camtasia'}) {
11302: $wantform = 1;
11303: }
1.1056 raeburn 11304: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11305: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11306: $currdir,\%is_dir,
11307: \%children,\%parent,
1.1056 raeburn 11308: \@contents,\%dirorder,
11309: \%titles,$wantform);
1.1055 raeburn 11310: if ($datatable ne '') {
11311: $output .= &archive_options_form('decompressed',$datatable,
11312: $count,$hiddenelem);
1.1065 raeburn 11313: my $startcount = 6;
1.1055 raeburn 11314: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11315: \%titles,\%children);
1.1055 raeburn 11316: }
1.1067 raeburn 11317: if ($env{'form.autoextract_camtasia'}) {
11318: my %displayed;
11319: my $total = 1;
11320: $env{'form.archive_directory'} = [];
11321: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11322: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11323: $path =~ s{/$}{};
11324: my $item;
11325: if ($path ne '') {
11326: $item = "$path/$titles{$i}";
11327: } else {
11328: $item = $titles{$i};
11329: }
11330: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11331: if ($item eq $contents[0]) {
11332: push(@{$env{'form.archive_directory'}},$i);
11333: $env{'form.archive_'.$i} = 'display';
11334: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11335: $displayed{'folder'} = $i;
11336: } elsif ($item eq "$contents[0]/index.html") {
11337: $env{'form.archive_'.$i} = 'display';
11338: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11339: $displayed{'web'} = $i;
11340: } else {
11341: if ($item eq "$contents[0]/media") {
11342: push(@{$env{'form.archive_directory'}},$i);
11343: }
11344: $env{'form.archive_'.$i} = 'dependency';
11345: }
11346: $total ++;
11347: }
11348: for (my $i=1; $i<$total; $i++) {
11349: next if ($i == $displayed{'web'});
11350: next if ($i == $displayed{'folder'});
11351: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11352: }
11353: $env{'form.phase'} = 'decompress_cleanup';
11354: $env{'form.archivedelete'} = 1;
11355: $env{'form.archive_count'} = $total-1;
11356: $output .=
11357: &process_extracted_files('coursedocs',$docudom,
11358: $docuname,$destination,
11359: $dir_root,$hiddenelem);
11360: }
1.1055 raeburn 11361: } else {
11362: $warning = &mt('No new items extracted from archive file.');
11363: }
11364: } else {
11365: $output = $display;
11366: $error = &mt('An error occurred during extraction from the archive file.');
11367: }
11368: }
11369: }
11370: }
11371: if ($error) {
11372: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11373: $error.'</p>'."\n";
11374: }
11375: if ($warning) {
11376: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11377: }
11378: return $output;
11379: }
11380:
11381: sub get_extracted {
1.1056 raeburn 11382: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11383: $titles,$wantform) = @_;
1.1055 raeburn 11384: my $count = 0;
11385: my $depth = 0;
11386: my $datatable;
1.1056 raeburn 11387: my @hierarchy;
1.1055 raeburn 11388: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11389: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11390: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11391: foreach my $item (@{$contents}) {
11392: $count ++;
1.1056 raeburn 11393: @{$dirorder->{$count}} = @hierarchy;
11394: $titles->{$count} = $item;
1.1055 raeburn 11395: &archive_hierarchy($depth,$count,$parent,$children);
11396: if ($wantform) {
11397: $datatable .= &archive_row($is_dir->{$item},$item,
11398: $currdir,$depth,$count);
11399: }
11400: if ($is_dir->{$item}) {
11401: $depth ++;
1.1056 raeburn 11402: push(@hierarchy,$count);
11403: $parent->{$depth} = $count;
1.1055 raeburn 11404: $datatable .=
11405: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11406: \$depth,\$count,\@hierarchy,$dirorder,
11407: $children,$parent,$titles,$wantform);
1.1055 raeburn 11408: $depth --;
1.1056 raeburn 11409: pop(@hierarchy);
1.1055 raeburn 11410: }
11411: }
11412: return ($count,$datatable);
11413: }
11414:
11415: sub recurse_extracted_archive {
1.1056 raeburn 11416: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11417: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11418: my $result='';
1.1056 raeburn 11419: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11420: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11421: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11422: return $result;
11423: }
11424: my $dirptr = 16384;
11425: my ($newdirlistref,$newlisterror) =
11426: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11427: if (ref($newdirlistref) eq 'ARRAY') {
11428: foreach my $dir_line (@{$newdirlistref}) {
11429: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11430: unless ($item =~ /^\.+$/) {
11431: $$count ++;
1.1056 raeburn 11432: @{$dirorder->{$$count}} = @{$hierarchy};
11433: $titles->{$$count} = $item;
1.1055 raeburn 11434: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11435:
1.1055 raeburn 11436: my $is_dir;
11437: if ($dirptr&$testdir) {
11438: $is_dir = 1;
11439: }
11440: if ($wantform) {
11441: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11442: }
11443: if ($is_dir) {
11444: $$depth ++;
1.1056 raeburn 11445: push(@{$hierarchy},$$count);
11446: $parent->{$$depth} = $$count;
1.1055 raeburn 11447: $result .=
11448: &recurse_extracted_archive("$currdir/$item",$docudom,
11449: $docuname,$depth,$count,
1.1056 raeburn 11450: $hierarchy,$dirorder,$children,
11451: $parent,$titles,$wantform);
1.1055 raeburn 11452: $$depth --;
1.1056 raeburn 11453: pop(@{$hierarchy});
1.1055 raeburn 11454: }
11455: }
11456: }
11457: }
11458: return $result;
11459: }
11460:
11461: sub archive_hierarchy {
11462: my ($depth,$count,$parent,$children) =@_;
11463: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11464: if (exists($parent->{$depth})) {
11465: $children->{$parent->{$depth}} .= $count.':';
11466: }
11467: }
11468: return;
11469: }
11470:
11471: sub archive_row {
11472: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11473: my ($name) = ($item =~ m{([^/]+)$});
11474: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11475: 'display' => 'Add as file',
1.1055 raeburn 11476: 'dependency' => 'Include as dependency',
11477: 'discard' => 'Discard',
11478: );
11479: if ($is_dir) {
1.1059 raeburn 11480: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11481: }
1.1056 raeburn 11482: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11483: my $offset = 0;
1.1055 raeburn 11484: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11485: $offset ++;
1.1065 raeburn 11486: if ($action ne 'display') {
11487: $offset ++;
11488: }
1.1055 raeburn 11489: $output .= '<td><span class="LC_nobreak">'.
11490: '<label><input type="radio" name="archive_'.$count.
11491: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11492: my $text = $choices{$action};
11493: if ($is_dir) {
11494: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11495: if ($action eq 'display') {
1.1059 raeburn 11496: $text = &mt('Add as folder');
1.1055 raeburn 11497: }
1.1056 raeburn 11498: } else {
11499: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11500:
11501: }
11502: $output .= ' /> '.$choices{$action}.'</label></span>';
11503: if ($action eq 'dependency') {
11504: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11505: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11506: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11507: '<option value=""></option>'."\n".
11508: '</select>'."\n".
11509: '</div>';
1.1059 raeburn 11510: } elsif ($action eq 'display') {
11511: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11512: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11513: '</div>';
1.1055 raeburn 11514: }
1.1056 raeburn 11515: $output .= '</td>';
1.1055 raeburn 11516: }
11517: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11518: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11519: for (my $i=0; $i<$depth; $i++) {
11520: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11521: }
11522: if ($is_dir) {
11523: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11524: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11525: } else {
11526: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11527: }
11528: $output .= ' '.$name.'</td>'."\n".
11529: &end_data_table_row();
11530: return $output;
11531: }
11532:
11533: sub archive_options_form {
1.1065 raeburn 11534: my ($form,$display,$count,$hiddenelem) = @_;
11535: my %lt = &Apache::lonlocal::texthash(
11536: perm => 'Permanently remove archive file?',
11537: hows => 'How should each extracted item be incorporated in the course?',
11538: cont => 'Content actions for all',
11539: addf => 'Add as folder/file',
11540: incd => 'Include as dependency for a displayed file',
11541: disc => 'Discard',
11542: no => 'No',
11543: yes => 'Yes',
11544: save => 'Save',
11545: );
11546: my $output = <<"END";
11547: <form name="$form" method="post" action="">
11548: <p><span class="LC_nobreak">$lt{'perm'}
11549: <label>
11550: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11551: </label>
11552:
11553: <label>
11554: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11555: </span>
11556: </p>
11557: <input type="hidden" name="phase" value="decompress_cleanup" />
11558: <br />$lt{'hows'}
11559: <div class="LC_columnSection">
11560: <fieldset>
11561: <legend>$lt{'cont'}</legend>
11562: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11563: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11564: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11565: </fieldset>
11566: </div>
11567: END
11568: return $output.
1.1055 raeburn 11569: &start_data_table()."\n".
1.1065 raeburn 11570: $display."\n".
1.1055 raeburn 11571: &end_data_table()."\n".
11572: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11573: $hiddenelem.
1.1065 raeburn 11574: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11575: '</form>';
11576: }
11577:
11578: sub archive_javascript {
1.1056 raeburn 11579: my ($startcount,$numitems,$titles,$children) = @_;
11580: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11581: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11582: my $scripttag = <<START;
11583: <script type="text/javascript">
11584: // <![CDATA[
11585:
11586: function checkAll(form,prefix) {
11587: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11588: for (var i=0; i < form.elements.length; i++) {
11589: var id = form.elements[i].id;
11590: if ((id != '') && (id != undefined)) {
11591: if (idstr.test(id)) {
11592: if (form.elements[i].type == 'radio') {
11593: form.elements[i].checked = true;
1.1056 raeburn 11594: var nostart = i-$startcount;
1.1059 raeburn 11595: var offset = nostart%7;
11596: var count = (nostart-offset)/7;
1.1056 raeburn 11597: dependencyCheck(form,count,offset);
1.1055 raeburn 11598: }
11599: }
11600: }
11601: }
11602: }
11603:
11604: function propagateCheck(form,count) {
11605: if (count > 0) {
1.1059 raeburn 11606: var startelement = $startcount + ((count-1) * 7);
11607: for (var j=1; j<6; j++) {
11608: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11609: var item = startelement + j;
11610: if (form.elements[item].type == 'radio') {
11611: if (form.elements[item].checked) {
11612: containerCheck(form,count,j);
11613: break;
11614: }
1.1055 raeburn 11615: }
11616: }
11617: }
11618: }
11619: }
11620:
11621: numitems = $numitems
1.1056 raeburn 11622: var titles = new Array(numitems);
11623: var parents = new Array(numitems);
1.1055 raeburn 11624: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11625: parents[i] = new Array;
1.1055 raeburn 11626: }
1.1059 raeburn 11627: var maintitle = '$maintitle';
1.1055 raeburn 11628:
11629: START
11630:
1.1056 raeburn 11631: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11632: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11633: for (my $i=0; $i<@contents; $i ++) {
11634: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11635: }
11636: }
11637:
1.1056 raeburn 11638: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11639: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11640: }
11641:
1.1055 raeburn 11642: $scripttag .= <<END;
11643:
11644: function containerCheck(form,count,offset) {
11645: if (count > 0) {
1.1056 raeburn 11646: dependencyCheck(form,count,offset);
1.1059 raeburn 11647: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11648: form.elements[item].checked = true;
11649: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11650: if (parents[count].length > 0) {
11651: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11652: containerCheck(form,parents[count][j],offset);
11653: }
11654: }
11655: }
11656: }
11657: }
11658:
11659: function dependencyCheck(form,count,offset) {
11660: if (count > 0) {
1.1059 raeburn 11661: var chosen = (offset+$startcount)+7*(count-1);
11662: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11663: var currtype = form.elements[depitem].type;
11664: if (form.elements[chosen].value == 'dependency') {
11665: document.getElementById('arc_depon_'+count).style.display='block';
11666: form.elements[depitem].options.length = 0;
11667: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11668: for (var i=1; i<=numitems; i++) {
11669: if (i == count) {
11670: continue;
11671: }
1.1059 raeburn 11672: var startelement = $startcount + (i-1) * 7;
11673: for (var j=1; j<6; j++) {
11674: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11675: var item = startelement + j;
11676: if (form.elements[item].type == 'radio') {
11677: if (form.elements[item].checked) {
11678: if (form.elements[item].value == 'display') {
11679: var n = form.elements[depitem].options.length;
11680: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11681: }
11682: }
11683: }
11684: }
11685: }
11686: }
11687: } else {
11688: document.getElementById('arc_depon_'+count).style.display='none';
11689: form.elements[depitem].options.length = 0;
11690: form.elements[depitem].options[0] = new Option('Select','',true,true);
11691: }
1.1059 raeburn 11692: titleCheck(form,count,offset);
1.1056 raeburn 11693: }
11694: }
11695:
11696: function propagateSelect(form,count,offset) {
11697: if (count > 0) {
1.1065 raeburn 11698: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11699: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11700: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11701: if (parents[count].length > 0) {
11702: for (var j=0; j<parents[count].length; j++) {
11703: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11704: }
11705: }
11706: }
11707: }
11708: }
1.1056 raeburn 11709:
11710: function containerSelect(form,count,offset,picked) {
11711: if (count > 0) {
1.1065 raeburn 11712: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11713: if (form.elements[item].type == 'radio') {
11714: if (form.elements[item].value == 'dependency') {
11715: if (form.elements[item+1].type == 'select-one') {
11716: for (var i=0; i<form.elements[item+1].options.length; i++) {
11717: if (form.elements[item+1].options[i].value == picked) {
11718: form.elements[item+1].selectedIndex = i;
11719: break;
11720: }
11721: }
11722: }
11723: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11724: if (parents[count].length > 0) {
11725: for (var j=0; j<parents[count].length; j++) {
11726: containerSelect(form,parents[count][j],offset,picked);
11727: }
11728: }
11729: }
11730: }
11731: }
11732: }
11733: }
11734:
1.1059 raeburn 11735: function titleCheck(form,count,offset) {
11736: if (count > 0) {
11737: var chosen = (offset+$startcount)+7*(count-1);
11738: var depitem = $startcount + ((count-1) * 7) + 2;
11739: var currtype = form.elements[depitem].type;
11740: if (form.elements[chosen].value == 'display') {
11741: document.getElementById('arc_title_'+count).style.display='block';
11742: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11743: document.getElementById('archive_title_'+count).value=maintitle;
11744: }
11745: } else {
11746: document.getElementById('arc_title_'+count).style.display='none';
11747: if (currtype == 'text') {
11748: document.getElementById('archive_title_'+count).value='';
11749: }
11750: }
11751: }
11752: return;
11753: }
11754:
1.1055 raeburn 11755: // ]]>
11756: </script>
11757: END
11758: return $scripttag;
11759: }
11760:
11761: sub process_extracted_files {
1.1067 raeburn 11762: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11763: my $numitems = $env{'form.archive_count'};
11764: return unless ($numitems);
11765: my @ids=&Apache::lonnet::current_machine_ids();
11766: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11767: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11768: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11769: if (grep(/^\Q$docuhome\E$/,@ids)) {
11770: $prefix = &LONCAPA::propath($docudom,$docuname);
11771: $pathtocheck = "$dir_root/$destination";
11772: $dir = $dir_root;
11773: $ishome = 1;
11774: } else {
11775: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11776: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11777: $dir = "$dir_root/$docudom/$docuname";
11778: }
11779: my $currdir = "$dir_root/$destination";
11780: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11781: if ($env{'form.folderpath'}) {
11782: my @items = split('&',$env{'form.folderpath'});
11783: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11784: if ($env{'form.folderpath'} =~ /\:1$/) {
11785: $containers{'0'}='page';
11786: } else {
11787: $containers{'0'}='sequence';
11788: }
1.1055 raeburn 11789: }
11790: my @archdirs = &get_env_multiple('form.archive_directory');
11791: if ($numitems) {
11792: for (my $i=1; $i<=$numitems; $i++) {
11793: my $path = $env{'form.archive_content_'.$i};
11794: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11795: my $item = $1;
11796: $toplevelitems{$item} = $i;
11797: if (grep(/^\Q$i\E$/,@archdirs)) {
11798: $is_dir{$item} = 1;
11799: }
11800: }
11801: }
11802: }
1.1067 raeburn 11803: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11804: if (keys(%toplevelitems) > 0) {
11805: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11806: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11807: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11808: }
1.1066 raeburn 11809: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11810: if ($numitems) {
11811: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11812: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11813: my $path = $env{'form.archive_content_'.$i};
11814: if ($path =~ /^\Q$pathtocheck\E/) {
11815: if ($env{'form.archive_'.$i} eq 'discard') {
11816: if ($prefix ne '' && $path ne '') {
11817: if (-e $prefix.$path) {
1.1066 raeburn 11818: if ((@archdirs > 0) &&
11819: (grep(/^\Q$i\E$/,@archdirs))) {
11820: $todeletedir{$prefix.$path} = 1;
11821: } else {
11822: $todelete{$prefix.$path} = 1;
11823: }
1.1055 raeburn 11824: }
11825: }
11826: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11827: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11828: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11829: $docstitle = $env{'form.archive_title_'.$i};
11830: if ($docstitle eq '') {
11831: $docstitle = $title;
11832: }
1.1055 raeburn 11833: $outer = 0;
1.1056 raeburn 11834: if (ref($dirorder{$i}) eq 'ARRAY') {
11835: if (@{$dirorder{$i}} > 0) {
11836: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11837: if ($env{'form.archive_'.$item} eq 'display') {
11838: $outer = $item;
11839: last;
11840: }
11841: }
11842: }
11843: }
11844: my ($errtext,$fatal) =
11845: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11846: '/'.$folders{$outer}.'.'.
11847: $containers{$outer});
11848: next if ($fatal);
11849: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11850: if ($context eq 'coursedocs') {
1.1056 raeburn 11851: $mapinner{$i} = time;
1.1055 raeburn 11852: $folders{$i} = 'default_'.$mapinner{$i};
11853: $containers{$i} = 'sequence';
11854: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11855: $folders{$i}.'.'.$containers{$i};
11856: my $newidx = &LONCAPA::map::getresidx();
11857: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11858: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11859: push(@LONCAPA::map::order,$newidx);
11860: my ($outtext,$errtext) =
11861: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11862: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11863: '.'.$containers{$outer},1,1);
1.1056 raeburn 11864: $newseqid{$i} = $newidx;
1.1067 raeburn 11865: unless ($errtext) {
11866: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11867: }
1.1055 raeburn 11868: }
11869: } else {
11870: if ($context eq 'coursedocs') {
11871: my $newidx=&LONCAPA::map::getresidx();
11872: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11873: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11874: $title;
11875: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11876: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11877: }
11878: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11879: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11880: }
11881: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11882: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11883: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11884: unless ($ishome) {
11885: my $fetch = "$newdest{$i}/$title";
11886: $fetch =~ s/^\Q$prefix$dir\E//;
11887: $prompttofetch{$fetch} = 1;
11888: }
1.1055 raeburn 11889: }
11890: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11891: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11892: push(@LONCAPA::map::order, $newidx);
11893: my ($outtext,$errtext)=
11894: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11895: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11896: '.'.$containers{$outer},1,1);
1.1067 raeburn 11897: unless ($errtext) {
11898: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11899: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11900: }
11901: }
1.1055 raeburn 11902: }
11903: }
1.1075.2.11 raeburn 11904: }
11905: } else {
11906: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11907: }
11908: }
11909: for (my $i=1; $i<=$numitems; $i++) {
11910: next unless ($env{'form.archive_'.$i} eq 'dependency');
11911: my $path = $env{'form.archive_content_'.$i};
11912: if ($path =~ /^\Q$pathtocheck\E/) {
11913: my ($title) = ($path =~ m{/([^/]+)$});
11914: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11915: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11916: if (ref($dirorder{$i}) eq 'ARRAY') {
11917: my ($itemidx,$fullpath,$relpath);
11918: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11919: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11920: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11921: if ($dirorder{$i}->[$j] eq $container) {
11922: $itemidx = $j;
1.1056 raeburn 11923: }
11924: }
1.1075.2.11 raeburn 11925: }
11926: if ($itemidx eq '') {
11927: $itemidx = 0;
11928: }
11929: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11930: if ($mapinner{$referrer{$i}}) {
11931: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11932: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11933: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11934: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11935: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11936: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11937: if (!-e $fullpath) {
11938: mkdir($fullpath,0755);
1.1056 raeburn 11939: }
11940: }
1.1075.2.11 raeburn 11941: } else {
11942: last;
1.1056 raeburn 11943: }
1.1075.2.11 raeburn 11944: }
11945: }
11946: } elsif ($newdest{$referrer{$i}}) {
11947: $fullpath = $newdest{$referrer{$i}};
11948: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11949: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11950: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11951: last;
11952: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11953: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11954: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11955: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11956: if (!-e $fullpath) {
11957: mkdir($fullpath,0755);
1.1056 raeburn 11958: }
11959: }
1.1075.2.11 raeburn 11960: } else {
11961: last;
1.1056 raeburn 11962: }
1.1075.2.11 raeburn 11963: }
11964: }
11965: if ($fullpath ne '') {
11966: if (-e "$prefix$path") {
11967: system("mv $prefix$path $fullpath/$title");
11968: }
11969: if (-e "$fullpath/$title") {
11970: my $showpath;
11971: if ($relpath ne '') {
11972: $showpath = "$relpath/$title";
11973: } else {
11974: $showpath = "/$title";
1.1056 raeburn 11975: }
1.1075.2.11 raeburn 11976: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11977: }
11978: unless ($ishome) {
11979: my $fetch = "$fullpath/$title";
11980: $fetch =~ s/^\Q$prefix$dir\E//;
11981: $prompttofetch{$fetch} = 1;
1.1055 raeburn 11982: }
11983: }
11984: }
1.1075.2.11 raeburn 11985: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11986: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11987: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11988: }
11989: } else {
1.1075.2.11 raeburn 11990: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 11991: }
11992: }
11993: if (keys(%todelete)) {
11994: foreach my $key (keys(%todelete)) {
11995: unlink($key);
1.1066 raeburn 11996: }
11997: }
11998: if (keys(%todeletedir)) {
11999: foreach my $key (keys(%todeletedir)) {
12000: rmdir($key);
12001: }
12002: }
12003: foreach my $dir (sort(keys(%is_dir))) {
12004: if (($pathtocheck ne '') && ($dir ne '')) {
12005: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12006: }
12007: }
1.1067 raeburn 12008: if ($result ne '') {
12009: $output .= '<ul>'."\n".
12010: $result."\n".
12011: '</ul>';
12012: }
12013: unless ($ishome) {
12014: my $replicationfail;
12015: foreach my $item (keys(%prompttofetch)) {
12016: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12017: unless ($fetchresult eq 'ok') {
12018: $replicationfail .= '<li>'.$item.'</li>'."\n";
12019: }
12020: }
12021: if ($replicationfail) {
12022: $output .= '<p class="LC_error">'.
12023: &mt('Course home server failed to retrieve:').'<ul>'.
12024: $replicationfail.
12025: '</ul></p>';
12026: }
12027: }
1.1055 raeburn 12028: } else {
12029: $warning = &mt('No items found in archive.');
12030: }
12031: if ($error) {
12032: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12033: $error.'</p>'."\n";
12034: }
12035: if ($warning) {
12036: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12037: }
12038: return $output;
12039: }
12040:
1.1066 raeburn 12041: sub cleanup_empty_dirs {
12042: my ($path) = @_;
12043: if (($path ne '') && (-d $path)) {
12044: if (opendir(my $dirh,$path)) {
12045: my @dircontents = grep(!/^\./,readdir($dirh));
12046: my $numitems = 0;
12047: foreach my $item (@dircontents) {
12048: if (-d "$path/$item") {
1.1075.2.28 raeburn 12049: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12050: if (-e "$path/$item") {
12051: $numitems ++;
12052: }
12053: } else {
12054: $numitems ++;
12055: }
12056: }
12057: if ($numitems == 0) {
12058: rmdir($path);
12059: }
12060: closedir($dirh);
12061: }
12062: }
12063: return;
12064: }
12065:
1.41 ng 12066: =pod
1.45 matthew 12067:
1.1075.2.56 raeburn 12068: =item * &get_folder_hierarchy()
1.1068 raeburn 12069:
12070: Provides hierarchy of names of folders/sub-folders containing the current
12071: item,
12072:
12073: Inputs: 3
12074: - $navmap - navmaps object
12075:
12076: - $map - url for map (either the trigger itself, or map containing
12077: the resource, which is the trigger).
12078:
12079: - $showitem - 1 => show title for map itself; 0 => do not show.
12080:
12081: Outputs: 1 @pathitems - array of folder/subfolder names.
12082:
12083: =cut
12084:
12085: sub get_folder_hierarchy {
12086: my ($navmap,$map,$showitem) = @_;
12087: my @pathitems;
12088: if (ref($navmap)) {
12089: my $mapres = $navmap->getResourceByUrl($map);
12090: if (ref($mapres)) {
12091: my $pcslist = $mapres->map_hierarchy();
12092: if ($pcslist ne '') {
12093: my @pcs = split(/,/,$pcslist);
12094: foreach my $pc (@pcs) {
12095: if ($pc == 1) {
1.1075.2.38 raeburn 12096: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12097: } else {
12098: my $res = $navmap->getByMapPc($pc);
12099: if (ref($res)) {
12100: my $title = $res->compTitle();
12101: $title =~ s/\W+/_/g;
12102: if ($title ne '') {
12103: push(@pathitems,$title);
12104: }
12105: }
12106: }
12107: }
12108: }
1.1071 raeburn 12109: if ($showitem) {
12110: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12111: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12112: } else {
12113: my $maptitle = $mapres->compTitle();
12114: $maptitle =~ s/\W+/_/g;
12115: if ($maptitle ne '') {
12116: push(@pathitems,$maptitle);
12117: }
1.1068 raeburn 12118: }
12119: }
12120: }
12121: }
12122: return @pathitems;
12123: }
12124:
12125: =pod
12126:
1.1015 raeburn 12127: =item * &get_turnedin_filepath()
12128:
12129: Determines path in a user's portfolio file for storage of files uploaded
12130: to a specific essayresponse or dropbox item.
12131:
12132: Inputs: 3 required + 1 optional.
12133: $symb is symb for resource, $uname and $udom are for current user (required).
12134: $caller is optional (can be "submission", if routine is called when storing
12135: an upoaded file when "Submit Answer" button was pressed).
12136:
12137: Returns array containing $path and $multiresp.
12138: $path is path in portfolio. $multiresp is 1 if this resource contains more
12139: than one file upload item. Callers of routine should append partid as a
12140: subdirectory to $path in cases where $multiresp is 1.
12141:
12142: Called by: homework/essayresponse.pm and homework/structuretags.pm
12143:
12144: =cut
12145:
12146: sub get_turnedin_filepath {
12147: my ($symb,$uname,$udom,$caller) = @_;
12148: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12149: my $turnindir;
12150: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12151: $turnindir = $userhash{'turnindir'};
12152: my ($path,$multiresp);
12153: if ($turnindir eq '') {
12154: if ($caller eq 'submission') {
12155: $turnindir = &mt('turned in');
12156: $turnindir =~ s/\W+/_/g;
12157: my %newhash = (
12158: 'turnindir' => $turnindir,
12159: );
12160: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12161: }
12162: }
12163: if ($turnindir ne '') {
12164: $path = '/'.$turnindir.'/';
12165: my ($multipart,$turnin,@pathitems);
12166: my $navmap = Apache::lonnavmaps::navmap->new();
12167: if (defined($navmap)) {
12168: my $mapres = $navmap->getResourceByUrl($map);
12169: if (ref($mapres)) {
12170: my $pcslist = $mapres->map_hierarchy();
12171: if ($pcslist ne '') {
12172: foreach my $pc (split(/,/,$pcslist)) {
12173: my $res = $navmap->getByMapPc($pc);
12174: if (ref($res)) {
12175: my $title = $res->compTitle();
12176: $title =~ s/\W+/_/g;
12177: if ($title ne '') {
1.1075.2.48 raeburn 12178: if (($pc > 1) && (length($title) > 12)) {
12179: $title = substr($title,0,12);
12180: }
1.1015 raeburn 12181: push(@pathitems,$title);
12182: }
12183: }
12184: }
12185: }
12186: my $maptitle = $mapres->compTitle();
12187: $maptitle =~ s/\W+/_/g;
12188: if ($maptitle ne '') {
1.1075.2.48 raeburn 12189: if (length($maptitle) > 12) {
12190: $maptitle = substr($maptitle,0,12);
12191: }
1.1015 raeburn 12192: push(@pathitems,$maptitle);
12193: }
12194: unless ($env{'request.state'} eq 'construct') {
12195: my $res = $navmap->getBySymb($symb);
12196: if (ref($res)) {
12197: my $partlist = $res->parts();
12198: my $totaluploads = 0;
12199: if (ref($partlist) eq 'ARRAY') {
12200: foreach my $part (@{$partlist}) {
12201: my @types = $res->responseType($part);
12202: my @ids = $res->responseIds($part);
12203: for (my $i=0; $i < scalar(@ids); $i++) {
12204: if ($types[$i] eq 'essay') {
12205: my $partid = $part.'_'.$ids[$i];
12206: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12207: $totaluploads ++;
12208: }
12209: }
12210: }
12211: }
12212: if ($totaluploads > 1) {
12213: $multiresp = 1;
12214: }
12215: }
12216: }
12217: }
12218: } else {
12219: return;
12220: }
12221: } else {
12222: return;
12223: }
12224: my $restitle=&Apache::lonnet::gettitle($symb);
12225: $restitle =~ s/\W+/_/g;
12226: if ($restitle eq '') {
12227: $restitle = ($resurl =~ m{/[^/]+$});
12228: if ($restitle eq '') {
12229: $restitle = time;
12230: }
12231: }
1.1075.2.48 raeburn 12232: if (length($restitle) > 12) {
12233: $restitle = substr($restitle,0,12);
12234: }
1.1015 raeburn 12235: push(@pathitems,$restitle);
12236: $path .= join('/',@pathitems);
12237: }
12238: return ($path,$multiresp);
12239: }
12240:
12241: =pod
12242:
1.464 albertel 12243: =back
1.41 ng 12244:
1.112 bowersj2 12245: =head1 CSV Upload/Handling functions
1.38 albertel 12246:
1.41 ng 12247: =over 4
12248:
1.648 raeburn 12249: =item * &upfile_store($r)
1.41 ng 12250:
12251: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12252: needs $env{'form.upfile'}
1.41 ng 12253: returns $datatoken to be put into hidden field
12254:
12255: =cut
1.31 albertel 12256:
12257: sub upfile_store {
12258: my $r=shift;
1.258 albertel 12259: $env{'form.upfile'}=~s/\r/\n/gs;
12260: $env{'form.upfile'}=~s/\f/\n/gs;
12261: $env{'form.upfile'}=~s/\n+/\n/gs;
12262: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12263:
1.258 albertel 12264: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12265: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12266: {
1.158 raeburn 12267: my $datafile = $r->dir_config('lonDaemons').
12268: '/tmp/'.$datatoken.'.tmp';
12269: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12270: print $fh $env{'form.upfile'};
1.158 raeburn 12271: close($fh);
12272: }
1.31 albertel 12273: }
12274: return $datatoken;
12275: }
12276:
1.56 matthew 12277: =pod
12278:
1.648 raeburn 12279: =item * &load_tmp_file($r)
1.41 ng 12280:
12281: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12282: needs $env{'form.datatoken'},
12283: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12284:
12285: =cut
1.31 albertel 12286:
12287: sub load_tmp_file {
12288: my $r=shift;
12289: my @studentdata=();
12290: {
1.158 raeburn 12291: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12292: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12293: if ( open(my $fh,"<$studentfile") ) {
12294: @studentdata=<$fh>;
12295: close($fh);
12296: }
1.31 albertel 12297: }
1.258 albertel 12298: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12299: }
12300:
1.56 matthew 12301: =pod
12302:
1.648 raeburn 12303: =item * &upfile_record_sep()
1.41 ng 12304:
12305: Separate uploaded file into records
12306: returns array of records,
1.258 albertel 12307: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12308:
12309: =cut
1.31 albertel 12310:
12311: sub upfile_record_sep {
1.258 albertel 12312: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12313: } else {
1.248 albertel 12314: my @records;
1.258 albertel 12315: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12316: if ($line=~/^\s*$/) { next; }
12317: push(@records,$line);
12318: }
12319: return @records;
1.31 albertel 12320: }
12321: }
12322:
1.56 matthew 12323: =pod
12324:
1.648 raeburn 12325: =item * &record_sep($record)
1.41 ng 12326:
1.258 albertel 12327: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12328:
12329: =cut
12330:
1.263 www 12331: sub takeleft {
12332: my $index=shift;
12333: return substr('0000'.$index,-4,4);
12334: }
12335:
1.31 albertel 12336: sub record_sep {
12337: my $record=shift;
12338: my %components=();
1.258 albertel 12339: if ($env{'form.upfiletype'} eq 'xml') {
12340: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12341: my $i=0;
1.356 albertel 12342: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12343: $field=~s/^(\"|\')//;
12344: $field=~s/(\"|\')$//;
1.263 www 12345: $components{&takeleft($i)}=$field;
1.31 albertel 12346: $i++;
12347: }
1.258 albertel 12348: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12349: my $i=0;
1.356 albertel 12350: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12351: $field=~s/^(\"|\')//;
12352: $field=~s/(\"|\')$//;
1.263 www 12353: $components{&takeleft($i)}=$field;
1.31 albertel 12354: $i++;
12355: }
12356: } else {
1.561 www 12357: my $separator=',';
1.480 banghart 12358: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12359: $separator=';';
1.480 banghart 12360: }
1.31 albertel 12361: my $i=0;
1.561 www 12362: # the character we are looking for to indicate the end of a quote or a record
12363: my $looking_for=$separator;
12364: # do not add the characters to the fields
12365: my $ignore=0;
12366: # we just encountered a separator (or the beginning of the record)
12367: my $just_found_separator=1;
12368: # store the field we are working on here
12369: my $field='';
12370: # work our way through all characters in record
12371: foreach my $character ($record=~/(.)/g) {
12372: if ($character eq $looking_for) {
12373: if ($character ne $separator) {
12374: # Found the end of a quote, again looking for separator
12375: $looking_for=$separator;
12376: $ignore=1;
12377: } else {
12378: # Found a separator, store away what we got
12379: $components{&takeleft($i)}=$field;
12380: $i++;
12381: $just_found_separator=1;
12382: $ignore=0;
12383: $field='';
12384: }
12385: next;
12386: }
12387: # single or double quotation marks after a separator indicate beginning of a quote
12388: # we are now looking for the end of the quote and need to ignore separators
12389: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12390: $looking_for=$character;
12391: next;
12392: }
12393: # ignore would be true after we reached the end of a quote
12394: if ($ignore) { next; }
12395: if (($just_found_separator) && ($character=~/\s/)) { next; }
12396: $field.=$character;
12397: $just_found_separator=0;
1.31 albertel 12398: }
1.561 www 12399: # catch the very last entry, since we never encountered the separator
12400: $components{&takeleft($i)}=$field;
1.31 albertel 12401: }
12402: return %components;
12403: }
12404:
1.144 matthew 12405: ######################################################
12406: ######################################################
12407:
1.56 matthew 12408: =pod
12409:
1.648 raeburn 12410: =item * &upfile_select_html()
1.41 ng 12411:
1.144 matthew 12412: Return HTML code to select a file from the users machine and specify
12413: the file type.
1.41 ng 12414:
12415: =cut
12416:
1.144 matthew 12417: ######################################################
12418: ######################################################
1.31 albertel 12419: sub upfile_select_html {
1.144 matthew 12420: my %Types = (
12421: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12422: semisv => &mt('Semicolon separated values'),
1.144 matthew 12423: space => &mt('Space separated'),
12424: tab => &mt('Tabulator separated'),
12425: # xml => &mt('HTML/XML'),
12426: );
12427: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12428: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12429: foreach my $type (sort(keys(%Types))) {
12430: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12431: }
12432: $Str .= "</select>\n";
12433: return $Str;
1.31 albertel 12434: }
12435:
1.301 albertel 12436: sub get_samples {
12437: my ($records,$toget) = @_;
12438: my @samples=({});
12439: my $got=0;
12440: foreach my $rec (@$records) {
12441: my %temp = &record_sep($rec);
12442: if (! grep(/\S/, values(%temp))) { next; }
12443: if (%temp) {
12444: $samples[$got]=\%temp;
12445: $got++;
12446: if ($got == $toget) { last; }
12447: }
12448: }
12449: return \@samples;
12450: }
12451:
1.144 matthew 12452: ######################################################
12453: ######################################################
12454:
1.56 matthew 12455: =pod
12456:
1.648 raeburn 12457: =item * &csv_print_samples($r,$records)
1.41 ng 12458:
12459: Prints a table of sample values from each column uploaded $r is an
12460: Apache Request ref, $records is an arrayref from
12461: &Apache::loncommon::upfile_record_sep
12462:
12463: =cut
12464:
1.144 matthew 12465: ######################################################
12466: ######################################################
1.31 albertel 12467: sub csv_print_samples {
12468: my ($r,$records) = @_;
1.662 bisitz 12469: my $samples = &get_samples($records,5);
1.301 albertel 12470:
1.594 raeburn 12471: $r->print(&mt('Samples').'<br />'.&start_data_table().
12472: &start_data_table_header_row());
1.356 albertel 12473: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12474: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12475: $r->print(&end_data_table_header_row());
1.301 albertel 12476: foreach my $hash (@$samples) {
1.594 raeburn 12477: $r->print(&start_data_table_row());
1.356 albertel 12478: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12479: $r->print('<td>');
1.356 albertel 12480: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12481: $r->print('</td>');
12482: }
1.594 raeburn 12483: $r->print(&end_data_table_row());
1.31 albertel 12484: }
1.594 raeburn 12485: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12486: }
12487:
1.144 matthew 12488: ######################################################
12489: ######################################################
12490:
1.56 matthew 12491: =pod
12492:
1.648 raeburn 12493: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12494:
12495: Prints a table to create associations between values and table columns.
1.144 matthew 12496:
1.41 ng 12497: $r is an Apache Request ref,
12498: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12499: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12500:
12501: =cut
12502:
1.144 matthew 12503: ######################################################
12504: ######################################################
1.31 albertel 12505: sub csv_print_select_table {
12506: my ($r,$records,$d) = @_;
1.301 albertel 12507: my $i=0;
12508: my $samples = &get_samples($records,1);
1.144 matthew 12509: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12510: &start_data_table().&start_data_table_header_row().
1.144 matthew 12511: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12512: '<th>'.&mt('Column').'</th>'.
12513: &end_data_table_header_row()."\n");
1.356 albertel 12514: foreach my $array_ref (@$d) {
12515: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12516: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12517:
1.875 bisitz 12518: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12519: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12520: $r->print('<option value="none"></option>');
1.356 albertel 12521: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12522: $r->print('<option value="'.$sample.'"'.
12523: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12524: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12525: }
1.594 raeburn 12526: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12527: $i++;
12528: }
1.594 raeburn 12529: $r->print(&end_data_table());
1.31 albertel 12530: $i--;
12531: return $i;
12532: }
1.56 matthew 12533:
1.144 matthew 12534: ######################################################
12535: ######################################################
12536:
1.56 matthew 12537: =pod
1.31 albertel 12538:
1.648 raeburn 12539: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12540:
12541: Prints a table of sample values from the upload and can make associate samples to internal names.
12542:
12543: $r is an Apache Request ref,
12544: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12545: $d is an array of 2 element arrays (internal name, displayed name)
12546:
12547: =cut
12548:
1.144 matthew 12549: ######################################################
12550: ######################################################
1.31 albertel 12551: sub csv_samples_select_table {
12552: my ($r,$records,$d) = @_;
12553: my $i=0;
1.144 matthew 12554: #
1.662 bisitz 12555: my $max_samples = 5;
12556: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12557: $r->print(&start_data_table().
12558: &start_data_table_header_row().'<th>'.
12559: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12560: &end_data_table_header_row());
1.301 albertel 12561:
12562: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12563: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12564: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12565: foreach my $option (@$d) {
12566: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12567: $r->print('<option value="'.$value.'"'.
1.253 albertel 12568: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12569: $display.'</option>');
1.31 albertel 12570: }
12571: $r->print('</select></td><td>');
1.662 bisitz 12572: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12573: if (defined($samples->[$line]{$key})) {
12574: $r->print($samples->[$line]{$key}."<br />\n");
12575: }
12576: }
1.594 raeburn 12577: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12578: $i++;
12579: }
1.594 raeburn 12580: $r->print(&end_data_table());
1.31 albertel 12581: $i--;
12582: return($i);
1.115 matthew 12583: }
12584:
1.144 matthew 12585: ######################################################
12586: ######################################################
12587:
1.115 matthew 12588: =pod
12589:
1.648 raeburn 12590: =item * &clean_excel_name($name)
1.115 matthew 12591:
12592: Returns a replacement for $name which does not contain any illegal characters.
12593:
12594: =cut
12595:
1.144 matthew 12596: ######################################################
12597: ######################################################
1.115 matthew 12598: sub clean_excel_name {
12599: my ($name) = @_;
12600: $name =~ s/[:\*\?\/\\]//g;
12601: if (length($name) > 31) {
12602: $name = substr($name,0,31);
12603: }
12604: return $name;
1.25 albertel 12605: }
1.84 albertel 12606:
1.85 albertel 12607: =pod
12608:
1.648 raeburn 12609: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12610:
12611: Returns either 1 or undef
12612:
12613: 1 if the part is to be hidden, undef if it is to be shown
12614:
12615: Arguments are:
12616:
12617: $id the id of the part to be checked
12618: $symb, optional the symb of the resource to check
12619: $udom, optional the domain of the user to check for
12620: $uname, optional the username of the user to check for
12621:
12622: =cut
1.84 albertel 12623:
12624: sub check_if_partid_hidden {
12625: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12626: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12627: $symb,$udom,$uname);
1.141 albertel 12628: my $truth=1;
12629: #if the string starts with !, then the list is the list to show not hide
12630: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12631: my @hiddenlist=split(/,/,$hiddenparts);
12632: foreach my $checkid (@hiddenlist) {
1.141 albertel 12633: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12634: }
1.141 albertel 12635: return !$truth;
1.84 albertel 12636: }
1.127 matthew 12637:
1.138 matthew 12638:
12639: ############################################################
12640: ############################################################
12641:
12642: =pod
12643:
1.157 matthew 12644: =back
12645:
1.138 matthew 12646: =head1 cgi-bin script and graphing routines
12647:
1.157 matthew 12648: =over 4
12649:
1.648 raeburn 12650: =item * &get_cgi_id()
1.138 matthew 12651:
12652: Inputs: none
12653:
12654: Returns an id which can be used to pass environment variables
12655: to various cgi-bin scripts. These environment variables will
12656: be removed from the users environment after a given time by
12657: the routine &Apache::lonnet::transfer_profile_to_env.
12658:
12659: =cut
12660:
12661: ############################################################
12662: ############################################################
1.152 albertel 12663: my $uniq=0;
1.136 matthew 12664: sub get_cgi_id {
1.154 albertel 12665: $uniq=($uniq+1)%100000;
1.280 albertel 12666: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12667: }
12668:
1.127 matthew 12669: ############################################################
12670: ############################################################
12671:
12672: =pod
12673:
1.648 raeburn 12674: =item * &DrawBarGraph()
1.127 matthew 12675:
1.138 matthew 12676: Facilitates the plotting of data in a (stacked) bar graph.
12677: Puts plot definition data into the users environment in order for
12678: graph.png to plot it. Returns an <img> tag for the plot.
12679: The bars on the plot are labeled '1','2',...,'n'.
12680:
12681: Inputs:
12682:
12683: =over 4
12684:
12685: =item $Title: string, the title of the plot
12686:
12687: =item $xlabel: string, text describing the X-axis of the plot
12688:
12689: =item $ylabel: string, text describing the Y-axis of the plot
12690:
12691: =item $Max: scalar, the maximum Y value to use in the plot
12692: If $Max is < any data point, the graph will not be rendered.
12693:
1.140 matthew 12694: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12695: they are plotted. If undefined, default values will be used.
12696:
1.178 matthew 12697: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12698:
1.138 matthew 12699: =item @Values: An array of array references. Each array reference holds data
12700: to be plotted in a stacked bar chart.
12701:
1.239 matthew 12702: =item If the final element of @Values is a hash reference the key/value
12703: pairs will be added to the graph definition.
12704:
1.138 matthew 12705: =back
12706:
12707: Returns:
12708:
12709: An <img> tag which references graph.png and the appropriate identifying
12710: information for the plot.
12711:
1.127 matthew 12712: =cut
12713:
12714: ############################################################
12715: ############################################################
1.134 matthew 12716: sub DrawBarGraph {
1.178 matthew 12717: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12718: #
12719: if (! defined($colors)) {
12720: $colors = ['#33ff00',
12721: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12722: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12723: ];
12724: }
1.228 matthew 12725: my $extra_settings = {};
12726: if (ref($Values[-1]) eq 'HASH') {
12727: $extra_settings = pop(@Values);
12728: }
1.127 matthew 12729: #
1.136 matthew 12730: my $identifier = &get_cgi_id();
12731: my $id = 'cgi.'.$identifier;
1.129 matthew 12732: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12733: return '';
12734: }
1.225 matthew 12735: #
12736: my @Labels;
12737: if (defined($labels)) {
12738: @Labels = @$labels;
12739: } else {
12740: for (my $i=0;$i<@{$Values[0]};$i++) {
12741: push (@Labels,$i+1);
12742: }
12743: }
12744: #
1.129 matthew 12745: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12746: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12747: my %ValuesHash;
12748: my $NumSets=1;
12749: foreach my $array (@Values) {
12750: next if (! ref($array));
1.136 matthew 12751: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12752: join(',',@$array);
1.129 matthew 12753: }
1.127 matthew 12754: #
1.136 matthew 12755: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12756: if ($NumBars < 3) {
12757: $width = 120+$NumBars*32;
1.220 matthew 12758: $xskip = 1;
1.225 matthew 12759: $bar_width = 30;
12760: } elsif ($NumBars < 5) {
12761: $width = 120+$NumBars*20;
12762: $xskip = 1;
12763: $bar_width = 20;
1.220 matthew 12764: } elsif ($NumBars < 10) {
1.136 matthew 12765: $width = 120+$NumBars*15;
12766: $xskip = 1;
12767: $bar_width = 15;
12768: } elsif ($NumBars <= 25) {
12769: $width = 120+$NumBars*11;
12770: $xskip = 5;
12771: $bar_width = 8;
12772: } elsif ($NumBars <= 50) {
12773: $width = 120+$NumBars*8;
12774: $xskip = 5;
12775: $bar_width = 4;
12776: } else {
12777: $width = 120+$NumBars*8;
12778: $xskip = 5;
12779: $bar_width = 4;
12780: }
12781: #
1.137 matthew 12782: $Max = 1 if ($Max < 1);
12783: if ( int($Max) < $Max ) {
12784: $Max++;
12785: $Max = int($Max);
12786: }
1.127 matthew 12787: $Title = '' if (! defined($Title));
12788: $xlabel = '' if (! defined($xlabel));
12789: $ylabel = '' if (! defined($ylabel));
1.369 www 12790: $ValuesHash{$id.'.title'} = &escape($Title);
12791: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12792: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12793: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12794: $ValuesHash{$id.'.NumBars'} = $NumBars;
12795: $ValuesHash{$id.'.NumSets'} = $NumSets;
12796: $ValuesHash{$id.'.PlotType'} = 'bar';
12797: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12798: $ValuesHash{$id.'.height'} = $height;
12799: $ValuesHash{$id.'.width'} = $width;
12800: $ValuesHash{$id.'.xskip'} = $xskip;
12801: $ValuesHash{$id.'.bar_width'} = $bar_width;
12802: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12803: #
1.228 matthew 12804: # Deal with other parameters
12805: while (my ($key,$value) = each(%$extra_settings)) {
12806: $ValuesHash{$id.'.'.$key} = $value;
12807: }
12808: #
1.646 raeburn 12809: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12810: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12811: }
12812:
12813: ############################################################
12814: ############################################################
12815:
12816: =pod
12817:
1.648 raeburn 12818: =item * &DrawXYGraph()
1.137 matthew 12819:
1.138 matthew 12820: Facilitates the plotting of data in an XY graph.
12821: Puts plot definition data into the users environment in order for
12822: graph.png to plot it. Returns an <img> tag for the plot.
12823:
12824: Inputs:
12825:
12826: =over 4
12827:
12828: =item $Title: string, the title of the plot
12829:
12830: =item $xlabel: string, text describing the X-axis of the plot
12831:
12832: =item $ylabel: string, text describing the Y-axis of the plot
12833:
12834: =item $Max: scalar, the maximum Y value to use in the plot
12835: If $Max is < any data point, the graph will not be rendered.
12836:
12837: =item $colors: Array ref containing the hex color codes for the data to be
12838: plotted in. If undefined, default values will be used.
12839:
12840: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12841:
12842: =item $Ydata: Array ref containing Array refs.
1.185 www 12843: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12844:
12845: =item %Values: hash indicating or overriding any default values which are
12846: passed to graph.png.
12847: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12848:
12849: =back
12850:
12851: Returns:
12852:
12853: An <img> tag which references graph.png and the appropriate identifying
12854: information for the plot.
12855:
1.137 matthew 12856: =cut
12857:
12858: ############################################################
12859: ############################################################
12860: sub DrawXYGraph {
12861: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12862: #
12863: # Create the identifier for the graph
12864: my $identifier = &get_cgi_id();
12865: my $id = 'cgi.'.$identifier;
12866: #
12867: $Title = '' if (! defined($Title));
12868: $xlabel = '' if (! defined($xlabel));
12869: $ylabel = '' if (! defined($ylabel));
12870: my %ValuesHash =
12871: (
1.369 www 12872: $id.'.title' => &escape($Title),
12873: $id.'.xlabel' => &escape($xlabel),
12874: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12875: $id.'.y_max_value'=> $Max,
12876: $id.'.labels' => join(',',@$Xlabels),
12877: $id.'.PlotType' => 'XY',
12878: );
12879: #
12880: if (defined($colors) && ref($colors) eq 'ARRAY') {
12881: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12882: }
12883: #
12884: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12885: return '';
12886: }
12887: my $NumSets=1;
1.138 matthew 12888: foreach my $array (@{$Ydata}){
1.137 matthew 12889: next if (! ref($array));
12890: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12891: }
1.138 matthew 12892: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12893: #
12894: # Deal with other parameters
12895: while (my ($key,$value) = each(%Values)) {
12896: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12897: }
12898: #
1.646 raeburn 12899: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12900: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12901: }
12902:
12903: ############################################################
12904: ############################################################
12905:
12906: =pod
12907:
1.648 raeburn 12908: =item * &DrawXYYGraph()
1.138 matthew 12909:
12910: Facilitates the plotting of data in an XY graph with two Y axes.
12911: Puts plot definition data into the users environment in order for
12912: graph.png to plot it. Returns an <img> tag for the plot.
12913:
12914: Inputs:
12915:
12916: =over 4
12917:
12918: =item $Title: string, the title of the plot
12919:
12920: =item $xlabel: string, text describing the X-axis of the plot
12921:
12922: =item $ylabel: string, text describing the Y-axis of the plot
12923:
12924: =item $colors: Array ref containing the hex color codes for the data to be
12925: plotted in. If undefined, default values will be used.
12926:
12927: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12928:
12929: =item $Ydata1: The first data set
12930:
12931: =item $Min1: The minimum value of the left Y-axis
12932:
12933: =item $Max1: The maximum value of the left Y-axis
12934:
12935: =item $Ydata2: The second data set
12936:
12937: =item $Min2: The minimum value of the right Y-axis
12938:
12939: =item $Max2: The maximum value of the left Y-axis
12940:
12941: =item %Values: hash indicating or overriding any default values which are
12942: passed to graph.png.
12943: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12944:
12945: =back
12946:
12947: Returns:
12948:
12949: An <img> tag which references graph.png and the appropriate identifying
12950: information for the plot.
1.136 matthew 12951:
12952: =cut
12953:
12954: ############################################################
12955: ############################################################
1.137 matthew 12956: sub DrawXYYGraph {
12957: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12958: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12959: #
12960: # Create the identifier for the graph
12961: my $identifier = &get_cgi_id();
12962: my $id = 'cgi.'.$identifier;
12963: #
12964: $Title = '' if (! defined($Title));
12965: $xlabel = '' if (! defined($xlabel));
12966: $ylabel = '' if (! defined($ylabel));
12967: my %ValuesHash =
12968: (
1.369 www 12969: $id.'.title' => &escape($Title),
12970: $id.'.xlabel' => &escape($xlabel),
12971: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12972: $id.'.labels' => join(',',@$Xlabels),
12973: $id.'.PlotType' => 'XY',
12974: $id.'.NumSets' => 2,
1.137 matthew 12975: $id.'.two_axes' => 1,
12976: $id.'.y1_max_value' => $Max1,
12977: $id.'.y1_min_value' => $Min1,
12978: $id.'.y2_max_value' => $Max2,
12979: $id.'.y2_min_value' => $Min2,
1.136 matthew 12980: );
12981: #
1.137 matthew 12982: if (defined($colors) && ref($colors) eq 'ARRAY') {
12983: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12984: }
12985: #
12986: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12987: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12988: return '';
12989: }
12990: my $NumSets=1;
1.137 matthew 12991: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12992: next if (! ref($array));
12993: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12994: }
12995: #
12996: # Deal with other parameters
12997: while (my ($key,$value) = each(%Values)) {
12998: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12999: }
13000: #
1.646 raeburn 13001: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13002: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13003: }
13004:
13005: ############################################################
13006: ############################################################
13007:
13008: =pod
13009:
1.157 matthew 13010: =back
13011:
1.139 matthew 13012: =head1 Statistics helper routines?
13013:
13014: Bad place for them but what the hell.
13015:
1.157 matthew 13016: =over 4
13017:
1.648 raeburn 13018: =item * &chartlink()
1.139 matthew 13019:
13020: Returns a link to the chart for a specific student.
13021:
13022: Inputs:
13023:
13024: =over 4
13025:
13026: =item $linktext: The text of the link
13027:
13028: =item $sname: The students username
13029:
13030: =item $sdomain: The students domain
13031:
13032: =back
13033:
1.157 matthew 13034: =back
13035:
1.139 matthew 13036: =cut
13037:
13038: ############################################################
13039: ############################################################
13040: sub chartlink {
13041: my ($linktext, $sname, $sdomain) = @_;
13042: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13043: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13044: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13045: '">'.$linktext.'</a>';
1.153 matthew 13046: }
13047:
13048: #######################################################
13049: #######################################################
13050:
13051: =pod
13052:
13053: =head1 Course Environment Routines
1.157 matthew 13054:
13055: =over 4
1.153 matthew 13056:
1.648 raeburn 13057: =item * &restore_course_settings()
1.153 matthew 13058:
1.648 raeburn 13059: =item * &store_course_settings()
1.153 matthew 13060:
13061: Restores/Store indicated form parameters from the course environment.
13062: Will not overwrite existing values of the form parameters.
13063:
13064: Inputs:
13065: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13066:
13067: a hash ref describing the data to be stored. For example:
13068:
13069: %Save_Parameters = ('Status' => 'scalar',
13070: 'chartoutputmode' => 'scalar',
13071: 'chartoutputdata' => 'scalar',
13072: 'Section' => 'array',
1.373 raeburn 13073: 'Group' => 'array',
1.153 matthew 13074: 'StudentData' => 'array',
13075: 'Maps' => 'array');
13076:
13077: Returns: both routines return nothing
13078:
1.631 raeburn 13079: =back
13080:
1.153 matthew 13081: =cut
13082:
13083: #######################################################
13084: #######################################################
13085: sub store_course_settings {
1.496 albertel 13086: return &store_settings($env{'request.course.id'},@_);
13087: }
13088:
13089: sub store_settings {
1.153 matthew 13090: # save to the environment
13091: # appenv the same items, just to be safe
1.300 albertel 13092: my $udom = $env{'user.domain'};
13093: my $uname = $env{'user.name'};
1.496 albertel 13094: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13095: my %SaveHash;
13096: my %AppHash;
13097: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13098: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13099: my $envname = 'environment.'.$basename;
1.258 albertel 13100: if (exists($env{'form.'.$setting})) {
1.153 matthew 13101: # Save this value away
13102: if ($type eq 'scalar' &&
1.258 albertel 13103: (! exists($env{$envname}) ||
13104: $env{$envname} ne $env{'form.'.$setting})) {
13105: $SaveHash{$basename} = $env{'form.'.$setting};
13106: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13107: } elsif ($type eq 'array') {
13108: my $stored_form;
1.258 albertel 13109: if (ref($env{'form.'.$setting})) {
1.153 matthew 13110: $stored_form = join(',',
13111: map {
1.369 www 13112: &escape($_);
1.258 albertel 13113: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13114: } else {
13115: $stored_form =
1.369 www 13116: &escape($env{'form.'.$setting});
1.153 matthew 13117: }
13118: # Determine if the array contents are the same.
1.258 albertel 13119: if ($stored_form ne $env{$envname}) {
1.153 matthew 13120: $SaveHash{$basename} = $stored_form;
13121: $AppHash{$envname} = $stored_form;
13122: }
13123: }
13124: }
13125: }
13126: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13127: $udom,$uname);
1.153 matthew 13128: if ($put_result !~ /^(ok|delayed)/) {
13129: &Apache::lonnet::logthis('unable to save form parameters, '.
13130: 'got error:'.$put_result);
13131: }
13132: # Make sure these settings stick around in this session, too
1.646 raeburn 13133: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13134: return;
13135: }
13136:
13137: sub restore_course_settings {
1.499 albertel 13138: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13139: }
13140:
13141: sub restore_settings {
13142: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13143: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13144: next if (exists($env{'form.'.$setting}));
1.496 albertel 13145: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13146: '.'.$setting;
1.258 albertel 13147: if (exists($env{$envname})) {
1.153 matthew 13148: if ($type eq 'scalar') {
1.258 albertel 13149: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13150: } elsif ($type eq 'array') {
1.258 albertel 13151: $env{'form.'.$setting} = [
1.153 matthew 13152: map {
1.369 www 13153: &unescape($_);
1.258 albertel 13154: } split(',',$env{$envname})
1.153 matthew 13155: ];
13156: }
13157: }
13158: }
1.127 matthew 13159: }
13160:
1.618 raeburn 13161: #######################################################
13162: #######################################################
13163:
13164: =pod
13165:
13166: =head1 Domain E-mail Routines
13167:
13168: =over 4
13169:
1.648 raeburn 13170: =item * &build_recipient_list()
1.618 raeburn 13171:
1.1075.2.44 raeburn 13172: Build recipient lists for following types of e-mail:
1.766 raeburn 13173: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13174: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13175: module change checking, student/employee ID conflict checks, as
13176: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13177: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13178:
13179: Inputs:
1.1075.2.44 raeburn 13180: defmail (scalar - email address of default recipient),
13181: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13182: requestsmail, updatesmail, or idconflictsmail).
13183:
1.619 raeburn 13184: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13185:
13186: origmail (scalar - email address of recipient from loncapa.conf,
13187: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13188:
1.655 raeburn 13189: Returns: comma separated list of addresses to which to send e-mail.
13190:
13191: =back
1.618 raeburn 13192:
13193: =cut
13194:
13195: ############################################################
13196: ############################################################
13197: sub build_recipient_list {
1.619 raeburn 13198: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13199: my @recipients;
13200: my $otheremails;
13201: my %domconfig =
13202: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13203: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13204: if (exists($domconfig{'contacts'}{$mailing})) {
13205: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13206: my @contacts = ('adminemail','supportemail');
13207: foreach my $item (@contacts) {
13208: if ($domconfig{'contacts'}{$mailing}{$item}) {
13209: my $addr = $domconfig{'contacts'}{$item};
13210: if (!grep(/^\Q$addr\E$/,@recipients)) {
13211: push(@recipients,$addr);
13212: }
1.619 raeburn 13213: }
1.766 raeburn 13214: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13215: }
13216: }
1.766 raeburn 13217: } elsif ($origmail ne '') {
13218: push(@recipients,$origmail);
1.618 raeburn 13219: }
1.619 raeburn 13220: } elsif ($origmail ne '') {
13221: push(@recipients,$origmail);
1.618 raeburn 13222: }
1.688 raeburn 13223: if (defined($defmail)) {
13224: if ($defmail ne '') {
13225: push(@recipients,$defmail);
13226: }
1.618 raeburn 13227: }
13228: if ($otheremails) {
1.619 raeburn 13229: my @others;
13230: if ($otheremails =~ /,/) {
13231: @others = split(/,/,$otheremails);
1.618 raeburn 13232: } else {
1.619 raeburn 13233: push(@others,$otheremails);
13234: }
13235: foreach my $addr (@others) {
13236: if (!grep(/^\Q$addr\E$/,@recipients)) {
13237: push(@recipients,$addr);
13238: }
1.618 raeburn 13239: }
13240: }
1.619 raeburn 13241: my $recipientlist = join(',',@recipients);
1.618 raeburn 13242: return $recipientlist;
13243: }
13244:
1.127 matthew 13245: ############################################################
13246: ############################################################
1.154 albertel 13247:
1.655 raeburn 13248: =pod
13249:
13250: =head1 Course Catalog Routines
13251:
13252: =over 4
13253:
13254: =item * &gather_categories()
13255:
13256: Converts category definitions - keys of categories hash stored in
13257: coursecategories in configuration.db on the primary library server in a
13258: domain - to an array. Also generates javascript and idx hash used to
13259: generate Domain Coordinator interface for editing Course Categories.
13260:
13261: Inputs:
1.663 raeburn 13262:
1.655 raeburn 13263: categories (reference to hash of category definitions).
1.663 raeburn 13264:
1.655 raeburn 13265: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13266: categories and subcategories).
1.663 raeburn 13267:
1.655 raeburn 13268: idx (reference to hash of counters used in Domain Coordinator interface for
13269: editing Course Categories).
1.663 raeburn 13270:
1.655 raeburn 13271: jsarray (reference to array of categories used to create Javascript arrays for
13272: Domain Coordinator interface for editing Course Categories).
13273:
13274: Returns: nothing
13275:
13276: Side effects: populates cats, idx and jsarray.
13277:
13278: =cut
13279:
13280: sub gather_categories {
13281: my ($categories,$cats,$idx,$jsarray) = @_;
13282: my %counters;
13283: my $num = 0;
13284: foreach my $item (keys(%{$categories})) {
13285: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13286: if ($container eq '' && $depth == 0) {
13287: $cats->[$depth][$categories->{$item}] = $cat;
13288: } else {
13289: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13290: }
13291: my ($escitem,$tail) = split(/:/,$item,2);
13292: if ($counters{$tail} eq '') {
13293: $counters{$tail} = $num;
13294: $num ++;
13295: }
13296: if (ref($idx) eq 'HASH') {
13297: $idx->{$item} = $counters{$tail};
13298: }
13299: if (ref($jsarray) eq 'ARRAY') {
13300: push(@{$jsarray->[$counters{$tail}]},$item);
13301: }
13302: }
13303: return;
13304: }
13305:
13306: =pod
13307:
13308: =item * &extract_categories()
13309:
13310: Used to generate breadcrumb trails for course categories.
13311:
13312: Inputs:
1.663 raeburn 13313:
1.655 raeburn 13314: categories (reference to hash of category definitions).
1.663 raeburn 13315:
1.655 raeburn 13316: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13317: categories and subcategories).
1.663 raeburn 13318:
1.655 raeburn 13319: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13320:
1.655 raeburn 13321: allitems (reference to hash - key is category key
13322: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13323:
1.655 raeburn 13324: idx (reference to hash of counters used in Domain Coordinator interface for
13325: editing Course Categories).
1.663 raeburn 13326:
1.655 raeburn 13327: jsarray (reference to array of categories used to create Javascript arrays for
13328: Domain Coordinator interface for editing Course Categories).
13329:
1.665 raeburn 13330: subcats (reference to hash of arrays containing all subcategories within each
13331: category, -recursive)
13332:
1.655 raeburn 13333: Returns: nothing
13334:
13335: Side effects: populates trails and allitems hash references.
13336:
13337: =cut
13338:
13339: sub extract_categories {
1.665 raeburn 13340: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13341: if (ref($categories) eq 'HASH') {
13342: &gather_categories($categories,$cats,$idx,$jsarray);
13343: if (ref($cats->[0]) eq 'ARRAY') {
13344: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13345: my $name = $cats->[0][$i];
13346: my $item = &escape($name).'::0';
13347: my $trailstr;
13348: if ($name eq 'instcode') {
13349: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13350: } elsif ($name eq 'communities') {
13351: $trailstr = &mt('Communities');
1.655 raeburn 13352: } else {
13353: $trailstr = $name;
13354: }
13355: if ($allitems->{$item} eq '') {
13356: push(@{$trails},$trailstr);
13357: $allitems->{$item} = scalar(@{$trails})-1;
13358: }
13359: my @parents = ($name);
13360: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13361: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13362: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13363: if (ref($subcats) eq 'HASH') {
13364: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13365: }
13366: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13367: }
13368: } else {
13369: if (ref($subcats) eq 'HASH') {
13370: $subcats->{$item} = [];
1.655 raeburn 13371: }
13372: }
13373: }
13374: }
13375: }
13376: return;
13377: }
13378:
13379: =pod
13380:
1.1075.2.56 raeburn 13381: =item * &recurse_categories()
1.655 raeburn 13382:
13383: Recursively used to generate breadcrumb trails for course categories.
13384:
13385: Inputs:
1.663 raeburn 13386:
1.655 raeburn 13387: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13388: categories and subcategories).
1.663 raeburn 13389:
1.655 raeburn 13390: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13391:
13392: category (current course category, for which breadcrumb trail is being generated).
13393:
13394: trails (reference to array of breadcrumb trails for each category).
13395:
1.655 raeburn 13396: allitems (reference to hash - key is category key
13397: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13398:
1.655 raeburn 13399: parents (array containing containers directories for current category,
13400: back to top level).
13401:
13402: Returns: nothing
13403:
13404: Side effects: populates trails and allitems hash references
13405:
13406: =cut
13407:
13408: sub recurse_categories {
1.665 raeburn 13409: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13410: my $shallower = $depth - 1;
13411: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13412: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13413: my $name = $cats->[$depth]{$category}[$k];
13414: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13415: my $trailstr = join(' -> ',(@{$parents},$category));
13416: if ($allitems->{$item} eq '') {
13417: push(@{$trails},$trailstr);
13418: $allitems->{$item} = scalar(@{$trails})-1;
13419: }
13420: my $deeper = $depth+1;
13421: push(@{$parents},$category);
1.665 raeburn 13422: if (ref($subcats) eq 'HASH') {
13423: my $subcat = &escape($name).':'.$category.':'.$depth;
13424: for (my $j=@{$parents}; $j>=0; $j--) {
13425: my $higher;
13426: if ($j > 0) {
13427: $higher = &escape($parents->[$j]).':'.
13428: &escape($parents->[$j-1]).':'.$j;
13429: } else {
13430: $higher = &escape($parents->[$j]).'::'.$j;
13431: }
13432: push(@{$subcats->{$higher}},$subcat);
13433: }
13434: }
13435: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13436: $subcats);
1.655 raeburn 13437: pop(@{$parents});
13438: }
13439: } else {
13440: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13441: my $trailstr = join(' -> ',(@{$parents},$category));
13442: if ($allitems->{$item} eq '') {
13443: push(@{$trails},$trailstr);
13444: $allitems->{$item} = scalar(@{$trails})-1;
13445: }
13446: }
13447: return;
13448: }
13449:
1.663 raeburn 13450: =pod
13451:
1.1075.2.56 raeburn 13452: =item * &assign_categories_table()
1.663 raeburn 13453:
13454: Create a datatable for display of hierarchical categories in a domain,
13455: with checkboxes to allow a course to be categorized.
13456:
13457: Inputs:
13458:
13459: cathash - reference to hash of categories defined for the domain (from
13460: configuration.db)
13461:
13462: currcat - scalar with an & separated list of categories assigned to a course.
13463:
1.919 raeburn 13464: type - scalar contains course type (Course or Community).
13465:
1.663 raeburn 13466: Returns: $output (markup to be displayed)
13467:
13468: =cut
13469:
13470: sub assign_categories_table {
1.919 raeburn 13471: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13472: my $output;
13473: if (ref($cathash) eq 'HASH') {
13474: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13475: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13476: $maxdepth = scalar(@cats);
13477: if (@cats > 0) {
13478: my $itemcount = 0;
13479: if (ref($cats[0]) eq 'ARRAY') {
13480: my @currcategories;
13481: if ($currcat ne '') {
13482: @currcategories = split('&',$currcat);
13483: }
1.919 raeburn 13484: my $table;
1.663 raeburn 13485: for (my $i=0; $i<@{$cats[0]}; $i++) {
13486: my $parent = $cats[0][$i];
1.919 raeburn 13487: next if ($parent eq 'instcode');
13488: if ($type eq 'Community') {
13489: next unless ($parent eq 'communities');
13490: } else {
13491: next if ($parent eq 'communities');
13492: }
1.663 raeburn 13493: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13494: my $item = &escape($parent).'::0';
13495: my $checked = '';
13496: if (@currcategories > 0) {
13497: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13498: $checked = ' checked="checked"';
1.663 raeburn 13499: }
13500: }
1.919 raeburn 13501: my $parent_title = $parent;
13502: if ($parent eq 'communities') {
13503: $parent_title = &mt('Communities');
13504: }
13505: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13506: '<input type="checkbox" name="usecategory" value="'.
13507: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13508: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13509: my $depth = 1;
13510: push(@path,$parent);
1.919 raeburn 13511: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13512: pop(@path);
1.919 raeburn 13513: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13514: $itemcount ++;
13515: }
1.919 raeburn 13516: if ($itemcount) {
13517: $output = &Apache::loncommon::start_data_table().
13518: $table.
13519: &Apache::loncommon::end_data_table();
13520: }
1.663 raeburn 13521: }
13522: }
13523: }
13524: return $output;
13525: }
13526:
13527: =pod
13528:
1.1075.2.56 raeburn 13529: =item * &assign_category_rows()
1.663 raeburn 13530:
13531: Create a datatable row for display of nested categories in a domain,
13532: with checkboxes to allow a course to be categorized,called recursively.
13533:
13534: Inputs:
13535:
13536: itemcount - track row number for alternating colors
13537:
13538: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13539: categories and subcategories.
13540:
13541: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13542:
13543: parent - parent of current category item
13544:
13545: path - Array containing all categories back up through the hierarchy from the
13546: current category to the top level.
13547:
13548: currcategories - reference to array of current categories assigned to the course
13549:
13550: Returns: $output (markup to be displayed).
13551:
13552: =cut
13553:
13554: sub assign_category_rows {
13555: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13556: my ($text,$name,$item,$chgstr);
13557: if (ref($cats) eq 'ARRAY') {
13558: my $maxdepth = scalar(@{$cats});
13559: if (ref($cats->[$depth]) eq 'HASH') {
13560: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13561: my $numchildren = @{$cats->[$depth]{$parent}};
13562: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13563: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13564: for (my $j=0; $j<$numchildren; $j++) {
13565: $name = $cats->[$depth]{$parent}[$j];
13566: $item = &escape($name).':'.&escape($parent).':'.$depth;
13567: my $deeper = $depth+1;
13568: my $checked = '';
13569: if (ref($currcategories) eq 'ARRAY') {
13570: if (@{$currcategories} > 0) {
13571: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13572: $checked = ' checked="checked"';
1.663 raeburn 13573: }
13574: }
13575: }
1.664 raeburn 13576: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13577: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13578: $item.'"'.$checked.' />'.$name.'</label></span>'.
13579: '<input type="hidden" name="catname" value="'.$name.'" />'.
13580: '</td><td>';
1.663 raeburn 13581: if (ref($path) eq 'ARRAY') {
13582: push(@{$path},$name);
13583: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13584: pop(@{$path});
13585: }
13586: $text .= '</td></tr>';
13587: }
13588: $text .= '</table></td>';
13589: }
13590: }
13591: }
13592: return $text;
13593: }
13594:
1.655 raeburn 13595: ############################################################
13596: ############################################################
13597:
13598:
1.443 albertel 13599: sub commit_customrole {
1.664 raeburn 13600: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13601: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13602: ($start?', '.&mt('starting').' '.localtime($start):'').
13603: ($end?', ending '.localtime($end):'').': <b>'.
13604: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13605: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13606: '</b><br />';
13607: return $output;
13608: }
13609:
13610: sub commit_standardrole {
1.1075.2.31 raeburn 13611: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13612: my ($output,$logmsg,$linefeed);
13613: if ($context eq 'auto') {
13614: $linefeed = "\n";
13615: } else {
13616: $linefeed = "<br />\n";
13617: }
1.443 albertel 13618: if ($three eq 'st') {
1.541 raeburn 13619: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13620: $one,$two,$sec,$context,$credits);
1.541 raeburn 13621: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13622: ($result eq 'unknown_course') || ($result eq 'refused')) {
13623: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13624: } else {
1.541 raeburn 13625: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13626: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13627: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13628: if ($context eq 'auto') {
13629: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13630: } else {
13631: $output .= '<b>'.$result.'</b>'.$linefeed.
13632: &mt('Add to classlist').': <b>ok</b>';
13633: }
13634: $output .= $linefeed;
1.443 albertel 13635: }
13636: } else {
13637: $output = &mt('Assigning').' '.$three.' in '.$url.
13638: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13639: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13640: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13641: if ($context eq 'auto') {
13642: $output .= $result.$linefeed;
13643: } else {
13644: $output .= '<b>'.$result.'</b>'.$linefeed;
13645: }
1.443 albertel 13646: }
13647: return $output;
13648: }
13649:
13650: sub commit_studentrole {
1.1075.2.31 raeburn 13651: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13652: $credits) = @_;
1.626 raeburn 13653: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13654: if ($context eq 'auto') {
13655: $linefeed = "\n";
13656: } else {
13657: $linefeed = '<br />'."\n";
13658: }
1.443 albertel 13659: if (defined($one) && defined($two)) {
13660: my $cid=$one.'_'.$two;
13661: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13662: my $secchange = 0;
13663: my $expire_role_result;
13664: my $modify_section_result;
1.628 raeburn 13665: if ($oldsec ne '-1') {
13666: if ($oldsec ne $sec) {
1.443 albertel 13667: $secchange = 1;
1.628 raeburn 13668: my $now = time;
1.443 albertel 13669: my $uurl='/'.$cid;
13670: $uurl=~s/\_/\//g;
13671: if ($oldsec) {
13672: $uurl.='/'.$oldsec;
13673: }
1.626 raeburn 13674: $oldsecurl = $uurl;
1.628 raeburn 13675: $expire_role_result =
1.652 raeburn 13676: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13677: if ($env{'request.course.sec'} ne '') {
13678: if ($expire_role_result eq 'refused') {
13679: my @roles = ('st');
13680: my @statuses = ('previous');
13681: my @roledoms = ($one);
13682: my $withsec = 1;
13683: my %roleshash =
13684: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13685: \@statuses,\@roles,\@roledoms,$withsec);
13686: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13687: my ($oldstart,$oldend) =
13688: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13689: if ($oldend > 0 && $oldend <= $now) {
13690: $expire_role_result = 'ok';
13691: }
13692: }
13693: }
13694: }
1.443 albertel 13695: $result = $expire_role_result;
13696: }
13697: }
13698: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13699: $modify_section_result =
13700: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13701: undef,undef,undef,$sec,
13702: $end,$start,'','',$cid,
13703: '',$context,$credits);
1.443 albertel 13704: if ($modify_section_result =~ /^ok/) {
13705: if ($secchange == 1) {
1.628 raeburn 13706: if ($sec eq '') {
13707: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13708: } else {
13709: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13710: }
1.443 albertel 13711: } elsif ($oldsec eq '-1') {
1.628 raeburn 13712: if ($sec eq '') {
13713: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13714: } else {
13715: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13716: }
1.443 albertel 13717: } else {
1.628 raeburn 13718: if ($sec eq '') {
13719: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13720: } else {
13721: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13722: }
1.443 albertel 13723: }
13724: } else {
1.628 raeburn 13725: if ($secchange) {
13726: $$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;
13727: } else {
13728: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13729: }
1.443 albertel 13730: }
13731: $result = $modify_section_result;
13732: } elsif ($secchange == 1) {
1.628 raeburn 13733: if ($oldsec eq '') {
1.1075.2.20 raeburn 13734: $$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 13735: } else {
13736: $$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;
13737: }
1.626 raeburn 13738: if ($expire_role_result eq 'refused') {
13739: my $newsecurl = '/'.$cid;
13740: $newsecurl =~ s/\_/\//g;
13741: if ($sec ne '') {
13742: $newsecurl.='/'.$sec;
13743: }
13744: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13745: if ($sec eq '') {
13746: $$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;
13747: } else {
13748: $$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;
13749: }
13750: }
13751: }
1.443 albertel 13752: }
13753: } else {
1.626 raeburn 13754: $$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 13755: $result = "error: incomplete course id\n";
13756: }
13757: return $result;
13758: }
13759:
1.1075.2.25 raeburn 13760: sub show_role_extent {
13761: my ($scope,$context,$role) = @_;
13762: $scope =~ s{^/}{};
13763: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13764: push(@courseroles,'co');
13765: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13766: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13767: $scope =~ s{/}{_};
13768: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13769: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13770: my ($audom,$auname) = split(/\//,$scope);
13771: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13772: &Apache::loncommon::plainname($auname,$audom).'</span>');
13773: } else {
13774: $scope =~ s{/$}{};
13775: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13776: &Apache::lonnet::domain($scope,'description').'</span>');
13777: }
13778: }
13779:
1.443 albertel 13780: ############################################################
13781: ############################################################
13782:
1.566 albertel 13783: sub check_clone {
1.578 raeburn 13784: my ($args,$linefeed) = @_;
1.566 albertel 13785: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13786: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13787: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13788: my $clonemsg;
13789: my $can_clone = 0;
1.944 raeburn 13790: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13791: if ($lctype ne 'community') {
13792: $lctype = 'course';
13793: }
1.566 albertel 13794: if ($clonehome eq 'no_host') {
1.944 raeburn 13795: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13796: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
13797: } else {
13798: $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'});
13799: }
1.566 albertel 13800: } else {
13801: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13802: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13803: if ($clonedesc{'type'} ne 'Community') {
13804: $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'});
13805: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13806: }
13807: }
1.882 raeburn 13808: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13809: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13810: $can_clone = 1;
13811: } else {
13812: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13813: $args->{'clonedomain'},$args->{'clonecourse'});
13814: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13815: if (grep(/^\*$/,@cloners)) {
13816: $can_clone = 1;
13817: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13818: $can_clone = 1;
13819: } else {
1.908 raeburn 13820: my $ccrole = 'cc';
1.944 raeburn 13821: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13822: $ccrole = 'co';
13823: }
1.578 raeburn 13824: my %roleshash =
13825: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13826: $args->{'ccdomain'},
1.908 raeburn 13827: 'userroles',['active'],[$ccrole],
1.578 raeburn 13828: [$args->{'clonedomain'}]);
1.908 raeburn 13829: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13830: $can_clone = 1;
13831: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13832: $can_clone = 1;
13833: } else {
1.944 raeburn 13834: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13835: $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'});
13836: } else {
13837: $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'});
13838: }
1.578 raeburn 13839: }
1.566 albertel 13840: }
1.578 raeburn 13841: }
1.566 albertel 13842: }
13843: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13844: }
13845:
1.444 albertel 13846: sub construct_course {
1.885 raeburn 13847: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13848: my $outcome;
1.541 raeburn 13849: my $linefeed = '<br />'."\n";
13850: if ($context eq 'auto') {
13851: $linefeed = "\n";
13852: }
1.566 albertel 13853:
13854: #
13855: # Are we cloning?
13856: #
13857: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13858: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13859: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13860: if ($context ne 'auto') {
1.578 raeburn 13861: if ($clonemsg ne '') {
13862: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13863: }
1.566 albertel 13864: }
13865: $outcome .= $clonemsg.$linefeed;
13866:
13867: if (!$can_clone) {
13868: return (0,$outcome);
13869: }
13870: }
13871:
1.444 albertel 13872: #
13873: # Open course
13874: #
13875: my $crstype = lc($args->{'crstype'});
13876: my %cenv=();
13877: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13878: $args->{'cdescr'},
13879: $args->{'curl'},
13880: $args->{'course_home'},
13881: $args->{'nonstandard'},
13882: $args->{'crscode'},
13883: $args->{'ccuname'}.':'.
13884: $args->{'ccdomain'},
1.882 raeburn 13885: $args->{'crstype'},
1.885 raeburn 13886: $cnum,$context,$category);
1.444 albertel 13887:
13888: # Note: The testing routines depend on this being output; see
13889: # Utils::Course. This needs to at least be output as a comment
13890: # if anyone ever decides to not show this, and Utils::Course::new
13891: # will need to be suitably modified.
1.541 raeburn 13892: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13893: if ($$courseid =~ /^error:/) {
13894: return (0,$outcome);
13895: }
13896:
1.444 albertel 13897: #
13898: # Check if created correctly
13899: #
1.479 albertel 13900: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13901: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13902: if ($crsuhome eq 'no_host') {
13903: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13904: return (0,$outcome);
13905: }
1.541 raeburn 13906: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13907:
1.444 albertel 13908: #
1.566 albertel 13909: # Do the cloning
13910: #
13911: if ($can_clone && $cloneid) {
13912: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13913: if ($context ne 'auto') {
13914: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13915: }
13916: $outcome .= $clonemsg.$linefeed;
13917: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13918: # Copy all files
1.637 www 13919: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13920: # Restore URL
1.566 albertel 13921: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13922: # Restore title
1.566 albertel 13923: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13924: # Restore creation date, creator and creation context.
13925: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13926: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13927: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13928: # Mark as cloned
1.566 albertel 13929: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13930: # Need to clone grading mode
13931: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13932: $cenv{'grading'}=$newenv{'grading'};
13933: # Do not clone these environment entries
13934: &Apache::lonnet::del('environment',
13935: ['default_enrollment_start_date',
13936: 'default_enrollment_end_date',
13937: 'question.email',
13938: 'policy.email',
13939: 'comment.email',
13940: 'pch.users.denied',
1.725 raeburn 13941: 'plc.users.denied',
13942: 'hidefromcat',
1.1075.2.36 raeburn 13943: 'checkforpriv',
1.725 raeburn 13944: 'categories'],
1.638 www 13945: $$crsudom,$$crsunum);
1.444 albertel 13946: }
1.566 albertel 13947:
1.444 albertel 13948: #
13949: # Set environment (will override cloned, if existing)
13950: #
13951: my @sections = ();
13952: my @xlists = ();
13953: if ($args->{'crstype'}) {
13954: $cenv{'type'}=$args->{'crstype'};
13955: }
13956: if ($args->{'crsid'}) {
13957: $cenv{'courseid'}=$args->{'crsid'};
13958: }
13959: if ($args->{'crscode'}) {
13960: $cenv{'internal.coursecode'}=$args->{'crscode'};
13961: }
13962: if ($args->{'crsquota'} ne '') {
13963: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13964: } else {
13965: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13966: }
13967: if ($args->{'ccuname'}) {
13968: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13969: ':'.$args->{'ccdomain'};
13970: } else {
13971: $cenv{'internal.courseowner'} = $args->{'curruser'};
13972: }
1.1075.2.31 raeburn 13973: if ($args->{'defaultcredits'}) {
13974: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13975: }
1.444 albertel 13976: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13977: if ($args->{'crssections'}) {
13978: $cenv{'internal.sectionnums'} = '';
13979: if ($args->{'crssections'} =~ m/,/) {
13980: @sections = split/,/,$args->{'crssections'};
13981: } else {
13982: $sections[0] = $args->{'crssections'};
13983: }
13984: if (@sections > 0) {
13985: foreach my $item (@sections) {
13986: my ($sec,$gp) = split/:/,$item;
13987: my $class = $args->{'crscode'}.$sec;
13988: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13989: $cenv{'internal.sectionnums'} .= $item.',';
13990: unless ($addcheck eq 'ok') {
13991: push @badclasses, $class;
13992: }
13993: }
13994: $cenv{'internal.sectionnums'} =~ s/,$//;
13995: }
13996: }
13997: # do not hide course coordinator from staff listing,
13998: # even if privileged
13999: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14000: # add course coordinator's domain to domains to check for privileged users
14001: # if different to course domain
14002: if ($$crsudom ne $args->{'ccdomain'}) {
14003: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14004: }
1.444 albertel 14005: # add crosslistings
14006: if ($args->{'crsxlist'}) {
14007: $cenv{'internal.crosslistings'}='';
14008: if ($args->{'crsxlist'} =~ m/,/) {
14009: @xlists = split/,/,$args->{'crsxlist'};
14010: } else {
14011: $xlists[0] = $args->{'crsxlist'};
14012: }
14013: if (@xlists > 0) {
14014: foreach my $item (@xlists) {
14015: my ($xl,$gp) = split/:/,$item;
14016: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14017: $cenv{'internal.crosslistings'} .= $item.',';
14018: unless ($addcheck eq 'ok') {
14019: push @badclasses, $xl;
14020: }
14021: }
14022: $cenv{'internal.crosslistings'} =~ s/,$//;
14023: }
14024: }
14025: if ($args->{'autoadds'}) {
14026: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14027: }
14028: if ($args->{'autodrops'}) {
14029: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14030: }
14031: # check for notification of enrollment changes
14032: my @notified = ();
14033: if ($args->{'notify_owner'}) {
14034: if ($args->{'ccuname'} ne '') {
14035: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14036: }
14037: }
14038: if ($args->{'notify_dc'}) {
14039: if ($uname ne '') {
1.630 raeburn 14040: push(@notified,$uname.':'.$udom);
1.444 albertel 14041: }
14042: }
14043: if (@notified > 0) {
14044: my $notifylist;
14045: if (@notified > 1) {
14046: $notifylist = join(',',@notified);
14047: } else {
14048: $notifylist = $notified[0];
14049: }
14050: $cenv{'internal.notifylist'} = $notifylist;
14051: }
14052: if (@badclasses > 0) {
14053: my %lt=&Apache::lonlocal::texthash(
14054: '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',
14055: 'dnhr' => 'does not have rights to access enrollment in these classes',
14056: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14057: );
1.541 raeburn 14058: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14059: ' ('.$lt{'adby'}.')';
14060: if ($context eq 'auto') {
14061: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14062: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14063: foreach my $item (@badclasses) {
14064: if ($context eq 'auto') {
14065: $outcome .= " - $item\n";
14066: } else {
14067: $outcome .= "<li>$item</li>\n";
14068: }
14069: }
14070: if ($context eq 'auto') {
14071: $outcome .= $linefeed;
14072: } else {
1.566 albertel 14073: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14074: }
14075: }
1.444 albertel 14076: }
14077: if ($args->{'no_end_date'}) {
14078: $args->{'endaccess'} = 0;
14079: }
14080: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14081: $cenv{'internal.autoend'}=$args->{'enrollend'};
14082: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14083: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14084: if ($args->{'showphotos'}) {
14085: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14086: }
14087: $cenv{'internal.authtype'} = $args->{'authtype'};
14088: $cenv{'internal.autharg'} = $args->{'autharg'};
14089: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14090: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14091: 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');
14092: if ($context eq 'auto') {
14093: $outcome .= $krb_msg;
14094: } else {
1.566 albertel 14095: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14096: }
14097: $outcome .= $linefeed;
1.444 albertel 14098: }
14099: }
14100: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14101: if ($args->{'setpolicy'}) {
14102: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14103: }
14104: if ($args->{'setcontent'}) {
14105: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14106: }
14107: }
14108: if ($args->{'reshome'}) {
14109: $cenv{'reshome'}=$args->{'reshome'}.'/';
14110: $cenv{'reshome'}=~s/\/+$/\//;
14111: }
14112: #
14113: # course has keyed access
14114: #
14115: if ($args->{'setkeys'}) {
14116: $cenv{'keyaccess'}='yes';
14117: }
14118: # if specified, key authority is not course, but user
14119: # only active if keyaccess is yes
14120: if ($args->{'keyauth'}) {
1.487 albertel 14121: my ($user,$domain) = split(':',$args->{'keyauth'});
14122: $user = &LONCAPA::clean_username($user);
14123: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14124: if ($user ne '' && $domain ne '') {
1.487 albertel 14125: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14126: }
14127: }
14128:
14129: if ($args->{'disresdis'}) {
14130: $cenv{'pch.roles.denied'}='st';
14131: }
14132: if ($args->{'disablechat'}) {
14133: $cenv{'plc.roles.denied'}='st';
14134: }
14135:
14136: # Record we've not yet viewed the Course Initialization Helper for this
14137: # course
14138: $cenv{'course.helper.not.run'} = 1;
14139: #
14140: # Use new Randomseed
14141: #
14142: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14143: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14144: #
14145: # The encryption code and receipt prefix for this course
14146: #
14147: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14148: $cenv{'internal.encpref'}=100+int(9*rand(99));
14149: #
14150: # By default, use standard grading
14151: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14152:
1.541 raeburn 14153: $outcome .= $linefeed.&mt('Setting environment').': '.
14154: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14155: #
14156: # Open all assignments
14157: #
14158: if ($args->{'openall'}) {
14159: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14160: my %storecontent = ($storeunder => time,
14161: $storeunder.'.type' => 'date_start');
14162:
14163: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14164: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14165: }
14166: #
14167: # Set first page
14168: #
14169: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14170: || ($cloneid)) {
1.445 albertel 14171: use LONCAPA::map;
1.444 albertel 14172: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14173:
14174: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14175: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14176:
1.444 albertel 14177: $outcome .= ($fatal?$errtext:'read ok').' - ';
14178: my $title; my $url;
14179: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14180: $title=&mt('Syllabus');
1.444 albertel 14181: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14182: } else {
1.963 raeburn 14183: $title=&mt('Table of Contents');
1.444 albertel 14184: $url='/adm/navmaps';
14185: }
1.445 albertel 14186:
14187: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14188: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14189:
14190: if ($errtext) { $fatal=2; }
1.541 raeburn 14191: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14192: }
1.566 albertel 14193:
14194: return (1,$outcome);
1.444 albertel 14195: }
14196:
14197: ############################################################
14198: ############################################################
14199:
1.953 droeschl 14200: #SD
14201: # only Community and Course, or anything else?
1.378 raeburn 14202: sub course_type {
14203: my ($cid) = @_;
14204: if (!defined($cid)) {
14205: $cid = $env{'request.course.id'};
14206: }
1.404 albertel 14207: if (defined($env{'course.'.$cid.'.type'})) {
14208: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14209: } else {
14210: return 'Course';
1.377 raeburn 14211: }
14212: }
1.156 albertel 14213:
1.406 raeburn 14214: sub group_term {
14215: my $crstype = &course_type();
14216: my %names = (
14217: 'Course' => 'group',
1.865 raeburn 14218: 'Community' => 'group',
1.406 raeburn 14219: );
14220: return $names{$crstype};
14221: }
14222:
1.902 raeburn 14223: sub course_types {
14224: my @types = ('official','unofficial','community');
14225: my %typename = (
14226: official => 'Official course',
14227: unofficial => 'Unofficial course',
14228: community => 'Community',
14229: );
14230: return (\@types,\%typename);
14231: }
14232:
1.156 albertel 14233: sub icon {
14234: my ($file)=@_;
1.505 albertel 14235: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14236: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14237: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14238: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14239: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14240: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14241: $curfext.".gif") {
14242: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14243: $curfext.".gif";
14244: }
14245: }
1.249 albertel 14246: return &lonhttpdurl($iconname);
1.154 albertel 14247: }
1.84 albertel 14248:
1.575 albertel 14249: sub lonhttpdurl {
1.692 www 14250: #
14251: # Had been used for "small fry" static images on separate port 8080.
14252: # Modify here if lightweight http functionality desired again.
14253: # Currently eliminated due to increasing firewall issues.
14254: #
1.575 albertel 14255: my ($url)=@_;
1.692 www 14256: return $url;
1.215 albertel 14257: }
14258:
1.213 albertel 14259: sub connection_aborted {
14260: my ($r)=@_;
14261: $r->print(" ");$r->rflush();
14262: my $c = $r->connection;
14263: return $c->aborted();
14264: }
14265:
1.221 foxr 14266: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14267: # strings as 'strings'.
14268: sub escape_single {
1.221 foxr 14269: my ($input) = @_;
1.223 albertel 14270: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14271: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14272: return $input;
14273: }
1.223 albertel 14274:
1.222 foxr 14275: # Same as escape_single, but escape's "'s This
14276: # can be used for "strings"
14277: sub escape_double {
14278: my ($input) = @_;
14279: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14280: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14281: return $input;
14282: }
1.223 albertel 14283:
1.222 foxr 14284: # Escapes the last element of a full URL.
14285: sub escape_url {
14286: my ($url) = @_;
1.238 raeburn 14287: my @urlslices = split(/\//, $url,-1);
1.369 www 14288: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14289: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14290: }
1.462 albertel 14291:
1.820 raeburn 14292: sub compare_arrays {
14293: my ($arrayref1,$arrayref2) = @_;
14294: my (@difference,%count);
14295: @difference = ();
14296: %count = ();
14297: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14298: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14299: foreach my $element (keys(%count)) {
14300: if ($count{$element} == 1) {
14301: push(@difference,$element);
14302: }
14303: }
14304: }
14305: return @difference;
14306: }
14307:
1.817 bisitz 14308: # -------------------------------------------------------- Initialize user login
1.462 albertel 14309: sub init_user_environment {
1.463 albertel 14310: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14311: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14312:
14313: my $public=($username eq 'public' && $domain eq 'public');
14314:
14315: # See if old ID present, if so, remove
14316:
1.1062 raeburn 14317: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14318: my $now=time;
14319:
14320: if ($public) {
14321: my $max_public=100;
14322: my $oldest;
14323: my $oldest_time=0;
14324: for(my $next=1;$next<=$max_public;$next++) {
14325: if (-e $lonids."/publicuser_$next.id") {
14326: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14327: if ($mtime<$oldest_time || !$oldest_time) {
14328: $oldest_time=$mtime;
14329: $oldest=$next;
14330: }
14331: } else {
14332: $cookie="publicuser_$next";
14333: last;
14334: }
14335: }
14336: if (!$cookie) { $cookie="publicuser_$oldest"; }
14337: } else {
1.463 albertel 14338: # if this isn't a robot, kill any existing non-robot sessions
14339: if (!$args->{'robot'}) {
14340: opendir(DIR,$lonids);
14341: while ($filename=readdir(DIR)) {
14342: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14343: unlink($lonids.'/'.$filename);
14344: }
1.462 albertel 14345: }
1.463 albertel 14346: closedir(DIR);
1.462 albertel 14347: }
14348: # Give them a new cookie
1.463 albertel 14349: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14350: : $now.$$.int(rand(10000)));
1.463 albertel 14351: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14352:
14353: # Initialize roles
14354:
1.1062 raeburn 14355: ($userroles,$firstaccenv,$timerintenv) =
14356: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14357: }
14358: # ------------------------------------ Check browser type and MathML capability
14359:
14360: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14361: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14362:
14363: # ------------------------------------------------------------- Get environment
14364:
14365: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14366: my ($tmp) = keys(%userenv);
14367: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14368: } else {
14369: undef(%userenv);
14370: }
14371: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14372: $form->{'interface'}=$userenv{'interface'};
14373: }
14374: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14375:
14376: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14377: foreach my $option ('interface','localpath','localres') {
14378: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14379: }
14380: # --------------------------------------------------------- Write first profile
14381:
14382: {
14383: my %initial_env =
14384: ("user.name" => $username,
14385: "user.domain" => $domain,
14386: "user.home" => $authhost,
14387: "browser.type" => $clientbrowser,
14388: "browser.version" => $clientversion,
14389: "browser.mathml" => $clientmathml,
14390: "browser.unicode" => $clientunicode,
14391: "browser.os" => $clientos,
1.1075.2.42 raeburn 14392: "browser.mobile" => $clientmobile,
14393: "browser.info" => $clientinfo,
1.462 albertel 14394: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14395: "request.course.fn" => '',
14396: "request.course.uri" => '',
14397: "request.course.sec" => '',
14398: "request.role" => 'cm',
14399: "request.role.adv" => $env{'user.adv'},
14400: "request.host" => $ENV{'REMOTE_ADDR'},);
14401:
14402: if ($form->{'localpath'}) {
14403: $initial_env{"browser.localpath"} = $form->{'localpath'};
14404: $initial_env{"browser.localres"} = $form->{'localres'};
14405: }
14406:
14407: if ($form->{'interface'}) {
14408: $form->{'interface'}=~s/\W//gs;
14409: $initial_env{"browser.interface"} = $form->{'interface'};
14410: $env{'browser.interface'}=$form->{'interface'};
14411: }
14412:
1.1075.2.54 raeburn 14413: if ($form->{'iptoken'}) {
14414: my $lonhost = $r->dir_config('lonHostID');
14415: $initial_env{"user.noloadbalance"} = $lonhost;
14416: $env{'user.noloadbalance'} = $lonhost;
14417: }
14418:
1.981 raeburn 14419: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14420: my %domdef;
14421: unless ($domain eq 'public') {
14422: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14423: }
1.980 raeburn 14424:
1.1075.2.7 raeburn 14425: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14426: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14427: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14428: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14429: }
14430:
1.864 raeburn 14431: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14432: $userenv{'canrequest.'.$crstype} =
14433: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14434: 'reload','requestcourses',
14435: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14436: }
14437:
1.1075.2.14 raeburn 14438: $userenv{'canrequest.author'} =
14439: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14440: 'reload','requestauthor',
14441: \%userenv,\%domdef,\%is_adv);
14442: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14443: $domain,$username);
14444: my $reqstatus = $reqauthor{'author_status'};
14445: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14446: if (ref($reqauthor{'author'}) eq 'HASH') {
14447: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14448: $reqauthor{'author'}{'timestamp'};
14449: }
14450: }
14451:
1.462 albertel 14452: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14453:
1.462 albertel 14454: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14455: &GDBM_WRCREAT(),0640)) {
14456: &_add_to_env(\%disk_env,\%initial_env);
14457: &_add_to_env(\%disk_env,\%userenv,'environment.');
14458: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14459: if (ref($firstaccenv) eq 'HASH') {
14460: &_add_to_env(\%disk_env,$firstaccenv);
14461: }
14462: if (ref($timerintenv) eq 'HASH') {
14463: &_add_to_env(\%disk_env,$timerintenv);
14464: }
1.463 albertel 14465: if (ref($args->{'extra_env'})) {
14466: &_add_to_env(\%disk_env,$args->{'extra_env'});
14467: }
1.462 albertel 14468: untie(%disk_env);
14469: } else {
1.705 tempelho 14470: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14471: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14472: return 'error: '.$!;
14473: }
14474: }
14475: $env{'request.role'}='cm';
14476: $env{'request.role.adv'}=$env{'user.adv'};
14477: $env{'browser.type'}=$clientbrowser;
14478:
14479: return $cookie;
14480:
14481: }
14482:
14483: sub _add_to_env {
14484: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14485: if (ref($env_data) eq 'HASH') {
14486: while (my ($key,$value) = each(%$env_data)) {
14487: $idf->{$prefix.$key} = $value;
14488: $env{$prefix.$key} = $value;
14489: }
1.462 albertel 14490: }
14491: }
14492:
1.685 tempelho 14493: # --- Get the symbolic name of a problem and the url
14494: sub get_symb {
14495: my ($request,$silent) = @_;
1.726 raeburn 14496: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14497: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14498: if ($symb eq '') {
14499: if (!$silent) {
1.1071 raeburn 14500: if (ref($request)) {
14501: $request->print("Unable to handle ambiguous references:$url:.");
14502: }
1.685 tempelho 14503: return ();
14504: }
14505: }
14506: &Apache::lonenc::check_decrypt(\$symb);
14507: return ($symb);
14508: }
14509:
14510: # --------------------------------------------------------------Get annotation
14511:
14512: sub get_annotation {
14513: my ($symb,$enc) = @_;
14514:
14515: my $key = $symb;
14516: if (!$enc) {
14517: $key =
14518: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14519: }
14520: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14521: return $annotation{$key};
14522: }
14523:
14524: sub clean_symb {
1.731 raeburn 14525: my ($symb,$delete_enc) = @_;
1.685 tempelho 14526:
14527: &Apache::lonenc::check_decrypt(\$symb);
14528: my $enc = $env{'request.enc'};
1.731 raeburn 14529: if ($delete_enc) {
1.730 raeburn 14530: delete($env{'request.enc'});
14531: }
1.685 tempelho 14532:
14533: return ($symb,$enc);
14534: }
1.462 albertel 14535:
1.990 raeburn 14536: sub build_release_hashes {
14537: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14538: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14539: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14540: (ref($randomizetry) eq 'HASH'));
14541: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14542: my ($item,$name,$value) = split(/:/,$key);
14543: if ($item eq 'parameter') {
14544: if (ref($checkparms->{$name}) eq 'ARRAY') {
14545: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14546: push(@{$checkparms->{$name}},$value);
14547: }
14548: } else {
14549: push(@{$checkparms->{$name}},$value);
14550: }
14551: } elsif ($item eq 'resourcetag') {
14552: if ($name eq 'responsetype') {
14553: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14554: }
14555: } elsif ($item eq 'course') {
14556: if ($name eq 'crstype') {
14557: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14558: }
14559: }
14560: }
14561: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14562: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14563: return;
14564: }
14565:
1.1075.2.11 raeburn 14566: sub update_content_constraints {
14567: my ($cdom,$cnum,$chome,$cid) = @_;
14568: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14569: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14570: my %checkresponsetypes;
14571: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14572: my ($item,$name,$value) = split(/:/,$key);
14573: if ($item eq 'resourcetag') {
14574: if ($name eq 'responsetype') {
14575: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14576: }
14577: }
14578: }
14579: my $navmap = Apache::lonnavmaps::navmap->new();
14580: if (defined($navmap)) {
14581: my %allresponses;
14582: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14583: my %responses = $res->responseTypes();
14584: foreach my $key (keys(%responses)) {
14585: next unless(exists($checkresponsetypes{$key}));
14586: $allresponses{$key} += $responses{$key};
14587: }
14588: }
14589: foreach my $key (keys(%allresponses)) {
14590: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14591: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14592: ($reqdmajor,$reqdminor) = ($major,$minor);
14593: }
14594: }
14595: undef($navmap);
14596: }
14597: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14598: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14599: }
14600: return;
14601: }
14602:
1.1075.2.27 raeburn 14603: sub allmaps_incourse {
14604: my ($cdom,$cnum,$chome,$cid) = @_;
14605: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14606: $cid = $env{'request.course.id'};
14607: $cdom = $env{'course.'.$cid.'.domain'};
14608: $cnum = $env{'course.'.$cid.'.num'};
14609: $chome = $env{'course.'.$cid.'.home'};
14610: }
14611: my %allmaps = ();
14612: my $lastchange =
14613: &Apache::lonnet::get_coursechange($cdom,$cnum);
14614: if ($lastchange > $env{'request.course.tied'}) {
14615: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14616: unless ($ferr) {
14617: &update_content_constraints($cdom,$cnum,$chome,$cid);
14618: }
14619: }
14620: my $navmap = Apache::lonnavmaps::navmap->new();
14621: if (defined($navmap)) {
14622: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14623: $allmaps{$res->src()} = 1;
14624: }
14625: }
14626: return \%allmaps;
14627: }
14628:
1.1075.2.11 raeburn 14629: sub parse_supplemental_title {
14630: my ($title) = @_;
14631:
14632: my ($foldertitle,$renametitle);
14633: if ($title =~ /&&&/) {
14634: $title = &HTML::Entites::decode($title);
14635: }
14636: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14637: $renametitle=$4;
14638: my ($time,$uname,$udom) = ($1,$2,$3);
14639: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14640: my $name = &plainname($uname,$udom);
14641: $name = &HTML::Entities::encode($name,'"<>&\'');
14642: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14643: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14644: $name.': <br />'.$foldertitle;
14645: }
14646: if (wantarray) {
14647: return ($title,$foldertitle,$renametitle);
14648: }
14649: return $title;
14650: }
14651:
1.1075.2.43 raeburn 14652: sub recurse_supplemental {
14653: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14654: if ($suppmap) {
14655: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14656: if ($fatal) {
14657: $errors ++;
14658: } else {
14659: if ($#LONCAPA::map::resources > 0) {
14660: foreach my $res (@LONCAPA::map::resources) {
14661: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14662: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 14663: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14664: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 14665: } else {
14666: $numfiles ++;
14667: }
14668: }
14669: }
14670: }
14671: }
14672: }
14673: return ($numfiles,$errors);
14674: }
14675:
1.1075.2.18 raeburn 14676: sub symb_to_docspath {
14677: my ($symb) = @_;
14678: return unless ($symb);
14679: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14680: if ($resurl=~/\.(sequence|page)$/) {
14681: $mapurl=$resurl;
14682: } elsif ($resurl eq 'adm/navmaps') {
14683: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14684: }
14685: my $mapresobj;
14686: my $navmap = Apache::lonnavmaps::navmap->new();
14687: if (ref($navmap)) {
14688: $mapresobj = $navmap->getResourceByUrl($mapurl);
14689: }
14690: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14691: my $type=$2;
14692: my $path;
14693: if (ref($mapresobj)) {
14694: my $pcslist = $mapresobj->map_hierarchy();
14695: if ($pcslist ne '') {
14696: foreach my $pc (split(/,/,$pcslist)) {
14697: next if ($pc <= 1);
14698: my $res = $navmap->getByMapPc($pc);
14699: if (ref($res)) {
14700: my $thisurl = $res->src();
14701: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14702: my $thistitle = $res->title();
14703: $path .= '&'.
14704: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 14705: &escape($thistitle).
1.1075.2.18 raeburn 14706: ':'.$res->randompick().
14707: ':'.$res->randomout().
14708: ':'.$res->encrypted().
14709: ':'.$res->randomorder().
14710: ':'.$res->is_page();
14711: }
14712: }
14713: }
14714: $path =~ s/^\&//;
14715: my $maptitle = $mapresobj->title();
14716: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14717: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14718: }
14719: $path .= (($path ne '')? '&' : '').
14720: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14721: &escape($maptitle).
1.1075.2.18 raeburn 14722: ':'.$mapresobj->randompick().
14723: ':'.$mapresobj->randomout().
14724: ':'.$mapresobj->encrypted().
14725: ':'.$mapresobj->randomorder().
14726: ':'.$mapresobj->is_page();
14727: } else {
14728: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14729: my $ispage = (($type eq 'page')? 1 : '');
14730: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14731: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14732: }
14733: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14734: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 14735: }
14736: unless ($mapurl eq 'default') {
14737: $path = 'default&'.
1.1075.2.46 raeburn 14738: &escape('Main Content').
1.1075.2.18 raeburn 14739: ':::::&'.$path;
14740: }
14741: return $path;
14742: }
14743:
1.1075.2.14 raeburn 14744: sub captcha_display {
14745: my ($context,$lonhost) = @_;
14746: my ($output,$error);
14747: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14748: if ($captcha eq 'original') {
14749: $output = &create_captcha();
14750: unless ($output) {
14751: $error = 'captcha';
14752: }
14753: } elsif ($captcha eq 'recaptcha') {
14754: $output = &create_recaptcha($pubkey);
14755: unless ($output) {
14756: $error = 'recaptcha';
14757: }
14758: }
14759: return ($output,$error);
14760: }
14761:
14762: sub captcha_response {
14763: my ($context,$lonhost) = @_;
14764: my ($captcha_chk,$captcha_error);
14765: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14766: if ($captcha eq 'original') {
14767: ($captcha_chk,$captcha_error) = &check_captcha();
14768: } elsif ($captcha eq 'recaptcha') {
14769: $captcha_chk = &check_recaptcha($privkey);
14770: } else {
14771: $captcha_chk = 1;
14772: }
14773: return ($captcha_chk,$captcha_error);
14774: }
14775:
14776: sub get_captcha_config {
14777: my ($context,$lonhost) = @_;
14778: my ($captcha,$pubkey,$privkey,$hashtocheck);
14779: my $hostname = &Apache::lonnet::hostname($lonhost);
14780: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14781: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14782: if ($context eq 'usercreation') {
14783: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14784: if (ref($domconfig{$context}) eq 'HASH') {
14785: $hashtocheck = $domconfig{$context}{'cancreate'};
14786: if (ref($hashtocheck) eq 'HASH') {
14787: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14788: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14789: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14790: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14791: }
14792: if ($privkey && $pubkey) {
14793: $captcha = 'recaptcha';
14794: } else {
14795: $captcha = 'original';
14796: }
14797: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14798: $captcha = 'original';
14799: }
14800: }
14801: } else {
14802: $captcha = 'captcha';
14803: }
14804: } elsif ($context eq 'login') {
14805: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14806: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14807: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14808: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14809: if ($privkey && $pubkey) {
14810: $captcha = 'recaptcha';
14811: } else {
14812: $captcha = 'original';
14813: }
14814: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14815: $captcha = 'original';
14816: }
14817: }
14818: return ($captcha,$pubkey,$privkey);
14819: }
14820:
14821: sub create_captcha {
14822: my %captcha_params = &captcha_settings();
14823: my ($output,$maxtries,$tries) = ('',10,0);
14824: while ($tries < $maxtries) {
14825: $tries ++;
14826: my $captcha = Authen::Captcha->new (
14827: output_folder => $captcha_params{'output_dir'},
14828: data_folder => $captcha_params{'db_dir'},
14829: );
14830: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14831:
14832: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14833: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14834: &mt('Type in the letters/numbers shown below').' '.
14835: '<input type="text" size="5" name="code" value="" /><br />'.
14836: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14837: last;
14838: }
14839: }
14840: return $output;
14841: }
14842:
14843: sub captcha_settings {
14844: my %captcha_params = (
14845: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14846: www_output_dir => "/captchaspool",
14847: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14848: numchars => '5',
14849: );
14850: return %captcha_params;
14851: }
14852:
14853: sub check_captcha {
14854: my ($captcha_chk,$captcha_error);
14855: my $code = $env{'form.code'};
14856: my $md5sum = $env{'form.crypt'};
14857: my %captcha_params = &captcha_settings();
14858: my $captcha = Authen::Captcha->new(
14859: output_folder => $captcha_params{'output_dir'},
14860: data_folder => $captcha_params{'db_dir'},
14861: );
1.1075.2.26 raeburn 14862: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 14863: my %captcha_hash = (
14864: 0 => 'Code not checked (file error)',
14865: -1 => 'Failed: code expired',
14866: -2 => 'Failed: invalid code (not in database)',
14867: -3 => 'Failed: invalid code (code does not match crypt)',
14868: );
14869: if ($captcha_chk != 1) {
14870: $captcha_error = $captcha_hash{$captcha_chk}
14871: }
14872: return ($captcha_chk,$captcha_error);
14873: }
14874:
14875: sub create_recaptcha {
14876: my ($pubkey) = @_;
1.1075.2.51 raeburn 14877: my $use_ssl;
14878: if ($ENV{'SERVER_PORT'} == 443) {
14879: $use_ssl = 1;
14880: }
1.1075.2.14 raeburn 14881: my $captcha = Captcha::reCAPTCHA->new;
14882: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 14883: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 14884: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 14885: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 14886: '<br /><br />';
14887: }
14888:
14889: sub check_recaptcha {
14890: my ($privkey) = @_;
14891: my $captcha_chk;
14892: my $captcha = Captcha::reCAPTCHA->new;
14893: my $captcha_result =
14894: $captcha->check_answer(
14895: $privkey,
14896: $ENV{'REMOTE_ADDR'},
14897: $env{'form.recaptcha_challenge_field'},
14898: $env{'form.recaptcha_response_field'},
14899: );
14900: if ($captcha_result->{is_valid}) {
14901: $captcha_chk = 1;
14902: }
14903: return $captcha_chk;
14904: }
14905:
1.1075.2.56 raeburn 14906: sub cleanup_html {
14907: my ($incoming) = @_;
14908: my $outgoing;
14909: if ($incoming ne '') {
14910: $outgoing = $incoming;
14911: $outgoing =~ s/;/;/g;
14912: $outgoing =~ s/\#/#/g;
14913: $outgoing =~ s/\&/&/g;
14914: $outgoing =~ s/</</g;
14915: $outgoing =~ s/>/>/g;
14916: $outgoing =~ s/\(/(/g;
14917: $outgoing =~ s/\)/)/g;
14918: $outgoing =~ s/"/"/g;
14919: $outgoing =~ s/'/'/g;
14920: $outgoing =~ s/\$/$/g;
14921: $outgoing =~ s{/}{/}g;
14922: $outgoing =~ s/=/=/g;
14923: $outgoing =~ s/\\/\/g
14924: }
14925: return $outgoing;
14926: }
14927:
1.41 ng 14928: =pod
14929:
14930: =back
14931:
1.112 bowersj2 14932: =cut
1.41 ng 14933:
1.112 bowersj2 14934: 1;
14935: __END__;
1.41 ng 14936:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>