Annotation of loncom/interface/loncommon.pm, revision 1.1088
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1088 ! foxr 4: # $Id: loncommon.pm,v 1.1087 2012/07/21 22:10:23 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.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.1088 ! foxr 157: my %supported_codes;
1.1048 foxr 158: my %latex_language; # For choosing hyphenation in <transl..>
159: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 160: my %cprtag;
1.192 taceyjo1 161: my %scprtag;
1.351 www 162: my %fe; my %fd; my %fm;
1.41 ng 163: my %category_extensions;
1.12 harris41 164:
1.46 matthew 165: # ---------------------------------------------- Thesaurus variables
1.144 matthew 166: #
167: # %Keywords:
168: # A hash used by &keyword to determine if a word is considered a keyword.
169: # $thesaurus_db_file
170: # Scalar containing the full path to the thesaurus database.
1.46 matthew 171:
172: my %Keywords;
173: my $thesaurus_db_file;
174:
1.144 matthew 175: #
176: # Initialize values from language.tab, copyright.tab, filetypes.tab,
177: # thesaurus.tab, and filecategories.tab.
178: #
1.18 www 179: BEGIN {
1.46 matthew 180: # Variable initialization
181: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
182: #
1.22 www 183: unless ($readit) {
1.12 harris41 184: # ------------------------------------------------------------------- languages
185: {
1.158 raeburn 186: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
187: '/language.tab';
188: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 189: while (my $line = <$fh>) {
190: next if ($line=~/^\#/);
191: chomp($line);
1.1088 ! foxr 192: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 193: $language{$key}=$val.' - '.$enc;
194: if ($sup) {
195: $supported_language{$key}=$sup;
1.1088 ! foxr 196: $supported_codes{$key} = $code;
1.158 raeburn 197: }
1.1048 foxr 198: if ($latex) {
199: $latex_language_bykey{$key} = $latex;
1.1088 ! foxr 200: $latex_language{$code} = $latex;
1.1048 foxr 201: }
1.158 raeburn 202: }
203: close($fh);
204: }
1.12 harris41 205: }
206: # ------------------------------------------------------------------ copyrights
207: {
1.158 raeburn 208: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
209: '/copyright.tab';
210: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 211: while (my $line = <$fh>) {
212: next if ($line=~/^\#/);
213: chomp($line);
214: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 215: $cprtag{$key}=$val;
216: }
217: close($fh);
218: }
1.12 harris41 219: }
1.351 www 220: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 221: {
222: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/source_copyright.tab';
224: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line =~ /^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 229: $scprtag{$key}=$val;
230: }
231: close($fh);
232: }
233: }
1.63 www 234:
1.517 raeburn 235: # -------------------------------------------------------------- default domain designs
1.63 www 236: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 237: my $designfile = $designdir.'/default.tab';
238: if ( open (my $fh,"<$designfile") ) {
239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\=/,$line));
243: if ($val) { $defaultdesign{$key}=$val; }
244: }
245: close($fh);
1.63 www 246: }
247:
1.15 harris41 248: # ------------------------------------------------------------- file categories
249: {
1.158 raeburn 250: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
251: '/filecategories.tab';
252: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 257: push @{$category_extensions{lc($category)}},$extension;
258: }
259: close($fh);
260: }
261:
1.15 harris41 262: }
1.12 harris41 263: # ------------------------------------------------------------------ file types
264: {
1.158 raeburn 265: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
266: '/filetypes.tab';
267: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 268: while (my $line = <$fh>) {
269: next if ($line =~ /^\#/);
270: chomp($line);
271: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 272: if ($descr ne '') {
273: $fe{$ending}=lc($emb);
274: $fd{$ending}=$descr;
1.351 www 275: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 276: }
277: }
278: close($fh);
279: }
1.12 harris41 280: }
1.22 www 281: &Apache::lonnet::logthis(
1.705 tempelho 282: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 283: $readit=1;
1.46 matthew 284: } # end of unless($readit)
1.32 matthew 285:
286: }
1.112 bowersj2 287:
1.42 matthew 288: ###############################################################
289: ## HTML and Javascript Helper Functions ##
290: ###############################################################
291:
292: =pod
293:
1.112 bowersj2 294: =head1 HTML and Javascript Functions
1.42 matthew 295:
1.112 bowersj2 296: =over 4
297:
1.648 raeburn 298: =item * &browser_and_searcher_javascript()
1.112 bowersj2 299:
300: X<browsing, javascript>X<searching, javascript>Returns a string
301: containing javascript with two functions, C<openbrowser> and
302: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
303: tags.
1.42 matthew 304:
1.648 raeburn 305: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 306:
307: inputs: formname, elementname, only, omit
308:
309: formname and elementname indicate the name of the html form and name of
310: the element that the results of the browsing selection are to be placed in.
311:
312: Specifying 'only' will restrict the browser to displaying only files
1.185 www 313: with the given extension. Can be a comma separated list.
1.42 matthew 314:
315: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 316: with the given extension. Can be a comma separated list.
1.42 matthew 317:
1.648 raeburn 318: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 319:
320: Inputs: formname, elementname
321:
322: formname and elementname specify the name of the html form and the name
323: of the element the selection from the search results will be placed in.
1.542 raeburn 324:
1.42 matthew 325: =cut
326:
327: sub browser_and_searcher_javascript {
1.199 albertel 328: my ($mode)=@_;
329: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 330: my $resurl=&escape_single(&lastresurl());
1.42 matthew 331: return <<END;
1.219 albertel 332: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 333: var editbrowser = null;
1.135 albertel 334: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 335: var url = '$resurl/?';
1.42 matthew 336: if (editbrowser == null) {
337: url += 'launch=1&';
338: }
339: url += 'catalogmode=interactive&';
1.199 albertel 340: url += 'mode=$mode&';
1.611 albertel 341: url += 'inhibitmenu=yes&';
1.42 matthew 342: url += 'form=' + formname + '&';
343: if (only != null) {
344: url += 'only=' + only + '&';
1.217 albertel 345: } else {
346: url += 'only=&';
347: }
1.42 matthew 348: if (omit != null) {
349: url += 'omit=' + omit + '&';
1.217 albertel 350: } else {
351: url += 'omit=&';
352: }
1.135 albertel 353: if (titleelement != null) {
354: url += 'titleelement=' + titleelement + '&';
1.217 albertel 355: } else {
356: url += 'titleelement=&';
357: }
1.42 matthew 358: url += 'element=' + elementname + '';
359: var title = 'Browser';
1.435 albertel 360: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 361: options += ',width=700,height=600';
362: editbrowser = open(url,title,options,'1');
363: editbrowser.focus();
364: }
365: var editsearcher;
1.135 albertel 366: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 367: var url = '/adm/searchcat?';
368: if (editsearcher == null) {
369: url += 'launch=1&';
370: }
371: url += 'catalogmode=interactive&';
1.199 albertel 372: url += 'mode=$mode&';
1.42 matthew 373: url += 'form=' + formname + '&';
1.135 albertel 374: if (titleelement != null) {
375: url += 'titleelement=' + titleelement + '&';
1.217 albertel 376: } else {
377: url += 'titleelement=&';
378: }
1.42 matthew 379: url += 'element=' + elementname + '';
380: var title = 'Search';
1.435 albertel 381: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 382: options += ',width=700,height=600';
383: editsearcher = open(url,title,options,'1');
384: editsearcher.focus();
385: }
1.219 albertel 386: // END LON-CAPA Internal -->
1.42 matthew 387: END
1.170 www 388: }
389:
390: sub lastresurl {
1.258 albertel 391: if ($env{'environment.lastresurl'}) {
392: return $env{'environment.lastresurl'}
1.170 www 393: } else {
394: return '/res';
395: }
396: }
397:
398: sub storeresurl {
399: my $resurl=&Apache::lonnet::clutter(shift);
400: unless ($resurl=~/^\/res/) { return 0; }
401: $resurl=~s/\/$//;
402: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 403: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 404: return 1;
1.42 matthew 405: }
406:
1.74 www 407: sub studentbrowser_javascript {
1.111 www 408: unless (
1.258 albertel 409: (($env{'request.course.id'}) &&
1.302 albertel 410: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
411: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
412: '/'.$env{'request.course.sec'})
413: ))
1.258 albertel 414: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 415: ) { return ''; }
1.74 www 416: return (<<'ENDSTDBRW');
1.776 bisitz 417: <script type="text/javascript" language="Javascript">
1.824 bisitz 418: // <![CDATA[
1.74 www 419: var stdeditbrowser;
1.999 www 420: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 421: var url = '/adm/pickstudent?';
422: var filter;
1.558 albertel 423: if (!ignorefilter) {
424: eval('filter=document.'+formname+'.'+uname+'.value;');
425: }
1.74 www 426: if (filter != null) {
427: if (filter != '') {
428: url += 'filter='+filter+'&';
429: }
430: }
431: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 432: '&udomelement='+udom+
433: '&clicker='+clicker;
1.111 www 434: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 435: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 436: var title = 'Student_Browser';
1.74 www 437: var options = 'scrollbars=1,resizable=1,menubar=0';
438: options += ',width=700,height=600';
439: stdeditbrowser = open(url,title,options,'1');
440: stdeditbrowser.focus();
441: }
1.824 bisitz 442: // ]]>
1.74 www 443: </script>
444: ENDSTDBRW
445: }
1.42 matthew 446:
1.1003 www 447: sub resourcebrowser_javascript {
448: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 449: return (<<'ENDRESBRW');
1.1003 www 450: <script type="text/javascript" language="Javascript">
451: // <![CDATA[
452: var reseditbrowser;
1.1004 www 453: function openresbrowser(formname,reslink) {
1.1005 www 454: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 455: var title = 'Resource_Browser';
456: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 457: options += ',width=700,height=500';
1.1004 www 458: reseditbrowser = open(url,title,options,'1');
459: reseditbrowser.focus();
1.1003 www 460: }
461: // ]]>
462: </script>
1.1004 www 463: ENDRESBRW
1.1003 www 464: }
465:
1.74 www 466: sub selectstudent_link {
1.999 www 467: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
468: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
469: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
470: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 471: if ($env{'request.course.id'}) {
1.302 albertel 472: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
473: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
474: '/'.$env{'request.course.sec'})) {
1.111 www 475: return '';
476: }
1.999 www 477: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 478: if ($courseadvonly) {
479: $callargs .= ",'',1,1";
480: }
481: return '<span class="LC_nobreak">'.
482: '<a href="javascript:openstdbrowser('.$callargs.');">'.
483: &mt('Select User').'</a></span>';
1.74 www 484: }
1.258 albertel 485: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 486: $callargs .= ",'',1";
1.793 raeburn 487: return '<span class="LC_nobreak">'.
488: '<a href="javascript:openstdbrowser('.$callargs.');">'.
489: &mt('Select User').'</a></span>';
1.111 www 490: }
491: return '';
1.91 www 492: }
493:
1.1004 www 494: sub selectresource_link {
495: my ($form,$reslink,$arg)=@_;
496:
497: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
498: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
499: unless ($env{'request.course.id'}) { return $arg; }
500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openresbrowser('.$callargs.');">'.
502: $arg.'</a></span>';
503: }
504:
505:
506:
1.653 raeburn 507: sub authorbrowser_javascript {
508: return <<"ENDAUTHORBRW";
1.776 bisitz 509: <script type="text/javascript" language="JavaScript">
1.824 bisitz 510: // <![CDATA[
1.653 raeburn 511: var stdeditbrowser;
512:
513: function openauthorbrowser(formname,udom) {
514: var url = '/adm/pickauthor?';
515: url += 'form='+formname+'&roledom='+udom;
516: var title = 'Author_Browser';
517: var options = 'scrollbars=1,resizable=1,menubar=0';
518: options += ',width=700,height=600';
519: stdeditbrowser = open(url,title,options,'1');
520: stdeditbrowser.focus();
521: }
522:
1.824 bisitz 523: // ]]>
1.653 raeburn 524: </script>
525: ENDAUTHORBRW
526: }
527:
1.91 www 528: sub coursebrowser_javascript {
1.909 raeburn 529: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 530: my $wintitle = 'Course_Browser';
1.931 raeburn 531: if ($crstype eq 'Community') {
1.932 raeburn 532: $wintitle = 'Community_Browser';
1.909 raeburn 533: }
1.876 raeburn 534: my $id_functions = &javascript_index_functions();
535: my $output = '
1.776 bisitz 536: <script type="text/javascript" language="JavaScript">
1.824 bisitz 537: // <![CDATA[
1.468 raeburn 538: var stdeditbrowser;'."\n";
1.876 raeburn 539:
540: $output .= <<"ENDSTDBRW";
1.909 raeburn 541: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 542: var url = '/adm/pickcourse?';
1.895 raeburn 543: var formid = getFormIdByName(formname);
1.876 raeburn 544: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 545: if (domainfilter != null) {
546: if (domainfilter != '') {
547: url += 'domainfilter='+domainfilter+'&';
548: }
549: }
1.91 www 550: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 551: '&cdomelement='+udom+
552: '&cnameelement='+desc;
1.468 raeburn 553: if (extra_element !=null && extra_element != '') {
1.594 raeburn 554: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 555: url += '&roleelement='+extra_element;
556: if (domainfilter == null || domainfilter == '') {
557: url += '&domainfilter='+extra_element;
558: }
1.234 raeburn 559: }
1.468 raeburn 560: else {
561: if (formname == 'portform') {
562: url += '&setroles='+extra_element;
1.800 raeburn 563: } else {
564: if (formname == 'rules') {
565: url += '&fixeddom='+extra_element;
566: }
1.468 raeburn 567: }
568: }
1.230 raeburn 569: }
1.909 raeburn 570: if (type != null && type != '') {
571: url += '&type='+type;
572: }
573: if (type_elem != null && type_elem != '') {
574: url += '&typeelement='+type_elem;
575: }
1.872 raeburn 576: if (formname == 'ccrs') {
577: var ownername = document.forms[formid].ccuname.value;
578: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
579: url += '&cloner='+ownername+':'+ownerdom;
580: }
1.293 raeburn 581: if (multflag !=null && multflag != '') {
582: url += '&multiple='+multflag;
583: }
1.909 raeburn 584: var title = '$wintitle';
1.91 www 585: var options = 'scrollbars=1,resizable=1,menubar=0';
586: options += ',width=700,height=600';
587: stdeditbrowser = open(url,title,options,'1');
588: stdeditbrowser.focus();
589: }
1.876 raeburn 590: $id_functions
591: ENDSTDBRW
1.905 raeburn 592: if (($sec_element ne '') || ($role_element ne '')) {
593: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 594: }
595: $output .= '
596: // ]]>
597: </script>';
598: return $output;
599: }
600:
601: sub javascript_index_functions {
602: return <<"ENDJS";
603:
604: function getFormIdByName(formname) {
605: for (var i=0;i<document.forms.length;i++) {
606: if (document.forms[i].name == formname) {
607: return i;
608: }
609: }
610: return -1;
611: }
612:
613: function getIndexByName(formid,item) {
614: for (var i=0;i<document.forms[formid].elements.length;i++) {
615: if (document.forms[formid].elements[i].name == item) {
616: return i;
617: }
618: }
619: return -1;
620: }
1.468 raeburn 621:
1.876 raeburn 622: function getDomainFromSelectbox(formname,udom) {
623: var userdom;
624: var formid = getFormIdByName(formname);
625: if (formid > -1) {
626: var domid = getIndexByName(formid,udom);
627: if (domid > -1) {
628: if (document.forms[formid].elements[domid].type == 'select-one') {
629: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
630: }
631: if (document.forms[formid].elements[domid].type == 'hidden') {
632: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 633: }
634: }
635: }
1.876 raeburn 636: return userdom;
637: }
638:
639: ENDJS
1.468 raeburn 640:
1.876 raeburn 641: }
642:
1.1017 raeburn 643: sub javascript_array_indexof {
1.1018 raeburn 644: return <<ENDJS;
1.1017 raeburn 645: <script type="text/javascript" language="JavaScript">
646: // <![CDATA[
647:
648: if (!Array.prototype.indexOf) {
649: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
650: "use strict";
651: if (this === void 0 || this === null) {
652: throw new TypeError();
653: }
654: var t = Object(this);
655: var len = t.length >>> 0;
656: if (len === 0) {
657: return -1;
658: }
659: var n = 0;
660: if (arguments.length > 0) {
661: n = Number(arguments[1]);
1.1088 ! foxr 662: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 663: n = 0;
664: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
665: n = (n > 0 || -1) * Math.floor(Math.abs(n));
666: }
667: }
668: if (n >= len) {
669: return -1;
670: }
671: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
672: for (; k < len; k++) {
673: if (k in t && t[k] === searchElement) {
674: return k;
675: }
676: }
677: return -1;
678: }
679: }
680:
681: // ]]>
682: </script>
683:
684: ENDJS
685:
686: }
687:
1.876 raeburn 688: sub userbrowser_javascript {
689: my $id_functions = &javascript_index_functions();
690: return <<"ENDUSERBRW";
691:
1.888 raeburn 692: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 693: var url = '/adm/pickuser?';
694: var userdom = getDomainFromSelectbox(formname,udom);
695: if (userdom != null) {
696: if (userdom != '') {
697: url += 'srchdom='+userdom+'&';
698: }
699: }
700: url += 'form=' + formname + '&unameelement='+uname+
701: '&udomelement='+udom+
702: '&ulastelement='+ulast+
703: '&ufirstelement='+ufirst+
704: '&uemailelement='+uemail+
1.881 raeburn 705: '&hideudomelement='+hideudom+
706: '&coursedom='+crsdom;
1.888 raeburn 707: if ((caller != null) && (caller != undefined)) {
708: url += '&caller='+caller;
709: }
1.876 raeburn 710: var title = 'User_Browser';
711: var options = 'scrollbars=1,resizable=1,menubar=0';
712: options += ',width=700,height=600';
713: var stdeditbrowser = open(url,title,options,'1');
714: stdeditbrowser.focus();
715: }
716:
1.888 raeburn 717: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 718: var formid = getFormIdByName(formname);
719: if (formid > -1) {
1.888 raeburn 720: var unameid = getIndexByName(formid,uname);
1.876 raeburn 721: var domid = getIndexByName(formid,udom);
722: var hidedomid = getIndexByName(formid,origdom);
723: if (hidedomid > -1) {
724: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 725: var unameval = document.forms[formid].elements[unameid].value;
726: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
727: if (domid > -1) {
728: var slct = document.forms[formid].elements[domid];
729: if (slct.type == 'select-one') {
730: var i;
731: for (i=0;i<slct.length;i++) {
732: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
733: }
734: }
735: if (slct.type == 'hidden') {
736: slct.value = fixeddom;
1.876 raeburn 737: }
738: }
1.468 raeburn 739: }
740: }
741: }
1.876 raeburn 742: return;
743: }
744:
745: $id_functions
746: ENDUSERBRW
1.468 raeburn 747: }
748:
749: sub setsec_javascript {
1.905 raeburn 750: my ($sec_element,$formname,$role_element) = @_;
751: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
752: $communityrolestr);
753: if ($role_element ne '') {
754: my @allroles = ('st','ta','ep','in','ad');
755: foreach my $crstype ('Course','Community') {
756: if ($crstype eq 'Community') {
757: foreach my $role (@allroles) {
758: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
759: }
760: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
761: } else {
762: foreach my $role (@allroles) {
763: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
764: }
765: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
766: }
767: }
768: $rolestr = '"'.join('","',@allroles).'"';
769: $courserolestr = '"'.join('","',@courserolenames).'"';
770: $communityrolestr = '"'.join('","',@communityrolenames).'"';
771: }
1.468 raeburn 772: my $setsections = qq|
773: function setSect(sectionlist) {
1.629 raeburn 774: var sectionsArray = new Array();
775: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
776: sectionsArray = sectionlist.split(",");
777: }
1.468 raeburn 778: var numSections = sectionsArray.length;
779: document.$formname.$sec_element.length = 0;
780: if (numSections == 0) {
781: document.$formname.$sec_element.multiple=false;
782: document.$formname.$sec_element.size=1;
783: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
784: } else {
785: if (numSections == 1) {
786: document.$formname.$sec_element.multiple=false;
787: document.$formname.$sec_element.size=1;
788: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
789: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
790: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
791: } else {
792: for (var i=0; i<numSections; i++) {
793: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
794: }
795: document.$formname.$sec_element.multiple=true
796: if (numSections < 3) {
797: document.$formname.$sec_element.size=numSections;
798: } else {
799: document.$formname.$sec_element.size=3;
800: }
801: document.$formname.$sec_element.options[0].selected = false
802: }
803: }
1.91 www 804: }
1.905 raeburn 805:
806: function setRole(crstype) {
1.468 raeburn 807: |;
1.905 raeburn 808: if ($role_element eq '') {
809: $setsections .= ' return;
810: }
811: ';
812: } else {
813: $setsections .= qq|
814: var elementLength = document.$formname.$role_element.length;
815: var allroles = Array($rolestr);
816: var courserolenames = Array($courserolestr);
817: var communityrolenames = Array($communityrolestr);
818: if (elementLength != undefined) {
819: if (document.$formname.$role_element.options[5].value == 'cc') {
820: if (crstype == 'Course') {
821: return;
822: } else {
823: allroles[5] = 'co';
824: for (var i=0; i<6; i++) {
825: document.$formname.$role_element.options[i].value = allroles[i];
826: document.$formname.$role_element.options[i].text = communityrolenames[i];
827: }
828: }
829: } else {
830: if (crstype == 'Community') {
831: return;
832: } else {
833: allroles[5] = 'cc';
834: for (var i=0; i<6; i++) {
835: document.$formname.$role_element.options[i].value = allroles[i];
836: document.$formname.$role_element.options[i].text = courserolenames[i];
837: }
838: }
839: }
840: }
841: return;
842: }
843: |;
844: }
1.468 raeburn 845: return $setsections;
846: }
847:
1.91 www 848: sub selectcourse_link {
1.909 raeburn 849: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
850: $typeelement) = @_;
851: my $type = $selecttype;
1.871 raeburn 852: my $linktext = &mt('Select Course');
853: if ($selecttype eq 'Community') {
1.909 raeburn 854: $linktext = &mt('Select Community');
1.906 raeburn 855: } elsif ($selecttype eq 'Course/Community') {
856: $linktext = &mt('Select Course/Community');
1.909 raeburn 857: $type = '';
1.1019 raeburn 858: } elsif ($selecttype eq 'Select') {
859: $linktext = &mt('Select');
860: $type = '';
1.871 raeburn 861: }
1.787 bisitz 862: return '<span class="LC_nobreak">'
863: ."<a href='"
864: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
865: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 866: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 867: ."'>".$linktext.'</a>'
1.787 bisitz 868: .'</span>';
1.74 www 869: }
1.42 matthew 870:
1.653 raeburn 871: sub selectauthor_link {
872: my ($form,$udom)=@_;
873: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
874: &mt('Select Author').'</a>';
875: }
876:
1.876 raeburn 877: sub selectuser_link {
1.881 raeburn 878: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 879: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 880: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 881: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 882: ');">'.$linktext.'</a>';
1.876 raeburn 883: }
884:
1.273 raeburn 885: sub check_uncheck_jscript {
886: my $jscript = <<"ENDSCRT";
887: function checkAll(field) {
888: if (field.length > 0) {
889: for (i = 0; i < field.length; i++) {
890: field[i].checked = true ;
891: }
892: } else {
893: field.checked = true
894: }
895: }
896:
897: function uncheckAll(field) {
898: if (field.length > 0) {
899: for (i = 0; i < field.length; i++) {
900: field[i].checked = false ;
1.543 albertel 901: }
902: } else {
1.273 raeburn 903: field.checked = false ;
904: }
905: }
906: ENDSCRT
907: return $jscript;
908: }
909:
1.656 www 910: sub select_timezone {
1.659 raeburn 911: my ($name,$selected,$onchange,$includeempty)=@_;
912: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
913: if ($includeempty) {
914: $output .= '<option value=""';
915: if (($selected eq '') || ($selected eq 'local')) {
916: $output .= ' selected="selected" ';
917: }
918: $output .= '> </option>';
919: }
1.657 raeburn 920: my @timezones = DateTime::TimeZone->all_names;
921: foreach my $tzone (@timezones) {
922: $output.= '<option value="'.$tzone.'"';
923: if ($tzone eq $selected) {
924: $output.=' selected="selected"';
925: }
926: $output.=">$tzone</option>\n";
1.656 www 927: }
928: $output.="</select>";
929: return $output;
930: }
1.273 raeburn 931:
1.687 raeburn 932: sub select_datelocale {
933: my ($name,$selected,$onchange,$includeempty)=@_;
934: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
935: if ($includeempty) {
936: $output .= '<option value=""';
937: if ($selected eq '') {
938: $output .= ' selected="selected" ';
939: }
940: $output .= '> </option>';
941: }
942: my (@possibles,%locale_names);
943: my @locales = DateTime::Locale::Catalog::Locales;
944: foreach my $locale (@locales) {
945: if (ref($locale) eq 'HASH') {
946: my $id = $locale->{'id'};
947: if ($id ne '') {
948: my $en_terr = $locale->{'en_territory'};
949: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 950: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 951: if (grep(/^en$/,@languages) || !@languages) {
952: if ($en_terr ne '') {
953: $locale_names{$id} = '('.$en_terr.')';
954: } elsif ($native_terr ne '') {
955: $locale_names{$id} = $native_terr;
956: }
957: } else {
958: if ($native_terr ne '') {
959: $locale_names{$id} = $native_terr.' ';
960: } elsif ($en_terr ne '') {
961: $locale_names{$id} = '('.$en_terr.')';
962: }
963: }
964: push (@possibles,$id);
965: }
966: }
967: }
968: foreach my $item (sort(@possibles)) {
969: $output.= '<option value="'.$item.'"';
970: if ($item eq $selected) {
971: $output.=' selected="selected"';
972: }
973: $output.=">$item";
974: if ($locale_names{$item} ne '') {
975: $output.=" $locale_names{$item}</option>\n";
976: }
977: $output.="</option>\n";
978: }
979: $output.="</select>";
980: return $output;
981: }
982:
1.792 raeburn 983: sub select_language {
984: my ($name,$selected,$includeempty) = @_;
985: my %langchoices;
986: if ($includeempty) {
987: %langchoices = ('' => 'No language preference');
988: }
989: foreach my $id (&languageids()) {
990: my $code = &supportedlanguagecode($id);
991: if ($code) {
992: $langchoices{$code} = &plainlanguagedescription($id);
993: }
994: }
1.970 raeburn 995: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 996: }
997:
1.42 matthew 998: =pod
1.36 matthew 999:
1.1088 ! foxr 1000:
! 1001: =item * &list_languages()
! 1002:
! 1003: Returns an array reference that is suitable for use in language prompters.
! 1004: Each array element is itself a two element array. The first element
! 1005: is the language code. The second element a descsriptiuon of the
! 1006: language itself. This is suitable for use in e.g.
! 1007: &Apache::edit::select_arg (once dereferenced that is).
! 1008:
! 1009: =cut
! 1010:
! 1011: sub list_languages {
! 1012: my @lang_choices;
! 1013:
! 1014: foreach my $id (&languageids()) {
! 1015: my $code = &supportedlanguagecode($id);
! 1016: if ($code) {
! 1017: my $selector = $supported_codes{$id};
! 1018: my $description = &plainlanguagedescription($id);
! 1019: &Apache::lonnet::logthis("pushing $selector : $description");
! 1020: push (@lang_choices, [$selector, $description]);
! 1021: }
! 1022: }
! 1023: return \@lang_choices;
! 1024: }
! 1025:
! 1026: =pod
! 1027:
1.648 raeburn 1028: =item * &linked_select_forms(...)
1.36 matthew 1029:
1030: linked_select_forms returns a string containing a <script></script> block
1031: and html for two <select> menus. The select menus will be linked in that
1032: changing the value of the first menu will result in new values being placed
1033: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1034: order unless a defined order is provided.
1.36 matthew 1035:
1036: linked_select_forms takes the following ordered inputs:
1037:
1038: =over 4
1039:
1.112 bowersj2 1040: =item * $formname, the name of the <form> tag
1.36 matthew 1041:
1.112 bowersj2 1042: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1043:
1.112 bowersj2 1044: =item * $firstdefault, the default value for the first menu
1.36 matthew 1045:
1.112 bowersj2 1046: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1047:
1.112 bowersj2 1048: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1049:
1.112 bowersj2 1050: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1051:
1.609 raeburn 1052: =item * $menuorder, the order of values in the first menu
1053:
1.41 ng 1054: =back
1055:
1.36 matthew 1056: Below is an example of such a hash. Only the 'text', 'default', and
1057: 'select2' keys must appear as stated. keys(%menu) are the possible
1058: values for the first select menu. The text that coincides with the
1.41 ng 1059: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1060: and text for the second menu are given in the hash pointed to by
1061: $menu{$choice1}->{'select2'}.
1062:
1.112 bowersj2 1063: my %menu = ( A1 => { text =>"Choice A1" ,
1064: default => "B3",
1065: select2 => {
1066: B1 => "Choice B1",
1067: B2 => "Choice B2",
1068: B3 => "Choice B3",
1069: B4 => "Choice B4"
1.609 raeburn 1070: },
1071: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1072: },
1073: A2 => { text =>"Choice A2" ,
1074: default => "C2",
1075: select2 => {
1076: C1 => "Choice C1",
1077: C2 => "Choice C2",
1078: C3 => "Choice C3"
1.609 raeburn 1079: },
1080: order => ['C2','C1','C3'],
1.112 bowersj2 1081: },
1082: A3 => { text =>"Choice A3" ,
1083: default => "D6",
1084: select2 => {
1085: D1 => "Choice D1",
1086: D2 => "Choice D2",
1087: D3 => "Choice D3",
1088: D4 => "Choice D4",
1089: D5 => "Choice D5",
1090: D6 => "Choice D6",
1091: D7 => "Choice D7"
1.609 raeburn 1092: },
1093: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1094: }
1095: );
1.36 matthew 1096:
1097: =cut
1098:
1099: sub linked_select_forms {
1100: my ($formname,
1101: $middletext,
1102: $firstdefault,
1103: $firstselectname,
1104: $secondselectname,
1.609 raeburn 1105: $hashref,
1106: $menuorder,
1.36 matthew 1107: ) = @_;
1108: my $second = "document.$formname.$secondselectname";
1109: my $first = "document.$formname.$firstselectname";
1110: # output the javascript to do the changing
1111: my $result = '';
1.776 bisitz 1112: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1113: $result.="// <![CDATA[\n";
1.36 matthew 1114: $result.="var select2data = new Object();\n";
1115: $" = '","';
1116: my $debug = '';
1117: foreach my $s1 (sort(keys(%$hashref))) {
1118: $result.="select2data.d_$s1 = new Object();\n";
1119: $result.="select2data.d_$s1.def = new String('".
1120: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1121: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1122: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1123: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1124: @s2values = @{$hashref->{$s1}->{'order'}};
1125: }
1.36 matthew 1126: $result.="\"@s2values\");\n";
1127: $result.="select2data.d_$s1.texts = new Array(";
1128: my @s2texts;
1129: foreach my $value (@s2values) {
1130: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1131: }
1132: $result.="\"@s2texts\");\n";
1133: }
1134: $"=' ';
1135: $result.= <<"END";
1136:
1137: function select1_changed() {
1138: // Determine new choice
1139: var newvalue = "d_" + $first.value;
1140: // update select2
1141: var values = select2data[newvalue].values;
1142: var texts = select2data[newvalue].texts;
1143: var select2def = select2data[newvalue].def;
1144: var i;
1145: // out with the old
1146: for (i = 0; i < $second.options.length; i++) {
1147: $second.options[i] = null;
1148: }
1149: // in with the nuclear
1150: for (i=0;i<values.length; i++) {
1151: $second.options[i] = new Option(values[i]);
1.143 matthew 1152: $second.options[i].value = values[i];
1.36 matthew 1153: $second.options[i].text = texts[i];
1154: if (values[i] == select2def) {
1155: $second.options[i].selected = true;
1156: }
1157: }
1158: }
1.824 bisitz 1159: // ]]>
1.36 matthew 1160: </script>
1161: END
1162: # output the initial values for the selection lists
1163: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1164: my @order = sort(keys(%{$hashref}));
1165: if (ref($menuorder) eq 'ARRAY') {
1166: @order = @{$menuorder};
1167: }
1168: foreach my $value (@order) {
1.36 matthew 1169: $result.=" <option value=\"$value\" ";
1.253 albertel 1170: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1171: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1172: }
1173: $result .= "</select>\n";
1174: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1175: $result .= $middletext;
1176: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1177: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1178:
1179: my @secondorder = sort(keys(%select2));
1180: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1181: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1182: }
1183: foreach my $value (@secondorder) {
1.36 matthew 1184: $result.=" <option value=\"$value\" ";
1.253 albertel 1185: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1186: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1187: }
1188: $result .= "</select>\n";
1189: # return $debug;
1190: return $result;
1191: } # end of sub linked_select_forms {
1192:
1.45 matthew 1193: =pod
1.44 bowersj2 1194:
1.973 raeburn 1195: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1196:
1.112 bowersj2 1197: Returns a string corresponding to an HTML link to the given help
1198: $topic, where $topic corresponds to the name of a .tex file in
1199: /home/httpd/html/adm/help/tex, with underscores replaced by
1200: spaces.
1201:
1202: $text will optionally be linked to the same topic, allowing you to
1203: link text in addition to the graphic. If you do not want to link
1204: text, but wish to specify one of the later parameters, pass an
1205: empty string.
1206:
1207: $stayOnPage is a value that will be interpreted as a boolean. If true,
1208: the link will not open a new window. If false, the link will open
1209: a new window using Javascript. (Default is false.)
1210:
1211: $width and $height are optional numerical parameters that will
1212: override the width and height of the popped up window, which may
1.973 raeburn 1213: be useful for certain help topics with big pictures included.
1214:
1215: $imgid is the id of the img tag used for the help icon. This may be
1216: used in a javascript call to switch the image src. See
1217: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1218:
1219: =cut
1220:
1221: sub help_open_topic {
1.973 raeburn 1222: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1223: $text = "" if (not defined $text);
1.44 bowersj2 1224: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1225: $width = 500 if (not defined $width);
1.44 bowersj2 1226: $height = 400 if (not defined $height);
1227: my $filename = $topic;
1228: $filename =~ s/ /_/g;
1229:
1.48 bowersj2 1230: my $template = "";
1231: my $link;
1.572 banghart 1232:
1.159 www 1233: $topic=~s/\W/\_/g;
1.44 bowersj2 1234:
1.572 banghart 1235: if (!$stayOnPage) {
1.1033 www 1236: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1237: } elsif ($stayOnPage eq 'popup') {
1238: $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 1239: } else {
1.48 bowersj2 1240: $link = "/adm/help/${filename}.hlp";
1241: }
1242:
1243: # Add the text
1.755 neumanie 1244: if ($text ne "") {
1.763 bisitz 1245: $template.='<span class="LC_help_open_topic">'
1246: .'<a target="_top" href="'.$link.'">'
1247: .$text.'</a>';
1.48 bowersj2 1248: }
1249:
1.763 bisitz 1250: # (Always) Add the graphic
1.179 matthew 1251: my $title = &mt('Online Help');
1.667 raeburn 1252: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1253: if ($imgid ne '') {
1254: $imgid = ' id="'.$imgid.'"';
1255: }
1.763 bisitz 1256: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1257: .'<img src="'.$helpicon.'" border="0"'
1258: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1259: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1260: .' /></a>';
1261: if ($text ne "") {
1262: $template.='</span>';
1263: }
1.44 bowersj2 1264: return $template;
1265:
1.106 bowersj2 1266: }
1267:
1268: # This is a quicky function for Latex cheatsheet editing, since it
1269: # appears in at least four places
1270: sub helpLatexCheatsheet {
1.1037 www 1271: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1272: my $out;
1.106 bowersj2 1273: my $addOther = '';
1.732 raeburn 1274: if ($topic) {
1.1037 www 1275: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1276: }
1277: $out = '<span>' # Start cheatsheet
1278: .$addOther
1279: .'<span>'
1.1037 www 1280: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1281: .'</span> <span>'
1.1037 www 1282: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1283: .'</span>';
1.732 raeburn 1284: unless ($not_author) {
1.763 bisitz 1285: $out .= ' <span>'
1.1037 www 1286: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1287: .'</span>';
1.732 raeburn 1288: }
1.763 bisitz 1289: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1290: return $out;
1.172 www 1291: }
1292:
1.430 albertel 1293: sub general_help {
1294: my $helptopic='Student_Intro';
1295: if ($env{'request.role'}=~/^(ca|au)/) {
1296: $helptopic='Authoring_Intro';
1.907 raeburn 1297: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1298: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1299: } elsif ($env{'request.role'}=~/^dc/) {
1300: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1301: }
1302: return $helptopic;
1303: }
1304:
1305: sub update_help_link {
1306: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1307: my $origurl = $ENV{'REQUEST_URI'};
1308: $origurl=~s|^/~|/priv/|;
1309: my $timestamp = time;
1310: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1311: $$datum = &escape($$datum);
1312: }
1313:
1314: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1315: my $output .= <<"ENDOUTPUT";
1316: <script type="text/javascript">
1.824 bisitz 1317: // <![CDATA[
1.430 albertel 1318: banner_link = '$banner_link';
1.824 bisitz 1319: // ]]>
1.430 albertel 1320: </script>
1321: ENDOUTPUT
1322: return $output;
1323: }
1324:
1325: # now just updates the help link and generates a blue icon
1.193 raeburn 1326: sub help_open_menu {
1.430 albertel 1327: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1328: = @_;
1.949 droeschl 1329: $stayOnPage = 1;
1.430 albertel 1330: my $output;
1331: if ($component_help) {
1332: if (!$text) {
1333: $output=&help_open_topic($component_help,undef,$stayOnPage,
1334: $width,$height);
1335: } else {
1336: my $help_text;
1337: $help_text=&unescape($topic);
1338: $output='<table><tr><td>'.
1339: &help_open_topic($component_help,$help_text,$stayOnPage,
1340: $width,$height).'</td></tr></table>';
1341: }
1342: }
1343: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1344: return $output.$banner_link;
1345: }
1346:
1347: sub top_nav_help {
1348: my ($text) = @_;
1.436 albertel 1349: $text = &mt($text);
1.949 droeschl 1350: my $stay_on_page = 1;
1351:
1.572 banghart 1352: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1353: : "javascript:helpMenu('open')";
1.572 banghart 1354: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1355:
1.201 raeburn 1356: my $title = &mt('Get help');
1.436 albertel 1357:
1358: return <<"END";
1359: $banner_link
1360: <a href="$link" title="$title">$text</a>
1361: END
1362: }
1363:
1364: sub help_menu_js {
1365: my ($text) = @_;
1.949 droeschl 1366: my $stayOnPage = 1;
1.436 albertel 1367: my $width = 620;
1368: my $height = 600;
1.430 albertel 1369: my $helptopic=&general_help();
1370: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1371: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1372: my $start_page =
1373: &Apache::loncommon::start_page('Help Menu', undef,
1374: {'frameset' => 1,
1375: 'js_ready' => 1,
1376: 'add_entries' => {
1377: 'border' => '0',
1.579 raeburn 1378: 'rows' => "110,*",},});
1.331 albertel 1379: my $end_page =
1380: &Apache::loncommon::end_page({'frameset' => 1,
1381: 'js_ready' => 1,});
1382:
1.436 albertel 1383: my $template .= <<"ENDTEMPLATE";
1384: <script type="text/javascript">
1.877 bisitz 1385: // <![CDATA[
1.253 albertel 1386: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1387: var banner_link = '';
1.243 raeburn 1388: function helpMenu(target) {
1389: var caller = this;
1390: if (target == 'open') {
1391: var newWindow = null;
1392: try {
1.262 albertel 1393: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1394: }
1395: catch(error) {
1396: writeHelp(caller);
1397: return;
1398: }
1399: if (newWindow) {
1400: caller = newWindow;
1401: }
1.193 raeburn 1402: }
1.243 raeburn 1403: writeHelp(caller);
1404: return;
1405: }
1406: function writeHelp(caller) {
1.1072 raeburn 1407: 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 1408: caller.document.close()
1409: caller.focus()
1.193 raeburn 1410: }
1.877 bisitz 1411: // END LON-CAPA Internal -->
1.253 albertel 1412: // ]]>
1.436 albertel 1413: </script>
1.193 raeburn 1414: ENDTEMPLATE
1415: return $template;
1416: }
1417:
1.172 www 1418: sub help_open_bug {
1419: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1420: unless ($env{'user.adv'}) { return ''; }
1.172 www 1421: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1422: $text = "" if (not defined $text);
1423: $stayOnPage=1;
1.184 albertel 1424: $width = 600 if (not defined $width);
1425: $height = 600 if (not defined $height);
1.172 www 1426:
1427: $topic=~s/\W+/\+/g;
1428: my $link='';
1429: my $template='';
1.379 albertel 1430: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1431: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1432: if (!$stayOnPage)
1433: {
1434: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1435: }
1436: else
1437: {
1438: $link = $url;
1439: }
1440: # Add the text
1441: if ($text ne "")
1442: {
1443: $template .=
1444: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1445: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1446: }
1447:
1448: # Add the graphic
1.179 matthew 1449: my $title = &mt('Report a Bug');
1.215 albertel 1450: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1451: $template .= <<"ENDTEMPLATE";
1.436 albertel 1452: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1453: ENDTEMPLATE
1454: if ($text ne '') { $template.='</td></tr></table>' };
1455: return $template;
1456:
1457: }
1458:
1459: sub help_open_faq {
1460: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1461: unless ($env{'user.adv'}) { return ''; }
1.172 www 1462: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1463: $text = "" if (not defined $text);
1464: $stayOnPage=1;
1465: $width = 350 if (not defined $width);
1466: $height = 400 if (not defined $height);
1467:
1468: $topic=~s/\W+/\+/g;
1469: my $link='';
1470: my $template='';
1471: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1472: if (!$stayOnPage)
1473: {
1474: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1475: }
1476: else
1477: {
1478: $link = $url;
1479: }
1480:
1481: # Add the text
1482: if ($text ne "")
1483: {
1484: $template .=
1.173 www 1485: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1486: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1487: }
1488:
1489: # Add the graphic
1.179 matthew 1490: my $title = &mt('View the FAQ');
1.215 albertel 1491: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1492: $template .= <<"ENDTEMPLATE";
1.436 albertel 1493: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1494: ENDTEMPLATE
1495: if ($text ne '') { $template.='</td></tr></table>' };
1496: return $template;
1497:
1.44 bowersj2 1498: }
1.37 matthew 1499:
1.180 matthew 1500: ###############################################################
1501: ###############################################################
1502:
1.45 matthew 1503: =pod
1504:
1.648 raeburn 1505: =item * &change_content_javascript():
1.256 matthew 1506:
1507: This and the next function allow you to create small sections of an
1508: otherwise static HTML page that you can update on the fly with
1509: Javascript, even in Netscape 4.
1510:
1511: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1512: must be written to the HTML page once. It will prove the Javascript
1513: function "change(name, content)". Calling the change function with the
1514: name of the section
1515: you want to update, matching the name passed to C<changable_area>, and
1516: the new content you want to put in there, will put the content into
1517: that area.
1518:
1519: B<Note>: Netscape 4 only reserves enough space for the changable area
1520: to contain room for the original contents. You need to "make space"
1521: for whatever changes you wish to make, and be B<sure> to check your
1522: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1523: it's adequate for updating a one-line status display, but little more.
1524: This script will set the space to 100% width, so you only need to
1525: worry about height in Netscape 4.
1526:
1527: Modern browsers are much less limiting, and if you can commit to the
1528: user not using Netscape 4, this feature may be used freely with
1529: pretty much any HTML.
1530:
1531: =cut
1532:
1533: sub change_content_javascript {
1534: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1535: if ($env{'browser.type'} eq 'netscape' &&
1536: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1537: return (<<NETSCAPE4);
1538: function change(name, content) {
1539: doc = document.layers[name+"___escape"].layers[0].document;
1540: doc.open();
1541: doc.write(content);
1542: doc.close();
1543: }
1544: NETSCAPE4
1545: } else {
1546: # Otherwise, we need to use semi-standards-compliant code
1547: # (technically, "innerHTML" isn't standard but the equivalent
1548: # is really scary, and every useful browser supports it
1549: return (<<DOMBASED);
1550: function change(name, content) {
1551: element = document.getElementById(name);
1552: element.innerHTML = content;
1553: }
1554: DOMBASED
1555: }
1556: }
1557:
1558: =pod
1559:
1.648 raeburn 1560: =item * &changable_area($name,$origContent):
1.256 matthew 1561:
1562: This provides a "changable area" that can be modified on the fly via
1563: the Javascript code provided in C<change_content_javascript>. $name is
1564: the name you will use to reference the area later; do not repeat the
1565: same name on a given HTML page more then once. $origContent is what
1566: the area will originally contain, which can be left blank.
1567:
1568: =cut
1569:
1570: sub changable_area {
1571: my ($name, $origContent) = @_;
1572:
1.258 albertel 1573: if ($env{'browser.type'} eq 'netscape' &&
1574: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1575: # If this is netscape 4, we need to use the Layer tag
1576: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1577: } else {
1578: return "<span id='$name'>$origContent</span>";
1579: }
1580: }
1581:
1582: =pod
1583:
1.648 raeburn 1584: =item * &viewport_geometry_js
1.590 raeburn 1585:
1586: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1587:
1588: =cut
1589:
1590:
1591: sub viewport_geometry_js {
1592: return <<"GEOMETRY";
1593: var Geometry = {};
1594: function init_geometry() {
1595: if (Geometry.init) { return };
1596: Geometry.init=1;
1597: if (window.innerHeight) {
1598: Geometry.getViewportHeight = function() { return window.innerHeight; };
1599: Geometry.getViewportWidth = function() { return window.innerWidth; };
1600: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1601: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1602: }
1603: else if (document.documentElement && document.documentElement.clientHeight) {
1604: Geometry.getViewportHeight =
1605: function() { return document.documentElement.clientHeight; };
1606: Geometry.getViewportWidth =
1607: function() { return document.documentElement.clientWidth; };
1608:
1609: Geometry.getHorizontalScroll =
1610: function() { return document.documentElement.scrollLeft; };
1611: Geometry.getVerticalScroll =
1612: function() { return document.documentElement.scrollTop; };
1613: }
1614: else if (document.body.clientHeight) {
1615: Geometry.getViewportHeight =
1616: function() { return document.body.clientHeight; };
1617: Geometry.getViewportWidth =
1618: function() { return document.body.clientWidth; };
1619: Geometry.getHorizontalScroll =
1620: function() { return document.body.scrollLeft; };
1621: Geometry.getVerticalScroll =
1622: function() { return document.body.scrollTop; };
1623: }
1624: }
1625:
1626: GEOMETRY
1627: }
1628:
1629: =pod
1630:
1.648 raeburn 1631: =item * &viewport_size_js()
1.590 raeburn 1632:
1633: 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.
1634:
1635: =cut
1636:
1637: sub viewport_size_js {
1638: my $geometry = &viewport_geometry_js();
1639: return <<"DIMS";
1640:
1641: $geometry
1642:
1643: function getViewportDims(width,height) {
1644: init_geometry();
1645: width.value = Geometry.getViewportWidth();
1646: height.value = Geometry.getViewportHeight();
1647: return;
1648: }
1649:
1650: DIMS
1651: }
1652:
1653: =pod
1654:
1.648 raeburn 1655: =item * &resize_textarea_js()
1.565 albertel 1656:
1657: emits the needed javascript to resize a textarea to be as big as possible
1658:
1659: creates a function resize_textrea that takes two IDs first should be
1660: the id of the element to resize, second should be the id of a div that
1661: surrounds everything that comes after the textarea, this routine needs
1662: to be attached to the <body> for the onload and onresize events.
1663:
1.648 raeburn 1664: =back
1.565 albertel 1665:
1666: =cut
1667:
1668: sub resize_textarea_js {
1.590 raeburn 1669: my $geometry = &viewport_geometry_js();
1.565 albertel 1670: return <<"RESIZE";
1671: <script type="text/javascript">
1.824 bisitz 1672: // <![CDATA[
1.590 raeburn 1673: $geometry
1.565 albertel 1674:
1.588 albertel 1675: function getX(element) {
1676: var x = 0;
1677: while (element) {
1678: x += element.offsetLeft;
1679: element = element.offsetParent;
1680: }
1681: return x;
1682: }
1683: function getY(element) {
1684: var y = 0;
1685: while (element) {
1686: y += element.offsetTop;
1687: element = element.offsetParent;
1688: }
1689: return y;
1690: }
1691:
1692:
1.565 albertel 1693: function resize_textarea(textarea_id,bottom_id) {
1694: init_geometry();
1695: var textarea = document.getElementById(textarea_id);
1696: //alert(textarea);
1697:
1.588 albertel 1698: var textarea_top = getY(textarea);
1.565 albertel 1699: var textarea_height = textarea.offsetHeight;
1700: var bottom = document.getElementById(bottom_id);
1.588 albertel 1701: var bottom_top = getY(bottom);
1.565 albertel 1702: var bottom_height = bottom.offsetHeight;
1703: var window_height = Geometry.getViewportHeight();
1.588 albertel 1704: var fudge = 23;
1.565 albertel 1705: var new_height = window_height-fudge-textarea_top-bottom_height;
1706: if (new_height < 300) {
1707: new_height = 300;
1708: }
1709: textarea.style.height=new_height+'px';
1710: }
1.824 bisitz 1711: // ]]>
1.565 albertel 1712: </script>
1713: RESIZE
1714:
1715: }
1716:
1717: =pod
1718:
1.256 matthew 1719: =head1 Excel and CSV file utility routines
1720:
1721: =over 4
1722:
1723: =cut
1724:
1725: ###############################################################
1726: ###############################################################
1727:
1728: =pod
1729:
1.648 raeburn 1730: =item * &csv_translate($text)
1.37 matthew 1731:
1.185 www 1732: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1733: format.
1734:
1735: =cut
1736:
1.180 matthew 1737: ###############################################################
1738: ###############################################################
1.37 matthew 1739: sub csv_translate {
1740: my $text = shift;
1741: $text =~ s/\"/\"\"/g;
1.209 albertel 1742: $text =~ s/\n/ /g;
1.37 matthew 1743: return $text;
1744: }
1.180 matthew 1745:
1746: ###############################################################
1747: ###############################################################
1748:
1749: =pod
1750:
1.648 raeburn 1751: =item * &define_excel_formats()
1.180 matthew 1752:
1753: Define some commonly used Excel cell formats.
1754:
1755: Currently supported formats:
1756:
1757: =over 4
1758:
1759: =item header
1760:
1761: =item bold
1762:
1763: =item h1
1764:
1765: =item h2
1766:
1767: =item h3
1768:
1.256 matthew 1769: =item h4
1770:
1771: =item i
1772:
1.180 matthew 1773: =item date
1774:
1775: =back
1776:
1777: Inputs: $workbook
1778:
1779: Returns: $format, a hash reference.
1780:
1.1057 foxr 1781:
1.180 matthew 1782: =cut
1783:
1784: ###############################################################
1785: ###############################################################
1786: sub define_excel_formats {
1787: my ($workbook) = @_;
1788: my $format;
1789: $format->{'header'} = $workbook->add_format(bold => 1,
1790: bottom => 1,
1791: align => 'center');
1792: $format->{'bold'} = $workbook->add_format(bold=>1);
1793: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1794: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1795: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1796: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1797: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1798: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1799: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1800: return $format;
1801: }
1802:
1803: ###############################################################
1804: ###############################################################
1.113 bowersj2 1805:
1806: =pod
1807:
1.648 raeburn 1808: =item * &create_workbook()
1.255 matthew 1809:
1810: Create an Excel worksheet. If it fails, output message on the
1811: request object and return undefs.
1812:
1813: Inputs: Apache request object
1814:
1815: Returns (undef) on failure,
1816: Excel worksheet object, scalar with filename, and formats
1817: from &Apache::loncommon::define_excel_formats on success
1818:
1819: =cut
1820:
1821: ###############################################################
1822: ###############################################################
1823: sub create_workbook {
1824: my ($r) = @_;
1825: #
1826: # Create the excel spreadsheet
1827: my $filename = '/prtspool/'.
1.258 albertel 1828: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1829: time.'_'.rand(1000000000).'.xls';
1830: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1831: if (! defined($workbook)) {
1832: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1833: $r->print(
1834: '<p class="LC_error">'
1835: .&mt('Problems occurred in creating the new Excel file.')
1836: .' '.&mt('This error has been logged.')
1837: .' '.&mt('Please alert your LON-CAPA administrator.')
1838: .'</p>'
1839: );
1.255 matthew 1840: return (undef);
1841: }
1842: #
1.1014 foxr 1843: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1844: #
1845: my $format = &Apache::loncommon::define_excel_formats($workbook);
1846: return ($workbook,$filename,$format);
1847: }
1848:
1849: ###############################################################
1850: ###############################################################
1851:
1852: =pod
1853:
1.648 raeburn 1854: =item * &create_text_file()
1.113 bowersj2 1855:
1.542 raeburn 1856: Create a file to write to and eventually make available to the user.
1.256 matthew 1857: If file creation fails, outputs an error message on the request object and
1858: return undefs.
1.113 bowersj2 1859:
1.256 matthew 1860: Inputs: Apache request object, and file suffix
1.113 bowersj2 1861:
1.256 matthew 1862: Returns (undef) on failure,
1863: Filehandle and filename on success.
1.113 bowersj2 1864:
1865: =cut
1866:
1.256 matthew 1867: ###############################################################
1868: ###############################################################
1869: sub create_text_file {
1870: my ($r,$suffix) = @_;
1871: if (! defined($suffix)) { $suffix = 'txt'; };
1872: my $fh;
1873: my $filename = '/prtspool/'.
1.258 albertel 1874: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1875: time.'_'.rand(1000000000).'.'.$suffix;
1876: $fh = Apache::File->new('>/home/httpd'.$filename);
1877: if (! defined($fh)) {
1878: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1879: $r->print(
1880: '<p class="LC_error">'
1881: .&mt('Problems occurred in creating the output file.')
1882: .' '.&mt('This error has been logged.')
1883: .' '.&mt('Please alert your LON-CAPA administrator.')
1884: .'</p>'
1885: );
1.113 bowersj2 1886: }
1.256 matthew 1887: return ($fh,$filename)
1.113 bowersj2 1888: }
1889:
1890:
1.256 matthew 1891: =pod
1.113 bowersj2 1892:
1893: =back
1894:
1895: =cut
1.37 matthew 1896:
1897: ###############################################################
1.33 matthew 1898: ## Home server <option> list generating code ##
1899: ###############################################################
1.35 matthew 1900:
1.169 www 1901: # ------------------------------------------
1902:
1903: sub domain_select {
1904: my ($name,$value,$multiple)=@_;
1905: my %domains=map {
1.514 albertel 1906: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1907: } &Apache::lonnet::all_domains();
1.169 www 1908: if ($multiple) {
1909: $domains{''}=&mt('Any domain');
1.550 albertel 1910: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1911: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1912: } else {
1.550 albertel 1913: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1914: return &select_form($name,$value,\%domains);
1.169 www 1915: }
1916: }
1917:
1.282 albertel 1918: #-------------------------------------------
1919:
1920: =pod
1921:
1.519 raeburn 1922: =head1 Routines for form select boxes
1923:
1924: =over 4
1925:
1.648 raeburn 1926: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1927:
1928: Returns a string containing a <select> element int multiple mode
1929:
1930:
1931: Args:
1932: $name - name of the <select> element
1.506 raeburn 1933: $value - scalar or array ref of values that should already be selected
1.282 albertel 1934: $size - number of rows long the select element is
1.283 albertel 1935: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1936: (shown text should already have been &mt())
1.506 raeburn 1937: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1938:
1.282 albertel 1939: =cut
1940:
1941: #-------------------------------------------
1.169 www 1942: sub multiple_select_form {
1.284 albertel 1943: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1944: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1945: my $output='';
1.191 matthew 1946: if (! defined($size)) {
1947: $size = 4;
1.283 albertel 1948: if (scalar(keys(%$hash))<4) {
1949: $size = scalar(keys(%$hash));
1.191 matthew 1950: }
1951: }
1.734 bisitz 1952: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1953: my @order;
1.506 raeburn 1954: if (ref($order) eq 'ARRAY') {
1955: @order = @{$order};
1956: } else {
1957: @order = sort(keys(%$hash));
1.501 banghart 1958: }
1959: if (exists($$hash{'select_form_order'})) {
1960: @order = @{$$hash{'select_form_order'}};
1961: }
1962:
1.284 albertel 1963: foreach my $key (@order) {
1.356 albertel 1964: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1965: $output.='selected="selected" ' if ($selected{$key});
1966: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1967: }
1968: $output.="</select>\n";
1969: return $output;
1970: }
1971:
1.88 www 1972: #-------------------------------------------
1973:
1974: =pod
1975:
1.970 raeburn 1976: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1977:
1978: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1979: allow a user to select options from a ref to a hash containing:
1980: option_name => displayed text. An optional $onchange can include
1981: a javascript onchange item, e.g., onchange="this.form.submit();"
1982:
1.88 www 1983: See lonrights.pm for an example invocation and use.
1984:
1985: =cut
1986:
1987: #-------------------------------------------
1988: sub select_form {
1.970 raeburn 1989: my ($def,$name,$hashref,$onchange) = @_;
1990: return unless (ref($hashref) eq 'HASH');
1991: if ($onchange) {
1992: $onchange = ' onchange="'.$onchange.'"';
1993: }
1994: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1995: my @keys;
1.970 raeburn 1996: if (exists($hashref->{'select_form_order'})) {
1997: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1998: } else {
1.970 raeburn 1999: @keys=sort(keys(%{$hashref}));
1.128 albertel 2000: }
1.356 albertel 2001: foreach my $key (@keys) {
2002: $selectform.=
2003: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2004: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2005: ">".$hashref->{$key}."</option>\n";
1.88 www 2006: }
2007: $selectform.="</select>";
2008: return $selectform;
2009: }
2010:
1.475 www 2011: # For display filters
2012:
2013: sub display_filter {
1.1074 raeburn 2014: my ($context) = @_;
1.475 www 2015: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2016: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2017: my $phraseinput = 'hidden';
2018: my $includeinput = 'hidden';
2019: my ($checked,$includetypestext);
2020: if ($env{'form.displayfilter'} eq 'containing') {
2021: $phraseinput = 'text';
2022: if ($context eq 'parmslog') {
2023: $includeinput = 'checkbox';
2024: if ($env{'form.includetypes'}) {
2025: $checked = ' checked="checked"';
2026: }
2027: $includetypestext = &mt('Include parameter types');
2028: }
2029: } else {
2030: $includetypestext = ' ';
2031: }
2032: my ($additional,$secondid,$thirdid);
2033: if ($context eq 'parmslog') {
2034: $additional =
2035: '<label><input type="'.$includeinput.'" name="includetypes"'.
2036: $checked.' name="includetypes" value="1" id="includetypes" />'.
2037: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2038: '</label>';
2039: $secondid = 'includetypes';
2040: $thirdid = 'includetypestext';
2041: }
2042: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2043: '$secondid','$thirdid')";
2044: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2045: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2046: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2047: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2048: &mt('Filter: [_1]',
1.477 www 2049: &select_form($env{'form.displayfilter'},
2050: 'displayfilter',
1.970 raeburn 2051: {'currentfolder' => 'Current folder/page',
1.477 www 2052: 'containing' => 'Containing phrase',
1.1074 raeburn 2053: 'none' => 'None'},$onchange)).' '.
2054: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2055: &HTML::Entities::encode($env{'form.containingphrase'}).
2056: '" />'.$additional;
2057: }
2058:
2059: sub display_filter_js {
2060: my $includetext = &mt('Include parameter types');
2061: return <<"ENDJS";
2062:
2063: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2064: var firstType = 'hidden';
2065: if (setter.options[setter.selectedIndex].value == 'containing') {
2066: firstType = 'text';
2067: }
2068: firstObject = document.getElementById(firstid);
2069: if (typeof(firstObject) == 'object') {
2070: if (firstObject.type != firstType) {
2071: changeInputType(firstObject,firstType);
2072: }
2073: }
2074: if (context == 'parmslog') {
2075: var secondType = 'hidden';
2076: if (firstType == 'text') {
2077: secondType = 'checkbox';
2078: }
2079: secondObject = document.getElementById(secondid);
2080: if (typeof(secondObject) == 'object') {
2081: if (secondObject.type != secondType) {
2082: changeInputType(secondObject,secondType);
2083: }
2084: }
2085: var textItem = document.getElementById(thirdid);
2086: var currtext = textItem.innerHTML;
2087: var newtext;
2088: if (firstType == 'text') {
2089: newtext = '$includetext';
2090: } else {
2091: newtext = ' ';
2092: }
2093: if (currtext != newtext) {
2094: textItem.innerHTML = newtext;
2095: }
2096: }
2097: return;
2098: }
2099:
2100: function changeInputType(oldObject,newType) {
2101: var newObject = document.createElement('input');
2102: newObject.type = newType;
2103: if (oldObject.size) {
2104: newObject.size = oldObject.size;
2105: }
2106: if (oldObject.value) {
2107: newObject.value = oldObject.value;
2108: }
2109: if (oldObject.name) {
2110: newObject.name = oldObject.name;
2111: }
2112: if (oldObject.id) {
2113: newObject.id = oldObject.id;
2114: }
2115: oldObject.parentNode.replaceChild(newObject,oldObject);
2116: return;
2117: }
2118:
2119: ENDJS
1.475 www 2120: }
2121:
1.167 www 2122: sub gradeleveldescription {
2123: my $gradelevel=shift;
2124: my %gradelevels=(0 => 'Not specified',
2125: 1 => 'Grade 1',
2126: 2 => 'Grade 2',
2127: 3 => 'Grade 3',
2128: 4 => 'Grade 4',
2129: 5 => 'Grade 5',
2130: 6 => 'Grade 6',
2131: 7 => 'Grade 7',
2132: 8 => 'Grade 8',
2133: 9 => 'Grade 9',
2134: 10 => 'Grade 10',
2135: 11 => 'Grade 11',
2136: 12 => 'Grade 12',
2137: 13 => 'Grade 13',
2138: 14 => '100 Level',
2139: 15 => '200 Level',
2140: 16 => '300 Level',
2141: 17 => '400 Level',
2142: 18 => 'Graduate Level');
2143: return &mt($gradelevels{$gradelevel});
2144: }
2145:
1.163 www 2146: sub select_level_form {
2147: my ($deflevel,$name)=@_;
2148: unless ($deflevel) { $deflevel=0; }
1.167 www 2149: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2150: for (my $i=0; $i<=18; $i++) {
2151: $selectform.="<option value=\"$i\" ".
1.253 albertel 2152: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2153: ">".&gradeleveldescription($i)."</option>\n";
2154: }
2155: $selectform.="</select>";
2156: return $selectform;
1.163 www 2157: }
1.167 www 2158:
1.35 matthew 2159: #-------------------------------------------
2160:
1.45 matthew 2161: =pod
2162:
1.910 raeburn 2163: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2164:
2165: Returns a string containing a <select name='$name' size='1'> form to
2166: allow a user to select the domain to preform an operation in.
2167: See loncreateuser.pm for an example invocation and use.
2168:
1.90 www 2169: If the $includeempty flag is set, it also includes an empty choice ("no domain
2170: selected");
2171:
1.743 raeburn 2172: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2173:
1.910 raeburn 2174: 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.
2175:
2176: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2177:
1.35 matthew 2178: =cut
2179:
2180: #-------------------------------------------
1.34 matthew 2181: sub select_dom_form {
1.910 raeburn 2182: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2183: if ($onchange) {
1.874 raeburn 2184: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2185: }
1.910 raeburn 2186: my @domains;
2187: if (ref($incdoms) eq 'ARRAY') {
2188: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2189: } else {
2190: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2191: }
1.90 www 2192: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2193: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2194: foreach my $dom (@domains) {
2195: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2196: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2197: if ($showdomdesc) {
2198: if ($dom ne '') {
2199: my $domdesc = &Apache::lonnet::domain($dom,'description');
2200: if ($domdesc ne '') {
2201: $selectdomain .= ' ('.$domdesc.')';
2202: }
2203: }
2204: }
2205: $selectdomain .= "</option>\n";
1.34 matthew 2206: }
2207: $selectdomain.="</select>";
2208: return $selectdomain;
2209: }
2210:
1.35 matthew 2211: #-------------------------------------------
2212:
1.45 matthew 2213: =pod
2214:
1.648 raeburn 2215: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2216:
1.586 raeburn 2217: input: 4 arguments (two required, two optional) -
2218: $domain - domain of new user
2219: $name - name of form element
2220: $default - Value of 'default' causes a default item to be first
2221: option, and selected by default.
2222: $hide - Value of 'hide' causes hiding of the name of the server,
2223: if 1 server found, or default, if 0 found.
1.594 raeburn 2224: output: returns 2 items:
1.586 raeburn 2225: (a) form element which contains either:
2226: (i) <select name="$name">
2227: <option value="$hostid1">$hostid $servers{$hostid}</option>
2228: <option value="$hostid2">$hostid $servers{$hostid}</option>
2229: </select>
2230: form item if there are multiple library servers in $domain, or
2231: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2232: if there is only one library server in $domain.
2233:
2234: (b) number of library servers found.
2235:
2236: See loncreateuser.pm for example of use.
1.35 matthew 2237:
2238: =cut
2239:
2240: #-------------------------------------------
1.586 raeburn 2241: sub home_server_form_item {
2242: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2243: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2244: my $result;
2245: my $numlib = keys(%servers);
2246: if ($numlib > 1) {
2247: $result .= '<select name="'.$name.'" />'."\n";
2248: if ($default) {
1.804 bisitz 2249: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2250: '</option>'."\n";
2251: }
2252: foreach my $hostid (sort(keys(%servers))) {
2253: $result.= '<option value="'.$hostid.'">'.
2254: $hostid.' '.$servers{$hostid}."</option>\n";
2255: }
2256: $result .= '</select>'."\n";
2257: } elsif ($numlib == 1) {
2258: my $hostid;
2259: foreach my $item (keys(%servers)) {
2260: $hostid = $item;
2261: }
2262: $result .= '<input type="hidden" name="'.$name.'" value="'.
2263: $hostid.'" />';
2264: if (!$hide) {
2265: $result .= $hostid.' '.$servers{$hostid};
2266: }
2267: $result .= "\n";
2268: } elsif ($default) {
2269: $result .= '<input type="hidden" name="'.$name.
2270: '" value="default" />';
2271: if (!$hide) {
2272: $result .= &mt('default');
2273: }
2274: $result .= "\n";
1.33 matthew 2275: }
1.586 raeburn 2276: return ($result,$numlib);
1.33 matthew 2277: }
1.112 bowersj2 2278:
2279: =pod
2280:
1.534 albertel 2281: =back
2282:
1.112 bowersj2 2283: =cut
1.87 matthew 2284:
2285: ###############################################################
1.112 bowersj2 2286: ## Decoding User Agent ##
1.87 matthew 2287: ###############################################################
2288:
2289: =pod
2290:
1.112 bowersj2 2291: =head1 Decoding the User Agent
2292:
2293: =over 4
2294:
2295: =item * &decode_user_agent()
1.87 matthew 2296:
2297: Inputs: $r
2298:
2299: Outputs:
2300:
2301: =over 4
2302:
1.112 bowersj2 2303: =item * $httpbrowser
1.87 matthew 2304:
1.112 bowersj2 2305: =item * $clientbrowser
1.87 matthew 2306:
1.112 bowersj2 2307: =item * $clientversion
1.87 matthew 2308:
1.112 bowersj2 2309: =item * $clientmathml
1.87 matthew 2310:
1.112 bowersj2 2311: =item * $clientunicode
1.87 matthew 2312:
1.112 bowersj2 2313: =item * $clientos
1.87 matthew 2314:
2315: =back
2316:
1.157 matthew 2317: =back
2318:
1.87 matthew 2319: =cut
2320:
2321: ###############################################################
2322: ###############################################################
2323: sub decode_user_agent {
1.247 albertel 2324: my ($r)=@_;
1.87 matthew 2325: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2326: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2327: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2328: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2329: my $clientbrowser='unknown';
2330: my $clientversion='0';
2331: my $clientmathml='';
2332: my $clientunicode='0';
2333: for (my $i=0;$i<=$#browsertype;$i++) {
2334: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2335: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2336: $clientbrowser=$bname;
2337: $httpbrowser=~/$vreg/i;
2338: $clientversion=$1;
2339: $clientmathml=($clientversion>=$minv);
2340: $clientunicode=($clientversion>=$univ);
2341: }
2342: }
2343: my $clientos='unknown';
2344: if (($httpbrowser=~/linux/i) ||
2345: ($httpbrowser=~/unix/i) ||
2346: ($httpbrowser=~/ux/i) ||
2347: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2348: if (($httpbrowser=~/vax/i) ||
2349: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2350: if ($httpbrowser=~/next/i) { $clientos='next'; }
2351: if (($httpbrowser=~/mac/i) ||
2352: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2353: if ($httpbrowser=~/win/i) { $clientos='win'; }
2354: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2355: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2356: $clientunicode,$clientos,);
2357: }
2358:
1.32 matthew 2359: ###############################################################
2360: ## Authentication changing form generation subroutines ##
2361: ###############################################################
2362: ##
2363: ## All of the authform_xxxxxxx subroutines take their inputs in a
2364: ## hash, and have reasonable default values.
2365: ##
2366: ## formname = the name given in the <form> tag.
1.35 matthew 2367: #-------------------------------------------
2368:
1.45 matthew 2369: =pod
2370:
1.112 bowersj2 2371: =head1 Authentication Routines
2372:
2373: =over 4
2374:
1.648 raeburn 2375: =item * &authform_xxxxxx()
1.35 matthew 2376:
2377: The authform_xxxxxx subroutines provide javascript and html forms which
2378: handle some of the conveniences required for authentication forms.
2379: This is not an optimal method, but it works.
2380:
2381: =over 4
2382:
1.112 bowersj2 2383: =item * authform_header
1.35 matthew 2384:
1.112 bowersj2 2385: =item * authform_authorwarning
1.35 matthew 2386:
1.112 bowersj2 2387: =item * authform_nochange
1.35 matthew 2388:
1.112 bowersj2 2389: =item * authform_kerberos
1.35 matthew 2390:
1.112 bowersj2 2391: =item * authform_internal
1.35 matthew 2392:
1.112 bowersj2 2393: =item * authform_filesystem
1.35 matthew 2394:
2395: =back
2396:
1.648 raeburn 2397: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2398:
1.35 matthew 2399: =cut
2400:
2401: #-------------------------------------------
1.32 matthew 2402: sub authform_header{
2403: my %in = (
2404: formname => 'cu',
1.80 albertel 2405: kerb_def_dom => '',
1.32 matthew 2406: @_,
2407: );
2408: $in{'formname'} = 'document.' . $in{'formname'};
2409: my $result='';
1.80 albertel 2410:
2411: #---------------------------------------------- Code for upper case translation
2412: my $Javascript_toUpperCase;
2413: unless ($in{kerb_def_dom}) {
2414: $Javascript_toUpperCase =<<"END";
2415: switch (choice) {
2416: case 'krb': currentform.elements[choicearg].value =
2417: currentform.elements[choicearg].value.toUpperCase();
2418: break;
2419: default:
2420: }
2421: END
2422: } else {
2423: $Javascript_toUpperCase = "";
2424: }
2425:
1.165 raeburn 2426: my $radioval = "'nochange'";
1.591 raeburn 2427: if (defined($in{'curr_authtype'})) {
2428: if ($in{'curr_authtype'} ne '') {
2429: $radioval = "'".$in{'curr_authtype'}."arg'";
2430: }
1.174 matthew 2431: }
1.165 raeburn 2432: my $argfield = 'null';
1.591 raeburn 2433: if (defined($in{'mode'})) {
1.165 raeburn 2434: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2435: if (defined($in{'curr_autharg'})) {
2436: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2437: $argfield = "'$in{'curr_autharg'}'";
2438: }
2439: }
2440: }
2441: }
2442:
1.32 matthew 2443: $result.=<<"END";
2444: var current = new Object();
1.165 raeburn 2445: current.radiovalue = $radioval;
2446: current.argfield = $argfield;
1.32 matthew 2447:
2448: function changed_radio(choice,currentform) {
2449: var choicearg = choice + 'arg';
2450: // If a radio button in changed, we need to change the argfield
2451: if (current.radiovalue != choice) {
2452: current.radiovalue = choice;
2453: if (current.argfield != null) {
2454: currentform.elements[current.argfield].value = '';
2455: }
2456: if (choice == 'nochange') {
2457: current.argfield = null;
2458: } else {
2459: current.argfield = choicearg;
2460: switch(choice) {
2461: case 'krb':
2462: currentform.elements[current.argfield].value =
2463: "$in{'kerb_def_dom'}";
2464: break;
2465: default:
2466: break;
2467: }
2468: }
2469: }
2470: return;
2471: }
1.22 www 2472:
1.32 matthew 2473: function changed_text(choice,currentform) {
2474: var choicearg = choice + 'arg';
2475: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2476: $Javascript_toUpperCase
1.32 matthew 2477: // clear old field
2478: if ((current.argfield != choicearg) && (current.argfield != null)) {
2479: currentform.elements[current.argfield].value = '';
2480: }
2481: current.argfield = choicearg;
2482: }
2483: set_auth_radio_buttons(choice,currentform);
2484: return;
1.20 www 2485: }
1.32 matthew 2486:
2487: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2488: var numauthchoices = currentform.login.length;
2489: if (typeof numauthchoices == "undefined") {
2490: return;
2491: }
1.32 matthew 2492: var i=0;
1.986 raeburn 2493: while (i < numauthchoices) {
1.32 matthew 2494: if (currentform.login[i].value == newvalue) { break; }
2495: i++;
2496: }
1.986 raeburn 2497: if (i == numauthchoices) {
1.32 matthew 2498: return;
2499: }
2500: current.radiovalue = newvalue;
2501: currentform.login[i].checked = true;
2502: return;
2503: }
2504: END
2505: return $result;
2506: }
2507:
2508: sub authform_authorwarning{
2509: my $result='';
1.144 matthew 2510: $result='<i>'.
2511: &mt('As a general rule, only authors or co-authors should be '.
2512: 'filesystem authenticated '.
2513: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2514: return $result;
2515: }
2516:
2517: sub authform_nochange{
2518: my %in = (
2519: formname => 'document.cu',
2520: kerb_def_dom => 'MSU.EDU',
2521: @_,
2522: );
1.586 raeburn 2523: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2524: my $result;
2525: if (keys(%can_assign) == 0) {
2526: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2527: } else {
2528: $result = '<label>'.&mt('[_1] Do not change login data',
2529: '<input type="radio" name="login" value="nochange" '.
2530: 'checked="checked" onclick="'.
1.281 albertel 2531: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2532: '</label>';
1.586 raeburn 2533: }
1.32 matthew 2534: return $result;
2535: }
2536:
1.591 raeburn 2537: sub authform_kerberos {
1.32 matthew 2538: my %in = (
2539: formname => 'document.cu',
2540: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2541: kerb_def_auth => 'krb4',
1.32 matthew 2542: @_,
2543: );
1.586 raeburn 2544: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2545: $autharg,$jscall);
2546: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2547: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2548: $check5 = ' checked="checked"';
1.80 albertel 2549: } else {
1.772 bisitz 2550: $check4 = ' checked="checked"';
1.80 albertel 2551: }
1.165 raeburn 2552: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2553: if (defined($in{'curr_authtype'})) {
2554: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2555: $krbcheck = ' checked="checked"';
1.623 raeburn 2556: if (defined($in{'mode'})) {
2557: if ($in{'mode'} eq 'modifyuser') {
2558: $krbcheck = '';
2559: }
2560: }
1.591 raeburn 2561: if (defined($in{'curr_kerb_ver'})) {
2562: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2563: $check5 = ' checked="checked"';
1.591 raeburn 2564: $check4 = '';
2565: } else {
1.772 bisitz 2566: $check4 = ' checked="checked"';
1.591 raeburn 2567: $check5 = '';
2568: }
1.586 raeburn 2569: }
1.591 raeburn 2570: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2571: $krbarg = $in{'curr_autharg'};
2572: }
1.586 raeburn 2573: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2574: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2575: $result =
2576: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2577: $in{'curr_autharg'},$krbver);
2578: } else {
2579: $result =
2580: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2581: }
2582: return $result;
2583: }
2584: }
2585: } else {
2586: if ($authnum == 1) {
1.784 bisitz 2587: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2588: }
2589: }
1.586 raeburn 2590: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2591: return;
1.587 raeburn 2592: } elsif ($authtype eq '') {
1.591 raeburn 2593: if (defined($in{'mode'})) {
1.587 raeburn 2594: if ($in{'mode'} eq 'modifycourse') {
2595: if ($authnum == 1) {
1.784 bisitz 2596: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2597: }
2598: }
2599: }
1.586 raeburn 2600: }
2601: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2602: if ($authtype eq '') {
2603: $authtype = '<input type="radio" name="login" value="krb" '.
2604: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2605: $krbcheck.' />';
2606: }
2607: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2608: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2609: $in{'curr_authtype'} eq 'krb5') ||
2610: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2611: $in{'curr_authtype'} eq 'krb4')) {
2612: $result .= &mt
1.144 matthew 2613: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2614: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2615: '<label>'.$authtype,
1.281 albertel 2616: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2617: 'value="'.$krbarg.'" '.
1.144 matthew 2618: 'onchange="'.$jscall.'" />',
1.281 albertel 2619: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2620: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2621: '</label>');
1.586 raeburn 2622: } elsif ($can_assign{'krb4'}) {
2623: $result .= &mt
2624: ('[_1] Kerberos authenticated with domain [_2] '.
2625: '[_3] Version 4 [_4]',
2626: '<label>'.$authtype,
2627: '</label><input type="text" size="10" name="krbarg" '.
2628: 'value="'.$krbarg.'" '.
2629: 'onchange="'.$jscall.'" />',
2630: '<label><input type="hidden" name="krbver" value="4" />',
2631: '</label>');
2632: } elsif ($can_assign{'krb5'}) {
2633: $result .= &mt
2634: ('[_1] Kerberos authenticated with domain [_2] '.
2635: '[_3] Version 5 [_4]',
2636: '<label>'.$authtype,
2637: '</label><input type="text" size="10" name="krbarg" '.
2638: 'value="'.$krbarg.'" '.
2639: 'onchange="'.$jscall.'" />',
2640: '<label><input type="hidden" name="krbver" value="5" />',
2641: '</label>');
2642: }
1.32 matthew 2643: return $result;
2644: }
2645:
2646: sub authform_internal{
1.586 raeburn 2647: my %in = (
1.32 matthew 2648: formname => 'document.cu',
2649: kerb_def_dom => 'MSU.EDU',
2650: @_,
2651: );
1.586 raeburn 2652: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2653: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2654: if (defined($in{'curr_authtype'})) {
2655: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2656: if ($can_assign{'int'}) {
1.772 bisitz 2657: $intcheck = 'checked="checked" ';
1.623 raeburn 2658: if (defined($in{'mode'})) {
2659: if ($in{'mode'} eq 'modifyuser') {
2660: $intcheck = '';
2661: }
2662: }
1.591 raeburn 2663: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2664: $intarg = $in{'curr_autharg'};
2665: }
2666: } else {
2667: $result = &mt('Currently internally authenticated.');
2668: return $result;
1.165 raeburn 2669: }
2670: }
1.586 raeburn 2671: } else {
2672: if ($authnum == 1) {
1.784 bisitz 2673: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2674: }
2675: }
2676: if (!$can_assign{'int'}) {
2677: return;
1.587 raeburn 2678: } elsif ($authtype eq '') {
1.591 raeburn 2679: if (defined($in{'mode'})) {
1.587 raeburn 2680: if ($in{'mode'} eq 'modifycourse') {
2681: if ($authnum == 1) {
1.784 bisitz 2682: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2683: }
2684: }
2685: }
1.165 raeburn 2686: }
1.586 raeburn 2687: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2688: if ($authtype eq '') {
2689: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2690: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2691: }
1.605 bisitz 2692: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2693: $intarg.'" onchange="'.$jscall.'" />';
2694: $result = &mt
1.144 matthew 2695: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2696: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2697: $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 2698: return $result;
2699: }
2700:
2701: sub authform_local{
2702: my %in = (
2703: formname => 'document.cu',
2704: kerb_def_dom => 'MSU.EDU',
2705: @_,
2706: );
1.586 raeburn 2707: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2708: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2709: if (defined($in{'curr_authtype'})) {
2710: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2711: if ($can_assign{'loc'}) {
1.772 bisitz 2712: $loccheck = 'checked="checked" ';
1.623 raeburn 2713: if (defined($in{'mode'})) {
2714: if ($in{'mode'} eq 'modifyuser') {
2715: $loccheck = '';
2716: }
2717: }
1.591 raeburn 2718: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2719: $locarg = $in{'curr_autharg'};
2720: }
2721: } else {
2722: $result = &mt('Currently using local (institutional) authentication.');
2723: return $result;
1.165 raeburn 2724: }
2725: }
1.586 raeburn 2726: } else {
2727: if ($authnum == 1) {
1.784 bisitz 2728: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2729: }
2730: }
2731: if (!$can_assign{'loc'}) {
2732: return;
1.587 raeburn 2733: } elsif ($authtype eq '') {
1.591 raeburn 2734: if (defined($in{'mode'})) {
1.587 raeburn 2735: if ($in{'mode'} eq 'modifycourse') {
2736: if ($authnum == 1) {
1.784 bisitz 2737: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2738: }
2739: }
2740: }
1.165 raeburn 2741: }
1.586 raeburn 2742: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2743: if ($authtype eq '') {
2744: $authtype = '<input type="radio" name="login" value="loc" '.
2745: $loccheck.' onchange="'.$jscall.'" onclick="'.
2746: $jscall.'" />';
2747: }
2748: $autharg = '<input type="text" size="10" name="locarg" value="'.
2749: $locarg.'" onchange="'.$jscall.'" />';
2750: $result = &mt('[_1] Local Authentication with argument [_2]',
2751: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2752: return $result;
2753: }
2754:
2755: sub authform_filesystem{
2756: my %in = (
2757: formname => 'document.cu',
2758: kerb_def_dom => 'MSU.EDU',
2759: @_,
2760: );
1.586 raeburn 2761: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2762: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2763: if (defined($in{'curr_authtype'})) {
2764: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2765: if ($can_assign{'fsys'}) {
1.772 bisitz 2766: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2767: if (defined($in{'mode'})) {
2768: if ($in{'mode'} eq 'modifyuser') {
2769: $fsyscheck = '';
2770: }
2771: }
1.586 raeburn 2772: } else {
2773: $result = &mt('Currently Filesystem Authenticated.');
2774: return $result;
2775: }
2776: }
2777: } else {
2778: if ($authnum == 1) {
1.784 bisitz 2779: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2780: }
2781: }
2782: if (!$can_assign{'fsys'}) {
2783: return;
1.587 raeburn 2784: } elsif ($authtype eq '') {
1.591 raeburn 2785: if (defined($in{'mode'})) {
1.587 raeburn 2786: if ($in{'mode'} eq 'modifycourse') {
2787: if ($authnum == 1) {
1.784 bisitz 2788: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2789: }
2790: }
2791: }
1.586 raeburn 2792: }
2793: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2794: if ($authtype eq '') {
2795: $authtype = '<input type="radio" name="login" value="fsys" '.
2796: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2797: $jscall.'" />';
2798: }
2799: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2800: ' onchange="'.$jscall.'" />';
2801: $result = &mt
1.144 matthew 2802: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2803: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2804: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2805: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2806: 'onchange="'.$jscall.'" />');
1.32 matthew 2807: return $result;
2808: }
2809:
1.586 raeburn 2810: sub get_assignable_auth {
2811: my ($dom) = @_;
2812: if ($dom eq '') {
2813: $dom = $env{'request.role.domain'};
2814: }
2815: my %can_assign = (
2816: krb4 => 1,
2817: krb5 => 1,
2818: int => 1,
2819: loc => 1,
2820: );
2821: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2822: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2823: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2824: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2825: my $context;
2826: if ($env{'request.role'} =~ /^au/) {
2827: $context = 'author';
2828: } elsif ($env{'request.role'} =~ /^dc/) {
2829: $context = 'domain';
2830: } elsif ($env{'request.course.id'}) {
2831: $context = 'course';
2832: }
2833: if ($context) {
2834: if (ref($authhash->{$context}) eq 'HASH') {
2835: %can_assign = %{$authhash->{$context}};
2836: }
2837: }
2838: }
2839: }
2840: my $authnum = 0;
2841: foreach my $key (keys(%can_assign)) {
2842: if ($can_assign{$key}) {
2843: $authnum ++;
2844: }
2845: }
2846: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2847: $authnum --;
2848: }
2849: return ($authnum,%can_assign);
2850: }
2851:
1.80 albertel 2852: ###############################################################
2853: ## Get Kerberos Defaults for Domain ##
2854: ###############################################################
2855: ##
2856: ## Returns default kerberos version and an associated argument
2857: ## as listed in file domain.tab. If not listed, provides
2858: ## appropriate default domain and kerberos version.
2859: ##
2860: #-------------------------------------------
2861:
2862: =pod
2863:
1.648 raeburn 2864: =item * &get_kerberos_defaults()
1.80 albertel 2865:
2866: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2867: version and domain. If not found, it defaults to version 4 and the
2868: domain of the server.
1.80 albertel 2869:
1.648 raeburn 2870: =over 4
2871:
1.80 albertel 2872: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2873:
1.648 raeburn 2874: =back
2875:
2876: =back
2877:
1.80 albertel 2878: =cut
2879:
2880: #-------------------------------------------
2881: sub get_kerberos_defaults {
2882: my $domain=shift;
1.641 raeburn 2883: my ($krbdef,$krbdefdom);
2884: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2885: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2886: $krbdef = $domdefaults{'auth_def'};
2887: $krbdefdom = $domdefaults{'auth_arg_def'};
2888: } else {
1.80 albertel 2889: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2890: my $krbdefdom=$1;
2891: $krbdefdom=~tr/a-z/A-Z/;
2892: $krbdef = "krb4";
2893: }
2894: return ($krbdef,$krbdefdom);
2895: }
1.112 bowersj2 2896:
1.32 matthew 2897:
1.46 matthew 2898: ###############################################################
2899: ## Thesaurus Functions ##
2900: ###############################################################
1.20 www 2901:
1.46 matthew 2902: =pod
1.20 www 2903:
1.112 bowersj2 2904: =head1 Thesaurus Functions
2905:
2906: =over 4
2907:
1.648 raeburn 2908: =item * &initialize_keywords()
1.46 matthew 2909:
2910: Initializes the package variable %Keywords if it is empty. Uses the
2911: package variable $thesaurus_db_file.
2912:
2913: =cut
2914:
2915: ###################################################
2916:
2917: sub initialize_keywords {
2918: return 1 if (scalar keys(%Keywords));
2919: # If we are here, %Keywords is empty, so fill it up
2920: # Make sure the file we need exists...
2921: if (! -e $thesaurus_db_file) {
2922: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2923: " failed because it does not exist");
2924: return 0;
2925: }
2926: # Set up the hash as a database
2927: my %thesaurus_db;
2928: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2929: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2930: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2931: $thesaurus_db_file);
2932: return 0;
2933: }
2934: # Get the average number of appearances of a word.
2935: my $avecount = $thesaurus_db{'average.count'};
2936: # Put keywords (those that appear > average) into %Keywords
2937: while (my ($word,$data)=each (%thesaurus_db)) {
2938: my ($count,undef) = split /:/,$data;
2939: $Keywords{$word}++ if ($count > $avecount);
2940: }
2941: untie %thesaurus_db;
2942: # Remove special values from %Keywords.
1.356 albertel 2943: foreach my $value ('total.count','average.count') {
2944: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2945: }
1.46 matthew 2946: return 1;
2947: }
2948:
2949: ###################################################
2950:
2951: =pod
2952:
1.648 raeburn 2953: =item * &keyword($word)
1.46 matthew 2954:
2955: Returns true if $word is a keyword. A keyword is a word that appears more
2956: than the average number of times in the thesaurus database. Calls
2957: &initialize_keywords
2958:
2959: =cut
2960:
2961: ###################################################
1.20 www 2962:
2963: sub keyword {
1.46 matthew 2964: return if (!&initialize_keywords());
2965: my $word=lc(shift());
2966: $word=~s/\W//g;
2967: return exists($Keywords{$word});
1.20 www 2968: }
1.46 matthew 2969:
2970: ###############################################################
2971:
2972: =pod
1.20 www 2973:
1.648 raeburn 2974: =item * &get_related_words()
1.46 matthew 2975:
1.160 matthew 2976: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2977: an array of words. If the keyword is not in the thesaurus, an empty array
2978: will be returned. The order of the words returned is determined by the
2979: database which holds them.
2980:
2981: Uses global $thesaurus_db_file.
2982:
1.1057 foxr 2983:
1.46 matthew 2984: =cut
2985:
2986: ###############################################################
2987: sub get_related_words {
2988: my $keyword = shift;
2989: my %thesaurus_db;
2990: if (! -e $thesaurus_db_file) {
2991: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2992: "failed because the file does not exist");
2993: return ();
2994: }
2995: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2996: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2997: return ();
2998: }
2999: my @Words=();
1.429 www 3000: my $count=0;
1.46 matthew 3001: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3002: # The first element is the number of times
3003: # the word appears. We do not need it now.
1.429 www 3004: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3005: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3006: my $threshold=$mostfrequentcount/10;
3007: foreach my $possibleword (@RelatedWords) {
3008: my ($word,$wordcount)=split(/\,/,$possibleword);
3009: if ($wordcount>$threshold) {
3010: push(@Words,$word);
3011: $count++;
3012: if ($count>10) { last; }
3013: }
1.20 www 3014: }
3015: }
1.46 matthew 3016: untie %thesaurus_db;
3017: return @Words;
1.14 harris41 3018: }
1.46 matthew 3019:
1.112 bowersj2 3020: =pod
3021:
3022: =back
3023:
3024: =cut
1.61 www 3025:
3026: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3027: =pod
3028:
1.112 bowersj2 3029: =head1 User Name Functions
3030:
3031: =over 4
3032:
1.648 raeburn 3033: =item * &plainname($uname,$udom,$first)
1.81 albertel 3034:
1.112 bowersj2 3035: Takes a users logon name and returns it as a string in
1.226 albertel 3036: "first middle last generation" form
3037: if $first is set to 'lastname' then it returns it as
3038: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3039:
3040: =cut
1.61 www 3041:
1.295 www 3042:
1.81 albertel 3043: ###############################################################
1.61 www 3044: sub plainname {
1.226 albertel 3045: my ($uname,$udom,$first)=@_;
1.537 albertel 3046: return if (!defined($uname) || !defined($udom));
1.295 www 3047: my %names=&getnames($uname,$udom);
1.226 albertel 3048: my $name=&Apache::lonnet::format_name($names{'firstname'},
3049: $names{'middlename'},
3050: $names{'lastname'},
3051: $names{'generation'},$first);
3052: $name=~s/^\s+//;
1.62 www 3053: $name=~s/\s+$//;
3054: $name=~s/\s+/ /g;
1.353 albertel 3055: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3056: return $name;
1.61 www 3057: }
1.66 www 3058:
3059: # -------------------------------------------------------------------- Nickname
1.81 albertel 3060: =pod
3061:
1.648 raeburn 3062: =item * &nickname($uname,$udom)
1.81 albertel 3063:
3064: Gets a users name and returns it as a string as
3065:
3066: ""nickname""
1.66 www 3067:
1.81 albertel 3068: if the user has a nickname or
3069:
3070: "first middle last generation"
3071:
3072: if the user does not
3073:
3074: =cut
1.66 www 3075:
3076: sub nickname {
3077: my ($uname,$udom)=@_;
1.537 albertel 3078: return if (!defined($uname) || !defined($udom));
1.295 www 3079: my %names=&getnames($uname,$udom);
1.68 albertel 3080: my $name=$names{'nickname'};
1.66 www 3081: if ($name) {
3082: $name='"'.$name.'"';
3083: } else {
3084: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3085: $names{'lastname'}.' '.$names{'generation'};
3086: $name=~s/\s+$//;
3087: $name=~s/\s+/ /g;
3088: }
3089: return $name;
3090: }
3091:
1.295 www 3092: sub getnames {
3093: my ($uname,$udom)=@_;
1.537 albertel 3094: return if (!defined($uname) || !defined($udom));
1.433 albertel 3095: if ($udom eq 'public' && $uname eq 'public') {
3096: return ('lastname' => &mt('Public'));
3097: }
1.295 www 3098: my $id=$uname.':'.$udom;
3099: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3100: if ($cached) {
3101: return %{$names};
3102: } else {
3103: my %loadnames=&Apache::lonnet::get('environment',
3104: ['firstname','middlename','lastname','generation','nickname'],
3105: $udom,$uname);
3106: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3107: return %loadnames;
3108: }
3109: }
1.61 www 3110:
1.542 raeburn 3111: # -------------------------------------------------------------------- getemails
1.648 raeburn 3112:
1.542 raeburn 3113: =pod
3114:
1.648 raeburn 3115: =item * &getemails($uname,$udom)
1.542 raeburn 3116:
3117: Gets a user's email information and returns it as a hash with keys:
3118: notification, critnotification, permanentemail
3119:
3120: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3121: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3122:
1.648 raeburn 3123:
1.542 raeburn 3124: =cut
3125:
1.648 raeburn 3126:
1.466 albertel 3127: sub getemails {
3128: my ($uname,$udom)=@_;
3129: if ($udom eq 'public' && $uname eq 'public') {
3130: return;
3131: }
1.467 www 3132: if (!$udom) { $udom=$env{'user.domain'}; }
3133: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3134: my $id=$uname.':'.$udom;
3135: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3136: if ($cached) {
3137: return %{$names};
3138: } else {
3139: my %loadnames=&Apache::lonnet::get('environment',
3140: ['notification','critnotification',
3141: 'permanentemail'],
3142: $udom,$uname);
3143: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3144: return %loadnames;
3145: }
3146: }
3147:
1.551 albertel 3148: sub flush_email_cache {
3149: my ($uname,$udom)=@_;
3150: if (!$udom) { $udom =$env{'user.domain'}; }
3151: if (!$uname) { $uname=$env{'user.name'}; }
3152: return if ($udom eq 'public' && $uname eq 'public');
3153: my $id=$uname.':'.$udom;
3154: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3155: }
3156:
1.728 raeburn 3157: # -------------------------------------------------------------------- getlangs
3158:
3159: =pod
3160:
3161: =item * &getlangs($uname,$udom)
3162:
3163: Gets a user's language preference and returns it as a hash with key:
3164: language.
3165:
3166: =cut
3167:
3168:
3169: sub getlangs {
3170: my ($uname,$udom) = @_;
3171: if (!$udom) { $udom =$env{'user.domain'}; }
3172: if (!$uname) { $uname=$env{'user.name'}; }
3173: my $id=$uname.':'.$udom;
3174: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3175: if ($cached) {
3176: return %{$langs};
3177: } else {
3178: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3179: $udom,$uname);
3180: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3181: return %loadlangs;
3182: }
3183: }
3184:
3185: sub flush_langs_cache {
3186: my ($uname,$udom)=@_;
3187: if (!$udom) { $udom =$env{'user.domain'}; }
3188: if (!$uname) { $uname=$env{'user.name'}; }
3189: return if ($udom eq 'public' && $uname eq 'public');
3190: my $id=$uname.':'.$udom;
3191: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3192: }
3193:
1.61 www 3194: # ------------------------------------------------------------------ Screenname
1.81 albertel 3195:
3196: =pod
3197:
1.648 raeburn 3198: =item * &screenname($uname,$udom)
1.81 albertel 3199:
3200: Gets a users screenname and returns it as a string
3201:
3202: =cut
1.61 www 3203:
3204: sub screenname {
3205: my ($uname,$udom)=@_;
1.258 albertel 3206: if ($uname eq $env{'user.name'} &&
3207: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3208: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3209: return $names{'screenname'};
1.62 www 3210: }
3211:
1.212 albertel 3212:
1.802 bisitz 3213: # ------------------------------------------------------------- Confirm Wrapper
3214: =pod
3215:
3216: =item confirmwrapper
3217:
3218: Wrap messages about completion of operation in box
3219:
3220: =cut
3221:
3222: sub confirmwrapper {
3223: my ($message)=@_;
3224: if ($message) {
3225: return "\n".'<div class="LC_confirm_box">'."\n"
3226: .$message."\n"
3227: .'</div>'."\n";
3228: } else {
3229: return $message;
3230: }
3231: }
3232:
1.62 www 3233: # ------------------------------------------------------------- Message Wrapper
3234:
3235: sub messagewrapper {
1.369 www 3236: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3237: return
1.441 albertel 3238: '<a href="/adm/email?compose=individual&'.
3239: 'recname='.$username.'&recdom='.$domain.
3240: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3241: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3242: }
1.802 bisitz 3243:
1.74 www 3244: # --------------------------------------------------------------- Notes Wrapper
3245:
3246: sub noteswrapper {
3247: my ($link,$un,$do)=@_;
3248: return
1.896 amueller 3249: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3250: }
1.802 bisitz 3251:
1.62 www 3252: # ------------------------------------------------------------- Aboutme Wrapper
3253:
3254: sub aboutmewrapper {
1.1070 raeburn 3255: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3256: if (!defined($username) && !defined($domain)) {
3257: return;
3258: }
1.892 amueller 3259: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.1070 raeburn 3260: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3261: }
3262:
3263: # ------------------------------------------------------------ Syllabus Wrapper
3264:
3265: sub syllabuswrapper {
1.707 bisitz 3266: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3267: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3268: }
1.14 harris41 3269:
1.802 bisitz 3270: # -----------------------------------------------------------------------------
3271:
1.208 matthew 3272: sub track_student_link {
1.887 raeburn 3273: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3274: my $link ="/adm/trackstudent?";
1.208 matthew 3275: my $title = 'View recent activity';
3276: if (defined($sname) && $sname !~ /^\s*$/ &&
3277: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3278: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3279: $title .= ' of this student';
1.268 albertel 3280: }
1.208 matthew 3281: if (defined($target) && $target !~ /^\s*$/) {
3282: $target = qq{target="$target"};
3283: } else {
3284: $target = '';
3285: }
1.268 albertel 3286: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3287: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3288: $title = &mt($title);
3289: $linktext = &mt($linktext);
1.448 albertel 3290: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3291: &help_open_topic('View_recent_activity');
1.208 matthew 3292: }
3293:
1.781 raeburn 3294: sub slot_reservations_link {
3295: my ($linktext,$sname,$sdom,$target) = @_;
3296: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3297: my $title = 'View slot reservation history';
3298: if (defined($sname) && $sname !~ /^\s*$/ &&
3299: defined($sdom) && $sdom !~ /^\s*$/) {
3300: $link .= "&uname=$sname&udom=$sdom";
3301: $title .= ' of this student';
3302: }
3303: if (defined($target) && $target !~ /^\s*$/) {
3304: $target = qq{target="$target"};
3305: } else {
3306: $target = '';
3307: }
3308: $title = &mt($title);
3309: $linktext = &mt($linktext);
3310: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3311: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3312:
3313: }
3314:
1.508 www 3315: # ===================================================== Display a student photo
3316:
3317:
1.509 albertel 3318: sub student_image_tag {
1.508 www 3319: my ($domain,$user)=@_;
3320: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3321: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3322: return '<img src="'.$imgsrc.'" align="right" />';
3323: } else {
3324: return '';
3325: }
3326: }
3327:
1.112 bowersj2 3328: =pod
3329:
3330: =back
3331:
3332: =head1 Access .tab File Data
3333:
3334: =over 4
3335:
1.648 raeburn 3336: =item * &languageids()
1.112 bowersj2 3337:
3338: returns list of all language ids
3339:
3340: =cut
3341:
1.14 harris41 3342: sub languageids {
1.16 harris41 3343: return sort(keys(%language));
1.14 harris41 3344: }
3345:
1.112 bowersj2 3346: =pod
3347:
1.648 raeburn 3348: =item * &languagedescription()
1.112 bowersj2 3349:
3350: returns description of a specified language id
3351:
3352: =cut
3353:
1.14 harris41 3354: sub languagedescription {
1.125 www 3355: my $code=shift;
3356: return ($supported_language{$code}?'* ':'').
3357: $language{$code}.
1.126 www 3358: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3359: }
3360:
1.1048 foxr 3361: =pod
3362:
3363: =item * &plainlanguagedescription
3364:
3365: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3366: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3367:
3368: =cut
3369:
1.145 www 3370: sub plainlanguagedescription {
3371: my $code=shift;
3372: return $language{$code};
3373: }
3374:
1.1048 foxr 3375: =pod
3376:
3377: =item * &supportedlanguagecode
3378:
3379: Returns the supported language code (e.g. sptutf maps to pt) given a language
3380: code.
3381:
3382: =cut
3383:
1.145 www 3384: sub supportedlanguagecode {
3385: my $code=shift;
3386: return $supported_language{$code};
1.97 www 3387: }
3388:
1.112 bowersj2 3389: =pod
3390:
1.1048 foxr 3391: =item * &latexlanguage()
3392:
3393: Given a language key code returns the correspondnig language to use
3394: to select the correct hyphenation on LaTeX printouts. This is undef if there
3395: is no supported hyphenation for the language code.
3396:
3397: =cut
3398:
3399: sub latexlanguage {
3400: my $code = shift;
3401: return $latex_language{$code};
3402: }
3403:
3404: =pod
3405:
3406: =item * &latexhyphenation()
3407:
3408: Same as above but what's supplied is the language as it might be stored
3409: in the metadata.
3410:
3411: =cut
3412:
3413: sub latexhyphenation {
3414: my $key = shift;
3415: return $latex_language_bykey{$key};
3416: }
3417:
3418: =pod
3419:
1.648 raeburn 3420: =item * ©rightids()
1.112 bowersj2 3421:
3422: returns list of all copyrights
3423:
3424: =cut
3425:
3426: sub copyrightids {
3427: return sort(keys(%cprtag));
3428: }
3429:
3430: =pod
3431:
1.648 raeburn 3432: =item * ©rightdescription()
1.112 bowersj2 3433:
3434: returns description of a specified copyright id
3435:
3436: =cut
3437:
3438: sub copyrightdescription {
1.166 www 3439: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3440: }
1.197 matthew 3441:
3442: =pod
3443:
1.648 raeburn 3444: =item * &source_copyrightids()
1.192 taceyjo1 3445:
3446: returns list of all source copyrights
3447:
3448: =cut
3449:
3450: sub source_copyrightids {
3451: return sort(keys(%scprtag));
3452: }
3453:
3454: =pod
3455:
1.648 raeburn 3456: =item * &source_copyrightdescription()
1.192 taceyjo1 3457:
3458: returns description of a specified source copyright id
3459:
3460: =cut
3461:
3462: sub source_copyrightdescription {
3463: return &mt($scprtag{shift(@_)});
3464: }
1.112 bowersj2 3465:
3466: =pod
3467:
1.648 raeburn 3468: =item * &filecategories()
1.112 bowersj2 3469:
3470: returns list of all file categories
3471:
3472: =cut
3473:
3474: sub filecategories {
3475: return sort(keys(%category_extensions));
3476: }
3477:
3478: =pod
3479:
1.648 raeburn 3480: =item * &filecategorytypes()
1.112 bowersj2 3481:
3482: returns list of file types belonging to a given file
3483: category
3484:
3485: =cut
3486:
3487: sub filecategorytypes {
1.356 albertel 3488: my ($cat) = @_;
3489: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3490: }
3491:
3492: =pod
3493:
1.648 raeburn 3494: =item * &fileembstyle()
1.112 bowersj2 3495:
3496: returns embedding style for a specified file type
3497:
3498: =cut
3499:
3500: sub fileembstyle {
3501: return $fe{lc(shift(@_))};
1.169 www 3502: }
3503:
1.351 www 3504: sub filemimetype {
3505: return $fm{lc(shift(@_))};
3506: }
3507:
1.169 www 3508:
3509: sub filecategoryselect {
3510: my ($name,$value)=@_;
1.189 matthew 3511: return &select_form($value,$name,
1.970 raeburn 3512: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3513: }
3514:
3515: =pod
3516:
1.648 raeburn 3517: =item * &filedescription()
1.112 bowersj2 3518:
3519: returns description for a specified file type
3520:
3521: =cut
3522:
3523: sub filedescription {
1.188 matthew 3524: my $file_description = $fd{lc(shift())};
3525: $file_description =~ s:([\[\]]):~$1:g;
3526: return &mt($file_description);
1.112 bowersj2 3527: }
3528:
3529: =pod
3530:
1.648 raeburn 3531: =item * &filedescriptionex()
1.112 bowersj2 3532:
3533: returns description for a specified file type with
3534: extra formatting
3535:
3536: =cut
3537:
3538: sub filedescriptionex {
3539: my $ex=shift;
1.188 matthew 3540: my $file_description = $fd{lc($ex)};
3541: $file_description =~ s:([\[\]]):~$1:g;
3542: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3543: }
3544:
3545: # End of .tab access
3546: =pod
3547:
3548: =back
3549:
3550: =cut
3551:
3552: # ------------------------------------------------------------------ File Types
3553: sub fileextensions {
3554: return sort(keys(%fe));
3555: }
3556:
1.97 www 3557: # ----------------------------------------------------------- Display Languages
3558: # returns a hash with all desired display languages
3559: #
3560:
3561: sub display_languages {
3562: my %languages=();
1.695 raeburn 3563: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3564: $languages{$lang}=1;
1.97 www 3565: }
3566: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3567: if ($env{'form.displaylanguage'}) {
1.356 albertel 3568: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3569: $languages{$lang}=1;
1.97 www 3570: }
3571: }
3572: return %languages;
1.14 harris41 3573: }
3574:
1.582 albertel 3575: sub languages {
3576: my ($possible_langs) = @_;
1.695 raeburn 3577: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3578: if (!ref($possible_langs)) {
3579: if( wantarray ) {
3580: return @preferred_langs;
3581: } else {
3582: return $preferred_langs[0];
3583: }
3584: }
3585: my %possibilities = map { $_ => 1 } (@$possible_langs);
3586: my @preferred_possibilities;
3587: foreach my $preferred_lang (@preferred_langs) {
3588: if (exists($possibilities{$preferred_lang})) {
3589: push(@preferred_possibilities, $preferred_lang);
3590: }
3591: }
3592: if( wantarray ) {
3593: return @preferred_possibilities;
3594: }
3595: return $preferred_possibilities[0];
3596: }
3597:
1.742 raeburn 3598: sub user_lang {
3599: my ($touname,$toudom,$fromcid) = @_;
3600: my @userlangs;
3601: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3602: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3603: $env{'course.'.$fromcid.'.languages'}));
3604: } else {
3605: my %langhash = &getlangs($touname,$toudom);
3606: if ($langhash{'languages'} ne '') {
3607: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3608: } else {
3609: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3610: if ($domdefs{'lang_def'} ne '') {
3611: @userlangs = ($domdefs{'lang_def'});
3612: }
3613: }
3614: }
3615: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3616: my $user_lh = Apache::localize->get_handle(@languages);
3617: return $user_lh;
3618: }
3619:
3620:
1.112 bowersj2 3621: ###############################################################
3622: ## Student Answer Attempts ##
3623: ###############################################################
3624:
3625: =pod
3626:
3627: =head1 Alternate Problem Views
3628:
3629: =over 4
3630:
1.648 raeburn 3631: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3632: $getattempt, $regexp, $gradesub)
3633:
3634: Return string with previous attempt on problem. Arguments:
3635:
3636: =over 4
3637:
3638: =item * $symb: Problem, including path
3639:
3640: =item * $username: username of the desired student
3641:
3642: =item * $domain: domain of the desired student
1.14 harris41 3643:
1.112 bowersj2 3644: =item * $course: Course ID
1.14 harris41 3645:
1.112 bowersj2 3646: =item * $getattempt: Leave blank for all attempts, otherwise put
3647: something
1.14 harris41 3648:
1.112 bowersj2 3649: =item * $regexp: if string matches this regexp, the string will be
3650: sent to $gradesub
1.14 harris41 3651:
1.112 bowersj2 3652: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3653:
1.112 bowersj2 3654: =back
1.14 harris41 3655:
1.112 bowersj2 3656: The output string is a table containing all desired attempts, if any.
1.16 harris41 3657:
1.112 bowersj2 3658: =cut
1.1 albertel 3659:
3660: sub get_previous_attempt {
1.43 ng 3661: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3662: my $prevattempts='';
1.43 ng 3663: no strict 'refs';
1.1 albertel 3664: if ($symb) {
1.3 albertel 3665: my (%returnhash)=
3666: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3667: if ($returnhash{'version'}) {
3668: my %lasthash=();
3669: my $version;
3670: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3671: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3672: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3673: }
1.1 albertel 3674: }
1.596 albertel 3675: $prevattempts=&start_data_table().&start_data_table_header_row();
3676: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3677: my (%typeparts,%lasthidden);
1.945 raeburn 3678: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3679: foreach my $key (sort(keys(%lasthash))) {
3680: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3681: if ($#parts > 0) {
1.31 albertel 3682: my $data=$parts[-1];
1.989 raeburn 3683: next if ($data eq 'foilorder');
1.31 albertel 3684: pop(@parts);
1.1010 www 3685: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3686: if ($data eq 'type') {
3687: unless ($showsurv) {
3688: my $id = join(',',@parts);
3689: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3690: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3691: $lasthidden{$ign.'.'.$id} = 1;
3692: }
1.945 raeburn 3693: }
1.1010 www 3694: }
1.31 albertel 3695: } else {
1.41 ng 3696: if ($#parts == 0) {
3697: $prevattempts.='<th>'.$parts[0].'</th>';
3698: } else {
3699: $prevattempts.='<th>'.$ign.'</th>';
3700: }
1.31 albertel 3701: }
1.16 harris41 3702: }
1.596 albertel 3703: $prevattempts.=&end_data_table_header_row();
1.40 ng 3704: if ($getattempt eq '') {
3705: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3706: my @hidden;
3707: if (%typeparts) {
3708: foreach my $id (keys(%typeparts)) {
3709: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3710: push(@hidden,$id);
3711: }
3712: }
3713: }
3714: $prevattempts.=&start_data_table_row().
3715: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3716: if (@hidden) {
3717: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3718: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3719: my $hide;
3720: foreach my $id (@hidden) {
3721: if ($key =~ /^\Q$id\E/) {
3722: $hide = 1;
3723: last;
3724: }
3725: }
3726: if ($hide) {
3727: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3728: if (($data eq 'award') || ($data eq 'awarddetail')) {
3729: my $value = &format_previous_attempt_value($key,
3730: $returnhash{$version.':'.$key});
3731: $prevattempts.='<td>'.$value.' </td>';
3732: } else {
3733: $prevattempts.='<td> </td>';
3734: }
3735: } else {
3736: if ($key =~ /\./) {
3737: my $value = &format_previous_attempt_value($key,
3738: $returnhash{$version.':'.$key});
3739: $prevattempts.='<td>'.$value.' </td>';
3740: } else {
3741: $prevattempts.='<td> </td>';
3742: }
3743: }
3744: }
3745: } else {
3746: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3747: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3748: my $value = &format_previous_attempt_value($key,
3749: $returnhash{$version.':'.$key});
3750: $prevattempts.='<td>'.$value.' </td>';
3751: }
3752: }
3753: $prevattempts.=&end_data_table_row();
1.40 ng 3754: }
1.1 albertel 3755: }
1.945 raeburn 3756: my @currhidden = keys(%lasthidden);
1.596 albertel 3757: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3758: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3759: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3760: if (%typeparts) {
3761: my $hidden;
3762: foreach my $id (@currhidden) {
3763: if ($key =~ /^\Q$id\E/) {
3764: $hidden = 1;
3765: last;
3766: }
3767: }
3768: if ($hidden) {
3769: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3770: if (($data eq 'award') || ($data eq 'awarddetail')) {
3771: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3772: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3773: $value = &$gradesub($value);
3774: }
3775: $prevattempts.='<td>'.$value.' </td>';
3776: } else {
3777: $prevattempts.='<td> </td>';
3778: }
3779: } else {
3780: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3781: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3782: $value = &$gradesub($value);
3783: }
3784: $prevattempts.='<td>'.$value.' </td>';
3785: }
3786: } else {
3787: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3788: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3789: $value = &$gradesub($value);
3790: }
3791: $prevattempts.='<td>'.$value.' </td>';
3792: }
1.16 harris41 3793: }
1.596 albertel 3794: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3795: } else {
1.596 albertel 3796: $prevattempts=
3797: &start_data_table().&start_data_table_row().
3798: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3799: &end_data_table_row().&end_data_table();
1.1 albertel 3800: }
3801: } else {
1.596 albertel 3802: $prevattempts=
3803: &start_data_table().&start_data_table_row().
3804: '<td>'.&mt('No data.').'</td>'.
3805: &end_data_table_row().&end_data_table();
1.1 albertel 3806: }
1.10 albertel 3807: }
3808:
1.581 albertel 3809: sub format_previous_attempt_value {
3810: my ($key,$value) = @_;
1.1011 www 3811: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3812: $value = &Apache::lonlocal::locallocaltime($value);
3813: } elsif (ref($value) eq 'ARRAY') {
3814: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3815: } elsif ($key =~ /answerstring$/) {
3816: my %answers = &Apache::lonnet::str2hash($value);
3817: my @anskeys = sort(keys(%answers));
3818: if (@anskeys == 1) {
3819: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3820: if ($answer =~ m{\0}) {
3821: $answer =~ s{\0}{,}g;
1.988 raeburn 3822: }
3823: my $tag_internal_answer_name = 'INTERNAL';
3824: if ($anskeys[0] eq $tag_internal_answer_name) {
3825: $value = $answer;
3826: } else {
3827: $value = $anskeys[0].'='.$answer;
3828: }
3829: } else {
3830: foreach my $ans (@anskeys) {
3831: my $answer = $answers{$ans};
1.1001 raeburn 3832: if ($answer =~ m{\0}) {
3833: $answer =~ s{\0}{,}g;
1.988 raeburn 3834: }
3835: $value .= $ans.'='.$answer.'<br />';;
3836: }
3837: }
1.581 albertel 3838: } else {
3839: $value = &unescape($value);
3840: }
3841: return $value;
3842: }
3843:
3844:
1.107 albertel 3845: sub relative_to_absolute {
3846: my ($url,$output)=@_;
3847: my $parser=HTML::TokeParser->new(\$output);
3848: my $token;
3849: my $thisdir=$url;
3850: my @rlinks=();
3851: while ($token=$parser->get_token) {
3852: if ($token->[0] eq 'S') {
3853: if ($token->[1] eq 'a') {
3854: if ($token->[2]->{'href'}) {
3855: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3856: }
3857: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3858: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3859: } elsif ($token->[1] eq 'base') {
3860: $thisdir=$token->[2]->{'href'};
3861: }
3862: }
3863: }
3864: $thisdir=~s-/[^/]*$--;
1.356 albertel 3865: foreach my $link (@rlinks) {
1.726 raeburn 3866: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3867: ($link=~/^\//) ||
3868: ($link=~/^javascript:/i) ||
3869: ($link=~/^mailto:/i) ||
3870: ($link=~/^\#/)) {
3871: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3872: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3873: }
3874: }
3875: # -------------------------------------------------- Deal with Applet codebases
3876: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3877: return $output;
3878: }
3879:
1.112 bowersj2 3880: =pod
3881:
1.648 raeburn 3882: =item * &get_student_view()
1.112 bowersj2 3883:
3884: show a snapshot of what student was looking at
3885:
3886: =cut
3887:
1.10 albertel 3888: sub get_student_view {
1.186 albertel 3889: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3890: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3891: my (%form);
1.10 albertel 3892: my @elements=('symb','courseid','domain','username');
3893: foreach my $element (@elements) {
1.186 albertel 3894: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3895: }
1.186 albertel 3896: if (defined($moreenv)) {
3897: %form=(%form,%{$moreenv});
3898: }
1.236 albertel 3899: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3900: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3901: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3902: $userview=~s/\<body[^\>]*\>//gi;
3903: $userview=~s/\<\/body\>//gi;
3904: $userview=~s/\<html\>//gi;
3905: $userview=~s/\<\/html\>//gi;
3906: $userview=~s/\<head\>//gi;
3907: $userview=~s/\<\/head\>//gi;
3908: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3909: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3910: if (wantarray) {
3911: return ($userview,$response);
3912: } else {
3913: return $userview;
3914: }
3915: }
3916:
3917: sub get_student_view_with_retries {
3918: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3919:
3920: my $ok = 0; # True if we got a good response.
3921: my $content;
3922: my $response;
3923:
3924: # Try to get the student_view done. within the retries count:
3925:
3926: do {
3927: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3928: $ok = $response->is_success;
3929: if (!$ok) {
3930: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3931: }
3932: $retries--;
3933: } while (!$ok && ($retries > 0));
3934:
3935: if (!$ok) {
3936: $content = ''; # On error return an empty content.
3937: }
1.651 www 3938: if (wantarray) {
3939: return ($content, $response);
3940: } else {
3941: return $content;
3942: }
1.11 albertel 3943: }
3944:
1.112 bowersj2 3945: =pod
3946:
1.648 raeburn 3947: =item * &get_student_answers()
1.112 bowersj2 3948:
3949: show a snapshot of how student was answering problem
3950:
3951: =cut
3952:
1.11 albertel 3953: sub get_student_answers {
1.100 sakharuk 3954: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3955: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3956: my (%moreenv);
1.11 albertel 3957: my @elements=('symb','courseid','domain','username');
3958: foreach my $element (@elements) {
1.186 albertel 3959: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3960: }
1.186 albertel 3961: $moreenv{'grade_target'}='answer';
3962: %moreenv=(%form,%moreenv);
1.497 raeburn 3963: $feedurl = &Apache::lonnet::clutter($feedurl);
3964: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3965: return $userview;
1.1 albertel 3966: }
1.116 albertel 3967:
3968: =pod
3969:
3970: =item * &submlink()
3971:
1.242 albertel 3972: Inputs: $text $uname $udom $symb $target
1.116 albertel 3973:
3974: Returns: A link to grades.pm such as to see the SUBM view of a student
3975:
3976: =cut
3977:
3978: ###############################################
3979: sub submlink {
1.242 albertel 3980: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3981: if (!($uname && $udom)) {
3982: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3983: &Apache::lonnet::whichuser($symb);
1.116 albertel 3984: if (!$symb) { $symb=$cursymb; }
3985: }
1.254 matthew 3986: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3987: $symb=&escape($symb);
1.960 bisitz 3988: if ($target) { $target=" target=\"$target\""; }
3989: return
3990: '<a href="/adm/grades?command=submission'.
3991: '&symb='.$symb.
3992: '&student='.$uname.
3993: '&userdom='.$udom.'"'.
3994: $target.'>'.$text.'</a>';
1.242 albertel 3995: }
3996: ##############################################
3997:
3998: =pod
3999:
4000: =item * &pgrdlink()
4001:
4002: Inputs: $text $uname $udom $symb $target
4003:
4004: Returns: A link to grades.pm such as to see the PGRD view of a student
4005:
4006: =cut
4007:
4008: ###############################################
4009: sub pgrdlink {
4010: my $link=&submlink(@_);
4011: $link=~s/(&command=submission)/$1&showgrading=yes/;
4012: return $link;
4013: }
4014: ##############################################
4015:
4016: =pod
4017:
4018: =item * &pprmlink()
4019:
4020: Inputs: $text $uname $udom $symb $target
4021:
4022: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4023: student and a specific resource
1.242 albertel 4024:
4025: =cut
4026:
4027: ###############################################
4028: sub pprmlink {
4029: my ($text,$uname,$udom,$symb,$target)=@_;
4030: if (!($uname && $udom)) {
4031: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4032: &Apache::lonnet::whichuser($symb);
1.242 albertel 4033: if (!$symb) { $symb=$cursymb; }
4034: }
1.254 matthew 4035: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4036: $symb=&escape($symb);
1.242 albertel 4037: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4038: return '<a href="/adm/parmset?command=set&'.
4039: 'symb='.$symb.'&uname='.$uname.
4040: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4041: }
4042: ##############################################
1.37 matthew 4043:
1.112 bowersj2 4044: =pod
4045:
4046: =back
4047:
4048: =cut
4049:
1.37 matthew 4050: ###############################################
1.51 www 4051:
4052:
4053: sub timehash {
1.687 raeburn 4054: my ($thistime) = @_;
4055: my $timezone = &Apache::lonlocal::gettimezone();
4056: my $dt = DateTime->from_epoch(epoch => $thistime)
4057: ->set_time_zone($timezone);
4058: my $wday = $dt->day_of_week();
4059: if ($wday == 7) { $wday = 0; }
4060: return ( 'second' => $dt->second(),
4061: 'minute' => $dt->minute(),
4062: 'hour' => $dt->hour(),
4063: 'day' => $dt->day_of_month(),
4064: 'month' => $dt->month(),
4065: 'year' => $dt->year(),
4066: 'weekday' => $wday,
4067: 'dayyear' => $dt->day_of_year(),
4068: 'dlsav' => $dt->is_dst() );
1.51 www 4069: }
4070:
1.370 www 4071: sub utc_string {
4072: my ($date)=@_;
1.371 www 4073: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4074: }
4075:
1.51 www 4076: sub maketime {
4077: my %th=@_;
1.687 raeburn 4078: my ($epoch_time,$timezone,$dt);
4079: $timezone = &Apache::lonlocal::gettimezone();
4080: eval {
4081: $dt = DateTime->new( year => $th{'year'},
4082: month => $th{'month'},
4083: day => $th{'day'},
4084: hour => $th{'hour'},
4085: minute => $th{'minute'},
4086: second => $th{'second'},
4087: time_zone => $timezone,
4088: );
4089: };
4090: if (!$@) {
4091: $epoch_time = $dt->epoch;
4092: if ($epoch_time) {
4093: return $epoch_time;
4094: }
4095: }
1.51 www 4096: return POSIX::mktime(
4097: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4098: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4099: }
4100:
4101: #########################################
1.51 www 4102:
4103: sub findallcourses {
1.482 raeburn 4104: my ($roles,$uname,$udom) = @_;
1.355 albertel 4105: my %roles;
4106: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4107: my %courses;
1.51 www 4108: my $now=time;
1.482 raeburn 4109: if (!defined($uname)) {
4110: $uname = $env{'user.name'};
4111: }
4112: if (!defined($udom)) {
4113: $udom = $env{'user.domain'};
4114: }
4115: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4116: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4117: if (!%roles) {
4118: %roles = (
4119: cc => 1,
1.907 raeburn 4120: co => 1,
1.482 raeburn 4121: in => 1,
4122: ep => 1,
4123: ta => 1,
4124: cr => 1,
4125: st => 1,
4126: );
4127: }
4128: foreach my $entry (keys(%roleshash)) {
4129: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4130: if ($trole =~ /^cr/) {
4131: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4132: } else {
4133: next if (!exists($roles{$trole}));
4134: }
4135: if ($tend) {
4136: next if ($tend < $now);
4137: }
4138: if ($tstart) {
4139: next if ($tstart > $now);
4140: }
1.1058 raeburn 4141: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4142: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4143: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4144: if ($secpart eq '') {
4145: ($cnum,$role) = split(/_/,$cnumpart);
4146: $sec = 'none';
1.1058 raeburn 4147: $value .= $cnum.'/';
1.482 raeburn 4148: } else {
4149: $cnum = $cnumpart;
4150: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4151: $value .= $cnum.'/'.$sec;
4152: }
4153: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4154: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4155: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4156: }
4157: } else {
4158: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4159: }
1.482 raeburn 4160: }
4161: } else {
4162: foreach my $key (keys(%env)) {
1.483 albertel 4163: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4164: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4165: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4166: next if ($role eq 'ca' || $role eq 'aa');
4167: next if (%roles && !exists($roles{$role}));
4168: my ($starttime,$endtime)=split(/\./,$env{$key});
4169: my $active=1;
4170: if ($starttime) {
4171: if ($now<$starttime) { $active=0; }
4172: }
4173: if ($endtime) {
4174: if ($now>$endtime) { $active=0; }
4175: }
4176: if ($active) {
1.1058 raeburn 4177: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4178: if ($sec eq '') {
4179: $sec = 'none';
1.1058 raeburn 4180: } else {
4181: $value .= $sec;
4182: }
4183: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4184: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4185: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4186: }
4187: } else {
4188: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4189: }
1.474 raeburn 4190: }
4191: }
1.51 www 4192: }
4193: }
1.474 raeburn 4194: return %courses;
1.51 www 4195: }
1.37 matthew 4196:
1.54 www 4197: ###############################################
1.474 raeburn 4198:
4199: sub blockcheck {
1.1062 raeburn 4200: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4201:
4202: if (!defined($udom)) {
4203: $udom = $env{'user.domain'};
4204: }
4205: if (!defined($uname)) {
4206: $uname = $env{'user.name'};
4207: }
4208:
4209: # If uname and udom are for a course, check for blocks in the course.
4210:
4211: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4212: my ($startblock,$endblock,$triggerblock) =
4213: &get_blocks($setters,$activity,$udom,$uname,$url);
4214: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4215: }
1.474 raeburn 4216:
1.502 raeburn 4217: my $startblock = 0;
4218: my $endblock = 0;
1.1062 raeburn 4219: my $triggerblock = '';
1.482 raeburn 4220: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4221:
1.490 raeburn 4222: # If uname is for a user, and activity is course-specific, i.e.,
4223: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4224:
1.490 raeburn 4225: if (($activity eq 'boards' || $activity eq 'chat' ||
4226: $activity eq 'groups') && ($env{'request.course.id'})) {
4227: foreach my $key (keys(%live_courses)) {
4228: if ($key ne $env{'request.course.id'}) {
4229: delete($live_courses{$key});
4230: }
4231: }
4232: }
4233:
4234: my $otheruser = 0;
4235: my %own_courses;
4236: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4237: # Resource belongs to user other than current user.
4238: $otheruser = 1;
4239: # Gather courses for current user
4240: %own_courses =
4241: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4242: }
4243:
4244: # Gather active course roles - course coordinator, instructor,
4245: # exam proctor, ta, student, or custom role.
1.474 raeburn 4246:
4247: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4248: my ($cdom,$cnum);
4249: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4250: $cdom = $env{'course.'.$course.'.domain'};
4251: $cnum = $env{'course.'.$course.'.num'};
4252: } else {
1.490 raeburn 4253: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4254: }
4255: my $no_ownblock = 0;
4256: my $no_userblock = 0;
1.533 raeburn 4257: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4258: # Check if current user has 'evb' priv for this
4259: if (defined($own_courses{$course})) {
4260: foreach my $sec (keys(%{$own_courses{$course}})) {
4261: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4262: if ($sec ne 'none') {
4263: $checkrole .= '/'.$sec;
4264: }
4265: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4266: $no_ownblock = 1;
4267: last;
4268: }
4269: }
4270: }
4271: # if they have 'evb' priv and are currently not playing student
4272: next if (($no_ownblock) &&
4273: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4274: }
1.474 raeburn 4275: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4276: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4277: if ($sec ne 'none') {
1.482 raeburn 4278: $checkrole .= '/'.$sec;
1.474 raeburn 4279: }
1.490 raeburn 4280: if ($otheruser) {
4281: # Resource belongs to user other than current user.
4282: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4283: my (%allroles,%userroles);
4284: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4285: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4286: my ($trole,$tdom,$tnum,$tsec);
4287: if ($entry =~ /^cr/) {
4288: ($trole,$tdom,$tnum,$tsec) =
4289: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4290: } else {
4291: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4292: }
4293: my ($spec,$area,$trest);
4294: $area = '/'.$tdom.'/'.$tnum;
4295: $trest = $tnum;
4296: if ($tsec ne '') {
4297: $area .= '/'.$tsec;
4298: $trest .= '/'.$tsec;
4299: }
4300: $spec = $trole.'.'.$area;
4301: if ($trole =~ /^cr/) {
4302: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4303: $tdom,$spec,$trest,$area);
4304: } else {
4305: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4306: $tdom,$spec,$trest,$area);
4307: }
4308: }
4309: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4310: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4311: if ($1) {
4312: $no_userblock = 1;
4313: last;
4314: }
1.486 raeburn 4315: }
4316: }
1.490 raeburn 4317: } else {
4318: # Resource belongs to current user
4319: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4320: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4321: $no_ownblock = 1;
4322: last;
4323: }
1.474 raeburn 4324: }
4325: }
4326: # if they have the evb priv and are currently not playing student
1.482 raeburn 4327: next if (($no_ownblock) &&
1.491 albertel 4328: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4329: next if ($no_userblock);
1.474 raeburn 4330:
1.866 kalberla 4331: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4332: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4333:
1.1062 raeburn 4334: my ($start,$end,$trigger) =
4335: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4336: if (($start != 0) &&
4337: (($startblock == 0) || ($startblock > $start))) {
4338: $startblock = $start;
1.1062 raeburn 4339: if ($trigger ne '') {
4340: $triggerblock = $trigger;
4341: }
1.502 raeburn 4342: }
4343: if (($end != 0) &&
4344: (($endblock == 0) || ($endblock < $end))) {
4345: $endblock = $end;
1.1062 raeburn 4346: if ($trigger ne '') {
4347: $triggerblock = $trigger;
4348: }
1.502 raeburn 4349: }
1.490 raeburn 4350: }
1.1062 raeburn 4351: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4352: }
4353:
4354: sub get_blocks {
1.1062 raeburn 4355: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4356: my $startblock = 0;
4357: my $endblock = 0;
1.1062 raeburn 4358: my $triggerblock = '';
1.490 raeburn 4359: my $course = $cdom.'_'.$cnum;
4360: $setters->{$course} = {};
4361: $setters->{$course}{'staff'} = [];
4362: $setters->{$course}{'times'} = [];
1.1062 raeburn 4363: $setters->{$course}{'triggers'} = [];
4364: my (@blockers,%triggered);
4365: my $now = time;
4366: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4367: if ($activity eq 'docs') {
4368: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4369: foreach my $block (@blockers) {
4370: if ($block =~ /^firstaccess____(.+)$/) {
4371: my $item = $1;
4372: my $type = 'map';
4373: my $timersymb = $item;
4374: if ($item eq 'course') {
4375: $type = 'course';
4376: } elsif ($item =~ /___\d+___/) {
4377: $type = 'resource';
4378: } else {
4379: $timersymb = &Apache::lonnet::symbread($item);
4380: }
4381: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4382: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4383: $triggered{$block} = {
4384: start => $start,
4385: end => $end,
4386: type => $type,
4387: };
4388: }
4389: }
4390: } else {
4391: foreach my $block (keys(%commblocks)) {
4392: if ($block =~ m/^(\d+)____(\d+)$/) {
4393: my ($start,$end) = ($1,$2);
4394: if ($start <= time && $end >= time) {
4395: if (ref($commblocks{$block}) eq 'HASH') {
4396: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4397: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4398: unless(grep(/^\Q$block\E$/,@blockers)) {
4399: push(@blockers,$block);
4400: }
4401: }
4402: }
4403: }
4404: }
4405: } elsif ($block =~ /^firstaccess____(.+)$/) {
4406: my $item = $1;
4407: my $timersymb = $item;
4408: my $type = 'map';
4409: if ($item eq 'course') {
4410: $type = 'course';
4411: } elsif ($item =~ /___\d+___/) {
4412: $type = 'resource';
4413: } else {
4414: $timersymb = &Apache::lonnet::symbread($item);
4415: }
4416: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4417: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4418: if ($start && $end) {
4419: if (($start <= time) && ($end >= time)) {
4420: unless (grep(/^\Q$block\E$/,@blockers)) {
4421: push(@blockers,$block);
4422: $triggered{$block} = {
4423: start => $start,
4424: end => $end,
4425: type => $type,
4426: };
4427: }
4428: }
1.490 raeburn 4429: }
1.1062 raeburn 4430: }
4431: }
4432: }
4433: foreach my $blocker (@blockers) {
4434: my ($staff_name,$staff_dom,$title,$blocks) =
4435: &parse_block_record($commblocks{$blocker});
4436: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4437: my ($start,$end,$triggertype);
4438: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4439: ($start,$end) = ($1,$2);
4440: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4441: $start = $triggered{$blocker}{'start'};
4442: $end = $triggered{$blocker}{'end'};
4443: $triggertype = $triggered{$blocker}{'type'};
4444: }
4445: if ($start) {
4446: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4447: if ($triggertype) {
4448: push(@{$$setters{$course}{'triggers'}},$triggertype);
4449: } else {
4450: push(@{$$setters{$course}{'triggers'}},0);
4451: }
4452: if ( ($startblock == 0) || ($startblock > $start) ) {
4453: $startblock = $start;
4454: if ($triggertype) {
4455: $triggerblock = $blocker;
1.474 raeburn 4456: }
4457: }
1.1062 raeburn 4458: if ( ($endblock == 0) || ($endblock < $end) ) {
4459: $endblock = $end;
4460: if ($triggertype) {
4461: $triggerblock = $blocker;
4462: }
4463: }
1.474 raeburn 4464: }
4465: }
1.1062 raeburn 4466: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4467: }
4468:
4469: sub parse_block_record {
4470: my ($record) = @_;
4471: my ($setuname,$setudom,$title,$blocks);
4472: if (ref($record) eq 'HASH') {
4473: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4474: $title = &unescape($record->{'event'});
4475: $blocks = $record->{'blocks'};
4476: } else {
4477: my @data = split(/:/,$record,3);
4478: if (scalar(@data) eq 2) {
4479: $title = $data[1];
4480: ($setuname,$setudom) = split(/@/,$data[0]);
4481: } else {
4482: ($setuname,$setudom,$title) = @data;
4483: }
4484: $blocks = { 'com' => 'on' };
4485: }
4486: return ($setuname,$setudom,$title,$blocks);
4487: }
4488:
1.854 kalberla 4489: sub blocking_status {
1.1062 raeburn 4490: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4491: my %setters;
1.890 droeschl 4492:
1.1061 raeburn 4493: # check for active blocking
1.1062 raeburn 4494: my ($startblock,$endblock,$triggerblock) =
4495: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4496: my $blocked = 0;
4497: if ($startblock && $endblock) {
4498: $blocked = 1;
4499: }
1.890 droeschl 4500:
1.1061 raeburn 4501: # caller just wants to know whether a block is active
4502: if (!wantarray) { return $blocked; }
4503:
4504: # build a link to a popup window containing the details
4505: my $querystring = "?activity=$activity";
4506: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4507: if ($activity eq 'port') {
4508: $querystring .= "&udom=$udom" if $udom;
4509: $querystring .= "&uname=$uname" if $uname;
4510: } elsif ($activity eq 'docs') {
4511: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4512: }
1.1061 raeburn 4513:
4514: my $output .= <<'END_MYBLOCK';
4515: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4516: var options = "width=" + w + ",height=" + h + ",";
4517: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4518: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4519: var newWin = window.open(url, wdwName, options);
4520: newWin.focus();
4521: }
1.890 droeschl 4522: END_MYBLOCK
1.854 kalberla 4523:
1.1061 raeburn 4524: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4525:
1.1061 raeburn 4526: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4527: my $text = &mt('Communication Blocked');
4528: if ($activity eq 'docs') {
4529: $text = &mt('Content Access Blocked');
1.1063 raeburn 4530: } elsif ($activity eq 'printout') {
4531: $text = &mt('Printing Blocked');
1.1062 raeburn 4532: }
1.1061 raeburn 4533: $output .= <<"END_BLOCK";
1.867 kalberla 4534: <div class='LC_comblock'>
1.869 kalberla 4535: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4536: title='$text'>
4537: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4538: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4539: title='$text'>$text</a>
1.867 kalberla 4540: </div>
4541:
4542: END_BLOCK
1.474 raeburn 4543:
1.1061 raeburn 4544: return ($blocked, $output);
1.854 kalberla 4545: }
1.490 raeburn 4546:
1.60 matthew 4547: ###############################################
4548:
1.682 raeburn 4549: sub check_ip_acc {
4550: my ($acc)=@_;
4551: &Apache::lonxml::debug("acc is $acc");
4552: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4553: return 1;
4554: }
4555: my $allowed=0;
4556: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4557:
4558: my $name;
4559: foreach my $pattern (split(',',$acc)) {
4560: $pattern =~ s/^\s*//;
4561: $pattern =~ s/\s*$//;
4562: if ($pattern =~ /\*$/) {
4563: #35.8.*
4564: $pattern=~s/\*//;
4565: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4566: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4567: #35.8.3.[34-56]
4568: my $low=$2;
4569: my $high=$3;
4570: $pattern=$1;
4571: if ($ip =~ /^\Q$pattern\E/) {
4572: my $last=(split(/\./,$ip))[3];
4573: if ($last <=$high && $last >=$low) { $allowed=1; }
4574: }
4575: } elsif ($pattern =~ /^\*/) {
4576: #*.msu.edu
4577: $pattern=~s/\*//;
4578: if (!defined($name)) {
4579: use Socket;
4580: my $netaddr=inet_aton($ip);
4581: ($name)=gethostbyaddr($netaddr,AF_INET);
4582: }
4583: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4584: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4585: #127.0.0.1
4586: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4587: } else {
4588: #some.name.com
4589: if (!defined($name)) {
4590: use Socket;
4591: my $netaddr=inet_aton($ip);
4592: ($name)=gethostbyaddr($netaddr,AF_INET);
4593: }
4594: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4595: }
4596: if ($allowed) { last; }
4597: }
4598: return $allowed;
4599: }
4600:
4601: ###############################################
4602:
1.60 matthew 4603: =pod
4604:
1.112 bowersj2 4605: =head1 Domain Template Functions
4606:
4607: =over 4
4608:
4609: =item * &determinedomain()
1.60 matthew 4610:
4611: Inputs: $domain (usually will be undef)
4612:
1.63 www 4613: Returns: Determines which domain should be used for designs
1.60 matthew 4614:
4615: =cut
1.54 www 4616:
1.60 matthew 4617: ###############################################
1.63 www 4618: sub determinedomain {
4619: my $domain=shift;
1.531 albertel 4620: if (! $domain) {
1.60 matthew 4621: # Determine domain if we have not been given one
1.893 raeburn 4622: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4623: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4624: if ($env{'request.role.domain'}) {
4625: $domain=$env{'request.role.domain'};
1.60 matthew 4626: }
4627: }
1.63 www 4628: return $domain;
4629: }
4630: ###############################################
1.517 raeburn 4631:
1.518 albertel 4632: sub devalidate_domconfig_cache {
4633: my ($udom)=@_;
4634: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4635: }
4636:
4637: # ---------------------- Get domain configuration for a domain
4638: sub get_domainconf {
4639: my ($udom) = @_;
4640: my $cachetime=1800;
4641: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4642: if (defined($cached)) { return %{$result}; }
4643:
4644: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4645: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4646: my (%designhash,%legacy);
1.518 albertel 4647: if (keys(%domconfig) > 0) {
4648: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4649: if (keys(%{$domconfig{'login'}})) {
4650: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4651: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4652: if ($key eq 'loginvia') {
4653: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4654: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4655: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4656: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4657: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4658: $designhash{$udom.'.login.loginvia'} = $server;
4659: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4660:
4661: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4662: } else {
1.1013 raeburn 4663: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4664: }
4665: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4666: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4667: }
1.946 raeburn 4668: }
4669: }
4670: }
4671: }
4672: } else {
4673: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4674: $designhash{$udom.'.login.'.$key.'_'.$img} =
4675: $domconfig{'login'}{$key}{$img};
4676: }
1.699 raeburn 4677: }
4678: } else {
4679: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4680: }
1.632 raeburn 4681: }
4682: } else {
4683: $legacy{'login'} = 1;
1.518 albertel 4684: }
1.632 raeburn 4685: } else {
4686: $legacy{'login'} = 1;
1.518 albertel 4687: }
4688: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4689: if (keys(%{$domconfig{'rolecolors'}})) {
4690: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4691: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4692: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4693: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4694: }
1.518 albertel 4695: }
4696: }
1.632 raeburn 4697: } else {
4698: $legacy{'rolecolors'} = 1;
1.518 albertel 4699: }
1.632 raeburn 4700: } else {
4701: $legacy{'rolecolors'} = 1;
1.518 albertel 4702: }
1.948 raeburn 4703: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4704: if ($domconfig{'autoenroll'}{'co-owners'}) {
4705: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4706: }
4707: }
1.632 raeburn 4708: if (keys(%legacy) > 0) {
4709: my %legacyhash = &get_legacy_domconf($udom);
4710: foreach my $item (keys(%legacyhash)) {
4711: if ($item =~ /^\Q$udom\E\.login/) {
4712: if ($legacy{'login'}) {
4713: $designhash{$item} = $legacyhash{$item};
4714: }
4715: } else {
4716: if ($legacy{'rolecolors'}) {
4717: $designhash{$item} = $legacyhash{$item};
4718: }
1.518 albertel 4719: }
4720: }
4721: }
1.632 raeburn 4722: } else {
4723: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4724: }
4725: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4726: $cachetime);
4727: return %designhash;
4728: }
4729:
1.632 raeburn 4730: sub get_legacy_domconf {
4731: my ($udom) = @_;
4732: my %legacyhash;
4733: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4734: my $designfile = $designdir.'/'.$udom.'.tab';
4735: if (-e $designfile) {
4736: if ( open (my $fh,"<$designfile") ) {
4737: while (my $line = <$fh>) {
4738: next if ($line =~ /^\#/);
4739: chomp($line);
4740: my ($key,$val)=(split(/\=/,$line));
4741: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4742: }
4743: close($fh);
4744: }
4745: }
1.1026 raeburn 4746: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4747: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4748: }
4749: return %legacyhash;
4750: }
4751:
1.63 www 4752: =pod
4753:
1.112 bowersj2 4754: =item * &domainlogo()
1.63 www 4755:
4756: Inputs: $domain (usually will be undef)
4757:
4758: Returns: A link to a domain logo, if the domain logo exists.
4759: If the domain logo does not exist, a description of the domain.
4760:
4761: =cut
1.112 bowersj2 4762:
1.63 www 4763: ###############################################
4764: sub domainlogo {
1.517 raeburn 4765: my $domain = &determinedomain(shift);
1.518 albertel 4766: my %designhash = &get_domainconf($domain);
1.517 raeburn 4767: # See if there is a logo
4768: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4769: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4770: if ($imgsrc =~ m{^/(adm|res)/}) {
4771: if ($imgsrc =~ m{^/res/}) {
4772: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4773: &Apache::lonnet::repcopy($local_name);
4774: }
4775: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4776: }
4777: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4778: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4779: return &Apache::lonnet::domain($domain,'description');
1.59 www 4780: } else {
1.60 matthew 4781: return '';
1.59 www 4782: }
4783: }
1.63 www 4784: ##############################################
4785:
4786: =pod
4787:
1.112 bowersj2 4788: =item * &designparm()
1.63 www 4789:
4790: Inputs: $which parameter; $domain (usually will be undef)
4791:
4792: Returns: value of designparamter $which
4793:
4794: =cut
1.112 bowersj2 4795:
1.397 albertel 4796:
1.400 albertel 4797: ##############################################
1.397 albertel 4798: sub designparm {
4799: my ($which,$domain)=@_;
4800: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4801: return $env{'environment.color.'.$which};
1.96 www 4802: }
1.63 www 4803: $domain=&determinedomain($domain);
1.1016 raeburn 4804: my %domdesign;
4805: unless ($domain eq 'public') {
4806: %domdesign = &get_domainconf($domain);
4807: }
1.520 raeburn 4808: my $output;
1.517 raeburn 4809: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4810: $output = $domdesign{$domain.'.'.$which};
1.63 www 4811: } else {
1.520 raeburn 4812: $output = $defaultdesign{$which};
4813: }
4814: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4815: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4816: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4817: if ($output =~ m{^/res/}) {
4818: my $local_name = &Apache::lonnet::filelocation('',$output);
4819: &Apache::lonnet::repcopy($local_name);
4820: }
1.520 raeburn 4821: $output = &lonhttpdurl($output);
4822: }
1.63 www 4823: }
1.520 raeburn 4824: return $output;
1.63 www 4825: }
1.59 www 4826:
1.822 bisitz 4827: ##############################################
4828: =pod
4829:
1.832 bisitz 4830: =item * &authorspace()
4831:
1.1028 raeburn 4832: Inputs: $url (usually will be undef).
1.832 bisitz 4833:
1.1028 raeburn 4834: Returns: Path to Construction Space containing the resource or
4835: directory being viewed (or for which action is being taken).
4836: If $url is provided, and begins /priv/<domain>/<uname>
4837: the path will be that portion of the $context argument.
4838: Otherwise the path will be for the author space of the current
4839: user when the current role is author, or for that of the
4840: co-author/assistant co-author space when the current role
4841: is co-author or assistant co-author.
1.832 bisitz 4842:
4843: =cut
4844:
4845: sub authorspace {
1.1028 raeburn 4846: my ($url) = @_;
4847: if ($url ne '') {
4848: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4849: return $1;
4850: }
4851: }
1.832 bisitz 4852: my $caname = '';
1.1024 www 4853: my $cadom = '';
1.1028 raeburn 4854: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4855: ($cadom,$caname) =
1.832 bisitz 4856: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4857: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4858: $caname = $env{'user.name'};
1.1024 www 4859: $cadom = $env{'user.domain'};
1.832 bisitz 4860: }
1.1028 raeburn 4861: if (($caname ne '') && ($cadom ne '')) {
4862: return "/priv/$cadom/$caname/";
4863: }
4864: return;
1.832 bisitz 4865: }
4866:
4867: ##############################################
4868: =pod
4869:
1.822 bisitz 4870: =item * &head_subbox()
4871:
4872: Inputs: $content (contains HTML code with page functions, etc.)
4873:
4874: Returns: HTML div with $content
4875: To be included in page header
4876:
4877: =cut
4878:
4879: sub head_subbox {
4880: my ($content)=@_;
4881: my $output =
1.993 raeburn 4882: '<div class="LC_head_subbox">'
1.822 bisitz 4883: .$content
4884: .'</div>'
4885: }
4886:
4887: ##############################################
4888: =pod
4889:
4890: =item * &CSTR_pageheader()
4891:
1.1026 raeburn 4892: Input: (optional) filename from which breadcrumb trail is built.
4893: In most cases no input as needed, as $env{'request.filename'}
4894: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4895:
4896: Returns: HTML div with CSTR path and recent box
4897: To be included on Construction Space pages
4898:
4899: =cut
4900:
4901: sub CSTR_pageheader {
1.1026 raeburn 4902: my ($trailfile) = @_;
4903: if ($trailfile eq '') {
4904: $trailfile = $env{'request.filename'};
4905: }
4906:
4907: # this is for resources; directories have customtitle, and crumbs
4908: # and select recent are created in lonpubdir.pm
4909:
4910: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4911: my ($udom,$uname,$thisdisfn)=
1.1026 raeburn 4912: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
4913: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4914: $formaction =~ s{/+}{/}g;
1.822 bisitz 4915:
4916: my $parentpath = '';
4917: my $lastitem = '';
4918: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4919: $parentpath = $1;
4920: $lastitem = $2;
4921: } else {
4922: $lastitem = $thisdisfn;
4923: }
1.921 bisitz 4924:
4925: my $output =
1.822 bisitz 4926: '<div>'
4927: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4928: .'<b>'.&mt('Construction Space:').'</b> '
4929: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4930: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4931: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4932:
4933: if ($lastitem) {
4934: $output .=
4935: '<span class="LC_filename">'
4936: .$lastitem
4937: .'</span>';
4938: }
4939: $output .=
4940: '<br />'
1.822 bisitz 4941: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4942: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4943: .'</form>'
4944: .&Apache::lonmenu::constspaceform()
4945: .'</div>';
1.921 bisitz 4946:
4947: return $output;
1.822 bisitz 4948: }
4949:
1.60 matthew 4950: ###############################################
4951: ###############################################
4952:
4953: =pod
4954:
1.112 bowersj2 4955: =back
4956:
1.549 albertel 4957: =head1 HTML Helpers
1.112 bowersj2 4958:
4959: =over 4
4960:
4961: =item * &bodytag()
1.60 matthew 4962:
4963: Returns a uniform header for LON-CAPA web pages.
4964:
4965: Inputs:
4966:
1.112 bowersj2 4967: =over 4
4968:
4969: =item * $title, A title to be displayed on the page.
4970:
4971: =item * $function, the current role (can be undef).
4972:
4973: =item * $addentries, extra parameters for the <body> tag.
4974:
4975: =item * $bodyonly, if defined, only return the <body> tag.
4976:
4977: =item * $domain, if defined, force a given domain.
4978:
4979: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4980: text interface only)
1.60 matthew 4981:
1.814 bisitz 4982: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4983: navigational links
1.317 albertel 4984:
1.338 albertel 4985: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4986:
1.460 albertel 4987: =item * $args, optional argument valid values are
4988: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4989: inherit_jsmath -> when creating popup window in a page,
4990: should it have jsmath forced on by the
4991: current page
1.460 albertel 4992:
1.112 bowersj2 4993: =back
4994:
1.60 matthew 4995: Returns: A uniform header for LON-CAPA web pages.
4996: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4997: If $bodyonly is undef or zero, an html string containing a <body> tag and
4998: other decorations will be returned.
4999:
5000: =cut
5001:
1.54 www 5002: sub bodytag {
1.831 bisitz 5003: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962 droeschl 5004: $no_nav_bar,$bgcolor,$args)=@_;
1.339 albertel 5005:
1.954 raeburn 5006: my $public;
5007: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5008: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5009: $public = 1;
5010: }
1.460 albertel 5011: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5012:
1.183 matthew 5013: $function = &get_users_function() if (!$function);
1.339 albertel 5014: my $img = &designparm($function.'.img',$domain);
5015: my $font = &designparm($function.'.font',$domain);
5016: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5017:
1.803 bisitz 5018: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5019: 'bgcolor' => $pgbg,
1.339 albertel 5020: 'text' => $font,
5021: 'alink' => &designparm($function.'.alink',$domain),
5022: 'vlink' => &designparm($function.'.vlink',$domain),
5023: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5024: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5025:
1.63 www 5026: # role and realm
1.378 raeburn 5027: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5028: if ($role eq 'ca') {
1.479 albertel 5029: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5030: $realm = &plainname($rname,$rdom);
1.378 raeburn 5031: }
1.55 www 5032: # realm
1.258 albertel 5033: if ($env{'request.course.id'}) {
1.378 raeburn 5034: if ($env{'request.role'} !~ /^cr/) {
5035: $role = &Apache::lonnet::plaintext($role,&course_type());
5036: }
1.898 raeburn 5037: if ($env{'request.course.sec'}) {
5038: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5039: }
1.359 albertel 5040: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5041: } else {
5042: $role = &Apache::lonnet::plaintext($role);
1.54 www 5043: }
1.433 albertel 5044:
1.359 albertel 5045: if (!$realm) { $realm=' '; }
1.330 albertel 5046:
1.438 albertel 5047: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5048:
1.101 www 5049: # construct main body tag
1.359 albertel 5050: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5051: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5052:
1.530 albertel 5053: if ($bodyonly) {
1.60 matthew 5054: return $bodytag;
1.798 tempelho 5055: }
1.359 albertel 5056:
1.410 albertel 5057: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 5058: if ($public) {
1.433 albertel 5059: undef($role);
1.434 albertel 5060: } else {
1.1070 raeburn 5061: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5062: undef,'LC_menubuttons_link');
1.433 albertel 5063: }
1.359 albertel 5064:
1.762 bisitz 5065: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5066: #
5067: # Extra info if you are the DC
5068: my $dc_info = '';
5069: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5070: $env{'course.'.$env{'request.course.id'}.
5071: '.domain'}.'/'})) {
5072: my $cid = $env{'request.course.id'};
1.917 raeburn 5073: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5074: $dc_info =~ s/\s+$//;
1.359 albertel 5075: }
5076:
1.898 raeburn 5077: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5078: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5079:
1.916 droeschl 5080: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
5081: return $bodytag;
5082: }
1.903 droeschl 5083:
5084: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5085:
5086: # if ($env{'request.state'} eq 'construct') {
5087: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5088: # }
5089:
1.359 albertel 5090:
5091:
1.916 droeschl 5092: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5093: if ($dc_info) {
5094: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5095: }
1.916 droeschl 5096: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
5097: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5098: return $bodytag;
5099: }
1.894 droeschl 5100:
1.927 raeburn 5101: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5102: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
5103: }
1.916 droeschl 5104:
1.903 droeschl 5105: $bodytag .= Apache::lonhtmlcommon::scripttag(
5106: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 5107:
1.903 droeschl 5108: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 5109:
1.917 raeburn 5110: if ($dc_info) {
5111: $dc_info = &dc_courseid_toggle($dc_info);
5112: }
5113: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5114:
1.903 droeschl 5115: #don't show menus for public users
1.954 raeburn 5116: if (!$public){
1.903 droeschl 5117: $bodytag .= Apache::lonmenu::secondary_menu();
5118: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5119: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5120: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5121: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5122: $args->{'bread_crumbs'});
5123: } elsif ($forcereg) {
5124: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
5125: }
1.903 droeschl 5126: }else{
5127: # this is to seperate menu from content when there's no secondary
5128: # menu. Especially needed for public accessible ressources.
5129: $bodytag .= '<hr style="clear:both" />';
5130: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5131: }
1.903 droeschl 5132:
1.235 raeburn 5133: return $bodytag;
1.182 matthew 5134: }
5135:
1.917 raeburn 5136: sub dc_courseid_toggle {
5137: my ($dc_info) = @_;
1.980 raeburn 5138: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5139: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5140: &mt('(More ...)').'</a></span>'.
5141: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5142: }
5143:
1.330 albertel 5144: sub make_attr_string {
5145: my ($register,$attr_ref) = @_;
5146:
5147: if ($attr_ref && !ref($attr_ref)) {
5148: die("addentries Must be a hash ref ".
5149: join(':',caller(1))." ".
5150: join(':',caller(0))." ");
5151: }
5152:
5153: if ($register) {
1.339 albertel 5154: my ($on_load,$on_unload);
5155: foreach my $key (keys(%{$attr_ref})) {
5156: if (lc($key) eq 'onload') {
5157: $on_load.=$attr_ref->{$key}.';';
5158: delete($attr_ref->{$key});
5159:
5160: } elsif (lc($key) eq 'onunload') {
5161: $on_unload.=$attr_ref->{$key}.';';
5162: delete($attr_ref->{$key});
5163: }
5164: }
1.953 droeschl 5165: $attr_ref->{'onload'} = $on_load;
5166: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5167: }
1.339 albertel 5168:
1.330 albertel 5169: my $attr_string;
5170: foreach my $attr (keys(%$attr_ref)) {
5171: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5172: }
5173: return $attr_string;
5174: }
5175:
5176:
1.182 matthew 5177: ###############################################
1.251 albertel 5178: ###############################################
5179:
5180: =pod
5181:
5182: =item * &endbodytag()
5183:
5184: Returns a uniform footer for LON-CAPA web pages.
5185:
1.635 raeburn 5186: Inputs: 1 - optional reference to an args hash
5187: If in the hash, key for noredirectlink has a value which evaluates to true,
5188: a 'Continue' link is not displayed if the page contains an
5189: internal redirect in the <head></head> section,
5190: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5191:
5192: =cut
5193:
5194: sub endbodytag {
1.635 raeburn 5195: my ($args) = @_;
1.1080 raeburn 5196: my $endbodytag;
5197: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5198: $endbodytag='</body>';
5199: }
1.269 albertel 5200: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5201: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5202: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5203: $endbodytag=
5204: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5205: &mt('Continue').'</a>'.
5206: $endbodytag;
5207: }
1.315 albertel 5208: }
1.251 albertel 5209: return $endbodytag;
5210: }
5211:
1.352 albertel 5212: =pod
5213:
5214: =item * &standard_css()
5215:
5216: Returns a style sheet
5217:
5218: Inputs: (all optional)
5219: domain -> force to color decorate a page for a specific
5220: domain
5221: function -> force usage of a specific rolish color scheme
5222: bgcolor -> override the default page bgcolor
5223:
5224: =cut
5225:
1.343 albertel 5226: sub standard_css {
1.345 albertel 5227: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5228: $function = &get_users_function() if (!$function);
5229: my $img = &designparm($function.'.img', $domain);
5230: my $tabbg = &designparm($function.'.tabbg', $domain);
5231: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5232: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5233: #second colour for later usage
1.345 albertel 5234: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5235: my $pgbg_or_bgcolor =
5236: $bgcolor ||
1.352 albertel 5237: &designparm($function.'.pgbg', $domain);
1.382 albertel 5238: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5239: my $alink = &designparm($function.'.alink', $domain);
5240: my $vlink = &designparm($function.'.vlink', $domain);
5241: my $link = &designparm($function.'.link', $domain);
5242:
1.602 albertel 5243: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5244: my $mono = 'monospace';
1.850 bisitz 5245: my $data_table_head = $sidebg;
5246: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5247: my $data_table_dark = '#E0E0E0';
1.470 banghart 5248: my $data_table_darker = '#CCCCCC';
1.349 albertel 5249: my $data_table_highlight = '#FFFF00';
1.352 albertel 5250: my $mail_new = '#FFBB77';
5251: my $mail_new_hover = '#DD9955';
5252: my $mail_read = '#BBBB77';
5253: my $mail_read_hover = '#999944';
5254: my $mail_replied = '#AAAA88';
5255: my $mail_replied_hover = '#888855';
5256: my $mail_other = '#99BBBB';
5257: my $mail_other_hover = '#669999';
1.391 albertel 5258: my $table_header = '#DDDDDD';
1.489 raeburn 5259: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5260: my $lg_border_color = '#C8C8C8';
1.952 onken 5261: my $button_hover = '#BF2317';
1.392 albertel 5262:
1.608 albertel 5263: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5264: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5265: : '0 3px 0 4px';
1.448 albertel 5266:
1.523 albertel 5267:
1.343 albertel 5268: return <<END;
1.947 droeschl 5269:
5270: /* needed for iframe to allow 100% height in FF */
5271: body, html {
5272: margin: 0;
5273: padding: 0 0.5%;
5274: height: 99%; /* to avoid scrollbars */
5275: }
5276:
1.795 www 5277: body {
1.911 bisitz 5278: font-family: $sans;
5279: line-height:130%;
5280: font-size:0.83em;
5281: color:$font;
1.795 www 5282: }
5283:
1.959 onken 5284: a:focus,
5285: a:focus img {
1.795 www 5286: color: red;
5287: }
1.698 harmsja 5288:
1.911 bisitz 5289: form, .inline {
5290: display: inline;
1.795 www 5291: }
1.721 harmsja 5292:
1.795 www 5293: .LC_right {
1.911 bisitz 5294: text-align:right;
1.795 www 5295: }
5296:
5297: .LC_middle {
1.911 bisitz 5298: vertical-align:middle;
1.795 www 5299: }
1.721 harmsja 5300:
1.911 bisitz 5301: .LC_400Box {
5302: width:400px;
5303: }
1.721 harmsja 5304:
1.947 droeschl 5305: .LC_iframecontainer {
5306: width: 98%;
5307: margin: 0;
5308: position: fixed;
5309: top: 8.5em;
5310: bottom: 0;
5311: }
5312:
5313: .LC_iframecontainer iframe{
5314: border: none;
5315: width: 100%;
5316: height: 100%;
5317: }
5318:
1.778 bisitz 5319: .LC_filename {
5320: font-family: $mono;
5321: white-space:pre;
1.921 bisitz 5322: font-size: 120%;
1.778 bisitz 5323: }
5324:
5325: .LC_fileicon {
5326: border: none;
5327: height: 1.3em;
5328: vertical-align: text-bottom;
5329: margin-right: 0.3em;
5330: text-decoration:none;
5331: }
5332:
1.1008 www 5333: .LC_setting {
5334: text-decoration:underline;
5335: }
5336:
1.350 albertel 5337: .LC_error {
5338: color: red;
5339: font-size: larger;
5340: }
1.795 www 5341:
1.457 albertel 5342: .LC_warning,
5343: .LC_diff_removed {
1.733 bisitz 5344: color: red;
1.394 albertel 5345: }
1.532 albertel 5346:
5347: .LC_info,
1.457 albertel 5348: .LC_success,
5349: .LC_diff_added {
1.350 albertel 5350: color: green;
5351: }
1.795 www 5352:
1.802 bisitz 5353: div.LC_confirm_box {
5354: background-color: #FAFAFA;
5355: border: 1px solid $lg_border_color;
5356: margin-right: 0;
5357: padding: 5px;
5358: }
5359:
5360: div.LC_confirm_box .LC_error img,
5361: div.LC_confirm_box .LC_success img {
5362: vertical-align: middle;
5363: }
5364:
1.440 albertel 5365: .LC_icon {
1.771 droeschl 5366: border: none;
1.790 droeschl 5367: vertical-align: middle;
1.771 droeschl 5368: }
5369:
1.543 albertel 5370: .LC_docs_spacer {
5371: width: 25px;
5372: height: 1px;
1.771 droeschl 5373: border: none;
1.543 albertel 5374: }
1.346 albertel 5375:
1.532 albertel 5376: .LC_internal_info {
1.735 bisitz 5377: color: #999999;
1.532 albertel 5378: }
5379:
1.794 www 5380: .LC_discussion {
1.1050 www 5381: background: $data_table_dark;
1.911 bisitz 5382: border: 1px solid black;
5383: margin: 2px;
1.794 www 5384: }
5385:
5386: .LC_disc_action_left {
1.1050 www 5387: background: $sidebg;
1.911 bisitz 5388: text-align: left;
1.1050 www 5389: padding: 4px;
5390: margin: 2px;
1.794 www 5391: }
5392:
5393: .LC_disc_action_right {
1.1050 www 5394: background: $sidebg;
1.911 bisitz 5395: text-align: right;
1.1050 www 5396: padding: 4px;
5397: margin: 2px;
1.794 www 5398: }
5399:
5400: .LC_disc_new_item {
1.911 bisitz 5401: background: white;
5402: border: 2px solid red;
1.1050 www 5403: margin: 4px;
5404: padding: 4px;
1.794 www 5405: }
5406:
5407: .LC_disc_old_item {
1.911 bisitz 5408: background: white;
1.1050 www 5409: margin: 4px;
5410: padding: 4px;
1.794 www 5411: }
5412:
1.458 albertel 5413: table.LC_pastsubmission {
5414: border: 1px solid black;
5415: margin: 2px;
5416: }
5417:
1.924 bisitz 5418: table#LC_menubuttons {
1.345 albertel 5419: width: 100%;
5420: background: $pgbg;
1.392 albertel 5421: border: 2px;
1.402 albertel 5422: border-collapse: separate;
1.803 bisitz 5423: padding: 0;
1.345 albertel 5424: }
1.392 albertel 5425:
1.801 tempelho 5426: table#LC_title_bar a {
5427: color: $fontmenu;
5428: }
1.836 bisitz 5429:
1.807 droeschl 5430: table#LC_title_bar {
1.819 tempelho 5431: clear: both;
1.836 bisitz 5432: display: none;
1.807 droeschl 5433: }
5434:
1.795 www 5435: table#LC_title_bar,
1.933 droeschl 5436: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5437: table#LC_title_bar.LC_with_remote {
1.359 albertel 5438: width: 100%;
1.392 albertel 5439: border-color: $pgbg;
5440: border-style: solid;
5441: border-width: $border;
1.379 albertel 5442: background: $pgbg;
1.801 tempelho 5443: color: $fontmenu;
1.392 albertel 5444: border-collapse: collapse;
1.803 bisitz 5445: padding: 0;
1.819 tempelho 5446: margin: 0;
1.359 albertel 5447: }
1.795 www 5448:
1.933 droeschl 5449: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5450: margin: 0;
5451: padding: 0;
1.933 droeschl 5452: position: relative;
5453: list-style: none;
1.913 droeschl 5454: }
1.933 droeschl 5455: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5456: display: inline;
5457: }
1.933 droeschl 5458:
5459: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5460: padding: 0;
1.933 droeschl 5461: margin: 0;
5462: float: left;
1.913 droeschl 5463: }
1.933 droeschl 5464: .LC_breadcrumb_tools_tools {
5465: padding: 0;
5466: margin: 0;
1.913 droeschl 5467: float: right;
5468: }
5469:
1.359 albertel 5470: table#LC_title_bar td {
5471: background: $tabbg;
5472: }
1.795 www 5473:
1.911 bisitz 5474: table#LC_menubuttons img {
1.803 bisitz 5475: border: none;
1.346 albertel 5476: }
1.795 www 5477:
1.842 droeschl 5478: .LC_breadcrumbs_component {
1.911 bisitz 5479: float: right;
5480: margin: 0 1em;
1.357 albertel 5481: }
1.842 droeschl 5482: .LC_breadcrumbs_component img {
1.911 bisitz 5483: vertical-align: middle;
1.777 tempelho 5484: }
1.795 www 5485:
1.383 albertel 5486: td.LC_table_cell_checkbox {
5487: text-align: center;
5488: }
1.795 www 5489:
5490: .LC_fontsize_small {
1.911 bisitz 5491: font-size: 70%;
1.705 tempelho 5492: }
5493:
1.844 bisitz 5494: #LC_breadcrumbs {
1.911 bisitz 5495: clear:both;
5496: background: $sidebg;
5497: border-bottom: 1px solid $lg_border_color;
5498: line-height: 2.5em;
1.933 droeschl 5499: overflow: hidden;
1.911 bisitz 5500: margin: 0;
5501: padding: 0;
1.995 raeburn 5502: text-align: left;
1.819 tempelho 5503: }
1.862 bisitz 5504:
1.993 raeburn 5505: .LC_head_subbox {
1.911 bisitz 5506: clear:both;
5507: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5508: border: 1px solid $sidebg;
5509: margin: 0 0 10px 0;
1.966 bisitz 5510: padding: 3px;
1.995 raeburn 5511: text-align: left;
1.822 bisitz 5512: }
5513:
1.795 www 5514: .LC_fontsize_medium {
1.911 bisitz 5515: font-size: 85%;
1.705 tempelho 5516: }
5517:
1.795 www 5518: .LC_fontsize_large {
1.911 bisitz 5519: font-size: 120%;
1.705 tempelho 5520: }
5521:
1.346 albertel 5522: .LC_menubuttons_inline_text {
5523: color: $font;
1.698 harmsja 5524: font-size: 90%;
1.701 harmsja 5525: padding-left:3px;
1.346 albertel 5526: }
5527:
1.934 droeschl 5528: .LC_menubuttons_inline_text img{
5529: vertical-align: middle;
5530: }
5531:
1.1051 www 5532: li.LC_menubuttons_inline_text img {
1.951 onken 5533: cursor:pointer;
1.1002 droeschl 5534: text-decoration: none;
1.951 onken 5535: }
5536:
1.526 www 5537: .LC_menubuttons_link {
5538: text-decoration: none;
5539: }
1.795 www 5540:
1.522 albertel 5541: .LC_menubuttons_category {
1.521 www 5542: color: $font;
1.526 www 5543: background: $pgbg;
1.521 www 5544: font-size: larger;
5545: font-weight: bold;
5546: }
5547:
1.346 albertel 5548: td.LC_menubuttons_text {
1.911 bisitz 5549: color: $font;
1.346 albertel 5550: }
1.706 harmsja 5551:
1.346 albertel 5552: .LC_current_location {
5553: background: $tabbg;
5554: }
1.795 www 5555:
1.938 bisitz 5556: table.LC_data_table {
1.347 albertel 5557: border: 1px solid #000000;
1.402 albertel 5558: border-collapse: separate;
1.426 albertel 5559: border-spacing: 1px;
1.610 albertel 5560: background: $pgbg;
1.347 albertel 5561: }
1.795 www 5562:
1.422 albertel 5563: .LC_data_table_dense {
5564: font-size: small;
5565: }
1.795 www 5566:
1.507 raeburn 5567: table.LC_nested_outer {
5568: border: 1px solid #000000;
1.589 raeburn 5569: border-collapse: collapse;
1.803 bisitz 5570: border-spacing: 0;
1.507 raeburn 5571: width: 100%;
5572: }
1.795 www 5573:
1.879 raeburn 5574: table.LC_innerpickbox,
1.507 raeburn 5575: table.LC_nested {
1.803 bisitz 5576: border: none;
1.589 raeburn 5577: border-collapse: collapse;
1.803 bisitz 5578: border-spacing: 0;
1.507 raeburn 5579: width: 100%;
5580: }
1.795 www 5581:
1.911 bisitz 5582: table.LC_data_table tr th,
5583: table.LC_calendar tr th,
1.879 raeburn 5584: table.LC_prior_tries tr th,
5585: table.LC_innerpickbox tr th {
1.349 albertel 5586: font-weight: bold;
5587: background-color: $data_table_head;
1.801 tempelho 5588: color:$fontmenu;
1.701 harmsja 5589: font-size:90%;
1.347 albertel 5590: }
1.795 www 5591:
1.879 raeburn 5592: table.LC_innerpickbox tr th,
5593: table.LC_innerpickbox tr td {
5594: vertical-align: top;
5595: }
5596:
1.711 raeburn 5597: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5598: background-color: #CCCCCC;
1.711 raeburn 5599: font-weight: bold;
5600: text-align: left;
5601: }
1.795 www 5602:
1.912 bisitz 5603: table.LC_data_table tr.LC_odd_row > td {
5604: background-color: $data_table_light;
5605: padding: 2px;
5606: vertical-align: top;
5607: }
5608:
1.809 bisitz 5609: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5610: background-color: $data_table_light;
1.912 bisitz 5611: vertical-align: top;
5612: }
5613:
5614: table.LC_data_table tr.LC_even_row > td {
5615: background-color: $data_table_dark;
1.425 albertel 5616: padding: 2px;
1.900 bisitz 5617: vertical-align: top;
1.347 albertel 5618: }
1.795 www 5619:
1.809 bisitz 5620: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5621: background-color: $data_table_dark;
1.900 bisitz 5622: vertical-align: top;
1.347 albertel 5623: }
1.795 www 5624:
1.425 albertel 5625: table.LC_data_table tr.LC_data_table_highlight td {
5626: background-color: $data_table_darker;
5627: }
1.795 www 5628:
1.639 raeburn 5629: table.LC_data_table tr td.LC_leftcol_header {
5630: background-color: $data_table_head;
5631: font-weight: bold;
5632: }
1.795 www 5633:
1.451 albertel 5634: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5635: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5636: font-weight: bold;
5637: font-style: italic;
5638: text-align: center;
5639: padding: 8px;
1.347 albertel 5640: }
1.795 www 5641:
1.940 bisitz 5642: table.LC_data_table tr.LC_empty_row td {
5643: background-color: $sidebg;
5644: }
5645:
5646: table.LC_nested tr.LC_empty_row td {
5647: background-color: #FFFFFF;
5648: }
5649:
1.890 droeschl 5650: table.LC_caption {
5651: }
5652:
1.507 raeburn 5653: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5654: padding: 4ex
5655: }
1.795 www 5656:
1.507 raeburn 5657: table.LC_nested_outer tr th {
5658: font-weight: bold;
1.801 tempelho 5659: color:$fontmenu;
1.507 raeburn 5660: background-color: $data_table_head;
1.701 harmsja 5661: font-size: small;
1.507 raeburn 5662: border-bottom: 1px solid #000000;
5663: }
1.795 www 5664:
1.507 raeburn 5665: table.LC_nested_outer tr td.LC_subheader {
5666: background-color: $data_table_head;
5667: font-weight: bold;
5668: font-size: small;
5669: border-bottom: 1px solid #000000;
5670: text-align: right;
1.451 albertel 5671: }
1.795 www 5672:
1.507 raeburn 5673: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5674: background-color: #CCCCCC;
1.451 albertel 5675: font-weight: bold;
5676: font-size: small;
1.507 raeburn 5677: text-align: center;
5678: }
1.795 www 5679:
1.589 raeburn 5680: table.LC_nested tr.LC_info_row td.LC_left_item,
5681: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5682: text-align: left;
1.451 albertel 5683: }
1.795 www 5684:
1.507 raeburn 5685: table.LC_nested td {
1.735 bisitz 5686: background-color: #FFFFFF;
1.451 albertel 5687: font-size: small;
1.507 raeburn 5688: }
1.795 www 5689:
1.507 raeburn 5690: table.LC_nested_outer tr th.LC_right_item,
5691: table.LC_nested tr.LC_info_row td.LC_right_item,
5692: table.LC_nested tr.LC_odd_row td.LC_right_item,
5693: table.LC_nested tr td.LC_right_item {
1.451 albertel 5694: text-align: right;
5695: }
5696:
1.507 raeburn 5697: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5698: background-color: #EEEEEE;
1.451 albertel 5699: }
5700:
1.473 raeburn 5701: table.LC_createuser {
5702: }
5703:
5704: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5705: font-size: small;
1.473 raeburn 5706: }
5707:
5708: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5709: background-color: #CCCCCC;
1.473 raeburn 5710: font-weight: bold;
5711: text-align: center;
5712: }
5713:
1.349 albertel 5714: table.LC_calendar {
5715: border: 1px solid #000000;
5716: border-collapse: collapse;
1.917 raeburn 5717: width: 98%;
1.349 albertel 5718: }
1.795 www 5719:
1.349 albertel 5720: table.LC_calendar_pickdate {
5721: font-size: xx-small;
5722: }
1.795 www 5723:
1.349 albertel 5724: table.LC_calendar tr td {
5725: border: 1px solid #000000;
5726: vertical-align: top;
1.917 raeburn 5727: width: 14%;
1.349 albertel 5728: }
1.795 www 5729:
1.349 albertel 5730: table.LC_calendar tr td.LC_calendar_day_empty {
5731: background-color: $data_table_dark;
5732: }
1.795 www 5733:
1.779 bisitz 5734: table.LC_calendar tr td.LC_calendar_day_current {
5735: background-color: $data_table_highlight;
1.777 tempelho 5736: }
1.795 www 5737:
1.938 bisitz 5738: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5739: background-color: $mail_new;
5740: }
1.795 www 5741:
1.938 bisitz 5742: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5743: background-color: $mail_new_hover;
5744: }
1.795 www 5745:
1.938 bisitz 5746: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5747: background-color: $mail_read;
5748: }
1.795 www 5749:
1.938 bisitz 5750: /*
5751: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5752: background-color: $mail_read_hover;
5753: }
1.938 bisitz 5754: */
1.795 www 5755:
1.938 bisitz 5756: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5757: background-color: $mail_replied;
5758: }
1.795 www 5759:
1.938 bisitz 5760: /*
5761: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5762: background-color: $mail_replied_hover;
5763: }
1.938 bisitz 5764: */
1.795 www 5765:
1.938 bisitz 5766: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5767: background-color: $mail_other;
5768: }
1.795 www 5769:
1.938 bisitz 5770: /*
5771: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5772: background-color: $mail_other_hover;
5773: }
1.938 bisitz 5774: */
1.494 raeburn 5775:
1.777 tempelho 5776: table.LC_data_table tr > td.LC_browser_file,
5777: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5778: background: #AAEE77;
1.389 albertel 5779: }
1.795 www 5780:
1.777 tempelho 5781: table.LC_data_table tr > td.LC_browser_file_locked,
5782: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5783: background: #FFAA99;
1.387 albertel 5784: }
1.795 www 5785:
1.777 tempelho 5786: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5787: background: #888888;
1.779 bisitz 5788: }
1.795 www 5789:
1.777 tempelho 5790: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5791: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5792: background: #F8F866;
1.777 tempelho 5793: }
1.795 www 5794:
1.696 bisitz 5795: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5796: background: #E0E8FF;
1.387 albertel 5797: }
1.696 bisitz 5798:
1.707 bisitz 5799: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5800: /* background: #77FF77; */
1.707 bisitz 5801: }
1.795 www 5802:
1.707 bisitz 5803: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5804: border-right: 8px solid #FFFF77;
1.707 bisitz 5805: }
1.795 www 5806:
1.707 bisitz 5807: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5808: border-right: 8px solid #FFAA77;
1.707 bisitz 5809: }
1.795 www 5810:
1.707 bisitz 5811: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5812: border-right: 8px solid #FF7777;
1.707 bisitz 5813: }
1.795 www 5814:
1.707 bisitz 5815: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5816: border-right: 8px solid #AAFF77;
1.707 bisitz 5817: }
1.795 www 5818:
1.707 bisitz 5819: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5820: border-right: 8px solid #11CC55;
1.707 bisitz 5821: }
5822:
1.388 albertel 5823: span.LC_current_location {
1.701 harmsja 5824: font-size:larger;
1.388 albertel 5825: background: $pgbg;
5826: }
1.387 albertel 5827:
1.1029 www 5828: span.LC_current_nav_location {
5829: font-weight:bold;
5830: background: $sidebg;
5831: }
5832:
1.395 albertel 5833: span.LC_parm_menu_item {
5834: font-size: larger;
5835: }
1.795 www 5836:
1.395 albertel 5837: span.LC_parm_scope_all {
5838: color: red;
5839: }
1.795 www 5840:
1.395 albertel 5841: span.LC_parm_scope_folder {
5842: color: green;
5843: }
1.795 www 5844:
1.395 albertel 5845: span.LC_parm_scope_resource {
5846: color: orange;
5847: }
1.795 www 5848:
1.395 albertel 5849: span.LC_parm_part {
5850: color: blue;
5851: }
1.795 www 5852:
1.911 bisitz 5853: span.LC_parm_folder,
5854: span.LC_parm_symb {
1.395 albertel 5855: font-size: x-small;
5856: font-family: $mono;
5857: color: #AAAAAA;
5858: }
5859:
1.977 bisitz 5860: ul.LC_parm_parmlist li {
5861: display: inline-block;
5862: padding: 0.3em 0.8em;
5863: vertical-align: top;
5864: width: 150px;
5865: border-top:1px solid $lg_border_color;
5866: }
5867:
1.795 www 5868: td.LC_parm_overview_level_menu,
5869: td.LC_parm_overview_map_menu,
5870: td.LC_parm_overview_parm_selectors,
5871: td.LC_parm_overview_restrictions {
1.396 albertel 5872: border: 1px solid black;
5873: border-collapse: collapse;
5874: }
1.795 www 5875:
1.396 albertel 5876: table.LC_parm_overview_restrictions td {
5877: border-width: 1px 4px 1px 4px;
5878: border-style: solid;
5879: border-color: $pgbg;
5880: text-align: center;
5881: }
1.795 www 5882:
1.396 albertel 5883: table.LC_parm_overview_restrictions th {
5884: background: $tabbg;
5885: border-width: 1px 4px 1px 4px;
5886: border-style: solid;
5887: border-color: $pgbg;
5888: }
1.795 www 5889:
1.398 albertel 5890: table#LC_helpmenu {
1.803 bisitz 5891: border: none;
1.398 albertel 5892: height: 55px;
1.803 bisitz 5893: border-spacing: 0;
1.398 albertel 5894: }
5895:
5896: table#LC_helpmenu fieldset legend {
5897: font-size: larger;
5898: }
1.795 www 5899:
1.397 albertel 5900: table#LC_helpmenu_links {
5901: width: 100%;
5902: border: 1px solid black;
5903: background: $pgbg;
1.803 bisitz 5904: padding: 0;
1.397 albertel 5905: border-spacing: 1px;
5906: }
1.795 www 5907:
1.397 albertel 5908: table#LC_helpmenu_links tr td {
5909: padding: 1px;
5910: background: $tabbg;
1.399 albertel 5911: text-align: center;
5912: font-weight: bold;
1.397 albertel 5913: }
1.396 albertel 5914:
1.795 www 5915: table#LC_helpmenu_links a:link,
5916: table#LC_helpmenu_links a:visited,
1.397 albertel 5917: table#LC_helpmenu_links a:active {
5918: text-decoration: none;
5919: color: $font;
5920: }
1.795 www 5921:
1.397 albertel 5922: table#LC_helpmenu_links a:hover {
5923: text-decoration: underline;
5924: color: $vlink;
5925: }
1.396 albertel 5926:
1.417 albertel 5927: .LC_chrt_popup_exists {
5928: border: 1px solid #339933;
5929: margin: -1px;
5930: }
1.795 www 5931:
1.417 albertel 5932: .LC_chrt_popup_up {
5933: border: 1px solid yellow;
5934: margin: -1px;
5935: }
1.795 www 5936:
1.417 albertel 5937: .LC_chrt_popup {
5938: border: 1px solid #8888FF;
5939: background: #CCCCFF;
5940: }
1.795 www 5941:
1.421 albertel 5942: table.LC_pick_box {
5943: border-collapse: separate;
5944: background: white;
5945: border: 1px solid black;
5946: border-spacing: 1px;
5947: }
1.795 www 5948:
1.421 albertel 5949: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5950: background: $sidebg;
1.421 albertel 5951: font-weight: bold;
1.900 bisitz 5952: text-align: left;
1.740 bisitz 5953: vertical-align: top;
1.421 albertel 5954: width: 184px;
5955: padding: 8px;
5956: }
1.795 www 5957:
1.579 raeburn 5958: table.LC_pick_box td.LC_pick_box_value {
5959: text-align: left;
5960: padding: 8px;
5961: }
1.795 www 5962:
1.579 raeburn 5963: table.LC_pick_box td.LC_pick_box_select {
5964: text-align: left;
5965: padding: 8px;
5966: }
1.795 www 5967:
1.424 albertel 5968: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5969: padding: 0;
1.421 albertel 5970: height: 1px;
5971: background: black;
5972: }
1.795 www 5973:
1.421 albertel 5974: table.LC_pick_box td.LC_pick_box_submit {
5975: text-align: right;
5976: }
1.795 www 5977:
1.579 raeburn 5978: table.LC_pick_box td.LC_evenrow_value {
5979: text-align: left;
5980: padding: 8px;
5981: background-color: $data_table_light;
5982: }
1.795 www 5983:
1.579 raeburn 5984: table.LC_pick_box td.LC_oddrow_value {
5985: text-align: left;
5986: padding: 8px;
5987: background-color: $data_table_light;
5988: }
1.795 www 5989:
1.579 raeburn 5990: span.LC_helpform_receipt_cat {
5991: font-weight: bold;
5992: }
1.795 www 5993:
1.424 albertel 5994: table.LC_group_priv_box {
5995: background: white;
5996: border: 1px solid black;
5997: border-spacing: 1px;
5998: }
1.795 www 5999:
1.424 albertel 6000: table.LC_group_priv_box td.LC_pick_box_title {
6001: background: $tabbg;
6002: font-weight: bold;
6003: text-align: right;
6004: width: 184px;
6005: }
1.795 www 6006:
1.424 albertel 6007: table.LC_group_priv_box td.LC_groups_fixed {
6008: background: $data_table_light;
6009: text-align: center;
6010: }
1.795 www 6011:
1.424 albertel 6012: table.LC_group_priv_box td.LC_groups_optional {
6013: background: $data_table_dark;
6014: text-align: center;
6015: }
1.795 www 6016:
1.424 albertel 6017: table.LC_group_priv_box td.LC_groups_functionality {
6018: background: $data_table_darker;
6019: text-align: center;
6020: font-weight: bold;
6021: }
1.795 www 6022:
1.424 albertel 6023: table.LC_group_priv td {
6024: text-align: left;
1.803 bisitz 6025: padding: 0;
1.424 albertel 6026: }
6027:
6028: .LC_navbuttons {
6029: margin: 2ex 0ex 2ex 0ex;
6030: }
1.795 www 6031:
1.423 albertel 6032: .LC_topic_bar {
6033: font-weight: bold;
6034: background: $tabbg;
1.918 wenzelju 6035: margin: 1em 0em 1em 2em;
1.805 bisitz 6036: padding: 3px;
1.918 wenzelju 6037: font-size: 1.2em;
1.423 albertel 6038: }
1.795 www 6039:
1.423 albertel 6040: .LC_topic_bar span {
1.918 wenzelju 6041: left: 0.5em;
6042: position: absolute;
1.423 albertel 6043: vertical-align: middle;
1.918 wenzelju 6044: font-size: 1.2em;
1.423 albertel 6045: }
1.795 www 6046:
1.423 albertel 6047: table.LC_course_group_status {
6048: margin: 20px;
6049: }
1.795 www 6050:
1.423 albertel 6051: table.LC_status_selector td {
6052: vertical-align: top;
6053: text-align: center;
1.424 albertel 6054: padding: 4px;
6055: }
1.795 www 6056:
1.599 albertel 6057: div.LC_feedback_link {
1.616 albertel 6058: clear: both;
1.829 kalberla 6059: background: $sidebg;
1.779 bisitz 6060: width: 100%;
1.829 kalberla 6061: padding-bottom: 10px;
6062: border: 1px $tabbg solid;
1.833 kalberla 6063: height: 22px;
6064: line-height: 22px;
6065: padding-top: 5px;
6066: }
6067:
6068: div.LC_feedback_link img {
6069: height: 22px;
1.867 kalberla 6070: vertical-align:middle;
1.829 kalberla 6071: }
6072:
1.911 bisitz 6073: div.LC_feedback_link a {
1.829 kalberla 6074: text-decoration: none;
1.489 raeburn 6075: }
1.795 www 6076:
1.867 kalberla 6077: div.LC_comblock {
1.911 bisitz 6078: display:inline;
1.867 kalberla 6079: color:$font;
6080: font-size:90%;
6081: }
6082:
6083: div.LC_feedback_link div.LC_comblock {
6084: padding-left:5px;
6085: }
6086:
6087: div.LC_feedback_link div.LC_comblock a {
6088: color:$font;
6089: }
6090:
1.489 raeburn 6091: span.LC_feedback_link {
1.858 bisitz 6092: /* background: $feedback_link_bg; */
1.599 albertel 6093: font-size: larger;
6094: }
1.795 www 6095:
1.599 albertel 6096: span.LC_message_link {
1.858 bisitz 6097: /* background: $feedback_link_bg; */
1.599 albertel 6098: font-size: larger;
6099: position: absolute;
6100: right: 1em;
1.489 raeburn 6101: }
1.421 albertel 6102:
1.515 albertel 6103: table.LC_prior_tries {
1.524 albertel 6104: border: 1px solid #000000;
6105: border-collapse: separate;
6106: border-spacing: 1px;
1.515 albertel 6107: }
1.523 albertel 6108:
1.515 albertel 6109: table.LC_prior_tries td {
1.524 albertel 6110: padding: 2px;
1.515 albertel 6111: }
1.523 albertel 6112:
6113: .LC_answer_correct {
1.795 www 6114: background: lightgreen;
6115: color: darkgreen;
6116: padding: 6px;
1.523 albertel 6117: }
1.795 www 6118:
1.523 albertel 6119: .LC_answer_charged_try {
1.797 www 6120: background: #FFAAAA;
1.795 www 6121: color: darkred;
6122: padding: 6px;
1.523 albertel 6123: }
1.795 www 6124:
1.779 bisitz 6125: .LC_answer_not_charged_try,
1.523 albertel 6126: .LC_answer_no_grade,
6127: .LC_answer_late {
1.795 www 6128: background: lightyellow;
1.523 albertel 6129: color: black;
1.795 www 6130: padding: 6px;
1.523 albertel 6131: }
1.795 www 6132:
1.523 albertel 6133: .LC_answer_previous {
1.795 www 6134: background: lightblue;
6135: color: darkblue;
6136: padding: 6px;
1.523 albertel 6137: }
1.795 www 6138:
1.779 bisitz 6139: .LC_answer_no_message {
1.777 tempelho 6140: background: #FFFFFF;
6141: color: black;
1.795 www 6142: padding: 6px;
1.779 bisitz 6143: }
1.795 www 6144:
1.779 bisitz 6145: .LC_answer_unknown {
6146: background: orange;
6147: color: black;
1.795 www 6148: padding: 6px;
1.777 tempelho 6149: }
1.795 www 6150:
1.529 albertel 6151: span.LC_prior_numerical,
6152: span.LC_prior_string,
6153: span.LC_prior_custom,
6154: span.LC_prior_reaction,
6155: span.LC_prior_math {
1.925 bisitz 6156: font-family: $mono;
1.523 albertel 6157: white-space: pre;
6158: }
6159:
1.525 albertel 6160: span.LC_prior_string {
1.925 bisitz 6161: font-family: $mono;
1.525 albertel 6162: white-space: pre;
6163: }
6164:
1.523 albertel 6165: table.LC_prior_option {
6166: width: 100%;
6167: border-collapse: collapse;
6168: }
1.795 www 6169:
1.911 bisitz 6170: table.LC_prior_rank,
1.795 www 6171: table.LC_prior_match {
1.528 albertel 6172: border-collapse: collapse;
6173: }
1.795 www 6174:
1.528 albertel 6175: table.LC_prior_option tr td,
6176: table.LC_prior_rank tr td,
6177: table.LC_prior_match tr td {
1.524 albertel 6178: border: 1px solid #000000;
1.515 albertel 6179: }
6180:
1.855 bisitz 6181: .LC_nobreak {
1.544 albertel 6182: white-space: nowrap;
1.519 raeburn 6183: }
6184:
1.576 raeburn 6185: span.LC_cusr_emph {
6186: font-style: italic;
6187: }
6188:
1.633 raeburn 6189: span.LC_cusr_subheading {
6190: font-weight: normal;
6191: font-size: 85%;
6192: }
6193:
1.861 bisitz 6194: div.LC_docs_entry_move {
1.859 bisitz 6195: border: 1px solid #BBBBBB;
1.545 albertel 6196: background: #DDDDDD;
1.861 bisitz 6197: width: 22px;
1.859 bisitz 6198: padding: 1px;
6199: margin: 0;
1.545 albertel 6200: }
6201:
1.861 bisitz 6202: table.LC_data_table tr > td.LC_docs_entry_commands,
6203: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6204: background: #DDDDDD;
6205: font-size: x-small;
6206: }
1.795 www 6207:
1.861 bisitz 6208: .LC_docs_entry_parameter {
6209: white-space: nowrap;
6210: }
6211:
1.544 albertel 6212: .LC_docs_copy {
1.545 albertel 6213: color: #000099;
1.544 albertel 6214: }
1.795 www 6215:
1.544 albertel 6216: .LC_docs_cut {
1.545 albertel 6217: color: #550044;
1.544 albertel 6218: }
1.795 www 6219:
1.544 albertel 6220: .LC_docs_rename {
1.545 albertel 6221: color: #009900;
1.544 albertel 6222: }
1.795 www 6223:
1.544 albertel 6224: .LC_docs_remove {
1.545 albertel 6225: color: #990000;
6226: }
6227:
1.547 albertel 6228: .LC_docs_reinit_warn,
6229: .LC_docs_ext_edit {
6230: font-size: x-small;
6231: }
6232:
1.545 albertel 6233: table.LC_docs_adddocs td,
6234: table.LC_docs_adddocs th {
6235: border: 1px solid #BBBBBB;
6236: padding: 4px;
6237: background: #DDDDDD;
1.543 albertel 6238: }
6239:
1.584 albertel 6240: table.LC_sty_begin {
6241: background: #BBFFBB;
6242: }
1.795 www 6243:
1.584 albertel 6244: table.LC_sty_end {
6245: background: #FFBBBB;
6246: }
6247:
1.589 raeburn 6248: table.LC_double_column {
1.803 bisitz 6249: border-width: 0;
1.589 raeburn 6250: border-collapse: collapse;
6251: width: 100%;
6252: padding: 2px;
6253: }
6254:
6255: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6256: top: 2px;
1.589 raeburn 6257: left: 2px;
6258: width: 47%;
6259: vertical-align: top;
6260: }
6261:
6262: table.LC_double_column tr td.LC_right_col {
6263: top: 2px;
1.779 bisitz 6264: right: 2px;
1.589 raeburn 6265: width: 47%;
6266: vertical-align: top;
6267: }
6268:
1.591 raeburn 6269: div.LC_left_float {
6270: float: left;
6271: padding-right: 5%;
1.597 albertel 6272: padding-bottom: 4px;
1.591 raeburn 6273: }
6274:
6275: div.LC_clear_float_header {
1.597 albertel 6276: padding-bottom: 2px;
1.591 raeburn 6277: }
6278:
6279: div.LC_clear_float_footer {
1.597 albertel 6280: padding-top: 10px;
1.591 raeburn 6281: clear: both;
6282: }
6283:
1.597 albertel 6284: div.LC_grade_show_user {
1.941 bisitz 6285: /* border-left: 5px solid $sidebg; */
6286: border-top: 5px solid #000000;
6287: margin: 50px 0 0 0;
1.936 bisitz 6288: padding: 15px 0 5px 10px;
1.597 albertel 6289: }
1.795 www 6290:
1.936 bisitz 6291: div.LC_grade_show_user_odd_row {
1.941 bisitz 6292: /* border-left: 5px solid #000000; */
6293: }
6294:
6295: div.LC_grade_show_user div.LC_Box {
6296: margin-right: 50px;
1.597 albertel 6297: }
6298:
6299: div.LC_grade_submissions,
6300: div.LC_grade_message_center,
1.936 bisitz 6301: div.LC_grade_info_links {
1.597 albertel 6302: margin: 5px;
6303: width: 99%;
6304: background: #FFFFFF;
6305: }
1.795 www 6306:
1.597 albertel 6307: div.LC_grade_submissions_header,
1.936 bisitz 6308: div.LC_grade_message_center_header {
1.705 tempelho 6309: font-weight: bold;
6310: font-size: large;
1.597 albertel 6311: }
1.795 www 6312:
1.597 albertel 6313: div.LC_grade_submissions_body,
1.936 bisitz 6314: div.LC_grade_message_center_body {
1.597 albertel 6315: border: 1px solid black;
6316: width: 99%;
6317: background: #FFFFFF;
6318: }
1.795 www 6319:
1.613 albertel 6320: table.LC_scantron_action {
6321: width: 100%;
6322: }
1.795 www 6323:
1.613 albertel 6324: table.LC_scantron_action tr th {
1.698 harmsja 6325: font-weight:bold;
6326: font-style:normal;
1.613 albertel 6327: }
1.795 www 6328:
1.779 bisitz 6329: .LC_edit_problem_header,
1.614 albertel 6330: div.LC_edit_problem_footer {
1.705 tempelho 6331: font-weight: normal;
6332: font-size: medium;
1.602 albertel 6333: margin: 2px;
1.1060 bisitz 6334: background-color: $sidebg;
1.600 albertel 6335: }
1.795 www 6336:
1.600 albertel 6337: div.LC_edit_problem_header,
1.602 albertel 6338: div.LC_edit_problem_header div,
1.614 albertel 6339: div.LC_edit_problem_footer,
6340: div.LC_edit_problem_footer div,
1.602 albertel 6341: div.LC_edit_problem_editxml_header,
6342: div.LC_edit_problem_editxml_header div {
1.600 albertel 6343: margin-top: 5px;
6344: }
1.795 www 6345:
1.600 albertel 6346: div.LC_edit_problem_header_title {
1.705 tempelho 6347: font-weight: bold;
6348: font-size: larger;
1.602 albertel 6349: background: $tabbg;
6350: padding: 3px;
1.1060 bisitz 6351: margin: 0 0 5px 0;
1.602 albertel 6352: }
1.795 www 6353:
1.602 albertel 6354: table.LC_edit_problem_header_title {
6355: width: 100%;
1.600 albertel 6356: background: $tabbg;
1.602 albertel 6357: }
6358:
6359: div.LC_edit_problem_discards {
6360: float: left;
6361: padding-bottom: 5px;
6362: }
1.795 www 6363:
1.602 albertel 6364: div.LC_edit_problem_saves {
6365: float: right;
6366: padding-bottom: 5px;
1.600 albertel 6367: }
1.795 www 6368:
1.911 bisitz 6369: img.stift {
1.803 bisitz 6370: border-width: 0;
6371: vertical-align: middle;
1.677 riegler 6372: }
1.680 riegler 6373:
1.923 bisitz 6374: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6375: vertical-align: top;
1.777 tempelho 6376: }
1.795 www 6377:
1.716 raeburn 6378: div.LC_createcourse {
1.911 bisitz 6379: margin: 10px 10px 10px 10px;
1.716 raeburn 6380: }
6381:
1.917 raeburn 6382: .LC_dccid {
6383: margin: 0.2em 0 0 0;
6384: padding: 0;
6385: font-size: 90%;
6386: display:none;
6387: }
6388:
1.897 wenzelju 6389: ol.LC_primary_menu a:hover,
1.721 harmsja 6390: ol#LC_MenuBreadcrumbs a:hover,
6391: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6392: ul#LC_secondary_menu a:hover,
1.721 harmsja 6393: .LC_FormSectionClearButton input:hover
1.795 www 6394: ul.LC_TabContent li:hover a {
1.952 onken 6395: color:$button_hover;
1.911 bisitz 6396: text-decoration:none;
1.693 droeschl 6397: }
6398:
1.779 bisitz 6399: h1 {
1.911 bisitz 6400: padding: 0;
6401: line-height:130%;
1.693 droeschl 6402: }
1.698 harmsja 6403:
1.911 bisitz 6404: h2,
6405: h3,
6406: h4,
6407: h5,
6408: h6 {
6409: margin: 5px 0 5px 0;
6410: padding: 0;
6411: line-height:130%;
1.693 droeschl 6412: }
1.795 www 6413:
6414: .LC_hcell {
1.911 bisitz 6415: padding:3px 15px 3px 15px;
6416: margin: 0;
6417: background-color:$tabbg;
6418: color:$fontmenu;
6419: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6420: }
1.795 www 6421:
1.840 bisitz 6422: .LC_Box > .LC_hcell {
1.911 bisitz 6423: margin: 0 -10px 10px -10px;
1.835 bisitz 6424: }
6425:
1.721 harmsja 6426: .LC_noBorder {
1.911 bisitz 6427: border: 0;
1.698 harmsja 6428: }
1.693 droeschl 6429:
1.721 harmsja 6430: .LC_FormSectionClearButton input {
1.911 bisitz 6431: background-color:transparent;
6432: border: none;
6433: cursor:pointer;
6434: text-decoration:underline;
1.693 droeschl 6435: }
1.763 bisitz 6436:
6437: .LC_help_open_topic {
1.911 bisitz 6438: color: #FFFFFF;
6439: background-color: #EEEEFF;
6440: margin: 1px;
6441: padding: 4px;
6442: border: 1px solid #000033;
6443: white-space: nowrap;
6444: /* vertical-align: middle; */
1.759 neumanie 6445: }
1.693 droeschl 6446:
1.911 bisitz 6447: dl,
6448: ul,
6449: div,
6450: fieldset {
6451: margin: 10px 10px 10px 0;
6452: /* overflow: hidden; */
1.693 droeschl 6453: }
1.795 www 6454:
1.838 bisitz 6455: fieldset > legend {
1.911 bisitz 6456: font-weight: bold;
6457: padding: 0 5px 0 5px;
1.838 bisitz 6458: }
6459:
1.813 bisitz 6460: #LC_nav_bar {
1.911 bisitz 6461: float: left;
1.995 raeburn 6462: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6463: margin: 0 0 2px 0;
1.807 droeschl 6464: }
6465:
1.916 droeschl 6466: #LC_realm {
6467: margin: 0.2em 0 0 0;
6468: padding: 0;
6469: font-weight: bold;
6470: text-align: center;
1.995 raeburn 6471: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6472: }
6473:
1.911 bisitz 6474: #LC_nav_bar em {
6475: font-weight: bold;
6476: font-style: normal;
1.807 droeschl 6477: }
6478:
1.897 wenzelju 6479: ol.LC_primary_menu {
1.911 bisitz 6480: float: right;
1.934 droeschl 6481: margin: 0;
1.1076 raeburn 6482: padding: 0;
1.995 raeburn 6483: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6484: }
6485:
1.852 droeschl 6486: ol#LC_PathBreadcrumbs {
1.911 bisitz 6487: margin: 0;
1.693 droeschl 6488: }
6489:
1.897 wenzelju 6490: ol.LC_primary_menu li {
1.1076 raeburn 6491: color: RGB(80, 80, 80);
6492: vertical-align: middle;
6493: text-align: left;
6494: list-style: none;
6495: float: left;
6496: }
6497:
6498: ol.LC_primary_menu li a {
6499: display: block;
6500: margin: 0;
6501: padding: 0 5px 0 10px;
6502: text-decoration: none;
6503: }
6504:
6505: ol.LC_primary_menu li ul {
6506: display: none;
6507: width: 10em;
6508: background-color: $data_table_light;
6509: }
6510:
6511: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6512: display: block;
6513: position: absolute;
6514: margin: 0;
6515: padding: 0;
1.1078 raeburn 6516: z-index: 2;
1.1076 raeburn 6517: }
6518:
6519: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6520: font-size: 90%;
1.911 bisitz 6521: vertical-align: top;
1.1076 raeburn 6522: float: none;
1.1079 raeburn 6523: border-left: 1px solid black;
6524: border-right: 1px solid black;
1.1076 raeburn 6525: }
6526:
6527: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6528: background-color:$data_table_light;
1.1076 raeburn 6529: }
6530:
6531: ol.LC_primary_menu li li a:hover {
6532: color:$button_hover;
6533: background-color:$data_table_dark;
1.693 droeschl 6534: }
6535:
1.897 wenzelju 6536: ol.LC_primary_menu li img {
1.911 bisitz 6537: vertical-align: bottom;
1.934 droeschl 6538: height: 1.1em;
1.1077 raeburn 6539: margin: 0.2em 0 0 0;
1.693 droeschl 6540: }
6541:
1.897 wenzelju 6542: ol.LC_primary_menu a {
1.911 bisitz 6543: color: RGB(80, 80, 80);
6544: text-decoration: none;
1.693 droeschl 6545: }
1.795 www 6546:
1.949 droeschl 6547: ol.LC_primary_menu a.LC_new_message {
6548: font-weight:bold;
6549: color: darkred;
6550: }
6551:
1.975 raeburn 6552: ol.LC_docs_parameters {
6553: margin-left: 0;
6554: padding: 0;
6555: list-style: none;
6556: }
6557:
6558: ol.LC_docs_parameters li {
6559: margin: 0;
6560: padding-right: 20px;
6561: display: inline;
6562: }
6563:
1.976 raeburn 6564: ol.LC_docs_parameters li:before {
6565: content: "\\002022 \\0020";
6566: }
6567:
6568: li.LC_docs_parameters_title {
6569: font-weight: bold;
6570: }
6571:
6572: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6573: content: "";
6574: }
6575:
1.897 wenzelju 6576: ul#LC_secondary_menu {
1.911 bisitz 6577: clear: both;
6578: color: $fontmenu;
6579: background: $tabbg;
6580: list-style: none;
6581: padding: 0;
6582: margin: 0;
6583: width: 100%;
1.995 raeburn 6584: text-align: left;
1.808 droeschl 6585: }
6586:
1.897 wenzelju 6587: ul#LC_secondary_menu li {
1.911 bisitz 6588: font-weight: bold;
6589: line-height: 1.8em;
6590: padding: 0 0.8em;
6591: border-right: 1px solid black;
6592: display: inline;
6593: vertical-align: middle;
1.807 droeschl 6594: }
6595:
1.847 tempelho 6596: ul.LC_TabContent {
1.911 bisitz 6597: display:block;
6598: background: $sidebg;
6599: border-bottom: solid 1px $lg_border_color;
6600: list-style:none;
1.1020 raeburn 6601: margin: -1px -10px 0 -10px;
1.911 bisitz 6602: padding: 0;
1.693 droeschl 6603: }
6604:
1.795 www 6605: ul.LC_TabContent li,
6606: ul.LC_TabContentBigger li {
1.911 bisitz 6607: float:left;
1.741 harmsja 6608: }
1.795 www 6609:
1.897 wenzelju 6610: ul#LC_secondary_menu li a {
1.911 bisitz 6611: color: $fontmenu;
6612: text-decoration: none;
1.693 droeschl 6613: }
1.795 www 6614:
1.721 harmsja 6615: ul.LC_TabContent {
1.952 onken 6616: min-height:20px;
1.721 harmsja 6617: }
1.795 www 6618:
6619: ul.LC_TabContent li {
1.911 bisitz 6620: vertical-align:middle;
1.959 onken 6621: padding: 0 16px 0 10px;
1.911 bisitz 6622: background-color:$tabbg;
6623: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6624: border-left: solid 1px $font;
1.721 harmsja 6625: }
1.795 www 6626:
1.847 tempelho 6627: ul.LC_TabContent .right {
1.911 bisitz 6628: float:right;
1.847 tempelho 6629: }
6630:
1.911 bisitz 6631: ul.LC_TabContent li a,
6632: ul.LC_TabContent li {
6633: color:rgb(47,47,47);
6634: text-decoration:none;
6635: font-size:95%;
6636: font-weight:bold;
1.952 onken 6637: min-height:20px;
6638: }
6639:
1.959 onken 6640: ul.LC_TabContent li a:hover,
6641: ul.LC_TabContent li a:focus {
1.952 onken 6642: color: $button_hover;
1.959 onken 6643: background:none;
6644: outline:none;
1.952 onken 6645: }
6646:
6647: ul.LC_TabContent li:hover {
6648: color: $button_hover;
6649: cursor:pointer;
1.721 harmsja 6650: }
1.795 www 6651:
1.911 bisitz 6652: ul.LC_TabContent li.active {
1.952 onken 6653: color: $font;
1.911 bisitz 6654: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6655: border-bottom:solid 1px #FFFFFF;
6656: cursor: default;
1.744 ehlerst 6657: }
1.795 www 6658:
1.959 onken 6659: ul.LC_TabContent li.active a {
6660: color:$font;
6661: background:#FFFFFF;
6662: outline: none;
6663: }
1.1047 raeburn 6664:
6665: ul.LC_TabContent li.goback {
6666: float: left;
6667: border-left: none;
6668: }
6669:
1.870 tempelho 6670: #maincoursedoc {
1.911 bisitz 6671: clear:both;
1.870 tempelho 6672: }
6673:
6674: ul.LC_TabContentBigger {
1.911 bisitz 6675: display:block;
6676: list-style:none;
6677: padding: 0;
1.870 tempelho 6678: }
6679:
1.795 www 6680: ul.LC_TabContentBigger li {
1.911 bisitz 6681: vertical-align:bottom;
6682: height: 30px;
6683: font-size:110%;
6684: font-weight:bold;
6685: color: #737373;
1.841 tempelho 6686: }
6687:
1.957 onken 6688: ul.LC_TabContentBigger li.active {
6689: position: relative;
6690: top: 1px;
6691: }
6692:
1.870 tempelho 6693: ul.LC_TabContentBigger li a {
1.911 bisitz 6694: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6695: height: 30px;
6696: line-height: 30px;
6697: text-align: center;
6698: display: block;
6699: text-decoration: none;
1.958 onken 6700: outline: none;
1.741 harmsja 6701: }
1.795 www 6702:
1.870 tempelho 6703: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6704: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6705: color:$font;
1.744 ehlerst 6706: }
1.795 www 6707:
1.870 tempelho 6708: ul.LC_TabContentBigger li b {
1.911 bisitz 6709: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6710: display: block;
6711: float: left;
6712: padding: 0 30px;
1.957 onken 6713: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6714: }
6715:
1.956 onken 6716: ul.LC_TabContentBigger li:hover b {
6717: color:$button_hover;
6718: }
6719:
1.870 tempelho 6720: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6721: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6722: color:$font;
1.957 onken 6723: border: 0;
1.741 harmsja 6724: }
1.693 droeschl 6725:
1.870 tempelho 6726:
1.862 bisitz 6727: ul.LC_CourseBreadcrumbs {
6728: background: $sidebg;
1.1020 raeburn 6729: height: 2em;
1.862 bisitz 6730: padding-left: 10px;
1.1020 raeburn 6731: margin: 0;
1.862 bisitz 6732: list-style-position: inside;
6733: }
6734:
1.911 bisitz 6735: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6736: ol#LC_PathBreadcrumbs {
1.911 bisitz 6737: padding-left: 10px;
6738: margin: 0;
1.933 droeschl 6739: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6740: }
6741:
1.911 bisitz 6742: ol#LC_MenuBreadcrumbs li,
6743: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6744: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6745: display: inline;
1.933 droeschl 6746: white-space: normal;
1.693 droeschl 6747: }
6748:
1.823 bisitz 6749: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6750: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6751: text-decoration: none;
6752: font-size:90%;
1.693 droeschl 6753: }
1.795 www 6754:
1.969 droeschl 6755: ol#LC_MenuBreadcrumbs h1 {
6756: display: inline;
6757: font-size: 90%;
6758: line-height: 2.5em;
6759: margin: 0;
6760: padding: 0;
6761: }
6762:
1.795 www 6763: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6764: text-decoration:none;
6765: font-size:100%;
6766: font-weight:bold;
1.693 droeschl 6767: }
1.795 www 6768:
1.840 bisitz 6769: .LC_Box {
1.911 bisitz 6770: border: solid 1px $lg_border_color;
6771: padding: 0 10px 10px 10px;
1.746 neumanie 6772: }
1.795 www 6773:
1.1020 raeburn 6774: .LC_DocsBox {
6775: border: solid 1px $lg_border_color;
6776: padding: 0 0 10px 10px;
6777: }
6778:
1.795 www 6779: .LC_AboutMe_Image {
1.911 bisitz 6780: float:left;
6781: margin-right:10px;
1.747 neumanie 6782: }
1.795 www 6783:
6784: .LC_Clear_AboutMe_Image {
1.911 bisitz 6785: clear:left;
1.747 neumanie 6786: }
1.795 www 6787:
1.721 harmsja 6788: dl.LC_ListStyleClean dt {
1.911 bisitz 6789: padding-right: 5px;
6790: display: table-header-group;
1.693 droeschl 6791: }
6792:
1.721 harmsja 6793: dl.LC_ListStyleClean dd {
1.911 bisitz 6794: display: table-row;
1.693 droeschl 6795: }
6796:
1.721 harmsja 6797: .LC_ListStyleClean,
6798: .LC_ListStyleSimple,
6799: .LC_ListStyleNormal,
1.795 www 6800: .LC_ListStyleSpecial {
1.911 bisitz 6801: /* display:block; */
6802: list-style-position: inside;
6803: list-style-type: none;
6804: overflow: hidden;
6805: padding: 0;
1.693 droeschl 6806: }
6807:
1.721 harmsja 6808: .LC_ListStyleSimple li,
6809: .LC_ListStyleSimple dd,
6810: .LC_ListStyleNormal li,
6811: .LC_ListStyleNormal dd,
6812: .LC_ListStyleSpecial li,
1.795 www 6813: .LC_ListStyleSpecial dd {
1.911 bisitz 6814: margin: 0;
6815: padding: 5px 5px 5px 10px;
6816: clear: both;
1.693 droeschl 6817: }
6818:
1.721 harmsja 6819: .LC_ListStyleClean li,
6820: .LC_ListStyleClean dd {
1.911 bisitz 6821: padding-top: 0;
6822: padding-bottom: 0;
1.693 droeschl 6823: }
6824:
1.721 harmsja 6825: .LC_ListStyleSimple dd,
1.795 www 6826: .LC_ListStyleSimple li {
1.911 bisitz 6827: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6828: }
6829:
1.721 harmsja 6830: .LC_ListStyleSpecial li,
6831: .LC_ListStyleSpecial dd {
1.911 bisitz 6832: list-style-type: none;
6833: background-color: RGB(220, 220, 220);
6834: margin-bottom: 4px;
1.693 droeschl 6835: }
6836:
1.721 harmsja 6837: table.LC_SimpleTable {
1.911 bisitz 6838: margin:5px;
6839: border:solid 1px $lg_border_color;
1.795 www 6840: }
1.693 droeschl 6841:
1.721 harmsja 6842: table.LC_SimpleTable tr {
1.911 bisitz 6843: padding: 0;
6844: border:solid 1px $lg_border_color;
1.693 droeschl 6845: }
1.795 www 6846:
6847: table.LC_SimpleTable thead {
1.911 bisitz 6848: background:rgb(220,220,220);
1.693 droeschl 6849: }
6850:
1.721 harmsja 6851: div.LC_columnSection {
1.911 bisitz 6852: display: block;
6853: clear: both;
6854: overflow: hidden;
6855: margin: 0;
1.693 droeschl 6856: }
6857:
1.721 harmsja 6858: div.LC_columnSection>* {
1.911 bisitz 6859: float: left;
6860: margin: 10px 20px 10px 0;
6861: overflow:hidden;
1.693 droeschl 6862: }
1.721 harmsja 6863:
1.795 www 6864: table em {
1.911 bisitz 6865: font-weight: bold;
6866: font-style: normal;
1.748 schulted 6867: }
1.795 www 6868:
1.779 bisitz 6869: table.LC_tableBrowseRes,
1.795 www 6870: table.LC_tableOfContent {
1.911 bisitz 6871: border:none;
6872: border-spacing: 1px;
6873: padding: 3px;
6874: background-color: #FFFFFF;
6875: font-size: 90%;
1.753 droeschl 6876: }
1.789 droeschl 6877:
1.911 bisitz 6878: table.LC_tableOfContent {
6879: border-collapse: collapse;
1.789 droeschl 6880: }
6881:
1.771 droeschl 6882: table.LC_tableBrowseRes a,
1.768 schulted 6883: table.LC_tableOfContent a {
1.911 bisitz 6884: background-color: transparent;
6885: text-decoration: none;
1.753 droeschl 6886: }
6887:
1.795 www 6888: table.LC_tableOfContent img {
1.911 bisitz 6889: border: none;
6890: height: 1.3em;
6891: vertical-align: text-bottom;
6892: margin-right: 0.3em;
1.753 droeschl 6893: }
1.757 schulted 6894:
1.795 www 6895: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6896: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6897: }
6898:
1.795 www 6899: a#LC_content_toolbar_everything {
1.911 bisitz 6900: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6901: }
6902:
1.795 www 6903: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6904: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6905: }
6906:
1.795 www 6907: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6908: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6909: }
6910:
1.795 www 6911: a#LC_content_toolbar_changefolder {
1.911 bisitz 6912: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6913: }
6914:
1.795 www 6915: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6916: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6917: }
6918:
1.1043 raeburn 6919: a#LC_content_toolbar_edittoplevel {
6920: background-image:url(/res/adm/pages/edittoplevel.gif);
6921: }
6922:
1.795 www 6923: ul#LC_toolbar li a:hover {
1.911 bisitz 6924: background-position: bottom center;
1.757 schulted 6925: }
6926:
1.795 www 6927: ul#LC_toolbar {
1.911 bisitz 6928: padding: 0;
6929: margin: 2px;
6930: list-style:none;
6931: position:relative;
6932: background-color:white;
1.1082 raeburn 6933: overflow: auto;
1.757 schulted 6934: }
6935:
1.795 www 6936: ul#LC_toolbar li {
1.911 bisitz 6937: border:1px solid white;
6938: padding: 0;
6939: margin: 0;
6940: float: left;
6941: display:inline;
6942: vertical-align:middle;
1.1082 raeburn 6943: white-space: nowrap;
1.911 bisitz 6944: }
1.757 schulted 6945:
1.783 amueller 6946:
1.795 www 6947: a.LC_toolbarItem {
1.911 bisitz 6948: display:block;
6949: padding: 0;
6950: margin: 0;
6951: height: 32px;
6952: width: 32px;
6953: color:white;
6954: border: none;
6955: background-repeat:no-repeat;
6956: background-color:transparent;
1.757 schulted 6957: }
6958:
1.915 droeschl 6959: ul.LC_funclist {
6960: margin: 0;
6961: padding: 0.5em 1em 0.5em 0;
6962: }
6963:
1.933 droeschl 6964: ul.LC_funclist > li:first-child {
6965: font-weight:bold;
6966: margin-left:0.8em;
6967: }
6968:
1.915 droeschl 6969: ul.LC_funclist + ul.LC_funclist {
6970: /*
6971: left border as a seperator if we have more than
6972: one list
6973: */
6974: border-left: 1px solid $sidebg;
6975: /*
6976: this hides the left border behind the border of the
6977: outer box if element is wrapped to the next 'line'
6978: */
6979: margin-left: -1px;
6980: }
6981:
1.843 bisitz 6982: ul.LC_funclist li {
1.915 droeschl 6983: display: inline;
1.782 bisitz 6984: white-space: nowrap;
1.915 droeschl 6985: margin: 0 0 0 25px;
6986: line-height: 150%;
1.782 bisitz 6987: }
6988:
1.974 wenzelju 6989: .LC_hidden {
6990: display: none;
6991: }
6992:
1.1030 www 6993: .LCmodal-overlay {
6994: position:fixed;
6995: top:0;
6996: right:0;
6997: bottom:0;
6998: left:0;
6999: height:100%;
7000: width:100%;
7001: margin:0;
7002: padding:0;
7003: background:#999;
7004: opacity:.75;
7005: filter: alpha(opacity=75);
7006: -moz-opacity: 0.75;
7007: z-index:101;
7008: }
7009:
7010: * html .LCmodal-overlay {
7011: position: absolute;
7012: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7013: }
7014:
7015: .LCmodal-window {
7016: position:fixed;
7017: top:50%;
7018: left:50%;
7019: margin:0;
7020: padding:0;
7021: z-index:102;
7022: }
7023:
7024: * html .LCmodal-window {
7025: position:absolute;
7026: }
7027:
7028: .LCclose-window {
7029: position:absolute;
7030: width:32px;
7031: height:32px;
7032: right:8px;
7033: top:8px;
7034: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7035: text-indent:-99999px;
7036: overflow:hidden;
7037: cursor:pointer;
7038: }
7039:
1.343 albertel 7040: END
7041: }
7042:
1.306 albertel 7043: =pod
7044:
7045: =item * &headtag()
7046:
7047: Returns a uniform footer for LON-CAPA web pages.
7048:
1.307 albertel 7049: Inputs: $title - optional title for the head
7050: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7051: $args - optional arguments
1.319 albertel 7052: force_register - if is true call registerurl so the remote is
7053: informed
1.415 albertel 7054: redirect -> array ref of
7055: 1- seconds before redirect occurs
7056: 2- url to redirect to
7057: 3- whether the side effect should occur
1.315 albertel 7058: (side effect of setting
7059: $env{'internal.head.redirect'} to the url
7060: redirected too)
1.352 albertel 7061: domain -> force to color decorate a page for a specific
7062: domain
7063: function -> force usage of a specific rolish color scheme
7064: bgcolor -> override the default page bgcolor
1.460 albertel 7065: no_auto_mt_title
7066: -> prevent &mt()ing the title arg
1.464 albertel 7067:
1.306 albertel 7068: =cut
7069:
7070: sub headtag {
1.313 albertel 7071: my ($title,$head_extra,$args) = @_;
1.306 albertel 7072:
1.363 albertel 7073: my $function = $args->{'function'} || &get_users_function();
7074: my $domain = $args->{'domain'} || &determinedomain();
7075: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7076: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7077: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7078: #time(),
1.418 albertel 7079: $env{'environment.color.timestamp'},
1.363 albertel 7080: $function,$domain,$bgcolor);
7081:
1.369 www 7082: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7083:
1.308 albertel 7084: my $result =
7085: '<head>'.
1.461 albertel 7086: &font_settings();
1.319 albertel 7087:
1.1064 raeburn 7088: my $inhibitprint = &print_suppression();
7089:
1.461 albertel 7090: if (!$args->{'frameset'}) {
7091: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7092: }
1.962 droeschl 7093: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7094: $result .= Apache::lonxml::display_title();
1.319 albertel 7095: }
1.436 albertel 7096: if (!$args->{'no_nav_bar'}
7097: && !$args->{'only_body'}
7098: && !$args->{'frameset'}) {
7099: $result .= &help_menu_js();
1.1032 www 7100: $result.=&modal_window();
1.1038 www 7101: $result.=&togglebox_script();
1.1034 www 7102: $result.=&wishlist_window();
1.1041 www 7103: $result.=&LCprogressbarUpdate_script();
1.1034 www 7104: } else {
7105: if ($args->{'add_modal'}) {
7106: $result.=&modal_window();
7107: }
7108: if ($args->{'add_wishlist'}) {
7109: $result.=&wishlist_window();
7110: }
1.1038 www 7111: if ($args->{'add_togglebox'}) {
7112: $result.=&togglebox_script();
7113: }
1.1041 www 7114: if ($args->{'add_progressbar'}) {
7115: $result.=&LCprogressbarUpdate_script();
7116: }
1.436 albertel 7117: }
1.314 albertel 7118: if (ref($args->{'redirect'})) {
1.414 albertel 7119: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7120: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7121: if (!$inhibit_continue) {
7122: $env{'internal.head.redirect'} = $url;
7123: }
1.313 albertel 7124: $result.=<<ADDMETA
7125: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7126: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7127: ADDMETA
7128: }
1.306 albertel 7129: if (!defined($title)) {
7130: $title = 'The LearningOnline Network with CAPA';
7131: }
1.460 albertel 7132: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7133: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7134: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7135: .$inhibitprint
1.414 albertel 7136: .$head_extra;
1.962 droeschl 7137: return $result.'</head>';
1.306 albertel 7138: }
7139:
7140: =pod
7141:
1.340 albertel 7142: =item * &font_settings()
7143:
7144: Returns neccessary <meta> to set the proper encoding
7145:
7146: Inputs: none
7147:
7148: =cut
7149:
7150: sub font_settings {
7151: my $headerstring='';
1.647 www 7152: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7153: $headerstring.=
7154: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7155: }
7156: return $headerstring;
7157: }
7158:
1.341 albertel 7159: =pod
7160:
1.1064 raeburn 7161: =item * &print_suppression()
7162:
7163: In course context returns css which causes the body to be blank when media="print",
7164: if printout generation is unavailable for the current resource.
7165:
7166: This could be because:
7167:
7168: (a) printstartdate is in the future
7169:
7170: (b) printenddate is in the past
7171:
7172: (c) there is an active exam block with "printout"
7173: functionality blocked
7174:
7175: Users with pav, pfo or evb privileges are exempt.
7176:
7177: Inputs: none
7178:
7179: =cut
7180:
7181:
7182: sub print_suppression {
7183: my $noprint;
7184: if ($env{'request.course.id'}) {
7185: my $scope = $env{'request.course.id'};
7186: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7187: (&Apache::lonnet::allowed('pfo',$scope))) {
7188: return;
7189: }
7190: if ($env{'request.course.sec'} ne '') {
7191: $scope .= "/$env{'request.course.sec'}";
7192: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7193: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7194: return;
1.1064 raeburn 7195: }
7196: }
7197: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7198: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7199: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7200: if ($blocked) {
7201: my $checkrole = "cm./$cdom/$cnum";
7202: if ($env{'request.course.sec'} ne '') {
7203: $checkrole .= "/$env{'request.course.sec'}";
7204: }
7205: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7206: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7207: $noprint = 1;
7208: }
7209: }
7210: unless ($noprint) {
7211: my $symb = &Apache::lonnet::symbread();
7212: if ($symb ne '') {
7213: my $navmap = Apache::lonnavmaps::navmap->new();
7214: if (ref($navmap)) {
7215: my $res = $navmap->getBySymb($symb);
7216: if (ref($res)) {
7217: if (!$res->resprintable()) {
7218: $noprint = 1;
7219: }
7220: }
7221: }
7222: }
7223: }
7224: if ($noprint) {
7225: return <<"ENDSTYLE";
7226: <style type="text/css" media="print">
7227: body { display:none }
7228: </style>
7229: ENDSTYLE
7230: }
7231: }
7232: return;
7233: }
7234:
7235: =pod
7236:
1.341 albertel 7237: =item * &xml_begin()
7238:
7239: Returns the needed doctype and <html>
7240:
7241: Inputs: none
7242:
7243: =cut
7244:
7245: sub xml_begin {
7246: my $output='';
7247:
7248: if ($env{'browser.mathml'}) {
7249: $output='<?xml version="1.0"?>'
7250: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7251: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7252:
7253: # .'<!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">] >'
7254: .'<!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">'
7255: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7256: .'xmlns="http://www.w3.org/1999/xhtml">';
7257: } else {
1.849 bisitz 7258: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7259: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7260: }
7261: return $output;
7262: }
1.340 albertel 7263:
7264: =pod
7265:
1.306 albertel 7266: =item * &start_page()
7267:
7268: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7269:
1.648 raeburn 7270: Inputs:
7271:
7272: =over 4
7273:
7274: $title - optional title for the page
7275:
7276: $head_extra - optional extra HTML to incude inside the <head>
7277:
7278: $args - additional optional args supported are:
7279:
7280: =over 8
7281:
7282: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7283: arg on
1.814 bisitz 7284: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7285: add_entries -> additional attributes to add to the <body>
7286: domain -> force to color decorate a page for a
1.317 albertel 7287: specific domain
1.648 raeburn 7288: function -> force usage of a specific rolish color
1.317 albertel 7289: scheme
1.648 raeburn 7290: redirect -> see &headtag()
7291: bgcolor -> override the default page bg color
7292: js_ready -> return a string ready for being used in
1.317 albertel 7293: a javascript writeln
1.648 raeburn 7294: html_encode -> return a string ready for being used in
1.320 albertel 7295: a html attribute
1.648 raeburn 7296: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7297: $forcereg arg
1.648 raeburn 7298: frameset -> if true will start with a <frameset>
1.330 albertel 7299: rather than <body>
1.648 raeburn 7300: skip_phases -> hash ref of
1.338 albertel 7301: head -> skip the <html><head> generation
7302: body -> skip all <body> generation
1.648 raeburn 7303: no_auto_mt_title -> prevent &mt()ing the title arg
7304: inherit_jsmath -> when creating popup window in a page,
7305: should it have jsmath forced on by the
7306: current page
1.867 kalberla 7307: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7308: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 7309:
1.648 raeburn 7310: =back
1.460 albertel 7311:
1.648 raeburn 7312: =back
1.562 albertel 7313:
1.306 albertel 7314: =cut
7315:
7316: sub start_page {
1.309 albertel 7317: my ($title,$head_extra,$args) = @_;
1.318 albertel 7318: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7319:
1.315 albertel 7320: $env{'internal.start_page'}++;
1.338 albertel 7321: my $result;
1.964 droeschl 7322:
1.338 albertel 7323: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7324: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7325: }
7326:
7327: if (! exists($args->{'skip_phases'}{'body'}) ) {
7328: if ($args->{'frameset'}) {
7329: my $attr_string = &make_attr_string($args->{'force_register'},
7330: $args->{'add_entries'});
7331: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7332: } else {
7333: $result .=
7334: &bodytag($title,
7335: $args->{'function'}, $args->{'add_entries'},
7336: $args->{'only_body'}, $args->{'domain'},
7337: $args->{'force_register'}, $args->{'no_nav_bar'},
1.962 droeschl 7338: $args->{'bgcolor'}, $args);
1.831 bisitz 7339: }
1.330 albertel 7340: }
1.338 albertel 7341:
1.315 albertel 7342: if ($args->{'js_ready'}) {
1.713 kaisler 7343: $result = &js_ready($result);
1.315 albertel 7344: }
1.320 albertel 7345: if ($args->{'html_encode'}) {
1.713 kaisler 7346: $result = &html_encode($result);
7347: }
7348:
1.813 bisitz 7349: # Preparation for new and consistent functionlist at top of screen
7350: # if ($args->{'functionlist'}) {
7351: # $result .= &build_functionlist();
7352: #}
7353:
1.964 droeschl 7354: # Don't add anything more if only_body wanted or in const space
7355: return $result if $args->{'only_body'}
7356: || $env{'request.state'} eq 'construct';
1.813 bisitz 7357:
7358: #Breadcrumbs
1.758 kaisler 7359: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7360: &Apache::lonhtmlcommon::clear_breadcrumbs();
7361: #if any br links exists, add them to the breadcrumbs
7362: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7363: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7364: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7365: }
7366: }
7367:
7368: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7369: if(exists($args->{'bread_crumbs_component'})){
7370: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7371: }else{
7372: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7373: }
1.320 albertel 7374: }
1.315 albertel 7375: return $result;
1.306 albertel 7376: }
7377:
7378: sub end_page {
1.315 albertel 7379: my ($args) = @_;
7380: $env{'internal.end_page'}++;
1.330 albertel 7381: my $result;
1.335 albertel 7382: if ($args->{'discussion'}) {
7383: my ($target,$parser);
7384: if (ref($args->{'discussion'})) {
7385: ($target,$parser) =($args->{'discussion'}{'target'},
7386: $args->{'discussion'}{'parser'});
7387: }
7388: $result .= &Apache::lonxml::xmlend($target,$parser);
7389: }
1.330 albertel 7390: if ($args->{'frameset'}) {
7391: $result .= '</frameset>';
7392: } else {
1.635 raeburn 7393: $result .= &endbodytag($args);
1.330 albertel 7394: }
1.1080 raeburn 7395: unless ($args->{'notbody'}) {
7396: $result .= "\n</html>";
7397: }
1.330 albertel 7398:
1.315 albertel 7399: if ($args->{'js_ready'}) {
1.317 albertel 7400: $result = &js_ready($result);
1.315 albertel 7401: }
1.335 albertel 7402:
1.320 albertel 7403: if ($args->{'html_encode'}) {
7404: $result = &html_encode($result);
7405: }
1.335 albertel 7406:
1.315 albertel 7407: return $result;
7408: }
7409:
1.1034 www 7410: sub wishlist_window {
7411: return(<<'ENDWISHLIST');
1.1046 raeburn 7412: <script type="text/javascript">
1.1034 www 7413: // <![CDATA[
7414: // <!-- BEGIN LON-CAPA Internal
7415: function set_wishlistlink(title, path) {
7416: if (!title) {
7417: title = document.title;
7418: title = title.replace(/^LON-CAPA /,'');
7419: }
7420: if (!path) {
7421: path = location.pathname;
7422: }
7423: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7424: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7425: }
7426: // END LON-CAPA Internal -->
7427: // ]]>
7428: </script>
7429: ENDWISHLIST
7430: }
7431:
1.1030 www 7432: sub modal_window {
7433: return(<<'ENDMODAL');
1.1046 raeburn 7434: <script type="text/javascript">
1.1030 www 7435: // <![CDATA[
7436: // <!-- BEGIN LON-CAPA Internal
7437: var modalWindow = {
7438: parent:"body",
7439: windowId:null,
7440: content:null,
7441: width:null,
7442: height:null,
7443: close:function()
7444: {
7445: $(".LCmodal-window").remove();
7446: $(".LCmodal-overlay").remove();
7447: },
7448: open:function()
7449: {
7450: var modal = "";
7451: modal += "<div class=\"LCmodal-overlay\"></div>";
7452: 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;\">";
7453: modal += this.content;
7454: modal += "</div>";
7455:
7456: $(this.parent).append(modal);
7457:
7458: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7459: $(".LCclose-window").click(function(){modalWindow.close();});
7460: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7461: }
7462: };
1.1031 www 7463: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7464: {
7465: modalWindow.windowId = "myModal";
7466: modalWindow.width = width;
7467: modalWindow.height = height;
1.1031 www 7468: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7469: modalWindow.open();
7470: };
7471: // END LON-CAPA Internal -->
7472: // ]]>
7473: </script>
7474: ENDMODAL
7475: }
7476:
7477: sub modal_link {
1.1052 www 7478: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7479: unless ($width) { $width=480; }
7480: unless ($height) { $height=400; }
1.1031 www 7481: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7482: my $target_attr;
7483: if (defined($target)) {
7484: $target_attr = 'target="'.$target.'"';
7485: }
7486: return <<"ENDLINK";
7487: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7488: $linktext</a>
7489: ENDLINK
1.1030 www 7490: }
7491:
1.1032 www 7492: sub modal_adhoc_script {
7493: my ($funcname,$width,$height,$content)=@_;
7494: return (<<ENDADHOC);
1.1046 raeburn 7495: <script type="text/javascript">
1.1032 www 7496: // <![CDATA[
7497: var $funcname = function()
7498: {
7499: modalWindow.windowId = "myModal";
7500: modalWindow.width = $width;
7501: modalWindow.height = $height;
7502: modalWindow.content = '$content';
7503: modalWindow.open();
7504: };
7505: // ]]>
7506: </script>
7507: ENDADHOC
7508: }
7509:
1.1041 www 7510: sub modal_adhoc_inner {
7511: my ($funcname,$width,$height,$content)=@_;
7512: my $innerwidth=$width-20;
7513: $content=&js_ready(
1.1042 www 7514: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041 www 7515: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
7516: $content.
7517: &end_scrollbox().
7518: &end_page()
7519: );
7520: return &modal_adhoc_script($funcname,$width,$height,$content);
7521: }
7522:
7523: sub modal_adhoc_window {
7524: my ($funcname,$width,$height,$content,$linktext)=@_;
7525: return &modal_adhoc_inner($funcname,$width,$height,$content).
7526: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7527: }
7528:
7529: sub modal_adhoc_launch {
7530: my ($funcname,$width,$height,$content)=@_;
7531: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7532: <script type="text/javascript">
7533: // <![CDATA[
7534: $funcname();
7535: // ]]>
7536: </script>
7537: ENDLAUNCH
7538: }
7539:
7540: sub modal_adhoc_close {
7541: return (<<ENDCLOSE);
7542: <script type="text/javascript">
7543: // <![CDATA[
7544: modalWindow.close();
7545: // ]]>
7546: </script>
7547: ENDCLOSE
7548: }
7549:
1.1038 www 7550: sub togglebox_script {
7551: return(<<ENDTOGGLE);
7552: <script type="text/javascript">
7553: // <![CDATA[
7554: function LCtoggleDisplay(id,hidetext,showtext) {
7555: link = document.getElementById(id + "link").childNodes[0];
7556: with (document.getElementById(id).style) {
7557: if (display == "none" ) {
7558: display = "inline";
7559: link.nodeValue = hidetext;
7560: } else {
7561: display = "none";
7562: link.nodeValue = showtext;
7563: }
7564: }
7565: }
7566: // ]]>
7567: </script>
7568: ENDTOGGLE
7569: }
7570:
1.1039 www 7571: sub start_togglebox {
7572: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7573: unless ($heading) { $heading=''; } else { $heading.=' '; }
7574: unless ($showtext) { $showtext=&mt('show'); }
7575: unless ($hidetext) { $hidetext=&mt('hide'); }
7576: unless ($headerbg) { $headerbg='#FFFFFF'; }
7577: return &start_data_table().
7578: &start_data_table_header_row().
7579: '<td bgcolor="'.$headerbg.'">'.$heading.
7580: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7581: $showtext.'\')">'.$showtext.'</a>]</td>'.
7582: &end_data_table_header_row().
7583: '<tr id="'.$id.'" style="display:none""><td>';
7584: }
7585:
7586: sub end_togglebox {
7587: return '</td></tr>'.&end_data_table();
7588: }
7589:
1.1041 www 7590: sub LCprogressbar_script {
1.1045 www 7591: my ($id)=@_;
1.1041 www 7592: return(<<ENDPROGRESS);
7593: <script type="text/javascript">
7594: // <![CDATA[
1.1045 www 7595: \$('#progressbar$id').progressbar({
1.1041 www 7596: value: 0,
7597: change: function(event, ui) {
7598: var newVal = \$(this).progressbar('option', 'value');
7599: \$('.pblabel', this).text(LCprogressTxt);
7600: }
7601: });
7602: // ]]>
7603: </script>
7604: ENDPROGRESS
7605: }
7606:
7607: sub LCprogressbarUpdate_script {
7608: return(<<ENDPROGRESSUPDATE);
7609: <style type="text/css">
7610: .ui-progressbar { position:relative; }
7611: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7612: </style>
7613: <script type="text/javascript">
7614: // <![CDATA[
1.1045 www 7615: var LCprogressTxt='---';
7616:
7617: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7618: LCprogressTxt=progresstext;
1.1045 www 7619: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7620: }
7621: // ]]>
7622: </script>
7623: ENDPROGRESSUPDATE
7624: }
7625:
1.1042 www 7626: my $LClastpercent;
1.1045 www 7627: my $LCidcnt;
7628: my $LCcurrentid;
1.1042 www 7629:
1.1041 www 7630: sub LCprogressbar {
1.1042 www 7631: my ($r)=(@_);
7632: $LClastpercent=0;
1.1045 www 7633: $LCidcnt++;
7634: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7635: my $starting=&mt('Starting');
7636: my $content=(<<ENDPROGBAR);
7637: <p>
1.1045 www 7638: <div id="progressbar$LCcurrentid">
1.1041 www 7639: <span class="pblabel">$starting</span>
7640: </div>
7641: </p>
7642: ENDPROGBAR
1.1045 www 7643: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7644: }
7645:
7646: sub LCprogressbarUpdate {
1.1042 www 7647: my ($r,$val,$text)=@_;
7648: unless ($val) {
7649: if ($LClastpercent) {
7650: $val=$LClastpercent;
7651: } else {
7652: $val=0;
7653: }
7654: }
1.1041 www 7655: if ($val<0) { $val=0; }
7656: if ($val>100) { $val=0; }
1.1042 www 7657: $LClastpercent=$val;
1.1041 www 7658: unless ($text) { $text=$val.'%'; }
7659: $text=&js_ready($text);
1.1044 www 7660: &r_print($r,<<ENDUPDATE);
1.1041 www 7661: <script type="text/javascript">
7662: // <![CDATA[
1.1045 www 7663: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7664: // ]]>
7665: </script>
7666: ENDUPDATE
1.1035 www 7667: }
7668:
1.1042 www 7669: sub LCprogressbarClose {
7670: my ($r)=@_;
7671: $LClastpercent=0;
1.1044 www 7672: &r_print($r,<<ENDCLOSE);
1.1042 www 7673: <script type="text/javascript">
7674: // <![CDATA[
1.1045 www 7675: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7676: // ]]>
7677: </script>
7678: ENDCLOSE
1.1044 www 7679: }
7680:
7681: sub r_print {
7682: my ($r,$to_print)=@_;
7683: if ($r) {
7684: $r->print($to_print);
7685: $r->rflush();
7686: } else {
7687: print($to_print);
7688: }
1.1042 www 7689: }
7690:
1.320 albertel 7691: sub html_encode {
7692: my ($result) = @_;
7693:
1.322 albertel 7694: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7695:
7696: return $result;
7697: }
1.1044 www 7698:
1.317 albertel 7699: sub js_ready {
7700: my ($result) = @_;
7701:
1.323 albertel 7702: $result =~ s/[\n\r]/ /xmsg;
7703: $result =~ s/\\/\\\\/xmsg;
7704: $result =~ s/'/\\'/xmsg;
1.372 albertel 7705: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7706:
7707: return $result;
7708: }
7709:
1.315 albertel 7710: sub validate_page {
7711: if ( exists($env{'internal.start_page'})
1.316 albertel 7712: && $env{'internal.start_page'} > 1) {
7713: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7714: $env{'internal.start_page'}.' '.
1.316 albertel 7715: $ENV{'request.filename'});
1.315 albertel 7716: }
7717: if ( exists($env{'internal.end_page'})
1.316 albertel 7718: && $env{'internal.end_page'} > 1) {
7719: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7720: $env{'internal.end_page'}.' '.
1.316 albertel 7721: $env{'request.filename'});
1.315 albertel 7722: }
7723: if ( exists($env{'internal.start_page'})
7724: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7725: &Apache::lonnet::logthis('start_page called without end_page '.
7726: $env{'request.filename'});
1.315 albertel 7727: }
7728: if ( ! exists($env{'internal.start_page'})
7729: && exists($env{'internal.end_page'})) {
1.316 albertel 7730: &Apache::lonnet::logthis('end_page called without start_page'.
7731: $env{'request.filename'});
1.315 albertel 7732: }
1.306 albertel 7733: }
1.315 albertel 7734:
1.996 www 7735:
7736: sub start_scrollbox {
1.1075 raeburn 7737: my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998 raeburn 7738: unless ($outerwidth) { $outerwidth='520px'; }
7739: unless ($width) { $width='500px'; }
7740: unless ($height) { $height='200px'; }
1.1075 raeburn 7741: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7742: if ($id ne '') {
1.1020 raeburn 7743: $table_id = " id='table_$id'";
7744: $div_id = " id='div_$id'";
1.1018 raeburn 7745: }
1.1075 raeburn 7746: if ($bgcolor ne '') {
7747: $tdcol = "background-color: $bgcolor;";
7748: }
7749: return <<"END";
7750: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
7751: END
1.996 www 7752: }
7753:
7754: sub end_scrollbox {
1.1036 www 7755: return '</div></td></tr></table>';
1.996 www 7756: }
7757:
1.318 albertel 7758: sub simple_error_page {
7759: my ($r,$title,$msg) = @_;
7760: my $page =
7761: &Apache::loncommon::start_page($title).
7762: &mt($msg).
7763: &Apache::loncommon::end_page();
7764: if (ref($r)) {
7765: $r->print($page);
1.327 albertel 7766: return;
1.318 albertel 7767: }
7768: return $page;
7769: }
1.347 albertel 7770:
7771: {
1.610 albertel 7772: my @row_count;
1.961 onken 7773:
7774: sub start_data_table_count {
7775: unshift(@row_count, 0);
7776: return;
7777: }
7778:
7779: sub end_data_table_count {
7780: shift(@row_count);
7781: return;
7782: }
7783:
1.347 albertel 7784: sub start_data_table {
1.1018 raeburn 7785: my ($add_class,$id) = @_;
1.422 albertel 7786: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7787: my $table_id;
7788: if (defined($id)) {
7789: $table_id = ' id="'.$id.'"';
7790: }
1.961 onken 7791: &start_data_table_count();
1.1018 raeburn 7792: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7793: }
7794:
7795: sub end_data_table {
1.961 onken 7796: &end_data_table_count();
1.389 albertel 7797: return '</table>'."\n";;
1.347 albertel 7798: }
7799:
7800: sub start_data_table_row {
1.974 wenzelju 7801: my ($add_class, $id) = @_;
1.610 albertel 7802: $row_count[0]++;
7803: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7804: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7805: $id = (' id="'.$id.'"') unless ($id eq '');
7806: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7807: }
1.471 banghart 7808:
7809: sub continue_data_table_row {
1.974 wenzelju 7810: my ($add_class, $id) = @_;
1.610 albertel 7811: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7812: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7813: $id = (' id="'.$id.'"') unless ($id eq '');
7814: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7815: }
1.347 albertel 7816:
7817: sub end_data_table_row {
1.389 albertel 7818: return '</tr>'."\n";;
1.347 albertel 7819: }
1.367 www 7820:
1.421 albertel 7821: sub start_data_table_empty_row {
1.707 bisitz 7822: # $row_count[0]++;
1.421 albertel 7823: return '<tr class="LC_empty_row" >'."\n";;
7824: }
7825:
7826: sub end_data_table_empty_row {
7827: return '</tr>'."\n";;
7828: }
7829:
1.367 www 7830: sub start_data_table_header_row {
1.389 albertel 7831: return '<tr class="LC_header_row">'."\n";;
1.367 www 7832: }
7833:
7834: sub end_data_table_header_row {
1.389 albertel 7835: return '</tr>'."\n";;
1.367 www 7836: }
1.890 droeschl 7837:
7838: sub data_table_caption {
7839: my $caption = shift;
7840: return "<caption class=\"LC_caption\">$caption</caption>";
7841: }
1.347 albertel 7842: }
7843:
1.548 albertel 7844: =pod
7845:
7846: =item * &inhibit_menu_check($arg)
7847:
7848: Checks for a inhibitmenu state and generates output to preserve it
7849:
7850: Inputs: $arg - can be any of
7851: - undef - in which case the return value is a string
7852: to add into arguments list of a uri
7853: - 'input' - in which case the return value is a HTML
7854: <form> <input> field of type hidden to
7855: preserve the value
7856: - a url - in which case the return value is the url with
7857: the neccesary cgi args added to preserve the
7858: inhibitmenu state
7859: - a ref to a url - no return value, but the string is
7860: updated to include the neccessary cgi
7861: args to preserve the inhibitmenu state
7862:
7863: =cut
7864:
7865: sub inhibit_menu_check {
7866: my ($arg) = @_;
7867: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7868: if ($arg eq 'input') {
7869: if ($env{'form.inhibitmenu'}) {
7870: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7871: } else {
7872: return
7873: }
7874: }
7875: if ($env{'form.inhibitmenu'}) {
7876: if (ref($arg)) {
7877: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7878: } elsif ($arg eq '') {
7879: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7880: } else {
7881: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7882: }
7883: }
7884: if (!ref($arg)) {
7885: return $arg;
7886: }
7887: }
7888:
1.251 albertel 7889: ###############################################
1.182 matthew 7890:
7891: =pod
7892:
1.549 albertel 7893: =back
7894:
7895: =head1 User Information Routines
7896:
7897: =over 4
7898:
1.405 albertel 7899: =item * &get_users_function()
1.182 matthew 7900:
7901: Used by &bodytag to determine the current users primary role.
7902: Returns either 'student','coordinator','admin', or 'author'.
7903:
7904: =cut
7905:
7906: ###############################################
7907: sub get_users_function {
1.815 tempelho 7908: my $function = 'norole';
1.818 tempelho 7909: if ($env{'request.role'}=~/^(st)/) {
7910: $function='student';
7911: }
1.907 raeburn 7912: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7913: $function='coordinator';
7914: }
1.258 albertel 7915: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7916: $function='admin';
7917: }
1.826 bisitz 7918: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 7919: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 7920: $function='author';
7921: }
7922: return $function;
1.54 www 7923: }
1.99 www 7924:
7925: ###############################################
7926:
1.233 raeburn 7927: =pod
7928:
1.821 raeburn 7929: =item * &show_course()
7930:
7931: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7932: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7933:
7934: Inputs:
7935: None
7936:
7937: Outputs:
7938: Scalar: 1 if 'Course' to be used, 0 otherwise.
7939:
7940: =cut
7941:
7942: ###############################################
7943: sub show_course {
7944: my $course = !$env{'user.adv'};
7945: if (!$env{'user.adv'}) {
7946: foreach my $env (keys(%env)) {
7947: next if ($env !~ m/^user\.priv\./);
7948: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7949: $course = 0;
7950: last;
7951: }
7952: }
7953: }
7954: return $course;
7955: }
7956:
7957: ###############################################
7958:
7959: =pod
7960:
1.542 raeburn 7961: =item * &check_user_status()
1.274 raeburn 7962:
7963: Determines current status of supplied role for a
7964: specific user. Roles can be active, previous or future.
7965:
7966: Inputs:
7967: user's domain, user's username, course's domain,
1.375 raeburn 7968: course's number, optional section ID.
1.274 raeburn 7969:
7970: Outputs:
7971: role status: active, previous or future.
7972:
7973: =cut
7974:
7975: sub check_user_status {
1.412 raeburn 7976: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 7977: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 7978: my @uroles = keys %userinfo;
7979: my $srchstr;
7980: my $active_chk = 'none';
1.412 raeburn 7981: my $now = time;
1.274 raeburn 7982: if (@uroles > 0) {
1.908 raeburn 7983: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7984: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7985: } else {
1.412 raeburn 7986: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7987: }
7988: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7989: my $role_end = 0;
7990: my $role_start = 0;
7991: $active_chk = 'active';
1.412 raeburn 7992: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7993: $role_end = $1;
7994: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7995: $role_start = $1;
1.274 raeburn 7996: }
7997: }
7998: if ($role_start > 0) {
1.412 raeburn 7999: if ($now < $role_start) {
1.274 raeburn 8000: $active_chk = 'future';
8001: }
8002: }
8003: if ($role_end > 0) {
1.412 raeburn 8004: if ($now > $role_end) {
1.274 raeburn 8005: $active_chk = 'previous';
8006: }
8007: }
8008: }
8009: }
8010: return $active_chk;
8011: }
8012:
8013: ###############################################
8014:
8015: =pod
8016:
1.405 albertel 8017: =item * &get_sections()
1.233 raeburn 8018:
8019: Determines all the sections for a course including
8020: sections with students and sections containing other roles.
1.419 raeburn 8021: Incoming parameters:
8022:
8023: 1. domain
8024: 2. course number
8025: 3. reference to array containing roles for which sections should
8026: be gathered (optional).
8027: 4. reference to array containing status types for which sections
8028: should be gathered (optional).
8029:
8030: If the third argument is undefined, sections are gathered for any role.
8031: If the fourth argument is undefined, sections are gathered for any status.
8032: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8033:
1.374 raeburn 8034: Returns section hash (keys are section IDs, values are
8035: number of users in each section), subject to the
1.419 raeburn 8036: optional roles filter, optional status filter
1.233 raeburn 8037:
8038: =cut
8039:
8040: ###############################################
8041: sub get_sections {
1.419 raeburn 8042: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8043: if (!defined($cdom) || !defined($cnum)) {
8044: my $cid = $env{'request.course.id'};
8045:
8046: return if (!defined($cid));
8047:
8048: $cdom = $env{'course.'.$cid.'.domain'};
8049: $cnum = $env{'course.'.$cid.'.num'};
8050: }
8051:
8052: my %sectioncount;
1.419 raeburn 8053: my $now = time;
1.240 albertel 8054:
1.366 albertel 8055: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 8056: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8057: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8058: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8059: my $start_index = &Apache::loncoursedata::CL_START();
8060: my $end_index = &Apache::loncoursedata::CL_END();
8061: my $status;
1.366 albertel 8062: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8063: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8064: $data->[$status_index],
8065: $data->[$start_index],
8066: $data->[$end_index]);
8067: if ($stu_status eq 'Active') {
8068: $status = 'active';
8069: } elsif ($end < $now) {
8070: $status = 'previous';
8071: } elsif ($start > $now) {
8072: $status = 'future';
8073: }
8074: if ($section ne '-1' && $section !~ /^\s*$/) {
8075: if ((!defined($possible_status)) || (($status ne '') &&
8076: (grep/^\Q$status\E$/,@{$possible_status}))) {
8077: $sectioncount{$section}++;
8078: }
1.240 albertel 8079: }
8080: }
8081: }
8082: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8083: foreach my $user (sort(keys(%courseroles))) {
8084: if ($user !~ /^(\w{2})/) { next; }
8085: my ($role) = ($user =~ /^(\w{2})/);
8086: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8087: my ($section,$status);
1.240 albertel 8088: if ($role eq 'cr' &&
8089: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8090: $section=$1;
8091: }
8092: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8093: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8094: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8095: if ($end == -1 && $start == -1) {
8096: next; #deleted role
8097: }
8098: if (!defined($possible_status)) {
8099: $sectioncount{$section}++;
8100: } else {
8101: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8102: $status = 'active';
8103: } elsif ($end < $now) {
8104: $status = 'future';
8105: } elsif ($start > $now) {
8106: $status = 'previous';
8107: }
8108: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8109: $sectioncount{$section}++;
8110: }
8111: }
1.233 raeburn 8112: }
1.366 albertel 8113: return %sectioncount;
1.233 raeburn 8114: }
8115:
1.274 raeburn 8116: ###############################################
1.294 raeburn 8117:
8118: =pod
1.405 albertel 8119:
8120: =item * &get_course_users()
8121:
1.275 raeburn 8122: Retrieves usernames:domains for users in the specified course
8123: with specific role(s), and access status.
8124:
8125: Incoming parameters:
1.277 albertel 8126: 1. course domain
8127: 2. course number
8128: 3. access status: users must have - either active,
1.275 raeburn 8129: previous, future, or all.
1.277 albertel 8130: 4. reference to array of permissible roles
1.288 raeburn 8131: 5. reference to array of section restrictions (optional)
8132: 6. reference to results object (hash of hashes).
8133: 7. reference to optional userdata hash
1.609 raeburn 8134: 8. reference to optional statushash
1.630 raeburn 8135: 9. flag if privileged users (except those set to unhide in
8136: course settings) should be excluded
1.609 raeburn 8137: Keys of top level results hash are roles.
1.275 raeburn 8138: Keys of inner hashes are username:domain, with
8139: values set to access type.
1.288 raeburn 8140: Optional userdata hash returns an array with arguments in the
8141: same order as loncoursedata::get_classlist() for student data.
8142:
1.609 raeburn 8143: Optional statushash returns
8144:
1.288 raeburn 8145: Entries for end, start, section and status are blank because
8146: of the possibility of multiple values for non-student roles.
8147:
1.275 raeburn 8148: =cut
1.405 albertel 8149:
1.275 raeburn 8150: ###############################################
1.405 albertel 8151:
1.275 raeburn 8152: sub get_course_users {
1.630 raeburn 8153: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8154: my %idx = ();
1.419 raeburn 8155: my %seclists;
1.288 raeburn 8156:
8157: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8158: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8159: $idx{end} = &Apache::loncoursedata::CL_END();
8160: $idx{start} = &Apache::loncoursedata::CL_START();
8161: $idx{id} = &Apache::loncoursedata::CL_ID();
8162: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8163: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8164: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8165:
1.290 albertel 8166: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8167: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8168: my $now = time;
1.277 albertel 8169: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8170: my $match = 0;
1.412 raeburn 8171: my $secmatch = 0;
1.419 raeburn 8172: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8173: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8174: if ($section eq '') {
8175: $section = 'none';
8176: }
1.291 albertel 8177: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8178: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8179: $secmatch = 1;
8180: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8181: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8182: $secmatch = 1;
8183: }
8184: } else {
1.419 raeburn 8185: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8186: $secmatch = 1;
8187: }
1.290 albertel 8188: }
1.412 raeburn 8189: if (!$secmatch) {
8190: next;
8191: }
1.419 raeburn 8192: }
1.275 raeburn 8193: if (defined($$types{'active'})) {
1.288 raeburn 8194: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8195: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8196: $match = 1;
1.275 raeburn 8197: }
8198: }
8199: if (defined($$types{'previous'})) {
1.609 raeburn 8200: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8201: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8202: $match = 1;
1.275 raeburn 8203: }
8204: }
8205: if (defined($$types{'future'})) {
1.609 raeburn 8206: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8207: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8208: $match = 1;
1.275 raeburn 8209: }
8210: }
1.609 raeburn 8211: if ($match) {
8212: push(@{$seclists{$student}},$section);
8213: if (ref($userdata) eq 'HASH') {
8214: $$userdata{$student} = $$classlist{$student};
8215: }
8216: if (ref($statushash) eq 'HASH') {
8217: $statushash->{$student}{'st'}{$section} = $status;
8218: }
1.288 raeburn 8219: }
1.275 raeburn 8220: }
8221: }
1.412 raeburn 8222: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8223: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8224: my $now = time;
1.609 raeburn 8225: my %displaystatus = ( previous => 'Expired',
8226: active => 'Active',
8227: future => 'Future',
8228: );
1.630 raeburn 8229: my %nothide;
8230: if ($hidepriv) {
8231: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8232: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8233: if ($user !~ /:/) {
8234: $nothide{join(':',split(/[\@]/,$user))}=1;
8235: } else {
8236: $nothide{$user} = 1;
8237: }
8238: }
8239: }
1.439 raeburn 8240: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8241: my $match = 0;
1.412 raeburn 8242: my $secmatch = 0;
1.439 raeburn 8243: my $status;
1.412 raeburn 8244: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8245: $user =~ s/:$//;
1.439 raeburn 8246: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8247: if ($end == -1 || $start == -1) {
8248: next;
8249: }
8250: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8251: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8252: my ($uname,$udom) = split(/:/,$user);
8253: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8254: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8255: $secmatch = 1;
8256: } elsif ($usec eq '') {
1.420 albertel 8257: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8258: $secmatch = 1;
8259: }
8260: } else {
8261: if (grep(/^\Q$usec\E$/,@{$sections})) {
8262: $secmatch = 1;
8263: }
8264: }
8265: if (!$secmatch) {
8266: next;
8267: }
1.288 raeburn 8268: }
1.419 raeburn 8269: if ($usec eq '') {
8270: $usec = 'none';
8271: }
1.275 raeburn 8272: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8273: if ($hidepriv) {
8274: if ((&Apache::lonnet::privileged($uname,$udom)) &&
8275: (!$nothide{$uname.':'.$udom})) {
8276: next;
8277: }
8278: }
1.503 raeburn 8279: if ($end > 0 && $end < $now) {
1.439 raeburn 8280: $status = 'previous';
8281: } elsif ($start > $now) {
8282: $status = 'future';
8283: } else {
8284: $status = 'active';
8285: }
1.277 albertel 8286: foreach my $type (keys(%{$types})) {
1.275 raeburn 8287: if ($status eq $type) {
1.420 albertel 8288: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8289: push(@{$$users{$role}{$user}},$type);
8290: }
1.288 raeburn 8291: $match = 1;
8292: }
8293: }
1.419 raeburn 8294: if (($match) && (ref($userdata) eq 'HASH')) {
8295: if (!exists($$userdata{$uname.':'.$udom})) {
8296: &get_user_info($udom,$uname,\%idx,$userdata);
8297: }
1.420 albertel 8298: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8299: push(@{$seclists{$uname.':'.$udom}},$usec);
8300: }
1.609 raeburn 8301: if (ref($statushash) eq 'HASH') {
8302: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8303: }
1.275 raeburn 8304: }
8305: }
8306: }
8307: }
1.290 albertel 8308: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8309: if ((defined($cdom)) && (defined($cnum))) {
8310: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8311: if ( defined($csettings{'internal.courseowner'}) ) {
8312: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8313: next if ($owner eq '');
8314: my ($ownername,$ownerdom);
8315: if ($owner =~ /^([^:]+):([^:]+)$/) {
8316: $ownername = $1;
8317: $ownerdom = $2;
8318: } else {
8319: $ownername = $owner;
8320: $ownerdom = $cdom;
8321: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8322: }
8323: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8324: if (defined($userdata) &&
1.609 raeburn 8325: !exists($$userdata{$owner})) {
8326: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8327: if (!grep(/^none$/,@{$seclists{$owner}})) {
8328: push(@{$seclists{$owner}},'none');
8329: }
8330: if (ref($statushash) eq 'HASH') {
8331: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8332: }
1.290 albertel 8333: }
1.279 raeburn 8334: }
8335: }
8336: }
1.419 raeburn 8337: foreach my $user (keys(%seclists)) {
8338: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8339: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8340: }
1.275 raeburn 8341: }
8342: return;
8343: }
8344:
1.288 raeburn 8345: sub get_user_info {
8346: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8347: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8348: &plainname($uname,$udom,'lastname');
1.291 albertel 8349: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8350: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8351: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8352: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8353: return;
8354: }
1.275 raeburn 8355:
1.472 raeburn 8356: ###############################################
8357:
8358: =pod
8359:
8360: =item * &get_user_quota()
8361:
8362: Retrieves quota assigned for storage of portfolio files for a user
8363:
8364: Incoming parameters:
8365: 1. user's username
8366: 2. user's domain
8367:
8368: Returns:
1.536 raeburn 8369: 1. Disk quota (in Mb) assigned to student.
8370: 2. (Optional) Type of setting: custom or default
8371: (individually assigned or default for user's
8372: institutional status).
8373: 3. (Optional) - User's institutional status (e.g., faculty, staff
8374: or student - types as defined in localenroll::inst_usertypes
8375: for user's domain, which determines default quota for user.
8376: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8377:
8378: If a value has been stored in the user's environment,
1.536 raeburn 8379: it will return that, otherwise it returns the maximal default
8380: defined for the user's instituional status(es) in the domain.
1.472 raeburn 8381:
8382: =cut
8383:
8384: ###############################################
8385:
8386:
8387: sub get_user_quota {
8388: my ($uname,$udom) = @_;
1.536 raeburn 8389: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8390: if (!defined($udom)) {
8391: $udom = $env{'user.domain'};
8392: }
8393: if (!defined($uname)) {
8394: $uname = $env{'user.name'};
8395: }
8396: if (($udom eq '' || $uname eq '') ||
8397: ($udom eq 'public') && ($uname eq 'public')) {
8398: $quota = 0;
1.536 raeburn 8399: $quotatype = 'default';
8400: $defquota = 0;
1.472 raeburn 8401: } else {
1.536 raeburn 8402: my $inststatus;
1.472 raeburn 8403: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8404: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 8405: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 8406: } else {
1.536 raeburn 8407: my %userenv =
8408: &Apache::lonnet::get('environment',['portfolioquota',
8409: 'inststatus'],$udom,$uname);
1.472 raeburn 8410: my ($tmp) = keys(%userenv);
8411: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8412: $quota = $userenv{'portfolioquota'};
1.536 raeburn 8413: $inststatus = $userenv{'inststatus'};
1.472 raeburn 8414: } else {
8415: undef(%userenv);
8416: }
8417: }
1.536 raeburn 8418: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 8419: if ($quota eq '') {
1.536 raeburn 8420: $quota = $defquota;
8421: $quotatype = 'default';
8422: } else {
8423: $quotatype = 'custom';
1.472 raeburn 8424: }
8425: }
1.536 raeburn 8426: if (wantarray) {
8427: return ($quota,$quotatype,$settingstatus,$defquota);
8428: } else {
8429: return $quota;
8430: }
1.472 raeburn 8431: }
8432:
8433: ###############################################
8434:
8435: =pod
8436:
8437: =item * &default_quota()
8438:
1.536 raeburn 8439: Retrieves default quota assigned for storage of user portfolio files,
8440: given an (optional) user's institutional status.
1.472 raeburn 8441:
8442: Incoming parameters:
8443: 1. domain
1.536 raeburn 8444: 2. (Optional) institutional status(es). This is a : separated list of
8445: status types (e.g., faculty, staff, student etc.)
8446: which apply to the user for whom the default is being retrieved.
8447: If the institutional status string in undefined, the domain
8448: default quota will be returned.
1.472 raeburn 8449:
8450: Returns:
8451: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8452: 2. (Optional) institutional type which determined the value of the
8453: default quota.
1.472 raeburn 8454:
8455: If a value has been stored in the domain's configuration db,
8456: it will return that, otherwise it returns 20 (for backwards
8457: compatibility with domains which have not set up a configuration
8458: db file; the original statically defined portfolio quota was 20 Mb).
8459:
1.536 raeburn 8460: If the user's status includes multiple types (e.g., staff and student),
8461: the largest default quota which applies to the user determines the
8462: default quota returned.
8463:
1.780 raeburn 8464: =back
8465:
1.472 raeburn 8466: =cut
8467:
8468: ###############################################
8469:
8470:
8471: sub default_quota {
1.536 raeburn 8472: my ($udom,$inststatus) = @_;
8473: my ($defquota,$settingstatus);
8474: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8475: ['quotas'],$udom);
8476: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8477: if ($inststatus ne '') {
1.765 raeburn 8478: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8479: foreach my $item (@statuses) {
1.711 raeburn 8480: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8481: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
8482: if ($defquota eq '') {
8483: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8484: $settingstatus = $item;
8485: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
8486: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8487: $settingstatus = $item;
8488: }
8489: }
8490: } else {
8491: if ($quotahash{'quotas'}{$item} ne '') {
8492: if ($defquota eq '') {
8493: $defquota = $quotahash{'quotas'}{$item};
8494: $settingstatus = $item;
8495: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8496: $defquota = $quotahash{'quotas'}{$item};
8497: $settingstatus = $item;
8498: }
1.536 raeburn 8499: }
8500: }
8501: }
8502: }
8503: if ($defquota eq '') {
1.711 raeburn 8504: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8505: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
8506: } else {
8507: $defquota = $quotahash{'quotas'}{'default'};
8508: }
1.536 raeburn 8509: $settingstatus = 'default';
8510: }
8511: } else {
8512: $settingstatus = 'default';
8513: $defquota = 20;
8514: }
8515: if (wantarray) {
8516: return ($defquota,$settingstatus);
1.472 raeburn 8517: } else {
1.536 raeburn 8518: return $defquota;
1.472 raeburn 8519: }
8520: }
8521:
1.384 raeburn 8522: sub get_secgrprole_info {
8523: my ($cdom,$cnum,$needroles,$type) = @_;
8524: my %sections_count = &get_sections($cdom,$cnum);
8525: my @sections = (sort {$a <=> $b} keys(%sections_count));
8526: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8527: my @groups = sort(keys(%curr_groups));
8528: my $allroles = [];
8529: my $rolehash;
8530: my $accesshash = {
8531: active => 'Currently has access',
8532: future => 'Will have future access',
8533: previous => 'Previously had access',
8534: };
8535: if ($needroles) {
8536: $rolehash = {'all' => 'all'};
1.385 albertel 8537: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8538: if (&Apache::lonnet::error(%user_roles)) {
8539: undef(%user_roles);
8540: }
8541: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8542: my ($role)=split(/\:/,$item,2);
8543: if ($role eq 'cr') { next; }
8544: if ($role =~ /^cr/) {
8545: $$rolehash{$role} = (split('/',$role))[3];
8546: } else {
8547: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8548: }
8549: }
8550: foreach my $key (sort(keys(%{$rolehash}))) {
8551: push(@{$allroles},$key);
8552: }
8553: push (@{$allroles},'st');
8554: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8555: }
8556: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8557: }
8558:
1.555 raeburn 8559: sub user_picker {
1.994 raeburn 8560: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8561: my $currdom = $dom;
8562: my %curr_selected = (
8563: srchin => 'dom',
1.580 raeburn 8564: srchby => 'lastname',
1.555 raeburn 8565: );
8566: my $srchterm;
1.625 raeburn 8567: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8568: if ($srch->{'srchby'} ne '') {
8569: $curr_selected{'srchby'} = $srch->{'srchby'};
8570: }
8571: if ($srch->{'srchin'} ne '') {
8572: $curr_selected{'srchin'} = $srch->{'srchin'};
8573: }
8574: if ($srch->{'srchtype'} ne '') {
8575: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8576: }
8577: if ($srch->{'srchdomain'} ne '') {
8578: $currdom = $srch->{'srchdomain'};
8579: }
8580: $srchterm = $srch->{'srchterm'};
8581: }
8582: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8583: 'usr' => 'Search criteria',
1.563 raeburn 8584: 'doma' => 'Domain/institution to search',
1.558 albertel 8585: 'uname' => 'username',
8586: 'lastname' => 'last name',
1.555 raeburn 8587: 'lastfirst' => 'last name, first name',
1.558 albertel 8588: 'crs' => 'in this course',
1.576 raeburn 8589: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8590: 'alc' => 'all LON-CAPA',
1.573 raeburn 8591: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8592: 'exact' => 'is',
8593: 'contains' => 'contains',
1.569 raeburn 8594: 'begins' => 'begins with',
1.571 raeburn 8595: 'youm' => "You must include some text to search for.",
8596: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8597: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8598: 'yomc' => "You must choose a domain when using an institutional directory search.",
8599: 'ymcd' => "You must choose a domain when using a domain search.",
8600: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8601: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8602: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8603: );
1.563 raeburn 8604: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8605: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8606:
8607: my @srchins = ('crs','dom','alc','instd');
8608:
8609: foreach my $option (@srchins) {
8610: # FIXME 'alc' option unavailable until
8611: # loncreateuser::print_user_query_page()
8612: # has been completed.
8613: next if ($option eq 'alc');
1.880 raeburn 8614: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8615: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8616: if ($curr_selected{'srchin'} eq $option) {
8617: $srchinsel .= '
8618: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8619: } else {
8620: $srchinsel .= '
8621: <option value="'.$option.'">'.$lt{$option}.'</option>';
8622: }
1.555 raeburn 8623: }
1.563 raeburn 8624: $srchinsel .= "\n </select>\n";
1.555 raeburn 8625:
8626: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 8627: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 8628: if ($curr_selected{'srchby'} eq $option) {
8629: $srchbysel .= '
8630: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8631: } else {
8632: $srchbysel .= '
8633: <option value="'.$option.'">'.$lt{$option}.'</option>';
8634: }
8635: }
8636: $srchbysel .= "\n </select>\n";
8637:
8638: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 8639: foreach my $option ('begins','contains','exact') {
1.555 raeburn 8640: if ($curr_selected{'srchtype'} eq $option) {
8641: $srchtypesel .= '
8642: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8643: } else {
8644: $srchtypesel .= '
8645: <option value="'.$option.'">'.$lt{$option}.'</option>';
8646: }
8647: }
8648: $srchtypesel .= "\n </select>\n";
8649:
1.558 albertel 8650: my ($newuserscript,$new_user_create);
1.994 raeburn 8651: my $context_dom = $env{'request.role.domain'};
8652: if ($context eq 'requestcrs') {
8653: if ($env{'form.coursedom'} ne '') {
8654: $context_dom = $env{'form.coursedom'};
8655: }
8656: }
1.556 raeburn 8657: if ($forcenewuser) {
1.576 raeburn 8658: if (ref($srch) eq 'HASH') {
1.994 raeburn 8659: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8660: if ($cancreate) {
8661: $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>';
8662: } else {
1.799 bisitz 8663: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8664: my %usertypetext = (
8665: official => 'institutional',
8666: unofficial => 'non-institutional',
8667: );
1.799 bisitz 8668: $new_user_create = '<p class="LC_warning">'
8669: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
8670: .' '
8671: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8672: ,'<a href="'.$helplink.'">','</a>')
8673: .'</p><br />';
1.627 raeburn 8674: }
1.576 raeburn 8675: }
8676: }
8677:
1.556 raeburn 8678: $newuserscript = <<"ENDSCRIPT";
8679:
1.570 raeburn 8680: function setSearch(createnew,callingForm) {
1.556 raeburn 8681: if (createnew == 1) {
1.570 raeburn 8682: for (var i=0; i<callingForm.srchby.length; i++) {
8683: if (callingForm.srchby.options[i].value == 'uname') {
8684: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8685: }
8686: }
1.570 raeburn 8687: for (var i=0; i<callingForm.srchin.length; i++) {
8688: if ( callingForm.srchin.options[i].value == 'dom') {
8689: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8690: }
8691: }
1.570 raeburn 8692: for (var i=0; i<callingForm.srchtype.length; i++) {
8693: if (callingForm.srchtype.options[i].value == 'exact') {
8694: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8695: }
8696: }
1.570 raeburn 8697: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 8698: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8699: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8700: }
8701: }
8702: }
8703: }
8704: ENDSCRIPT
1.558 albertel 8705:
1.556 raeburn 8706: }
8707:
1.555 raeburn 8708: my $output = <<"END_BLOCK";
1.556 raeburn 8709: <script type="text/javascript">
1.824 bisitz 8710: // <![CDATA[
1.570 raeburn 8711: function validateEntry(callingForm) {
1.558 albertel 8712:
1.556 raeburn 8713: var checkok = 1;
1.558 albertel 8714: var srchin;
1.570 raeburn 8715: for (var i=0; i<callingForm.srchin.length; i++) {
8716: if ( callingForm.srchin[i].checked ) {
8717: srchin = callingForm.srchin[i].value;
1.558 albertel 8718: }
8719: }
8720:
1.570 raeburn 8721: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8722: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8723: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8724: var srchterm = callingForm.srchterm.value;
8725: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8726: var msg = "";
8727:
8728: if (srchterm == "") {
8729: checkok = 0;
1.571 raeburn 8730: msg += "$lt{'youm'}\\n";
1.556 raeburn 8731: }
8732:
1.569 raeburn 8733: if (srchtype== 'begins') {
8734: if (srchterm.length < 2) {
8735: checkok = 0;
1.571 raeburn 8736: msg += "$lt{'thte'}\\n";
1.569 raeburn 8737: }
8738: }
8739:
1.556 raeburn 8740: if (srchtype== 'contains') {
8741: if (srchterm.length < 3) {
8742: checkok = 0;
1.571 raeburn 8743: msg += "$lt{'thet'}\\n";
1.556 raeburn 8744: }
8745: }
8746: if (srchin == 'instd') {
8747: if (srchdomain == '') {
8748: checkok = 0;
1.571 raeburn 8749: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8750: }
8751: }
8752: if (srchin == 'dom') {
8753: if (srchdomain == '') {
8754: checkok = 0;
1.571 raeburn 8755: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8756: }
8757: }
8758: if (srchby == 'lastfirst') {
8759: if (srchterm.indexOf(",") == -1) {
8760: checkok = 0;
1.571 raeburn 8761: msg += "$lt{'whus'}\\n";
1.556 raeburn 8762: }
8763: if (srchterm.indexOf(",") == srchterm.length -1) {
8764: checkok = 0;
1.571 raeburn 8765: msg += "$lt{'whse'}\\n";
1.556 raeburn 8766: }
8767: }
8768: if (checkok == 0) {
1.571 raeburn 8769: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8770: return;
8771: }
8772: if (checkok == 1) {
1.570 raeburn 8773: callingForm.submit();
1.556 raeburn 8774: }
8775: }
8776:
8777: $newuserscript
8778:
1.824 bisitz 8779: // ]]>
1.556 raeburn 8780: </script>
1.558 albertel 8781:
8782: $new_user_create
8783:
1.555 raeburn 8784: END_BLOCK
1.558 albertel 8785:
1.876 raeburn 8786: $output .= &Apache::lonhtmlcommon::start_pick_box().
8787: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8788: $domform.
8789: &Apache::lonhtmlcommon::row_closure().
8790: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8791: $srchbysel.
8792: $srchtypesel.
8793: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8794: $srchinsel.
8795: &Apache::lonhtmlcommon::row_closure(1).
8796: &Apache::lonhtmlcommon::end_pick_box().
8797: '<br />';
1.555 raeburn 8798: return $output;
8799: }
8800:
1.612 raeburn 8801: sub user_rule_check {
1.615 raeburn 8802: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8803: my $response;
8804: if (ref($usershash) eq 'HASH') {
8805: foreach my $user (keys(%{$usershash})) {
8806: my ($uname,$udom) = split(/:/,$user);
8807: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8808: my ($id,$newuser);
1.612 raeburn 8809: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8810: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8811: $id = $usershash->{$user}->{'id'};
8812: }
8813: my $inst_response;
8814: if (ref($checks) eq 'HASH') {
8815: if (defined($checks->{'username'})) {
1.615 raeburn 8816: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8817: &Apache::lonnet::get_instuser($udom,$uname);
8818: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8819: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8820: &Apache::lonnet::get_instuser($udom,undef,$id);
8821: }
1.615 raeburn 8822: } else {
8823: ($inst_response,%{$inst_results->{$user}}) =
8824: &Apache::lonnet::get_instuser($udom,$uname);
8825: return;
1.612 raeburn 8826: }
1.615 raeburn 8827: if (!$got_rules->{$udom}) {
1.612 raeburn 8828: my %domconfig = &Apache::lonnet::get_dom('configuration',
8829: ['usercreation'],$udom);
8830: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8831: foreach my $item ('username','id') {
1.612 raeburn 8832: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8833: $$curr_rules{$udom}{$item} =
8834: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8835: }
8836: }
8837: }
1.615 raeburn 8838: $got_rules->{$udom} = 1;
1.585 raeburn 8839: }
1.612 raeburn 8840: foreach my $item (keys(%{$checks})) {
8841: if (ref($$curr_rules{$udom}) eq 'HASH') {
8842: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8843: if (@{$$curr_rules{$udom}{$item}} > 0) {
8844: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8845: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8846: if ($rule_check{$rule}) {
8847: $$rulematch{$user}{$item} = $rule;
8848: if ($inst_response eq 'ok') {
1.615 raeburn 8849: if (ref($inst_results) eq 'HASH') {
8850: if (ref($inst_results->{$user}) eq 'HASH') {
8851: if (keys(%{$inst_results->{$user}}) == 0) {
8852: $$alerts{$item}{$udom}{$uname} = 1;
8853: }
1.612 raeburn 8854: }
8855: }
1.615 raeburn 8856: }
8857: last;
1.585 raeburn 8858: }
8859: }
8860: }
8861: }
8862: }
8863: }
8864: }
8865: }
1.612 raeburn 8866: return;
8867: }
8868:
8869: sub user_rule_formats {
8870: my ($domain,$domdesc,$curr_rules,$check) = @_;
8871: my %text = (
8872: 'username' => 'Usernames',
8873: 'id' => 'IDs',
8874: );
8875: my $output;
8876: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8877: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8878: if (@{$ruleorder} > 0) {
8879: $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>';
8880: foreach my $rule (@{$ruleorder}) {
8881: if (ref($curr_rules) eq 'ARRAY') {
8882: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8883: if (ref($rules->{$rule}) eq 'HASH') {
8884: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8885: $rules->{$rule}{'desc'}.'</li>';
8886: }
8887: }
8888: }
8889: }
8890: $output .= '</ul>';
8891: }
8892: }
8893: return $output;
8894: }
8895:
8896: sub instrule_disallow_msg {
1.615 raeburn 8897: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8898: my $response;
8899: my %text = (
8900: item => 'username',
8901: items => 'usernames',
8902: match => 'matches',
8903: do => 'does',
8904: action => 'a username',
8905: one => 'one',
8906: );
8907: if ($count > 1) {
8908: $text{'item'} = 'usernames';
8909: $text{'match'} ='match';
8910: $text{'do'} = 'do';
8911: $text{'action'} = 'usernames',
8912: $text{'one'} = 'ones';
8913: }
8914: if ($checkitem eq 'id') {
8915: $text{'items'} = 'IDs';
8916: $text{'item'} = 'ID';
8917: $text{'action'} = 'an ID';
1.615 raeburn 8918: if ($count > 1) {
8919: $text{'item'} = 'IDs';
8920: $text{'action'} = 'IDs';
8921: }
1.612 raeburn 8922: }
1.674 bisitz 8923: $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 8924: if ($mode eq 'upload') {
8925: if ($checkitem eq 'username') {
8926: $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'}.");
8927: } elsif ($checkitem eq 'id') {
1.674 bisitz 8928: $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 8929: }
1.669 raeburn 8930: } elsif ($mode eq 'selfcreate') {
8931: if ($checkitem eq 'id') {
8932: $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.");
8933: }
1.615 raeburn 8934: } else {
8935: if ($checkitem eq 'username') {
8936: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8937: } elsif ($checkitem eq 'id') {
8938: $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.");
8939: }
1.612 raeburn 8940: }
8941: return $response;
1.585 raeburn 8942: }
8943:
1.624 raeburn 8944: sub personal_data_fieldtitles {
8945: my %fieldtitles = &Apache::lonlocal::texthash (
8946: id => 'Student/Employee ID',
8947: permanentemail => 'E-mail address',
8948: lastname => 'Last Name',
8949: firstname => 'First Name',
8950: middlename => 'Middle Name',
8951: generation => 'Generation',
8952: gen => 'Generation',
1.765 raeburn 8953: inststatus => 'Affiliation',
1.624 raeburn 8954: );
8955: return %fieldtitles;
8956: }
8957:
1.642 raeburn 8958: sub sorted_inst_types {
8959: my ($dom) = @_;
8960: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8961: my $othertitle = &mt('All users');
8962: if ($env{'request.course.id'}) {
1.668 raeburn 8963: $othertitle = &mt('Any users');
1.642 raeburn 8964: }
8965: my @types;
8966: if (ref($order) eq 'ARRAY') {
8967: @types = @{$order};
8968: }
8969: if (@types == 0) {
8970: if (ref($usertypes) eq 'HASH') {
8971: @types = sort(keys(%{$usertypes}));
8972: }
8973: }
8974: if (keys(%{$usertypes}) > 0) {
8975: $othertitle = &mt('Other users');
8976: }
8977: return ($othertitle,$usertypes,\@types);
8978: }
8979:
1.645 raeburn 8980: sub get_institutional_codes {
8981: my ($settings,$allcourses,$LC_code) = @_;
8982: # Get complete list of course sections to update
8983: my @currsections = ();
8984: my @currxlists = ();
8985: my $coursecode = $$settings{'internal.coursecode'};
8986:
8987: if ($$settings{'internal.sectionnums'} ne '') {
8988: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8989: }
8990:
8991: if ($$settings{'internal.crosslistings'} ne '') {
8992: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8993: }
8994:
8995: if (@currxlists > 0) {
8996: foreach (@currxlists) {
8997: if (m/^([^:]+):(\w*)$/) {
8998: unless (grep/^$1$/,@{$allcourses}) {
8999: push @{$allcourses},$1;
9000: $$LC_code{$1} = $2;
9001: }
9002: }
9003: }
9004: }
9005:
9006: if (@currsections > 0) {
9007: foreach (@currsections) {
9008: if (m/^(\w+):(\w*)$/) {
9009: my $sec = $coursecode.$1;
9010: my $lc_sec = $2;
9011: unless (grep/^$sec$/,@{$allcourses}) {
9012: push @{$allcourses},$sec;
9013: $$LC_code{$sec} = $lc_sec;
9014: }
9015: }
9016: }
9017: }
9018: return;
9019: }
9020:
1.971 raeburn 9021: sub get_standard_codeitems {
9022: return ('Year','Semester','Department','Number','Section');
9023: }
9024:
1.112 bowersj2 9025: =pod
9026:
1.780 raeburn 9027: =head1 Slot Helpers
9028:
9029: =over 4
9030:
9031: =item * sorted_slots()
9032:
1.1040 raeburn 9033: Sorts an array of slot names in order of an optional sort key,
9034: default sort is by slot start time (earliest first).
1.780 raeburn 9035:
9036: Inputs:
9037:
9038: =over 4
9039:
9040: slotsarr - Reference to array of unsorted slot names.
9041:
9042: slots - Reference to hash of hash, where outer hash keys are slot names.
9043:
1.1040 raeburn 9044: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9045:
1.549 albertel 9046: =back
9047:
1.780 raeburn 9048: Returns:
9049:
9050: =over 4
9051:
1.1040 raeburn 9052: sorted - An array of slot names sorted by a specified sort key
9053: (default sort key is start time of the slot).
1.780 raeburn 9054:
9055: =back
9056:
9057: =cut
9058:
9059:
9060: sub sorted_slots {
1.1040 raeburn 9061: my ($slotsarr,$slots,$sortkey) = @_;
9062: if ($sortkey eq '') {
9063: $sortkey = 'starttime';
9064: }
1.780 raeburn 9065: my @sorted;
9066: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9067: @sorted =
9068: sort {
9069: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9070: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9071: }
9072: if (ref($slots->{$a})) { return -1;}
9073: if (ref($slots->{$b})) { return 1;}
9074: return 0;
9075: } @{$slotsarr};
9076: }
9077: return @sorted;
9078: }
9079:
1.1040 raeburn 9080: =pod
9081:
9082: =item * get_future_slots()
9083:
9084: Inputs:
9085:
9086: =over 4
9087:
9088: cnum - course number
9089:
9090: cdom - course domain
9091:
9092: now - current UNIX time
9093:
9094: symb - optional symb
9095:
9096: =back
9097:
9098: Returns:
9099:
9100: =over 4
9101:
9102: sorted_reservable - ref to array of student_schedulable slots currently
9103: reservable, ordered by end date of reservation period.
9104:
9105: reservable_now - ref to hash of student_schedulable slots currently
9106: reservable.
9107:
9108: Keys in inner hash are:
9109: (a) symb: either blank or symb to which slot use is restricted.
9110: (b) endreserve: end date of reservation period.
9111:
9112: sorted_future - ref to array of student_schedulable slots reservable in
9113: the future, ordered by start date of reservation period.
9114:
9115: future_reservable - ref to hash of student_schedulable slots reservable
9116: in the future.
9117:
9118: Keys in inner hash are:
9119: (a) symb: either blank or symb to which slot use is restricted.
9120: (b) startreserve: start date of reservation period.
9121:
9122: =back
9123:
9124: =cut
9125:
9126: sub get_future_slots {
9127: my ($cnum,$cdom,$now,$symb) = @_;
9128: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9129: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9130: foreach my $slot (keys(%slots)) {
9131: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9132: if ($symb) {
9133: next if (($slots{$slot}->{'symb'} ne '') &&
9134: ($slots{$slot}->{'symb'} ne $symb));
9135: }
9136: if (($slots{$slot}->{'starttime'} > $now) &&
9137: ($slots{$slot}->{'endtime'} > $now)) {
9138: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9139: my $userallowed = 0;
9140: if ($slots{$slot}->{'allowedsections'}) {
9141: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9142: if (!defined($env{'request.role.sec'})
9143: && grep(/^No section assigned$/,@allowed_sec)) {
9144: $userallowed=1;
9145: } else {
9146: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9147: $userallowed=1;
9148: }
9149: }
9150: unless ($userallowed) {
9151: if (defined($env{'request.course.groups'})) {
9152: my @groups = split(/:/,$env{'request.course.groups'});
9153: foreach my $group (@groups) {
9154: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9155: $userallowed=1;
9156: last;
9157: }
9158: }
9159: }
9160: }
9161: }
9162: if ($slots{$slot}->{'allowedusers'}) {
9163: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9164: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9165: if (grep(/^\Q$user\E$/,@allowed_users)) {
9166: $userallowed = 1;
9167: }
9168: }
9169: next unless($userallowed);
9170: }
9171: my $startreserve = $slots{$slot}->{'startreserve'};
9172: my $endreserve = $slots{$slot}->{'endreserve'};
9173: my $symb = $slots{$slot}->{'symb'};
9174: if (($startreserve < $now) &&
9175: (!$endreserve || $endreserve > $now)) {
9176: my $lastres = $endreserve;
9177: if (!$lastres) {
9178: $lastres = $slots{$slot}->{'starttime'};
9179: }
9180: $reservable_now{$slot} = {
9181: symb => $symb,
9182: endreserve => $lastres
9183: };
9184: } elsif (($startreserve > $now) &&
9185: (!$endreserve || $endreserve > $startreserve)) {
9186: $future_reservable{$slot} = {
9187: symb => $symb,
9188: startreserve => $startreserve
9189: };
9190: }
9191: }
9192: }
9193: my @unsorted_reservable = keys(%reservable_now);
9194: if (@unsorted_reservable > 0) {
9195: @sorted_reservable =
9196: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9197: }
9198: my @unsorted_future = keys(%future_reservable);
9199: if (@unsorted_future > 0) {
9200: @sorted_future =
9201: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9202: }
9203: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9204: }
1.780 raeburn 9205:
9206: =pod
9207:
1.1057 foxr 9208: =back
9209:
1.549 albertel 9210: =head1 HTTP Helpers
9211:
9212: =over 4
9213:
1.648 raeburn 9214: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9215:
1.258 albertel 9216: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9217: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9218: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9219:
9220: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9221: $possible_names is an ref to an array of form element names. As an example:
9222: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9223: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9224:
9225: =cut
1.1 albertel 9226:
1.6 albertel 9227: sub get_unprocessed_cgi {
1.25 albertel 9228: my ($query,$possible_names)= @_;
1.26 matthew 9229: # $Apache::lonxml::debug=1;
1.356 albertel 9230: foreach my $pair (split(/&/,$query)) {
9231: my ($name, $value) = split(/=/,$pair);
1.369 www 9232: $name = &unescape($name);
1.25 albertel 9233: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9234: $value =~ tr/+/ /;
9235: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9236: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9237: }
1.16 harris41 9238: }
1.6 albertel 9239: }
9240:
1.112 bowersj2 9241: =pod
9242:
1.648 raeburn 9243: =item * &cacheheader()
1.112 bowersj2 9244:
9245: returns cache-controlling header code
9246:
9247: =cut
9248:
1.7 albertel 9249: sub cacheheader {
1.258 albertel 9250: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9251: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9252: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9253: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9254: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9255: return $output;
1.7 albertel 9256: }
9257:
1.112 bowersj2 9258: =pod
9259:
1.648 raeburn 9260: =item * &no_cache($r)
1.112 bowersj2 9261:
9262: specifies header code to not have cache
9263:
9264: =cut
9265:
1.9 albertel 9266: sub no_cache {
1.216 albertel 9267: my ($r) = @_;
9268: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9269: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9270: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9271: $r->no_cache(1);
9272: $r->header_out("Expires" => $date);
9273: $r->header_out("Pragma" => "no-cache");
1.123 www 9274: }
9275:
9276: sub content_type {
1.181 albertel 9277: my ($r,$type,$charset) = @_;
1.299 foxr 9278: if ($r) {
9279: # Note that printout.pl calls this with undef for $r.
9280: &no_cache($r);
9281: }
1.258 albertel 9282: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9283: unless ($charset) {
9284: $charset=&Apache::lonlocal::current_encoding;
9285: }
9286: if ($charset) { $type.='; charset='.$charset; }
9287: if ($r) {
9288: $r->content_type($type);
9289: } else {
9290: print("Content-type: $type\n\n");
9291: }
1.9 albertel 9292: }
1.25 albertel 9293:
1.112 bowersj2 9294: =pod
9295:
1.648 raeburn 9296: =item * &add_to_env($name,$value)
1.112 bowersj2 9297:
1.258 albertel 9298: adds $name to the %env hash with value
1.112 bowersj2 9299: $value, if $name already exists, the entry is converted to an array
9300: reference and $value is added to the array.
9301:
9302: =cut
9303:
1.25 albertel 9304: sub add_to_env {
9305: my ($name,$value)=@_;
1.258 albertel 9306: if (defined($env{$name})) {
9307: if (ref($env{$name})) {
1.25 albertel 9308: #already have multiple values
1.258 albertel 9309: push(@{ $env{$name} },$value);
1.25 albertel 9310: } else {
9311: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9312: my $first=$env{$name};
9313: undef($env{$name});
9314: push(@{ $env{$name} },$first,$value);
1.25 albertel 9315: }
9316: } else {
1.258 albertel 9317: $env{$name}=$value;
1.25 albertel 9318: }
1.31 albertel 9319: }
1.149 albertel 9320:
9321: =pod
9322:
1.648 raeburn 9323: =item * &get_env_multiple($name)
1.149 albertel 9324:
1.258 albertel 9325: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9326: values may be defined and end up as an array ref.
9327:
9328: returns an array of values
9329:
9330: =cut
9331:
9332: sub get_env_multiple {
9333: my ($name) = @_;
9334: my @values;
1.258 albertel 9335: if (defined($env{$name})) {
1.149 albertel 9336: # exists is it an array
1.258 albertel 9337: if (ref($env{$name})) {
9338: @values=@{ $env{$name} };
1.149 albertel 9339: } else {
1.258 albertel 9340: $values[0]=$env{$name};
1.149 albertel 9341: }
9342: }
9343: return(@values);
9344: }
9345:
1.660 raeburn 9346: sub ask_for_embedded_content {
9347: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9348: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9349: %currsubfile,%unused,$rem);
1.1071 raeburn 9350: my $counter = 0;
9351: my $numnew = 0;
1.987 raeburn 9352: my $numremref = 0;
9353: my $numinvalid = 0;
9354: my $numpathchg = 0;
9355: my $numexisting = 0;
1.1071 raeburn 9356: my $numunused = 0;
9357: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9358: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9359: my $heading = &mt('Upload embedded files');
9360: my $buttontext = &mt('Upload');
9361:
1.1085 raeburn 9362: my $navmap;
9363: if ($env{'request.course.id'}) {
9364: $navmap = Apache::lonnavmaps::navmap->new();
9365: }
1.984 raeburn 9366: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9367: my $current_path='/';
9368: if ($env{'form.currentpath'}) {
9369: $current_path = $env{'form.currentpath'};
9370: }
9371: if ($actionurl eq '/adm/coursegrp_portfolio') {
9372: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9373: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
9374: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9375: } else {
9376: $udom = $env{'user.domain'};
9377: $uname = $env{'user.name'};
9378: $url = '/userfiles/portfolio';
9379: }
1.987 raeburn 9380: $toplevel = $url.'/';
1.984 raeburn 9381: $url .= $current_path;
9382: $getpropath = 1;
1.987 raeburn 9383: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9384: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9385: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9386: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9387: $toplevel = $url;
1.984 raeburn 9388: if ($rest ne '') {
1.987 raeburn 9389: $url .= $rest;
9390: }
9391: } elsif ($actionurl eq '/adm/coursedocs') {
9392: if (ref($args) eq 'HASH') {
1.1071 raeburn 9393: $url = $args->{'docs_url'};
9394: $toplevel = $url;
1.1084 raeburn 9395: if ($args->{'context'} eq 'paste') {
9396: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9397: ($path) =
9398: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9399: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9400: $fileloc =~ s{^/}{};
9401: }
1.1071 raeburn 9402: }
1.1084 raeburn 9403: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9404: if ($env{'request.course.id'} ne '') {
9405: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9406: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9407: if (ref($args) eq 'HASH') {
9408: $url = $args->{'docs_url'};
9409: $title = $args->{'docs_title'};
9410: $toplevel = "/$url";
1.1085 raeburn 9411: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071 raeburn 9412: ($path) =
9413: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9414: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9415: $fileloc =~ s{^/}{};
9416: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9417: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9418: }
1.987 raeburn 9419: }
9420: }
9421: my $now = time();
9422: foreach my $embed_file (keys(%{$allfiles})) {
9423: my $absolutepath;
9424: if ($embed_file =~ m{^\w+://}) {
9425: $newfiles{$embed_file} = 1;
9426: $mapping{$embed_file} = $embed_file;
9427: } else {
9428: if ($embed_file =~ m{^/}) {
9429: $absolutepath = $embed_file;
9430: $embed_file =~ s{^(/+)}{};
9431: }
9432: if ($embed_file =~ m{/}) {
9433: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9434: $path = &check_for_traversal($path,$url,$toplevel);
9435: my $item = $fname;
9436: if ($path ne '') {
9437: $item = $path.'/'.$fname;
9438: $subdependencies{$path}{$fname} = 1;
9439: } else {
9440: $dependencies{$item} = 1;
9441: }
9442: if ($absolutepath) {
9443: $mapping{$item} = $absolutepath;
9444: } else {
9445: $mapping{$item} = $embed_file;
9446: }
9447: } else {
9448: $dependencies{$embed_file} = 1;
9449: if ($absolutepath) {
9450: $mapping{$embed_file} = $absolutepath;
9451: } else {
9452: $mapping{$embed_file} = $embed_file;
9453: }
9454: }
1.984 raeburn 9455: }
9456: }
1.1071 raeburn 9457: my $dirptr = 16384;
1.984 raeburn 9458: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9459: $currsubfile{$path} = {};
1.984 raeburn 9460: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9461: my ($sublistref,$listerror) =
9462: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9463: if (ref($sublistref) eq 'ARRAY') {
9464: foreach my $line (@{$sublistref}) {
9465: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9466: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9467: }
1.984 raeburn 9468: }
1.987 raeburn 9469: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9470: if (opendir(my $dir,$url.'/'.$path)) {
9471: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9472: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9473: }
1.1084 raeburn 9474: } elsif (($actionurl eq '/adm/dependencies') ||
9475: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9476: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9477: if ($env{'request.course.id'} ne '') {
9478: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9479: if ($dir ne '') {
9480: my ($sublistref,$listerror) =
9481: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9482: if (ref($sublistref) eq 'ARRAY') {
9483: foreach my $line (@{$sublistref}) {
9484: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9485: undef,$mtime)=split(/\&/,$line,12);
9486: unless (($testdir&$dirptr) ||
9487: ($file_name =~ /^\.\.?$/)) {
9488: $currsubfile{$path}{$file_name} = [$size,$mtime];
9489: }
9490: }
9491: }
9492: }
1.984 raeburn 9493: }
9494: }
9495: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9496: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9497: my $item = $path.'/'.$file;
9498: unless ($mapping{$item} eq $item) {
9499: $pathchanges{$item} = 1;
9500: }
9501: $existing{$item} = 1;
9502: $numexisting ++;
9503: } else {
9504: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9505: }
9506: }
1.1071 raeburn 9507: if ($actionurl eq '/adm/dependencies') {
9508: foreach my $path (keys(%currsubfile)) {
9509: if (ref($currsubfile{$path}) eq 'HASH') {
9510: foreach my $file (keys(%{$currsubfile{$path}})) {
9511: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9512: next if (($rem ne '') &&
9513: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9514: (ref($navmap) &&
9515: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9516: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9517: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9518: $unused{$path.'/'.$file} = 1;
9519: }
9520: }
9521: }
9522: }
9523: }
1.984 raeburn 9524: }
1.987 raeburn 9525: my %currfile;
1.984 raeburn 9526: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9527: my ($dirlistref,$listerror) =
9528: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9529: if (ref($dirlistref) eq 'ARRAY') {
9530: foreach my $line (@{$dirlistref}) {
9531: my ($file_name,$rest) = split(/\&/,$line,2);
9532: $currfile{$file_name} = 1;
9533: }
1.984 raeburn 9534: }
1.987 raeburn 9535: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9536: if (opendir(my $dir,$url)) {
1.987 raeburn 9537: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9538: map {$currfile{$_} = 1;} @dir_list;
9539: }
1.1084 raeburn 9540: } elsif (($actionurl eq '/adm/dependencies') ||
9541: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9542: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9543: if ($env{'request.course.id'} ne '') {
9544: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9545: if ($dir ne '') {
9546: my ($dirlistref,$listerror) =
9547: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9548: if (ref($dirlistref) eq 'ARRAY') {
9549: foreach my $line (@{$dirlistref}) {
9550: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9551: $size,undef,$mtime)=split(/\&/,$line,12);
9552: unless (($testdir&$dirptr) ||
9553: ($file_name =~ /^\.\.?$/)) {
9554: $currfile{$file_name} = [$size,$mtime];
9555: }
9556: }
9557: }
9558: }
9559: }
1.984 raeburn 9560: }
9561: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9562: if (exists($currfile{$file})) {
1.987 raeburn 9563: unless ($mapping{$file} eq $file) {
9564: $pathchanges{$file} = 1;
9565: }
9566: $existing{$file} = 1;
9567: $numexisting ++;
9568: } else {
1.984 raeburn 9569: $newfiles{$file} = 1;
9570: }
9571: }
1.1071 raeburn 9572: foreach my $file (keys(%currfile)) {
9573: unless (($file eq $filename) ||
9574: ($file eq $filename.'.bak') ||
9575: ($dependencies{$file})) {
1.1085 raeburn 9576: if ($actionurl eq '/adm/dependencies') {
9577: next if (($rem ne '') &&
9578: (($env{"httpref.$rem".$file} ne '') ||
9579: (ref($navmap) &&
9580: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9581: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9582: ($navmap->getResourceByUrl($rem.$1)))))));
9583: }
1.1071 raeburn 9584: $unused{$file} = 1;
9585: }
9586: }
1.1084 raeburn 9587: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9588: ($args->{'context'} eq 'paste')) {
9589: $counter = scalar(keys(%existing));
9590: $numpathchg = scalar(keys(%pathchanges));
9591: return ($output,$counter,$numpathchg,\%existing);
9592: }
1.984 raeburn 9593: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 9594: if ($actionurl eq '/adm/dependencies') {
9595: next if ($embed_file =~ m{^\w+://});
9596: }
1.660 raeburn 9597: $upload_output .= &start_data_table_row().
1.1071 raeburn 9598: '<td><img src="'.&icon($embed_file).'" /> '.
9599: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 9600: unless ($mapping{$embed_file} eq $embed_file) {
9601: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
9602: }
9603: $upload_output .= '</td><td>';
1.1071 raeburn 9604: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.660 raeburn 9605: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 9606: $numremref++;
1.660 raeburn 9607: } elsif ($args->{'error_on_invalid_names'}
9608: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987 raeburn 9609: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
9610: $numinvalid++;
1.660 raeburn 9611: } else {
1.1071 raeburn 9612: $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 9613: $embed_file,\%mapping,
1.1071 raeburn 9614: $allfiles,$codebase,'upload');
9615: $counter ++;
9616: $numnew ++;
1.987 raeburn 9617: }
9618: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
9619: }
9620: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 9621: if ($actionurl eq '/adm/dependencies') {
9622: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
9623: $modify_output .= &start_data_table_row().
9624: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
9625: '<img src="'.&icon($embed_file).'" border="0" />'.
9626: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
9627: '<td>'.$size.'</td>'.
9628: '<td>'.$mtime.'</td>'.
9629: '<td><label><input type="checkbox" name="mod_upload_dep" '.
9630: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
9631: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
9632: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
9633: &embedded_file_element('upload_embedded',$counter,
9634: $embed_file,\%mapping,
9635: $allfiles,$codebase,'modify').
9636: '</div></td>'.
9637: &end_data_table_row()."\n";
9638: $counter ++;
9639: } else {
9640: $upload_output .= &start_data_table_row().
9641: '<td><span class="LC_filename">'.$embed_file.'</span></td>';
9642: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
9643: &Apache::loncommon::end_data_table_row()."\n";
9644: }
9645: }
9646: my $delidx = $counter;
9647: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
9648: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
9649: $delete_output .= &start_data_table_row().
9650: '<td><img src="'.&icon($oldfile).'" />'.
9651: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
9652: '<td>'.$size.'</td>'.
9653: '<td>'.$mtime.'</td>'.
9654: '<td><label><input type="checkbox" name="del_upload_dep" '.
9655: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
9656: &embedded_file_element('upload_embedded',$delidx,
9657: $oldfile,\%mapping,$allfiles,
9658: $codebase,'delete').'</td>'.
9659: &end_data_table_row()."\n";
9660: $numunused ++;
9661: $delidx ++;
1.987 raeburn 9662: }
9663: if ($upload_output) {
9664: $upload_output = &start_data_table().
9665: $upload_output.
9666: &end_data_table()."\n";
9667: }
1.1071 raeburn 9668: if ($modify_output) {
9669: $modify_output = &start_data_table().
9670: &start_data_table_header_row().
9671: '<th>'.&mt('File').'</th>'.
9672: '<th>'.&mt('Size (KB)').'</th>'.
9673: '<th>'.&mt('Modified').'</th>'.
9674: '<th>'.&mt('Upload replacement?').'</th>'.
9675: &end_data_table_header_row().
9676: $modify_output.
9677: &end_data_table()."\n";
9678: }
9679: if ($delete_output) {
9680: $delete_output = &start_data_table().
9681: &start_data_table_header_row().
9682: '<th>'.&mt('File').'</th>'.
9683: '<th>'.&mt('Size (KB)').'</th>'.
9684: '<th>'.&mt('Modified').'</th>'.
9685: '<th>'.&mt('Delete?').'</th>'.
9686: &end_data_table_header_row().
9687: $delete_output.
9688: &end_data_table()."\n";
9689: }
1.987 raeburn 9690: my $applies = 0;
9691: if ($numremref) {
9692: $applies ++;
9693: }
9694: if ($numinvalid) {
9695: $applies ++;
9696: }
9697: if ($numexisting) {
9698: $applies ++;
9699: }
1.1071 raeburn 9700: if ($counter || $numunused) {
1.987 raeburn 9701: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
9702: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 9703: $state.'<h3>'.$heading.'</h3>';
9704: if ($actionurl eq '/adm/dependencies') {
9705: if ($numnew) {
9706: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
9707: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
9708: $upload_output.'<br />'."\n";
9709: }
9710: if ($numexisting) {
9711: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
9712: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
9713: $modify_output.'<br />'."\n";
9714: $buttontext = &mt('Save changes');
9715: }
9716: if ($numunused) {
9717: $output .= '<h4>'.&mt('Unused files').'</h4>'.
9718: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
9719: $delete_output.'<br />'."\n";
9720: $buttontext = &mt('Save changes');
9721: }
9722: } else {
9723: $output .= $upload_output.'<br />'."\n";
9724: }
9725: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
9726: $counter.'" />'."\n";
9727: if ($actionurl eq '/adm/dependencies') {
9728: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
9729: $numnew.'" />'."\n";
9730: } elsif ($actionurl eq '') {
1.987 raeburn 9731: $output .= '<input type="hidden" name="phase" value="three" />';
9732: }
9733: } elsif ($applies) {
9734: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
9735: if ($applies > 1) {
9736: $output .=
9737: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
9738: if ($numremref) {
9739: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
9740: }
9741: if ($numinvalid) {
9742: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
9743: }
9744: if ($numexisting) {
9745: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
9746: }
9747: $output .= '</ul><br />';
9748: } elsif ($numremref) {
9749: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
9750: } elsif ($numinvalid) {
9751: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
9752: } elsif ($numexisting) {
9753: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
9754: }
9755: $output .= $upload_output.'<br />';
9756: }
9757: my ($pathchange_output,$chgcount);
1.1071 raeburn 9758: $chgcount = $counter;
1.987 raeburn 9759: if (keys(%pathchanges) > 0) {
9760: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 9761: if ($counter) {
1.987 raeburn 9762: $output .= &embedded_file_element('pathchange',$chgcount,
9763: $embed_file,\%mapping,
1.1071 raeburn 9764: $allfiles,$codebase,'change');
1.987 raeburn 9765: } else {
9766: $pathchange_output .=
9767: &start_data_table_row().
9768: '<td><input type ="checkbox" name="namechange" value="'.
9769: $chgcount.'" checked="checked" /></td>'.
9770: '<td>'.$mapping{$embed_file}.'</td>'.
9771: '<td>'.$embed_file.
9772: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 9773: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 9774: '</td>'.&end_data_table_row();
1.660 raeburn 9775: }
1.987 raeburn 9776: $numpathchg ++;
9777: $chgcount ++;
1.660 raeburn 9778: }
9779: }
1.1071 raeburn 9780: if ($counter) {
1.987 raeburn 9781: if ($numpathchg) {
9782: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
9783: $numpathchg.'" />'."\n";
9784: }
9785: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9786: ($actionurl eq '/adm/imsimport')) {
9787: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
9788: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
9789: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 9790: } elsif ($actionurl eq '/adm/dependencies') {
9791: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 9792: }
1.1071 raeburn 9793: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 9794: } elsif ($numpathchg) {
9795: my %pathchange = ();
9796: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
9797: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9798: $output .= '<p>'.&mt('or').'</p>';
9799: }
9800: }
1.1071 raeburn 9801: return ($output,$counter,$numpathchg);
1.987 raeburn 9802: }
9803:
9804: sub embedded_file_element {
1.1071 raeburn 9805: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 9806: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
9807: (ref($codebase) eq 'HASH'));
9808: my $output;
1.1071 raeburn 9809: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 9810: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
9811: }
9812: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
9813: &escape($embed_file).'" />';
9814: unless (($context eq 'upload_embedded') &&
9815: ($mapping->{$embed_file} eq $embed_file)) {
9816: $output .='
9817: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
9818: }
9819: my $attrib;
9820: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
9821: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
9822: }
9823: $output .=
9824: "\n\t\t".
9825: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
9826: $attrib.'" />';
9827: if (exists($codebase->{$mapping->{$embed_file}})) {
9828: $output .=
9829: "\n\t\t".
9830: '<input name="codebase_'.$num.'" type="hidden" value="'.
9831: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 9832: }
1.987 raeburn 9833: return $output;
1.660 raeburn 9834: }
9835:
1.1071 raeburn 9836: sub get_dependency_details {
9837: my ($currfile,$currsubfile,$embed_file) = @_;
9838: my ($size,$mtime,$showsize,$showmtime);
9839: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
9840: if ($embed_file =~ m{/}) {
9841: my ($path,$fname) = split(/\//,$embed_file);
9842: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
9843: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
9844: }
9845: } else {
9846: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
9847: ($size,$mtime) = @{$currfile->{$embed_file}};
9848: }
9849: }
9850: $showsize = $size/1024.0;
9851: $showsize = sprintf("%.1f",$showsize);
9852: if ($mtime > 0) {
9853: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
9854: }
9855: }
9856: return ($showsize,$showmtime);
9857: }
9858:
9859: sub ask_embedded_js {
9860: return <<"END";
9861: <script type="text/javascript"">
9862: // <![CDATA[
9863: function toggleBrowse(counter) {
9864: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
9865: var fileid = document.getElementById('embedded_item_'+counter);
9866: var uploaddivid = document.getElementById('moduploaddep_'+counter);
9867: if (chkboxid.checked == true) {
9868: uploaddivid.style.display='block';
9869: } else {
9870: uploaddivid.style.display='none';
9871: fileid.value = '';
9872: }
9873: }
9874: // ]]>
9875: </script>
9876:
9877: END
9878: }
9879:
1.661 raeburn 9880: sub upload_embedded {
9881: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 9882: $current_disk_usage,$hiddenstate,$actionurl) = @_;
9883: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 9884: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
9885: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
9886: my $orig_uploaded_filename =
9887: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 9888: foreach my $type ('orig','ref','attrib','codebase') {
9889: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
9890: $env{'form.embedded_'.$type.'_'.$i} =
9891: &unescape($env{'form.embedded_'.$type.'_'.$i});
9892: }
9893: }
1.661 raeburn 9894: my ($path,$fname) =
9895: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
9896: # no path, whole string is fname
9897: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
9898: $fname = &Apache::lonnet::clean_filename($fname);
9899: # See if there is anything left
9900: next if ($fname eq '');
9901:
9902: # Check if file already exists as a file or directory.
9903: my ($state,$msg);
9904: if ($context eq 'portfolio') {
9905: my $port_path = $dirpath;
9906: if ($group ne '') {
9907: $port_path = "groups/$group/$port_path";
9908: }
1.987 raeburn 9909: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
9910: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 9911: $dir_root,$port_path,$disk_quota,
9912: $current_disk_usage,$uname,$udom);
9913: if ($state eq 'will_exceed_quota'
1.984 raeburn 9914: || $state eq 'file_locked') {
1.661 raeburn 9915: $output .= $msg;
9916: next;
9917: }
9918: } elsif (($context eq 'author') || ($context eq 'testbank')) {
9919: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
9920: if ($state eq 'exists') {
9921: $output .= $msg;
9922: next;
9923: }
9924: }
9925: # Check if extension is valid
9926: if (($fname =~ /\.(\w+)$/) &&
9927: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 9928: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 9929: next;
9930: } elsif (($fname =~ /\.(\w+)$/) &&
9931: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 9932: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 9933: next;
9934: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 9935: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 9936: next;
9937: }
9938: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
9939: if ($context eq 'portfolio') {
1.984 raeburn 9940: my $result;
9941: if ($state eq 'existingfile') {
9942: $result=
9943: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 9944: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 9945: } else {
1.984 raeburn 9946: $result=
9947: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 9948: $dirpath.
9949: $env{'form.currentpath'}.$path);
1.984 raeburn 9950: if ($result !~ m|^/uploaded/|) {
9951: $output .= '<span class="LC_error">'
9952: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
9953: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
9954: .'</span><br />';
9955: next;
9956: } else {
1.987 raeburn 9957: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
9958: $path.$fname.'</span>').'<br />';
1.984 raeburn 9959: }
1.661 raeburn 9960: }
1.987 raeburn 9961: } elsif ($context eq 'coursedoc') {
9962: my $result =
9963: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
9964: $dirpath.'/'.$path);
9965: if ($result !~ m|^/uploaded/|) {
9966: $output .= '<span class="LC_error">'
9967: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
9968: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
9969: .'</span><br />';
9970: next;
9971: } else {
9972: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
9973: $path.$fname.'</span>').'<br />';
9974: }
1.661 raeburn 9975: } else {
9976: # Save the file
9977: my $target = $env{'form.embedded_item_'.$i};
9978: my $fullpath = $dir_root.$dirpath.'/'.$path;
9979: my $dest = $fullpath.$fname;
9980: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 9981: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 9982: my $count;
9983: my $filepath = $dir_root;
1.1027 raeburn 9984: foreach my $subdir (@parts) {
9985: $filepath .= "/$subdir";
9986: if (!-e $filepath) {
1.661 raeburn 9987: mkdir($filepath,0770);
9988: }
9989: }
9990: my $fh;
9991: if (!open($fh,'>'.$dest)) {
9992: &Apache::lonnet::logthis('Failed to create '.$dest);
9993: $output .= '<span class="LC_error">'.
1.1071 raeburn 9994: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
9995: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 9996: '</span><br />';
9997: } else {
9998: if (!print $fh $env{'form.embedded_item_'.$i}) {
9999: &Apache::lonnet::logthis('Failed to write to '.$dest);
10000: $output .= '<span class="LC_error">'.
1.1071 raeburn 10001: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10002: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10003: '</span><br />';
10004: } else {
1.987 raeburn 10005: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10006: $url.'</span>').'<br />';
10007: unless ($context eq 'testbank') {
10008: $footer .= &mt('View embedded file: [_1]',
10009: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10010: }
10011: }
10012: close($fh);
10013: }
10014: }
10015: if ($env{'form.embedded_ref_'.$i}) {
10016: $pathchange{$i} = 1;
10017: }
10018: }
10019: if ($output) {
10020: $output = '<p>'.$output.'</p>';
10021: }
10022: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10023: $returnflag = 'ok';
1.1071 raeburn 10024: my $numpathchgs = scalar(keys(%pathchange));
10025: if ($numpathchgs > 0) {
1.987 raeburn 10026: if ($context eq 'portfolio') {
10027: $output .= '<p>'.&mt('or').'</p>';
10028: } elsif ($context eq 'testbank') {
1.1071 raeburn 10029: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10030: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10031: $returnflag = 'modify_orightml';
10032: }
10033: }
1.1071 raeburn 10034: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10035: }
10036:
10037: sub modify_html_form {
10038: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10039: my $end = 0;
10040: my $modifyform;
10041: if ($context eq 'upload_embedded') {
10042: return unless (ref($pathchange) eq 'HASH');
10043: if ($env{'form.number_embedded_items'}) {
10044: $end += $env{'form.number_embedded_items'};
10045: }
10046: if ($env{'form.number_pathchange_items'}) {
10047: $end += $env{'form.number_pathchange_items'};
10048: }
10049: if ($end) {
10050: for (my $i=0; $i<$end; $i++) {
10051: if ($i < $env{'form.number_embedded_items'}) {
10052: next unless($pathchange->{$i});
10053: }
10054: $modifyform .=
10055: &start_data_table_row().
10056: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10057: 'checked="checked" /></td>'.
10058: '<td>'.$env{'form.embedded_ref_'.$i}.
10059: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10060: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10061: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10062: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10063: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10064: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10065: '<td>'.$env{'form.embedded_orig_'.$i}.
10066: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10067: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10068: &end_data_table_row();
1.1071 raeburn 10069: }
1.987 raeburn 10070: }
10071: } else {
10072: $modifyform = $pathchgtable;
10073: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10074: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10075: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10076: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10077: }
10078: }
10079: if ($modifyform) {
1.1071 raeburn 10080: if ($actionurl eq '/adm/dependencies') {
10081: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10082: }
1.987 raeburn 10083: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10084: '<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".
10085: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10086: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10087: '</ol></p>'."\n".'<p>'.
10088: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10089: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10090: &start_data_table()."\n".
10091: &start_data_table_header_row().
10092: '<th>'.&mt('Change?').'</th>'.
10093: '<th>'.&mt('Current reference').'</th>'.
10094: '<th>'.&mt('Required reference').'</th>'.
10095: &end_data_table_header_row()."\n".
10096: $modifyform.
10097: &end_data_table().'<br />'."\n".$hiddenstate.
10098: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10099: '</form>'."\n";
10100: }
10101: return;
10102: }
10103:
10104: sub modify_html_refs {
10105: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
10106: my $container;
10107: if ($context eq 'portfolio') {
10108: $container = $env{'form.container'};
10109: } elsif ($context eq 'coursedoc') {
10110: $container = $env{'form.primaryurl'};
1.1071 raeburn 10111: } elsif ($context eq 'manage_dependencies') {
10112: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10113: $container = "/$container";
1.987 raeburn 10114: } else {
1.1027 raeburn 10115: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10116: }
10117: my (%allfiles,%codebase,$output,$content);
10118: my @changes = &get_env_multiple('form.namechange');
1.1071 raeburn 10119: unless (@changes > 0) {
10120: if (wantarray) {
10121: return ('',0,0);
10122: } else {
10123: return;
10124: }
10125: }
10126: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10127: ($context eq 'manage_dependencies')) {
10128: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10129: if (wantarray) {
10130: return ('',0,0);
10131: } else {
10132: return;
10133: }
10134: }
1.987 raeburn 10135: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10136: if ($content eq '-1') {
10137: if (wantarray) {
10138: return ('',0,0);
10139: } else {
10140: return;
10141: }
10142: }
1.987 raeburn 10143: } else {
1.1071 raeburn 10144: unless ($container =~ /^\Q$dir_root\E/) {
10145: if (wantarray) {
10146: return ('',0,0);
10147: } else {
10148: return;
10149: }
10150: }
1.987 raeburn 10151: if (open(my $fh,"<$container")) {
10152: $content = join('', <$fh>);
10153: close($fh);
10154: } else {
1.1071 raeburn 10155: if (wantarray) {
10156: return ('',0,0);
10157: } else {
10158: return;
10159: }
1.987 raeburn 10160: }
10161: }
10162: my ($count,$codebasecount) = (0,0);
10163: my $mm = new File::MMagic;
10164: my $mime_type = $mm->checktype_contents($content);
10165: if ($mime_type eq 'text/html') {
10166: my $parse_result =
10167: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10168: \%codebase,\$content);
10169: if ($parse_result eq 'ok') {
10170: foreach my $i (@changes) {
10171: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10172: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10173: if ($allfiles{$ref}) {
10174: my $newname = $orig;
10175: my ($attrib_regexp,$codebase);
1.1006 raeburn 10176: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10177: if ($attrib_regexp =~ /:/) {
10178: $attrib_regexp =~ s/\:/|/g;
10179: }
10180: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10181: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10182: $count += $numchg;
10183: }
10184: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10185: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10186: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10187: $codebasecount ++;
10188: }
10189: }
10190: }
10191: if ($count || $codebasecount) {
10192: my $saveresult;
1.1071 raeburn 10193: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10194: ($context eq 'manage_dependencies')) {
1.987 raeburn 10195: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10196: if ($url eq $container) {
10197: my ($fname) = ($container =~ m{/([^/]+)$});
10198: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10199: $count,'<span class="LC_filename">'.
1.1071 raeburn 10200: $fname.'</span>').'</p>';
1.987 raeburn 10201: } else {
10202: $output = '<p class="LC_error">'.
10203: &mt('Error: update failed for: [_1].',
10204: '<span class="LC_filename">'.
10205: $container.'</span>').'</p>';
10206: }
10207: } else {
10208: if (open(my $fh,">$container")) {
10209: print $fh $content;
10210: close($fh);
10211: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10212: $count,'<span class="LC_filename">'.
10213: $container.'</span>').'</p>';
1.661 raeburn 10214: } else {
1.987 raeburn 10215: $output = '<p class="LC_error">'.
10216: &mt('Error: could not update [_1].',
10217: '<span class="LC_filename">'.
10218: $container.'</span>').'</p>';
1.661 raeburn 10219: }
10220: }
10221: }
1.987 raeburn 10222: } else {
10223: &logthis('Failed to parse '.$container.
10224: ' to modify references: '.$parse_result);
1.661 raeburn 10225: }
10226: }
1.1071 raeburn 10227: if (wantarray) {
10228: return ($output,$count,$codebasecount);
10229: } else {
10230: return $output;
10231: }
1.661 raeburn 10232: }
10233:
10234: sub check_for_existing {
10235: my ($path,$fname,$element) = @_;
10236: my ($state,$msg);
10237: if (-d $path.'/'.$fname) {
10238: $state = 'exists';
10239: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10240: } elsif (-e $path.'/'.$fname) {
10241: $state = 'exists';
10242: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10243: }
10244: if ($state eq 'exists') {
10245: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10246: }
10247: return ($state,$msg);
10248: }
10249:
10250: sub check_for_upload {
10251: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10252: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10253: my $filesize = length($env{'form.'.$element});
10254: if (!$filesize) {
10255: my $msg = '<span class="LC_error">'.
10256: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10257: '<span class="LC_filename">'.$fname.'</span>',
10258: $filesize).'<br />'.
1.1007 raeburn 10259: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10260: '</span>';
10261: return ('zero_bytes',$msg);
10262: }
10263: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10264: my $getpropath = 1;
1.1021 raeburn 10265: my ($dirlistref,$listerror) =
10266: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10267: my $found_file = 0;
10268: my $locked_file = 0;
1.991 raeburn 10269: my @lockers;
10270: my $navmap;
10271: if ($env{'request.course.id'}) {
10272: $navmap = Apache::lonnavmaps::navmap->new();
10273: }
1.1021 raeburn 10274: if (ref($dirlistref) eq 'ARRAY') {
10275: foreach my $line (@{$dirlistref}) {
10276: my ($file_name,$rest)=split(/\&/,$line,2);
10277: if ($file_name eq $fname){
10278: $file_name = $path.$file_name;
10279: if ($group ne '') {
10280: $file_name = $group.$file_name;
10281: }
10282: $found_file = 1;
10283: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10284: foreach my $lock (@lockers) {
10285: if (ref($lock) eq 'ARRAY') {
10286: my ($symb,$crsid) = @{$lock};
10287: if ($crsid eq $env{'request.course.id'}) {
10288: if (ref($navmap)) {
10289: my $res = $navmap->getBySymb($symb);
10290: foreach my $part (@{$res->parts()}) {
10291: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10292: unless (($slot_status == $res->RESERVED) ||
10293: ($slot_status == $res->RESERVED_LOCATION)) {
10294: $locked_file = 1;
10295: }
1.991 raeburn 10296: }
1.1021 raeburn 10297: } else {
10298: $locked_file = 1;
1.991 raeburn 10299: }
10300: } else {
10301: $locked_file = 1;
10302: }
10303: }
1.1021 raeburn 10304: }
10305: } else {
10306: my @info = split(/\&/,$rest);
10307: my $currsize = $info[6]/1000;
10308: if ($currsize < $filesize) {
10309: my $extra = $filesize - $currsize;
10310: if (($current_disk_usage + $extra) > $disk_quota) {
10311: my $msg = '<span class="LC_error">'.
10312: &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.',
10313: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10314: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10315: $disk_quota,$current_disk_usage);
10316: return ('will_exceed_quota',$msg);
10317: }
1.984 raeburn 10318: }
10319: }
1.661 raeburn 10320: }
10321: }
10322: }
10323: if (($current_disk_usage + $filesize) > $disk_quota){
10324: my $msg = '<span class="LC_error">'.
10325: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10326: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10327: return ('will_exceed_quota',$msg);
10328: } elsif ($found_file) {
10329: if ($locked_file) {
10330: my $msg = '<span class="LC_error">';
10331: $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>');
10332: $msg .= '</span><br />';
10333: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10334: return ('file_locked',$msg);
10335: } else {
10336: my $msg = '<span class="LC_error">';
1.984 raeburn 10337: $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 10338: $msg .= '</span>';
1.984 raeburn 10339: return ('existingfile',$msg);
1.661 raeburn 10340: }
10341: }
10342: }
10343:
1.987 raeburn 10344: sub check_for_traversal {
10345: my ($path,$url,$toplevel) = @_;
10346: my @parts=split(/\//,$path);
10347: my $cleanpath;
10348: my $fullpath = $url;
10349: for (my $i=0;$i<@parts;$i++) {
10350: next if ($parts[$i] eq '.');
10351: if ($parts[$i] eq '..') {
10352: $fullpath =~ s{([^/]+/)$}{};
10353: } else {
10354: $fullpath .= $parts[$i].'/';
10355: }
10356: }
10357: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10358: $cleanpath = $1;
10359: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10360: my $curr_toprel = $1;
10361: my @parts = split(/\//,$curr_toprel);
10362: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10363: my @urlparts = split(/\//,$url_toprel);
10364: my $doubledots;
10365: my $startdiff = -1;
10366: for (my $i=0; $i<@urlparts; $i++) {
10367: if ($startdiff == -1) {
10368: unless ($urlparts[$i] eq $parts[$i]) {
10369: $startdiff = $i;
10370: $doubledots .= '../';
10371: }
10372: } else {
10373: $doubledots .= '../';
10374: }
10375: }
10376: if ($startdiff > -1) {
10377: $cleanpath = $doubledots;
10378: for (my $i=$startdiff; $i<@parts; $i++) {
10379: $cleanpath .= $parts[$i].'/';
10380: }
10381: }
10382: }
10383: $cleanpath =~ s{(/)$}{};
10384: return $cleanpath;
10385: }
1.31 albertel 10386:
1.1053 raeburn 10387: sub is_archive_file {
10388: my ($mimetype) = @_;
10389: if (($mimetype eq 'application/octet-stream') ||
10390: ($mimetype eq 'application/x-stuffit') ||
10391: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10392: return 1;
10393: }
10394: return;
10395: }
10396:
10397: sub decompress_form {
1.1065 raeburn 10398: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10399: my %lt = &Apache::lonlocal::texthash (
10400: this => 'This file is an archive file.',
1.1067 raeburn 10401: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10402: itsc => 'Its contents are as follows:',
1.1053 raeburn 10403: youm => 'You may wish to extract its contents.',
10404: extr => 'Extract contents',
1.1067 raeburn 10405: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10406: proa => 'Process automatically?',
1.1053 raeburn 10407: yes => 'Yes',
10408: no => 'No',
1.1067 raeburn 10409: fold => 'Title for folder containing movie',
10410: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10411: );
1.1065 raeburn 10412: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10413: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10414: my $info = &list_archive_contents($fileloc,\@paths);
10415: if (@paths) {
10416: foreach my $path (@paths) {
10417: $path =~ s{^/}{};
1.1067 raeburn 10418: if ($path =~ m{^([^/]+)/$}) {
10419: $topdir = $1;
10420: }
1.1065 raeburn 10421: if ($path =~ m{^([^/]+)/}) {
10422: $toplevel{$1} = $path;
10423: } else {
10424: $toplevel{$path} = $path;
10425: }
10426: }
10427: }
1.1067 raeburn 10428: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10429: my @camtasia = ("$topdir/","$topdir/index.html",
10430: "$topdir/media/",
10431: "$topdir/media/$topdir.mp4",
10432: "$topdir/media/FirstFrame.png",
10433: "$topdir/media/player.swf",
10434: "$topdir/media/swfobject.js",
10435: "$topdir/media/expressInstall.swf");
10436: my @diffs = &compare_arrays(\@paths,\@camtasia);
10437: if (@diffs == 0) {
10438: $is_camtasia = 1;
10439: }
10440: }
10441: my $output;
10442: if ($is_camtasia) {
10443: $output = <<"ENDCAM";
10444: <script type="text/javascript" language="Javascript">
10445: // <![CDATA[
10446:
10447: function camtasiaToggle() {
10448: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10449: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10450: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10451:
10452: document.getElementById('camtasia_titles').style.display='block';
10453: } else {
10454: document.getElementById('camtasia_titles').style.display='none';
10455: }
10456: }
10457: }
10458: return;
10459: }
10460:
10461: // ]]>
10462: </script>
10463: <p>$lt{'camt'}</p>
10464: ENDCAM
1.1065 raeburn 10465: } else {
1.1067 raeburn 10466: $output = '<p>'.$lt{'this'};
10467: if ($info eq '') {
10468: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10469: } else {
10470: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10471: '<div><pre>'.$info.'</pre></div>';
10472: }
1.1065 raeburn 10473: }
1.1067 raeburn 10474: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10475: my $duplicates;
10476: my $num = 0;
10477: if (ref($dirlist) eq 'ARRAY') {
10478: foreach my $item (@{$dirlist}) {
10479: if (ref($item) eq 'ARRAY') {
10480: if (exists($toplevel{$item->[0]})) {
10481: $duplicates .=
10482: &start_data_table_row().
10483: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10484: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10485: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10486: 'value="1" />'.&mt('Yes').'</label>'.
10487: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10488: '<td>'.$item->[0].'</td>';
10489: if ($item->[2]) {
10490: $duplicates .= '<td>'.&mt('Directory').'</td>';
10491: } else {
10492: $duplicates .= '<td>'.&mt('File').'</td>';
10493: }
10494: $duplicates .= '<td>'.$item->[3].'</td>'.
10495: '<td>'.
10496: &Apache::lonlocal::locallocaltime($item->[4]).
10497: '</td>'.
10498: &end_data_table_row();
10499: $num ++;
10500: }
10501: }
10502: }
10503: }
10504: my $itemcount;
10505: if (@paths > 0) {
10506: $itemcount = scalar(@paths);
10507: } else {
10508: $itemcount = 1;
10509: }
1.1067 raeburn 10510: if ($is_camtasia) {
10511: $output .= $lt{'auto'}.'<br />'.
10512: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10513: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10514: $lt{'yes'}.'</label> <label>'.
10515: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10516: $lt{'no'}.'</label></span><br />'.
10517: '<div id="camtasia_titles" style="display:block">'.
10518: &Apache::lonhtmlcommon::start_pick_box().
10519: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10520: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10521: &Apache::lonhtmlcommon::row_closure().
10522: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
10523: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
10524: &Apache::lonhtmlcommon::row_closure(1).
10525: &Apache::lonhtmlcommon::end_pick_box().
10526: '</div>';
10527: }
1.1065 raeburn 10528: $output .=
10529: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 10530: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
10531: "\n";
1.1065 raeburn 10532: if ($duplicates ne '') {
10533: $output .= '<p><span class="LC_warning">'.
10534: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
10535: &start_data_table().
10536: &start_data_table_header_row().
10537: '<th>'.&mt('Overwrite?').'</th>'.
10538: '<th>'.&mt('Name').'</th>'.
10539: '<th>'.&mt('Type').'</th>'.
10540: '<th>'.&mt('Size').'</th>'.
10541: '<th>'.&mt('Last modified').'</th>'.
10542: &end_data_table_header_row().
10543: $duplicates.
10544: &end_data_table().
10545: '</p>';
10546: }
1.1067 raeburn 10547: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 10548: if (ref($hiddenelements) eq 'HASH') {
10549: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
10550: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
10551: }
10552: }
10553: $output .= <<"END";
1.1067 raeburn 10554: <br />
1.1053 raeburn 10555: <input type="submit" name="decompress" value="$lt{'extr'}" />
10556: </form>
10557: $noextract
10558: END
10559: return $output;
10560: }
10561:
1.1065 raeburn 10562: sub decompression_utility {
10563: my ($program) = @_;
10564: my @utilities = ('tar','gunzip','bunzip2','unzip');
10565: my $location;
10566: if (grep(/^\Q$program\E$/,@utilities)) {
10567: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
10568: '/usr/sbin/') {
10569: if (-x $dir.$program) {
10570: $location = $dir.$program;
10571: last;
10572: }
10573: }
10574: }
10575: return $location;
10576: }
10577:
10578: sub list_archive_contents {
10579: my ($file,$pathsref) = @_;
10580: my (@cmd,$output);
10581: my $needsregexp;
10582: if ($file =~ /\.zip$/) {
10583: @cmd = (&decompression_utility('unzip'),"-l");
10584: $needsregexp = 1;
10585: } elsif (($file =~ m/\.tar\.gz$/) ||
10586: ($file =~ /\.tgz$/)) {
10587: @cmd = (&decompression_utility('tar'),"-ztf");
10588: } elsif ($file =~ /\.tar\.bz2$/) {
10589: @cmd = (&decompression_utility('tar'),"-jtf");
10590: } elsif ($file =~ m|\.tar$|) {
10591: @cmd = (&decompression_utility('tar'),"-tf");
10592: }
10593: if (@cmd) {
10594: undef($!);
10595: undef($@);
10596: if (open(my $fh,"-|", @cmd, $file)) {
10597: while (my $line = <$fh>) {
10598: $output .= $line;
10599: chomp($line);
10600: my $item;
10601: if ($needsregexp) {
10602: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
10603: } else {
10604: $item = $line;
10605: }
10606: if ($item ne '') {
10607: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
10608: push(@{$pathsref},$item);
10609: }
10610: }
10611: }
10612: close($fh);
10613: }
10614: }
10615: return $output;
10616: }
10617:
1.1053 raeburn 10618: sub decompress_uploaded_file {
10619: my ($file,$dir) = @_;
10620: &Apache::lonnet::appenv({'cgi.file' => $file});
10621: &Apache::lonnet::appenv({'cgi.dir' => $dir});
10622: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
10623: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
10624: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
10625: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
10626: my $decompressed = $env{'cgi.decompressed'};
10627: &Apache::lonnet::delenv('cgi.file');
10628: &Apache::lonnet::delenv('cgi.dir');
10629: &Apache::lonnet::delenv('cgi.decompressed');
10630: return ($decompressed,$result);
10631: }
10632:
1.1055 raeburn 10633: sub process_decompression {
10634: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
10635: my ($dir,$error,$warning,$output);
10636: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
10637: $error = &mt('File name not a supported archive file type.').
10638: '<br />'.&mt('File name should end with one of: [_1].',
10639: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
10640: } else {
10641: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
10642: if ($docuhome eq 'no_host') {
10643: $error = &mt('Could not determine home server for course.');
10644: } else {
10645: my @ids=&Apache::lonnet::current_machine_ids();
10646: my $currdir = "$dir_root/$destination";
10647: if (grep(/^\Q$docuhome\E$/,@ids)) {
10648: $dir = &LONCAPA::propath($docudom,$docuname).
10649: "$dir_root/$destination";
10650: } else {
10651: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
10652: "$dir_root/$docudom/$docuname/$destination";
10653: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
10654: $error = &mt('Archive file not found.');
10655: }
10656: }
1.1065 raeburn 10657: my (@to_overwrite,@to_skip);
10658: if ($env{'form.archive_overwrite_total'} > 0) {
10659: my $total = $env{'form.archive_overwrite_total'};
10660: for (my $i=0; $i<$total; $i++) {
10661: if ($env{'form.archive_overwrite_'.$i} == 1) {
10662: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
10663: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
10664: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
10665: }
10666: }
10667: }
10668: my $numskip = scalar(@to_skip);
10669: if (($numskip > 0) &&
10670: ($numskip == $env{'form.archive_itemcount'})) {
10671: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
10672: } elsif ($dir eq '') {
1.1055 raeburn 10673: $error = &mt('Directory containing archive file unavailable.');
10674: } elsif (!$error) {
1.1065 raeburn 10675: my ($decompressed,$display);
10676: if ($numskip > 0) {
10677: my $tempdir = time.'_'.$$.int(rand(10000));
10678: mkdir("$dir/$tempdir",0755);
10679: system("mv $dir/$file $dir/$tempdir/$file");
10680: ($decompressed,$display) =
10681: &decompress_uploaded_file($file,"$dir/$tempdir");
10682: foreach my $item (@to_skip) {
10683: if (($item ne '') && ($item !~ /\.\./)) {
10684: if (-f "$dir/$tempdir/$item") {
10685: unlink("$dir/$tempdir/$item");
10686: } elsif (-d "$dir/$tempdir/$item") {
10687: system("rm -rf $dir/$tempdir/$item");
10688: }
10689: }
10690: }
10691: system("mv $dir/$tempdir/* $dir");
10692: rmdir("$dir/$tempdir");
10693: } else {
10694: ($decompressed,$display) =
10695: &decompress_uploaded_file($file,$dir);
10696: }
1.1055 raeburn 10697: if ($decompressed eq 'ok') {
1.1065 raeburn 10698: $output = '<p class="LC_info">'.
10699: &mt('Files extracted successfully from archive.').
10700: '</p>'."\n";
1.1055 raeburn 10701: my ($warning,$result,@contents);
10702: my ($newdirlistref,$newlisterror) =
10703: &Apache::lonnet::dirlist($currdir,$docudom,
10704: $docuname,1);
10705: my (%is_dir,%changes,@newitems);
10706: my $dirptr = 16384;
1.1065 raeburn 10707: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 10708: foreach my $dir_line (@{$newdirlistref}) {
10709: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 10710: unless (($item =~ /^\.+$/) || ($item eq $file) ||
10711: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 10712: push(@newitems,$item);
10713: if ($dirptr&$testdir) {
10714: $is_dir{$item} = 1;
10715: }
10716: $changes{$item} = 1;
10717: }
10718: }
10719: }
10720: if (keys(%changes) > 0) {
10721: foreach my $item (sort(@newitems)) {
10722: if ($changes{$item}) {
10723: push(@contents,$item);
10724: }
10725: }
10726: }
10727: if (@contents > 0) {
1.1067 raeburn 10728: my $wantform;
10729: unless ($env{'form.autoextract_camtasia'}) {
10730: $wantform = 1;
10731: }
1.1056 raeburn 10732: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 10733: my ($count,$datatable) = &get_extracted($docudom,$docuname,
10734: $currdir,\%is_dir,
10735: \%children,\%parent,
1.1056 raeburn 10736: \@contents,\%dirorder,
10737: \%titles,$wantform);
1.1055 raeburn 10738: if ($datatable ne '') {
10739: $output .= &archive_options_form('decompressed',$datatable,
10740: $count,$hiddenelem);
1.1065 raeburn 10741: my $startcount = 6;
1.1055 raeburn 10742: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 10743: \%titles,\%children);
1.1055 raeburn 10744: }
1.1067 raeburn 10745: if ($env{'form.autoextract_camtasia'}) {
10746: my %displayed;
10747: my $total = 1;
10748: $env{'form.archive_directory'} = [];
10749: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
10750: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
10751: $path =~ s{/$}{};
10752: my $item;
10753: if ($path ne '') {
10754: $item = "$path/$titles{$i}";
10755: } else {
10756: $item = $titles{$i};
10757: }
10758: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
10759: if ($item eq $contents[0]) {
10760: push(@{$env{'form.archive_directory'}},$i);
10761: $env{'form.archive_'.$i} = 'display';
10762: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
10763: $displayed{'folder'} = $i;
10764: } elsif ($item eq "$contents[0]/index.html") {
10765: $env{'form.archive_'.$i} = 'display';
10766: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
10767: $displayed{'web'} = $i;
10768: } else {
10769: if ($item eq "$contents[0]/media") {
10770: push(@{$env{'form.archive_directory'}},$i);
10771: }
10772: $env{'form.archive_'.$i} = 'dependency';
10773: }
10774: $total ++;
10775: }
10776: for (my $i=1; $i<$total; $i++) {
10777: next if ($i == $displayed{'web'});
10778: next if ($i == $displayed{'folder'});
10779: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
10780: }
10781: $env{'form.phase'} = 'decompress_cleanup';
10782: $env{'form.archivedelete'} = 1;
10783: $env{'form.archive_count'} = $total-1;
10784: $output .=
10785: &process_extracted_files('coursedocs',$docudom,
10786: $docuname,$destination,
10787: $dir_root,$hiddenelem);
10788: }
1.1055 raeburn 10789: } else {
10790: $warning = &mt('No new items extracted from archive file.');
10791: }
10792: } else {
10793: $output = $display;
10794: $error = &mt('An error occurred during extraction from the archive file.');
10795: }
10796: }
10797: }
10798: }
10799: if ($error) {
10800: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
10801: $error.'</p>'."\n";
10802: }
10803: if ($warning) {
10804: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
10805: }
10806: return $output;
10807: }
10808:
10809: sub get_extracted {
1.1056 raeburn 10810: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
10811: $titles,$wantform) = @_;
1.1055 raeburn 10812: my $count = 0;
10813: my $depth = 0;
10814: my $datatable;
1.1056 raeburn 10815: my @hierarchy;
1.1055 raeburn 10816: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 10817: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
10818: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 10819: foreach my $item (@{$contents}) {
10820: $count ++;
1.1056 raeburn 10821: @{$dirorder->{$count}} = @hierarchy;
10822: $titles->{$count} = $item;
1.1055 raeburn 10823: &archive_hierarchy($depth,$count,$parent,$children);
10824: if ($wantform) {
10825: $datatable .= &archive_row($is_dir->{$item},$item,
10826: $currdir,$depth,$count);
10827: }
10828: if ($is_dir->{$item}) {
10829: $depth ++;
1.1056 raeburn 10830: push(@hierarchy,$count);
10831: $parent->{$depth} = $count;
1.1055 raeburn 10832: $datatable .=
10833: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 10834: \$depth,\$count,\@hierarchy,$dirorder,
10835: $children,$parent,$titles,$wantform);
1.1055 raeburn 10836: $depth --;
1.1056 raeburn 10837: pop(@hierarchy);
1.1055 raeburn 10838: }
10839: }
10840: return ($count,$datatable);
10841: }
10842:
10843: sub recurse_extracted_archive {
1.1056 raeburn 10844: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
10845: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 10846: my $result='';
1.1056 raeburn 10847: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
10848: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
10849: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 10850: return $result;
10851: }
10852: my $dirptr = 16384;
10853: my ($newdirlistref,$newlisterror) =
10854: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
10855: if (ref($newdirlistref) eq 'ARRAY') {
10856: foreach my $dir_line (@{$newdirlistref}) {
10857: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
10858: unless ($item =~ /^\.+$/) {
10859: $$count ++;
1.1056 raeburn 10860: @{$dirorder->{$$count}} = @{$hierarchy};
10861: $titles->{$$count} = $item;
1.1055 raeburn 10862: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 10863:
1.1055 raeburn 10864: my $is_dir;
10865: if ($dirptr&$testdir) {
10866: $is_dir = 1;
10867: }
10868: if ($wantform) {
10869: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
10870: }
10871: if ($is_dir) {
10872: $$depth ++;
1.1056 raeburn 10873: push(@{$hierarchy},$$count);
10874: $parent->{$$depth} = $$count;
1.1055 raeburn 10875: $result .=
10876: &recurse_extracted_archive("$currdir/$item",$docudom,
10877: $docuname,$depth,$count,
1.1056 raeburn 10878: $hierarchy,$dirorder,$children,
10879: $parent,$titles,$wantform);
1.1055 raeburn 10880: $$depth --;
1.1056 raeburn 10881: pop(@{$hierarchy});
1.1055 raeburn 10882: }
10883: }
10884: }
10885: }
10886: return $result;
10887: }
10888:
10889: sub archive_hierarchy {
10890: my ($depth,$count,$parent,$children) =@_;
10891: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
10892: if (exists($parent->{$depth})) {
10893: $children->{$parent->{$depth}} .= $count.':';
10894: }
10895: }
10896: return;
10897: }
10898:
10899: sub archive_row {
10900: my ($is_dir,$item,$currdir,$depth,$count) = @_;
10901: my ($name) = ($item =~ m{([^/]+)$});
10902: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 10903: 'display' => 'Add as file',
1.1055 raeburn 10904: 'dependency' => 'Include as dependency',
10905: 'discard' => 'Discard',
10906: );
10907: if ($is_dir) {
1.1059 raeburn 10908: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 10909: }
1.1056 raeburn 10910: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
10911: my $offset = 0;
1.1055 raeburn 10912: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 10913: $offset ++;
1.1065 raeburn 10914: if ($action ne 'display') {
10915: $offset ++;
10916: }
1.1055 raeburn 10917: $output .= '<td><span class="LC_nobreak">'.
10918: '<label><input type="radio" name="archive_'.$count.
10919: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
10920: my $text = $choices{$action};
10921: if ($is_dir) {
10922: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
10923: if ($action eq 'display') {
1.1059 raeburn 10924: $text = &mt('Add as folder');
1.1055 raeburn 10925: }
1.1056 raeburn 10926: } else {
10927: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
10928:
10929: }
10930: $output .= ' /> '.$choices{$action}.'</label></span>';
10931: if ($action eq 'dependency') {
10932: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
10933: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
10934: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
10935: '<option value=""></option>'."\n".
10936: '</select>'."\n".
10937: '</div>';
1.1059 raeburn 10938: } elsif ($action eq 'display') {
10939: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
10940: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
10941: '</div>';
1.1055 raeburn 10942: }
1.1056 raeburn 10943: $output .= '</td>';
1.1055 raeburn 10944: }
10945: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
10946: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
10947: for (my $i=0; $i<$depth; $i++) {
10948: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
10949: }
10950: if ($is_dir) {
10951: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
10952: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
10953: } else {
10954: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
10955: }
10956: $output .= ' '.$name.'</td>'."\n".
10957: &end_data_table_row();
10958: return $output;
10959: }
10960:
10961: sub archive_options_form {
1.1065 raeburn 10962: my ($form,$display,$count,$hiddenelem) = @_;
10963: my %lt = &Apache::lonlocal::texthash(
10964: perm => 'Permanently remove archive file?',
10965: hows => 'How should each extracted item be incorporated in the course?',
10966: cont => 'Content actions for all',
10967: addf => 'Add as folder/file',
10968: incd => 'Include as dependency for a displayed file',
10969: disc => 'Discard',
10970: no => 'No',
10971: yes => 'Yes',
10972: save => 'Save',
10973: );
10974: my $output = <<"END";
10975: <form name="$form" method="post" action="">
10976: <p><span class="LC_nobreak">$lt{'perm'}
10977: <label>
10978: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
10979: </label>
10980:
10981: <label>
10982: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
10983: </span>
10984: </p>
10985: <input type="hidden" name="phase" value="decompress_cleanup" />
10986: <br />$lt{'hows'}
10987: <div class="LC_columnSection">
10988: <fieldset>
10989: <legend>$lt{'cont'}</legend>
10990: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
10991: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
10992: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
10993: </fieldset>
10994: </div>
10995: END
10996: return $output.
1.1055 raeburn 10997: &start_data_table()."\n".
1.1065 raeburn 10998: $display."\n".
1.1055 raeburn 10999: &end_data_table()."\n".
11000: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11001: $hiddenelem.
1.1065 raeburn 11002: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11003: '</form>';
11004: }
11005:
11006: sub archive_javascript {
1.1056 raeburn 11007: my ($startcount,$numitems,$titles,$children) = @_;
11008: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11009: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11010: my $scripttag = <<START;
11011: <script type="text/javascript">
11012: // <![CDATA[
11013:
11014: function checkAll(form,prefix) {
11015: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11016: for (var i=0; i < form.elements.length; i++) {
11017: var id = form.elements[i].id;
11018: if ((id != '') && (id != undefined)) {
11019: if (idstr.test(id)) {
11020: if (form.elements[i].type == 'radio') {
11021: form.elements[i].checked = true;
1.1056 raeburn 11022: var nostart = i-$startcount;
1.1059 raeburn 11023: var offset = nostart%7;
11024: var count = (nostart-offset)/7;
1.1056 raeburn 11025: dependencyCheck(form,count,offset);
1.1055 raeburn 11026: }
11027: }
11028: }
11029: }
11030: }
11031:
11032: function propagateCheck(form,count) {
11033: if (count > 0) {
1.1059 raeburn 11034: var startelement = $startcount + ((count-1) * 7);
11035: for (var j=1; j<6; j++) {
11036: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11037: var item = startelement + j;
11038: if (form.elements[item].type == 'radio') {
11039: if (form.elements[item].checked) {
11040: containerCheck(form,count,j);
11041: break;
11042: }
1.1055 raeburn 11043: }
11044: }
11045: }
11046: }
11047: }
11048:
11049: numitems = $numitems
1.1056 raeburn 11050: var titles = new Array(numitems);
11051: var parents = new Array(numitems);
1.1055 raeburn 11052: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11053: parents[i] = new Array;
1.1055 raeburn 11054: }
1.1059 raeburn 11055: var maintitle = '$maintitle';
1.1055 raeburn 11056:
11057: START
11058:
1.1056 raeburn 11059: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11060: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11061: for (my $i=0; $i<@contents; $i ++) {
11062: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11063: }
11064: }
11065:
1.1056 raeburn 11066: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11067: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11068: }
11069:
1.1055 raeburn 11070: $scripttag .= <<END;
11071:
11072: function containerCheck(form,count,offset) {
11073: if (count > 0) {
1.1056 raeburn 11074: dependencyCheck(form,count,offset);
1.1059 raeburn 11075: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11076: form.elements[item].checked = true;
11077: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11078: if (parents[count].length > 0) {
11079: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11080: containerCheck(form,parents[count][j],offset);
11081: }
11082: }
11083: }
11084: }
11085: }
11086:
11087: function dependencyCheck(form,count,offset) {
11088: if (count > 0) {
1.1059 raeburn 11089: var chosen = (offset+$startcount)+7*(count-1);
11090: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11091: var currtype = form.elements[depitem].type;
11092: if (form.elements[chosen].value == 'dependency') {
11093: document.getElementById('arc_depon_'+count).style.display='block';
11094: form.elements[depitem].options.length = 0;
11095: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11096: for (var i=1; i<=numitems; i++) {
11097: if (i == count) {
11098: continue;
11099: }
1.1059 raeburn 11100: var startelement = $startcount + (i-1) * 7;
11101: for (var j=1; j<6; j++) {
11102: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11103: var item = startelement + j;
11104: if (form.elements[item].type == 'radio') {
11105: if (form.elements[item].checked) {
11106: if (form.elements[item].value == 'display') {
11107: var n = form.elements[depitem].options.length;
11108: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11109: }
11110: }
11111: }
11112: }
11113: }
11114: }
11115: } else {
11116: document.getElementById('arc_depon_'+count).style.display='none';
11117: form.elements[depitem].options.length = 0;
11118: form.elements[depitem].options[0] = new Option('Select','',true,true);
11119: }
1.1059 raeburn 11120: titleCheck(form,count,offset);
1.1056 raeburn 11121: }
11122: }
11123:
11124: function propagateSelect(form,count,offset) {
11125: if (count > 0) {
1.1065 raeburn 11126: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11127: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11128: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11129: if (parents[count].length > 0) {
11130: for (var j=0; j<parents[count].length; j++) {
11131: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11132: }
11133: }
11134: }
11135: }
11136: }
1.1056 raeburn 11137:
11138: function containerSelect(form,count,offset,picked) {
11139: if (count > 0) {
1.1065 raeburn 11140: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11141: if (form.elements[item].type == 'radio') {
11142: if (form.elements[item].value == 'dependency') {
11143: if (form.elements[item+1].type == 'select-one') {
11144: for (var i=0; i<form.elements[item+1].options.length; i++) {
11145: if (form.elements[item+1].options[i].value == picked) {
11146: form.elements[item+1].selectedIndex = i;
11147: break;
11148: }
11149: }
11150: }
11151: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11152: if (parents[count].length > 0) {
11153: for (var j=0; j<parents[count].length; j++) {
11154: containerSelect(form,parents[count][j],offset,picked);
11155: }
11156: }
11157: }
11158: }
11159: }
11160: }
11161: }
11162:
1.1059 raeburn 11163: function titleCheck(form,count,offset) {
11164: if (count > 0) {
11165: var chosen = (offset+$startcount)+7*(count-1);
11166: var depitem = $startcount + ((count-1) * 7) + 2;
11167: var currtype = form.elements[depitem].type;
11168: if (form.elements[chosen].value == 'display') {
11169: document.getElementById('arc_title_'+count).style.display='block';
11170: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11171: document.getElementById('archive_title_'+count).value=maintitle;
11172: }
11173: } else {
11174: document.getElementById('arc_title_'+count).style.display='none';
11175: if (currtype == 'text') {
11176: document.getElementById('archive_title_'+count).value='';
11177: }
11178: }
11179: }
11180: return;
11181: }
11182:
1.1055 raeburn 11183: // ]]>
11184: </script>
11185: END
11186: return $scripttag;
11187: }
11188:
11189: sub process_extracted_files {
1.1067 raeburn 11190: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11191: my $numitems = $env{'form.archive_count'};
11192: return unless ($numitems);
11193: my @ids=&Apache::lonnet::current_machine_ids();
11194: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11195: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11196: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11197: if (grep(/^\Q$docuhome\E$/,@ids)) {
11198: $prefix = &LONCAPA::propath($docudom,$docuname);
11199: $pathtocheck = "$dir_root/$destination";
11200: $dir = $dir_root;
11201: $ishome = 1;
11202: } else {
11203: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11204: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11205: $dir = "$dir_root/$docudom/$docuname";
11206: }
11207: my $currdir = "$dir_root/$destination";
11208: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11209: if ($env{'form.folderpath'}) {
11210: my @items = split('&',$env{'form.folderpath'});
11211: $folders{'0'} = $items[-2];
11212: $containers{'0'}='sequence';
11213: } elsif ($env{'form.pagepath'}) {
11214: my @items = split('&',$env{'form.pagepath'});
11215: $folders{'0'} = $items[-2];
11216: $containers{'0'}='page';
11217: }
11218: my @archdirs = &get_env_multiple('form.archive_directory');
11219: if ($numitems) {
11220: for (my $i=1; $i<=$numitems; $i++) {
11221: my $path = $env{'form.archive_content_'.$i};
11222: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11223: my $item = $1;
11224: $toplevelitems{$item} = $i;
11225: if (grep(/^\Q$i\E$/,@archdirs)) {
11226: $is_dir{$item} = 1;
11227: }
11228: }
11229: }
11230: }
1.1067 raeburn 11231: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11232: if (keys(%toplevelitems) > 0) {
11233: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11234: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11235: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11236: }
1.1066 raeburn 11237: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11238: if ($numitems) {
11239: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11240: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11241: my $path = $env{'form.archive_content_'.$i};
11242: if ($path =~ /^\Q$pathtocheck\E/) {
11243: if ($env{'form.archive_'.$i} eq 'discard') {
11244: if ($prefix ne '' && $path ne '') {
11245: if (-e $prefix.$path) {
1.1066 raeburn 11246: if ((@archdirs > 0) &&
11247: (grep(/^\Q$i\E$/,@archdirs))) {
11248: $todeletedir{$prefix.$path} = 1;
11249: } else {
11250: $todelete{$prefix.$path} = 1;
11251: }
1.1055 raeburn 11252: }
11253: }
11254: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11255: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11256: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11257: $docstitle = $env{'form.archive_title_'.$i};
11258: if ($docstitle eq '') {
11259: $docstitle = $title;
11260: }
1.1055 raeburn 11261: $outer = 0;
1.1056 raeburn 11262: if (ref($dirorder{$i}) eq 'ARRAY') {
11263: if (@{$dirorder{$i}} > 0) {
11264: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11265: if ($env{'form.archive_'.$item} eq 'display') {
11266: $outer = $item;
11267: last;
11268: }
11269: }
11270: }
11271: }
11272: my ($errtext,$fatal) =
11273: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11274: '/'.$folders{$outer}.'.'.
11275: $containers{$outer});
11276: next if ($fatal);
11277: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11278: if ($context eq 'coursedocs') {
1.1056 raeburn 11279: $mapinner{$i} = time;
1.1055 raeburn 11280: $folders{$i} = 'default_'.$mapinner{$i};
11281: $containers{$i} = 'sequence';
11282: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11283: $folders{$i}.'.'.$containers{$i};
11284: my $newidx = &LONCAPA::map::getresidx();
11285: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11286: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11287: push(@LONCAPA::map::order,$newidx);
11288: my ($outtext,$errtext) =
11289: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11290: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11291: '.'.$containers{$outer},1,1);
1.1056 raeburn 11292: $newseqid{$i} = $newidx;
1.1067 raeburn 11293: unless ($errtext) {
11294: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11295: }
1.1055 raeburn 11296: }
11297: } else {
11298: if ($context eq 'coursedocs') {
11299: my $newidx=&LONCAPA::map::getresidx();
11300: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11301: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11302: $title;
11303: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11304: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11305: }
11306: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11307: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11308: }
11309: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11310: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11311: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11312: unless ($ishome) {
11313: my $fetch = "$newdest{$i}/$title";
11314: $fetch =~ s/^\Q$prefix$dir\E//;
11315: $prompttofetch{$fetch} = 1;
11316: }
1.1055 raeburn 11317: }
11318: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11319: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11320: push(@LONCAPA::map::order, $newidx);
11321: my ($outtext,$errtext)=
11322: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11323: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11324: '.'.$containers{$outer},1,1);
1.1067 raeburn 11325: unless ($errtext) {
11326: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11327: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11328: }
11329: }
1.1055 raeburn 11330: }
11331: }
1.1086 raeburn 11332: }
11333: } else {
11334: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11335: }
11336: }
11337: for (my $i=1; $i<=$numitems; $i++) {
11338: next unless ($env{'form.archive_'.$i} eq 'dependency');
11339: my $path = $env{'form.archive_content_'.$i};
11340: if ($path =~ /^\Q$pathtocheck\E/) {
11341: my ($title) = ($path =~ m{/([^/]+)$});
11342: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11343: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11344: if (ref($dirorder{$i}) eq 'ARRAY') {
11345: my ($itemidx,$fullpath,$relpath);
11346: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11347: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11348: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11349: if ($dirorder{$i}->[$j] eq $container) {
11350: $itemidx = $j;
1.1056 raeburn 11351: }
11352: }
1.1086 raeburn 11353: }
11354: if ($itemidx eq '') {
11355: $itemidx = 0;
11356: }
11357: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11358: if ($mapinner{$referrer{$i}}) {
11359: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11360: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11361: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11362: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11363: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11364: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11365: if (!-e $fullpath) {
11366: mkdir($fullpath,0755);
1.1056 raeburn 11367: }
11368: }
1.1086 raeburn 11369: } else {
11370: last;
1.1056 raeburn 11371: }
1.1086 raeburn 11372: }
11373: }
11374: } elsif ($newdest{$referrer{$i}}) {
11375: $fullpath = $newdest{$referrer{$i}};
11376: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11377: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11378: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11379: last;
11380: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11381: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11382: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11383: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11384: if (!-e $fullpath) {
11385: mkdir($fullpath,0755);
1.1056 raeburn 11386: }
11387: }
1.1086 raeburn 11388: } else {
11389: last;
1.1056 raeburn 11390: }
1.1055 raeburn 11391: }
11392: }
1.1086 raeburn 11393: if ($fullpath ne '') {
11394: if (-e "$prefix$path") {
11395: system("mv $prefix$path $fullpath/$title");
11396: }
11397: if (-e "$fullpath/$title") {
11398: my $showpath;
11399: if ($relpath ne '') {
11400: $showpath = "$relpath/$title";
11401: } else {
11402: $showpath = "/$title";
11403: }
11404: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11405: }
11406: unless ($ishome) {
11407: my $fetch = "$fullpath/$title";
11408: $fetch =~ s/^\Q$prefix$dir\E//;
11409: $prompttofetch{$fetch} = 1;
11410: }
11411: }
1.1055 raeburn 11412: }
1.1086 raeburn 11413: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11414: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11415: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11416: }
11417: } else {
11418: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11419: }
11420: }
11421: if (keys(%todelete)) {
11422: foreach my $key (keys(%todelete)) {
11423: unlink($key);
1.1066 raeburn 11424: }
11425: }
11426: if (keys(%todeletedir)) {
11427: foreach my $key (keys(%todeletedir)) {
11428: rmdir($key);
11429: }
11430: }
11431: foreach my $dir (sort(keys(%is_dir))) {
11432: if (($pathtocheck ne '') && ($dir ne '')) {
11433: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11434: }
11435: }
1.1067 raeburn 11436: if ($result ne '') {
11437: $output .= '<ul>'."\n".
11438: $result."\n".
11439: '</ul>';
11440: }
11441: unless ($ishome) {
11442: my $replicationfail;
11443: foreach my $item (keys(%prompttofetch)) {
11444: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11445: unless ($fetchresult eq 'ok') {
11446: $replicationfail .= '<li>'.$item.'</li>'."\n";
11447: }
11448: }
11449: if ($replicationfail) {
11450: $output .= '<p class="LC_error">'.
11451: &mt('Course home server failed to retrieve:').'<ul>'.
11452: $replicationfail.
11453: '</ul></p>';
11454: }
11455: }
1.1055 raeburn 11456: } else {
11457: $warning = &mt('No items found in archive.');
11458: }
11459: if ($error) {
11460: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11461: $error.'</p>'."\n";
11462: }
11463: if ($warning) {
11464: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11465: }
11466: return $output;
11467: }
11468:
1.1066 raeburn 11469: sub cleanup_empty_dirs {
11470: my ($path) = @_;
11471: if (($path ne '') && (-d $path)) {
11472: if (opendir(my $dirh,$path)) {
11473: my @dircontents = grep(!/^\./,readdir($dirh));
11474: my $numitems = 0;
11475: foreach my $item (@dircontents) {
11476: if (-d "$path/$item") {
11477: &recurse_dirs("$path/$item");
11478: if (-e "$path/$item") {
11479: $numitems ++;
11480: }
11481: } else {
11482: $numitems ++;
11483: }
11484: }
11485: if ($numitems == 0) {
11486: rmdir($path);
11487: }
11488: closedir($dirh);
11489: }
11490: }
11491: return;
11492: }
11493:
1.41 ng 11494: =pod
1.45 matthew 11495:
1.1068 raeburn 11496: =item &get_folder_hierarchy()
11497:
11498: Provides hierarchy of names of folders/sub-folders containing the current
11499: item,
11500:
11501: Inputs: 3
11502: - $navmap - navmaps object
11503:
11504: - $map - url for map (either the trigger itself, or map containing
11505: the resource, which is the trigger).
11506:
11507: - $showitem - 1 => show title for map itself; 0 => do not show.
11508:
11509: Outputs: 1 @pathitems - array of folder/subfolder names.
11510:
11511: =cut
11512:
11513: sub get_folder_hierarchy {
11514: my ($navmap,$map,$showitem) = @_;
11515: my @pathitems;
11516: if (ref($navmap)) {
11517: my $mapres = $navmap->getResourceByUrl($map);
11518: if (ref($mapres)) {
11519: my $pcslist = $mapres->map_hierarchy();
11520: if ($pcslist ne '') {
11521: my @pcs = split(/,/,$pcslist);
11522: foreach my $pc (@pcs) {
11523: if ($pc == 1) {
11524: push(@pathitems,&mt('Main Course Documents'));
11525: } else {
11526: my $res = $navmap->getByMapPc($pc);
11527: if (ref($res)) {
11528: my $title = $res->compTitle();
11529: $title =~ s/\W+/_/g;
11530: if ($title ne '') {
11531: push(@pathitems,$title);
11532: }
11533: }
11534: }
11535: }
11536: }
1.1071 raeburn 11537: if ($showitem) {
11538: if ($mapres->{ID} eq '0.0') {
11539: push(@pathitems,&mt('Main Course Documents'));
11540: } else {
11541: my $maptitle = $mapres->compTitle();
11542: $maptitle =~ s/\W+/_/g;
11543: if ($maptitle ne '') {
11544: push(@pathitems,$maptitle);
11545: }
1.1068 raeburn 11546: }
11547: }
11548: }
11549: }
11550: return @pathitems;
11551: }
11552:
11553: =pod
11554:
1.1015 raeburn 11555: =item * &get_turnedin_filepath()
11556:
11557: Determines path in a user's portfolio file for storage of files uploaded
11558: to a specific essayresponse or dropbox item.
11559:
11560: Inputs: 3 required + 1 optional.
11561: $symb is symb for resource, $uname and $udom are for current user (required).
11562: $caller is optional (can be "submission", if routine is called when storing
11563: an upoaded file when "Submit Answer" button was pressed).
11564:
11565: Returns array containing $path and $multiresp.
11566: $path is path in portfolio. $multiresp is 1 if this resource contains more
11567: than one file upload item. Callers of routine should append partid as a
11568: subdirectory to $path in cases where $multiresp is 1.
11569:
11570: Called by: homework/essayresponse.pm and homework/structuretags.pm
11571:
11572: =cut
11573:
11574: sub get_turnedin_filepath {
11575: my ($symb,$uname,$udom,$caller) = @_;
11576: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
11577: my $turnindir;
11578: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
11579: $turnindir = $userhash{'turnindir'};
11580: my ($path,$multiresp);
11581: if ($turnindir eq '') {
11582: if ($caller eq 'submission') {
11583: $turnindir = &mt('turned in');
11584: $turnindir =~ s/\W+/_/g;
11585: my %newhash = (
11586: 'turnindir' => $turnindir,
11587: );
11588: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
11589: }
11590: }
11591: if ($turnindir ne '') {
11592: $path = '/'.$turnindir.'/';
11593: my ($multipart,$turnin,@pathitems);
11594: my $navmap = Apache::lonnavmaps::navmap->new();
11595: if (defined($navmap)) {
11596: my $mapres = $navmap->getResourceByUrl($map);
11597: if (ref($mapres)) {
11598: my $pcslist = $mapres->map_hierarchy();
11599: if ($pcslist ne '') {
11600: foreach my $pc (split(/,/,$pcslist)) {
11601: my $res = $navmap->getByMapPc($pc);
11602: if (ref($res)) {
11603: my $title = $res->compTitle();
11604: $title =~ s/\W+/_/g;
11605: if ($title ne '') {
11606: push(@pathitems,$title);
11607: }
11608: }
11609: }
11610: }
11611: my $maptitle = $mapres->compTitle();
11612: $maptitle =~ s/\W+/_/g;
11613: if ($maptitle ne '') {
11614: push(@pathitems,$maptitle);
11615: }
11616: unless ($env{'request.state'} eq 'construct') {
11617: my $res = $navmap->getBySymb($symb);
11618: if (ref($res)) {
11619: my $partlist = $res->parts();
11620: my $totaluploads = 0;
11621: if (ref($partlist) eq 'ARRAY') {
11622: foreach my $part (@{$partlist}) {
11623: my @types = $res->responseType($part);
11624: my @ids = $res->responseIds($part);
11625: for (my $i=0; $i < scalar(@ids); $i++) {
11626: if ($types[$i] eq 'essay') {
11627: my $partid = $part.'_'.$ids[$i];
11628: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
11629: $totaluploads ++;
11630: }
11631: }
11632: }
11633: }
11634: if ($totaluploads > 1) {
11635: $multiresp = 1;
11636: }
11637: }
11638: }
11639: }
11640: } else {
11641: return;
11642: }
11643: } else {
11644: return;
11645: }
11646: my $restitle=&Apache::lonnet::gettitle($symb);
11647: $restitle =~ s/\W+/_/g;
11648: if ($restitle eq '') {
11649: $restitle = ($resurl =~ m{/[^/]+$});
11650: if ($restitle eq '') {
11651: $restitle = time;
11652: }
11653: }
11654: push(@pathitems,$restitle);
11655: $path .= join('/',@pathitems);
11656: }
11657: return ($path,$multiresp);
11658: }
11659:
11660: =pod
11661:
1.464 albertel 11662: =back
1.41 ng 11663:
1.112 bowersj2 11664: =head1 CSV Upload/Handling functions
1.38 albertel 11665:
1.41 ng 11666: =over 4
11667:
1.648 raeburn 11668: =item * &upfile_store($r)
1.41 ng 11669:
11670: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 11671: needs $env{'form.upfile'}
1.41 ng 11672: returns $datatoken to be put into hidden field
11673:
11674: =cut
1.31 albertel 11675:
11676: sub upfile_store {
11677: my $r=shift;
1.258 albertel 11678: $env{'form.upfile'}=~s/\r/\n/gs;
11679: $env{'form.upfile'}=~s/\f/\n/gs;
11680: $env{'form.upfile'}=~s/\n+/\n/gs;
11681: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 11682:
1.258 albertel 11683: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
11684: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 11685: {
1.158 raeburn 11686: my $datafile = $r->dir_config('lonDaemons').
11687: '/tmp/'.$datatoken.'.tmp';
11688: if ( open(my $fh,">$datafile") ) {
1.258 albertel 11689: print $fh $env{'form.upfile'};
1.158 raeburn 11690: close($fh);
11691: }
1.31 albertel 11692: }
11693: return $datatoken;
11694: }
11695:
1.56 matthew 11696: =pod
11697:
1.648 raeburn 11698: =item * &load_tmp_file($r)
1.41 ng 11699:
11700: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 11701: needs $env{'form.datatoken'},
11702: sets $env{'form.upfile'} to the contents of the file
1.41 ng 11703:
11704: =cut
1.31 albertel 11705:
11706: sub load_tmp_file {
11707: my $r=shift;
11708: my @studentdata=();
11709: {
1.158 raeburn 11710: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 11711: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 11712: if ( open(my $fh,"<$studentfile") ) {
11713: @studentdata=<$fh>;
11714: close($fh);
11715: }
1.31 albertel 11716: }
1.258 albertel 11717: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 11718: }
11719:
1.56 matthew 11720: =pod
11721:
1.648 raeburn 11722: =item * &upfile_record_sep()
1.41 ng 11723:
11724: Separate uploaded file into records
11725: returns array of records,
1.258 albertel 11726: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 11727:
11728: =cut
1.31 albertel 11729:
11730: sub upfile_record_sep {
1.258 albertel 11731: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 11732: } else {
1.248 albertel 11733: my @records;
1.258 albertel 11734: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 11735: if ($line=~/^\s*$/) { next; }
11736: push(@records,$line);
11737: }
11738: return @records;
1.31 albertel 11739: }
11740: }
11741:
1.56 matthew 11742: =pod
11743:
1.648 raeburn 11744: =item * &record_sep($record)
1.41 ng 11745:
1.258 albertel 11746: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 11747:
11748: =cut
11749:
1.263 www 11750: sub takeleft {
11751: my $index=shift;
11752: return substr('0000'.$index,-4,4);
11753: }
11754:
1.31 albertel 11755: sub record_sep {
11756: my $record=shift;
11757: my %components=();
1.258 albertel 11758: if ($env{'form.upfiletype'} eq 'xml') {
11759: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 11760: my $i=0;
1.356 albertel 11761: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 11762: $field=~s/^(\"|\')//;
11763: $field=~s/(\"|\')$//;
1.263 www 11764: $components{&takeleft($i)}=$field;
1.31 albertel 11765: $i++;
11766: }
1.258 albertel 11767: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 11768: my $i=0;
1.356 albertel 11769: foreach my $field (split(/\t/,$record)) {
1.31 albertel 11770: $field=~s/^(\"|\')//;
11771: $field=~s/(\"|\')$//;
1.263 www 11772: $components{&takeleft($i)}=$field;
1.31 albertel 11773: $i++;
11774: }
11775: } else {
1.561 www 11776: my $separator=',';
1.480 banghart 11777: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 11778: $separator=';';
1.480 banghart 11779: }
1.31 albertel 11780: my $i=0;
1.561 www 11781: # the character we are looking for to indicate the end of a quote or a record
11782: my $looking_for=$separator;
11783: # do not add the characters to the fields
11784: my $ignore=0;
11785: # we just encountered a separator (or the beginning of the record)
11786: my $just_found_separator=1;
11787: # store the field we are working on here
11788: my $field='';
11789: # work our way through all characters in record
11790: foreach my $character ($record=~/(.)/g) {
11791: if ($character eq $looking_for) {
11792: if ($character ne $separator) {
11793: # Found the end of a quote, again looking for separator
11794: $looking_for=$separator;
11795: $ignore=1;
11796: } else {
11797: # Found a separator, store away what we got
11798: $components{&takeleft($i)}=$field;
11799: $i++;
11800: $just_found_separator=1;
11801: $ignore=0;
11802: $field='';
11803: }
11804: next;
11805: }
11806: # single or double quotation marks after a separator indicate beginning of a quote
11807: # we are now looking for the end of the quote and need to ignore separators
11808: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
11809: $looking_for=$character;
11810: next;
11811: }
11812: # ignore would be true after we reached the end of a quote
11813: if ($ignore) { next; }
11814: if (($just_found_separator) && ($character=~/\s/)) { next; }
11815: $field.=$character;
11816: $just_found_separator=0;
1.31 albertel 11817: }
1.561 www 11818: # catch the very last entry, since we never encountered the separator
11819: $components{&takeleft($i)}=$field;
1.31 albertel 11820: }
11821: return %components;
11822: }
11823:
1.144 matthew 11824: ######################################################
11825: ######################################################
11826:
1.56 matthew 11827: =pod
11828:
1.648 raeburn 11829: =item * &upfile_select_html()
1.41 ng 11830:
1.144 matthew 11831: Return HTML code to select a file from the users machine and specify
11832: the file type.
1.41 ng 11833:
11834: =cut
11835:
1.144 matthew 11836: ######################################################
11837: ######################################################
1.31 albertel 11838: sub upfile_select_html {
1.144 matthew 11839: my %Types = (
11840: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 11841: semisv => &mt('Semicolon separated values'),
1.144 matthew 11842: space => &mt('Space separated'),
11843: tab => &mt('Tabulator separated'),
11844: # xml => &mt('HTML/XML'),
11845: );
11846: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 11847: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 11848: foreach my $type (sort(keys(%Types))) {
11849: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
11850: }
11851: $Str .= "</select>\n";
11852: return $Str;
1.31 albertel 11853: }
11854:
1.301 albertel 11855: sub get_samples {
11856: my ($records,$toget) = @_;
11857: my @samples=({});
11858: my $got=0;
11859: foreach my $rec (@$records) {
11860: my %temp = &record_sep($rec);
11861: if (! grep(/\S/, values(%temp))) { next; }
11862: if (%temp) {
11863: $samples[$got]=\%temp;
11864: $got++;
11865: if ($got == $toget) { last; }
11866: }
11867: }
11868: return \@samples;
11869: }
11870:
1.144 matthew 11871: ######################################################
11872: ######################################################
11873:
1.56 matthew 11874: =pod
11875:
1.648 raeburn 11876: =item * &csv_print_samples($r,$records)
1.41 ng 11877:
11878: Prints a table of sample values from each column uploaded $r is an
11879: Apache Request ref, $records is an arrayref from
11880: &Apache::loncommon::upfile_record_sep
11881:
11882: =cut
11883:
1.144 matthew 11884: ######################################################
11885: ######################################################
1.31 albertel 11886: sub csv_print_samples {
11887: my ($r,$records) = @_;
1.662 bisitz 11888: my $samples = &get_samples($records,5);
1.301 albertel 11889:
1.594 raeburn 11890: $r->print(&mt('Samples').'<br />'.&start_data_table().
11891: &start_data_table_header_row());
1.356 albertel 11892: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 11893: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 11894: $r->print(&end_data_table_header_row());
1.301 albertel 11895: foreach my $hash (@$samples) {
1.594 raeburn 11896: $r->print(&start_data_table_row());
1.356 albertel 11897: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 11898: $r->print('<td>');
1.356 albertel 11899: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 11900: $r->print('</td>');
11901: }
1.594 raeburn 11902: $r->print(&end_data_table_row());
1.31 albertel 11903: }
1.594 raeburn 11904: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 11905: }
11906:
1.144 matthew 11907: ######################################################
11908: ######################################################
11909:
1.56 matthew 11910: =pod
11911:
1.648 raeburn 11912: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 11913:
11914: Prints a table to create associations between values and table columns.
1.144 matthew 11915:
1.41 ng 11916: $r is an Apache Request ref,
11917: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 11918: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 11919:
11920: =cut
11921:
1.144 matthew 11922: ######################################################
11923: ######################################################
1.31 albertel 11924: sub csv_print_select_table {
11925: my ($r,$records,$d) = @_;
1.301 albertel 11926: my $i=0;
11927: my $samples = &get_samples($records,1);
1.144 matthew 11928: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 11929: &start_data_table().&start_data_table_header_row().
1.144 matthew 11930: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 11931: '<th>'.&mt('Column').'</th>'.
11932: &end_data_table_header_row()."\n");
1.356 albertel 11933: foreach my $array_ref (@$d) {
11934: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 11935: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 11936:
1.875 bisitz 11937: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 11938: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 11939: $r->print('<option value="none"></option>');
1.356 albertel 11940: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
11941: $r->print('<option value="'.$sample.'"'.
11942: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 11943: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 11944: }
1.594 raeburn 11945: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 11946: $i++;
11947: }
1.594 raeburn 11948: $r->print(&end_data_table());
1.31 albertel 11949: $i--;
11950: return $i;
11951: }
1.56 matthew 11952:
1.144 matthew 11953: ######################################################
11954: ######################################################
11955:
1.56 matthew 11956: =pod
1.31 albertel 11957:
1.648 raeburn 11958: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 11959:
11960: Prints a table of sample values from the upload and can make associate samples to internal names.
11961:
11962: $r is an Apache Request ref,
11963: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
11964: $d is an array of 2 element arrays (internal name, displayed name)
11965:
11966: =cut
11967:
1.144 matthew 11968: ######################################################
11969: ######################################################
1.31 albertel 11970: sub csv_samples_select_table {
11971: my ($r,$records,$d) = @_;
11972: my $i=0;
1.144 matthew 11973: #
1.662 bisitz 11974: my $max_samples = 5;
11975: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 11976: $r->print(&start_data_table().
11977: &start_data_table_header_row().'<th>'.
11978: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
11979: &end_data_table_header_row());
1.301 albertel 11980:
11981: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 11982: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 11983: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 11984: foreach my $option (@$d) {
11985: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 11986: $r->print('<option value="'.$value.'"'.
1.253 albertel 11987: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 11988: $display.'</option>');
1.31 albertel 11989: }
11990: $r->print('</select></td><td>');
1.662 bisitz 11991: foreach my $line (0..($max_samples-1)) {
1.301 albertel 11992: if (defined($samples->[$line]{$key})) {
11993: $r->print($samples->[$line]{$key}."<br />\n");
11994: }
11995: }
1.594 raeburn 11996: $r->print('</td>'.&end_data_table_row());
1.31 albertel 11997: $i++;
11998: }
1.594 raeburn 11999: $r->print(&end_data_table());
1.31 albertel 12000: $i--;
12001: return($i);
1.115 matthew 12002: }
12003:
1.144 matthew 12004: ######################################################
12005: ######################################################
12006:
1.115 matthew 12007: =pod
12008:
1.648 raeburn 12009: =item * &clean_excel_name($name)
1.115 matthew 12010:
12011: Returns a replacement for $name which does not contain any illegal characters.
12012:
12013: =cut
12014:
1.144 matthew 12015: ######################################################
12016: ######################################################
1.115 matthew 12017: sub clean_excel_name {
12018: my ($name) = @_;
12019: $name =~ s/[:\*\?\/\\]//g;
12020: if (length($name) > 31) {
12021: $name = substr($name,0,31);
12022: }
12023: return $name;
1.25 albertel 12024: }
1.84 albertel 12025:
1.85 albertel 12026: =pod
12027:
1.648 raeburn 12028: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12029:
12030: Returns either 1 or undef
12031:
12032: 1 if the part is to be hidden, undef if it is to be shown
12033:
12034: Arguments are:
12035:
12036: $id the id of the part to be checked
12037: $symb, optional the symb of the resource to check
12038: $udom, optional the domain of the user to check for
12039: $uname, optional the username of the user to check for
12040:
12041: =cut
1.84 albertel 12042:
12043: sub check_if_partid_hidden {
12044: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12045: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12046: $symb,$udom,$uname);
1.141 albertel 12047: my $truth=1;
12048: #if the string starts with !, then the list is the list to show not hide
12049: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12050: my @hiddenlist=split(/,/,$hiddenparts);
12051: foreach my $checkid (@hiddenlist) {
1.141 albertel 12052: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12053: }
1.141 albertel 12054: return !$truth;
1.84 albertel 12055: }
1.127 matthew 12056:
1.138 matthew 12057:
12058: ############################################################
12059: ############################################################
12060:
12061: =pod
12062:
1.157 matthew 12063: =back
12064:
1.138 matthew 12065: =head1 cgi-bin script and graphing routines
12066:
1.157 matthew 12067: =over 4
12068:
1.648 raeburn 12069: =item * &get_cgi_id()
1.138 matthew 12070:
12071: Inputs: none
12072:
12073: Returns an id which can be used to pass environment variables
12074: to various cgi-bin scripts. These environment variables will
12075: be removed from the users environment after a given time by
12076: the routine &Apache::lonnet::transfer_profile_to_env.
12077:
12078: =cut
12079:
12080: ############################################################
12081: ############################################################
1.152 albertel 12082: my $uniq=0;
1.136 matthew 12083: sub get_cgi_id {
1.154 albertel 12084: $uniq=($uniq+1)%100000;
1.280 albertel 12085: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12086: }
12087:
1.127 matthew 12088: ############################################################
12089: ############################################################
12090:
12091: =pod
12092:
1.648 raeburn 12093: =item * &DrawBarGraph()
1.127 matthew 12094:
1.138 matthew 12095: Facilitates the plotting of data in a (stacked) bar graph.
12096: Puts plot definition data into the users environment in order for
12097: graph.png to plot it. Returns an <img> tag for the plot.
12098: The bars on the plot are labeled '1','2',...,'n'.
12099:
12100: Inputs:
12101:
12102: =over 4
12103:
12104: =item $Title: string, the title of the plot
12105:
12106: =item $xlabel: string, text describing the X-axis of the plot
12107:
12108: =item $ylabel: string, text describing the Y-axis of the plot
12109:
12110: =item $Max: scalar, the maximum Y value to use in the plot
12111: If $Max is < any data point, the graph will not be rendered.
12112:
1.140 matthew 12113: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12114: they are plotted. If undefined, default values will be used.
12115:
1.178 matthew 12116: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12117:
1.138 matthew 12118: =item @Values: An array of array references. Each array reference holds data
12119: to be plotted in a stacked bar chart.
12120:
1.239 matthew 12121: =item If the final element of @Values is a hash reference the key/value
12122: pairs will be added to the graph definition.
12123:
1.138 matthew 12124: =back
12125:
12126: Returns:
12127:
12128: An <img> tag which references graph.png and the appropriate identifying
12129: information for the plot.
12130:
1.127 matthew 12131: =cut
12132:
12133: ############################################################
12134: ############################################################
1.134 matthew 12135: sub DrawBarGraph {
1.178 matthew 12136: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12137: #
12138: if (! defined($colors)) {
12139: $colors = ['#33ff00',
12140: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12141: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12142: ];
12143: }
1.228 matthew 12144: my $extra_settings = {};
12145: if (ref($Values[-1]) eq 'HASH') {
12146: $extra_settings = pop(@Values);
12147: }
1.127 matthew 12148: #
1.136 matthew 12149: my $identifier = &get_cgi_id();
12150: my $id = 'cgi.'.$identifier;
1.129 matthew 12151: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12152: return '';
12153: }
1.225 matthew 12154: #
12155: my @Labels;
12156: if (defined($labels)) {
12157: @Labels = @$labels;
12158: } else {
12159: for (my $i=0;$i<@{$Values[0]};$i++) {
12160: push (@Labels,$i+1);
12161: }
12162: }
12163: #
1.129 matthew 12164: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12165: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12166: my %ValuesHash;
12167: my $NumSets=1;
12168: foreach my $array (@Values) {
12169: next if (! ref($array));
1.136 matthew 12170: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12171: join(',',@$array);
1.129 matthew 12172: }
1.127 matthew 12173: #
1.136 matthew 12174: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12175: if ($NumBars < 3) {
12176: $width = 120+$NumBars*32;
1.220 matthew 12177: $xskip = 1;
1.225 matthew 12178: $bar_width = 30;
12179: } elsif ($NumBars < 5) {
12180: $width = 120+$NumBars*20;
12181: $xskip = 1;
12182: $bar_width = 20;
1.220 matthew 12183: } elsif ($NumBars < 10) {
1.136 matthew 12184: $width = 120+$NumBars*15;
12185: $xskip = 1;
12186: $bar_width = 15;
12187: } elsif ($NumBars <= 25) {
12188: $width = 120+$NumBars*11;
12189: $xskip = 5;
12190: $bar_width = 8;
12191: } elsif ($NumBars <= 50) {
12192: $width = 120+$NumBars*8;
12193: $xskip = 5;
12194: $bar_width = 4;
12195: } else {
12196: $width = 120+$NumBars*8;
12197: $xskip = 5;
12198: $bar_width = 4;
12199: }
12200: #
1.137 matthew 12201: $Max = 1 if ($Max < 1);
12202: if ( int($Max) < $Max ) {
12203: $Max++;
12204: $Max = int($Max);
12205: }
1.127 matthew 12206: $Title = '' if (! defined($Title));
12207: $xlabel = '' if (! defined($xlabel));
12208: $ylabel = '' if (! defined($ylabel));
1.369 www 12209: $ValuesHash{$id.'.title'} = &escape($Title);
12210: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12211: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12212: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12213: $ValuesHash{$id.'.NumBars'} = $NumBars;
12214: $ValuesHash{$id.'.NumSets'} = $NumSets;
12215: $ValuesHash{$id.'.PlotType'} = 'bar';
12216: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12217: $ValuesHash{$id.'.height'} = $height;
12218: $ValuesHash{$id.'.width'} = $width;
12219: $ValuesHash{$id.'.xskip'} = $xskip;
12220: $ValuesHash{$id.'.bar_width'} = $bar_width;
12221: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12222: #
1.228 matthew 12223: # Deal with other parameters
12224: while (my ($key,$value) = each(%$extra_settings)) {
12225: $ValuesHash{$id.'.'.$key} = $value;
12226: }
12227: #
1.646 raeburn 12228: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12229: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12230: }
12231:
12232: ############################################################
12233: ############################################################
12234:
12235: =pod
12236:
1.648 raeburn 12237: =item * &DrawXYGraph()
1.137 matthew 12238:
1.138 matthew 12239: Facilitates the plotting of data in an XY graph.
12240: Puts plot definition data into the users environment in order for
12241: graph.png to plot it. Returns an <img> tag for the plot.
12242:
12243: Inputs:
12244:
12245: =over 4
12246:
12247: =item $Title: string, the title of the plot
12248:
12249: =item $xlabel: string, text describing the X-axis of the plot
12250:
12251: =item $ylabel: string, text describing the Y-axis of the plot
12252:
12253: =item $Max: scalar, the maximum Y value to use in the plot
12254: If $Max is < any data point, the graph will not be rendered.
12255:
12256: =item $colors: Array ref containing the hex color codes for the data to be
12257: plotted in. If undefined, default values will be used.
12258:
12259: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12260:
12261: =item $Ydata: Array ref containing Array refs.
1.185 www 12262: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12263:
12264: =item %Values: hash indicating or overriding any default values which are
12265: passed to graph.png.
12266: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12267:
12268: =back
12269:
12270: Returns:
12271:
12272: An <img> tag which references graph.png and the appropriate identifying
12273: information for the plot.
12274:
1.137 matthew 12275: =cut
12276:
12277: ############################################################
12278: ############################################################
12279: sub DrawXYGraph {
12280: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12281: #
12282: # Create the identifier for the graph
12283: my $identifier = &get_cgi_id();
12284: my $id = 'cgi.'.$identifier;
12285: #
12286: $Title = '' if (! defined($Title));
12287: $xlabel = '' if (! defined($xlabel));
12288: $ylabel = '' if (! defined($ylabel));
12289: my %ValuesHash =
12290: (
1.369 www 12291: $id.'.title' => &escape($Title),
12292: $id.'.xlabel' => &escape($xlabel),
12293: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12294: $id.'.y_max_value'=> $Max,
12295: $id.'.labels' => join(',',@$Xlabels),
12296: $id.'.PlotType' => 'XY',
12297: );
12298: #
12299: if (defined($colors) && ref($colors) eq 'ARRAY') {
12300: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12301: }
12302: #
12303: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12304: return '';
12305: }
12306: my $NumSets=1;
1.138 matthew 12307: foreach my $array (@{$Ydata}){
1.137 matthew 12308: next if (! ref($array));
12309: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12310: }
1.138 matthew 12311: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12312: #
12313: # Deal with other parameters
12314: while (my ($key,$value) = each(%Values)) {
12315: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12316: }
12317: #
1.646 raeburn 12318: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12319: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12320: }
12321:
12322: ############################################################
12323: ############################################################
12324:
12325: =pod
12326:
1.648 raeburn 12327: =item * &DrawXYYGraph()
1.138 matthew 12328:
12329: Facilitates the plotting of data in an XY graph with two Y axes.
12330: Puts plot definition data into the users environment in order for
12331: graph.png to plot it. Returns an <img> tag for the plot.
12332:
12333: Inputs:
12334:
12335: =over 4
12336:
12337: =item $Title: string, the title of the plot
12338:
12339: =item $xlabel: string, text describing the X-axis of the plot
12340:
12341: =item $ylabel: string, text describing the Y-axis of the plot
12342:
12343: =item $colors: Array ref containing the hex color codes for the data to be
12344: plotted in. If undefined, default values will be used.
12345:
12346: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12347:
12348: =item $Ydata1: The first data set
12349:
12350: =item $Min1: The minimum value of the left Y-axis
12351:
12352: =item $Max1: The maximum value of the left Y-axis
12353:
12354: =item $Ydata2: The second data set
12355:
12356: =item $Min2: The minimum value of the right Y-axis
12357:
12358: =item $Max2: The maximum value of the left Y-axis
12359:
12360: =item %Values: hash indicating or overriding any default values which are
12361: passed to graph.png.
12362: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12363:
12364: =back
12365:
12366: Returns:
12367:
12368: An <img> tag which references graph.png and the appropriate identifying
12369: information for the plot.
1.136 matthew 12370:
12371: =cut
12372:
12373: ############################################################
12374: ############################################################
1.137 matthew 12375: sub DrawXYYGraph {
12376: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12377: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12378: #
12379: # Create the identifier for the graph
12380: my $identifier = &get_cgi_id();
12381: my $id = 'cgi.'.$identifier;
12382: #
12383: $Title = '' if (! defined($Title));
12384: $xlabel = '' if (! defined($xlabel));
12385: $ylabel = '' if (! defined($ylabel));
12386: my %ValuesHash =
12387: (
1.369 www 12388: $id.'.title' => &escape($Title),
12389: $id.'.xlabel' => &escape($xlabel),
12390: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12391: $id.'.labels' => join(',',@$Xlabels),
12392: $id.'.PlotType' => 'XY',
12393: $id.'.NumSets' => 2,
1.137 matthew 12394: $id.'.two_axes' => 1,
12395: $id.'.y1_max_value' => $Max1,
12396: $id.'.y1_min_value' => $Min1,
12397: $id.'.y2_max_value' => $Max2,
12398: $id.'.y2_min_value' => $Min2,
1.136 matthew 12399: );
12400: #
1.137 matthew 12401: if (defined($colors) && ref($colors) eq 'ARRAY') {
12402: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12403: }
12404: #
12405: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12406: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12407: return '';
12408: }
12409: my $NumSets=1;
1.137 matthew 12410: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12411: next if (! ref($array));
12412: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12413: }
12414: #
12415: # Deal with other parameters
12416: while (my ($key,$value) = each(%Values)) {
12417: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12418: }
12419: #
1.646 raeburn 12420: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12421: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12422: }
12423:
12424: ############################################################
12425: ############################################################
12426:
12427: =pod
12428:
1.157 matthew 12429: =back
12430:
1.139 matthew 12431: =head1 Statistics helper routines?
12432:
12433: Bad place for them but what the hell.
12434:
1.157 matthew 12435: =over 4
12436:
1.648 raeburn 12437: =item * &chartlink()
1.139 matthew 12438:
12439: Returns a link to the chart for a specific student.
12440:
12441: Inputs:
12442:
12443: =over 4
12444:
12445: =item $linktext: The text of the link
12446:
12447: =item $sname: The students username
12448:
12449: =item $sdomain: The students domain
12450:
12451: =back
12452:
1.157 matthew 12453: =back
12454:
1.139 matthew 12455: =cut
12456:
12457: ############################################################
12458: ############################################################
12459: sub chartlink {
12460: my ($linktext, $sname, $sdomain) = @_;
12461: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12462: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12463: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12464: '">'.$linktext.'</a>';
1.153 matthew 12465: }
12466:
12467: #######################################################
12468: #######################################################
12469:
12470: =pod
12471:
12472: =head1 Course Environment Routines
1.157 matthew 12473:
12474: =over 4
1.153 matthew 12475:
1.648 raeburn 12476: =item * &restore_course_settings()
1.153 matthew 12477:
1.648 raeburn 12478: =item * &store_course_settings()
1.153 matthew 12479:
12480: Restores/Store indicated form parameters from the course environment.
12481: Will not overwrite existing values of the form parameters.
12482:
12483: Inputs:
12484: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12485:
12486: a hash ref describing the data to be stored. For example:
12487:
12488: %Save_Parameters = ('Status' => 'scalar',
12489: 'chartoutputmode' => 'scalar',
12490: 'chartoutputdata' => 'scalar',
12491: 'Section' => 'array',
1.373 raeburn 12492: 'Group' => 'array',
1.153 matthew 12493: 'StudentData' => 'array',
12494: 'Maps' => 'array');
12495:
12496: Returns: both routines return nothing
12497:
1.631 raeburn 12498: =back
12499:
1.153 matthew 12500: =cut
12501:
12502: #######################################################
12503: #######################################################
12504: sub store_course_settings {
1.496 albertel 12505: return &store_settings($env{'request.course.id'},@_);
12506: }
12507:
12508: sub store_settings {
1.153 matthew 12509: # save to the environment
12510: # appenv the same items, just to be safe
1.300 albertel 12511: my $udom = $env{'user.domain'};
12512: my $uname = $env{'user.name'};
1.496 albertel 12513: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12514: my %SaveHash;
12515: my %AppHash;
12516: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12517: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12518: my $envname = 'environment.'.$basename;
1.258 albertel 12519: if (exists($env{'form.'.$setting})) {
1.153 matthew 12520: # Save this value away
12521: if ($type eq 'scalar' &&
1.258 albertel 12522: (! exists($env{$envname}) ||
12523: $env{$envname} ne $env{'form.'.$setting})) {
12524: $SaveHash{$basename} = $env{'form.'.$setting};
12525: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 12526: } elsif ($type eq 'array') {
12527: my $stored_form;
1.258 albertel 12528: if (ref($env{'form.'.$setting})) {
1.153 matthew 12529: $stored_form = join(',',
12530: map {
1.369 www 12531: &escape($_);
1.258 albertel 12532: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 12533: } else {
12534: $stored_form =
1.369 www 12535: &escape($env{'form.'.$setting});
1.153 matthew 12536: }
12537: # Determine if the array contents are the same.
1.258 albertel 12538: if ($stored_form ne $env{$envname}) {
1.153 matthew 12539: $SaveHash{$basename} = $stored_form;
12540: $AppHash{$envname} = $stored_form;
12541: }
12542: }
12543: }
12544: }
12545: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 12546: $udom,$uname);
1.153 matthew 12547: if ($put_result !~ /^(ok|delayed)/) {
12548: &Apache::lonnet::logthis('unable to save form parameters, '.
12549: 'got error:'.$put_result);
12550: }
12551: # Make sure these settings stick around in this session, too
1.646 raeburn 12552: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 12553: return;
12554: }
12555:
12556: sub restore_course_settings {
1.499 albertel 12557: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 12558: }
12559:
12560: sub restore_settings {
12561: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12562: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 12563: next if (exists($env{'form.'.$setting}));
1.496 albertel 12564: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 12565: '.'.$setting;
1.258 albertel 12566: if (exists($env{$envname})) {
1.153 matthew 12567: if ($type eq 'scalar') {
1.258 albertel 12568: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 12569: } elsif ($type eq 'array') {
1.258 albertel 12570: $env{'form.'.$setting} = [
1.153 matthew 12571: map {
1.369 www 12572: &unescape($_);
1.258 albertel 12573: } split(',',$env{$envname})
1.153 matthew 12574: ];
12575: }
12576: }
12577: }
1.127 matthew 12578: }
12579:
1.618 raeburn 12580: #######################################################
12581: #######################################################
12582:
12583: =pod
12584:
12585: =head1 Domain E-mail Routines
12586:
12587: =over 4
12588:
1.648 raeburn 12589: =item * &build_recipient_list()
1.618 raeburn 12590:
1.884 raeburn 12591: Build recipient lists for five types of e-mail:
1.766 raeburn 12592: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 12593: (d) Help requests, (e) Course requests needing approval, generated by
12594: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
12595: loncoursequeueadmin.pm respectively.
1.618 raeburn 12596:
12597: Inputs:
1.619 raeburn 12598: defmail (scalar - email address of default recipient),
1.618 raeburn 12599: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 12600: defdom (domain for which to retrieve configuration settings),
12601: origmail (scalar - email address of recipient from loncapa.conf,
12602: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 12603:
1.655 raeburn 12604: Returns: comma separated list of addresses to which to send e-mail.
12605:
12606: =back
1.618 raeburn 12607:
12608: =cut
12609:
12610: ############################################################
12611: ############################################################
12612: sub build_recipient_list {
1.619 raeburn 12613: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 12614: my @recipients;
12615: my $otheremails;
12616: my %domconfig =
12617: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
12618: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 12619: if (exists($domconfig{'contacts'}{$mailing})) {
12620: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
12621: my @contacts = ('adminemail','supportemail');
12622: foreach my $item (@contacts) {
12623: if ($domconfig{'contacts'}{$mailing}{$item}) {
12624: my $addr = $domconfig{'contacts'}{$item};
12625: if (!grep(/^\Q$addr\E$/,@recipients)) {
12626: push(@recipients,$addr);
12627: }
1.619 raeburn 12628: }
1.766 raeburn 12629: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 12630: }
12631: }
1.766 raeburn 12632: } elsif ($origmail ne '') {
12633: push(@recipients,$origmail);
1.618 raeburn 12634: }
1.619 raeburn 12635: } elsif ($origmail ne '') {
12636: push(@recipients,$origmail);
1.618 raeburn 12637: }
1.688 raeburn 12638: if (defined($defmail)) {
12639: if ($defmail ne '') {
12640: push(@recipients,$defmail);
12641: }
1.618 raeburn 12642: }
12643: if ($otheremails) {
1.619 raeburn 12644: my @others;
12645: if ($otheremails =~ /,/) {
12646: @others = split(/,/,$otheremails);
1.618 raeburn 12647: } else {
1.619 raeburn 12648: push(@others,$otheremails);
12649: }
12650: foreach my $addr (@others) {
12651: if (!grep(/^\Q$addr\E$/,@recipients)) {
12652: push(@recipients,$addr);
12653: }
1.618 raeburn 12654: }
12655: }
1.619 raeburn 12656: my $recipientlist = join(',',@recipients);
1.618 raeburn 12657: return $recipientlist;
12658: }
12659:
1.127 matthew 12660: ############################################################
12661: ############################################################
1.154 albertel 12662:
1.655 raeburn 12663: =pod
12664:
12665: =head1 Course Catalog Routines
12666:
12667: =over 4
12668:
12669: =item * &gather_categories()
12670:
12671: Converts category definitions - keys of categories hash stored in
12672: coursecategories in configuration.db on the primary library server in a
12673: domain - to an array. Also generates javascript and idx hash used to
12674: generate Domain Coordinator interface for editing Course Categories.
12675:
12676: Inputs:
1.663 raeburn 12677:
1.655 raeburn 12678: categories (reference to hash of category definitions).
1.663 raeburn 12679:
1.655 raeburn 12680: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12681: categories and subcategories).
1.663 raeburn 12682:
1.655 raeburn 12683: idx (reference to hash of counters used in Domain Coordinator interface for
12684: editing Course Categories).
1.663 raeburn 12685:
1.655 raeburn 12686: jsarray (reference to array of categories used to create Javascript arrays for
12687: Domain Coordinator interface for editing Course Categories).
12688:
12689: Returns: nothing
12690:
12691: Side effects: populates cats, idx and jsarray.
12692:
12693: =cut
12694:
12695: sub gather_categories {
12696: my ($categories,$cats,$idx,$jsarray) = @_;
12697: my %counters;
12698: my $num = 0;
12699: foreach my $item (keys(%{$categories})) {
12700: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12701: if ($container eq '' && $depth == 0) {
12702: $cats->[$depth][$categories->{$item}] = $cat;
12703: } else {
12704: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
12705: }
12706: my ($escitem,$tail) = split(/:/,$item,2);
12707: if ($counters{$tail} eq '') {
12708: $counters{$tail} = $num;
12709: $num ++;
12710: }
12711: if (ref($idx) eq 'HASH') {
12712: $idx->{$item} = $counters{$tail};
12713: }
12714: if (ref($jsarray) eq 'ARRAY') {
12715: push(@{$jsarray->[$counters{$tail}]},$item);
12716: }
12717: }
12718: return;
12719: }
12720:
12721: =pod
12722:
12723: =item * &extract_categories()
12724:
12725: Used to generate breadcrumb trails for course categories.
12726:
12727: Inputs:
1.663 raeburn 12728:
1.655 raeburn 12729: categories (reference to hash of category definitions).
1.663 raeburn 12730:
1.655 raeburn 12731: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12732: categories and subcategories).
1.663 raeburn 12733:
1.655 raeburn 12734: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 12735:
1.655 raeburn 12736: allitems (reference to hash - key is category key
12737: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12738:
1.655 raeburn 12739: idx (reference to hash of counters used in Domain Coordinator interface for
12740: editing Course Categories).
1.663 raeburn 12741:
1.655 raeburn 12742: jsarray (reference to array of categories used to create Javascript arrays for
12743: Domain Coordinator interface for editing Course Categories).
12744:
1.665 raeburn 12745: subcats (reference to hash of arrays containing all subcategories within each
12746: category, -recursive)
12747:
1.655 raeburn 12748: Returns: nothing
12749:
12750: Side effects: populates trails and allitems hash references.
12751:
12752: =cut
12753:
12754: sub extract_categories {
1.665 raeburn 12755: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 12756: if (ref($categories) eq 'HASH') {
12757: &gather_categories($categories,$cats,$idx,$jsarray);
12758: if (ref($cats->[0]) eq 'ARRAY') {
12759: for (my $i=0; $i<@{$cats->[0]}; $i++) {
12760: my $name = $cats->[0][$i];
12761: my $item = &escape($name).'::0';
12762: my $trailstr;
12763: if ($name eq 'instcode') {
12764: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 12765: } elsif ($name eq 'communities') {
12766: $trailstr = &mt('Communities');
1.655 raeburn 12767: } else {
12768: $trailstr = $name;
12769: }
12770: if ($allitems->{$item} eq '') {
12771: push(@{$trails},$trailstr);
12772: $allitems->{$item} = scalar(@{$trails})-1;
12773: }
12774: my @parents = ($name);
12775: if (ref($cats->[1]{$name}) eq 'ARRAY') {
12776: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
12777: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 12778: if (ref($subcats) eq 'HASH') {
12779: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
12780: }
12781: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
12782: }
12783: } else {
12784: if (ref($subcats) eq 'HASH') {
12785: $subcats->{$item} = [];
1.655 raeburn 12786: }
12787: }
12788: }
12789: }
12790: }
12791: return;
12792: }
12793:
12794: =pod
12795:
12796: =item *&recurse_categories()
12797:
12798: Recursively used to generate breadcrumb trails for course categories.
12799:
12800: Inputs:
1.663 raeburn 12801:
1.655 raeburn 12802: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12803: categories and subcategories).
1.663 raeburn 12804:
1.655 raeburn 12805: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 12806:
12807: category (current course category, for which breadcrumb trail is being generated).
12808:
12809: trails (reference to array of breadcrumb trails for each category).
12810:
1.655 raeburn 12811: allitems (reference to hash - key is category key
12812: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12813:
1.655 raeburn 12814: parents (array containing containers directories for current category,
12815: back to top level).
12816:
12817: Returns: nothing
12818:
12819: Side effects: populates trails and allitems hash references
12820:
12821: =cut
12822:
12823: sub recurse_categories {
1.665 raeburn 12824: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 12825: my $shallower = $depth - 1;
12826: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
12827: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
12828: my $name = $cats->[$depth]{$category}[$k];
12829: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
12830: my $trailstr = join(' -> ',(@{$parents},$category));
12831: if ($allitems->{$item} eq '') {
12832: push(@{$trails},$trailstr);
12833: $allitems->{$item} = scalar(@{$trails})-1;
12834: }
12835: my $deeper = $depth+1;
12836: push(@{$parents},$category);
1.665 raeburn 12837: if (ref($subcats) eq 'HASH') {
12838: my $subcat = &escape($name).':'.$category.':'.$depth;
12839: for (my $j=@{$parents}; $j>=0; $j--) {
12840: my $higher;
12841: if ($j > 0) {
12842: $higher = &escape($parents->[$j]).':'.
12843: &escape($parents->[$j-1]).':'.$j;
12844: } else {
12845: $higher = &escape($parents->[$j]).'::'.$j;
12846: }
12847: push(@{$subcats->{$higher}},$subcat);
12848: }
12849: }
12850: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
12851: $subcats);
1.655 raeburn 12852: pop(@{$parents});
12853: }
12854: } else {
12855: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
12856: my $trailstr = join(' -> ',(@{$parents},$category));
12857: if ($allitems->{$item} eq '') {
12858: push(@{$trails},$trailstr);
12859: $allitems->{$item} = scalar(@{$trails})-1;
12860: }
12861: }
12862: return;
12863: }
12864:
1.663 raeburn 12865: =pod
12866:
12867: =item *&assign_categories_table()
12868:
12869: Create a datatable for display of hierarchical categories in a domain,
12870: with checkboxes to allow a course to be categorized.
12871:
12872: Inputs:
12873:
12874: cathash - reference to hash of categories defined for the domain (from
12875: configuration.db)
12876:
12877: currcat - scalar with an & separated list of categories assigned to a course.
12878:
1.919 raeburn 12879: type - scalar contains course type (Course or Community).
12880:
1.663 raeburn 12881: Returns: $output (markup to be displayed)
12882:
12883: =cut
12884:
12885: sub assign_categories_table {
1.919 raeburn 12886: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 12887: my $output;
12888: if (ref($cathash) eq 'HASH') {
12889: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
12890: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
12891: $maxdepth = scalar(@cats);
12892: if (@cats > 0) {
12893: my $itemcount = 0;
12894: if (ref($cats[0]) eq 'ARRAY') {
12895: my @currcategories;
12896: if ($currcat ne '') {
12897: @currcategories = split('&',$currcat);
12898: }
1.919 raeburn 12899: my $table;
1.663 raeburn 12900: for (my $i=0; $i<@{$cats[0]}; $i++) {
12901: my $parent = $cats[0][$i];
1.919 raeburn 12902: next if ($parent eq 'instcode');
12903: if ($type eq 'Community') {
12904: next unless ($parent eq 'communities');
12905: } else {
12906: next if ($parent eq 'communities');
12907: }
1.663 raeburn 12908: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
12909: my $item = &escape($parent).'::0';
12910: my $checked = '';
12911: if (@currcategories > 0) {
12912: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 12913: $checked = ' checked="checked"';
1.663 raeburn 12914: }
12915: }
1.919 raeburn 12916: my $parent_title = $parent;
12917: if ($parent eq 'communities') {
12918: $parent_title = &mt('Communities');
12919: }
12920: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
12921: '<input type="checkbox" name="usecategory" value="'.
12922: $item.'"'.$checked.' />'.$parent_title.'</span>'.
12923: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 12924: my $depth = 1;
12925: push(@path,$parent);
1.919 raeburn 12926: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 12927: pop(@path);
1.919 raeburn 12928: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 12929: $itemcount ++;
12930: }
1.919 raeburn 12931: if ($itemcount) {
12932: $output = &Apache::loncommon::start_data_table().
12933: $table.
12934: &Apache::loncommon::end_data_table();
12935: }
1.663 raeburn 12936: }
12937: }
12938: }
12939: return $output;
12940: }
12941:
12942: =pod
12943:
12944: =item *&assign_category_rows()
12945:
12946: Create a datatable row for display of nested categories in a domain,
12947: with checkboxes to allow a course to be categorized,called recursively.
12948:
12949: Inputs:
12950:
12951: itemcount - track row number for alternating colors
12952:
12953: cats - reference to array of arrays/hashes which encapsulates hierarchy of
12954: categories and subcategories.
12955:
12956: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
12957:
12958: parent - parent of current category item
12959:
12960: path - Array containing all categories back up through the hierarchy from the
12961: current category to the top level.
12962:
12963: currcategories - reference to array of current categories assigned to the course
12964:
12965: Returns: $output (markup to be displayed).
12966:
12967: =cut
12968:
12969: sub assign_category_rows {
12970: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
12971: my ($text,$name,$item,$chgstr);
12972: if (ref($cats) eq 'ARRAY') {
12973: my $maxdepth = scalar(@{$cats});
12974: if (ref($cats->[$depth]) eq 'HASH') {
12975: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
12976: my $numchildren = @{$cats->[$depth]{$parent}};
12977: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
12978: $text .= '<td><table class="LC_datatable">';
12979: for (my $j=0; $j<$numchildren; $j++) {
12980: $name = $cats->[$depth]{$parent}[$j];
12981: $item = &escape($name).':'.&escape($parent).':'.$depth;
12982: my $deeper = $depth+1;
12983: my $checked = '';
12984: if (ref($currcategories) eq 'ARRAY') {
12985: if (@{$currcategories} > 0) {
12986: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 12987: $checked = ' checked="checked"';
1.663 raeburn 12988: }
12989: }
12990: }
1.664 raeburn 12991: $text .= '<tr><td><span class="LC_nobreak"><label>'.
12992: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 12993: $item.'"'.$checked.' />'.$name.'</label></span>'.
12994: '<input type="hidden" name="catname" value="'.$name.'" />'.
12995: '</td><td>';
1.663 raeburn 12996: if (ref($path) eq 'ARRAY') {
12997: push(@{$path},$name);
12998: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
12999: pop(@{$path});
13000: }
13001: $text .= '</td></tr>';
13002: }
13003: $text .= '</table></td>';
13004: }
13005: }
13006: }
13007: return $text;
13008: }
13009:
1.655 raeburn 13010: ############################################################
13011: ############################################################
13012:
13013:
1.443 albertel 13014: sub commit_customrole {
1.664 raeburn 13015: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13016: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13017: ($start?', '.&mt('starting').' '.localtime($start):'').
13018: ($end?', ending '.localtime($end):'').': <b>'.
13019: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13020: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13021: '</b><br />';
13022: return $output;
13023: }
13024:
13025: sub commit_standardrole {
1.541 raeburn 13026: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
13027: my ($output,$logmsg,$linefeed);
13028: if ($context eq 'auto') {
13029: $linefeed = "\n";
13030: } else {
13031: $linefeed = "<br />\n";
13032: }
1.443 albertel 13033: if ($three eq 'st') {
1.541 raeburn 13034: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
13035: $one,$two,$sec,$context);
13036: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13037: ($result eq 'unknown_course') || ($result eq 'refused')) {
13038: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13039: } else {
1.541 raeburn 13040: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13041: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13042: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13043: if ($context eq 'auto') {
13044: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13045: } else {
13046: $output .= '<b>'.$result.'</b>'.$linefeed.
13047: &mt('Add to classlist').': <b>ok</b>';
13048: }
13049: $output .= $linefeed;
1.443 albertel 13050: }
13051: } else {
13052: $output = &mt('Assigning').' '.$three.' in '.$url.
13053: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13054: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13055: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13056: if ($context eq 'auto') {
13057: $output .= $result.$linefeed;
13058: } else {
13059: $output .= '<b>'.$result.'</b>'.$linefeed;
13060: }
1.443 albertel 13061: }
13062: return $output;
13063: }
13064:
13065: sub commit_studentrole {
1.541 raeburn 13066: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 13067: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13068: if ($context eq 'auto') {
13069: $linefeed = "\n";
13070: } else {
13071: $linefeed = '<br />'."\n";
13072: }
1.443 albertel 13073: if (defined($one) && defined($two)) {
13074: my $cid=$one.'_'.$two;
13075: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13076: my $secchange = 0;
13077: my $expire_role_result;
13078: my $modify_section_result;
1.628 raeburn 13079: if ($oldsec ne '-1') {
13080: if ($oldsec ne $sec) {
1.443 albertel 13081: $secchange = 1;
1.628 raeburn 13082: my $now = time;
1.443 albertel 13083: my $uurl='/'.$cid;
13084: $uurl=~s/\_/\//g;
13085: if ($oldsec) {
13086: $uurl.='/'.$oldsec;
13087: }
1.626 raeburn 13088: $oldsecurl = $uurl;
1.628 raeburn 13089: $expire_role_result =
1.652 raeburn 13090: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13091: if ($env{'request.course.sec'} ne '') {
13092: if ($expire_role_result eq 'refused') {
13093: my @roles = ('st');
13094: my @statuses = ('previous');
13095: my @roledoms = ($one);
13096: my $withsec = 1;
13097: my %roleshash =
13098: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13099: \@statuses,\@roles,\@roledoms,$withsec);
13100: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13101: my ($oldstart,$oldend) =
13102: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13103: if ($oldend > 0 && $oldend <= $now) {
13104: $expire_role_result = 'ok';
13105: }
13106: }
13107: }
13108: }
1.443 albertel 13109: $result = $expire_role_result;
13110: }
13111: }
13112: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 13113: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 13114: if ($modify_section_result =~ /^ok/) {
13115: if ($secchange == 1) {
1.628 raeburn 13116: if ($sec eq '') {
13117: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13118: } else {
13119: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13120: }
1.443 albertel 13121: } elsif ($oldsec eq '-1') {
1.628 raeburn 13122: if ($sec eq '') {
13123: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13124: } else {
13125: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13126: }
1.443 albertel 13127: } else {
1.628 raeburn 13128: if ($sec eq '') {
13129: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13130: } else {
13131: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13132: }
1.443 albertel 13133: }
13134: } else {
1.628 raeburn 13135: if ($secchange) {
13136: $$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;
13137: } else {
13138: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13139: }
1.443 albertel 13140: }
13141: $result = $modify_section_result;
13142: } elsif ($secchange == 1) {
1.628 raeburn 13143: if ($oldsec eq '') {
13144: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
13145: } else {
13146: $$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;
13147: }
1.626 raeburn 13148: if ($expire_role_result eq 'refused') {
13149: my $newsecurl = '/'.$cid;
13150: $newsecurl =~ s/\_/\//g;
13151: if ($sec ne '') {
13152: $newsecurl.='/'.$sec;
13153: }
13154: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13155: if ($sec eq '') {
13156: $$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;
13157: } else {
13158: $$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;
13159: }
13160: }
13161: }
1.443 albertel 13162: }
13163: } else {
1.626 raeburn 13164: $$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 13165: $result = "error: incomplete course id\n";
13166: }
13167: return $result;
13168: }
13169:
13170: ############################################################
13171: ############################################################
13172:
1.566 albertel 13173: sub check_clone {
1.578 raeburn 13174: my ($args,$linefeed) = @_;
1.566 albertel 13175: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13176: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13177: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13178: my $clonemsg;
13179: my $can_clone = 0;
1.944 raeburn 13180: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13181: if ($lctype ne 'community') {
13182: $lctype = 'course';
13183: }
1.566 albertel 13184: if ($clonehome eq 'no_host') {
1.944 raeburn 13185: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13186: $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'});
13187: } else {
13188: $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'});
13189: }
1.566 albertel 13190: } else {
13191: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13192: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13193: if ($clonedesc{'type'} ne 'Community') {
13194: $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'});
13195: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13196: }
13197: }
1.882 raeburn 13198: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13199: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13200: $can_clone = 1;
13201: } else {
13202: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13203: $args->{'clonedomain'},$args->{'clonecourse'});
13204: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13205: if (grep(/^\*$/,@cloners)) {
13206: $can_clone = 1;
13207: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13208: $can_clone = 1;
13209: } else {
1.908 raeburn 13210: my $ccrole = 'cc';
1.944 raeburn 13211: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13212: $ccrole = 'co';
13213: }
1.578 raeburn 13214: my %roleshash =
13215: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13216: $args->{'ccdomain'},
1.908 raeburn 13217: 'userroles',['active'],[$ccrole],
1.578 raeburn 13218: [$args->{'clonedomain'}]);
1.908 raeburn 13219: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13220: $can_clone = 1;
13221: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13222: $can_clone = 1;
13223: } else {
1.944 raeburn 13224: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13225: $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'});
13226: } else {
13227: $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'});
13228: }
1.578 raeburn 13229: }
1.566 albertel 13230: }
1.578 raeburn 13231: }
1.566 albertel 13232: }
13233: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13234: }
13235:
1.444 albertel 13236: sub construct_course {
1.885 raeburn 13237: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13238: my $outcome;
1.541 raeburn 13239: my $linefeed = '<br />'."\n";
13240: if ($context eq 'auto') {
13241: $linefeed = "\n";
13242: }
1.566 albertel 13243:
13244: #
13245: # Are we cloning?
13246: #
13247: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13248: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13249: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13250: if ($context ne 'auto') {
1.578 raeburn 13251: if ($clonemsg ne '') {
13252: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13253: }
1.566 albertel 13254: }
13255: $outcome .= $clonemsg.$linefeed;
13256:
13257: if (!$can_clone) {
13258: return (0,$outcome);
13259: }
13260: }
13261:
1.444 albertel 13262: #
13263: # Open course
13264: #
13265: my $crstype = lc($args->{'crstype'});
13266: my %cenv=();
13267: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13268: $args->{'cdescr'},
13269: $args->{'curl'},
13270: $args->{'course_home'},
13271: $args->{'nonstandard'},
13272: $args->{'crscode'},
13273: $args->{'ccuname'}.':'.
13274: $args->{'ccdomain'},
1.882 raeburn 13275: $args->{'crstype'},
1.885 raeburn 13276: $cnum,$context,$category);
1.444 albertel 13277:
13278: # Note: The testing routines depend on this being output; see
13279: # Utils::Course. This needs to at least be output as a comment
13280: # if anyone ever decides to not show this, and Utils::Course::new
13281: # will need to be suitably modified.
1.541 raeburn 13282: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13283: if ($$courseid =~ /^error:/) {
13284: return (0,$outcome);
13285: }
13286:
1.444 albertel 13287: #
13288: # Check if created correctly
13289: #
1.479 albertel 13290: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13291: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13292: if ($crsuhome eq 'no_host') {
13293: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13294: return (0,$outcome);
13295: }
1.541 raeburn 13296: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13297:
1.444 albertel 13298: #
1.566 albertel 13299: # Do the cloning
13300: #
13301: if ($can_clone && $cloneid) {
13302: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13303: if ($context ne 'auto') {
13304: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13305: }
13306: $outcome .= $clonemsg.$linefeed;
13307: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13308: # Copy all files
1.637 www 13309: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13310: # Restore URL
1.566 albertel 13311: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13312: # Restore title
1.566 albertel 13313: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13314: # Restore creation date, creator and creation context.
13315: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13316: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13317: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13318: # Mark as cloned
1.566 albertel 13319: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13320: # Need to clone grading mode
13321: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13322: $cenv{'grading'}=$newenv{'grading'};
13323: # Do not clone these environment entries
13324: &Apache::lonnet::del('environment',
13325: ['default_enrollment_start_date',
13326: 'default_enrollment_end_date',
13327: 'question.email',
13328: 'policy.email',
13329: 'comment.email',
13330: 'pch.users.denied',
1.725 raeburn 13331: 'plc.users.denied',
13332: 'hidefromcat',
13333: 'categories'],
1.638 www 13334: $$crsudom,$$crsunum);
1.444 albertel 13335: }
1.566 albertel 13336:
1.444 albertel 13337: #
13338: # Set environment (will override cloned, if existing)
13339: #
13340: my @sections = ();
13341: my @xlists = ();
13342: if ($args->{'crstype'}) {
13343: $cenv{'type'}=$args->{'crstype'};
13344: }
13345: if ($args->{'crsid'}) {
13346: $cenv{'courseid'}=$args->{'crsid'};
13347: }
13348: if ($args->{'crscode'}) {
13349: $cenv{'internal.coursecode'}=$args->{'crscode'};
13350: }
13351: if ($args->{'crsquota'} ne '') {
13352: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13353: } else {
13354: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13355: }
13356: if ($args->{'ccuname'}) {
13357: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13358: ':'.$args->{'ccdomain'};
13359: } else {
13360: $cenv{'internal.courseowner'} = $args->{'curruser'};
13361: }
13362: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13363: if ($args->{'crssections'}) {
13364: $cenv{'internal.sectionnums'} = '';
13365: if ($args->{'crssections'} =~ m/,/) {
13366: @sections = split/,/,$args->{'crssections'};
13367: } else {
13368: $sections[0] = $args->{'crssections'};
13369: }
13370: if (@sections > 0) {
13371: foreach my $item (@sections) {
13372: my ($sec,$gp) = split/:/,$item;
13373: my $class = $args->{'crscode'}.$sec;
13374: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13375: $cenv{'internal.sectionnums'} .= $item.',';
13376: unless ($addcheck eq 'ok') {
13377: push @badclasses, $class;
13378: }
13379: }
13380: $cenv{'internal.sectionnums'} =~ s/,$//;
13381: }
13382: }
13383: # do not hide course coordinator from staff listing,
13384: # even if privileged
13385: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13386: # add crosslistings
13387: if ($args->{'crsxlist'}) {
13388: $cenv{'internal.crosslistings'}='';
13389: if ($args->{'crsxlist'} =~ m/,/) {
13390: @xlists = split/,/,$args->{'crsxlist'};
13391: } else {
13392: $xlists[0] = $args->{'crsxlist'};
13393: }
13394: if (@xlists > 0) {
13395: foreach my $item (@xlists) {
13396: my ($xl,$gp) = split/:/,$item;
13397: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13398: $cenv{'internal.crosslistings'} .= $item.',';
13399: unless ($addcheck eq 'ok') {
13400: push @badclasses, $xl;
13401: }
13402: }
13403: $cenv{'internal.crosslistings'} =~ s/,$//;
13404: }
13405: }
13406: if ($args->{'autoadds'}) {
13407: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13408: }
13409: if ($args->{'autodrops'}) {
13410: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13411: }
13412: # check for notification of enrollment changes
13413: my @notified = ();
13414: if ($args->{'notify_owner'}) {
13415: if ($args->{'ccuname'} ne '') {
13416: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13417: }
13418: }
13419: if ($args->{'notify_dc'}) {
13420: if ($uname ne '') {
1.630 raeburn 13421: push(@notified,$uname.':'.$udom);
1.444 albertel 13422: }
13423: }
13424: if (@notified > 0) {
13425: my $notifylist;
13426: if (@notified > 1) {
13427: $notifylist = join(',',@notified);
13428: } else {
13429: $notifylist = $notified[0];
13430: }
13431: $cenv{'internal.notifylist'} = $notifylist;
13432: }
13433: if (@badclasses > 0) {
13434: my %lt=&Apache::lonlocal::texthash(
13435: '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',
13436: 'dnhr' => 'does not have rights to access enrollment in these classes',
13437: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13438: );
1.541 raeburn 13439: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13440: ' ('.$lt{'adby'}.')';
13441: if ($context eq 'auto') {
13442: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13443: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13444: foreach my $item (@badclasses) {
13445: if ($context eq 'auto') {
13446: $outcome .= " - $item\n";
13447: } else {
13448: $outcome .= "<li>$item</li>\n";
13449: }
13450: }
13451: if ($context eq 'auto') {
13452: $outcome .= $linefeed;
13453: } else {
1.566 albertel 13454: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13455: }
13456: }
1.444 albertel 13457: }
13458: if ($args->{'no_end_date'}) {
13459: $args->{'endaccess'} = 0;
13460: }
13461: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13462: $cenv{'internal.autoend'}=$args->{'enrollend'};
13463: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13464: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13465: if ($args->{'showphotos'}) {
13466: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13467: }
13468: $cenv{'internal.authtype'} = $args->{'authtype'};
13469: $cenv{'internal.autharg'} = $args->{'autharg'};
13470: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13471: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13472: 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');
13473: if ($context eq 'auto') {
13474: $outcome .= $krb_msg;
13475: } else {
1.566 albertel 13476: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13477: }
13478: $outcome .= $linefeed;
1.444 albertel 13479: }
13480: }
13481: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13482: if ($args->{'setpolicy'}) {
13483: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13484: }
13485: if ($args->{'setcontent'}) {
13486: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13487: }
13488: }
13489: if ($args->{'reshome'}) {
13490: $cenv{'reshome'}=$args->{'reshome'}.'/';
13491: $cenv{'reshome'}=~s/\/+$/\//;
13492: }
13493: #
13494: # course has keyed access
13495: #
13496: if ($args->{'setkeys'}) {
13497: $cenv{'keyaccess'}='yes';
13498: }
13499: # if specified, key authority is not course, but user
13500: # only active if keyaccess is yes
13501: if ($args->{'keyauth'}) {
1.487 albertel 13502: my ($user,$domain) = split(':',$args->{'keyauth'});
13503: $user = &LONCAPA::clean_username($user);
13504: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 13505: if ($user ne '' && $domain ne '') {
1.487 albertel 13506: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 13507: }
13508: }
13509:
13510: if ($args->{'disresdis'}) {
13511: $cenv{'pch.roles.denied'}='st';
13512: }
13513: if ($args->{'disablechat'}) {
13514: $cenv{'plc.roles.denied'}='st';
13515: }
13516:
13517: # Record we've not yet viewed the Course Initialization Helper for this
13518: # course
13519: $cenv{'course.helper.not.run'} = 1;
13520: #
13521: # Use new Randomseed
13522: #
13523: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
13524: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
13525: #
13526: # The encryption code and receipt prefix for this course
13527: #
13528: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
13529: $cenv{'internal.encpref'}=100+int(9*rand(99));
13530: #
13531: # By default, use standard grading
13532: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
13533:
1.541 raeburn 13534: $outcome .= $linefeed.&mt('Setting environment').': '.
13535: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13536: #
13537: # Open all assignments
13538: #
13539: if ($args->{'openall'}) {
13540: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
13541: my %storecontent = ($storeunder => time,
13542: $storeunder.'.type' => 'date_start');
13543:
13544: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 13545: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13546: }
13547: #
13548: # Set first page
13549: #
13550: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
13551: || ($cloneid)) {
1.445 albertel 13552: use LONCAPA::map;
1.444 albertel 13553: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 13554:
13555: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
13556: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
13557:
1.444 albertel 13558: $outcome .= ($fatal?$errtext:'read ok').' - ';
13559: my $title; my $url;
13560: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 13561: $title=&mt('Syllabus');
1.444 albertel 13562: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
13563: } else {
1.963 raeburn 13564: $title=&mt('Table of Contents');
1.444 albertel 13565: $url='/adm/navmaps';
13566: }
1.445 albertel 13567:
13568: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
13569: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
13570:
13571: if ($errtext) { $fatal=2; }
1.541 raeburn 13572: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 13573: }
1.566 albertel 13574:
13575: return (1,$outcome);
1.444 albertel 13576: }
13577:
13578: ############################################################
13579: ############################################################
13580:
1.953 droeschl 13581: #SD
13582: # only Community and Course, or anything else?
1.378 raeburn 13583: sub course_type {
13584: my ($cid) = @_;
13585: if (!defined($cid)) {
13586: $cid = $env{'request.course.id'};
13587: }
1.404 albertel 13588: if (defined($env{'course.'.$cid.'.type'})) {
13589: return $env{'course.'.$cid.'.type'};
1.378 raeburn 13590: } else {
13591: return 'Course';
1.377 raeburn 13592: }
13593: }
1.156 albertel 13594:
1.406 raeburn 13595: sub group_term {
13596: my $crstype = &course_type();
13597: my %names = (
13598: 'Course' => 'group',
1.865 raeburn 13599: 'Community' => 'group',
1.406 raeburn 13600: );
13601: return $names{$crstype};
13602: }
13603:
1.902 raeburn 13604: sub course_types {
13605: my @types = ('official','unofficial','community');
13606: my %typename = (
13607: official => 'Official course',
13608: unofficial => 'Unofficial course',
13609: community => 'Community',
13610: );
13611: return (\@types,\%typename);
13612: }
13613:
1.156 albertel 13614: sub icon {
13615: my ($file)=@_;
1.505 albertel 13616: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 13617: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 13618: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 13619: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
13620: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
13621: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13622: $curfext.".gif") {
13623: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13624: $curfext.".gif";
13625: }
13626: }
1.249 albertel 13627: return &lonhttpdurl($iconname);
1.154 albertel 13628: }
1.84 albertel 13629:
1.575 albertel 13630: sub lonhttpdurl {
1.692 www 13631: #
13632: # Had been used for "small fry" static images on separate port 8080.
13633: # Modify here if lightweight http functionality desired again.
13634: # Currently eliminated due to increasing firewall issues.
13635: #
1.575 albertel 13636: my ($url)=@_;
1.692 www 13637: return $url;
1.215 albertel 13638: }
13639:
1.213 albertel 13640: sub connection_aborted {
13641: my ($r)=@_;
13642: $r->print(" ");$r->rflush();
13643: my $c = $r->connection;
13644: return $c->aborted();
13645: }
13646:
1.221 foxr 13647: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 13648: # strings as 'strings'.
13649: sub escape_single {
1.221 foxr 13650: my ($input) = @_;
1.223 albertel 13651: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 13652: $input =~ s/\'/\\\'/g; # Esacpe the 's....
13653: return $input;
13654: }
1.223 albertel 13655:
1.222 foxr 13656: # Same as escape_single, but escape's "'s This
13657: # can be used for "strings"
13658: sub escape_double {
13659: my ($input) = @_;
13660: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
13661: $input =~ s/\"/\\\"/g; # Esacpe the "s....
13662: return $input;
13663: }
1.223 albertel 13664:
1.222 foxr 13665: # Escapes the last element of a full URL.
13666: sub escape_url {
13667: my ($url) = @_;
1.238 raeburn 13668: my @urlslices = split(/\//, $url,-1);
1.369 www 13669: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 13670: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 13671: }
1.462 albertel 13672:
1.820 raeburn 13673: sub compare_arrays {
13674: my ($arrayref1,$arrayref2) = @_;
13675: my (@difference,%count);
13676: @difference = ();
13677: %count = ();
13678: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
13679: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
13680: foreach my $element (keys(%count)) {
13681: if ($count{$element} == 1) {
13682: push(@difference,$element);
13683: }
13684: }
13685: }
13686: return @difference;
13687: }
13688:
1.817 bisitz 13689: # -------------------------------------------------------- Initialize user login
1.462 albertel 13690: sub init_user_environment {
1.463 albertel 13691: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 13692: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
13693:
13694: my $public=($username eq 'public' && $domain eq 'public');
13695:
13696: # See if old ID present, if so, remove
13697:
1.1062 raeburn 13698: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 13699: my $now=time;
13700:
13701: if ($public) {
13702: my $max_public=100;
13703: my $oldest;
13704: my $oldest_time=0;
13705: for(my $next=1;$next<=$max_public;$next++) {
13706: if (-e $lonids."/publicuser_$next.id") {
13707: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
13708: if ($mtime<$oldest_time || !$oldest_time) {
13709: $oldest_time=$mtime;
13710: $oldest=$next;
13711: }
13712: } else {
13713: $cookie="publicuser_$next";
13714: last;
13715: }
13716: }
13717: if (!$cookie) { $cookie="publicuser_$oldest"; }
13718: } else {
1.463 albertel 13719: # if this isn't a robot, kill any existing non-robot sessions
13720: if (!$args->{'robot'}) {
13721: opendir(DIR,$lonids);
13722: while ($filename=readdir(DIR)) {
13723: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
13724: unlink($lonids.'/'.$filename);
13725: }
1.462 albertel 13726: }
1.463 albertel 13727: closedir(DIR);
1.462 albertel 13728: }
13729: # Give them a new cookie
1.463 albertel 13730: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 13731: : $now.$$.int(rand(10000)));
1.463 albertel 13732: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 13733:
13734: # Initialize roles
13735:
1.1062 raeburn 13736: ($userroles,$firstaccenv,$timerintenv) =
13737: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 13738: }
13739: # ------------------------------------ Check browser type and MathML capability
13740:
13741: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
13742: $clientunicode,$clientos) = &decode_user_agent($r);
13743:
13744: # ------------------------------------------------------------- Get environment
13745:
13746: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
13747: my ($tmp) = keys(%userenv);
13748: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
13749: } else {
13750: undef(%userenv);
13751: }
13752: if (($userenv{'interface'}) && (!$form->{'interface'})) {
13753: $form->{'interface'}=$userenv{'interface'};
13754: }
13755: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
13756:
13757: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 13758: foreach my $option ('interface','localpath','localres') {
13759: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 13760: }
13761: # --------------------------------------------------------- Write first profile
13762:
13763: {
13764: my %initial_env =
13765: ("user.name" => $username,
13766: "user.domain" => $domain,
13767: "user.home" => $authhost,
13768: "browser.type" => $clientbrowser,
13769: "browser.version" => $clientversion,
13770: "browser.mathml" => $clientmathml,
13771: "browser.unicode" => $clientunicode,
13772: "browser.os" => $clientos,
13773: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
13774: "request.course.fn" => '',
13775: "request.course.uri" => '',
13776: "request.course.sec" => '',
13777: "request.role" => 'cm',
13778: "request.role.adv" => $env{'user.adv'},
13779: "request.host" => $ENV{'REMOTE_ADDR'},);
13780:
13781: if ($form->{'localpath'}) {
13782: $initial_env{"browser.localpath"} = $form->{'localpath'};
13783: $initial_env{"browser.localres"} = $form->{'localres'};
13784: }
13785:
13786: if ($form->{'interface'}) {
13787: $form->{'interface'}=~s/\W//gs;
13788: $initial_env{"browser.interface"} = $form->{'interface'};
13789: $env{'browser.interface'}=$form->{'interface'};
13790: }
13791:
1.981 raeburn 13792: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 13793: my %domdef;
13794: unless ($domain eq 'public') {
13795: %domdef = &Apache::lonnet::get_domain_defaults($domain);
13796: }
1.980 raeburn 13797:
1.1081 raeburn 13798: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 13799: $userenv{'availabletools.'.$tool} =
1.980 raeburn 13800: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
13801: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 13802: }
13803:
1.864 raeburn 13804: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 13805: $userenv{'canrequest.'.$crstype} =
13806: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 13807: 'reload','requestcourses',
13808: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 13809: }
13810:
1.462 albertel 13811: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 13812:
1.462 albertel 13813: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
13814: &GDBM_WRCREAT(),0640)) {
13815: &_add_to_env(\%disk_env,\%initial_env);
13816: &_add_to_env(\%disk_env,\%userenv,'environment.');
13817: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 13818: if (ref($firstaccenv) eq 'HASH') {
13819: &_add_to_env(\%disk_env,$firstaccenv);
13820: }
13821: if (ref($timerintenv) eq 'HASH') {
13822: &_add_to_env(\%disk_env,$timerintenv);
13823: }
1.463 albertel 13824: if (ref($args->{'extra_env'})) {
13825: &_add_to_env(\%disk_env,$args->{'extra_env'});
13826: }
1.462 albertel 13827: untie(%disk_env);
13828: } else {
1.705 tempelho 13829: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
13830: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 13831: return 'error: '.$!;
13832: }
13833: }
13834: $env{'request.role'}='cm';
13835: $env{'request.role.adv'}=$env{'user.adv'};
13836: $env{'browser.type'}=$clientbrowser;
13837:
13838: return $cookie;
13839:
13840: }
13841:
13842: sub _add_to_env {
13843: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 13844: if (ref($env_data) eq 'HASH') {
13845: while (my ($key,$value) = each(%$env_data)) {
13846: $idf->{$prefix.$key} = $value;
13847: $env{$prefix.$key} = $value;
13848: }
1.462 albertel 13849: }
13850: }
13851:
1.685 tempelho 13852: # --- Get the symbolic name of a problem and the url
13853: sub get_symb {
13854: my ($request,$silent) = @_;
1.726 raeburn 13855: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 13856: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
13857: if ($symb eq '') {
13858: if (!$silent) {
1.1071 raeburn 13859: if (ref($request)) {
13860: $request->print("Unable to handle ambiguous references:$url:.");
13861: }
1.685 tempelho 13862: return ();
13863: }
13864: }
13865: &Apache::lonenc::check_decrypt(\$symb);
13866: return ($symb);
13867: }
13868:
13869: # --------------------------------------------------------------Get annotation
13870:
13871: sub get_annotation {
13872: my ($symb,$enc) = @_;
13873:
13874: my $key = $symb;
13875: if (!$enc) {
13876: $key =
13877: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
13878: }
13879: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
13880: return $annotation{$key};
13881: }
13882:
13883: sub clean_symb {
1.731 raeburn 13884: my ($symb,$delete_enc) = @_;
1.685 tempelho 13885:
13886: &Apache::lonenc::check_decrypt(\$symb);
13887: my $enc = $env{'request.enc'};
1.731 raeburn 13888: if ($delete_enc) {
1.730 raeburn 13889: delete($env{'request.enc'});
13890: }
1.685 tempelho 13891:
13892: return ($symb,$enc);
13893: }
1.462 albertel 13894:
1.990 raeburn 13895: sub build_release_hashes {
13896: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
13897: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
13898: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
13899: (ref($randomizetry) eq 'HASH'));
13900: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
13901: my ($item,$name,$value) = split(/:/,$key);
13902: if ($item eq 'parameter') {
13903: if (ref($checkparms->{$name}) eq 'ARRAY') {
13904: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
13905: push(@{$checkparms->{$name}},$value);
13906: }
13907: } else {
13908: push(@{$checkparms->{$name}},$value);
13909: }
13910: } elsif ($item eq 'resourcetag') {
13911: if ($name eq 'responsetype') {
13912: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
13913: }
13914: } elsif ($item eq 'course') {
13915: if ($name eq 'crstype') {
13916: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
13917: }
13918: }
13919: }
13920: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
13921: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
13922: return;
13923: }
13924:
1.1083 raeburn 13925: sub update_content_constraints {
13926: my ($cdom,$cnum,$chome,$cid) = @_;
13927: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
13928: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
13929: my %checkresponsetypes;
13930: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
13931: my ($item,$name,$value) = split(/:/,$key);
13932: if ($item eq 'resourcetag') {
13933: if ($name eq 'responsetype') {
13934: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
13935: }
13936: }
13937: }
13938: my $navmap = Apache::lonnavmaps::navmap->new();
13939: if (defined($navmap)) {
13940: my %allresponses;
13941: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
13942: my %responses = $res->responseTypes();
13943: foreach my $key (keys(%responses)) {
13944: next unless(exists($checkresponsetypes{$key}));
13945: $allresponses{$key} += $responses{$key};
13946: }
13947: }
13948: foreach my $key (keys(%allresponses)) {
13949: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
13950: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
13951: ($reqdmajor,$reqdminor) = ($major,$minor);
13952: }
13953: }
13954: undef($navmap);
13955: }
13956: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
13957: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
13958: }
13959: return;
13960: }
13961:
13962: sub parse_supplemental_title {
13963: my ($title) = @_;
13964:
13965: my ($foldertitle,$renametitle);
13966: if ($title =~ /&&&/) {
13967: $title = &HTML::Entites::decode($title);
13968: }
13969: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
13970: $renametitle=$4;
13971: my ($time,$uname,$udom) = ($1,$2,$3);
13972: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
13973: my $name = &plainname($uname,$udom);
13974: $name = &HTML::Entities::encode($name,'"<>&\'');
13975: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
13976: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
13977: $name.': <br />'.$foldertitle;
13978: }
13979: if (wantarray) {
13980: return ($title,$foldertitle,$renametitle);
13981: }
13982: return $title;
13983: }
13984:
1.41 ng 13985: =pod
13986:
13987: =back
13988:
1.112 bowersj2 13989: =cut
1.41 ng 13990:
1.112 bowersj2 13991: 1;
13992: __END__;
1.41 ng 13993:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>