Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.59
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.59! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.58 2013/12/19 08:28:05 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1075.2.14 raeburn 75: use Authen::Captcha;
76: use Captcha::reCAPTCHA;
1.117 www 77:
1.517 raeburn 78: # ---------------------------------------------- Designs
79: use vars qw(%defaultdesign);
80:
1.22 www 81: my $readit;
82:
1.517 raeburn 83:
1.157 matthew 84: ##
85: ## Global Variables
86: ##
1.46 matthew 87:
1.643 foxr 88:
89: # ----------------------------------------------- SSI with retries:
90: #
91:
92: =pod
93:
1.648 raeburn 94: =head1 Server Side include with retries:
1.643 foxr 95:
96: =over 4
97:
1.648 raeburn 98: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 99:
100: Performs an ssi with some number of retries. Retries continue either
101: until the result is ok or until the retry count supplied by the
102: caller is exhausted.
103:
104: Inputs:
1.648 raeburn 105:
106: =over 4
107:
1.643 foxr 108: resource - Identifies the resource to insert.
1.648 raeburn 109:
1.643 foxr 110: retries - Count of the number of retries allowed.
1.648 raeburn 111:
1.643 foxr 112: form - Hash that identifies the rendering options.
113:
1.648 raeburn 114: =back
115:
116: Returns:
117:
118: =over 4
119:
1.643 foxr 120: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 121:
1.643 foxr 122: response - The response from the last attempt (which may or may not have been successful.
123:
1.648 raeburn 124: =back
125:
126: =back
127:
1.643 foxr 128: =cut
129:
130: sub ssi_with_retries {
131: my ($resource, $retries, %form) = @_;
132:
133:
134: my $ok = 0; # True if we got a good response.
135: my $content;
136: my $response;
137:
138: # Try to get the ssi done. within the retries count:
139:
140: do {
141: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
142: $ok = $response->is_success;
1.650 www 143: if (!$ok) {
144: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
145: }
1.643 foxr 146: $retries--;
147: } while (!$ok && ($retries > 0));
148:
149: if (!$ok) {
150: $content = ''; # On error return an empty content.
151: }
152: return ($content, $response);
153:
154: }
155:
156:
157:
1.20 www 158: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 159: my %language;
1.124 www 160: my %supported_language;
1.1048 foxr 161: my %latex_language; # For choosing hyphenation in <transl..>
162: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 163: my %cprtag;
1.192 taceyjo1 164: my %scprtag;
1.351 www 165: my %fe; my %fd; my %fm;
1.41 ng 166: my %category_extensions;
1.12 harris41 167:
1.46 matthew 168: # ---------------------------------------------- Thesaurus variables
1.144 matthew 169: #
170: # %Keywords:
171: # A hash used by &keyword to determine if a word is considered a keyword.
172: # $thesaurus_db_file
173: # Scalar containing the full path to the thesaurus database.
1.46 matthew 174:
175: my %Keywords;
176: my $thesaurus_db_file;
177:
1.144 matthew 178: #
179: # Initialize values from language.tab, copyright.tab, filetypes.tab,
180: # thesaurus.tab, and filecategories.tab.
181: #
1.18 www 182: BEGIN {
1.46 matthew 183: # Variable initialization
184: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
185: #
1.22 www 186: unless ($readit) {
1.12 harris41 187: # ------------------------------------------------------------------- languages
188: {
1.158 raeburn 189: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
190: '/language.tab';
191: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 192: while (my $line = <$fh>) {
193: next if ($line=~/^\#/);
194: chomp($line);
1.1048 foxr 195: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 196: $language{$key}=$val.' - '.$enc;
197: if ($sup) {
198: $supported_language{$key}=$sup;
199: }
1.1048 foxr 200: if ($latex) {
201: $latex_language_bykey{$key} = $latex;
202: $latex_language{$two} = $latex;
203: }
1.158 raeburn 204: }
205: close($fh);
206: }
1.12 harris41 207: }
208: # ------------------------------------------------------------------ copyrights
209: {
1.158 raeburn 210: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
211: '/copyright.tab';
212: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 213: while (my $line = <$fh>) {
214: next if ($line=~/^\#/);
215: chomp($line);
216: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 217: $cprtag{$key}=$val;
218: }
219: close($fh);
220: }
1.12 harris41 221: }
1.351 www 222: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 223: {
224: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
225: '/source_copyright.tab';
226: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 227: while (my $line = <$fh>) {
228: next if ($line =~ /^\#/);
229: chomp($line);
230: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 231: $scprtag{$key}=$val;
232: }
233: close($fh);
234: }
235: }
1.63 www 236:
1.517 raeburn 237: # -------------------------------------------------------------- default domain designs
1.63 www 238: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 239: my $designfile = $designdir.'/default.tab';
240: if ( open (my $fh,"<$designfile") ) {
241: while (my $line = <$fh>) {
242: next if ($line =~ /^\#/);
243: chomp($line);
244: my ($key,$val)=(split(/\=/,$line));
245: if ($val) { $defaultdesign{$key}=$val; }
246: }
247: close($fh);
1.63 www 248: }
249:
1.15 harris41 250: # ------------------------------------------------------------- file categories
251: {
1.158 raeburn 252: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
253: '/filecategories.tab';
254: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 255: while (my $line = <$fh>) {
256: next if ($line =~ /^\#/);
257: chomp($line);
258: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 259: push @{$category_extensions{lc($category)}},$extension;
260: }
261: close($fh);
262: }
263:
1.15 harris41 264: }
1.12 harris41 265: # ------------------------------------------------------------------ file types
266: {
1.158 raeburn 267: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
268: '/filetypes.tab';
269: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 270: while (my $line = <$fh>) {
271: next if ($line =~ /^\#/);
272: chomp($line);
273: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 274: if ($descr ne '') {
275: $fe{$ending}=lc($emb);
276: $fd{$ending}=$descr;
1.351 www 277: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 278: }
279: }
280: close($fh);
281: }
1.12 harris41 282: }
1.22 www 283: &Apache::lonnet::logthis(
1.705 tempelho 284: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 285: $readit=1;
1.46 matthew 286: } # end of unless($readit)
1.32 matthew 287:
288: }
1.112 bowersj2 289:
1.42 matthew 290: ###############################################################
291: ## HTML and Javascript Helper Functions ##
292: ###############################################################
293:
294: =pod
295:
1.112 bowersj2 296: =head1 HTML and Javascript Functions
1.42 matthew 297:
1.112 bowersj2 298: =over 4
299:
1.648 raeburn 300: =item * &browser_and_searcher_javascript()
1.112 bowersj2 301:
302: X<browsing, javascript>X<searching, javascript>Returns a string
303: containing javascript with two functions, C<openbrowser> and
304: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
305: tags.
1.42 matthew 306:
1.648 raeburn 307: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 308:
309: inputs: formname, elementname, only, omit
310:
311: formname and elementname indicate the name of the html form and name of
312: the element that the results of the browsing selection are to be placed in.
313:
314: Specifying 'only' will restrict the browser to displaying only files
1.185 www 315: with the given extension. Can be a comma separated list.
1.42 matthew 316:
317: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
1.648 raeburn 320: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 321:
322: Inputs: formname, elementname
323:
324: formname and elementname specify the name of the html form and the name
325: of the element the selection from the search results will be placed in.
1.542 raeburn 326:
1.42 matthew 327: =cut
328:
329: sub browser_and_searcher_javascript {
1.199 albertel 330: my ($mode)=@_;
331: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 332: my $resurl=&escape_single(&lastresurl());
1.42 matthew 333: return <<END;
1.219 albertel 334: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 335: var editbrowser = null;
1.135 albertel 336: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 337: var url = '$resurl/?';
1.42 matthew 338: if (editbrowser == null) {
339: url += 'launch=1&';
340: }
341: url += 'catalogmode=interactive&';
1.199 albertel 342: url += 'mode=$mode&';
1.611 albertel 343: url += 'inhibitmenu=yes&';
1.42 matthew 344: url += 'form=' + formname + '&';
345: if (only != null) {
346: url += 'only=' + only + '&';
1.217 albertel 347: } else {
348: url += 'only=&';
349: }
1.42 matthew 350: if (omit != null) {
351: url += 'omit=' + omit + '&';
1.217 albertel 352: } else {
353: url += 'omit=&';
354: }
1.135 albertel 355: if (titleelement != null) {
356: url += 'titleelement=' + titleelement + '&';
1.217 albertel 357: } else {
358: url += 'titleelement=&';
359: }
1.42 matthew 360: url += 'element=' + elementname + '';
361: var title = 'Browser';
1.435 albertel 362: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 363: options += ',width=700,height=600';
364: editbrowser = open(url,title,options,'1');
365: editbrowser.focus();
366: }
367: var editsearcher;
1.135 albertel 368: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 369: var url = '/adm/searchcat?';
370: if (editsearcher == null) {
371: url += 'launch=1&';
372: }
373: url += 'catalogmode=interactive&';
1.199 albertel 374: url += 'mode=$mode&';
1.42 matthew 375: url += 'form=' + formname + '&';
1.135 albertel 376: if (titleelement != null) {
377: url += 'titleelement=' + titleelement + '&';
1.217 albertel 378: } else {
379: url += 'titleelement=&';
380: }
1.42 matthew 381: url += 'element=' + elementname + '';
382: var title = 'Search';
1.435 albertel 383: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 384: options += ',width=700,height=600';
385: editsearcher = open(url,title,options,'1');
386: editsearcher.focus();
387: }
1.219 albertel 388: // END LON-CAPA Internal -->
1.42 matthew 389: END
1.170 www 390: }
391:
392: sub lastresurl {
1.258 albertel 393: if ($env{'environment.lastresurl'}) {
394: return $env{'environment.lastresurl'}
1.170 www 395: } else {
396: return '/res';
397: }
398: }
399:
400: sub storeresurl {
401: my $resurl=&Apache::lonnet::clutter(shift);
402: unless ($resurl=~/^\/res/) { return 0; }
403: $resurl=~s/\/$//;
404: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 405: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 406: return 1;
1.42 matthew 407: }
408:
1.74 www 409: sub studentbrowser_javascript {
1.111 www 410: unless (
1.258 albertel 411: (($env{'request.course.id'}) &&
1.302 albertel 412: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
413: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
414: '/'.$env{'request.course.sec'})
415: ))
1.258 albertel 416: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 417: ) { return ''; }
1.74 www 418: return (<<'ENDSTDBRW');
1.776 bisitz 419: <script type="text/javascript" language="Javascript">
1.824 bisitz 420: // <![CDATA[
1.74 www 421: var stdeditbrowser;
1.999 www 422: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 423: var url = '/adm/pickstudent?';
424: var filter;
1.558 albertel 425: if (!ignorefilter) {
426: eval('filter=document.'+formname+'.'+uname+'.value;');
427: }
1.74 www 428: if (filter != null) {
429: if (filter != '') {
430: url += 'filter='+filter+'&';
431: }
432: }
433: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 434: '&udomelement='+udom+
435: '&clicker='+clicker;
1.111 www 436: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 437: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 438: var title = 'Student_Browser';
1.74 www 439: var options = 'scrollbars=1,resizable=1,menubar=0';
440: options += ',width=700,height=600';
441: stdeditbrowser = open(url,title,options,'1');
442: stdeditbrowser.focus();
443: }
1.824 bisitz 444: // ]]>
1.74 www 445: </script>
446: ENDSTDBRW
447: }
1.42 matthew 448:
1.1003 www 449: sub resourcebrowser_javascript {
450: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 451: return (<<'ENDRESBRW');
1.1003 www 452: <script type="text/javascript" language="Javascript">
453: // <![CDATA[
454: var reseditbrowser;
1.1004 www 455: function openresbrowser(formname,reslink) {
1.1005 www 456: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 457: var title = 'Resource_Browser';
458: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 459: options += ',width=700,height=500';
1.1004 www 460: reseditbrowser = open(url,title,options,'1');
461: reseditbrowser.focus();
1.1003 www 462: }
463: // ]]>
464: </script>
1.1004 www 465: ENDRESBRW
1.1003 www 466: }
467:
1.74 www 468: sub selectstudent_link {
1.999 www 469: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
470: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
471: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
472: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 473: if ($env{'request.course.id'}) {
1.302 albertel 474: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
475: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
476: '/'.$env{'request.course.sec'})) {
1.111 www 477: return '';
478: }
1.999 www 479: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 480: if ($courseadvonly) {
481: $callargs .= ",'',1,1";
482: }
483: return '<span class="LC_nobreak">'.
484: '<a href="javascript:openstdbrowser('.$callargs.');">'.
485: &mt('Select User').'</a></span>';
1.74 www 486: }
1.258 albertel 487: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 488: $callargs .= ",'',1";
1.793 raeburn 489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.111 www 492: }
493: return '';
1.91 www 494: }
495:
1.1004 www 496: sub selectresource_link {
497: my ($form,$reslink,$arg)=@_;
498:
499: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
500: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
501: unless ($env{'request.course.id'}) { return $arg; }
502: return '<span class="LC_nobreak">'.
503: '<a href="javascript:openresbrowser('.$callargs.');">'.
504: $arg.'</a></span>';
505: }
506:
507:
508:
1.653 raeburn 509: sub authorbrowser_javascript {
510: return <<"ENDAUTHORBRW";
1.776 bisitz 511: <script type="text/javascript" language="JavaScript">
1.824 bisitz 512: // <![CDATA[
1.653 raeburn 513: var stdeditbrowser;
514:
515: function openauthorbrowser(formname,udom) {
516: var url = '/adm/pickauthor?';
517: url += 'form='+formname+'&roledom='+udom;
518: var title = 'Author_Browser';
519: var options = 'scrollbars=1,resizable=1,menubar=0';
520: options += ',width=700,height=600';
521: stdeditbrowser = open(url,title,options,'1');
522: stdeditbrowser.focus();
523: }
524:
1.824 bisitz 525: // ]]>
1.653 raeburn 526: </script>
527: ENDAUTHORBRW
528: }
529:
1.91 www 530: sub coursebrowser_javascript {
1.1075.2.31 raeburn 531: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
532: $credits_element) = @_;
1.932 raeburn 533: my $wintitle = 'Course_Browser';
1.931 raeburn 534: if ($crstype eq 'Community') {
1.932 raeburn 535: $wintitle = 'Community_Browser';
1.909 raeburn 536: }
1.876 raeburn 537: my $id_functions = &javascript_index_functions();
538: my $output = '
1.776 bisitz 539: <script type="text/javascript" language="JavaScript">
1.824 bisitz 540: // <![CDATA[
1.468 raeburn 541: var stdeditbrowser;'."\n";
1.876 raeburn 542:
543: $output .= <<"ENDSTDBRW";
1.909 raeburn 544: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 545: var url = '/adm/pickcourse?';
1.895 raeburn 546: var formid = getFormIdByName(formname);
1.876 raeburn 547: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 548: if (domainfilter != null) {
549: if (domainfilter != '') {
550: url += 'domainfilter='+domainfilter+'&';
551: }
552: }
1.91 www 553: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 554: '&cdomelement='+udom+
555: '&cnameelement='+desc;
1.468 raeburn 556: if (extra_element !=null && extra_element != '') {
1.594 raeburn 557: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 558: url += '&roleelement='+extra_element;
559: if (domainfilter == null || domainfilter == '') {
560: url += '&domainfilter='+extra_element;
561: }
1.234 raeburn 562: }
1.468 raeburn 563: else {
564: if (formname == 'portform') {
565: url += '&setroles='+extra_element;
1.800 raeburn 566: } else {
567: if (formname == 'rules') {
568: url += '&fixeddom='+extra_element;
569: }
1.468 raeburn 570: }
571: }
1.230 raeburn 572: }
1.909 raeburn 573: if (type != null && type != '') {
574: url += '&type='+type;
575: }
576: if (type_elem != null && type_elem != '') {
577: url += '&typeelement='+type_elem;
578: }
1.872 raeburn 579: if (formname == 'ccrs') {
580: var ownername = document.forms[formid].ccuname.value;
581: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
582: url += '&cloner='+ownername+':'+ownerdom;
583: }
1.293 raeburn 584: if (multflag !=null && multflag != '') {
585: url += '&multiple='+multflag;
586: }
1.909 raeburn 587: var title = '$wintitle';
1.91 www 588: var options = 'scrollbars=1,resizable=1,menubar=0';
589: options += ',width=700,height=600';
590: stdeditbrowser = open(url,title,options,'1');
591: stdeditbrowser.focus();
592: }
1.876 raeburn 593: $id_functions
594: ENDSTDBRW
1.1075.2.31 raeburn 595: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
596: $output .= &setsec_javascript($sec_element,$formname,$role_element,
597: $credits_element);
1.876 raeburn 598: }
599: $output .= '
600: // ]]>
601: </script>';
602: return $output;
603: }
604:
605: sub javascript_index_functions {
606: return <<"ENDJS";
607:
608: function getFormIdByName(formname) {
609: for (var i=0;i<document.forms.length;i++) {
610: if (document.forms[i].name == formname) {
611: return i;
612: }
613: }
614: return -1;
615: }
616:
617: function getIndexByName(formid,item) {
618: for (var i=0;i<document.forms[formid].elements.length;i++) {
619: if (document.forms[formid].elements[i].name == item) {
620: return i;
621: }
622: }
623: return -1;
624: }
1.468 raeburn 625:
1.876 raeburn 626: function getDomainFromSelectbox(formname,udom) {
627: var userdom;
628: var formid = getFormIdByName(formname);
629: if (formid > -1) {
630: var domid = getIndexByName(formid,udom);
631: if (domid > -1) {
632: if (document.forms[formid].elements[domid].type == 'select-one') {
633: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
634: }
635: if (document.forms[formid].elements[domid].type == 'hidden') {
636: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 637: }
638: }
639: }
1.876 raeburn 640: return userdom;
641: }
642:
643: ENDJS
1.468 raeburn 644:
1.876 raeburn 645: }
646:
1.1017 raeburn 647: sub javascript_array_indexof {
1.1018 raeburn 648: return <<ENDJS;
1.1017 raeburn 649: <script type="text/javascript" language="JavaScript">
650: // <![CDATA[
651:
652: if (!Array.prototype.indexOf) {
653: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
654: "use strict";
655: if (this === void 0 || this === null) {
656: throw new TypeError();
657: }
658: var t = Object(this);
659: var len = t.length >>> 0;
660: if (len === 0) {
661: return -1;
662: }
663: var n = 0;
664: if (arguments.length > 0) {
665: n = Number(arguments[1]);
666: if (n !== n) { // shortcut for verifying if it's NaN
667: n = 0;
668: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
669: n = (n > 0 || -1) * Math.floor(Math.abs(n));
670: }
671: }
672: if (n >= len) {
673: return -1;
674: }
675: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
676: for (; k < len; k++) {
677: if (k in t && t[k] === searchElement) {
678: return k;
679: }
680: }
681: return -1;
682: }
683: }
684:
685: // ]]>
686: </script>
687:
688: ENDJS
689:
690: }
691:
1.876 raeburn 692: sub userbrowser_javascript {
693: my $id_functions = &javascript_index_functions();
694: return <<"ENDUSERBRW";
695:
1.888 raeburn 696: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 697: var url = '/adm/pickuser?';
698: var userdom = getDomainFromSelectbox(formname,udom);
699: if (userdom != null) {
700: if (userdom != '') {
701: url += 'srchdom='+userdom+'&';
702: }
703: }
704: url += 'form=' + formname + '&unameelement='+uname+
705: '&udomelement='+udom+
706: '&ulastelement='+ulast+
707: '&ufirstelement='+ufirst+
708: '&uemailelement='+uemail+
1.881 raeburn 709: '&hideudomelement='+hideudom+
710: '&coursedom='+crsdom;
1.888 raeburn 711: if ((caller != null) && (caller != undefined)) {
712: url += '&caller='+caller;
713: }
1.876 raeburn 714: var title = 'User_Browser';
715: var options = 'scrollbars=1,resizable=1,menubar=0';
716: options += ',width=700,height=600';
717: var stdeditbrowser = open(url,title,options,'1');
718: stdeditbrowser.focus();
719: }
720:
1.888 raeburn 721: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 722: var formid = getFormIdByName(formname);
723: if (formid > -1) {
1.888 raeburn 724: var unameid = getIndexByName(formid,uname);
1.876 raeburn 725: var domid = getIndexByName(formid,udom);
726: var hidedomid = getIndexByName(formid,origdom);
727: if (hidedomid > -1) {
728: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 729: var unameval = document.forms[formid].elements[unameid].value;
730: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
731: if (domid > -1) {
732: var slct = document.forms[formid].elements[domid];
733: if (slct.type == 'select-one') {
734: var i;
735: for (i=0;i<slct.length;i++) {
736: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
737: }
738: }
739: if (slct.type == 'hidden') {
740: slct.value = fixeddom;
1.876 raeburn 741: }
742: }
1.468 raeburn 743: }
744: }
745: }
1.876 raeburn 746: return;
747: }
748:
749: $id_functions
750: ENDUSERBRW
1.468 raeburn 751: }
752:
753: sub setsec_javascript {
1.1075.2.31 raeburn 754: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 755: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
756: $communityrolestr);
757: if ($role_element ne '') {
758: my @allroles = ('st','ta','ep','in','ad');
759: foreach my $crstype ('Course','Community') {
760: if ($crstype eq 'Community') {
761: foreach my $role (@allroles) {
762: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
763: }
764: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
765: } else {
766: foreach my $role (@allroles) {
767: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
768: }
769: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
770: }
771: }
772: $rolestr = '"'.join('","',@allroles).'"';
773: $courserolestr = '"'.join('","',@courserolenames).'"';
774: $communityrolestr = '"'.join('","',@communityrolenames).'"';
775: }
1.468 raeburn 776: my $setsections = qq|
777: function setSect(sectionlist) {
1.629 raeburn 778: var sectionsArray = new Array();
779: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
780: sectionsArray = sectionlist.split(",");
781: }
1.468 raeburn 782: var numSections = sectionsArray.length;
783: document.$formname.$sec_element.length = 0;
784: if (numSections == 0) {
785: document.$formname.$sec_element.multiple=false;
786: document.$formname.$sec_element.size=1;
787: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
788: } else {
789: if (numSections == 1) {
790: document.$formname.$sec_element.multiple=false;
791: document.$formname.$sec_element.size=1;
792: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
793: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
794: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
795: } else {
796: for (var i=0; i<numSections; i++) {
797: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
798: }
799: document.$formname.$sec_element.multiple=true
800: if (numSections < 3) {
801: document.$formname.$sec_element.size=numSections;
802: } else {
803: document.$formname.$sec_element.size=3;
804: }
805: document.$formname.$sec_element.options[0].selected = false
806: }
807: }
1.91 www 808: }
1.905 raeburn 809:
810: function setRole(crstype) {
1.468 raeburn 811: |;
1.905 raeburn 812: if ($role_element eq '') {
813: $setsections .= ' return;
814: }
815: ';
816: } else {
817: $setsections .= qq|
818: var elementLength = document.$formname.$role_element.length;
819: var allroles = Array($rolestr);
820: var courserolenames = Array($courserolestr);
821: var communityrolenames = Array($communityrolestr);
822: if (elementLength != undefined) {
823: if (document.$formname.$role_element.options[5].value == 'cc') {
824: if (crstype == 'Course') {
825: return;
826: } else {
827: allroles[5] = 'co';
828: for (var i=0; i<6; i++) {
829: document.$formname.$role_element.options[i].value = allroles[i];
830: document.$formname.$role_element.options[i].text = communityrolenames[i];
831: }
832: }
833: } else {
834: if (crstype == 'Community') {
835: return;
836: } else {
837: allroles[5] = 'cc';
838: for (var i=0; i<6; i++) {
839: document.$formname.$role_element.options[i].value = allroles[i];
840: document.$formname.$role_element.options[i].text = courserolenames[i];
841: }
842: }
843: }
844: }
845: return;
846: }
847: |;
848: }
1.1075.2.31 raeburn 849: if ($credits_element) {
850: $setsections .= qq|
851: function setCredits(defaultcredits) {
852: document.$formname.$credits_element.value = defaultcredits;
853: return;
854: }
855: |;
856: }
1.468 raeburn 857: return $setsections;
858: }
859:
1.91 www 860: sub selectcourse_link {
1.909 raeburn 861: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
862: $typeelement) = @_;
863: my $type = $selecttype;
1.871 raeburn 864: my $linktext = &mt('Select Course');
865: if ($selecttype eq 'Community') {
1.909 raeburn 866: $linktext = &mt('Select Community');
1.906 raeburn 867: } elsif ($selecttype eq 'Course/Community') {
868: $linktext = &mt('Select Course/Community');
1.909 raeburn 869: $type = '';
1.1019 raeburn 870: } elsif ($selecttype eq 'Select') {
871: $linktext = &mt('Select');
872: $type = '';
1.871 raeburn 873: }
1.787 bisitz 874: return '<span class="LC_nobreak">'
875: ."<a href='"
876: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
877: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 878: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 879: ."'>".$linktext.'</a>'
1.787 bisitz 880: .'</span>';
1.74 www 881: }
1.42 matthew 882:
1.653 raeburn 883: sub selectauthor_link {
884: my ($form,$udom)=@_;
885: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
886: &mt('Select Author').'</a>';
887: }
888:
1.876 raeburn 889: sub selectuser_link {
1.881 raeburn 890: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 891: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 892: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 893: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 894: ');">'.$linktext.'</a>';
1.876 raeburn 895: }
896:
1.273 raeburn 897: sub check_uncheck_jscript {
898: my $jscript = <<"ENDSCRT";
899: function checkAll(field) {
900: if (field.length > 0) {
901: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 902: if (!field[i].disabled) {
903: field[i].checked = true;
904: }
1.273 raeburn 905: }
906: } else {
1.1075.2.14 raeburn 907: if (!field.disabled) {
908: field.checked = true;
909: }
1.273 raeburn 910: }
911: }
912:
913: function uncheckAll(field) {
914: if (field.length > 0) {
915: for (i = 0; i < field.length; i++) {
916: field[i].checked = false ;
1.543 albertel 917: }
918: } else {
1.273 raeburn 919: field.checked = false ;
920: }
921: }
922: ENDSCRT
923: return $jscript;
924: }
925:
1.656 www 926: sub select_timezone {
1.659 raeburn 927: my ($name,$selected,$onchange,$includeempty)=@_;
928: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
929: if ($includeempty) {
930: $output .= '<option value=""';
931: if (($selected eq '') || ($selected eq 'local')) {
932: $output .= ' selected="selected" ';
933: }
934: $output .= '> </option>';
935: }
1.657 raeburn 936: my @timezones = DateTime::TimeZone->all_names;
937: foreach my $tzone (@timezones) {
938: $output.= '<option value="'.$tzone.'"';
939: if ($tzone eq $selected) {
940: $output.=' selected="selected"';
941: }
942: $output.=">$tzone</option>\n";
1.656 www 943: }
944: $output.="</select>";
945: return $output;
946: }
1.273 raeburn 947:
1.687 raeburn 948: sub select_datelocale {
949: my ($name,$selected,$onchange,$includeempty)=@_;
950: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
951: if ($includeempty) {
952: $output .= '<option value=""';
953: if ($selected eq '') {
954: $output .= ' selected="selected" ';
955: }
956: $output .= '> </option>';
957: }
958: my (@possibles,%locale_names);
959: my @locales = DateTime::Locale::Catalog::Locales;
960: foreach my $locale (@locales) {
961: if (ref($locale) eq 'HASH') {
962: my $id = $locale->{'id'};
963: if ($id ne '') {
964: my $en_terr = $locale->{'en_territory'};
965: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 966: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 967: if (grep(/^en$/,@languages) || !@languages) {
968: if ($en_terr ne '') {
969: $locale_names{$id} = '('.$en_terr.')';
970: } elsif ($native_terr ne '') {
971: $locale_names{$id} = $native_terr;
972: }
973: } else {
974: if ($native_terr ne '') {
975: $locale_names{$id} = $native_terr.' ';
976: } elsif ($en_terr ne '') {
977: $locale_names{$id} = '('.$en_terr.')';
978: }
979: }
980: push (@possibles,$id);
981: }
982: }
983: }
984: foreach my $item (sort(@possibles)) {
985: $output.= '<option value="'.$item.'"';
986: if ($item eq $selected) {
987: $output.=' selected="selected"';
988: }
989: $output.=">$item";
990: if ($locale_names{$item} ne '') {
991: $output.=" $locale_names{$item}</option>\n";
992: }
993: $output.="</option>\n";
994: }
995: $output.="</select>";
996: return $output;
997: }
998:
1.792 raeburn 999: sub select_language {
1000: my ($name,$selected,$includeempty) = @_;
1001: my %langchoices;
1002: if ($includeempty) {
1.1075.2.32 raeburn 1003: %langchoices = ('' => 'No language preference');
1.792 raeburn 1004: }
1005: foreach my $id (&languageids()) {
1006: my $code = &supportedlanguagecode($id);
1007: if ($code) {
1008: $langchoices{$code} = &plainlanguagedescription($id);
1009: }
1010: }
1.1075.2.32 raeburn 1011: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1012: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1013: }
1014:
1.42 matthew 1015: =pod
1.36 matthew 1016:
1.648 raeburn 1017: =item * &linked_select_forms(...)
1.36 matthew 1018:
1019: linked_select_forms returns a string containing a <script></script> block
1020: and html for two <select> menus. The select menus will be linked in that
1021: changing the value of the first menu will result in new values being placed
1022: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1023: order unless a defined order is provided.
1.36 matthew 1024:
1025: linked_select_forms takes the following ordered inputs:
1026:
1027: =over 4
1028:
1.112 bowersj2 1029: =item * $formname, the name of the <form> tag
1.36 matthew 1030:
1.112 bowersj2 1031: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1032:
1.112 bowersj2 1033: =item * $firstdefault, the default value for the first menu
1.36 matthew 1034:
1.112 bowersj2 1035: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1036:
1.112 bowersj2 1037: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1038:
1.112 bowersj2 1039: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1040:
1.609 raeburn 1041: =item * $menuorder, the order of values in the first menu
1042:
1.1075.2.31 raeburn 1043: =item * $onchangefirst, additional javascript call to execute for an onchange
1044: event for the first <select> tag
1045:
1046: =item * $onchangesecond, additional javascript call to execute for an onchange
1047: event for the second <select> tag
1048:
1.41 ng 1049: =back
1050:
1.36 matthew 1051: Below is an example of such a hash. Only the 'text', 'default', and
1052: 'select2' keys must appear as stated. keys(%menu) are the possible
1053: values for the first select menu. The text that coincides with the
1.41 ng 1054: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1055: and text for the second menu are given in the hash pointed to by
1056: $menu{$choice1}->{'select2'}.
1057:
1.112 bowersj2 1058: my %menu = ( A1 => { text =>"Choice A1" ,
1059: default => "B3",
1060: select2 => {
1061: B1 => "Choice B1",
1062: B2 => "Choice B2",
1063: B3 => "Choice B3",
1064: B4 => "Choice B4"
1.609 raeburn 1065: },
1066: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1067: },
1068: A2 => { text =>"Choice A2" ,
1069: default => "C2",
1070: select2 => {
1071: C1 => "Choice C1",
1072: C2 => "Choice C2",
1073: C3 => "Choice C3"
1.609 raeburn 1074: },
1075: order => ['C2','C1','C3'],
1.112 bowersj2 1076: },
1077: A3 => { text =>"Choice A3" ,
1078: default => "D6",
1079: select2 => {
1080: D1 => "Choice D1",
1081: D2 => "Choice D2",
1082: D3 => "Choice D3",
1083: D4 => "Choice D4",
1084: D5 => "Choice D5",
1085: D6 => "Choice D6",
1086: D7 => "Choice D7"
1.609 raeburn 1087: },
1088: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1089: }
1090: );
1.36 matthew 1091:
1092: =cut
1093:
1094: sub linked_select_forms {
1095: my ($formname,
1096: $middletext,
1097: $firstdefault,
1098: $firstselectname,
1099: $secondselectname,
1.609 raeburn 1100: $hashref,
1101: $menuorder,
1.1075.2.31 raeburn 1102: $onchangefirst,
1103: $onchangesecond
1.36 matthew 1104: ) = @_;
1105: my $second = "document.$formname.$secondselectname";
1106: my $first = "document.$formname.$firstselectname";
1107: # output the javascript to do the changing
1108: my $result = '';
1.776 bisitz 1109: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1110: $result.="// <![CDATA[\n";
1.36 matthew 1111: $result.="var select2data = new Object();\n";
1112: $" = '","';
1113: my $debug = '';
1114: foreach my $s1 (sort(keys(%$hashref))) {
1115: $result.="select2data.d_$s1 = new Object();\n";
1116: $result.="select2data.d_$s1.def = new String('".
1117: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1118: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1119: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1120: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1121: @s2values = @{$hashref->{$s1}->{'order'}};
1122: }
1.36 matthew 1123: $result.="\"@s2values\");\n";
1124: $result.="select2data.d_$s1.texts = new Array(";
1125: my @s2texts;
1126: foreach my $value (@s2values) {
1127: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1128: }
1129: $result.="\"@s2texts\");\n";
1130: }
1131: $"=' ';
1132: $result.= <<"END";
1133:
1134: function select1_changed() {
1135: // Determine new choice
1136: var newvalue = "d_" + $first.value;
1137: // update select2
1138: var values = select2data[newvalue].values;
1139: var texts = select2data[newvalue].texts;
1140: var select2def = select2data[newvalue].def;
1141: var i;
1142: // out with the old
1143: for (i = 0; i < $second.options.length; i++) {
1144: $second.options[i] = null;
1145: }
1146: // in with the nuclear
1147: for (i=0;i<values.length; i++) {
1148: $second.options[i] = new Option(values[i]);
1.143 matthew 1149: $second.options[i].value = values[i];
1.36 matthew 1150: $second.options[i].text = texts[i];
1151: if (values[i] == select2def) {
1152: $second.options[i].selected = true;
1153: }
1154: }
1155: }
1.824 bisitz 1156: // ]]>
1.36 matthew 1157: </script>
1158: END
1159: # output the initial values for the selection lists
1.1075.2.31 raeburn 1160: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1161: my @order = sort(keys(%{$hashref}));
1162: if (ref($menuorder) eq 'ARRAY') {
1163: @order = @{$menuorder};
1164: }
1165: foreach my $value (@order) {
1.36 matthew 1166: $result.=" <option value=\"$value\" ";
1.253 albertel 1167: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1168: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1169: }
1170: $result .= "</select>\n";
1171: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1172: $result .= $middletext;
1.1075.2.31 raeburn 1173: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1174: if ($onchangesecond) {
1175: $result .= ' onchange="'.$onchangesecond.'"';
1176: }
1177: $result .= ">\n";
1.36 matthew 1178: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1179:
1180: my @secondorder = sort(keys(%select2));
1181: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1182: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1183: }
1184: foreach my $value (@secondorder) {
1.36 matthew 1185: $result.=" <option value=\"$value\" ";
1.253 albertel 1186: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1187: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1188: }
1189: $result .= "</select>\n";
1190: # return $debug;
1191: return $result;
1192: } # end of sub linked_select_forms {
1193:
1.45 matthew 1194: =pod
1.44 bowersj2 1195:
1.973 raeburn 1196: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1197:
1.112 bowersj2 1198: Returns a string corresponding to an HTML link to the given help
1199: $topic, where $topic corresponds to the name of a .tex file in
1200: /home/httpd/html/adm/help/tex, with underscores replaced by
1201: spaces.
1202:
1203: $text will optionally be linked to the same topic, allowing you to
1204: link text in addition to the graphic. If you do not want to link
1205: text, but wish to specify one of the later parameters, pass an
1206: empty string.
1207:
1208: $stayOnPage is a value that will be interpreted as a boolean. If true,
1209: the link will not open a new window. If false, the link will open
1210: a new window using Javascript. (Default is false.)
1211:
1212: $width and $height are optional numerical parameters that will
1213: override the width and height of the popped up window, which may
1.973 raeburn 1214: be useful for certain help topics with big pictures included.
1215:
1216: $imgid is the id of the img tag used for the help icon. This may be
1217: used in a javascript call to switch the image src. See
1218: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1219:
1220: =cut
1221:
1222: sub help_open_topic {
1.973 raeburn 1223: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1224: $text = "" if (not defined $text);
1.44 bowersj2 1225: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1226: $width = 500 if (not defined $width);
1.44 bowersj2 1227: $height = 400 if (not defined $height);
1228: my $filename = $topic;
1229: $filename =~ s/ /_/g;
1230:
1.48 bowersj2 1231: my $template = "";
1232: my $link;
1.572 banghart 1233:
1.159 www 1234: $topic=~s/\W/\_/g;
1.44 bowersj2 1235:
1.572 banghart 1236: if (!$stayOnPage) {
1.1075.2.50 raeburn 1237: if ($env{'browser.mobile'}) {
1238: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1239: } else {
1240: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1241: }
1.1037 www 1242: } elsif ($stayOnPage eq 'popup') {
1243: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1244: } else {
1.48 bowersj2 1245: $link = "/adm/help/${filename}.hlp";
1246: }
1247:
1248: # Add the text
1.755 neumanie 1249: if ($text ne "") {
1.763 bisitz 1250: $template.='<span class="LC_help_open_topic">'
1251: .'<a target="_top" href="'.$link.'">'
1252: .$text.'</a>';
1.48 bowersj2 1253: }
1254:
1.763 bisitz 1255: # (Always) Add the graphic
1.179 matthew 1256: my $title = &mt('Online Help');
1.667 raeburn 1257: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1258: if ($imgid ne '') {
1259: $imgid = ' id="'.$imgid.'"';
1260: }
1.763 bisitz 1261: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1262: .'<img src="'.$helpicon.'" border="0"'
1263: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1264: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1265: .' /></a>';
1266: if ($text ne "") {
1267: $template.='</span>';
1268: }
1.44 bowersj2 1269: return $template;
1270:
1.106 bowersj2 1271: }
1272:
1273: # This is a quicky function for Latex cheatsheet editing, since it
1274: # appears in at least four places
1275: sub helpLatexCheatsheet {
1.1037 www 1276: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1277: my $out;
1.106 bowersj2 1278: my $addOther = '';
1.732 raeburn 1279: if ($topic) {
1.1037 www 1280: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1281: }
1282: $out = '<span>' # Start cheatsheet
1283: .$addOther
1284: .'<span>'
1.1037 www 1285: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1286: .'</span> <span>'
1.1037 www 1287: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1288: .'</span>';
1.732 raeburn 1289: unless ($not_author) {
1.763 bisitz 1290: $out .= ' <span>'
1.1037 www 1291: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1292: .'</span>';
1.732 raeburn 1293: }
1.763 bisitz 1294: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1295: return $out;
1.172 www 1296: }
1297:
1.430 albertel 1298: sub general_help {
1299: my $helptopic='Student_Intro';
1300: if ($env{'request.role'}=~/^(ca|au)/) {
1301: $helptopic='Authoring_Intro';
1.907 raeburn 1302: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1303: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1304: } elsif ($env{'request.role'}=~/^dc/) {
1305: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1306: }
1307: return $helptopic;
1308: }
1309:
1310: sub update_help_link {
1311: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1312: my $origurl = $ENV{'REQUEST_URI'};
1313: $origurl=~s|^/~|/priv/|;
1314: my $timestamp = time;
1315: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1316: $$datum = &escape($$datum);
1317: }
1318:
1319: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1320: my $output .= <<"ENDOUTPUT";
1321: <script type="text/javascript">
1.824 bisitz 1322: // <![CDATA[
1.430 albertel 1323: banner_link = '$banner_link';
1.824 bisitz 1324: // ]]>
1.430 albertel 1325: </script>
1326: ENDOUTPUT
1327: return $output;
1328: }
1329:
1330: # now just updates the help link and generates a blue icon
1.193 raeburn 1331: sub help_open_menu {
1.430 albertel 1332: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1333: = @_;
1.949 droeschl 1334: $stayOnPage = 1;
1.430 albertel 1335: my $output;
1336: if ($component_help) {
1337: if (!$text) {
1338: $output=&help_open_topic($component_help,undef,$stayOnPage,
1339: $width,$height);
1340: } else {
1341: my $help_text;
1342: $help_text=&unescape($topic);
1343: $output='<table><tr><td>'.
1344: &help_open_topic($component_help,$help_text,$stayOnPage,
1345: $width,$height).'</td></tr></table>';
1346: }
1347: }
1348: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1349: return $output.$banner_link;
1350: }
1351:
1352: sub top_nav_help {
1353: my ($text) = @_;
1.436 albertel 1354: $text = &mt($text);
1.949 droeschl 1355: my $stay_on_page = 1;
1356:
1.572 banghart 1357: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1358: : "javascript:helpMenu('open')";
1.572 banghart 1359: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1360:
1.201 raeburn 1361: my $title = &mt('Get help');
1.436 albertel 1362:
1363: return <<"END";
1364: $banner_link
1.1075.2.56 raeburn 1365: <a href="$link" title="$title">$text</a>
1.436 albertel 1366: END
1367: }
1368:
1369: sub help_menu_js {
1.1075.2.52 raeburn 1370: my ($httphost) = @_;
1.949 droeschl 1371: my $stayOnPage = 1;
1.436 albertel 1372: my $width = 620;
1373: my $height = 600;
1.430 albertel 1374: my $helptopic=&general_help();
1.1075.2.52 raeburn 1375: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1376: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1377: my $start_page =
1378: &Apache::loncommon::start_page('Help Menu', undef,
1379: {'frameset' => 1,
1380: 'js_ready' => 1,
1.1075.2.52 raeburn 1381: 'use_absolute' => $httphost,
1.331 albertel 1382: 'add_entries' => {
1383: 'border' => '0',
1.579 raeburn 1384: 'rows' => "110,*",},});
1.331 albertel 1385: my $end_page =
1386: &Apache::loncommon::end_page({'frameset' => 1,
1387: 'js_ready' => 1,});
1388:
1.436 albertel 1389: my $template .= <<"ENDTEMPLATE";
1390: <script type="text/javascript">
1.877 bisitz 1391: // <![CDATA[
1.253 albertel 1392: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1393: var banner_link = '';
1.243 raeburn 1394: function helpMenu(target) {
1395: var caller = this;
1396: if (target == 'open') {
1397: var newWindow = null;
1398: try {
1.262 albertel 1399: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1400: }
1401: catch(error) {
1402: writeHelp(caller);
1403: return;
1404: }
1405: if (newWindow) {
1406: caller = newWindow;
1407: }
1.193 raeburn 1408: }
1.243 raeburn 1409: writeHelp(caller);
1410: return;
1411: }
1412: function writeHelp(caller) {
1.1072 raeburn 1413: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1414: caller.document.close()
1415: caller.focus()
1.193 raeburn 1416: }
1.877 bisitz 1417: // END LON-CAPA Internal -->
1.253 albertel 1418: // ]]>
1.436 albertel 1419: </script>
1.193 raeburn 1420: ENDTEMPLATE
1421: return $template;
1422: }
1423:
1.172 www 1424: sub help_open_bug {
1425: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1426: unless ($env{'user.adv'}) { return ''; }
1.172 www 1427: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1428: $text = "" if (not defined $text);
1429: $stayOnPage=1;
1.184 albertel 1430: $width = 600 if (not defined $width);
1431: $height = 600 if (not defined $height);
1.172 www 1432:
1433: $topic=~s/\W+/\+/g;
1434: my $link='';
1435: my $template='';
1.379 albertel 1436: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1437: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1438: if (!$stayOnPage)
1439: {
1440: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1441: }
1442: else
1443: {
1444: $link = $url;
1445: }
1446: # Add the text
1447: if ($text ne "")
1448: {
1449: $template .=
1450: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1451: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1452: }
1453:
1454: # Add the graphic
1.179 matthew 1455: my $title = &mt('Report a Bug');
1.215 albertel 1456: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1457: $template .= <<"ENDTEMPLATE";
1.436 albertel 1458: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1459: ENDTEMPLATE
1460: if ($text ne '') { $template.='</td></tr></table>' };
1461: return $template;
1462:
1463: }
1464:
1465: sub help_open_faq {
1466: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1467: unless ($env{'user.adv'}) { return ''; }
1.172 www 1468: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1469: $text = "" if (not defined $text);
1470: $stayOnPage=1;
1471: $width = 350 if (not defined $width);
1472: $height = 400 if (not defined $height);
1473:
1474: $topic=~s/\W+/\+/g;
1475: my $link='';
1476: my $template='';
1477: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1478: if (!$stayOnPage)
1479: {
1480: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1481: }
1482: else
1483: {
1484: $link = $url;
1485: }
1486:
1487: # Add the text
1488: if ($text ne "")
1489: {
1490: $template .=
1.173 www 1491: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1492: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1493: }
1494:
1495: # Add the graphic
1.179 matthew 1496: my $title = &mt('View the FAQ');
1.215 albertel 1497: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1498: $template .= <<"ENDTEMPLATE";
1.436 albertel 1499: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1500: ENDTEMPLATE
1501: if ($text ne '') { $template.='</td></tr></table>' };
1502: return $template;
1503:
1.44 bowersj2 1504: }
1.37 matthew 1505:
1.180 matthew 1506: ###############################################################
1507: ###############################################################
1508:
1.45 matthew 1509: =pod
1510:
1.648 raeburn 1511: =item * &change_content_javascript():
1.256 matthew 1512:
1513: This and the next function allow you to create small sections of an
1514: otherwise static HTML page that you can update on the fly with
1515: Javascript, even in Netscape 4.
1516:
1517: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1518: must be written to the HTML page once. It will prove the Javascript
1519: function "change(name, content)". Calling the change function with the
1520: name of the section
1521: you want to update, matching the name passed to C<changable_area>, and
1522: the new content you want to put in there, will put the content into
1523: that area.
1524:
1525: B<Note>: Netscape 4 only reserves enough space for the changable area
1526: to contain room for the original contents. You need to "make space"
1527: for whatever changes you wish to make, and be B<sure> to check your
1528: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1529: it's adequate for updating a one-line status display, but little more.
1530: This script will set the space to 100% width, so you only need to
1531: worry about height in Netscape 4.
1532:
1533: Modern browsers are much less limiting, and if you can commit to the
1534: user not using Netscape 4, this feature may be used freely with
1535: pretty much any HTML.
1536:
1537: =cut
1538:
1539: sub change_content_javascript {
1540: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1541: if ($env{'browser.type'} eq 'netscape' &&
1542: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1543: return (<<NETSCAPE4);
1544: function change(name, content) {
1545: doc = document.layers[name+"___escape"].layers[0].document;
1546: doc.open();
1547: doc.write(content);
1548: doc.close();
1549: }
1550: NETSCAPE4
1551: } else {
1552: # Otherwise, we need to use semi-standards-compliant code
1553: # (technically, "innerHTML" isn't standard but the equivalent
1554: # is really scary, and every useful browser supports it
1555: return (<<DOMBASED);
1556: function change(name, content) {
1557: element = document.getElementById(name);
1558: element.innerHTML = content;
1559: }
1560: DOMBASED
1561: }
1562: }
1563:
1564: =pod
1565:
1.648 raeburn 1566: =item * &changable_area($name,$origContent):
1.256 matthew 1567:
1568: This provides a "changable area" that can be modified on the fly via
1569: the Javascript code provided in C<change_content_javascript>. $name is
1570: the name you will use to reference the area later; do not repeat the
1571: same name on a given HTML page more then once. $origContent is what
1572: the area will originally contain, which can be left blank.
1573:
1574: =cut
1575:
1576: sub changable_area {
1577: my ($name, $origContent) = @_;
1578:
1.258 albertel 1579: if ($env{'browser.type'} eq 'netscape' &&
1580: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1581: # If this is netscape 4, we need to use the Layer tag
1582: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1583: } else {
1584: return "<span id='$name'>$origContent</span>";
1585: }
1586: }
1587:
1588: =pod
1589:
1.648 raeburn 1590: =item * &viewport_geometry_js
1.590 raeburn 1591:
1592: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1593:
1594: =cut
1595:
1596:
1597: sub viewport_geometry_js {
1598: return <<"GEOMETRY";
1599: var Geometry = {};
1600: function init_geometry() {
1601: if (Geometry.init) { return };
1602: Geometry.init=1;
1603: if (window.innerHeight) {
1604: Geometry.getViewportHeight = function() { return window.innerHeight; };
1605: Geometry.getViewportWidth = function() { return window.innerWidth; };
1606: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1607: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1608: }
1609: else if (document.documentElement && document.documentElement.clientHeight) {
1610: Geometry.getViewportHeight =
1611: function() { return document.documentElement.clientHeight; };
1612: Geometry.getViewportWidth =
1613: function() { return document.documentElement.clientWidth; };
1614:
1615: Geometry.getHorizontalScroll =
1616: function() { return document.documentElement.scrollLeft; };
1617: Geometry.getVerticalScroll =
1618: function() { return document.documentElement.scrollTop; };
1619: }
1620: else if (document.body.clientHeight) {
1621: Geometry.getViewportHeight =
1622: function() { return document.body.clientHeight; };
1623: Geometry.getViewportWidth =
1624: function() { return document.body.clientWidth; };
1625: Geometry.getHorizontalScroll =
1626: function() { return document.body.scrollLeft; };
1627: Geometry.getVerticalScroll =
1628: function() { return document.body.scrollTop; };
1629: }
1630: }
1631:
1632: GEOMETRY
1633: }
1634:
1635: =pod
1636:
1.648 raeburn 1637: =item * &viewport_size_js()
1.590 raeburn 1638:
1639: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1640:
1641: =cut
1642:
1643: sub viewport_size_js {
1644: my $geometry = &viewport_geometry_js();
1645: return <<"DIMS";
1646:
1647: $geometry
1648:
1649: function getViewportDims(width,height) {
1650: init_geometry();
1651: width.value = Geometry.getViewportWidth();
1652: height.value = Geometry.getViewportHeight();
1653: return;
1654: }
1655:
1656: DIMS
1657: }
1658:
1659: =pod
1660:
1.648 raeburn 1661: =item * &resize_textarea_js()
1.565 albertel 1662:
1663: emits the needed javascript to resize a textarea to be as big as possible
1664:
1665: creates a function resize_textrea that takes two IDs first should be
1666: the id of the element to resize, second should be the id of a div that
1667: surrounds everything that comes after the textarea, this routine needs
1668: to be attached to the <body> for the onload and onresize events.
1669:
1.648 raeburn 1670: =back
1.565 albertel 1671:
1672: =cut
1673:
1674: sub resize_textarea_js {
1.590 raeburn 1675: my $geometry = &viewport_geometry_js();
1.565 albertel 1676: return <<"RESIZE";
1677: <script type="text/javascript">
1.824 bisitz 1678: // <![CDATA[
1.590 raeburn 1679: $geometry
1.565 albertel 1680:
1.588 albertel 1681: function getX(element) {
1682: var x = 0;
1683: while (element) {
1684: x += element.offsetLeft;
1685: element = element.offsetParent;
1686: }
1687: return x;
1688: }
1689: function getY(element) {
1690: var y = 0;
1691: while (element) {
1692: y += element.offsetTop;
1693: element = element.offsetParent;
1694: }
1695: return y;
1696: }
1697:
1698:
1.565 albertel 1699: function resize_textarea(textarea_id,bottom_id) {
1700: init_geometry();
1701: var textarea = document.getElementById(textarea_id);
1702: //alert(textarea);
1703:
1.588 albertel 1704: var textarea_top = getY(textarea);
1.565 albertel 1705: var textarea_height = textarea.offsetHeight;
1706: var bottom = document.getElementById(bottom_id);
1.588 albertel 1707: var bottom_top = getY(bottom);
1.565 albertel 1708: var bottom_height = bottom.offsetHeight;
1709: var window_height = Geometry.getViewportHeight();
1.588 albertel 1710: var fudge = 23;
1.565 albertel 1711: var new_height = window_height-fudge-textarea_top-bottom_height;
1712: if (new_height < 300) {
1713: new_height = 300;
1714: }
1715: textarea.style.height=new_height+'px';
1716: }
1.824 bisitz 1717: // ]]>
1.565 albertel 1718: </script>
1719: RESIZE
1720:
1721: }
1722:
1723: =pod
1724:
1.256 matthew 1725: =head1 Excel and CSV file utility routines
1726:
1727: =cut
1728:
1729: ###############################################################
1730: ###############################################################
1731:
1732: =pod
1733:
1.1075.2.56 raeburn 1734: =over 4
1735:
1.648 raeburn 1736: =item * &csv_translate($text)
1.37 matthew 1737:
1.185 www 1738: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1739: format.
1740:
1741: =cut
1742:
1.180 matthew 1743: ###############################################################
1744: ###############################################################
1.37 matthew 1745: sub csv_translate {
1746: my $text = shift;
1747: $text =~ s/\"/\"\"/g;
1.209 albertel 1748: $text =~ s/\n/ /g;
1.37 matthew 1749: return $text;
1750: }
1.180 matthew 1751:
1752: ###############################################################
1753: ###############################################################
1754:
1755: =pod
1756:
1.648 raeburn 1757: =item * &define_excel_formats()
1.180 matthew 1758:
1759: Define some commonly used Excel cell formats.
1760:
1761: Currently supported formats:
1762:
1763: =over 4
1764:
1765: =item header
1766:
1767: =item bold
1768:
1769: =item h1
1770:
1771: =item h2
1772:
1773: =item h3
1774:
1.256 matthew 1775: =item h4
1776:
1777: =item i
1778:
1.180 matthew 1779: =item date
1780:
1781: =back
1782:
1783: Inputs: $workbook
1784:
1785: Returns: $format, a hash reference.
1786:
1.1057 foxr 1787:
1.180 matthew 1788: =cut
1789:
1790: ###############################################################
1791: ###############################################################
1792: sub define_excel_formats {
1793: my ($workbook) = @_;
1794: my $format;
1795: $format->{'header'} = $workbook->add_format(bold => 1,
1796: bottom => 1,
1797: align => 'center');
1798: $format->{'bold'} = $workbook->add_format(bold=>1);
1799: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1800: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1801: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1802: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1803: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1804: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1805: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1806: return $format;
1807: }
1808:
1809: ###############################################################
1810: ###############################################################
1.113 bowersj2 1811:
1812: =pod
1813:
1.648 raeburn 1814: =item * &create_workbook()
1.255 matthew 1815:
1816: Create an Excel worksheet. If it fails, output message on the
1817: request object and return undefs.
1818:
1819: Inputs: Apache request object
1820:
1821: Returns (undef) on failure,
1822: Excel worksheet object, scalar with filename, and formats
1823: from &Apache::loncommon::define_excel_formats on success
1824:
1825: =cut
1826:
1827: ###############################################################
1828: ###############################################################
1829: sub create_workbook {
1830: my ($r) = @_;
1831: #
1832: # Create the excel spreadsheet
1833: my $filename = '/prtspool/'.
1.258 albertel 1834: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1835: time.'_'.rand(1000000000).'.xls';
1836: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1837: if (! defined($workbook)) {
1838: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1839: $r->print(
1840: '<p class="LC_error">'
1841: .&mt('Problems occurred in creating the new Excel file.')
1842: .' '.&mt('This error has been logged.')
1843: .' '.&mt('Please alert your LON-CAPA administrator.')
1844: .'</p>'
1845: );
1.255 matthew 1846: return (undef);
1847: }
1848: #
1.1014 foxr 1849: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1850: #
1851: my $format = &Apache::loncommon::define_excel_formats($workbook);
1852: return ($workbook,$filename,$format);
1853: }
1854:
1855: ###############################################################
1856: ###############################################################
1857:
1858: =pod
1859:
1.648 raeburn 1860: =item * &create_text_file()
1.113 bowersj2 1861:
1.542 raeburn 1862: Create a file to write to and eventually make available to the user.
1.256 matthew 1863: If file creation fails, outputs an error message on the request object and
1864: return undefs.
1.113 bowersj2 1865:
1.256 matthew 1866: Inputs: Apache request object, and file suffix
1.113 bowersj2 1867:
1.256 matthew 1868: Returns (undef) on failure,
1869: Filehandle and filename on success.
1.113 bowersj2 1870:
1871: =cut
1872:
1.256 matthew 1873: ###############################################################
1874: ###############################################################
1875: sub create_text_file {
1876: my ($r,$suffix) = @_;
1877: if (! defined($suffix)) { $suffix = 'txt'; };
1878: my $fh;
1879: my $filename = '/prtspool/'.
1.258 albertel 1880: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1881: time.'_'.rand(1000000000).'.'.$suffix;
1882: $fh = Apache::File->new('>/home/httpd'.$filename);
1883: if (! defined($fh)) {
1884: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1885: $r->print(
1886: '<p class="LC_error">'
1887: .&mt('Problems occurred in creating the output file.')
1888: .' '.&mt('This error has been logged.')
1889: .' '.&mt('Please alert your LON-CAPA administrator.')
1890: .'</p>'
1891: );
1.113 bowersj2 1892: }
1.256 matthew 1893: return ($fh,$filename)
1.113 bowersj2 1894: }
1895:
1896:
1.256 matthew 1897: =pod
1.113 bowersj2 1898:
1899: =back
1900:
1901: =cut
1.37 matthew 1902:
1903: ###############################################################
1.33 matthew 1904: ## Home server <option> list generating code ##
1905: ###############################################################
1.35 matthew 1906:
1.169 www 1907: # ------------------------------------------
1908:
1909: sub domain_select {
1910: my ($name,$value,$multiple)=@_;
1911: my %domains=map {
1.514 albertel 1912: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1913: } &Apache::lonnet::all_domains();
1.169 www 1914: if ($multiple) {
1915: $domains{''}=&mt('Any domain');
1.550 albertel 1916: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1917: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1918: } else {
1.550 albertel 1919: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1920: return &select_form($name,$value,\%domains);
1.169 www 1921: }
1922: }
1923:
1.282 albertel 1924: #-------------------------------------------
1925:
1926: =pod
1927:
1.519 raeburn 1928: =head1 Routines for form select boxes
1929:
1930: =over 4
1931:
1.648 raeburn 1932: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1933:
1934: Returns a string containing a <select> element int multiple mode
1935:
1936:
1937: Args:
1938: $name - name of the <select> element
1.506 raeburn 1939: $value - scalar or array ref of values that should already be selected
1.282 albertel 1940: $size - number of rows long the select element is
1.283 albertel 1941: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1942: (shown text should already have been &mt())
1.506 raeburn 1943: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1944:
1.282 albertel 1945: =cut
1946:
1947: #-------------------------------------------
1.169 www 1948: sub multiple_select_form {
1.284 albertel 1949: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1950: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1951: my $output='';
1.191 matthew 1952: if (! defined($size)) {
1953: $size = 4;
1.283 albertel 1954: if (scalar(keys(%$hash))<4) {
1955: $size = scalar(keys(%$hash));
1.191 matthew 1956: }
1957: }
1.734 bisitz 1958: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1959: my @order;
1.506 raeburn 1960: if (ref($order) eq 'ARRAY') {
1961: @order = @{$order};
1962: } else {
1963: @order = sort(keys(%$hash));
1.501 banghart 1964: }
1965: if (exists($$hash{'select_form_order'})) {
1966: @order = @{$$hash{'select_form_order'}};
1967: }
1968:
1.284 albertel 1969: foreach my $key (@order) {
1.356 albertel 1970: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1971: $output.='selected="selected" ' if ($selected{$key});
1972: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1973: }
1974: $output.="</select>\n";
1975: return $output;
1976: }
1977:
1.88 www 1978: #-------------------------------------------
1979:
1980: =pod
1981:
1.970 raeburn 1982: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1983:
1984: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1985: allow a user to select options from a ref to a hash containing:
1986: option_name => displayed text. An optional $onchange can include
1987: a javascript onchange item, e.g., onchange="this.form.submit();"
1988:
1.88 www 1989: See lonrights.pm for an example invocation and use.
1990:
1991: =cut
1992:
1993: #-------------------------------------------
1994: sub select_form {
1.970 raeburn 1995: my ($def,$name,$hashref,$onchange) = @_;
1996: return unless (ref($hashref) eq 'HASH');
1997: if ($onchange) {
1998: $onchange = ' onchange="'.$onchange.'"';
1999: }
2000: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2001: my @keys;
1.970 raeburn 2002: if (exists($hashref->{'select_form_order'})) {
2003: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2004: } else {
1.970 raeburn 2005: @keys=sort(keys(%{$hashref}));
1.128 albertel 2006: }
1.356 albertel 2007: foreach my $key (@keys) {
2008: $selectform.=
2009: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2010: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2011: ">".$hashref->{$key}."</option>\n";
1.88 www 2012: }
2013: $selectform.="</select>";
2014: return $selectform;
2015: }
2016:
1.475 www 2017: # For display filters
2018:
2019: sub display_filter {
1.1074 raeburn 2020: my ($context) = @_;
1.475 www 2021: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2022: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2023: my $phraseinput = 'hidden';
2024: my $includeinput = 'hidden';
2025: my ($checked,$includetypestext);
2026: if ($env{'form.displayfilter'} eq 'containing') {
2027: $phraseinput = 'text';
2028: if ($context eq 'parmslog') {
2029: $includeinput = 'checkbox';
2030: if ($env{'form.includetypes'}) {
2031: $checked = ' checked="checked"';
2032: }
2033: $includetypestext = &mt('Include parameter types');
2034: }
2035: } else {
2036: $includetypestext = ' ';
2037: }
2038: my ($additional,$secondid,$thirdid);
2039: if ($context eq 'parmslog') {
2040: $additional =
2041: '<label><input type="'.$includeinput.'" name="includetypes"'.
2042: $checked.' name="includetypes" value="1" id="includetypes" />'.
2043: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2044: '</label>';
2045: $secondid = 'includetypes';
2046: $thirdid = 'includetypestext';
2047: }
2048: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2049: '$secondid','$thirdid')";
2050: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2051: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2052: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2053: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2054: &mt('Filter: [_1]',
1.477 www 2055: &select_form($env{'form.displayfilter'},
2056: 'displayfilter',
1.970 raeburn 2057: {'currentfolder' => 'Current folder/page',
1.477 www 2058: 'containing' => 'Containing phrase',
1.1074 raeburn 2059: 'none' => 'None'},$onchange)).' '.
2060: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2061: &HTML::Entities::encode($env{'form.containingphrase'}).
2062: '" />'.$additional;
2063: }
2064:
2065: sub display_filter_js {
2066: my $includetext = &mt('Include parameter types');
2067: return <<"ENDJS";
2068:
2069: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2070: var firstType = 'hidden';
2071: if (setter.options[setter.selectedIndex].value == 'containing') {
2072: firstType = 'text';
2073: }
2074: firstObject = document.getElementById(firstid);
2075: if (typeof(firstObject) == 'object') {
2076: if (firstObject.type != firstType) {
2077: changeInputType(firstObject,firstType);
2078: }
2079: }
2080: if (context == 'parmslog') {
2081: var secondType = 'hidden';
2082: if (firstType == 'text') {
2083: secondType = 'checkbox';
2084: }
2085: secondObject = document.getElementById(secondid);
2086: if (typeof(secondObject) == 'object') {
2087: if (secondObject.type != secondType) {
2088: changeInputType(secondObject,secondType);
2089: }
2090: }
2091: var textItem = document.getElementById(thirdid);
2092: var currtext = textItem.innerHTML;
2093: var newtext;
2094: if (firstType == 'text') {
2095: newtext = '$includetext';
2096: } else {
2097: newtext = ' ';
2098: }
2099: if (currtext != newtext) {
2100: textItem.innerHTML = newtext;
2101: }
2102: }
2103: return;
2104: }
2105:
2106: function changeInputType(oldObject,newType) {
2107: var newObject = document.createElement('input');
2108: newObject.type = newType;
2109: if (oldObject.size) {
2110: newObject.size = oldObject.size;
2111: }
2112: if (oldObject.value) {
2113: newObject.value = oldObject.value;
2114: }
2115: if (oldObject.name) {
2116: newObject.name = oldObject.name;
2117: }
2118: if (oldObject.id) {
2119: newObject.id = oldObject.id;
2120: }
2121: oldObject.parentNode.replaceChild(newObject,oldObject);
2122: return;
2123: }
2124:
2125: ENDJS
1.475 www 2126: }
2127:
1.167 www 2128: sub gradeleveldescription {
2129: my $gradelevel=shift;
2130: my %gradelevels=(0 => 'Not specified',
2131: 1 => 'Grade 1',
2132: 2 => 'Grade 2',
2133: 3 => 'Grade 3',
2134: 4 => 'Grade 4',
2135: 5 => 'Grade 5',
2136: 6 => 'Grade 6',
2137: 7 => 'Grade 7',
2138: 8 => 'Grade 8',
2139: 9 => 'Grade 9',
2140: 10 => 'Grade 10',
2141: 11 => 'Grade 11',
2142: 12 => 'Grade 12',
2143: 13 => 'Grade 13',
2144: 14 => '100 Level',
2145: 15 => '200 Level',
2146: 16 => '300 Level',
2147: 17 => '400 Level',
2148: 18 => 'Graduate Level');
2149: return &mt($gradelevels{$gradelevel});
2150: }
2151:
1.163 www 2152: sub select_level_form {
2153: my ($deflevel,$name)=@_;
2154: unless ($deflevel) { $deflevel=0; }
1.167 www 2155: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2156: for (my $i=0; $i<=18; $i++) {
2157: $selectform.="<option value=\"$i\" ".
1.253 albertel 2158: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2159: ">".&gradeleveldescription($i)."</option>\n";
2160: }
2161: $selectform.="</select>";
2162: return $selectform;
1.163 www 2163: }
1.167 www 2164:
1.35 matthew 2165: #-------------------------------------------
2166:
1.45 matthew 2167: =pod
2168:
1.1075.2.42 raeburn 2169: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2170:
2171: Returns a string containing a <select name='$name' size='1'> form to
2172: allow a user to select the domain to preform an operation in.
2173: See loncreateuser.pm for an example invocation and use.
2174:
1.90 www 2175: If the $includeempty flag is set, it also includes an empty choice ("no domain
2176: selected");
2177:
1.743 raeburn 2178: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2179:
1.910 raeburn 2180: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2181:
1.1075.2.36 raeburn 2182: The optional $incdoms is a reference to an array of domains which will be the only available options.
2183:
2184: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2185:
1.35 matthew 2186: =cut
2187:
2188: #-------------------------------------------
1.34 matthew 2189: sub select_dom_form {
1.1075.2.36 raeburn 2190: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2191: if ($onchange) {
1.874 raeburn 2192: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2193: }
1.1075.2.36 raeburn 2194: my (@domains,%exclude);
1.910 raeburn 2195: if (ref($incdoms) eq 'ARRAY') {
2196: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2197: } else {
2198: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2199: }
1.90 www 2200: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2201: if (ref($excdoms) eq 'ARRAY') {
2202: map { $exclude{$_} = 1; } @{$excdoms};
2203: }
1.743 raeburn 2204: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2205: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2206: next if ($exclude{$dom});
1.356 albertel 2207: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2208: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2209: if ($showdomdesc) {
2210: if ($dom ne '') {
2211: my $domdesc = &Apache::lonnet::domain($dom,'description');
2212: if ($domdesc ne '') {
2213: $selectdomain .= ' ('.$domdesc.')';
2214: }
2215: }
2216: }
2217: $selectdomain .= "</option>\n";
1.34 matthew 2218: }
2219: $selectdomain.="</select>";
2220: return $selectdomain;
2221: }
2222:
1.35 matthew 2223: #-------------------------------------------
2224:
1.45 matthew 2225: =pod
2226:
1.648 raeburn 2227: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2228:
1.586 raeburn 2229: input: 4 arguments (two required, two optional) -
2230: $domain - domain of new user
2231: $name - name of form element
2232: $default - Value of 'default' causes a default item to be first
2233: option, and selected by default.
2234: $hide - Value of 'hide' causes hiding of the name of the server,
2235: if 1 server found, or default, if 0 found.
1.594 raeburn 2236: output: returns 2 items:
1.586 raeburn 2237: (a) form element which contains either:
2238: (i) <select name="$name">
2239: <option value="$hostid1">$hostid $servers{$hostid}</option>
2240: <option value="$hostid2">$hostid $servers{$hostid}</option>
2241: </select>
2242: form item if there are multiple library servers in $domain, or
2243: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2244: if there is only one library server in $domain.
2245:
2246: (b) number of library servers found.
2247:
2248: See loncreateuser.pm for example of use.
1.35 matthew 2249:
2250: =cut
2251:
2252: #-------------------------------------------
1.586 raeburn 2253: sub home_server_form_item {
2254: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2255: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2256: my $result;
2257: my $numlib = keys(%servers);
2258: if ($numlib > 1) {
2259: $result .= '<select name="'.$name.'" />'."\n";
2260: if ($default) {
1.804 bisitz 2261: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2262: '</option>'."\n";
2263: }
2264: foreach my $hostid (sort(keys(%servers))) {
2265: $result.= '<option value="'.$hostid.'">'.
2266: $hostid.' '.$servers{$hostid}."</option>\n";
2267: }
2268: $result .= '</select>'."\n";
2269: } elsif ($numlib == 1) {
2270: my $hostid;
2271: foreach my $item (keys(%servers)) {
2272: $hostid = $item;
2273: }
2274: $result .= '<input type="hidden" name="'.$name.'" value="'.
2275: $hostid.'" />';
2276: if (!$hide) {
2277: $result .= $hostid.' '.$servers{$hostid};
2278: }
2279: $result .= "\n";
2280: } elsif ($default) {
2281: $result .= '<input type="hidden" name="'.$name.
2282: '" value="default" />';
2283: if (!$hide) {
2284: $result .= &mt('default');
2285: }
2286: $result .= "\n";
1.33 matthew 2287: }
1.586 raeburn 2288: return ($result,$numlib);
1.33 matthew 2289: }
1.112 bowersj2 2290:
2291: =pod
2292:
1.534 albertel 2293: =back
2294:
1.112 bowersj2 2295: =cut
1.87 matthew 2296:
2297: ###############################################################
1.112 bowersj2 2298: ## Decoding User Agent ##
1.87 matthew 2299: ###############################################################
2300:
2301: =pod
2302:
1.112 bowersj2 2303: =head1 Decoding the User Agent
2304:
2305: =over 4
2306:
2307: =item * &decode_user_agent()
1.87 matthew 2308:
2309: Inputs: $r
2310:
2311: Outputs:
2312:
2313: =over 4
2314:
1.112 bowersj2 2315: =item * $httpbrowser
1.87 matthew 2316:
1.112 bowersj2 2317: =item * $clientbrowser
1.87 matthew 2318:
1.112 bowersj2 2319: =item * $clientversion
1.87 matthew 2320:
1.112 bowersj2 2321: =item * $clientmathml
1.87 matthew 2322:
1.112 bowersj2 2323: =item * $clientunicode
1.87 matthew 2324:
1.112 bowersj2 2325: =item * $clientos
1.87 matthew 2326:
1.1075.2.42 raeburn 2327: =item * $clientmobile
2328:
2329: =item * $clientinfo
2330:
1.87 matthew 2331: =back
2332:
1.157 matthew 2333: =back
2334:
1.87 matthew 2335: =cut
2336:
2337: ###############################################################
2338: ###############################################################
2339: sub decode_user_agent {
1.247 albertel 2340: my ($r)=@_;
1.87 matthew 2341: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2342: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2343: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2344: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2345: my $clientbrowser='unknown';
2346: my $clientversion='0';
2347: my $clientmathml='';
2348: my $clientunicode='0';
1.1075.2.42 raeburn 2349: my $clientmobile=0;
1.87 matthew 2350: for (my $i=0;$i<=$#browsertype;$i++) {
2351: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2352: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2353: $clientbrowser=$bname;
2354: $httpbrowser=~/$vreg/i;
2355: $clientversion=$1;
2356: $clientmathml=($clientversion>=$minv);
2357: $clientunicode=($clientversion>=$univ);
2358: }
2359: }
2360: my $clientos='unknown';
1.1075.2.42 raeburn 2361: my $clientinfo;
1.87 matthew 2362: if (($httpbrowser=~/linux/i) ||
2363: ($httpbrowser=~/unix/i) ||
2364: ($httpbrowser=~/ux/i) ||
2365: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2366: if (($httpbrowser=~/vax/i) ||
2367: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2368: if ($httpbrowser=~/next/i) { $clientos='next'; }
2369: if (($httpbrowser=~/mac/i) ||
2370: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2371: if ($httpbrowser=~/win/i) { $clientos='win'; }
2372: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2373: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2374: $clientmobile=lc($1);
2375: }
2376: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2377: $clientinfo = 'firefox-'.$1;
2378: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2379: $clientinfo = 'chromeframe-'.$1;
2380: }
1.87 matthew 2381: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 2382: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2383: }
2384:
1.32 matthew 2385: ###############################################################
2386: ## Authentication changing form generation subroutines ##
2387: ###############################################################
2388: ##
2389: ## All of the authform_xxxxxxx subroutines take their inputs in a
2390: ## hash, and have reasonable default values.
2391: ##
2392: ## formname = the name given in the <form> tag.
1.35 matthew 2393: #-------------------------------------------
2394:
1.45 matthew 2395: =pod
2396:
1.112 bowersj2 2397: =head1 Authentication Routines
2398:
2399: =over 4
2400:
1.648 raeburn 2401: =item * &authform_xxxxxx()
1.35 matthew 2402:
2403: The authform_xxxxxx subroutines provide javascript and html forms which
2404: handle some of the conveniences required for authentication forms.
2405: This is not an optimal method, but it works.
2406:
2407: =over 4
2408:
1.112 bowersj2 2409: =item * authform_header
1.35 matthew 2410:
1.112 bowersj2 2411: =item * authform_authorwarning
1.35 matthew 2412:
1.112 bowersj2 2413: =item * authform_nochange
1.35 matthew 2414:
1.112 bowersj2 2415: =item * authform_kerberos
1.35 matthew 2416:
1.112 bowersj2 2417: =item * authform_internal
1.35 matthew 2418:
1.112 bowersj2 2419: =item * authform_filesystem
1.35 matthew 2420:
2421: =back
2422:
1.648 raeburn 2423: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2424:
1.35 matthew 2425: =cut
2426:
2427: #-------------------------------------------
1.32 matthew 2428: sub authform_header{
2429: my %in = (
2430: formname => 'cu',
1.80 albertel 2431: kerb_def_dom => '',
1.32 matthew 2432: @_,
2433: );
2434: $in{'formname'} = 'document.' . $in{'formname'};
2435: my $result='';
1.80 albertel 2436:
2437: #---------------------------------------------- Code for upper case translation
2438: my $Javascript_toUpperCase;
2439: unless ($in{kerb_def_dom}) {
2440: $Javascript_toUpperCase =<<"END";
2441: switch (choice) {
2442: case 'krb': currentform.elements[choicearg].value =
2443: currentform.elements[choicearg].value.toUpperCase();
2444: break;
2445: default:
2446: }
2447: END
2448: } else {
2449: $Javascript_toUpperCase = "";
2450: }
2451:
1.165 raeburn 2452: my $radioval = "'nochange'";
1.591 raeburn 2453: if (defined($in{'curr_authtype'})) {
2454: if ($in{'curr_authtype'} ne '') {
2455: $radioval = "'".$in{'curr_authtype'}."arg'";
2456: }
1.174 matthew 2457: }
1.165 raeburn 2458: my $argfield = 'null';
1.591 raeburn 2459: if (defined($in{'mode'})) {
1.165 raeburn 2460: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2461: if (defined($in{'curr_autharg'})) {
2462: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2463: $argfield = "'$in{'curr_autharg'}'";
2464: }
2465: }
2466: }
2467: }
2468:
1.32 matthew 2469: $result.=<<"END";
2470: var current = new Object();
1.165 raeburn 2471: current.radiovalue = $radioval;
2472: current.argfield = $argfield;
1.32 matthew 2473:
2474: function changed_radio(choice,currentform) {
2475: var choicearg = choice + 'arg';
2476: // If a radio button in changed, we need to change the argfield
2477: if (current.radiovalue != choice) {
2478: current.radiovalue = choice;
2479: if (current.argfield != null) {
2480: currentform.elements[current.argfield].value = '';
2481: }
2482: if (choice == 'nochange') {
2483: current.argfield = null;
2484: } else {
2485: current.argfield = choicearg;
2486: switch(choice) {
2487: case 'krb':
2488: currentform.elements[current.argfield].value =
2489: "$in{'kerb_def_dom'}";
2490: break;
2491: default:
2492: break;
2493: }
2494: }
2495: }
2496: return;
2497: }
1.22 www 2498:
1.32 matthew 2499: function changed_text(choice,currentform) {
2500: var choicearg = choice + 'arg';
2501: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2502: $Javascript_toUpperCase
1.32 matthew 2503: // clear old field
2504: if ((current.argfield != choicearg) && (current.argfield != null)) {
2505: currentform.elements[current.argfield].value = '';
2506: }
2507: current.argfield = choicearg;
2508: }
2509: set_auth_radio_buttons(choice,currentform);
2510: return;
1.20 www 2511: }
1.32 matthew 2512:
2513: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2514: var numauthchoices = currentform.login.length;
2515: if (typeof numauthchoices == "undefined") {
2516: return;
2517: }
1.32 matthew 2518: var i=0;
1.986 raeburn 2519: while (i < numauthchoices) {
1.32 matthew 2520: if (currentform.login[i].value == newvalue) { break; }
2521: i++;
2522: }
1.986 raeburn 2523: if (i == numauthchoices) {
1.32 matthew 2524: return;
2525: }
2526: current.radiovalue = newvalue;
2527: currentform.login[i].checked = true;
2528: return;
2529: }
2530: END
2531: return $result;
2532: }
2533:
1.1075.2.20 raeburn 2534: sub authform_authorwarning {
1.32 matthew 2535: my $result='';
1.144 matthew 2536: $result='<i>'.
2537: &mt('As a general rule, only authors or co-authors should be '.
2538: 'filesystem authenticated '.
2539: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2540: return $result;
2541: }
2542:
1.1075.2.20 raeburn 2543: sub authform_nochange {
1.32 matthew 2544: my %in = (
2545: formname => 'document.cu',
2546: kerb_def_dom => 'MSU.EDU',
2547: @_,
2548: );
1.1075.2.20 raeburn 2549: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2550: my $result;
1.1075.2.20 raeburn 2551: if (!$authnum) {
2552: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2553: } else {
2554: $result = '<label>'.&mt('[_1] Do not change login data',
2555: '<input type="radio" name="login" value="nochange" '.
2556: 'checked="checked" onclick="'.
1.281 albertel 2557: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2558: '</label>';
1.586 raeburn 2559: }
1.32 matthew 2560: return $result;
2561: }
2562:
1.591 raeburn 2563: sub authform_kerberos {
1.32 matthew 2564: my %in = (
2565: formname => 'document.cu',
2566: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2567: kerb_def_auth => 'krb4',
1.32 matthew 2568: @_,
2569: );
1.586 raeburn 2570: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2571: $autharg,$jscall);
1.1075.2.20 raeburn 2572: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2573: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2574: $check5 = ' checked="checked"';
1.80 albertel 2575: } else {
1.772 bisitz 2576: $check4 = ' checked="checked"';
1.80 albertel 2577: }
1.165 raeburn 2578: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2579: if (defined($in{'curr_authtype'})) {
2580: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2581: $krbcheck = ' checked="checked"';
1.623 raeburn 2582: if (defined($in{'mode'})) {
2583: if ($in{'mode'} eq 'modifyuser') {
2584: $krbcheck = '';
2585: }
2586: }
1.591 raeburn 2587: if (defined($in{'curr_kerb_ver'})) {
2588: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2589: $check5 = ' checked="checked"';
1.591 raeburn 2590: $check4 = '';
2591: } else {
1.772 bisitz 2592: $check4 = ' checked="checked"';
1.591 raeburn 2593: $check5 = '';
2594: }
1.586 raeburn 2595: }
1.591 raeburn 2596: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2597: $krbarg = $in{'curr_autharg'};
2598: }
1.586 raeburn 2599: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2600: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2601: $result =
2602: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2603: $in{'curr_autharg'},$krbver);
2604: } else {
2605: $result =
2606: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2607: }
2608: return $result;
2609: }
2610: }
2611: } else {
2612: if ($authnum == 1) {
1.784 bisitz 2613: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2614: }
2615: }
1.586 raeburn 2616: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2617: return;
1.587 raeburn 2618: } elsif ($authtype eq '') {
1.591 raeburn 2619: if (defined($in{'mode'})) {
1.587 raeburn 2620: if ($in{'mode'} eq 'modifycourse') {
2621: if ($authnum == 1) {
1.1075.2.20 raeburn 2622: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2623: }
2624: }
2625: }
1.586 raeburn 2626: }
2627: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2628: if ($authtype eq '') {
2629: $authtype = '<input type="radio" name="login" value="krb" '.
2630: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2631: $krbcheck.' />';
2632: }
2633: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2634: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2635: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2636: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2637: $in{'curr_authtype'} eq 'krb4')) {
2638: $result .= &mt
1.144 matthew 2639: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2640: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2641: '<label>'.$authtype,
1.281 albertel 2642: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2643: 'value="'.$krbarg.'" '.
1.144 matthew 2644: 'onchange="'.$jscall.'" />',
1.281 albertel 2645: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2646: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2647: '</label>');
1.586 raeburn 2648: } elsif ($can_assign{'krb4'}) {
2649: $result .= &mt
2650: ('[_1] Kerberos authenticated with domain [_2] '.
2651: '[_3] Version 4 [_4]',
2652: '<label>'.$authtype,
2653: '</label><input type="text" size="10" name="krbarg" '.
2654: 'value="'.$krbarg.'" '.
2655: 'onchange="'.$jscall.'" />',
2656: '<label><input type="hidden" name="krbver" value="4" />',
2657: '</label>');
2658: } elsif ($can_assign{'krb5'}) {
2659: $result .= &mt
2660: ('[_1] Kerberos authenticated with domain [_2] '.
2661: '[_3] Version 5 [_4]',
2662: '<label>'.$authtype,
2663: '</label><input type="text" size="10" name="krbarg" '.
2664: 'value="'.$krbarg.'" '.
2665: 'onchange="'.$jscall.'" />',
2666: '<label><input type="hidden" name="krbver" value="5" />',
2667: '</label>');
2668: }
1.32 matthew 2669: return $result;
2670: }
2671:
1.1075.2.20 raeburn 2672: sub authform_internal {
1.586 raeburn 2673: my %in = (
1.32 matthew 2674: formname => 'document.cu',
2675: kerb_def_dom => 'MSU.EDU',
2676: @_,
2677: );
1.586 raeburn 2678: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2679: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2680: if (defined($in{'curr_authtype'})) {
2681: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2682: if ($can_assign{'int'}) {
1.772 bisitz 2683: $intcheck = 'checked="checked" ';
1.623 raeburn 2684: if (defined($in{'mode'})) {
2685: if ($in{'mode'} eq 'modifyuser') {
2686: $intcheck = '';
2687: }
2688: }
1.591 raeburn 2689: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2690: $intarg = $in{'curr_autharg'};
2691: }
2692: } else {
2693: $result = &mt('Currently internally authenticated.');
2694: return $result;
1.165 raeburn 2695: }
2696: }
1.586 raeburn 2697: } else {
2698: if ($authnum == 1) {
1.784 bisitz 2699: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2700: }
2701: }
2702: if (!$can_assign{'int'}) {
2703: return;
1.587 raeburn 2704: } elsif ($authtype eq '') {
1.591 raeburn 2705: if (defined($in{'mode'})) {
1.587 raeburn 2706: if ($in{'mode'} eq 'modifycourse') {
2707: if ($authnum == 1) {
1.1075.2.20 raeburn 2708: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2709: }
2710: }
2711: }
1.165 raeburn 2712: }
1.586 raeburn 2713: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2714: if ($authtype eq '') {
2715: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2716: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2717: }
1.605 bisitz 2718: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2719: $intarg.'" onchange="'.$jscall.'" />';
2720: $result = &mt
1.144 matthew 2721: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2722: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2723: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2724: return $result;
2725: }
2726:
1.1075.2.20 raeburn 2727: sub authform_local {
1.32 matthew 2728: my %in = (
2729: formname => 'document.cu',
2730: kerb_def_dom => 'MSU.EDU',
2731: @_,
2732: );
1.586 raeburn 2733: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2734: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2735: if (defined($in{'curr_authtype'})) {
2736: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2737: if ($can_assign{'loc'}) {
1.772 bisitz 2738: $loccheck = 'checked="checked" ';
1.623 raeburn 2739: if (defined($in{'mode'})) {
2740: if ($in{'mode'} eq 'modifyuser') {
2741: $loccheck = '';
2742: }
2743: }
1.591 raeburn 2744: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2745: $locarg = $in{'curr_autharg'};
2746: }
2747: } else {
2748: $result = &mt('Currently using local (institutional) authentication.');
2749: return $result;
1.165 raeburn 2750: }
2751: }
1.586 raeburn 2752: } else {
2753: if ($authnum == 1) {
1.784 bisitz 2754: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2755: }
2756: }
2757: if (!$can_assign{'loc'}) {
2758: return;
1.587 raeburn 2759: } elsif ($authtype eq '') {
1.591 raeburn 2760: if (defined($in{'mode'})) {
1.587 raeburn 2761: if ($in{'mode'} eq 'modifycourse') {
2762: if ($authnum == 1) {
1.1075.2.20 raeburn 2763: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2764: }
2765: }
2766: }
1.165 raeburn 2767: }
1.586 raeburn 2768: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2769: if ($authtype eq '') {
2770: $authtype = '<input type="radio" name="login" value="loc" '.
2771: $loccheck.' onchange="'.$jscall.'" onclick="'.
2772: $jscall.'" />';
2773: }
2774: $autharg = '<input type="text" size="10" name="locarg" value="'.
2775: $locarg.'" onchange="'.$jscall.'" />';
2776: $result = &mt('[_1] Local Authentication with argument [_2]',
2777: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2778: return $result;
2779: }
2780:
1.1075.2.20 raeburn 2781: sub authform_filesystem {
1.32 matthew 2782: my %in = (
2783: formname => 'document.cu',
2784: kerb_def_dom => 'MSU.EDU',
2785: @_,
2786: );
1.586 raeburn 2787: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2788: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2789: if (defined($in{'curr_authtype'})) {
2790: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2791: if ($can_assign{'fsys'}) {
1.772 bisitz 2792: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2793: if (defined($in{'mode'})) {
2794: if ($in{'mode'} eq 'modifyuser') {
2795: $fsyscheck = '';
2796: }
2797: }
1.586 raeburn 2798: } else {
2799: $result = &mt('Currently Filesystem Authenticated.');
2800: return $result;
2801: }
2802: }
2803: } else {
2804: if ($authnum == 1) {
1.784 bisitz 2805: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2806: }
2807: }
2808: if (!$can_assign{'fsys'}) {
2809: return;
1.587 raeburn 2810: } elsif ($authtype eq '') {
1.591 raeburn 2811: if (defined($in{'mode'})) {
1.587 raeburn 2812: if ($in{'mode'} eq 'modifycourse') {
2813: if ($authnum == 1) {
1.1075.2.20 raeburn 2814: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2815: }
2816: }
2817: }
1.586 raeburn 2818: }
2819: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2820: if ($authtype eq '') {
2821: $authtype = '<input type="radio" name="login" value="fsys" '.
2822: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2823: $jscall.'" />';
2824: }
2825: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2826: ' onchange="'.$jscall.'" />';
2827: $result = &mt
1.144 matthew 2828: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2829: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2830: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2831: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2832: 'onchange="'.$jscall.'" />');
1.32 matthew 2833: return $result;
2834: }
2835:
1.586 raeburn 2836: sub get_assignable_auth {
2837: my ($dom) = @_;
2838: if ($dom eq '') {
2839: $dom = $env{'request.role.domain'};
2840: }
2841: my %can_assign = (
2842: krb4 => 1,
2843: krb5 => 1,
2844: int => 1,
2845: loc => 1,
2846: );
2847: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2848: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2849: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2850: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2851: my $context;
2852: if ($env{'request.role'} =~ /^au/) {
2853: $context = 'author';
2854: } elsif ($env{'request.role'} =~ /^dc/) {
2855: $context = 'domain';
2856: } elsif ($env{'request.course.id'}) {
2857: $context = 'course';
2858: }
2859: if ($context) {
2860: if (ref($authhash->{$context}) eq 'HASH') {
2861: %can_assign = %{$authhash->{$context}};
2862: }
2863: }
2864: }
2865: }
2866: my $authnum = 0;
2867: foreach my $key (keys(%can_assign)) {
2868: if ($can_assign{$key}) {
2869: $authnum ++;
2870: }
2871: }
2872: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2873: $authnum --;
2874: }
2875: return ($authnum,%can_assign);
2876: }
2877:
1.80 albertel 2878: ###############################################################
2879: ## Get Kerberos Defaults for Domain ##
2880: ###############################################################
2881: ##
2882: ## Returns default kerberos version and an associated argument
2883: ## as listed in file domain.tab. If not listed, provides
2884: ## appropriate default domain and kerberos version.
2885: ##
2886: #-------------------------------------------
2887:
2888: =pod
2889:
1.648 raeburn 2890: =item * &get_kerberos_defaults()
1.80 albertel 2891:
2892: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2893: version and domain. If not found, it defaults to version 4 and the
2894: domain of the server.
1.80 albertel 2895:
1.648 raeburn 2896: =over 4
2897:
1.80 albertel 2898: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2899:
1.648 raeburn 2900: =back
2901:
2902: =back
2903:
1.80 albertel 2904: =cut
2905:
2906: #-------------------------------------------
2907: sub get_kerberos_defaults {
2908: my $domain=shift;
1.641 raeburn 2909: my ($krbdef,$krbdefdom);
2910: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2911: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2912: $krbdef = $domdefaults{'auth_def'};
2913: $krbdefdom = $domdefaults{'auth_arg_def'};
2914: } else {
1.80 albertel 2915: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2916: my $krbdefdom=$1;
2917: $krbdefdom=~tr/a-z/A-Z/;
2918: $krbdef = "krb4";
2919: }
2920: return ($krbdef,$krbdefdom);
2921: }
1.112 bowersj2 2922:
1.32 matthew 2923:
1.46 matthew 2924: ###############################################################
2925: ## Thesaurus Functions ##
2926: ###############################################################
1.20 www 2927:
1.46 matthew 2928: =pod
1.20 www 2929:
1.112 bowersj2 2930: =head1 Thesaurus Functions
2931:
2932: =over 4
2933:
1.648 raeburn 2934: =item * &initialize_keywords()
1.46 matthew 2935:
2936: Initializes the package variable %Keywords if it is empty. Uses the
2937: package variable $thesaurus_db_file.
2938:
2939: =cut
2940:
2941: ###################################################
2942:
2943: sub initialize_keywords {
2944: return 1 if (scalar keys(%Keywords));
2945: # If we are here, %Keywords is empty, so fill it up
2946: # Make sure the file we need exists...
2947: if (! -e $thesaurus_db_file) {
2948: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2949: " failed because it does not exist");
2950: return 0;
2951: }
2952: # Set up the hash as a database
2953: my %thesaurus_db;
2954: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2955: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2956: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2957: $thesaurus_db_file);
2958: return 0;
2959: }
2960: # Get the average number of appearances of a word.
2961: my $avecount = $thesaurus_db{'average.count'};
2962: # Put keywords (those that appear > average) into %Keywords
2963: while (my ($word,$data)=each (%thesaurus_db)) {
2964: my ($count,undef) = split /:/,$data;
2965: $Keywords{$word}++ if ($count > $avecount);
2966: }
2967: untie %thesaurus_db;
2968: # Remove special values from %Keywords.
1.356 albertel 2969: foreach my $value ('total.count','average.count') {
2970: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2971: }
1.46 matthew 2972: return 1;
2973: }
2974:
2975: ###################################################
2976:
2977: =pod
2978:
1.648 raeburn 2979: =item * &keyword($word)
1.46 matthew 2980:
2981: Returns true if $word is a keyword. A keyword is a word that appears more
2982: than the average number of times in the thesaurus database. Calls
2983: &initialize_keywords
2984:
2985: =cut
2986:
2987: ###################################################
1.20 www 2988:
2989: sub keyword {
1.46 matthew 2990: return if (!&initialize_keywords());
2991: my $word=lc(shift());
2992: $word=~s/\W//g;
2993: return exists($Keywords{$word});
1.20 www 2994: }
1.46 matthew 2995:
2996: ###############################################################
2997:
2998: =pod
1.20 www 2999:
1.648 raeburn 3000: =item * &get_related_words()
1.46 matthew 3001:
1.160 matthew 3002: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3003: an array of words. If the keyword is not in the thesaurus, an empty array
3004: will be returned. The order of the words returned is determined by the
3005: database which holds them.
3006:
3007: Uses global $thesaurus_db_file.
3008:
1.1057 foxr 3009:
1.46 matthew 3010: =cut
3011:
3012: ###############################################################
3013: sub get_related_words {
3014: my $keyword = shift;
3015: my %thesaurus_db;
3016: if (! -e $thesaurus_db_file) {
3017: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3018: "failed because the file does not exist");
3019: return ();
3020: }
3021: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3022: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3023: return ();
3024: }
3025: my @Words=();
1.429 www 3026: my $count=0;
1.46 matthew 3027: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3028: # The first element is the number of times
3029: # the word appears. We do not need it now.
1.429 www 3030: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3031: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3032: my $threshold=$mostfrequentcount/10;
3033: foreach my $possibleword (@RelatedWords) {
3034: my ($word,$wordcount)=split(/\,/,$possibleword);
3035: if ($wordcount>$threshold) {
3036: push(@Words,$word);
3037: $count++;
3038: if ($count>10) { last; }
3039: }
1.20 www 3040: }
3041: }
1.46 matthew 3042: untie %thesaurus_db;
3043: return @Words;
1.14 harris41 3044: }
1.46 matthew 3045:
1.112 bowersj2 3046: =pod
3047:
3048: =back
3049:
3050: =cut
1.61 www 3051:
3052: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3053: =pod
3054:
1.112 bowersj2 3055: =head1 User Name Functions
3056:
3057: =over 4
3058:
1.648 raeburn 3059: =item * &plainname($uname,$udom,$first)
1.81 albertel 3060:
1.112 bowersj2 3061: Takes a users logon name and returns it as a string in
1.226 albertel 3062: "first middle last generation" form
3063: if $first is set to 'lastname' then it returns it as
3064: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3065:
3066: =cut
1.61 www 3067:
1.295 www 3068:
1.81 albertel 3069: ###############################################################
1.61 www 3070: sub plainname {
1.226 albertel 3071: my ($uname,$udom,$first)=@_;
1.537 albertel 3072: return if (!defined($uname) || !defined($udom));
1.295 www 3073: my %names=&getnames($uname,$udom);
1.226 albertel 3074: my $name=&Apache::lonnet::format_name($names{'firstname'},
3075: $names{'middlename'},
3076: $names{'lastname'},
3077: $names{'generation'},$first);
3078: $name=~s/^\s+//;
1.62 www 3079: $name=~s/\s+$//;
3080: $name=~s/\s+/ /g;
1.353 albertel 3081: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3082: return $name;
1.61 www 3083: }
1.66 www 3084:
3085: # -------------------------------------------------------------------- Nickname
1.81 albertel 3086: =pod
3087:
1.648 raeburn 3088: =item * &nickname($uname,$udom)
1.81 albertel 3089:
3090: Gets a users name and returns it as a string as
3091:
3092: ""nickname""
1.66 www 3093:
1.81 albertel 3094: if the user has a nickname or
3095:
3096: "first middle last generation"
3097:
3098: if the user does not
3099:
3100: =cut
1.66 www 3101:
3102: sub nickname {
3103: my ($uname,$udom)=@_;
1.537 albertel 3104: return if (!defined($uname) || !defined($udom));
1.295 www 3105: my %names=&getnames($uname,$udom);
1.68 albertel 3106: my $name=$names{'nickname'};
1.66 www 3107: if ($name) {
3108: $name='"'.$name.'"';
3109: } else {
3110: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3111: $names{'lastname'}.' '.$names{'generation'};
3112: $name=~s/\s+$//;
3113: $name=~s/\s+/ /g;
3114: }
3115: return $name;
3116: }
3117:
1.295 www 3118: sub getnames {
3119: my ($uname,$udom)=@_;
1.537 albertel 3120: return if (!defined($uname) || !defined($udom));
1.433 albertel 3121: if ($udom eq 'public' && $uname eq 'public') {
3122: return ('lastname' => &mt('Public'));
3123: }
1.295 www 3124: my $id=$uname.':'.$udom;
3125: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3126: if ($cached) {
3127: return %{$names};
3128: } else {
3129: my %loadnames=&Apache::lonnet::get('environment',
3130: ['firstname','middlename','lastname','generation','nickname'],
3131: $udom,$uname);
3132: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3133: return %loadnames;
3134: }
3135: }
1.61 www 3136:
1.542 raeburn 3137: # -------------------------------------------------------------------- getemails
1.648 raeburn 3138:
1.542 raeburn 3139: =pod
3140:
1.648 raeburn 3141: =item * &getemails($uname,$udom)
1.542 raeburn 3142:
3143: Gets a user's email information and returns it as a hash with keys:
3144: notification, critnotification, permanentemail
3145:
3146: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3147: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3148:
1.648 raeburn 3149:
1.542 raeburn 3150: =cut
3151:
1.648 raeburn 3152:
1.466 albertel 3153: sub getemails {
3154: my ($uname,$udom)=@_;
3155: if ($udom eq 'public' && $uname eq 'public') {
3156: return;
3157: }
1.467 www 3158: if (!$udom) { $udom=$env{'user.domain'}; }
3159: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3160: my $id=$uname.':'.$udom;
3161: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3162: if ($cached) {
3163: return %{$names};
3164: } else {
3165: my %loadnames=&Apache::lonnet::get('environment',
3166: ['notification','critnotification',
3167: 'permanentemail'],
3168: $udom,$uname);
3169: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3170: return %loadnames;
3171: }
3172: }
3173:
1.551 albertel 3174: sub flush_email_cache {
3175: my ($uname,$udom)=@_;
3176: if (!$udom) { $udom =$env{'user.domain'}; }
3177: if (!$uname) { $uname=$env{'user.name'}; }
3178: return if ($udom eq 'public' && $uname eq 'public');
3179: my $id=$uname.':'.$udom;
3180: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3181: }
3182:
1.728 raeburn 3183: # -------------------------------------------------------------------- getlangs
3184:
3185: =pod
3186:
3187: =item * &getlangs($uname,$udom)
3188:
3189: Gets a user's language preference and returns it as a hash with key:
3190: language.
3191:
3192: =cut
3193:
3194:
3195: sub getlangs {
3196: my ($uname,$udom) = @_;
3197: if (!$udom) { $udom =$env{'user.domain'}; }
3198: if (!$uname) { $uname=$env{'user.name'}; }
3199: my $id=$uname.':'.$udom;
3200: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3201: if ($cached) {
3202: return %{$langs};
3203: } else {
3204: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3205: $udom,$uname);
3206: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3207: return %loadlangs;
3208: }
3209: }
3210:
3211: sub flush_langs_cache {
3212: my ($uname,$udom)=@_;
3213: if (!$udom) { $udom =$env{'user.domain'}; }
3214: if (!$uname) { $uname=$env{'user.name'}; }
3215: return if ($udom eq 'public' && $uname eq 'public');
3216: my $id=$uname.':'.$udom;
3217: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3218: }
3219:
1.61 www 3220: # ------------------------------------------------------------------ Screenname
1.81 albertel 3221:
3222: =pod
3223:
1.648 raeburn 3224: =item * &screenname($uname,$udom)
1.81 albertel 3225:
3226: Gets a users screenname and returns it as a string
3227:
3228: =cut
1.61 www 3229:
3230: sub screenname {
3231: my ($uname,$udom)=@_;
1.258 albertel 3232: if ($uname eq $env{'user.name'} &&
3233: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3234: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3235: return $names{'screenname'};
1.62 www 3236: }
3237:
1.212 albertel 3238:
1.802 bisitz 3239: # ------------------------------------------------------------- Confirm Wrapper
3240: =pod
3241:
1.1075.2.42 raeburn 3242: =item * &confirmwrapper($message)
1.802 bisitz 3243:
3244: Wrap messages about completion of operation in box
3245:
3246: =cut
3247:
3248: sub confirmwrapper {
3249: my ($message)=@_;
3250: if ($message) {
3251: return "\n".'<div class="LC_confirm_box">'."\n"
3252: .$message."\n"
3253: .'</div>'."\n";
3254: } else {
3255: return $message;
3256: }
3257: }
3258:
1.62 www 3259: # ------------------------------------------------------------- Message Wrapper
3260:
3261: sub messagewrapper {
1.369 www 3262: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3263: return
1.441 albertel 3264: '<a href="/adm/email?compose=individual&'.
3265: 'recname='.$username.'&recdom='.$domain.
3266: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3267: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3268: }
1.802 bisitz 3269:
1.74 www 3270: # --------------------------------------------------------------- Notes Wrapper
3271:
3272: sub noteswrapper {
3273: my ($link,$un,$do)=@_;
3274: return
1.896 amueller 3275: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3276: }
1.802 bisitz 3277:
1.62 www 3278: # ------------------------------------------------------------- Aboutme Wrapper
3279:
3280: sub aboutmewrapper {
1.1070 raeburn 3281: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3282: if (!defined($username) && !defined($domain)) {
3283: return;
3284: }
1.1075.2.15 raeburn 3285: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3286: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3287: }
3288:
3289: # ------------------------------------------------------------ Syllabus Wrapper
3290:
3291: sub syllabuswrapper {
1.707 bisitz 3292: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3293: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3294: }
1.14 harris41 3295:
1.802 bisitz 3296: # -----------------------------------------------------------------------------
3297:
1.208 matthew 3298: sub track_student_link {
1.887 raeburn 3299: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3300: my $link ="/adm/trackstudent?";
1.208 matthew 3301: my $title = 'View recent activity';
3302: if (defined($sname) && $sname !~ /^\s*$/ &&
3303: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3304: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3305: $title .= ' of this student';
1.268 albertel 3306: }
1.208 matthew 3307: if (defined($target) && $target !~ /^\s*$/) {
3308: $target = qq{target="$target"};
3309: } else {
3310: $target = '';
3311: }
1.268 albertel 3312: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3313: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3314: $title = &mt($title);
3315: $linktext = &mt($linktext);
1.448 albertel 3316: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3317: &help_open_topic('View_recent_activity');
1.208 matthew 3318: }
3319:
1.781 raeburn 3320: sub slot_reservations_link {
3321: my ($linktext,$sname,$sdom,$target) = @_;
3322: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3323: my $title = 'View slot reservation history';
3324: if (defined($sname) && $sname !~ /^\s*$/ &&
3325: defined($sdom) && $sdom !~ /^\s*$/) {
3326: $link .= "&uname=$sname&udom=$sdom";
3327: $title .= ' of this student';
3328: }
3329: if (defined($target) && $target !~ /^\s*$/) {
3330: $target = qq{target="$target"};
3331: } else {
3332: $target = '';
3333: }
3334: $title = &mt($title);
3335: $linktext = &mt($linktext);
3336: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3337: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3338:
3339: }
3340:
1.508 www 3341: # ===================================================== Display a student photo
3342:
3343:
1.509 albertel 3344: sub student_image_tag {
1.508 www 3345: my ($domain,$user)=@_;
3346: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3347: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3348: return '<img src="'.$imgsrc.'" align="right" />';
3349: } else {
3350: return '';
3351: }
3352: }
3353:
1.112 bowersj2 3354: =pod
3355:
3356: =back
3357:
3358: =head1 Access .tab File Data
3359:
3360: =over 4
3361:
1.648 raeburn 3362: =item * &languageids()
1.112 bowersj2 3363:
3364: returns list of all language ids
3365:
3366: =cut
3367:
1.14 harris41 3368: sub languageids {
1.16 harris41 3369: return sort(keys(%language));
1.14 harris41 3370: }
3371:
1.112 bowersj2 3372: =pod
3373:
1.648 raeburn 3374: =item * &languagedescription()
1.112 bowersj2 3375:
3376: returns description of a specified language id
3377:
3378: =cut
3379:
1.14 harris41 3380: sub languagedescription {
1.125 www 3381: my $code=shift;
3382: return ($supported_language{$code}?'* ':'').
3383: $language{$code}.
1.126 www 3384: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3385: }
3386:
1.1048 foxr 3387: =pod
3388:
3389: =item * &plainlanguagedescription
3390:
3391: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3392: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3393:
3394: =cut
3395:
1.145 www 3396: sub plainlanguagedescription {
3397: my $code=shift;
3398: return $language{$code};
3399: }
3400:
1.1048 foxr 3401: =pod
3402:
3403: =item * &supportedlanguagecode
3404:
3405: Returns the supported language code (e.g. sptutf maps to pt) given a language
3406: code.
3407:
3408: =cut
3409:
1.145 www 3410: sub supportedlanguagecode {
3411: my $code=shift;
3412: return $supported_language{$code};
1.97 www 3413: }
3414:
1.112 bowersj2 3415: =pod
3416:
1.1048 foxr 3417: =item * &latexlanguage()
3418:
3419: Given a language key code returns the correspondnig language to use
3420: to select the correct hyphenation on LaTeX printouts. This is undef if there
3421: is no supported hyphenation for the language code.
3422:
3423: =cut
3424:
3425: sub latexlanguage {
3426: my $code = shift;
3427: return $latex_language{$code};
3428: }
3429:
3430: =pod
3431:
3432: =item * &latexhyphenation()
3433:
3434: Same as above but what's supplied is the language as it might be stored
3435: in the metadata.
3436:
3437: =cut
3438:
3439: sub latexhyphenation {
3440: my $key = shift;
3441: return $latex_language_bykey{$key};
3442: }
3443:
3444: =pod
3445:
1.648 raeburn 3446: =item * ©rightids()
1.112 bowersj2 3447:
3448: returns list of all copyrights
3449:
3450: =cut
3451:
3452: sub copyrightids {
3453: return sort(keys(%cprtag));
3454: }
3455:
3456: =pod
3457:
1.648 raeburn 3458: =item * ©rightdescription()
1.112 bowersj2 3459:
3460: returns description of a specified copyright id
3461:
3462: =cut
3463:
3464: sub copyrightdescription {
1.166 www 3465: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3466: }
1.197 matthew 3467:
3468: =pod
3469:
1.648 raeburn 3470: =item * &source_copyrightids()
1.192 taceyjo1 3471:
3472: returns list of all source copyrights
3473:
3474: =cut
3475:
3476: sub source_copyrightids {
3477: return sort(keys(%scprtag));
3478: }
3479:
3480: =pod
3481:
1.648 raeburn 3482: =item * &source_copyrightdescription()
1.192 taceyjo1 3483:
3484: returns description of a specified source copyright id
3485:
3486: =cut
3487:
3488: sub source_copyrightdescription {
3489: return &mt($scprtag{shift(@_)});
3490: }
1.112 bowersj2 3491:
3492: =pod
3493:
1.648 raeburn 3494: =item * &filecategories()
1.112 bowersj2 3495:
3496: returns list of all file categories
3497:
3498: =cut
3499:
3500: sub filecategories {
3501: return sort(keys(%category_extensions));
3502: }
3503:
3504: =pod
3505:
1.648 raeburn 3506: =item * &filecategorytypes()
1.112 bowersj2 3507:
3508: returns list of file types belonging to a given file
3509: category
3510:
3511: =cut
3512:
3513: sub filecategorytypes {
1.356 albertel 3514: my ($cat) = @_;
3515: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3516: }
3517:
3518: =pod
3519:
1.648 raeburn 3520: =item * &fileembstyle()
1.112 bowersj2 3521:
3522: returns embedding style for a specified file type
3523:
3524: =cut
3525:
3526: sub fileembstyle {
3527: return $fe{lc(shift(@_))};
1.169 www 3528: }
3529:
1.351 www 3530: sub filemimetype {
3531: return $fm{lc(shift(@_))};
3532: }
3533:
1.169 www 3534:
3535: sub filecategoryselect {
3536: my ($name,$value)=@_;
1.189 matthew 3537: return &select_form($value,$name,
1.970 raeburn 3538: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3539: }
3540:
3541: =pod
3542:
1.648 raeburn 3543: =item * &filedescription()
1.112 bowersj2 3544:
3545: returns description for a specified file type
3546:
3547: =cut
3548:
3549: sub filedescription {
1.188 matthew 3550: my $file_description = $fd{lc(shift())};
3551: $file_description =~ s:([\[\]]):~$1:g;
3552: return &mt($file_description);
1.112 bowersj2 3553: }
3554:
3555: =pod
3556:
1.648 raeburn 3557: =item * &filedescriptionex()
1.112 bowersj2 3558:
3559: returns description for a specified file type with
3560: extra formatting
3561:
3562: =cut
3563:
3564: sub filedescriptionex {
3565: my $ex=shift;
1.188 matthew 3566: my $file_description = $fd{lc($ex)};
3567: $file_description =~ s:([\[\]]):~$1:g;
3568: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3569: }
3570:
3571: # End of .tab access
3572: =pod
3573:
3574: =back
3575:
3576: =cut
3577:
3578: # ------------------------------------------------------------------ File Types
3579: sub fileextensions {
3580: return sort(keys(%fe));
3581: }
3582:
1.97 www 3583: # ----------------------------------------------------------- Display Languages
3584: # returns a hash with all desired display languages
3585: #
3586:
3587: sub display_languages {
3588: my %languages=();
1.695 raeburn 3589: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3590: $languages{$lang}=1;
1.97 www 3591: }
3592: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3593: if ($env{'form.displaylanguage'}) {
1.356 albertel 3594: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3595: $languages{$lang}=1;
1.97 www 3596: }
3597: }
3598: return %languages;
1.14 harris41 3599: }
3600:
1.582 albertel 3601: sub languages {
3602: my ($possible_langs) = @_;
1.695 raeburn 3603: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3604: if (!ref($possible_langs)) {
3605: if( wantarray ) {
3606: return @preferred_langs;
3607: } else {
3608: return $preferred_langs[0];
3609: }
3610: }
3611: my %possibilities = map { $_ => 1 } (@$possible_langs);
3612: my @preferred_possibilities;
3613: foreach my $preferred_lang (@preferred_langs) {
3614: if (exists($possibilities{$preferred_lang})) {
3615: push(@preferred_possibilities, $preferred_lang);
3616: }
3617: }
3618: if( wantarray ) {
3619: return @preferred_possibilities;
3620: }
3621: return $preferred_possibilities[0];
3622: }
3623:
1.742 raeburn 3624: sub user_lang {
3625: my ($touname,$toudom,$fromcid) = @_;
3626: my @userlangs;
3627: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3628: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3629: $env{'course.'.$fromcid.'.languages'}));
3630: } else {
3631: my %langhash = &getlangs($touname,$toudom);
3632: if ($langhash{'languages'} ne '') {
3633: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3634: } else {
3635: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3636: if ($domdefs{'lang_def'} ne '') {
3637: @userlangs = ($domdefs{'lang_def'});
3638: }
3639: }
3640: }
3641: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3642: my $user_lh = Apache::localize->get_handle(@languages);
3643: return $user_lh;
3644: }
3645:
3646:
1.112 bowersj2 3647: ###############################################################
3648: ## Student Answer Attempts ##
3649: ###############################################################
3650:
3651: =pod
3652:
3653: =head1 Alternate Problem Views
3654:
3655: =over 4
3656:
1.648 raeburn 3657: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3658: $getattempt, $regexp, $gradesub)
3659:
3660: Return string with previous attempt on problem. Arguments:
3661:
3662: =over 4
3663:
3664: =item * $symb: Problem, including path
3665:
3666: =item * $username: username of the desired student
3667:
3668: =item * $domain: domain of the desired student
1.14 harris41 3669:
1.112 bowersj2 3670: =item * $course: Course ID
1.14 harris41 3671:
1.112 bowersj2 3672: =item * $getattempt: Leave blank for all attempts, otherwise put
3673: something
1.14 harris41 3674:
1.112 bowersj2 3675: =item * $regexp: if string matches this regexp, the string will be
3676: sent to $gradesub
1.14 harris41 3677:
1.112 bowersj2 3678: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3679:
1.112 bowersj2 3680: =back
1.14 harris41 3681:
1.112 bowersj2 3682: The output string is a table containing all desired attempts, if any.
1.16 harris41 3683:
1.112 bowersj2 3684: =cut
1.1 albertel 3685:
3686: sub get_previous_attempt {
1.43 ng 3687: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3688: my $prevattempts='';
1.43 ng 3689: no strict 'refs';
1.1 albertel 3690: if ($symb) {
1.3 albertel 3691: my (%returnhash)=
3692: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3693: if ($returnhash{'version'}) {
3694: my %lasthash=();
3695: my $version;
3696: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3697: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3698: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3699: }
1.1 albertel 3700: }
1.596 albertel 3701: $prevattempts=&start_data_table().&start_data_table_header_row();
3702: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3703: my (%typeparts,%lasthidden);
1.945 raeburn 3704: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3705: foreach my $key (sort(keys(%lasthash))) {
3706: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3707: if ($#parts > 0) {
1.31 albertel 3708: my $data=$parts[-1];
1.989 raeburn 3709: next if ($data eq 'foilorder');
1.31 albertel 3710: pop(@parts);
1.1010 www 3711: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3712: if ($data eq 'type') {
3713: unless ($showsurv) {
3714: my $id = join(',',@parts);
3715: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3716: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3717: $lasthidden{$ign.'.'.$id} = 1;
3718: }
1.945 raeburn 3719: }
1.1010 www 3720: }
1.31 albertel 3721: } else {
1.41 ng 3722: if ($#parts == 0) {
3723: $prevattempts.='<th>'.$parts[0].'</th>';
3724: } else {
3725: $prevattempts.='<th>'.$ign.'</th>';
3726: }
1.31 albertel 3727: }
1.16 harris41 3728: }
1.596 albertel 3729: $prevattempts.=&end_data_table_header_row();
1.40 ng 3730: if ($getattempt eq '') {
3731: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3732: my @hidden;
3733: if (%typeparts) {
3734: foreach my $id (keys(%typeparts)) {
3735: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3736: push(@hidden,$id);
3737: }
3738: }
3739: }
3740: $prevattempts.=&start_data_table_row().
3741: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3742: if (@hidden) {
3743: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3744: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3745: my $hide;
3746: foreach my $id (@hidden) {
3747: if ($key =~ /^\Q$id\E/) {
3748: $hide = 1;
3749: last;
3750: }
3751: }
3752: if ($hide) {
3753: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3754: if (($data eq 'award') || ($data eq 'awarddetail')) {
3755: my $value = &format_previous_attempt_value($key,
3756: $returnhash{$version.':'.$key});
3757: $prevattempts.='<td>'.$value.' </td>';
3758: } else {
3759: $prevattempts.='<td> </td>';
3760: }
3761: } else {
3762: if ($key =~ /\./) {
3763: my $value = &format_previous_attempt_value($key,
3764: $returnhash{$version.':'.$key});
3765: $prevattempts.='<td>'.$value.' </td>';
3766: } else {
3767: $prevattempts.='<td> </td>';
3768: }
3769: }
3770: }
3771: } else {
3772: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3773: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3774: my $value = &format_previous_attempt_value($key,
3775: $returnhash{$version.':'.$key});
3776: $prevattempts.='<td>'.$value.' </td>';
3777: }
3778: }
3779: $prevattempts.=&end_data_table_row();
1.40 ng 3780: }
1.1 albertel 3781: }
1.945 raeburn 3782: my @currhidden = keys(%lasthidden);
1.596 albertel 3783: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3784: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3785: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3786: if (%typeparts) {
3787: my $hidden;
3788: foreach my $id (@currhidden) {
3789: if ($key =~ /^\Q$id\E/) {
3790: $hidden = 1;
3791: last;
3792: }
3793: }
3794: if ($hidden) {
3795: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3796: if (($data eq 'award') || ($data eq 'awarddetail')) {
3797: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3798: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3799: $value = &$gradesub($value);
3800: }
3801: $prevattempts.='<td>'.$value.' </td>';
3802: } else {
3803: $prevattempts.='<td> </td>';
3804: }
3805: } else {
3806: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3807: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3808: $value = &$gradesub($value);
3809: }
3810: $prevattempts.='<td>'.$value.' </td>';
3811: }
3812: } else {
3813: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3814: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3815: $value = &$gradesub($value);
3816: }
3817: $prevattempts.='<td>'.$value.' </td>';
3818: }
1.16 harris41 3819: }
1.596 albertel 3820: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3821: } else {
1.596 albertel 3822: $prevattempts=
3823: &start_data_table().&start_data_table_row().
3824: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3825: &end_data_table_row().&end_data_table();
1.1 albertel 3826: }
3827: } else {
1.596 albertel 3828: $prevattempts=
3829: &start_data_table().&start_data_table_row().
3830: '<td>'.&mt('No data.').'</td>'.
3831: &end_data_table_row().&end_data_table();
1.1 albertel 3832: }
1.10 albertel 3833: }
3834:
1.581 albertel 3835: sub format_previous_attempt_value {
3836: my ($key,$value) = @_;
1.1011 www 3837: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3838: $value = &Apache::lonlocal::locallocaltime($value);
3839: } elsif (ref($value) eq 'ARRAY') {
3840: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3841: } elsif ($key =~ /answerstring$/) {
3842: my %answers = &Apache::lonnet::str2hash($value);
3843: my @anskeys = sort(keys(%answers));
3844: if (@anskeys == 1) {
3845: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3846: if ($answer =~ m{\0}) {
3847: $answer =~ s{\0}{,}g;
1.988 raeburn 3848: }
3849: my $tag_internal_answer_name = 'INTERNAL';
3850: if ($anskeys[0] eq $tag_internal_answer_name) {
3851: $value = $answer;
3852: } else {
3853: $value = $anskeys[0].'='.$answer;
3854: }
3855: } else {
3856: foreach my $ans (@anskeys) {
3857: my $answer = $answers{$ans};
1.1001 raeburn 3858: if ($answer =~ m{\0}) {
3859: $answer =~ s{\0}{,}g;
1.988 raeburn 3860: }
3861: $value .= $ans.'='.$answer.'<br />';;
3862: }
3863: }
1.581 albertel 3864: } else {
3865: $value = &unescape($value);
3866: }
3867: return $value;
3868: }
3869:
3870:
1.107 albertel 3871: sub relative_to_absolute {
3872: my ($url,$output)=@_;
3873: my $parser=HTML::TokeParser->new(\$output);
3874: my $token;
3875: my $thisdir=$url;
3876: my @rlinks=();
3877: while ($token=$parser->get_token) {
3878: if ($token->[0] eq 'S') {
3879: if ($token->[1] eq 'a') {
3880: if ($token->[2]->{'href'}) {
3881: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3882: }
3883: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3884: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3885: } elsif ($token->[1] eq 'base') {
3886: $thisdir=$token->[2]->{'href'};
3887: }
3888: }
3889: }
3890: $thisdir=~s-/[^/]*$--;
1.356 albertel 3891: foreach my $link (@rlinks) {
1.726 raeburn 3892: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3893: ($link=~/^\//) ||
3894: ($link=~/^javascript:/i) ||
3895: ($link=~/^mailto:/i) ||
3896: ($link=~/^\#/)) {
3897: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3898: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3899: }
3900: }
3901: # -------------------------------------------------- Deal with Applet codebases
3902: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3903: return $output;
3904: }
3905:
1.112 bowersj2 3906: =pod
3907:
1.648 raeburn 3908: =item * &get_student_view()
1.112 bowersj2 3909:
3910: show a snapshot of what student was looking at
3911:
3912: =cut
3913:
1.10 albertel 3914: sub get_student_view {
1.186 albertel 3915: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3916: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3917: my (%form);
1.10 albertel 3918: my @elements=('symb','courseid','domain','username');
3919: foreach my $element (@elements) {
1.186 albertel 3920: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3921: }
1.186 albertel 3922: if (defined($moreenv)) {
3923: %form=(%form,%{$moreenv});
3924: }
1.236 albertel 3925: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3926: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3927: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3928: $userview=~s/\<body[^\>]*\>//gi;
3929: $userview=~s/\<\/body\>//gi;
3930: $userview=~s/\<html\>//gi;
3931: $userview=~s/\<\/html\>//gi;
3932: $userview=~s/\<head\>//gi;
3933: $userview=~s/\<\/head\>//gi;
3934: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3935: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3936: if (wantarray) {
3937: return ($userview,$response);
3938: } else {
3939: return $userview;
3940: }
3941: }
3942:
3943: sub get_student_view_with_retries {
3944: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3945:
3946: my $ok = 0; # True if we got a good response.
3947: my $content;
3948: my $response;
3949:
3950: # Try to get the student_view done. within the retries count:
3951:
3952: do {
3953: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3954: $ok = $response->is_success;
3955: if (!$ok) {
3956: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3957: }
3958: $retries--;
3959: } while (!$ok && ($retries > 0));
3960:
3961: if (!$ok) {
3962: $content = ''; # On error return an empty content.
3963: }
1.651 www 3964: if (wantarray) {
3965: return ($content, $response);
3966: } else {
3967: return $content;
3968: }
1.11 albertel 3969: }
3970:
1.112 bowersj2 3971: =pod
3972:
1.648 raeburn 3973: =item * &get_student_answers()
1.112 bowersj2 3974:
3975: show a snapshot of how student was answering problem
3976:
3977: =cut
3978:
1.11 albertel 3979: sub get_student_answers {
1.100 sakharuk 3980: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3981: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3982: my (%moreenv);
1.11 albertel 3983: my @elements=('symb','courseid','domain','username');
3984: foreach my $element (@elements) {
1.186 albertel 3985: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3986: }
1.186 albertel 3987: $moreenv{'grade_target'}='answer';
3988: %moreenv=(%form,%moreenv);
1.497 raeburn 3989: $feedurl = &Apache::lonnet::clutter($feedurl);
3990: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3991: return $userview;
1.1 albertel 3992: }
1.116 albertel 3993:
3994: =pod
3995:
3996: =item * &submlink()
3997:
1.242 albertel 3998: Inputs: $text $uname $udom $symb $target
1.116 albertel 3999:
4000: Returns: A link to grades.pm such as to see the SUBM view of a student
4001:
4002: =cut
4003:
4004: ###############################################
4005: sub submlink {
1.242 albertel 4006: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4007: if (!($uname && $udom)) {
4008: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4009: &Apache::lonnet::whichuser($symb);
1.116 albertel 4010: if (!$symb) { $symb=$cursymb; }
4011: }
1.254 matthew 4012: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4013: $symb=&escape($symb);
1.960 bisitz 4014: if ($target) { $target=" target=\"$target\""; }
4015: return
4016: '<a href="/adm/grades?command=submission'.
4017: '&symb='.$symb.
4018: '&student='.$uname.
4019: '&userdom='.$udom.'"'.
4020: $target.'>'.$text.'</a>';
1.242 albertel 4021: }
4022: ##############################################
4023:
4024: =pod
4025:
4026: =item * &pgrdlink()
4027:
4028: Inputs: $text $uname $udom $symb $target
4029:
4030: Returns: A link to grades.pm such as to see the PGRD view of a student
4031:
4032: =cut
4033:
4034: ###############################################
4035: sub pgrdlink {
4036: my $link=&submlink(@_);
4037: $link=~s/(&command=submission)/$1&showgrading=yes/;
4038: return $link;
4039: }
4040: ##############################################
4041:
4042: =pod
4043:
4044: =item * &pprmlink()
4045:
4046: Inputs: $text $uname $udom $symb $target
4047:
4048: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4049: student and a specific resource
1.242 albertel 4050:
4051: =cut
4052:
4053: ###############################################
4054: sub pprmlink {
4055: my ($text,$uname,$udom,$symb,$target)=@_;
4056: if (!($uname && $udom)) {
4057: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4058: &Apache::lonnet::whichuser($symb);
1.242 albertel 4059: if (!$symb) { $symb=$cursymb; }
4060: }
1.254 matthew 4061: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4062: $symb=&escape($symb);
1.242 albertel 4063: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4064: return '<a href="/adm/parmset?command=set&'.
4065: 'symb='.$symb.'&uname='.$uname.
4066: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4067: }
4068: ##############################################
1.37 matthew 4069:
1.112 bowersj2 4070: =pod
4071:
4072: =back
4073:
4074: =cut
4075:
1.37 matthew 4076: ###############################################
1.51 www 4077:
4078:
4079: sub timehash {
1.687 raeburn 4080: my ($thistime) = @_;
4081: my $timezone = &Apache::lonlocal::gettimezone();
4082: my $dt = DateTime->from_epoch(epoch => $thistime)
4083: ->set_time_zone($timezone);
4084: my $wday = $dt->day_of_week();
4085: if ($wday == 7) { $wday = 0; }
4086: return ( 'second' => $dt->second(),
4087: 'minute' => $dt->minute(),
4088: 'hour' => $dt->hour(),
4089: 'day' => $dt->day_of_month(),
4090: 'month' => $dt->month(),
4091: 'year' => $dt->year(),
4092: 'weekday' => $wday,
4093: 'dayyear' => $dt->day_of_year(),
4094: 'dlsav' => $dt->is_dst() );
1.51 www 4095: }
4096:
1.370 www 4097: sub utc_string {
4098: my ($date)=@_;
1.371 www 4099: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4100: }
4101:
1.51 www 4102: sub maketime {
4103: my %th=@_;
1.687 raeburn 4104: my ($epoch_time,$timezone,$dt);
4105: $timezone = &Apache::lonlocal::gettimezone();
4106: eval {
4107: $dt = DateTime->new( year => $th{'year'},
4108: month => $th{'month'},
4109: day => $th{'day'},
4110: hour => $th{'hour'},
4111: minute => $th{'minute'},
4112: second => $th{'second'},
4113: time_zone => $timezone,
4114: );
4115: };
4116: if (!$@) {
4117: $epoch_time = $dt->epoch;
4118: if ($epoch_time) {
4119: return $epoch_time;
4120: }
4121: }
1.51 www 4122: return POSIX::mktime(
4123: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4124: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4125: }
4126:
4127: #########################################
1.51 www 4128:
4129: sub findallcourses {
1.482 raeburn 4130: my ($roles,$uname,$udom) = @_;
1.355 albertel 4131: my %roles;
4132: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4133: my %courses;
1.51 www 4134: my $now=time;
1.482 raeburn 4135: if (!defined($uname)) {
4136: $uname = $env{'user.name'};
4137: }
4138: if (!defined($udom)) {
4139: $udom = $env{'user.domain'};
4140: }
4141: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4142: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4143: if (!%roles) {
4144: %roles = (
4145: cc => 1,
1.907 raeburn 4146: co => 1,
1.482 raeburn 4147: in => 1,
4148: ep => 1,
4149: ta => 1,
4150: cr => 1,
4151: st => 1,
4152: );
4153: }
4154: foreach my $entry (keys(%roleshash)) {
4155: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4156: if ($trole =~ /^cr/) {
4157: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4158: } else {
4159: next if (!exists($roles{$trole}));
4160: }
4161: if ($tend) {
4162: next if ($tend < $now);
4163: }
4164: if ($tstart) {
4165: next if ($tstart > $now);
4166: }
1.1058 raeburn 4167: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4168: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4169: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4170: if ($secpart eq '') {
4171: ($cnum,$role) = split(/_/,$cnumpart);
4172: $sec = 'none';
1.1058 raeburn 4173: $value .= $cnum.'/';
1.482 raeburn 4174: } else {
4175: $cnum = $cnumpart;
4176: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4177: $value .= $cnum.'/'.$sec;
4178: }
4179: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4180: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4181: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4182: }
4183: } else {
4184: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4185: }
1.482 raeburn 4186: }
4187: } else {
4188: foreach my $key (keys(%env)) {
1.483 albertel 4189: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4190: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4191: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4192: next if ($role eq 'ca' || $role eq 'aa');
4193: next if (%roles && !exists($roles{$role}));
4194: my ($starttime,$endtime)=split(/\./,$env{$key});
4195: my $active=1;
4196: if ($starttime) {
4197: if ($now<$starttime) { $active=0; }
4198: }
4199: if ($endtime) {
4200: if ($now>$endtime) { $active=0; }
4201: }
4202: if ($active) {
1.1058 raeburn 4203: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4204: if ($sec eq '') {
4205: $sec = 'none';
1.1058 raeburn 4206: } else {
4207: $value .= $sec;
4208: }
4209: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4210: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4211: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4212: }
4213: } else {
4214: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4215: }
1.474 raeburn 4216: }
4217: }
1.51 www 4218: }
4219: }
1.474 raeburn 4220: return %courses;
1.51 www 4221: }
1.37 matthew 4222:
1.54 www 4223: ###############################################
1.474 raeburn 4224:
4225: sub blockcheck {
1.1062 raeburn 4226: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4227:
4228: if (!defined($udom)) {
4229: $udom = $env{'user.domain'};
4230: }
4231: if (!defined($uname)) {
4232: $uname = $env{'user.name'};
4233: }
4234:
4235: # If uname and udom are for a course, check for blocks in the course.
4236:
4237: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4238: my ($startblock,$endblock,$triggerblock) =
4239: &get_blocks($setters,$activity,$udom,$uname,$url);
4240: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4241: }
1.474 raeburn 4242:
1.502 raeburn 4243: my $startblock = 0;
4244: my $endblock = 0;
1.1062 raeburn 4245: my $triggerblock = '';
1.482 raeburn 4246: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4247:
1.490 raeburn 4248: # If uname is for a user, and activity is course-specific, i.e.,
4249: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4250:
1.490 raeburn 4251: if (($activity eq 'boards' || $activity eq 'chat' ||
4252: $activity eq 'groups') && ($env{'request.course.id'})) {
4253: foreach my $key (keys(%live_courses)) {
4254: if ($key ne $env{'request.course.id'}) {
4255: delete($live_courses{$key});
4256: }
4257: }
4258: }
4259:
4260: my $otheruser = 0;
4261: my %own_courses;
4262: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4263: # Resource belongs to user other than current user.
4264: $otheruser = 1;
4265: # Gather courses for current user
4266: %own_courses =
4267: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4268: }
4269:
4270: # Gather active course roles - course coordinator, instructor,
4271: # exam proctor, ta, student, or custom role.
1.474 raeburn 4272:
4273: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4274: my ($cdom,$cnum);
4275: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4276: $cdom = $env{'course.'.$course.'.domain'};
4277: $cnum = $env{'course.'.$course.'.num'};
4278: } else {
1.490 raeburn 4279: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4280: }
4281: my $no_ownblock = 0;
4282: my $no_userblock = 0;
1.533 raeburn 4283: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4284: # Check if current user has 'evb' priv for this
4285: if (defined($own_courses{$course})) {
4286: foreach my $sec (keys(%{$own_courses{$course}})) {
4287: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4288: if ($sec ne 'none') {
4289: $checkrole .= '/'.$sec;
4290: }
4291: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4292: $no_ownblock = 1;
4293: last;
4294: }
4295: }
4296: }
4297: # if they have 'evb' priv and are currently not playing student
4298: next if (($no_ownblock) &&
4299: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4300: }
1.474 raeburn 4301: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4302: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4303: if ($sec ne 'none') {
1.482 raeburn 4304: $checkrole .= '/'.$sec;
1.474 raeburn 4305: }
1.490 raeburn 4306: if ($otheruser) {
4307: # Resource belongs to user other than current user.
4308: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4309: my (%allroles,%userroles);
4310: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4311: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4312: my ($trole,$tdom,$tnum,$tsec);
4313: if ($entry =~ /^cr/) {
4314: ($trole,$tdom,$tnum,$tsec) =
4315: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4316: } else {
4317: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4318: }
4319: my ($spec,$area,$trest);
4320: $area = '/'.$tdom.'/'.$tnum;
4321: $trest = $tnum;
4322: if ($tsec ne '') {
4323: $area .= '/'.$tsec;
4324: $trest .= '/'.$tsec;
4325: }
4326: $spec = $trole.'.'.$area;
4327: if ($trole =~ /^cr/) {
4328: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4329: $tdom,$spec,$trest,$area);
4330: } else {
4331: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4332: $tdom,$spec,$trest,$area);
4333: }
4334: }
4335: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4336: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4337: if ($1) {
4338: $no_userblock = 1;
4339: last;
4340: }
1.486 raeburn 4341: }
4342: }
1.490 raeburn 4343: } else {
4344: # Resource belongs to current user
4345: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4346: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4347: $no_ownblock = 1;
4348: last;
4349: }
1.474 raeburn 4350: }
4351: }
4352: # if they have the evb priv and are currently not playing student
1.482 raeburn 4353: next if (($no_ownblock) &&
1.491 albertel 4354: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4355: next if ($no_userblock);
1.474 raeburn 4356:
1.866 kalberla 4357: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4358: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4359:
1.1062 raeburn 4360: my ($start,$end,$trigger) =
4361: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4362: if (($start != 0) &&
4363: (($startblock == 0) || ($startblock > $start))) {
4364: $startblock = $start;
1.1062 raeburn 4365: if ($trigger ne '') {
4366: $triggerblock = $trigger;
4367: }
1.502 raeburn 4368: }
4369: if (($end != 0) &&
4370: (($endblock == 0) || ($endblock < $end))) {
4371: $endblock = $end;
1.1062 raeburn 4372: if ($trigger ne '') {
4373: $triggerblock = $trigger;
4374: }
1.502 raeburn 4375: }
1.490 raeburn 4376: }
1.1062 raeburn 4377: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4378: }
4379:
4380: sub get_blocks {
1.1062 raeburn 4381: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4382: my $startblock = 0;
4383: my $endblock = 0;
1.1062 raeburn 4384: my $triggerblock = '';
1.490 raeburn 4385: my $course = $cdom.'_'.$cnum;
4386: $setters->{$course} = {};
4387: $setters->{$course}{'staff'} = [];
4388: $setters->{$course}{'times'} = [];
1.1062 raeburn 4389: $setters->{$course}{'triggers'} = [];
4390: my (@blockers,%triggered);
4391: my $now = time;
4392: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4393: if ($activity eq 'docs') {
4394: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4395: foreach my $block (@blockers) {
4396: if ($block =~ /^firstaccess____(.+)$/) {
4397: my $item = $1;
4398: my $type = 'map';
4399: my $timersymb = $item;
4400: if ($item eq 'course') {
4401: $type = 'course';
4402: } elsif ($item =~ /___\d+___/) {
4403: $type = 'resource';
4404: } else {
4405: $timersymb = &Apache::lonnet::symbread($item);
4406: }
4407: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4408: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4409: $triggered{$block} = {
4410: start => $start,
4411: end => $end,
4412: type => $type,
4413: };
4414: }
4415: }
4416: } else {
4417: foreach my $block (keys(%commblocks)) {
4418: if ($block =~ m/^(\d+)____(\d+)$/) {
4419: my ($start,$end) = ($1,$2);
4420: if ($start <= time && $end >= time) {
4421: if (ref($commblocks{$block}) eq 'HASH') {
4422: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4423: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4424: unless(grep(/^\Q$block\E$/,@blockers)) {
4425: push(@blockers,$block);
4426: }
4427: }
4428: }
4429: }
4430: }
4431: } elsif ($block =~ /^firstaccess____(.+)$/) {
4432: my $item = $1;
4433: my $timersymb = $item;
4434: my $type = 'map';
4435: if ($item eq 'course') {
4436: $type = 'course';
4437: } elsif ($item =~ /___\d+___/) {
4438: $type = 'resource';
4439: } else {
4440: $timersymb = &Apache::lonnet::symbread($item);
4441: }
4442: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4443: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4444: if ($start && $end) {
4445: if (($start <= time) && ($end >= time)) {
4446: unless (grep(/^\Q$block\E$/,@blockers)) {
4447: push(@blockers,$block);
4448: $triggered{$block} = {
4449: start => $start,
4450: end => $end,
4451: type => $type,
4452: };
4453: }
4454: }
1.490 raeburn 4455: }
1.1062 raeburn 4456: }
4457: }
4458: }
4459: foreach my $blocker (@blockers) {
4460: my ($staff_name,$staff_dom,$title,$blocks) =
4461: &parse_block_record($commblocks{$blocker});
4462: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4463: my ($start,$end,$triggertype);
4464: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4465: ($start,$end) = ($1,$2);
4466: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4467: $start = $triggered{$blocker}{'start'};
4468: $end = $triggered{$blocker}{'end'};
4469: $triggertype = $triggered{$blocker}{'type'};
4470: }
4471: if ($start) {
4472: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4473: if ($triggertype) {
4474: push(@{$$setters{$course}{'triggers'}},$triggertype);
4475: } else {
4476: push(@{$$setters{$course}{'triggers'}},0);
4477: }
4478: if ( ($startblock == 0) || ($startblock > $start) ) {
4479: $startblock = $start;
4480: if ($triggertype) {
4481: $triggerblock = $blocker;
1.474 raeburn 4482: }
4483: }
1.1062 raeburn 4484: if ( ($endblock == 0) || ($endblock < $end) ) {
4485: $endblock = $end;
4486: if ($triggertype) {
4487: $triggerblock = $blocker;
4488: }
4489: }
1.474 raeburn 4490: }
4491: }
1.1062 raeburn 4492: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4493: }
4494:
4495: sub parse_block_record {
4496: my ($record) = @_;
4497: my ($setuname,$setudom,$title,$blocks);
4498: if (ref($record) eq 'HASH') {
4499: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4500: $title = &unescape($record->{'event'});
4501: $blocks = $record->{'blocks'};
4502: } else {
4503: my @data = split(/:/,$record,3);
4504: if (scalar(@data) eq 2) {
4505: $title = $data[1];
4506: ($setuname,$setudom) = split(/@/,$data[0]);
4507: } else {
4508: ($setuname,$setudom,$title) = @data;
4509: }
4510: $blocks = { 'com' => 'on' };
4511: }
4512: return ($setuname,$setudom,$title,$blocks);
4513: }
4514:
1.854 kalberla 4515: sub blocking_status {
1.1062 raeburn 4516: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4517: my %setters;
1.890 droeschl 4518:
1.1061 raeburn 4519: # check for active blocking
1.1062 raeburn 4520: my ($startblock,$endblock,$triggerblock) =
4521: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4522: my $blocked = 0;
4523: if ($startblock && $endblock) {
4524: $blocked = 1;
4525: }
1.890 droeschl 4526:
1.1061 raeburn 4527: # caller just wants to know whether a block is active
4528: if (!wantarray) { return $blocked; }
4529:
4530: # build a link to a popup window containing the details
4531: my $querystring = "?activity=$activity";
4532: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4533: if ($activity eq 'port') {
4534: $querystring .= "&udom=$udom" if $udom;
4535: $querystring .= "&uname=$uname" if $uname;
4536: } elsif ($activity eq 'docs') {
4537: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4538: }
1.1061 raeburn 4539:
4540: my $output .= <<'END_MYBLOCK';
4541: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4542: var options = "width=" + w + ",height=" + h + ",";
4543: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4544: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4545: var newWin = window.open(url, wdwName, options);
4546: newWin.focus();
4547: }
1.890 droeschl 4548: END_MYBLOCK
1.854 kalberla 4549:
1.1061 raeburn 4550: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4551:
1.1061 raeburn 4552: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4553: my $text = &mt('Communication Blocked');
4554: if ($activity eq 'docs') {
4555: $text = &mt('Content Access Blocked');
1.1063 raeburn 4556: } elsif ($activity eq 'printout') {
4557: $text = &mt('Printing Blocked');
1.1062 raeburn 4558: }
1.1061 raeburn 4559: $output .= <<"END_BLOCK";
1.867 kalberla 4560: <div class='LC_comblock'>
1.869 kalberla 4561: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4562: title='$text'>
4563: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4564: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4565: title='$text'>$text</a>
1.867 kalberla 4566: </div>
4567:
4568: END_BLOCK
1.474 raeburn 4569:
1.1061 raeburn 4570: return ($blocked, $output);
1.854 kalberla 4571: }
1.490 raeburn 4572:
1.60 matthew 4573: ###############################################
4574:
1.682 raeburn 4575: sub check_ip_acc {
4576: my ($acc)=@_;
4577: &Apache::lonxml::debug("acc is $acc");
4578: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4579: return 1;
4580: }
4581: my $allowed=0;
4582: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4583:
4584: my $name;
4585: foreach my $pattern (split(',',$acc)) {
4586: $pattern =~ s/^\s*//;
4587: $pattern =~ s/\s*$//;
4588: if ($pattern =~ /\*$/) {
4589: #35.8.*
4590: $pattern=~s/\*//;
4591: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4592: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4593: #35.8.3.[34-56]
4594: my $low=$2;
4595: my $high=$3;
4596: $pattern=$1;
4597: if ($ip =~ /^\Q$pattern\E/) {
4598: my $last=(split(/\./,$ip))[3];
4599: if ($last <=$high && $last >=$low) { $allowed=1; }
4600: }
4601: } elsif ($pattern =~ /^\*/) {
4602: #*.msu.edu
4603: $pattern=~s/\*//;
4604: if (!defined($name)) {
4605: use Socket;
4606: my $netaddr=inet_aton($ip);
4607: ($name)=gethostbyaddr($netaddr,AF_INET);
4608: }
4609: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4610: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4611: #127.0.0.1
4612: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4613: } else {
4614: #some.name.com
4615: if (!defined($name)) {
4616: use Socket;
4617: my $netaddr=inet_aton($ip);
4618: ($name)=gethostbyaddr($netaddr,AF_INET);
4619: }
4620: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4621: }
4622: if ($allowed) { last; }
4623: }
4624: return $allowed;
4625: }
4626:
4627: ###############################################
4628:
1.60 matthew 4629: =pod
4630:
1.112 bowersj2 4631: =head1 Domain Template Functions
4632:
4633: =over 4
4634:
4635: =item * &determinedomain()
1.60 matthew 4636:
4637: Inputs: $domain (usually will be undef)
4638:
1.63 www 4639: Returns: Determines which domain should be used for designs
1.60 matthew 4640:
4641: =cut
1.54 www 4642:
1.60 matthew 4643: ###############################################
1.63 www 4644: sub determinedomain {
4645: my $domain=shift;
1.531 albertel 4646: if (! $domain) {
1.60 matthew 4647: # Determine domain if we have not been given one
1.893 raeburn 4648: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4649: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4650: if ($env{'request.role.domain'}) {
4651: $domain=$env{'request.role.domain'};
1.60 matthew 4652: }
4653: }
1.63 www 4654: return $domain;
4655: }
4656: ###############################################
1.517 raeburn 4657:
1.518 albertel 4658: sub devalidate_domconfig_cache {
4659: my ($udom)=@_;
4660: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4661: }
4662:
4663: # ---------------------- Get domain configuration for a domain
4664: sub get_domainconf {
4665: my ($udom) = @_;
4666: my $cachetime=1800;
4667: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4668: if (defined($cached)) { return %{$result}; }
4669:
4670: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4671: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4672: my (%designhash,%legacy);
1.518 albertel 4673: if (keys(%domconfig) > 0) {
4674: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4675: if (keys(%{$domconfig{'login'}})) {
4676: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4677: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4678: if ($key eq 'loginvia') {
4679: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4680: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4681: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4682: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4683: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4684: $designhash{$udom.'.login.loginvia'} = $server;
4685: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4686:
4687: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4688: } else {
1.1013 raeburn 4689: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4690: }
4691: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4692: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4693: }
1.946 raeburn 4694: }
4695: }
4696: }
4697: }
4698: } else {
4699: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4700: $designhash{$udom.'.login.'.$key.'_'.$img} =
4701: $domconfig{'login'}{$key}{$img};
4702: }
1.699 raeburn 4703: }
4704: } else {
4705: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4706: }
1.632 raeburn 4707: }
4708: } else {
4709: $legacy{'login'} = 1;
1.518 albertel 4710: }
1.632 raeburn 4711: } else {
4712: $legacy{'login'} = 1;
1.518 albertel 4713: }
4714: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4715: if (keys(%{$domconfig{'rolecolors'}})) {
4716: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4717: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4718: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4719: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4720: }
1.518 albertel 4721: }
4722: }
1.632 raeburn 4723: } else {
4724: $legacy{'rolecolors'} = 1;
1.518 albertel 4725: }
1.632 raeburn 4726: } else {
4727: $legacy{'rolecolors'} = 1;
1.518 albertel 4728: }
1.948 raeburn 4729: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4730: if ($domconfig{'autoenroll'}{'co-owners'}) {
4731: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4732: }
4733: }
1.632 raeburn 4734: if (keys(%legacy) > 0) {
4735: my %legacyhash = &get_legacy_domconf($udom);
4736: foreach my $item (keys(%legacyhash)) {
4737: if ($item =~ /^\Q$udom\E\.login/) {
4738: if ($legacy{'login'}) {
4739: $designhash{$item} = $legacyhash{$item};
4740: }
4741: } else {
4742: if ($legacy{'rolecolors'}) {
4743: $designhash{$item} = $legacyhash{$item};
4744: }
1.518 albertel 4745: }
4746: }
4747: }
1.632 raeburn 4748: } else {
4749: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4750: }
4751: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4752: $cachetime);
4753: return %designhash;
4754: }
4755:
1.632 raeburn 4756: sub get_legacy_domconf {
4757: my ($udom) = @_;
4758: my %legacyhash;
4759: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4760: my $designfile = $designdir.'/'.$udom.'.tab';
4761: if (-e $designfile) {
4762: if ( open (my $fh,"<$designfile") ) {
4763: while (my $line = <$fh>) {
4764: next if ($line =~ /^\#/);
4765: chomp($line);
4766: my ($key,$val)=(split(/\=/,$line));
4767: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4768: }
4769: close($fh);
4770: }
4771: }
1.1026 raeburn 4772: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4773: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4774: }
4775: return %legacyhash;
4776: }
4777:
1.63 www 4778: =pod
4779:
1.112 bowersj2 4780: =item * &domainlogo()
1.63 www 4781:
4782: Inputs: $domain (usually will be undef)
4783:
4784: Returns: A link to a domain logo, if the domain logo exists.
4785: If the domain logo does not exist, a description of the domain.
4786:
4787: =cut
1.112 bowersj2 4788:
1.63 www 4789: ###############################################
4790: sub domainlogo {
1.517 raeburn 4791: my $domain = &determinedomain(shift);
1.518 albertel 4792: my %designhash = &get_domainconf($domain);
1.517 raeburn 4793: # See if there is a logo
4794: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4795: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4796: if ($imgsrc =~ m{^/(adm|res)/}) {
4797: if ($imgsrc =~ m{^/res/}) {
4798: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4799: &Apache::lonnet::repcopy($local_name);
4800: }
4801: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4802: }
4803: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4804: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4805: return &Apache::lonnet::domain($domain,'description');
1.59 www 4806: } else {
1.60 matthew 4807: return '';
1.59 www 4808: }
4809: }
1.63 www 4810: ##############################################
4811:
4812: =pod
4813:
1.112 bowersj2 4814: =item * &designparm()
1.63 www 4815:
4816: Inputs: $which parameter; $domain (usually will be undef)
4817:
4818: Returns: value of designparamter $which
4819:
4820: =cut
1.112 bowersj2 4821:
1.397 albertel 4822:
1.400 albertel 4823: ##############################################
1.397 albertel 4824: sub designparm {
4825: my ($which,$domain)=@_;
4826: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4827: return $env{'environment.color.'.$which};
1.96 www 4828: }
1.63 www 4829: $domain=&determinedomain($domain);
1.1016 raeburn 4830: my %domdesign;
4831: unless ($domain eq 'public') {
4832: %domdesign = &get_domainconf($domain);
4833: }
1.520 raeburn 4834: my $output;
1.517 raeburn 4835: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4836: $output = $domdesign{$domain.'.'.$which};
1.63 www 4837: } else {
1.520 raeburn 4838: $output = $defaultdesign{$which};
4839: }
4840: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4841: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4842: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4843: if ($output =~ m{^/res/}) {
4844: my $local_name = &Apache::lonnet::filelocation('',$output);
4845: &Apache::lonnet::repcopy($local_name);
4846: }
1.520 raeburn 4847: $output = &lonhttpdurl($output);
4848: }
1.63 www 4849: }
1.520 raeburn 4850: return $output;
1.63 www 4851: }
1.59 www 4852:
1.822 bisitz 4853: ##############################################
4854: =pod
4855:
1.832 bisitz 4856: =item * &authorspace()
4857:
1.1028 raeburn 4858: Inputs: $url (usually will be undef).
1.832 bisitz 4859:
1.1075.2.40 raeburn 4860: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4861: directory being viewed (or for which action is being taken).
4862: If $url is provided, and begins /priv/<domain>/<uname>
4863: the path will be that portion of the $context argument.
4864: Otherwise the path will be for the author space of the current
4865: user when the current role is author, or for that of the
4866: co-author/assistant co-author space when the current role
4867: is co-author or assistant co-author.
1.832 bisitz 4868:
4869: =cut
4870:
4871: sub authorspace {
1.1028 raeburn 4872: my ($url) = @_;
4873: if ($url ne '') {
4874: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4875: return $1;
4876: }
4877: }
1.832 bisitz 4878: my $caname = '';
1.1024 www 4879: my $cadom = '';
1.1028 raeburn 4880: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4881: ($cadom,$caname) =
1.832 bisitz 4882: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4883: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4884: $caname = $env{'user.name'};
1.1024 www 4885: $cadom = $env{'user.domain'};
1.832 bisitz 4886: }
1.1028 raeburn 4887: if (($caname ne '') && ($cadom ne '')) {
4888: return "/priv/$cadom/$caname/";
4889: }
4890: return;
1.832 bisitz 4891: }
4892:
4893: ##############################################
4894: =pod
4895:
1.822 bisitz 4896: =item * &head_subbox()
4897:
4898: Inputs: $content (contains HTML code with page functions, etc.)
4899:
4900: Returns: HTML div with $content
4901: To be included in page header
4902:
4903: =cut
4904:
4905: sub head_subbox {
4906: my ($content)=@_;
4907: my $output =
1.993 raeburn 4908: '<div class="LC_head_subbox">'
1.822 bisitz 4909: .$content
4910: .'</div>'
4911: }
4912:
4913: ##############################################
4914: =pod
4915:
4916: =item * &CSTR_pageheader()
4917:
1.1026 raeburn 4918: Input: (optional) filename from which breadcrumb trail is built.
4919: In most cases no input as needed, as $env{'request.filename'}
4920: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4921:
4922: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4923: To be included on Authoring Space pages
1.822 bisitz 4924:
4925: =cut
4926:
4927: sub CSTR_pageheader {
1.1026 raeburn 4928: my ($trailfile) = @_;
4929: if ($trailfile eq '') {
4930: $trailfile = $env{'request.filename'};
4931: }
4932:
4933: # this is for resources; directories have customtitle, and crumbs
4934: # and select recent are created in lonpubdir.pm
4935:
4936: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4937: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4938: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4939: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4940: $formaction =~ s{/+}{/}g;
1.822 bisitz 4941:
4942: my $parentpath = '';
4943: my $lastitem = '';
4944: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4945: $parentpath = $1;
4946: $lastitem = $2;
4947: } else {
4948: $lastitem = $thisdisfn;
4949: }
1.921 bisitz 4950:
4951: my $output =
1.822 bisitz 4952: '<div>'
4953: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4954: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4955: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4956: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4957: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4958:
4959: if ($lastitem) {
4960: $output .=
4961: '<span class="LC_filename">'
4962: .$lastitem
4963: .'</span>';
4964: }
4965: $output .=
4966: '<br />'
1.822 bisitz 4967: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4968: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4969: .'</form>'
4970: .&Apache::lonmenu::constspaceform()
4971: .'</div>';
1.921 bisitz 4972:
4973: return $output;
1.822 bisitz 4974: }
4975:
1.60 matthew 4976: ###############################################
4977: ###############################################
4978:
4979: =pod
4980:
1.112 bowersj2 4981: =back
4982:
1.549 albertel 4983: =head1 HTML Helpers
1.112 bowersj2 4984:
4985: =over 4
4986:
4987: =item * &bodytag()
1.60 matthew 4988:
4989: Returns a uniform header for LON-CAPA web pages.
4990:
4991: Inputs:
4992:
1.112 bowersj2 4993: =over 4
4994:
4995: =item * $title, A title to be displayed on the page.
4996:
4997: =item * $function, the current role (can be undef).
4998:
4999: =item * $addentries, extra parameters for the <body> tag.
5000:
5001: =item * $bodyonly, if defined, only return the <body> tag.
5002:
5003: =item * $domain, if defined, force a given domain.
5004:
5005: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5006: text interface only)
1.60 matthew 5007:
1.814 bisitz 5008: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5009: navigational links
1.317 albertel 5010:
1.338 albertel 5011: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5012:
1.1075.2.12 raeburn 5013: =item * $no_inline_link, if true and in remote mode, don't show the
5014: 'Switch To Inline Menu' link
5015:
1.460 albertel 5016: =item * $args, optional argument valid values are
5017: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5018: inherit_jsmath -> when creating popup window in a page,
5019: should it have jsmath forced on by the
5020: current page
1.460 albertel 5021:
1.1075.2.15 raeburn 5022: =item * $advtoolsref, optional argument, ref to an array containing
5023: inlineremote items to be added in "Functions" menu below
5024: breadcrumbs.
5025:
1.112 bowersj2 5026: =back
5027:
1.60 matthew 5028: Returns: A uniform header for LON-CAPA web pages.
5029: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5030: If $bodyonly is undef or zero, an html string containing a <body> tag and
5031: other decorations will be returned.
5032:
5033: =cut
5034:
1.54 www 5035: sub bodytag {
1.831 bisitz 5036: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5037: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5038:
1.954 raeburn 5039: my $public;
5040: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5041: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5042: $public = 1;
5043: }
1.460 albertel 5044: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5045: my $httphost = $args->{'use_absolute'};
1.339 albertel 5046:
1.183 matthew 5047: $function = &get_users_function() if (!$function);
1.339 albertel 5048: my $img = &designparm($function.'.img',$domain);
5049: my $font = &designparm($function.'.font',$domain);
5050: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5051:
1.803 bisitz 5052: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5053: 'bgcolor' => $pgbg,
1.339 albertel 5054: 'text' => $font,
5055: 'alink' => &designparm($function.'.alink',$domain),
5056: 'vlink' => &designparm($function.'.vlink',$domain),
5057: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5058: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5059:
1.63 www 5060: # role and realm
1.378 raeburn 5061: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5062: if ($role eq 'ca') {
1.479 albertel 5063: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5064: $realm = &plainname($rname,$rdom);
1.378 raeburn 5065: }
1.55 www 5066: # realm
1.258 albertel 5067: if ($env{'request.course.id'}) {
1.378 raeburn 5068: if ($env{'request.role'} !~ /^cr/) {
5069: $role = &Apache::lonnet::plaintext($role,&course_type());
5070: }
1.898 raeburn 5071: if ($env{'request.course.sec'}) {
5072: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5073: }
1.359 albertel 5074: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5075: } else {
5076: $role = &Apache::lonnet::plaintext($role);
1.54 www 5077: }
1.433 albertel 5078:
1.359 albertel 5079: if (!$realm) { $realm=' '; }
1.330 albertel 5080:
1.438 albertel 5081: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5082:
1.101 www 5083: # construct main body tag
1.359 albertel 5084: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5085: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5086:
1.1075.2.38 raeburn 5087: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5088:
5089: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5090: return $bodytag;
1.1075.2.38 raeburn 5091: }
1.359 albertel 5092:
1.954 raeburn 5093: if ($public) {
1.433 albertel 5094: undef($role);
5095: }
1.359 albertel 5096:
1.762 bisitz 5097: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5098: #
5099: # Extra info if you are the DC
5100: my $dc_info = '';
5101: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5102: $env{'course.'.$env{'request.course.id'}.
5103: '.domain'}.'/'})) {
5104: my $cid = $env{'request.course.id'};
1.917 raeburn 5105: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5106: $dc_info =~ s/\s+$//;
1.359 albertel 5107: }
5108:
1.898 raeburn 5109: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5110:
1.1075.2.13 raeburn 5111: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5112:
1.1075.2.38 raeburn 5113:
5114:
1.1075.2.21 raeburn 5115: my $funclist;
5116: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5117: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5118: Apache::lonmenu::serverform();
5119: my $forbodytag;
5120: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5121: $forcereg,$args->{'group'},
5122: $args->{'bread_crumbs'},
5123: $advtoolsref,'',\$forbodytag);
5124: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5125: $funclist = $forbodytag;
5126: }
5127: } else {
1.903 droeschl 5128:
5129: # if ($env{'request.state'} eq 'construct') {
5130: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5131: # }
5132:
1.1075.2.38 raeburn 5133: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5134: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5135:
1.1075.2.38 raeburn 5136: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5137:
1.916 droeschl 5138: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5139: if ($dc_info) {
5140: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5141: }
1.1075.2.38 raeburn 5142: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5143: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5144: return $bodytag;
5145: }
1.894 droeschl 5146:
1.927 raeburn 5147: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5148: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5149: }
1.916 droeschl 5150:
1.1075.2.38 raeburn 5151: $bodytag .= $right;
1.852 droeschl 5152:
1.917 raeburn 5153: if ($dc_info) {
5154: $dc_info = &dc_courseid_toggle($dc_info);
5155: }
5156: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5157:
1.903 droeschl 5158: #don't show menus for public users
1.954 raeburn 5159: if (!$public){
1.1075.2.52 raeburn 5160: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5161: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5162: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5163: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5164: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5165: $args->{'bread_crumbs'});
5166: } elsif ($forcereg) {
1.1075.2.22 raeburn 5167: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5168: $args->{'group'});
1.1075.2.15 raeburn 5169: } else {
1.1075.2.21 raeburn 5170: my $forbodytag;
5171: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5172: $forcereg,$args->{'group'},
5173: $args->{'bread_crumbs'},
5174: $advtoolsref,'',\$forbodytag);
5175: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5176: $bodytag .= $forbodytag;
5177: }
1.920 raeburn 5178: }
1.903 droeschl 5179: }else{
5180: # this is to seperate menu from content when there's no secondary
5181: # menu. Especially needed for public accessible ressources.
5182: $bodytag .= '<hr style="clear:both" />';
5183: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5184: }
1.903 droeschl 5185:
1.235 raeburn 5186: return $bodytag;
1.1075.2.12 raeburn 5187: }
5188:
5189: #
5190: # Top frame rendering, Remote is up
5191: #
5192:
5193: my $imgsrc = $img;
5194: if ($img =~ /^\/adm/) {
5195: $imgsrc = &lonhttpdurl($img);
5196: }
5197: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5198:
5199: # Explicit link to get inline menu
5200: my $menu= ($no_inline_link?''
5201: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5202:
5203: if ($dc_info) {
5204: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5205: }
5206:
1.1075.2.38 raeburn 5207: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5208: unless ($public) {
5209: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5210: undef,'LC_menubuttons_link');
5211: }
5212:
1.1075.2.12 raeburn 5213: unless ($env{'form.inhibitmenu'}) {
5214: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5215: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.12 raeburn 5216: <li>$menu</li>
5217: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5218: }
1.1075.2.13 raeburn 5219: if ($env{'request.state'} eq 'construct') {
5220: if (!$public){
5221: if ($env{'request.state'} eq 'construct') {
5222: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5223: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5224: &Apache::lonhtmlcommon::scripttag('','end').
5225: &Apache::lonmenu::innerregister($forcereg,
5226: $args->{'bread_crumbs'});
5227: }
5228: }
5229: }
1.1075.2.21 raeburn 5230: return $bodytag."\n".$funclist;
1.182 matthew 5231: }
5232:
1.917 raeburn 5233: sub dc_courseid_toggle {
5234: my ($dc_info) = @_;
1.980 raeburn 5235: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5236: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5237: &mt('(More ...)').'</a></span>'.
5238: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5239: }
5240:
1.330 albertel 5241: sub make_attr_string {
5242: my ($register,$attr_ref) = @_;
5243:
5244: if ($attr_ref && !ref($attr_ref)) {
5245: die("addentries Must be a hash ref ".
5246: join(':',caller(1))." ".
5247: join(':',caller(0))." ");
5248: }
5249:
5250: if ($register) {
1.339 albertel 5251: my ($on_load,$on_unload);
5252: foreach my $key (keys(%{$attr_ref})) {
5253: if (lc($key) eq 'onload') {
5254: $on_load.=$attr_ref->{$key}.';';
5255: delete($attr_ref->{$key});
5256:
5257: } elsif (lc($key) eq 'onunload') {
5258: $on_unload.=$attr_ref->{$key}.';';
5259: delete($attr_ref->{$key});
5260: }
5261: }
1.1075.2.12 raeburn 5262: if ($env{'environment.remote'} eq 'on') {
5263: $attr_ref->{'onload'} =
5264: &Apache::lonmenu::loadevents(). $on_load;
5265: $attr_ref->{'onunload'}=
5266: &Apache::lonmenu::unloadevents().$on_unload;
5267: } else {
5268: $attr_ref->{'onload'} = $on_load;
5269: $attr_ref->{'onunload'}= $on_unload;
5270: }
1.330 albertel 5271: }
1.339 albertel 5272:
1.330 albertel 5273: my $attr_string;
1.1075.2.56 raeburn 5274: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5275: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5276: }
5277: return $attr_string;
5278: }
5279:
5280:
1.182 matthew 5281: ###############################################
1.251 albertel 5282: ###############################################
5283:
5284: =pod
5285:
5286: =item * &endbodytag()
5287:
5288: Returns a uniform footer for LON-CAPA web pages.
5289:
1.635 raeburn 5290: Inputs: 1 - optional reference to an args hash
5291: If in the hash, key for noredirectlink has a value which evaluates to true,
5292: a 'Continue' link is not displayed if the page contains an
5293: internal redirect in the <head></head> section,
5294: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5295:
5296: =cut
5297:
5298: sub endbodytag {
1.635 raeburn 5299: my ($args) = @_;
1.1075.2.6 raeburn 5300: my $endbodytag;
5301: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5302: $endbodytag='</body>';
5303: }
1.269 albertel 5304: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5305: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5306: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5307: $endbodytag=
5308: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5309: &mt('Continue').'</a>'.
5310: $endbodytag;
5311: }
1.315 albertel 5312: }
1.251 albertel 5313: return $endbodytag;
5314: }
5315:
1.352 albertel 5316: =pod
5317:
5318: =item * &standard_css()
5319:
5320: Returns a style sheet
5321:
5322: Inputs: (all optional)
5323: domain -> force to color decorate a page for a specific
5324: domain
5325: function -> force usage of a specific rolish color scheme
5326: bgcolor -> override the default page bgcolor
5327:
5328: =cut
5329:
1.343 albertel 5330: sub standard_css {
1.345 albertel 5331: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5332: $function = &get_users_function() if (!$function);
5333: my $img = &designparm($function.'.img', $domain);
5334: my $tabbg = &designparm($function.'.tabbg', $domain);
5335: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5336: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5337: #second colour for later usage
1.345 albertel 5338: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5339: my $pgbg_or_bgcolor =
5340: $bgcolor ||
1.352 albertel 5341: &designparm($function.'.pgbg', $domain);
1.382 albertel 5342: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5343: my $alink = &designparm($function.'.alink', $domain);
5344: my $vlink = &designparm($function.'.vlink', $domain);
5345: my $link = &designparm($function.'.link', $domain);
5346:
1.602 albertel 5347: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5348: my $mono = 'monospace';
1.850 bisitz 5349: my $data_table_head = $sidebg;
5350: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5351: my $data_table_dark = '#E0E0E0';
1.470 banghart 5352: my $data_table_darker = '#CCCCCC';
1.349 albertel 5353: my $data_table_highlight = '#FFFF00';
1.352 albertel 5354: my $mail_new = '#FFBB77';
5355: my $mail_new_hover = '#DD9955';
5356: my $mail_read = '#BBBB77';
5357: my $mail_read_hover = '#999944';
5358: my $mail_replied = '#AAAA88';
5359: my $mail_replied_hover = '#888855';
5360: my $mail_other = '#99BBBB';
5361: my $mail_other_hover = '#669999';
1.391 albertel 5362: my $table_header = '#DDDDDD';
1.489 raeburn 5363: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5364: my $lg_border_color = '#C8C8C8';
1.952 onken 5365: my $button_hover = '#BF2317';
1.392 albertel 5366:
1.608 albertel 5367: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5368: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5369: : '0 3px 0 4px';
1.448 albertel 5370:
1.523 albertel 5371:
1.343 albertel 5372: return <<END;
1.947 droeschl 5373:
5374: /* needed for iframe to allow 100% height in FF */
5375: body, html {
5376: margin: 0;
5377: padding: 0 0.5%;
5378: height: 99%; /* to avoid scrollbars */
5379: }
5380:
1.795 www 5381: body {
1.911 bisitz 5382: font-family: $sans;
5383: line-height:130%;
5384: font-size:0.83em;
5385: color:$font;
1.795 www 5386: }
5387:
1.959 onken 5388: a:focus,
5389: a:focus img {
1.795 www 5390: color: red;
5391: }
1.698 harmsja 5392:
1.911 bisitz 5393: form, .inline {
5394: display: inline;
1.795 www 5395: }
1.721 harmsja 5396:
1.795 www 5397: .LC_right {
1.911 bisitz 5398: text-align:right;
1.795 www 5399: }
5400:
5401: .LC_middle {
1.911 bisitz 5402: vertical-align:middle;
1.795 www 5403: }
1.721 harmsja 5404:
1.1075.2.38 raeburn 5405: .LC_floatleft {
5406: float: left;
5407: }
5408:
5409: .LC_floatright {
5410: float: right;
5411: }
5412:
1.911 bisitz 5413: .LC_400Box {
5414: width:400px;
5415: }
1.721 harmsja 5416:
1.947 droeschl 5417: .LC_iframecontainer {
5418: width: 98%;
5419: margin: 0;
5420: position: fixed;
5421: top: 8.5em;
5422: bottom: 0;
5423: }
5424:
5425: .LC_iframecontainer iframe{
5426: border: none;
5427: width: 100%;
5428: height: 100%;
5429: }
5430:
1.778 bisitz 5431: .LC_filename {
5432: font-family: $mono;
5433: white-space:pre;
1.921 bisitz 5434: font-size: 120%;
1.778 bisitz 5435: }
5436:
5437: .LC_fileicon {
5438: border: none;
5439: height: 1.3em;
5440: vertical-align: text-bottom;
5441: margin-right: 0.3em;
5442: text-decoration:none;
5443: }
5444:
1.1008 www 5445: .LC_setting {
5446: text-decoration:underline;
5447: }
5448:
1.350 albertel 5449: .LC_error {
5450: color: red;
5451: }
1.795 www 5452:
1.1075.2.15 raeburn 5453: .LC_warning {
5454: color: darkorange;
5455: }
5456:
1.457 albertel 5457: .LC_diff_removed {
1.733 bisitz 5458: color: red;
1.394 albertel 5459: }
1.532 albertel 5460:
5461: .LC_info,
1.457 albertel 5462: .LC_success,
5463: .LC_diff_added {
1.350 albertel 5464: color: green;
5465: }
1.795 www 5466:
1.802 bisitz 5467: div.LC_confirm_box {
5468: background-color: #FAFAFA;
5469: border: 1px solid $lg_border_color;
5470: margin-right: 0;
5471: padding: 5px;
5472: }
5473:
5474: div.LC_confirm_box .LC_error img,
5475: div.LC_confirm_box .LC_success img {
5476: vertical-align: middle;
5477: }
5478:
1.440 albertel 5479: .LC_icon {
1.771 droeschl 5480: border: none;
1.790 droeschl 5481: vertical-align: middle;
1.771 droeschl 5482: }
5483:
1.543 albertel 5484: .LC_docs_spacer {
5485: width: 25px;
5486: height: 1px;
1.771 droeschl 5487: border: none;
1.543 albertel 5488: }
1.346 albertel 5489:
1.532 albertel 5490: .LC_internal_info {
1.735 bisitz 5491: color: #999999;
1.532 albertel 5492: }
5493:
1.794 www 5494: .LC_discussion {
1.1050 www 5495: background: $data_table_dark;
1.911 bisitz 5496: border: 1px solid black;
5497: margin: 2px;
1.794 www 5498: }
5499:
5500: .LC_disc_action_left {
1.1050 www 5501: background: $sidebg;
1.911 bisitz 5502: text-align: left;
1.1050 www 5503: padding: 4px;
5504: margin: 2px;
1.794 www 5505: }
5506:
5507: .LC_disc_action_right {
1.1050 www 5508: background: $sidebg;
1.911 bisitz 5509: text-align: right;
1.1050 www 5510: padding: 4px;
5511: margin: 2px;
1.794 www 5512: }
5513:
5514: .LC_disc_new_item {
1.911 bisitz 5515: background: white;
5516: border: 2px solid red;
1.1050 www 5517: margin: 4px;
5518: padding: 4px;
1.794 www 5519: }
5520:
5521: .LC_disc_old_item {
1.911 bisitz 5522: background: white;
1.1050 www 5523: margin: 4px;
5524: padding: 4px;
1.794 www 5525: }
5526:
1.458 albertel 5527: table.LC_pastsubmission {
5528: border: 1px solid black;
5529: margin: 2px;
5530: }
5531:
1.924 bisitz 5532: table#LC_menubuttons {
1.345 albertel 5533: width: 100%;
5534: background: $pgbg;
1.392 albertel 5535: border: 2px;
1.402 albertel 5536: border-collapse: separate;
1.803 bisitz 5537: padding: 0;
1.345 albertel 5538: }
1.392 albertel 5539:
1.801 tempelho 5540: table#LC_title_bar a {
5541: color: $fontmenu;
5542: }
1.836 bisitz 5543:
1.807 droeschl 5544: table#LC_title_bar {
1.819 tempelho 5545: clear: both;
1.836 bisitz 5546: display: none;
1.807 droeschl 5547: }
5548:
1.795 www 5549: table#LC_title_bar,
1.933 droeschl 5550: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5551: table#LC_title_bar.LC_with_remote {
1.359 albertel 5552: width: 100%;
1.392 albertel 5553: border-color: $pgbg;
5554: border-style: solid;
5555: border-width: $border;
1.379 albertel 5556: background: $pgbg;
1.801 tempelho 5557: color: $fontmenu;
1.392 albertel 5558: border-collapse: collapse;
1.803 bisitz 5559: padding: 0;
1.819 tempelho 5560: margin: 0;
1.359 albertel 5561: }
1.795 www 5562:
1.933 droeschl 5563: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5564: margin: 0;
5565: padding: 0;
1.933 droeschl 5566: position: relative;
5567: list-style: none;
1.913 droeschl 5568: }
1.933 droeschl 5569: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5570: display: inline;
5571: }
1.933 droeschl 5572:
5573: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5574: padding: 0;
1.933 droeschl 5575: margin: 0;
5576: float: left;
1.913 droeschl 5577: }
1.933 droeschl 5578: .LC_breadcrumb_tools_tools {
5579: padding: 0;
5580: margin: 0;
1.913 droeschl 5581: float: right;
5582: }
5583:
1.359 albertel 5584: table#LC_title_bar td {
5585: background: $tabbg;
5586: }
1.795 www 5587:
1.911 bisitz 5588: table#LC_menubuttons img {
1.803 bisitz 5589: border: none;
1.346 albertel 5590: }
1.795 www 5591:
1.842 droeschl 5592: .LC_breadcrumbs_component {
1.911 bisitz 5593: float: right;
5594: margin: 0 1em;
1.357 albertel 5595: }
1.842 droeschl 5596: .LC_breadcrumbs_component img {
1.911 bisitz 5597: vertical-align: middle;
1.777 tempelho 5598: }
1.795 www 5599:
1.383 albertel 5600: td.LC_table_cell_checkbox {
5601: text-align: center;
5602: }
1.795 www 5603:
5604: .LC_fontsize_small {
1.911 bisitz 5605: font-size: 70%;
1.705 tempelho 5606: }
5607:
1.844 bisitz 5608: #LC_breadcrumbs {
1.911 bisitz 5609: clear:both;
5610: background: $sidebg;
5611: border-bottom: 1px solid $lg_border_color;
5612: line-height: 2.5em;
1.933 droeschl 5613: overflow: hidden;
1.911 bisitz 5614: margin: 0;
5615: padding: 0;
1.995 raeburn 5616: text-align: left;
1.819 tempelho 5617: }
1.862 bisitz 5618:
1.1075.2.16 raeburn 5619: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5620: clear:both;
5621: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5622: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5623: margin: 0 0 10px 0;
1.966 bisitz 5624: padding: 3px;
1.995 raeburn 5625: text-align: left;
1.822 bisitz 5626: }
5627:
1.795 www 5628: .LC_fontsize_medium {
1.911 bisitz 5629: font-size: 85%;
1.705 tempelho 5630: }
5631:
1.795 www 5632: .LC_fontsize_large {
1.911 bisitz 5633: font-size: 120%;
1.705 tempelho 5634: }
5635:
1.346 albertel 5636: .LC_menubuttons_inline_text {
5637: color: $font;
1.698 harmsja 5638: font-size: 90%;
1.701 harmsja 5639: padding-left:3px;
1.346 albertel 5640: }
5641:
1.934 droeschl 5642: .LC_menubuttons_inline_text img{
5643: vertical-align: middle;
5644: }
5645:
1.1051 www 5646: li.LC_menubuttons_inline_text img {
1.951 onken 5647: cursor:pointer;
1.1002 droeschl 5648: text-decoration: none;
1.951 onken 5649: }
5650:
1.526 www 5651: .LC_menubuttons_link {
5652: text-decoration: none;
5653: }
1.795 www 5654:
1.522 albertel 5655: .LC_menubuttons_category {
1.521 www 5656: color: $font;
1.526 www 5657: background: $pgbg;
1.521 www 5658: font-size: larger;
5659: font-weight: bold;
5660: }
5661:
1.346 albertel 5662: td.LC_menubuttons_text {
1.911 bisitz 5663: color: $font;
1.346 albertel 5664: }
1.706 harmsja 5665:
1.346 albertel 5666: .LC_current_location {
5667: background: $tabbg;
5668: }
1.795 www 5669:
1.938 bisitz 5670: table.LC_data_table {
1.347 albertel 5671: border: 1px solid #000000;
1.402 albertel 5672: border-collapse: separate;
1.426 albertel 5673: border-spacing: 1px;
1.610 albertel 5674: background: $pgbg;
1.347 albertel 5675: }
1.795 www 5676:
1.422 albertel 5677: .LC_data_table_dense {
5678: font-size: small;
5679: }
1.795 www 5680:
1.507 raeburn 5681: table.LC_nested_outer {
5682: border: 1px solid #000000;
1.589 raeburn 5683: border-collapse: collapse;
1.803 bisitz 5684: border-spacing: 0;
1.507 raeburn 5685: width: 100%;
5686: }
1.795 www 5687:
1.879 raeburn 5688: table.LC_innerpickbox,
1.507 raeburn 5689: table.LC_nested {
1.803 bisitz 5690: border: none;
1.589 raeburn 5691: border-collapse: collapse;
1.803 bisitz 5692: border-spacing: 0;
1.507 raeburn 5693: width: 100%;
5694: }
1.795 www 5695:
1.911 bisitz 5696: table.LC_data_table tr th,
5697: table.LC_calendar tr th,
1.879 raeburn 5698: table.LC_prior_tries tr th,
5699: table.LC_innerpickbox tr th {
1.349 albertel 5700: font-weight: bold;
5701: background-color: $data_table_head;
1.801 tempelho 5702: color:$fontmenu;
1.701 harmsja 5703: font-size:90%;
1.347 albertel 5704: }
1.795 www 5705:
1.879 raeburn 5706: table.LC_innerpickbox tr th,
5707: table.LC_innerpickbox tr td {
5708: vertical-align: top;
5709: }
5710:
1.711 raeburn 5711: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5712: background-color: #CCCCCC;
1.711 raeburn 5713: font-weight: bold;
5714: text-align: left;
5715: }
1.795 www 5716:
1.912 bisitz 5717: table.LC_data_table tr.LC_odd_row > td {
5718: background-color: $data_table_light;
5719: padding: 2px;
5720: vertical-align: top;
5721: }
5722:
1.809 bisitz 5723: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5724: background-color: $data_table_light;
1.912 bisitz 5725: vertical-align: top;
5726: }
5727:
5728: table.LC_data_table tr.LC_even_row > td {
5729: background-color: $data_table_dark;
1.425 albertel 5730: padding: 2px;
1.900 bisitz 5731: vertical-align: top;
1.347 albertel 5732: }
1.795 www 5733:
1.809 bisitz 5734: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5735: background-color: $data_table_dark;
1.900 bisitz 5736: vertical-align: top;
1.347 albertel 5737: }
1.795 www 5738:
1.425 albertel 5739: table.LC_data_table tr.LC_data_table_highlight td {
5740: background-color: $data_table_darker;
5741: }
1.795 www 5742:
1.639 raeburn 5743: table.LC_data_table tr td.LC_leftcol_header {
5744: background-color: $data_table_head;
5745: font-weight: bold;
5746: }
1.795 www 5747:
1.451 albertel 5748: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5749: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5750: font-weight: bold;
5751: font-style: italic;
5752: text-align: center;
5753: padding: 8px;
1.347 albertel 5754: }
1.795 www 5755:
1.1075.2.30 raeburn 5756: table.LC_data_table tr.LC_empty_row td,
5757: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5758: background-color: $sidebg;
5759: }
5760:
5761: table.LC_nested tr.LC_empty_row td {
5762: background-color: #FFFFFF;
5763: }
5764:
1.890 droeschl 5765: table.LC_caption {
5766: }
5767:
1.507 raeburn 5768: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5769: padding: 4ex
5770: }
1.795 www 5771:
1.507 raeburn 5772: table.LC_nested_outer tr th {
5773: font-weight: bold;
1.801 tempelho 5774: color:$fontmenu;
1.507 raeburn 5775: background-color: $data_table_head;
1.701 harmsja 5776: font-size: small;
1.507 raeburn 5777: border-bottom: 1px solid #000000;
5778: }
1.795 www 5779:
1.507 raeburn 5780: table.LC_nested_outer tr td.LC_subheader {
5781: background-color: $data_table_head;
5782: font-weight: bold;
5783: font-size: small;
5784: border-bottom: 1px solid #000000;
5785: text-align: right;
1.451 albertel 5786: }
1.795 www 5787:
1.507 raeburn 5788: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5789: background-color: #CCCCCC;
1.451 albertel 5790: font-weight: bold;
5791: font-size: small;
1.507 raeburn 5792: text-align: center;
5793: }
1.795 www 5794:
1.589 raeburn 5795: table.LC_nested tr.LC_info_row td.LC_left_item,
5796: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5797: text-align: left;
1.451 albertel 5798: }
1.795 www 5799:
1.507 raeburn 5800: table.LC_nested td {
1.735 bisitz 5801: background-color: #FFFFFF;
1.451 albertel 5802: font-size: small;
1.507 raeburn 5803: }
1.795 www 5804:
1.507 raeburn 5805: table.LC_nested_outer tr th.LC_right_item,
5806: table.LC_nested tr.LC_info_row td.LC_right_item,
5807: table.LC_nested tr.LC_odd_row td.LC_right_item,
5808: table.LC_nested tr td.LC_right_item {
1.451 albertel 5809: text-align: right;
5810: }
5811:
1.507 raeburn 5812: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5813: background-color: #EEEEEE;
1.451 albertel 5814: }
5815:
1.473 raeburn 5816: table.LC_createuser {
5817: }
5818:
5819: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5820: font-size: small;
1.473 raeburn 5821: }
5822:
5823: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5824: background-color: #CCCCCC;
1.473 raeburn 5825: font-weight: bold;
5826: text-align: center;
5827: }
5828:
1.349 albertel 5829: table.LC_calendar {
5830: border: 1px solid #000000;
5831: border-collapse: collapse;
1.917 raeburn 5832: width: 98%;
1.349 albertel 5833: }
1.795 www 5834:
1.349 albertel 5835: table.LC_calendar_pickdate {
5836: font-size: xx-small;
5837: }
1.795 www 5838:
1.349 albertel 5839: table.LC_calendar tr td {
5840: border: 1px solid #000000;
5841: vertical-align: top;
1.917 raeburn 5842: width: 14%;
1.349 albertel 5843: }
1.795 www 5844:
1.349 albertel 5845: table.LC_calendar tr td.LC_calendar_day_empty {
5846: background-color: $data_table_dark;
5847: }
1.795 www 5848:
1.779 bisitz 5849: table.LC_calendar tr td.LC_calendar_day_current {
5850: background-color: $data_table_highlight;
1.777 tempelho 5851: }
1.795 www 5852:
1.938 bisitz 5853: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5854: background-color: $mail_new;
5855: }
1.795 www 5856:
1.938 bisitz 5857: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5858: background-color: $mail_new_hover;
5859: }
1.795 www 5860:
1.938 bisitz 5861: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5862: background-color: $mail_read;
5863: }
1.795 www 5864:
1.938 bisitz 5865: /*
5866: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5867: background-color: $mail_read_hover;
5868: }
1.938 bisitz 5869: */
1.795 www 5870:
1.938 bisitz 5871: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5872: background-color: $mail_replied;
5873: }
1.795 www 5874:
1.938 bisitz 5875: /*
5876: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5877: background-color: $mail_replied_hover;
5878: }
1.938 bisitz 5879: */
1.795 www 5880:
1.938 bisitz 5881: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5882: background-color: $mail_other;
5883: }
1.795 www 5884:
1.938 bisitz 5885: /*
5886: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5887: background-color: $mail_other_hover;
5888: }
1.938 bisitz 5889: */
1.494 raeburn 5890:
1.777 tempelho 5891: table.LC_data_table tr > td.LC_browser_file,
5892: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5893: background: #AAEE77;
1.389 albertel 5894: }
1.795 www 5895:
1.777 tempelho 5896: table.LC_data_table tr > td.LC_browser_file_locked,
5897: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5898: background: #FFAA99;
1.387 albertel 5899: }
1.795 www 5900:
1.777 tempelho 5901: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5902: background: #888888;
1.779 bisitz 5903: }
1.795 www 5904:
1.777 tempelho 5905: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5906: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5907: background: #F8F866;
1.777 tempelho 5908: }
1.795 www 5909:
1.696 bisitz 5910: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5911: background: #E0E8FF;
1.387 albertel 5912: }
1.696 bisitz 5913:
1.707 bisitz 5914: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5915: /* background: #77FF77; */
1.707 bisitz 5916: }
1.795 www 5917:
1.707 bisitz 5918: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5919: border-right: 8px solid #FFFF77;
1.707 bisitz 5920: }
1.795 www 5921:
1.707 bisitz 5922: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5923: border-right: 8px solid #FFAA77;
1.707 bisitz 5924: }
1.795 www 5925:
1.707 bisitz 5926: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5927: border-right: 8px solid #FF7777;
1.707 bisitz 5928: }
1.795 www 5929:
1.707 bisitz 5930: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5931: border-right: 8px solid #AAFF77;
1.707 bisitz 5932: }
1.795 www 5933:
1.707 bisitz 5934: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5935: border-right: 8px solid #11CC55;
1.707 bisitz 5936: }
5937:
1.388 albertel 5938: span.LC_current_location {
1.701 harmsja 5939: font-size:larger;
1.388 albertel 5940: background: $pgbg;
5941: }
1.387 albertel 5942:
1.1029 www 5943: span.LC_current_nav_location {
5944: font-weight:bold;
5945: background: $sidebg;
5946: }
5947:
1.395 albertel 5948: span.LC_parm_menu_item {
5949: font-size: larger;
5950: }
1.795 www 5951:
1.395 albertel 5952: span.LC_parm_scope_all {
5953: color: red;
5954: }
1.795 www 5955:
1.395 albertel 5956: span.LC_parm_scope_folder {
5957: color: green;
5958: }
1.795 www 5959:
1.395 albertel 5960: span.LC_parm_scope_resource {
5961: color: orange;
5962: }
1.795 www 5963:
1.395 albertel 5964: span.LC_parm_part {
5965: color: blue;
5966: }
1.795 www 5967:
1.911 bisitz 5968: span.LC_parm_folder,
5969: span.LC_parm_symb {
1.395 albertel 5970: font-size: x-small;
5971: font-family: $mono;
5972: color: #AAAAAA;
5973: }
5974:
1.977 bisitz 5975: ul.LC_parm_parmlist li {
5976: display: inline-block;
5977: padding: 0.3em 0.8em;
5978: vertical-align: top;
5979: width: 150px;
5980: border-top:1px solid $lg_border_color;
5981: }
5982:
1.795 www 5983: td.LC_parm_overview_level_menu,
5984: td.LC_parm_overview_map_menu,
5985: td.LC_parm_overview_parm_selectors,
5986: td.LC_parm_overview_restrictions {
1.396 albertel 5987: border: 1px solid black;
5988: border-collapse: collapse;
5989: }
1.795 www 5990:
1.396 albertel 5991: table.LC_parm_overview_restrictions td {
5992: border-width: 1px 4px 1px 4px;
5993: border-style: solid;
5994: border-color: $pgbg;
5995: text-align: center;
5996: }
1.795 www 5997:
1.396 albertel 5998: table.LC_parm_overview_restrictions th {
5999: background: $tabbg;
6000: border-width: 1px 4px 1px 4px;
6001: border-style: solid;
6002: border-color: $pgbg;
6003: }
1.795 www 6004:
1.398 albertel 6005: table#LC_helpmenu {
1.803 bisitz 6006: border: none;
1.398 albertel 6007: height: 55px;
1.803 bisitz 6008: border-spacing: 0;
1.398 albertel 6009: }
6010:
6011: table#LC_helpmenu fieldset legend {
6012: font-size: larger;
6013: }
1.795 www 6014:
1.397 albertel 6015: table#LC_helpmenu_links {
6016: width: 100%;
6017: border: 1px solid black;
6018: background: $pgbg;
1.803 bisitz 6019: padding: 0;
1.397 albertel 6020: border-spacing: 1px;
6021: }
1.795 www 6022:
1.397 albertel 6023: table#LC_helpmenu_links tr td {
6024: padding: 1px;
6025: background: $tabbg;
1.399 albertel 6026: text-align: center;
6027: font-weight: bold;
1.397 albertel 6028: }
1.396 albertel 6029:
1.795 www 6030: table#LC_helpmenu_links a:link,
6031: table#LC_helpmenu_links a:visited,
1.397 albertel 6032: table#LC_helpmenu_links a:active {
6033: text-decoration: none;
6034: color: $font;
6035: }
1.795 www 6036:
1.397 albertel 6037: table#LC_helpmenu_links a:hover {
6038: text-decoration: underline;
6039: color: $vlink;
6040: }
1.396 albertel 6041:
1.417 albertel 6042: .LC_chrt_popup_exists {
6043: border: 1px solid #339933;
6044: margin: -1px;
6045: }
1.795 www 6046:
1.417 albertel 6047: .LC_chrt_popup_up {
6048: border: 1px solid yellow;
6049: margin: -1px;
6050: }
1.795 www 6051:
1.417 albertel 6052: .LC_chrt_popup {
6053: border: 1px solid #8888FF;
6054: background: #CCCCFF;
6055: }
1.795 www 6056:
1.421 albertel 6057: table.LC_pick_box {
6058: border-collapse: separate;
6059: background: white;
6060: border: 1px solid black;
6061: border-spacing: 1px;
6062: }
1.795 www 6063:
1.421 albertel 6064: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6065: background: $sidebg;
1.421 albertel 6066: font-weight: bold;
1.900 bisitz 6067: text-align: left;
1.740 bisitz 6068: vertical-align: top;
1.421 albertel 6069: width: 184px;
6070: padding: 8px;
6071: }
1.795 www 6072:
1.579 raeburn 6073: table.LC_pick_box td.LC_pick_box_value {
6074: text-align: left;
6075: padding: 8px;
6076: }
1.795 www 6077:
1.579 raeburn 6078: table.LC_pick_box td.LC_pick_box_select {
6079: text-align: left;
6080: padding: 8px;
6081: }
1.795 www 6082:
1.424 albertel 6083: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6084: padding: 0;
1.421 albertel 6085: height: 1px;
6086: background: black;
6087: }
1.795 www 6088:
1.421 albertel 6089: table.LC_pick_box td.LC_pick_box_submit {
6090: text-align: right;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_evenrow_value {
6094: text-align: left;
6095: padding: 8px;
6096: background-color: $data_table_light;
6097: }
1.795 www 6098:
1.579 raeburn 6099: table.LC_pick_box td.LC_oddrow_value {
6100: text-align: left;
6101: padding: 8px;
6102: background-color: $data_table_light;
6103: }
1.795 www 6104:
1.579 raeburn 6105: span.LC_helpform_receipt_cat {
6106: font-weight: bold;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv_box {
6110: background: white;
6111: border: 1px solid black;
6112: border-spacing: 1px;
6113: }
1.795 www 6114:
1.424 albertel 6115: table.LC_group_priv_box td.LC_pick_box_title {
6116: background: $tabbg;
6117: font-weight: bold;
6118: text-align: right;
6119: width: 184px;
6120: }
1.795 www 6121:
1.424 albertel 6122: table.LC_group_priv_box td.LC_groups_fixed {
6123: background: $data_table_light;
6124: text-align: center;
6125: }
1.795 www 6126:
1.424 albertel 6127: table.LC_group_priv_box td.LC_groups_optional {
6128: background: $data_table_dark;
6129: text-align: center;
6130: }
1.795 www 6131:
1.424 albertel 6132: table.LC_group_priv_box td.LC_groups_functionality {
6133: background: $data_table_darker;
6134: text-align: center;
6135: font-weight: bold;
6136: }
1.795 www 6137:
1.424 albertel 6138: table.LC_group_priv td {
6139: text-align: left;
1.803 bisitz 6140: padding: 0;
1.424 albertel 6141: }
6142:
6143: .LC_navbuttons {
6144: margin: 2ex 0ex 2ex 0ex;
6145: }
1.795 www 6146:
1.423 albertel 6147: .LC_topic_bar {
6148: font-weight: bold;
6149: background: $tabbg;
1.918 wenzelju 6150: margin: 1em 0em 1em 2em;
1.805 bisitz 6151: padding: 3px;
1.918 wenzelju 6152: font-size: 1.2em;
1.423 albertel 6153: }
1.795 www 6154:
1.423 albertel 6155: .LC_topic_bar span {
1.918 wenzelju 6156: left: 0.5em;
6157: position: absolute;
1.423 albertel 6158: vertical-align: middle;
1.918 wenzelju 6159: font-size: 1.2em;
1.423 albertel 6160: }
1.795 www 6161:
1.423 albertel 6162: table.LC_course_group_status {
6163: margin: 20px;
6164: }
1.795 www 6165:
1.423 albertel 6166: table.LC_status_selector td {
6167: vertical-align: top;
6168: text-align: center;
1.424 albertel 6169: padding: 4px;
6170: }
1.795 www 6171:
1.599 albertel 6172: div.LC_feedback_link {
1.616 albertel 6173: clear: both;
1.829 kalberla 6174: background: $sidebg;
1.779 bisitz 6175: width: 100%;
1.829 kalberla 6176: padding-bottom: 10px;
6177: border: 1px $tabbg solid;
1.833 kalberla 6178: height: 22px;
6179: line-height: 22px;
6180: padding-top: 5px;
6181: }
6182:
6183: div.LC_feedback_link img {
6184: height: 22px;
1.867 kalberla 6185: vertical-align:middle;
1.829 kalberla 6186: }
6187:
1.911 bisitz 6188: div.LC_feedback_link a {
1.829 kalberla 6189: text-decoration: none;
1.489 raeburn 6190: }
1.795 www 6191:
1.867 kalberla 6192: div.LC_comblock {
1.911 bisitz 6193: display:inline;
1.867 kalberla 6194: color:$font;
6195: font-size:90%;
6196: }
6197:
6198: div.LC_feedback_link div.LC_comblock {
6199: padding-left:5px;
6200: }
6201:
6202: div.LC_feedback_link div.LC_comblock a {
6203: color:$font;
6204: }
6205:
1.489 raeburn 6206: span.LC_feedback_link {
1.858 bisitz 6207: /* background: $feedback_link_bg; */
1.599 albertel 6208: font-size: larger;
6209: }
1.795 www 6210:
1.599 albertel 6211: span.LC_message_link {
1.858 bisitz 6212: /* background: $feedback_link_bg; */
1.599 albertel 6213: font-size: larger;
6214: position: absolute;
6215: right: 1em;
1.489 raeburn 6216: }
1.421 albertel 6217:
1.515 albertel 6218: table.LC_prior_tries {
1.524 albertel 6219: border: 1px solid #000000;
6220: border-collapse: separate;
6221: border-spacing: 1px;
1.515 albertel 6222: }
1.523 albertel 6223:
1.515 albertel 6224: table.LC_prior_tries td {
1.524 albertel 6225: padding: 2px;
1.515 albertel 6226: }
1.523 albertel 6227:
6228: .LC_answer_correct {
1.795 www 6229: background: lightgreen;
6230: color: darkgreen;
6231: padding: 6px;
1.523 albertel 6232: }
1.795 www 6233:
1.523 albertel 6234: .LC_answer_charged_try {
1.797 www 6235: background: #FFAAAA;
1.795 www 6236: color: darkred;
6237: padding: 6px;
1.523 albertel 6238: }
1.795 www 6239:
1.779 bisitz 6240: .LC_answer_not_charged_try,
1.523 albertel 6241: .LC_answer_no_grade,
6242: .LC_answer_late {
1.795 www 6243: background: lightyellow;
1.523 albertel 6244: color: black;
1.795 www 6245: padding: 6px;
1.523 albertel 6246: }
1.795 www 6247:
1.523 albertel 6248: .LC_answer_previous {
1.795 www 6249: background: lightblue;
6250: color: darkblue;
6251: padding: 6px;
1.523 albertel 6252: }
1.795 www 6253:
1.779 bisitz 6254: .LC_answer_no_message {
1.777 tempelho 6255: background: #FFFFFF;
6256: color: black;
1.795 www 6257: padding: 6px;
1.779 bisitz 6258: }
1.795 www 6259:
1.779 bisitz 6260: .LC_answer_unknown {
6261: background: orange;
6262: color: black;
1.795 www 6263: padding: 6px;
1.777 tempelho 6264: }
1.795 www 6265:
1.529 albertel 6266: span.LC_prior_numerical,
6267: span.LC_prior_string,
6268: span.LC_prior_custom,
6269: span.LC_prior_reaction,
6270: span.LC_prior_math {
1.925 bisitz 6271: font-family: $mono;
1.523 albertel 6272: white-space: pre;
6273: }
6274:
1.525 albertel 6275: span.LC_prior_string {
1.925 bisitz 6276: font-family: $mono;
1.525 albertel 6277: white-space: pre;
6278: }
6279:
1.523 albertel 6280: table.LC_prior_option {
6281: width: 100%;
6282: border-collapse: collapse;
6283: }
1.795 www 6284:
1.911 bisitz 6285: table.LC_prior_rank,
1.795 www 6286: table.LC_prior_match {
1.528 albertel 6287: border-collapse: collapse;
6288: }
1.795 www 6289:
1.528 albertel 6290: table.LC_prior_option tr td,
6291: table.LC_prior_rank tr td,
6292: table.LC_prior_match tr td {
1.524 albertel 6293: border: 1px solid #000000;
1.515 albertel 6294: }
6295:
1.855 bisitz 6296: .LC_nobreak {
1.544 albertel 6297: white-space: nowrap;
1.519 raeburn 6298: }
6299:
1.576 raeburn 6300: span.LC_cusr_emph {
6301: font-style: italic;
6302: }
6303:
1.633 raeburn 6304: span.LC_cusr_subheading {
6305: font-weight: normal;
6306: font-size: 85%;
6307: }
6308:
1.861 bisitz 6309: div.LC_docs_entry_move {
1.859 bisitz 6310: border: 1px solid #BBBBBB;
1.545 albertel 6311: background: #DDDDDD;
1.861 bisitz 6312: width: 22px;
1.859 bisitz 6313: padding: 1px;
6314: margin: 0;
1.545 albertel 6315: }
6316:
1.861 bisitz 6317: table.LC_data_table tr > td.LC_docs_entry_commands,
6318: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6319: font-size: x-small;
6320: }
1.795 www 6321:
1.861 bisitz 6322: .LC_docs_entry_parameter {
6323: white-space: nowrap;
6324: }
6325:
1.544 albertel 6326: .LC_docs_copy {
1.545 albertel 6327: color: #000099;
1.544 albertel 6328: }
1.795 www 6329:
1.544 albertel 6330: .LC_docs_cut {
1.545 albertel 6331: color: #550044;
1.544 albertel 6332: }
1.795 www 6333:
1.544 albertel 6334: .LC_docs_rename {
1.545 albertel 6335: color: #009900;
1.544 albertel 6336: }
1.795 www 6337:
1.544 albertel 6338: .LC_docs_remove {
1.545 albertel 6339: color: #990000;
6340: }
6341:
1.547 albertel 6342: .LC_docs_reinit_warn,
6343: .LC_docs_ext_edit {
6344: font-size: x-small;
6345: }
6346:
1.545 albertel 6347: table.LC_docs_adddocs td,
6348: table.LC_docs_adddocs th {
6349: border: 1px solid #BBBBBB;
6350: padding: 4px;
6351: background: #DDDDDD;
1.543 albertel 6352: }
6353:
1.584 albertel 6354: table.LC_sty_begin {
6355: background: #BBFFBB;
6356: }
1.795 www 6357:
1.584 albertel 6358: table.LC_sty_end {
6359: background: #FFBBBB;
6360: }
6361:
1.589 raeburn 6362: table.LC_double_column {
1.803 bisitz 6363: border-width: 0;
1.589 raeburn 6364: border-collapse: collapse;
6365: width: 100%;
6366: padding: 2px;
6367: }
6368:
6369: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6370: top: 2px;
1.589 raeburn 6371: left: 2px;
6372: width: 47%;
6373: vertical-align: top;
6374: }
6375:
6376: table.LC_double_column tr td.LC_right_col {
6377: top: 2px;
1.779 bisitz 6378: right: 2px;
1.589 raeburn 6379: width: 47%;
6380: vertical-align: top;
6381: }
6382:
1.591 raeburn 6383: div.LC_left_float {
6384: float: left;
6385: padding-right: 5%;
1.597 albertel 6386: padding-bottom: 4px;
1.591 raeburn 6387: }
6388:
6389: div.LC_clear_float_header {
1.597 albertel 6390: padding-bottom: 2px;
1.591 raeburn 6391: }
6392:
6393: div.LC_clear_float_footer {
1.597 albertel 6394: padding-top: 10px;
1.591 raeburn 6395: clear: both;
6396: }
6397:
1.597 albertel 6398: div.LC_grade_show_user {
1.941 bisitz 6399: /* border-left: 5px solid $sidebg; */
6400: border-top: 5px solid #000000;
6401: margin: 50px 0 0 0;
1.936 bisitz 6402: padding: 15px 0 5px 10px;
1.597 albertel 6403: }
1.795 www 6404:
1.936 bisitz 6405: div.LC_grade_show_user_odd_row {
1.941 bisitz 6406: /* border-left: 5px solid #000000; */
6407: }
6408:
6409: div.LC_grade_show_user div.LC_Box {
6410: margin-right: 50px;
1.597 albertel 6411: }
6412:
6413: div.LC_grade_submissions,
6414: div.LC_grade_message_center,
1.936 bisitz 6415: div.LC_grade_info_links {
1.597 albertel 6416: margin: 5px;
6417: width: 99%;
6418: background: #FFFFFF;
6419: }
1.795 www 6420:
1.597 albertel 6421: div.LC_grade_submissions_header,
1.936 bisitz 6422: div.LC_grade_message_center_header {
1.705 tempelho 6423: font-weight: bold;
6424: font-size: large;
1.597 albertel 6425: }
1.795 www 6426:
1.597 albertel 6427: div.LC_grade_submissions_body,
1.936 bisitz 6428: div.LC_grade_message_center_body {
1.597 albertel 6429: border: 1px solid black;
6430: width: 99%;
6431: background: #FFFFFF;
6432: }
1.795 www 6433:
1.613 albertel 6434: table.LC_scantron_action {
6435: width: 100%;
6436: }
1.795 www 6437:
1.613 albertel 6438: table.LC_scantron_action tr th {
1.698 harmsja 6439: font-weight:bold;
6440: font-style:normal;
1.613 albertel 6441: }
1.795 www 6442:
1.779 bisitz 6443: .LC_edit_problem_header,
1.614 albertel 6444: div.LC_edit_problem_footer {
1.705 tempelho 6445: font-weight: normal;
6446: font-size: medium;
1.602 albertel 6447: margin: 2px;
1.1060 bisitz 6448: background-color: $sidebg;
1.600 albertel 6449: }
1.795 www 6450:
1.600 albertel 6451: div.LC_edit_problem_header,
1.602 albertel 6452: div.LC_edit_problem_header div,
1.614 albertel 6453: div.LC_edit_problem_footer,
6454: div.LC_edit_problem_footer div,
1.602 albertel 6455: div.LC_edit_problem_editxml_header,
6456: div.LC_edit_problem_editxml_header div {
1.600 albertel 6457: margin-top: 5px;
6458: }
1.795 www 6459:
1.600 albertel 6460: div.LC_edit_problem_header_title {
1.705 tempelho 6461: font-weight: bold;
6462: font-size: larger;
1.602 albertel 6463: background: $tabbg;
6464: padding: 3px;
1.1060 bisitz 6465: margin: 0 0 5px 0;
1.602 albertel 6466: }
1.795 www 6467:
1.602 albertel 6468: table.LC_edit_problem_header_title {
6469: width: 100%;
1.600 albertel 6470: background: $tabbg;
1.602 albertel 6471: }
6472:
6473: div.LC_edit_problem_discards {
6474: float: left;
6475: padding-bottom: 5px;
6476: }
1.795 www 6477:
1.602 albertel 6478: div.LC_edit_problem_saves {
6479: float: right;
6480: padding-bottom: 5px;
1.600 albertel 6481: }
1.795 www 6482:
1.1075.2.34 raeburn 6483: .LC_edit_opt {
6484: padding-left: 1em;
6485: white-space: nowrap;
6486: }
6487:
1.1075.2.57 raeburn 6488: .LC_edit_problem_latexhelper{
6489: text-align: right;
6490: }
6491:
6492: #LC_edit_problem_colorful div{
6493: margin-left: 40px;
6494: }
6495:
1.911 bisitz 6496: img.stift {
1.803 bisitz 6497: border-width: 0;
6498: vertical-align: middle;
1.677 riegler 6499: }
1.680 riegler 6500:
1.923 bisitz 6501: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6502: vertical-align: top;
1.777 tempelho 6503: }
1.795 www 6504:
1.716 raeburn 6505: div.LC_createcourse {
1.911 bisitz 6506: margin: 10px 10px 10px 10px;
1.716 raeburn 6507: }
6508:
1.917 raeburn 6509: .LC_dccid {
1.1075.2.38 raeburn 6510: float: right;
1.917 raeburn 6511: margin: 0.2em 0 0 0;
6512: padding: 0;
6513: font-size: 90%;
6514: display:none;
6515: }
6516:
1.897 wenzelju 6517: ol.LC_primary_menu a:hover,
1.721 harmsja 6518: ol#LC_MenuBreadcrumbs a:hover,
6519: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6520: ul#LC_secondary_menu a:hover,
1.721 harmsja 6521: .LC_FormSectionClearButton input:hover
1.795 www 6522: ul.LC_TabContent li:hover a {
1.952 onken 6523: color:$button_hover;
1.911 bisitz 6524: text-decoration:none;
1.693 droeschl 6525: }
6526:
1.779 bisitz 6527: h1 {
1.911 bisitz 6528: padding: 0;
6529: line-height:130%;
1.693 droeschl 6530: }
1.698 harmsja 6531:
1.911 bisitz 6532: h2,
6533: h3,
6534: h4,
6535: h5,
6536: h6 {
6537: margin: 5px 0 5px 0;
6538: padding: 0;
6539: line-height:130%;
1.693 droeschl 6540: }
1.795 www 6541:
6542: .LC_hcell {
1.911 bisitz 6543: padding:3px 15px 3px 15px;
6544: margin: 0;
6545: background-color:$tabbg;
6546: color:$fontmenu;
6547: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6548: }
1.795 www 6549:
1.840 bisitz 6550: .LC_Box > .LC_hcell {
1.911 bisitz 6551: margin: 0 -10px 10px -10px;
1.835 bisitz 6552: }
6553:
1.721 harmsja 6554: .LC_noBorder {
1.911 bisitz 6555: border: 0;
1.698 harmsja 6556: }
1.693 droeschl 6557:
1.721 harmsja 6558: .LC_FormSectionClearButton input {
1.911 bisitz 6559: background-color:transparent;
6560: border: none;
6561: cursor:pointer;
6562: text-decoration:underline;
1.693 droeschl 6563: }
1.763 bisitz 6564:
6565: .LC_help_open_topic {
1.911 bisitz 6566: color: #FFFFFF;
6567: background-color: #EEEEFF;
6568: margin: 1px;
6569: padding: 4px;
6570: border: 1px solid #000033;
6571: white-space: nowrap;
6572: /* vertical-align: middle; */
1.759 neumanie 6573: }
1.693 droeschl 6574:
1.911 bisitz 6575: dl,
6576: ul,
6577: div,
6578: fieldset {
6579: margin: 10px 10px 10px 0;
6580: /* overflow: hidden; */
1.693 droeschl 6581: }
1.795 www 6582:
1.838 bisitz 6583: fieldset > legend {
1.911 bisitz 6584: font-weight: bold;
6585: padding: 0 5px 0 5px;
1.838 bisitz 6586: }
6587:
1.813 bisitz 6588: #LC_nav_bar {
1.911 bisitz 6589: float: left;
1.995 raeburn 6590: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6591: margin: 0 0 2px 0;
1.807 droeschl 6592: }
6593:
1.916 droeschl 6594: #LC_realm {
6595: margin: 0.2em 0 0 0;
6596: padding: 0;
6597: font-weight: bold;
6598: text-align: center;
1.995 raeburn 6599: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6600: }
6601:
1.911 bisitz 6602: #LC_nav_bar em {
6603: font-weight: bold;
6604: font-style: normal;
1.807 droeschl 6605: }
6606:
1.897 wenzelju 6607: ol.LC_primary_menu {
1.934 droeschl 6608: margin: 0;
1.1075.2.2 raeburn 6609: padding: 0;
1.995 raeburn 6610: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6611: }
6612:
1.852 droeschl 6613: ol#LC_PathBreadcrumbs {
1.911 bisitz 6614: margin: 0;
1.693 droeschl 6615: }
6616:
1.897 wenzelju 6617: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6618: color: RGB(80, 80, 80);
6619: vertical-align: middle;
6620: text-align: left;
6621: list-style: none;
6622: float: left;
6623: }
6624:
6625: ol.LC_primary_menu li a {
6626: display: block;
6627: margin: 0;
6628: padding: 0 5px 0 10px;
6629: text-decoration: none;
6630: }
6631:
6632: ol.LC_primary_menu li ul {
6633: display: none;
6634: width: 10em;
6635: background-color: $data_table_light;
6636: }
6637:
6638: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6639: display: block;
6640: position: absolute;
6641: margin: 0;
6642: padding: 0;
1.1075.2.5 raeburn 6643: z-index: 2;
1.1075.2.2 raeburn 6644: }
6645:
6646: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6647: font-size: 90%;
1.911 bisitz 6648: vertical-align: top;
1.1075.2.2 raeburn 6649: float: none;
1.1075.2.5 raeburn 6650: border-left: 1px solid black;
6651: border-right: 1px solid black;
1.1075.2.2 raeburn 6652: }
6653:
6654: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6655: background-color:$data_table_light;
1.1075.2.2 raeburn 6656: }
6657:
6658: ol.LC_primary_menu li li a:hover {
6659: color:$button_hover;
6660: background-color:$data_table_dark;
1.693 droeschl 6661: }
6662:
1.897 wenzelju 6663: ol.LC_primary_menu li img {
1.911 bisitz 6664: vertical-align: bottom;
1.934 droeschl 6665: height: 1.1em;
1.1075.2.3 raeburn 6666: margin: 0.2em 0 0 0;
1.693 droeschl 6667: }
6668:
1.897 wenzelju 6669: ol.LC_primary_menu a {
1.911 bisitz 6670: color: RGB(80, 80, 80);
6671: text-decoration: none;
1.693 droeschl 6672: }
1.795 www 6673:
1.949 droeschl 6674: ol.LC_primary_menu a.LC_new_message {
6675: font-weight:bold;
6676: color: darkred;
6677: }
6678:
1.975 raeburn 6679: ol.LC_docs_parameters {
6680: margin-left: 0;
6681: padding: 0;
6682: list-style: none;
6683: }
6684:
6685: ol.LC_docs_parameters li {
6686: margin: 0;
6687: padding-right: 20px;
6688: display: inline;
6689: }
6690:
1.976 raeburn 6691: ol.LC_docs_parameters li:before {
6692: content: "\\002022 \\0020";
6693: }
6694:
6695: li.LC_docs_parameters_title {
6696: font-weight: bold;
6697: }
6698:
6699: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6700: content: "";
6701: }
6702:
1.897 wenzelju 6703: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6704: clear: right;
1.911 bisitz 6705: color: $fontmenu;
6706: background: $tabbg;
6707: list-style: none;
6708: padding: 0;
6709: margin: 0;
6710: width: 100%;
1.995 raeburn 6711: text-align: left;
1.1075.2.4 raeburn 6712: float: left;
1.808 droeschl 6713: }
6714:
1.897 wenzelju 6715: ul#LC_secondary_menu li {
1.911 bisitz 6716: font-weight: bold;
6717: line-height: 1.8em;
6718: border-right: 1px solid black;
6719: vertical-align: middle;
1.1075.2.4 raeburn 6720: float: left;
6721: }
6722:
6723: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6724: background-color: $data_table_light;
6725: }
6726:
6727: ul#LC_secondary_menu li a {
6728: padding: 0 0.8em;
6729: }
6730:
6731: ul#LC_secondary_menu li ul {
6732: display: none;
6733: }
6734:
6735: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6736: display: block;
6737: position: absolute;
6738: margin: 0;
6739: padding: 0;
6740: list-style:none;
6741: float: none;
6742: background-color: $data_table_light;
1.1075.2.5 raeburn 6743: z-index: 2;
1.1075.2.10 raeburn 6744: margin-left: -1px;
1.1075.2.4 raeburn 6745: }
6746:
6747: ul#LC_secondary_menu li ul li {
6748: font-size: 90%;
6749: vertical-align: top;
6750: border-left: 1px solid black;
6751: border-right: 1px solid black;
1.1075.2.33 raeburn 6752: background-color: $data_table_light;
1.1075.2.4 raeburn 6753: list-style:none;
6754: float: none;
6755: }
6756:
6757: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6758: background-color: $data_table_dark;
1.807 droeschl 6759: }
6760:
1.847 tempelho 6761: ul.LC_TabContent {
1.911 bisitz 6762: display:block;
6763: background: $sidebg;
6764: border-bottom: solid 1px $lg_border_color;
6765: list-style:none;
1.1020 raeburn 6766: margin: -1px -10px 0 -10px;
1.911 bisitz 6767: padding: 0;
1.693 droeschl 6768: }
6769:
1.795 www 6770: ul.LC_TabContent li,
6771: ul.LC_TabContentBigger li {
1.911 bisitz 6772: float:left;
1.741 harmsja 6773: }
1.795 www 6774:
1.897 wenzelju 6775: ul#LC_secondary_menu li a {
1.911 bisitz 6776: color: $fontmenu;
6777: text-decoration: none;
1.693 droeschl 6778: }
1.795 www 6779:
1.721 harmsja 6780: ul.LC_TabContent {
1.952 onken 6781: min-height:20px;
1.721 harmsja 6782: }
1.795 www 6783:
6784: ul.LC_TabContent li {
1.911 bisitz 6785: vertical-align:middle;
1.959 onken 6786: padding: 0 16px 0 10px;
1.911 bisitz 6787: background-color:$tabbg;
6788: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6789: border-left: solid 1px $font;
1.721 harmsja 6790: }
1.795 www 6791:
1.847 tempelho 6792: ul.LC_TabContent .right {
1.911 bisitz 6793: float:right;
1.847 tempelho 6794: }
6795:
1.911 bisitz 6796: ul.LC_TabContent li a,
6797: ul.LC_TabContent li {
6798: color:rgb(47,47,47);
6799: text-decoration:none;
6800: font-size:95%;
6801: font-weight:bold;
1.952 onken 6802: min-height:20px;
6803: }
6804:
1.959 onken 6805: ul.LC_TabContent li a:hover,
6806: ul.LC_TabContent li a:focus {
1.952 onken 6807: color: $button_hover;
1.959 onken 6808: background:none;
6809: outline:none;
1.952 onken 6810: }
6811:
6812: ul.LC_TabContent li:hover {
6813: color: $button_hover;
6814: cursor:pointer;
1.721 harmsja 6815: }
1.795 www 6816:
1.911 bisitz 6817: ul.LC_TabContent li.active {
1.952 onken 6818: color: $font;
1.911 bisitz 6819: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6820: border-bottom:solid 1px #FFFFFF;
6821: cursor: default;
1.744 ehlerst 6822: }
1.795 www 6823:
1.959 onken 6824: ul.LC_TabContent li.active a {
6825: color:$font;
6826: background:#FFFFFF;
6827: outline: none;
6828: }
1.1047 raeburn 6829:
6830: ul.LC_TabContent li.goback {
6831: float: left;
6832: border-left: none;
6833: }
6834:
1.870 tempelho 6835: #maincoursedoc {
1.911 bisitz 6836: clear:both;
1.870 tempelho 6837: }
6838:
6839: ul.LC_TabContentBigger {
1.911 bisitz 6840: display:block;
6841: list-style:none;
6842: padding: 0;
1.870 tempelho 6843: }
6844:
1.795 www 6845: ul.LC_TabContentBigger li {
1.911 bisitz 6846: vertical-align:bottom;
6847: height: 30px;
6848: font-size:110%;
6849: font-weight:bold;
6850: color: #737373;
1.841 tempelho 6851: }
6852:
1.957 onken 6853: ul.LC_TabContentBigger li.active {
6854: position: relative;
6855: top: 1px;
6856: }
6857:
1.870 tempelho 6858: ul.LC_TabContentBigger li a {
1.911 bisitz 6859: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6860: height: 30px;
6861: line-height: 30px;
6862: text-align: center;
6863: display: block;
6864: text-decoration: none;
1.958 onken 6865: outline: none;
1.741 harmsja 6866: }
1.795 www 6867:
1.870 tempelho 6868: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6869: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6870: color:$font;
1.744 ehlerst 6871: }
1.795 www 6872:
1.870 tempelho 6873: ul.LC_TabContentBigger li b {
1.911 bisitz 6874: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6875: display: block;
6876: float: left;
6877: padding: 0 30px;
1.957 onken 6878: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6879: }
6880:
1.956 onken 6881: ul.LC_TabContentBigger li:hover b {
6882: color:$button_hover;
6883: }
6884:
1.870 tempelho 6885: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6886: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6887: color:$font;
1.957 onken 6888: border: 0;
1.741 harmsja 6889: }
1.693 droeschl 6890:
1.870 tempelho 6891:
1.862 bisitz 6892: ul.LC_CourseBreadcrumbs {
6893: background: $sidebg;
1.1020 raeburn 6894: height: 2em;
1.862 bisitz 6895: padding-left: 10px;
1.1020 raeburn 6896: margin: 0;
1.862 bisitz 6897: list-style-position: inside;
6898: }
6899:
1.911 bisitz 6900: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6901: ol#LC_PathBreadcrumbs {
1.911 bisitz 6902: padding-left: 10px;
6903: margin: 0;
1.933 droeschl 6904: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6905: }
6906:
1.911 bisitz 6907: ol#LC_MenuBreadcrumbs li,
6908: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6909: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6910: display: inline;
1.933 droeschl 6911: white-space: normal;
1.693 droeschl 6912: }
6913:
1.823 bisitz 6914: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6915: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6916: text-decoration: none;
6917: font-size:90%;
1.693 droeschl 6918: }
1.795 www 6919:
1.969 droeschl 6920: ol#LC_MenuBreadcrumbs h1 {
6921: display: inline;
6922: font-size: 90%;
6923: line-height: 2.5em;
6924: margin: 0;
6925: padding: 0;
6926: }
6927:
1.795 www 6928: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6929: text-decoration:none;
6930: font-size:100%;
6931: font-weight:bold;
1.693 droeschl 6932: }
1.795 www 6933:
1.840 bisitz 6934: .LC_Box {
1.911 bisitz 6935: border: solid 1px $lg_border_color;
6936: padding: 0 10px 10px 10px;
1.746 neumanie 6937: }
1.795 www 6938:
1.1020 raeburn 6939: .LC_DocsBox {
6940: border: solid 1px $lg_border_color;
6941: padding: 0 0 10px 10px;
6942: }
6943:
1.795 www 6944: .LC_AboutMe_Image {
1.911 bisitz 6945: float:left;
6946: margin-right:10px;
1.747 neumanie 6947: }
1.795 www 6948:
6949: .LC_Clear_AboutMe_Image {
1.911 bisitz 6950: clear:left;
1.747 neumanie 6951: }
1.795 www 6952:
1.721 harmsja 6953: dl.LC_ListStyleClean dt {
1.911 bisitz 6954: padding-right: 5px;
6955: display: table-header-group;
1.693 droeschl 6956: }
6957:
1.721 harmsja 6958: dl.LC_ListStyleClean dd {
1.911 bisitz 6959: display: table-row;
1.693 droeschl 6960: }
6961:
1.721 harmsja 6962: .LC_ListStyleClean,
6963: .LC_ListStyleSimple,
6964: .LC_ListStyleNormal,
1.795 www 6965: .LC_ListStyleSpecial {
1.911 bisitz 6966: /* display:block; */
6967: list-style-position: inside;
6968: list-style-type: none;
6969: overflow: hidden;
6970: padding: 0;
1.693 droeschl 6971: }
6972:
1.721 harmsja 6973: .LC_ListStyleSimple li,
6974: .LC_ListStyleSimple dd,
6975: .LC_ListStyleNormal li,
6976: .LC_ListStyleNormal dd,
6977: .LC_ListStyleSpecial li,
1.795 www 6978: .LC_ListStyleSpecial dd {
1.911 bisitz 6979: margin: 0;
6980: padding: 5px 5px 5px 10px;
6981: clear: both;
1.693 droeschl 6982: }
6983:
1.721 harmsja 6984: .LC_ListStyleClean li,
6985: .LC_ListStyleClean dd {
1.911 bisitz 6986: padding-top: 0;
6987: padding-bottom: 0;
1.693 droeschl 6988: }
6989:
1.721 harmsja 6990: .LC_ListStyleSimple dd,
1.795 www 6991: .LC_ListStyleSimple li {
1.911 bisitz 6992: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6993: }
6994:
1.721 harmsja 6995: .LC_ListStyleSpecial li,
6996: .LC_ListStyleSpecial dd {
1.911 bisitz 6997: list-style-type: none;
6998: background-color: RGB(220, 220, 220);
6999: margin-bottom: 4px;
1.693 droeschl 7000: }
7001:
1.721 harmsja 7002: table.LC_SimpleTable {
1.911 bisitz 7003: margin:5px;
7004: border:solid 1px $lg_border_color;
1.795 www 7005: }
1.693 droeschl 7006:
1.721 harmsja 7007: table.LC_SimpleTable tr {
1.911 bisitz 7008: padding: 0;
7009: border:solid 1px $lg_border_color;
1.693 droeschl 7010: }
1.795 www 7011:
7012: table.LC_SimpleTable thead {
1.911 bisitz 7013: background:rgb(220,220,220);
1.693 droeschl 7014: }
7015:
1.721 harmsja 7016: div.LC_columnSection {
1.911 bisitz 7017: display: block;
7018: clear: both;
7019: overflow: hidden;
7020: margin: 0;
1.693 droeschl 7021: }
7022:
1.721 harmsja 7023: div.LC_columnSection>* {
1.911 bisitz 7024: float: left;
7025: margin: 10px 20px 10px 0;
7026: overflow:hidden;
1.693 droeschl 7027: }
1.721 harmsja 7028:
1.795 www 7029: table em {
1.911 bisitz 7030: font-weight: bold;
7031: font-style: normal;
1.748 schulted 7032: }
1.795 www 7033:
1.779 bisitz 7034: table.LC_tableBrowseRes,
1.795 www 7035: table.LC_tableOfContent {
1.911 bisitz 7036: border:none;
7037: border-spacing: 1px;
7038: padding: 3px;
7039: background-color: #FFFFFF;
7040: font-size: 90%;
1.753 droeschl 7041: }
1.789 droeschl 7042:
1.911 bisitz 7043: table.LC_tableOfContent {
7044: border-collapse: collapse;
1.789 droeschl 7045: }
7046:
1.771 droeschl 7047: table.LC_tableBrowseRes a,
1.768 schulted 7048: table.LC_tableOfContent a {
1.911 bisitz 7049: background-color: transparent;
7050: text-decoration: none;
1.753 droeschl 7051: }
7052:
1.795 www 7053: table.LC_tableOfContent img {
1.911 bisitz 7054: border: none;
7055: height: 1.3em;
7056: vertical-align: text-bottom;
7057: margin-right: 0.3em;
1.753 droeschl 7058: }
1.757 schulted 7059:
1.795 www 7060: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7061: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7062: }
7063:
1.795 www 7064: a#LC_content_toolbar_everything {
1.911 bisitz 7065: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7066: }
7067:
1.795 www 7068: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7069: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7070: }
7071:
1.795 www 7072: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7073: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7074: }
7075:
1.795 www 7076: a#LC_content_toolbar_changefolder {
1.911 bisitz 7077: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7078: }
7079:
1.795 www 7080: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7081: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7082: }
7083:
1.1043 raeburn 7084: a#LC_content_toolbar_edittoplevel {
7085: background-image:url(/res/adm/pages/edittoplevel.gif);
7086: }
7087:
1.795 www 7088: ul#LC_toolbar li a:hover {
1.911 bisitz 7089: background-position: bottom center;
1.757 schulted 7090: }
7091:
1.795 www 7092: ul#LC_toolbar {
1.911 bisitz 7093: padding: 0;
7094: margin: 2px;
7095: list-style:none;
7096: position:relative;
7097: background-color:white;
1.1075.2.9 raeburn 7098: overflow: auto;
1.757 schulted 7099: }
7100:
1.795 www 7101: ul#LC_toolbar li {
1.911 bisitz 7102: border:1px solid white;
7103: padding: 0;
7104: margin: 0;
7105: float: left;
7106: display:inline;
7107: vertical-align:middle;
1.1075.2.9 raeburn 7108: white-space: nowrap;
1.911 bisitz 7109: }
1.757 schulted 7110:
1.783 amueller 7111:
1.795 www 7112: a.LC_toolbarItem {
1.911 bisitz 7113: display:block;
7114: padding: 0;
7115: margin: 0;
7116: height: 32px;
7117: width: 32px;
7118: color:white;
7119: border: none;
7120: background-repeat:no-repeat;
7121: background-color:transparent;
1.757 schulted 7122: }
7123:
1.915 droeschl 7124: ul.LC_funclist {
7125: margin: 0;
7126: padding: 0.5em 1em 0.5em 0;
7127: }
7128:
1.933 droeschl 7129: ul.LC_funclist > li:first-child {
7130: font-weight:bold;
7131: margin-left:0.8em;
7132: }
7133:
1.915 droeschl 7134: ul.LC_funclist + ul.LC_funclist {
7135: /*
7136: left border as a seperator if we have more than
7137: one list
7138: */
7139: border-left: 1px solid $sidebg;
7140: /*
7141: this hides the left border behind the border of the
7142: outer box if element is wrapped to the next 'line'
7143: */
7144: margin-left: -1px;
7145: }
7146:
1.843 bisitz 7147: ul.LC_funclist li {
1.915 droeschl 7148: display: inline;
1.782 bisitz 7149: white-space: nowrap;
1.915 droeschl 7150: margin: 0 0 0 25px;
7151: line-height: 150%;
1.782 bisitz 7152: }
7153:
1.974 wenzelju 7154: .LC_hidden {
7155: display: none;
7156: }
7157:
1.1030 www 7158: .LCmodal-overlay {
7159: position:fixed;
7160: top:0;
7161: right:0;
7162: bottom:0;
7163: left:0;
7164: height:100%;
7165: width:100%;
7166: margin:0;
7167: padding:0;
7168: background:#999;
7169: opacity:.75;
7170: filter: alpha(opacity=75);
7171: -moz-opacity: 0.75;
7172: z-index:101;
7173: }
7174:
7175: * html .LCmodal-overlay {
7176: position: absolute;
7177: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7178: }
7179:
7180: .LCmodal-window {
7181: position:fixed;
7182: top:50%;
7183: left:50%;
7184: margin:0;
7185: padding:0;
7186: z-index:102;
7187: }
7188:
7189: * html .LCmodal-window {
7190: position:absolute;
7191: }
7192:
7193: .LCclose-window {
7194: position:absolute;
7195: width:32px;
7196: height:32px;
7197: right:8px;
7198: top:8px;
7199: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7200: text-indent:-99999px;
7201: overflow:hidden;
7202: cursor:pointer;
7203: }
7204:
1.1075.2.17 raeburn 7205: /*
7206: styles used by TTH when "Default set of options to pass to tth/m
7207: when converting TeX" in course settings has been set
7208:
7209: option passed: -t
7210:
7211: */
7212:
7213: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7214: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7215: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7216: td div.norm {line-height:normal;}
7217:
7218: /*
7219: option passed -y3
7220: */
7221:
7222: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7223: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7224: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7225:
1.343 albertel 7226: END
7227: }
7228:
1.306 albertel 7229: =pod
7230:
7231: =item * &headtag()
7232:
7233: Returns a uniform footer for LON-CAPA web pages.
7234:
1.307 albertel 7235: Inputs: $title - optional title for the head
7236: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7237: $args - optional arguments
1.319 albertel 7238: force_register - if is true call registerurl so the remote is
7239: informed
1.415 albertel 7240: redirect -> array ref of
7241: 1- seconds before redirect occurs
7242: 2- url to redirect to
7243: 3- whether the side effect should occur
1.315 albertel 7244: (side effect of setting
7245: $env{'internal.head.redirect'} to the url
7246: redirected too)
1.352 albertel 7247: domain -> force to color decorate a page for a specific
7248: domain
7249: function -> force usage of a specific rolish color scheme
7250: bgcolor -> override the default page bgcolor
1.460 albertel 7251: no_auto_mt_title
7252: -> prevent &mt()ing the title arg
1.464 albertel 7253:
1.306 albertel 7254: =cut
7255:
7256: sub headtag {
1.313 albertel 7257: my ($title,$head_extra,$args) = @_;
1.306 albertel 7258:
1.363 albertel 7259: my $function = $args->{'function'} || &get_users_function();
7260: my $domain = $args->{'domain'} || &determinedomain();
7261: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7262: my $httphost = $args->{'use_absolute'};
1.418 albertel 7263: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7264: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7265: #time(),
1.418 albertel 7266: $env{'environment.color.timestamp'},
1.363 albertel 7267: $function,$domain,$bgcolor);
7268:
1.369 www 7269: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7270:
1.308 albertel 7271: my $result =
7272: '<head>'.
1.1075.2.56 raeburn 7273: &font_settings($args);
1.319 albertel 7274:
1.1064 raeburn 7275: my $inhibitprint = &print_suppression();
7276:
1.461 albertel 7277: if (!$args->{'frameset'}) {
7278: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7279: }
1.1075.2.12 raeburn 7280: if ($args->{'force_register'}) {
7281: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7282: }
1.436 albertel 7283: if (!$args->{'no_nav_bar'}
7284: && !$args->{'only_body'}
7285: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7286: $result .= &help_menu_js($httphost);
1.1032 www 7287: $result.=&modal_window();
1.1038 www 7288: $result.=&togglebox_script();
1.1034 www 7289: $result.=&wishlist_window();
1.1041 www 7290: $result.=&LCprogressbarUpdate_script();
1.1034 www 7291: } else {
7292: if ($args->{'add_modal'}) {
7293: $result.=&modal_window();
7294: }
7295: if ($args->{'add_wishlist'}) {
7296: $result.=&wishlist_window();
7297: }
1.1038 www 7298: if ($args->{'add_togglebox'}) {
7299: $result.=&togglebox_script();
7300: }
1.1041 www 7301: if ($args->{'add_progressbar'}) {
7302: $result.=&LCprogressbarUpdate_script();
7303: }
1.436 albertel 7304: }
1.314 albertel 7305: if (ref($args->{'redirect'})) {
1.414 albertel 7306: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7307: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7308: if (!$inhibit_continue) {
7309: $env{'internal.head.redirect'} = $url;
7310: }
1.313 albertel 7311: $result.=<<ADDMETA
7312: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7313: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7314: ADDMETA
7315: }
1.306 albertel 7316: if (!defined($title)) {
7317: $title = 'The LearningOnline Network with CAPA';
7318: }
1.460 albertel 7319: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7320: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7321: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7322: .$inhibitprint
1.414 albertel 7323: .$head_extra;
1.1075.2.42 raeburn 7324: if ($env{'browser.mobile'}) {
7325: $result .= '
7326: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7327: <meta name="apple-mobile-web-app-capable" content="yes" />';
7328: }
1.962 droeschl 7329: return $result.'</head>';
1.306 albertel 7330: }
7331:
7332: =pod
7333:
1.340 albertel 7334: =item * &font_settings()
7335:
7336: Returns neccessary <meta> to set the proper encoding
7337:
1.1075.2.56 raeburn 7338: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7339:
7340: =cut
7341:
7342: sub font_settings {
1.1075.2.56 raeburn 7343: my ($args) = @_;
1.340 albertel 7344: my $headerstring='';
1.1075.2.56 raeburn 7345: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7346: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7347: $headerstring.=
1.1075.2.56 raeburn 7348: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
1.340 albertel 7349: }
7350: return $headerstring;
7351: }
7352:
1.341 albertel 7353: =pod
7354:
1.1064 raeburn 7355: =item * &print_suppression()
7356:
7357: In course context returns css which causes the body to be blank when media="print",
7358: if printout generation is unavailable for the current resource.
7359:
7360: This could be because:
7361:
7362: (a) printstartdate is in the future
7363:
7364: (b) printenddate is in the past
7365:
7366: (c) there is an active exam block with "printout"
7367: functionality blocked
7368:
7369: Users with pav, pfo or evb privileges are exempt.
7370:
7371: Inputs: none
7372:
7373: =cut
7374:
7375:
7376: sub print_suppression {
7377: my $noprint;
7378: if ($env{'request.course.id'}) {
7379: my $scope = $env{'request.course.id'};
7380: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7381: (&Apache::lonnet::allowed('pfo',$scope))) {
7382: return;
7383: }
7384: if ($env{'request.course.sec'} ne '') {
7385: $scope .= "/$env{'request.course.sec'}";
7386: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7387: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7388: return;
1.1064 raeburn 7389: }
7390: }
7391: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7392: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7393: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7394: if ($blocked) {
7395: my $checkrole = "cm./$cdom/$cnum";
7396: if ($env{'request.course.sec'} ne '') {
7397: $checkrole .= "/$env{'request.course.sec'}";
7398: }
7399: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7400: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7401: $noprint = 1;
7402: }
7403: }
7404: unless ($noprint) {
7405: my $symb = &Apache::lonnet::symbread();
7406: if ($symb ne '') {
7407: my $navmap = Apache::lonnavmaps::navmap->new();
7408: if (ref($navmap)) {
7409: my $res = $navmap->getBySymb($symb);
7410: if (ref($res)) {
7411: if (!$res->resprintable()) {
7412: $noprint = 1;
7413: }
7414: }
7415: }
7416: }
7417: }
7418: if ($noprint) {
7419: return <<"ENDSTYLE";
7420: <style type="text/css" media="print">
7421: body { display:none }
7422: </style>
7423: ENDSTYLE
7424: }
7425: }
7426: return;
7427: }
7428:
7429: =pod
7430:
1.341 albertel 7431: =item * &xml_begin()
7432:
7433: Returns the needed doctype and <html>
7434:
7435: Inputs: none
7436:
7437: =cut
7438:
7439: sub xml_begin {
7440: my $output='';
7441:
7442: if ($env{'browser.mathml'}) {
7443: $output='<?xml version="1.0"?>'
7444: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7445: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7446:
7447: # .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >'
7448: .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
7449: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7450: .'xmlns="http://www.w3.org/1999/xhtml">';
7451: } else {
1.1075.2.56 raeburn 7452: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n"
7453: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7454: }
7455: return $output;
7456: }
1.340 albertel 7457:
7458: =pod
7459:
1.306 albertel 7460: =item * &start_page()
7461:
7462: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7463:
1.648 raeburn 7464: Inputs:
7465:
7466: =over 4
7467:
7468: $title - optional title for the page
7469:
7470: $head_extra - optional extra HTML to incude inside the <head>
7471:
7472: $args - additional optional args supported are:
7473:
7474: =over 8
7475:
7476: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7477: arg on
1.814 bisitz 7478: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7479: add_entries -> additional attributes to add to the <body>
7480: domain -> force to color decorate a page for a
1.317 albertel 7481: specific domain
1.648 raeburn 7482: function -> force usage of a specific rolish color
1.317 albertel 7483: scheme
1.648 raeburn 7484: redirect -> see &headtag()
7485: bgcolor -> override the default page bg color
7486: js_ready -> return a string ready for being used in
1.317 albertel 7487: a javascript writeln
1.648 raeburn 7488: html_encode -> return a string ready for being used in
1.320 albertel 7489: a html attribute
1.648 raeburn 7490: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7491: $forcereg arg
1.648 raeburn 7492: frameset -> if true will start with a <frameset>
1.330 albertel 7493: rather than <body>
1.648 raeburn 7494: skip_phases -> hash ref of
1.338 albertel 7495: head -> skip the <html><head> generation
7496: body -> skip all <body> generation
1.1075.2.12 raeburn 7497: no_inline_link -> if true and in remote mode, don't show the
7498: 'Switch To Inline Menu' link
1.648 raeburn 7499: no_auto_mt_title -> prevent &mt()ing the title arg
7500: inherit_jsmath -> when creating popup window in a page,
7501: should it have jsmath forced on by the
7502: current page
1.867 kalberla 7503: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7504: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7505: group -> includes the current group, if page is for a
7506: specific group
1.361 albertel 7507:
1.648 raeburn 7508: =back
1.460 albertel 7509:
1.648 raeburn 7510: =back
1.562 albertel 7511:
1.306 albertel 7512: =cut
7513:
7514: sub start_page {
1.309 albertel 7515: my ($title,$head_extra,$args) = @_;
1.318 albertel 7516: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7517:
1.315 albertel 7518: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7519: my ($result,@advtools);
1.964 droeschl 7520:
1.338 albertel 7521: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7522: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7523: }
7524:
7525: if (! exists($args->{'skip_phases'}{'body'}) ) {
7526: if ($args->{'frameset'}) {
7527: my $attr_string = &make_attr_string($args->{'force_register'},
7528: $args->{'add_entries'});
7529: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7530: } else {
7531: $result .=
7532: &bodytag($title,
7533: $args->{'function'}, $args->{'add_entries'},
7534: $args->{'only_body'}, $args->{'domain'},
7535: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7536: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7537: $args, \@advtools);
1.831 bisitz 7538: }
1.330 albertel 7539: }
1.338 albertel 7540:
1.315 albertel 7541: if ($args->{'js_ready'}) {
1.713 kaisler 7542: $result = &js_ready($result);
1.315 albertel 7543: }
1.320 albertel 7544: if ($args->{'html_encode'}) {
1.713 kaisler 7545: $result = &html_encode($result);
7546: }
7547:
1.813 bisitz 7548: # Preparation for new and consistent functionlist at top of screen
7549: # if ($args->{'functionlist'}) {
7550: # $result .= &build_functionlist();
7551: #}
7552:
1.964 droeschl 7553: # Don't add anything more if only_body wanted or in const space
7554: return $result if $args->{'only_body'}
7555: || $env{'request.state'} eq 'construct';
1.813 bisitz 7556:
7557: #Breadcrumbs
1.758 kaisler 7558: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7559: &Apache::lonhtmlcommon::clear_breadcrumbs();
7560: #if any br links exists, add them to the breadcrumbs
7561: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7562: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7563: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7564: }
7565: }
1.1075.2.19 raeburn 7566: # if @advtools array contains items add then to the breadcrumbs
7567: if (@advtools > 0) {
7568: &Apache::lonmenu::advtools_crumbs(@advtools);
7569: }
1.758 kaisler 7570:
7571: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7572: if(exists($args->{'bread_crumbs_component'})){
7573: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7574: }else{
7575: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7576: }
1.1075.2.24 raeburn 7577: } elsif (($env{'environment.remote'} eq 'on') &&
7578: ($env{'form.inhibitmenu'} ne 'yes') &&
7579: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7580: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7581: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7582: }
1.315 albertel 7583: return $result;
1.306 albertel 7584: }
7585:
7586: sub end_page {
1.315 albertel 7587: my ($args) = @_;
7588: $env{'internal.end_page'}++;
1.330 albertel 7589: my $result;
1.335 albertel 7590: if ($args->{'discussion'}) {
7591: my ($target,$parser);
7592: if (ref($args->{'discussion'})) {
7593: ($target,$parser) =($args->{'discussion'}{'target'},
7594: $args->{'discussion'}{'parser'});
7595: }
7596: $result .= &Apache::lonxml::xmlend($target,$parser);
7597: }
1.330 albertel 7598: if ($args->{'frameset'}) {
7599: $result .= '</frameset>';
7600: } else {
1.635 raeburn 7601: $result .= &endbodytag($args);
1.330 albertel 7602: }
1.1075.2.6 raeburn 7603: unless ($args->{'notbody'}) {
7604: $result .= "\n</html>";
7605: }
1.330 albertel 7606:
1.315 albertel 7607: if ($args->{'js_ready'}) {
1.317 albertel 7608: $result = &js_ready($result);
1.315 albertel 7609: }
1.335 albertel 7610:
1.320 albertel 7611: if ($args->{'html_encode'}) {
7612: $result = &html_encode($result);
7613: }
1.335 albertel 7614:
1.315 albertel 7615: return $result;
7616: }
7617:
1.1034 www 7618: sub wishlist_window {
7619: return(<<'ENDWISHLIST');
1.1046 raeburn 7620: <script type="text/javascript">
1.1034 www 7621: // <![CDATA[
7622: // <!-- BEGIN LON-CAPA Internal
7623: function set_wishlistlink(title, path) {
7624: if (!title) {
7625: title = document.title;
7626: title = title.replace(/^LON-CAPA /,'');
7627: }
7628: if (!path) {
7629: path = location.pathname;
7630: }
7631: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7632: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7633: }
7634: // END LON-CAPA Internal -->
7635: // ]]>
7636: </script>
7637: ENDWISHLIST
7638: }
7639:
1.1030 www 7640: sub modal_window {
7641: return(<<'ENDMODAL');
1.1046 raeburn 7642: <script type="text/javascript">
1.1030 www 7643: // <![CDATA[
7644: // <!-- BEGIN LON-CAPA Internal
7645: var modalWindow = {
7646: parent:"body",
7647: windowId:null,
7648: content:null,
7649: width:null,
7650: height:null,
7651: close:function()
7652: {
7653: $(".LCmodal-window").remove();
7654: $(".LCmodal-overlay").remove();
7655: },
7656: open:function()
7657: {
7658: var modal = "";
7659: modal += "<div class=\"LCmodal-overlay\"></div>";
7660: modal += "<div id=\"" + this.windowId + "\" class=\"LCmodal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
7661: modal += this.content;
7662: modal += "</div>";
7663:
7664: $(this.parent).append(modal);
7665:
7666: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7667: $(".LCclose-window").click(function(){modalWindow.close();});
7668: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7669: }
7670: };
1.1075.2.42 raeburn 7671: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7672: {
7673: modalWindow.windowId = "myModal";
7674: modalWindow.width = width;
7675: modalWindow.height = height;
1.1075.2.42 raeburn 7676: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7677: modalWindow.open();
7678: };
7679: // END LON-CAPA Internal -->
7680: // ]]>
7681: </script>
7682: ENDMODAL
7683: }
7684:
7685: sub modal_link {
1.1075.2.42 raeburn 7686: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7687: unless ($width) { $width=480; }
7688: unless ($height) { $height=400; }
1.1031 www 7689: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7690: unless ($transparency) { $transparency='true'; }
7691:
1.1074 raeburn 7692: my $target_attr;
7693: if (defined($target)) {
7694: $target_attr = 'target="'.$target.'"';
7695: }
7696: return <<"ENDLINK";
1.1075.2.42 raeburn 7697: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7698: $linktext</a>
7699: ENDLINK
1.1030 www 7700: }
7701:
1.1032 www 7702: sub modal_adhoc_script {
7703: my ($funcname,$width,$height,$content)=@_;
7704: return (<<ENDADHOC);
1.1046 raeburn 7705: <script type="text/javascript">
1.1032 www 7706: // <![CDATA[
7707: var $funcname = function()
7708: {
7709: modalWindow.windowId = "myModal";
7710: modalWindow.width = $width;
7711: modalWindow.height = $height;
7712: modalWindow.content = '$content';
7713: modalWindow.open();
7714: };
7715: // ]]>
7716: </script>
7717: ENDADHOC
7718: }
7719:
1.1041 www 7720: sub modal_adhoc_inner {
7721: my ($funcname,$width,$height,$content)=@_;
7722: my $innerwidth=$width-20;
7723: $content=&js_ready(
1.1042 www 7724: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7725: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7726: $content.
1.1041 www 7727: &end_scrollbox().
1.1075.2.42 raeburn 7728: &end_page()
1.1041 www 7729: );
7730: return &modal_adhoc_script($funcname,$width,$height,$content);
7731: }
7732:
7733: sub modal_adhoc_window {
7734: my ($funcname,$width,$height,$content,$linktext)=@_;
7735: return &modal_adhoc_inner($funcname,$width,$height,$content).
7736: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7737: }
7738:
7739: sub modal_adhoc_launch {
7740: my ($funcname,$width,$height,$content)=@_;
7741: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7742: <script type="text/javascript">
7743: // <![CDATA[
7744: $funcname();
7745: // ]]>
7746: </script>
7747: ENDLAUNCH
7748: }
7749:
7750: sub modal_adhoc_close {
7751: return (<<ENDCLOSE);
7752: <script type="text/javascript">
7753: // <![CDATA[
7754: modalWindow.close();
7755: // ]]>
7756: </script>
7757: ENDCLOSE
7758: }
7759:
1.1038 www 7760: sub togglebox_script {
7761: return(<<ENDTOGGLE);
7762: <script type="text/javascript">
7763: // <![CDATA[
7764: function LCtoggleDisplay(id,hidetext,showtext) {
7765: link = document.getElementById(id + "link").childNodes[0];
7766: with (document.getElementById(id).style) {
7767: if (display == "none" ) {
7768: display = "inline";
7769: link.nodeValue = hidetext;
7770: } else {
7771: display = "none";
7772: link.nodeValue = showtext;
7773: }
7774: }
7775: }
7776: // ]]>
7777: </script>
7778: ENDTOGGLE
7779: }
7780:
1.1039 www 7781: sub start_togglebox {
7782: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7783: unless ($heading) { $heading=''; } else { $heading.=' '; }
7784: unless ($showtext) { $showtext=&mt('show'); }
7785: unless ($hidetext) { $hidetext=&mt('hide'); }
7786: unless ($headerbg) { $headerbg='#FFFFFF'; }
7787: return &start_data_table().
7788: &start_data_table_header_row().
7789: '<td bgcolor="'.$headerbg.'">'.$heading.
7790: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7791: $showtext.'\')">'.$showtext.'</a>]</td>'.
7792: &end_data_table_header_row().
7793: '<tr id="'.$id.'" style="display:none""><td>';
7794: }
7795:
7796: sub end_togglebox {
7797: return '</td></tr>'.&end_data_table();
7798: }
7799:
1.1041 www 7800: sub LCprogressbar_script {
1.1045 www 7801: my ($id)=@_;
1.1041 www 7802: return(<<ENDPROGRESS);
7803: <script type="text/javascript">
7804: // <![CDATA[
1.1045 www 7805: \$('#progressbar$id').progressbar({
1.1041 www 7806: value: 0,
7807: change: function(event, ui) {
7808: var newVal = \$(this).progressbar('option', 'value');
7809: \$('.pblabel', this).text(LCprogressTxt);
7810: }
7811: });
7812: // ]]>
7813: </script>
7814: ENDPROGRESS
7815: }
7816:
7817: sub LCprogressbarUpdate_script {
7818: return(<<ENDPROGRESSUPDATE);
7819: <style type="text/css">
7820: .ui-progressbar { position:relative; }
7821: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7822: </style>
7823: <script type="text/javascript">
7824: // <![CDATA[
1.1045 www 7825: var LCprogressTxt='---';
7826:
7827: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7828: LCprogressTxt=progresstext;
1.1045 www 7829: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7830: }
7831: // ]]>
7832: </script>
7833: ENDPROGRESSUPDATE
7834: }
7835:
1.1042 www 7836: my $LClastpercent;
1.1045 www 7837: my $LCidcnt;
7838: my $LCcurrentid;
1.1042 www 7839:
1.1041 www 7840: sub LCprogressbar {
1.1042 www 7841: my ($r)=(@_);
7842: $LClastpercent=0;
1.1045 www 7843: $LCidcnt++;
7844: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7845: my $starting=&mt('Starting');
7846: my $content=(<<ENDPROGBAR);
1.1045 www 7847: <div id="progressbar$LCcurrentid">
1.1041 www 7848: <span class="pblabel">$starting</span>
7849: </div>
7850: ENDPROGBAR
1.1045 www 7851: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7852: }
7853:
7854: sub LCprogressbarUpdate {
1.1042 www 7855: my ($r,$val,$text)=@_;
7856: unless ($val) {
7857: if ($LClastpercent) {
7858: $val=$LClastpercent;
7859: } else {
7860: $val=0;
7861: }
7862: }
1.1041 www 7863: if ($val<0) { $val=0; }
7864: if ($val>100) { $val=0; }
1.1042 www 7865: $LClastpercent=$val;
1.1041 www 7866: unless ($text) { $text=$val.'%'; }
7867: $text=&js_ready($text);
1.1044 www 7868: &r_print($r,<<ENDUPDATE);
1.1041 www 7869: <script type="text/javascript">
7870: // <![CDATA[
1.1045 www 7871: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7872: // ]]>
7873: </script>
7874: ENDUPDATE
1.1035 www 7875: }
7876:
1.1042 www 7877: sub LCprogressbarClose {
7878: my ($r)=@_;
7879: $LClastpercent=0;
1.1044 www 7880: &r_print($r,<<ENDCLOSE);
1.1042 www 7881: <script type="text/javascript">
7882: // <![CDATA[
1.1045 www 7883: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7884: // ]]>
7885: </script>
7886: ENDCLOSE
1.1044 www 7887: }
7888:
7889: sub r_print {
7890: my ($r,$to_print)=@_;
7891: if ($r) {
7892: $r->print($to_print);
7893: $r->rflush();
7894: } else {
7895: print($to_print);
7896: }
1.1042 www 7897: }
7898:
1.320 albertel 7899: sub html_encode {
7900: my ($result) = @_;
7901:
1.322 albertel 7902: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7903:
7904: return $result;
7905: }
1.1044 www 7906:
1.317 albertel 7907: sub js_ready {
7908: my ($result) = @_;
7909:
1.323 albertel 7910: $result =~ s/[\n\r]/ /xmsg;
7911: $result =~ s/\\/\\\\/xmsg;
7912: $result =~ s/'/\\'/xmsg;
1.372 albertel 7913: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7914:
7915: return $result;
7916: }
7917:
1.315 albertel 7918: sub validate_page {
7919: if ( exists($env{'internal.start_page'})
1.316 albertel 7920: && $env{'internal.start_page'} > 1) {
7921: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7922: $env{'internal.start_page'}.' '.
1.316 albertel 7923: $ENV{'request.filename'});
1.315 albertel 7924: }
7925: if ( exists($env{'internal.end_page'})
1.316 albertel 7926: && $env{'internal.end_page'} > 1) {
7927: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7928: $env{'internal.end_page'}.' '.
1.316 albertel 7929: $env{'request.filename'});
1.315 albertel 7930: }
7931: if ( exists($env{'internal.start_page'})
7932: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7933: &Apache::lonnet::logthis('start_page called without end_page '.
7934: $env{'request.filename'});
1.315 albertel 7935: }
7936: if ( ! exists($env{'internal.start_page'})
7937: && exists($env{'internal.end_page'})) {
1.316 albertel 7938: &Apache::lonnet::logthis('end_page called without start_page'.
7939: $env{'request.filename'});
1.315 albertel 7940: }
1.306 albertel 7941: }
1.315 albertel 7942:
1.996 www 7943:
7944: sub start_scrollbox {
1.1075.2.56 raeburn 7945: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7946: unless ($outerwidth) { $outerwidth='520px'; }
7947: unless ($width) { $width='500px'; }
7948: unless ($height) { $height='200px'; }
1.1075 raeburn 7949: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7950: if ($id ne '') {
1.1075.2.42 raeburn 7951: $table_id = ' id="table_'.$id.'"';
7952: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7953: }
1.1075 raeburn 7954: if ($bgcolor ne '') {
7955: $tdcol = "background-color: $bgcolor;";
7956: }
1.1075.2.42 raeburn 7957: my $nicescroll_js;
7958: if ($env{'browser.mobile'}) {
7959: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7960: }
1.1075 raeburn 7961: return <<"END";
1.1075.2.42 raeburn 7962: $nicescroll_js
7963:
7964: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 7965: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 7966: END
1.996 www 7967: }
7968:
7969: sub end_scrollbox {
1.1036 www 7970: return '</div></td></tr></table>';
1.996 www 7971: }
7972:
1.1075.2.42 raeburn 7973: sub nicescroll_javascript {
7974: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7975: my %options;
7976: if (ref($cursor) eq 'HASH') {
7977: %options = %{$cursor};
7978: }
7979: unless ($options{'railalign'} =~ /^left|right$/) {
7980: $options{'railalign'} = 'left';
7981: }
7982: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7983: my $function = &get_users_function();
7984: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
7985: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7986: $options{'cursorcolor'} = '#00F';
7987: }
7988: }
7989: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7990: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
7991: $options{'cursoropacity'}='1.0';
7992: }
7993: } else {
7994: $options{'cursoropacity'}='1.0';
7995: }
7996: if ($options{'cursorfixedheight'} eq 'none') {
7997: delete($options{'cursorfixedheight'});
7998: } else {
7999: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8000: }
8001: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8002: delete($options{'railoffset'});
8003: }
8004: my @niceoptions;
8005: while (my($key,$value) = each(%options)) {
8006: if ($value =~ /^\{.+\}$/) {
8007: push(@niceoptions,$key.':'.$value);
8008: } else {
8009: push(@niceoptions,$key.':"'.$value.'"');
8010: }
8011: }
8012: my $nicescroll_js = '
8013: $(document).ready(
8014: function() {
8015: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8016: }
8017: );
8018: ';
8019: if ($framecheck) {
8020: $nicescroll_js .= '
8021: function expand_div(caller) {
8022: if (top === self) {
8023: document.getElementById("'.$id.'").style.width = "auto";
8024: document.getElementById("'.$id.'").style.height = "auto";
8025: } else {
8026: try {
8027: if (parent.frames) {
8028: if (parent.frames.length > 1) {
8029: var framesrc = parent.frames[1].location.href;
8030: var currsrc = framesrc.replace(/\#.*$/,"");
8031: if ((caller == "search") || (currsrc == "'.$location.'")) {
8032: document.getElementById("'.$id.'").style.width = "auto";
8033: document.getElementById("'.$id.'").style.height = "auto";
8034: }
8035: }
8036: }
8037: } catch (e) {
8038: return;
8039: }
8040: }
8041: return;
8042: }
8043: ';
8044: }
8045: if ($needjsready) {
8046: $nicescroll_js = '
8047: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8048: } else {
8049: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8050: }
8051: return $nicescroll_js;
8052: }
8053:
1.318 albertel 8054: sub simple_error_page {
1.1075.2.49 raeburn 8055: my ($r,$title,$msg,$args) = @_;
8056: if (ref($args) eq 'HASH') {
8057: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8058: } else {
8059: $msg = &mt($msg);
8060: }
8061:
1.318 albertel 8062: my $page =
8063: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8064: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8065: &Apache::loncommon::end_page();
8066: if (ref($r)) {
8067: $r->print($page);
1.327 albertel 8068: return;
1.318 albertel 8069: }
8070: return $page;
8071: }
1.347 albertel 8072:
8073: {
1.610 albertel 8074: my @row_count;
1.961 onken 8075:
8076: sub start_data_table_count {
8077: unshift(@row_count, 0);
8078: return;
8079: }
8080:
8081: sub end_data_table_count {
8082: shift(@row_count);
8083: return;
8084: }
8085:
1.347 albertel 8086: sub start_data_table {
1.1018 raeburn 8087: my ($add_class,$id) = @_;
1.422 albertel 8088: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8089: my $table_id;
8090: if (defined($id)) {
8091: $table_id = ' id="'.$id.'"';
8092: }
1.961 onken 8093: &start_data_table_count();
1.1018 raeburn 8094: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8095: }
8096:
8097: sub end_data_table {
1.961 onken 8098: &end_data_table_count();
1.389 albertel 8099: return '</table>'."\n";;
1.347 albertel 8100: }
8101:
8102: sub start_data_table_row {
1.974 wenzelju 8103: my ($add_class, $id) = @_;
1.610 albertel 8104: $row_count[0]++;
8105: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8106: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8107: $id = (' id="'.$id.'"') unless ($id eq '');
8108: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8109: }
1.471 banghart 8110:
8111: sub continue_data_table_row {
1.974 wenzelju 8112: my ($add_class, $id) = @_;
1.610 albertel 8113: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8114: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8115: $id = (' id="'.$id.'"') unless ($id eq '');
8116: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8117: }
1.347 albertel 8118:
8119: sub end_data_table_row {
1.389 albertel 8120: return '</tr>'."\n";;
1.347 albertel 8121: }
1.367 www 8122:
1.421 albertel 8123: sub start_data_table_empty_row {
1.707 bisitz 8124: # $row_count[0]++;
1.421 albertel 8125: return '<tr class="LC_empty_row" >'."\n";;
8126: }
8127:
8128: sub end_data_table_empty_row {
8129: return '</tr>'."\n";;
8130: }
8131:
1.367 www 8132: sub start_data_table_header_row {
1.389 albertel 8133: return '<tr class="LC_header_row">'."\n";;
1.367 www 8134: }
8135:
8136: sub end_data_table_header_row {
1.389 albertel 8137: return '</tr>'."\n";;
1.367 www 8138: }
1.890 droeschl 8139:
8140: sub data_table_caption {
8141: my $caption = shift;
8142: return "<caption class=\"LC_caption\">$caption</caption>";
8143: }
1.347 albertel 8144: }
8145:
1.548 albertel 8146: =pod
8147:
8148: =item * &inhibit_menu_check($arg)
8149:
8150: Checks for a inhibitmenu state and generates output to preserve it
8151:
8152: Inputs: $arg - can be any of
8153: - undef - in which case the return value is a string
8154: to add into arguments list of a uri
8155: - 'input' - in which case the return value is a HTML
8156: <form> <input> field of type hidden to
8157: preserve the value
8158: - a url - in which case the return value is the url with
8159: the neccesary cgi args added to preserve the
8160: inhibitmenu state
8161: - a ref to a url - no return value, but the string is
8162: updated to include the neccessary cgi
8163: args to preserve the inhibitmenu state
8164:
8165: =cut
8166:
8167: sub inhibit_menu_check {
8168: my ($arg) = @_;
8169: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8170: if ($arg eq 'input') {
8171: if ($env{'form.inhibitmenu'}) {
8172: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8173: } else {
8174: return
8175: }
8176: }
8177: if ($env{'form.inhibitmenu'}) {
8178: if (ref($arg)) {
8179: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8180: } elsif ($arg eq '') {
8181: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8182: } else {
8183: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8184: }
8185: }
8186: if (!ref($arg)) {
8187: return $arg;
8188: }
8189: }
8190:
1.251 albertel 8191: ###############################################
1.182 matthew 8192:
8193: =pod
8194:
1.549 albertel 8195: =back
8196:
8197: =head1 User Information Routines
8198:
8199: =over 4
8200:
1.405 albertel 8201: =item * &get_users_function()
1.182 matthew 8202:
8203: Used by &bodytag to determine the current users primary role.
8204: Returns either 'student','coordinator','admin', or 'author'.
8205:
8206: =cut
8207:
8208: ###############################################
8209: sub get_users_function {
1.815 tempelho 8210: my $function = 'norole';
1.818 tempelho 8211: if ($env{'request.role'}=~/^(st)/) {
8212: $function='student';
8213: }
1.907 raeburn 8214: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8215: $function='coordinator';
8216: }
1.258 albertel 8217: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8218: $function='admin';
8219: }
1.826 bisitz 8220: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8221: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8222: $function='author';
8223: }
8224: return $function;
1.54 www 8225: }
1.99 www 8226:
8227: ###############################################
8228:
1.233 raeburn 8229: =pod
8230:
1.821 raeburn 8231: =item * &show_course()
8232:
8233: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8234: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8235:
8236: Inputs:
8237: None
8238:
8239: Outputs:
8240: Scalar: 1 if 'Course' to be used, 0 otherwise.
8241:
8242: =cut
8243:
8244: ###############################################
8245: sub show_course {
8246: my $course = !$env{'user.adv'};
8247: if (!$env{'user.adv'}) {
8248: foreach my $env (keys(%env)) {
8249: next if ($env !~ m/^user\.priv\./);
8250: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8251: $course = 0;
8252: last;
8253: }
8254: }
8255: }
8256: return $course;
8257: }
8258:
8259: ###############################################
8260:
8261: =pod
8262:
1.542 raeburn 8263: =item * &check_user_status()
1.274 raeburn 8264:
8265: Determines current status of supplied role for a
8266: specific user. Roles can be active, previous or future.
8267:
8268: Inputs:
8269: user's domain, user's username, course's domain,
1.375 raeburn 8270: course's number, optional section ID.
1.274 raeburn 8271:
8272: Outputs:
8273: role status: active, previous or future.
8274:
8275: =cut
8276:
8277: sub check_user_status {
1.412 raeburn 8278: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8279: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8280: my @uroles = keys %userinfo;
8281: my $srchstr;
8282: my $active_chk = 'none';
1.412 raeburn 8283: my $now = time;
1.274 raeburn 8284: if (@uroles > 0) {
1.908 raeburn 8285: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8286: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8287: } else {
1.412 raeburn 8288: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8289: }
8290: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8291: my $role_end = 0;
8292: my $role_start = 0;
8293: $active_chk = 'active';
1.412 raeburn 8294: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8295: $role_end = $1;
8296: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8297: $role_start = $1;
1.274 raeburn 8298: }
8299: }
8300: if ($role_start > 0) {
1.412 raeburn 8301: if ($now < $role_start) {
1.274 raeburn 8302: $active_chk = 'future';
8303: }
8304: }
8305: if ($role_end > 0) {
1.412 raeburn 8306: if ($now > $role_end) {
1.274 raeburn 8307: $active_chk = 'previous';
8308: }
8309: }
8310: }
8311: }
8312: return $active_chk;
8313: }
8314:
8315: ###############################################
8316:
8317: =pod
8318:
1.405 albertel 8319: =item * &get_sections()
1.233 raeburn 8320:
8321: Determines all the sections for a course including
8322: sections with students and sections containing other roles.
1.419 raeburn 8323: Incoming parameters:
8324:
8325: 1. domain
8326: 2. course number
8327: 3. reference to array containing roles for which sections should
8328: be gathered (optional).
8329: 4. reference to array containing status types for which sections
8330: should be gathered (optional).
8331:
8332: If the third argument is undefined, sections are gathered for any role.
8333: If the fourth argument is undefined, sections are gathered for any status.
8334: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8335:
1.374 raeburn 8336: Returns section hash (keys are section IDs, values are
8337: number of users in each section), subject to the
1.419 raeburn 8338: optional roles filter, optional status filter
1.233 raeburn 8339:
8340: =cut
8341:
8342: ###############################################
8343: sub get_sections {
1.419 raeburn 8344: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8345: if (!defined($cdom) || !defined($cnum)) {
8346: my $cid = $env{'request.course.id'};
8347:
8348: return if (!defined($cid));
8349:
8350: $cdom = $env{'course.'.$cid.'.domain'};
8351: $cnum = $env{'course.'.$cid.'.num'};
8352: }
8353:
8354: my %sectioncount;
1.419 raeburn 8355: my $now = time;
1.240 albertel 8356:
1.1075.2.33 raeburn 8357: my $check_students = 1;
8358: my $only_students = 0;
8359: if (ref($possible_roles) eq 'ARRAY') {
8360: if (grep(/^st$/,@{$possible_roles})) {
8361: if (@{$possible_roles} == 1) {
8362: $only_students = 1;
8363: }
8364: } else {
8365: $check_students = 0;
8366: }
8367: }
8368:
8369: if ($check_students) {
1.276 albertel 8370: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8371: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8372: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8373: my $start_index = &Apache::loncoursedata::CL_START();
8374: my $end_index = &Apache::loncoursedata::CL_END();
8375: my $status;
1.366 albertel 8376: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8377: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8378: $data->[$status_index],
8379: $data->[$start_index],
8380: $data->[$end_index]);
8381: if ($stu_status eq 'Active') {
8382: $status = 'active';
8383: } elsif ($end < $now) {
8384: $status = 'previous';
8385: } elsif ($start > $now) {
8386: $status = 'future';
8387: }
8388: if ($section ne '-1' && $section !~ /^\s*$/) {
8389: if ((!defined($possible_status)) || (($status ne '') &&
8390: (grep/^\Q$status\E$/,@{$possible_status}))) {
8391: $sectioncount{$section}++;
8392: }
1.240 albertel 8393: }
8394: }
8395: }
1.1075.2.33 raeburn 8396: if ($only_students) {
8397: return %sectioncount;
8398: }
1.240 albertel 8399: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8400: foreach my $user (sort(keys(%courseroles))) {
8401: if ($user !~ /^(\w{2})/) { next; }
8402: my ($role) = ($user =~ /^(\w{2})/);
8403: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8404: my ($section,$status);
1.240 albertel 8405: if ($role eq 'cr' &&
8406: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8407: $section=$1;
8408: }
8409: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8410: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8411: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8412: if ($end == -1 && $start == -1) {
8413: next; #deleted role
8414: }
8415: if (!defined($possible_status)) {
8416: $sectioncount{$section}++;
8417: } else {
8418: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8419: $status = 'active';
8420: } elsif ($end < $now) {
8421: $status = 'future';
8422: } elsif ($start > $now) {
8423: $status = 'previous';
8424: }
8425: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8426: $sectioncount{$section}++;
8427: }
8428: }
1.233 raeburn 8429: }
1.366 albertel 8430: return %sectioncount;
1.233 raeburn 8431: }
8432:
1.274 raeburn 8433: ###############################################
1.294 raeburn 8434:
8435: =pod
1.405 albertel 8436:
8437: =item * &get_course_users()
8438:
1.275 raeburn 8439: Retrieves usernames:domains for users in the specified course
8440: with specific role(s), and access status.
8441:
8442: Incoming parameters:
1.277 albertel 8443: 1. course domain
8444: 2. course number
8445: 3. access status: users must have - either active,
1.275 raeburn 8446: previous, future, or all.
1.277 albertel 8447: 4. reference to array of permissible roles
1.288 raeburn 8448: 5. reference to array of section restrictions (optional)
8449: 6. reference to results object (hash of hashes).
8450: 7. reference to optional userdata hash
1.609 raeburn 8451: 8. reference to optional statushash
1.630 raeburn 8452: 9. flag if privileged users (except those set to unhide in
8453: course settings) should be excluded
1.609 raeburn 8454: Keys of top level results hash are roles.
1.275 raeburn 8455: Keys of inner hashes are username:domain, with
8456: values set to access type.
1.288 raeburn 8457: Optional userdata hash returns an array with arguments in the
8458: same order as loncoursedata::get_classlist() for student data.
8459:
1.609 raeburn 8460: Optional statushash returns
8461:
1.288 raeburn 8462: Entries for end, start, section and status are blank because
8463: of the possibility of multiple values for non-student roles.
8464:
1.275 raeburn 8465: =cut
1.405 albertel 8466:
1.275 raeburn 8467: ###############################################
1.405 albertel 8468:
1.275 raeburn 8469: sub get_course_users {
1.630 raeburn 8470: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8471: my %idx = ();
1.419 raeburn 8472: my %seclists;
1.288 raeburn 8473:
8474: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8475: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8476: $idx{end} = &Apache::loncoursedata::CL_END();
8477: $idx{start} = &Apache::loncoursedata::CL_START();
8478: $idx{id} = &Apache::loncoursedata::CL_ID();
8479: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8480: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8481: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8482:
1.290 albertel 8483: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8484: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8485: my $now = time;
1.277 albertel 8486: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8487: my $match = 0;
1.412 raeburn 8488: my $secmatch = 0;
1.419 raeburn 8489: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8490: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8491: if ($section eq '') {
8492: $section = 'none';
8493: }
1.291 albertel 8494: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8495: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8496: $secmatch = 1;
8497: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8498: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8499: $secmatch = 1;
8500: }
8501: } else {
1.419 raeburn 8502: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8503: $secmatch = 1;
8504: }
1.290 albertel 8505: }
1.412 raeburn 8506: if (!$secmatch) {
8507: next;
8508: }
1.419 raeburn 8509: }
1.275 raeburn 8510: if (defined($$types{'active'})) {
1.288 raeburn 8511: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8512: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8513: $match = 1;
1.275 raeburn 8514: }
8515: }
8516: if (defined($$types{'previous'})) {
1.609 raeburn 8517: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8518: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8519: $match = 1;
1.275 raeburn 8520: }
8521: }
8522: if (defined($$types{'future'})) {
1.609 raeburn 8523: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8524: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8525: $match = 1;
1.275 raeburn 8526: }
8527: }
1.609 raeburn 8528: if ($match) {
8529: push(@{$seclists{$student}},$section);
8530: if (ref($userdata) eq 'HASH') {
8531: $$userdata{$student} = $$classlist{$student};
8532: }
8533: if (ref($statushash) eq 'HASH') {
8534: $statushash->{$student}{'st'}{$section} = $status;
8535: }
1.288 raeburn 8536: }
1.275 raeburn 8537: }
8538: }
1.412 raeburn 8539: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8540: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8541: my $now = time;
1.609 raeburn 8542: my %displaystatus = ( previous => 'Expired',
8543: active => 'Active',
8544: future => 'Future',
8545: );
1.1075.2.36 raeburn 8546: my (%nothide,@possdoms);
1.630 raeburn 8547: if ($hidepriv) {
8548: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8549: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8550: if ($user !~ /:/) {
8551: $nothide{join(':',split(/[\@]/,$user))}=1;
8552: } else {
8553: $nothide{$user} = 1;
8554: }
8555: }
1.1075.2.36 raeburn 8556: my @possdoms = ($cdom);
8557: if ($coursehash{'checkforpriv'}) {
8558: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8559: }
1.630 raeburn 8560: }
1.439 raeburn 8561: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8562: my $match = 0;
1.412 raeburn 8563: my $secmatch = 0;
1.439 raeburn 8564: my $status;
1.412 raeburn 8565: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8566: $user =~ s/:$//;
1.439 raeburn 8567: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8568: if ($end == -1 || $start == -1) {
8569: next;
8570: }
8571: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8572: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8573: my ($uname,$udom) = split(/:/,$user);
8574: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8575: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8576: $secmatch = 1;
8577: } elsif ($usec eq '') {
1.420 albertel 8578: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8579: $secmatch = 1;
8580: }
8581: } else {
8582: if (grep(/^\Q$usec\E$/,@{$sections})) {
8583: $secmatch = 1;
8584: }
8585: }
8586: if (!$secmatch) {
8587: next;
8588: }
1.288 raeburn 8589: }
1.419 raeburn 8590: if ($usec eq '') {
8591: $usec = 'none';
8592: }
1.275 raeburn 8593: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8594: if ($hidepriv) {
1.1075.2.36 raeburn 8595: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8596: (!$nothide{$uname.':'.$udom})) {
8597: next;
8598: }
8599: }
1.503 raeburn 8600: if ($end > 0 && $end < $now) {
1.439 raeburn 8601: $status = 'previous';
8602: } elsif ($start > $now) {
8603: $status = 'future';
8604: } else {
8605: $status = 'active';
8606: }
1.277 albertel 8607: foreach my $type (keys(%{$types})) {
1.275 raeburn 8608: if ($status eq $type) {
1.420 albertel 8609: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8610: push(@{$$users{$role}{$user}},$type);
8611: }
1.288 raeburn 8612: $match = 1;
8613: }
8614: }
1.419 raeburn 8615: if (($match) && (ref($userdata) eq 'HASH')) {
8616: if (!exists($$userdata{$uname.':'.$udom})) {
8617: &get_user_info($udom,$uname,\%idx,$userdata);
8618: }
1.420 albertel 8619: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8620: push(@{$seclists{$uname.':'.$udom}},$usec);
8621: }
1.609 raeburn 8622: if (ref($statushash) eq 'HASH') {
8623: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8624: }
1.275 raeburn 8625: }
8626: }
8627: }
8628: }
1.290 albertel 8629: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8630: if ((defined($cdom)) && (defined($cnum))) {
8631: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8632: if ( defined($csettings{'internal.courseowner'}) ) {
8633: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8634: next if ($owner eq '');
8635: my ($ownername,$ownerdom);
8636: if ($owner =~ /^([^:]+):([^:]+)$/) {
8637: $ownername = $1;
8638: $ownerdom = $2;
8639: } else {
8640: $ownername = $owner;
8641: $ownerdom = $cdom;
8642: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8643: }
8644: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8645: if (defined($userdata) &&
1.609 raeburn 8646: !exists($$userdata{$owner})) {
8647: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8648: if (!grep(/^none$/,@{$seclists{$owner}})) {
8649: push(@{$seclists{$owner}},'none');
8650: }
8651: if (ref($statushash) eq 'HASH') {
8652: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8653: }
1.290 albertel 8654: }
1.279 raeburn 8655: }
8656: }
8657: }
1.419 raeburn 8658: foreach my $user (keys(%seclists)) {
8659: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8660: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8661: }
1.275 raeburn 8662: }
8663: return;
8664: }
8665:
1.288 raeburn 8666: sub get_user_info {
8667: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8668: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8669: &plainname($uname,$udom,'lastname');
1.291 albertel 8670: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8671: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8672: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8673: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8674: return;
8675: }
1.275 raeburn 8676:
1.472 raeburn 8677: ###############################################
8678:
8679: =pod
8680:
8681: =item * &get_user_quota()
8682:
1.1075.2.41 raeburn 8683: Retrieves quota assigned for storage of user files.
8684: Default is to report quota for portfolio files.
1.472 raeburn 8685:
8686: Incoming parameters:
8687: 1. user's username
8688: 2. user's domain
1.1075.2.41 raeburn 8689: 3. quota name - portfolio, author, or course
8690: (if no quota name provided, defaults to portfolio).
1.1075.2.59! raeburn 8691: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8692: course
1.472 raeburn 8693:
8694: Returns:
1.1075.2.58 raeburn 8695: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8696: 2. (Optional) Type of setting: custom or default
8697: (individually assigned or default for user's
8698: institutional status).
8699: 3. (Optional) - User's institutional status (e.g., faculty, staff
8700: or student - types as defined in localenroll::inst_usertypes
8701: for user's domain, which determines default quota for user.
8702: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8703:
8704: If a value has been stored in the user's environment,
1.536 raeburn 8705: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8706: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8707:
8708: =cut
8709:
8710: ###############################################
8711:
8712:
8713: sub get_user_quota {
1.1075.2.42 raeburn 8714: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8715: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8716: if (!defined($udom)) {
8717: $udom = $env{'user.domain'};
8718: }
8719: if (!defined($uname)) {
8720: $uname = $env{'user.name'};
8721: }
8722: if (($udom eq '' || $uname eq '') ||
8723: ($udom eq 'public') && ($uname eq 'public')) {
8724: $quota = 0;
1.536 raeburn 8725: $quotatype = 'default';
8726: $defquota = 0;
1.472 raeburn 8727: } else {
1.536 raeburn 8728: my $inststatus;
1.1075.2.41 raeburn 8729: if ($quotaname eq 'course') {
8730: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8731: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8732: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8733: } else {
8734: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8735: $quota = $cenv{'internal.uploadquota'};
8736: }
1.536 raeburn 8737: } else {
1.1075.2.41 raeburn 8738: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8739: if ($quotaname eq 'author') {
8740: $quota = $env{'environment.authorquota'};
8741: } else {
8742: $quota = $env{'environment.portfolioquota'};
8743: }
8744: $inststatus = $env{'environment.inststatus'};
8745: } else {
8746: my %userenv =
8747: &Apache::lonnet::get('environment',['portfolioquota',
8748: 'authorquota','inststatus'],$udom,$uname);
8749: my ($tmp) = keys(%userenv);
8750: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8751: if ($quotaname eq 'author') {
8752: $quota = $userenv{'authorquota'};
8753: } else {
8754: $quota = $userenv{'portfolioquota'};
8755: }
8756: $inststatus = $userenv{'inststatus'};
8757: } else {
8758: undef(%userenv);
8759: }
8760: }
8761: }
8762: if ($quota eq '' || wantarray) {
8763: if ($quotaname eq 'course') {
8764: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59! raeburn 8765: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
! 8766: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8767: $defquota = $domdefs{$crstype.'quota'};
8768: }
8769: if ($defquota eq '') {
8770: $defquota = 500;
8771: }
1.1075.2.41 raeburn 8772: } else {
8773: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8774: }
8775: if ($quota eq '') {
8776: $quota = $defquota;
8777: $quotatype = 'default';
8778: } else {
8779: $quotatype = 'custom';
8780: }
1.472 raeburn 8781: }
8782: }
1.536 raeburn 8783: if (wantarray) {
8784: return ($quota,$quotatype,$settingstatus,$defquota);
8785: } else {
8786: return $quota;
8787: }
1.472 raeburn 8788: }
8789:
8790: ###############################################
8791:
8792: =pod
8793:
8794: =item * &default_quota()
8795:
1.536 raeburn 8796: Retrieves default quota assigned for storage of user portfolio files,
8797: given an (optional) user's institutional status.
1.472 raeburn 8798:
8799: Incoming parameters:
1.1075.2.42 raeburn 8800:
1.472 raeburn 8801: 1. domain
1.536 raeburn 8802: 2. (Optional) institutional status(es). This is a : separated list of
8803: status types (e.g., faculty, staff, student etc.)
8804: which apply to the user for whom the default is being retrieved.
8805: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8806: default quota will be returned.
8807: 3. quota name - portfolio, author, or course
8808: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8809:
8810: Returns:
1.1075.2.42 raeburn 8811:
1.1075.2.58 raeburn 8812: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8813: 2. (Optional) institutional type which determined the value of the
8814: default quota.
1.472 raeburn 8815:
8816: If a value has been stored in the domain's configuration db,
8817: it will return that, otherwise it returns 20 (for backwards
8818: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 8819: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8820:
1.536 raeburn 8821: If the user's status includes multiple types (e.g., staff and student),
8822: the largest default quota which applies to the user determines the
8823: default quota returned.
8824:
1.472 raeburn 8825: =cut
8826:
8827: ###############################################
8828:
8829:
8830: sub default_quota {
1.1075.2.41 raeburn 8831: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8832: my ($defquota,$settingstatus);
8833: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8834: ['quotas'],$udom);
1.1075.2.41 raeburn 8835: my $key = 'defaultquota';
8836: if ($quotaname eq 'author') {
8837: $key = 'authorquota';
8838: }
1.622 raeburn 8839: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8840: if ($inststatus ne '') {
1.765 raeburn 8841: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8842: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8843: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8844: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8845: if ($defquota eq '') {
1.1075.2.41 raeburn 8846: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8847: $settingstatus = $item;
1.1075.2.41 raeburn 8848: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8849: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8850: $settingstatus = $item;
8851: }
8852: }
1.1075.2.41 raeburn 8853: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8854: if ($quotahash{'quotas'}{$item} ne '') {
8855: if ($defquota eq '') {
8856: $defquota = $quotahash{'quotas'}{$item};
8857: $settingstatus = $item;
8858: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8859: $defquota = $quotahash{'quotas'}{$item};
8860: $settingstatus = $item;
8861: }
1.536 raeburn 8862: }
8863: }
8864: }
8865: }
8866: if ($defquota eq '') {
1.1075.2.41 raeburn 8867: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8868: $defquota = $quotahash{'quotas'}{$key}{'default'};
8869: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8870: $defquota = $quotahash{'quotas'}{'default'};
8871: }
1.536 raeburn 8872: $settingstatus = 'default';
1.1075.2.42 raeburn 8873: if ($defquota eq '') {
8874: if ($quotaname eq 'author') {
8875: $defquota = 500;
8876: }
8877: }
1.536 raeburn 8878: }
8879: } else {
8880: $settingstatus = 'default';
1.1075.2.41 raeburn 8881: if ($quotaname eq 'author') {
8882: $defquota = 500;
8883: } else {
8884: $defquota = 20;
8885: }
1.536 raeburn 8886: }
8887: if (wantarray) {
8888: return ($defquota,$settingstatus);
1.472 raeburn 8889: } else {
1.536 raeburn 8890: return $defquota;
1.472 raeburn 8891: }
8892: }
8893:
1.1075.2.41 raeburn 8894: ###############################################
8895:
8896: =pod
8897:
1.1075.2.42 raeburn 8898: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8899:
8900: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8901: of existing file within authoring space will cause quota for the authoring
8902: space to be exceeded.
8903:
8904: Same, if upload of a file directly to a course/community via Course Editor
8905: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8906:
8907: Inputs: 6
1.1075.2.42 raeburn 8908: 1. username or coursenum
1.1075.2.41 raeburn 8909: 2. domain
1.1075.2.42 raeburn 8910: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8911: 4. filename of file for which action is being requested
8912: 5. filesize (kB) of file
8913: 6. action being taken: copy or upload.
1.1075.2.59! raeburn 8914: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 8915:
8916: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8917: otherwise return null.
8918:
1.1075.2.42 raeburn 8919: =back
8920:
1.1075.2.41 raeburn 8921: =cut
8922:
1.1075.2.42 raeburn 8923: sub excess_filesize_warning {
1.1075.2.59! raeburn 8924: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 8925: my $current_disk_usage = 0;
1.1075.2.59! raeburn 8926: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 8927: if ($context eq 'author') {
8928: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8929: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8930: } else {
8931: foreach my $subdir ('docs','supplemental') {
8932: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8933: }
8934: }
1.1075.2.41 raeburn 8935: $disk_quota = int($disk_quota * 1000);
8936: if (($current_disk_usage + $filesize) > $disk_quota) {
8937: return '<p><span class="LC_warning">'.
8938: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8939: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8940: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8941: $disk_quota,$current_disk_usage).
8942: '</p>';
8943: }
8944: return;
8945: }
8946:
8947: ###############################################
8948:
8949:
1.384 raeburn 8950: sub get_secgrprole_info {
8951: my ($cdom,$cnum,$needroles,$type) = @_;
8952: my %sections_count = &get_sections($cdom,$cnum);
8953: my @sections = (sort {$a <=> $b} keys(%sections_count));
8954: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8955: my @groups = sort(keys(%curr_groups));
8956: my $allroles = [];
8957: my $rolehash;
8958: my $accesshash = {
8959: active => 'Currently has access',
8960: future => 'Will have future access',
8961: previous => 'Previously had access',
8962: };
8963: if ($needroles) {
8964: $rolehash = {'all' => 'all'};
1.385 albertel 8965: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8966: if (&Apache::lonnet::error(%user_roles)) {
8967: undef(%user_roles);
8968: }
8969: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8970: my ($role)=split(/\:/,$item,2);
8971: if ($role eq 'cr') { next; }
8972: if ($role =~ /^cr/) {
8973: $$rolehash{$role} = (split('/',$role))[3];
8974: } else {
8975: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8976: }
8977: }
8978: foreach my $key (sort(keys(%{$rolehash}))) {
8979: push(@{$allroles},$key);
8980: }
8981: push (@{$allroles},'st');
8982: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8983: }
8984: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8985: }
8986:
1.555 raeburn 8987: sub user_picker {
1.994 raeburn 8988: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8989: my $currdom = $dom;
8990: my %curr_selected = (
8991: srchin => 'dom',
1.580 raeburn 8992: srchby => 'lastname',
1.555 raeburn 8993: );
8994: my $srchterm;
1.625 raeburn 8995: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8996: if ($srch->{'srchby'} ne '') {
8997: $curr_selected{'srchby'} = $srch->{'srchby'};
8998: }
8999: if ($srch->{'srchin'} ne '') {
9000: $curr_selected{'srchin'} = $srch->{'srchin'};
9001: }
9002: if ($srch->{'srchtype'} ne '') {
9003: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9004: }
9005: if ($srch->{'srchdomain'} ne '') {
9006: $currdom = $srch->{'srchdomain'};
9007: }
9008: $srchterm = $srch->{'srchterm'};
9009: }
9010: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9011: 'usr' => 'Search criteria',
1.563 raeburn 9012: 'doma' => 'Domain/institution to search',
1.558 albertel 9013: 'uname' => 'username',
9014: 'lastname' => 'last name',
1.555 raeburn 9015: 'lastfirst' => 'last name, first name',
1.558 albertel 9016: 'crs' => 'in this course',
1.576 raeburn 9017: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9018: 'alc' => 'all LON-CAPA',
1.573 raeburn 9019: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9020: 'exact' => 'is',
9021: 'contains' => 'contains',
1.569 raeburn 9022: 'begins' => 'begins with',
1.571 raeburn 9023: 'youm' => "You must include some text to search for.",
9024: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9025: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9026: 'yomc' => "You must choose a domain when using an institutional directory search.",
9027: 'ymcd' => "You must choose a domain when using a domain search.",
9028: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9029: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9030: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9031: );
1.563 raeburn 9032: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9033: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9034:
9035: my @srchins = ('crs','dom','alc','instd');
9036:
9037: foreach my $option (@srchins) {
9038: # FIXME 'alc' option unavailable until
9039: # loncreateuser::print_user_query_page()
9040: # has been completed.
9041: next if ($option eq 'alc');
1.880 raeburn 9042: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9043: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9044: if ($curr_selected{'srchin'} eq $option) {
9045: $srchinsel .= '
9046: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9047: } else {
9048: $srchinsel .= '
9049: <option value="'.$option.'">'.$lt{$option}.'</option>';
9050: }
1.555 raeburn 9051: }
1.563 raeburn 9052: $srchinsel .= "\n </select>\n";
1.555 raeburn 9053:
9054: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9055: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9056: if ($curr_selected{'srchby'} eq $option) {
9057: $srchbysel .= '
9058: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9059: } else {
9060: $srchbysel .= '
9061: <option value="'.$option.'">'.$lt{$option}.'</option>';
9062: }
9063: }
9064: $srchbysel .= "\n </select>\n";
9065:
9066: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9067: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9068: if ($curr_selected{'srchtype'} eq $option) {
9069: $srchtypesel .= '
9070: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9071: } else {
9072: $srchtypesel .= '
9073: <option value="'.$option.'">'.$lt{$option}.'</option>';
9074: }
9075: }
9076: $srchtypesel .= "\n </select>\n";
9077:
1.558 albertel 9078: my ($newuserscript,$new_user_create);
1.994 raeburn 9079: my $context_dom = $env{'request.role.domain'};
9080: if ($context eq 'requestcrs') {
9081: if ($env{'form.coursedom'} ne '') {
9082: $context_dom = $env{'form.coursedom'};
9083: }
9084: }
1.556 raeburn 9085: if ($forcenewuser) {
1.576 raeburn 9086: if (ref($srch) eq 'HASH') {
1.994 raeburn 9087: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9088: if ($cancreate) {
9089: $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>';
9090: } else {
1.799 bisitz 9091: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9092: my %usertypetext = (
9093: official => 'institutional',
9094: unofficial => 'non-institutional',
9095: );
1.799 bisitz 9096: $new_user_create = '<p class="LC_warning">'
9097: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9098: .' '
9099: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9100: ,'<a href="'.$helplink.'">','</a>')
9101: .'</p><br />';
1.627 raeburn 9102: }
1.576 raeburn 9103: }
9104: }
9105:
1.556 raeburn 9106: $newuserscript = <<"ENDSCRIPT";
9107:
1.570 raeburn 9108: function setSearch(createnew,callingForm) {
1.556 raeburn 9109: if (createnew == 1) {
1.570 raeburn 9110: for (var i=0; i<callingForm.srchby.length; i++) {
9111: if (callingForm.srchby.options[i].value == 'uname') {
9112: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9113: }
9114: }
1.570 raeburn 9115: for (var i=0; i<callingForm.srchin.length; i++) {
9116: if ( callingForm.srchin.options[i].value == 'dom') {
9117: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9118: }
9119: }
1.570 raeburn 9120: for (var i=0; i<callingForm.srchtype.length; i++) {
9121: if (callingForm.srchtype.options[i].value == 'exact') {
9122: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9123: }
9124: }
1.570 raeburn 9125: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9126: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9127: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9128: }
9129: }
9130: }
9131: }
9132: ENDSCRIPT
1.558 albertel 9133:
1.556 raeburn 9134: }
9135:
1.555 raeburn 9136: my $output = <<"END_BLOCK";
1.556 raeburn 9137: <script type="text/javascript">
1.824 bisitz 9138: // <![CDATA[
1.570 raeburn 9139: function validateEntry(callingForm) {
1.558 albertel 9140:
1.556 raeburn 9141: var checkok = 1;
1.558 albertel 9142: var srchin;
1.570 raeburn 9143: for (var i=0; i<callingForm.srchin.length; i++) {
9144: if ( callingForm.srchin[i].checked ) {
9145: srchin = callingForm.srchin[i].value;
1.558 albertel 9146: }
9147: }
9148:
1.570 raeburn 9149: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9150: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9151: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9152: var srchterm = callingForm.srchterm.value;
9153: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9154: var msg = "";
9155:
9156: if (srchterm == "") {
9157: checkok = 0;
1.571 raeburn 9158: msg += "$lt{'youm'}\\n";
1.556 raeburn 9159: }
9160:
1.569 raeburn 9161: if (srchtype== 'begins') {
9162: if (srchterm.length < 2) {
9163: checkok = 0;
1.571 raeburn 9164: msg += "$lt{'thte'}\\n";
1.569 raeburn 9165: }
9166: }
9167:
1.556 raeburn 9168: if (srchtype== 'contains') {
9169: if (srchterm.length < 3) {
9170: checkok = 0;
1.571 raeburn 9171: msg += "$lt{'thet'}\\n";
1.556 raeburn 9172: }
9173: }
9174: if (srchin == 'instd') {
9175: if (srchdomain == '') {
9176: checkok = 0;
1.571 raeburn 9177: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9178: }
9179: }
9180: if (srchin == 'dom') {
9181: if (srchdomain == '') {
9182: checkok = 0;
1.571 raeburn 9183: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9184: }
9185: }
9186: if (srchby == 'lastfirst') {
9187: if (srchterm.indexOf(",") == -1) {
9188: checkok = 0;
1.571 raeburn 9189: msg += "$lt{'whus'}\\n";
1.556 raeburn 9190: }
9191: if (srchterm.indexOf(",") == srchterm.length -1) {
9192: checkok = 0;
1.571 raeburn 9193: msg += "$lt{'whse'}\\n";
1.556 raeburn 9194: }
9195: }
9196: if (checkok == 0) {
1.571 raeburn 9197: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9198: return;
9199: }
9200: if (checkok == 1) {
1.570 raeburn 9201: callingForm.submit();
1.556 raeburn 9202: }
9203: }
9204:
9205: $newuserscript
9206:
1.824 bisitz 9207: // ]]>
1.556 raeburn 9208: </script>
1.558 albertel 9209:
9210: $new_user_create
9211:
1.555 raeburn 9212: END_BLOCK
1.558 albertel 9213:
1.876 raeburn 9214: $output .= &Apache::lonhtmlcommon::start_pick_box().
9215: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9216: $domform.
9217: &Apache::lonhtmlcommon::row_closure().
9218: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9219: $srchbysel.
9220: $srchtypesel.
9221: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9222: $srchinsel.
9223: &Apache::lonhtmlcommon::row_closure(1).
9224: &Apache::lonhtmlcommon::end_pick_box().
9225: '<br />';
1.555 raeburn 9226: return $output;
9227: }
9228:
1.612 raeburn 9229: sub user_rule_check {
1.615 raeburn 9230: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9231: my $response;
9232: if (ref($usershash) eq 'HASH') {
9233: foreach my $user (keys(%{$usershash})) {
9234: my ($uname,$udom) = split(/:/,$user);
9235: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9236: my ($id,$newuser);
1.612 raeburn 9237: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9238: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9239: $id = $usershash->{$user}->{'id'};
9240: }
9241: my $inst_response;
9242: if (ref($checks) eq 'HASH') {
9243: if (defined($checks->{'username'})) {
1.615 raeburn 9244: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9245: &Apache::lonnet::get_instuser($udom,$uname);
9246: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9247: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9248: &Apache::lonnet::get_instuser($udom,undef,$id);
9249: }
1.615 raeburn 9250: } else {
9251: ($inst_response,%{$inst_results->{$user}}) =
9252: &Apache::lonnet::get_instuser($udom,$uname);
9253: return;
1.612 raeburn 9254: }
1.615 raeburn 9255: if (!$got_rules->{$udom}) {
1.612 raeburn 9256: my %domconfig = &Apache::lonnet::get_dom('configuration',
9257: ['usercreation'],$udom);
9258: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9259: foreach my $item ('username','id') {
1.612 raeburn 9260: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9261: $$curr_rules{$udom}{$item} =
9262: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9263: }
9264: }
9265: }
1.615 raeburn 9266: $got_rules->{$udom} = 1;
1.585 raeburn 9267: }
1.612 raeburn 9268: foreach my $item (keys(%{$checks})) {
9269: if (ref($$curr_rules{$udom}) eq 'HASH') {
9270: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9271: if (@{$$curr_rules{$udom}{$item}} > 0) {
9272: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9273: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9274: if ($rule_check{$rule}) {
9275: $$rulematch{$user}{$item} = $rule;
9276: if ($inst_response eq 'ok') {
1.615 raeburn 9277: if (ref($inst_results) eq 'HASH') {
9278: if (ref($inst_results->{$user}) eq 'HASH') {
9279: if (keys(%{$inst_results->{$user}}) == 0) {
9280: $$alerts{$item}{$udom}{$uname} = 1;
9281: }
1.612 raeburn 9282: }
9283: }
1.615 raeburn 9284: }
9285: last;
1.585 raeburn 9286: }
9287: }
9288: }
9289: }
9290: }
9291: }
9292: }
9293: }
1.612 raeburn 9294: return;
9295: }
9296:
9297: sub user_rule_formats {
9298: my ($domain,$domdesc,$curr_rules,$check) = @_;
9299: my %text = (
9300: 'username' => 'Usernames',
9301: 'id' => 'IDs',
9302: );
9303: my $output;
9304: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9305: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9306: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9307: $output = '<br />'.
9308: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9309: '<span class="LC_cusr_emph">','</span>',$domdesc).
9310: ' <ul>';
1.612 raeburn 9311: foreach my $rule (@{$ruleorder}) {
9312: if (ref($curr_rules) eq 'ARRAY') {
9313: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9314: if (ref($rules->{$rule}) eq 'HASH') {
9315: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9316: $rules->{$rule}{'desc'}.'</li>';
9317: }
9318: }
9319: }
9320: }
9321: $output .= '</ul>';
9322: }
9323: }
9324: return $output;
9325: }
9326:
9327: sub instrule_disallow_msg {
1.615 raeburn 9328: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9329: my $response;
9330: my %text = (
9331: item => 'username',
9332: items => 'usernames',
9333: match => 'matches',
9334: do => 'does',
9335: action => 'a username',
9336: one => 'one',
9337: );
9338: if ($count > 1) {
9339: $text{'item'} = 'usernames';
9340: $text{'match'} ='match';
9341: $text{'do'} = 'do';
9342: $text{'action'} = 'usernames',
9343: $text{'one'} = 'ones';
9344: }
9345: if ($checkitem eq 'id') {
9346: $text{'items'} = 'IDs';
9347: $text{'item'} = 'ID';
9348: $text{'action'} = 'an ID';
1.615 raeburn 9349: if ($count > 1) {
9350: $text{'item'} = 'IDs';
9351: $text{'action'} = 'IDs';
9352: }
1.612 raeburn 9353: }
1.674 bisitz 9354: $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 9355: if ($mode eq 'upload') {
9356: if ($checkitem eq 'username') {
9357: $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'}.");
9358: } elsif ($checkitem eq 'id') {
1.674 bisitz 9359: $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 9360: }
1.669 raeburn 9361: } elsif ($mode eq 'selfcreate') {
9362: if ($checkitem eq 'id') {
9363: $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.");
9364: }
1.615 raeburn 9365: } else {
9366: if ($checkitem eq 'username') {
9367: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9368: } elsif ($checkitem eq 'id') {
9369: $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.");
9370: }
1.612 raeburn 9371: }
9372: return $response;
1.585 raeburn 9373: }
9374:
1.624 raeburn 9375: sub personal_data_fieldtitles {
9376: my %fieldtitles = &Apache::lonlocal::texthash (
9377: id => 'Student/Employee ID',
9378: permanentemail => 'E-mail address',
9379: lastname => 'Last Name',
9380: firstname => 'First Name',
9381: middlename => 'Middle Name',
9382: generation => 'Generation',
9383: gen => 'Generation',
1.765 raeburn 9384: inststatus => 'Affiliation',
1.624 raeburn 9385: );
9386: return %fieldtitles;
9387: }
9388:
1.642 raeburn 9389: sub sorted_inst_types {
9390: my ($dom) = @_;
9391: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9392: my $othertitle = &mt('All users');
9393: if ($env{'request.course.id'}) {
1.668 raeburn 9394: $othertitle = &mt('Any users');
1.642 raeburn 9395: }
9396: my @types;
9397: if (ref($order) eq 'ARRAY') {
9398: @types = @{$order};
9399: }
9400: if (@types == 0) {
9401: if (ref($usertypes) eq 'HASH') {
9402: @types = sort(keys(%{$usertypes}));
9403: }
9404: }
9405: if (keys(%{$usertypes}) > 0) {
9406: $othertitle = &mt('Other users');
9407: }
9408: return ($othertitle,$usertypes,\@types);
9409: }
9410:
1.645 raeburn 9411: sub get_institutional_codes {
9412: my ($settings,$allcourses,$LC_code) = @_;
9413: # Get complete list of course sections to update
9414: my @currsections = ();
9415: my @currxlists = ();
9416: my $coursecode = $$settings{'internal.coursecode'};
9417:
9418: if ($$settings{'internal.sectionnums'} ne '') {
9419: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9420: }
9421:
9422: if ($$settings{'internal.crosslistings'} ne '') {
9423: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9424: }
9425:
9426: if (@currxlists > 0) {
9427: foreach (@currxlists) {
9428: if (m/^([^:]+):(\w*)$/) {
9429: unless (grep/^$1$/,@{$allcourses}) {
9430: push @{$allcourses},$1;
9431: $$LC_code{$1} = $2;
9432: }
9433: }
9434: }
9435: }
9436:
9437: if (@currsections > 0) {
9438: foreach (@currsections) {
9439: if (m/^(\w+):(\w*)$/) {
9440: my $sec = $coursecode.$1;
9441: my $lc_sec = $2;
9442: unless (grep/^$sec$/,@{$allcourses}) {
9443: push @{$allcourses},$sec;
9444: $$LC_code{$sec} = $lc_sec;
9445: }
9446: }
9447: }
9448: }
9449: return;
9450: }
9451:
1.971 raeburn 9452: sub get_standard_codeitems {
9453: return ('Year','Semester','Department','Number','Section');
9454: }
9455:
1.112 bowersj2 9456: =pod
9457:
1.780 raeburn 9458: =head1 Slot Helpers
9459:
9460: =over 4
9461:
9462: =item * sorted_slots()
9463:
1.1040 raeburn 9464: Sorts an array of slot names in order of an optional sort key,
9465: default sort is by slot start time (earliest first).
1.780 raeburn 9466:
9467: Inputs:
9468:
9469: =over 4
9470:
9471: slotsarr - Reference to array of unsorted slot names.
9472:
9473: slots - Reference to hash of hash, where outer hash keys are slot names.
9474:
1.1040 raeburn 9475: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9476:
1.549 albertel 9477: =back
9478:
1.780 raeburn 9479: Returns:
9480:
9481: =over 4
9482:
1.1040 raeburn 9483: sorted - An array of slot names sorted by a specified sort key
9484: (default sort key is start time of the slot).
1.780 raeburn 9485:
9486: =back
9487:
9488: =cut
9489:
9490:
9491: sub sorted_slots {
1.1040 raeburn 9492: my ($slotsarr,$slots,$sortkey) = @_;
9493: if ($sortkey eq '') {
9494: $sortkey = 'starttime';
9495: }
1.780 raeburn 9496: my @sorted;
9497: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9498: @sorted =
9499: sort {
9500: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9501: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9502: }
9503: if (ref($slots->{$a})) { return -1;}
9504: if (ref($slots->{$b})) { return 1;}
9505: return 0;
9506: } @{$slotsarr};
9507: }
9508: return @sorted;
9509: }
9510:
1.1040 raeburn 9511: =pod
9512:
9513: =item * get_future_slots()
9514:
9515: Inputs:
9516:
9517: =over 4
9518:
9519: cnum - course number
9520:
9521: cdom - course domain
9522:
9523: now - current UNIX time
9524:
9525: symb - optional symb
9526:
9527: =back
9528:
9529: Returns:
9530:
9531: =over 4
9532:
9533: sorted_reservable - ref to array of student_schedulable slots currently
9534: reservable, ordered by end date of reservation period.
9535:
9536: reservable_now - ref to hash of student_schedulable slots currently
9537: reservable.
9538:
9539: Keys in inner hash are:
9540: (a) symb: either blank or symb to which slot use is restricted.
9541: (b) endreserve: end date of reservation period.
9542:
9543: sorted_future - ref to array of student_schedulable slots reservable in
9544: the future, ordered by start date of reservation period.
9545:
9546: future_reservable - ref to hash of student_schedulable slots reservable
9547: in the future.
9548:
9549: Keys in inner hash are:
9550: (a) symb: either blank or symb to which slot use is restricted.
9551: (b) startreserve: start date of reservation period.
9552:
9553: =back
9554:
9555: =cut
9556:
9557: sub get_future_slots {
9558: my ($cnum,$cdom,$now,$symb) = @_;
9559: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9560: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9561: foreach my $slot (keys(%slots)) {
9562: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9563: if ($symb) {
9564: next if (($slots{$slot}->{'symb'} ne '') &&
9565: ($slots{$slot}->{'symb'} ne $symb));
9566: }
9567: if (($slots{$slot}->{'starttime'} > $now) &&
9568: ($slots{$slot}->{'endtime'} > $now)) {
9569: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9570: my $userallowed = 0;
9571: if ($slots{$slot}->{'allowedsections'}) {
9572: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9573: if (!defined($env{'request.role.sec'})
9574: && grep(/^No section assigned$/,@allowed_sec)) {
9575: $userallowed=1;
9576: } else {
9577: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9578: $userallowed=1;
9579: }
9580: }
9581: unless ($userallowed) {
9582: if (defined($env{'request.course.groups'})) {
9583: my @groups = split(/:/,$env{'request.course.groups'});
9584: foreach my $group (@groups) {
9585: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9586: $userallowed=1;
9587: last;
9588: }
9589: }
9590: }
9591: }
9592: }
9593: if ($slots{$slot}->{'allowedusers'}) {
9594: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9595: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9596: if (grep(/^\Q$user\E$/,@allowed_users)) {
9597: $userallowed = 1;
9598: }
9599: }
9600: next unless($userallowed);
9601: }
9602: my $startreserve = $slots{$slot}->{'startreserve'};
9603: my $endreserve = $slots{$slot}->{'endreserve'};
9604: my $symb = $slots{$slot}->{'symb'};
9605: if (($startreserve < $now) &&
9606: (!$endreserve || $endreserve > $now)) {
9607: my $lastres = $endreserve;
9608: if (!$lastres) {
9609: $lastres = $slots{$slot}->{'starttime'};
9610: }
9611: $reservable_now{$slot} = {
9612: symb => $symb,
9613: endreserve => $lastres
9614: };
9615: } elsif (($startreserve > $now) &&
9616: (!$endreserve || $endreserve > $startreserve)) {
9617: $future_reservable{$slot} = {
9618: symb => $symb,
9619: startreserve => $startreserve
9620: };
9621: }
9622: }
9623: }
9624: my @unsorted_reservable = keys(%reservable_now);
9625: if (@unsorted_reservable > 0) {
9626: @sorted_reservable =
9627: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9628: }
9629: my @unsorted_future = keys(%future_reservable);
9630: if (@unsorted_future > 0) {
9631: @sorted_future =
9632: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9633: }
9634: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9635: }
1.780 raeburn 9636:
9637: =pod
9638:
1.1057 foxr 9639: =back
9640:
1.549 albertel 9641: =head1 HTTP Helpers
9642:
9643: =over 4
9644:
1.648 raeburn 9645: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9646:
1.258 albertel 9647: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9648: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9649: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9650:
9651: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9652: $possible_names is an ref to an array of form element names. As an example:
9653: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9654: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9655:
9656: =cut
1.1 albertel 9657:
1.6 albertel 9658: sub get_unprocessed_cgi {
1.25 albertel 9659: my ($query,$possible_names)= @_;
1.26 matthew 9660: # $Apache::lonxml::debug=1;
1.356 albertel 9661: foreach my $pair (split(/&/,$query)) {
9662: my ($name, $value) = split(/=/,$pair);
1.369 www 9663: $name = &unescape($name);
1.25 albertel 9664: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9665: $value =~ tr/+/ /;
9666: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9667: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9668: }
1.16 harris41 9669: }
1.6 albertel 9670: }
9671:
1.112 bowersj2 9672: =pod
9673:
1.648 raeburn 9674: =item * &cacheheader()
1.112 bowersj2 9675:
9676: returns cache-controlling header code
9677:
9678: =cut
9679:
1.7 albertel 9680: sub cacheheader {
1.258 albertel 9681: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9682: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9683: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9684: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9685: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9686: return $output;
1.7 albertel 9687: }
9688:
1.112 bowersj2 9689: =pod
9690:
1.648 raeburn 9691: =item * &no_cache($r)
1.112 bowersj2 9692:
9693: specifies header code to not have cache
9694:
9695: =cut
9696:
1.9 albertel 9697: sub no_cache {
1.216 albertel 9698: my ($r) = @_;
9699: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9700: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9701: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9702: $r->no_cache(1);
9703: $r->header_out("Expires" => $date);
9704: $r->header_out("Pragma" => "no-cache");
1.123 www 9705: }
9706:
9707: sub content_type {
1.181 albertel 9708: my ($r,$type,$charset) = @_;
1.299 foxr 9709: if ($r) {
9710: # Note that printout.pl calls this with undef for $r.
9711: &no_cache($r);
9712: }
1.258 albertel 9713: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9714: unless ($charset) {
9715: $charset=&Apache::lonlocal::current_encoding;
9716: }
9717: if ($charset) { $type.='; charset='.$charset; }
9718: if ($r) {
9719: $r->content_type($type);
9720: } else {
9721: print("Content-type: $type\n\n");
9722: }
1.9 albertel 9723: }
1.25 albertel 9724:
1.112 bowersj2 9725: =pod
9726:
1.648 raeburn 9727: =item * &add_to_env($name,$value)
1.112 bowersj2 9728:
1.258 albertel 9729: adds $name to the %env hash with value
1.112 bowersj2 9730: $value, if $name already exists, the entry is converted to an array
9731: reference and $value is added to the array.
9732:
9733: =cut
9734:
1.25 albertel 9735: sub add_to_env {
9736: my ($name,$value)=@_;
1.258 albertel 9737: if (defined($env{$name})) {
9738: if (ref($env{$name})) {
1.25 albertel 9739: #already have multiple values
1.258 albertel 9740: push(@{ $env{$name} },$value);
1.25 albertel 9741: } else {
9742: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9743: my $first=$env{$name};
9744: undef($env{$name});
9745: push(@{ $env{$name} },$first,$value);
1.25 albertel 9746: }
9747: } else {
1.258 albertel 9748: $env{$name}=$value;
1.25 albertel 9749: }
1.31 albertel 9750: }
1.149 albertel 9751:
9752: =pod
9753:
1.648 raeburn 9754: =item * &get_env_multiple($name)
1.149 albertel 9755:
1.258 albertel 9756: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9757: values may be defined and end up as an array ref.
9758:
9759: returns an array of values
9760:
9761: =cut
9762:
9763: sub get_env_multiple {
9764: my ($name) = @_;
9765: my @values;
1.258 albertel 9766: if (defined($env{$name})) {
1.149 albertel 9767: # exists is it an array
1.258 albertel 9768: if (ref($env{$name})) {
9769: @values=@{ $env{$name} };
1.149 albertel 9770: } else {
1.258 albertel 9771: $values[0]=$env{$name};
1.149 albertel 9772: }
9773: }
9774: return(@values);
9775: }
9776:
1.660 raeburn 9777: sub ask_for_embedded_content {
9778: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9779: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9780: %currsubfile,%unused,$rem);
1.1071 raeburn 9781: my $counter = 0;
9782: my $numnew = 0;
1.987 raeburn 9783: my $numremref = 0;
9784: my $numinvalid = 0;
9785: my $numpathchg = 0;
9786: my $numexisting = 0;
1.1071 raeburn 9787: my $numunused = 0;
9788: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9789: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9790: my $heading = &mt('Upload embedded files');
9791: my $buttontext = &mt('Upload');
9792:
1.1075.2.11 raeburn 9793: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9794: if ($actionurl eq '/adm/dependencies') {
9795: $navmap = Apache::lonnavmaps::navmap->new();
9796: }
9797: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9798: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9799: }
1.1075.2.35 raeburn 9800: if (($actionurl eq '/adm/portfolio') ||
9801: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9802: my $current_path='/';
9803: if ($env{'form.currentpath'}) {
9804: $current_path = $env{'form.currentpath'};
9805: }
9806: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9807: $udom = $cdom;
9808: $uname = $cnum;
1.984 raeburn 9809: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9810: } else {
9811: $udom = $env{'user.domain'};
9812: $uname = $env{'user.name'};
9813: $url = '/userfiles/portfolio';
9814: }
1.987 raeburn 9815: $toplevel = $url.'/';
1.984 raeburn 9816: $url .= $current_path;
9817: $getpropath = 1;
1.987 raeburn 9818: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9819: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9820: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9821: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9822: $toplevel = $url;
1.984 raeburn 9823: if ($rest ne '') {
1.987 raeburn 9824: $url .= $rest;
9825: }
9826: } elsif ($actionurl eq '/adm/coursedocs') {
9827: if (ref($args) eq 'HASH') {
1.1071 raeburn 9828: $url = $args->{'docs_url'};
9829: $toplevel = $url;
1.1075.2.11 raeburn 9830: if ($args->{'context'} eq 'paste') {
9831: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9832: ($path) =
9833: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9834: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9835: $fileloc =~ s{^/}{};
9836: }
1.1071 raeburn 9837: }
9838: } elsif ($actionurl eq '/adm/dependencies') {
9839: if ($env{'request.course.id'} ne '') {
9840: if (ref($args) eq 'HASH') {
9841: $url = $args->{'docs_url'};
9842: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9843: $toplevel = $url;
9844: unless ($toplevel =~ m{^/}) {
9845: $toplevel = "/$url";
9846: }
1.1075.2.11 raeburn 9847: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9848: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9849: $path = $1;
9850: } else {
9851: ($path) =
9852: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9853: }
1.1071 raeburn 9854: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9855: $fileloc =~ s{^/}{};
9856: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9857: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9858: }
1.987 raeburn 9859: }
1.1075.2.35 raeburn 9860: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9861: $udom = $cdom;
9862: $uname = $cnum;
9863: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9864: $toplevel = $url;
9865: $path = $url;
9866: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9867: $fileloc =~ s{^/}{};
9868: }
9869: foreach my $file (keys(%{$allfiles})) {
9870: my $embed_file;
9871: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9872: $embed_file = $1;
9873: } else {
9874: $embed_file = $file;
9875: }
1.1075.2.55 raeburn 9876: my ($absolutepath,$cleaned_file);
9877: if ($embed_file =~ m{^\w+://}) {
9878: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9879: $newfiles{$cleaned_file} = 1;
9880: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9881: } else {
1.1075.2.55 raeburn 9882: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9883: if ($embed_file =~ m{^/}) {
9884: $absolutepath = $embed_file;
9885: }
1.1075.2.47 raeburn 9886: if ($cleaned_file =~ m{/}) {
9887: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9888: $path = &check_for_traversal($path,$url,$toplevel);
9889: my $item = $fname;
9890: if ($path ne '') {
9891: $item = $path.'/'.$fname;
9892: $subdependencies{$path}{$fname} = 1;
9893: } else {
9894: $dependencies{$item} = 1;
9895: }
9896: if ($absolutepath) {
9897: $mapping{$item} = $absolutepath;
9898: } else {
9899: $mapping{$item} = $embed_file;
9900: }
9901: } else {
9902: $dependencies{$embed_file} = 1;
9903: if ($absolutepath) {
1.1075.2.47 raeburn 9904: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9905: } else {
1.1075.2.47 raeburn 9906: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9907: }
9908: }
1.984 raeburn 9909: }
9910: }
1.1071 raeburn 9911: my $dirptr = 16384;
1.984 raeburn 9912: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9913: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9914: if (($actionurl eq '/adm/portfolio') ||
9915: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9916: my ($sublistref,$listerror) =
9917: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9918: if (ref($sublistref) eq 'ARRAY') {
9919: foreach my $line (@{$sublistref}) {
9920: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9921: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9922: }
1.984 raeburn 9923: }
1.987 raeburn 9924: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9925: if (opendir(my $dir,$url.'/'.$path)) {
9926: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9927: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9928: }
1.1075.2.11 raeburn 9929: } elsif (($actionurl eq '/adm/dependencies') ||
9930: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9931: ($args->{'context'} eq 'paste')) ||
9932: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9933: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9934: my $dir;
9935: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9936: $dir = $fileloc;
9937: } else {
9938: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9939: }
1.1071 raeburn 9940: if ($dir ne '') {
9941: my ($sublistref,$listerror) =
9942: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9943: if (ref($sublistref) eq 'ARRAY') {
9944: foreach my $line (@{$sublistref}) {
9945: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9946: undef,$mtime)=split(/\&/,$line,12);
9947: unless (($testdir&$dirptr) ||
9948: ($file_name =~ /^\.\.?$/)) {
9949: $currsubfile{$path}{$file_name} = [$size,$mtime];
9950: }
9951: }
9952: }
9953: }
1.984 raeburn 9954: }
9955: }
9956: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9957: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9958: my $item = $path.'/'.$file;
9959: unless ($mapping{$item} eq $item) {
9960: $pathchanges{$item} = 1;
9961: }
9962: $existing{$item} = 1;
9963: $numexisting ++;
9964: } else {
9965: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9966: }
9967: }
1.1071 raeburn 9968: if ($actionurl eq '/adm/dependencies') {
9969: foreach my $path (keys(%currsubfile)) {
9970: if (ref($currsubfile{$path}) eq 'HASH') {
9971: foreach my $file (keys(%{$currsubfile{$path}})) {
9972: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9973: next if (($rem ne '') &&
9974: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9975: (ref($navmap) &&
9976: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9977: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9978: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9979: $unused{$path.'/'.$file} = 1;
9980: }
9981: }
9982: }
9983: }
9984: }
1.984 raeburn 9985: }
1.987 raeburn 9986: my %currfile;
1.1075.2.35 raeburn 9987: if (($actionurl eq '/adm/portfolio') ||
9988: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9989: my ($dirlistref,$listerror) =
9990: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9991: if (ref($dirlistref) eq 'ARRAY') {
9992: foreach my $line (@{$dirlistref}) {
9993: my ($file_name,$rest) = split(/\&/,$line,2);
9994: $currfile{$file_name} = 1;
9995: }
1.984 raeburn 9996: }
1.987 raeburn 9997: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9998: if (opendir(my $dir,$url)) {
1.987 raeburn 9999: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10000: map {$currfile{$_} = 1;} @dir_list;
10001: }
1.1075.2.11 raeburn 10002: } elsif (($actionurl eq '/adm/dependencies') ||
10003: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10004: ($args->{'context'} eq 'paste')) ||
10005: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10006: if ($env{'request.course.id'} ne '') {
10007: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10008: if ($dir ne '') {
10009: my ($dirlistref,$listerror) =
10010: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10011: if (ref($dirlistref) eq 'ARRAY') {
10012: foreach my $line (@{$dirlistref}) {
10013: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10014: $size,undef,$mtime)=split(/\&/,$line,12);
10015: unless (($testdir&$dirptr) ||
10016: ($file_name =~ /^\.\.?$/)) {
10017: $currfile{$file_name} = [$size,$mtime];
10018: }
10019: }
10020: }
10021: }
10022: }
1.984 raeburn 10023: }
10024: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10025: if (exists($currfile{$file})) {
1.987 raeburn 10026: unless ($mapping{$file} eq $file) {
10027: $pathchanges{$file} = 1;
10028: }
10029: $existing{$file} = 1;
10030: $numexisting ++;
10031: } else {
1.984 raeburn 10032: $newfiles{$file} = 1;
10033: }
10034: }
1.1071 raeburn 10035: foreach my $file (keys(%currfile)) {
10036: unless (($file eq $filename) ||
10037: ($file eq $filename.'.bak') ||
10038: ($dependencies{$file})) {
1.1075.2.11 raeburn 10039: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10040: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10041: next if (($rem ne '') &&
10042: (($env{"httpref.$rem".$file} ne '') ||
10043: (ref($navmap) &&
10044: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10045: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10046: ($navmap->getResourceByUrl($rem.$1)))))));
10047: }
1.1075.2.11 raeburn 10048: }
1.1071 raeburn 10049: $unused{$file} = 1;
10050: }
10051: }
1.1075.2.11 raeburn 10052: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10053: ($args->{'context'} eq 'paste')) {
10054: $counter = scalar(keys(%existing));
10055: $numpathchg = scalar(keys(%pathchanges));
10056: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10057: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10058: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10059: $counter = scalar(keys(%existing));
10060: $numpathchg = scalar(keys(%pathchanges));
10061: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10062: }
1.984 raeburn 10063: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10064: if ($actionurl eq '/adm/dependencies') {
10065: next if ($embed_file =~ m{^\w+://});
10066: }
1.660 raeburn 10067: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10068: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10069: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10070: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10071: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10072: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10073: }
1.1075.2.35 raeburn 10074: $upload_output .= '</td>';
1.1071 raeburn 10075: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10076: $upload_output.='<td align="right">'.
10077: '<span class="LC_info LC_fontsize_medium">'.
10078: &mt("URL points to web address").'</span>';
1.987 raeburn 10079: $numremref++;
1.660 raeburn 10080: } elsif ($args->{'error_on_invalid_names'}
10081: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10082: $upload_output.='<td align="right"><span class="LC_warning">'.
10083: &mt('Invalid characters').'</span>';
1.987 raeburn 10084: $numinvalid++;
1.660 raeburn 10085: } else {
1.1075.2.35 raeburn 10086: $upload_output .= '<td>'.
10087: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10088: $embed_file,\%mapping,
1.1071 raeburn 10089: $allfiles,$codebase,'upload');
10090: $counter ++;
10091: $numnew ++;
1.987 raeburn 10092: }
10093: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10094: }
10095: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10096: if ($actionurl eq '/adm/dependencies') {
10097: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10098: $modify_output .= &start_data_table_row().
10099: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10100: '<img src="'.&icon($embed_file).'" border="0" />'.
10101: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10102: '<td>'.$size.'</td>'.
10103: '<td>'.$mtime.'</td>'.
10104: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10105: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10106: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10107: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10108: &embedded_file_element('upload_embedded',$counter,
10109: $embed_file,\%mapping,
10110: $allfiles,$codebase,'modify').
10111: '</div></td>'.
10112: &end_data_table_row()."\n";
10113: $counter ++;
10114: } else {
10115: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10116: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10117: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10118: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10119: &Apache::loncommon::end_data_table_row()."\n";
10120: }
10121: }
10122: my $delidx = $counter;
10123: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10124: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10125: $delete_output .= &start_data_table_row().
10126: '<td><img src="'.&icon($oldfile).'" />'.
10127: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10128: '<td>'.$size.'</td>'.
10129: '<td>'.$mtime.'</td>'.
10130: '<td><label><input type="checkbox" name="del_upload_dep" '.
10131: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10132: &embedded_file_element('upload_embedded',$delidx,
10133: $oldfile,\%mapping,$allfiles,
10134: $codebase,'delete').'</td>'.
10135: &end_data_table_row()."\n";
10136: $numunused ++;
10137: $delidx ++;
1.987 raeburn 10138: }
10139: if ($upload_output) {
10140: $upload_output = &start_data_table().
10141: $upload_output.
10142: &end_data_table()."\n";
10143: }
1.1071 raeburn 10144: if ($modify_output) {
10145: $modify_output = &start_data_table().
10146: &start_data_table_header_row().
10147: '<th>'.&mt('File').'</th>'.
10148: '<th>'.&mt('Size (KB)').'</th>'.
10149: '<th>'.&mt('Modified').'</th>'.
10150: '<th>'.&mt('Upload replacement?').'</th>'.
10151: &end_data_table_header_row().
10152: $modify_output.
10153: &end_data_table()."\n";
10154: }
10155: if ($delete_output) {
10156: $delete_output = &start_data_table().
10157: &start_data_table_header_row().
10158: '<th>'.&mt('File').'</th>'.
10159: '<th>'.&mt('Size (KB)').'</th>'.
10160: '<th>'.&mt('Modified').'</th>'.
10161: '<th>'.&mt('Delete?').'</th>'.
10162: &end_data_table_header_row().
10163: $delete_output.
10164: &end_data_table()."\n";
10165: }
1.987 raeburn 10166: my $applies = 0;
10167: if ($numremref) {
10168: $applies ++;
10169: }
10170: if ($numinvalid) {
10171: $applies ++;
10172: }
10173: if ($numexisting) {
10174: $applies ++;
10175: }
1.1071 raeburn 10176: if ($counter || $numunused) {
1.987 raeburn 10177: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10178: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10179: $state.'<h3>'.$heading.'</h3>';
10180: if ($actionurl eq '/adm/dependencies') {
10181: if ($numnew) {
10182: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10183: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10184: $upload_output.'<br />'."\n";
10185: }
10186: if ($numexisting) {
10187: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10188: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10189: $modify_output.'<br />'."\n";
10190: $buttontext = &mt('Save changes');
10191: }
10192: if ($numunused) {
10193: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10194: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10195: $delete_output.'<br />'."\n";
10196: $buttontext = &mt('Save changes');
10197: }
10198: } else {
10199: $output .= $upload_output.'<br />'."\n";
10200: }
10201: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10202: $counter.'" />'."\n";
10203: if ($actionurl eq '/adm/dependencies') {
10204: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10205: $numnew.'" />'."\n";
10206: } elsif ($actionurl eq '') {
1.987 raeburn 10207: $output .= '<input type="hidden" name="phase" value="three" />';
10208: }
10209: } elsif ($applies) {
10210: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10211: if ($applies > 1) {
10212: $output .=
1.1075.2.35 raeburn 10213: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10214: if ($numremref) {
10215: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10216: }
10217: if ($numinvalid) {
10218: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10219: }
10220: if ($numexisting) {
10221: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10222: }
10223: $output .= '</ul><br />';
10224: } elsif ($numremref) {
10225: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10226: } elsif ($numinvalid) {
10227: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10228: } elsif ($numexisting) {
10229: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10230: }
10231: $output .= $upload_output.'<br />';
10232: }
10233: my ($pathchange_output,$chgcount);
1.1071 raeburn 10234: $chgcount = $counter;
1.987 raeburn 10235: if (keys(%pathchanges) > 0) {
10236: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10237: if ($counter) {
1.987 raeburn 10238: $output .= &embedded_file_element('pathchange',$chgcount,
10239: $embed_file,\%mapping,
1.1071 raeburn 10240: $allfiles,$codebase,'change');
1.987 raeburn 10241: } else {
10242: $pathchange_output .=
10243: &start_data_table_row().
10244: '<td><input type ="checkbox" name="namechange" value="'.
10245: $chgcount.'" checked="checked" /></td>'.
10246: '<td>'.$mapping{$embed_file}.'</td>'.
10247: '<td>'.$embed_file.
10248: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10249: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10250: '</td>'.&end_data_table_row();
1.660 raeburn 10251: }
1.987 raeburn 10252: $numpathchg ++;
10253: $chgcount ++;
1.660 raeburn 10254: }
10255: }
1.1075.2.35 raeburn 10256: if (($counter) || ($numunused)) {
1.987 raeburn 10257: if ($numpathchg) {
10258: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10259: $numpathchg.'" />'."\n";
10260: }
10261: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10262: ($actionurl eq '/adm/imsimport')) {
10263: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10264: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10265: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10266: } elsif ($actionurl eq '/adm/dependencies') {
10267: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10268: }
1.1075.2.35 raeburn 10269: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10270: } elsif ($numpathchg) {
10271: my %pathchange = ();
10272: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10273: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10274: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10275: }
1.987 raeburn 10276: }
1.1071 raeburn 10277: return ($output,$counter,$numpathchg);
1.987 raeburn 10278: }
10279:
1.1075.2.47 raeburn 10280: =pod
10281:
10282: =item * clean_path($name)
10283:
10284: Performs clean-up of directories, subdirectories and filename in an
10285: embedded object, referenced in an HTML file which is being uploaded
10286: to a course or portfolio, where
10287: "Upload embedded images/multimedia files if HTML file" checkbox was
10288: checked.
10289:
10290: Clean-up is similar to replacements in lonnet::clean_filename()
10291: except each / between sub-directory and next level is preserved.
10292:
10293: =cut
10294:
10295: sub clean_path {
10296: my ($embed_file) = @_;
10297: $embed_file =~s{^/+}{};
10298: my @contents;
10299: if ($embed_file =~ m{/}) {
10300: @contents = split(/\//,$embed_file);
10301: } else {
10302: @contents = ($embed_file);
10303: }
10304: my $lastidx = scalar(@contents)-1;
10305: for (my $i=0; $i<=$lastidx; $i++) {
10306: $contents[$i]=~s{\\}{/}g;
10307: $contents[$i]=~s/\s+/\_/g;
10308: $contents[$i]=~s{[^/\w\.\-]}{}g;
10309: if ($i == $lastidx) {
10310: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10311: }
10312: }
10313: if ($lastidx > 0) {
10314: return join('/',@contents);
10315: } else {
10316: return $contents[0];
10317: }
10318: }
10319:
1.987 raeburn 10320: sub embedded_file_element {
1.1071 raeburn 10321: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10322: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10323: (ref($codebase) eq 'HASH'));
10324: my $output;
1.1071 raeburn 10325: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10326: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10327: }
10328: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10329: &escape($embed_file).'" />';
10330: unless (($context eq 'upload_embedded') &&
10331: ($mapping->{$embed_file} eq $embed_file)) {
10332: $output .='
10333: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10334: }
10335: my $attrib;
10336: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10337: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10338: }
10339: $output .=
10340: "\n\t\t".
10341: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10342: $attrib.'" />';
10343: if (exists($codebase->{$mapping->{$embed_file}})) {
10344: $output .=
10345: "\n\t\t".
10346: '<input name="codebase_'.$num.'" type="hidden" value="'.
10347: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10348: }
1.987 raeburn 10349: return $output;
1.660 raeburn 10350: }
10351:
1.1071 raeburn 10352: sub get_dependency_details {
10353: my ($currfile,$currsubfile,$embed_file) = @_;
10354: my ($size,$mtime,$showsize,$showmtime);
10355: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10356: if ($embed_file =~ m{/}) {
10357: my ($path,$fname) = split(/\//,$embed_file);
10358: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10359: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10360: }
10361: } else {
10362: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10363: ($size,$mtime) = @{$currfile->{$embed_file}};
10364: }
10365: }
10366: $showsize = $size/1024.0;
10367: $showsize = sprintf("%.1f",$showsize);
10368: if ($mtime > 0) {
10369: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10370: }
10371: }
10372: return ($showsize,$showmtime);
10373: }
10374:
10375: sub ask_embedded_js {
10376: return <<"END";
10377: <script type="text/javascript"">
10378: // <![CDATA[
10379: function toggleBrowse(counter) {
10380: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10381: var fileid = document.getElementById('embedded_item_'+counter);
10382: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10383: if (chkboxid.checked == true) {
10384: uploaddivid.style.display='block';
10385: } else {
10386: uploaddivid.style.display='none';
10387: fileid.value = '';
10388: }
10389: }
10390: // ]]>
10391: </script>
10392:
10393: END
10394: }
10395:
1.661 raeburn 10396: sub upload_embedded {
10397: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10398: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10399: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10400: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10401: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10402: my $orig_uploaded_filename =
10403: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10404: foreach my $type ('orig','ref','attrib','codebase') {
10405: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10406: $env{'form.embedded_'.$type.'_'.$i} =
10407: &unescape($env{'form.embedded_'.$type.'_'.$i});
10408: }
10409: }
1.661 raeburn 10410: my ($path,$fname) =
10411: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10412: # no path, whole string is fname
10413: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10414: $fname = &Apache::lonnet::clean_filename($fname);
10415: # See if there is anything left
10416: next if ($fname eq '');
10417:
10418: # Check if file already exists as a file or directory.
10419: my ($state,$msg);
10420: if ($context eq 'portfolio') {
10421: my $port_path = $dirpath;
10422: if ($group ne '') {
10423: $port_path = "groups/$group/$port_path";
10424: }
1.987 raeburn 10425: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10426: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10427: $dir_root,$port_path,$disk_quota,
10428: $current_disk_usage,$uname,$udom);
10429: if ($state eq 'will_exceed_quota'
1.984 raeburn 10430: || $state eq 'file_locked') {
1.661 raeburn 10431: $output .= $msg;
10432: next;
10433: }
10434: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10435: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10436: if ($state eq 'exists') {
10437: $output .= $msg;
10438: next;
10439: }
10440: }
10441: # Check if extension is valid
10442: if (($fname =~ /\.(\w+)$/) &&
10443: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10444: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10445: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10446: next;
10447: } elsif (($fname =~ /\.(\w+)$/) &&
10448: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10449: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10450: next;
10451: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10452: $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10453: next;
10454: }
10455: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10456: my $subdir = $path;
10457: $subdir =~ s{/+$}{};
1.661 raeburn 10458: if ($context eq 'portfolio') {
1.984 raeburn 10459: my $result;
10460: if ($state eq 'existingfile') {
10461: $result=
10462: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10463: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10464: } else {
1.984 raeburn 10465: $result=
10466: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10467: $dirpath.
1.1075.2.35 raeburn 10468: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10469: if ($result !~ m|^/uploaded/|) {
10470: $output .= '<span class="LC_error">'
10471: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10472: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10473: .'</span><br />';
10474: next;
10475: } else {
1.987 raeburn 10476: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10477: $path.$fname.'</span>').'<br />';
1.984 raeburn 10478: }
1.661 raeburn 10479: }
1.1075.2.35 raeburn 10480: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10481: my $extendedsubdir = $dirpath.'/'.$subdir;
10482: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10483: my $result =
1.1075.2.35 raeburn 10484: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10485: if ($result !~ m|^/uploaded/|) {
10486: $output .= '<span class="LC_error">'
10487: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10488: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10489: .'</span><br />';
10490: next;
10491: } else {
10492: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10493: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10494: if ($context eq 'syllabus') {
10495: &Apache::lonnet::make_public_indefinitely($result);
10496: }
1.987 raeburn 10497: }
1.661 raeburn 10498: } else {
10499: # Save the file
10500: my $target = $env{'form.embedded_item_'.$i};
10501: my $fullpath = $dir_root.$dirpath.'/'.$path;
10502: my $dest = $fullpath.$fname;
10503: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10504: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10505: my $count;
10506: my $filepath = $dir_root;
1.1027 raeburn 10507: foreach my $subdir (@parts) {
10508: $filepath .= "/$subdir";
10509: if (!-e $filepath) {
1.661 raeburn 10510: mkdir($filepath,0770);
10511: }
10512: }
10513: my $fh;
10514: if (!open($fh,'>'.$dest)) {
10515: &Apache::lonnet::logthis('Failed to create '.$dest);
10516: $output .= '<span class="LC_error">'.
1.1071 raeburn 10517: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10518: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10519: '</span><br />';
10520: } else {
10521: if (!print $fh $env{'form.embedded_item_'.$i}) {
10522: &Apache::lonnet::logthis('Failed to write to '.$dest);
10523: $output .= '<span class="LC_error">'.
1.1071 raeburn 10524: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10525: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10526: '</span><br />';
10527: } else {
1.987 raeburn 10528: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10529: $url.'</span>').'<br />';
10530: unless ($context eq 'testbank') {
10531: $footer .= &mt('View embedded file: [_1]',
10532: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10533: }
10534: }
10535: close($fh);
10536: }
10537: }
10538: if ($env{'form.embedded_ref_'.$i}) {
10539: $pathchange{$i} = 1;
10540: }
10541: }
10542: if ($output) {
10543: $output = '<p>'.$output.'</p>';
10544: }
10545: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10546: $returnflag = 'ok';
1.1071 raeburn 10547: my $numpathchgs = scalar(keys(%pathchange));
10548: if ($numpathchgs > 0) {
1.987 raeburn 10549: if ($context eq 'portfolio') {
10550: $output .= '<p>'.&mt('or').'</p>';
10551: } elsif ($context eq 'testbank') {
1.1071 raeburn 10552: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10553: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10554: $returnflag = 'modify_orightml';
10555: }
10556: }
1.1071 raeburn 10557: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10558: }
10559:
10560: sub modify_html_form {
10561: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10562: my $end = 0;
10563: my $modifyform;
10564: if ($context eq 'upload_embedded') {
10565: return unless (ref($pathchange) eq 'HASH');
10566: if ($env{'form.number_embedded_items'}) {
10567: $end += $env{'form.number_embedded_items'};
10568: }
10569: if ($env{'form.number_pathchange_items'}) {
10570: $end += $env{'form.number_pathchange_items'};
10571: }
10572: if ($end) {
10573: for (my $i=0; $i<$end; $i++) {
10574: if ($i < $env{'form.number_embedded_items'}) {
10575: next unless($pathchange->{$i});
10576: }
10577: $modifyform .=
10578: &start_data_table_row().
10579: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10580: 'checked="checked" /></td>'.
10581: '<td>'.$env{'form.embedded_ref_'.$i}.
10582: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10583: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10584: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10585: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10586: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10587: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10588: '<td>'.$env{'form.embedded_orig_'.$i}.
10589: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10590: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10591: &end_data_table_row();
1.1071 raeburn 10592: }
1.987 raeburn 10593: }
10594: } else {
10595: $modifyform = $pathchgtable;
10596: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10597: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10598: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10599: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10600: }
10601: }
10602: if ($modifyform) {
1.1071 raeburn 10603: if ($actionurl eq '/adm/dependencies') {
10604: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10605: }
1.987 raeburn 10606: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10607: '<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".
10608: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10609: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10610: '</ol></p>'."\n".'<p>'.
10611: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10612: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10613: &start_data_table()."\n".
10614: &start_data_table_header_row().
10615: '<th>'.&mt('Change?').'</th>'.
10616: '<th>'.&mt('Current reference').'</th>'.
10617: '<th>'.&mt('Required reference').'</th>'.
10618: &end_data_table_header_row()."\n".
10619: $modifyform.
10620: &end_data_table().'<br />'."\n".$hiddenstate.
10621: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10622: '</form>'."\n";
10623: }
10624: return;
10625: }
10626:
10627: sub modify_html_refs {
1.1075.2.35 raeburn 10628: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10629: my $container;
10630: if ($context eq 'portfolio') {
10631: $container = $env{'form.container'};
10632: } elsif ($context eq 'coursedoc') {
10633: $container = $env{'form.primaryurl'};
1.1071 raeburn 10634: } elsif ($context eq 'manage_dependencies') {
10635: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10636: $container = "/$container";
1.1075.2.35 raeburn 10637: } elsif ($context eq 'syllabus') {
10638: $container = $url;
1.987 raeburn 10639: } else {
1.1027 raeburn 10640: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10641: }
10642: my (%allfiles,%codebase,$output,$content);
10643: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10644: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10645: if (wantarray) {
10646: return ('',0,0);
10647: } else {
10648: return;
10649: }
10650: }
10651: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10652: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10653: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10654: if (wantarray) {
10655: return ('',0,0);
10656: } else {
10657: return;
10658: }
10659: }
1.987 raeburn 10660: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10661: if ($content eq '-1') {
10662: if (wantarray) {
10663: return ('',0,0);
10664: } else {
10665: return;
10666: }
10667: }
1.987 raeburn 10668: } else {
1.1071 raeburn 10669: unless ($container =~ /^\Q$dir_root\E/) {
10670: if (wantarray) {
10671: return ('',0,0);
10672: } else {
10673: return;
10674: }
10675: }
1.987 raeburn 10676: if (open(my $fh,"<$container")) {
10677: $content = join('', <$fh>);
10678: close($fh);
10679: } else {
1.1071 raeburn 10680: if (wantarray) {
10681: return ('',0,0);
10682: } else {
10683: return;
10684: }
1.987 raeburn 10685: }
10686: }
10687: my ($count,$codebasecount) = (0,0);
10688: my $mm = new File::MMagic;
10689: my $mime_type = $mm->checktype_contents($content);
10690: if ($mime_type eq 'text/html') {
10691: my $parse_result =
10692: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10693: \%codebase,\$content);
10694: if ($parse_result eq 'ok') {
10695: foreach my $i (@changes) {
10696: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10697: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10698: if ($allfiles{$ref}) {
10699: my $newname = $orig;
10700: my ($attrib_regexp,$codebase);
1.1006 raeburn 10701: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10702: if ($attrib_regexp =~ /:/) {
10703: $attrib_regexp =~ s/\:/|/g;
10704: }
10705: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10706: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10707: $count += $numchg;
1.1075.2.35 raeburn 10708: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10709: delete($allfiles{$ref});
1.987 raeburn 10710: }
10711: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10712: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10713: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10714: $codebasecount ++;
10715: }
10716: }
10717: }
1.1075.2.35 raeburn 10718: my $skiprewrites;
1.987 raeburn 10719: if ($count || $codebasecount) {
10720: my $saveresult;
1.1071 raeburn 10721: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10722: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10723: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10724: if ($url eq $container) {
10725: my ($fname) = ($container =~ m{/([^/]+)$});
10726: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10727: $count,'<span class="LC_filename">'.
1.1071 raeburn 10728: $fname.'</span>').'</p>';
1.987 raeburn 10729: } else {
10730: $output = '<p class="LC_error">'.
10731: &mt('Error: update failed for: [_1].',
10732: '<span class="LC_filename">'.
10733: $container.'</span>').'</p>';
10734: }
1.1075.2.35 raeburn 10735: if ($context eq 'syllabus') {
10736: unless ($saveresult eq 'ok') {
10737: $skiprewrites = 1;
10738: }
10739: }
1.987 raeburn 10740: } else {
10741: if (open(my $fh,">$container")) {
10742: print $fh $content;
10743: close($fh);
10744: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10745: $count,'<span class="LC_filename">'.
10746: $container.'</span>').'</p>';
1.661 raeburn 10747: } else {
1.987 raeburn 10748: $output = '<p class="LC_error">'.
10749: &mt('Error: could not update [_1].',
10750: '<span class="LC_filename">'.
10751: $container.'</span>').'</p>';
1.661 raeburn 10752: }
10753: }
10754: }
1.1075.2.35 raeburn 10755: if (($context eq 'syllabus') && (!$skiprewrites)) {
10756: my ($actionurl,$state);
10757: $actionurl = "/public/$udom/$uname/syllabus";
10758: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10759: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10760: \%codebase,
10761: {'context' => 'rewrites',
10762: 'ignore_remote_references' => 1,});
10763: if (ref($mapping) eq 'HASH') {
10764: my $rewrites = 0;
10765: foreach my $key (keys(%{$mapping})) {
10766: next if ($key =~ m{^https?://});
10767: my $ref = $mapping->{$key};
10768: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10769: my $attrib;
10770: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10771: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10772: }
10773: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10774: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10775: $rewrites += $numchg;
10776: }
10777: }
10778: if ($rewrites) {
10779: my $saveresult;
10780: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10781: if ($url eq $container) {
10782: my ($fname) = ($container =~ m{/([^/]+)$});
10783: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10784: $count,'<span class="LC_filename">'.
10785: $fname.'</span>').'</p>';
10786: } else {
10787: $output .= '<p class="LC_error">'.
10788: &mt('Error: could not update links in [_1].',
10789: '<span class="LC_filename">'.
10790: $container.'</span>').'</p>';
10791:
10792: }
10793: }
10794: }
10795: }
1.987 raeburn 10796: } else {
10797: &logthis('Failed to parse '.$container.
10798: ' to modify references: '.$parse_result);
1.661 raeburn 10799: }
10800: }
1.1071 raeburn 10801: if (wantarray) {
10802: return ($output,$count,$codebasecount);
10803: } else {
10804: return $output;
10805: }
1.661 raeburn 10806: }
10807:
10808: sub check_for_existing {
10809: my ($path,$fname,$element) = @_;
10810: my ($state,$msg);
10811: if (-d $path.'/'.$fname) {
10812: $state = 'exists';
10813: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10814: } elsif (-e $path.'/'.$fname) {
10815: $state = 'exists';
10816: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10817: }
10818: if ($state eq 'exists') {
10819: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10820: }
10821: return ($state,$msg);
10822: }
10823:
10824: sub check_for_upload {
10825: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10826: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10827: my $filesize = length($env{'form.'.$element});
10828: if (!$filesize) {
10829: my $msg = '<span class="LC_error">'.
10830: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10831: '<span class="LC_filename">'.$fname.'</span>',
10832: $filesize).'<br />'.
1.1007 raeburn 10833: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10834: '</span>';
10835: return ('zero_bytes',$msg);
10836: }
10837: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10838: my $getpropath = 1;
1.1021 raeburn 10839: my ($dirlistref,$listerror) =
10840: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10841: my $found_file = 0;
10842: my $locked_file = 0;
1.991 raeburn 10843: my @lockers;
10844: my $navmap;
10845: if ($env{'request.course.id'}) {
10846: $navmap = Apache::lonnavmaps::navmap->new();
10847: }
1.1021 raeburn 10848: if (ref($dirlistref) eq 'ARRAY') {
10849: foreach my $line (@{$dirlistref}) {
10850: my ($file_name,$rest)=split(/\&/,$line,2);
10851: if ($file_name eq $fname){
10852: $file_name = $path.$file_name;
10853: if ($group ne '') {
10854: $file_name = $group.$file_name;
10855: }
10856: $found_file = 1;
10857: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10858: foreach my $lock (@lockers) {
10859: if (ref($lock) eq 'ARRAY') {
10860: my ($symb,$crsid) = @{$lock};
10861: if ($crsid eq $env{'request.course.id'}) {
10862: if (ref($navmap)) {
10863: my $res = $navmap->getBySymb($symb);
10864: foreach my $part (@{$res->parts()}) {
10865: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10866: unless (($slot_status == $res->RESERVED) ||
10867: ($slot_status == $res->RESERVED_LOCATION)) {
10868: $locked_file = 1;
10869: }
1.991 raeburn 10870: }
1.1021 raeburn 10871: } else {
10872: $locked_file = 1;
1.991 raeburn 10873: }
10874: } else {
10875: $locked_file = 1;
10876: }
10877: }
1.1021 raeburn 10878: }
10879: } else {
10880: my @info = split(/\&/,$rest);
10881: my $currsize = $info[6]/1000;
10882: if ($currsize < $filesize) {
10883: my $extra = $filesize - $currsize;
10884: if (($current_disk_usage + $extra) > $disk_quota) {
10885: my $msg = '<span class="LC_error">'.
10886: &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.',
10887: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10888: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10889: $disk_quota,$current_disk_usage);
10890: return ('will_exceed_quota',$msg);
10891: }
1.984 raeburn 10892: }
10893: }
1.661 raeburn 10894: }
10895: }
10896: }
10897: if (($current_disk_usage + $filesize) > $disk_quota){
10898: my $msg = '<span class="LC_error">'.
10899: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10900: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10901: return ('will_exceed_quota',$msg);
10902: } elsif ($found_file) {
10903: if ($locked_file) {
10904: my $msg = '<span class="LC_error">';
10905: $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>');
10906: $msg .= '</span><br />';
10907: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10908: return ('file_locked',$msg);
10909: } else {
10910: my $msg = '<span class="LC_error">';
1.984 raeburn 10911: $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 10912: $msg .= '</span>';
1.984 raeburn 10913: return ('existingfile',$msg);
1.661 raeburn 10914: }
10915: }
10916: }
10917:
1.987 raeburn 10918: sub check_for_traversal {
10919: my ($path,$url,$toplevel) = @_;
10920: my @parts=split(/\//,$path);
10921: my $cleanpath;
10922: my $fullpath = $url;
10923: for (my $i=0;$i<@parts;$i++) {
10924: next if ($parts[$i] eq '.');
10925: if ($parts[$i] eq '..') {
10926: $fullpath =~ s{([^/]+/)$}{};
10927: } else {
10928: $fullpath .= $parts[$i].'/';
10929: }
10930: }
10931: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10932: $cleanpath = $1;
10933: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10934: my $curr_toprel = $1;
10935: my @parts = split(/\//,$curr_toprel);
10936: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10937: my @urlparts = split(/\//,$url_toprel);
10938: my $doubledots;
10939: my $startdiff = -1;
10940: for (my $i=0; $i<@urlparts; $i++) {
10941: if ($startdiff == -1) {
10942: unless ($urlparts[$i] eq $parts[$i]) {
10943: $startdiff = $i;
10944: $doubledots .= '../';
10945: }
10946: } else {
10947: $doubledots .= '../';
10948: }
10949: }
10950: if ($startdiff > -1) {
10951: $cleanpath = $doubledots;
10952: for (my $i=$startdiff; $i<@parts; $i++) {
10953: $cleanpath .= $parts[$i].'/';
10954: }
10955: }
10956: }
10957: $cleanpath =~ s{(/)$}{};
10958: return $cleanpath;
10959: }
1.31 albertel 10960:
1.1053 raeburn 10961: sub is_archive_file {
10962: my ($mimetype) = @_;
10963: if (($mimetype eq 'application/octet-stream') ||
10964: ($mimetype eq 'application/x-stuffit') ||
10965: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10966: return 1;
10967: }
10968: return;
10969: }
10970:
10971: sub decompress_form {
1.1065 raeburn 10972: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10973: my %lt = &Apache::lonlocal::texthash (
10974: this => 'This file is an archive file.',
1.1067 raeburn 10975: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10976: itsc => 'Its contents are as follows:',
1.1053 raeburn 10977: youm => 'You may wish to extract its contents.',
10978: extr => 'Extract contents',
1.1067 raeburn 10979: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10980: proa => 'Process automatically?',
1.1053 raeburn 10981: yes => 'Yes',
10982: no => 'No',
1.1067 raeburn 10983: fold => 'Title for folder containing movie',
10984: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10985: );
1.1065 raeburn 10986: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10987: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10988: my $info = &list_archive_contents($fileloc,\@paths);
10989: if (@paths) {
10990: foreach my $path (@paths) {
10991: $path =~ s{^/}{};
1.1067 raeburn 10992: if ($path =~ m{^([^/]+)/$}) {
10993: $topdir = $1;
10994: }
1.1065 raeburn 10995: if ($path =~ m{^([^/]+)/}) {
10996: $toplevel{$1} = $path;
10997: } else {
10998: $toplevel{$path} = $path;
10999: }
11000: }
11001: }
1.1067 raeburn 11002: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59! raeburn 11003: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11004: "$topdir/media/",
11005: "$topdir/media/$topdir.mp4",
11006: "$topdir/media/FirstFrame.png",
11007: "$topdir/media/player.swf",
11008: "$topdir/media/swfobject.js",
11009: "$topdir/media/expressInstall.swf");
1.1075.2.59! raeburn 11010: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
! 11011: "$topdir/$topdir.mp4",
! 11012: "$topdir/$topdir\_config.xml",
! 11013: "$topdir/$topdir\_controller.swf",
! 11014: "$topdir/$topdir\_embed.css",
! 11015: "$topdir/$topdir\_First_Frame.png",
! 11016: "$topdir/$topdir\_player.html",
! 11017: "$topdir/$topdir\_Thumbnails.png",
! 11018: "$topdir/playerProductInstall.swf",
! 11019: "$topdir/scripts/",
! 11020: "$topdir/scripts/config_xml.js",
! 11021: "$topdir/scripts/handlebars.js",
! 11022: "$topdir/scripts/jquery-1.7.1.min.js",
! 11023: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
! 11024: "$topdir/scripts/modernizr.js",
! 11025: "$topdir/scripts/player-min.js",
! 11026: "$topdir/scripts/swfobject.js",
! 11027: "$topdir/skins/",
! 11028: "$topdir/skins/configuration_express.xml",
! 11029: "$topdir/skins/express_show/",
! 11030: "$topdir/skins/express_show/player-min.css",
! 11031: "$topdir/skins/express_show/spritesheet.png");
! 11032: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11033: if (@diffs == 0) {
1.1075.2.59! raeburn 11034: $is_camtasia = 6;
! 11035: } else {
! 11036: @diffs = &compare_arrays(\@paths,\@camtasia8);
! 11037: if (@diffs == 0) {
! 11038: $is_camtasia = 8;
! 11039: }
1.1067 raeburn 11040: }
11041: }
11042: my $output;
11043: if ($is_camtasia) {
11044: $output = <<"ENDCAM";
11045: <script type="text/javascript" language="Javascript">
11046: // <![CDATA[
11047:
11048: function camtasiaToggle() {
11049: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11050: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59! raeburn 11051: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11052: document.getElementById('camtasia_titles').style.display='block';
11053: } else {
11054: document.getElementById('camtasia_titles').style.display='none';
11055: }
11056: }
11057: }
11058: return;
11059: }
11060:
11061: // ]]>
11062: </script>
11063: <p>$lt{'camt'}</p>
11064: ENDCAM
1.1065 raeburn 11065: } else {
1.1067 raeburn 11066: $output = '<p>'.$lt{'this'};
11067: if ($info eq '') {
11068: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11069: } else {
11070: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11071: '<div><pre>'.$info.'</pre></div>';
11072: }
1.1065 raeburn 11073: }
1.1067 raeburn 11074: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11075: my $duplicates;
11076: my $num = 0;
11077: if (ref($dirlist) eq 'ARRAY') {
11078: foreach my $item (@{$dirlist}) {
11079: if (ref($item) eq 'ARRAY') {
11080: if (exists($toplevel{$item->[0]})) {
11081: $duplicates .=
11082: &start_data_table_row().
11083: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11084: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11085: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11086: 'value="1" />'.&mt('Yes').'</label>'.
11087: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11088: '<td>'.$item->[0].'</td>';
11089: if ($item->[2]) {
11090: $duplicates .= '<td>'.&mt('Directory').'</td>';
11091: } else {
11092: $duplicates .= '<td>'.&mt('File').'</td>';
11093: }
11094: $duplicates .= '<td>'.$item->[3].'</td>'.
11095: '<td>'.
11096: &Apache::lonlocal::locallocaltime($item->[4]).
11097: '</td>'.
11098: &end_data_table_row();
11099: $num ++;
11100: }
11101: }
11102: }
11103: }
11104: my $itemcount;
11105: if (@paths > 0) {
11106: $itemcount = scalar(@paths);
11107: } else {
11108: $itemcount = 1;
11109: }
1.1067 raeburn 11110: if ($is_camtasia) {
11111: $output .= $lt{'auto'}.'<br />'.
11112: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59! raeburn 11113: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11114: $lt{'yes'}.'</label> <label>'.
11115: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11116: $lt{'no'}.'</label></span><br />'.
11117: '<div id="camtasia_titles" style="display:block">'.
11118: &Apache::lonhtmlcommon::start_pick_box().
11119: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11120: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11121: &Apache::lonhtmlcommon::row_closure().
11122: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11123: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11124: &Apache::lonhtmlcommon::row_closure(1).
11125: &Apache::lonhtmlcommon::end_pick_box().
11126: '</div>';
11127: }
1.1065 raeburn 11128: $output .=
11129: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11130: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11131: "\n";
1.1065 raeburn 11132: if ($duplicates ne '') {
11133: $output .= '<p><span class="LC_warning">'.
11134: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11135: &start_data_table().
11136: &start_data_table_header_row().
11137: '<th>'.&mt('Overwrite?').'</th>'.
11138: '<th>'.&mt('Name').'</th>'.
11139: '<th>'.&mt('Type').'</th>'.
11140: '<th>'.&mt('Size').'</th>'.
11141: '<th>'.&mt('Last modified').'</th>'.
11142: &end_data_table_header_row().
11143: $duplicates.
11144: &end_data_table().
11145: '</p>';
11146: }
1.1067 raeburn 11147: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11148: if (ref($hiddenelements) eq 'HASH') {
11149: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11150: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11151: }
11152: }
11153: $output .= <<"END";
1.1067 raeburn 11154: <br />
1.1053 raeburn 11155: <input type="submit" name="decompress" value="$lt{'extr'}" />
11156: </form>
11157: $noextract
11158: END
11159: return $output;
11160: }
11161:
1.1065 raeburn 11162: sub decompression_utility {
11163: my ($program) = @_;
11164: my @utilities = ('tar','gunzip','bunzip2','unzip');
11165: my $location;
11166: if (grep(/^\Q$program\E$/,@utilities)) {
11167: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11168: '/usr/sbin/') {
11169: if (-x $dir.$program) {
11170: $location = $dir.$program;
11171: last;
11172: }
11173: }
11174: }
11175: return $location;
11176: }
11177:
11178: sub list_archive_contents {
11179: my ($file,$pathsref) = @_;
11180: my (@cmd,$output);
11181: my $needsregexp;
11182: if ($file =~ /\.zip$/) {
11183: @cmd = (&decompression_utility('unzip'),"-l");
11184: $needsregexp = 1;
11185: } elsif (($file =~ m/\.tar\.gz$/) ||
11186: ($file =~ /\.tgz$/)) {
11187: @cmd = (&decompression_utility('tar'),"-ztf");
11188: } elsif ($file =~ /\.tar\.bz2$/) {
11189: @cmd = (&decompression_utility('tar'),"-jtf");
11190: } elsif ($file =~ m|\.tar$|) {
11191: @cmd = (&decompression_utility('tar'),"-tf");
11192: }
11193: if (@cmd) {
11194: undef($!);
11195: undef($@);
11196: if (open(my $fh,"-|", @cmd, $file)) {
11197: while (my $line = <$fh>) {
11198: $output .= $line;
11199: chomp($line);
11200: my $item;
11201: if ($needsregexp) {
11202: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11203: } else {
11204: $item = $line;
11205: }
11206: if ($item ne '') {
11207: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11208: push(@{$pathsref},$item);
11209: }
11210: }
11211: }
11212: close($fh);
11213: }
11214: }
11215: return $output;
11216: }
11217:
1.1053 raeburn 11218: sub decompress_uploaded_file {
11219: my ($file,$dir) = @_;
11220: &Apache::lonnet::appenv({'cgi.file' => $file});
11221: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11222: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11223: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11224: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11225: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11226: my $decompressed = $env{'cgi.decompressed'};
11227: &Apache::lonnet::delenv('cgi.file');
11228: &Apache::lonnet::delenv('cgi.dir');
11229: &Apache::lonnet::delenv('cgi.decompressed');
11230: return ($decompressed,$result);
11231: }
11232:
1.1055 raeburn 11233: sub process_decompression {
11234: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11235: my ($dir,$error,$warning,$output);
11236: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34 raeburn 11237: $error = &mt('Filename not a supported archive file type.').
11238: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11239: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11240: } else {
11241: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11242: if ($docuhome eq 'no_host') {
11243: $error = &mt('Could not determine home server for course.');
11244: } else {
11245: my @ids=&Apache::lonnet::current_machine_ids();
11246: my $currdir = "$dir_root/$destination";
11247: if (grep(/^\Q$docuhome\E$/,@ids)) {
11248: $dir = &LONCAPA::propath($docudom,$docuname).
11249: "$dir_root/$destination";
11250: } else {
11251: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11252: "$dir_root/$docudom/$docuname/$destination";
11253: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11254: $error = &mt('Archive file not found.');
11255: }
11256: }
1.1065 raeburn 11257: my (@to_overwrite,@to_skip);
11258: if ($env{'form.archive_overwrite_total'} > 0) {
11259: my $total = $env{'form.archive_overwrite_total'};
11260: for (my $i=0; $i<$total; $i++) {
11261: if ($env{'form.archive_overwrite_'.$i} == 1) {
11262: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11263: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11264: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11265: }
11266: }
11267: }
11268: my $numskip = scalar(@to_skip);
11269: if (($numskip > 0) &&
11270: ($numskip == $env{'form.archive_itemcount'})) {
11271: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11272: } elsif ($dir eq '') {
1.1055 raeburn 11273: $error = &mt('Directory containing archive file unavailable.');
11274: } elsif (!$error) {
1.1065 raeburn 11275: my ($decompressed,$display);
11276: if ($numskip > 0) {
11277: my $tempdir = time.'_'.$$.int(rand(10000));
11278: mkdir("$dir/$tempdir",0755);
11279: system("mv $dir/$file $dir/$tempdir/$file");
11280: ($decompressed,$display) =
11281: &decompress_uploaded_file($file,"$dir/$tempdir");
11282: foreach my $item (@to_skip) {
11283: if (($item ne '') && ($item !~ /\.\./)) {
11284: if (-f "$dir/$tempdir/$item") {
11285: unlink("$dir/$tempdir/$item");
11286: } elsif (-d "$dir/$tempdir/$item") {
11287: system("rm -rf $dir/$tempdir/$item");
11288: }
11289: }
11290: }
11291: system("mv $dir/$tempdir/* $dir");
11292: rmdir("$dir/$tempdir");
11293: } else {
11294: ($decompressed,$display) =
11295: &decompress_uploaded_file($file,$dir);
11296: }
1.1055 raeburn 11297: if ($decompressed eq 'ok') {
1.1065 raeburn 11298: $output = '<p class="LC_info">'.
11299: &mt('Files extracted successfully from archive.').
11300: '</p>'."\n";
1.1055 raeburn 11301: my ($warning,$result,@contents);
11302: my ($newdirlistref,$newlisterror) =
11303: &Apache::lonnet::dirlist($currdir,$docudom,
11304: $docuname,1);
11305: my (%is_dir,%changes,@newitems);
11306: my $dirptr = 16384;
1.1065 raeburn 11307: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11308: foreach my $dir_line (@{$newdirlistref}) {
11309: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11310: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11311: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11312: push(@newitems,$item);
11313: if ($dirptr&$testdir) {
11314: $is_dir{$item} = 1;
11315: }
11316: $changes{$item} = 1;
11317: }
11318: }
11319: }
11320: if (keys(%changes) > 0) {
11321: foreach my $item (sort(@newitems)) {
11322: if ($changes{$item}) {
11323: push(@contents,$item);
11324: }
11325: }
11326: }
11327: if (@contents > 0) {
1.1067 raeburn 11328: my $wantform;
11329: unless ($env{'form.autoextract_camtasia'}) {
11330: $wantform = 1;
11331: }
1.1056 raeburn 11332: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11333: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11334: $currdir,\%is_dir,
11335: \%children,\%parent,
1.1056 raeburn 11336: \@contents,\%dirorder,
11337: \%titles,$wantform);
1.1055 raeburn 11338: if ($datatable ne '') {
11339: $output .= &archive_options_form('decompressed',$datatable,
11340: $count,$hiddenelem);
1.1065 raeburn 11341: my $startcount = 6;
1.1055 raeburn 11342: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11343: \%titles,\%children);
1.1055 raeburn 11344: }
1.1067 raeburn 11345: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59! raeburn 11346: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11347: my %displayed;
11348: my $total = 1;
11349: $env{'form.archive_directory'} = [];
11350: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11351: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11352: $path =~ s{/$}{};
11353: my $item;
11354: if ($path ne '') {
11355: $item = "$path/$titles{$i}";
11356: } else {
11357: $item = $titles{$i};
11358: }
11359: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11360: if ($item eq $contents[0]) {
11361: push(@{$env{'form.archive_directory'}},$i);
11362: $env{'form.archive_'.$i} = 'display';
11363: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11364: $displayed{'folder'} = $i;
1.1075.2.59! raeburn 11365: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
! 11366: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11367: $env{'form.archive_'.$i} = 'display';
11368: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11369: $displayed{'web'} = $i;
11370: } else {
1.1075.2.59! raeburn 11371: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
! 11372: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
! 11373: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11374: push(@{$env{'form.archive_directory'}},$i);
11375: }
11376: $env{'form.archive_'.$i} = 'dependency';
11377: }
11378: $total ++;
11379: }
11380: for (my $i=1; $i<$total; $i++) {
11381: next if ($i == $displayed{'web'});
11382: next if ($i == $displayed{'folder'});
11383: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11384: }
11385: $env{'form.phase'} = 'decompress_cleanup';
11386: $env{'form.archivedelete'} = 1;
11387: $env{'form.archive_count'} = $total-1;
11388: $output .=
11389: &process_extracted_files('coursedocs',$docudom,
11390: $docuname,$destination,
11391: $dir_root,$hiddenelem);
11392: }
1.1055 raeburn 11393: } else {
11394: $warning = &mt('No new items extracted from archive file.');
11395: }
11396: } else {
11397: $output = $display;
11398: $error = &mt('An error occurred during extraction from the archive file.');
11399: }
11400: }
11401: }
11402: }
11403: if ($error) {
11404: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11405: $error.'</p>'."\n";
11406: }
11407: if ($warning) {
11408: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11409: }
11410: return $output;
11411: }
11412:
11413: sub get_extracted {
1.1056 raeburn 11414: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11415: $titles,$wantform) = @_;
1.1055 raeburn 11416: my $count = 0;
11417: my $depth = 0;
11418: my $datatable;
1.1056 raeburn 11419: my @hierarchy;
1.1055 raeburn 11420: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11421: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11422: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11423: foreach my $item (@{$contents}) {
11424: $count ++;
1.1056 raeburn 11425: @{$dirorder->{$count}} = @hierarchy;
11426: $titles->{$count} = $item;
1.1055 raeburn 11427: &archive_hierarchy($depth,$count,$parent,$children);
11428: if ($wantform) {
11429: $datatable .= &archive_row($is_dir->{$item},$item,
11430: $currdir,$depth,$count);
11431: }
11432: if ($is_dir->{$item}) {
11433: $depth ++;
1.1056 raeburn 11434: push(@hierarchy,$count);
11435: $parent->{$depth} = $count;
1.1055 raeburn 11436: $datatable .=
11437: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11438: \$depth,\$count,\@hierarchy,$dirorder,
11439: $children,$parent,$titles,$wantform);
1.1055 raeburn 11440: $depth --;
1.1056 raeburn 11441: pop(@hierarchy);
1.1055 raeburn 11442: }
11443: }
11444: return ($count,$datatable);
11445: }
11446:
11447: sub recurse_extracted_archive {
1.1056 raeburn 11448: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11449: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11450: my $result='';
1.1056 raeburn 11451: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11452: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11453: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11454: return $result;
11455: }
11456: my $dirptr = 16384;
11457: my ($newdirlistref,$newlisterror) =
11458: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11459: if (ref($newdirlistref) eq 'ARRAY') {
11460: foreach my $dir_line (@{$newdirlistref}) {
11461: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11462: unless ($item =~ /^\.+$/) {
11463: $$count ++;
1.1056 raeburn 11464: @{$dirorder->{$$count}} = @{$hierarchy};
11465: $titles->{$$count} = $item;
1.1055 raeburn 11466: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11467:
1.1055 raeburn 11468: my $is_dir;
11469: if ($dirptr&$testdir) {
11470: $is_dir = 1;
11471: }
11472: if ($wantform) {
11473: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11474: }
11475: if ($is_dir) {
11476: $$depth ++;
1.1056 raeburn 11477: push(@{$hierarchy},$$count);
11478: $parent->{$$depth} = $$count;
1.1055 raeburn 11479: $result .=
11480: &recurse_extracted_archive("$currdir/$item",$docudom,
11481: $docuname,$depth,$count,
1.1056 raeburn 11482: $hierarchy,$dirorder,$children,
11483: $parent,$titles,$wantform);
1.1055 raeburn 11484: $$depth --;
1.1056 raeburn 11485: pop(@{$hierarchy});
1.1055 raeburn 11486: }
11487: }
11488: }
11489: }
11490: return $result;
11491: }
11492:
11493: sub archive_hierarchy {
11494: my ($depth,$count,$parent,$children) =@_;
11495: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11496: if (exists($parent->{$depth})) {
11497: $children->{$parent->{$depth}} .= $count.':';
11498: }
11499: }
11500: return;
11501: }
11502:
11503: sub archive_row {
11504: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11505: my ($name) = ($item =~ m{([^/]+)$});
11506: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11507: 'display' => 'Add as file',
1.1055 raeburn 11508: 'dependency' => 'Include as dependency',
11509: 'discard' => 'Discard',
11510: );
11511: if ($is_dir) {
1.1059 raeburn 11512: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11513: }
1.1056 raeburn 11514: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11515: my $offset = 0;
1.1055 raeburn 11516: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11517: $offset ++;
1.1065 raeburn 11518: if ($action ne 'display') {
11519: $offset ++;
11520: }
1.1055 raeburn 11521: $output .= '<td><span class="LC_nobreak">'.
11522: '<label><input type="radio" name="archive_'.$count.
11523: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11524: my $text = $choices{$action};
11525: if ($is_dir) {
11526: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11527: if ($action eq 'display') {
1.1059 raeburn 11528: $text = &mt('Add as folder');
1.1055 raeburn 11529: }
1.1056 raeburn 11530: } else {
11531: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11532:
11533: }
11534: $output .= ' /> '.$choices{$action}.'</label></span>';
11535: if ($action eq 'dependency') {
11536: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11537: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11538: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11539: '<option value=""></option>'."\n".
11540: '</select>'."\n".
11541: '</div>';
1.1059 raeburn 11542: } elsif ($action eq 'display') {
11543: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11544: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11545: '</div>';
1.1055 raeburn 11546: }
1.1056 raeburn 11547: $output .= '</td>';
1.1055 raeburn 11548: }
11549: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11550: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11551: for (my $i=0; $i<$depth; $i++) {
11552: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11553: }
11554: if ($is_dir) {
11555: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11556: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11557: } else {
11558: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11559: }
11560: $output .= ' '.$name.'</td>'."\n".
11561: &end_data_table_row();
11562: return $output;
11563: }
11564:
11565: sub archive_options_form {
1.1065 raeburn 11566: my ($form,$display,$count,$hiddenelem) = @_;
11567: my %lt = &Apache::lonlocal::texthash(
11568: perm => 'Permanently remove archive file?',
11569: hows => 'How should each extracted item be incorporated in the course?',
11570: cont => 'Content actions for all',
11571: addf => 'Add as folder/file',
11572: incd => 'Include as dependency for a displayed file',
11573: disc => 'Discard',
11574: no => 'No',
11575: yes => 'Yes',
11576: save => 'Save',
11577: );
11578: my $output = <<"END";
11579: <form name="$form" method="post" action="">
11580: <p><span class="LC_nobreak">$lt{'perm'}
11581: <label>
11582: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11583: </label>
11584:
11585: <label>
11586: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11587: </span>
11588: </p>
11589: <input type="hidden" name="phase" value="decompress_cleanup" />
11590: <br />$lt{'hows'}
11591: <div class="LC_columnSection">
11592: <fieldset>
11593: <legend>$lt{'cont'}</legend>
11594: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11595: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11596: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11597: </fieldset>
11598: </div>
11599: END
11600: return $output.
1.1055 raeburn 11601: &start_data_table()."\n".
1.1065 raeburn 11602: $display."\n".
1.1055 raeburn 11603: &end_data_table()."\n".
11604: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11605: $hiddenelem.
1.1065 raeburn 11606: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11607: '</form>';
11608: }
11609:
11610: sub archive_javascript {
1.1056 raeburn 11611: my ($startcount,$numitems,$titles,$children) = @_;
11612: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11613: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11614: my $scripttag = <<START;
11615: <script type="text/javascript">
11616: // <![CDATA[
11617:
11618: function checkAll(form,prefix) {
11619: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11620: for (var i=0; i < form.elements.length; i++) {
11621: var id = form.elements[i].id;
11622: if ((id != '') && (id != undefined)) {
11623: if (idstr.test(id)) {
11624: if (form.elements[i].type == 'radio') {
11625: form.elements[i].checked = true;
1.1056 raeburn 11626: var nostart = i-$startcount;
1.1059 raeburn 11627: var offset = nostart%7;
11628: var count = (nostart-offset)/7;
1.1056 raeburn 11629: dependencyCheck(form,count,offset);
1.1055 raeburn 11630: }
11631: }
11632: }
11633: }
11634: }
11635:
11636: function propagateCheck(form,count) {
11637: if (count > 0) {
1.1059 raeburn 11638: var startelement = $startcount + ((count-1) * 7);
11639: for (var j=1; j<6; j++) {
11640: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11641: var item = startelement + j;
11642: if (form.elements[item].type == 'radio') {
11643: if (form.elements[item].checked) {
11644: containerCheck(form,count,j);
11645: break;
11646: }
1.1055 raeburn 11647: }
11648: }
11649: }
11650: }
11651: }
11652:
11653: numitems = $numitems
1.1056 raeburn 11654: var titles = new Array(numitems);
11655: var parents = new Array(numitems);
1.1055 raeburn 11656: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11657: parents[i] = new Array;
1.1055 raeburn 11658: }
1.1059 raeburn 11659: var maintitle = '$maintitle';
1.1055 raeburn 11660:
11661: START
11662:
1.1056 raeburn 11663: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11664: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11665: for (my $i=0; $i<@contents; $i ++) {
11666: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11667: }
11668: }
11669:
1.1056 raeburn 11670: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11671: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11672: }
11673:
1.1055 raeburn 11674: $scripttag .= <<END;
11675:
11676: function containerCheck(form,count,offset) {
11677: if (count > 0) {
1.1056 raeburn 11678: dependencyCheck(form,count,offset);
1.1059 raeburn 11679: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11680: form.elements[item].checked = true;
11681: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11682: if (parents[count].length > 0) {
11683: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11684: containerCheck(form,parents[count][j],offset);
11685: }
11686: }
11687: }
11688: }
11689: }
11690:
11691: function dependencyCheck(form,count,offset) {
11692: if (count > 0) {
1.1059 raeburn 11693: var chosen = (offset+$startcount)+7*(count-1);
11694: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11695: var currtype = form.elements[depitem].type;
11696: if (form.elements[chosen].value == 'dependency') {
11697: document.getElementById('arc_depon_'+count).style.display='block';
11698: form.elements[depitem].options.length = 0;
11699: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11700: for (var i=1; i<=numitems; i++) {
11701: if (i == count) {
11702: continue;
11703: }
1.1059 raeburn 11704: var startelement = $startcount + (i-1) * 7;
11705: for (var j=1; j<6; j++) {
11706: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11707: var item = startelement + j;
11708: if (form.elements[item].type == 'radio') {
11709: if (form.elements[item].checked) {
11710: if (form.elements[item].value == 'display') {
11711: var n = form.elements[depitem].options.length;
11712: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11713: }
11714: }
11715: }
11716: }
11717: }
11718: }
11719: } else {
11720: document.getElementById('arc_depon_'+count).style.display='none';
11721: form.elements[depitem].options.length = 0;
11722: form.elements[depitem].options[0] = new Option('Select','',true,true);
11723: }
1.1059 raeburn 11724: titleCheck(form,count,offset);
1.1056 raeburn 11725: }
11726: }
11727:
11728: function propagateSelect(form,count,offset) {
11729: if (count > 0) {
1.1065 raeburn 11730: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11731: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11732: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11733: if (parents[count].length > 0) {
11734: for (var j=0; j<parents[count].length; j++) {
11735: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11736: }
11737: }
11738: }
11739: }
11740: }
1.1056 raeburn 11741:
11742: function containerSelect(form,count,offset,picked) {
11743: if (count > 0) {
1.1065 raeburn 11744: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11745: if (form.elements[item].type == 'radio') {
11746: if (form.elements[item].value == 'dependency') {
11747: if (form.elements[item+1].type == 'select-one') {
11748: for (var i=0; i<form.elements[item+1].options.length; i++) {
11749: if (form.elements[item+1].options[i].value == picked) {
11750: form.elements[item+1].selectedIndex = i;
11751: break;
11752: }
11753: }
11754: }
11755: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11756: if (parents[count].length > 0) {
11757: for (var j=0; j<parents[count].length; j++) {
11758: containerSelect(form,parents[count][j],offset,picked);
11759: }
11760: }
11761: }
11762: }
11763: }
11764: }
11765: }
11766:
1.1059 raeburn 11767: function titleCheck(form,count,offset) {
11768: if (count > 0) {
11769: var chosen = (offset+$startcount)+7*(count-1);
11770: var depitem = $startcount + ((count-1) * 7) + 2;
11771: var currtype = form.elements[depitem].type;
11772: if (form.elements[chosen].value == 'display') {
11773: document.getElementById('arc_title_'+count).style.display='block';
11774: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11775: document.getElementById('archive_title_'+count).value=maintitle;
11776: }
11777: } else {
11778: document.getElementById('arc_title_'+count).style.display='none';
11779: if (currtype == 'text') {
11780: document.getElementById('archive_title_'+count).value='';
11781: }
11782: }
11783: }
11784: return;
11785: }
11786:
1.1055 raeburn 11787: // ]]>
11788: </script>
11789: END
11790: return $scripttag;
11791: }
11792:
11793: sub process_extracted_files {
1.1067 raeburn 11794: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11795: my $numitems = $env{'form.archive_count'};
11796: return unless ($numitems);
11797: my @ids=&Apache::lonnet::current_machine_ids();
11798: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11799: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11800: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11801: if (grep(/^\Q$docuhome\E$/,@ids)) {
11802: $prefix = &LONCAPA::propath($docudom,$docuname);
11803: $pathtocheck = "$dir_root/$destination";
11804: $dir = $dir_root;
11805: $ishome = 1;
11806: } else {
11807: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11808: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11809: $dir = "$dir_root/$docudom/$docuname";
11810: }
11811: my $currdir = "$dir_root/$destination";
11812: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11813: if ($env{'form.folderpath'}) {
11814: my @items = split('&',$env{'form.folderpath'});
11815: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11816: if ($env{'form.folderpath'} =~ /\:1$/) {
11817: $containers{'0'}='page';
11818: } else {
11819: $containers{'0'}='sequence';
11820: }
1.1055 raeburn 11821: }
11822: my @archdirs = &get_env_multiple('form.archive_directory');
11823: if ($numitems) {
11824: for (my $i=1; $i<=$numitems; $i++) {
11825: my $path = $env{'form.archive_content_'.$i};
11826: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11827: my $item = $1;
11828: $toplevelitems{$item} = $i;
11829: if (grep(/^\Q$i\E$/,@archdirs)) {
11830: $is_dir{$item} = 1;
11831: }
11832: }
11833: }
11834: }
1.1067 raeburn 11835: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11836: if (keys(%toplevelitems) > 0) {
11837: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11838: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11839: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11840: }
1.1066 raeburn 11841: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11842: if ($numitems) {
11843: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11844: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11845: my $path = $env{'form.archive_content_'.$i};
11846: if ($path =~ /^\Q$pathtocheck\E/) {
11847: if ($env{'form.archive_'.$i} eq 'discard') {
11848: if ($prefix ne '' && $path ne '') {
11849: if (-e $prefix.$path) {
1.1066 raeburn 11850: if ((@archdirs > 0) &&
11851: (grep(/^\Q$i\E$/,@archdirs))) {
11852: $todeletedir{$prefix.$path} = 1;
11853: } else {
11854: $todelete{$prefix.$path} = 1;
11855: }
1.1055 raeburn 11856: }
11857: }
11858: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11859: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11860: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11861: $docstitle = $env{'form.archive_title_'.$i};
11862: if ($docstitle eq '') {
11863: $docstitle = $title;
11864: }
1.1055 raeburn 11865: $outer = 0;
1.1056 raeburn 11866: if (ref($dirorder{$i}) eq 'ARRAY') {
11867: if (@{$dirorder{$i}} > 0) {
11868: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11869: if ($env{'form.archive_'.$item} eq 'display') {
11870: $outer = $item;
11871: last;
11872: }
11873: }
11874: }
11875: }
11876: my ($errtext,$fatal) =
11877: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11878: '/'.$folders{$outer}.'.'.
11879: $containers{$outer});
11880: next if ($fatal);
11881: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11882: if ($context eq 'coursedocs') {
1.1056 raeburn 11883: $mapinner{$i} = time;
1.1055 raeburn 11884: $folders{$i} = 'default_'.$mapinner{$i};
11885: $containers{$i} = 'sequence';
11886: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11887: $folders{$i}.'.'.$containers{$i};
11888: my $newidx = &LONCAPA::map::getresidx();
11889: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11890: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11891: push(@LONCAPA::map::order,$newidx);
11892: my ($outtext,$errtext) =
11893: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11894: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11895: '.'.$containers{$outer},1,1);
1.1056 raeburn 11896: $newseqid{$i} = $newidx;
1.1067 raeburn 11897: unless ($errtext) {
11898: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11899: }
1.1055 raeburn 11900: }
11901: } else {
11902: if ($context eq 'coursedocs') {
11903: my $newidx=&LONCAPA::map::getresidx();
11904: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11905: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11906: $title;
11907: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11908: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11909: }
11910: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11911: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11912: }
11913: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11914: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11915: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11916: unless ($ishome) {
11917: my $fetch = "$newdest{$i}/$title";
11918: $fetch =~ s/^\Q$prefix$dir\E//;
11919: $prompttofetch{$fetch} = 1;
11920: }
1.1055 raeburn 11921: }
11922: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11923: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11924: push(@LONCAPA::map::order, $newidx);
11925: my ($outtext,$errtext)=
11926: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11927: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11928: '.'.$containers{$outer},1,1);
1.1067 raeburn 11929: unless ($errtext) {
11930: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11931: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11932: }
11933: }
1.1055 raeburn 11934: }
11935: }
1.1075.2.11 raeburn 11936: }
11937: } else {
11938: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11939: }
11940: }
11941: for (my $i=1; $i<=$numitems; $i++) {
11942: next unless ($env{'form.archive_'.$i} eq 'dependency');
11943: my $path = $env{'form.archive_content_'.$i};
11944: if ($path =~ /^\Q$pathtocheck\E/) {
11945: my ($title) = ($path =~ m{/([^/]+)$});
11946: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11947: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11948: if (ref($dirorder{$i}) eq 'ARRAY') {
11949: my ($itemidx,$fullpath,$relpath);
11950: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11951: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11952: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11953: if ($dirorder{$i}->[$j] eq $container) {
11954: $itemidx = $j;
1.1056 raeburn 11955: }
11956: }
1.1075.2.11 raeburn 11957: }
11958: if ($itemidx eq '') {
11959: $itemidx = 0;
11960: }
11961: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11962: if ($mapinner{$referrer{$i}}) {
11963: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11964: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11965: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11966: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11967: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11968: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11969: if (!-e $fullpath) {
11970: mkdir($fullpath,0755);
1.1056 raeburn 11971: }
11972: }
1.1075.2.11 raeburn 11973: } else {
11974: last;
1.1056 raeburn 11975: }
1.1075.2.11 raeburn 11976: }
11977: }
11978: } elsif ($newdest{$referrer{$i}}) {
11979: $fullpath = $newdest{$referrer{$i}};
11980: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11981: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11982: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11983: last;
11984: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11985: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11986: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11987: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11988: if (!-e $fullpath) {
11989: mkdir($fullpath,0755);
1.1056 raeburn 11990: }
11991: }
1.1075.2.11 raeburn 11992: } else {
11993: last;
1.1056 raeburn 11994: }
1.1075.2.11 raeburn 11995: }
11996: }
11997: if ($fullpath ne '') {
11998: if (-e "$prefix$path") {
11999: system("mv $prefix$path $fullpath/$title");
12000: }
12001: if (-e "$fullpath/$title") {
12002: my $showpath;
12003: if ($relpath ne '') {
12004: $showpath = "$relpath/$title";
12005: } else {
12006: $showpath = "/$title";
1.1056 raeburn 12007: }
1.1075.2.11 raeburn 12008: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12009: }
12010: unless ($ishome) {
12011: my $fetch = "$fullpath/$title";
12012: $fetch =~ s/^\Q$prefix$dir\E//;
12013: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12014: }
12015: }
12016: }
1.1075.2.11 raeburn 12017: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12018: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12019: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12020: }
12021: } else {
1.1075.2.11 raeburn 12022: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12023: }
12024: }
12025: if (keys(%todelete)) {
12026: foreach my $key (keys(%todelete)) {
12027: unlink($key);
1.1066 raeburn 12028: }
12029: }
12030: if (keys(%todeletedir)) {
12031: foreach my $key (keys(%todeletedir)) {
12032: rmdir($key);
12033: }
12034: }
12035: foreach my $dir (sort(keys(%is_dir))) {
12036: if (($pathtocheck ne '') && ($dir ne '')) {
12037: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12038: }
12039: }
1.1067 raeburn 12040: if ($result ne '') {
12041: $output .= '<ul>'."\n".
12042: $result."\n".
12043: '</ul>';
12044: }
12045: unless ($ishome) {
12046: my $replicationfail;
12047: foreach my $item (keys(%prompttofetch)) {
12048: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12049: unless ($fetchresult eq 'ok') {
12050: $replicationfail .= '<li>'.$item.'</li>'."\n";
12051: }
12052: }
12053: if ($replicationfail) {
12054: $output .= '<p class="LC_error">'.
12055: &mt('Course home server failed to retrieve:').'<ul>'.
12056: $replicationfail.
12057: '</ul></p>';
12058: }
12059: }
1.1055 raeburn 12060: } else {
12061: $warning = &mt('No items found in archive.');
12062: }
12063: if ($error) {
12064: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12065: $error.'</p>'."\n";
12066: }
12067: if ($warning) {
12068: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12069: }
12070: return $output;
12071: }
12072:
1.1066 raeburn 12073: sub cleanup_empty_dirs {
12074: my ($path) = @_;
12075: if (($path ne '') && (-d $path)) {
12076: if (opendir(my $dirh,$path)) {
12077: my @dircontents = grep(!/^\./,readdir($dirh));
12078: my $numitems = 0;
12079: foreach my $item (@dircontents) {
12080: if (-d "$path/$item") {
1.1075.2.28 raeburn 12081: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12082: if (-e "$path/$item") {
12083: $numitems ++;
12084: }
12085: } else {
12086: $numitems ++;
12087: }
12088: }
12089: if ($numitems == 0) {
12090: rmdir($path);
12091: }
12092: closedir($dirh);
12093: }
12094: }
12095: return;
12096: }
12097:
1.41 ng 12098: =pod
1.45 matthew 12099:
1.1075.2.56 raeburn 12100: =item * &get_folder_hierarchy()
1.1068 raeburn 12101:
12102: Provides hierarchy of names of folders/sub-folders containing the current
12103: item,
12104:
12105: Inputs: 3
12106: - $navmap - navmaps object
12107:
12108: - $map - url for map (either the trigger itself, or map containing
12109: the resource, which is the trigger).
12110:
12111: - $showitem - 1 => show title for map itself; 0 => do not show.
12112:
12113: Outputs: 1 @pathitems - array of folder/subfolder names.
12114:
12115: =cut
12116:
12117: sub get_folder_hierarchy {
12118: my ($navmap,$map,$showitem) = @_;
12119: my @pathitems;
12120: if (ref($navmap)) {
12121: my $mapres = $navmap->getResourceByUrl($map);
12122: if (ref($mapres)) {
12123: my $pcslist = $mapres->map_hierarchy();
12124: if ($pcslist ne '') {
12125: my @pcs = split(/,/,$pcslist);
12126: foreach my $pc (@pcs) {
12127: if ($pc == 1) {
1.1075.2.38 raeburn 12128: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12129: } else {
12130: my $res = $navmap->getByMapPc($pc);
12131: if (ref($res)) {
12132: my $title = $res->compTitle();
12133: $title =~ s/\W+/_/g;
12134: if ($title ne '') {
12135: push(@pathitems,$title);
12136: }
12137: }
12138: }
12139: }
12140: }
1.1071 raeburn 12141: if ($showitem) {
12142: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12143: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12144: } else {
12145: my $maptitle = $mapres->compTitle();
12146: $maptitle =~ s/\W+/_/g;
12147: if ($maptitle ne '') {
12148: push(@pathitems,$maptitle);
12149: }
1.1068 raeburn 12150: }
12151: }
12152: }
12153: }
12154: return @pathitems;
12155: }
12156:
12157: =pod
12158:
1.1015 raeburn 12159: =item * &get_turnedin_filepath()
12160:
12161: Determines path in a user's portfolio file for storage of files uploaded
12162: to a specific essayresponse or dropbox item.
12163:
12164: Inputs: 3 required + 1 optional.
12165: $symb is symb for resource, $uname and $udom are for current user (required).
12166: $caller is optional (can be "submission", if routine is called when storing
12167: an upoaded file when "Submit Answer" button was pressed).
12168:
12169: Returns array containing $path and $multiresp.
12170: $path is path in portfolio. $multiresp is 1 if this resource contains more
12171: than one file upload item. Callers of routine should append partid as a
12172: subdirectory to $path in cases where $multiresp is 1.
12173:
12174: Called by: homework/essayresponse.pm and homework/structuretags.pm
12175:
12176: =cut
12177:
12178: sub get_turnedin_filepath {
12179: my ($symb,$uname,$udom,$caller) = @_;
12180: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12181: my $turnindir;
12182: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12183: $turnindir = $userhash{'turnindir'};
12184: my ($path,$multiresp);
12185: if ($turnindir eq '') {
12186: if ($caller eq 'submission') {
12187: $turnindir = &mt('turned in');
12188: $turnindir =~ s/\W+/_/g;
12189: my %newhash = (
12190: 'turnindir' => $turnindir,
12191: );
12192: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12193: }
12194: }
12195: if ($turnindir ne '') {
12196: $path = '/'.$turnindir.'/';
12197: my ($multipart,$turnin,@pathitems);
12198: my $navmap = Apache::lonnavmaps::navmap->new();
12199: if (defined($navmap)) {
12200: my $mapres = $navmap->getResourceByUrl($map);
12201: if (ref($mapres)) {
12202: my $pcslist = $mapres->map_hierarchy();
12203: if ($pcslist ne '') {
12204: foreach my $pc (split(/,/,$pcslist)) {
12205: my $res = $navmap->getByMapPc($pc);
12206: if (ref($res)) {
12207: my $title = $res->compTitle();
12208: $title =~ s/\W+/_/g;
12209: if ($title ne '') {
1.1075.2.48 raeburn 12210: if (($pc > 1) && (length($title) > 12)) {
12211: $title = substr($title,0,12);
12212: }
1.1015 raeburn 12213: push(@pathitems,$title);
12214: }
12215: }
12216: }
12217: }
12218: my $maptitle = $mapres->compTitle();
12219: $maptitle =~ s/\W+/_/g;
12220: if ($maptitle ne '') {
1.1075.2.48 raeburn 12221: if (length($maptitle) > 12) {
12222: $maptitle = substr($maptitle,0,12);
12223: }
1.1015 raeburn 12224: push(@pathitems,$maptitle);
12225: }
12226: unless ($env{'request.state'} eq 'construct') {
12227: my $res = $navmap->getBySymb($symb);
12228: if (ref($res)) {
12229: my $partlist = $res->parts();
12230: my $totaluploads = 0;
12231: if (ref($partlist) eq 'ARRAY') {
12232: foreach my $part (@{$partlist}) {
12233: my @types = $res->responseType($part);
12234: my @ids = $res->responseIds($part);
12235: for (my $i=0; $i < scalar(@ids); $i++) {
12236: if ($types[$i] eq 'essay') {
12237: my $partid = $part.'_'.$ids[$i];
12238: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12239: $totaluploads ++;
12240: }
12241: }
12242: }
12243: }
12244: if ($totaluploads > 1) {
12245: $multiresp = 1;
12246: }
12247: }
12248: }
12249: }
12250: } else {
12251: return;
12252: }
12253: } else {
12254: return;
12255: }
12256: my $restitle=&Apache::lonnet::gettitle($symb);
12257: $restitle =~ s/\W+/_/g;
12258: if ($restitle eq '') {
12259: $restitle = ($resurl =~ m{/[^/]+$});
12260: if ($restitle eq '') {
12261: $restitle = time;
12262: }
12263: }
1.1075.2.48 raeburn 12264: if (length($restitle) > 12) {
12265: $restitle = substr($restitle,0,12);
12266: }
1.1015 raeburn 12267: push(@pathitems,$restitle);
12268: $path .= join('/',@pathitems);
12269: }
12270: return ($path,$multiresp);
12271: }
12272:
12273: =pod
12274:
1.464 albertel 12275: =back
1.41 ng 12276:
1.112 bowersj2 12277: =head1 CSV Upload/Handling functions
1.38 albertel 12278:
1.41 ng 12279: =over 4
12280:
1.648 raeburn 12281: =item * &upfile_store($r)
1.41 ng 12282:
12283: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12284: needs $env{'form.upfile'}
1.41 ng 12285: returns $datatoken to be put into hidden field
12286:
12287: =cut
1.31 albertel 12288:
12289: sub upfile_store {
12290: my $r=shift;
1.258 albertel 12291: $env{'form.upfile'}=~s/\r/\n/gs;
12292: $env{'form.upfile'}=~s/\f/\n/gs;
12293: $env{'form.upfile'}=~s/\n+/\n/gs;
12294: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12295:
1.258 albertel 12296: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12297: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12298: {
1.158 raeburn 12299: my $datafile = $r->dir_config('lonDaemons').
12300: '/tmp/'.$datatoken.'.tmp';
12301: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12302: print $fh $env{'form.upfile'};
1.158 raeburn 12303: close($fh);
12304: }
1.31 albertel 12305: }
12306: return $datatoken;
12307: }
12308:
1.56 matthew 12309: =pod
12310:
1.648 raeburn 12311: =item * &load_tmp_file($r)
1.41 ng 12312:
12313: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12314: needs $env{'form.datatoken'},
12315: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12316:
12317: =cut
1.31 albertel 12318:
12319: sub load_tmp_file {
12320: my $r=shift;
12321: my @studentdata=();
12322: {
1.158 raeburn 12323: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12324: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12325: if ( open(my $fh,"<$studentfile") ) {
12326: @studentdata=<$fh>;
12327: close($fh);
12328: }
1.31 albertel 12329: }
1.258 albertel 12330: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12331: }
12332:
1.56 matthew 12333: =pod
12334:
1.648 raeburn 12335: =item * &upfile_record_sep()
1.41 ng 12336:
12337: Separate uploaded file into records
12338: returns array of records,
1.258 albertel 12339: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12340:
12341: =cut
1.31 albertel 12342:
12343: sub upfile_record_sep {
1.258 albertel 12344: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12345: } else {
1.248 albertel 12346: my @records;
1.258 albertel 12347: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12348: if ($line=~/^\s*$/) { next; }
12349: push(@records,$line);
12350: }
12351: return @records;
1.31 albertel 12352: }
12353: }
12354:
1.56 matthew 12355: =pod
12356:
1.648 raeburn 12357: =item * &record_sep($record)
1.41 ng 12358:
1.258 albertel 12359: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12360:
12361: =cut
12362:
1.263 www 12363: sub takeleft {
12364: my $index=shift;
12365: return substr('0000'.$index,-4,4);
12366: }
12367:
1.31 albertel 12368: sub record_sep {
12369: my $record=shift;
12370: my %components=();
1.258 albertel 12371: if ($env{'form.upfiletype'} eq 'xml') {
12372: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12373: my $i=0;
1.356 albertel 12374: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12375: $field=~s/^(\"|\')//;
12376: $field=~s/(\"|\')$//;
1.263 www 12377: $components{&takeleft($i)}=$field;
1.31 albertel 12378: $i++;
12379: }
1.258 albertel 12380: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12381: my $i=0;
1.356 albertel 12382: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12383: $field=~s/^(\"|\')//;
12384: $field=~s/(\"|\')$//;
1.263 www 12385: $components{&takeleft($i)}=$field;
1.31 albertel 12386: $i++;
12387: }
12388: } else {
1.561 www 12389: my $separator=',';
1.480 banghart 12390: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12391: $separator=';';
1.480 banghart 12392: }
1.31 albertel 12393: my $i=0;
1.561 www 12394: # the character we are looking for to indicate the end of a quote or a record
12395: my $looking_for=$separator;
12396: # do not add the characters to the fields
12397: my $ignore=0;
12398: # we just encountered a separator (or the beginning of the record)
12399: my $just_found_separator=1;
12400: # store the field we are working on here
12401: my $field='';
12402: # work our way through all characters in record
12403: foreach my $character ($record=~/(.)/g) {
12404: if ($character eq $looking_for) {
12405: if ($character ne $separator) {
12406: # Found the end of a quote, again looking for separator
12407: $looking_for=$separator;
12408: $ignore=1;
12409: } else {
12410: # Found a separator, store away what we got
12411: $components{&takeleft($i)}=$field;
12412: $i++;
12413: $just_found_separator=1;
12414: $ignore=0;
12415: $field='';
12416: }
12417: next;
12418: }
12419: # single or double quotation marks after a separator indicate beginning of a quote
12420: # we are now looking for the end of the quote and need to ignore separators
12421: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12422: $looking_for=$character;
12423: next;
12424: }
12425: # ignore would be true after we reached the end of a quote
12426: if ($ignore) { next; }
12427: if (($just_found_separator) && ($character=~/\s/)) { next; }
12428: $field.=$character;
12429: $just_found_separator=0;
1.31 albertel 12430: }
1.561 www 12431: # catch the very last entry, since we never encountered the separator
12432: $components{&takeleft($i)}=$field;
1.31 albertel 12433: }
12434: return %components;
12435: }
12436:
1.144 matthew 12437: ######################################################
12438: ######################################################
12439:
1.56 matthew 12440: =pod
12441:
1.648 raeburn 12442: =item * &upfile_select_html()
1.41 ng 12443:
1.144 matthew 12444: Return HTML code to select a file from the users machine and specify
12445: the file type.
1.41 ng 12446:
12447: =cut
12448:
1.144 matthew 12449: ######################################################
12450: ######################################################
1.31 albertel 12451: sub upfile_select_html {
1.144 matthew 12452: my %Types = (
12453: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12454: semisv => &mt('Semicolon separated values'),
1.144 matthew 12455: space => &mt('Space separated'),
12456: tab => &mt('Tabulator separated'),
12457: # xml => &mt('HTML/XML'),
12458: );
12459: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12460: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12461: foreach my $type (sort(keys(%Types))) {
12462: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12463: }
12464: $Str .= "</select>\n";
12465: return $Str;
1.31 albertel 12466: }
12467:
1.301 albertel 12468: sub get_samples {
12469: my ($records,$toget) = @_;
12470: my @samples=({});
12471: my $got=0;
12472: foreach my $rec (@$records) {
12473: my %temp = &record_sep($rec);
12474: if (! grep(/\S/, values(%temp))) { next; }
12475: if (%temp) {
12476: $samples[$got]=\%temp;
12477: $got++;
12478: if ($got == $toget) { last; }
12479: }
12480: }
12481: return \@samples;
12482: }
12483:
1.144 matthew 12484: ######################################################
12485: ######################################################
12486:
1.56 matthew 12487: =pod
12488:
1.648 raeburn 12489: =item * &csv_print_samples($r,$records)
1.41 ng 12490:
12491: Prints a table of sample values from each column uploaded $r is an
12492: Apache Request ref, $records is an arrayref from
12493: &Apache::loncommon::upfile_record_sep
12494:
12495: =cut
12496:
1.144 matthew 12497: ######################################################
12498: ######################################################
1.31 albertel 12499: sub csv_print_samples {
12500: my ($r,$records) = @_;
1.662 bisitz 12501: my $samples = &get_samples($records,5);
1.301 albertel 12502:
1.594 raeburn 12503: $r->print(&mt('Samples').'<br />'.&start_data_table().
12504: &start_data_table_header_row());
1.356 albertel 12505: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12506: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12507: $r->print(&end_data_table_header_row());
1.301 albertel 12508: foreach my $hash (@$samples) {
1.594 raeburn 12509: $r->print(&start_data_table_row());
1.356 albertel 12510: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12511: $r->print('<td>');
1.356 albertel 12512: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12513: $r->print('</td>');
12514: }
1.594 raeburn 12515: $r->print(&end_data_table_row());
1.31 albertel 12516: }
1.594 raeburn 12517: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12518: }
12519:
1.144 matthew 12520: ######################################################
12521: ######################################################
12522:
1.56 matthew 12523: =pod
12524:
1.648 raeburn 12525: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12526:
12527: Prints a table to create associations between values and table columns.
1.144 matthew 12528:
1.41 ng 12529: $r is an Apache Request ref,
12530: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12531: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12532:
12533: =cut
12534:
1.144 matthew 12535: ######################################################
12536: ######################################################
1.31 albertel 12537: sub csv_print_select_table {
12538: my ($r,$records,$d) = @_;
1.301 albertel 12539: my $i=0;
12540: my $samples = &get_samples($records,1);
1.144 matthew 12541: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12542: &start_data_table().&start_data_table_header_row().
1.144 matthew 12543: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12544: '<th>'.&mt('Column').'</th>'.
12545: &end_data_table_header_row()."\n");
1.356 albertel 12546: foreach my $array_ref (@$d) {
12547: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12548: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12549:
1.875 bisitz 12550: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12551: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12552: $r->print('<option value="none"></option>');
1.356 albertel 12553: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12554: $r->print('<option value="'.$sample.'"'.
12555: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12556: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12557: }
1.594 raeburn 12558: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12559: $i++;
12560: }
1.594 raeburn 12561: $r->print(&end_data_table());
1.31 albertel 12562: $i--;
12563: return $i;
12564: }
1.56 matthew 12565:
1.144 matthew 12566: ######################################################
12567: ######################################################
12568:
1.56 matthew 12569: =pod
1.31 albertel 12570:
1.648 raeburn 12571: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12572:
12573: Prints a table of sample values from the upload and can make associate samples to internal names.
12574:
12575: $r is an Apache Request ref,
12576: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12577: $d is an array of 2 element arrays (internal name, displayed name)
12578:
12579: =cut
12580:
1.144 matthew 12581: ######################################################
12582: ######################################################
1.31 albertel 12583: sub csv_samples_select_table {
12584: my ($r,$records,$d) = @_;
12585: my $i=0;
1.144 matthew 12586: #
1.662 bisitz 12587: my $max_samples = 5;
12588: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12589: $r->print(&start_data_table().
12590: &start_data_table_header_row().'<th>'.
12591: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12592: &end_data_table_header_row());
1.301 albertel 12593:
12594: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12595: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12596: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12597: foreach my $option (@$d) {
12598: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12599: $r->print('<option value="'.$value.'"'.
1.253 albertel 12600: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12601: $display.'</option>');
1.31 albertel 12602: }
12603: $r->print('</select></td><td>');
1.662 bisitz 12604: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12605: if (defined($samples->[$line]{$key})) {
12606: $r->print($samples->[$line]{$key}."<br />\n");
12607: }
12608: }
1.594 raeburn 12609: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12610: $i++;
12611: }
1.594 raeburn 12612: $r->print(&end_data_table());
1.31 albertel 12613: $i--;
12614: return($i);
1.115 matthew 12615: }
12616:
1.144 matthew 12617: ######################################################
12618: ######################################################
12619:
1.115 matthew 12620: =pod
12621:
1.648 raeburn 12622: =item * &clean_excel_name($name)
1.115 matthew 12623:
12624: Returns a replacement for $name which does not contain any illegal characters.
12625:
12626: =cut
12627:
1.144 matthew 12628: ######################################################
12629: ######################################################
1.115 matthew 12630: sub clean_excel_name {
12631: my ($name) = @_;
12632: $name =~ s/[:\*\?\/\\]//g;
12633: if (length($name) > 31) {
12634: $name = substr($name,0,31);
12635: }
12636: return $name;
1.25 albertel 12637: }
1.84 albertel 12638:
1.85 albertel 12639: =pod
12640:
1.648 raeburn 12641: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12642:
12643: Returns either 1 or undef
12644:
12645: 1 if the part is to be hidden, undef if it is to be shown
12646:
12647: Arguments are:
12648:
12649: $id the id of the part to be checked
12650: $symb, optional the symb of the resource to check
12651: $udom, optional the domain of the user to check for
12652: $uname, optional the username of the user to check for
12653:
12654: =cut
1.84 albertel 12655:
12656: sub check_if_partid_hidden {
12657: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12658: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12659: $symb,$udom,$uname);
1.141 albertel 12660: my $truth=1;
12661: #if the string starts with !, then the list is the list to show not hide
12662: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12663: my @hiddenlist=split(/,/,$hiddenparts);
12664: foreach my $checkid (@hiddenlist) {
1.141 albertel 12665: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12666: }
1.141 albertel 12667: return !$truth;
1.84 albertel 12668: }
1.127 matthew 12669:
1.138 matthew 12670:
12671: ############################################################
12672: ############################################################
12673:
12674: =pod
12675:
1.157 matthew 12676: =back
12677:
1.138 matthew 12678: =head1 cgi-bin script and graphing routines
12679:
1.157 matthew 12680: =over 4
12681:
1.648 raeburn 12682: =item * &get_cgi_id()
1.138 matthew 12683:
12684: Inputs: none
12685:
12686: Returns an id which can be used to pass environment variables
12687: to various cgi-bin scripts. These environment variables will
12688: be removed from the users environment after a given time by
12689: the routine &Apache::lonnet::transfer_profile_to_env.
12690:
12691: =cut
12692:
12693: ############################################################
12694: ############################################################
1.152 albertel 12695: my $uniq=0;
1.136 matthew 12696: sub get_cgi_id {
1.154 albertel 12697: $uniq=($uniq+1)%100000;
1.280 albertel 12698: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12699: }
12700:
1.127 matthew 12701: ############################################################
12702: ############################################################
12703:
12704: =pod
12705:
1.648 raeburn 12706: =item * &DrawBarGraph()
1.127 matthew 12707:
1.138 matthew 12708: Facilitates the plotting of data in a (stacked) bar graph.
12709: Puts plot definition data into the users environment in order for
12710: graph.png to plot it. Returns an <img> tag for the plot.
12711: The bars on the plot are labeled '1','2',...,'n'.
12712:
12713: Inputs:
12714:
12715: =over 4
12716:
12717: =item $Title: string, the title of the plot
12718:
12719: =item $xlabel: string, text describing the X-axis of the plot
12720:
12721: =item $ylabel: string, text describing the Y-axis of the plot
12722:
12723: =item $Max: scalar, the maximum Y value to use in the plot
12724: If $Max is < any data point, the graph will not be rendered.
12725:
1.140 matthew 12726: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12727: they are plotted. If undefined, default values will be used.
12728:
1.178 matthew 12729: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12730:
1.138 matthew 12731: =item @Values: An array of array references. Each array reference holds data
12732: to be plotted in a stacked bar chart.
12733:
1.239 matthew 12734: =item If the final element of @Values is a hash reference the key/value
12735: pairs will be added to the graph definition.
12736:
1.138 matthew 12737: =back
12738:
12739: Returns:
12740:
12741: An <img> tag which references graph.png and the appropriate identifying
12742: information for the plot.
12743:
1.127 matthew 12744: =cut
12745:
12746: ############################################################
12747: ############################################################
1.134 matthew 12748: sub DrawBarGraph {
1.178 matthew 12749: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12750: #
12751: if (! defined($colors)) {
12752: $colors = ['#33ff00',
12753: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12754: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12755: ];
12756: }
1.228 matthew 12757: my $extra_settings = {};
12758: if (ref($Values[-1]) eq 'HASH') {
12759: $extra_settings = pop(@Values);
12760: }
1.127 matthew 12761: #
1.136 matthew 12762: my $identifier = &get_cgi_id();
12763: my $id = 'cgi.'.$identifier;
1.129 matthew 12764: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12765: return '';
12766: }
1.225 matthew 12767: #
12768: my @Labels;
12769: if (defined($labels)) {
12770: @Labels = @$labels;
12771: } else {
12772: for (my $i=0;$i<@{$Values[0]};$i++) {
12773: push (@Labels,$i+1);
12774: }
12775: }
12776: #
1.129 matthew 12777: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12778: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12779: my %ValuesHash;
12780: my $NumSets=1;
12781: foreach my $array (@Values) {
12782: next if (! ref($array));
1.136 matthew 12783: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12784: join(',',@$array);
1.129 matthew 12785: }
1.127 matthew 12786: #
1.136 matthew 12787: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12788: if ($NumBars < 3) {
12789: $width = 120+$NumBars*32;
1.220 matthew 12790: $xskip = 1;
1.225 matthew 12791: $bar_width = 30;
12792: } elsif ($NumBars < 5) {
12793: $width = 120+$NumBars*20;
12794: $xskip = 1;
12795: $bar_width = 20;
1.220 matthew 12796: } elsif ($NumBars < 10) {
1.136 matthew 12797: $width = 120+$NumBars*15;
12798: $xskip = 1;
12799: $bar_width = 15;
12800: } elsif ($NumBars <= 25) {
12801: $width = 120+$NumBars*11;
12802: $xskip = 5;
12803: $bar_width = 8;
12804: } elsif ($NumBars <= 50) {
12805: $width = 120+$NumBars*8;
12806: $xskip = 5;
12807: $bar_width = 4;
12808: } else {
12809: $width = 120+$NumBars*8;
12810: $xskip = 5;
12811: $bar_width = 4;
12812: }
12813: #
1.137 matthew 12814: $Max = 1 if ($Max < 1);
12815: if ( int($Max) < $Max ) {
12816: $Max++;
12817: $Max = int($Max);
12818: }
1.127 matthew 12819: $Title = '' if (! defined($Title));
12820: $xlabel = '' if (! defined($xlabel));
12821: $ylabel = '' if (! defined($ylabel));
1.369 www 12822: $ValuesHash{$id.'.title'} = &escape($Title);
12823: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12824: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12825: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12826: $ValuesHash{$id.'.NumBars'} = $NumBars;
12827: $ValuesHash{$id.'.NumSets'} = $NumSets;
12828: $ValuesHash{$id.'.PlotType'} = 'bar';
12829: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12830: $ValuesHash{$id.'.height'} = $height;
12831: $ValuesHash{$id.'.width'} = $width;
12832: $ValuesHash{$id.'.xskip'} = $xskip;
12833: $ValuesHash{$id.'.bar_width'} = $bar_width;
12834: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12835: #
1.228 matthew 12836: # Deal with other parameters
12837: while (my ($key,$value) = each(%$extra_settings)) {
12838: $ValuesHash{$id.'.'.$key} = $value;
12839: }
12840: #
1.646 raeburn 12841: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12842: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12843: }
12844:
12845: ############################################################
12846: ############################################################
12847:
12848: =pod
12849:
1.648 raeburn 12850: =item * &DrawXYGraph()
1.137 matthew 12851:
1.138 matthew 12852: Facilitates the plotting of data in an XY graph.
12853: Puts plot definition data into the users environment in order for
12854: graph.png to plot it. Returns an <img> tag for the plot.
12855:
12856: Inputs:
12857:
12858: =over 4
12859:
12860: =item $Title: string, the title of the plot
12861:
12862: =item $xlabel: string, text describing the X-axis of the plot
12863:
12864: =item $ylabel: string, text describing the Y-axis of the plot
12865:
12866: =item $Max: scalar, the maximum Y value to use in the plot
12867: If $Max is < any data point, the graph will not be rendered.
12868:
12869: =item $colors: Array ref containing the hex color codes for the data to be
12870: plotted in. If undefined, default values will be used.
12871:
12872: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12873:
12874: =item $Ydata: Array ref containing Array refs.
1.185 www 12875: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12876:
12877: =item %Values: hash indicating or overriding any default values which are
12878: passed to graph.png.
12879: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12880:
12881: =back
12882:
12883: Returns:
12884:
12885: An <img> tag which references graph.png and the appropriate identifying
12886: information for the plot.
12887:
1.137 matthew 12888: =cut
12889:
12890: ############################################################
12891: ############################################################
12892: sub DrawXYGraph {
12893: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12894: #
12895: # Create the identifier for the graph
12896: my $identifier = &get_cgi_id();
12897: my $id = 'cgi.'.$identifier;
12898: #
12899: $Title = '' if (! defined($Title));
12900: $xlabel = '' if (! defined($xlabel));
12901: $ylabel = '' if (! defined($ylabel));
12902: my %ValuesHash =
12903: (
1.369 www 12904: $id.'.title' => &escape($Title),
12905: $id.'.xlabel' => &escape($xlabel),
12906: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12907: $id.'.y_max_value'=> $Max,
12908: $id.'.labels' => join(',',@$Xlabels),
12909: $id.'.PlotType' => 'XY',
12910: );
12911: #
12912: if (defined($colors) && ref($colors) eq 'ARRAY') {
12913: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12914: }
12915: #
12916: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12917: return '';
12918: }
12919: my $NumSets=1;
1.138 matthew 12920: foreach my $array (@{$Ydata}){
1.137 matthew 12921: next if (! ref($array));
12922: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12923: }
1.138 matthew 12924: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12925: #
12926: # Deal with other parameters
12927: while (my ($key,$value) = each(%Values)) {
12928: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12929: }
12930: #
1.646 raeburn 12931: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12932: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12933: }
12934:
12935: ############################################################
12936: ############################################################
12937:
12938: =pod
12939:
1.648 raeburn 12940: =item * &DrawXYYGraph()
1.138 matthew 12941:
12942: Facilitates the plotting of data in an XY graph with two Y axes.
12943: Puts plot definition data into the users environment in order for
12944: graph.png to plot it. Returns an <img> tag for the plot.
12945:
12946: Inputs:
12947:
12948: =over 4
12949:
12950: =item $Title: string, the title of the plot
12951:
12952: =item $xlabel: string, text describing the X-axis of the plot
12953:
12954: =item $ylabel: string, text describing the Y-axis of the plot
12955:
12956: =item $colors: Array ref containing the hex color codes for the data to be
12957: plotted in. If undefined, default values will be used.
12958:
12959: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12960:
12961: =item $Ydata1: The first data set
12962:
12963: =item $Min1: The minimum value of the left Y-axis
12964:
12965: =item $Max1: The maximum value of the left Y-axis
12966:
12967: =item $Ydata2: The second data set
12968:
12969: =item $Min2: The minimum value of the right Y-axis
12970:
12971: =item $Max2: The maximum value of the left Y-axis
12972:
12973: =item %Values: hash indicating or overriding any default values which are
12974: passed to graph.png.
12975: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12976:
12977: =back
12978:
12979: Returns:
12980:
12981: An <img> tag which references graph.png and the appropriate identifying
12982: information for the plot.
1.136 matthew 12983:
12984: =cut
12985:
12986: ############################################################
12987: ############################################################
1.137 matthew 12988: sub DrawXYYGraph {
12989: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12990: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12991: #
12992: # Create the identifier for the graph
12993: my $identifier = &get_cgi_id();
12994: my $id = 'cgi.'.$identifier;
12995: #
12996: $Title = '' if (! defined($Title));
12997: $xlabel = '' if (! defined($xlabel));
12998: $ylabel = '' if (! defined($ylabel));
12999: my %ValuesHash =
13000: (
1.369 www 13001: $id.'.title' => &escape($Title),
13002: $id.'.xlabel' => &escape($xlabel),
13003: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13004: $id.'.labels' => join(',',@$Xlabels),
13005: $id.'.PlotType' => 'XY',
13006: $id.'.NumSets' => 2,
1.137 matthew 13007: $id.'.two_axes' => 1,
13008: $id.'.y1_max_value' => $Max1,
13009: $id.'.y1_min_value' => $Min1,
13010: $id.'.y2_max_value' => $Max2,
13011: $id.'.y2_min_value' => $Min2,
1.136 matthew 13012: );
13013: #
1.137 matthew 13014: if (defined($colors) && ref($colors) eq 'ARRAY') {
13015: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13016: }
13017: #
13018: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13019: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13020: return '';
13021: }
13022: my $NumSets=1;
1.137 matthew 13023: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13024: next if (! ref($array));
13025: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13026: }
13027: #
13028: # Deal with other parameters
13029: while (my ($key,$value) = each(%Values)) {
13030: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13031: }
13032: #
1.646 raeburn 13033: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13034: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13035: }
13036:
13037: ############################################################
13038: ############################################################
13039:
13040: =pod
13041:
1.157 matthew 13042: =back
13043:
1.139 matthew 13044: =head1 Statistics helper routines?
13045:
13046: Bad place for them but what the hell.
13047:
1.157 matthew 13048: =over 4
13049:
1.648 raeburn 13050: =item * &chartlink()
1.139 matthew 13051:
13052: Returns a link to the chart for a specific student.
13053:
13054: Inputs:
13055:
13056: =over 4
13057:
13058: =item $linktext: The text of the link
13059:
13060: =item $sname: The students username
13061:
13062: =item $sdomain: The students domain
13063:
13064: =back
13065:
1.157 matthew 13066: =back
13067:
1.139 matthew 13068: =cut
13069:
13070: ############################################################
13071: ############################################################
13072: sub chartlink {
13073: my ($linktext, $sname, $sdomain) = @_;
13074: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13075: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13076: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13077: '">'.$linktext.'</a>';
1.153 matthew 13078: }
13079:
13080: #######################################################
13081: #######################################################
13082:
13083: =pod
13084:
13085: =head1 Course Environment Routines
1.157 matthew 13086:
13087: =over 4
1.153 matthew 13088:
1.648 raeburn 13089: =item * &restore_course_settings()
1.153 matthew 13090:
1.648 raeburn 13091: =item * &store_course_settings()
1.153 matthew 13092:
13093: Restores/Store indicated form parameters from the course environment.
13094: Will not overwrite existing values of the form parameters.
13095:
13096: Inputs:
13097: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13098:
13099: a hash ref describing the data to be stored. For example:
13100:
13101: %Save_Parameters = ('Status' => 'scalar',
13102: 'chartoutputmode' => 'scalar',
13103: 'chartoutputdata' => 'scalar',
13104: 'Section' => 'array',
1.373 raeburn 13105: 'Group' => 'array',
1.153 matthew 13106: 'StudentData' => 'array',
13107: 'Maps' => 'array');
13108:
13109: Returns: both routines return nothing
13110:
1.631 raeburn 13111: =back
13112:
1.153 matthew 13113: =cut
13114:
13115: #######################################################
13116: #######################################################
13117: sub store_course_settings {
1.496 albertel 13118: return &store_settings($env{'request.course.id'},@_);
13119: }
13120:
13121: sub store_settings {
1.153 matthew 13122: # save to the environment
13123: # appenv the same items, just to be safe
1.300 albertel 13124: my $udom = $env{'user.domain'};
13125: my $uname = $env{'user.name'};
1.496 albertel 13126: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13127: my %SaveHash;
13128: my %AppHash;
13129: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13130: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13131: my $envname = 'environment.'.$basename;
1.258 albertel 13132: if (exists($env{'form.'.$setting})) {
1.153 matthew 13133: # Save this value away
13134: if ($type eq 'scalar' &&
1.258 albertel 13135: (! exists($env{$envname}) ||
13136: $env{$envname} ne $env{'form.'.$setting})) {
13137: $SaveHash{$basename} = $env{'form.'.$setting};
13138: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13139: } elsif ($type eq 'array') {
13140: my $stored_form;
1.258 albertel 13141: if (ref($env{'form.'.$setting})) {
1.153 matthew 13142: $stored_form = join(',',
13143: map {
1.369 www 13144: &escape($_);
1.258 albertel 13145: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13146: } else {
13147: $stored_form =
1.369 www 13148: &escape($env{'form.'.$setting});
1.153 matthew 13149: }
13150: # Determine if the array contents are the same.
1.258 albertel 13151: if ($stored_form ne $env{$envname}) {
1.153 matthew 13152: $SaveHash{$basename} = $stored_form;
13153: $AppHash{$envname} = $stored_form;
13154: }
13155: }
13156: }
13157: }
13158: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13159: $udom,$uname);
1.153 matthew 13160: if ($put_result !~ /^(ok|delayed)/) {
13161: &Apache::lonnet::logthis('unable to save form parameters, '.
13162: 'got error:'.$put_result);
13163: }
13164: # Make sure these settings stick around in this session, too
1.646 raeburn 13165: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13166: return;
13167: }
13168:
13169: sub restore_course_settings {
1.499 albertel 13170: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13171: }
13172:
13173: sub restore_settings {
13174: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13175: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13176: next if (exists($env{'form.'.$setting}));
1.496 albertel 13177: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13178: '.'.$setting;
1.258 albertel 13179: if (exists($env{$envname})) {
1.153 matthew 13180: if ($type eq 'scalar') {
1.258 albertel 13181: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13182: } elsif ($type eq 'array') {
1.258 albertel 13183: $env{'form.'.$setting} = [
1.153 matthew 13184: map {
1.369 www 13185: &unescape($_);
1.258 albertel 13186: } split(',',$env{$envname})
1.153 matthew 13187: ];
13188: }
13189: }
13190: }
1.127 matthew 13191: }
13192:
1.618 raeburn 13193: #######################################################
13194: #######################################################
13195:
13196: =pod
13197:
13198: =head1 Domain E-mail Routines
13199:
13200: =over 4
13201:
1.648 raeburn 13202: =item * &build_recipient_list()
1.618 raeburn 13203:
1.1075.2.44 raeburn 13204: Build recipient lists for following types of e-mail:
1.766 raeburn 13205: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13206: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13207: module change checking, student/employee ID conflict checks, as
13208: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13209: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13210:
13211: Inputs:
1.1075.2.44 raeburn 13212: defmail (scalar - email address of default recipient),
13213: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13214: requestsmail, updatesmail, or idconflictsmail).
13215:
1.619 raeburn 13216: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13217:
13218: origmail (scalar - email address of recipient from loncapa.conf,
13219: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13220:
1.655 raeburn 13221: Returns: comma separated list of addresses to which to send e-mail.
13222:
13223: =back
1.618 raeburn 13224:
13225: =cut
13226:
13227: ############################################################
13228: ############################################################
13229: sub build_recipient_list {
1.619 raeburn 13230: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13231: my @recipients;
13232: my $otheremails;
13233: my %domconfig =
13234: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13235: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13236: if (exists($domconfig{'contacts'}{$mailing})) {
13237: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13238: my @contacts = ('adminemail','supportemail');
13239: foreach my $item (@contacts) {
13240: if ($domconfig{'contacts'}{$mailing}{$item}) {
13241: my $addr = $domconfig{'contacts'}{$item};
13242: if (!grep(/^\Q$addr\E$/,@recipients)) {
13243: push(@recipients,$addr);
13244: }
1.619 raeburn 13245: }
1.766 raeburn 13246: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13247: }
13248: }
1.766 raeburn 13249: } elsif ($origmail ne '') {
13250: push(@recipients,$origmail);
1.618 raeburn 13251: }
1.619 raeburn 13252: } elsif ($origmail ne '') {
13253: push(@recipients,$origmail);
1.618 raeburn 13254: }
1.688 raeburn 13255: if (defined($defmail)) {
13256: if ($defmail ne '') {
13257: push(@recipients,$defmail);
13258: }
1.618 raeburn 13259: }
13260: if ($otheremails) {
1.619 raeburn 13261: my @others;
13262: if ($otheremails =~ /,/) {
13263: @others = split(/,/,$otheremails);
1.618 raeburn 13264: } else {
1.619 raeburn 13265: push(@others,$otheremails);
13266: }
13267: foreach my $addr (@others) {
13268: if (!grep(/^\Q$addr\E$/,@recipients)) {
13269: push(@recipients,$addr);
13270: }
1.618 raeburn 13271: }
13272: }
1.619 raeburn 13273: my $recipientlist = join(',',@recipients);
1.618 raeburn 13274: return $recipientlist;
13275: }
13276:
1.127 matthew 13277: ############################################################
13278: ############################################################
1.154 albertel 13279:
1.655 raeburn 13280: =pod
13281:
13282: =head1 Course Catalog Routines
13283:
13284: =over 4
13285:
13286: =item * &gather_categories()
13287:
13288: Converts category definitions - keys of categories hash stored in
13289: coursecategories in configuration.db on the primary library server in a
13290: domain - to an array. Also generates javascript and idx hash used to
13291: generate Domain Coordinator interface for editing Course Categories.
13292:
13293: Inputs:
1.663 raeburn 13294:
1.655 raeburn 13295: categories (reference to hash of category definitions).
1.663 raeburn 13296:
1.655 raeburn 13297: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13298: categories and subcategories).
1.663 raeburn 13299:
1.655 raeburn 13300: idx (reference to hash of counters used in Domain Coordinator interface for
13301: editing Course Categories).
1.663 raeburn 13302:
1.655 raeburn 13303: jsarray (reference to array of categories used to create Javascript arrays for
13304: Domain Coordinator interface for editing Course Categories).
13305:
13306: Returns: nothing
13307:
13308: Side effects: populates cats, idx and jsarray.
13309:
13310: =cut
13311:
13312: sub gather_categories {
13313: my ($categories,$cats,$idx,$jsarray) = @_;
13314: my %counters;
13315: my $num = 0;
13316: foreach my $item (keys(%{$categories})) {
13317: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13318: if ($container eq '' && $depth == 0) {
13319: $cats->[$depth][$categories->{$item}] = $cat;
13320: } else {
13321: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13322: }
13323: my ($escitem,$tail) = split(/:/,$item,2);
13324: if ($counters{$tail} eq '') {
13325: $counters{$tail} = $num;
13326: $num ++;
13327: }
13328: if (ref($idx) eq 'HASH') {
13329: $idx->{$item} = $counters{$tail};
13330: }
13331: if (ref($jsarray) eq 'ARRAY') {
13332: push(@{$jsarray->[$counters{$tail}]},$item);
13333: }
13334: }
13335: return;
13336: }
13337:
13338: =pod
13339:
13340: =item * &extract_categories()
13341:
13342: Used to generate breadcrumb trails for course categories.
13343:
13344: Inputs:
1.663 raeburn 13345:
1.655 raeburn 13346: categories (reference to hash of category definitions).
1.663 raeburn 13347:
1.655 raeburn 13348: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13349: categories and subcategories).
1.663 raeburn 13350:
1.655 raeburn 13351: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13352:
1.655 raeburn 13353: allitems (reference to hash - key is category key
13354: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13355:
1.655 raeburn 13356: idx (reference to hash of counters used in Domain Coordinator interface for
13357: editing Course Categories).
1.663 raeburn 13358:
1.655 raeburn 13359: jsarray (reference to array of categories used to create Javascript arrays for
13360: Domain Coordinator interface for editing Course Categories).
13361:
1.665 raeburn 13362: subcats (reference to hash of arrays containing all subcategories within each
13363: category, -recursive)
13364:
1.655 raeburn 13365: Returns: nothing
13366:
13367: Side effects: populates trails and allitems hash references.
13368:
13369: =cut
13370:
13371: sub extract_categories {
1.665 raeburn 13372: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13373: if (ref($categories) eq 'HASH') {
13374: &gather_categories($categories,$cats,$idx,$jsarray);
13375: if (ref($cats->[0]) eq 'ARRAY') {
13376: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13377: my $name = $cats->[0][$i];
13378: my $item = &escape($name).'::0';
13379: my $trailstr;
13380: if ($name eq 'instcode') {
13381: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13382: } elsif ($name eq 'communities') {
13383: $trailstr = &mt('Communities');
1.655 raeburn 13384: } else {
13385: $trailstr = $name;
13386: }
13387: if ($allitems->{$item} eq '') {
13388: push(@{$trails},$trailstr);
13389: $allitems->{$item} = scalar(@{$trails})-1;
13390: }
13391: my @parents = ($name);
13392: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13393: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13394: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13395: if (ref($subcats) eq 'HASH') {
13396: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13397: }
13398: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13399: }
13400: } else {
13401: if (ref($subcats) eq 'HASH') {
13402: $subcats->{$item} = [];
1.655 raeburn 13403: }
13404: }
13405: }
13406: }
13407: }
13408: return;
13409: }
13410:
13411: =pod
13412:
1.1075.2.56 raeburn 13413: =item * &recurse_categories()
1.655 raeburn 13414:
13415: Recursively used to generate breadcrumb trails for course categories.
13416:
13417: Inputs:
1.663 raeburn 13418:
1.655 raeburn 13419: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13420: categories and subcategories).
1.663 raeburn 13421:
1.655 raeburn 13422: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13423:
13424: category (current course category, for which breadcrumb trail is being generated).
13425:
13426: trails (reference to array of breadcrumb trails for each category).
13427:
1.655 raeburn 13428: allitems (reference to hash - key is category key
13429: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13430:
1.655 raeburn 13431: parents (array containing containers directories for current category,
13432: back to top level).
13433:
13434: Returns: nothing
13435:
13436: Side effects: populates trails and allitems hash references
13437:
13438: =cut
13439:
13440: sub recurse_categories {
1.665 raeburn 13441: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13442: my $shallower = $depth - 1;
13443: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13444: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13445: my $name = $cats->[$depth]{$category}[$k];
13446: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13447: my $trailstr = join(' -> ',(@{$parents},$category));
13448: if ($allitems->{$item} eq '') {
13449: push(@{$trails},$trailstr);
13450: $allitems->{$item} = scalar(@{$trails})-1;
13451: }
13452: my $deeper = $depth+1;
13453: push(@{$parents},$category);
1.665 raeburn 13454: if (ref($subcats) eq 'HASH') {
13455: my $subcat = &escape($name).':'.$category.':'.$depth;
13456: for (my $j=@{$parents}; $j>=0; $j--) {
13457: my $higher;
13458: if ($j > 0) {
13459: $higher = &escape($parents->[$j]).':'.
13460: &escape($parents->[$j-1]).':'.$j;
13461: } else {
13462: $higher = &escape($parents->[$j]).'::'.$j;
13463: }
13464: push(@{$subcats->{$higher}},$subcat);
13465: }
13466: }
13467: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13468: $subcats);
1.655 raeburn 13469: pop(@{$parents});
13470: }
13471: } else {
13472: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13473: my $trailstr = join(' -> ',(@{$parents},$category));
13474: if ($allitems->{$item} eq '') {
13475: push(@{$trails},$trailstr);
13476: $allitems->{$item} = scalar(@{$trails})-1;
13477: }
13478: }
13479: return;
13480: }
13481:
1.663 raeburn 13482: =pod
13483:
1.1075.2.56 raeburn 13484: =item * &assign_categories_table()
1.663 raeburn 13485:
13486: Create a datatable for display of hierarchical categories in a domain,
13487: with checkboxes to allow a course to be categorized.
13488:
13489: Inputs:
13490:
13491: cathash - reference to hash of categories defined for the domain (from
13492: configuration.db)
13493:
13494: currcat - scalar with an & separated list of categories assigned to a course.
13495:
1.919 raeburn 13496: type - scalar contains course type (Course or Community).
13497:
1.663 raeburn 13498: Returns: $output (markup to be displayed)
13499:
13500: =cut
13501:
13502: sub assign_categories_table {
1.919 raeburn 13503: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13504: my $output;
13505: if (ref($cathash) eq 'HASH') {
13506: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13507: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13508: $maxdepth = scalar(@cats);
13509: if (@cats > 0) {
13510: my $itemcount = 0;
13511: if (ref($cats[0]) eq 'ARRAY') {
13512: my @currcategories;
13513: if ($currcat ne '') {
13514: @currcategories = split('&',$currcat);
13515: }
1.919 raeburn 13516: my $table;
1.663 raeburn 13517: for (my $i=0; $i<@{$cats[0]}; $i++) {
13518: my $parent = $cats[0][$i];
1.919 raeburn 13519: next if ($parent eq 'instcode');
13520: if ($type eq 'Community') {
13521: next unless ($parent eq 'communities');
13522: } else {
13523: next if ($parent eq 'communities');
13524: }
1.663 raeburn 13525: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13526: my $item = &escape($parent).'::0';
13527: my $checked = '';
13528: if (@currcategories > 0) {
13529: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13530: $checked = ' checked="checked"';
1.663 raeburn 13531: }
13532: }
1.919 raeburn 13533: my $parent_title = $parent;
13534: if ($parent eq 'communities') {
13535: $parent_title = &mt('Communities');
13536: }
13537: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13538: '<input type="checkbox" name="usecategory" value="'.
13539: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13540: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13541: my $depth = 1;
13542: push(@path,$parent);
1.919 raeburn 13543: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13544: pop(@path);
1.919 raeburn 13545: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13546: $itemcount ++;
13547: }
1.919 raeburn 13548: if ($itemcount) {
13549: $output = &Apache::loncommon::start_data_table().
13550: $table.
13551: &Apache::loncommon::end_data_table();
13552: }
1.663 raeburn 13553: }
13554: }
13555: }
13556: return $output;
13557: }
13558:
13559: =pod
13560:
1.1075.2.56 raeburn 13561: =item * &assign_category_rows()
1.663 raeburn 13562:
13563: Create a datatable row for display of nested categories in a domain,
13564: with checkboxes to allow a course to be categorized,called recursively.
13565:
13566: Inputs:
13567:
13568: itemcount - track row number for alternating colors
13569:
13570: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13571: categories and subcategories.
13572:
13573: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13574:
13575: parent - parent of current category item
13576:
13577: path - Array containing all categories back up through the hierarchy from the
13578: current category to the top level.
13579:
13580: currcategories - reference to array of current categories assigned to the course
13581:
13582: Returns: $output (markup to be displayed).
13583:
13584: =cut
13585:
13586: sub assign_category_rows {
13587: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13588: my ($text,$name,$item,$chgstr);
13589: if (ref($cats) eq 'ARRAY') {
13590: my $maxdepth = scalar(@{$cats});
13591: if (ref($cats->[$depth]) eq 'HASH') {
13592: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13593: my $numchildren = @{$cats->[$depth]{$parent}};
13594: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13595: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13596: for (my $j=0; $j<$numchildren; $j++) {
13597: $name = $cats->[$depth]{$parent}[$j];
13598: $item = &escape($name).':'.&escape($parent).':'.$depth;
13599: my $deeper = $depth+1;
13600: my $checked = '';
13601: if (ref($currcategories) eq 'ARRAY') {
13602: if (@{$currcategories} > 0) {
13603: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13604: $checked = ' checked="checked"';
1.663 raeburn 13605: }
13606: }
13607: }
1.664 raeburn 13608: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13609: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13610: $item.'"'.$checked.' />'.$name.'</label></span>'.
13611: '<input type="hidden" name="catname" value="'.$name.'" />'.
13612: '</td><td>';
1.663 raeburn 13613: if (ref($path) eq 'ARRAY') {
13614: push(@{$path},$name);
13615: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13616: pop(@{$path});
13617: }
13618: $text .= '</td></tr>';
13619: }
13620: $text .= '</table></td>';
13621: }
13622: }
13623: }
13624: return $text;
13625: }
13626:
1.655 raeburn 13627: ############################################################
13628: ############################################################
13629:
13630:
1.443 albertel 13631: sub commit_customrole {
1.664 raeburn 13632: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13633: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13634: ($start?', '.&mt('starting').' '.localtime($start):'').
13635: ($end?', ending '.localtime($end):'').': <b>'.
13636: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13637: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13638: '</b><br />';
13639: return $output;
13640: }
13641:
13642: sub commit_standardrole {
1.1075.2.31 raeburn 13643: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13644: my ($output,$logmsg,$linefeed);
13645: if ($context eq 'auto') {
13646: $linefeed = "\n";
13647: } else {
13648: $linefeed = "<br />\n";
13649: }
1.443 albertel 13650: if ($three eq 'st') {
1.541 raeburn 13651: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13652: $one,$two,$sec,$context,$credits);
1.541 raeburn 13653: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13654: ($result eq 'unknown_course') || ($result eq 'refused')) {
13655: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13656: } else {
1.541 raeburn 13657: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13658: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13659: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13660: if ($context eq 'auto') {
13661: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13662: } else {
13663: $output .= '<b>'.$result.'</b>'.$linefeed.
13664: &mt('Add to classlist').': <b>ok</b>';
13665: }
13666: $output .= $linefeed;
1.443 albertel 13667: }
13668: } else {
13669: $output = &mt('Assigning').' '.$three.' in '.$url.
13670: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13671: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13672: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13673: if ($context eq 'auto') {
13674: $output .= $result.$linefeed;
13675: } else {
13676: $output .= '<b>'.$result.'</b>'.$linefeed;
13677: }
1.443 albertel 13678: }
13679: return $output;
13680: }
13681:
13682: sub commit_studentrole {
1.1075.2.31 raeburn 13683: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13684: $credits) = @_;
1.626 raeburn 13685: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13686: if ($context eq 'auto') {
13687: $linefeed = "\n";
13688: } else {
13689: $linefeed = '<br />'."\n";
13690: }
1.443 albertel 13691: if (defined($one) && defined($two)) {
13692: my $cid=$one.'_'.$two;
13693: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13694: my $secchange = 0;
13695: my $expire_role_result;
13696: my $modify_section_result;
1.628 raeburn 13697: if ($oldsec ne '-1') {
13698: if ($oldsec ne $sec) {
1.443 albertel 13699: $secchange = 1;
1.628 raeburn 13700: my $now = time;
1.443 albertel 13701: my $uurl='/'.$cid;
13702: $uurl=~s/\_/\//g;
13703: if ($oldsec) {
13704: $uurl.='/'.$oldsec;
13705: }
1.626 raeburn 13706: $oldsecurl = $uurl;
1.628 raeburn 13707: $expire_role_result =
1.652 raeburn 13708: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13709: if ($env{'request.course.sec'} ne '') {
13710: if ($expire_role_result eq 'refused') {
13711: my @roles = ('st');
13712: my @statuses = ('previous');
13713: my @roledoms = ($one);
13714: my $withsec = 1;
13715: my %roleshash =
13716: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13717: \@statuses,\@roles,\@roledoms,$withsec);
13718: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13719: my ($oldstart,$oldend) =
13720: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13721: if ($oldend > 0 && $oldend <= $now) {
13722: $expire_role_result = 'ok';
13723: }
13724: }
13725: }
13726: }
1.443 albertel 13727: $result = $expire_role_result;
13728: }
13729: }
13730: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13731: $modify_section_result =
13732: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13733: undef,undef,undef,$sec,
13734: $end,$start,'','',$cid,
13735: '',$context,$credits);
1.443 albertel 13736: if ($modify_section_result =~ /^ok/) {
13737: if ($secchange == 1) {
1.628 raeburn 13738: if ($sec eq '') {
13739: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13740: } else {
13741: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13742: }
1.443 albertel 13743: } elsif ($oldsec eq '-1') {
1.628 raeburn 13744: if ($sec eq '') {
13745: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13746: } else {
13747: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13748: }
1.443 albertel 13749: } else {
1.628 raeburn 13750: if ($sec eq '') {
13751: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13752: } else {
13753: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13754: }
1.443 albertel 13755: }
13756: } else {
1.628 raeburn 13757: if ($secchange) {
13758: $$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;
13759: } else {
13760: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13761: }
1.443 albertel 13762: }
13763: $result = $modify_section_result;
13764: } elsif ($secchange == 1) {
1.628 raeburn 13765: if ($oldsec eq '') {
1.1075.2.20 raeburn 13766: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_2] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
1.628 raeburn 13767: } else {
13768: $$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;
13769: }
1.626 raeburn 13770: if ($expire_role_result eq 'refused') {
13771: my $newsecurl = '/'.$cid;
13772: $newsecurl =~ s/\_/\//g;
13773: if ($sec ne '') {
13774: $newsecurl.='/'.$sec;
13775: }
13776: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13777: if ($sec eq '') {
13778: $$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;
13779: } else {
13780: $$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;
13781: }
13782: }
13783: }
1.443 albertel 13784: }
13785: } else {
1.626 raeburn 13786: $$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 13787: $result = "error: incomplete course id\n";
13788: }
13789: return $result;
13790: }
13791:
1.1075.2.25 raeburn 13792: sub show_role_extent {
13793: my ($scope,$context,$role) = @_;
13794: $scope =~ s{^/}{};
13795: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13796: push(@courseroles,'co');
13797: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13798: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13799: $scope =~ s{/}{_};
13800: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13801: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13802: my ($audom,$auname) = split(/\//,$scope);
13803: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13804: &Apache::loncommon::plainname($auname,$audom).'</span>');
13805: } else {
13806: $scope =~ s{/$}{};
13807: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13808: &Apache::lonnet::domain($scope,'description').'</span>');
13809: }
13810: }
13811:
1.443 albertel 13812: ############################################################
13813: ############################################################
13814:
1.566 albertel 13815: sub check_clone {
1.578 raeburn 13816: my ($args,$linefeed) = @_;
1.566 albertel 13817: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13818: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13819: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13820: my $clonemsg;
13821: my $can_clone = 0;
1.944 raeburn 13822: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13823: if ($lctype ne 'community') {
13824: $lctype = 'course';
13825: }
1.566 albertel 13826: if ($clonehome eq 'no_host') {
1.944 raeburn 13827: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13828: $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'});
13829: } else {
13830: $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'});
13831: }
1.566 albertel 13832: } else {
13833: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13834: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13835: if ($clonedesc{'type'} ne 'Community') {
13836: $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'});
13837: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13838: }
13839: }
1.882 raeburn 13840: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13841: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13842: $can_clone = 1;
13843: } else {
13844: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13845: $args->{'clonedomain'},$args->{'clonecourse'});
13846: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13847: if (grep(/^\*$/,@cloners)) {
13848: $can_clone = 1;
13849: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13850: $can_clone = 1;
13851: } else {
1.908 raeburn 13852: my $ccrole = 'cc';
1.944 raeburn 13853: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13854: $ccrole = 'co';
13855: }
1.578 raeburn 13856: my %roleshash =
13857: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13858: $args->{'ccdomain'},
1.908 raeburn 13859: 'userroles',['active'],[$ccrole],
1.578 raeburn 13860: [$args->{'clonedomain'}]);
1.908 raeburn 13861: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13862: $can_clone = 1;
13863: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13864: $can_clone = 1;
13865: } else {
1.944 raeburn 13866: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13867: $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'});
13868: } else {
13869: $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'});
13870: }
1.578 raeburn 13871: }
1.566 albertel 13872: }
1.578 raeburn 13873: }
1.566 albertel 13874: }
13875: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13876: }
13877:
1.444 albertel 13878: sub construct_course {
1.1075.2.59! raeburn 13879: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13880: my $outcome;
1.541 raeburn 13881: my $linefeed = '<br />'."\n";
13882: if ($context eq 'auto') {
13883: $linefeed = "\n";
13884: }
1.566 albertel 13885:
13886: #
13887: # Are we cloning?
13888: #
13889: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13890: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13891: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13892: if ($context ne 'auto') {
1.578 raeburn 13893: if ($clonemsg ne '') {
13894: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13895: }
1.566 albertel 13896: }
13897: $outcome .= $clonemsg.$linefeed;
13898:
13899: if (!$can_clone) {
13900: return (0,$outcome);
13901: }
13902: }
13903:
1.444 albertel 13904: #
13905: # Open course
13906: #
13907: my $crstype = lc($args->{'crstype'});
13908: my %cenv=();
13909: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13910: $args->{'cdescr'},
13911: $args->{'curl'},
13912: $args->{'course_home'},
13913: $args->{'nonstandard'},
13914: $args->{'crscode'},
13915: $args->{'ccuname'}.':'.
13916: $args->{'ccdomain'},
1.882 raeburn 13917: $args->{'crstype'},
1.885 raeburn 13918: $cnum,$context,$category);
1.444 albertel 13919:
13920: # Note: The testing routines depend on this being output; see
13921: # Utils::Course. This needs to at least be output as a comment
13922: # if anyone ever decides to not show this, and Utils::Course::new
13923: # will need to be suitably modified.
1.541 raeburn 13924: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13925: if ($$courseid =~ /^error:/) {
13926: return (0,$outcome);
13927: }
13928:
1.444 albertel 13929: #
13930: # Check if created correctly
13931: #
1.479 albertel 13932: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13933: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13934: if ($crsuhome eq 'no_host') {
13935: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13936: return (0,$outcome);
13937: }
1.541 raeburn 13938: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13939:
1.444 albertel 13940: #
1.566 albertel 13941: # Do the cloning
13942: #
13943: if ($can_clone && $cloneid) {
13944: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13945: if ($context ne 'auto') {
13946: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13947: }
13948: $outcome .= $clonemsg.$linefeed;
13949: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13950: # Copy all files
1.637 www 13951: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13952: # Restore URL
1.566 albertel 13953: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13954: # Restore title
1.566 albertel 13955: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13956: # Restore creation date, creator and creation context.
13957: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13958: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13959: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13960: # Mark as cloned
1.566 albertel 13961: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13962: # Need to clone grading mode
13963: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13964: $cenv{'grading'}=$newenv{'grading'};
13965: # Do not clone these environment entries
13966: &Apache::lonnet::del('environment',
13967: ['default_enrollment_start_date',
13968: 'default_enrollment_end_date',
13969: 'question.email',
13970: 'policy.email',
13971: 'comment.email',
13972: 'pch.users.denied',
1.725 raeburn 13973: 'plc.users.denied',
13974: 'hidefromcat',
1.1075.2.36 raeburn 13975: 'checkforpriv',
1.1075.2.59! raeburn 13976: 'categories',
! 13977: 'internal.uniquecode'],
1.638 www 13978: $$crsudom,$$crsunum);
1.444 albertel 13979: }
1.566 albertel 13980:
1.444 albertel 13981: #
13982: # Set environment (will override cloned, if existing)
13983: #
13984: my @sections = ();
13985: my @xlists = ();
13986: if ($args->{'crstype'}) {
13987: $cenv{'type'}=$args->{'crstype'};
13988: }
13989: if ($args->{'crsid'}) {
13990: $cenv{'courseid'}=$args->{'crsid'};
13991: }
13992: if ($args->{'crscode'}) {
13993: $cenv{'internal.coursecode'}=$args->{'crscode'};
13994: }
13995: if ($args->{'crsquota'} ne '') {
13996: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13997: } else {
13998: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13999: }
14000: if ($args->{'ccuname'}) {
14001: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14002: ':'.$args->{'ccdomain'};
14003: } else {
14004: $cenv{'internal.courseowner'} = $args->{'curruser'};
14005: }
1.1075.2.31 raeburn 14006: if ($args->{'defaultcredits'}) {
14007: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14008: }
1.444 albertel 14009: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14010: if ($args->{'crssections'}) {
14011: $cenv{'internal.sectionnums'} = '';
14012: if ($args->{'crssections'} =~ m/,/) {
14013: @sections = split/,/,$args->{'crssections'};
14014: } else {
14015: $sections[0] = $args->{'crssections'};
14016: }
14017: if (@sections > 0) {
14018: foreach my $item (@sections) {
14019: my ($sec,$gp) = split/:/,$item;
14020: my $class = $args->{'crscode'}.$sec;
14021: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14022: $cenv{'internal.sectionnums'} .= $item.',';
14023: unless ($addcheck eq 'ok') {
14024: push @badclasses, $class;
14025: }
14026: }
14027: $cenv{'internal.sectionnums'} =~ s/,$//;
14028: }
14029: }
14030: # do not hide course coordinator from staff listing,
14031: # even if privileged
14032: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14033: # add course coordinator's domain to domains to check for privileged users
14034: # if different to course domain
14035: if ($$crsudom ne $args->{'ccdomain'}) {
14036: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14037: }
1.444 albertel 14038: # add crosslistings
14039: if ($args->{'crsxlist'}) {
14040: $cenv{'internal.crosslistings'}='';
14041: if ($args->{'crsxlist'} =~ m/,/) {
14042: @xlists = split/,/,$args->{'crsxlist'};
14043: } else {
14044: $xlists[0] = $args->{'crsxlist'};
14045: }
14046: if (@xlists > 0) {
14047: foreach my $item (@xlists) {
14048: my ($xl,$gp) = split/:/,$item;
14049: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14050: $cenv{'internal.crosslistings'} .= $item.',';
14051: unless ($addcheck eq 'ok') {
14052: push @badclasses, $xl;
14053: }
14054: }
14055: $cenv{'internal.crosslistings'} =~ s/,$//;
14056: }
14057: }
14058: if ($args->{'autoadds'}) {
14059: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14060: }
14061: if ($args->{'autodrops'}) {
14062: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14063: }
14064: # check for notification of enrollment changes
14065: my @notified = ();
14066: if ($args->{'notify_owner'}) {
14067: if ($args->{'ccuname'} ne '') {
14068: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14069: }
14070: }
14071: if ($args->{'notify_dc'}) {
14072: if ($uname ne '') {
1.630 raeburn 14073: push(@notified,$uname.':'.$udom);
1.444 albertel 14074: }
14075: }
14076: if (@notified > 0) {
14077: my $notifylist;
14078: if (@notified > 1) {
14079: $notifylist = join(',',@notified);
14080: } else {
14081: $notifylist = $notified[0];
14082: }
14083: $cenv{'internal.notifylist'} = $notifylist;
14084: }
14085: if (@badclasses > 0) {
14086: my %lt=&Apache::lonlocal::texthash(
14087: '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',
14088: 'dnhr' => 'does not have rights to access enrollment in these classes',
14089: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14090: );
1.541 raeburn 14091: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14092: ' ('.$lt{'adby'}.')';
14093: if ($context eq 'auto') {
14094: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14095: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14096: foreach my $item (@badclasses) {
14097: if ($context eq 'auto') {
14098: $outcome .= " - $item\n";
14099: } else {
14100: $outcome .= "<li>$item</li>\n";
14101: }
14102: }
14103: if ($context eq 'auto') {
14104: $outcome .= $linefeed;
14105: } else {
1.566 albertel 14106: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14107: }
14108: }
1.444 albertel 14109: }
14110: if ($args->{'no_end_date'}) {
14111: $args->{'endaccess'} = 0;
14112: }
14113: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14114: $cenv{'internal.autoend'}=$args->{'enrollend'};
14115: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14116: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14117: if ($args->{'showphotos'}) {
14118: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14119: }
14120: $cenv{'internal.authtype'} = $args->{'authtype'};
14121: $cenv{'internal.autharg'} = $args->{'autharg'};
14122: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14123: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14124: 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');
14125: if ($context eq 'auto') {
14126: $outcome .= $krb_msg;
14127: } else {
1.566 albertel 14128: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14129: }
14130: $outcome .= $linefeed;
1.444 albertel 14131: }
14132: }
14133: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14134: if ($args->{'setpolicy'}) {
14135: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14136: }
14137: if ($args->{'setcontent'}) {
14138: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14139: }
14140: }
14141: if ($args->{'reshome'}) {
14142: $cenv{'reshome'}=$args->{'reshome'}.'/';
14143: $cenv{'reshome'}=~s/\/+$/\//;
14144: }
14145: #
14146: # course has keyed access
14147: #
14148: if ($args->{'setkeys'}) {
14149: $cenv{'keyaccess'}='yes';
14150: }
14151: # if specified, key authority is not course, but user
14152: # only active if keyaccess is yes
14153: if ($args->{'keyauth'}) {
1.487 albertel 14154: my ($user,$domain) = split(':',$args->{'keyauth'});
14155: $user = &LONCAPA::clean_username($user);
14156: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14157: if ($user ne '' && $domain ne '') {
1.487 albertel 14158: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14159: }
14160: }
14161:
1.1075.2.59! raeburn 14162: #
! 14163: # generate and store uniquecode (available to course requester), if course should have one.
! 14164: #
! 14165: if ($args->{'uniquecode'}) {
! 14166: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
! 14167: if ($code) {
! 14168: $cenv{'internal.uniquecode'} = $code;
! 14169: my %crsinfo =
! 14170: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
! 14171: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
! 14172: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
! 14173: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
! 14174: }
! 14175: if (ref($coderef)) {
! 14176: $$coderef = $code;
! 14177: }
! 14178: }
! 14179: }
! 14180:
1.444 albertel 14181: if ($args->{'disresdis'}) {
14182: $cenv{'pch.roles.denied'}='st';
14183: }
14184: if ($args->{'disablechat'}) {
14185: $cenv{'plc.roles.denied'}='st';
14186: }
14187:
14188: # Record we've not yet viewed the Course Initialization Helper for this
14189: # course
14190: $cenv{'course.helper.not.run'} = 1;
14191: #
14192: # Use new Randomseed
14193: #
14194: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14195: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14196: #
14197: # The encryption code and receipt prefix for this course
14198: #
14199: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14200: $cenv{'internal.encpref'}=100+int(9*rand(99));
14201: #
14202: # By default, use standard grading
14203: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14204:
1.541 raeburn 14205: $outcome .= $linefeed.&mt('Setting environment').': '.
14206: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14207: #
14208: # Open all assignments
14209: #
14210: if ($args->{'openall'}) {
14211: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14212: my %storecontent = ($storeunder => time,
14213: $storeunder.'.type' => 'date_start');
14214:
14215: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14216: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14217: }
14218: #
14219: # Set first page
14220: #
14221: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14222: || ($cloneid)) {
1.445 albertel 14223: use LONCAPA::map;
1.444 albertel 14224: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14225:
14226: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14227: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14228:
1.444 albertel 14229: $outcome .= ($fatal?$errtext:'read ok').' - ';
14230: my $title; my $url;
14231: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14232: $title=&mt('Syllabus');
1.444 albertel 14233: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14234: } else {
1.963 raeburn 14235: $title=&mt('Table of Contents');
1.444 albertel 14236: $url='/adm/navmaps';
14237: }
1.445 albertel 14238:
14239: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14240: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14241:
14242: if ($errtext) { $fatal=2; }
1.541 raeburn 14243: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14244: }
1.566 albertel 14245:
14246: return (1,$outcome);
1.444 albertel 14247: }
14248:
1.1075.2.59! raeburn 14249: sub make_unique_code {
! 14250: my ($cdom,$cnum) = @_;
! 14251: # get lock on uniquecodes db
! 14252: my $lockhash = {
! 14253: $cnum."\0".'uniquecodes' => $env{'user.name'}.
! 14254: ':'.$env{'user.domain'},
! 14255: };
! 14256: my $tries = 0;
! 14257: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
! 14258: my ($code,$error);
! 14259:
! 14260: while (($gotlock ne 'ok') && ($tries<3)) {
! 14261: $tries ++;
! 14262: sleep 1;
! 14263: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
! 14264: }
! 14265: if ($gotlock eq 'ok') {
! 14266: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
! 14267: my $gotcode;
! 14268: my $attempts = 0;
! 14269: while ((!$gotcode) && ($attempts < 100)) {
! 14270: $code = &generate_code();
! 14271: if (!exists($currcodes{$code})) {
! 14272: $gotcode = 1;
! 14273: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
! 14274: $error = 'nostore';
! 14275: }
! 14276: }
! 14277: $attempts ++;
! 14278: }
! 14279: my @del_lock = ($cnum."\0".'uniquecodes');
! 14280: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
! 14281: } else {
! 14282: $error = 'nolock';
! 14283: }
! 14284: return ($code,$error);
! 14285: }
! 14286:
! 14287: sub generate_code {
! 14288: my $code;
! 14289: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
! 14290: for (my $i=0; $i<6; $i++) {
! 14291: my $lettnum = int (rand 2);
! 14292: my $item = '';
! 14293: if ($lettnum) {
! 14294: $item = $letts[int( rand(18) )];
! 14295: } else {
! 14296: $item = 1+int( rand(8) );
! 14297: }
! 14298: $code .= $item;
! 14299: }
! 14300: return $code;
! 14301: }
! 14302:
1.444 albertel 14303: ############################################################
14304: ############################################################
14305:
1.953 droeschl 14306: #SD
14307: # only Community and Course, or anything else?
1.378 raeburn 14308: sub course_type {
14309: my ($cid) = @_;
14310: if (!defined($cid)) {
14311: $cid = $env{'request.course.id'};
14312: }
1.404 albertel 14313: if (defined($env{'course.'.$cid.'.type'})) {
14314: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14315: } else {
14316: return 'Course';
1.377 raeburn 14317: }
14318: }
1.156 albertel 14319:
1.406 raeburn 14320: sub group_term {
14321: my $crstype = &course_type();
14322: my %names = (
14323: 'Course' => 'group',
1.865 raeburn 14324: 'Community' => 'group',
1.406 raeburn 14325: );
14326: return $names{$crstype};
14327: }
14328:
1.902 raeburn 14329: sub course_types {
1.1075.2.59! raeburn 14330: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14331: my %typename = (
14332: official => 'Official course',
14333: unofficial => 'Unofficial course',
14334: community => 'Community',
1.1075.2.59! raeburn 14335: textbook => 'Textbook course',
1.902 raeburn 14336: );
14337: return (\@types,\%typename);
14338: }
14339:
1.156 albertel 14340: sub icon {
14341: my ($file)=@_;
1.505 albertel 14342: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14343: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14344: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14345: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14346: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14347: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14348: $curfext.".gif") {
14349: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14350: $curfext.".gif";
14351: }
14352: }
1.249 albertel 14353: return &lonhttpdurl($iconname);
1.154 albertel 14354: }
1.84 albertel 14355:
1.575 albertel 14356: sub lonhttpdurl {
1.692 www 14357: #
14358: # Had been used for "small fry" static images on separate port 8080.
14359: # Modify here if lightweight http functionality desired again.
14360: # Currently eliminated due to increasing firewall issues.
14361: #
1.575 albertel 14362: my ($url)=@_;
1.692 www 14363: return $url;
1.215 albertel 14364: }
14365:
1.213 albertel 14366: sub connection_aborted {
14367: my ($r)=@_;
14368: $r->print(" ");$r->rflush();
14369: my $c = $r->connection;
14370: return $c->aborted();
14371: }
14372:
1.221 foxr 14373: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14374: # strings as 'strings'.
14375: sub escape_single {
1.221 foxr 14376: my ($input) = @_;
1.223 albertel 14377: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14378: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14379: return $input;
14380: }
1.223 albertel 14381:
1.222 foxr 14382: # Same as escape_single, but escape's "'s This
14383: # can be used for "strings"
14384: sub escape_double {
14385: my ($input) = @_;
14386: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14387: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14388: return $input;
14389: }
1.223 albertel 14390:
1.222 foxr 14391: # Escapes the last element of a full URL.
14392: sub escape_url {
14393: my ($url) = @_;
1.238 raeburn 14394: my @urlslices = split(/\//, $url,-1);
1.369 www 14395: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14396: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14397: }
1.462 albertel 14398:
1.820 raeburn 14399: sub compare_arrays {
14400: my ($arrayref1,$arrayref2) = @_;
14401: my (@difference,%count);
14402: @difference = ();
14403: %count = ();
14404: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14405: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14406: foreach my $element (keys(%count)) {
14407: if ($count{$element} == 1) {
14408: push(@difference,$element);
14409: }
14410: }
14411: }
14412: return @difference;
14413: }
14414:
1.817 bisitz 14415: # -------------------------------------------------------- Initialize user login
1.462 albertel 14416: sub init_user_environment {
1.463 albertel 14417: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14418: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14419:
14420: my $public=($username eq 'public' && $domain eq 'public');
14421:
14422: # See if old ID present, if so, remove
14423:
1.1062 raeburn 14424: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14425: my $now=time;
14426:
14427: if ($public) {
14428: my $max_public=100;
14429: my $oldest;
14430: my $oldest_time=0;
14431: for(my $next=1;$next<=$max_public;$next++) {
14432: if (-e $lonids."/publicuser_$next.id") {
14433: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14434: if ($mtime<$oldest_time || !$oldest_time) {
14435: $oldest_time=$mtime;
14436: $oldest=$next;
14437: }
14438: } else {
14439: $cookie="publicuser_$next";
14440: last;
14441: }
14442: }
14443: if (!$cookie) { $cookie="publicuser_$oldest"; }
14444: } else {
1.463 albertel 14445: # if this isn't a robot, kill any existing non-robot sessions
14446: if (!$args->{'robot'}) {
14447: opendir(DIR,$lonids);
14448: while ($filename=readdir(DIR)) {
14449: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14450: unlink($lonids.'/'.$filename);
14451: }
1.462 albertel 14452: }
1.463 albertel 14453: closedir(DIR);
1.462 albertel 14454: }
14455: # Give them a new cookie
1.463 albertel 14456: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14457: : $now.$$.int(rand(10000)));
1.463 albertel 14458: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14459:
14460: # Initialize roles
14461:
1.1062 raeburn 14462: ($userroles,$firstaccenv,$timerintenv) =
14463: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14464: }
14465: # ------------------------------------ Check browser type and MathML capability
14466:
14467: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14468: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14469:
14470: # ------------------------------------------------------------- Get environment
14471:
14472: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14473: my ($tmp) = keys(%userenv);
14474: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14475: } else {
14476: undef(%userenv);
14477: }
14478: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14479: $form->{'interface'}=$userenv{'interface'};
14480: }
14481: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14482:
14483: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14484: foreach my $option ('interface','localpath','localres') {
14485: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14486: }
14487: # --------------------------------------------------------- Write first profile
14488:
14489: {
14490: my %initial_env =
14491: ("user.name" => $username,
14492: "user.domain" => $domain,
14493: "user.home" => $authhost,
14494: "browser.type" => $clientbrowser,
14495: "browser.version" => $clientversion,
14496: "browser.mathml" => $clientmathml,
14497: "browser.unicode" => $clientunicode,
14498: "browser.os" => $clientos,
1.1075.2.42 raeburn 14499: "browser.mobile" => $clientmobile,
14500: "browser.info" => $clientinfo,
1.462 albertel 14501: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14502: "request.course.fn" => '',
14503: "request.course.uri" => '',
14504: "request.course.sec" => '',
14505: "request.role" => 'cm',
14506: "request.role.adv" => $env{'user.adv'},
14507: "request.host" => $ENV{'REMOTE_ADDR'},);
14508:
14509: if ($form->{'localpath'}) {
14510: $initial_env{"browser.localpath"} = $form->{'localpath'};
14511: $initial_env{"browser.localres"} = $form->{'localres'};
14512: }
14513:
14514: if ($form->{'interface'}) {
14515: $form->{'interface'}=~s/\W//gs;
14516: $initial_env{"browser.interface"} = $form->{'interface'};
14517: $env{'browser.interface'}=$form->{'interface'};
14518: }
14519:
1.1075.2.54 raeburn 14520: if ($form->{'iptoken'}) {
14521: my $lonhost = $r->dir_config('lonHostID');
14522: $initial_env{"user.noloadbalance"} = $lonhost;
14523: $env{'user.noloadbalance'} = $lonhost;
14524: }
14525:
1.981 raeburn 14526: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14527: my %domdef;
14528: unless ($domain eq 'public') {
14529: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14530: }
1.980 raeburn 14531:
1.1075.2.7 raeburn 14532: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14533: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14534: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14535: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14536: }
14537:
1.1075.2.59! raeburn 14538: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14539: $userenv{'canrequest.'.$crstype} =
14540: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14541: 'reload','requestcourses',
14542: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14543: }
14544:
1.1075.2.14 raeburn 14545: $userenv{'canrequest.author'} =
14546: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14547: 'reload','requestauthor',
14548: \%userenv,\%domdef,\%is_adv);
14549: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14550: $domain,$username);
14551: my $reqstatus = $reqauthor{'author_status'};
14552: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14553: if (ref($reqauthor{'author'}) eq 'HASH') {
14554: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14555: $reqauthor{'author'}{'timestamp'};
14556: }
14557: }
14558:
1.462 albertel 14559: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14560:
1.462 albertel 14561: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14562: &GDBM_WRCREAT(),0640)) {
14563: &_add_to_env(\%disk_env,\%initial_env);
14564: &_add_to_env(\%disk_env,\%userenv,'environment.');
14565: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14566: if (ref($firstaccenv) eq 'HASH') {
14567: &_add_to_env(\%disk_env,$firstaccenv);
14568: }
14569: if (ref($timerintenv) eq 'HASH') {
14570: &_add_to_env(\%disk_env,$timerintenv);
14571: }
1.463 albertel 14572: if (ref($args->{'extra_env'})) {
14573: &_add_to_env(\%disk_env,$args->{'extra_env'});
14574: }
1.462 albertel 14575: untie(%disk_env);
14576: } else {
1.705 tempelho 14577: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14578: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14579: return 'error: '.$!;
14580: }
14581: }
14582: $env{'request.role'}='cm';
14583: $env{'request.role.adv'}=$env{'user.adv'};
14584: $env{'browser.type'}=$clientbrowser;
14585:
14586: return $cookie;
14587:
14588: }
14589:
14590: sub _add_to_env {
14591: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14592: if (ref($env_data) eq 'HASH') {
14593: while (my ($key,$value) = each(%$env_data)) {
14594: $idf->{$prefix.$key} = $value;
14595: $env{$prefix.$key} = $value;
14596: }
1.462 albertel 14597: }
14598: }
14599:
1.685 tempelho 14600: # --- Get the symbolic name of a problem and the url
14601: sub get_symb {
14602: my ($request,$silent) = @_;
1.726 raeburn 14603: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14604: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14605: if ($symb eq '') {
14606: if (!$silent) {
1.1071 raeburn 14607: if (ref($request)) {
14608: $request->print("Unable to handle ambiguous references:$url:.");
14609: }
1.685 tempelho 14610: return ();
14611: }
14612: }
14613: &Apache::lonenc::check_decrypt(\$symb);
14614: return ($symb);
14615: }
14616:
14617: # --------------------------------------------------------------Get annotation
14618:
14619: sub get_annotation {
14620: my ($symb,$enc) = @_;
14621:
14622: my $key = $symb;
14623: if (!$enc) {
14624: $key =
14625: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14626: }
14627: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14628: return $annotation{$key};
14629: }
14630:
14631: sub clean_symb {
1.731 raeburn 14632: my ($symb,$delete_enc) = @_;
1.685 tempelho 14633:
14634: &Apache::lonenc::check_decrypt(\$symb);
14635: my $enc = $env{'request.enc'};
1.731 raeburn 14636: if ($delete_enc) {
1.730 raeburn 14637: delete($env{'request.enc'});
14638: }
1.685 tempelho 14639:
14640: return ($symb,$enc);
14641: }
1.462 albertel 14642:
1.990 raeburn 14643: sub build_release_hashes {
14644: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14645: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14646: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14647: (ref($randomizetry) eq 'HASH'));
14648: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14649: my ($item,$name,$value) = split(/:/,$key);
14650: if ($item eq 'parameter') {
14651: if (ref($checkparms->{$name}) eq 'ARRAY') {
14652: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14653: push(@{$checkparms->{$name}},$value);
14654: }
14655: } else {
14656: push(@{$checkparms->{$name}},$value);
14657: }
14658: } elsif ($item eq 'resourcetag') {
14659: if ($name eq 'responsetype') {
14660: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14661: }
14662: } elsif ($item eq 'course') {
14663: if ($name eq 'crstype') {
14664: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14665: }
14666: }
14667: }
14668: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14669: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14670: return;
14671: }
14672:
1.1075.2.11 raeburn 14673: sub update_content_constraints {
14674: my ($cdom,$cnum,$chome,$cid) = @_;
14675: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14676: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14677: my %checkresponsetypes;
14678: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14679: my ($item,$name,$value) = split(/:/,$key);
14680: if ($item eq 'resourcetag') {
14681: if ($name eq 'responsetype') {
14682: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14683: }
14684: }
14685: }
14686: my $navmap = Apache::lonnavmaps::navmap->new();
14687: if (defined($navmap)) {
14688: my %allresponses;
14689: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14690: my %responses = $res->responseTypes();
14691: foreach my $key (keys(%responses)) {
14692: next unless(exists($checkresponsetypes{$key}));
14693: $allresponses{$key} += $responses{$key};
14694: }
14695: }
14696: foreach my $key (keys(%allresponses)) {
14697: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14698: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14699: ($reqdmajor,$reqdminor) = ($major,$minor);
14700: }
14701: }
14702: undef($navmap);
14703: }
14704: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14705: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14706: }
14707: return;
14708: }
14709:
1.1075.2.27 raeburn 14710: sub allmaps_incourse {
14711: my ($cdom,$cnum,$chome,$cid) = @_;
14712: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14713: $cid = $env{'request.course.id'};
14714: $cdom = $env{'course.'.$cid.'.domain'};
14715: $cnum = $env{'course.'.$cid.'.num'};
14716: $chome = $env{'course.'.$cid.'.home'};
14717: }
14718: my %allmaps = ();
14719: my $lastchange =
14720: &Apache::lonnet::get_coursechange($cdom,$cnum);
14721: if ($lastchange > $env{'request.course.tied'}) {
14722: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14723: unless ($ferr) {
14724: &update_content_constraints($cdom,$cnum,$chome,$cid);
14725: }
14726: }
14727: my $navmap = Apache::lonnavmaps::navmap->new();
14728: if (defined($navmap)) {
14729: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14730: $allmaps{$res->src()} = 1;
14731: }
14732: }
14733: return \%allmaps;
14734: }
14735:
1.1075.2.11 raeburn 14736: sub parse_supplemental_title {
14737: my ($title) = @_;
14738:
14739: my ($foldertitle,$renametitle);
14740: if ($title =~ /&&&/) {
14741: $title = &HTML::Entites::decode($title);
14742: }
14743: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14744: $renametitle=$4;
14745: my ($time,$uname,$udom) = ($1,$2,$3);
14746: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14747: my $name = &plainname($uname,$udom);
14748: $name = &HTML::Entities::encode($name,'"<>&\'');
14749: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14750: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14751: $name.': <br />'.$foldertitle;
14752: }
14753: if (wantarray) {
14754: return ($title,$foldertitle,$renametitle);
14755: }
14756: return $title;
14757: }
14758:
1.1075.2.43 raeburn 14759: sub recurse_supplemental {
14760: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14761: if ($suppmap) {
14762: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14763: if ($fatal) {
14764: $errors ++;
14765: } else {
14766: if ($#LONCAPA::map::resources > 0) {
14767: foreach my $res (@LONCAPA::map::resources) {
14768: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14769: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 14770: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14771: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 14772: } else {
14773: $numfiles ++;
14774: }
14775: }
14776: }
14777: }
14778: }
14779: }
14780: return ($numfiles,$errors);
14781: }
14782:
1.1075.2.18 raeburn 14783: sub symb_to_docspath {
14784: my ($symb) = @_;
14785: return unless ($symb);
14786: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14787: if ($resurl=~/\.(sequence|page)$/) {
14788: $mapurl=$resurl;
14789: } elsif ($resurl eq 'adm/navmaps') {
14790: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14791: }
14792: my $mapresobj;
14793: my $navmap = Apache::lonnavmaps::navmap->new();
14794: if (ref($navmap)) {
14795: $mapresobj = $navmap->getResourceByUrl($mapurl);
14796: }
14797: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14798: my $type=$2;
14799: my $path;
14800: if (ref($mapresobj)) {
14801: my $pcslist = $mapresobj->map_hierarchy();
14802: if ($pcslist ne '') {
14803: foreach my $pc (split(/,/,$pcslist)) {
14804: next if ($pc <= 1);
14805: my $res = $navmap->getByMapPc($pc);
14806: if (ref($res)) {
14807: my $thisurl = $res->src();
14808: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14809: my $thistitle = $res->title();
14810: $path .= '&'.
14811: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 14812: &escape($thistitle).
1.1075.2.18 raeburn 14813: ':'.$res->randompick().
14814: ':'.$res->randomout().
14815: ':'.$res->encrypted().
14816: ':'.$res->randomorder().
14817: ':'.$res->is_page();
14818: }
14819: }
14820: }
14821: $path =~ s/^\&//;
14822: my $maptitle = $mapresobj->title();
14823: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14824: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14825: }
14826: $path .= (($path ne '')? '&' : '').
14827: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14828: &escape($maptitle).
1.1075.2.18 raeburn 14829: ':'.$mapresobj->randompick().
14830: ':'.$mapresobj->randomout().
14831: ':'.$mapresobj->encrypted().
14832: ':'.$mapresobj->randomorder().
14833: ':'.$mapresobj->is_page();
14834: } else {
14835: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14836: my $ispage = (($type eq 'page')? 1 : '');
14837: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14838: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14839: }
14840: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14841: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 14842: }
14843: unless ($mapurl eq 'default') {
14844: $path = 'default&'.
1.1075.2.46 raeburn 14845: &escape('Main Content').
1.1075.2.18 raeburn 14846: ':::::&'.$path;
14847: }
14848: return $path;
14849: }
14850:
1.1075.2.14 raeburn 14851: sub captcha_display {
14852: my ($context,$lonhost) = @_;
14853: my ($output,$error);
14854: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14855: if ($captcha eq 'original') {
14856: $output = &create_captcha();
14857: unless ($output) {
14858: $error = 'captcha';
14859: }
14860: } elsif ($captcha eq 'recaptcha') {
14861: $output = &create_recaptcha($pubkey);
14862: unless ($output) {
14863: $error = 'recaptcha';
14864: }
14865: }
14866: return ($output,$error);
14867: }
14868:
14869: sub captcha_response {
14870: my ($context,$lonhost) = @_;
14871: my ($captcha_chk,$captcha_error);
14872: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14873: if ($captcha eq 'original') {
14874: ($captcha_chk,$captcha_error) = &check_captcha();
14875: } elsif ($captcha eq 'recaptcha') {
14876: $captcha_chk = &check_recaptcha($privkey);
14877: } else {
14878: $captcha_chk = 1;
14879: }
14880: return ($captcha_chk,$captcha_error);
14881: }
14882:
14883: sub get_captcha_config {
14884: my ($context,$lonhost) = @_;
14885: my ($captcha,$pubkey,$privkey,$hashtocheck);
14886: my $hostname = &Apache::lonnet::hostname($lonhost);
14887: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14888: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14889: if ($context eq 'usercreation') {
14890: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14891: if (ref($domconfig{$context}) eq 'HASH') {
14892: $hashtocheck = $domconfig{$context}{'cancreate'};
14893: if (ref($hashtocheck) eq 'HASH') {
14894: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14895: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14896: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14897: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14898: }
14899: if ($privkey && $pubkey) {
14900: $captcha = 'recaptcha';
14901: } else {
14902: $captcha = 'original';
14903: }
14904: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14905: $captcha = 'original';
14906: }
14907: }
14908: } else {
14909: $captcha = 'captcha';
14910: }
14911: } elsif ($context eq 'login') {
14912: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14913: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14914: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14915: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14916: if ($privkey && $pubkey) {
14917: $captcha = 'recaptcha';
14918: } else {
14919: $captcha = 'original';
14920: }
14921: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14922: $captcha = 'original';
14923: }
14924: }
14925: return ($captcha,$pubkey,$privkey);
14926: }
14927:
14928: sub create_captcha {
14929: my %captcha_params = &captcha_settings();
14930: my ($output,$maxtries,$tries) = ('',10,0);
14931: while ($tries < $maxtries) {
14932: $tries ++;
14933: my $captcha = Authen::Captcha->new (
14934: output_folder => $captcha_params{'output_dir'},
14935: data_folder => $captcha_params{'db_dir'},
14936: );
14937: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14938:
14939: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14940: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14941: &mt('Type in the letters/numbers shown below').' '.
14942: '<input type="text" size="5" name="code" value="" /><br />'.
14943: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14944: last;
14945: }
14946: }
14947: return $output;
14948: }
14949:
14950: sub captcha_settings {
14951: my %captcha_params = (
14952: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14953: www_output_dir => "/captchaspool",
14954: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14955: numchars => '5',
14956: );
14957: return %captcha_params;
14958: }
14959:
14960: sub check_captcha {
14961: my ($captcha_chk,$captcha_error);
14962: my $code = $env{'form.code'};
14963: my $md5sum = $env{'form.crypt'};
14964: my %captcha_params = &captcha_settings();
14965: my $captcha = Authen::Captcha->new(
14966: output_folder => $captcha_params{'output_dir'},
14967: data_folder => $captcha_params{'db_dir'},
14968: );
1.1075.2.26 raeburn 14969: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 14970: my %captcha_hash = (
14971: 0 => 'Code not checked (file error)',
14972: -1 => 'Failed: code expired',
14973: -2 => 'Failed: invalid code (not in database)',
14974: -3 => 'Failed: invalid code (code does not match crypt)',
14975: );
14976: if ($captcha_chk != 1) {
14977: $captcha_error = $captcha_hash{$captcha_chk}
14978: }
14979: return ($captcha_chk,$captcha_error);
14980: }
14981:
14982: sub create_recaptcha {
14983: my ($pubkey) = @_;
1.1075.2.51 raeburn 14984: my $use_ssl;
14985: if ($ENV{'SERVER_PORT'} == 443) {
14986: $use_ssl = 1;
14987: }
1.1075.2.14 raeburn 14988: my $captcha = Captcha::reCAPTCHA->new;
14989: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 14990: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 14991: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 14992: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 14993: '<br /><br />';
14994: }
14995:
14996: sub check_recaptcha {
14997: my ($privkey) = @_;
14998: my $captcha_chk;
14999: my $captcha = Captcha::reCAPTCHA->new;
15000: my $captcha_result =
15001: $captcha->check_answer(
15002: $privkey,
15003: $ENV{'REMOTE_ADDR'},
15004: $env{'form.recaptcha_challenge_field'},
15005: $env{'form.recaptcha_response_field'},
15006: );
15007: if ($captcha_result->{is_valid}) {
15008: $captcha_chk = 1;
15009: }
15010: return $captcha_chk;
15011: }
15012:
1.1075.2.56 raeburn 15013: sub cleanup_html {
15014: my ($incoming) = @_;
15015: my $outgoing;
15016: if ($incoming ne '') {
15017: $outgoing = $incoming;
15018: $outgoing =~ s/;/;/g;
15019: $outgoing =~ s/\#/#/g;
15020: $outgoing =~ s/\&/&/g;
15021: $outgoing =~ s/</</g;
15022: $outgoing =~ s/>/>/g;
15023: $outgoing =~ s/\(/(/g;
15024: $outgoing =~ s/\)/)/g;
15025: $outgoing =~ s/"/"/g;
15026: $outgoing =~ s/'/'/g;
15027: $outgoing =~ s/\$/$/g;
15028: $outgoing =~ s{/}{/}g;
15029: $outgoing =~ s/=/=/g;
15030: $outgoing =~ s/\\/\/g
15031: }
15032: return $outgoing;
15033: }
15034:
1.41 ng 15035: =pod
15036:
15037: =back
15038:
1.112 bowersj2 15039: =cut
1.41 ng 15040:
1.112 bowersj2 15041: 1;
15042: __END__;
1.41 ng 15043:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>