Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.127.2.8
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.127. .8(raebu 4:19): # $Id: loncommon.pm,v 1.1075.2.127.2.7 2019/02/06 16:10:34 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.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.1075.2.102 raeburn 75: use DateTime::Locale;
1.1075.2.94 raeburn 76: use Encode();
1.1075.2.14 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 79: use JSON::DWIW;
80: use LWP::UserAgent;
1.1075.2.64 raeburn 81: use Crypt::DES;
82: use DynaLoader; # for Crypt::DES version
1.1075.2.127. .3(raebu 83:17): use File::Copy();
.4(raebu 84:17): use File::Path();
.7(raebu 85:19): use String::CRC32();
86:19): use Short::URL();
1.117 www 87:
1.517 raeburn 88: # ---------------------------------------------- Designs
89: use vars qw(%defaultdesign);
90:
1.22 www 91: my $readit;
92:
1.517 raeburn 93:
1.157 matthew 94: ##
95: ## Global Variables
96: ##
1.46 matthew 97:
1.643 foxr 98:
99: # ----------------------------------------------- SSI with retries:
100: #
101:
102: =pod
103:
1.648 raeburn 104: =head1 Server Side include with retries:
1.643 foxr 105:
106: =over 4
107:
1.648 raeburn 108: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 109:
110: Performs an ssi with some number of retries. Retries continue either
111: until the result is ok or until the retry count supplied by the
112: caller is exhausted.
113:
114: Inputs:
1.648 raeburn 115:
116: =over 4
117:
1.643 foxr 118: resource - Identifies the resource to insert.
1.648 raeburn 119:
1.643 foxr 120: retries - Count of the number of retries allowed.
1.648 raeburn 121:
1.643 foxr 122: form - Hash that identifies the rendering options.
123:
1.648 raeburn 124: =back
125:
126: Returns:
127:
128: =over 4
129:
1.643 foxr 130: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 131:
1.643 foxr 132: response - The response from the last attempt (which may or may not have been successful.
133:
1.648 raeburn 134: =back
135:
136: =back
137:
1.643 foxr 138: =cut
139:
140: sub ssi_with_retries {
141: my ($resource, $retries, %form) = @_;
142:
143:
144: my $ok = 0; # True if we got a good response.
145: my $content;
146: my $response;
147:
148: # Try to get the ssi done. within the retries count:
149:
150: do {
151: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
152: $ok = $response->is_success;
1.650 www 153: if (!$ok) {
154: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
155: }
1.643 foxr 156: $retries--;
157: } while (!$ok && ($retries > 0));
158:
159: if (!$ok) {
160: $content = ''; # On error return an empty content.
161: }
162: return ($content, $response);
163:
164: }
165:
166:
167:
1.20 www 168: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 169: my %language;
1.124 www 170: my %supported_language;
1.1048 foxr 171: my %latex_language; # For choosing hyphenation in <transl..>
172: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 173: my %cprtag;
1.192 taceyjo1 174: my %scprtag;
1.351 www 175: my %fe; my %fd; my %fm;
1.41 ng 176: my %category_extensions;
1.12 harris41 177:
1.46 matthew 178: # ---------------------------------------------- Thesaurus variables
1.144 matthew 179: #
180: # %Keywords:
181: # A hash used by &keyword to determine if a word is considered a keyword.
182: # $thesaurus_db_file
183: # Scalar containing the full path to the thesaurus database.
1.46 matthew 184:
185: my %Keywords;
186: my $thesaurus_db_file;
187:
1.144 matthew 188: #
189: # Initialize values from language.tab, copyright.tab, filetypes.tab,
190: # thesaurus.tab, and filecategories.tab.
191: #
1.18 www 192: BEGIN {
1.46 matthew 193: # Variable initialization
194: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
195: #
1.22 www 196: unless ($readit) {
1.12 harris41 197: # ------------------------------------------------------------------- languages
198: {
1.158 raeburn 199: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
200: '/language.tab';
1.1075.2.127. .5(raebu 201:18): if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 202: while (my $line = <$fh>) {
203: next if ($line=~/^\#/);
204: chomp($line);
1.1048 foxr 205: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 206: $language{$key}=$val.' - '.$enc;
207: if ($sup) {
208: $supported_language{$key}=$sup;
209: }
1.1048 foxr 210: if ($latex) {
211: $latex_language_bykey{$key} = $latex;
212: $latex_language{$two} = $latex;
213: }
1.158 raeburn 214: }
215: close($fh);
216: }
1.12 harris41 217: }
218: # ------------------------------------------------------------------ copyrights
219: {
1.158 raeburn 220: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
221: '/copyright.tab';
1.1075.2.127. .5(raebu 222:18): if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 223: while (my $line = <$fh>) {
224: next if ($line=~/^\#/);
225: chomp($line);
226: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 227: $cprtag{$key}=$val;
228: }
229: close($fh);
230: }
1.12 harris41 231: }
1.351 www 232: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 233: {
234: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
235: '/source_copyright.tab';
1.1075.2.127. .5(raebu 236:18): if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 237: while (my $line = <$fh>) {
238: next if ($line =~ /^\#/);
239: chomp($line);
240: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 241: $scprtag{$key}=$val;
242: }
243: close($fh);
244: }
245: }
1.63 www 246:
1.517 raeburn 247: # -------------------------------------------------------------- default domain designs
1.63 www 248: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 249: my $designfile = $designdir.'/default.tab';
1.1075.2.127. .5(raebu 250:18): if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 251: while (my $line = <$fh>) {
252: next if ($line =~ /^\#/);
253: chomp($line);
254: my ($key,$val)=(split(/\=/,$line));
255: if ($val) { $defaultdesign{$key}=$val; }
256: }
257: close($fh);
1.63 www 258: }
259:
1.15 harris41 260: # ------------------------------------------------------------- file categories
261: {
1.158 raeburn 262: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
263: '/filecategories.tab';
1.1075.2.127. .5(raebu 264:18): if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 265: while (my $line = <$fh>) {
266: next if ($line =~ /^\#/);
267: chomp($line);
268: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 269: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 270: }
271: close($fh);
272: }
273:
1.15 harris41 274: }
1.12 harris41 275: # ------------------------------------------------------------------ file types
276: {
1.158 raeburn 277: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
278: '/filetypes.tab';
1.1075.2.127. .5(raebu 279:18): if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 280: while (my $line = <$fh>) {
281: next if ($line =~ /^\#/);
282: chomp($line);
283: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 284: if ($descr ne '') {
285: $fe{$ending}=lc($emb);
286: $fd{$ending}=$descr;
1.351 www 287: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 288: }
289: }
290: close($fh);
291: }
1.12 harris41 292: }
1.22 www 293: &Apache::lonnet::logthis(
1.705 tempelho 294: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 295: $readit=1;
1.46 matthew 296: } # end of unless($readit)
1.32 matthew 297:
298: }
1.112 bowersj2 299:
1.42 matthew 300: ###############################################################
301: ## HTML and Javascript Helper Functions ##
302: ###############################################################
303:
304: =pod
305:
1.112 bowersj2 306: =head1 HTML and Javascript Functions
1.42 matthew 307:
1.112 bowersj2 308: =over 4
309:
1.648 raeburn 310: =item * &browser_and_searcher_javascript()
1.112 bowersj2 311:
312: X<browsing, javascript>X<searching, javascript>Returns a string
313: containing javascript with two functions, C<openbrowser> and
314: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
315: tags.
1.42 matthew 316:
1.648 raeburn 317: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 318:
319: inputs: formname, elementname, only, omit
320:
321: formname and elementname indicate the name of the html form and name of
322: the element that the results of the browsing selection are to be placed in.
323:
324: Specifying 'only' will restrict the browser to displaying only files
1.185 www 325: with the given extension. Can be a comma separated list.
1.42 matthew 326:
327: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 328: with the given extension. Can be a comma separated list.
1.42 matthew 329:
1.648 raeburn 330: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 331:
332: Inputs: formname, elementname
333:
334: formname and elementname specify the name of the html form and the name
335: of the element the selection from the search results will be placed in.
1.542 raeburn 336:
1.42 matthew 337: =cut
338:
339: sub browser_and_searcher_javascript {
1.199 albertel 340: my ($mode)=@_;
341: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 342: my $resurl=&escape_single(&lastresurl());
1.42 matthew 343: return <<END;
1.219 albertel 344: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 345: var editbrowser = null;
1.135 albertel 346: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 347: var url = '$resurl/?';
1.42 matthew 348: if (editbrowser == null) {
349: url += 'launch=1&';
350: }
351: url += 'catalogmode=interactive&';
1.199 albertel 352: url += 'mode=$mode&';
1.611 albertel 353: url += 'inhibitmenu=yes&';
1.42 matthew 354: url += 'form=' + formname + '&';
355: if (only != null) {
356: url += 'only=' + only + '&';
1.217 albertel 357: } else {
358: url += 'only=&';
359: }
1.42 matthew 360: if (omit != null) {
361: url += 'omit=' + omit + '&';
1.217 albertel 362: } else {
363: url += 'omit=&';
364: }
1.135 albertel 365: if (titleelement != null) {
366: url += 'titleelement=' + titleelement + '&';
1.217 albertel 367: } else {
368: url += 'titleelement=&';
369: }
1.42 matthew 370: url += 'element=' + elementname + '';
371: var title = 'Browser';
1.435 albertel 372: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 373: options += ',width=700,height=600';
374: editbrowser = open(url,title,options,'1');
375: editbrowser.focus();
376: }
377: var editsearcher;
1.135 albertel 378: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 379: var url = '/adm/searchcat?';
380: if (editsearcher == null) {
381: url += 'launch=1&';
382: }
383: url += 'catalogmode=interactive&';
1.199 albertel 384: url += 'mode=$mode&';
1.42 matthew 385: url += 'form=' + formname + '&';
1.135 albertel 386: if (titleelement != null) {
387: url += 'titleelement=' + titleelement + '&';
1.217 albertel 388: } else {
389: url += 'titleelement=&';
390: }
1.42 matthew 391: url += 'element=' + elementname + '';
392: var title = 'Search';
1.435 albertel 393: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 394: options += ',width=700,height=600';
395: editsearcher = open(url,title,options,'1');
396: editsearcher.focus();
397: }
1.219 albertel 398: // END LON-CAPA Internal -->
1.42 matthew 399: END
1.170 www 400: }
401:
402: sub lastresurl {
1.258 albertel 403: if ($env{'environment.lastresurl'}) {
404: return $env{'environment.lastresurl'}
1.170 www 405: } else {
406: return '/res';
407: }
408: }
409:
410: sub storeresurl {
411: my $resurl=&Apache::lonnet::clutter(shift);
412: unless ($resurl=~/^\/res/) { return 0; }
413: $resurl=~s/\/$//;
414: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 415: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 416: return 1;
1.42 matthew 417: }
418:
1.74 www 419: sub studentbrowser_javascript {
1.111 www 420: unless (
1.258 albertel 421: (($env{'request.course.id'}) &&
1.302 albertel 422: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
423: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
424: '/'.$env{'request.course.sec'})
425: ))
1.258 albertel 426: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 427: ) { return ''; }
1.74 www 428: return (<<'ENDSTDBRW');
1.776 bisitz 429: <script type="text/javascript" language="Javascript">
1.824 bisitz 430: // <![CDATA[
1.74 www 431: var stdeditbrowser;
1.999 www 432: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 433: var url = '/adm/pickstudent?';
434: var filter;
1.558 albertel 435: if (!ignorefilter) {
436: eval('filter=document.'+formname+'.'+uname+'.value;');
437: }
1.74 www 438: if (filter != null) {
439: if (filter != '') {
440: url += 'filter='+filter+'&';
441: }
442: }
443: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 444: '&udomelement='+udom+
445: '&clicker='+clicker;
1.111 www 446: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 447: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 448: var title = 'Student_Browser';
1.74 www 449: var options = 'scrollbars=1,resizable=1,menubar=0';
450: options += ',width=700,height=600';
451: stdeditbrowser = open(url,title,options,'1');
452: stdeditbrowser.focus();
453: }
1.824 bisitz 454: // ]]>
1.74 www 455: </script>
456: ENDSTDBRW
457: }
1.42 matthew 458:
1.1003 www 459: sub resourcebrowser_javascript {
460: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 461: return (<<'ENDRESBRW');
1.1003 www 462: <script type="text/javascript" language="Javascript">
463: // <![CDATA[
464: var reseditbrowser;
1.1004 www 465: function openresbrowser(formname,reslink) {
1.1005 www 466: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 467: var title = 'Resource_Browser';
468: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 469: options += ',width=700,height=500';
1.1004 www 470: reseditbrowser = open(url,title,options,'1');
471: reseditbrowser.focus();
1.1003 www 472: }
473: // ]]>
474: </script>
1.1004 www 475: ENDRESBRW
1.1003 www 476: }
477:
1.74 www 478: sub selectstudent_link {
1.999 www 479: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
480: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
481: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
482: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 483: if ($env{'request.course.id'}) {
1.302 albertel 484: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
485: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
486: '/'.$env{'request.course.sec'})) {
1.111 www 487: return '';
488: }
1.999 www 489: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 490: if ($courseadvonly) {
491: $callargs .= ",'',1,1";
492: }
493: return '<span class="LC_nobreak">'.
494: '<a href="javascript:openstdbrowser('.$callargs.');">'.
495: &mt('Select User').'</a></span>';
1.74 www 496: }
1.258 albertel 497: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 498: $callargs .= ",'',1";
1.793 raeburn 499: return '<span class="LC_nobreak">'.
500: '<a href="javascript:openstdbrowser('.$callargs.');">'.
501: &mt('Select User').'</a></span>';
1.111 www 502: }
503: return '';
1.91 www 504: }
505:
1.1004 www 506: sub selectresource_link {
507: my ($form,$reslink,$arg)=@_;
508:
509: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
510: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
511: unless ($env{'request.course.id'}) { return $arg; }
512: return '<span class="LC_nobreak">'.
513: '<a href="javascript:openresbrowser('.$callargs.');">'.
514: $arg.'</a></span>';
515: }
516:
517:
518:
1.653 raeburn 519: sub authorbrowser_javascript {
520: return <<"ENDAUTHORBRW";
1.776 bisitz 521: <script type="text/javascript" language="JavaScript">
1.824 bisitz 522: // <![CDATA[
1.653 raeburn 523: var stdeditbrowser;
524:
525: function openauthorbrowser(formname,udom) {
526: var url = '/adm/pickauthor?';
527: url += 'form='+formname+'&roledom='+udom;
528: var title = 'Author_Browser';
529: var options = 'scrollbars=1,resizable=1,menubar=0';
530: options += ',width=700,height=600';
531: stdeditbrowser = open(url,title,options,'1');
532: stdeditbrowser.focus();
533: }
534:
1.824 bisitz 535: // ]]>
1.653 raeburn 536: </script>
537: ENDAUTHORBRW
538: }
539:
1.91 www 540: sub coursebrowser_javascript {
1.1075.2.31 raeburn 541: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 542: $credits_element,$instcode) = @_;
1.932 raeburn 543: my $wintitle = 'Course_Browser';
1.931 raeburn 544: if ($crstype eq 'Community') {
1.932 raeburn 545: $wintitle = 'Community_Browser';
1.909 raeburn 546: }
1.876 raeburn 547: my $id_functions = &javascript_index_functions();
548: my $output = '
1.776 bisitz 549: <script type="text/javascript" language="JavaScript">
1.824 bisitz 550: // <![CDATA[
1.468 raeburn 551: var stdeditbrowser;'."\n";
1.876 raeburn 552:
553: $output .= <<"ENDSTDBRW";
1.909 raeburn 554: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 555: var url = '/adm/pickcourse?';
1.895 raeburn 556: var formid = getFormIdByName(formname);
1.876 raeburn 557: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 558: if (domainfilter != null) {
559: if (domainfilter != '') {
560: url += 'domainfilter='+domainfilter+'&';
561: }
562: }
1.91 www 563: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 564: '&cdomelement='+udom+
565: '&cnameelement='+desc;
1.468 raeburn 566: if (extra_element !=null && extra_element != '') {
1.594 raeburn 567: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 568: url += '&roleelement='+extra_element;
569: if (domainfilter == null || domainfilter == '') {
570: url += '&domainfilter='+extra_element;
571: }
1.234 raeburn 572: }
1.468 raeburn 573: else {
574: if (formname == 'portform') {
575: url += '&setroles='+extra_element;
1.800 raeburn 576: } else {
577: if (formname == 'rules') {
578: url += '&fixeddom='+extra_element;
579: }
1.468 raeburn 580: }
581: }
1.230 raeburn 582: }
1.909 raeburn 583: if (type != null && type != '') {
584: url += '&type='+type;
585: }
586: if (type_elem != null && type_elem != '') {
587: url += '&typeelement='+type_elem;
588: }
1.872 raeburn 589: if (formname == 'ccrs') {
590: var ownername = document.forms[formid].ccuname.value;
591: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 592: url += '&cloner='+ownername+':'+ownerdom;
593: if (type == 'Course') {
594: url += '&crscode='+document.forms[formid].crscode.value;
595: }
1.1075.2.95 raeburn 596: }
597: if (formname == 'requestcrs') {
598: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 599: }
1.293 raeburn 600: if (multflag !=null && multflag != '') {
601: url += '&multiple='+multflag;
602: }
1.909 raeburn 603: var title = '$wintitle';
1.91 www 604: var options = 'scrollbars=1,resizable=1,menubar=0';
605: options += ',width=700,height=600';
606: stdeditbrowser = open(url,title,options,'1');
607: stdeditbrowser.focus();
608: }
1.876 raeburn 609: $id_functions
610: ENDSTDBRW
1.1075.2.31 raeburn 611: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
612: $output .= &setsec_javascript($sec_element,$formname,$role_element,
613: $credits_element);
1.876 raeburn 614: }
615: $output .= '
616: // ]]>
617: </script>';
618: return $output;
619: }
620:
621: sub javascript_index_functions {
622: return <<"ENDJS";
623:
624: function getFormIdByName(formname) {
625: for (var i=0;i<document.forms.length;i++) {
626: if (document.forms[i].name == formname) {
627: return i;
628: }
629: }
630: return -1;
631: }
632:
633: function getIndexByName(formid,item) {
634: for (var i=0;i<document.forms[formid].elements.length;i++) {
635: if (document.forms[formid].elements[i].name == item) {
636: return i;
637: }
638: }
639: return -1;
640: }
1.468 raeburn 641:
1.876 raeburn 642: function getDomainFromSelectbox(formname,udom) {
643: var userdom;
644: var formid = getFormIdByName(formname);
645: if (formid > -1) {
646: var domid = getIndexByName(formid,udom);
647: if (domid > -1) {
648: if (document.forms[formid].elements[domid].type == 'select-one') {
649: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
650: }
651: if (document.forms[formid].elements[domid].type == 'hidden') {
652: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 653: }
654: }
655: }
1.876 raeburn 656: return userdom;
657: }
658:
659: ENDJS
1.468 raeburn 660:
1.876 raeburn 661: }
662:
1.1017 raeburn 663: sub javascript_array_indexof {
1.1018 raeburn 664: return <<ENDJS;
1.1017 raeburn 665: <script type="text/javascript" language="JavaScript">
666: // <![CDATA[
667:
668: if (!Array.prototype.indexOf) {
669: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
670: "use strict";
671: if (this === void 0 || this === null) {
672: throw new TypeError();
673: }
674: var t = Object(this);
675: var len = t.length >>> 0;
676: if (len === 0) {
677: return -1;
678: }
679: var n = 0;
680: if (arguments.length > 0) {
681: n = Number(arguments[1]);
682: if (n !== n) { // shortcut for verifying if it's NaN
683: n = 0;
684: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
685: n = (n > 0 || -1) * Math.floor(Math.abs(n));
686: }
687: }
688: if (n >= len) {
689: return -1;
690: }
691: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
692: for (; k < len; k++) {
693: if (k in t && t[k] === searchElement) {
694: return k;
695: }
696: }
697: return -1;
698: }
699: }
700:
701: // ]]>
702: </script>
703:
704: ENDJS
705:
706: }
707:
1.876 raeburn 708: sub userbrowser_javascript {
709: my $id_functions = &javascript_index_functions();
710: return <<"ENDUSERBRW";
711:
1.888 raeburn 712: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 713: var url = '/adm/pickuser?';
714: var userdom = getDomainFromSelectbox(formname,udom);
715: if (userdom != null) {
716: if (userdom != '') {
717: url += 'srchdom='+userdom+'&';
718: }
719: }
720: url += 'form=' + formname + '&unameelement='+uname+
721: '&udomelement='+udom+
722: '&ulastelement='+ulast+
723: '&ufirstelement='+ufirst+
724: '&uemailelement='+uemail+
1.881 raeburn 725: '&hideudomelement='+hideudom+
726: '&coursedom='+crsdom;
1.888 raeburn 727: if ((caller != null) && (caller != undefined)) {
728: url += '&caller='+caller;
729: }
1.876 raeburn 730: var title = 'User_Browser';
731: var options = 'scrollbars=1,resizable=1,menubar=0';
732: options += ',width=700,height=600';
733: var stdeditbrowser = open(url,title,options,'1');
734: stdeditbrowser.focus();
735: }
736:
1.888 raeburn 737: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 738: var formid = getFormIdByName(formname);
739: if (formid > -1) {
1.888 raeburn 740: var unameid = getIndexByName(formid,uname);
1.876 raeburn 741: var domid = getIndexByName(formid,udom);
742: var hidedomid = getIndexByName(formid,origdom);
743: if (hidedomid > -1) {
744: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 745: var unameval = document.forms[formid].elements[unameid].value;
746: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
747: if (domid > -1) {
748: var slct = document.forms[formid].elements[domid];
749: if (slct.type == 'select-one') {
750: var i;
751: for (i=0;i<slct.length;i++) {
752: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
753: }
754: }
755: if (slct.type == 'hidden') {
756: slct.value = fixeddom;
1.876 raeburn 757: }
758: }
1.468 raeburn 759: }
760: }
761: }
1.876 raeburn 762: return;
763: }
764:
765: $id_functions
766: ENDUSERBRW
1.468 raeburn 767: }
768:
769: sub setsec_javascript {
1.1075.2.31 raeburn 770: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 771: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
772: $communityrolestr);
773: if ($role_element ne '') {
774: my @allroles = ('st','ta','ep','in','ad');
775: foreach my $crstype ('Course','Community') {
776: if ($crstype eq 'Community') {
777: foreach my $role (@allroles) {
778: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
779: }
780: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
781: } else {
782: foreach my $role (@allroles) {
783: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
784: }
785: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
786: }
787: }
788: $rolestr = '"'.join('","',@allroles).'"';
789: $courserolestr = '"'.join('","',@courserolenames).'"';
790: $communityrolestr = '"'.join('","',@communityrolenames).'"';
791: }
1.468 raeburn 792: my $setsections = qq|
793: function setSect(sectionlist) {
1.629 raeburn 794: var sectionsArray = new Array();
795: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
796: sectionsArray = sectionlist.split(",");
797: }
1.468 raeburn 798: var numSections = sectionsArray.length;
799: document.$formname.$sec_element.length = 0;
800: if (numSections == 0) {
801: document.$formname.$sec_element.multiple=false;
802: document.$formname.$sec_element.size=1;
803: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
804: } else {
805: if (numSections == 1) {
806: document.$formname.$sec_element.multiple=false;
807: document.$formname.$sec_element.size=1;
808: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
809: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
810: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
811: } else {
812: for (var i=0; i<numSections; i++) {
813: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
814: }
815: document.$formname.$sec_element.multiple=true
816: if (numSections < 3) {
817: document.$formname.$sec_element.size=numSections;
818: } else {
819: document.$formname.$sec_element.size=3;
820: }
821: document.$formname.$sec_element.options[0].selected = false
822: }
823: }
1.91 www 824: }
1.905 raeburn 825:
826: function setRole(crstype) {
1.468 raeburn 827: |;
1.905 raeburn 828: if ($role_element eq '') {
829: $setsections .= ' return;
830: }
831: ';
832: } else {
833: $setsections .= qq|
834: var elementLength = document.$formname.$role_element.length;
835: var allroles = Array($rolestr);
836: var courserolenames = Array($courserolestr);
837: var communityrolenames = Array($communityrolestr);
838: if (elementLength != undefined) {
839: if (document.$formname.$role_element.options[5].value == 'cc') {
840: if (crstype == 'Course') {
841: return;
842: } else {
843: allroles[5] = 'co';
844: for (var i=0; i<6; i++) {
845: document.$formname.$role_element.options[i].value = allroles[i];
846: document.$formname.$role_element.options[i].text = communityrolenames[i];
847: }
848: }
849: } else {
850: if (crstype == 'Community') {
851: return;
852: } else {
853: allroles[5] = 'cc';
854: for (var i=0; i<6; i++) {
855: document.$formname.$role_element.options[i].value = allroles[i];
856: document.$formname.$role_element.options[i].text = courserolenames[i];
857: }
858: }
859: }
860: }
861: return;
862: }
863: |;
864: }
1.1075.2.31 raeburn 865: if ($credits_element) {
866: $setsections .= qq|
867: function setCredits(defaultcredits) {
868: document.$formname.$credits_element.value = defaultcredits;
869: return;
870: }
871: |;
872: }
1.468 raeburn 873: return $setsections;
874: }
875:
1.91 www 876: sub selectcourse_link {
1.909 raeburn 877: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
878: $typeelement) = @_;
879: my $type = $selecttype;
1.871 raeburn 880: my $linktext = &mt('Select Course');
881: if ($selecttype eq 'Community') {
1.909 raeburn 882: $linktext = &mt('Select Community');
1.906 raeburn 883: } elsif ($selecttype eq 'Course/Community') {
884: $linktext = &mt('Select Course/Community');
1.909 raeburn 885: $type = '';
1.1019 raeburn 886: } elsif ($selecttype eq 'Select') {
887: $linktext = &mt('Select');
888: $type = '';
1.871 raeburn 889: }
1.787 bisitz 890: return '<span class="LC_nobreak">'
891: ."<a href='"
892: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
893: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 894: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 895: ."'>".$linktext.'</a>'
1.787 bisitz 896: .'</span>';
1.74 www 897: }
1.42 matthew 898:
1.653 raeburn 899: sub selectauthor_link {
900: my ($form,$udom)=@_;
901: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
902: &mt('Select Author').'</a>';
903: }
904:
1.876 raeburn 905: sub selectuser_link {
1.881 raeburn 906: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 907: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 908: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 909: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 910: ');">'.$linktext.'</a>';
1.876 raeburn 911: }
912:
1.273 raeburn 913: sub check_uncheck_jscript {
914: my $jscript = <<"ENDSCRT";
915: function checkAll(field) {
916: if (field.length > 0) {
917: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 918: if (!field[i].disabled) {
919: field[i].checked = true;
920: }
1.273 raeburn 921: }
922: } else {
1.1075.2.14 raeburn 923: if (!field.disabled) {
924: field.checked = true;
925: }
1.273 raeburn 926: }
927: }
928:
929: function uncheckAll(field) {
930: if (field.length > 0) {
931: for (i = 0; i < field.length; i++) {
932: field[i].checked = false ;
1.543 albertel 933: }
934: } else {
1.273 raeburn 935: field.checked = false ;
936: }
937: }
938: ENDSCRT
939: return $jscript;
940: }
941:
1.656 www 942: sub select_timezone {
1.1075.2.115 raeburn 943: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
944: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 945: if ($includeempty) {
946: $output .= '<option value=""';
947: if (($selected eq '') || ($selected eq 'local')) {
948: $output .= ' selected="selected" ';
949: }
950: $output .= '> </option>';
951: }
1.657 raeburn 952: my @timezones = DateTime::TimeZone->all_names;
953: foreach my $tzone (@timezones) {
954: $output.= '<option value="'.$tzone.'"';
955: if ($tzone eq $selected) {
956: $output.=' selected="selected"';
957: }
958: $output.=">$tzone</option>\n";
1.656 www 959: }
960: $output.="</select>";
961: return $output;
962: }
1.273 raeburn 963:
1.687 raeburn 964: sub select_datelocale {
1.1075.2.115 raeburn 965: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
966: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 967: if ($includeempty) {
968: $output .= '<option value=""';
969: if ($selected eq '') {
970: $output .= ' selected="selected" ';
971: }
972: $output .= '> </option>';
973: }
1.1075.2.102 raeburn 974: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 975: my (@possibles,%locale_names);
1.1075.2.102 raeburn 976: my @locales = DateTime::Locale->ids();
977: foreach my $id (@locales) {
978: if ($id ne '') {
979: my ($en_terr,$native_terr);
980: my $loc = DateTime::Locale->load($id);
981: if (ref($loc)) {
982: $en_terr = $loc->name();
983: $native_terr = $loc->native_name();
1.687 raeburn 984: if (grep(/^en$/,@languages) || !@languages) {
985: if ($en_terr ne '') {
986: $locale_names{$id} = '('.$en_terr.')';
987: } elsif ($native_terr ne '') {
988: $locale_names{$id} = $native_terr;
989: }
990: } else {
991: if ($native_terr ne '') {
992: $locale_names{$id} = $native_terr.' ';
993: } elsif ($en_terr ne '') {
994: $locale_names{$id} = '('.$en_terr.')';
995: }
996: }
1.1075.2.94 raeburn 997: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 998: push(@possibles,$id);
1.687 raeburn 999: }
1000: }
1001: }
1002: foreach my $item (sort(@possibles)) {
1003: $output.= '<option value="'.$item.'"';
1004: if ($item eq $selected) {
1005: $output.=' selected="selected"';
1006: }
1007: $output.=">$item";
1008: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1009: $output.=' '.$locale_names{$item};
1.687 raeburn 1010: }
1011: $output.="</option>\n";
1012: }
1013: $output.="</select>";
1014: return $output;
1015: }
1016:
1.792 raeburn 1017: sub select_language {
1.1075.2.115 raeburn 1018: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1019: my %langchoices;
1020: if ($includeempty) {
1.1075.2.32 raeburn 1021: %langchoices = ('' => 'No language preference');
1.792 raeburn 1022: }
1023: foreach my $id (&languageids()) {
1024: my $code = &supportedlanguagecode($id);
1025: if ($code) {
1026: $langchoices{$code} = &plainlanguagedescription($id);
1027: }
1028: }
1.1075.2.32 raeburn 1029: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1030: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1031: }
1032:
1.42 matthew 1033: =pod
1.36 matthew 1034:
1.648 raeburn 1035: =item * &linked_select_forms(...)
1.36 matthew 1036:
1037: linked_select_forms returns a string containing a <script></script> block
1038: and html for two <select> menus. The select menus will be linked in that
1039: changing the value of the first menu will result in new values being placed
1040: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1041: order unless a defined order is provided.
1.36 matthew 1042:
1043: linked_select_forms takes the following ordered inputs:
1044:
1045: =over 4
1046:
1.112 bowersj2 1047: =item * $formname, the name of the <form> tag
1.36 matthew 1048:
1.112 bowersj2 1049: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1050:
1.112 bowersj2 1051: =item * $firstdefault, the default value for the first menu
1.36 matthew 1052:
1.112 bowersj2 1053: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1054:
1.112 bowersj2 1055: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1056:
1.112 bowersj2 1057: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1058:
1.609 raeburn 1059: =item * $menuorder, the order of values in the first menu
1060:
1.1075.2.31 raeburn 1061: =item * $onchangefirst, additional javascript call to execute for an onchange
1062: event for the first <select> tag
1063:
1064: =item * $onchangesecond, additional javascript call to execute for an onchange
1065: event for the second <select> tag
1066:
1.41 ng 1067: =back
1068:
1.36 matthew 1069: Below is an example of such a hash. Only the 'text', 'default', and
1070: 'select2' keys must appear as stated. keys(%menu) are the possible
1071: values for the first select menu. The text that coincides with the
1.41 ng 1072: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1073: and text for the second menu are given in the hash pointed to by
1074: $menu{$choice1}->{'select2'}.
1075:
1.112 bowersj2 1076: my %menu = ( A1 => { text =>"Choice A1" ,
1077: default => "B3",
1078: select2 => {
1079: B1 => "Choice B1",
1080: B2 => "Choice B2",
1081: B3 => "Choice B3",
1082: B4 => "Choice B4"
1.609 raeburn 1083: },
1084: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1085: },
1086: A2 => { text =>"Choice A2" ,
1087: default => "C2",
1088: select2 => {
1089: C1 => "Choice C1",
1090: C2 => "Choice C2",
1091: C3 => "Choice C3"
1.609 raeburn 1092: },
1093: order => ['C2','C1','C3'],
1.112 bowersj2 1094: },
1095: A3 => { text =>"Choice A3" ,
1096: default => "D6",
1097: select2 => {
1098: D1 => "Choice D1",
1099: D2 => "Choice D2",
1100: D3 => "Choice D3",
1101: D4 => "Choice D4",
1102: D5 => "Choice D5",
1103: D6 => "Choice D6",
1104: D7 => "Choice D7"
1.609 raeburn 1105: },
1106: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1107: }
1108: );
1.36 matthew 1109:
1110: =cut
1111:
1112: sub linked_select_forms {
1113: my ($formname,
1114: $middletext,
1115: $firstdefault,
1116: $firstselectname,
1117: $secondselectname,
1.609 raeburn 1118: $hashref,
1119: $menuorder,
1.1075.2.31 raeburn 1120: $onchangefirst,
1121: $onchangesecond
1.36 matthew 1122: ) = @_;
1123: my $second = "document.$formname.$secondselectname";
1124: my $first = "document.$formname.$firstselectname";
1125: # output the javascript to do the changing
1126: my $result = '';
1.776 bisitz 1127: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1128: $result.="// <![CDATA[\n";
1.36 matthew 1129: $result.="var select2data = new Object();\n";
1130: $" = '","';
1131: my $debug = '';
1132: foreach my $s1 (sort(keys(%$hashref))) {
1133: $result.="select2data.d_$s1 = new Object();\n";
1134: $result.="select2data.d_$s1.def = new String('".
1135: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1136: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1137: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1138: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1139: @s2values = @{$hashref->{$s1}->{'order'}};
1140: }
1.36 matthew 1141: $result.="\"@s2values\");\n";
1142: $result.="select2data.d_$s1.texts = new Array(";
1143: my @s2texts;
1144: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1145: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1146: }
1147: $result.="\"@s2texts\");\n";
1148: }
1149: $"=' ';
1150: $result.= <<"END";
1151:
1152: function select1_changed() {
1153: // Determine new choice
1154: var newvalue = "d_" + $first.value;
1155: // update select2
1156: var values = select2data[newvalue].values;
1157: var texts = select2data[newvalue].texts;
1158: var select2def = select2data[newvalue].def;
1159: var i;
1160: // out with the old
1161: for (i = 0; i < $second.options.length; i++) {
1162: $second.options[i] = null;
1163: }
1164: // in with the nuclear
1165: for (i=0;i<values.length; i++) {
1166: $second.options[i] = new Option(values[i]);
1.143 matthew 1167: $second.options[i].value = values[i];
1.36 matthew 1168: $second.options[i].text = texts[i];
1169: if (values[i] == select2def) {
1170: $second.options[i].selected = true;
1171: }
1172: }
1173: }
1.824 bisitz 1174: // ]]>
1.36 matthew 1175: </script>
1176: END
1177: # output the initial values for the selection lists
1.1075.2.31 raeburn 1178: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1179: my @order = sort(keys(%{$hashref}));
1180: if (ref($menuorder) eq 'ARRAY') {
1181: @order = @{$menuorder};
1182: }
1183: foreach my $value (@order) {
1.36 matthew 1184: $result.=" <option value=\"$value\" ";
1.253 albertel 1185: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1186: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1187: }
1188: $result .= "</select>\n";
1189: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1190: $result .= $middletext;
1.1075.2.31 raeburn 1191: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1192: if ($onchangesecond) {
1193: $result .= ' onchange="'.$onchangesecond.'"';
1194: }
1195: $result .= ">\n";
1.36 matthew 1196: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1197:
1198: my @secondorder = sort(keys(%select2));
1199: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1200: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1201: }
1202: foreach my $value (@secondorder) {
1.36 matthew 1203: $result.=" <option value=\"$value\" ";
1.253 albertel 1204: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1205: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1206: }
1207: $result .= "</select>\n";
1208: # return $debug;
1209: return $result;
1210: } # end of sub linked_select_forms {
1211:
1.45 matthew 1212: =pod
1.44 bowersj2 1213:
1.973 raeburn 1214: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1215:
1.112 bowersj2 1216: Returns a string corresponding to an HTML link to the given help
1217: $topic, where $topic corresponds to the name of a .tex file in
1218: /home/httpd/html/adm/help/tex, with underscores replaced by
1219: spaces.
1220:
1221: $text will optionally be linked to the same topic, allowing you to
1222: link text in addition to the graphic. If you do not want to link
1223: text, but wish to specify one of the later parameters, pass an
1224: empty string.
1225:
1226: $stayOnPage is a value that will be interpreted as a boolean. If true,
1227: the link will not open a new window. If false, the link will open
1228: a new window using Javascript. (Default is false.)
1229:
1230: $width and $height are optional numerical parameters that will
1231: override the width and height of the popped up window, which may
1.973 raeburn 1232: be useful for certain help topics with big pictures included.
1233:
1234: $imgid is the id of the img tag used for the help icon. This may be
1235: used in a javascript call to switch the image src. See
1236: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1237:
1238: =cut
1239:
1240: sub help_open_topic {
1.973 raeburn 1241: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1242: $text = "" if (not defined $text);
1.44 bowersj2 1243: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1244: $width = 500 if (not defined $width);
1.44 bowersj2 1245: $height = 400 if (not defined $height);
1246: my $filename = $topic;
1247: $filename =~ s/ /_/g;
1248:
1.48 bowersj2 1249: my $template = "";
1250: my $link;
1.572 banghart 1251:
1.159 www 1252: $topic=~s/\W/\_/g;
1.44 bowersj2 1253:
1.572 banghart 1254: if (!$stayOnPage) {
1.1075.2.50 raeburn 1255: if ($env{'browser.mobile'}) {
1256: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1257: } else {
1258: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1259: }
1.1037 www 1260: } elsif ($stayOnPage eq 'popup') {
1261: $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 1262: } else {
1.48 bowersj2 1263: $link = "/adm/help/${filename}.hlp";
1264: }
1265:
1266: # Add the text
1.755 neumanie 1267: if ($text ne "") {
1.763 bisitz 1268: $template.='<span class="LC_help_open_topic">'
1269: .'<a target="_top" href="'.$link.'">'
1270: .$text.'</a>';
1.48 bowersj2 1271: }
1272:
1.763 bisitz 1273: # (Always) Add the graphic
1.179 matthew 1274: my $title = &mt('Online Help');
1.667 raeburn 1275: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1276: if ($imgid ne '') {
1277: $imgid = ' id="'.$imgid.'"';
1278: }
1.763 bisitz 1279: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1280: .'<img src="'.$helpicon.'" border="0"'
1281: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1282: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1283: .' /></a>';
1284: if ($text ne "") {
1285: $template.='</span>';
1286: }
1.44 bowersj2 1287: return $template;
1288:
1.106 bowersj2 1289: }
1290:
1291: # This is a quicky function for Latex cheatsheet editing, since it
1292: # appears in at least four places
1293: sub helpLatexCheatsheet {
1.1037 www 1294: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1295: my $out;
1.106 bowersj2 1296: my $addOther = '';
1.732 raeburn 1297: if ($topic) {
1.1037 www 1298: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1299: }
1300: $out = '<span>' # Start cheatsheet
1301: .$addOther
1302: .'<span>'
1.1037 www 1303: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1304: .'</span> <span>'
1.1037 www 1305: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1306: .'</span>';
1.732 raeburn 1307: unless ($not_author) {
1.763 bisitz 1308: $out .= ' <span>'
1.1037 www 1309: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1310: .'</span> <span>'
1.1075.2.78 raeburn 1311: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1312: .'</span>';
1.732 raeburn 1313: }
1.763 bisitz 1314: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1315: return $out;
1.172 www 1316: }
1317:
1.430 albertel 1318: sub general_help {
1319: my $helptopic='Student_Intro';
1320: if ($env{'request.role'}=~/^(ca|au)/) {
1321: $helptopic='Authoring_Intro';
1.907 raeburn 1322: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1323: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1324: } elsif ($env{'request.role'}=~/^dc/) {
1325: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1326: }
1327: return $helptopic;
1328: }
1329:
1330: sub update_help_link {
1331: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1332: my $origurl = $ENV{'REQUEST_URI'};
1333: $origurl=~s|^/~|/priv/|;
1334: my $timestamp = time;
1335: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1336: $$datum = &escape($$datum);
1337: }
1338:
1339: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1340: my $output .= <<"ENDOUTPUT";
1341: <script type="text/javascript">
1.824 bisitz 1342: // <![CDATA[
1.430 albertel 1343: banner_link = '$banner_link';
1.824 bisitz 1344: // ]]>
1.430 albertel 1345: </script>
1346: ENDOUTPUT
1347: return $output;
1348: }
1349:
1350: # now just updates the help link and generates a blue icon
1.193 raeburn 1351: sub help_open_menu {
1.430 albertel 1352: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1353: = @_;
1.949 droeschl 1354: $stayOnPage = 1;
1.430 albertel 1355: my $output;
1356: if ($component_help) {
1357: if (!$text) {
1358: $output=&help_open_topic($component_help,undef,$stayOnPage,
1359: $width,$height);
1360: } else {
1361: my $help_text;
1362: $help_text=&unescape($topic);
1363: $output='<table><tr><td>'.
1364: &help_open_topic($component_help,$help_text,$stayOnPage,
1365: $width,$height).'</td></tr></table>';
1366: }
1367: }
1368: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1369: return $output.$banner_link;
1370: }
1371:
1372: sub top_nav_help {
1373: my ($text) = @_;
1.436 albertel 1374: $text = &mt($text);
1.1075.2.60 raeburn 1375: my $stay_on_page;
1376: unless ($env{'environment.remote'} eq 'on') {
1377: $stay_on_page = 1;
1378: }
1.1075.2.61 raeburn 1379: my ($link,$banner_link);
1380: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1381: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1382: : "javascript:helpMenu('open')";
1383: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1384: }
1.201 raeburn 1385: my $title = &mt('Get help');
1.1075.2.61 raeburn 1386: if ($link) {
1387: return <<"END";
1.436 albertel 1388: $banner_link
1.1075.2.56 raeburn 1389: <a href="$link" title="$title">$text</a>
1.436 albertel 1390: END
1.1075.2.61 raeburn 1391: } else {
1392: return ' '.$text.' ';
1393: }
1.436 albertel 1394: }
1395:
1396: sub help_menu_js {
1.1075.2.52 raeburn 1397: my ($httphost) = @_;
1.949 droeschl 1398: my $stayOnPage = 1;
1.436 albertel 1399: my $width = 620;
1400: my $height = 600;
1.430 albertel 1401: my $helptopic=&general_help();
1.1075.2.52 raeburn 1402: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1403: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1404: my $start_page =
1405: &Apache::loncommon::start_page('Help Menu', undef,
1406: {'frameset' => 1,
1407: 'js_ready' => 1,
1.1075.2.52 raeburn 1408: 'use_absolute' => $httphost,
1.331 albertel 1409: 'add_entries' => {
1410: 'border' => '0',
1.579 raeburn 1411: 'rows' => "110,*",},});
1.331 albertel 1412: my $end_page =
1413: &Apache::loncommon::end_page({'frameset' => 1,
1414: 'js_ready' => 1,});
1415:
1.436 albertel 1416: my $template .= <<"ENDTEMPLATE";
1417: <script type="text/javascript">
1.877 bisitz 1418: // <![CDATA[
1.253 albertel 1419: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1420: var banner_link = '';
1.243 raeburn 1421: function helpMenu(target) {
1422: var caller = this;
1423: if (target == 'open') {
1424: var newWindow = null;
1425: try {
1.262 albertel 1426: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1427: }
1428: catch(error) {
1429: writeHelp(caller);
1430: return;
1431: }
1432: if (newWindow) {
1433: caller = newWindow;
1434: }
1.193 raeburn 1435: }
1.243 raeburn 1436: writeHelp(caller);
1437: return;
1438: }
1439: function writeHelp(caller) {
1.1075.2.61 raeburn 1440: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1441: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1442: caller.document.close();
1443: caller.focus();
1.193 raeburn 1444: }
1.877 bisitz 1445: // END LON-CAPA Internal -->
1.253 albertel 1446: // ]]>
1.436 albertel 1447: </script>
1.193 raeburn 1448: ENDTEMPLATE
1449: return $template;
1450: }
1451:
1.172 www 1452: sub help_open_bug {
1453: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1454: unless ($env{'user.adv'}) { return ''; }
1.172 www 1455: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1456: $text = "" if (not defined $text);
1457: $stayOnPage=1;
1.184 albertel 1458: $width = 600 if (not defined $width);
1459: $height = 600 if (not defined $height);
1.172 www 1460:
1461: $topic=~s/\W+/\+/g;
1462: my $link='';
1463: my $template='';
1.379 albertel 1464: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1465: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1466: if (!$stayOnPage)
1467: {
1468: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1469: }
1470: else
1471: {
1472: $link = $url;
1473: }
1474: # Add the text
1475: if ($text ne "")
1476: {
1477: $template .=
1478: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1479: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1480: }
1481:
1482: # Add the graphic
1.179 matthew 1483: my $title = &mt('Report a Bug');
1.215 albertel 1484: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1485: $template .= <<"ENDTEMPLATE";
1.436 albertel 1486: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1487: ENDTEMPLATE
1488: if ($text ne '') { $template.='</td></tr></table>' };
1489: return $template;
1490:
1491: }
1492:
1493: sub help_open_faq {
1494: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1495: unless ($env{'user.adv'}) { return ''; }
1.172 www 1496: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1497: $text = "" if (not defined $text);
1498: $stayOnPage=1;
1499: $width = 350 if (not defined $width);
1500: $height = 400 if (not defined $height);
1501:
1502: $topic=~s/\W+/\+/g;
1503: my $link='';
1504: my $template='';
1505: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1506: if (!$stayOnPage)
1507: {
1508: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1509: }
1510: else
1511: {
1512: $link = $url;
1513: }
1514:
1515: # Add the text
1516: if ($text ne "")
1517: {
1518: $template .=
1.173 www 1519: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1520: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1521: }
1522:
1523: # Add the graphic
1.179 matthew 1524: my $title = &mt('View the FAQ');
1.215 albertel 1525: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1526: $template .= <<"ENDTEMPLATE";
1.436 albertel 1527: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1528: ENDTEMPLATE
1529: if ($text ne '') { $template.='</td></tr></table>' };
1530: return $template;
1531:
1.44 bowersj2 1532: }
1.37 matthew 1533:
1.180 matthew 1534: ###############################################################
1535: ###############################################################
1536:
1.45 matthew 1537: =pod
1538:
1.648 raeburn 1539: =item * &change_content_javascript():
1.256 matthew 1540:
1541: This and the next function allow you to create small sections of an
1542: otherwise static HTML page that you can update on the fly with
1543: Javascript, even in Netscape 4.
1544:
1545: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1546: must be written to the HTML page once. It will prove the Javascript
1547: function "change(name, content)". Calling the change function with the
1548: name of the section
1549: you want to update, matching the name passed to C<changable_area>, and
1550: the new content you want to put in there, will put the content into
1551: that area.
1552:
1553: B<Note>: Netscape 4 only reserves enough space for the changable area
1554: to contain room for the original contents. You need to "make space"
1555: for whatever changes you wish to make, and be B<sure> to check your
1556: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1557: it's adequate for updating a one-line status display, but little more.
1558: This script will set the space to 100% width, so you only need to
1559: worry about height in Netscape 4.
1560:
1561: Modern browsers are much less limiting, and if you can commit to the
1562: user not using Netscape 4, this feature may be used freely with
1563: pretty much any HTML.
1564:
1565: =cut
1566:
1567: sub change_content_javascript {
1568: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1569: if ($env{'browser.type'} eq 'netscape' &&
1570: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1571: return (<<NETSCAPE4);
1572: function change(name, content) {
1573: doc = document.layers[name+"___escape"].layers[0].document;
1574: doc.open();
1575: doc.write(content);
1576: doc.close();
1577: }
1578: NETSCAPE4
1579: } else {
1580: # Otherwise, we need to use semi-standards-compliant code
1581: # (technically, "innerHTML" isn't standard but the equivalent
1582: # is really scary, and every useful browser supports it
1583: return (<<DOMBASED);
1584: function change(name, content) {
1585: element = document.getElementById(name);
1586: element.innerHTML = content;
1587: }
1588: DOMBASED
1589: }
1590: }
1591:
1592: =pod
1593:
1.648 raeburn 1594: =item * &changable_area($name,$origContent):
1.256 matthew 1595:
1596: This provides a "changable area" that can be modified on the fly via
1597: the Javascript code provided in C<change_content_javascript>. $name is
1598: the name you will use to reference the area later; do not repeat the
1599: same name on a given HTML page more then once. $origContent is what
1600: the area will originally contain, which can be left blank.
1601:
1602: =cut
1603:
1604: sub changable_area {
1605: my ($name, $origContent) = @_;
1606:
1.258 albertel 1607: if ($env{'browser.type'} eq 'netscape' &&
1608: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1609: # If this is netscape 4, we need to use the Layer tag
1610: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1611: } else {
1612: return "<span id='$name'>$origContent</span>";
1613: }
1614: }
1615:
1616: =pod
1617:
1.648 raeburn 1618: =item * &viewport_geometry_js
1.590 raeburn 1619:
1620: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1621:
1622: =cut
1623:
1624:
1625: sub viewport_geometry_js {
1626: return <<"GEOMETRY";
1627: var Geometry = {};
1628: function init_geometry() {
1629: if (Geometry.init) { return };
1630: Geometry.init=1;
1631: if (window.innerHeight) {
1632: Geometry.getViewportHeight = function() { return window.innerHeight; };
1633: Geometry.getViewportWidth = function() { return window.innerWidth; };
1634: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1635: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1636: }
1637: else if (document.documentElement && document.documentElement.clientHeight) {
1638: Geometry.getViewportHeight =
1639: function() { return document.documentElement.clientHeight; };
1640: Geometry.getViewportWidth =
1641: function() { return document.documentElement.clientWidth; };
1642:
1643: Geometry.getHorizontalScroll =
1644: function() { return document.documentElement.scrollLeft; };
1645: Geometry.getVerticalScroll =
1646: function() { return document.documentElement.scrollTop; };
1647: }
1648: else if (document.body.clientHeight) {
1649: Geometry.getViewportHeight =
1650: function() { return document.body.clientHeight; };
1651: Geometry.getViewportWidth =
1652: function() { return document.body.clientWidth; };
1653: Geometry.getHorizontalScroll =
1654: function() { return document.body.scrollLeft; };
1655: Geometry.getVerticalScroll =
1656: function() { return document.body.scrollTop; };
1657: }
1658: }
1659:
1660: GEOMETRY
1661: }
1662:
1663: =pod
1664:
1.648 raeburn 1665: =item * &viewport_size_js()
1.590 raeburn 1666:
1667: 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.
1668:
1669: =cut
1670:
1671: sub viewport_size_js {
1672: my $geometry = &viewport_geometry_js();
1673: return <<"DIMS";
1674:
1675: $geometry
1676:
1677: function getViewportDims(width,height) {
1678: init_geometry();
1679: width.value = Geometry.getViewportWidth();
1680: height.value = Geometry.getViewportHeight();
1681: return;
1682: }
1683:
1684: DIMS
1685: }
1686:
1687: =pod
1688:
1.648 raeburn 1689: =item * &resize_textarea_js()
1.565 albertel 1690:
1691: emits the needed javascript to resize a textarea to be as big as possible
1692:
1693: creates a function resize_textrea that takes two IDs first should be
1694: the id of the element to resize, second should be the id of a div that
1695: surrounds everything that comes after the textarea, this routine needs
1696: to be attached to the <body> for the onload and onresize events.
1697:
1.648 raeburn 1698: =back
1.565 albertel 1699:
1700: =cut
1701:
1702: sub resize_textarea_js {
1.590 raeburn 1703: my $geometry = &viewport_geometry_js();
1.565 albertel 1704: return <<"RESIZE";
1705: <script type="text/javascript">
1.824 bisitz 1706: // <![CDATA[
1.590 raeburn 1707: $geometry
1.565 albertel 1708:
1.588 albertel 1709: function getX(element) {
1710: var x = 0;
1711: while (element) {
1712: x += element.offsetLeft;
1713: element = element.offsetParent;
1714: }
1715: return x;
1716: }
1717: function getY(element) {
1718: var y = 0;
1719: while (element) {
1720: y += element.offsetTop;
1721: element = element.offsetParent;
1722: }
1723: return y;
1724: }
1725:
1726:
1.565 albertel 1727: function resize_textarea(textarea_id,bottom_id) {
1728: init_geometry();
1729: var textarea = document.getElementById(textarea_id);
1730: //alert(textarea);
1731:
1.588 albertel 1732: var textarea_top = getY(textarea);
1.565 albertel 1733: var textarea_height = textarea.offsetHeight;
1734: var bottom = document.getElementById(bottom_id);
1.588 albertel 1735: var bottom_top = getY(bottom);
1.565 albertel 1736: var bottom_height = bottom.offsetHeight;
1737: var window_height = Geometry.getViewportHeight();
1.588 albertel 1738: var fudge = 23;
1.565 albertel 1739: var new_height = window_height-fudge-textarea_top-bottom_height;
1740: if (new_height < 300) {
1741: new_height = 300;
1742: }
1743: textarea.style.height=new_height+'px';
1744: }
1.824 bisitz 1745: // ]]>
1.565 albertel 1746: </script>
1747: RESIZE
1748:
1749: }
1750:
1.1075.2.112 raeburn 1751: sub colorfuleditor_js {
1752: return <<"COLORFULEDIT"
1753: <script type="text/javascript">
1754: // <![CDATA[>
1755: function fold_box(curDepth, lastresource){
1756:
1757: // we need a list because there can be several blocks you need to fold in one tag
1758: var block = document.getElementsByName('foldblock_'+curDepth);
1759: // but there is only one folding button per tag
1760: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1761:
1762: if(block.item(0).style.display == 'none'){
1763:
1764: foldbutton.value = '@{[&mt("Hide")]}';
1765: for (i = 0; i < block.length; i++){
1766: block.item(i).style.display = '';
1767: }
1768: }else{
1769:
1770: foldbutton.value = '@{[&mt("Show")]}';
1771: for (i = 0; i < block.length; i++){
1772: // block.item(i).style.visibility = 'collapse';
1773: block.item(i).style.display = 'none';
1774: }
1775: };
1776: saveState(lastresource);
1777: }
1778:
1779: function saveState (lastresource) {
1780:
1781: var tag_list = getTagList();
1782: if(tag_list != null){
1783: var timestamp = new Date().getTime();
1784: var key = lastresource;
1785:
1786: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1787: // starting with timestamp
1788: var value = timestamp+';';
1789:
1790: // building the list of key-value pairs
1791: for(var i = 0; i < tag_list.length; i++){
1792: value += tag_list[i]+',';
1793: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1794: }
1795:
1796: // only iterate whole storage if nothing to override
1797: if(localStorage.getItem(key) == null){
1798:
1799: // prevent storage from growing large
1800: if(localStorage.length > 50){
1801: var regex_getTimestamp = /^(?:\d)+;/;
1802: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1803: var oldest_key;
1804:
1805: for(var i = 1; i < localStorage.length; i++){
1806: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1807: oldest_key = localStorage.key(i);
1808: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1809: }
1810: }
1811: localStorage.removeItem(oldest_key);
1812: }
1813: }
1814: localStorage.setItem(key,value);
1815: }
1816: }
1817:
1818: // restore folding status of blocks (on page load)
1819: function restoreState (lastresource) {
1820: if(localStorage.getItem(lastresource) != null){
1821: var key = lastresource;
1822: var value = localStorage.getItem(key);
1823: var regex_delTimestamp = /^\d+;/;
1824:
1825: value.replace(regex_delTimestamp, '');
1826:
1827: var valueArr = value.split(';');
1828: var pairs;
1829: var elements;
1830: for (var i = 0; i < valueArr.length; i++){
1831: pairs = valueArr[i].split(',');
1832: elements = document.getElementsByName(pairs[0]);
1833:
1834: for (var j = 0; j < elements.length; j++){
1835: elements[j].style.display = pairs[1];
1836: if (pairs[1] == "none"){
1837: var regex_id = /([_\\d]+)\$/;
1838: regex_id.exec(pairs[0]);
1839: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1840: }
1841: }
1842: }
1843: }
1844: }
1845:
1846: function getTagList () {
1847:
1848: var stringToSearch = document.lonhomework.innerHTML;
1849:
1850: var ret = new Array();
1851: var regex_findBlock = /(foldblock_.*?)"/g;
1852: var tag_list = stringToSearch.match(regex_findBlock);
1853:
1854: if(tag_list != null){
1855: for(var i = 0; i < tag_list.length; i++){
1856: ret.push(tag_list[i].replace(/"/, ''));
1857: }
1858: }
1859: return ret;
1860: }
1861:
1862: function saveScrollPosition (resource) {
1863: var tag_list = getTagList();
1864:
1865: // we dont always want to jump to the first block
1866: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1867: if(\$(window).scrollTop() > 170){
1868: if(tag_list != null){
1869: var result;
1870: for(var i = 0; i < tag_list.length; i++){
1871: if(isElementInViewport(tag_list[i])){
1872: result += tag_list[i]+';';
1873: }
1874: }
1875: sessionStorage.setItem('anchor_'+resource, result);
1876: }
1877: } else {
1878: // we dont need to save zero, just delete the item to leave everything tidy
1879: sessionStorage.removeItem('anchor_'+resource);
1880: }
1881: }
1882:
1883: function restoreScrollPosition(resource){
1884:
1885: var elem = sessionStorage.getItem('anchor_'+resource);
1886: if(elem != null){
1887: var tag_list = elem.split(';');
1888: var elem_list;
1889:
1890: for(var i = 0; i < tag_list.length; i++){
1891: elem_list = document.getElementsByName(tag_list[i]);
1892:
1893: if(elem_list.length > 0){
1894: elem = elem_list[0];
1895: break;
1896: }
1897: }
1898: elem.scrollIntoView();
1899: }
1900: }
1901:
1902: function isElementInViewport(el) {
1903:
1904: // change to last element instead of first
1905: var elem = document.getElementsByName(el);
1906: var rect = elem[0].getBoundingClientRect();
1907:
1908: return (
1909: rect.top >= 0 &&
1910: rect.left >= 0 &&
1911: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1912: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1913: );
1914: }
1915:
1916: function autosize(depth){
1917: var cmInst = window['cm'+depth];
1918: var fitsizeButton = document.getElementById('fitsize'+depth);
1919:
1920: // is fixed size, switching to dynamic
1921: if (sessionStorage.getItem("autosized_"+depth) == null) {
1922: cmInst.setSize("","auto");
1923: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1924: sessionStorage.setItem("autosized_"+depth, "yes");
1925:
1926: // is dynamic size, switching to fixed
1927: } else {
1928: cmInst.setSize("","300px");
1929: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1930: sessionStorage.removeItem("autosized_"+depth);
1931: }
1932: }
1933:
1934:
1935:
1936: // ]]>
1937: </script>
1938: COLORFULEDIT
1939: }
1940:
1941: sub xmleditor_js {
1942: return <<XMLEDIT
1943: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1944: <script type="text/javascript">
1945: // <![CDATA[>
1946:
1947: function saveScrollPosition (resource) {
1948:
1949: var scrollPos = \$(window).scrollTop();
1950: sessionStorage.setItem(resource,scrollPos);
1951: }
1952:
1953: function restoreScrollPosition(resource){
1954:
1955: var scrollPos = sessionStorage.getItem(resource);
1956: \$(window).scrollTop(scrollPos);
1957: }
1958:
1959: // unless internet explorer
1960: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1961:
1962: \$(document).ready(function() {
1963: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1964: });
1965: }
1966:
1967: // inserts text at cursor position into codemirror (xml editor only)
1968: function insertText(text){
1969: cm.focus();
1970: var curPos = cm.getCursor();
1971: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1972: }
1973: // ]]>
1974: </script>
1975: XMLEDIT
1976: }
1977:
1978: sub insert_folding_button {
1979: my $curDepth = $Apache::lonxml::curdepth;
1980: my $lastresource = $env{'request.ambiguous'};
1981:
1982: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1983: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1984: }
1985:
1986:
1.565 albertel 1987: =pod
1988:
1.256 matthew 1989: =head1 Excel and CSV file utility routines
1990:
1991: =cut
1992:
1993: ###############################################################
1994: ###############################################################
1995:
1996: =pod
1997:
1.1075.2.56 raeburn 1998: =over 4
1999:
1.648 raeburn 2000: =item * &csv_translate($text)
1.37 matthew 2001:
1.185 www 2002: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2003: format.
2004:
2005: =cut
2006:
1.180 matthew 2007: ###############################################################
2008: ###############################################################
1.37 matthew 2009: sub csv_translate {
2010: my $text = shift;
2011: $text =~ s/\"/\"\"/g;
1.209 albertel 2012: $text =~ s/\n/ /g;
1.37 matthew 2013: return $text;
2014: }
1.180 matthew 2015:
2016: ###############################################################
2017: ###############################################################
2018:
2019: =pod
2020:
1.648 raeburn 2021: =item * &define_excel_formats()
1.180 matthew 2022:
2023: Define some commonly used Excel cell formats.
2024:
2025: Currently supported formats:
2026:
2027: =over 4
2028:
2029: =item header
2030:
2031: =item bold
2032:
2033: =item h1
2034:
2035: =item h2
2036:
2037: =item h3
2038:
1.256 matthew 2039: =item h4
2040:
2041: =item i
2042:
1.180 matthew 2043: =item date
2044:
2045: =back
2046:
2047: Inputs: $workbook
2048:
2049: Returns: $format, a hash reference.
2050:
1.1057 foxr 2051:
1.180 matthew 2052: =cut
2053:
2054: ###############################################################
2055: ###############################################################
2056: sub define_excel_formats {
2057: my ($workbook) = @_;
2058: my $format;
2059: $format->{'header'} = $workbook->add_format(bold => 1,
2060: bottom => 1,
2061: align => 'center');
2062: $format->{'bold'} = $workbook->add_format(bold=>1);
2063: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2064: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2065: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2066: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2067: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2068: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2069: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2070: return $format;
2071: }
2072:
2073: ###############################################################
2074: ###############################################################
1.113 bowersj2 2075:
2076: =pod
2077:
1.648 raeburn 2078: =item * &create_workbook()
1.255 matthew 2079:
2080: Create an Excel worksheet. If it fails, output message on the
2081: request object and return undefs.
2082:
2083: Inputs: Apache request object
2084:
2085: Returns (undef) on failure,
2086: Excel worksheet object, scalar with filename, and formats
2087: from &Apache::loncommon::define_excel_formats on success
2088:
2089: =cut
2090:
2091: ###############################################################
2092: ###############################################################
2093: sub create_workbook {
2094: my ($r) = @_;
2095: #
2096: # Create the excel spreadsheet
2097: my $filename = '/prtspool/'.
1.258 albertel 2098: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2099: time.'_'.rand(1000000000).'.xls';
2100: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2101: if (! defined($workbook)) {
2102: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2103: $r->print(
2104: '<p class="LC_error">'
2105: .&mt('Problems occurred in creating the new Excel file.')
2106: .' '.&mt('This error has been logged.')
2107: .' '.&mt('Please alert your LON-CAPA administrator.')
2108: .'</p>'
2109: );
1.255 matthew 2110: return (undef);
2111: }
2112: #
1.1014 foxr 2113: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2114: #
2115: my $format = &Apache::loncommon::define_excel_formats($workbook);
2116: return ($workbook,$filename,$format);
2117: }
2118:
2119: ###############################################################
2120: ###############################################################
2121:
2122: =pod
2123:
1.648 raeburn 2124: =item * &create_text_file()
1.113 bowersj2 2125:
1.542 raeburn 2126: Create a file to write to and eventually make available to the user.
1.256 matthew 2127: If file creation fails, outputs an error message on the request object and
2128: return undefs.
1.113 bowersj2 2129:
1.256 matthew 2130: Inputs: Apache request object, and file suffix
1.113 bowersj2 2131:
1.256 matthew 2132: Returns (undef) on failure,
2133: Filehandle and filename on success.
1.113 bowersj2 2134:
2135: =cut
2136:
1.256 matthew 2137: ###############################################################
2138: ###############################################################
2139: sub create_text_file {
2140: my ($r,$suffix) = @_;
2141: if (! defined($suffix)) { $suffix = 'txt'; };
2142: my $fh;
2143: my $filename = '/prtspool/'.
1.258 albertel 2144: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2145: time.'_'.rand(1000000000).'.'.$suffix;
2146: $fh = Apache::File->new('>/home/httpd'.$filename);
2147: if (! defined($fh)) {
2148: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2149: $r->print(
2150: '<p class="LC_error">'
2151: .&mt('Problems occurred in creating the output file.')
2152: .' '.&mt('This error has been logged.')
2153: .' '.&mt('Please alert your LON-CAPA administrator.')
2154: .'</p>'
2155: );
1.113 bowersj2 2156: }
1.256 matthew 2157: return ($fh,$filename)
1.113 bowersj2 2158: }
2159:
2160:
1.256 matthew 2161: =pod
1.113 bowersj2 2162:
2163: =back
2164:
2165: =cut
1.37 matthew 2166:
2167: ###############################################################
1.33 matthew 2168: ## Home server <option> list generating code ##
2169: ###############################################################
1.35 matthew 2170:
1.169 www 2171: # ------------------------------------------
2172:
2173: sub domain_select {
2174: my ($name,$value,$multiple)=@_;
2175: my %domains=map {
1.514 albertel 2176: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2177: } &Apache::lonnet::all_domains();
1.169 www 2178: if ($multiple) {
2179: $domains{''}=&mt('Any domain');
1.550 albertel 2180: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2181: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2182: } else {
1.550 albertel 2183: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2184: return &select_form($name,$value,\%domains);
1.169 www 2185: }
2186: }
2187:
1.282 albertel 2188: #-------------------------------------------
2189:
2190: =pod
2191:
1.519 raeburn 2192: =head1 Routines for form select boxes
2193:
2194: =over 4
2195:
1.648 raeburn 2196: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2197:
2198: Returns a string containing a <select> element int multiple mode
2199:
2200:
2201: Args:
2202: $name - name of the <select> element
1.506 raeburn 2203: $value - scalar or array ref of values that should already be selected
1.282 albertel 2204: $size - number of rows long the select element is
1.283 albertel 2205: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2206: (shown text should already have been &mt())
1.506 raeburn 2207: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2208:
1.282 albertel 2209: =cut
2210:
2211: #-------------------------------------------
1.169 www 2212: sub multiple_select_form {
1.284 albertel 2213: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2214: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2215: my $output='';
1.191 matthew 2216: if (! defined($size)) {
2217: $size = 4;
1.283 albertel 2218: if (scalar(keys(%$hash))<4) {
2219: $size = scalar(keys(%$hash));
1.191 matthew 2220: }
2221: }
1.734 bisitz 2222: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2223: my @order;
1.506 raeburn 2224: if (ref($order) eq 'ARRAY') {
2225: @order = @{$order};
2226: } else {
2227: @order = sort(keys(%$hash));
1.501 banghart 2228: }
2229: if (exists($$hash{'select_form_order'})) {
2230: @order = @{$$hash{'select_form_order'}};
2231: }
2232:
1.284 albertel 2233: foreach my $key (@order) {
1.356 albertel 2234: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2235: $output.='selected="selected" ' if ($selected{$key});
2236: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2237: }
2238: $output.="</select>\n";
2239: return $output;
2240: }
2241:
1.88 www 2242: #-------------------------------------------
2243:
2244: =pod
2245:
1.1075.2.115 raeburn 2246: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2247:
2248: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2249: allow a user to select options from a ref to a hash containing:
2250: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2251: a javascript onchange item, e.g., onchange="this.form.submit();".
2252: An optional arg -- $readonly -- if true will cause the select form
2253: to be disabled, e.g., for the case where an instructor has a section-
2254: specific role, and is viewing/modifying parameters.
1.970 raeburn 2255:
1.88 www 2256: See lonrights.pm for an example invocation and use.
2257:
2258: =cut
2259:
2260: #-------------------------------------------
2261: sub select_form {
1.1075.2.115 raeburn 2262: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2263: return unless (ref($hashref) eq 'HASH');
2264: if ($onchange) {
2265: $onchange = ' onchange="'.$onchange.'"';
2266: }
2267: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2268: my @keys;
1.970 raeburn 2269: if (exists($hashref->{'select_form_order'})) {
2270: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2271: } else {
1.970 raeburn 2272: @keys=sort(keys(%{$hashref}));
1.128 albertel 2273: }
1.356 albertel 2274: foreach my $key (@keys) {
2275: $selectform.=
2276: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2277: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2278: ">".$hashref->{$key}."</option>\n";
1.88 www 2279: }
2280: $selectform.="</select>";
2281: return $selectform;
2282: }
2283:
1.475 www 2284: # For display filters
2285:
2286: sub display_filter {
1.1074 raeburn 2287: my ($context) = @_;
1.475 www 2288: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2289: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2290: my $phraseinput = 'hidden';
2291: my $includeinput = 'hidden';
2292: my ($checked,$includetypestext);
2293: if ($env{'form.displayfilter'} eq 'containing') {
2294: $phraseinput = 'text';
2295: if ($context eq 'parmslog') {
2296: $includeinput = 'checkbox';
2297: if ($env{'form.includetypes'}) {
2298: $checked = ' checked="checked"';
2299: }
2300: $includetypestext = &mt('Include parameter types');
2301: }
2302: } else {
2303: $includetypestext = ' ';
2304: }
2305: my ($additional,$secondid,$thirdid);
2306: if ($context eq 'parmslog') {
2307: $additional =
2308: '<label><input type="'.$includeinput.'" name="includetypes"'.
2309: $checked.' name="includetypes" value="1" id="includetypes" />'.
2310: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2311: '</label>';
2312: $secondid = 'includetypes';
2313: $thirdid = 'includetypestext';
2314: }
2315: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2316: '$secondid','$thirdid')";
2317: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2318: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2319: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2320: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2321: &mt('Filter: [_1]',
1.477 www 2322: &select_form($env{'form.displayfilter'},
2323: 'displayfilter',
1.970 raeburn 2324: {'currentfolder' => 'Current folder/page',
1.477 www 2325: 'containing' => 'Containing phrase',
1.1074 raeburn 2326: 'none' => 'None'},$onchange)).' '.
2327: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2328: &HTML::Entities::encode($env{'form.containingphrase'}).
2329: '" />'.$additional;
2330: }
2331:
2332: sub display_filter_js {
2333: my $includetext = &mt('Include parameter types');
2334: return <<"ENDJS";
2335:
2336: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2337: var firstType = 'hidden';
2338: if (setter.options[setter.selectedIndex].value == 'containing') {
2339: firstType = 'text';
2340: }
2341: firstObject = document.getElementById(firstid);
2342: if (typeof(firstObject) == 'object') {
2343: if (firstObject.type != firstType) {
2344: changeInputType(firstObject,firstType);
2345: }
2346: }
2347: if (context == 'parmslog') {
2348: var secondType = 'hidden';
2349: if (firstType == 'text') {
2350: secondType = 'checkbox';
2351: }
2352: secondObject = document.getElementById(secondid);
2353: if (typeof(secondObject) == 'object') {
2354: if (secondObject.type != secondType) {
2355: changeInputType(secondObject,secondType);
2356: }
2357: }
2358: var textItem = document.getElementById(thirdid);
2359: var currtext = textItem.innerHTML;
2360: var newtext;
2361: if (firstType == 'text') {
2362: newtext = '$includetext';
2363: } else {
2364: newtext = ' ';
2365: }
2366: if (currtext != newtext) {
2367: textItem.innerHTML = newtext;
2368: }
2369: }
2370: return;
2371: }
2372:
2373: function changeInputType(oldObject,newType) {
2374: var newObject = document.createElement('input');
2375: newObject.type = newType;
2376: if (oldObject.size) {
2377: newObject.size = oldObject.size;
2378: }
2379: if (oldObject.value) {
2380: newObject.value = oldObject.value;
2381: }
2382: if (oldObject.name) {
2383: newObject.name = oldObject.name;
2384: }
2385: if (oldObject.id) {
2386: newObject.id = oldObject.id;
2387: }
2388: oldObject.parentNode.replaceChild(newObject,oldObject);
2389: return;
2390: }
2391:
2392: ENDJS
1.475 www 2393: }
2394:
1.167 www 2395: sub gradeleveldescription {
2396: my $gradelevel=shift;
2397: my %gradelevels=(0 => 'Not specified',
2398: 1 => 'Grade 1',
2399: 2 => 'Grade 2',
2400: 3 => 'Grade 3',
2401: 4 => 'Grade 4',
2402: 5 => 'Grade 5',
2403: 6 => 'Grade 6',
2404: 7 => 'Grade 7',
2405: 8 => 'Grade 8',
2406: 9 => 'Grade 9',
2407: 10 => 'Grade 10',
2408: 11 => 'Grade 11',
2409: 12 => 'Grade 12',
2410: 13 => 'Grade 13',
2411: 14 => '100 Level',
2412: 15 => '200 Level',
2413: 16 => '300 Level',
2414: 17 => '400 Level',
2415: 18 => 'Graduate Level');
2416: return &mt($gradelevels{$gradelevel});
2417: }
2418:
1.163 www 2419: sub select_level_form {
2420: my ($deflevel,$name)=@_;
2421: unless ($deflevel) { $deflevel=0; }
1.167 www 2422: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2423: for (my $i=0; $i<=18; $i++) {
2424: $selectform.="<option value=\"$i\" ".
1.253 albertel 2425: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2426: ">".&gradeleveldescription($i)."</option>\n";
2427: }
2428: $selectform.="</select>";
2429: return $selectform;
1.163 www 2430: }
1.167 www 2431:
1.35 matthew 2432: #-------------------------------------------
2433:
1.45 matthew 2434: =pod
2435:
1.1075.2.115 raeburn 2436: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2437:
2438: Returns a string containing a <select name='$name' size='1'> form to
2439: allow a user to select the domain to preform an operation in.
2440: See loncreateuser.pm for an example invocation and use.
2441:
1.90 www 2442: If the $includeempty flag is set, it also includes an empty choice ("no domain
2443: selected");
2444:
1.743 raeburn 2445: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2446:
1.910 raeburn 2447: 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.
2448:
1.1075.2.36 raeburn 2449: The optional $incdoms is a reference to an array of domains which will be the only available options.
2450:
1.1075.2.115 raeburn 2451: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2452:
2453: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2454:
1.35 matthew 2455: =cut
2456:
2457: #-------------------------------------------
1.34 matthew 2458: sub select_dom_form {
1.1075.2.115 raeburn 2459: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2460: if ($onchange) {
1.874 raeburn 2461: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2462: }
1.1075.2.115 raeburn 2463: if ($disabled) {
2464: $disabled = ' disabled="disabled"';
2465: }
1.1075.2.36 raeburn 2466: my (@domains,%exclude);
1.910 raeburn 2467: if (ref($incdoms) eq 'ARRAY') {
2468: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2469: } else {
2470: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2471: }
1.90 www 2472: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2473: if (ref($excdoms) eq 'ARRAY') {
2474: map { $exclude{$_} = 1; } @{$excdoms};
2475: }
1.1075.2.115 raeburn 2476: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2477: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2478: next if ($exclude{$dom});
1.356 albertel 2479: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2480: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2481: if ($showdomdesc) {
2482: if ($dom ne '') {
2483: my $domdesc = &Apache::lonnet::domain($dom,'description');
2484: if ($domdesc ne '') {
2485: $selectdomain .= ' ('.$domdesc.')';
2486: }
2487: }
2488: }
2489: $selectdomain .= "</option>\n";
1.34 matthew 2490: }
2491: $selectdomain.="</select>";
2492: return $selectdomain;
2493: }
2494:
1.35 matthew 2495: #-------------------------------------------
2496:
1.45 matthew 2497: =pod
2498:
1.648 raeburn 2499: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2500:
1.586 raeburn 2501: input: 4 arguments (two required, two optional) -
2502: $domain - domain of new user
2503: $name - name of form element
2504: $default - Value of 'default' causes a default item to be first
2505: option, and selected by default.
2506: $hide - Value of 'hide' causes hiding of the name of the server,
2507: if 1 server found, or default, if 0 found.
1.594 raeburn 2508: output: returns 2 items:
1.586 raeburn 2509: (a) form element which contains either:
2510: (i) <select name="$name">
2511: <option value="$hostid1">$hostid $servers{$hostid}</option>
2512: <option value="$hostid2">$hostid $servers{$hostid}</option>
2513: </select>
2514: form item if there are multiple library servers in $domain, or
2515: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2516: if there is only one library server in $domain.
2517:
2518: (b) number of library servers found.
2519:
2520: See loncreateuser.pm for example of use.
1.35 matthew 2521:
2522: =cut
2523:
2524: #-------------------------------------------
1.586 raeburn 2525: sub home_server_form_item {
2526: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2527: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2528: my $result;
2529: my $numlib = keys(%servers);
2530: if ($numlib > 1) {
2531: $result .= '<select name="'.$name.'" />'."\n";
2532: if ($default) {
1.804 bisitz 2533: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2534: '</option>'."\n";
2535: }
2536: foreach my $hostid (sort(keys(%servers))) {
2537: $result.= '<option value="'.$hostid.'">'.
2538: $hostid.' '.$servers{$hostid}."</option>\n";
2539: }
2540: $result .= '</select>'."\n";
2541: } elsif ($numlib == 1) {
2542: my $hostid;
2543: foreach my $item (keys(%servers)) {
2544: $hostid = $item;
2545: }
2546: $result .= '<input type="hidden" name="'.$name.'" value="'.
2547: $hostid.'" />';
2548: if (!$hide) {
2549: $result .= $hostid.' '.$servers{$hostid};
2550: }
2551: $result .= "\n";
2552: } elsif ($default) {
2553: $result .= '<input type="hidden" name="'.$name.
2554: '" value="default" />';
2555: if (!$hide) {
2556: $result .= &mt('default');
2557: }
2558: $result .= "\n";
1.33 matthew 2559: }
1.586 raeburn 2560: return ($result,$numlib);
1.33 matthew 2561: }
1.112 bowersj2 2562:
2563: =pod
2564:
1.534 albertel 2565: =back
2566:
1.112 bowersj2 2567: =cut
1.87 matthew 2568:
2569: ###############################################################
1.112 bowersj2 2570: ## Decoding User Agent ##
1.87 matthew 2571: ###############################################################
2572:
2573: =pod
2574:
1.112 bowersj2 2575: =head1 Decoding the User Agent
2576:
2577: =over 4
2578:
2579: =item * &decode_user_agent()
1.87 matthew 2580:
2581: Inputs: $r
2582:
2583: Outputs:
2584:
2585: =over 4
2586:
1.112 bowersj2 2587: =item * $httpbrowser
1.87 matthew 2588:
1.112 bowersj2 2589: =item * $clientbrowser
1.87 matthew 2590:
1.112 bowersj2 2591: =item * $clientversion
1.87 matthew 2592:
1.112 bowersj2 2593: =item * $clientmathml
1.87 matthew 2594:
1.112 bowersj2 2595: =item * $clientunicode
1.87 matthew 2596:
1.112 bowersj2 2597: =item * $clientos
1.87 matthew 2598:
1.1075.2.42 raeburn 2599: =item * $clientmobile
2600:
2601: =item * $clientinfo
2602:
1.1075.2.77 raeburn 2603: =item * $clientosversion
2604:
1.87 matthew 2605: =back
2606:
1.157 matthew 2607: =back
2608:
1.87 matthew 2609: =cut
2610:
2611: ###############################################################
2612: ###############################################################
2613: sub decode_user_agent {
1.247 albertel 2614: my ($r)=@_;
1.87 matthew 2615: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2616: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2617: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2618: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2619: my $clientbrowser='unknown';
2620: my $clientversion='0';
2621: my $clientmathml='';
2622: my $clientunicode='0';
1.1075.2.42 raeburn 2623: my $clientmobile=0;
1.1075.2.77 raeburn 2624: my $clientosversion='';
1.87 matthew 2625: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2626: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2627: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2628: $clientbrowser=$bname;
2629: $httpbrowser=~/$vreg/i;
2630: $clientversion=$1;
2631: $clientmathml=($clientversion>=$minv);
2632: $clientunicode=($clientversion>=$univ);
2633: }
2634: }
2635: my $clientos='unknown';
1.1075.2.42 raeburn 2636: my $clientinfo;
1.87 matthew 2637: if (($httpbrowser=~/linux/i) ||
2638: ($httpbrowser=~/unix/i) ||
2639: ($httpbrowser=~/ux/i) ||
2640: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2641: if (($httpbrowser=~/vax/i) ||
2642: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2643: if ($httpbrowser=~/next/i) { $clientos='next'; }
2644: if (($httpbrowser=~/mac/i) ||
2645: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2646: if ($httpbrowser=~/win/i) {
2647: $clientos='win';
2648: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2649: $clientosversion = $1;
2650: }
2651: }
1.87 matthew 2652: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2653: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2654: $clientmobile=lc($1);
2655: }
2656: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2657: $clientinfo = 'firefox-'.$1;
2658: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2659: $clientinfo = 'chromeframe-'.$1;
2660: }
1.87 matthew 2661: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2662: $clientunicode,$clientos,$clientmobile,$clientinfo,
2663: $clientosversion);
1.87 matthew 2664: }
2665:
1.32 matthew 2666: ###############################################################
2667: ## Authentication changing form generation subroutines ##
2668: ###############################################################
2669: ##
2670: ## All of the authform_xxxxxxx subroutines take their inputs in a
2671: ## hash, and have reasonable default values.
2672: ##
2673: ## formname = the name given in the <form> tag.
1.35 matthew 2674: #-------------------------------------------
2675:
1.45 matthew 2676: =pod
2677:
1.112 bowersj2 2678: =head1 Authentication Routines
2679:
2680: =over 4
2681:
1.648 raeburn 2682: =item * &authform_xxxxxx()
1.35 matthew 2683:
2684: The authform_xxxxxx subroutines provide javascript and html forms which
2685: handle some of the conveniences required for authentication forms.
2686: This is not an optimal method, but it works.
2687:
2688: =over 4
2689:
1.112 bowersj2 2690: =item * authform_header
1.35 matthew 2691:
1.112 bowersj2 2692: =item * authform_authorwarning
1.35 matthew 2693:
1.112 bowersj2 2694: =item * authform_nochange
1.35 matthew 2695:
1.112 bowersj2 2696: =item * authform_kerberos
1.35 matthew 2697:
1.112 bowersj2 2698: =item * authform_internal
1.35 matthew 2699:
1.112 bowersj2 2700: =item * authform_filesystem
1.35 matthew 2701:
2702: =back
2703:
1.648 raeburn 2704: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2705:
1.35 matthew 2706: =cut
2707:
2708: #-------------------------------------------
1.32 matthew 2709: sub authform_header{
2710: my %in = (
2711: formname => 'cu',
1.80 albertel 2712: kerb_def_dom => '',
1.32 matthew 2713: @_,
2714: );
2715: $in{'formname'} = 'document.' . $in{'formname'};
2716: my $result='';
1.80 albertel 2717:
2718: #---------------------------------------------- Code for upper case translation
2719: my $Javascript_toUpperCase;
2720: unless ($in{kerb_def_dom}) {
2721: $Javascript_toUpperCase =<<"END";
2722: switch (choice) {
2723: case 'krb': currentform.elements[choicearg].value =
2724: currentform.elements[choicearg].value.toUpperCase();
2725: break;
2726: default:
2727: }
2728: END
2729: } else {
2730: $Javascript_toUpperCase = "";
2731: }
2732:
1.165 raeburn 2733: my $radioval = "'nochange'";
1.591 raeburn 2734: if (defined($in{'curr_authtype'})) {
2735: if ($in{'curr_authtype'} ne '') {
2736: $radioval = "'".$in{'curr_authtype'}."arg'";
2737: }
1.174 matthew 2738: }
1.165 raeburn 2739: my $argfield = 'null';
1.591 raeburn 2740: if (defined($in{'mode'})) {
1.165 raeburn 2741: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2742: if (defined($in{'curr_autharg'})) {
2743: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2744: $argfield = "'$in{'curr_autharg'}'";
2745: }
2746: }
2747: }
2748: }
2749:
1.32 matthew 2750: $result.=<<"END";
2751: var current = new Object();
1.165 raeburn 2752: current.radiovalue = $radioval;
2753: current.argfield = $argfield;
1.32 matthew 2754:
2755: function changed_radio(choice,currentform) {
2756: var choicearg = choice + 'arg';
2757: // If a radio button in changed, we need to change the argfield
2758: if (current.radiovalue != choice) {
2759: current.radiovalue = choice;
2760: if (current.argfield != null) {
2761: currentform.elements[current.argfield].value = '';
2762: }
2763: if (choice == 'nochange') {
2764: current.argfield = null;
2765: } else {
2766: current.argfield = choicearg;
2767: switch(choice) {
2768: case 'krb':
2769: currentform.elements[current.argfield].value =
2770: "$in{'kerb_def_dom'}";
2771: break;
2772: default:
2773: break;
2774: }
2775: }
2776: }
2777: return;
2778: }
1.22 www 2779:
1.32 matthew 2780: function changed_text(choice,currentform) {
2781: var choicearg = choice + 'arg';
2782: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2783: $Javascript_toUpperCase
1.32 matthew 2784: // clear old field
2785: if ((current.argfield != choicearg) && (current.argfield != null)) {
2786: currentform.elements[current.argfield].value = '';
2787: }
2788: current.argfield = choicearg;
2789: }
2790: set_auth_radio_buttons(choice,currentform);
2791: return;
1.20 www 2792: }
1.32 matthew 2793:
2794: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2795: var numauthchoices = currentform.login.length;
2796: if (typeof numauthchoices == "undefined") {
2797: return;
2798: }
1.32 matthew 2799: var i=0;
1.986 raeburn 2800: while (i < numauthchoices) {
1.32 matthew 2801: if (currentform.login[i].value == newvalue) { break; }
2802: i++;
2803: }
1.986 raeburn 2804: if (i == numauthchoices) {
1.32 matthew 2805: return;
2806: }
2807: current.radiovalue = newvalue;
2808: currentform.login[i].checked = true;
2809: return;
2810: }
2811: END
2812: return $result;
2813: }
2814:
1.1075.2.20 raeburn 2815: sub authform_authorwarning {
1.32 matthew 2816: my $result='';
1.144 matthew 2817: $result='<i>'.
2818: &mt('As a general rule, only authors or co-authors should be '.
2819: 'filesystem authenticated '.
2820: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2821: return $result;
2822: }
2823:
1.1075.2.20 raeburn 2824: sub authform_nochange {
1.32 matthew 2825: my %in = (
2826: formname => 'document.cu',
2827: kerb_def_dom => 'MSU.EDU',
2828: @_,
2829: );
1.1075.2.20 raeburn 2830: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2831: my $result;
1.1075.2.20 raeburn 2832: if (!$authnum) {
2833: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2834: } else {
2835: $result = '<label>'.&mt('[_1] Do not change login data',
2836: '<input type="radio" name="login" value="nochange" '.
2837: 'checked="checked" onclick="'.
1.281 albertel 2838: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2839: '</label>';
1.586 raeburn 2840: }
1.32 matthew 2841: return $result;
2842: }
2843:
1.591 raeburn 2844: sub authform_kerberos {
1.32 matthew 2845: my %in = (
2846: formname => 'document.cu',
2847: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2848: kerb_def_auth => 'krb4',
1.32 matthew 2849: @_,
2850: );
1.586 raeburn 2851: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2852: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2853: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2854: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2855: $check5 = ' checked="checked"';
1.80 albertel 2856: } else {
1.772 bisitz 2857: $check4 = ' checked="checked"';
1.80 albertel 2858: }
1.1075.2.117 raeburn 2859: if ($in{'readonly'}) {
2860: $disabled = ' disabled="disabled"';
2861: }
1.165 raeburn 2862: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2863: if (defined($in{'curr_authtype'})) {
2864: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2865: $krbcheck = ' checked="checked"';
1.623 raeburn 2866: if (defined($in{'mode'})) {
2867: if ($in{'mode'} eq 'modifyuser') {
2868: $krbcheck = '';
2869: }
2870: }
1.591 raeburn 2871: if (defined($in{'curr_kerb_ver'})) {
2872: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2873: $check5 = ' checked="checked"';
1.591 raeburn 2874: $check4 = '';
2875: } else {
1.772 bisitz 2876: $check4 = ' checked="checked"';
1.591 raeburn 2877: $check5 = '';
2878: }
1.586 raeburn 2879: }
1.591 raeburn 2880: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2881: $krbarg = $in{'curr_autharg'};
2882: }
1.586 raeburn 2883: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2884: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2885: $result =
2886: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2887: $in{'curr_autharg'},$krbver);
2888: } else {
2889: $result =
2890: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2891: }
2892: return $result;
2893: }
2894: }
2895: } else {
2896: if ($authnum == 1) {
1.784 bisitz 2897: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2898: }
2899: }
1.586 raeburn 2900: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2901: return;
1.587 raeburn 2902: } elsif ($authtype eq '') {
1.591 raeburn 2903: if (defined($in{'mode'})) {
1.587 raeburn 2904: if ($in{'mode'} eq 'modifycourse') {
2905: if ($authnum == 1) {
1.1075.2.117 raeburn 2906: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2907: }
2908: }
2909: }
1.586 raeburn 2910: }
2911: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2912: if ($authtype eq '') {
2913: $authtype = '<input type="radio" name="login" value="krb" '.
2914: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2915: $krbcheck.$disabled.' />';
1.586 raeburn 2916: }
2917: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2918: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2919: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2920: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2921: $in{'curr_authtype'} eq 'krb4')) {
2922: $result .= &mt
1.144 matthew 2923: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2924: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2925: '<label>'.$authtype,
1.281 albertel 2926: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2927: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2928: 'onchange="'.$jscall.'"'.$disabled.' />',
2929: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2930: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2931: '</label>');
1.586 raeburn 2932: } elsif ($can_assign{'krb4'}) {
2933: $result .= &mt
2934: ('[_1] Kerberos authenticated with domain [_2] '.
2935: '[_3] Version 4 [_4]',
2936: '<label>'.$authtype,
2937: '</label><input type="text" size="10" name="krbarg" '.
2938: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2939: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2940: '<label><input type="hidden" name="krbver" value="4" />',
2941: '</label>');
2942: } elsif ($can_assign{'krb5'}) {
2943: $result .= &mt
2944: ('[_1] Kerberos authenticated with domain [_2] '.
2945: '[_3] Version 5 [_4]',
2946: '<label>'.$authtype,
2947: '</label><input type="text" size="10" name="krbarg" '.
2948: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2949: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2950: '<label><input type="hidden" name="krbver" value="5" />',
2951: '</label>');
2952: }
1.32 matthew 2953: return $result;
2954: }
2955:
1.1075.2.20 raeburn 2956: sub authform_internal {
1.586 raeburn 2957: my %in = (
1.32 matthew 2958: formname => 'document.cu',
2959: kerb_def_dom => 'MSU.EDU',
2960: @_,
2961: );
1.1075.2.117 raeburn 2962: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2963: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2964: if ($in{'readonly'}) {
2965: $disabled = ' disabled="disabled"';
2966: }
1.591 raeburn 2967: if (defined($in{'curr_authtype'})) {
2968: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2969: if ($can_assign{'int'}) {
1.772 bisitz 2970: $intcheck = 'checked="checked" ';
1.623 raeburn 2971: if (defined($in{'mode'})) {
2972: if ($in{'mode'} eq 'modifyuser') {
2973: $intcheck = '';
2974: }
2975: }
1.591 raeburn 2976: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2977: $intarg = $in{'curr_autharg'};
2978: }
2979: } else {
2980: $result = &mt('Currently internally authenticated.');
2981: return $result;
1.165 raeburn 2982: }
2983: }
1.586 raeburn 2984: } else {
2985: if ($authnum == 1) {
1.784 bisitz 2986: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2987: }
2988: }
2989: if (!$can_assign{'int'}) {
2990: return;
1.587 raeburn 2991: } elsif ($authtype eq '') {
1.591 raeburn 2992: if (defined($in{'mode'})) {
1.587 raeburn 2993: if ($in{'mode'} eq 'modifycourse') {
2994: if ($authnum == 1) {
1.1075.2.117 raeburn 2995: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 2996: }
2997: }
2998: }
1.165 raeburn 2999: }
1.586 raeburn 3000: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3001: if ($authtype eq '') {
3002: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3003: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3004: }
1.605 bisitz 3005: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3006: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3007: $result = &mt
1.144 matthew 3008: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3009: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3010: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3011: return $result;
3012: }
3013:
1.1075.2.20 raeburn 3014: sub authform_local {
1.32 matthew 3015: my %in = (
3016: formname => 'document.cu',
3017: kerb_def_dom => 'MSU.EDU',
3018: @_,
3019: );
1.1075.2.117 raeburn 3020: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3021: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3022: if ($in{'readonly'}) {
3023: $disabled = ' disabled="disabled"';
3024: }
1.591 raeburn 3025: if (defined($in{'curr_authtype'})) {
3026: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3027: if ($can_assign{'loc'}) {
1.772 bisitz 3028: $loccheck = 'checked="checked" ';
1.623 raeburn 3029: if (defined($in{'mode'})) {
3030: if ($in{'mode'} eq 'modifyuser') {
3031: $loccheck = '';
3032: }
3033: }
1.591 raeburn 3034: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3035: $locarg = $in{'curr_autharg'};
3036: }
3037: } else {
3038: $result = &mt('Currently using local (institutional) authentication.');
3039: return $result;
1.165 raeburn 3040: }
3041: }
1.586 raeburn 3042: } else {
3043: if ($authnum == 1) {
1.784 bisitz 3044: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3045: }
3046: }
3047: if (!$can_assign{'loc'}) {
3048: return;
1.587 raeburn 3049: } elsif ($authtype eq '') {
1.591 raeburn 3050: if (defined($in{'mode'})) {
1.587 raeburn 3051: if ($in{'mode'} eq 'modifycourse') {
3052: if ($authnum == 1) {
1.1075.2.117 raeburn 3053: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3054: }
3055: }
3056: }
1.165 raeburn 3057: }
1.586 raeburn 3058: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3059: if ($authtype eq '') {
3060: $authtype = '<input type="radio" name="login" value="loc" '.
3061: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3062: $jscall.'"'.$disabled.' />';
1.586 raeburn 3063: }
3064: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3065: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3066: $result = &mt('[_1] Local Authentication with argument [_2]',
3067: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3068: return $result;
3069: }
3070:
1.1075.2.20 raeburn 3071: sub authform_filesystem {
1.32 matthew 3072: my %in = (
3073: formname => 'document.cu',
3074: kerb_def_dom => 'MSU.EDU',
3075: @_,
3076: );
1.1075.2.117 raeburn 3077: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3078: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3079: if ($in{'readonly'}) {
3080: $disabled = ' disabled="disabled"';
3081: }
1.591 raeburn 3082: if (defined($in{'curr_authtype'})) {
3083: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3084: if ($can_assign{'fsys'}) {
1.772 bisitz 3085: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3086: if (defined($in{'mode'})) {
3087: if ($in{'mode'} eq 'modifyuser') {
3088: $fsyscheck = '';
3089: }
3090: }
1.586 raeburn 3091: } else {
3092: $result = &mt('Currently Filesystem Authenticated.');
3093: return $result;
3094: }
3095: }
3096: } else {
3097: if ($authnum == 1) {
1.784 bisitz 3098: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3099: }
3100: }
3101: if (!$can_assign{'fsys'}) {
3102: return;
1.587 raeburn 3103: } elsif ($authtype eq '') {
1.591 raeburn 3104: if (defined($in{'mode'})) {
1.587 raeburn 3105: if ($in{'mode'} eq 'modifycourse') {
3106: if ($authnum == 1) {
1.1075.2.117 raeburn 3107: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3108: }
3109: }
3110: }
1.586 raeburn 3111: }
3112: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3113: if ($authtype eq '') {
3114: $authtype = '<input type="radio" name="login" value="fsys" '.
3115: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3116: $jscall.'"'.$disabled.' />';
1.586 raeburn 3117: }
3118: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3119: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3120: $result = &mt
1.144 matthew 3121: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3122: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3123: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3124: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3125: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3126: return $result;
3127: }
3128:
1.586 raeburn 3129: sub get_assignable_auth {
3130: my ($dom) = @_;
3131: if ($dom eq '') {
3132: $dom = $env{'request.role.domain'};
3133: }
3134: my %can_assign = (
3135: krb4 => 1,
3136: krb5 => 1,
3137: int => 1,
3138: loc => 1,
3139: );
3140: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3141: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3142: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3143: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3144: my $context;
3145: if ($env{'request.role'} =~ /^au/) {
3146: $context = 'author';
1.1075.2.117 raeburn 3147: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3148: $context = 'domain';
3149: } elsif ($env{'request.course.id'}) {
3150: $context = 'course';
3151: }
3152: if ($context) {
3153: if (ref($authhash->{$context}) eq 'HASH') {
3154: %can_assign = %{$authhash->{$context}};
3155: }
3156: }
3157: }
3158: }
3159: my $authnum = 0;
3160: foreach my $key (keys(%can_assign)) {
3161: if ($can_assign{$key}) {
3162: $authnum ++;
3163: }
3164: }
3165: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3166: $authnum --;
3167: }
3168: return ($authnum,%can_assign);
3169: }
3170:
1.80 albertel 3171: ###############################################################
3172: ## Get Kerberos Defaults for Domain ##
3173: ###############################################################
3174: ##
3175: ## Returns default kerberos version and an associated argument
3176: ## as listed in file domain.tab. If not listed, provides
3177: ## appropriate default domain and kerberos version.
3178: ##
3179: #-------------------------------------------
3180:
3181: =pod
3182:
1.648 raeburn 3183: =item * &get_kerberos_defaults()
1.80 albertel 3184:
3185: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3186: version and domain. If not found, it defaults to version 4 and the
3187: domain of the server.
1.80 albertel 3188:
1.648 raeburn 3189: =over 4
3190:
1.80 albertel 3191: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3192:
1.648 raeburn 3193: =back
3194:
3195: =back
3196:
1.80 albertel 3197: =cut
3198:
3199: #-------------------------------------------
3200: sub get_kerberos_defaults {
3201: my $domain=shift;
1.641 raeburn 3202: my ($krbdef,$krbdefdom);
3203: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3204: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3205: $krbdef = $domdefaults{'auth_def'};
3206: $krbdefdom = $domdefaults{'auth_arg_def'};
3207: } else {
1.80 albertel 3208: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3209: my $krbdefdom=$1;
3210: $krbdefdom=~tr/a-z/A-Z/;
3211: $krbdef = "krb4";
3212: }
3213: return ($krbdef,$krbdefdom);
3214: }
1.112 bowersj2 3215:
1.32 matthew 3216:
1.46 matthew 3217: ###############################################################
3218: ## Thesaurus Functions ##
3219: ###############################################################
1.20 www 3220:
1.46 matthew 3221: =pod
1.20 www 3222:
1.112 bowersj2 3223: =head1 Thesaurus Functions
3224:
3225: =over 4
3226:
1.648 raeburn 3227: =item * &initialize_keywords()
1.46 matthew 3228:
3229: Initializes the package variable %Keywords if it is empty. Uses the
3230: package variable $thesaurus_db_file.
3231:
3232: =cut
3233:
3234: ###################################################
3235:
3236: sub initialize_keywords {
3237: return 1 if (scalar keys(%Keywords));
3238: # If we are here, %Keywords is empty, so fill it up
3239: # Make sure the file we need exists...
3240: if (! -e $thesaurus_db_file) {
3241: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3242: " failed because it does not exist");
3243: return 0;
3244: }
3245: # Set up the hash as a database
3246: my %thesaurus_db;
3247: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3248: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3249: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3250: $thesaurus_db_file);
3251: return 0;
3252: }
3253: # Get the average number of appearances of a word.
3254: my $avecount = $thesaurus_db{'average.count'};
3255: # Put keywords (those that appear > average) into %Keywords
3256: while (my ($word,$data)=each (%thesaurus_db)) {
3257: my ($count,undef) = split /:/,$data;
3258: $Keywords{$word}++ if ($count > $avecount);
3259: }
3260: untie %thesaurus_db;
3261: # Remove special values from %Keywords.
1.356 albertel 3262: foreach my $value ('total.count','average.count') {
3263: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3264: }
1.46 matthew 3265: return 1;
3266: }
3267:
3268: ###################################################
3269:
3270: =pod
3271:
1.648 raeburn 3272: =item * &keyword($word)
1.46 matthew 3273:
3274: Returns true if $word is a keyword. A keyword is a word that appears more
3275: than the average number of times in the thesaurus database. Calls
3276: &initialize_keywords
3277:
3278: =cut
3279:
3280: ###################################################
1.20 www 3281:
3282: sub keyword {
1.46 matthew 3283: return if (!&initialize_keywords());
3284: my $word=lc(shift());
3285: $word=~s/\W//g;
3286: return exists($Keywords{$word});
1.20 www 3287: }
1.46 matthew 3288:
3289: ###############################################################
3290:
3291: =pod
1.20 www 3292:
1.648 raeburn 3293: =item * &get_related_words()
1.46 matthew 3294:
1.160 matthew 3295: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3296: an array of words. If the keyword is not in the thesaurus, an empty array
3297: will be returned. The order of the words returned is determined by the
3298: database which holds them.
3299:
3300: Uses global $thesaurus_db_file.
3301:
1.1057 foxr 3302:
1.46 matthew 3303: =cut
3304:
3305: ###############################################################
3306: sub get_related_words {
3307: my $keyword = shift;
3308: my %thesaurus_db;
3309: if (! -e $thesaurus_db_file) {
3310: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3311: "failed because the file does not exist");
3312: return ();
3313: }
3314: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3315: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3316: return ();
3317: }
3318: my @Words=();
1.429 www 3319: my $count=0;
1.46 matthew 3320: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3321: # The first element is the number of times
3322: # the word appears. We do not need it now.
1.429 www 3323: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3324: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3325: my $threshold=$mostfrequentcount/10;
3326: foreach my $possibleword (@RelatedWords) {
3327: my ($word,$wordcount)=split(/\,/,$possibleword);
3328: if ($wordcount>$threshold) {
3329: push(@Words,$word);
3330: $count++;
3331: if ($count>10) { last; }
3332: }
1.20 www 3333: }
3334: }
1.46 matthew 3335: untie %thesaurus_db;
3336: return @Words;
1.14 harris41 3337: }
1.46 matthew 3338:
1.112 bowersj2 3339: =pod
3340:
3341: =back
3342:
3343: =cut
1.61 www 3344:
3345: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3346: =pod
3347:
1.112 bowersj2 3348: =head1 User Name Functions
3349:
3350: =over 4
3351:
1.648 raeburn 3352: =item * &plainname($uname,$udom,$first)
1.81 albertel 3353:
1.112 bowersj2 3354: Takes a users logon name and returns it as a string in
1.226 albertel 3355: "first middle last generation" form
3356: if $first is set to 'lastname' then it returns it as
3357: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3358:
3359: =cut
1.61 www 3360:
1.295 www 3361:
1.81 albertel 3362: ###############################################################
1.61 www 3363: sub plainname {
1.226 albertel 3364: my ($uname,$udom,$first)=@_;
1.537 albertel 3365: return if (!defined($uname) || !defined($udom));
1.295 www 3366: my %names=&getnames($uname,$udom);
1.226 albertel 3367: my $name=&Apache::lonnet::format_name($names{'firstname'},
3368: $names{'middlename'},
3369: $names{'lastname'},
3370: $names{'generation'},$first);
3371: $name=~s/^\s+//;
1.62 www 3372: $name=~s/\s+$//;
3373: $name=~s/\s+/ /g;
1.353 albertel 3374: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3375: return $name;
1.61 www 3376: }
1.66 www 3377:
3378: # -------------------------------------------------------------------- Nickname
1.81 albertel 3379: =pod
3380:
1.648 raeburn 3381: =item * &nickname($uname,$udom)
1.81 albertel 3382:
3383: Gets a users name and returns it as a string as
3384:
3385: ""nickname""
1.66 www 3386:
1.81 albertel 3387: if the user has a nickname or
3388:
3389: "first middle last generation"
3390:
3391: if the user does not
3392:
3393: =cut
1.66 www 3394:
3395: sub nickname {
3396: my ($uname,$udom)=@_;
1.537 albertel 3397: return if (!defined($uname) || !defined($udom));
1.295 www 3398: my %names=&getnames($uname,$udom);
1.68 albertel 3399: my $name=$names{'nickname'};
1.66 www 3400: if ($name) {
3401: $name='"'.$name.'"';
3402: } else {
3403: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3404: $names{'lastname'}.' '.$names{'generation'};
3405: $name=~s/\s+$//;
3406: $name=~s/\s+/ /g;
3407: }
3408: return $name;
3409: }
3410:
1.295 www 3411: sub getnames {
3412: my ($uname,$udom)=@_;
1.537 albertel 3413: return if (!defined($uname) || !defined($udom));
1.433 albertel 3414: if ($udom eq 'public' && $uname eq 'public') {
3415: return ('lastname' => &mt('Public'));
3416: }
1.295 www 3417: my $id=$uname.':'.$udom;
3418: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3419: if ($cached) {
3420: return %{$names};
3421: } else {
3422: my %loadnames=&Apache::lonnet::get('environment',
3423: ['firstname','middlename','lastname','generation','nickname'],
3424: $udom,$uname);
3425: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3426: return %loadnames;
3427: }
3428: }
1.61 www 3429:
1.542 raeburn 3430: # -------------------------------------------------------------------- getemails
1.648 raeburn 3431:
1.542 raeburn 3432: =pod
3433:
1.648 raeburn 3434: =item * &getemails($uname,$udom)
1.542 raeburn 3435:
3436: Gets a user's email information and returns it as a hash with keys:
3437: notification, critnotification, permanentemail
3438:
3439: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3440: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3441:
1.648 raeburn 3442:
1.542 raeburn 3443: =cut
3444:
1.648 raeburn 3445:
1.466 albertel 3446: sub getemails {
3447: my ($uname,$udom)=@_;
3448: if ($udom eq 'public' && $uname eq 'public') {
3449: return;
3450: }
1.467 www 3451: if (!$udom) { $udom=$env{'user.domain'}; }
3452: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3453: my $id=$uname.':'.$udom;
3454: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3455: if ($cached) {
3456: return %{$names};
3457: } else {
3458: my %loadnames=&Apache::lonnet::get('environment',
3459: ['notification','critnotification',
3460: 'permanentemail'],
3461: $udom,$uname);
3462: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3463: return %loadnames;
3464: }
3465: }
3466:
1.551 albertel 3467: sub flush_email_cache {
3468: my ($uname,$udom)=@_;
3469: if (!$udom) { $udom =$env{'user.domain'}; }
3470: if (!$uname) { $uname=$env{'user.name'}; }
3471: return if ($udom eq 'public' && $uname eq 'public');
3472: my $id=$uname.':'.$udom;
3473: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3474: }
3475:
1.728 raeburn 3476: # -------------------------------------------------------------------- getlangs
3477:
3478: =pod
3479:
3480: =item * &getlangs($uname,$udom)
3481:
3482: Gets a user's language preference and returns it as a hash with key:
3483: language.
3484:
3485: =cut
3486:
3487:
3488: sub getlangs {
3489: my ($uname,$udom) = @_;
3490: if (!$udom) { $udom =$env{'user.domain'}; }
3491: if (!$uname) { $uname=$env{'user.name'}; }
3492: my $id=$uname.':'.$udom;
3493: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3494: if ($cached) {
3495: return %{$langs};
3496: } else {
3497: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3498: $udom,$uname);
3499: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3500: return %loadlangs;
3501: }
3502: }
3503:
3504: sub flush_langs_cache {
3505: my ($uname,$udom)=@_;
3506: if (!$udom) { $udom =$env{'user.domain'}; }
3507: if (!$uname) { $uname=$env{'user.name'}; }
3508: return if ($udom eq 'public' && $uname eq 'public');
3509: my $id=$uname.':'.$udom;
3510: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3511: }
3512:
1.61 www 3513: # ------------------------------------------------------------------ Screenname
1.81 albertel 3514:
3515: =pod
3516:
1.648 raeburn 3517: =item * &screenname($uname,$udom)
1.81 albertel 3518:
3519: Gets a users screenname and returns it as a string
3520:
3521: =cut
1.61 www 3522:
3523: sub screenname {
3524: my ($uname,$udom)=@_;
1.258 albertel 3525: if ($uname eq $env{'user.name'} &&
3526: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3527: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3528: return $names{'screenname'};
1.62 www 3529: }
3530:
1.212 albertel 3531:
1.802 bisitz 3532: # ------------------------------------------------------------- Confirm Wrapper
3533: =pod
3534:
1.1075.2.42 raeburn 3535: =item * &confirmwrapper($message)
1.802 bisitz 3536:
3537: Wrap messages about completion of operation in box
3538:
3539: =cut
3540:
3541: sub confirmwrapper {
3542: my ($message)=@_;
3543: if ($message) {
3544: return "\n".'<div class="LC_confirm_box">'."\n"
3545: .$message."\n"
3546: .'</div>'."\n";
3547: } else {
3548: return $message;
3549: }
3550: }
3551:
1.62 www 3552: # ------------------------------------------------------------- Message Wrapper
3553:
3554: sub messagewrapper {
1.369 www 3555: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3556: return
1.441 albertel 3557: '<a href="/adm/email?compose=individual&'.
3558: 'recname='.$username.'&recdom='.$domain.
3559: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3560: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3561: }
1.802 bisitz 3562:
1.74 www 3563: # --------------------------------------------------------------- Notes Wrapper
3564:
3565: sub noteswrapper {
3566: my ($link,$un,$do)=@_;
3567: return
1.896 amueller 3568: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3569: }
1.802 bisitz 3570:
1.62 www 3571: # ------------------------------------------------------------- Aboutme Wrapper
3572:
3573: sub aboutmewrapper {
1.1070 raeburn 3574: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3575: if (!defined($username) && !defined($domain)) {
3576: return;
3577: }
1.1075.2.15 raeburn 3578: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3579: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3580: }
3581:
3582: # ------------------------------------------------------------ Syllabus Wrapper
3583:
3584: sub syllabuswrapper {
1.707 bisitz 3585: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3586: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3587: }
1.14 harris41 3588:
1.802 bisitz 3589: # -----------------------------------------------------------------------------
3590:
1.208 matthew 3591: sub track_student_link {
1.887 raeburn 3592: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3593: my $link ="/adm/trackstudent?";
1.208 matthew 3594: my $title = 'View recent activity';
3595: if (defined($sname) && $sname !~ /^\s*$/ &&
3596: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3597: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3598: $title .= ' of this student';
1.268 albertel 3599: }
1.208 matthew 3600: if (defined($target) && $target !~ /^\s*$/) {
3601: $target = qq{target="$target"};
3602: } else {
3603: $target = '';
3604: }
1.268 albertel 3605: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3606: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3607: $title = &mt($title);
3608: $linktext = &mt($linktext);
1.448 albertel 3609: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3610: &help_open_topic('View_recent_activity');
1.208 matthew 3611: }
3612:
1.781 raeburn 3613: sub slot_reservations_link {
3614: my ($linktext,$sname,$sdom,$target) = @_;
3615: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3616: my $title = 'View slot reservation history';
3617: if (defined($sname) && $sname !~ /^\s*$/ &&
3618: defined($sdom) && $sdom !~ /^\s*$/) {
3619: $link .= "&uname=$sname&udom=$sdom";
3620: $title .= ' of this student';
3621: }
3622: if (defined($target) && $target !~ /^\s*$/) {
3623: $target = qq{target="$target"};
3624: } else {
3625: $target = '';
3626: }
3627: $title = &mt($title);
3628: $linktext = &mt($linktext);
3629: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3630: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3631:
3632: }
3633:
1.508 www 3634: # ===================================================== Display a student photo
3635:
3636:
1.509 albertel 3637: sub student_image_tag {
1.508 www 3638: my ($domain,$user)=@_;
3639: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3640: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3641: return '<img src="'.$imgsrc.'" align="right" />';
3642: } else {
3643: return '';
3644: }
3645: }
3646:
1.112 bowersj2 3647: =pod
3648:
3649: =back
3650:
3651: =head1 Access .tab File Data
3652:
3653: =over 4
3654:
1.648 raeburn 3655: =item * &languageids()
1.112 bowersj2 3656:
3657: returns list of all language ids
3658:
3659: =cut
3660:
1.14 harris41 3661: sub languageids {
1.16 harris41 3662: return sort(keys(%language));
1.14 harris41 3663: }
3664:
1.112 bowersj2 3665: =pod
3666:
1.648 raeburn 3667: =item * &languagedescription()
1.112 bowersj2 3668:
3669: returns description of a specified language id
3670:
3671: =cut
3672:
1.14 harris41 3673: sub languagedescription {
1.125 www 3674: my $code=shift;
3675: return ($supported_language{$code}?'* ':'').
3676: $language{$code}.
1.126 www 3677: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3678: }
3679:
1.1048 foxr 3680: =pod
3681:
3682: =item * &plainlanguagedescription
3683:
3684: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3685: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3686:
3687: =cut
3688:
1.145 www 3689: sub plainlanguagedescription {
3690: my $code=shift;
3691: return $language{$code};
3692: }
3693:
1.1048 foxr 3694: =pod
3695:
3696: =item * &supportedlanguagecode
3697:
3698: Returns the supported language code (e.g. sptutf maps to pt) given a language
3699: code.
3700:
3701: =cut
3702:
1.145 www 3703: sub supportedlanguagecode {
3704: my $code=shift;
3705: return $supported_language{$code};
1.97 www 3706: }
3707:
1.112 bowersj2 3708: =pod
3709:
1.1048 foxr 3710: =item * &latexlanguage()
3711:
3712: Given a language key code returns the correspondnig language to use
3713: to select the correct hyphenation on LaTeX printouts. This is undef if there
3714: is no supported hyphenation for the language code.
3715:
3716: =cut
3717:
3718: sub latexlanguage {
3719: my $code = shift;
3720: return $latex_language{$code};
3721: }
3722:
3723: =pod
3724:
3725: =item * &latexhyphenation()
3726:
3727: Same as above but what's supplied is the language as it might be stored
3728: in the metadata.
3729:
3730: =cut
3731:
3732: sub latexhyphenation {
3733: my $key = shift;
3734: return $latex_language_bykey{$key};
3735: }
3736:
3737: =pod
3738:
1.648 raeburn 3739: =item * ©rightids()
1.112 bowersj2 3740:
3741: returns list of all copyrights
3742:
3743: =cut
3744:
3745: sub copyrightids {
3746: return sort(keys(%cprtag));
3747: }
3748:
3749: =pod
3750:
1.648 raeburn 3751: =item * ©rightdescription()
1.112 bowersj2 3752:
3753: returns description of a specified copyright id
3754:
3755: =cut
3756:
3757: sub copyrightdescription {
1.166 www 3758: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3759: }
1.197 matthew 3760:
3761: =pod
3762:
1.648 raeburn 3763: =item * &source_copyrightids()
1.192 taceyjo1 3764:
3765: returns list of all source copyrights
3766:
3767: =cut
3768:
3769: sub source_copyrightids {
3770: return sort(keys(%scprtag));
3771: }
3772:
3773: =pod
3774:
1.648 raeburn 3775: =item * &source_copyrightdescription()
1.192 taceyjo1 3776:
3777: returns description of a specified source copyright id
3778:
3779: =cut
3780:
3781: sub source_copyrightdescription {
3782: return &mt($scprtag{shift(@_)});
3783: }
1.112 bowersj2 3784:
3785: =pod
3786:
1.648 raeburn 3787: =item * &filecategories()
1.112 bowersj2 3788:
3789: returns list of all file categories
3790:
3791: =cut
3792:
3793: sub filecategories {
3794: return sort(keys(%category_extensions));
3795: }
3796:
3797: =pod
3798:
1.648 raeburn 3799: =item * &filecategorytypes()
1.112 bowersj2 3800:
3801: returns list of file types belonging to a given file
3802: category
3803:
3804: =cut
3805:
3806: sub filecategorytypes {
1.356 albertel 3807: my ($cat) = @_;
3808: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3809: }
3810:
3811: =pod
3812:
1.648 raeburn 3813: =item * &fileembstyle()
1.112 bowersj2 3814:
3815: returns embedding style for a specified file type
3816:
3817: =cut
3818:
3819: sub fileembstyle {
3820: return $fe{lc(shift(@_))};
1.169 www 3821: }
3822:
1.351 www 3823: sub filemimetype {
3824: return $fm{lc(shift(@_))};
3825: }
3826:
1.169 www 3827:
3828: sub filecategoryselect {
3829: my ($name,$value)=@_;
1.189 matthew 3830: return &select_form($value,$name,
1.970 raeburn 3831: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3832: }
3833:
3834: =pod
3835:
1.648 raeburn 3836: =item * &filedescription()
1.112 bowersj2 3837:
3838: returns description for a specified file type
3839:
3840: =cut
3841:
3842: sub filedescription {
1.188 matthew 3843: my $file_description = $fd{lc(shift())};
3844: $file_description =~ s:([\[\]]):~$1:g;
3845: return &mt($file_description);
1.112 bowersj2 3846: }
3847:
3848: =pod
3849:
1.648 raeburn 3850: =item * &filedescriptionex()
1.112 bowersj2 3851:
3852: returns description for a specified file type with
3853: extra formatting
3854:
3855: =cut
3856:
3857: sub filedescriptionex {
3858: my $ex=shift;
1.188 matthew 3859: my $file_description = $fd{lc($ex)};
3860: $file_description =~ s:([\[\]]):~$1:g;
3861: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3862: }
3863:
3864: # End of .tab access
3865: =pod
3866:
3867: =back
3868:
3869: =cut
3870:
3871: # ------------------------------------------------------------------ File Types
3872: sub fileextensions {
3873: return sort(keys(%fe));
3874: }
3875:
1.97 www 3876: # ----------------------------------------------------------- Display Languages
3877: # returns a hash with all desired display languages
3878: #
3879:
3880: sub display_languages {
3881: my %languages=();
1.695 raeburn 3882: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3883: $languages{$lang}=1;
1.97 www 3884: }
3885: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3886: if ($env{'form.displaylanguage'}) {
1.356 albertel 3887: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3888: $languages{$lang}=1;
1.97 www 3889: }
3890: }
3891: return %languages;
1.14 harris41 3892: }
3893:
1.582 albertel 3894: sub languages {
3895: my ($possible_langs) = @_;
1.695 raeburn 3896: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3897: if (!ref($possible_langs)) {
3898: if( wantarray ) {
3899: return @preferred_langs;
3900: } else {
3901: return $preferred_langs[0];
3902: }
3903: }
3904: my %possibilities = map { $_ => 1 } (@$possible_langs);
3905: my @preferred_possibilities;
3906: foreach my $preferred_lang (@preferred_langs) {
3907: if (exists($possibilities{$preferred_lang})) {
3908: push(@preferred_possibilities, $preferred_lang);
3909: }
3910: }
3911: if( wantarray ) {
3912: return @preferred_possibilities;
3913: }
3914: return $preferred_possibilities[0];
3915: }
3916:
1.742 raeburn 3917: sub user_lang {
3918: my ($touname,$toudom,$fromcid) = @_;
3919: my @userlangs;
3920: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3921: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3922: $env{'course.'.$fromcid.'.languages'}));
3923: } else {
3924: my %langhash = &getlangs($touname,$toudom);
3925: if ($langhash{'languages'} ne '') {
3926: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3927: } else {
3928: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3929: if ($domdefs{'lang_def'} ne '') {
3930: @userlangs = ($domdefs{'lang_def'});
3931: }
3932: }
3933: }
3934: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3935: my $user_lh = Apache::localize->get_handle(@languages);
3936: return $user_lh;
3937: }
3938:
3939:
1.112 bowersj2 3940: ###############################################################
3941: ## Student Answer Attempts ##
3942: ###############################################################
3943:
3944: =pod
3945:
3946: =head1 Alternate Problem Views
3947:
3948: =over 4
3949:
1.648 raeburn 3950: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3951: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3952:
3953: Return string with previous attempt on problem. Arguments:
3954:
3955: =over 4
3956:
3957: =item * $symb: Problem, including path
3958:
3959: =item * $username: username of the desired student
3960:
3961: =item * $domain: domain of the desired student
1.14 harris41 3962:
1.112 bowersj2 3963: =item * $course: Course ID
1.14 harris41 3964:
1.112 bowersj2 3965: =item * $getattempt: Leave blank for all attempts, otherwise put
3966: something
1.14 harris41 3967:
1.112 bowersj2 3968: =item * $regexp: if string matches this regexp, the string will be
3969: sent to $gradesub
1.14 harris41 3970:
1.112 bowersj2 3971: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3972:
1.1075.2.86 raeburn 3973: =item * $usec: section of the desired student
3974:
3975: =item * $identifier: counter for student (multiple students one problem) or
3976: problem (one student; whole sequence).
3977:
1.112 bowersj2 3978: =back
1.14 harris41 3979:
1.112 bowersj2 3980: The output string is a table containing all desired attempts, if any.
1.16 harris41 3981:
1.112 bowersj2 3982: =cut
1.1 albertel 3983:
3984: sub get_previous_attempt {
1.1075.2.86 raeburn 3985: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3986: my $prevattempts='';
1.43 ng 3987: no strict 'refs';
1.1 albertel 3988: if ($symb) {
1.3 albertel 3989: my (%returnhash)=
3990: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3991: if ($returnhash{'version'}) {
3992: my %lasthash=();
3993: my $version;
3994: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3995: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3996: if ($key =~ /\.rawrndseed$/) {
3997: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
3998: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
3999: } else {
4000: $lasthash{$key}=$returnhash{$version.':'.$key};
4001: }
1.19 harris41 4002: }
1.1 albertel 4003: }
1.596 albertel 4004: $prevattempts=&start_data_table().&start_data_table_header_row();
4005: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4006: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4007: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4008: foreach my $key (sort(keys(%lasthash))) {
4009: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4010: if ($#parts > 0) {
1.31 albertel 4011: my $data=$parts[-1];
1.989 raeburn 4012: next if ($data eq 'foilorder');
1.31 albertel 4013: pop(@parts);
1.1010 www 4014: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4015: if ($data eq 'type') {
4016: unless ($showsurv) {
4017: my $id = join(',',@parts);
4018: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4019: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4020: $lasthidden{$ign.'.'.$id} = 1;
4021: }
1.945 raeburn 4022: }
1.1075.2.86 raeburn 4023: if ($identifier ne '') {
4024: my $id = join(',',@parts);
4025: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4026: $domain,$username,$usec,undef,$course) =~ /^no/) {
4027: $hidestatus{$ign.'.'.$id} = 1;
4028: }
4029: }
4030: } elsif ($data eq 'regrader') {
4031: if (($identifier ne '') && (@parts)) {
4032: my $id = join(',',@parts);
4033: $regraded{$ign.'.'.$id} = 1;
4034: }
1.1010 www 4035: }
1.31 albertel 4036: } else {
1.41 ng 4037: if ($#parts == 0) {
4038: $prevattempts.='<th>'.$parts[0].'</th>';
4039: } else {
4040: $prevattempts.='<th>'.$ign.'</th>';
4041: }
1.31 albertel 4042: }
1.16 harris41 4043: }
1.596 albertel 4044: $prevattempts.=&end_data_table_header_row();
1.40 ng 4045: if ($getattempt eq '') {
1.1075.2.86 raeburn 4046: my (%solved,%resets,%probstatus);
4047: if (($identifier ne '') && (keys(%regraded) > 0)) {
4048: for ($version=1;$version<=$returnhash{'version'};$version++) {
4049: foreach my $id (keys(%regraded)) {
4050: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4051: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4052: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4053: push(@{$resets{$id}},$version);
4054: }
4055: }
4056: }
4057: }
1.40 ng 4058: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4059: my (@hidden,@unsolved);
1.945 raeburn 4060: if (%typeparts) {
4061: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4062: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4063: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4064: push(@hidden,$id);
1.1075.2.86 raeburn 4065: } elsif ($identifier ne '') {
4066: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4067: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4068: ($hidestatus{$id})) {
4069: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4070: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4071: push(@{$solved{$id}},$version);
4072: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4073: (ref($solved{$id}) eq 'ARRAY')) {
4074: my $skip;
4075: if (ref($resets{$id}) eq 'ARRAY') {
4076: foreach my $reset (@{$resets{$id}}) {
4077: if ($reset > $solved{$id}[-1]) {
4078: $skip=1;
4079: last;
4080: }
4081: }
4082: }
4083: unless ($skip) {
4084: my ($ign,$partslist) = split(/\./,$id,2);
4085: push(@unsolved,$partslist);
4086: }
4087: }
4088: }
1.945 raeburn 4089: }
4090: }
4091: }
4092: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4093: '<td>'.&mt('Transaction [_1]',$version);
4094: if (@unsolved) {
4095: $prevattempts .= '<span class="LC_nobreak"><label>'.
4096: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4097: &mt('Hide').'</label></span>';
4098: }
4099: $prevattempts .= '</td>';
1.945 raeburn 4100: if (@hidden) {
4101: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4102: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4103: my $hide;
4104: foreach my $id (@hidden) {
4105: if ($key =~ /^\Q$id\E/) {
4106: $hide = 1;
4107: last;
4108: }
4109: }
4110: if ($hide) {
4111: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4112: if (($data eq 'award') || ($data eq 'awarddetail')) {
4113: my $value = &format_previous_attempt_value($key,
4114: $returnhash{$version.':'.$key});
4115: $prevattempts.='<td>'.$value.' </td>';
4116: } else {
4117: $prevattempts.='<td> </td>';
4118: }
4119: } else {
4120: if ($key =~ /\./) {
1.1075.2.91 raeburn 4121: my $value = $returnhash{$version.':'.$key};
4122: if ($key =~ /\.rndseed$/) {
4123: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4124: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4125: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4126: }
4127: }
4128: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4129: ' </td>';
1.945 raeburn 4130: } else {
4131: $prevattempts.='<td> </td>';
4132: }
4133: }
4134: }
4135: } else {
4136: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4137: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4138: my $value = $returnhash{$version.':'.$key};
4139: if ($key =~ /\.rndseed$/) {
4140: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4141: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4142: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4143: }
4144: }
4145: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4146: ' </td>';
1.945 raeburn 4147: }
4148: }
4149: $prevattempts.=&end_data_table_row();
1.40 ng 4150: }
1.1 albertel 4151: }
1.945 raeburn 4152: my @currhidden = keys(%lasthidden);
1.596 albertel 4153: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4154: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4155: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4156: if (%typeparts) {
4157: my $hidden;
4158: foreach my $id (@currhidden) {
4159: if ($key =~ /^\Q$id\E/) {
4160: $hidden = 1;
4161: last;
4162: }
4163: }
4164: if ($hidden) {
4165: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4166: if (($data eq 'award') || ($data eq 'awarddetail')) {
4167: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4168: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4169: $value = &$gradesub($value);
4170: }
4171: $prevattempts.='<td>'.$value.' </td>';
4172: } else {
4173: $prevattempts.='<td> </td>';
4174: }
4175: } else {
4176: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4177: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4178: $value = &$gradesub($value);
4179: }
4180: $prevattempts.='<td>'.$value.' </td>';
4181: }
4182: } else {
4183: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4184: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4185: $value = &$gradesub($value);
4186: }
4187: $prevattempts.='<td>'.$value.' </td>';
4188: }
1.16 harris41 4189: }
1.596 albertel 4190: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4191: } else {
1.596 albertel 4192: $prevattempts=
4193: &start_data_table().&start_data_table_row().
4194: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4195: &end_data_table_row().&end_data_table();
1.1 albertel 4196: }
4197: } else {
1.596 albertel 4198: $prevattempts=
4199: &start_data_table().&start_data_table_row().
4200: '<td>'.&mt('No data.').'</td>'.
4201: &end_data_table_row().&end_data_table();
1.1 albertel 4202: }
1.10 albertel 4203: }
4204:
1.581 albertel 4205: sub format_previous_attempt_value {
4206: my ($key,$value) = @_;
1.1011 www 4207: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4208: $value = &Apache::lonlocal::locallocaltime($value);
4209: } elsif (ref($value) eq 'ARRAY') {
4210: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4211: } elsif ($key =~ /answerstring$/) {
4212: my %answers = &Apache::lonnet::str2hash($value);
4213: my @anskeys = sort(keys(%answers));
4214: if (@anskeys == 1) {
4215: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4216: if ($answer =~ m{\0}) {
4217: $answer =~ s{\0}{,}g;
1.988 raeburn 4218: }
4219: my $tag_internal_answer_name = 'INTERNAL';
4220: if ($anskeys[0] eq $tag_internal_answer_name) {
4221: $value = $answer;
4222: } else {
4223: $value = $anskeys[0].'='.$answer;
4224: }
4225: } else {
4226: foreach my $ans (@anskeys) {
4227: my $answer = $answers{$ans};
1.1001 raeburn 4228: if ($answer =~ m{\0}) {
4229: $answer =~ s{\0}{,}g;
1.988 raeburn 4230: }
4231: $value .= $ans.'='.$answer.'<br />';;
4232: }
4233: }
1.581 albertel 4234: } else {
4235: $value = &unescape($value);
4236: }
4237: return $value;
4238: }
4239:
4240:
1.107 albertel 4241: sub relative_to_absolute {
4242: my ($url,$output)=@_;
4243: my $parser=HTML::TokeParser->new(\$output);
4244: my $token;
4245: my $thisdir=$url;
4246: my @rlinks=();
4247: while ($token=$parser->get_token) {
4248: if ($token->[0] eq 'S') {
4249: if ($token->[1] eq 'a') {
4250: if ($token->[2]->{'href'}) {
4251: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4252: }
4253: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4254: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4255: } elsif ($token->[1] eq 'base') {
4256: $thisdir=$token->[2]->{'href'};
4257: }
4258: }
4259: }
4260: $thisdir=~s-/[^/]*$--;
1.356 albertel 4261: foreach my $link (@rlinks) {
1.726 raeburn 4262: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4263: ($link=~/^\//) ||
4264: ($link=~/^javascript:/i) ||
4265: ($link=~/^mailto:/i) ||
4266: ($link=~/^\#/)) {
4267: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4268: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4269: }
4270: }
4271: # -------------------------------------------------- Deal with Applet codebases
4272: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4273: return $output;
4274: }
4275:
1.112 bowersj2 4276: =pod
4277:
1.648 raeburn 4278: =item * &get_student_view()
1.112 bowersj2 4279:
4280: show a snapshot of what student was looking at
4281:
4282: =cut
4283:
1.10 albertel 4284: sub get_student_view {
1.186 albertel 4285: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4286: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4287: my (%form);
1.10 albertel 4288: my @elements=('symb','courseid','domain','username');
4289: foreach my $element (@elements) {
1.186 albertel 4290: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4291: }
1.186 albertel 4292: if (defined($moreenv)) {
4293: %form=(%form,%{$moreenv});
4294: }
1.236 albertel 4295: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4296: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4297: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4298: $userview=~s/\<body[^\>]*\>//gi;
4299: $userview=~s/\<\/body\>//gi;
4300: $userview=~s/\<html\>//gi;
4301: $userview=~s/\<\/html\>//gi;
4302: $userview=~s/\<head\>//gi;
4303: $userview=~s/\<\/head\>//gi;
4304: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4305: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4306: if (wantarray) {
4307: return ($userview,$response);
4308: } else {
4309: return $userview;
4310: }
4311: }
4312:
4313: sub get_student_view_with_retries {
4314: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4315:
4316: my $ok = 0; # True if we got a good response.
4317: my $content;
4318: my $response;
4319:
4320: # Try to get the student_view done. within the retries count:
4321:
4322: do {
4323: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4324: $ok = $response->is_success;
4325: if (!$ok) {
4326: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4327: }
4328: $retries--;
4329: } while (!$ok && ($retries > 0));
4330:
4331: if (!$ok) {
4332: $content = ''; # On error return an empty content.
4333: }
1.651 www 4334: if (wantarray) {
4335: return ($content, $response);
4336: } else {
4337: return $content;
4338: }
1.11 albertel 4339: }
4340:
1.112 bowersj2 4341: =pod
4342:
1.648 raeburn 4343: =item * &get_student_answers()
1.112 bowersj2 4344:
4345: show a snapshot of how student was answering problem
4346:
4347: =cut
4348:
1.11 albertel 4349: sub get_student_answers {
1.100 sakharuk 4350: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4351: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4352: my (%moreenv);
1.11 albertel 4353: my @elements=('symb','courseid','domain','username');
4354: foreach my $element (@elements) {
1.186 albertel 4355: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4356: }
1.186 albertel 4357: $moreenv{'grade_target'}='answer';
4358: %moreenv=(%form,%moreenv);
1.497 raeburn 4359: $feedurl = &Apache::lonnet::clutter($feedurl);
4360: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4361: return $userview;
1.1 albertel 4362: }
1.116 albertel 4363:
4364: =pod
4365:
4366: =item * &submlink()
4367:
1.242 albertel 4368: Inputs: $text $uname $udom $symb $target
1.116 albertel 4369:
4370: Returns: A link to grades.pm such as to see the SUBM view of a student
4371:
4372: =cut
4373:
4374: ###############################################
4375: sub submlink {
1.242 albertel 4376: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4377: if (!($uname && $udom)) {
4378: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4379: &Apache::lonnet::whichuser($symb);
1.116 albertel 4380: if (!$symb) { $symb=$cursymb; }
4381: }
1.254 matthew 4382: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4383: $symb=&escape($symb);
1.960 bisitz 4384: if ($target) { $target=" target=\"$target\""; }
4385: return
4386: '<a href="/adm/grades?command=submission'.
4387: '&symb='.$symb.
4388: '&student='.$uname.
4389: '&userdom='.$udom.'"'.
4390: $target.'>'.$text.'</a>';
1.242 albertel 4391: }
4392: ##############################################
4393:
4394: =pod
4395:
4396: =item * &pgrdlink()
4397:
4398: Inputs: $text $uname $udom $symb $target
4399:
4400: Returns: A link to grades.pm such as to see the PGRD view of a student
4401:
4402: =cut
4403:
4404: ###############################################
4405: sub pgrdlink {
4406: my $link=&submlink(@_);
4407: $link=~s/(&command=submission)/$1&showgrading=yes/;
4408: return $link;
4409: }
4410: ##############################################
4411:
4412: =pod
4413:
4414: =item * &pprmlink()
4415:
4416: Inputs: $text $uname $udom $symb $target
4417:
4418: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4419: student and a specific resource
1.242 albertel 4420:
4421: =cut
4422:
4423: ###############################################
4424: sub pprmlink {
4425: my ($text,$uname,$udom,$symb,$target)=@_;
4426: if (!($uname && $udom)) {
4427: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4428: &Apache::lonnet::whichuser($symb);
1.242 albertel 4429: if (!$symb) { $symb=$cursymb; }
4430: }
1.254 matthew 4431: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4432: $symb=&escape($symb);
1.242 albertel 4433: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4434: return '<a href="/adm/parmset?command=set&'.
4435: 'symb='.$symb.'&uname='.$uname.
4436: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4437: }
4438: ##############################################
1.37 matthew 4439:
1.112 bowersj2 4440: =pod
4441:
4442: =back
4443:
4444: =cut
4445:
1.37 matthew 4446: ###############################################
1.51 www 4447:
4448:
4449: sub timehash {
1.687 raeburn 4450: my ($thistime) = @_;
4451: my $timezone = &Apache::lonlocal::gettimezone();
4452: my $dt = DateTime->from_epoch(epoch => $thistime)
4453: ->set_time_zone($timezone);
4454: my $wday = $dt->day_of_week();
4455: if ($wday == 7) { $wday = 0; }
4456: return ( 'second' => $dt->second(),
4457: 'minute' => $dt->minute(),
4458: 'hour' => $dt->hour(),
4459: 'day' => $dt->day_of_month(),
4460: 'month' => $dt->month(),
4461: 'year' => $dt->year(),
4462: 'weekday' => $wday,
4463: 'dayyear' => $dt->day_of_year(),
4464: 'dlsav' => $dt->is_dst() );
1.51 www 4465: }
4466:
1.370 www 4467: sub utc_string {
4468: my ($date)=@_;
1.371 www 4469: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4470: }
4471:
1.51 www 4472: sub maketime {
4473: my %th=@_;
1.687 raeburn 4474: my ($epoch_time,$timezone,$dt);
4475: $timezone = &Apache::lonlocal::gettimezone();
4476: eval {
4477: $dt = DateTime->new( year => $th{'year'},
4478: month => $th{'month'},
4479: day => $th{'day'},
4480: hour => $th{'hour'},
4481: minute => $th{'minute'},
4482: second => $th{'second'},
4483: time_zone => $timezone,
4484: );
4485: };
4486: if (!$@) {
4487: $epoch_time = $dt->epoch;
4488: if ($epoch_time) {
4489: return $epoch_time;
4490: }
4491: }
1.51 www 4492: return POSIX::mktime(
4493: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4494: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4495: }
4496:
4497: #########################################
1.51 www 4498:
4499: sub findallcourses {
1.482 raeburn 4500: my ($roles,$uname,$udom) = @_;
1.355 albertel 4501: my %roles;
4502: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4503: my %courses;
1.51 www 4504: my $now=time;
1.482 raeburn 4505: if (!defined($uname)) {
4506: $uname = $env{'user.name'};
4507: }
4508: if (!defined($udom)) {
4509: $udom = $env{'user.domain'};
4510: }
4511: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4512: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4513: if (!%roles) {
4514: %roles = (
4515: cc => 1,
1.907 raeburn 4516: co => 1,
1.482 raeburn 4517: in => 1,
4518: ep => 1,
4519: ta => 1,
4520: cr => 1,
4521: st => 1,
4522: );
4523: }
4524: foreach my $entry (keys(%roleshash)) {
4525: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4526: if ($trole =~ /^cr/) {
4527: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4528: } else {
4529: next if (!exists($roles{$trole}));
4530: }
4531: if ($tend) {
4532: next if ($tend < $now);
4533: }
4534: if ($tstart) {
4535: next if ($tstart > $now);
4536: }
1.1058 raeburn 4537: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4538: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4539: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4540: if ($secpart eq '') {
4541: ($cnum,$role) = split(/_/,$cnumpart);
4542: $sec = 'none';
1.1058 raeburn 4543: $value .= $cnum.'/';
1.482 raeburn 4544: } else {
4545: $cnum = $cnumpart;
4546: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4547: $value .= $cnum.'/'.$sec;
4548: }
4549: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4550: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4551: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4552: }
4553: } else {
4554: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4555: }
1.482 raeburn 4556: }
4557: } else {
4558: foreach my $key (keys(%env)) {
1.483 albertel 4559: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4560: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4561: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4562: next if ($role eq 'ca' || $role eq 'aa');
4563: next if (%roles && !exists($roles{$role}));
4564: my ($starttime,$endtime)=split(/\./,$env{$key});
4565: my $active=1;
4566: if ($starttime) {
4567: if ($now<$starttime) { $active=0; }
4568: }
4569: if ($endtime) {
4570: if ($now>$endtime) { $active=0; }
4571: }
4572: if ($active) {
1.1058 raeburn 4573: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4574: if ($sec eq '') {
4575: $sec = 'none';
1.1058 raeburn 4576: } else {
4577: $value .= $sec;
4578: }
4579: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4580: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4581: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4582: }
4583: } else {
4584: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4585: }
1.474 raeburn 4586: }
4587: }
1.51 www 4588: }
4589: }
1.474 raeburn 4590: return %courses;
1.51 www 4591: }
1.37 matthew 4592:
1.54 www 4593: ###############################################
1.474 raeburn 4594:
4595: sub blockcheck {
1.1075.2.73 raeburn 4596: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4597:
1.1075.2.73 raeburn 4598: if (defined($udom) && defined($uname)) {
4599: # If uname and udom are for a course, check for blocks in the course.
4600: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4601: my ($startblock,$endblock,$triggerblock) =
4602: &get_blocks($setters,$activity,$udom,$uname,$url);
4603: return ($startblock,$endblock,$triggerblock);
4604: }
4605: } else {
1.490 raeburn 4606: $udom = $env{'user.domain'};
4607: $uname = $env{'user.name'};
4608: }
4609:
1.502 raeburn 4610: my $startblock = 0;
4611: my $endblock = 0;
1.1062 raeburn 4612: my $triggerblock = '';
1.482 raeburn 4613: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4614:
1.490 raeburn 4615: # If uname is for a user, and activity is course-specific, i.e.,
4616: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4617:
1.490 raeburn 4618: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4619: $activity eq 'groups' || $activity eq 'printout') &&
4620: ($env{'request.course.id'})) {
1.490 raeburn 4621: foreach my $key (keys(%live_courses)) {
4622: if ($key ne $env{'request.course.id'}) {
4623: delete($live_courses{$key});
4624: }
4625: }
4626: }
4627:
4628: my $otheruser = 0;
4629: my %own_courses;
4630: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4631: # Resource belongs to user other than current user.
4632: $otheruser = 1;
4633: # Gather courses for current user
4634: %own_courses =
4635: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4636: }
4637:
4638: # Gather active course roles - course coordinator, instructor,
4639: # exam proctor, ta, student, or custom role.
1.474 raeburn 4640:
4641: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4642: my ($cdom,$cnum);
4643: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4644: $cdom = $env{'course.'.$course.'.domain'};
4645: $cnum = $env{'course.'.$course.'.num'};
4646: } else {
1.490 raeburn 4647: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4648: }
4649: my $no_ownblock = 0;
4650: my $no_userblock = 0;
1.533 raeburn 4651: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4652: # Check if current user has 'evb' priv for this
4653: if (defined($own_courses{$course})) {
4654: foreach my $sec (keys(%{$own_courses{$course}})) {
4655: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4656: if ($sec ne 'none') {
4657: $checkrole .= '/'.$sec;
4658: }
4659: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4660: $no_ownblock = 1;
4661: last;
4662: }
4663: }
4664: }
4665: # if they have 'evb' priv and are currently not playing student
4666: next if (($no_ownblock) &&
4667: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4668: }
1.474 raeburn 4669: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4670: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4671: if ($sec ne 'none') {
1.482 raeburn 4672: $checkrole .= '/'.$sec;
1.474 raeburn 4673: }
1.490 raeburn 4674: if ($otheruser) {
4675: # Resource belongs to user other than current user.
4676: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4677: my (%allroles,%userroles);
4678: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4679: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4680: my ($trole,$tdom,$tnum,$tsec);
4681: if ($entry =~ /^cr/) {
4682: ($trole,$tdom,$tnum,$tsec) =
4683: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4684: } else {
4685: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4686: }
4687: my ($spec,$area,$trest);
4688: $area = '/'.$tdom.'/'.$tnum;
4689: $trest = $tnum;
4690: if ($tsec ne '') {
4691: $area .= '/'.$tsec;
4692: $trest .= '/'.$tsec;
4693: }
4694: $spec = $trole.'.'.$area;
4695: if ($trole =~ /^cr/) {
4696: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4697: $tdom,$spec,$trest,$area);
4698: } else {
4699: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4700: $tdom,$spec,$trest,$area);
4701: }
4702: }
1.1075.2.124 raeburn 4703: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4704: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4705: if ($1) {
4706: $no_userblock = 1;
4707: last;
4708: }
1.486 raeburn 4709: }
4710: }
1.490 raeburn 4711: } else {
4712: # Resource belongs to current user
4713: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4714: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4715: $no_ownblock = 1;
4716: last;
4717: }
1.474 raeburn 4718: }
4719: }
4720: # if they have the evb priv and are currently not playing student
1.482 raeburn 4721: next if (($no_ownblock) &&
1.491 albertel 4722: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4723: next if ($no_userblock);
1.474 raeburn 4724:
1.866 kalberla 4725: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4726: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4727:
1.1062 raeburn 4728: my ($start,$end,$trigger) =
4729: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4730: if (($start != 0) &&
4731: (($startblock == 0) || ($startblock > $start))) {
4732: $startblock = $start;
1.1062 raeburn 4733: if ($trigger ne '') {
4734: $triggerblock = $trigger;
4735: }
1.502 raeburn 4736: }
4737: if (($end != 0) &&
4738: (($endblock == 0) || ($endblock < $end))) {
4739: $endblock = $end;
1.1062 raeburn 4740: if ($trigger ne '') {
4741: $triggerblock = $trigger;
4742: }
1.502 raeburn 4743: }
1.490 raeburn 4744: }
1.1062 raeburn 4745: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4746: }
4747:
4748: sub get_blocks {
1.1062 raeburn 4749: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4750: my $startblock = 0;
4751: my $endblock = 0;
1.1062 raeburn 4752: my $triggerblock = '';
1.490 raeburn 4753: my $course = $cdom.'_'.$cnum;
4754: $setters->{$course} = {};
4755: $setters->{$course}{'staff'} = [];
4756: $setters->{$course}{'times'} = [];
1.1062 raeburn 4757: $setters->{$course}{'triggers'} = [];
4758: my (@blockers,%triggered);
4759: my $now = time;
4760: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4761: if ($activity eq 'docs') {
4762: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4763: foreach my $block (@blockers) {
4764: if ($block =~ /^firstaccess____(.+)$/) {
4765: my $item = $1;
4766: my $type = 'map';
4767: my $timersymb = $item;
4768: if ($item eq 'course') {
4769: $type = 'course';
4770: } elsif ($item =~ /___\d+___/) {
4771: $type = 'resource';
4772: } else {
4773: $timersymb = &Apache::lonnet::symbread($item);
4774: }
4775: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4776: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4777: $triggered{$block} = {
4778: start => $start,
4779: end => $end,
4780: type => $type,
4781: };
4782: }
4783: }
4784: } else {
4785: foreach my $block (keys(%commblocks)) {
4786: if ($block =~ m/^(\d+)____(\d+)$/) {
4787: my ($start,$end) = ($1,$2);
4788: if ($start <= time && $end >= time) {
4789: if (ref($commblocks{$block}) eq 'HASH') {
4790: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4791: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4792: unless(grep(/^\Q$block\E$/,@blockers)) {
4793: push(@blockers,$block);
4794: }
4795: }
4796: }
4797: }
4798: }
4799: } elsif ($block =~ /^firstaccess____(.+)$/) {
4800: my $item = $1;
4801: my $timersymb = $item;
4802: my $type = 'map';
4803: if ($item eq 'course') {
4804: $type = 'course';
4805: } elsif ($item =~ /___\d+___/) {
4806: $type = 'resource';
4807: } else {
4808: $timersymb = &Apache::lonnet::symbread($item);
4809: }
4810: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4811: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4812: if ($start && $end) {
4813: if (($start <= time) && ($end >= time)) {
4814: unless (grep(/^\Q$block\E$/,@blockers)) {
4815: push(@blockers,$block);
4816: $triggered{$block} = {
4817: start => $start,
4818: end => $end,
4819: type => $type,
4820: };
4821: }
4822: }
1.490 raeburn 4823: }
1.1062 raeburn 4824: }
4825: }
4826: }
4827: foreach my $blocker (@blockers) {
4828: my ($staff_name,$staff_dom,$title,$blocks) =
4829: &parse_block_record($commblocks{$blocker});
4830: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4831: my ($start,$end,$triggertype);
4832: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4833: ($start,$end) = ($1,$2);
4834: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4835: $start = $triggered{$blocker}{'start'};
4836: $end = $triggered{$blocker}{'end'};
4837: $triggertype = $triggered{$blocker}{'type'};
4838: }
4839: if ($start) {
4840: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4841: if ($triggertype) {
4842: push(@{$$setters{$course}{'triggers'}},$triggertype);
4843: } else {
4844: push(@{$$setters{$course}{'triggers'}},0);
4845: }
4846: if ( ($startblock == 0) || ($startblock > $start) ) {
4847: $startblock = $start;
4848: if ($triggertype) {
4849: $triggerblock = $blocker;
1.474 raeburn 4850: }
4851: }
1.1062 raeburn 4852: if ( ($endblock == 0) || ($endblock < $end) ) {
4853: $endblock = $end;
4854: if ($triggertype) {
4855: $triggerblock = $blocker;
4856: }
4857: }
1.474 raeburn 4858: }
4859: }
1.1062 raeburn 4860: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4861: }
4862:
4863: sub parse_block_record {
4864: my ($record) = @_;
4865: my ($setuname,$setudom,$title,$blocks);
4866: if (ref($record) eq 'HASH') {
4867: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4868: $title = &unescape($record->{'event'});
4869: $blocks = $record->{'blocks'};
4870: } else {
4871: my @data = split(/:/,$record,3);
4872: if (scalar(@data) eq 2) {
4873: $title = $data[1];
4874: ($setuname,$setudom) = split(/@/,$data[0]);
4875: } else {
4876: ($setuname,$setudom,$title) = @data;
4877: }
4878: $blocks = { 'com' => 'on' };
4879: }
4880: return ($setuname,$setudom,$title,$blocks);
4881: }
4882:
1.854 kalberla 4883: sub blocking_status {
1.1075.2.73 raeburn 4884: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4885: my %setters;
1.890 droeschl 4886:
1.1061 raeburn 4887: # check for active blocking
1.1062 raeburn 4888: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4889: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4890: my $blocked = 0;
4891: if ($startblock && $endblock) {
4892: $blocked = 1;
4893: }
1.890 droeschl 4894:
1.1061 raeburn 4895: # caller just wants to know whether a block is active
4896: if (!wantarray) { return $blocked; }
4897:
4898: # build a link to a popup window containing the details
4899: my $querystring = "?activity=$activity";
4900: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4901: if (($activity eq 'port') || ($activity eq 'passwd')) {
4902: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4903: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4904: } elsif ($activity eq 'docs') {
4905: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4906: }
1.1061 raeburn 4907:
4908: my $output .= <<'END_MYBLOCK';
4909: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4910: var options = "width=" + w + ",height=" + h + ",";
4911: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4912: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4913: var newWin = window.open(url, wdwName, options);
4914: newWin.focus();
4915: }
1.890 droeschl 4916: END_MYBLOCK
1.854 kalberla 4917:
1.1061 raeburn 4918: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4919:
1.1061 raeburn 4920: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4921: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4922: my $class = 'LC_comblock';
1.1062 raeburn 4923: if ($activity eq 'docs') {
4924: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4925: $class = '';
1.1063 raeburn 4926: } elsif ($activity eq 'printout') {
4927: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 4928: } elsif ($activity eq 'passwd') {
4929: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4930: }
1.1061 raeburn 4931: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4932: <div class='$class'>
1.869 kalberla 4933: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4934: title='$text'>
4935: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4936: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4937: title='$text'>$text</a>
1.867 kalberla 4938: </div>
4939:
4940: END_BLOCK
1.474 raeburn 4941:
1.1061 raeburn 4942: return ($blocked, $output);
1.854 kalberla 4943: }
1.490 raeburn 4944:
1.60 matthew 4945: ###############################################
4946:
1.682 raeburn 4947: sub check_ip_acc {
1.1075.2.105 raeburn 4948: my ($acc,$clientip)=@_;
1.682 raeburn 4949: &Apache::lonxml::debug("acc is $acc");
4950: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4951: return 1;
4952: }
4953: my $allowed=0;
1.1075.2.111 raeburn 4954: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 4955:
4956: my $name;
4957: foreach my $pattern (split(',',$acc)) {
4958: $pattern =~ s/^\s*//;
4959: $pattern =~ s/\s*$//;
4960: if ($pattern =~ /\*$/) {
4961: #35.8.*
4962: $pattern=~s/\*//;
4963: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4964: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4965: #35.8.3.[34-56]
4966: my $low=$2;
4967: my $high=$3;
4968: $pattern=$1;
4969: if ($ip =~ /^\Q$pattern\E/) {
4970: my $last=(split(/\./,$ip))[3];
4971: if ($last <=$high && $last >=$low) { $allowed=1; }
4972: }
4973: } elsif ($pattern =~ /^\*/) {
4974: #*.msu.edu
4975: $pattern=~s/\*//;
4976: if (!defined($name)) {
4977: use Socket;
4978: my $netaddr=inet_aton($ip);
4979: ($name)=gethostbyaddr($netaddr,AF_INET);
4980: }
4981: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4982: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4983: #127.0.0.1
4984: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4985: } else {
4986: #some.name.com
4987: if (!defined($name)) {
4988: use Socket;
4989: my $netaddr=inet_aton($ip);
4990: ($name)=gethostbyaddr($netaddr,AF_INET);
4991: }
4992: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4993: }
4994: if ($allowed) { last; }
4995: }
4996: return $allowed;
4997: }
4998:
1.1075.2.127. .1(raebu 4999:17): sub check_slotip_acc {
5000:17): my ($acc,$clientip)=@_;
5001:17): &Apache::lonxml::debug("acc is $acc");
5002:17): if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5003:17): return 1;
5004:17): }
5005:17): my $allowed;
5006:17): my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
5007:17):
5008:17): my $name;
5009:17): my %access = (
5010:17): allowfrom => 1,
5011:17): denyfrom => 0,
5012:17): );
5013:17): my @allows;
5014:17): my @denies;
5015:17): foreach my $item (split(',',$acc)) {
5016:17): $item =~ s/^\s*//;
5017:17): $item =~ s/\s*$//;
5018:17): my $pattern;
5019:17): if ($item =~ /^\!(.+)$/) {
5020:17): push(@denies,$1);
5021:17): } else {
5022:17): push(@allows,$item);
5023:17): }
5024:17): }
5025:17): my $numdenies = scalar(@denies);
5026:17): my $numallows = scalar(@allows);
5027:17): my $count = 0;
5028:17): foreach my $pattern (@denies,@allows) {
5029:17): $count ++;
5030:17): my $acctype = 'allowfrom';
5031:17): if ($count <= $numdenies) {
5032:17): $acctype = 'denyfrom';
5033:17): }
5034:17): if ($pattern =~ /\*$/) {
5035:17): #35.8.*
5036:17): $pattern=~s/\*//;
5037:17): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
5038:17): } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5039:17): #35.8.3.[34-56]
5040:17): my $low=$2;
5041:17): my $high=$3;
5042:17): $pattern=$1;
5043:17): if ($ip =~ /^\Q$pattern\E/) {
5044:17): my $last=(split(/\./,$ip))[3];
5045:17): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
5046:17): }
5047:17): } elsif ($pattern =~ /^\*/) {
5048:17): #*.msu.edu
5049:17): $pattern=~s/\*//;
5050:17): if (!defined($name)) {
5051:17): use Socket;
5052:17): my $netaddr=inet_aton($ip);
5053:17): ($name)=gethostbyaddr($netaddr,AF_INET);
5054:17): }
5055:17): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5056:17): } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5057:17): #127.0.0.1
5058:17): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
5059:17): } else {
5060:17): #some.name.com
5061:17): if (!defined($name)) {
5062:17): use Socket;
5063:17): my $netaddr=inet_aton($ip);
5064:17): ($name)=gethostbyaddr($netaddr,AF_INET);
5065:17): }
5066:17): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5067:17): }
5068:17): if ($allowed =~ /^(0|1)$/) { last; }
5069:17): }
5070:17): if ($allowed eq '') {
5071:17): if ($numdenies && !$numallows) {
5072:17): $allowed = 1;
5073:17): } else {
5074:17): $allowed = 0;
5075:17): }
5076:17): }
5077:17): return $allowed;
5078:17): }
5079:17):
1.682 raeburn 5080: ###############################################
5081:
1.60 matthew 5082: =pod
5083:
1.112 bowersj2 5084: =head1 Domain Template Functions
5085:
5086: =over 4
5087:
5088: =item * &determinedomain()
1.60 matthew 5089:
5090: Inputs: $domain (usually will be undef)
5091:
1.63 www 5092: Returns: Determines which domain should be used for designs
1.60 matthew 5093:
5094: =cut
1.54 www 5095:
1.60 matthew 5096: ###############################################
1.63 www 5097: sub determinedomain {
5098: my $domain=shift;
1.531 albertel 5099: if (! $domain) {
1.60 matthew 5100: # Determine domain if we have not been given one
1.893 raeburn 5101: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5102: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5103: if ($env{'request.role.domain'}) {
5104: $domain=$env{'request.role.domain'};
1.60 matthew 5105: }
5106: }
1.63 www 5107: return $domain;
5108: }
5109: ###############################################
1.517 raeburn 5110:
1.518 albertel 5111: sub devalidate_domconfig_cache {
5112: my ($udom)=@_;
5113: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5114: }
5115:
5116: # ---------------------- Get domain configuration for a domain
5117: sub get_domainconf {
5118: my ($udom) = @_;
5119: my $cachetime=1800;
5120: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5121: if (defined($cached)) { return %{$result}; }
5122:
5123: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5124: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5125: my (%designhash,%legacy);
1.518 albertel 5126: if (keys(%domconfig) > 0) {
5127: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5128: if (keys(%{$domconfig{'login'}})) {
5129: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5130: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5131: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5132: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5133: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5134: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5135: if ($key eq 'loginvia') {
5136: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5137: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5138: $designhash{$udom.'.login.loginvia'} = $server;
5139: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5140: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5141: } else {
5142: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5143: }
1.948 raeburn 5144: }
1.1075.2.87 raeburn 5145: } elsif ($key eq 'headtag') {
5146: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5147: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5148: }
1.946 raeburn 5149: }
1.1075.2.87 raeburn 5150: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5151: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5152: }
1.946 raeburn 5153: }
5154: }
5155: }
5156: } else {
5157: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5158: $designhash{$udom.'.login.'.$key.'_'.$img} =
5159: $domconfig{'login'}{$key}{$img};
5160: }
1.699 raeburn 5161: }
5162: } else {
5163: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5164: }
1.632 raeburn 5165: }
5166: } else {
5167: $legacy{'login'} = 1;
1.518 albertel 5168: }
1.632 raeburn 5169: } else {
5170: $legacy{'login'} = 1;
1.518 albertel 5171: }
5172: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5173: if (keys(%{$domconfig{'rolecolors'}})) {
5174: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5175: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5176: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5177: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5178: }
1.518 albertel 5179: }
5180: }
1.632 raeburn 5181: } else {
5182: $legacy{'rolecolors'} = 1;
1.518 albertel 5183: }
1.632 raeburn 5184: } else {
5185: $legacy{'rolecolors'} = 1;
1.518 albertel 5186: }
1.948 raeburn 5187: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5188: if ($domconfig{'autoenroll'}{'co-owners'}) {
5189: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5190: }
5191: }
1.632 raeburn 5192: if (keys(%legacy) > 0) {
5193: my %legacyhash = &get_legacy_domconf($udom);
5194: foreach my $item (keys(%legacyhash)) {
5195: if ($item =~ /^\Q$udom\E\.login/) {
5196: if ($legacy{'login'}) {
5197: $designhash{$item} = $legacyhash{$item};
5198: }
5199: } else {
5200: if ($legacy{'rolecolors'}) {
5201: $designhash{$item} = $legacyhash{$item};
5202: }
1.518 albertel 5203: }
5204: }
5205: }
1.632 raeburn 5206: } else {
5207: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5208: }
5209: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5210: $cachetime);
5211: return %designhash;
5212: }
5213:
1.632 raeburn 5214: sub get_legacy_domconf {
5215: my ($udom) = @_;
5216: my %legacyhash;
5217: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5218: my $designfile = $designdir.'/'.$udom.'.tab';
5219: if (-e $designfile) {
1.1075.2.127. .5(raebu 5220:18): if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5221: while (my $line = <$fh>) {
5222: next if ($line =~ /^\#/);
5223: chomp($line);
5224: my ($key,$val)=(split(/\=/,$line));
5225: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5226: }
5227: close($fh);
5228: }
5229: }
1.1026 raeburn 5230: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5231: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5232: }
5233: return %legacyhash;
5234: }
5235:
1.63 www 5236: =pod
5237:
1.112 bowersj2 5238: =item * &domainlogo()
1.63 www 5239:
5240: Inputs: $domain (usually will be undef)
5241:
5242: Returns: A link to a domain logo, if the domain logo exists.
5243: If the domain logo does not exist, a description of the domain.
5244:
5245: =cut
1.112 bowersj2 5246:
1.63 www 5247: ###############################################
5248: sub domainlogo {
1.517 raeburn 5249: my $domain = &determinedomain(shift);
1.518 albertel 5250: my %designhash = &get_domainconf($domain);
1.517 raeburn 5251: # See if there is a logo
5252: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5253: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5254: if ($imgsrc =~ m{^/(adm|res)/}) {
5255: if ($imgsrc =~ m{^/res/}) {
5256: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5257: &Apache::lonnet::repcopy($local_name);
5258: }
5259: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5260: }
5261: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5262: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5263: return &Apache::lonnet::domain($domain,'description');
1.59 www 5264: } else {
1.60 matthew 5265: return '';
1.59 www 5266: }
5267: }
1.63 www 5268: ##############################################
5269:
5270: =pod
5271:
1.112 bowersj2 5272: =item * &designparm()
1.63 www 5273:
5274: Inputs: $which parameter; $domain (usually will be undef)
5275:
5276: Returns: value of designparamter $which
5277:
5278: =cut
1.112 bowersj2 5279:
1.397 albertel 5280:
1.400 albertel 5281: ##############################################
1.397 albertel 5282: sub designparm {
5283: my ($which,$domain)=@_;
5284: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5285: return $env{'environment.color.'.$which};
1.96 www 5286: }
1.63 www 5287: $domain=&determinedomain($domain);
1.1016 raeburn 5288: my %domdesign;
5289: unless ($domain eq 'public') {
5290: %domdesign = &get_domainconf($domain);
5291: }
1.520 raeburn 5292: my $output;
1.517 raeburn 5293: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5294: $output = $domdesign{$domain.'.'.$which};
1.63 www 5295: } else {
1.520 raeburn 5296: $output = $defaultdesign{$which};
5297: }
5298: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5299: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5300: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5301: if ($output =~ m{^/res/}) {
5302: my $local_name = &Apache::lonnet::filelocation('',$output);
5303: &Apache::lonnet::repcopy($local_name);
5304: }
1.520 raeburn 5305: $output = &lonhttpdurl($output);
5306: }
1.63 www 5307: }
1.520 raeburn 5308: return $output;
1.63 www 5309: }
1.59 www 5310:
1.822 bisitz 5311: ##############################################
5312: =pod
5313:
1.832 bisitz 5314: =item * &authorspace()
5315:
1.1028 raeburn 5316: Inputs: $url (usually will be undef).
1.832 bisitz 5317:
1.1075.2.40 raeburn 5318: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5319: directory being viewed (or for which action is being taken).
5320: If $url is provided, and begins /priv/<domain>/<uname>
5321: the path will be that portion of the $context argument.
5322: Otherwise the path will be for the author space of the current
5323: user when the current role is author, or for that of the
5324: co-author/assistant co-author space when the current role
5325: is co-author or assistant co-author.
1.832 bisitz 5326:
5327: =cut
5328:
5329: sub authorspace {
1.1028 raeburn 5330: my ($url) = @_;
5331: if ($url ne '') {
5332: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5333: return $1;
5334: }
5335: }
1.832 bisitz 5336: my $caname = '';
1.1024 www 5337: my $cadom = '';
1.1028 raeburn 5338: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5339: ($cadom,$caname) =
1.832 bisitz 5340: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5341: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5342: $caname = $env{'user.name'};
1.1024 www 5343: $cadom = $env{'user.domain'};
1.832 bisitz 5344: }
1.1028 raeburn 5345: if (($caname ne '') && ($cadom ne '')) {
5346: return "/priv/$cadom/$caname/";
5347: }
5348: return;
1.832 bisitz 5349: }
5350:
5351: ##############################################
5352: =pod
5353:
1.822 bisitz 5354: =item * &head_subbox()
5355:
5356: Inputs: $content (contains HTML code with page functions, etc.)
5357:
5358: Returns: HTML div with $content
5359: To be included in page header
5360:
5361: =cut
5362:
5363: sub head_subbox {
5364: my ($content)=@_;
5365: my $output =
1.993 raeburn 5366: '<div class="LC_head_subbox">'
1.822 bisitz 5367: .$content
5368: .'</div>'
5369: }
5370:
5371: ##############################################
5372: =pod
5373:
5374: =item * &CSTR_pageheader()
5375:
1.1026 raeburn 5376: Input: (optional) filename from which breadcrumb trail is built.
5377: In most cases no input as needed, as $env{'request.filename'}
5378: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5379:
5380: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5381: To be included on Authoring Space pages
1.822 bisitz 5382:
5383: =cut
5384:
5385: sub CSTR_pageheader {
1.1026 raeburn 5386: my ($trailfile) = @_;
5387: if ($trailfile eq '') {
5388: $trailfile = $env{'request.filename'};
5389: }
5390:
5391: # this is for resources; directories have customtitle, and crumbs
5392: # and select recent are created in lonpubdir.pm
5393:
5394: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5395: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5396: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5397: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5398: $formaction =~ s{/+}{/}g;
1.822 bisitz 5399:
5400: my $parentpath = '';
5401: my $lastitem = '';
5402: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5403: $parentpath = $1;
5404: $lastitem = $2;
5405: } else {
5406: $lastitem = $thisdisfn;
5407: }
1.921 bisitz 5408:
5409: my $output =
1.822 bisitz 5410: '<div>'
5411: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5412: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5413: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5414: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5415: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5416:
5417: if ($lastitem) {
5418: $output .=
5419: '<span class="LC_filename">'
5420: .$lastitem
5421: .'</span>';
5422: }
5423: $output .=
5424: '<br />'
1.822 bisitz 5425: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5426: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5427: .'</form>'
5428: .&Apache::lonmenu::constspaceform()
5429: .'</div>';
1.921 bisitz 5430:
5431: return $output;
1.822 bisitz 5432: }
5433:
1.60 matthew 5434: ###############################################
5435: ###############################################
5436:
5437: =pod
5438:
1.112 bowersj2 5439: =back
5440:
1.549 albertel 5441: =head1 HTML Helpers
1.112 bowersj2 5442:
5443: =over 4
5444:
5445: =item * &bodytag()
1.60 matthew 5446:
5447: Returns a uniform header for LON-CAPA web pages.
5448:
5449: Inputs:
5450:
1.112 bowersj2 5451: =over 4
5452:
5453: =item * $title, A title to be displayed on the page.
5454:
5455: =item * $function, the current role (can be undef).
5456:
5457: =item * $addentries, extra parameters for the <body> tag.
5458:
5459: =item * $bodyonly, if defined, only return the <body> tag.
5460:
5461: =item * $domain, if defined, force a given domain.
5462:
5463: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5464: text interface only)
1.60 matthew 5465:
1.814 bisitz 5466: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5467: navigational links
1.317 albertel 5468:
1.338 albertel 5469: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5470:
1.1075.2.12 raeburn 5471: =item * $no_inline_link, if true and in remote mode, don't show the
5472: 'Switch To Inline Menu' link
5473:
1.460 albertel 5474: =item * $args, optional argument valid values are
5475: no_auto_mt_title -> prevents &mt()ing the title arg
5476:
1.1075.2.15 raeburn 5477: =item * $advtoolsref, optional argument, ref to an array containing
5478: inlineremote items to be added in "Functions" menu below
5479: breadcrumbs.
5480:
1.112 bowersj2 5481: =back
5482:
1.60 matthew 5483: Returns: A uniform header for LON-CAPA web pages.
5484: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5485: If $bodyonly is undef or zero, an html string containing a <body> tag and
5486: other decorations will be returned.
5487:
5488: =cut
5489:
1.54 www 5490: sub bodytag {
1.831 bisitz 5491: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5492: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5493:
1.954 raeburn 5494: my $public;
5495: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5496: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5497: $public = 1;
5498: }
1.460 albertel 5499: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5500: my $httphost = $args->{'use_absolute'};
1.339 albertel 5501:
1.183 matthew 5502: $function = &get_users_function() if (!$function);
1.339 albertel 5503: my $img = &designparm($function.'.img',$domain);
5504: my $font = &designparm($function.'.font',$domain);
5505: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5506:
1.803 bisitz 5507: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5508: 'bgcolor' => $pgbg,
1.339 albertel 5509: 'text' => $font,
5510: 'alink' => &designparm($function.'.alink',$domain),
5511: 'vlink' => &designparm($function.'.vlink',$domain),
5512: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5513: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5514:
1.63 www 5515: # role and realm
1.1075.2.68 raeburn 5516: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5517: if ($realm) {
5518: $realm = '/'.$realm;
5519: }
1.378 raeburn 5520: if ($role eq 'ca') {
1.479 albertel 5521: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5522: $realm = &plainname($rname,$rdom);
1.378 raeburn 5523: }
1.55 www 5524: # realm
1.258 albertel 5525: if ($env{'request.course.id'}) {
1.378 raeburn 5526: if ($env{'request.role'} !~ /^cr/) {
5527: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5528: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5529: if ($env{'request.role.desc'}) {
5530: $role = $env{'request.role.desc'};
5531: } else {
5532: $role = &mt('Helpdesk[_1]',' '.$2);
5533: }
1.1075.2.115 raeburn 5534: } else {
5535: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5536: }
1.898 raeburn 5537: if ($env{'request.course.sec'}) {
5538: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5539: }
1.359 albertel 5540: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5541: } else {
5542: $role = &Apache::lonnet::plaintext($role);
1.54 www 5543: }
1.433 albertel 5544:
1.359 albertel 5545: if (!$realm) { $realm=' '; }
1.330 albertel 5546:
1.438 albertel 5547: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5548:
1.101 www 5549: # construct main body tag
1.359 albertel 5550: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5551: &Apache::lontexconvert::init_math_support();
1.252 albertel 5552:
1.1075.2.38 raeburn 5553: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5554:
5555: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5556: return $bodytag;
1.1075.2.38 raeburn 5557: }
1.359 albertel 5558:
1.954 raeburn 5559: if ($public) {
1.433 albertel 5560: undef($role);
5561: }
1.359 albertel 5562:
1.762 bisitz 5563: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5564: #
5565: # Extra info if you are the DC
5566: my $dc_info = '';
5567: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5568: $env{'course.'.$env{'request.course.id'}.
5569: '.domain'}.'/'})) {
5570: my $cid = $env{'request.course.id'};
1.917 raeburn 5571: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5572: $dc_info =~ s/\s+$//;
1.359 albertel 5573: }
5574:
1.1075.2.108 raeburn 5575: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5576:
1.1075.2.13 raeburn 5577: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5578:
1.1075.2.38 raeburn 5579:
5580:
1.1075.2.21 raeburn 5581: my $funclist;
5582: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5583: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5584: Apache::lonmenu::serverform();
5585: my $forbodytag;
5586: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5587: $forcereg,$args->{'group'},
5588: $args->{'bread_crumbs'},
5589: $advtoolsref,'',\$forbodytag);
5590: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5591: $funclist = $forbodytag;
5592: }
5593: } else {
1.903 droeschl 5594:
5595: # if ($env{'request.state'} eq 'construct') {
5596: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5597: # }
5598:
1.1075.2.38 raeburn 5599: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5600: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5601:
1.1075.2.38 raeburn 5602: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5603:
1.916 droeschl 5604: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5605: if ($dc_info) {
5606: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5607: }
1.1075.2.38 raeburn 5608: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5609: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5610: return $bodytag;
5611: }
1.894 droeschl 5612:
1.927 raeburn 5613: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5614: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5615: }
1.916 droeschl 5616:
1.1075.2.38 raeburn 5617: $bodytag .= $right;
1.852 droeschl 5618:
1.917 raeburn 5619: if ($dc_info) {
5620: $dc_info = &dc_courseid_toggle($dc_info);
5621: }
5622: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5623:
1.1075.2.61 raeburn 5624: #if directed to not display the secondary menu, don't.
5625: if ($args->{'no_secondary_menu'}) {
5626: return $bodytag;
5627: }
1.903 droeschl 5628: #don't show menus for public users
1.954 raeburn 5629: if (!$public){
1.1075.2.52 raeburn 5630: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5631: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5632: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5633: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5634: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5635: $args->{'bread_crumbs'});
1.1075.2.116 raeburn 5636: } elsif ($forcereg) {
1.1075.2.22 raeburn 5637: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5638: $args->{'group'},
5639: $args->{'hide_buttons'});
1.1075.2.15 raeburn 5640: } else {
1.1075.2.21 raeburn 5641: my $forbodytag;
5642: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5643: $forcereg,$args->{'group'},
5644: $args->{'bread_crumbs'},
5645: $advtoolsref,'',\$forbodytag);
5646: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5647: $bodytag .= $forbodytag;
5648: }
1.920 raeburn 5649: }
1.903 droeschl 5650: }else{
5651: # this is to seperate menu from content when there's no secondary
5652: # menu. Especially needed for public accessible ressources.
5653: $bodytag .= '<hr style="clear:both" />';
5654: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5655: }
1.903 droeschl 5656:
1.235 raeburn 5657: return $bodytag;
1.1075.2.12 raeburn 5658: }
5659:
5660: #
5661: # Top frame rendering, Remote is up
5662: #
5663:
5664: my $imgsrc = $img;
5665: if ($img =~ /^\/adm/) {
5666: $imgsrc = &lonhttpdurl($img);
5667: }
5668: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5669:
1.1075.2.60 raeburn 5670: my $help=($no_inline_link?''
5671: :&Apache::loncommon::top_nav_help('Help'));
5672:
1.1075.2.12 raeburn 5673: # Explicit link to get inline menu
5674: my $menu= ($no_inline_link?''
5675: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5676:
5677: if ($dc_info) {
5678: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5679: }
5680:
1.1075.2.38 raeburn 5681: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5682: unless ($public) {
5683: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5684: undef,'LC_menubuttons_link');
5685: }
5686:
1.1075.2.12 raeburn 5687: unless ($env{'form.inhibitmenu'}) {
5688: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5689: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5690: <li>$help</li>
1.1075.2.12 raeburn 5691: <li>$menu</li>
5692: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5693: }
1.1075.2.13 raeburn 5694: if ($env{'request.state'} eq 'construct') {
5695: if (!$public){
5696: if ($env{'request.state'} eq 'construct') {
5697: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5698: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5699: &Apache::lonhtmlcommon::scripttag('','end').
5700: &Apache::lonmenu::innerregister($forcereg,
5701: $args->{'bread_crumbs'});
5702: }
5703: }
5704: }
1.1075.2.21 raeburn 5705: return $bodytag."\n".$funclist;
1.182 matthew 5706: }
5707:
1.917 raeburn 5708: sub dc_courseid_toggle {
5709: my ($dc_info) = @_;
1.980 raeburn 5710: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5711: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5712: &mt('(More ...)').'</a></span>'.
5713: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5714: }
5715:
1.330 albertel 5716: sub make_attr_string {
5717: my ($register,$attr_ref) = @_;
5718:
5719: if ($attr_ref && !ref($attr_ref)) {
5720: die("addentries Must be a hash ref ".
5721: join(':',caller(1))." ".
5722: join(':',caller(0))." ");
5723: }
5724:
5725: if ($register) {
1.339 albertel 5726: my ($on_load,$on_unload);
5727: foreach my $key (keys(%{$attr_ref})) {
5728: if (lc($key) eq 'onload') {
5729: $on_load.=$attr_ref->{$key}.';';
5730: delete($attr_ref->{$key});
5731:
5732: } elsif (lc($key) eq 'onunload') {
5733: $on_unload.=$attr_ref->{$key}.';';
5734: delete($attr_ref->{$key});
5735: }
5736: }
1.1075.2.12 raeburn 5737: if ($env{'environment.remote'} eq 'on') {
5738: $attr_ref->{'onload'} =
5739: &Apache::lonmenu::loadevents(). $on_load;
5740: $attr_ref->{'onunload'}=
5741: &Apache::lonmenu::unloadevents().$on_unload;
5742: } else {
5743: $attr_ref->{'onload'} = $on_load;
5744: $attr_ref->{'onunload'}= $on_unload;
5745: }
1.330 albertel 5746: }
1.339 albertel 5747:
1.330 albertel 5748: my $attr_string;
1.1075.2.56 raeburn 5749: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5750: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5751: }
5752: return $attr_string;
5753: }
5754:
5755:
1.182 matthew 5756: ###############################################
1.251 albertel 5757: ###############################################
5758:
5759: =pod
5760:
5761: =item * &endbodytag()
5762:
5763: Returns a uniform footer for LON-CAPA web pages.
5764:
1.635 raeburn 5765: Inputs: 1 - optional reference to an args hash
5766: If in the hash, key for noredirectlink has a value which evaluates to true,
5767: a 'Continue' link is not displayed if the page contains an
5768: internal redirect in the <head></head> section,
5769: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5770:
5771: =cut
5772:
5773: sub endbodytag {
1.635 raeburn 5774: my ($args) = @_;
1.1075.2.6 raeburn 5775: my $endbodytag;
5776: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5777: $endbodytag='</body>';
5778: }
1.315 albertel 5779: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5780: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5781: $endbodytag=
5782: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5783: &mt('Continue').'</a>'.
5784: $endbodytag;
5785: }
1.315 albertel 5786: }
1.251 albertel 5787: return $endbodytag;
5788: }
5789:
1.352 albertel 5790: =pod
5791:
5792: =item * &standard_css()
5793:
5794: Returns a style sheet
5795:
5796: Inputs: (all optional)
5797: domain -> force to color decorate a page for a specific
5798: domain
5799: function -> force usage of a specific rolish color scheme
5800: bgcolor -> override the default page bgcolor
5801:
5802: =cut
5803:
1.343 albertel 5804: sub standard_css {
1.345 albertel 5805: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5806: $function = &get_users_function() if (!$function);
5807: my $img = &designparm($function.'.img', $domain);
5808: my $tabbg = &designparm($function.'.tabbg', $domain);
5809: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5810: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5811: #second colour for later usage
1.345 albertel 5812: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5813: my $pgbg_or_bgcolor =
5814: $bgcolor ||
1.352 albertel 5815: &designparm($function.'.pgbg', $domain);
1.382 albertel 5816: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5817: my $alink = &designparm($function.'.alink', $domain);
5818: my $vlink = &designparm($function.'.vlink', $domain);
5819: my $link = &designparm($function.'.link', $domain);
5820:
1.602 albertel 5821: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5822: my $mono = 'monospace';
1.850 bisitz 5823: my $data_table_head = $sidebg;
5824: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5825: my $data_table_dark = '#E0E0E0';
1.470 banghart 5826: my $data_table_darker = '#CCCCCC';
1.349 albertel 5827: my $data_table_highlight = '#FFFF00';
1.352 albertel 5828: my $mail_new = '#FFBB77';
5829: my $mail_new_hover = '#DD9955';
5830: my $mail_read = '#BBBB77';
5831: my $mail_read_hover = '#999944';
5832: my $mail_replied = '#AAAA88';
5833: my $mail_replied_hover = '#888855';
5834: my $mail_other = '#99BBBB';
5835: my $mail_other_hover = '#669999';
1.391 albertel 5836: my $table_header = '#DDDDDD';
1.489 raeburn 5837: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5838: my $lg_border_color = '#C8C8C8';
1.952 onken 5839: my $button_hover = '#BF2317';
1.392 albertel 5840:
1.608 albertel 5841: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5842: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5843: : '0 3px 0 4px';
1.448 albertel 5844:
1.523 albertel 5845:
1.343 albertel 5846: return <<END;
1.947 droeschl 5847:
5848: /* needed for iframe to allow 100% height in FF */
5849: body, html {
5850: margin: 0;
5851: padding: 0 0.5%;
5852: height: 99%; /* to avoid scrollbars */
5853: }
5854:
1.795 www 5855: body {
1.911 bisitz 5856: font-family: $sans;
5857: line-height:130%;
5858: font-size:0.83em;
5859: color:$font;
1.795 www 5860: }
5861:
1.959 onken 5862: a:focus,
5863: a:focus img {
1.795 www 5864: color: red;
5865: }
1.698 harmsja 5866:
1.911 bisitz 5867: form, .inline {
5868: display: inline;
1.795 www 5869: }
1.721 harmsja 5870:
1.795 www 5871: .LC_right {
1.911 bisitz 5872: text-align:right;
1.795 www 5873: }
5874:
5875: .LC_middle {
1.911 bisitz 5876: vertical-align:middle;
1.795 www 5877: }
1.721 harmsja 5878:
1.1075.2.38 raeburn 5879: .LC_floatleft {
5880: float: left;
5881: }
5882:
5883: .LC_floatright {
5884: float: right;
5885: }
5886:
1.911 bisitz 5887: .LC_400Box {
5888: width:400px;
5889: }
1.721 harmsja 5890:
1.947 droeschl 5891: .LC_iframecontainer {
5892: width: 98%;
5893: margin: 0;
5894: position: fixed;
5895: top: 8.5em;
5896: bottom: 0;
5897: }
5898:
5899: .LC_iframecontainer iframe{
5900: border: none;
5901: width: 100%;
5902: height: 100%;
5903: }
5904:
1.778 bisitz 5905: .LC_filename {
5906: font-family: $mono;
5907: white-space:pre;
1.921 bisitz 5908: font-size: 120%;
1.778 bisitz 5909: }
5910:
5911: .LC_fileicon {
5912: border: none;
5913: height: 1.3em;
5914: vertical-align: text-bottom;
5915: margin-right: 0.3em;
5916: text-decoration:none;
5917: }
5918:
1.1008 www 5919: .LC_setting {
5920: text-decoration:underline;
5921: }
5922:
1.350 albertel 5923: .LC_error {
5924: color: red;
5925: }
1.795 www 5926:
1.1075.2.15 raeburn 5927: .LC_warning {
5928: color: darkorange;
5929: }
5930:
1.457 albertel 5931: .LC_diff_removed {
1.733 bisitz 5932: color: red;
1.394 albertel 5933: }
1.532 albertel 5934:
5935: .LC_info,
1.457 albertel 5936: .LC_success,
5937: .LC_diff_added {
1.350 albertel 5938: color: green;
5939: }
1.795 www 5940:
1.802 bisitz 5941: div.LC_confirm_box {
5942: background-color: #FAFAFA;
5943: border: 1px solid $lg_border_color;
5944: margin-right: 0;
5945: padding: 5px;
5946: }
5947:
5948: div.LC_confirm_box .LC_error img,
5949: div.LC_confirm_box .LC_success img {
5950: vertical-align: middle;
5951: }
5952:
1.1075.2.108 raeburn 5953: .LC_maxwidth {
5954: max-width: 100%;
5955: height: auto;
5956: }
5957:
5958: .LC_textsize_mobile {
5959: \@media only screen and (max-device-width: 480px) {
5960: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5961: }
5962: }
5963:
1.440 albertel 5964: .LC_icon {
1.771 droeschl 5965: border: none;
1.790 droeschl 5966: vertical-align: middle;
1.771 droeschl 5967: }
5968:
1.543 albertel 5969: .LC_docs_spacer {
5970: width: 25px;
5971: height: 1px;
1.771 droeschl 5972: border: none;
1.543 albertel 5973: }
1.346 albertel 5974:
1.532 albertel 5975: .LC_internal_info {
1.735 bisitz 5976: color: #999999;
1.532 albertel 5977: }
5978:
1.794 www 5979: .LC_discussion {
1.1050 www 5980: background: $data_table_dark;
1.911 bisitz 5981: border: 1px solid black;
5982: margin: 2px;
1.794 www 5983: }
5984:
5985: .LC_disc_action_left {
1.1050 www 5986: background: $sidebg;
1.911 bisitz 5987: text-align: left;
1.1050 www 5988: padding: 4px;
5989: margin: 2px;
1.794 www 5990: }
5991:
5992: .LC_disc_action_right {
1.1050 www 5993: background: $sidebg;
1.911 bisitz 5994: text-align: right;
1.1050 www 5995: padding: 4px;
5996: margin: 2px;
1.794 www 5997: }
5998:
5999: .LC_disc_new_item {
1.911 bisitz 6000: background: white;
6001: border: 2px solid red;
1.1050 www 6002: margin: 4px;
6003: padding: 4px;
1.794 www 6004: }
6005:
6006: .LC_disc_old_item {
1.911 bisitz 6007: background: white;
1.1050 www 6008: margin: 4px;
6009: padding: 4px;
1.794 www 6010: }
6011:
1.458 albertel 6012: table.LC_pastsubmission {
6013: border: 1px solid black;
6014: margin: 2px;
6015: }
6016:
1.924 bisitz 6017: table#LC_menubuttons {
1.345 albertel 6018: width: 100%;
6019: background: $pgbg;
1.392 albertel 6020: border: 2px;
1.402 albertel 6021: border-collapse: separate;
1.803 bisitz 6022: padding: 0;
1.345 albertel 6023: }
1.392 albertel 6024:
1.801 tempelho 6025: table#LC_title_bar a {
6026: color: $fontmenu;
6027: }
1.836 bisitz 6028:
1.807 droeschl 6029: table#LC_title_bar {
1.819 tempelho 6030: clear: both;
1.836 bisitz 6031: display: none;
1.807 droeschl 6032: }
6033:
1.795 www 6034: table#LC_title_bar,
1.933 droeschl 6035: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6036: table#LC_title_bar.LC_with_remote {
1.359 albertel 6037: width: 100%;
1.392 albertel 6038: border-color: $pgbg;
6039: border-style: solid;
6040: border-width: $border;
1.379 albertel 6041: background: $pgbg;
1.801 tempelho 6042: color: $fontmenu;
1.392 albertel 6043: border-collapse: collapse;
1.803 bisitz 6044: padding: 0;
1.819 tempelho 6045: margin: 0;
1.359 albertel 6046: }
1.795 www 6047:
1.933 droeschl 6048: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6049: margin: 0;
6050: padding: 0;
1.933 droeschl 6051: position: relative;
6052: list-style: none;
1.913 droeschl 6053: }
1.933 droeschl 6054: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6055: display: inline;
6056: }
1.933 droeschl 6057:
6058: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6059: padding: 0;
1.933 droeschl 6060: margin: 0;
6061: float: left;
1.913 droeschl 6062: }
1.933 droeschl 6063: .LC_breadcrumb_tools_tools {
6064: padding: 0;
6065: margin: 0;
1.913 droeschl 6066: float: right;
6067: }
6068:
1.359 albertel 6069: table#LC_title_bar td {
6070: background: $tabbg;
6071: }
1.795 www 6072:
1.911 bisitz 6073: table#LC_menubuttons img {
1.803 bisitz 6074: border: none;
1.346 albertel 6075: }
1.795 www 6076:
1.842 droeschl 6077: .LC_breadcrumbs_component {
1.911 bisitz 6078: float: right;
6079: margin: 0 1em;
1.357 albertel 6080: }
1.842 droeschl 6081: .LC_breadcrumbs_component img {
1.911 bisitz 6082: vertical-align: middle;
1.777 tempelho 6083: }
1.795 www 6084:
1.1075.2.108 raeburn 6085: .LC_breadcrumbs_hoverable {
6086: background: $sidebg;
6087: }
6088:
1.383 albertel 6089: td.LC_table_cell_checkbox {
6090: text-align: center;
6091: }
1.795 www 6092:
6093: .LC_fontsize_small {
1.911 bisitz 6094: font-size: 70%;
1.705 tempelho 6095: }
6096:
1.844 bisitz 6097: #LC_breadcrumbs {
1.911 bisitz 6098: clear:both;
6099: background: $sidebg;
6100: border-bottom: 1px solid $lg_border_color;
6101: line-height: 2.5em;
1.933 droeschl 6102: overflow: hidden;
1.911 bisitz 6103: margin: 0;
6104: padding: 0;
1.995 raeburn 6105: text-align: left;
1.819 tempelho 6106: }
1.862 bisitz 6107:
1.1075.2.16 raeburn 6108: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6109: clear:both;
6110: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6111: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6112: margin: 0 0 10px 0;
1.966 bisitz 6113: padding: 3px;
1.995 raeburn 6114: text-align: left;
1.822 bisitz 6115: }
6116:
1.795 www 6117: .LC_fontsize_medium {
1.911 bisitz 6118: font-size: 85%;
1.705 tempelho 6119: }
6120:
1.795 www 6121: .LC_fontsize_large {
1.911 bisitz 6122: font-size: 120%;
1.705 tempelho 6123: }
6124:
1.346 albertel 6125: .LC_menubuttons_inline_text {
6126: color: $font;
1.698 harmsja 6127: font-size: 90%;
1.701 harmsja 6128: padding-left:3px;
1.346 albertel 6129: }
6130:
1.934 droeschl 6131: .LC_menubuttons_inline_text img{
6132: vertical-align: middle;
6133: }
6134:
1.1051 www 6135: li.LC_menubuttons_inline_text img {
1.951 onken 6136: cursor:pointer;
1.1002 droeschl 6137: text-decoration: none;
1.951 onken 6138: }
6139:
1.526 www 6140: .LC_menubuttons_link {
6141: text-decoration: none;
6142: }
1.795 www 6143:
1.522 albertel 6144: .LC_menubuttons_category {
1.521 www 6145: color: $font;
1.526 www 6146: background: $pgbg;
1.521 www 6147: font-size: larger;
6148: font-weight: bold;
6149: }
6150:
1.346 albertel 6151: td.LC_menubuttons_text {
1.911 bisitz 6152: color: $font;
1.346 albertel 6153: }
1.706 harmsja 6154:
1.346 albertel 6155: .LC_current_location {
6156: background: $tabbg;
6157: }
1.795 www 6158:
1.938 bisitz 6159: table.LC_data_table {
1.347 albertel 6160: border: 1px solid #000000;
1.402 albertel 6161: border-collapse: separate;
1.426 albertel 6162: border-spacing: 1px;
1.610 albertel 6163: background: $pgbg;
1.347 albertel 6164: }
1.795 www 6165:
1.422 albertel 6166: .LC_data_table_dense {
6167: font-size: small;
6168: }
1.795 www 6169:
1.507 raeburn 6170: table.LC_nested_outer {
6171: border: 1px solid #000000;
1.589 raeburn 6172: border-collapse: collapse;
1.803 bisitz 6173: border-spacing: 0;
1.507 raeburn 6174: width: 100%;
6175: }
1.795 www 6176:
1.879 raeburn 6177: table.LC_innerpickbox,
1.507 raeburn 6178: table.LC_nested {
1.803 bisitz 6179: border: none;
1.589 raeburn 6180: border-collapse: collapse;
1.803 bisitz 6181: border-spacing: 0;
1.507 raeburn 6182: width: 100%;
6183: }
1.795 www 6184:
1.911 bisitz 6185: table.LC_data_table tr th,
6186: table.LC_calendar tr th,
1.879 raeburn 6187: table.LC_prior_tries tr th,
6188: table.LC_innerpickbox tr th {
1.349 albertel 6189: font-weight: bold;
6190: background-color: $data_table_head;
1.801 tempelho 6191: color:$fontmenu;
1.701 harmsja 6192: font-size:90%;
1.347 albertel 6193: }
1.795 www 6194:
1.879 raeburn 6195: table.LC_innerpickbox tr th,
6196: table.LC_innerpickbox tr td {
6197: vertical-align: top;
6198: }
6199:
1.711 raeburn 6200: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6201: background-color: #CCCCCC;
1.711 raeburn 6202: font-weight: bold;
6203: text-align: left;
6204: }
1.795 www 6205:
1.912 bisitz 6206: table.LC_data_table tr.LC_odd_row > td {
6207: background-color: $data_table_light;
6208: padding: 2px;
6209: vertical-align: top;
6210: }
6211:
1.809 bisitz 6212: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6213: background-color: $data_table_light;
1.912 bisitz 6214: vertical-align: top;
6215: }
6216:
6217: table.LC_data_table tr.LC_even_row > td {
6218: background-color: $data_table_dark;
1.425 albertel 6219: padding: 2px;
1.900 bisitz 6220: vertical-align: top;
1.347 albertel 6221: }
1.795 www 6222:
1.809 bisitz 6223: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6224: background-color: $data_table_dark;
1.900 bisitz 6225: vertical-align: top;
1.347 albertel 6226: }
1.795 www 6227:
1.425 albertel 6228: table.LC_data_table tr.LC_data_table_highlight td {
6229: background-color: $data_table_darker;
6230: }
1.795 www 6231:
1.639 raeburn 6232: table.LC_data_table tr td.LC_leftcol_header {
6233: background-color: $data_table_head;
6234: font-weight: bold;
6235: }
1.795 www 6236:
1.451 albertel 6237: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6238: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6239: font-weight: bold;
6240: font-style: italic;
6241: text-align: center;
6242: padding: 8px;
1.347 albertel 6243: }
1.795 www 6244:
1.1075.2.30 raeburn 6245: table.LC_data_table tr.LC_empty_row td,
6246: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6247: background-color: $sidebg;
6248: }
6249:
6250: table.LC_nested tr.LC_empty_row td {
6251: background-color: #FFFFFF;
6252: }
6253:
1.890 droeschl 6254: table.LC_caption {
6255: }
6256:
1.507 raeburn 6257: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6258: padding: 4ex
6259: }
1.795 www 6260:
1.507 raeburn 6261: table.LC_nested_outer tr th {
6262: font-weight: bold;
1.801 tempelho 6263: color:$fontmenu;
1.507 raeburn 6264: background-color: $data_table_head;
1.701 harmsja 6265: font-size: small;
1.507 raeburn 6266: border-bottom: 1px solid #000000;
6267: }
1.795 www 6268:
1.507 raeburn 6269: table.LC_nested_outer tr td.LC_subheader {
6270: background-color: $data_table_head;
6271: font-weight: bold;
6272: font-size: small;
6273: border-bottom: 1px solid #000000;
6274: text-align: right;
1.451 albertel 6275: }
1.795 www 6276:
1.507 raeburn 6277: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6278: background-color: #CCCCCC;
1.451 albertel 6279: font-weight: bold;
6280: font-size: small;
1.507 raeburn 6281: text-align: center;
6282: }
1.795 www 6283:
1.589 raeburn 6284: table.LC_nested tr.LC_info_row td.LC_left_item,
6285: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6286: text-align: left;
1.451 albertel 6287: }
1.795 www 6288:
1.507 raeburn 6289: table.LC_nested td {
1.735 bisitz 6290: background-color: #FFFFFF;
1.451 albertel 6291: font-size: small;
1.507 raeburn 6292: }
1.795 www 6293:
1.507 raeburn 6294: table.LC_nested_outer tr th.LC_right_item,
6295: table.LC_nested tr.LC_info_row td.LC_right_item,
6296: table.LC_nested tr.LC_odd_row td.LC_right_item,
6297: table.LC_nested tr td.LC_right_item {
1.451 albertel 6298: text-align: right;
6299: }
6300:
1.507 raeburn 6301: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6302: background-color: #EEEEEE;
1.451 albertel 6303: }
6304:
1.473 raeburn 6305: table.LC_createuser {
6306: }
6307:
6308: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6309: font-size: small;
1.473 raeburn 6310: }
6311:
6312: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6313: background-color: #CCCCCC;
1.473 raeburn 6314: font-weight: bold;
6315: text-align: center;
6316: }
6317:
1.349 albertel 6318: table.LC_calendar {
6319: border: 1px solid #000000;
6320: border-collapse: collapse;
1.917 raeburn 6321: width: 98%;
1.349 albertel 6322: }
1.795 www 6323:
1.349 albertel 6324: table.LC_calendar_pickdate {
6325: font-size: xx-small;
6326: }
1.795 www 6327:
1.349 albertel 6328: table.LC_calendar tr td {
6329: border: 1px solid #000000;
6330: vertical-align: top;
1.917 raeburn 6331: width: 14%;
1.349 albertel 6332: }
1.795 www 6333:
1.349 albertel 6334: table.LC_calendar tr td.LC_calendar_day_empty {
6335: background-color: $data_table_dark;
6336: }
1.795 www 6337:
1.779 bisitz 6338: table.LC_calendar tr td.LC_calendar_day_current {
6339: background-color: $data_table_highlight;
1.777 tempelho 6340: }
1.795 www 6341:
1.938 bisitz 6342: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6343: background-color: $mail_new;
6344: }
1.795 www 6345:
1.938 bisitz 6346: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6347: background-color: $mail_new_hover;
6348: }
1.795 www 6349:
1.938 bisitz 6350: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6351: background-color: $mail_read;
6352: }
1.795 www 6353:
1.938 bisitz 6354: /*
6355: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6356: background-color: $mail_read_hover;
6357: }
1.938 bisitz 6358: */
1.795 www 6359:
1.938 bisitz 6360: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6361: background-color: $mail_replied;
6362: }
1.795 www 6363:
1.938 bisitz 6364: /*
6365: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6366: background-color: $mail_replied_hover;
6367: }
1.938 bisitz 6368: */
1.795 www 6369:
1.938 bisitz 6370: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6371: background-color: $mail_other;
6372: }
1.795 www 6373:
1.938 bisitz 6374: /*
6375: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6376: background-color: $mail_other_hover;
6377: }
1.938 bisitz 6378: */
1.494 raeburn 6379:
1.777 tempelho 6380: table.LC_data_table tr > td.LC_browser_file,
6381: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6382: background: #AAEE77;
1.389 albertel 6383: }
1.795 www 6384:
1.777 tempelho 6385: table.LC_data_table tr > td.LC_browser_file_locked,
6386: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6387: background: #FFAA99;
1.387 albertel 6388: }
1.795 www 6389:
1.777 tempelho 6390: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6391: background: #888888;
1.779 bisitz 6392: }
1.795 www 6393:
1.777 tempelho 6394: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6395: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6396: background: #F8F866;
1.777 tempelho 6397: }
1.795 www 6398:
1.696 bisitz 6399: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6400: background: #E0E8FF;
1.387 albertel 6401: }
1.696 bisitz 6402:
1.707 bisitz 6403: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6404: /* background: #77FF77; */
1.707 bisitz 6405: }
1.795 www 6406:
1.707 bisitz 6407: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6408: border-right: 8px solid #FFFF77;
1.707 bisitz 6409: }
1.795 www 6410:
1.707 bisitz 6411: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6412: border-right: 8px solid #FFAA77;
1.707 bisitz 6413: }
1.795 www 6414:
1.707 bisitz 6415: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6416: border-right: 8px solid #FF7777;
1.707 bisitz 6417: }
1.795 www 6418:
1.707 bisitz 6419: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6420: border-right: 8px solid #AAFF77;
1.707 bisitz 6421: }
1.795 www 6422:
1.707 bisitz 6423: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6424: border-right: 8px solid #11CC55;
1.707 bisitz 6425: }
6426:
1.388 albertel 6427: span.LC_current_location {
1.701 harmsja 6428: font-size:larger;
1.388 albertel 6429: background: $pgbg;
6430: }
1.387 albertel 6431:
1.1029 www 6432: span.LC_current_nav_location {
6433: font-weight:bold;
6434: background: $sidebg;
6435: }
6436:
1.395 albertel 6437: span.LC_parm_menu_item {
6438: font-size: larger;
6439: }
1.795 www 6440:
1.395 albertel 6441: span.LC_parm_scope_all {
6442: color: red;
6443: }
1.795 www 6444:
1.395 albertel 6445: span.LC_parm_scope_folder {
6446: color: green;
6447: }
1.795 www 6448:
1.395 albertel 6449: span.LC_parm_scope_resource {
6450: color: orange;
6451: }
1.795 www 6452:
1.395 albertel 6453: span.LC_parm_part {
6454: color: blue;
6455: }
1.795 www 6456:
1.911 bisitz 6457: span.LC_parm_folder,
6458: span.LC_parm_symb {
1.395 albertel 6459: font-size: x-small;
6460: font-family: $mono;
6461: color: #AAAAAA;
6462: }
6463:
1.977 bisitz 6464: ul.LC_parm_parmlist li {
6465: display: inline-block;
6466: padding: 0.3em 0.8em;
6467: vertical-align: top;
6468: width: 150px;
6469: border-top:1px solid $lg_border_color;
6470: }
6471:
1.795 www 6472: td.LC_parm_overview_level_menu,
6473: td.LC_parm_overview_map_menu,
6474: td.LC_parm_overview_parm_selectors,
6475: td.LC_parm_overview_restrictions {
1.396 albertel 6476: border: 1px solid black;
6477: border-collapse: collapse;
6478: }
1.795 www 6479:
1.396 albertel 6480: table.LC_parm_overview_restrictions td {
6481: border-width: 1px 4px 1px 4px;
6482: border-style: solid;
6483: border-color: $pgbg;
6484: text-align: center;
6485: }
1.795 www 6486:
1.396 albertel 6487: table.LC_parm_overview_restrictions th {
6488: background: $tabbg;
6489: border-width: 1px 4px 1px 4px;
6490: border-style: solid;
6491: border-color: $pgbg;
6492: }
1.795 www 6493:
1.398 albertel 6494: table#LC_helpmenu {
1.803 bisitz 6495: border: none;
1.398 albertel 6496: height: 55px;
1.803 bisitz 6497: border-spacing: 0;
1.398 albertel 6498: }
6499:
6500: table#LC_helpmenu fieldset legend {
6501: font-size: larger;
6502: }
1.795 www 6503:
1.397 albertel 6504: table#LC_helpmenu_links {
6505: width: 100%;
6506: border: 1px solid black;
6507: background: $pgbg;
1.803 bisitz 6508: padding: 0;
1.397 albertel 6509: border-spacing: 1px;
6510: }
1.795 www 6511:
1.397 albertel 6512: table#LC_helpmenu_links tr td {
6513: padding: 1px;
6514: background: $tabbg;
1.399 albertel 6515: text-align: center;
6516: font-weight: bold;
1.397 albertel 6517: }
1.396 albertel 6518:
1.795 www 6519: table#LC_helpmenu_links a:link,
6520: table#LC_helpmenu_links a:visited,
1.397 albertel 6521: table#LC_helpmenu_links a:active {
6522: text-decoration: none;
6523: color: $font;
6524: }
1.795 www 6525:
1.397 albertel 6526: table#LC_helpmenu_links a:hover {
6527: text-decoration: underline;
6528: color: $vlink;
6529: }
1.396 albertel 6530:
1.417 albertel 6531: .LC_chrt_popup_exists {
6532: border: 1px solid #339933;
6533: margin: -1px;
6534: }
1.795 www 6535:
1.417 albertel 6536: .LC_chrt_popup_up {
6537: border: 1px solid yellow;
6538: margin: -1px;
6539: }
1.795 www 6540:
1.417 albertel 6541: .LC_chrt_popup {
6542: border: 1px solid #8888FF;
6543: background: #CCCCFF;
6544: }
1.795 www 6545:
1.421 albertel 6546: table.LC_pick_box {
6547: border-collapse: separate;
6548: background: white;
6549: border: 1px solid black;
6550: border-spacing: 1px;
6551: }
1.795 www 6552:
1.421 albertel 6553: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6554: background: $sidebg;
1.421 albertel 6555: font-weight: bold;
1.900 bisitz 6556: text-align: left;
1.740 bisitz 6557: vertical-align: top;
1.421 albertel 6558: width: 184px;
6559: padding: 8px;
6560: }
1.795 www 6561:
1.579 raeburn 6562: table.LC_pick_box td.LC_pick_box_value {
6563: text-align: left;
6564: padding: 8px;
6565: }
1.795 www 6566:
1.579 raeburn 6567: table.LC_pick_box td.LC_pick_box_select {
6568: text-align: left;
6569: padding: 8px;
6570: }
1.795 www 6571:
1.424 albertel 6572: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6573: padding: 0;
1.421 albertel 6574: height: 1px;
6575: background: black;
6576: }
1.795 www 6577:
1.421 albertel 6578: table.LC_pick_box td.LC_pick_box_submit {
6579: text-align: right;
6580: }
1.795 www 6581:
1.579 raeburn 6582: table.LC_pick_box td.LC_evenrow_value {
6583: text-align: left;
6584: padding: 8px;
6585: background-color: $data_table_light;
6586: }
1.795 www 6587:
1.579 raeburn 6588: table.LC_pick_box td.LC_oddrow_value {
6589: text-align: left;
6590: padding: 8px;
6591: background-color: $data_table_light;
6592: }
1.795 www 6593:
1.579 raeburn 6594: span.LC_helpform_receipt_cat {
6595: font-weight: bold;
6596: }
1.795 www 6597:
1.424 albertel 6598: table.LC_group_priv_box {
6599: background: white;
6600: border: 1px solid black;
6601: border-spacing: 1px;
6602: }
1.795 www 6603:
1.424 albertel 6604: table.LC_group_priv_box td.LC_pick_box_title {
6605: background: $tabbg;
6606: font-weight: bold;
6607: text-align: right;
6608: width: 184px;
6609: }
1.795 www 6610:
1.424 albertel 6611: table.LC_group_priv_box td.LC_groups_fixed {
6612: background: $data_table_light;
6613: text-align: center;
6614: }
1.795 www 6615:
1.424 albertel 6616: table.LC_group_priv_box td.LC_groups_optional {
6617: background: $data_table_dark;
6618: text-align: center;
6619: }
1.795 www 6620:
1.424 albertel 6621: table.LC_group_priv_box td.LC_groups_functionality {
6622: background: $data_table_darker;
6623: text-align: center;
6624: font-weight: bold;
6625: }
1.795 www 6626:
1.424 albertel 6627: table.LC_group_priv td {
6628: text-align: left;
1.803 bisitz 6629: padding: 0;
1.424 albertel 6630: }
6631:
6632: .LC_navbuttons {
6633: margin: 2ex 0ex 2ex 0ex;
6634: }
1.795 www 6635:
1.423 albertel 6636: .LC_topic_bar {
6637: font-weight: bold;
6638: background: $tabbg;
1.918 wenzelju 6639: margin: 1em 0em 1em 2em;
1.805 bisitz 6640: padding: 3px;
1.918 wenzelju 6641: font-size: 1.2em;
1.423 albertel 6642: }
1.795 www 6643:
1.423 albertel 6644: .LC_topic_bar span {
1.918 wenzelju 6645: left: 0.5em;
6646: position: absolute;
1.423 albertel 6647: vertical-align: middle;
1.918 wenzelju 6648: font-size: 1.2em;
1.423 albertel 6649: }
1.795 www 6650:
1.423 albertel 6651: table.LC_course_group_status {
6652: margin: 20px;
6653: }
1.795 www 6654:
1.423 albertel 6655: table.LC_status_selector td {
6656: vertical-align: top;
6657: text-align: center;
1.424 albertel 6658: padding: 4px;
6659: }
1.795 www 6660:
1.599 albertel 6661: div.LC_feedback_link {
1.616 albertel 6662: clear: both;
1.829 kalberla 6663: background: $sidebg;
1.779 bisitz 6664: width: 100%;
1.829 kalberla 6665: padding-bottom: 10px;
6666: border: 1px $tabbg solid;
1.833 kalberla 6667: height: 22px;
6668: line-height: 22px;
6669: padding-top: 5px;
6670: }
6671:
6672: div.LC_feedback_link img {
6673: height: 22px;
1.867 kalberla 6674: vertical-align:middle;
1.829 kalberla 6675: }
6676:
1.911 bisitz 6677: div.LC_feedback_link a {
1.829 kalberla 6678: text-decoration: none;
1.489 raeburn 6679: }
1.795 www 6680:
1.867 kalberla 6681: div.LC_comblock {
1.911 bisitz 6682: display:inline;
1.867 kalberla 6683: color:$font;
6684: font-size:90%;
6685: }
6686:
6687: div.LC_feedback_link div.LC_comblock {
6688: padding-left:5px;
6689: }
6690:
6691: div.LC_feedback_link div.LC_comblock a {
6692: color:$font;
6693: }
6694:
1.489 raeburn 6695: span.LC_feedback_link {
1.858 bisitz 6696: /* background: $feedback_link_bg; */
1.599 albertel 6697: font-size: larger;
6698: }
1.795 www 6699:
1.599 albertel 6700: span.LC_message_link {
1.858 bisitz 6701: /* background: $feedback_link_bg; */
1.599 albertel 6702: font-size: larger;
6703: position: absolute;
6704: right: 1em;
1.489 raeburn 6705: }
1.421 albertel 6706:
1.515 albertel 6707: table.LC_prior_tries {
1.524 albertel 6708: border: 1px solid #000000;
6709: border-collapse: separate;
6710: border-spacing: 1px;
1.515 albertel 6711: }
1.523 albertel 6712:
1.515 albertel 6713: table.LC_prior_tries td {
1.524 albertel 6714: padding: 2px;
1.515 albertel 6715: }
1.523 albertel 6716:
6717: .LC_answer_correct {
1.795 www 6718: background: lightgreen;
6719: color: darkgreen;
6720: padding: 6px;
1.523 albertel 6721: }
1.795 www 6722:
1.523 albertel 6723: .LC_answer_charged_try {
1.797 www 6724: background: #FFAAAA;
1.795 www 6725: color: darkred;
6726: padding: 6px;
1.523 albertel 6727: }
1.795 www 6728:
1.779 bisitz 6729: .LC_answer_not_charged_try,
1.523 albertel 6730: .LC_answer_no_grade,
6731: .LC_answer_late {
1.795 www 6732: background: lightyellow;
1.523 albertel 6733: color: black;
1.795 www 6734: padding: 6px;
1.523 albertel 6735: }
1.795 www 6736:
1.523 albertel 6737: .LC_answer_previous {
1.795 www 6738: background: lightblue;
6739: color: darkblue;
6740: padding: 6px;
1.523 albertel 6741: }
1.795 www 6742:
1.779 bisitz 6743: .LC_answer_no_message {
1.777 tempelho 6744: background: #FFFFFF;
6745: color: black;
1.795 www 6746: padding: 6px;
1.779 bisitz 6747: }
1.795 www 6748:
1.779 bisitz 6749: .LC_answer_unknown {
6750: background: orange;
6751: color: black;
1.795 www 6752: padding: 6px;
1.777 tempelho 6753: }
1.795 www 6754:
1.529 albertel 6755: span.LC_prior_numerical,
6756: span.LC_prior_string,
6757: span.LC_prior_custom,
6758: span.LC_prior_reaction,
6759: span.LC_prior_math {
1.925 bisitz 6760: font-family: $mono;
1.523 albertel 6761: white-space: pre;
6762: }
6763:
1.525 albertel 6764: span.LC_prior_string {
1.925 bisitz 6765: font-family: $mono;
1.525 albertel 6766: white-space: pre;
6767: }
6768:
1.523 albertel 6769: table.LC_prior_option {
6770: width: 100%;
6771: border-collapse: collapse;
6772: }
1.795 www 6773:
1.911 bisitz 6774: table.LC_prior_rank,
1.795 www 6775: table.LC_prior_match {
1.528 albertel 6776: border-collapse: collapse;
6777: }
1.795 www 6778:
1.528 albertel 6779: table.LC_prior_option tr td,
6780: table.LC_prior_rank tr td,
6781: table.LC_prior_match tr td {
1.524 albertel 6782: border: 1px solid #000000;
1.515 albertel 6783: }
6784:
1.855 bisitz 6785: .LC_nobreak {
1.544 albertel 6786: white-space: nowrap;
1.519 raeburn 6787: }
6788:
1.576 raeburn 6789: span.LC_cusr_emph {
6790: font-style: italic;
6791: }
6792:
1.633 raeburn 6793: span.LC_cusr_subheading {
6794: font-weight: normal;
6795: font-size: 85%;
6796: }
6797:
1.861 bisitz 6798: div.LC_docs_entry_move {
1.859 bisitz 6799: border: 1px solid #BBBBBB;
1.545 albertel 6800: background: #DDDDDD;
1.861 bisitz 6801: width: 22px;
1.859 bisitz 6802: padding: 1px;
6803: margin: 0;
1.545 albertel 6804: }
6805:
1.861 bisitz 6806: table.LC_data_table tr > td.LC_docs_entry_commands,
6807: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6808: font-size: x-small;
6809: }
1.795 www 6810:
1.861 bisitz 6811: .LC_docs_entry_parameter {
6812: white-space: nowrap;
6813: }
6814:
1.544 albertel 6815: .LC_docs_copy {
1.545 albertel 6816: color: #000099;
1.544 albertel 6817: }
1.795 www 6818:
1.544 albertel 6819: .LC_docs_cut {
1.545 albertel 6820: color: #550044;
1.544 albertel 6821: }
1.795 www 6822:
1.544 albertel 6823: .LC_docs_rename {
1.545 albertel 6824: color: #009900;
1.544 albertel 6825: }
1.795 www 6826:
1.544 albertel 6827: .LC_docs_remove {
1.545 albertel 6828: color: #990000;
6829: }
6830:
1.547 albertel 6831: .LC_docs_reinit_warn,
6832: .LC_docs_ext_edit {
6833: font-size: x-small;
6834: }
6835:
1.545 albertel 6836: table.LC_docs_adddocs td,
6837: table.LC_docs_adddocs th {
6838: border: 1px solid #BBBBBB;
6839: padding: 4px;
6840: background: #DDDDDD;
1.543 albertel 6841: }
6842:
1.584 albertel 6843: table.LC_sty_begin {
6844: background: #BBFFBB;
6845: }
1.795 www 6846:
1.584 albertel 6847: table.LC_sty_end {
6848: background: #FFBBBB;
6849: }
6850:
1.589 raeburn 6851: table.LC_double_column {
1.803 bisitz 6852: border-width: 0;
1.589 raeburn 6853: border-collapse: collapse;
6854: width: 100%;
6855: padding: 2px;
6856: }
6857:
6858: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6859: top: 2px;
1.589 raeburn 6860: left: 2px;
6861: width: 47%;
6862: vertical-align: top;
6863: }
6864:
6865: table.LC_double_column tr td.LC_right_col {
6866: top: 2px;
1.779 bisitz 6867: right: 2px;
1.589 raeburn 6868: width: 47%;
6869: vertical-align: top;
6870: }
6871:
1.591 raeburn 6872: div.LC_left_float {
6873: float: left;
6874: padding-right: 5%;
1.597 albertel 6875: padding-bottom: 4px;
1.591 raeburn 6876: }
6877:
6878: div.LC_clear_float_header {
1.597 albertel 6879: padding-bottom: 2px;
1.591 raeburn 6880: }
6881:
6882: div.LC_clear_float_footer {
1.597 albertel 6883: padding-top: 10px;
1.591 raeburn 6884: clear: both;
6885: }
6886:
1.597 albertel 6887: div.LC_grade_show_user {
1.941 bisitz 6888: /* border-left: 5px solid $sidebg; */
6889: border-top: 5px solid #000000;
6890: margin: 50px 0 0 0;
1.936 bisitz 6891: padding: 15px 0 5px 10px;
1.597 albertel 6892: }
1.795 www 6893:
1.936 bisitz 6894: div.LC_grade_show_user_odd_row {
1.941 bisitz 6895: /* border-left: 5px solid #000000; */
6896: }
6897:
6898: div.LC_grade_show_user div.LC_Box {
6899: margin-right: 50px;
1.597 albertel 6900: }
6901:
6902: div.LC_grade_submissions,
6903: div.LC_grade_message_center,
1.936 bisitz 6904: div.LC_grade_info_links {
1.597 albertel 6905: margin: 5px;
6906: width: 99%;
6907: background: #FFFFFF;
6908: }
1.795 www 6909:
1.597 albertel 6910: div.LC_grade_submissions_header,
1.936 bisitz 6911: div.LC_grade_message_center_header {
1.705 tempelho 6912: font-weight: bold;
6913: font-size: large;
1.597 albertel 6914: }
1.795 www 6915:
1.597 albertel 6916: div.LC_grade_submissions_body,
1.936 bisitz 6917: div.LC_grade_message_center_body {
1.597 albertel 6918: border: 1px solid black;
6919: width: 99%;
6920: background: #FFFFFF;
6921: }
1.795 www 6922:
1.613 albertel 6923: table.LC_scantron_action {
6924: width: 100%;
6925: }
1.795 www 6926:
1.613 albertel 6927: table.LC_scantron_action tr th {
1.698 harmsja 6928: font-weight:bold;
6929: font-style:normal;
1.613 albertel 6930: }
1.795 www 6931:
1.779 bisitz 6932: .LC_edit_problem_header,
1.614 albertel 6933: div.LC_edit_problem_footer {
1.705 tempelho 6934: font-weight: normal;
6935: font-size: medium;
1.602 albertel 6936: margin: 2px;
1.1060 bisitz 6937: background-color: $sidebg;
1.600 albertel 6938: }
1.795 www 6939:
1.600 albertel 6940: div.LC_edit_problem_header,
1.602 albertel 6941: div.LC_edit_problem_header div,
1.614 albertel 6942: div.LC_edit_problem_footer,
6943: div.LC_edit_problem_footer div,
1.602 albertel 6944: div.LC_edit_problem_editxml_header,
6945: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6946: z-index: 100;
1.600 albertel 6947: }
1.795 www 6948:
1.600 albertel 6949: div.LC_edit_problem_header_title {
1.705 tempelho 6950: font-weight: bold;
6951: font-size: larger;
1.602 albertel 6952: background: $tabbg;
6953: padding: 3px;
1.1060 bisitz 6954: margin: 0 0 5px 0;
1.602 albertel 6955: }
1.795 www 6956:
1.602 albertel 6957: table.LC_edit_problem_header_title {
6958: width: 100%;
1.600 albertel 6959: background: $tabbg;
1.602 albertel 6960: }
6961:
1.1075.2.112 raeburn 6962: div.LC_edit_actionbar {
6963: background-color: $sidebg;
6964: margin: 0;
6965: padding: 0;
6966: line-height: 200%;
1.602 albertel 6967: }
1.795 www 6968:
1.1075.2.112 raeburn 6969: div.LC_edit_actionbar div{
6970: padding: 0;
6971: margin: 0;
6972: display: inline-block;
1.600 albertel 6973: }
1.795 www 6974:
1.1075.2.34 raeburn 6975: .LC_edit_opt {
6976: padding-left: 1em;
6977: white-space: nowrap;
6978: }
6979:
1.1075.2.57 raeburn 6980: .LC_edit_problem_latexhelper{
6981: text-align: right;
6982: }
6983:
6984: #LC_edit_problem_colorful div{
6985: margin-left: 40px;
6986: }
6987:
1.1075.2.112 raeburn 6988: #LC_edit_problem_codemirror div{
6989: margin-left: 0px;
6990: }
6991:
1.911 bisitz 6992: img.stift {
1.803 bisitz 6993: border-width: 0;
6994: vertical-align: middle;
1.677 riegler 6995: }
1.680 riegler 6996:
1.923 bisitz 6997: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6998: vertical-align: top;
1.777 tempelho 6999: }
1.795 www 7000:
1.716 raeburn 7001: div.LC_createcourse {
1.911 bisitz 7002: margin: 10px 10px 10px 10px;
1.716 raeburn 7003: }
7004:
1.917 raeburn 7005: .LC_dccid {
1.1075.2.38 raeburn 7006: float: right;
1.917 raeburn 7007: margin: 0.2em 0 0 0;
7008: padding: 0;
7009: font-size: 90%;
7010: display:none;
7011: }
7012:
1.897 wenzelju 7013: ol.LC_primary_menu a:hover,
1.721 harmsja 7014: ol#LC_MenuBreadcrumbs a:hover,
7015: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7016: ul#LC_secondary_menu a:hover,
1.721 harmsja 7017: .LC_FormSectionClearButton input:hover
1.795 www 7018: ul.LC_TabContent li:hover a {
1.952 onken 7019: color:$button_hover;
1.911 bisitz 7020: text-decoration:none;
1.693 droeschl 7021: }
7022:
1.779 bisitz 7023: h1 {
1.911 bisitz 7024: padding: 0;
7025: line-height:130%;
1.693 droeschl 7026: }
1.698 harmsja 7027:
1.911 bisitz 7028: h2,
7029: h3,
7030: h4,
7031: h5,
7032: h6 {
7033: margin: 5px 0 5px 0;
7034: padding: 0;
7035: line-height:130%;
1.693 droeschl 7036: }
1.795 www 7037:
7038: .LC_hcell {
1.911 bisitz 7039: padding:3px 15px 3px 15px;
7040: margin: 0;
7041: background-color:$tabbg;
7042: color:$fontmenu;
7043: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7044: }
1.795 www 7045:
1.840 bisitz 7046: .LC_Box > .LC_hcell {
1.911 bisitz 7047: margin: 0 -10px 10px -10px;
1.835 bisitz 7048: }
7049:
1.721 harmsja 7050: .LC_noBorder {
1.911 bisitz 7051: border: 0;
1.698 harmsja 7052: }
1.693 droeschl 7053:
1.721 harmsja 7054: .LC_FormSectionClearButton input {
1.911 bisitz 7055: background-color:transparent;
7056: border: none;
7057: cursor:pointer;
7058: text-decoration:underline;
1.693 droeschl 7059: }
1.763 bisitz 7060:
7061: .LC_help_open_topic {
1.911 bisitz 7062: color: #FFFFFF;
7063: background-color: #EEEEFF;
7064: margin: 1px;
7065: padding: 4px;
7066: border: 1px solid #000033;
7067: white-space: nowrap;
7068: /* vertical-align: middle; */
1.759 neumanie 7069: }
1.693 droeschl 7070:
1.911 bisitz 7071: dl,
7072: ul,
7073: div,
7074: fieldset {
7075: margin: 10px 10px 10px 0;
7076: /* overflow: hidden; */
1.693 droeschl 7077: }
1.795 www 7078:
1.1075.2.90 raeburn 7079: article.geogebraweb div {
7080: margin: 0;
7081: }
7082:
1.838 bisitz 7083: fieldset > legend {
1.911 bisitz 7084: font-weight: bold;
7085: padding: 0 5px 0 5px;
1.838 bisitz 7086: }
7087:
1.813 bisitz 7088: #LC_nav_bar {
1.911 bisitz 7089: float: left;
1.995 raeburn 7090: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7091: margin: 0 0 2px 0;
1.807 droeschl 7092: }
7093:
1.916 droeschl 7094: #LC_realm {
7095: margin: 0.2em 0 0 0;
7096: padding: 0;
7097: font-weight: bold;
7098: text-align: center;
1.995 raeburn 7099: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7100: }
7101:
1.911 bisitz 7102: #LC_nav_bar em {
7103: font-weight: bold;
7104: font-style: normal;
1.807 droeschl 7105: }
7106:
1.897 wenzelju 7107: ol.LC_primary_menu {
1.934 droeschl 7108: margin: 0;
1.1075.2.2 raeburn 7109: padding: 0;
1.807 droeschl 7110: }
7111:
1.852 droeschl 7112: ol#LC_PathBreadcrumbs {
1.911 bisitz 7113: margin: 0;
1.693 droeschl 7114: }
7115:
1.897 wenzelju 7116: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7117: color: RGB(80, 80, 80);
7118: vertical-align: middle;
7119: text-align: left;
7120: list-style: none;
1.1075.2.112 raeburn 7121: position: relative;
1.1075.2.2 raeburn 7122: float: left;
1.1075.2.112 raeburn 7123: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7124: line-height: 1.5em;
1.1075.2.2 raeburn 7125: }
7126:
1.1075.2.113 raeburn 7127: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7128: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7129: display: block;
7130: margin: 0;
7131: padding: 0 5px 0 10px;
7132: text-decoration: none;
7133: }
7134:
1.1075.2.112 raeburn 7135: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7136: display: inline-block;
7137: width: 95%;
7138: text-align: left;
7139: }
7140:
7141: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7142: display: inline-block;
7143: width: 5%;
7144: float: right;
7145: text-align: right;
7146: font-size: 70%;
7147: }
7148:
7149: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7150: display: none;
1.1075.2.112 raeburn 7151: width: 15em;
1.1075.2.2 raeburn 7152: background-color: $data_table_light;
1.1075.2.112 raeburn 7153: position: absolute;
7154: top: 100%;
7155: }
7156:
7157: ol.LC_primary_menu ul ul {
7158: left: 100%;
7159: top: 0;
1.1075.2.2 raeburn 7160: }
7161:
1.1075.2.112 raeburn 7162: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7163: display: block;
7164: position: absolute;
7165: margin: 0;
7166: padding: 0;
1.1075.2.5 raeburn 7167: z-index: 2;
1.1075.2.2 raeburn 7168: }
7169:
7170: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7171: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7172: font-size: 90%;
1.911 bisitz 7173: vertical-align: top;
1.1075.2.2 raeburn 7174: float: none;
1.1075.2.5 raeburn 7175: border-left: 1px solid black;
7176: border-right: 1px solid black;
1.1075.2.112 raeburn 7177: /* A dark bottom border to visualize different menu options;
7178: overwritten in the create_submenu routine for the last border-bottom of the menu */
7179: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7180: }
7181:
1.1075.2.112 raeburn 7182: ol.LC_primary_menu li li p:hover {
7183: color:$button_hover;
7184: text-decoration:none;
7185: background-color:$data_table_dark;
1.1075.2.2 raeburn 7186: }
7187:
7188: ol.LC_primary_menu li li a:hover {
7189: color:$button_hover;
7190: background-color:$data_table_dark;
1.693 droeschl 7191: }
7192:
1.1075.2.112 raeburn 7193: /* Font-size equal to the size of the predecessors*/
7194: ol.LC_primary_menu li:hover li li {
7195: font-size: 100%;
7196: }
7197:
1.897 wenzelju 7198: ol.LC_primary_menu li img {
1.911 bisitz 7199: vertical-align: bottom;
1.934 droeschl 7200: height: 1.1em;
1.1075.2.3 raeburn 7201: margin: 0.2em 0 0 0;
1.693 droeschl 7202: }
7203:
1.897 wenzelju 7204: ol.LC_primary_menu a {
1.911 bisitz 7205: color: RGB(80, 80, 80);
7206: text-decoration: none;
1.693 droeschl 7207: }
1.795 www 7208:
1.949 droeschl 7209: ol.LC_primary_menu a.LC_new_message {
7210: font-weight:bold;
7211: color: darkred;
7212: }
7213:
1.975 raeburn 7214: ol.LC_docs_parameters {
7215: margin-left: 0;
7216: padding: 0;
7217: list-style: none;
7218: }
7219:
7220: ol.LC_docs_parameters li {
7221: margin: 0;
7222: padding-right: 20px;
7223: display: inline;
7224: }
7225:
1.976 raeburn 7226: ol.LC_docs_parameters li:before {
7227: content: "\\002022 \\0020";
7228: }
7229:
7230: li.LC_docs_parameters_title {
7231: font-weight: bold;
7232: }
7233:
7234: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7235: content: "";
7236: }
7237:
1.897 wenzelju 7238: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7239: clear: right;
1.911 bisitz 7240: color: $fontmenu;
7241: background: $tabbg;
7242: list-style: none;
7243: padding: 0;
7244: margin: 0;
7245: width: 100%;
1.995 raeburn 7246: text-align: left;
1.1075.2.4 raeburn 7247: float: left;
1.808 droeschl 7248: }
7249:
1.897 wenzelju 7250: ul#LC_secondary_menu li {
1.911 bisitz 7251: font-weight: bold;
7252: line-height: 1.8em;
7253: border-right: 1px solid black;
1.1075.2.4 raeburn 7254: float: left;
7255: }
7256:
7257: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7258: background-color: $data_table_light;
7259: }
7260:
7261: ul#LC_secondary_menu li a {
7262: padding: 0 0.8em;
7263: }
7264:
7265: ul#LC_secondary_menu li ul {
7266: display: none;
7267: }
7268:
7269: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7270: display: block;
7271: position: absolute;
7272: margin: 0;
7273: padding: 0;
7274: list-style:none;
7275: float: none;
7276: background-color: $data_table_light;
1.1075.2.5 raeburn 7277: z-index: 2;
1.1075.2.10 raeburn 7278: margin-left: -1px;
1.1075.2.4 raeburn 7279: }
7280:
7281: ul#LC_secondary_menu li ul li {
7282: font-size: 90%;
7283: vertical-align: top;
7284: border-left: 1px solid black;
7285: border-right: 1px solid black;
1.1075.2.33 raeburn 7286: background-color: $data_table_light;
1.1075.2.4 raeburn 7287: list-style:none;
7288: float: none;
7289: }
7290:
7291: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7292: background-color: $data_table_dark;
1.807 droeschl 7293: }
7294:
1.847 tempelho 7295: ul.LC_TabContent {
1.911 bisitz 7296: display:block;
7297: background: $sidebg;
7298: border-bottom: solid 1px $lg_border_color;
7299: list-style:none;
1.1020 raeburn 7300: margin: -1px -10px 0 -10px;
1.911 bisitz 7301: padding: 0;
1.693 droeschl 7302: }
7303:
1.795 www 7304: ul.LC_TabContent li,
7305: ul.LC_TabContentBigger li {
1.911 bisitz 7306: float:left;
1.741 harmsja 7307: }
1.795 www 7308:
1.897 wenzelju 7309: ul#LC_secondary_menu li a {
1.911 bisitz 7310: color: $fontmenu;
7311: text-decoration: none;
1.693 droeschl 7312: }
1.795 www 7313:
1.721 harmsja 7314: ul.LC_TabContent {
1.952 onken 7315: min-height:20px;
1.721 harmsja 7316: }
1.795 www 7317:
7318: ul.LC_TabContent li {
1.911 bisitz 7319: vertical-align:middle;
1.959 onken 7320: padding: 0 16px 0 10px;
1.911 bisitz 7321: background-color:$tabbg;
7322: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7323: border-left: solid 1px $font;
1.721 harmsja 7324: }
1.795 www 7325:
1.847 tempelho 7326: ul.LC_TabContent .right {
1.911 bisitz 7327: float:right;
1.847 tempelho 7328: }
7329:
1.911 bisitz 7330: ul.LC_TabContent li a,
7331: ul.LC_TabContent li {
7332: color:rgb(47,47,47);
7333: text-decoration:none;
7334: font-size:95%;
7335: font-weight:bold;
1.952 onken 7336: min-height:20px;
7337: }
7338:
1.959 onken 7339: ul.LC_TabContent li a:hover,
7340: ul.LC_TabContent li a:focus {
1.952 onken 7341: color: $button_hover;
1.959 onken 7342: background:none;
7343: outline:none;
1.952 onken 7344: }
7345:
7346: ul.LC_TabContent li:hover {
7347: color: $button_hover;
7348: cursor:pointer;
1.721 harmsja 7349: }
1.795 www 7350:
1.911 bisitz 7351: ul.LC_TabContent li.active {
1.952 onken 7352: color: $font;
1.911 bisitz 7353: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7354: border-bottom:solid 1px #FFFFFF;
7355: cursor: default;
1.744 ehlerst 7356: }
1.795 www 7357:
1.959 onken 7358: ul.LC_TabContent li.active a {
7359: color:$font;
7360: background:#FFFFFF;
7361: outline: none;
7362: }
1.1047 raeburn 7363:
7364: ul.LC_TabContent li.goback {
7365: float: left;
7366: border-left: none;
7367: }
7368:
1.870 tempelho 7369: #maincoursedoc {
1.911 bisitz 7370: clear:both;
1.870 tempelho 7371: }
7372:
7373: ul.LC_TabContentBigger {
1.911 bisitz 7374: display:block;
7375: list-style:none;
7376: padding: 0;
1.870 tempelho 7377: }
7378:
1.795 www 7379: ul.LC_TabContentBigger li {
1.911 bisitz 7380: vertical-align:bottom;
7381: height: 30px;
7382: font-size:110%;
7383: font-weight:bold;
7384: color: #737373;
1.841 tempelho 7385: }
7386:
1.957 onken 7387: ul.LC_TabContentBigger li.active {
7388: position: relative;
7389: top: 1px;
7390: }
7391:
1.870 tempelho 7392: ul.LC_TabContentBigger li a {
1.911 bisitz 7393: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7394: height: 30px;
7395: line-height: 30px;
7396: text-align: center;
7397: display: block;
7398: text-decoration: none;
1.958 onken 7399: outline: none;
1.741 harmsja 7400: }
1.795 www 7401:
1.870 tempelho 7402: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7403: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7404: color:$font;
1.744 ehlerst 7405: }
1.795 www 7406:
1.870 tempelho 7407: ul.LC_TabContentBigger li b {
1.911 bisitz 7408: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7409: display: block;
7410: float: left;
7411: padding: 0 30px;
1.957 onken 7412: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7413: }
7414:
1.956 onken 7415: ul.LC_TabContentBigger li:hover b {
7416: color:$button_hover;
7417: }
7418:
1.870 tempelho 7419: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7420: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7421: color:$font;
1.957 onken 7422: border: 0;
1.741 harmsja 7423: }
1.693 droeschl 7424:
1.870 tempelho 7425:
1.862 bisitz 7426: ul.LC_CourseBreadcrumbs {
7427: background: $sidebg;
1.1020 raeburn 7428: height: 2em;
1.862 bisitz 7429: padding-left: 10px;
1.1020 raeburn 7430: margin: 0;
1.862 bisitz 7431: list-style-position: inside;
7432: }
7433:
1.911 bisitz 7434: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7435: ol#LC_PathBreadcrumbs {
1.911 bisitz 7436: padding-left: 10px;
7437: margin: 0;
1.933 droeschl 7438: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7439: }
7440:
1.911 bisitz 7441: ol#LC_MenuBreadcrumbs li,
7442: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7443: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7444: display: inline;
1.933 droeschl 7445: white-space: normal;
1.693 droeschl 7446: }
7447:
1.823 bisitz 7448: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7449: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7450: text-decoration: none;
7451: font-size:90%;
1.693 droeschl 7452: }
1.795 www 7453:
1.969 droeschl 7454: ol#LC_MenuBreadcrumbs h1 {
7455: display: inline;
7456: font-size: 90%;
7457: line-height: 2.5em;
7458: margin: 0;
7459: padding: 0;
7460: }
7461:
1.795 www 7462: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7463: text-decoration:none;
7464: font-size:100%;
7465: font-weight:bold;
1.693 droeschl 7466: }
1.795 www 7467:
1.840 bisitz 7468: .LC_Box {
1.911 bisitz 7469: border: solid 1px $lg_border_color;
7470: padding: 0 10px 10px 10px;
1.746 neumanie 7471: }
1.795 www 7472:
1.1020 raeburn 7473: .LC_DocsBox {
7474: border: solid 1px $lg_border_color;
7475: padding: 0 0 10px 10px;
7476: }
7477:
1.795 www 7478: .LC_AboutMe_Image {
1.911 bisitz 7479: float:left;
7480: margin-right:10px;
1.747 neumanie 7481: }
1.795 www 7482:
7483: .LC_Clear_AboutMe_Image {
1.911 bisitz 7484: clear:left;
1.747 neumanie 7485: }
1.795 www 7486:
1.721 harmsja 7487: dl.LC_ListStyleClean dt {
1.911 bisitz 7488: padding-right: 5px;
7489: display: table-header-group;
1.693 droeschl 7490: }
7491:
1.721 harmsja 7492: dl.LC_ListStyleClean dd {
1.911 bisitz 7493: display: table-row;
1.693 droeschl 7494: }
7495:
1.721 harmsja 7496: .LC_ListStyleClean,
7497: .LC_ListStyleSimple,
7498: .LC_ListStyleNormal,
1.795 www 7499: .LC_ListStyleSpecial {
1.911 bisitz 7500: /* display:block; */
7501: list-style-position: inside;
7502: list-style-type: none;
7503: overflow: hidden;
7504: padding: 0;
1.693 droeschl 7505: }
7506:
1.721 harmsja 7507: .LC_ListStyleSimple li,
7508: .LC_ListStyleSimple dd,
7509: .LC_ListStyleNormal li,
7510: .LC_ListStyleNormal dd,
7511: .LC_ListStyleSpecial li,
1.795 www 7512: .LC_ListStyleSpecial dd {
1.911 bisitz 7513: margin: 0;
7514: padding: 5px 5px 5px 10px;
7515: clear: both;
1.693 droeschl 7516: }
7517:
1.721 harmsja 7518: .LC_ListStyleClean li,
7519: .LC_ListStyleClean dd {
1.911 bisitz 7520: padding-top: 0;
7521: padding-bottom: 0;
1.693 droeschl 7522: }
7523:
1.721 harmsja 7524: .LC_ListStyleSimple dd,
1.795 www 7525: .LC_ListStyleSimple li {
1.911 bisitz 7526: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7527: }
7528:
1.721 harmsja 7529: .LC_ListStyleSpecial li,
7530: .LC_ListStyleSpecial dd {
1.911 bisitz 7531: list-style-type: none;
7532: background-color: RGB(220, 220, 220);
7533: margin-bottom: 4px;
1.693 droeschl 7534: }
7535:
1.721 harmsja 7536: table.LC_SimpleTable {
1.911 bisitz 7537: margin:5px;
7538: border:solid 1px $lg_border_color;
1.795 www 7539: }
1.693 droeschl 7540:
1.721 harmsja 7541: table.LC_SimpleTable tr {
1.911 bisitz 7542: padding: 0;
7543: border:solid 1px $lg_border_color;
1.693 droeschl 7544: }
1.795 www 7545:
7546: table.LC_SimpleTable thead {
1.911 bisitz 7547: background:rgb(220,220,220);
1.693 droeschl 7548: }
7549:
1.721 harmsja 7550: div.LC_columnSection {
1.911 bisitz 7551: display: block;
7552: clear: both;
7553: overflow: hidden;
7554: margin: 0;
1.693 droeschl 7555: }
7556:
1.721 harmsja 7557: div.LC_columnSection>* {
1.911 bisitz 7558: float: left;
7559: margin: 10px 20px 10px 0;
7560: overflow:hidden;
1.693 droeschl 7561: }
1.721 harmsja 7562:
1.795 www 7563: table em {
1.911 bisitz 7564: font-weight: bold;
7565: font-style: normal;
1.748 schulted 7566: }
1.795 www 7567:
1.779 bisitz 7568: table.LC_tableBrowseRes,
1.795 www 7569: table.LC_tableOfContent {
1.911 bisitz 7570: border:none;
7571: border-spacing: 1px;
7572: padding: 3px;
7573: background-color: #FFFFFF;
7574: font-size: 90%;
1.753 droeschl 7575: }
1.789 droeschl 7576:
1.911 bisitz 7577: table.LC_tableOfContent {
7578: border-collapse: collapse;
1.789 droeschl 7579: }
7580:
1.771 droeschl 7581: table.LC_tableBrowseRes a,
1.768 schulted 7582: table.LC_tableOfContent a {
1.911 bisitz 7583: background-color: transparent;
7584: text-decoration: none;
1.753 droeschl 7585: }
7586:
1.795 www 7587: table.LC_tableOfContent img {
1.911 bisitz 7588: border: none;
7589: height: 1.3em;
7590: vertical-align: text-bottom;
7591: margin-right: 0.3em;
1.753 droeschl 7592: }
1.757 schulted 7593:
1.795 www 7594: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7595: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7596: }
7597:
1.795 www 7598: a#LC_content_toolbar_everything {
1.911 bisitz 7599: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7600: }
7601:
1.795 www 7602: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7603: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7604: }
7605:
1.795 www 7606: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7607: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7608: }
7609:
1.795 www 7610: a#LC_content_toolbar_changefolder {
1.911 bisitz 7611: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7612: }
7613:
1.795 www 7614: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7615: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7616: }
7617:
1.1043 raeburn 7618: a#LC_content_toolbar_edittoplevel {
7619: background-image:url(/res/adm/pages/edittoplevel.gif);
7620: }
7621:
1.795 www 7622: ul#LC_toolbar li a:hover {
1.911 bisitz 7623: background-position: bottom center;
1.757 schulted 7624: }
7625:
1.795 www 7626: ul#LC_toolbar {
1.911 bisitz 7627: padding: 0;
7628: margin: 2px;
7629: list-style:none;
7630: position:relative;
7631: background-color:white;
1.1075.2.9 raeburn 7632: overflow: auto;
1.757 schulted 7633: }
7634:
1.795 www 7635: ul#LC_toolbar li {
1.911 bisitz 7636: border:1px solid white;
7637: padding: 0;
7638: margin: 0;
7639: float: left;
7640: display:inline;
7641: vertical-align:middle;
1.1075.2.9 raeburn 7642: white-space: nowrap;
1.911 bisitz 7643: }
1.757 schulted 7644:
1.783 amueller 7645:
1.795 www 7646: a.LC_toolbarItem {
1.911 bisitz 7647: display:block;
7648: padding: 0;
7649: margin: 0;
7650: height: 32px;
7651: width: 32px;
7652: color:white;
7653: border: none;
7654: background-repeat:no-repeat;
7655: background-color:transparent;
1.757 schulted 7656: }
7657:
1.915 droeschl 7658: ul.LC_funclist {
7659: margin: 0;
7660: padding: 0.5em 1em 0.5em 0;
7661: }
7662:
1.933 droeschl 7663: ul.LC_funclist > li:first-child {
7664: font-weight:bold;
7665: margin-left:0.8em;
7666: }
7667:
1.915 droeschl 7668: ul.LC_funclist + ul.LC_funclist {
7669: /*
7670: left border as a seperator if we have more than
7671: one list
7672: */
7673: border-left: 1px solid $sidebg;
7674: /*
7675: this hides the left border behind the border of the
7676: outer box if element is wrapped to the next 'line'
7677: */
7678: margin-left: -1px;
7679: }
7680:
1.843 bisitz 7681: ul.LC_funclist li {
1.915 droeschl 7682: display: inline;
1.782 bisitz 7683: white-space: nowrap;
1.915 droeschl 7684: margin: 0 0 0 25px;
7685: line-height: 150%;
1.782 bisitz 7686: }
7687:
1.974 wenzelju 7688: .LC_hidden {
7689: display: none;
7690: }
7691:
1.1030 www 7692: .LCmodal-overlay {
7693: position:fixed;
7694: top:0;
7695: right:0;
7696: bottom:0;
7697: left:0;
7698: height:100%;
7699: width:100%;
7700: margin:0;
7701: padding:0;
7702: background:#999;
7703: opacity:.75;
7704: filter: alpha(opacity=75);
7705: -moz-opacity: 0.75;
7706: z-index:101;
7707: }
7708:
7709: * html .LCmodal-overlay {
7710: position: absolute;
7711: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7712: }
7713:
7714: .LCmodal-window {
7715: position:fixed;
7716: top:50%;
7717: left:50%;
7718: margin:0;
7719: padding:0;
7720: z-index:102;
7721: }
7722:
7723: * html .LCmodal-window {
7724: position:absolute;
7725: }
7726:
7727: .LCclose-window {
7728: position:absolute;
7729: width:32px;
7730: height:32px;
7731: right:8px;
7732: top:8px;
7733: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7734: text-indent:-99999px;
7735: overflow:hidden;
7736: cursor:pointer;
7737: }
7738:
1.1075.2.17 raeburn 7739: /*
7740: styles used by TTH when "Default set of options to pass to tth/m
7741: when converting TeX" in course settings has been set
7742:
7743: option passed: -t
7744:
7745: */
7746:
7747: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7748: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7749: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7750: td div.norm {line-height:normal;}
7751:
7752: /*
7753: option passed -y3
7754: */
7755:
7756: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7757: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7758: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7759:
1.1075.2.121 raeburn 7760: #LC_minitab_header {
7761: float:left;
7762: width:100%;
7763: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7764: font-size:93%;
7765: line-height:normal;
7766: margin: 0.5em 0 0.5em 0;
7767: }
7768: #LC_minitab_header ul {
7769: margin:0;
7770: padding:10px 10px 0;
7771: list-style:none;
7772: }
7773: #LC_minitab_header li {
7774: float:left;
7775: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7776: margin:0;
7777: padding:0 0 0 9px;
7778: }
7779: #LC_minitab_header a {
7780: display:block;
7781: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7782: padding:5px 15px 4px 6px;
7783: }
7784: #LC_minitab_header #LC_current_minitab {
7785: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7786: }
7787: #LC_minitab_header #LC_current_minitab a {
7788: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7789: padding-bottom:5px;
7790: }
7791:
7792:
1.343 albertel 7793: END
7794: }
7795:
1.306 albertel 7796: =pod
7797:
7798: =item * &headtag()
7799:
7800: Returns a uniform footer for LON-CAPA web pages.
7801:
1.307 albertel 7802: Inputs: $title - optional title for the head
7803: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7804: $args - optional arguments
1.319 albertel 7805: force_register - if is true call registerurl so the remote is
7806: informed
1.415 albertel 7807: redirect -> array ref of
7808: 1- seconds before redirect occurs
7809: 2- url to redirect to
7810: 3- whether the side effect should occur
1.315 albertel 7811: (side effect of setting
7812: $env{'internal.head.redirect'} to the url
7813: redirected too)
1.352 albertel 7814: domain -> force to color decorate a page for a specific
7815: domain
7816: function -> force usage of a specific rolish color scheme
7817: bgcolor -> override the default page bgcolor
1.460 albertel 7818: no_auto_mt_title
7819: -> prevent &mt()ing the title arg
1.464 albertel 7820:
1.306 albertel 7821: =cut
7822:
7823: sub headtag {
1.313 albertel 7824: my ($title,$head_extra,$args) = @_;
1.306 albertel 7825:
1.363 albertel 7826: my $function = $args->{'function'} || &get_users_function();
7827: my $domain = $args->{'domain'} || &determinedomain();
7828: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7829: my $httphost = $args->{'use_absolute'};
1.418 albertel 7830: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7831: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7832: #time(),
1.418 albertel 7833: $env{'environment.color.timestamp'},
1.363 albertel 7834: $function,$domain,$bgcolor);
7835:
1.369 www 7836: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7837:
1.308 albertel 7838: my $result =
7839: '<head>'.
1.1075.2.56 raeburn 7840: &font_settings($args);
1.319 albertel 7841:
1.1075.2.72 raeburn 7842: my $inhibitprint;
7843: if ($args->{'print_suppress'}) {
7844: $inhibitprint = &print_suppression();
7845: }
1.1064 raeburn 7846:
1.461 albertel 7847: if (!$args->{'frameset'}) {
7848: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7849: }
1.1075.2.12 raeburn 7850: if ($args->{'force_register'}) {
7851: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7852: }
1.436 albertel 7853: if (!$args->{'no_nav_bar'}
7854: && !$args->{'only_body'}
7855: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7856: $result .= &help_menu_js($httphost);
1.1032 www 7857: $result.=&modal_window();
1.1038 www 7858: $result.=&togglebox_script();
1.1034 www 7859: $result.=&wishlist_window();
1.1041 www 7860: $result.=&LCprogressbarUpdate_script();
1.1034 www 7861: } else {
7862: if ($args->{'add_modal'}) {
7863: $result.=&modal_window();
7864: }
7865: if ($args->{'add_wishlist'}) {
7866: $result.=&wishlist_window();
7867: }
1.1038 www 7868: if ($args->{'add_togglebox'}) {
7869: $result.=&togglebox_script();
7870: }
1.1041 www 7871: if ($args->{'add_progressbar'}) {
7872: $result.=&LCprogressbarUpdate_script();
7873: }
1.436 albertel 7874: }
1.314 albertel 7875: if (ref($args->{'redirect'})) {
1.414 albertel 7876: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7877: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7878: if (!$inhibit_continue) {
7879: $env{'internal.head.redirect'} = $url;
7880: }
1.313 albertel 7881: $result.=<<ADDMETA
7882: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7883: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7884: ADDMETA
1.1075.2.89 raeburn 7885: } else {
7886: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7887: my $requrl = $env{'request.uri'};
7888: if ($requrl eq '') {
7889: $requrl = $ENV{'REQUEST_URI'};
7890: $requrl =~ s/\?.+$//;
7891: }
7892: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7893: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7894: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7895: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7896: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7897: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7898: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7899: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7900: if ($domdefs{'offloadnow'}{$lonhost}) {
7901: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7902: if (($newserver) && ($newserver ne $lonhost)) {
7903: my $numsec = 5;
7904: my $timeout = $numsec * 1000;
7905: my ($newurl,$locknum,%locks,$msg);
7906: if ($env{'request.role.adv'}) {
7907: ($locknum,%locks) = &Apache::lonnet::get_locks();
7908: }
7909: my $disable_submit = 0;
7910: if ($requrl =~ /$LONCAPA::assess_re/) {
7911: $disable_submit = 1;
7912: }
7913: if ($locknum) {
7914: my @lockinfo = sort(values(%locks));
7915: $msg = &mt('Once the following tasks are complete: ')."\\n".
7916: join(", ",sort(values(%locks)))."\\n".
7917: &mt('your session will be transferred to a different server, after you click "Roles".');
7918: } else {
7919: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7920: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7921: }
7922: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7923: $newurl = '/adm/switchserver?otherserver='.$newserver;
7924: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7925: $newurl .= '&role='.$env{'request.role'};
7926: }
7927: if ($env{'request.symb'}) {
7928: $newurl .= '&symb='.$env{'request.symb'};
7929: } else {
7930: $newurl .= '&origurl='.$requrl;
7931: }
7932: }
1.1075.2.98 raeburn 7933: &js_escape(\$msg);
1.1075.2.89 raeburn 7934: $result.=<<OFFLOAD
7935: <meta http-equiv="pragma" content="no-cache" />
7936: <script type="text/javascript">
1.1075.2.92 raeburn 7937: // <![CDATA[
1.1075.2.89 raeburn 7938: function LC_Offload_Now() {
7939: var dest = "$newurl";
7940: if (dest != '') {
7941: window.location.href="$newurl";
7942: }
7943: }
1.1075.2.92 raeburn 7944: \$(document).ready(function () {
7945: window.alert('$msg');
7946: if ($disable_submit) {
1.1075.2.89 raeburn 7947: \$(".LC_hwk_submit").prop("disabled", true);
7948: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7949: }
7950: setTimeout('LC_Offload_Now()', $timeout);
7951: });
7952: // ]]>
1.1075.2.89 raeburn 7953: </script>
7954: OFFLOAD
7955: }
7956: }
7957: }
7958: }
7959: }
7960: }
1.313 albertel 7961: }
1.306 albertel 7962: if (!defined($title)) {
7963: $title = 'The LearningOnline Network with CAPA';
7964: }
1.460 albertel 7965: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7966: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7967: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7968: if (!$args->{'frameset'}) {
7969: $result .= ' /';
7970: }
7971: $result .= '>'
1.1064 raeburn 7972: .$inhibitprint
1.414 albertel 7973: .$head_extra;
1.1075.2.108 raeburn 7974: my $clientmobile;
7975: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7976: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7977: } else {
7978: $clientmobile = $env{'browser.mobile'};
7979: }
7980: if ($clientmobile) {
1.1075.2.42 raeburn 7981: $result .= '
7982: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7983: <meta name="apple-mobile-web-app-capable" content="yes" />';
7984: }
1.1075.2.126 raeburn 7985: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7986: return $result.'</head>';
1.306 albertel 7987: }
7988:
7989: =pod
7990:
1.340 albertel 7991: =item * &font_settings()
7992:
7993: Returns neccessary <meta> to set the proper encoding
7994:
1.1075.2.56 raeburn 7995: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7996:
7997: =cut
7998:
7999: sub font_settings {
1.1075.2.56 raeburn 8000: my ($args) = @_;
1.340 albertel 8001: my $headerstring='';
1.1075.2.56 raeburn 8002: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8003: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8004: $headerstring.=
1.1075.2.61 raeburn 8005: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8006: if (!$args->{'frameset'}) {
8007: $headerstring.= ' /';
8008: }
8009: $headerstring .= '>'."\n";
1.340 albertel 8010: }
8011: return $headerstring;
8012: }
8013:
1.341 albertel 8014: =pod
8015:
1.1064 raeburn 8016: =item * &print_suppression()
8017:
8018: In course context returns css which causes the body to be blank when media="print",
8019: if printout generation is unavailable for the current resource.
8020:
8021: This could be because:
8022:
8023: (a) printstartdate is in the future
8024:
8025: (b) printenddate is in the past
8026:
8027: (c) there is an active exam block with "printout"
8028: functionality blocked
8029:
8030: Users with pav, pfo or evb privileges are exempt.
8031:
8032: Inputs: none
8033:
8034: =cut
8035:
8036:
8037: sub print_suppression {
8038: my $noprint;
8039: if ($env{'request.course.id'}) {
8040: my $scope = $env{'request.course.id'};
8041: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8042: (&Apache::lonnet::allowed('pfo',$scope))) {
8043: return;
8044: }
8045: if ($env{'request.course.sec'} ne '') {
8046: $scope .= "/$env{'request.course.sec'}";
8047: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8048: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8049: return;
1.1064 raeburn 8050: }
8051: }
8052: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8053: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8054: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8055: if ($blocked) {
8056: my $checkrole = "cm./$cdom/$cnum";
8057: if ($env{'request.course.sec'} ne '') {
8058: $checkrole .= "/$env{'request.course.sec'}";
8059: }
8060: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8061: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8062: $noprint = 1;
8063: }
8064: }
8065: unless ($noprint) {
8066: my $symb = &Apache::lonnet::symbread();
8067: if ($symb ne '') {
8068: my $navmap = Apache::lonnavmaps::navmap->new();
8069: if (ref($navmap)) {
8070: my $res = $navmap->getBySymb($symb);
8071: if (ref($res)) {
8072: if (!$res->resprintable()) {
8073: $noprint = 1;
8074: }
8075: }
8076: }
8077: }
8078: }
8079: if ($noprint) {
8080: return <<"ENDSTYLE";
8081: <style type="text/css" media="print">
8082: body { display:none }
8083: </style>
8084: ENDSTYLE
8085: }
8086: }
8087: return;
8088: }
8089:
8090: =pod
8091:
1.341 albertel 8092: =item * &xml_begin()
8093:
8094: Returns the needed doctype and <html>
8095:
8096: Inputs: none
8097:
8098: =cut
8099:
8100: sub xml_begin {
1.1075.2.61 raeburn 8101: my ($is_frameset) = @_;
1.341 albertel 8102: my $output='';
8103:
8104: if ($env{'browser.mathml'}) {
8105: $output='<?xml version="1.0"?>'
8106: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8107: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8108:
8109: # .'<!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">] >'
8110: .'<!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">'
8111: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8112: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8113: } elsif ($is_frameset) {
8114: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8115: '<html>'."\n";
1.341 albertel 8116: } else {
1.1075.2.61 raeburn 8117: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8118: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8119: }
8120: return $output;
8121: }
1.340 albertel 8122:
8123: =pod
8124:
1.306 albertel 8125: =item * &start_page()
8126:
8127: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8128:
1.648 raeburn 8129: Inputs:
8130:
8131: =over 4
8132:
8133: $title - optional title for the page
8134:
8135: $head_extra - optional extra HTML to incude inside the <head>
8136:
8137: $args - additional optional args supported are:
8138:
8139: =over 8
8140:
8141: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8142: arg on
1.814 bisitz 8143: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8144: add_entries -> additional attributes to add to the <body>
8145: domain -> force to color decorate a page for a
1.317 albertel 8146: specific domain
1.648 raeburn 8147: function -> force usage of a specific rolish color
1.317 albertel 8148: scheme
1.648 raeburn 8149: redirect -> see &headtag()
8150: bgcolor -> override the default page bg color
8151: js_ready -> return a string ready for being used in
1.317 albertel 8152: a javascript writeln
1.648 raeburn 8153: html_encode -> return a string ready for being used in
1.320 albertel 8154: a html attribute
1.648 raeburn 8155: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8156: $forcereg arg
1.648 raeburn 8157: frameset -> if true will start with a <frameset>
1.330 albertel 8158: rather than <body>
1.648 raeburn 8159: skip_phases -> hash ref of
1.338 albertel 8160: head -> skip the <html><head> generation
8161: body -> skip all <body> generation
1.1075.2.12 raeburn 8162: no_inline_link -> if true and in remote mode, don't show the
8163: 'Switch To Inline Menu' link
1.648 raeburn 8164: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8165: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8166: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8167: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8168: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8169: group -> includes the current group, if page is for a
8170: specific group
1.361 albertel 8171:
1.648 raeburn 8172: =back
1.460 albertel 8173:
1.648 raeburn 8174: =back
1.562 albertel 8175:
1.306 albertel 8176: =cut
8177:
8178: sub start_page {
1.309 albertel 8179: my ($title,$head_extra,$args) = @_;
1.318 albertel 8180: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8181:
1.315 albertel 8182: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8183: my ($result,@advtools);
1.964 droeschl 8184:
1.338 albertel 8185: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8186: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8187: }
8188:
8189: if (! exists($args->{'skip_phases'}{'body'}) ) {
8190: if ($args->{'frameset'}) {
8191: my $attr_string = &make_attr_string($args->{'force_register'},
8192: $args->{'add_entries'});
8193: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8194: } else {
8195: $result .=
8196: &bodytag($title,
8197: $args->{'function'}, $args->{'add_entries'},
8198: $args->{'only_body'}, $args->{'domain'},
8199: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8200: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8201: $args, \@advtools);
1.831 bisitz 8202: }
1.330 albertel 8203: }
1.338 albertel 8204:
1.315 albertel 8205: if ($args->{'js_ready'}) {
1.713 kaisler 8206: $result = &js_ready($result);
1.315 albertel 8207: }
1.320 albertel 8208: if ($args->{'html_encode'}) {
1.713 kaisler 8209: $result = &html_encode($result);
8210: }
8211:
1.813 bisitz 8212: # Preparation for new and consistent functionlist at top of screen
8213: # if ($args->{'functionlist'}) {
8214: # $result .= &build_functionlist();
8215: #}
8216:
1.964 droeschl 8217: # Don't add anything more if only_body wanted or in const space
8218: return $result if $args->{'only_body'}
8219: || $env{'request.state'} eq 'construct';
1.813 bisitz 8220:
8221: #Breadcrumbs
1.758 kaisler 8222: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8223: &Apache::lonhtmlcommon::clear_breadcrumbs();
8224: #if any br links exists, add them to the breadcrumbs
8225: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8226: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8227: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8228: }
8229: }
1.1075.2.19 raeburn 8230: # if @advtools array contains items add then to the breadcrumbs
8231: if (@advtools > 0) {
8232: &Apache::lonmenu::advtools_crumbs(@advtools);
8233: }
1.1075.2.123 raeburn 8234: my $menulink;
8235: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8236: if (exists($args->{'bread_crumbs_nomenu'})) {
8237: $menulink = 0;
8238: } else {
8239: undef($menulink);
8240: }
1.758 kaisler 8241: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8242: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8243: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8244: }else{
1.1075.2.123 raeburn 8245: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8246: }
1.1075.2.24 raeburn 8247: } elsif (($env{'environment.remote'} eq 'on') &&
8248: ($env{'form.inhibitmenu'} ne 'yes') &&
8249: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8250: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8251: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8252: }
1.315 albertel 8253: return $result;
1.306 albertel 8254: }
8255:
8256: sub end_page {
1.315 albertel 8257: my ($args) = @_;
8258: $env{'internal.end_page'}++;
1.330 albertel 8259: my $result;
1.335 albertel 8260: if ($args->{'discussion'}) {
8261: my ($target,$parser);
8262: if (ref($args->{'discussion'})) {
8263: ($target,$parser) =($args->{'discussion'}{'target'},
8264: $args->{'discussion'}{'parser'});
8265: }
8266: $result .= &Apache::lonxml::xmlend($target,$parser);
8267: }
1.330 albertel 8268: if ($args->{'frameset'}) {
8269: $result .= '</frameset>';
8270: } else {
1.635 raeburn 8271: $result .= &endbodytag($args);
1.330 albertel 8272: }
1.1075.2.6 raeburn 8273: unless ($args->{'notbody'}) {
8274: $result .= "\n</html>";
8275: }
1.330 albertel 8276:
1.315 albertel 8277: if ($args->{'js_ready'}) {
1.317 albertel 8278: $result = &js_ready($result);
1.315 albertel 8279: }
1.335 albertel 8280:
1.320 albertel 8281: if ($args->{'html_encode'}) {
8282: $result = &html_encode($result);
8283: }
1.335 albertel 8284:
1.315 albertel 8285: return $result;
8286: }
8287:
1.1034 www 8288: sub wishlist_window {
8289: return(<<'ENDWISHLIST');
1.1046 raeburn 8290: <script type="text/javascript">
1.1034 www 8291: // <![CDATA[
8292: // <!-- BEGIN LON-CAPA Internal
8293: function set_wishlistlink(title, path) {
8294: if (!title) {
8295: title = document.title;
8296: title = title.replace(/^LON-CAPA /,'');
8297: }
1.1075.2.65 raeburn 8298: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8299: title = title.replace("'","\\\'");
1.1034 www 8300: if (!path) {
8301: path = location.pathname;
8302: }
1.1075.2.65 raeburn 8303: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8304: path = path.replace("'","\\\'");
1.1034 www 8305: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8306: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8307: }
8308: // END LON-CAPA Internal -->
8309: // ]]>
8310: </script>
8311: ENDWISHLIST
8312: }
8313:
1.1030 www 8314: sub modal_window {
8315: return(<<'ENDMODAL');
1.1046 raeburn 8316: <script type="text/javascript">
1.1030 www 8317: // <![CDATA[
8318: // <!-- BEGIN LON-CAPA Internal
8319: var modalWindow = {
8320: parent:"body",
8321: windowId:null,
8322: content:null,
8323: width:null,
8324: height:null,
8325: close:function()
8326: {
8327: $(".LCmodal-window").remove();
8328: $(".LCmodal-overlay").remove();
8329: },
8330: open:function()
8331: {
8332: var modal = "";
8333: modal += "<div class=\"LCmodal-overlay\"></div>";
8334: 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;\">";
8335: modal += this.content;
8336: modal += "</div>";
8337:
8338: $(this.parent).append(modal);
8339:
8340: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8341: $(".LCclose-window").click(function(){modalWindow.close();});
8342: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8343: }
8344: };
1.1075.2.42 raeburn 8345: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8346: {
1.1075.2.119 raeburn 8347: source = source.replace(/'/g,"'");
1.1030 www 8348: modalWindow.windowId = "myModal";
8349: modalWindow.width = width;
8350: modalWindow.height = height;
1.1075.2.80 raeburn 8351: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8352: modalWindow.open();
1.1075.2.87 raeburn 8353: };
1.1030 www 8354: // END LON-CAPA Internal -->
8355: // ]]>
8356: </script>
8357: ENDMODAL
8358: }
8359:
8360: sub modal_link {
1.1075.2.42 raeburn 8361: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8362: unless ($width) { $width=480; }
8363: unless ($height) { $height=400; }
1.1031 www 8364: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8365: unless ($transparency) { $transparency='true'; }
8366:
1.1074 raeburn 8367: my $target_attr;
8368: if (defined($target)) {
8369: $target_attr = 'target="'.$target.'"';
8370: }
8371: return <<"ENDLINK";
1.1075.2.42 raeburn 8372: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8373: $linktext</a>
8374: ENDLINK
1.1030 www 8375: }
8376:
1.1032 www 8377: sub modal_adhoc_script {
8378: my ($funcname,$width,$height,$content)=@_;
8379: return (<<ENDADHOC);
1.1046 raeburn 8380: <script type="text/javascript">
1.1032 www 8381: // <![CDATA[
8382: var $funcname = function()
8383: {
8384: modalWindow.windowId = "myModal";
8385: modalWindow.width = $width;
8386: modalWindow.height = $height;
8387: modalWindow.content = '$content';
8388: modalWindow.open();
8389: };
8390: // ]]>
8391: </script>
8392: ENDADHOC
8393: }
8394:
1.1041 www 8395: sub modal_adhoc_inner {
8396: my ($funcname,$width,$height,$content)=@_;
8397: my $innerwidth=$width-20;
8398: $content=&js_ready(
1.1042 www 8399: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8400: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8401: $content.
1.1041 www 8402: &end_scrollbox().
1.1075.2.42 raeburn 8403: &end_page()
1.1041 www 8404: );
8405: return &modal_adhoc_script($funcname,$width,$height,$content);
8406: }
8407:
8408: sub modal_adhoc_window {
8409: my ($funcname,$width,$height,$content,$linktext)=@_;
8410: return &modal_adhoc_inner($funcname,$width,$height,$content).
8411: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8412: }
8413:
8414: sub modal_adhoc_launch {
8415: my ($funcname,$width,$height,$content)=@_;
8416: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8417: <script type="text/javascript">
8418: // <![CDATA[
8419: $funcname();
8420: // ]]>
8421: </script>
8422: ENDLAUNCH
8423: }
8424:
8425: sub modal_adhoc_close {
8426: return (<<ENDCLOSE);
8427: <script type="text/javascript">
8428: // <![CDATA[
8429: modalWindow.close();
8430: // ]]>
8431: </script>
8432: ENDCLOSE
8433: }
8434:
1.1038 www 8435: sub togglebox_script {
8436: return(<<ENDTOGGLE);
8437: <script type="text/javascript">
8438: // <![CDATA[
8439: function LCtoggleDisplay(id,hidetext,showtext) {
8440: link = document.getElementById(id + "link").childNodes[0];
8441: with (document.getElementById(id).style) {
8442: if (display == "none" ) {
8443: display = "inline";
8444: link.nodeValue = hidetext;
8445: } else {
8446: display = "none";
8447: link.nodeValue = showtext;
8448: }
8449: }
8450: }
8451: // ]]>
8452: </script>
8453: ENDTOGGLE
8454: }
8455:
1.1039 www 8456: sub start_togglebox {
8457: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8458: unless ($heading) { $heading=''; } else { $heading.=' '; }
8459: unless ($showtext) { $showtext=&mt('show'); }
8460: unless ($hidetext) { $hidetext=&mt('hide'); }
8461: unless ($headerbg) { $headerbg='#FFFFFF'; }
8462: return &start_data_table().
8463: &start_data_table_header_row().
8464: '<td bgcolor="'.$headerbg.'">'.$heading.
8465: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8466: $showtext.'\')">'.$showtext.'</a>]</td>'.
8467: &end_data_table_header_row().
8468: '<tr id="'.$id.'" style="display:none""><td>';
8469: }
8470:
8471: sub end_togglebox {
8472: return '</td></tr>'.&end_data_table();
8473: }
8474:
1.1041 www 8475: sub LCprogressbar_script {
1.1045 www 8476: my ($id)=@_;
1.1041 www 8477: return(<<ENDPROGRESS);
8478: <script type="text/javascript">
8479: // <![CDATA[
1.1045 www 8480: \$('#progressbar$id').progressbar({
1.1041 www 8481: value: 0,
8482: change: function(event, ui) {
8483: var newVal = \$(this).progressbar('option', 'value');
8484: \$('.pblabel', this).text(LCprogressTxt);
8485: }
8486: });
8487: // ]]>
8488: </script>
8489: ENDPROGRESS
8490: }
8491:
8492: sub LCprogressbarUpdate_script {
8493: return(<<ENDPROGRESSUPDATE);
8494: <style type="text/css">
8495: .ui-progressbar { position:relative; }
8496: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8497: </style>
8498: <script type="text/javascript">
8499: // <![CDATA[
1.1045 www 8500: var LCprogressTxt='---';
8501:
8502: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8503: LCprogressTxt=progresstext;
1.1045 www 8504: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8505: }
8506: // ]]>
8507: </script>
8508: ENDPROGRESSUPDATE
8509: }
8510:
1.1042 www 8511: my $LClastpercent;
1.1045 www 8512: my $LCidcnt;
8513: my $LCcurrentid;
1.1042 www 8514:
1.1041 www 8515: sub LCprogressbar {
1.1042 www 8516: my ($r)=(@_);
8517: $LClastpercent=0;
1.1045 www 8518: $LCidcnt++;
8519: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8520: my $starting=&mt('Starting');
8521: my $content=(<<ENDPROGBAR);
1.1045 www 8522: <div id="progressbar$LCcurrentid">
1.1041 www 8523: <span class="pblabel">$starting</span>
8524: </div>
8525: ENDPROGBAR
1.1045 www 8526: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8527: }
8528:
8529: sub LCprogressbarUpdate {
1.1042 www 8530: my ($r,$val,$text)=@_;
8531: unless ($val) {
8532: if ($LClastpercent) {
8533: $val=$LClastpercent;
8534: } else {
8535: $val=0;
8536: }
8537: }
1.1041 www 8538: if ($val<0) { $val=0; }
8539: if ($val>100) { $val=0; }
1.1042 www 8540: $LClastpercent=$val;
1.1041 www 8541: unless ($text) { $text=$val.'%'; }
8542: $text=&js_ready($text);
1.1044 www 8543: &r_print($r,<<ENDUPDATE);
1.1041 www 8544: <script type="text/javascript">
8545: // <![CDATA[
1.1045 www 8546: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8547: // ]]>
8548: </script>
8549: ENDUPDATE
1.1035 www 8550: }
8551:
1.1042 www 8552: sub LCprogressbarClose {
8553: my ($r)=@_;
8554: $LClastpercent=0;
1.1044 www 8555: &r_print($r,<<ENDCLOSE);
1.1042 www 8556: <script type="text/javascript">
8557: // <![CDATA[
1.1045 www 8558: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8559: // ]]>
8560: </script>
8561: ENDCLOSE
1.1044 www 8562: }
8563:
8564: sub r_print {
8565: my ($r,$to_print)=@_;
8566: if ($r) {
8567: $r->print($to_print);
8568: $r->rflush();
8569: } else {
8570: print($to_print);
8571: }
1.1042 www 8572: }
8573:
1.320 albertel 8574: sub html_encode {
8575: my ($result) = @_;
8576:
1.322 albertel 8577: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8578:
8579: return $result;
8580: }
1.1044 www 8581:
1.317 albertel 8582: sub js_ready {
8583: my ($result) = @_;
8584:
1.323 albertel 8585: $result =~ s/[\n\r]/ /xmsg;
8586: $result =~ s/\\/\\\\/xmsg;
8587: $result =~ s/'/\\'/xmsg;
1.372 albertel 8588: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8589:
8590: return $result;
8591: }
8592:
1.315 albertel 8593: sub validate_page {
8594: if ( exists($env{'internal.start_page'})
1.316 albertel 8595: && $env{'internal.start_page'} > 1) {
8596: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8597: $env{'internal.start_page'}.' '.
1.316 albertel 8598: $ENV{'request.filename'});
1.315 albertel 8599: }
8600: if ( exists($env{'internal.end_page'})
1.316 albertel 8601: && $env{'internal.end_page'} > 1) {
8602: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8603: $env{'internal.end_page'}.' '.
1.316 albertel 8604: $env{'request.filename'});
1.315 albertel 8605: }
8606: if ( exists($env{'internal.start_page'})
8607: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8608: &Apache::lonnet::logthis('start_page called without end_page '.
8609: $env{'request.filename'});
1.315 albertel 8610: }
8611: if ( ! exists($env{'internal.start_page'})
8612: && exists($env{'internal.end_page'})) {
1.316 albertel 8613: &Apache::lonnet::logthis('end_page called without start_page'.
8614: $env{'request.filename'});
1.315 albertel 8615: }
1.306 albertel 8616: }
1.315 albertel 8617:
1.996 www 8618:
8619: sub start_scrollbox {
1.1075.2.56 raeburn 8620: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8621: unless ($outerwidth) { $outerwidth='520px'; }
8622: unless ($width) { $width='500px'; }
8623: unless ($height) { $height='200px'; }
1.1075 raeburn 8624: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8625: if ($id ne '') {
1.1075.2.42 raeburn 8626: $table_id = ' id="table_'.$id.'"';
8627: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8628: }
1.1075 raeburn 8629: if ($bgcolor ne '') {
8630: $tdcol = "background-color: $bgcolor;";
8631: }
1.1075.2.42 raeburn 8632: my $nicescroll_js;
8633: if ($env{'browser.mobile'}) {
8634: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8635: }
1.1075 raeburn 8636: return <<"END";
1.1075.2.42 raeburn 8637: $nicescroll_js
8638:
8639: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8640: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8641: END
1.996 www 8642: }
8643:
8644: sub end_scrollbox {
1.1036 www 8645: return '</div></td></tr></table>';
1.996 www 8646: }
8647:
1.1075.2.42 raeburn 8648: sub nicescroll_javascript {
8649: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8650: my %options;
8651: if (ref($cursor) eq 'HASH') {
8652: %options = %{$cursor};
8653: }
8654: unless ($options{'railalign'} =~ /^left|right$/) {
8655: $options{'railalign'} = 'left';
8656: }
8657: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8658: my $function = &get_users_function();
8659: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8660: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8661: $options{'cursorcolor'} = '#00F';
8662: }
8663: }
8664: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8665: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8666: $options{'cursoropacity'}='1.0';
8667: }
8668: } else {
8669: $options{'cursoropacity'}='1.0';
8670: }
8671: if ($options{'cursorfixedheight'} eq 'none') {
8672: delete($options{'cursorfixedheight'});
8673: } else {
8674: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8675: }
8676: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8677: delete($options{'railoffset'});
8678: }
8679: my @niceoptions;
8680: while (my($key,$value) = each(%options)) {
8681: if ($value =~ /^\{.+\}$/) {
8682: push(@niceoptions,$key.':'.$value);
8683: } else {
8684: push(@niceoptions,$key.':"'.$value.'"');
8685: }
8686: }
8687: my $nicescroll_js = '
8688: $(document).ready(
8689: function() {
8690: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8691: }
8692: );
8693: ';
8694: if ($framecheck) {
8695: $nicescroll_js .= '
8696: function expand_div(caller) {
8697: if (top === self) {
8698: document.getElementById("'.$id.'").style.width = "auto";
8699: document.getElementById("'.$id.'").style.height = "auto";
8700: } else {
8701: try {
8702: if (parent.frames) {
8703: if (parent.frames.length > 1) {
8704: var framesrc = parent.frames[1].location.href;
8705: var currsrc = framesrc.replace(/\#.*$/,"");
8706: if ((caller == "search") || (currsrc == "'.$location.'")) {
8707: document.getElementById("'.$id.'").style.width = "auto";
8708: document.getElementById("'.$id.'").style.height = "auto";
8709: }
8710: }
8711: }
8712: } catch (e) {
8713: return;
8714: }
8715: }
8716: return;
8717: }
8718: ';
8719: }
8720: if ($needjsready) {
8721: $nicescroll_js = '
8722: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8723: } else {
8724: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8725: }
8726: return $nicescroll_js;
8727: }
8728:
1.318 albertel 8729: sub simple_error_page {
1.1075.2.49 raeburn 8730: my ($r,$title,$msg,$args) = @_;
8731: if (ref($args) eq 'HASH') {
8732: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8733: } else {
8734: $msg = &mt($msg);
8735: }
8736:
1.318 albertel 8737: my $page =
8738: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8739: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8740: &Apache::loncommon::end_page();
8741: if (ref($r)) {
8742: $r->print($page);
1.327 albertel 8743: return;
1.318 albertel 8744: }
8745: return $page;
8746: }
1.347 albertel 8747:
8748: {
1.610 albertel 8749: my @row_count;
1.961 onken 8750:
8751: sub start_data_table_count {
8752: unshift(@row_count, 0);
8753: return;
8754: }
8755:
8756: sub end_data_table_count {
8757: shift(@row_count);
8758: return;
8759: }
8760:
1.347 albertel 8761: sub start_data_table {
1.1018 raeburn 8762: my ($add_class,$id) = @_;
1.422 albertel 8763: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8764: my $table_id;
8765: if (defined($id)) {
8766: $table_id = ' id="'.$id.'"';
8767: }
1.961 onken 8768: &start_data_table_count();
1.1018 raeburn 8769: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8770: }
8771:
8772: sub end_data_table {
1.961 onken 8773: &end_data_table_count();
1.389 albertel 8774: return '</table>'."\n";;
1.347 albertel 8775: }
8776:
8777: sub start_data_table_row {
1.974 wenzelju 8778: my ($add_class, $id) = @_;
1.610 albertel 8779: $row_count[0]++;
8780: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8781: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8782: $id = (' id="'.$id.'"') unless ($id eq '');
8783: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8784: }
1.471 banghart 8785:
8786: sub continue_data_table_row {
1.974 wenzelju 8787: my ($add_class, $id) = @_;
1.610 albertel 8788: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8789: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8790: $id = (' id="'.$id.'"') unless ($id eq '');
8791: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8792: }
1.347 albertel 8793:
8794: sub end_data_table_row {
1.389 albertel 8795: return '</tr>'."\n";;
1.347 albertel 8796: }
1.367 www 8797:
1.421 albertel 8798: sub start_data_table_empty_row {
1.707 bisitz 8799: # $row_count[0]++;
1.421 albertel 8800: return '<tr class="LC_empty_row" >'."\n";;
8801: }
8802:
8803: sub end_data_table_empty_row {
8804: return '</tr>'."\n";;
8805: }
8806:
1.367 www 8807: sub start_data_table_header_row {
1.389 albertel 8808: return '<tr class="LC_header_row">'."\n";;
1.367 www 8809: }
8810:
8811: sub end_data_table_header_row {
1.389 albertel 8812: return '</tr>'."\n";;
1.367 www 8813: }
1.890 droeschl 8814:
8815: sub data_table_caption {
8816: my $caption = shift;
8817: return "<caption class=\"LC_caption\">$caption</caption>";
8818: }
1.347 albertel 8819: }
8820:
1.548 albertel 8821: =pod
8822:
8823: =item * &inhibit_menu_check($arg)
8824:
8825: Checks for a inhibitmenu state and generates output to preserve it
8826:
8827: Inputs: $arg - can be any of
8828: - undef - in which case the return value is a string
8829: to add into arguments list of a uri
8830: - 'input' - in which case the return value is a HTML
8831: <form> <input> field of type hidden to
8832: preserve the value
8833: - a url - in which case the return value is the url with
8834: the neccesary cgi args added to preserve the
8835: inhibitmenu state
8836: - a ref to a url - no return value, but the string is
8837: updated to include the neccessary cgi
8838: args to preserve the inhibitmenu state
8839:
8840: =cut
8841:
8842: sub inhibit_menu_check {
8843: my ($arg) = @_;
8844: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8845: if ($arg eq 'input') {
8846: if ($env{'form.inhibitmenu'}) {
8847: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8848: } else {
8849: return
8850: }
8851: }
8852: if ($env{'form.inhibitmenu'}) {
8853: if (ref($arg)) {
8854: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8855: } elsif ($arg eq '') {
8856: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8857: } else {
8858: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8859: }
8860: }
8861: if (!ref($arg)) {
8862: return $arg;
8863: }
8864: }
8865:
1.251 albertel 8866: ###############################################
1.182 matthew 8867:
8868: =pod
8869:
1.549 albertel 8870: =back
8871:
8872: =head1 User Information Routines
8873:
8874: =over 4
8875:
1.405 albertel 8876: =item * &get_users_function()
1.182 matthew 8877:
8878: Used by &bodytag to determine the current users primary role.
8879: Returns either 'student','coordinator','admin', or 'author'.
8880:
8881: =cut
8882:
8883: ###############################################
8884: sub get_users_function {
1.815 tempelho 8885: my $function = 'norole';
1.818 tempelho 8886: if ($env{'request.role'}=~/^(st)/) {
8887: $function='student';
8888: }
1.907 raeburn 8889: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8890: $function='coordinator';
8891: }
1.258 albertel 8892: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8893: $function='admin';
8894: }
1.826 bisitz 8895: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8896: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8897: $function='author';
8898: }
8899: return $function;
1.54 www 8900: }
1.99 www 8901:
8902: ###############################################
8903:
1.233 raeburn 8904: =pod
8905:
1.821 raeburn 8906: =item * &show_course()
8907:
8908: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8909: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8910:
8911: Inputs:
8912: None
8913:
8914: Outputs:
8915: Scalar: 1 if 'Course' to be used, 0 otherwise.
8916:
8917: =cut
8918:
8919: ###############################################
8920: sub show_course {
8921: my $course = !$env{'user.adv'};
8922: if (!$env{'user.adv'}) {
8923: foreach my $env (keys(%env)) {
8924: next if ($env !~ m/^user\.priv\./);
8925: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8926: $course = 0;
8927: last;
8928: }
8929: }
8930: }
8931: return $course;
8932: }
8933:
8934: ###############################################
8935:
8936: =pod
8937:
1.542 raeburn 8938: =item * &check_user_status()
1.274 raeburn 8939:
8940: Determines current status of supplied role for a
8941: specific user. Roles can be active, previous or future.
8942:
8943: Inputs:
8944: user's domain, user's username, course's domain,
1.375 raeburn 8945: course's number, optional section ID.
1.274 raeburn 8946:
8947: Outputs:
8948: role status: active, previous or future.
8949:
8950: =cut
8951:
8952: sub check_user_status {
1.412 raeburn 8953: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8954: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8955: my @uroles = keys(%userinfo);
1.274 raeburn 8956: my $srchstr;
8957: my $active_chk = 'none';
1.412 raeburn 8958: my $now = time;
1.274 raeburn 8959: if (@uroles > 0) {
1.908 raeburn 8960: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8961: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8962: } else {
1.412 raeburn 8963: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8964: }
8965: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8966: my $role_end = 0;
8967: my $role_start = 0;
8968: $active_chk = 'active';
1.412 raeburn 8969: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8970: $role_end = $1;
8971: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8972: $role_start = $1;
1.274 raeburn 8973: }
8974: }
8975: if ($role_start > 0) {
1.412 raeburn 8976: if ($now < $role_start) {
1.274 raeburn 8977: $active_chk = 'future';
8978: }
8979: }
8980: if ($role_end > 0) {
1.412 raeburn 8981: if ($now > $role_end) {
1.274 raeburn 8982: $active_chk = 'previous';
8983: }
8984: }
8985: }
8986: }
8987: return $active_chk;
8988: }
8989:
8990: ###############################################
8991:
8992: =pod
8993:
1.405 albertel 8994: =item * &get_sections()
1.233 raeburn 8995:
8996: Determines all the sections for a course including
8997: sections with students and sections containing other roles.
1.419 raeburn 8998: Incoming parameters:
8999:
9000: 1. domain
9001: 2. course number
9002: 3. reference to array containing roles for which sections should
9003: be gathered (optional).
9004: 4. reference to array containing status types for which sections
9005: should be gathered (optional).
9006:
9007: If the third argument is undefined, sections are gathered for any role.
9008: If the fourth argument is undefined, sections are gathered for any status.
9009: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9010:
1.374 raeburn 9011: Returns section hash (keys are section IDs, values are
9012: number of users in each section), subject to the
1.419 raeburn 9013: optional roles filter, optional status filter
1.233 raeburn 9014:
9015: =cut
9016:
9017: ###############################################
9018: sub get_sections {
1.419 raeburn 9019: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9020: if (!defined($cdom) || !defined($cnum)) {
9021: my $cid = $env{'request.course.id'};
9022:
9023: return if (!defined($cid));
9024:
9025: $cdom = $env{'course.'.$cid.'.domain'};
9026: $cnum = $env{'course.'.$cid.'.num'};
9027: }
9028:
9029: my %sectioncount;
1.419 raeburn 9030: my $now = time;
1.240 albertel 9031:
1.1075.2.33 raeburn 9032: my $check_students = 1;
9033: my $only_students = 0;
9034: if (ref($possible_roles) eq 'ARRAY') {
9035: if (grep(/^st$/,@{$possible_roles})) {
9036: if (@{$possible_roles} == 1) {
9037: $only_students = 1;
9038: }
9039: } else {
9040: $check_students = 0;
9041: }
9042: }
9043:
9044: if ($check_students) {
1.276 albertel 9045: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9046: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9047: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9048: my $start_index = &Apache::loncoursedata::CL_START();
9049: my $end_index = &Apache::loncoursedata::CL_END();
9050: my $status;
1.366 albertel 9051: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9052: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9053: $data->[$status_index],
9054: $data->[$start_index],
9055: $data->[$end_index]);
9056: if ($stu_status eq 'Active') {
9057: $status = 'active';
9058: } elsif ($end < $now) {
9059: $status = 'previous';
9060: } elsif ($start > $now) {
9061: $status = 'future';
9062: }
9063: if ($section ne '-1' && $section !~ /^\s*$/) {
9064: if ((!defined($possible_status)) || (($status ne '') &&
9065: (grep/^\Q$status\E$/,@{$possible_status}))) {
9066: $sectioncount{$section}++;
9067: }
1.240 albertel 9068: }
9069: }
9070: }
1.1075.2.33 raeburn 9071: if ($only_students) {
9072: return %sectioncount;
9073: }
1.240 albertel 9074: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9075: foreach my $user (sort(keys(%courseroles))) {
9076: if ($user !~ /^(\w{2})/) { next; }
9077: my ($role) = ($user =~ /^(\w{2})/);
9078: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9079: my ($section,$status);
1.240 albertel 9080: if ($role eq 'cr' &&
9081: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9082: $section=$1;
9083: }
9084: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9085: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9086: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9087: if ($end == -1 && $start == -1) {
9088: next; #deleted role
9089: }
9090: if (!defined($possible_status)) {
9091: $sectioncount{$section}++;
9092: } else {
9093: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9094: $status = 'active';
9095: } elsif ($end < $now) {
9096: $status = 'future';
9097: } elsif ($start > $now) {
9098: $status = 'previous';
9099: }
9100: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9101: $sectioncount{$section}++;
9102: }
9103: }
1.233 raeburn 9104: }
1.366 albertel 9105: return %sectioncount;
1.233 raeburn 9106: }
9107:
1.274 raeburn 9108: ###############################################
1.294 raeburn 9109:
9110: =pod
1.405 albertel 9111:
9112: =item * &get_course_users()
9113:
1.275 raeburn 9114: Retrieves usernames:domains for users in the specified course
9115: with specific role(s), and access status.
9116:
9117: Incoming parameters:
1.277 albertel 9118: 1. course domain
9119: 2. course number
9120: 3. access status: users must have - either active,
1.275 raeburn 9121: previous, future, or all.
1.277 albertel 9122: 4. reference to array of permissible roles
1.288 raeburn 9123: 5. reference to array of section restrictions (optional)
9124: 6. reference to results object (hash of hashes).
9125: 7. reference to optional userdata hash
1.609 raeburn 9126: 8. reference to optional statushash
1.630 raeburn 9127: 9. flag if privileged users (except those set to unhide in
9128: course settings) should be excluded
1.609 raeburn 9129: Keys of top level results hash are roles.
1.275 raeburn 9130: Keys of inner hashes are username:domain, with
9131: values set to access type.
1.288 raeburn 9132: Optional userdata hash returns an array with arguments in the
9133: same order as loncoursedata::get_classlist() for student data.
9134:
1.609 raeburn 9135: Optional statushash returns
9136:
1.288 raeburn 9137: Entries for end, start, section and status are blank because
9138: of the possibility of multiple values for non-student roles.
9139:
1.275 raeburn 9140: =cut
1.405 albertel 9141:
1.275 raeburn 9142: ###############################################
1.405 albertel 9143:
1.275 raeburn 9144: sub get_course_users {
1.630 raeburn 9145: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9146: my %idx = ();
1.419 raeburn 9147: my %seclists;
1.288 raeburn 9148:
9149: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9150: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9151: $idx{end} = &Apache::loncoursedata::CL_END();
9152: $idx{start} = &Apache::loncoursedata::CL_START();
9153: $idx{id} = &Apache::loncoursedata::CL_ID();
9154: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9155: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9156: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9157:
1.290 albertel 9158: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9159: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9160: my $now = time;
1.277 albertel 9161: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9162: my $match = 0;
1.412 raeburn 9163: my $secmatch = 0;
1.419 raeburn 9164: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9165: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9166: if ($section eq '') {
9167: $section = 'none';
9168: }
1.291 albertel 9169: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9170: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9171: $secmatch = 1;
9172: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9173: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9174: $secmatch = 1;
9175: }
9176: } else {
1.419 raeburn 9177: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9178: $secmatch = 1;
9179: }
1.290 albertel 9180: }
1.412 raeburn 9181: if (!$secmatch) {
9182: next;
9183: }
1.419 raeburn 9184: }
1.275 raeburn 9185: if (defined($$types{'active'})) {
1.288 raeburn 9186: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9187: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9188: $match = 1;
1.275 raeburn 9189: }
9190: }
9191: if (defined($$types{'previous'})) {
1.609 raeburn 9192: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9193: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9194: $match = 1;
1.275 raeburn 9195: }
9196: }
9197: if (defined($$types{'future'})) {
1.609 raeburn 9198: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9199: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9200: $match = 1;
1.275 raeburn 9201: }
9202: }
1.609 raeburn 9203: if ($match) {
9204: push(@{$seclists{$student}},$section);
9205: if (ref($userdata) eq 'HASH') {
9206: $$userdata{$student} = $$classlist{$student};
9207: }
9208: if (ref($statushash) eq 'HASH') {
9209: $statushash->{$student}{'st'}{$section} = $status;
9210: }
1.288 raeburn 9211: }
1.275 raeburn 9212: }
9213: }
1.412 raeburn 9214: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9215: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9216: my $now = time;
1.609 raeburn 9217: my %displaystatus = ( previous => 'Expired',
9218: active => 'Active',
9219: future => 'Future',
9220: );
1.1075.2.36 raeburn 9221: my (%nothide,@possdoms);
1.630 raeburn 9222: if ($hidepriv) {
9223: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9224: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9225: if ($user !~ /:/) {
9226: $nothide{join(':',split(/[\@]/,$user))}=1;
9227: } else {
9228: $nothide{$user} = 1;
9229: }
9230: }
1.1075.2.36 raeburn 9231: my @possdoms = ($cdom);
9232: if ($coursehash{'checkforpriv'}) {
9233: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9234: }
1.630 raeburn 9235: }
1.439 raeburn 9236: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9237: my $match = 0;
1.412 raeburn 9238: my $secmatch = 0;
1.439 raeburn 9239: my $status;
1.412 raeburn 9240: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9241: $user =~ s/:$//;
1.439 raeburn 9242: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9243: if ($end == -1 || $start == -1) {
9244: next;
9245: }
9246: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9247: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9248: my ($uname,$udom) = split(/:/,$user);
9249: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9250: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9251: $secmatch = 1;
9252: } elsif ($usec eq '') {
1.420 albertel 9253: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9254: $secmatch = 1;
9255: }
9256: } else {
9257: if (grep(/^\Q$usec\E$/,@{$sections})) {
9258: $secmatch = 1;
9259: }
9260: }
9261: if (!$secmatch) {
9262: next;
9263: }
1.288 raeburn 9264: }
1.419 raeburn 9265: if ($usec eq '') {
9266: $usec = 'none';
9267: }
1.275 raeburn 9268: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9269: if ($hidepriv) {
1.1075.2.36 raeburn 9270: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9271: (!$nothide{$uname.':'.$udom})) {
9272: next;
9273: }
9274: }
1.503 raeburn 9275: if ($end > 0 && $end < $now) {
1.439 raeburn 9276: $status = 'previous';
9277: } elsif ($start > $now) {
9278: $status = 'future';
9279: } else {
9280: $status = 'active';
9281: }
1.277 albertel 9282: foreach my $type (keys(%{$types})) {
1.275 raeburn 9283: if ($status eq $type) {
1.420 albertel 9284: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9285: push(@{$$users{$role}{$user}},$type);
9286: }
1.288 raeburn 9287: $match = 1;
9288: }
9289: }
1.419 raeburn 9290: if (($match) && (ref($userdata) eq 'HASH')) {
9291: if (!exists($$userdata{$uname.':'.$udom})) {
9292: &get_user_info($udom,$uname,\%idx,$userdata);
9293: }
1.420 albertel 9294: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9295: push(@{$seclists{$uname.':'.$udom}},$usec);
9296: }
1.609 raeburn 9297: if (ref($statushash) eq 'HASH') {
9298: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9299: }
1.275 raeburn 9300: }
9301: }
9302: }
9303: }
1.290 albertel 9304: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9305: if ((defined($cdom)) && (defined($cnum))) {
9306: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9307: if ( defined($csettings{'internal.courseowner'}) ) {
9308: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9309: next if ($owner eq '');
9310: my ($ownername,$ownerdom);
9311: if ($owner =~ /^([^:]+):([^:]+)$/) {
9312: $ownername = $1;
9313: $ownerdom = $2;
9314: } else {
9315: $ownername = $owner;
9316: $ownerdom = $cdom;
9317: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9318: }
9319: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9320: if (defined($userdata) &&
1.609 raeburn 9321: !exists($$userdata{$owner})) {
9322: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9323: if (!grep(/^none$/,@{$seclists{$owner}})) {
9324: push(@{$seclists{$owner}},'none');
9325: }
9326: if (ref($statushash) eq 'HASH') {
9327: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9328: }
1.290 albertel 9329: }
1.279 raeburn 9330: }
9331: }
9332: }
1.419 raeburn 9333: foreach my $user (keys(%seclists)) {
9334: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9335: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9336: }
1.275 raeburn 9337: }
9338: return;
9339: }
9340:
1.288 raeburn 9341: sub get_user_info {
9342: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9343: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9344: &plainname($uname,$udom,'lastname');
1.291 albertel 9345: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9346: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9347: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9348: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9349: return;
9350: }
1.275 raeburn 9351:
1.472 raeburn 9352: ###############################################
9353:
9354: =pod
9355:
9356: =item * &get_user_quota()
9357:
1.1075.2.41 raeburn 9358: Retrieves quota assigned for storage of user files.
9359: Default is to report quota for portfolio files.
1.472 raeburn 9360:
9361: Incoming parameters:
9362: 1. user's username
9363: 2. user's domain
1.1075.2.41 raeburn 9364: 3. quota name - portfolio, author, or course
9365: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9366: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9367: course
1.472 raeburn 9368:
9369: Returns:
1.1075.2.58 raeburn 9370: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9371: 2. (Optional) Type of setting: custom or default
9372: (individually assigned or default for user's
9373: institutional status).
9374: 3. (Optional) - User's institutional status (e.g., faculty, staff
9375: or student - types as defined in localenroll::inst_usertypes
9376: for user's domain, which determines default quota for user.
9377: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9378:
9379: If a value has been stored in the user's environment,
1.536 raeburn 9380: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9381: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9382:
9383: =cut
9384:
9385: ###############################################
9386:
9387:
9388: sub get_user_quota {
1.1075.2.42 raeburn 9389: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9390: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9391: if (!defined($udom)) {
9392: $udom = $env{'user.domain'};
9393: }
9394: if (!defined($uname)) {
9395: $uname = $env{'user.name'};
9396: }
9397: if (($udom eq '' || $uname eq '') ||
9398: ($udom eq 'public') && ($uname eq 'public')) {
9399: $quota = 0;
1.536 raeburn 9400: $quotatype = 'default';
9401: $defquota = 0;
1.472 raeburn 9402: } else {
1.536 raeburn 9403: my $inststatus;
1.1075.2.41 raeburn 9404: if ($quotaname eq 'course') {
9405: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9406: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9407: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9408: } else {
9409: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9410: $quota = $cenv{'internal.uploadquota'};
9411: }
1.536 raeburn 9412: } else {
1.1075.2.41 raeburn 9413: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9414: if ($quotaname eq 'author') {
9415: $quota = $env{'environment.authorquota'};
9416: } else {
9417: $quota = $env{'environment.portfolioquota'};
9418: }
9419: $inststatus = $env{'environment.inststatus'};
9420: } else {
9421: my %userenv =
9422: &Apache::lonnet::get('environment',['portfolioquota',
9423: 'authorquota','inststatus'],$udom,$uname);
9424: my ($tmp) = keys(%userenv);
9425: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9426: if ($quotaname eq 'author') {
9427: $quota = $userenv{'authorquota'};
9428: } else {
9429: $quota = $userenv{'portfolioquota'};
9430: }
9431: $inststatus = $userenv{'inststatus'};
9432: } else {
9433: undef(%userenv);
9434: }
9435: }
9436: }
9437: if ($quota eq '' || wantarray) {
9438: if ($quotaname eq 'course') {
9439: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9440: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9441: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9442: $defquota = $domdefs{$crstype.'quota'};
9443: }
9444: if ($defquota eq '') {
9445: $defquota = 500;
9446: }
1.1075.2.41 raeburn 9447: } else {
9448: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9449: }
9450: if ($quota eq '') {
9451: $quota = $defquota;
9452: $quotatype = 'default';
9453: } else {
9454: $quotatype = 'custom';
9455: }
1.472 raeburn 9456: }
9457: }
1.536 raeburn 9458: if (wantarray) {
9459: return ($quota,$quotatype,$settingstatus,$defquota);
9460: } else {
9461: return $quota;
9462: }
1.472 raeburn 9463: }
9464:
9465: ###############################################
9466:
9467: =pod
9468:
9469: =item * &default_quota()
9470:
1.536 raeburn 9471: Retrieves default quota assigned for storage of user portfolio files,
9472: given an (optional) user's institutional status.
1.472 raeburn 9473:
9474: Incoming parameters:
1.1075.2.42 raeburn 9475:
1.472 raeburn 9476: 1. domain
1.536 raeburn 9477: 2. (Optional) institutional status(es). This is a : separated list of
9478: status types (e.g., faculty, staff, student etc.)
9479: which apply to the user for whom the default is being retrieved.
9480: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9481: default quota will be returned.
9482: 3. quota name - portfolio, author, or course
9483: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9484:
9485: Returns:
1.1075.2.42 raeburn 9486:
1.1075.2.58 raeburn 9487: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9488: 2. (Optional) institutional type which determined the value of the
9489: default quota.
1.472 raeburn 9490:
9491: If a value has been stored in the domain's configuration db,
9492: it will return that, otherwise it returns 20 (for backwards
9493: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9494: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9495:
1.536 raeburn 9496: If the user's status includes multiple types (e.g., staff and student),
9497: the largest default quota which applies to the user determines the
9498: default quota returned.
9499:
1.472 raeburn 9500: =cut
9501:
9502: ###############################################
9503:
9504:
9505: sub default_quota {
1.1075.2.41 raeburn 9506: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9507: my ($defquota,$settingstatus);
9508: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9509: ['quotas'],$udom);
1.1075.2.41 raeburn 9510: my $key = 'defaultquota';
9511: if ($quotaname eq 'author') {
9512: $key = 'authorquota';
9513: }
1.622 raeburn 9514: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9515: if ($inststatus ne '') {
1.765 raeburn 9516: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9517: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9518: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9519: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9520: if ($defquota eq '') {
1.1075.2.41 raeburn 9521: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9522: $settingstatus = $item;
1.1075.2.41 raeburn 9523: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9524: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9525: $settingstatus = $item;
9526: }
9527: }
1.1075.2.41 raeburn 9528: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9529: if ($quotahash{'quotas'}{$item} ne '') {
9530: if ($defquota eq '') {
9531: $defquota = $quotahash{'quotas'}{$item};
9532: $settingstatus = $item;
9533: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9534: $defquota = $quotahash{'quotas'}{$item};
9535: $settingstatus = $item;
9536: }
1.536 raeburn 9537: }
9538: }
9539: }
9540: }
9541: if ($defquota eq '') {
1.1075.2.41 raeburn 9542: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9543: $defquota = $quotahash{'quotas'}{$key}{'default'};
9544: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9545: $defquota = $quotahash{'quotas'}{'default'};
9546: }
1.536 raeburn 9547: $settingstatus = 'default';
1.1075.2.42 raeburn 9548: if ($defquota eq '') {
9549: if ($quotaname eq 'author') {
9550: $defquota = 500;
9551: }
9552: }
1.536 raeburn 9553: }
9554: } else {
9555: $settingstatus = 'default';
1.1075.2.41 raeburn 9556: if ($quotaname eq 'author') {
9557: $defquota = 500;
9558: } else {
9559: $defquota = 20;
9560: }
1.536 raeburn 9561: }
9562: if (wantarray) {
9563: return ($defquota,$settingstatus);
1.472 raeburn 9564: } else {
1.536 raeburn 9565: return $defquota;
1.472 raeburn 9566: }
9567: }
9568:
1.1075.2.41 raeburn 9569: ###############################################
9570:
9571: =pod
9572:
1.1075.2.42 raeburn 9573: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9574:
9575: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9576: of existing file within authoring space will cause quota for the authoring
9577: space to be exceeded.
9578:
9579: Same, if upload of a file directly to a course/community via Course Editor
9580: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9581:
1.1075.2.61 raeburn 9582: Inputs: 7
1.1075.2.42 raeburn 9583: 1. username or coursenum
1.1075.2.41 raeburn 9584: 2. domain
1.1075.2.42 raeburn 9585: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9586: 4. filename of file for which action is being requested
9587: 5. filesize (kB) of file
9588: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9589: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9590:
9591: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9592: otherwise return null.
9593:
1.1075.2.42 raeburn 9594: =back
9595:
1.1075.2.41 raeburn 9596: =cut
9597:
1.1075.2.42 raeburn 9598: sub excess_filesize_warning {
1.1075.2.59 raeburn 9599: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9600: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9601: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9602: if ($context eq 'author') {
9603: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9604: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9605: } else {
9606: foreach my $subdir ('docs','supplemental') {
9607: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9608: }
9609: }
1.1075.2.41 raeburn 9610: $disk_quota = int($disk_quota * 1000);
9611: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9612: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9613: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9614: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9615: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9616: $disk_quota,$current_disk_usage).
9617: '</p>';
9618: }
9619: return;
9620: }
9621:
9622: ###############################################
9623:
9624:
1.384 raeburn 9625: sub get_secgrprole_info {
9626: my ($cdom,$cnum,$needroles,$type) = @_;
9627: my %sections_count = &get_sections($cdom,$cnum);
9628: my @sections = (sort {$a <=> $b} keys(%sections_count));
9629: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9630: my @groups = sort(keys(%curr_groups));
9631: my $allroles = [];
9632: my $rolehash;
9633: my $accesshash = {
9634: active => 'Currently has access',
9635: future => 'Will have future access',
9636: previous => 'Previously had access',
9637: };
9638: if ($needroles) {
9639: $rolehash = {'all' => 'all'};
1.385 albertel 9640: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9641: if (&Apache::lonnet::error(%user_roles)) {
9642: undef(%user_roles);
9643: }
9644: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9645: my ($role)=split(/\:/,$item,2);
9646: if ($role eq 'cr') { next; }
9647: if ($role =~ /^cr/) {
9648: $$rolehash{$role} = (split('/',$role))[3];
9649: } else {
9650: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9651: }
9652: }
9653: foreach my $key (sort(keys(%{$rolehash}))) {
9654: push(@{$allroles},$key);
9655: }
9656: push (@{$allroles},'st');
9657: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9658: }
9659: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9660: }
9661:
1.555 raeburn 9662: sub user_picker {
1.1075.2.127 raeburn 9663: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9664: my $currdom = $dom;
1.1075.2.114 raeburn 9665: my @alldoms = &Apache::lonnet::all_domains();
9666: if (@alldoms == 1) {
9667: my %domsrch = &Apache::lonnet::get_dom('configuration',
9668: ['directorysrch'],$alldoms[0]);
9669: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9670: my $showdom = $domdesc;
9671: if ($showdom eq '') {
9672: $showdom = $dom;
9673: }
9674: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9675: if ((!$domsrch{'directorysrch'}{'available'}) &&
9676: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9677: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9678: }
9679: }
9680: }
1.555 raeburn 9681: my %curr_selected = (
9682: srchin => 'dom',
1.580 raeburn 9683: srchby => 'lastname',
1.555 raeburn 9684: );
9685: my $srchterm;
1.625 raeburn 9686: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9687: if ($srch->{'srchby'} ne '') {
9688: $curr_selected{'srchby'} = $srch->{'srchby'};
9689: }
9690: if ($srch->{'srchin'} ne '') {
9691: $curr_selected{'srchin'} = $srch->{'srchin'};
9692: }
9693: if ($srch->{'srchtype'} ne '') {
9694: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9695: }
9696: if ($srch->{'srchdomain'} ne '') {
9697: $currdom = $srch->{'srchdomain'};
9698: }
9699: $srchterm = $srch->{'srchterm'};
9700: }
1.1075.2.98 raeburn 9701: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9702: 'usr' => 'Search criteria',
1.563 raeburn 9703: 'doma' => 'Domain/institution to search',
1.558 albertel 9704: 'uname' => 'username',
9705: 'lastname' => 'last name',
1.555 raeburn 9706: 'lastfirst' => 'last name, first name',
1.558 albertel 9707: 'crs' => 'in this course',
1.576 raeburn 9708: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9709: 'alc' => 'all LON-CAPA',
1.573 raeburn 9710: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9711: 'exact' => 'is',
9712: 'contains' => 'contains',
1.569 raeburn 9713: 'begins' => 'begins with',
1.1075.2.98 raeburn 9714: );
9715: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9716: 'youm' => "You must include some text to search for.",
9717: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9718: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9719: 'yomc' => "You must choose a domain when using an institutional directory search.",
9720: 'ymcd' => "You must choose a domain when using a domain search.",
9721: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9722: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9723: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9724: );
1.1075.2.98 raeburn 9725: &html_escape(\%html_lt);
9726: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9727: my $domform;
1.1075.2.126 raeburn 9728: my $allow_blank = 1;
1.1075.2.115 raeburn 9729: if ($fixeddom) {
1.1075.2.126 raeburn 9730: $allow_blank = 0;
9731: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9732: } else {
1.1075.2.126 raeburn 9733: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9734: }
1.563 raeburn 9735: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9736:
9737: my @srchins = ('crs','dom','alc','instd');
9738:
9739: foreach my $option (@srchins) {
9740: # FIXME 'alc' option unavailable until
9741: # loncreateuser::print_user_query_page()
9742: # has been completed.
9743: next if ($option eq 'alc');
1.880 raeburn 9744: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9745: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9746: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9747: if ($curr_selected{'srchin'} eq $option) {
9748: $srchinsel .= '
1.1075.2.98 raeburn 9749: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9750: } else {
9751: $srchinsel .= '
1.1075.2.98 raeburn 9752: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9753: }
1.555 raeburn 9754: }
1.563 raeburn 9755: $srchinsel .= "\n </select>\n";
1.555 raeburn 9756:
9757: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9758: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9759: if ($curr_selected{'srchby'} eq $option) {
9760: $srchbysel .= '
1.1075.2.98 raeburn 9761: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9762: } else {
9763: $srchbysel .= '
1.1075.2.98 raeburn 9764: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9765: }
9766: }
9767: $srchbysel .= "\n </select>\n";
9768:
9769: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9770: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9771: if ($curr_selected{'srchtype'} eq $option) {
9772: $srchtypesel .= '
1.1075.2.98 raeburn 9773: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9774: } else {
9775: $srchtypesel .= '
1.1075.2.98 raeburn 9776: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9777: }
9778: }
9779: $srchtypesel .= "\n </select>\n";
9780:
1.558 albertel 9781: my ($newuserscript,$new_user_create);
1.994 raeburn 9782: my $context_dom = $env{'request.role.domain'};
9783: if ($context eq 'requestcrs') {
9784: if ($env{'form.coursedom'} ne '') {
9785: $context_dom = $env{'form.coursedom'};
9786: }
9787: }
1.556 raeburn 9788: if ($forcenewuser) {
1.576 raeburn 9789: if (ref($srch) eq 'HASH') {
1.994 raeburn 9790: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9791: if ($cancreate) {
9792: $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>';
9793: } else {
1.799 bisitz 9794: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9795: my %usertypetext = (
9796: official => 'institutional',
9797: unofficial => 'non-institutional',
9798: );
1.799 bisitz 9799: $new_user_create = '<p class="LC_warning">'
9800: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9801: .' '
9802: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9803: ,'<a href="'.$helplink.'">','</a>')
9804: .'</p><br />';
1.627 raeburn 9805: }
1.576 raeburn 9806: }
9807: }
9808:
1.556 raeburn 9809: $newuserscript = <<"ENDSCRIPT";
9810:
1.570 raeburn 9811: function setSearch(createnew,callingForm) {
1.556 raeburn 9812: if (createnew == 1) {
1.570 raeburn 9813: for (var i=0; i<callingForm.srchby.length; i++) {
9814: if (callingForm.srchby.options[i].value == 'uname') {
9815: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9816: }
9817: }
1.570 raeburn 9818: for (var i=0; i<callingForm.srchin.length; i++) {
9819: if ( callingForm.srchin.options[i].value == 'dom') {
9820: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9821: }
9822: }
1.570 raeburn 9823: for (var i=0; i<callingForm.srchtype.length; i++) {
9824: if (callingForm.srchtype.options[i].value == 'exact') {
9825: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9826: }
9827: }
1.570 raeburn 9828: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9829: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9830: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9831: }
9832: }
9833: }
9834: }
9835: ENDSCRIPT
1.558 albertel 9836:
1.556 raeburn 9837: }
9838:
1.555 raeburn 9839: my $output = <<"END_BLOCK";
1.556 raeburn 9840: <script type="text/javascript">
1.824 bisitz 9841: // <![CDATA[
1.570 raeburn 9842: function validateEntry(callingForm) {
1.558 albertel 9843:
1.556 raeburn 9844: var checkok = 1;
1.558 albertel 9845: var srchin;
1.570 raeburn 9846: for (var i=0; i<callingForm.srchin.length; i++) {
9847: if ( callingForm.srchin[i].checked ) {
9848: srchin = callingForm.srchin[i].value;
1.558 albertel 9849: }
9850: }
9851:
1.570 raeburn 9852: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9853: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9854: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9855: var srchterm = callingForm.srchterm.value;
9856: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9857: var msg = "";
9858:
9859: if (srchterm == "") {
9860: checkok = 0;
1.1075.2.98 raeburn 9861: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9862: }
9863:
1.569 raeburn 9864: if (srchtype== 'begins') {
9865: if (srchterm.length < 2) {
9866: checkok = 0;
1.1075.2.98 raeburn 9867: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9868: }
9869: }
9870:
1.556 raeburn 9871: if (srchtype== 'contains') {
9872: if (srchterm.length < 3) {
9873: checkok = 0;
1.1075.2.98 raeburn 9874: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9875: }
9876: }
9877: if (srchin == 'instd') {
9878: if (srchdomain == '') {
9879: checkok = 0;
1.1075.2.98 raeburn 9880: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9881: }
9882: }
9883: if (srchin == 'dom') {
9884: if (srchdomain == '') {
9885: checkok = 0;
1.1075.2.98 raeburn 9886: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9887: }
9888: }
9889: if (srchby == 'lastfirst') {
9890: if (srchterm.indexOf(",") == -1) {
9891: checkok = 0;
1.1075.2.98 raeburn 9892: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9893: }
9894: if (srchterm.indexOf(",") == srchterm.length -1) {
9895: checkok = 0;
1.1075.2.98 raeburn 9896: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9897: }
9898: }
9899: if (checkok == 0) {
1.1075.2.98 raeburn 9900: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9901: return;
9902: }
9903: if (checkok == 1) {
1.570 raeburn 9904: callingForm.submit();
1.556 raeburn 9905: }
9906: }
9907:
9908: $newuserscript
9909:
1.824 bisitz 9910: // ]]>
1.556 raeburn 9911: </script>
1.558 albertel 9912:
9913: $new_user_create
9914:
1.555 raeburn 9915: END_BLOCK
1.558 albertel 9916:
1.876 raeburn 9917: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9918: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9919: $domform.
9920: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9921: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9922: $srchbysel.
9923: $srchtypesel.
9924: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9925: $srchinsel.
9926: &Apache::lonhtmlcommon::row_closure(1).
9927: &Apache::lonhtmlcommon::end_pick_box().
9928: '<br />';
1.1075.2.114 raeburn 9929: return ($output,1);
1.555 raeburn 9930: }
9931:
1.612 raeburn 9932: sub user_rule_check {
1.615 raeburn 9933: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9934: my ($response,%inst_response);
1.612 raeburn 9935: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9936: if (keys(%{$usershash}) > 1) {
9937: my (%by_username,%by_id,%userdoms);
9938: my $checkid;
1.612 raeburn 9939: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9940: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9941: $checkid = 1;
9942: }
9943: }
9944: foreach my $user (keys(%{$usershash})) {
9945: my ($uname,$udom) = split(/:/,$user);
9946: if ($checkid) {
9947: if (ref($usershash->{$user}) eq 'HASH') {
9948: if ($usershash->{$user}->{'id'} ne '') {
9949: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9950: $userdoms{$udom} = 1;
9951: if (ref($inst_results) eq 'HASH') {
9952: $inst_results->{$uname.':'.$udom} = {};
9953: }
9954: }
9955: }
9956: } else {
9957: $by_username{$udom}{$uname} = 1;
9958: $userdoms{$udom} = 1;
9959: if (ref($inst_results) eq 'HASH') {
9960: $inst_results->{$uname.':'.$udom} = {};
9961: }
9962: }
9963: }
9964: foreach my $udom (keys(%userdoms)) {
9965: if (!$got_rules->{$udom}) {
9966: my %domconfig = &Apache::lonnet::get_dom('configuration',
9967: ['usercreation'],$udom);
9968: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9969: foreach my $item ('username','id') {
9970: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9971: $$curr_rules{$udom}{$item} =
9972: $domconfig{'usercreation'}{$item.'_rule'};
9973: }
9974: }
9975: }
9976: $got_rules->{$udom} = 1;
9977: }
9978: }
9979: if ($checkid) {
9980: foreach my $udom (keys(%by_id)) {
9981: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9982: if ($outcome eq 'ok') {
9983: foreach my $id (keys(%{$by_id{$udom}})) {
9984: my $uname = $by_id{$udom}{$id};
9985: $inst_response{$uname.':'.$udom} = $outcome;
9986: }
9987: if (ref($results) eq 'HASH') {
9988: foreach my $uname (keys(%{$results})) {
9989: if (exists($inst_response{$uname.':'.$udom})) {
9990: $inst_response{$uname.':'.$udom} = $outcome;
9991: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9992: }
9993: }
9994: }
9995: }
1.612 raeburn 9996: }
1.615 raeburn 9997: } else {
1.1075.2.99 raeburn 9998: foreach my $udom (keys(%by_username)) {
9999: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10000: if ($outcome eq 'ok') {
10001: foreach my $uname (keys(%{$by_username{$udom}})) {
10002: $inst_response{$uname.':'.$udom} = $outcome;
10003: }
10004: if (ref($results) eq 'HASH') {
10005: foreach my $uname (keys(%{$results})) {
10006: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10007: }
10008: }
10009: }
10010: }
1.612 raeburn 10011: }
1.1075.2.99 raeburn 10012: } elsif (keys(%{$usershash}) == 1) {
10013: my $user = (keys(%{$usershash}))[0];
10014: my ($uname,$udom) = split(/:/,$user);
10015: if (($udom ne '') && ($uname ne '')) {
10016: if (ref($usershash->{$user}) eq 'HASH') {
10017: if (ref($checks) eq 'HASH') {
10018: if (defined($checks->{'username'})) {
10019: ($inst_response{$user},%{$inst_results->{$user}}) =
10020: &Apache::lonnet::get_instuser($udom,$uname);
10021: } elsif (defined($checks->{'id'})) {
10022: if ($usershash->{$user}->{'id'} ne '') {
10023: ($inst_response{$user},%{$inst_results->{$user}}) =
10024: &Apache::lonnet::get_instuser($udom,undef,
10025: $usershash->{$user}->{'id'});
10026: } else {
10027: ($inst_response{$user},%{$inst_results->{$user}}) =
10028: &Apache::lonnet::get_instuser($udom,$uname);
10029: }
10030: }
10031: } else {
10032: ($inst_response{$user},%{$inst_results->{$user}}) =
10033: &Apache::lonnet::get_instuser($udom,$uname);
10034: return;
10035: }
10036: if (!$got_rules->{$udom}) {
10037: my %domconfig = &Apache::lonnet::get_dom('configuration',
10038: ['usercreation'],$udom);
10039: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10040: foreach my $item ('username','id') {
10041: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10042: $$curr_rules{$udom}{$item} =
10043: $domconfig{'usercreation'}{$item.'_rule'};
10044: }
10045: }
1.585 raeburn 10046: }
1.1075.2.99 raeburn 10047: $got_rules->{$udom} = 1;
1.585 raeburn 10048: }
10049: }
1.1075.2.99 raeburn 10050: } else {
10051: return;
10052: }
10053: } else {
10054: return;
10055: }
10056: foreach my $user (keys(%{$usershash})) {
10057: my ($uname,$udom) = split(/:/,$user);
10058: next if (($udom eq '') || ($uname eq ''));
10059: my $id;
10060: if (ref($inst_results) eq 'HASH') {
10061: if (ref($inst_results->{$user}) eq 'HASH') {
10062: $id = $inst_results->{$user}->{'id'};
10063: }
10064: }
10065: if ($id eq '') {
10066: if (ref($usershash->{$user})) {
10067: $id = $usershash->{$user}->{'id'};
10068: }
1.585 raeburn 10069: }
1.612 raeburn 10070: foreach my $item (keys(%{$checks})) {
10071: if (ref($$curr_rules{$udom}) eq 'HASH') {
10072: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10073: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10074: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10075: $$curr_rules{$udom}{$item});
1.612 raeburn 10076: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10077: if ($rule_check{$rule}) {
10078: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10079: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10080: if (ref($inst_results) eq 'HASH') {
10081: if (ref($inst_results->{$user}) eq 'HASH') {
10082: if (keys(%{$inst_results->{$user}}) == 0) {
10083: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10084: } elsif ($item eq 'id') {
10085: if ($inst_results->{$user}->{'id'} eq '') {
10086: $$alerts{$item}{$udom}{$uname} = 1;
10087: }
1.615 raeburn 10088: }
1.612 raeburn 10089: }
10090: }
1.615 raeburn 10091: }
10092: last;
1.585 raeburn 10093: }
10094: }
10095: }
10096: }
10097: }
10098: }
10099: }
10100: }
1.612 raeburn 10101: return;
10102: }
10103:
10104: sub user_rule_formats {
10105: my ($domain,$domdesc,$curr_rules,$check) = @_;
10106: my %text = (
10107: 'username' => 'Usernames',
10108: 'id' => 'IDs',
10109: );
10110: my $output;
10111: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10112: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10113: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10114: $output = '<br />'.
10115: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10116: '<span class="LC_cusr_emph">','</span>',$domdesc).
10117: ' <ul>';
1.612 raeburn 10118: foreach my $rule (@{$ruleorder}) {
10119: if (ref($curr_rules) eq 'ARRAY') {
10120: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10121: if (ref($rules->{$rule}) eq 'HASH') {
10122: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10123: $rules->{$rule}{'desc'}.'</li>';
10124: }
10125: }
10126: }
10127: }
10128: $output .= '</ul>';
10129: }
10130: }
10131: return $output;
10132: }
10133:
10134: sub instrule_disallow_msg {
1.615 raeburn 10135: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10136: my $response;
10137: my %text = (
10138: item => 'username',
10139: items => 'usernames',
10140: match => 'matches',
10141: do => 'does',
10142: action => 'a username',
10143: one => 'one',
10144: );
10145: if ($count > 1) {
10146: $text{'item'} = 'usernames';
10147: $text{'match'} ='match';
10148: $text{'do'} = 'do';
10149: $text{'action'} = 'usernames',
10150: $text{'one'} = 'ones';
10151: }
10152: if ($checkitem eq 'id') {
10153: $text{'items'} = 'IDs';
10154: $text{'item'} = 'ID';
10155: $text{'action'} = 'an ID';
1.615 raeburn 10156: if ($count > 1) {
10157: $text{'item'} = 'IDs';
10158: $text{'action'} = 'IDs';
10159: }
1.612 raeburn 10160: }
1.674 bisitz 10161: $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 10162: if ($mode eq 'upload') {
10163: if ($checkitem eq 'username') {
10164: $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'}.");
10165: } elsif ($checkitem eq 'id') {
1.674 bisitz 10166: $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 10167: }
1.669 raeburn 10168: } elsif ($mode eq 'selfcreate') {
10169: if ($checkitem eq 'id') {
10170: $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.");
10171: }
1.615 raeburn 10172: } else {
10173: if ($checkitem eq 'username') {
10174: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10175: } elsif ($checkitem eq 'id') {
10176: $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.");
10177: }
1.612 raeburn 10178: }
10179: return $response;
1.585 raeburn 10180: }
10181:
1.624 raeburn 10182: sub personal_data_fieldtitles {
10183: my %fieldtitles = &Apache::lonlocal::texthash (
10184: id => 'Student/Employee ID',
10185: permanentemail => 'E-mail address',
10186: lastname => 'Last Name',
10187: firstname => 'First Name',
10188: middlename => 'Middle Name',
10189: generation => 'Generation',
10190: gen => 'Generation',
1.765 raeburn 10191: inststatus => 'Affiliation',
1.624 raeburn 10192: );
10193: return %fieldtitles;
10194: }
10195:
1.642 raeburn 10196: sub sorted_inst_types {
10197: my ($dom) = @_;
1.1075.2.70 raeburn 10198: my ($usertypes,$order);
10199: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10200: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10201: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10202: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10203: } else {
10204: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10205: }
1.642 raeburn 10206: my $othertitle = &mt('All users');
10207: if ($env{'request.course.id'}) {
1.668 raeburn 10208: $othertitle = &mt('Any users');
1.642 raeburn 10209: }
10210: my @types;
10211: if (ref($order) eq 'ARRAY') {
10212: @types = @{$order};
10213: }
10214: if (@types == 0) {
10215: if (ref($usertypes) eq 'HASH') {
10216: @types = sort(keys(%{$usertypes}));
10217: }
10218: }
10219: if (keys(%{$usertypes}) > 0) {
10220: $othertitle = &mt('Other users');
10221: }
10222: return ($othertitle,$usertypes,\@types);
10223: }
10224:
1.645 raeburn 10225: sub get_institutional_codes {
10226: my ($settings,$allcourses,$LC_code) = @_;
10227: # Get complete list of course sections to update
10228: my @currsections = ();
10229: my @currxlists = ();
10230: my $coursecode = $$settings{'internal.coursecode'};
10231:
10232: if ($$settings{'internal.sectionnums'} ne '') {
10233: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10234: }
10235:
10236: if ($$settings{'internal.crosslistings'} ne '') {
10237: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10238: }
10239:
10240: if (@currxlists > 0) {
10241: foreach (@currxlists) {
10242: if (m/^([^:]+):(\w*)$/) {
10243: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10244: push(@{$allcourses},$1);
1.645 raeburn 10245: $$LC_code{$1} = $2;
10246: }
10247: }
10248: }
10249: }
10250:
10251: if (@currsections > 0) {
10252: foreach (@currsections) {
10253: if (m/^(\w+):(\w*)$/) {
10254: my $sec = $coursecode.$1;
10255: my $lc_sec = $2;
10256: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10257: push(@{$allcourses},$sec);
1.645 raeburn 10258: $$LC_code{$sec} = $lc_sec;
10259: }
10260: }
10261: }
10262: }
10263: return;
10264: }
10265:
1.971 raeburn 10266: sub get_standard_codeitems {
10267: return ('Year','Semester','Department','Number','Section');
10268: }
10269:
1.112 bowersj2 10270: =pod
10271:
1.780 raeburn 10272: =head1 Slot Helpers
10273:
10274: =over 4
10275:
10276: =item * sorted_slots()
10277:
1.1040 raeburn 10278: Sorts an array of slot names in order of an optional sort key,
10279: default sort is by slot start time (earliest first).
1.780 raeburn 10280:
10281: Inputs:
10282:
10283: =over 4
10284:
10285: slotsarr - Reference to array of unsorted slot names.
10286:
10287: slots - Reference to hash of hash, where outer hash keys are slot names.
10288:
1.1040 raeburn 10289: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10290:
1.549 albertel 10291: =back
10292:
1.780 raeburn 10293: Returns:
10294:
10295: =over 4
10296:
1.1040 raeburn 10297: sorted - An array of slot names sorted by a specified sort key
10298: (default sort key is start time of the slot).
1.780 raeburn 10299:
10300: =back
10301:
10302: =cut
10303:
10304:
10305: sub sorted_slots {
1.1040 raeburn 10306: my ($slotsarr,$slots,$sortkey) = @_;
10307: if ($sortkey eq '') {
10308: $sortkey = 'starttime';
10309: }
1.780 raeburn 10310: my @sorted;
10311: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10312: @sorted =
10313: sort {
10314: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10315: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10316: }
10317: if (ref($slots->{$a})) { return -1;}
10318: if (ref($slots->{$b})) { return 1;}
10319: return 0;
10320: } @{$slotsarr};
10321: }
10322: return @sorted;
10323: }
10324:
1.1040 raeburn 10325: =pod
10326:
10327: =item * get_future_slots()
10328:
10329: Inputs:
10330:
10331: =over 4
10332:
10333: cnum - course number
10334:
10335: cdom - course domain
10336:
10337: now - current UNIX time
10338:
10339: symb - optional symb
10340:
10341: =back
10342:
10343: Returns:
10344:
10345: =over 4
10346:
10347: sorted_reservable - ref to array of student_schedulable slots currently
10348: reservable, ordered by end date of reservation period.
10349:
10350: reservable_now - ref to hash of student_schedulable slots currently
10351: reservable.
10352:
10353: Keys in inner hash are:
10354: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10355: (b) endreserve: end date of reservation period.
10356: (c) uniqueperiod: start,end dates when slot is to be uniquely
10357: selected.
1.1040 raeburn 10358:
10359: sorted_future - ref to array of student_schedulable slots reservable in
10360: the future, ordered by start date of reservation period.
10361:
10362: future_reservable - ref to hash of student_schedulable slots reservable
10363: in the future.
10364:
10365: Keys in inner hash are:
10366: (a) symb: either blank or symb to which slot use is restricted.
10367: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10368: (c) uniqueperiod: start,end dates when slot is to be uniquely
10369: selected.
1.1040 raeburn 10370:
10371: =back
10372:
10373: =cut
10374:
10375: sub get_future_slots {
10376: my ($cnum,$cdom,$now,$symb) = @_;
10377: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10378: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10379: foreach my $slot (keys(%slots)) {
10380: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10381: if ($symb) {
10382: next if (($slots{$slot}->{'symb'} ne '') &&
10383: ($slots{$slot}->{'symb'} ne $symb));
10384: }
10385: if (($slots{$slot}->{'starttime'} > $now) &&
10386: ($slots{$slot}->{'endtime'} > $now)) {
10387: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10388: my $userallowed = 0;
10389: if ($slots{$slot}->{'allowedsections'}) {
10390: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10391: if (!defined($env{'request.role.sec'})
10392: && grep(/^No section assigned$/,@allowed_sec)) {
10393: $userallowed=1;
10394: } else {
10395: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10396: $userallowed=1;
10397: }
10398: }
10399: unless ($userallowed) {
10400: if (defined($env{'request.course.groups'})) {
10401: my @groups = split(/:/,$env{'request.course.groups'});
10402: foreach my $group (@groups) {
10403: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10404: $userallowed=1;
10405: last;
10406: }
10407: }
10408: }
10409: }
10410: }
10411: if ($slots{$slot}->{'allowedusers'}) {
10412: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10413: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10414: if (grep(/^\Q$user\E$/,@allowed_users)) {
10415: $userallowed = 1;
10416: }
10417: }
10418: next unless($userallowed);
10419: }
10420: my $startreserve = $slots{$slot}->{'startreserve'};
10421: my $endreserve = $slots{$slot}->{'endreserve'};
10422: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10423: my $uniqueperiod;
10424: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10425: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10426: }
1.1040 raeburn 10427: if (($startreserve < $now) &&
10428: (!$endreserve || $endreserve > $now)) {
10429: my $lastres = $endreserve;
10430: if (!$lastres) {
10431: $lastres = $slots{$slot}->{'starttime'};
10432: }
10433: $reservable_now{$slot} = {
10434: symb => $symb,
1.1075.2.104 raeburn 10435: endreserve => $lastres,
10436: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10437: };
10438: } elsif (($startreserve > $now) &&
10439: (!$endreserve || $endreserve > $startreserve)) {
10440: $future_reservable{$slot} = {
10441: symb => $symb,
1.1075.2.104 raeburn 10442: startreserve => $startreserve,
10443: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10444: };
10445: }
10446: }
10447: }
10448: my @unsorted_reservable = keys(%reservable_now);
10449: if (@unsorted_reservable > 0) {
10450: @sorted_reservable =
10451: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10452: }
10453: my @unsorted_future = keys(%future_reservable);
10454: if (@unsorted_future > 0) {
10455: @sorted_future =
10456: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10457: }
10458: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10459: }
1.780 raeburn 10460:
10461: =pod
10462:
1.1057 foxr 10463: =back
10464:
1.549 albertel 10465: =head1 HTTP Helpers
10466:
10467: =over 4
10468:
1.648 raeburn 10469: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10470:
1.258 albertel 10471: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10472: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10473: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10474:
10475: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10476: $possible_names is an ref to an array of form element names. As an example:
10477: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10478: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10479:
10480: =cut
1.1 albertel 10481:
1.6 albertel 10482: sub get_unprocessed_cgi {
1.25 albertel 10483: my ($query,$possible_names)= @_;
1.26 matthew 10484: # $Apache::lonxml::debug=1;
1.356 albertel 10485: foreach my $pair (split(/&/,$query)) {
10486: my ($name, $value) = split(/=/,$pair);
1.369 www 10487: $name = &unescape($name);
1.25 albertel 10488: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10489: $value =~ tr/+/ /;
10490: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10491: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10492: }
1.16 harris41 10493: }
1.6 albertel 10494: }
10495:
1.112 bowersj2 10496: =pod
10497:
1.648 raeburn 10498: =item * &cacheheader()
1.112 bowersj2 10499:
10500: returns cache-controlling header code
10501:
10502: =cut
10503:
1.7 albertel 10504: sub cacheheader {
1.258 albertel 10505: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10506: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10507: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10508: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10509: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10510: return $output;
1.7 albertel 10511: }
10512:
1.112 bowersj2 10513: =pod
10514:
1.648 raeburn 10515: =item * &no_cache($r)
1.112 bowersj2 10516:
10517: specifies header code to not have cache
10518:
10519: =cut
10520:
1.9 albertel 10521: sub no_cache {
1.216 albertel 10522: my ($r) = @_;
10523: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10524: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10525: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10526: $r->no_cache(1);
10527: $r->header_out("Expires" => $date);
10528: $r->header_out("Pragma" => "no-cache");
1.123 www 10529: }
10530:
10531: sub content_type {
1.181 albertel 10532: my ($r,$type,$charset) = @_;
1.299 foxr 10533: if ($r) {
10534: # Note that printout.pl calls this with undef for $r.
10535: &no_cache($r);
10536: }
1.258 albertel 10537: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10538: unless ($charset) {
10539: $charset=&Apache::lonlocal::current_encoding;
10540: }
10541: if ($charset) { $type.='; charset='.$charset; }
10542: if ($r) {
10543: $r->content_type($type);
10544: } else {
10545: print("Content-type: $type\n\n");
10546: }
1.9 albertel 10547: }
1.25 albertel 10548:
1.112 bowersj2 10549: =pod
10550:
1.648 raeburn 10551: =item * &add_to_env($name,$value)
1.112 bowersj2 10552:
1.258 albertel 10553: adds $name to the %env hash with value
1.112 bowersj2 10554: $value, if $name already exists, the entry is converted to an array
10555: reference and $value is added to the array.
10556:
10557: =cut
10558:
1.25 albertel 10559: sub add_to_env {
10560: my ($name,$value)=@_;
1.258 albertel 10561: if (defined($env{$name})) {
10562: if (ref($env{$name})) {
1.25 albertel 10563: #already have multiple values
1.258 albertel 10564: push(@{ $env{$name} },$value);
1.25 albertel 10565: } else {
10566: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10567: my $first=$env{$name};
10568: undef($env{$name});
10569: push(@{ $env{$name} },$first,$value);
1.25 albertel 10570: }
10571: } else {
1.258 albertel 10572: $env{$name}=$value;
1.25 albertel 10573: }
1.31 albertel 10574: }
1.149 albertel 10575:
10576: =pod
10577:
1.648 raeburn 10578: =item * &get_env_multiple($name)
1.149 albertel 10579:
1.258 albertel 10580: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10581: values may be defined and end up as an array ref.
10582:
10583: returns an array of values
10584:
10585: =cut
10586:
10587: sub get_env_multiple {
10588: my ($name) = @_;
10589: my @values;
1.258 albertel 10590: if (defined($env{$name})) {
1.149 albertel 10591: # exists is it an array
1.258 albertel 10592: if (ref($env{$name})) {
10593: @values=@{ $env{$name} };
1.149 albertel 10594: } else {
1.258 albertel 10595: $values[0]=$env{$name};
1.149 albertel 10596: }
10597: }
10598: return(@values);
10599: }
10600:
1.660 raeburn 10601: sub ask_for_embedded_content {
10602: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10603: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10604: %currsubfile,%unused,$rem);
1.1071 raeburn 10605: my $counter = 0;
10606: my $numnew = 0;
1.987 raeburn 10607: my $numremref = 0;
10608: my $numinvalid = 0;
10609: my $numpathchg = 0;
10610: my $numexisting = 0;
1.1071 raeburn 10611: my $numunused = 0;
10612: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10613: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10614: my $heading = &mt('Upload embedded files');
10615: my $buttontext = &mt('Upload');
10616:
1.1075.2.11 raeburn 10617: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10618: if ($actionurl eq '/adm/dependencies') {
10619: $navmap = Apache::lonnavmaps::navmap->new();
10620: }
10621: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10622: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10623: }
1.1075.2.35 raeburn 10624: if (($actionurl eq '/adm/portfolio') ||
10625: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10626: my $current_path='/';
10627: if ($env{'form.currentpath'}) {
10628: $current_path = $env{'form.currentpath'};
10629: }
10630: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10631: $udom = $cdom;
10632: $uname = $cnum;
1.984 raeburn 10633: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10634: } else {
10635: $udom = $env{'user.domain'};
10636: $uname = $env{'user.name'};
10637: $url = '/userfiles/portfolio';
10638: }
1.987 raeburn 10639: $toplevel = $url.'/';
1.984 raeburn 10640: $url .= $current_path;
10641: $getpropath = 1;
1.987 raeburn 10642: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10643: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10644: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10645: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10646: $toplevel = $url;
1.984 raeburn 10647: if ($rest ne '') {
1.987 raeburn 10648: $url .= $rest;
10649: }
10650: } elsif ($actionurl eq '/adm/coursedocs') {
10651: if (ref($args) eq 'HASH') {
1.1071 raeburn 10652: $url = $args->{'docs_url'};
10653: $toplevel = $url;
1.1075.2.11 raeburn 10654: if ($args->{'context'} eq 'paste') {
10655: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10656: ($path) =
10657: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10658: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10659: $fileloc =~ s{^/}{};
10660: }
1.1071 raeburn 10661: }
10662: } elsif ($actionurl eq '/adm/dependencies') {
10663: if ($env{'request.course.id'} ne '') {
10664: if (ref($args) eq 'HASH') {
10665: $url = $args->{'docs_url'};
10666: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10667: $toplevel = $url;
10668: unless ($toplevel =~ m{^/}) {
10669: $toplevel = "/$url";
10670: }
1.1075.2.11 raeburn 10671: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10672: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10673: $path = $1;
10674: } else {
10675: ($path) =
10676: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10677: }
1.1075.2.79 raeburn 10678: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10679: $fileloc = $toplevel;
10680: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10681: my ($udom,$uname,$fname) =
10682: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10683: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10684: } else {
10685: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10686: }
1.1071 raeburn 10687: $fileloc =~ s{^/}{};
10688: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10689: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10690: }
1.987 raeburn 10691: }
1.1075.2.35 raeburn 10692: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10693: $udom = $cdom;
10694: $uname = $cnum;
10695: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10696: $toplevel = $url;
10697: $path = $url;
10698: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10699: $fileloc =~ s{^/}{};
10700: }
10701: foreach my $file (keys(%{$allfiles})) {
10702: my $embed_file;
10703: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10704: $embed_file = $1;
10705: } else {
10706: $embed_file = $file;
10707: }
1.1075.2.55 raeburn 10708: my ($absolutepath,$cleaned_file);
10709: if ($embed_file =~ m{^\w+://}) {
10710: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10711: $newfiles{$cleaned_file} = 1;
10712: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10713: } else {
1.1075.2.55 raeburn 10714: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10715: if ($embed_file =~ m{^/}) {
10716: $absolutepath = $embed_file;
10717: }
1.1075.2.47 raeburn 10718: if ($cleaned_file =~ m{/}) {
10719: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10720: $path = &check_for_traversal($path,$url,$toplevel);
10721: my $item = $fname;
10722: if ($path ne '') {
10723: $item = $path.'/'.$fname;
10724: $subdependencies{$path}{$fname} = 1;
10725: } else {
10726: $dependencies{$item} = 1;
10727: }
10728: if ($absolutepath) {
10729: $mapping{$item} = $absolutepath;
10730: } else {
10731: $mapping{$item} = $embed_file;
10732: }
10733: } else {
10734: $dependencies{$embed_file} = 1;
10735: if ($absolutepath) {
1.1075.2.47 raeburn 10736: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10737: } else {
1.1075.2.47 raeburn 10738: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10739: }
10740: }
1.984 raeburn 10741: }
10742: }
1.1071 raeburn 10743: my $dirptr = 16384;
1.984 raeburn 10744: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10745: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10746: if (($actionurl eq '/adm/portfolio') ||
10747: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10748: my ($sublistref,$listerror) =
10749: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10750: if (ref($sublistref) eq 'ARRAY') {
10751: foreach my $line (@{$sublistref}) {
10752: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10753: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10754: }
1.984 raeburn 10755: }
1.987 raeburn 10756: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10757: if (opendir(my $dir,$url.'/'.$path)) {
10758: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10759: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10760: }
1.1075.2.11 raeburn 10761: } elsif (($actionurl eq '/adm/dependencies') ||
10762: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10763: ($args->{'context'} eq 'paste')) ||
10764: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10765: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10766: my $dir;
10767: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10768: $dir = $fileloc;
10769: } else {
10770: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10771: }
1.1071 raeburn 10772: if ($dir ne '') {
10773: my ($sublistref,$listerror) =
10774: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10775: if (ref($sublistref) eq 'ARRAY') {
10776: foreach my $line (@{$sublistref}) {
10777: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10778: undef,$mtime)=split(/\&/,$line,12);
10779: unless (($testdir&$dirptr) ||
10780: ($file_name =~ /^\.\.?$/)) {
10781: $currsubfile{$path}{$file_name} = [$size,$mtime];
10782: }
10783: }
10784: }
10785: }
1.984 raeburn 10786: }
10787: }
10788: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10789: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10790: my $item = $path.'/'.$file;
10791: unless ($mapping{$item} eq $item) {
10792: $pathchanges{$item} = 1;
10793: }
10794: $existing{$item} = 1;
10795: $numexisting ++;
10796: } else {
10797: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10798: }
10799: }
1.1071 raeburn 10800: if ($actionurl eq '/adm/dependencies') {
10801: foreach my $path (keys(%currsubfile)) {
10802: if (ref($currsubfile{$path}) eq 'HASH') {
10803: foreach my $file (keys(%{$currsubfile{$path}})) {
10804: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10805: next if (($rem ne '') &&
10806: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10807: (ref($navmap) &&
10808: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10809: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10810: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10811: $unused{$path.'/'.$file} = 1;
10812: }
10813: }
10814: }
10815: }
10816: }
1.984 raeburn 10817: }
1.987 raeburn 10818: my %currfile;
1.1075.2.35 raeburn 10819: if (($actionurl eq '/adm/portfolio') ||
10820: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10821: my ($dirlistref,$listerror) =
10822: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10823: if (ref($dirlistref) eq 'ARRAY') {
10824: foreach my $line (@{$dirlistref}) {
10825: my ($file_name,$rest) = split(/\&/,$line,2);
10826: $currfile{$file_name} = 1;
10827: }
1.984 raeburn 10828: }
1.987 raeburn 10829: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10830: if (opendir(my $dir,$url)) {
1.987 raeburn 10831: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10832: map {$currfile{$_} = 1;} @dir_list;
10833: }
1.1075.2.11 raeburn 10834: } elsif (($actionurl eq '/adm/dependencies') ||
10835: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10836: ($args->{'context'} eq 'paste')) ||
10837: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10838: if ($env{'request.course.id'} ne '') {
10839: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10840: if ($dir ne '') {
10841: my ($dirlistref,$listerror) =
10842: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10843: if (ref($dirlistref) eq 'ARRAY') {
10844: foreach my $line (@{$dirlistref}) {
10845: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10846: $size,undef,$mtime)=split(/\&/,$line,12);
10847: unless (($testdir&$dirptr) ||
10848: ($file_name =~ /^\.\.?$/)) {
10849: $currfile{$file_name} = [$size,$mtime];
10850: }
10851: }
10852: }
10853: }
10854: }
1.984 raeburn 10855: }
10856: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10857: if (exists($currfile{$file})) {
1.987 raeburn 10858: unless ($mapping{$file} eq $file) {
10859: $pathchanges{$file} = 1;
10860: }
10861: $existing{$file} = 1;
10862: $numexisting ++;
10863: } else {
1.984 raeburn 10864: $newfiles{$file} = 1;
10865: }
10866: }
1.1071 raeburn 10867: foreach my $file (keys(%currfile)) {
10868: unless (($file eq $filename) ||
10869: ($file eq $filename.'.bak') ||
10870: ($dependencies{$file})) {
1.1075.2.11 raeburn 10871: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10872: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10873: next if (($rem ne '') &&
10874: (($env{"httpref.$rem".$file} ne '') ||
10875: (ref($navmap) &&
10876: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10877: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10878: ($navmap->getResourceByUrl($rem.$1)))))));
10879: }
1.1075.2.11 raeburn 10880: }
1.1071 raeburn 10881: $unused{$file} = 1;
10882: }
10883: }
1.1075.2.11 raeburn 10884: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10885: ($args->{'context'} eq 'paste')) {
10886: $counter = scalar(keys(%existing));
10887: $numpathchg = scalar(keys(%pathchanges));
10888: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10889: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10890: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10891: $counter = scalar(keys(%existing));
10892: $numpathchg = scalar(keys(%pathchanges));
10893: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10894: }
1.984 raeburn 10895: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10896: if ($actionurl eq '/adm/dependencies') {
10897: next if ($embed_file =~ m{^\w+://});
10898: }
1.660 raeburn 10899: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10900: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10901: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10902: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10903: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10904: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10905: }
1.1075.2.35 raeburn 10906: $upload_output .= '</td>';
1.1071 raeburn 10907: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10908: $upload_output.='<td align="right">'.
10909: '<span class="LC_info LC_fontsize_medium">'.
10910: &mt("URL points to web address").'</span>';
1.987 raeburn 10911: $numremref++;
1.660 raeburn 10912: } elsif ($args->{'error_on_invalid_names'}
10913: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10914: $upload_output.='<td align="right"><span class="LC_warning">'.
10915: &mt('Invalid characters').'</span>';
1.987 raeburn 10916: $numinvalid++;
1.660 raeburn 10917: } else {
1.1075.2.35 raeburn 10918: $upload_output .= '<td>'.
10919: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10920: $embed_file,\%mapping,
1.1071 raeburn 10921: $allfiles,$codebase,'upload');
10922: $counter ++;
10923: $numnew ++;
1.987 raeburn 10924: }
10925: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10926: }
10927: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10928: if ($actionurl eq '/adm/dependencies') {
10929: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10930: $modify_output .= &start_data_table_row().
10931: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10932: '<img src="'.&icon($embed_file).'" border="0" />'.
10933: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10934: '<td>'.$size.'</td>'.
10935: '<td>'.$mtime.'</td>'.
10936: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10937: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10938: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10939: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10940: &embedded_file_element('upload_embedded',$counter,
10941: $embed_file,\%mapping,
10942: $allfiles,$codebase,'modify').
10943: '</div></td>'.
10944: &end_data_table_row()."\n";
10945: $counter ++;
10946: } else {
10947: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10948: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10949: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10950: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10951: &Apache::loncommon::end_data_table_row()."\n";
10952: }
10953: }
10954: my $delidx = $counter;
10955: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10956: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10957: $delete_output .= &start_data_table_row().
10958: '<td><img src="'.&icon($oldfile).'" />'.
10959: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10960: '<td>'.$size.'</td>'.
10961: '<td>'.$mtime.'</td>'.
10962: '<td><label><input type="checkbox" name="del_upload_dep" '.
10963: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10964: &embedded_file_element('upload_embedded',$delidx,
10965: $oldfile,\%mapping,$allfiles,
10966: $codebase,'delete').'</td>'.
10967: &end_data_table_row()."\n";
10968: $numunused ++;
10969: $delidx ++;
1.987 raeburn 10970: }
10971: if ($upload_output) {
10972: $upload_output = &start_data_table().
10973: $upload_output.
10974: &end_data_table()."\n";
10975: }
1.1071 raeburn 10976: if ($modify_output) {
10977: $modify_output = &start_data_table().
10978: &start_data_table_header_row().
10979: '<th>'.&mt('File').'</th>'.
10980: '<th>'.&mt('Size (KB)').'</th>'.
10981: '<th>'.&mt('Modified').'</th>'.
10982: '<th>'.&mt('Upload replacement?').'</th>'.
10983: &end_data_table_header_row().
10984: $modify_output.
10985: &end_data_table()."\n";
10986: }
10987: if ($delete_output) {
10988: $delete_output = &start_data_table().
10989: &start_data_table_header_row().
10990: '<th>'.&mt('File').'</th>'.
10991: '<th>'.&mt('Size (KB)').'</th>'.
10992: '<th>'.&mt('Modified').'</th>'.
10993: '<th>'.&mt('Delete?').'</th>'.
10994: &end_data_table_header_row().
10995: $delete_output.
10996: &end_data_table()."\n";
10997: }
1.987 raeburn 10998: my $applies = 0;
10999: if ($numremref) {
11000: $applies ++;
11001: }
11002: if ($numinvalid) {
11003: $applies ++;
11004: }
11005: if ($numexisting) {
11006: $applies ++;
11007: }
1.1071 raeburn 11008: if ($counter || $numunused) {
1.987 raeburn 11009: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11010: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11011: $state.'<h3>'.$heading.'</h3>';
11012: if ($actionurl eq '/adm/dependencies') {
11013: if ($numnew) {
11014: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11015: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11016: $upload_output.'<br />'."\n";
11017: }
11018: if ($numexisting) {
11019: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11020: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11021: $modify_output.'<br />'."\n";
11022: $buttontext = &mt('Save changes');
11023: }
11024: if ($numunused) {
11025: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11026: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11027: $delete_output.'<br />'."\n";
11028: $buttontext = &mt('Save changes');
11029: }
11030: } else {
11031: $output .= $upload_output.'<br />'."\n";
11032: }
11033: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11034: $counter.'" />'."\n";
11035: if ($actionurl eq '/adm/dependencies') {
11036: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11037: $numnew.'" />'."\n";
11038: } elsif ($actionurl eq '') {
1.987 raeburn 11039: $output .= '<input type="hidden" name="phase" value="three" />';
11040: }
11041: } elsif ($applies) {
11042: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11043: if ($applies > 1) {
11044: $output .=
1.1075.2.35 raeburn 11045: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11046: if ($numremref) {
11047: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11048: }
11049: if ($numinvalid) {
11050: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11051: }
11052: if ($numexisting) {
11053: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11054: }
11055: $output .= '</ul><br />';
11056: } elsif ($numremref) {
11057: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11058: } elsif ($numinvalid) {
11059: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11060: } elsif ($numexisting) {
11061: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11062: }
11063: $output .= $upload_output.'<br />';
11064: }
11065: my ($pathchange_output,$chgcount);
1.1071 raeburn 11066: $chgcount = $counter;
1.987 raeburn 11067: if (keys(%pathchanges) > 0) {
11068: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11069: if ($counter) {
1.987 raeburn 11070: $output .= &embedded_file_element('pathchange',$chgcount,
11071: $embed_file,\%mapping,
1.1071 raeburn 11072: $allfiles,$codebase,'change');
1.987 raeburn 11073: } else {
11074: $pathchange_output .=
11075: &start_data_table_row().
11076: '<td><input type ="checkbox" name="namechange" value="'.
11077: $chgcount.'" checked="checked" /></td>'.
11078: '<td>'.$mapping{$embed_file}.'</td>'.
11079: '<td>'.$embed_file.
11080: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11081: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11082: '</td>'.&end_data_table_row();
1.660 raeburn 11083: }
1.987 raeburn 11084: $numpathchg ++;
11085: $chgcount ++;
1.660 raeburn 11086: }
11087: }
1.1075.2.35 raeburn 11088: if (($counter) || ($numunused)) {
1.987 raeburn 11089: if ($numpathchg) {
11090: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11091: $numpathchg.'" />'."\n";
11092: }
11093: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11094: ($actionurl eq '/adm/imsimport')) {
11095: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11096: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11097: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11098: } elsif ($actionurl eq '/adm/dependencies') {
11099: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11100: }
1.1075.2.35 raeburn 11101: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11102: } elsif ($numpathchg) {
11103: my %pathchange = ();
11104: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11105: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11106: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11107: }
1.987 raeburn 11108: }
1.1071 raeburn 11109: return ($output,$counter,$numpathchg);
1.987 raeburn 11110: }
11111:
1.1075.2.47 raeburn 11112: =pod
11113:
11114: =item * clean_path($name)
11115:
11116: Performs clean-up of directories, subdirectories and filename in an
11117: embedded object, referenced in an HTML file which is being uploaded
11118: to a course or portfolio, where
11119: "Upload embedded images/multimedia files if HTML file" checkbox was
11120: checked.
11121:
11122: Clean-up is similar to replacements in lonnet::clean_filename()
11123: except each / between sub-directory and next level is preserved.
11124:
11125: =cut
11126:
11127: sub clean_path {
11128: my ($embed_file) = @_;
11129: $embed_file =~s{^/+}{};
11130: my @contents;
11131: if ($embed_file =~ m{/}) {
11132: @contents = split(/\//,$embed_file);
11133: } else {
11134: @contents = ($embed_file);
11135: }
11136: my $lastidx = scalar(@contents)-1;
11137: for (my $i=0; $i<=$lastidx; $i++) {
11138: $contents[$i]=~s{\\}{/}g;
11139: $contents[$i]=~s/\s+/\_/g;
11140: $contents[$i]=~s{[^/\w\.\-]}{}g;
11141: if ($i == $lastidx) {
11142: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11143: }
11144: }
11145: if ($lastidx > 0) {
11146: return join('/',@contents);
11147: } else {
11148: return $contents[0];
11149: }
11150: }
11151:
1.987 raeburn 11152: sub embedded_file_element {
1.1071 raeburn 11153: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11154: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11155: (ref($codebase) eq 'HASH'));
11156: my $output;
1.1071 raeburn 11157: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11158: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11159: }
11160: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11161: &escape($embed_file).'" />';
11162: unless (($context eq 'upload_embedded') &&
11163: ($mapping->{$embed_file} eq $embed_file)) {
11164: $output .='
11165: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11166: }
11167: my $attrib;
11168: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11169: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11170: }
11171: $output .=
11172: "\n\t\t".
11173: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11174: $attrib.'" />';
11175: if (exists($codebase->{$mapping->{$embed_file}})) {
11176: $output .=
11177: "\n\t\t".
11178: '<input name="codebase_'.$num.'" type="hidden" value="'.
11179: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11180: }
1.987 raeburn 11181: return $output;
1.660 raeburn 11182: }
11183:
1.1071 raeburn 11184: sub get_dependency_details {
11185: my ($currfile,$currsubfile,$embed_file) = @_;
11186: my ($size,$mtime,$showsize,$showmtime);
11187: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11188: if ($embed_file =~ m{/}) {
11189: my ($path,$fname) = split(/\//,$embed_file);
11190: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11191: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11192: }
11193: } else {
11194: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11195: ($size,$mtime) = @{$currfile->{$embed_file}};
11196: }
11197: }
11198: $showsize = $size/1024.0;
11199: $showsize = sprintf("%.1f",$showsize);
11200: if ($mtime > 0) {
11201: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11202: }
11203: }
11204: return ($showsize,$showmtime);
11205: }
11206:
11207: sub ask_embedded_js {
11208: return <<"END";
11209: <script type="text/javascript"">
11210: // <![CDATA[
11211: function toggleBrowse(counter) {
11212: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11213: var fileid = document.getElementById('embedded_item_'+counter);
11214: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11215: if (chkboxid.checked == true) {
11216: uploaddivid.style.display='block';
11217: } else {
11218: uploaddivid.style.display='none';
11219: fileid.value = '';
11220: }
11221: }
11222: // ]]>
11223: </script>
11224:
11225: END
11226: }
11227:
1.661 raeburn 11228: sub upload_embedded {
11229: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11230: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11231: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11232: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11233: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11234: my $orig_uploaded_filename =
11235: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11236: foreach my $type ('orig','ref','attrib','codebase') {
11237: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11238: $env{'form.embedded_'.$type.'_'.$i} =
11239: &unescape($env{'form.embedded_'.$type.'_'.$i});
11240: }
11241: }
1.661 raeburn 11242: my ($path,$fname) =
11243: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11244: # no path, whole string is fname
11245: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11246: $fname = &Apache::lonnet::clean_filename($fname);
11247: # See if there is anything left
11248: next if ($fname eq '');
11249:
11250: # Check if file already exists as a file or directory.
11251: my ($state,$msg);
11252: if ($context eq 'portfolio') {
11253: my $port_path = $dirpath;
11254: if ($group ne '') {
11255: $port_path = "groups/$group/$port_path";
11256: }
1.987 raeburn 11257: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11258: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11259: $dir_root,$port_path,$disk_quota,
11260: $current_disk_usage,$uname,$udom);
11261: if ($state eq 'will_exceed_quota'
1.984 raeburn 11262: || $state eq 'file_locked') {
1.661 raeburn 11263: $output .= $msg;
11264: next;
11265: }
11266: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11267: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11268: if ($state eq 'exists') {
11269: $output .= $msg;
11270: next;
11271: }
11272: }
11273: # Check if extension is valid
11274: if (($fname =~ /\.(\w+)$/) &&
11275: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11276: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11277: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11278: next;
11279: } elsif (($fname =~ /\.(\w+)$/) &&
11280: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11281: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11282: next;
11283: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11284: $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 11285: next;
11286: }
11287: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11288: my $subdir = $path;
11289: $subdir =~ s{/+$}{};
1.661 raeburn 11290: if ($context eq 'portfolio') {
1.984 raeburn 11291: my $result;
11292: if ($state eq 'existingfile') {
11293: $result=
11294: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11295: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11296: } else {
1.984 raeburn 11297: $result=
11298: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11299: $dirpath.
1.1075.2.35 raeburn 11300: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11301: if ($result !~ m|^/uploaded/|) {
11302: $output .= '<span class="LC_error">'
11303: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11304: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11305: .'</span><br />';
11306: next;
11307: } else {
1.987 raeburn 11308: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11309: $path.$fname.'</span>').'<br />';
1.984 raeburn 11310: }
1.661 raeburn 11311: }
1.1075.2.35 raeburn 11312: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11313: my $extendedsubdir = $dirpath.'/'.$subdir;
11314: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11315: my $result =
1.1075.2.35 raeburn 11316: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11317: if ($result !~ m|^/uploaded/|) {
11318: $output .= '<span class="LC_error">'
11319: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11320: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11321: .'</span><br />';
11322: next;
11323: } else {
11324: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11325: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11326: if ($context eq 'syllabus') {
11327: &Apache::lonnet::make_public_indefinitely($result);
11328: }
1.987 raeburn 11329: }
1.661 raeburn 11330: } else {
11331: # Save the file
11332: my $target = $env{'form.embedded_item_'.$i};
11333: my $fullpath = $dir_root.$dirpath.'/'.$path;
11334: my $dest = $fullpath.$fname;
11335: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11336: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11337: my $count;
11338: my $filepath = $dir_root;
1.1027 raeburn 11339: foreach my $subdir (@parts) {
11340: $filepath .= "/$subdir";
11341: if (!-e $filepath) {
1.661 raeburn 11342: mkdir($filepath,0770);
11343: }
11344: }
11345: my $fh;
11346: if (!open($fh,'>'.$dest)) {
11347: &Apache::lonnet::logthis('Failed to create '.$dest);
11348: $output .= '<span class="LC_error">'.
1.1071 raeburn 11349: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11350: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11351: '</span><br />';
11352: } else {
11353: if (!print $fh $env{'form.embedded_item_'.$i}) {
11354: &Apache::lonnet::logthis('Failed to write to '.$dest);
11355: $output .= '<span class="LC_error">'.
1.1071 raeburn 11356: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11357: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11358: '</span><br />';
11359: } else {
1.987 raeburn 11360: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11361: $url.'</span>').'<br />';
11362: unless ($context eq 'testbank') {
11363: $footer .= &mt('View embedded file: [_1]',
11364: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11365: }
11366: }
11367: close($fh);
11368: }
11369: }
11370: if ($env{'form.embedded_ref_'.$i}) {
11371: $pathchange{$i} = 1;
11372: }
11373: }
11374: if ($output) {
11375: $output = '<p>'.$output.'</p>';
11376: }
11377: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11378: $returnflag = 'ok';
1.1071 raeburn 11379: my $numpathchgs = scalar(keys(%pathchange));
11380: if ($numpathchgs > 0) {
1.987 raeburn 11381: if ($context eq 'portfolio') {
11382: $output .= '<p>'.&mt('or').'</p>';
11383: } elsif ($context eq 'testbank') {
1.1071 raeburn 11384: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11385: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11386: $returnflag = 'modify_orightml';
11387: }
11388: }
1.1071 raeburn 11389: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11390: }
11391:
11392: sub modify_html_form {
11393: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11394: my $end = 0;
11395: my $modifyform;
11396: if ($context eq 'upload_embedded') {
11397: return unless (ref($pathchange) eq 'HASH');
11398: if ($env{'form.number_embedded_items'}) {
11399: $end += $env{'form.number_embedded_items'};
11400: }
11401: if ($env{'form.number_pathchange_items'}) {
11402: $end += $env{'form.number_pathchange_items'};
11403: }
11404: if ($end) {
11405: for (my $i=0; $i<$end; $i++) {
11406: if ($i < $env{'form.number_embedded_items'}) {
11407: next unless($pathchange->{$i});
11408: }
11409: $modifyform .=
11410: &start_data_table_row().
11411: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11412: 'checked="checked" /></td>'.
11413: '<td>'.$env{'form.embedded_ref_'.$i}.
11414: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11415: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11416: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11417: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11418: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11419: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11420: '<td>'.$env{'form.embedded_orig_'.$i}.
11421: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11422: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11423: &end_data_table_row();
1.1071 raeburn 11424: }
1.987 raeburn 11425: }
11426: } else {
11427: $modifyform = $pathchgtable;
11428: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11429: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11430: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11431: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11432: }
11433: }
11434: if ($modifyform) {
1.1071 raeburn 11435: if ($actionurl eq '/adm/dependencies') {
11436: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11437: }
1.987 raeburn 11438: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11439: '<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".
11440: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11441: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11442: '</ol></p>'."\n".'<p>'.
11443: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11444: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11445: &start_data_table()."\n".
11446: &start_data_table_header_row().
11447: '<th>'.&mt('Change?').'</th>'.
11448: '<th>'.&mt('Current reference').'</th>'.
11449: '<th>'.&mt('Required reference').'</th>'.
11450: &end_data_table_header_row()."\n".
11451: $modifyform.
11452: &end_data_table().'<br />'."\n".$hiddenstate.
11453: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11454: '</form>'."\n";
11455: }
11456: return;
11457: }
11458:
11459: sub modify_html_refs {
1.1075.2.35 raeburn 11460: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11461: my $container;
11462: if ($context eq 'portfolio') {
11463: $container = $env{'form.container'};
11464: } elsif ($context eq 'coursedoc') {
11465: $container = $env{'form.primaryurl'};
1.1071 raeburn 11466: } elsif ($context eq 'manage_dependencies') {
11467: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11468: $container = "/$container";
1.1075.2.35 raeburn 11469: } elsif ($context eq 'syllabus') {
11470: $container = $url;
1.987 raeburn 11471: } else {
1.1027 raeburn 11472: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11473: }
11474: my (%allfiles,%codebase,$output,$content);
11475: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11476: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11477: if (wantarray) {
11478: return ('',0,0);
11479: } else {
11480: return;
11481: }
11482: }
11483: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11484: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11485: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11486: if (wantarray) {
11487: return ('',0,0);
11488: } else {
11489: return;
11490: }
11491: }
1.987 raeburn 11492: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11493: if ($content eq '-1') {
11494: if (wantarray) {
11495: return ('',0,0);
11496: } else {
11497: return;
11498: }
11499: }
1.987 raeburn 11500: } else {
1.1071 raeburn 11501: unless ($container =~ /^\Q$dir_root\E/) {
11502: if (wantarray) {
11503: return ('',0,0);
11504: } else {
11505: return;
11506: }
11507: }
1.1075.2.127. .5(raebu 11508:18): if (open(my $fh,'<',$container)) {
1.987 raeburn 11509: $content = join('', <$fh>);
11510: close($fh);
11511: } else {
1.1071 raeburn 11512: if (wantarray) {
11513: return ('',0,0);
11514: } else {
11515: return;
11516: }
1.987 raeburn 11517: }
11518: }
11519: my ($count,$codebasecount) = (0,0);
11520: my $mm = new File::MMagic;
11521: my $mime_type = $mm->checktype_contents($content);
11522: if ($mime_type eq 'text/html') {
11523: my $parse_result =
11524: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11525: \%codebase,\$content);
11526: if ($parse_result eq 'ok') {
11527: foreach my $i (@changes) {
11528: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11529: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11530: if ($allfiles{$ref}) {
11531: my $newname = $orig;
11532: my ($attrib_regexp,$codebase);
1.1006 raeburn 11533: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11534: if ($attrib_regexp =~ /:/) {
11535: $attrib_regexp =~ s/\:/|/g;
11536: }
11537: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11538: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11539: $count += $numchg;
1.1075.2.35 raeburn 11540: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11541: delete($allfiles{$ref});
1.987 raeburn 11542: }
11543: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11544: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11545: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11546: $codebasecount ++;
11547: }
11548: }
11549: }
1.1075.2.35 raeburn 11550: my $skiprewrites;
1.987 raeburn 11551: if ($count || $codebasecount) {
11552: my $saveresult;
1.1071 raeburn 11553: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11554: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11555: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11556: if ($url eq $container) {
11557: my ($fname) = ($container =~ m{/([^/]+)$});
11558: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11559: $count,'<span class="LC_filename">'.
1.1071 raeburn 11560: $fname.'</span>').'</p>';
1.987 raeburn 11561: } else {
11562: $output = '<p class="LC_error">'.
11563: &mt('Error: update failed for: [_1].',
11564: '<span class="LC_filename">'.
11565: $container.'</span>').'</p>';
11566: }
1.1075.2.35 raeburn 11567: if ($context eq 'syllabus') {
11568: unless ($saveresult eq 'ok') {
11569: $skiprewrites = 1;
11570: }
11571: }
1.987 raeburn 11572: } else {
1.1075.2.127. .5(raebu 11573:18): if (open(my $fh,'>',$container)) {
1.987 raeburn 11574: print $fh $content;
11575: close($fh);
11576: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11577: $count,'<span class="LC_filename">'.
11578: $container.'</span>').'</p>';
1.661 raeburn 11579: } else {
1.987 raeburn 11580: $output = '<p class="LC_error">'.
11581: &mt('Error: could not update [_1].',
11582: '<span class="LC_filename">'.
11583: $container.'</span>').'</p>';
1.661 raeburn 11584: }
11585: }
11586: }
1.1075.2.35 raeburn 11587: if (($context eq 'syllabus') && (!$skiprewrites)) {
11588: my ($actionurl,$state);
11589: $actionurl = "/public/$udom/$uname/syllabus";
11590: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11591: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11592: \%codebase,
11593: {'context' => 'rewrites',
11594: 'ignore_remote_references' => 1,});
11595: if (ref($mapping) eq 'HASH') {
11596: my $rewrites = 0;
11597: foreach my $key (keys(%{$mapping})) {
11598: next if ($key =~ m{^https?://});
11599: my $ref = $mapping->{$key};
11600: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11601: my $attrib;
11602: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11603: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11604: }
11605: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11606: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11607: $rewrites += $numchg;
11608: }
11609: }
11610: if ($rewrites) {
11611: my $saveresult;
11612: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11613: if ($url eq $container) {
11614: my ($fname) = ($container =~ m{/([^/]+)$});
11615: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11616: $count,'<span class="LC_filename">'.
11617: $fname.'</span>').'</p>';
11618: } else {
11619: $output .= '<p class="LC_error">'.
11620: &mt('Error: could not update links in [_1].',
11621: '<span class="LC_filename">'.
11622: $container.'</span>').'</p>';
11623:
11624: }
11625: }
11626: }
11627: }
1.987 raeburn 11628: } else {
11629: &logthis('Failed to parse '.$container.
11630: ' to modify references: '.$parse_result);
1.661 raeburn 11631: }
11632: }
1.1071 raeburn 11633: if (wantarray) {
11634: return ($output,$count,$codebasecount);
11635: } else {
11636: return $output;
11637: }
1.661 raeburn 11638: }
11639:
11640: sub check_for_existing {
11641: my ($path,$fname,$element) = @_;
11642: my ($state,$msg);
11643: if (-d $path.'/'.$fname) {
11644: $state = 'exists';
11645: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11646: } elsif (-e $path.'/'.$fname) {
11647: $state = 'exists';
11648: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11649: }
11650: if ($state eq 'exists') {
11651: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11652: }
11653: return ($state,$msg);
11654: }
11655:
11656: sub check_for_upload {
11657: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11658: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11659: my $filesize = length($env{'form.'.$element});
11660: if (!$filesize) {
11661: my $msg = '<span class="LC_error">'.
11662: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11663: '<span class="LC_filename">'.$fname.'</span>',
11664: $filesize).'<br />'.
1.1007 raeburn 11665: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11666: '</span>';
11667: return ('zero_bytes',$msg);
11668: }
11669: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11670: my $getpropath = 1;
1.1021 raeburn 11671: my ($dirlistref,$listerror) =
11672: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11673: my $found_file = 0;
11674: my $locked_file = 0;
1.991 raeburn 11675: my @lockers;
11676: my $navmap;
11677: if ($env{'request.course.id'}) {
11678: $navmap = Apache::lonnavmaps::navmap->new();
11679: }
1.1021 raeburn 11680: if (ref($dirlistref) eq 'ARRAY') {
11681: foreach my $line (@{$dirlistref}) {
11682: my ($file_name,$rest)=split(/\&/,$line,2);
11683: if ($file_name eq $fname){
11684: $file_name = $path.$file_name;
11685: if ($group ne '') {
11686: $file_name = $group.$file_name;
11687: }
11688: $found_file = 1;
11689: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11690: foreach my $lock (@lockers) {
11691: if (ref($lock) eq 'ARRAY') {
11692: my ($symb,$crsid) = @{$lock};
11693: if ($crsid eq $env{'request.course.id'}) {
11694: if (ref($navmap)) {
11695: my $res = $navmap->getBySymb($symb);
11696: foreach my $part (@{$res->parts()}) {
11697: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11698: unless (($slot_status == $res->RESERVED) ||
11699: ($slot_status == $res->RESERVED_LOCATION)) {
11700: $locked_file = 1;
11701: }
1.991 raeburn 11702: }
1.1021 raeburn 11703: } else {
11704: $locked_file = 1;
1.991 raeburn 11705: }
11706: } else {
11707: $locked_file = 1;
11708: }
11709: }
1.1021 raeburn 11710: }
11711: } else {
11712: my @info = split(/\&/,$rest);
11713: my $currsize = $info[6]/1000;
11714: if ($currsize < $filesize) {
11715: my $extra = $filesize - $currsize;
11716: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11717: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11718: &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.',
1.1075.2.69 raeburn 11719: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11720: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11721: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11722: return ('will_exceed_quota',$msg);
11723: }
1.984 raeburn 11724: }
11725: }
1.661 raeburn 11726: }
11727: }
11728: }
11729: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11730: my $msg = '<p class="LC_warning">'.
11731: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11732: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11733: return ('will_exceed_quota',$msg);
11734: } elsif ($found_file) {
11735: if ($locked_file) {
1.1075.2.69 raeburn 11736: my $msg = '<p class="LC_warning">';
1.661 raeburn 11737: $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>');
1.1075.2.69 raeburn 11738: $msg .= '</p>';
1.661 raeburn 11739: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11740: return ('file_locked',$msg);
11741: } else {
1.1075.2.69 raeburn 11742: my $msg = '<p class="LC_error">';
1.984 raeburn 11743: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 11744: $msg .= '</p>';
1.984 raeburn 11745: return ('existingfile',$msg);
1.661 raeburn 11746: }
11747: }
11748: }
11749:
1.987 raeburn 11750: sub check_for_traversal {
11751: my ($path,$url,$toplevel) = @_;
11752: my @parts=split(/\//,$path);
11753: my $cleanpath;
11754: my $fullpath = $url;
11755: for (my $i=0;$i<@parts;$i++) {
11756: next if ($parts[$i] eq '.');
11757: if ($parts[$i] eq '..') {
11758: $fullpath =~ s{([^/]+/)$}{};
11759: } else {
11760: $fullpath .= $parts[$i].'/';
11761: }
11762: }
11763: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11764: $cleanpath = $1;
11765: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11766: my $curr_toprel = $1;
11767: my @parts = split(/\//,$curr_toprel);
11768: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11769: my @urlparts = split(/\//,$url_toprel);
11770: my $doubledots;
11771: my $startdiff = -1;
11772: for (my $i=0; $i<@urlparts; $i++) {
11773: if ($startdiff == -1) {
11774: unless ($urlparts[$i] eq $parts[$i]) {
11775: $startdiff = $i;
11776: $doubledots .= '../';
11777: }
11778: } else {
11779: $doubledots .= '../';
11780: }
11781: }
11782: if ($startdiff > -1) {
11783: $cleanpath = $doubledots;
11784: for (my $i=$startdiff; $i<@parts; $i++) {
11785: $cleanpath .= $parts[$i].'/';
11786: }
11787: }
11788: }
11789: $cleanpath =~ s{(/)$}{};
11790: return $cleanpath;
11791: }
1.31 albertel 11792:
1.1053 raeburn 11793: sub is_archive_file {
11794: my ($mimetype) = @_;
11795: if (($mimetype eq 'application/octet-stream') ||
11796: ($mimetype eq 'application/x-stuffit') ||
11797: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11798: return 1;
11799: }
11800: return;
11801: }
11802:
11803: sub decompress_form {
1.1065 raeburn 11804: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11805: my %lt = &Apache::lonlocal::texthash (
11806: this => 'This file is an archive file.',
1.1067 raeburn 11807: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11808: itsc => 'Its contents are as follows:',
1.1053 raeburn 11809: youm => 'You may wish to extract its contents.',
11810: extr => 'Extract contents',
1.1067 raeburn 11811: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11812: proa => 'Process automatically?',
1.1053 raeburn 11813: yes => 'Yes',
11814: no => 'No',
1.1067 raeburn 11815: fold => 'Title for folder containing movie',
11816: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11817: );
1.1065 raeburn 11818: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11819: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11820: my $info = &list_archive_contents($fileloc,\@paths);
11821: if (@paths) {
11822: foreach my $path (@paths) {
11823: $path =~ s{^/}{};
1.1067 raeburn 11824: if ($path =~ m{^([^/]+)/$}) {
11825: $topdir = $1;
11826: }
1.1065 raeburn 11827: if ($path =~ m{^([^/]+)/}) {
11828: $toplevel{$1} = $path;
11829: } else {
11830: $toplevel{$path} = $path;
11831: }
11832: }
11833: }
1.1067 raeburn 11834: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11835: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11836: "$topdir/media/",
11837: "$topdir/media/$topdir.mp4",
11838: "$topdir/media/FirstFrame.png",
11839: "$topdir/media/player.swf",
11840: "$topdir/media/swfobject.js",
11841: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11842: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11843: "$topdir/$topdir.mp4",
11844: "$topdir/$topdir\_config.xml",
11845: "$topdir/$topdir\_controller.swf",
11846: "$topdir/$topdir\_embed.css",
11847: "$topdir/$topdir\_First_Frame.png",
11848: "$topdir/$topdir\_player.html",
11849: "$topdir/$topdir\_Thumbnails.png",
11850: "$topdir/playerProductInstall.swf",
11851: "$topdir/scripts/",
11852: "$topdir/scripts/config_xml.js",
11853: "$topdir/scripts/handlebars.js",
11854: "$topdir/scripts/jquery-1.7.1.min.js",
11855: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11856: "$topdir/scripts/modernizr.js",
11857: "$topdir/scripts/player-min.js",
11858: "$topdir/scripts/swfobject.js",
11859: "$topdir/skins/",
11860: "$topdir/skins/configuration_express.xml",
11861: "$topdir/skins/express_show/",
11862: "$topdir/skins/express_show/player-min.css",
11863: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11864: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11865: "$topdir/$topdir.mp4",
11866: "$topdir/$topdir\_config.xml",
11867: "$topdir/$topdir\_controller.swf",
11868: "$topdir/$topdir\_embed.css",
11869: "$topdir/$topdir\_First_Frame.png",
11870: "$topdir/$topdir\_player.html",
11871: "$topdir/$topdir\_Thumbnails.png",
11872: "$topdir/playerProductInstall.swf",
11873: "$topdir/scripts/",
11874: "$topdir/scripts/config_xml.js",
11875: "$topdir/scripts/techsmith-smart-player.min.js",
11876: "$topdir/skins/",
11877: "$topdir/skins/configuration_express.xml",
11878: "$topdir/skins/express_show/",
11879: "$topdir/skins/express_show/spritesheet.min.css",
11880: "$topdir/skins/express_show/spritesheet.png",
11881: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11882: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11883: if (@diffs == 0) {
1.1075.2.59 raeburn 11884: $is_camtasia = 6;
11885: } else {
1.1075.2.81 raeburn 11886: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11887: if (@diffs == 0) {
11888: $is_camtasia = 8;
1.1075.2.81 raeburn 11889: } else {
11890: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11891: if (@diffs == 0) {
11892: $is_camtasia = 8;
11893: }
1.1075.2.59 raeburn 11894: }
1.1067 raeburn 11895: }
11896: }
11897: my $output;
11898: if ($is_camtasia) {
11899: $output = <<"ENDCAM";
11900: <script type="text/javascript" language="Javascript">
11901: // <![CDATA[
11902:
11903: function camtasiaToggle() {
11904: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11905: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11906: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11907: document.getElementById('camtasia_titles').style.display='block';
11908: } else {
11909: document.getElementById('camtasia_titles').style.display='none';
11910: }
11911: }
11912: }
11913: return;
11914: }
11915:
11916: // ]]>
11917: </script>
11918: <p>$lt{'camt'}</p>
11919: ENDCAM
1.1065 raeburn 11920: } else {
1.1067 raeburn 11921: $output = '<p>'.$lt{'this'};
11922: if ($info eq '') {
11923: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11924: } else {
11925: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11926: '<div><pre>'.$info.'</pre></div>';
11927: }
1.1065 raeburn 11928: }
1.1067 raeburn 11929: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11930: my $duplicates;
11931: my $num = 0;
11932: if (ref($dirlist) eq 'ARRAY') {
11933: foreach my $item (@{$dirlist}) {
11934: if (ref($item) eq 'ARRAY') {
11935: if (exists($toplevel{$item->[0]})) {
11936: $duplicates .=
11937: &start_data_table_row().
11938: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11939: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11940: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11941: 'value="1" />'.&mt('Yes').'</label>'.
11942: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11943: '<td>'.$item->[0].'</td>';
11944: if ($item->[2]) {
11945: $duplicates .= '<td>'.&mt('Directory').'</td>';
11946: } else {
11947: $duplicates .= '<td>'.&mt('File').'</td>';
11948: }
11949: $duplicates .= '<td>'.$item->[3].'</td>'.
11950: '<td>'.
11951: &Apache::lonlocal::locallocaltime($item->[4]).
11952: '</td>'.
11953: &end_data_table_row();
11954: $num ++;
11955: }
11956: }
11957: }
11958: }
11959: my $itemcount;
11960: if (@paths > 0) {
11961: $itemcount = scalar(@paths);
11962: } else {
11963: $itemcount = 1;
11964: }
1.1067 raeburn 11965: if ($is_camtasia) {
11966: $output .= $lt{'auto'}.'<br />'.
11967: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11968: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11969: $lt{'yes'}.'</label> <label>'.
11970: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11971: $lt{'no'}.'</label></span><br />'.
11972: '<div id="camtasia_titles" style="display:block">'.
11973: &Apache::lonhtmlcommon::start_pick_box().
11974: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11975: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11976: &Apache::lonhtmlcommon::row_closure().
11977: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11978: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11979: &Apache::lonhtmlcommon::row_closure(1).
11980: &Apache::lonhtmlcommon::end_pick_box().
11981: '</div>';
11982: }
1.1065 raeburn 11983: $output .=
11984: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11985: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11986: "\n";
1.1065 raeburn 11987: if ($duplicates ne '') {
11988: $output .= '<p><span class="LC_warning">'.
11989: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11990: &start_data_table().
11991: &start_data_table_header_row().
11992: '<th>'.&mt('Overwrite?').'</th>'.
11993: '<th>'.&mt('Name').'</th>'.
11994: '<th>'.&mt('Type').'</th>'.
11995: '<th>'.&mt('Size').'</th>'.
11996: '<th>'.&mt('Last modified').'</th>'.
11997: &end_data_table_header_row().
11998: $duplicates.
11999: &end_data_table().
12000: '</p>';
12001: }
1.1067 raeburn 12002: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12003: if (ref($hiddenelements) eq 'HASH') {
12004: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12005: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12006: }
12007: }
12008: $output .= <<"END";
1.1067 raeburn 12009: <br />
1.1053 raeburn 12010: <input type="submit" name="decompress" value="$lt{'extr'}" />
12011: </form>
12012: $noextract
12013: END
12014: return $output;
12015: }
12016:
1.1065 raeburn 12017: sub decompression_utility {
12018: my ($program) = @_;
12019: my @utilities = ('tar','gunzip','bunzip2','unzip');
12020: my $location;
12021: if (grep(/^\Q$program\E$/,@utilities)) {
12022: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12023: '/usr/sbin/') {
12024: if (-x $dir.$program) {
12025: $location = $dir.$program;
12026: last;
12027: }
12028: }
12029: }
12030: return $location;
12031: }
12032:
12033: sub list_archive_contents {
12034: my ($file,$pathsref) = @_;
12035: my (@cmd,$output);
12036: my $needsregexp;
12037: if ($file =~ /\.zip$/) {
12038: @cmd = (&decompression_utility('unzip'),"-l");
12039: $needsregexp = 1;
12040: } elsif (($file =~ m/\.tar\.gz$/) ||
12041: ($file =~ /\.tgz$/)) {
12042: @cmd = (&decompression_utility('tar'),"-ztf");
12043: } elsif ($file =~ /\.tar\.bz2$/) {
12044: @cmd = (&decompression_utility('tar'),"-jtf");
12045: } elsif ($file =~ m|\.tar$|) {
12046: @cmd = (&decompression_utility('tar'),"-tf");
12047: }
12048: if (@cmd) {
12049: undef($!);
12050: undef($@);
12051: if (open(my $fh,"-|", @cmd, $file)) {
12052: while (my $line = <$fh>) {
12053: $output .= $line;
12054: chomp($line);
12055: my $item;
12056: if ($needsregexp) {
12057: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12058: } else {
12059: $item = $line;
12060: }
12061: if ($item ne '') {
12062: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12063: push(@{$pathsref},$item);
12064: }
12065: }
12066: }
12067: close($fh);
12068: }
12069: }
12070: return $output;
12071: }
12072:
1.1053 raeburn 12073: sub decompress_uploaded_file {
12074: my ($file,$dir) = @_;
12075: &Apache::lonnet::appenv({'cgi.file' => $file});
12076: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12077: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12078: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12079: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12080: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12081: my $decompressed = $env{'cgi.decompressed'};
12082: &Apache::lonnet::delenv('cgi.file');
12083: &Apache::lonnet::delenv('cgi.dir');
12084: &Apache::lonnet::delenv('cgi.decompressed');
12085: return ($decompressed,$result);
12086: }
12087:
1.1055 raeburn 12088: sub process_decompression {
12089: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.127. .3(raebu 12090:17): unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12091:17): return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12092:17): &mt('Unexpected file path.').'</p>'."\n";
12093:17): }
12094:17): unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12095:17): return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12096:17): &mt('Unexpected course context.').'</p>'."\n";
12097:17): }
12098:17): unless ($file eq &Apache::lonnet::clean_filename($file)) {
12099:17): return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12100:17): &mt('Filename contained unexpected characters.').'</p>'."\n";
12101:17): }
1.1055 raeburn 12102: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12103: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12104: $error = &mt('Filename not a supported archive file type.').
12105: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12106: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12107: } else {
12108: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12109: if ($docuhome eq 'no_host') {
12110: $error = &mt('Could not determine home server for course.');
12111: } else {
12112: my @ids=&Apache::lonnet::current_machine_ids();
12113: my $currdir = "$dir_root/$destination";
12114: if (grep(/^\Q$docuhome\E$/,@ids)) {
12115: $dir = &LONCAPA::propath($docudom,$docuname).
12116: "$dir_root/$destination";
12117: } else {
12118: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12119: "$dir_root/$docudom/$docuname/$destination";
12120: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12121: $error = &mt('Archive file not found.');
12122: }
12123: }
1.1065 raeburn 12124: my (@to_overwrite,@to_skip);
12125: if ($env{'form.archive_overwrite_total'} > 0) {
12126: my $total = $env{'form.archive_overwrite_total'};
12127: for (my $i=0; $i<$total; $i++) {
12128: if ($env{'form.archive_overwrite_'.$i} == 1) {
12129: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12130: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12131: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12132: }
12133: }
12134: }
12135: my $numskip = scalar(@to_skip);
1.1075.2.127. .3(raebu 12136:17): my $numoverwrite = scalar(@to_overwrite);
12137:17): if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12138: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12139: } elsif ($dir eq '') {
1.1055 raeburn 12140: $error = &mt('Directory containing archive file unavailable.');
12141: } elsif (!$error) {
1.1065 raeburn 12142: my ($decompressed,$display);
1.1075.2.127. .3(raebu 12143:17): if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12144: my $tempdir = time.'_'.$$.int(rand(10000));
12145: mkdir("$dir/$tempdir",0755);
1.1075.2.127. .3(raebu 12146:17): if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12147:17): ($decompressed,$display) =
12148:17): &decompress_uploaded_file($file,"$dir/$tempdir");
12149:17): foreach my $item (@to_skip) {
12150:17): if (($item ne '') && ($item !~ /\.\./)) {
12151:17): if (-f "$dir/$tempdir/$item") {
12152:17): unlink("$dir/$tempdir/$item");
12153:17): } elsif (-d "$dir/$tempdir/$item") {
.4(raebu 12154:17): &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
.3(raebu 12155:17): }
12156:17): }
12157:17): }
12158:17): foreach my $item (@to_overwrite) {
12159:17): if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12160:17): if (($item ne '') && ($item !~ /\.\./)) {
12161:17): if (-f "$dir/$item") {
12162:17): unlink("$dir/$item");
12163:17): } elsif (-d "$dir/$item") {
.4(raebu 12164:17): &File::Path::remove_tree("$dir/$item",{ safe => 1 });
.3(raebu 12165:17): }
12166:17): &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12167:17): }
1.1065 raeburn 12168: }
12169: }
1.1075.2.127. .3(raebu 12170:17): if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
.4(raebu 12171:17): &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
.3(raebu 12172:17): }
1.1065 raeburn 12173: }
12174: } else {
12175: ($decompressed,$display) =
12176: &decompress_uploaded_file($file,$dir);
12177: }
1.1055 raeburn 12178: if ($decompressed eq 'ok') {
1.1065 raeburn 12179: $output = '<p class="LC_info">'.
12180: &mt('Files extracted successfully from archive.').
12181: '</p>'."\n";
1.1055 raeburn 12182: my ($warning,$result,@contents);
12183: my ($newdirlistref,$newlisterror) =
12184: &Apache::lonnet::dirlist($currdir,$docudom,
12185: $docuname,1);
12186: my (%is_dir,%changes,@newitems);
12187: my $dirptr = 16384;
1.1065 raeburn 12188: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12189: foreach my $dir_line (@{$newdirlistref}) {
12190: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12191: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12192: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12193: push(@newitems,$item);
12194: if ($dirptr&$testdir) {
12195: $is_dir{$item} = 1;
12196: }
12197: $changes{$item} = 1;
12198: }
12199: }
12200: }
12201: if (keys(%changes) > 0) {
12202: foreach my $item (sort(@newitems)) {
12203: if ($changes{$item}) {
12204: push(@contents,$item);
12205: }
12206: }
12207: }
12208: if (@contents > 0) {
1.1067 raeburn 12209: my $wantform;
12210: unless ($env{'form.autoextract_camtasia'}) {
12211: $wantform = 1;
12212: }
1.1056 raeburn 12213: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12214: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12215: $currdir,\%is_dir,
12216: \%children,\%parent,
1.1056 raeburn 12217: \@contents,\%dirorder,
12218: \%titles,$wantform);
1.1055 raeburn 12219: if ($datatable ne '') {
12220: $output .= &archive_options_form('decompressed',$datatable,
12221: $count,$hiddenelem);
1.1065 raeburn 12222: my $startcount = 6;
1.1055 raeburn 12223: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12224: \%titles,\%children);
1.1055 raeburn 12225: }
1.1067 raeburn 12226: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12227: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12228: my %displayed;
12229: my $total = 1;
12230: $env{'form.archive_directory'} = [];
12231: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12232: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12233: $path =~ s{/$}{};
12234: my $item;
12235: if ($path ne '') {
12236: $item = "$path/$titles{$i}";
12237: } else {
12238: $item = $titles{$i};
12239: }
12240: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12241: if ($item eq $contents[0]) {
12242: push(@{$env{'form.archive_directory'}},$i);
12243: $env{'form.archive_'.$i} = 'display';
12244: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12245: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12246: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12247: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12248: $env{'form.archive_'.$i} = 'display';
12249: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12250: $displayed{'web'} = $i;
12251: } else {
1.1075.2.59 raeburn 12252: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12253: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12254: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12255: push(@{$env{'form.archive_directory'}},$i);
12256: }
12257: $env{'form.archive_'.$i} = 'dependency';
12258: }
12259: $total ++;
12260: }
12261: for (my $i=1; $i<$total; $i++) {
12262: next if ($i == $displayed{'web'});
12263: next if ($i == $displayed{'folder'});
12264: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12265: }
12266: $env{'form.phase'} = 'decompress_cleanup';
12267: $env{'form.archivedelete'} = 1;
12268: $env{'form.archive_count'} = $total-1;
12269: $output .=
12270: &process_extracted_files('coursedocs',$docudom,
12271: $docuname,$destination,
12272: $dir_root,$hiddenelem);
12273: }
1.1055 raeburn 12274: } else {
12275: $warning = &mt('No new items extracted from archive file.');
12276: }
12277: } else {
12278: $output = $display;
12279: $error = &mt('An error occurred during extraction from the archive file.');
12280: }
12281: }
12282: }
12283: }
12284: if ($error) {
12285: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12286: $error.'</p>'."\n";
12287: }
12288: if ($warning) {
12289: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12290: }
12291: return $output;
12292: }
12293:
12294: sub get_extracted {
1.1056 raeburn 12295: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12296: $titles,$wantform) = @_;
1.1055 raeburn 12297: my $count = 0;
12298: my $depth = 0;
12299: my $datatable;
1.1056 raeburn 12300: my @hierarchy;
1.1055 raeburn 12301: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12302: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12303: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12304: foreach my $item (@{$contents}) {
12305: $count ++;
1.1056 raeburn 12306: @{$dirorder->{$count}} = @hierarchy;
12307: $titles->{$count} = $item;
1.1055 raeburn 12308: &archive_hierarchy($depth,$count,$parent,$children);
12309: if ($wantform) {
12310: $datatable .= &archive_row($is_dir->{$item},$item,
12311: $currdir,$depth,$count);
12312: }
12313: if ($is_dir->{$item}) {
12314: $depth ++;
1.1056 raeburn 12315: push(@hierarchy,$count);
12316: $parent->{$depth} = $count;
1.1055 raeburn 12317: $datatable .=
12318: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12319: \$depth,\$count,\@hierarchy,$dirorder,
12320: $children,$parent,$titles,$wantform);
1.1055 raeburn 12321: $depth --;
1.1056 raeburn 12322: pop(@hierarchy);
1.1055 raeburn 12323: }
12324: }
12325: return ($count,$datatable);
12326: }
12327:
12328: sub recurse_extracted_archive {
1.1056 raeburn 12329: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12330: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12331: my $result='';
1.1056 raeburn 12332: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12333: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12334: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12335: return $result;
12336: }
12337: my $dirptr = 16384;
12338: my ($newdirlistref,$newlisterror) =
12339: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12340: if (ref($newdirlistref) eq 'ARRAY') {
12341: foreach my $dir_line (@{$newdirlistref}) {
12342: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12343: unless ($item =~ /^\.+$/) {
12344: $$count ++;
1.1056 raeburn 12345: @{$dirorder->{$$count}} = @{$hierarchy};
12346: $titles->{$$count} = $item;
1.1055 raeburn 12347: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12348:
1.1055 raeburn 12349: my $is_dir;
12350: if ($dirptr&$testdir) {
12351: $is_dir = 1;
12352: }
12353: if ($wantform) {
12354: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12355: }
12356: if ($is_dir) {
12357: $$depth ++;
1.1056 raeburn 12358: push(@{$hierarchy},$$count);
12359: $parent->{$$depth} = $$count;
1.1055 raeburn 12360: $result .=
12361: &recurse_extracted_archive("$currdir/$item",$docudom,
12362: $docuname,$depth,$count,
1.1056 raeburn 12363: $hierarchy,$dirorder,$children,
12364: $parent,$titles,$wantform);
1.1055 raeburn 12365: $$depth --;
1.1056 raeburn 12366: pop(@{$hierarchy});
1.1055 raeburn 12367: }
12368: }
12369: }
12370: }
12371: return $result;
12372: }
12373:
12374: sub archive_hierarchy {
12375: my ($depth,$count,$parent,$children) =@_;
12376: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12377: if (exists($parent->{$depth})) {
12378: $children->{$parent->{$depth}} .= $count.':';
12379: }
12380: }
12381: return;
12382: }
12383:
12384: sub archive_row {
12385: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12386: my ($name) = ($item =~ m{([^/]+)$});
12387: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12388: 'display' => 'Add as file',
1.1055 raeburn 12389: 'dependency' => 'Include as dependency',
12390: 'discard' => 'Discard',
12391: );
12392: if ($is_dir) {
1.1059 raeburn 12393: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12394: }
1.1056 raeburn 12395: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12396: my $offset = 0;
1.1055 raeburn 12397: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12398: $offset ++;
1.1065 raeburn 12399: if ($action ne 'display') {
12400: $offset ++;
12401: }
1.1055 raeburn 12402: $output .= '<td><span class="LC_nobreak">'.
12403: '<label><input type="radio" name="archive_'.$count.
12404: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12405: my $text = $choices{$action};
12406: if ($is_dir) {
12407: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12408: if ($action eq 'display') {
1.1059 raeburn 12409: $text = &mt('Add as folder');
1.1055 raeburn 12410: }
1.1056 raeburn 12411: } else {
12412: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12413:
12414: }
12415: $output .= ' /> '.$choices{$action}.'</label></span>';
12416: if ($action eq 'dependency') {
12417: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12418: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12419: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12420: '<option value=""></option>'."\n".
12421: '</select>'."\n".
12422: '</div>';
1.1059 raeburn 12423: } elsif ($action eq 'display') {
12424: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12425: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12426: '</div>';
1.1055 raeburn 12427: }
1.1056 raeburn 12428: $output .= '</td>';
1.1055 raeburn 12429: }
12430: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12431: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12432: for (my $i=0; $i<$depth; $i++) {
12433: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12434: }
12435: if ($is_dir) {
12436: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12437: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12438: } else {
12439: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12440: }
12441: $output .= ' '.$name.'</td>'."\n".
12442: &end_data_table_row();
12443: return $output;
12444: }
12445:
12446: sub archive_options_form {
1.1065 raeburn 12447: my ($form,$display,$count,$hiddenelem) = @_;
12448: my %lt = &Apache::lonlocal::texthash(
12449: perm => 'Permanently remove archive file?',
12450: hows => 'How should each extracted item be incorporated in the course?',
12451: cont => 'Content actions for all',
12452: addf => 'Add as folder/file',
12453: incd => 'Include as dependency for a displayed file',
12454: disc => 'Discard',
12455: no => 'No',
12456: yes => 'Yes',
12457: save => 'Save',
12458: );
12459: my $output = <<"END";
12460: <form name="$form" method="post" action="">
12461: <p><span class="LC_nobreak">$lt{'perm'}
12462: <label>
12463: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12464: </label>
12465:
12466: <label>
12467: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12468: </span>
12469: </p>
12470: <input type="hidden" name="phase" value="decompress_cleanup" />
12471: <br />$lt{'hows'}
12472: <div class="LC_columnSection">
12473: <fieldset>
12474: <legend>$lt{'cont'}</legend>
12475: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12476: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12477: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12478: </fieldset>
12479: </div>
12480: END
12481: return $output.
1.1055 raeburn 12482: &start_data_table()."\n".
1.1065 raeburn 12483: $display."\n".
1.1055 raeburn 12484: &end_data_table()."\n".
12485: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12486: $hiddenelem.
1.1065 raeburn 12487: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12488: '</form>';
12489: }
12490:
12491: sub archive_javascript {
1.1056 raeburn 12492: my ($startcount,$numitems,$titles,$children) = @_;
12493: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12494: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12495: my $scripttag = <<START;
12496: <script type="text/javascript">
12497: // <![CDATA[
12498:
12499: function checkAll(form,prefix) {
12500: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12501: for (var i=0; i < form.elements.length; i++) {
12502: var id = form.elements[i].id;
12503: if ((id != '') && (id != undefined)) {
12504: if (idstr.test(id)) {
12505: if (form.elements[i].type == 'radio') {
12506: form.elements[i].checked = true;
1.1056 raeburn 12507: var nostart = i-$startcount;
1.1059 raeburn 12508: var offset = nostart%7;
12509: var count = (nostart-offset)/7;
1.1056 raeburn 12510: dependencyCheck(form,count,offset);
1.1055 raeburn 12511: }
12512: }
12513: }
12514: }
12515: }
12516:
12517: function propagateCheck(form,count) {
12518: if (count > 0) {
1.1059 raeburn 12519: var startelement = $startcount + ((count-1) * 7);
12520: for (var j=1; j<6; j++) {
12521: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12522: var item = startelement + j;
12523: if (form.elements[item].type == 'radio') {
12524: if (form.elements[item].checked) {
12525: containerCheck(form,count,j);
12526: break;
12527: }
1.1055 raeburn 12528: }
12529: }
12530: }
12531: }
12532: }
12533:
12534: numitems = $numitems
1.1056 raeburn 12535: var titles = new Array(numitems);
12536: var parents = new Array(numitems);
1.1055 raeburn 12537: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12538: parents[i] = new Array;
1.1055 raeburn 12539: }
1.1059 raeburn 12540: var maintitle = '$maintitle';
1.1055 raeburn 12541:
12542: START
12543:
1.1056 raeburn 12544: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12545: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12546: for (my $i=0; $i<@contents; $i ++) {
12547: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12548: }
12549: }
12550:
1.1056 raeburn 12551: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12552: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12553: }
12554:
1.1055 raeburn 12555: $scripttag .= <<END;
12556:
12557: function containerCheck(form,count,offset) {
12558: if (count > 0) {
1.1056 raeburn 12559: dependencyCheck(form,count,offset);
1.1059 raeburn 12560: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12561: form.elements[item].checked = true;
12562: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12563: if (parents[count].length > 0) {
12564: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12565: containerCheck(form,parents[count][j],offset);
12566: }
12567: }
12568: }
12569: }
12570: }
12571:
12572: function dependencyCheck(form,count,offset) {
12573: if (count > 0) {
1.1059 raeburn 12574: var chosen = (offset+$startcount)+7*(count-1);
12575: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12576: var currtype = form.elements[depitem].type;
12577: if (form.elements[chosen].value == 'dependency') {
12578: document.getElementById('arc_depon_'+count).style.display='block';
12579: form.elements[depitem].options.length = 0;
12580: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12581: for (var i=1; i<=numitems; i++) {
12582: if (i == count) {
12583: continue;
12584: }
1.1059 raeburn 12585: var startelement = $startcount + (i-1) * 7;
12586: for (var j=1; j<6; j++) {
12587: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12588: var item = startelement + j;
12589: if (form.elements[item].type == 'radio') {
12590: if (form.elements[item].checked) {
12591: if (form.elements[item].value == 'display') {
12592: var n = form.elements[depitem].options.length;
12593: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12594: }
12595: }
12596: }
12597: }
12598: }
12599: }
12600: } else {
12601: document.getElementById('arc_depon_'+count).style.display='none';
12602: form.elements[depitem].options.length = 0;
12603: form.elements[depitem].options[0] = new Option('Select','',true,true);
12604: }
1.1059 raeburn 12605: titleCheck(form,count,offset);
1.1056 raeburn 12606: }
12607: }
12608:
12609: function propagateSelect(form,count,offset) {
12610: if (count > 0) {
1.1065 raeburn 12611: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12612: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12613: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12614: if (parents[count].length > 0) {
12615: for (var j=0; j<parents[count].length; j++) {
12616: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12617: }
12618: }
12619: }
12620: }
12621: }
1.1056 raeburn 12622:
12623: function containerSelect(form,count,offset,picked) {
12624: if (count > 0) {
1.1065 raeburn 12625: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12626: if (form.elements[item].type == 'radio') {
12627: if (form.elements[item].value == 'dependency') {
12628: if (form.elements[item+1].type == 'select-one') {
12629: for (var i=0; i<form.elements[item+1].options.length; i++) {
12630: if (form.elements[item+1].options[i].value == picked) {
12631: form.elements[item+1].selectedIndex = i;
12632: break;
12633: }
12634: }
12635: }
12636: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12637: if (parents[count].length > 0) {
12638: for (var j=0; j<parents[count].length; j++) {
12639: containerSelect(form,parents[count][j],offset,picked);
12640: }
12641: }
12642: }
12643: }
12644: }
12645: }
12646: }
12647:
1.1059 raeburn 12648: function titleCheck(form,count,offset) {
12649: if (count > 0) {
12650: var chosen = (offset+$startcount)+7*(count-1);
12651: var depitem = $startcount + ((count-1) * 7) + 2;
12652: var currtype = form.elements[depitem].type;
12653: if (form.elements[chosen].value == 'display') {
12654: document.getElementById('arc_title_'+count).style.display='block';
12655: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12656: document.getElementById('archive_title_'+count).value=maintitle;
12657: }
12658: } else {
12659: document.getElementById('arc_title_'+count).style.display='none';
12660: if (currtype == 'text') {
12661: document.getElementById('archive_title_'+count).value='';
12662: }
12663: }
12664: }
12665: return;
12666: }
12667:
1.1055 raeburn 12668: // ]]>
12669: </script>
12670: END
12671: return $scripttag;
12672: }
12673:
12674: sub process_extracted_files {
1.1067 raeburn 12675: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12676: my $numitems = $env{'form.archive_count'};
1.1075.2.127. .3(raebu 12677:17): return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12678: my @ids=&Apache::lonnet::current_machine_ids();
12679: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12680: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12681: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12682: if (grep(/^\Q$docuhome\E$/,@ids)) {
12683: $prefix = &LONCAPA::propath($docudom,$docuname);
12684: $pathtocheck = "$dir_root/$destination";
12685: $dir = $dir_root;
12686: $ishome = 1;
12687: } else {
12688: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12689: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.127. .3(raebu 12690:17): $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12691: }
12692: my $currdir = "$dir_root/$destination";
12693: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12694: if ($env{'form.folderpath'}) {
12695: my @items = split('&',$env{'form.folderpath'});
12696: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12697: if ($env{'form.folderpath'} =~ /\:1$/) {
12698: $containers{'0'}='page';
12699: } else {
12700: $containers{'0'}='sequence';
12701: }
1.1055 raeburn 12702: }
12703: my @archdirs = &get_env_multiple('form.archive_directory');
12704: if ($numitems) {
12705: for (my $i=1; $i<=$numitems; $i++) {
12706: my $path = $env{'form.archive_content_'.$i};
12707: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12708: my $item = $1;
12709: $toplevelitems{$item} = $i;
12710: if (grep(/^\Q$i\E$/,@archdirs)) {
12711: $is_dir{$item} = 1;
12712: }
12713: }
12714: }
12715: }
1.1067 raeburn 12716: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12717: if (keys(%toplevelitems) > 0) {
12718: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12719: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12720: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12721: }
1.1066 raeburn 12722: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12723: if ($numitems) {
12724: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12725: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12726: my $path = $env{'form.archive_content_'.$i};
12727: if ($path =~ /^\Q$pathtocheck\E/) {
12728: if ($env{'form.archive_'.$i} eq 'discard') {
12729: if ($prefix ne '' && $path ne '') {
12730: if (-e $prefix.$path) {
1.1066 raeburn 12731: if ((@archdirs > 0) &&
12732: (grep(/^\Q$i\E$/,@archdirs))) {
12733: $todeletedir{$prefix.$path} = 1;
12734: } else {
12735: $todelete{$prefix.$path} = 1;
12736: }
1.1055 raeburn 12737: }
12738: }
12739: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12740: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12741: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12742: $docstitle = $env{'form.archive_title_'.$i};
12743: if ($docstitle eq '') {
12744: $docstitle = $title;
12745: }
1.1055 raeburn 12746: $outer = 0;
1.1056 raeburn 12747: if (ref($dirorder{$i}) eq 'ARRAY') {
12748: if (@{$dirorder{$i}} > 0) {
12749: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12750: if ($env{'form.archive_'.$item} eq 'display') {
12751: $outer = $item;
12752: last;
12753: }
12754: }
12755: }
12756: }
12757: my ($errtext,$fatal) =
12758: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12759: '/'.$folders{$outer}.'.'.
12760: $containers{$outer});
12761: next if ($fatal);
12762: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12763: if ($context eq 'coursedocs') {
1.1056 raeburn 12764: $mapinner{$i} = time;
1.1055 raeburn 12765: $folders{$i} = 'default_'.$mapinner{$i};
12766: $containers{$i} = 'sequence';
12767: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12768: $folders{$i}.'.'.$containers{$i};
12769: my $newidx = &LONCAPA::map::getresidx();
12770: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12771: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12772: push(@LONCAPA::map::order,$newidx);
12773: my ($outtext,$errtext) =
12774: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12775: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12776: '.'.$containers{$outer},1,1);
1.1056 raeburn 12777: $newseqid{$i} = $newidx;
1.1067 raeburn 12778: unless ($errtext) {
1.1075.2.127. .3(raebu 12779:17): $result .= '<li>'.&mt('Folder: [_1] added to course',
12780:17): &HTML::Entities::encode($docstitle,'<>&"')).
12781:17): '</li>'."\n";
1.1067 raeburn 12782: }
1.1055 raeburn 12783: }
12784: } else {
12785: if ($context eq 'coursedocs') {
12786: my $newidx=&LONCAPA::map::getresidx();
12787: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12788: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12789: $title;
1.1075.2.127. .3(raebu 12790:17): if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12791:17): if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12792:17): mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12793: }
1.1075.2.127. .3(raebu 12794:17): if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12795:17): mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12796:17): }
12797:17): if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12798:17): if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12799:17): $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12800:17): unless ($ishome) {
12801:17): my $fetch = "$newdest{$i}/$title";
12802:17): $fetch =~ s/^\Q$prefix$dir\E//;
12803:17): $prompttofetch{$fetch} = 1;
12804:17): }
12805:17): }
12806:17): }
12807:17): $LONCAPA::map::resources[$newidx]=
12808:17): $docstitle.':'.$url.':false:normal:res';
12809:17): push(@LONCAPA::map::order, $newidx);
12810:17): my ($outtext,$errtext)=
12811:17): &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12812:17): $docuname.'/'.$folders{$outer}.
12813:17): '.'.$containers{$outer},1,1);
12814:17): unless ($errtext) {
12815:17): if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
.4(raebu 12816:17): $result .= '<li>'.&mt('File: [_1] added to course',
12817:17): &HTML::Entities::encode($docstitle,'<>&"')).
12818:17): '</li>'."\n";
.3(raebu 12819:17): }
1.1067 raeburn 12820: }
1.1075.2.127. .3(raebu 12821:17): } else {
12822:17): $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12823:17): &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12824: }
1.1055 raeburn 12825: }
12826: }
1.1075.2.11 raeburn 12827: }
12828: } else {
1.1075.2.127. .3(raebu 12829:17): $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12830:17): &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12831: }
12832: }
12833: for (my $i=1; $i<=$numitems; $i++) {
12834: next unless ($env{'form.archive_'.$i} eq 'dependency');
12835: my $path = $env{'form.archive_content_'.$i};
12836: if ($path =~ /^\Q$pathtocheck\E/) {
12837: my ($title) = ($path =~ m{/([^/]+)$});
12838: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12839: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12840: if (ref($dirorder{$i}) eq 'ARRAY') {
12841: my ($itemidx,$fullpath,$relpath);
12842: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12843: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12844: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12845: if ($dirorder{$i}->[$j] eq $container) {
12846: $itemidx = $j;
1.1056 raeburn 12847: }
12848: }
1.1075.2.11 raeburn 12849: }
12850: if ($itemidx eq '') {
12851: $itemidx = 0;
12852: }
12853: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12854: if ($mapinner{$referrer{$i}}) {
12855: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12856: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12857: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12858: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12859: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12860: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12861: if (!-e $fullpath) {
12862: mkdir($fullpath,0755);
1.1056 raeburn 12863: }
12864: }
1.1075.2.11 raeburn 12865: } else {
12866: last;
1.1056 raeburn 12867: }
1.1075.2.11 raeburn 12868: }
12869: }
12870: } elsif ($newdest{$referrer{$i}}) {
12871: $fullpath = $newdest{$referrer{$i}};
12872: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12873: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12874: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12875: last;
12876: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12877: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12878: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12879: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12880: if (!-e $fullpath) {
12881: mkdir($fullpath,0755);
1.1056 raeburn 12882: }
12883: }
1.1075.2.11 raeburn 12884: } else {
12885: last;
1.1056 raeburn 12886: }
1.1075.2.11 raeburn 12887: }
12888: }
12889: if ($fullpath ne '') {
12890: if (-e "$prefix$path") {
1.1075.2.127. .4(raebu 12891:17): unless (rename("$prefix$path","$fullpath/$title")) {
12892:17): $warning .= &mt('Failed to rename dependency').'<br />';
12893:17): }
1.1075.2.11 raeburn 12894: }
12895: if (-e "$fullpath/$title") {
12896: my $showpath;
12897: if ($relpath ne '') {
12898: $showpath = "$relpath/$title";
12899: } else {
12900: $showpath = "/$title";
1.1056 raeburn 12901: }
1.1075.2.127. .3(raebu 12902:17): $result .= '<li>'.&mt('[_1] included as a dependency',
12903:17): &HTML::Entities::encode($showpath,'<>&"')).
12904:17): '</li>'."\n";
1.1075.2.11 raeburn 12905: }
12906: unless ($ishome) {
12907: my $fetch = "$fullpath/$title";
12908: $fetch =~ s/^\Q$prefix$dir\E//;
12909: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12910: }
12911: }
12912: }
1.1075.2.11 raeburn 12913: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12914: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.127. .3(raebu 12915:17): &HTML::Entities::encode($path,'<>&"'),
12916:17): &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
12917:17): '<br />';
1.1055 raeburn 12918: }
12919: } else {
1.1075.2.127. .3(raebu 12920:17): $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12921:17): &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 12922: }
12923: }
12924: if (keys(%todelete)) {
12925: foreach my $key (keys(%todelete)) {
12926: unlink($key);
1.1066 raeburn 12927: }
12928: }
12929: if (keys(%todeletedir)) {
12930: foreach my $key (keys(%todeletedir)) {
12931: rmdir($key);
12932: }
12933: }
12934: foreach my $dir (sort(keys(%is_dir))) {
12935: if (($pathtocheck ne '') && ($dir ne '')) {
12936: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12937: }
12938: }
1.1067 raeburn 12939: if ($result ne '') {
12940: $output .= '<ul>'."\n".
12941: $result."\n".
12942: '</ul>';
12943: }
12944: unless ($ishome) {
12945: my $replicationfail;
12946: foreach my $item (keys(%prompttofetch)) {
12947: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12948: unless ($fetchresult eq 'ok') {
12949: $replicationfail .= '<li>'.$item.'</li>'."\n";
12950: }
12951: }
12952: if ($replicationfail) {
12953: $output .= '<p class="LC_error">'.
12954: &mt('Course home server failed to retrieve:').'<ul>'.
12955: $replicationfail.
12956: '</ul></p>';
12957: }
12958: }
1.1055 raeburn 12959: } else {
12960: $warning = &mt('No items found in archive.');
12961: }
12962: if ($error) {
12963: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12964: $error.'</p>'."\n";
12965: }
12966: if ($warning) {
12967: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12968: }
12969: return $output;
12970: }
12971:
1.1066 raeburn 12972: sub cleanup_empty_dirs {
12973: my ($path) = @_;
12974: if (($path ne '') && (-d $path)) {
12975: if (opendir(my $dirh,$path)) {
12976: my @dircontents = grep(!/^\./,readdir($dirh));
12977: my $numitems = 0;
12978: foreach my $item (@dircontents) {
12979: if (-d "$path/$item") {
1.1075.2.28 raeburn 12980: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12981: if (-e "$path/$item") {
12982: $numitems ++;
12983: }
12984: } else {
12985: $numitems ++;
12986: }
12987: }
12988: if ($numitems == 0) {
12989: rmdir($path);
12990: }
12991: closedir($dirh);
12992: }
12993: }
12994: return;
12995: }
12996:
1.41 ng 12997: =pod
1.45 matthew 12998:
1.1075.2.56 raeburn 12999: =item * &get_folder_hierarchy()
1.1068 raeburn 13000:
13001: Provides hierarchy of names of folders/sub-folders containing the current
13002: item,
13003:
13004: Inputs: 3
13005: - $navmap - navmaps object
13006:
13007: - $map - url for map (either the trigger itself, or map containing
13008: the resource, which is the trigger).
13009:
13010: - $showitem - 1 => show title for map itself; 0 => do not show.
13011:
13012: Outputs: 1 @pathitems - array of folder/subfolder names.
13013:
13014: =cut
13015:
13016: sub get_folder_hierarchy {
13017: my ($navmap,$map,$showitem) = @_;
13018: my @pathitems;
13019: if (ref($navmap)) {
13020: my $mapres = $navmap->getResourceByUrl($map);
13021: if (ref($mapres)) {
13022: my $pcslist = $mapres->map_hierarchy();
13023: if ($pcslist ne '') {
13024: my @pcs = split(/,/,$pcslist);
13025: foreach my $pc (@pcs) {
13026: if ($pc == 1) {
1.1075.2.38 raeburn 13027: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13028: } else {
13029: my $res = $navmap->getByMapPc($pc);
13030: if (ref($res)) {
13031: my $title = $res->compTitle();
13032: $title =~ s/\W+/_/g;
13033: if ($title ne '') {
13034: push(@pathitems,$title);
13035: }
13036: }
13037: }
13038: }
13039: }
1.1071 raeburn 13040: if ($showitem) {
13041: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13042: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13043: } else {
13044: my $maptitle = $mapres->compTitle();
13045: $maptitle =~ s/\W+/_/g;
13046: if ($maptitle ne '') {
13047: push(@pathitems,$maptitle);
13048: }
1.1068 raeburn 13049: }
13050: }
13051: }
13052: }
13053: return @pathitems;
13054: }
13055:
13056: =pod
13057:
1.1015 raeburn 13058: =item * &get_turnedin_filepath()
13059:
13060: Determines path in a user's portfolio file for storage of files uploaded
13061: to a specific essayresponse or dropbox item.
13062:
13063: Inputs: 3 required + 1 optional.
13064: $symb is symb for resource, $uname and $udom are for current user (required).
13065: $caller is optional (can be "submission", if routine is called when storing
13066: an upoaded file when "Submit Answer" button was pressed).
13067:
13068: Returns array containing $path and $multiresp.
13069: $path is path in portfolio. $multiresp is 1 if this resource contains more
13070: than one file upload item. Callers of routine should append partid as a
13071: subdirectory to $path in cases where $multiresp is 1.
13072:
13073: Called by: homework/essayresponse.pm and homework/structuretags.pm
13074:
13075: =cut
13076:
13077: sub get_turnedin_filepath {
13078: my ($symb,$uname,$udom,$caller) = @_;
13079: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13080: my $turnindir;
13081: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13082: $turnindir = $userhash{'turnindir'};
13083: my ($path,$multiresp);
13084: if ($turnindir eq '') {
13085: if ($caller eq 'submission') {
13086: $turnindir = &mt('turned in');
13087: $turnindir =~ s/\W+/_/g;
13088: my %newhash = (
13089: 'turnindir' => $turnindir,
13090: );
13091: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13092: }
13093: }
13094: if ($turnindir ne '') {
13095: $path = '/'.$turnindir.'/';
13096: my ($multipart,$turnin,@pathitems);
13097: my $navmap = Apache::lonnavmaps::navmap->new();
13098: if (defined($navmap)) {
13099: my $mapres = $navmap->getResourceByUrl($map);
13100: if (ref($mapres)) {
13101: my $pcslist = $mapres->map_hierarchy();
13102: if ($pcslist ne '') {
13103: foreach my $pc (split(/,/,$pcslist)) {
13104: my $res = $navmap->getByMapPc($pc);
13105: if (ref($res)) {
13106: my $title = $res->compTitle();
13107: $title =~ s/\W+/_/g;
13108: if ($title ne '') {
1.1075.2.48 raeburn 13109: if (($pc > 1) && (length($title) > 12)) {
13110: $title = substr($title,0,12);
13111: }
1.1015 raeburn 13112: push(@pathitems,$title);
13113: }
13114: }
13115: }
13116: }
13117: my $maptitle = $mapres->compTitle();
13118: $maptitle =~ s/\W+/_/g;
13119: if ($maptitle ne '') {
1.1075.2.48 raeburn 13120: if (length($maptitle) > 12) {
13121: $maptitle = substr($maptitle,0,12);
13122: }
1.1015 raeburn 13123: push(@pathitems,$maptitle);
13124: }
13125: unless ($env{'request.state'} eq 'construct') {
13126: my $res = $navmap->getBySymb($symb);
13127: if (ref($res)) {
13128: my $partlist = $res->parts();
13129: my $totaluploads = 0;
13130: if (ref($partlist) eq 'ARRAY') {
13131: foreach my $part (@{$partlist}) {
13132: my @types = $res->responseType($part);
13133: my @ids = $res->responseIds($part);
13134: for (my $i=0; $i < scalar(@ids); $i++) {
13135: if ($types[$i] eq 'essay') {
13136: my $partid = $part.'_'.$ids[$i];
13137: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13138: $totaluploads ++;
13139: }
13140: }
13141: }
13142: }
13143: if ($totaluploads > 1) {
13144: $multiresp = 1;
13145: }
13146: }
13147: }
13148: }
13149: } else {
13150: return;
13151: }
13152: } else {
13153: return;
13154: }
13155: my $restitle=&Apache::lonnet::gettitle($symb);
13156: $restitle =~ s/\W+/_/g;
13157: if ($restitle eq '') {
13158: $restitle = ($resurl =~ m{/[^/]+$});
13159: if ($restitle eq '') {
13160: $restitle = time;
13161: }
13162: }
1.1075.2.48 raeburn 13163: if (length($restitle) > 12) {
13164: $restitle = substr($restitle,0,12);
13165: }
1.1015 raeburn 13166: push(@pathitems,$restitle);
13167: $path .= join('/',@pathitems);
13168: }
13169: return ($path,$multiresp);
13170: }
13171:
13172: =pod
13173:
1.464 albertel 13174: =back
1.41 ng 13175:
1.112 bowersj2 13176: =head1 CSV Upload/Handling functions
1.38 albertel 13177:
1.41 ng 13178: =over 4
13179:
1.648 raeburn 13180: =item * &upfile_store($r)
1.41 ng 13181:
13182: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13183: needs $env{'form.upfile'}
1.41 ng 13184: returns $datatoken to be put into hidden field
13185:
13186: =cut
1.31 albertel 13187:
13188: sub upfile_store {
13189: my $r=shift;
1.258 albertel 13190: $env{'form.upfile'}=~s/\r/\n/gs;
13191: $env{'form.upfile'}=~s/\f/\n/gs;
13192: $env{'form.upfile'}=~s/\n+/\n/gs;
13193: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13194:
1.1075.2.127. .4(raebu 13195:17): my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13196:17): '_enroll_'.$env{'request.course.id'}.'_'.
13197:17): time.'_'.$$);
13198:17): return if ($datatoken eq '');
1.31 albertel 13199: {
1.158 raeburn 13200: my $datafile = $r->dir_config('lonDaemons').
13201: '/tmp/'.$datatoken.'.tmp';
1.1075.2.127. .5(raebu 13202:18): if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13203: print $fh $env{'form.upfile'};
1.158 raeburn 13204: close($fh);
13205: }
1.31 albertel 13206: }
13207: return $datatoken;
13208: }
13209:
1.56 matthew 13210: =pod
13211:
1.1075.2.127. .3(raebu 13212:17): =item * &load_tmp_file($r,$datatoken)
1.41 ng 13213:
13214: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.127. .3(raebu 13215:17): $datatoken is the name to assign to the temporary file.
1.258 albertel 13216: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13217:
13218: =cut
1.31 albertel 13219:
13220: sub load_tmp_file {
1.1075.2.127. .3(raebu 13221:17): my ($r,$datatoken) = @_;
13222:17): return if ($datatoken eq '');
1.31 albertel 13223: my @studentdata=();
13224: {
1.158 raeburn 13225: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.127. .3(raebu 13226:17): '/tmp/'.$datatoken.'.tmp';
.5(raebu 13227:18): if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13228: @studentdata=<$fh>;
13229: close($fh);
13230: }
1.31 albertel 13231: }
1.258 albertel 13232: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13233: }
13234:
1.1075.2.127. .3(raebu 13235:17): sub valid_datatoken {
13236:17): my ($datatoken) = @_;
.6(raebu 13237:19): if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
.3(raebu 13238:17): return $datatoken;
13239:17): }
13240:17): return;
13241:17): }
13242:17):
1.56 matthew 13243: =pod
13244:
1.648 raeburn 13245: =item * &upfile_record_sep()
1.41 ng 13246:
13247: Separate uploaded file into records
13248: returns array of records,
1.258 albertel 13249: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13250:
13251: =cut
1.31 albertel 13252:
13253: sub upfile_record_sep {
1.258 albertel 13254: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13255: } else {
1.248 albertel 13256: my @records;
1.258 albertel 13257: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13258: if ($line=~/^\s*$/) { next; }
13259: push(@records,$line);
13260: }
13261: return @records;
1.31 albertel 13262: }
13263: }
13264:
1.56 matthew 13265: =pod
13266:
1.648 raeburn 13267: =item * &record_sep($record)
1.41 ng 13268:
1.258 albertel 13269: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13270:
13271: =cut
13272:
1.263 www 13273: sub takeleft {
13274: my $index=shift;
13275: return substr('0000'.$index,-4,4);
13276: }
13277:
1.31 albertel 13278: sub record_sep {
13279: my $record=shift;
13280: my %components=();
1.258 albertel 13281: if ($env{'form.upfiletype'} eq 'xml') {
13282: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13283: my $i=0;
1.356 albertel 13284: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13285: $field=~s/^(\"|\')//;
13286: $field=~s/(\"|\')$//;
1.263 www 13287: $components{&takeleft($i)}=$field;
1.31 albertel 13288: $i++;
13289: }
1.258 albertel 13290: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13291: my $i=0;
1.356 albertel 13292: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13293: $field=~s/^(\"|\')//;
13294: $field=~s/(\"|\')$//;
1.263 www 13295: $components{&takeleft($i)}=$field;
1.31 albertel 13296: $i++;
13297: }
13298: } else {
1.561 www 13299: my $separator=',';
1.480 banghart 13300: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13301: $separator=';';
1.480 banghart 13302: }
1.31 albertel 13303: my $i=0;
1.561 www 13304: # the character we are looking for to indicate the end of a quote or a record
13305: my $looking_for=$separator;
13306: # do not add the characters to the fields
13307: my $ignore=0;
13308: # we just encountered a separator (or the beginning of the record)
13309: my $just_found_separator=1;
13310: # store the field we are working on here
13311: my $field='';
13312: # work our way through all characters in record
13313: foreach my $character ($record=~/(.)/g) {
13314: if ($character eq $looking_for) {
13315: if ($character ne $separator) {
13316: # Found the end of a quote, again looking for separator
13317: $looking_for=$separator;
13318: $ignore=1;
13319: } else {
13320: # Found a separator, store away what we got
13321: $components{&takeleft($i)}=$field;
13322: $i++;
13323: $just_found_separator=1;
13324: $ignore=0;
13325: $field='';
13326: }
13327: next;
13328: }
13329: # single or double quotation marks after a separator indicate beginning of a quote
13330: # we are now looking for the end of the quote and need to ignore separators
13331: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13332: $looking_for=$character;
13333: next;
13334: }
13335: # ignore would be true after we reached the end of a quote
13336: if ($ignore) { next; }
13337: if (($just_found_separator) && ($character=~/\s/)) { next; }
13338: $field.=$character;
13339: $just_found_separator=0;
1.31 albertel 13340: }
1.561 www 13341: # catch the very last entry, since we never encountered the separator
13342: $components{&takeleft($i)}=$field;
1.31 albertel 13343: }
13344: return %components;
13345: }
13346:
1.144 matthew 13347: ######################################################
13348: ######################################################
13349:
1.56 matthew 13350: =pod
13351:
1.648 raeburn 13352: =item * &upfile_select_html()
1.41 ng 13353:
1.144 matthew 13354: Return HTML code to select a file from the users machine and specify
13355: the file type.
1.41 ng 13356:
13357: =cut
13358:
1.144 matthew 13359: ######################################################
13360: ######################################################
1.31 albertel 13361: sub upfile_select_html {
1.144 matthew 13362: my %Types = (
13363: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13364: semisv => &mt('Semicolon separated values'),
1.144 matthew 13365: space => &mt('Space separated'),
13366: tab => &mt('Tabulator separated'),
13367: # xml => &mt('HTML/XML'),
13368: );
13369: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13370: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13371: foreach my $type (sort(keys(%Types))) {
13372: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13373: }
13374: $Str .= "</select>\n";
13375: return $Str;
1.31 albertel 13376: }
13377:
1.301 albertel 13378: sub get_samples {
13379: my ($records,$toget) = @_;
13380: my @samples=({});
13381: my $got=0;
13382: foreach my $rec (@$records) {
13383: my %temp = &record_sep($rec);
13384: if (! grep(/\S/, values(%temp))) { next; }
13385: if (%temp) {
13386: $samples[$got]=\%temp;
13387: $got++;
13388: if ($got == $toget) { last; }
13389: }
13390: }
13391: return \@samples;
13392: }
13393:
1.144 matthew 13394: ######################################################
13395: ######################################################
13396:
1.56 matthew 13397: =pod
13398:
1.648 raeburn 13399: =item * &csv_print_samples($r,$records)
1.41 ng 13400:
13401: Prints a table of sample values from each column uploaded $r is an
13402: Apache Request ref, $records is an arrayref from
13403: &Apache::loncommon::upfile_record_sep
13404:
13405: =cut
13406:
1.144 matthew 13407: ######################################################
13408: ######################################################
1.31 albertel 13409: sub csv_print_samples {
13410: my ($r,$records) = @_;
1.662 bisitz 13411: my $samples = &get_samples($records,5);
1.301 albertel 13412:
1.594 raeburn 13413: $r->print(&mt('Samples').'<br />'.&start_data_table().
13414: &start_data_table_header_row());
1.356 albertel 13415: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13416: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13417: $r->print(&end_data_table_header_row());
1.301 albertel 13418: foreach my $hash (@$samples) {
1.594 raeburn 13419: $r->print(&start_data_table_row());
1.356 albertel 13420: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13421: $r->print('<td>');
1.356 albertel 13422: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13423: $r->print('</td>');
13424: }
1.594 raeburn 13425: $r->print(&end_data_table_row());
1.31 albertel 13426: }
1.594 raeburn 13427: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13428: }
13429:
1.144 matthew 13430: ######################################################
13431: ######################################################
13432:
1.56 matthew 13433: =pod
13434:
1.648 raeburn 13435: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13436:
13437: Prints a table to create associations between values and table columns.
1.144 matthew 13438:
1.41 ng 13439: $r is an Apache Request ref,
13440: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13441: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13442:
13443: =cut
13444:
1.144 matthew 13445: ######################################################
13446: ######################################################
1.31 albertel 13447: sub csv_print_select_table {
13448: my ($r,$records,$d) = @_;
1.301 albertel 13449: my $i=0;
13450: my $samples = &get_samples($records,1);
1.144 matthew 13451: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13452: &start_data_table().&start_data_table_header_row().
1.144 matthew 13453: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13454: '<th>'.&mt('Column').'</th>'.
13455: &end_data_table_header_row()."\n");
1.356 albertel 13456: foreach my $array_ref (@$d) {
13457: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13458: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13459:
1.875 bisitz 13460: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13461: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13462: $r->print('<option value="none"></option>');
1.356 albertel 13463: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13464: $r->print('<option value="'.$sample.'"'.
13465: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13466: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13467: }
1.594 raeburn 13468: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13469: $i++;
13470: }
1.594 raeburn 13471: $r->print(&end_data_table());
1.31 albertel 13472: $i--;
13473: return $i;
13474: }
1.56 matthew 13475:
1.144 matthew 13476: ######################################################
13477: ######################################################
13478:
1.56 matthew 13479: =pod
1.31 albertel 13480:
1.648 raeburn 13481: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13482:
13483: Prints a table of sample values from the upload and can make associate samples to internal names.
13484:
13485: $r is an Apache Request ref,
13486: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13487: $d is an array of 2 element arrays (internal name, displayed name)
13488:
13489: =cut
13490:
1.144 matthew 13491: ######################################################
13492: ######################################################
1.31 albertel 13493: sub csv_samples_select_table {
13494: my ($r,$records,$d) = @_;
13495: my $i=0;
1.144 matthew 13496: #
1.662 bisitz 13497: my $max_samples = 5;
13498: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13499: $r->print(&start_data_table().
13500: &start_data_table_header_row().'<th>'.
13501: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13502: &end_data_table_header_row());
1.301 albertel 13503:
13504: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13505: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13506: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13507: foreach my $option (@$d) {
13508: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13509: $r->print('<option value="'.$value.'"'.
1.253 albertel 13510: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13511: $display.'</option>');
1.31 albertel 13512: }
13513: $r->print('</select></td><td>');
1.662 bisitz 13514: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13515: if (defined($samples->[$line]{$key})) {
13516: $r->print($samples->[$line]{$key}."<br />\n");
13517: }
13518: }
1.594 raeburn 13519: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13520: $i++;
13521: }
1.594 raeburn 13522: $r->print(&end_data_table());
1.31 albertel 13523: $i--;
13524: return($i);
1.115 matthew 13525: }
13526:
1.144 matthew 13527: ######################################################
13528: ######################################################
13529:
1.115 matthew 13530: =pod
13531:
1.648 raeburn 13532: =item * &clean_excel_name($name)
1.115 matthew 13533:
13534: Returns a replacement for $name which does not contain any illegal characters.
13535:
13536: =cut
13537:
1.144 matthew 13538: ######################################################
13539: ######################################################
1.115 matthew 13540: sub clean_excel_name {
13541: my ($name) = @_;
13542: $name =~ s/[:\*\?\/\\]//g;
13543: if (length($name) > 31) {
13544: $name = substr($name,0,31);
13545: }
13546: return $name;
1.25 albertel 13547: }
1.84 albertel 13548:
1.85 albertel 13549: =pod
13550:
1.648 raeburn 13551: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13552:
13553: Returns either 1 or undef
13554:
13555: 1 if the part is to be hidden, undef if it is to be shown
13556:
13557: Arguments are:
13558:
13559: $id the id of the part to be checked
13560: $symb, optional the symb of the resource to check
13561: $udom, optional the domain of the user to check for
13562: $uname, optional the username of the user to check for
13563:
13564: =cut
1.84 albertel 13565:
13566: sub check_if_partid_hidden {
13567: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13568: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13569: $symb,$udom,$uname);
1.141 albertel 13570: my $truth=1;
13571: #if the string starts with !, then the list is the list to show not hide
13572: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13573: my @hiddenlist=split(/,/,$hiddenparts);
13574: foreach my $checkid (@hiddenlist) {
1.141 albertel 13575: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13576: }
1.141 albertel 13577: return !$truth;
1.84 albertel 13578: }
1.127 matthew 13579:
1.138 matthew 13580:
13581: ############################################################
13582: ############################################################
13583:
13584: =pod
13585:
1.157 matthew 13586: =back
13587:
1.138 matthew 13588: =head1 cgi-bin script and graphing routines
13589:
1.157 matthew 13590: =over 4
13591:
1.648 raeburn 13592: =item * &get_cgi_id()
1.138 matthew 13593:
13594: Inputs: none
13595:
13596: Returns an id which can be used to pass environment variables
13597: to various cgi-bin scripts. These environment variables will
13598: be removed from the users environment after a given time by
13599: the routine &Apache::lonnet::transfer_profile_to_env.
13600:
13601: =cut
13602:
13603: ############################################################
13604: ############################################################
1.152 albertel 13605: my $uniq=0;
1.136 matthew 13606: sub get_cgi_id {
1.154 albertel 13607: $uniq=($uniq+1)%100000;
1.280 albertel 13608: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13609: }
13610:
1.127 matthew 13611: ############################################################
13612: ############################################################
13613:
13614: =pod
13615:
1.648 raeburn 13616: =item * &DrawBarGraph()
1.127 matthew 13617:
1.138 matthew 13618: Facilitates the plotting of data in a (stacked) bar graph.
13619: Puts plot definition data into the users environment in order for
13620: graph.png to plot it. Returns an <img> tag for the plot.
13621: The bars on the plot are labeled '1','2',...,'n'.
13622:
13623: Inputs:
13624:
13625: =over 4
13626:
13627: =item $Title: string, the title of the plot
13628:
13629: =item $xlabel: string, text describing the X-axis of the plot
13630:
13631: =item $ylabel: string, text describing the Y-axis of the plot
13632:
13633: =item $Max: scalar, the maximum Y value to use in the plot
13634: If $Max is < any data point, the graph will not be rendered.
13635:
1.140 matthew 13636: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13637: they are plotted. If undefined, default values will be used.
13638:
1.178 matthew 13639: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13640:
1.138 matthew 13641: =item @Values: An array of array references. Each array reference holds data
13642: to be plotted in a stacked bar chart.
13643:
1.239 matthew 13644: =item If the final element of @Values is a hash reference the key/value
13645: pairs will be added to the graph definition.
13646:
1.138 matthew 13647: =back
13648:
13649: Returns:
13650:
13651: An <img> tag which references graph.png and the appropriate identifying
13652: information for the plot.
13653:
1.127 matthew 13654: =cut
13655:
13656: ############################################################
13657: ############################################################
1.134 matthew 13658: sub DrawBarGraph {
1.178 matthew 13659: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13660: #
13661: if (! defined($colors)) {
13662: $colors = ['#33ff00',
13663: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13664: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13665: ];
13666: }
1.228 matthew 13667: my $extra_settings = {};
13668: if (ref($Values[-1]) eq 'HASH') {
13669: $extra_settings = pop(@Values);
13670: }
1.127 matthew 13671: #
1.136 matthew 13672: my $identifier = &get_cgi_id();
13673: my $id = 'cgi.'.$identifier;
1.129 matthew 13674: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13675: return '';
13676: }
1.225 matthew 13677: #
13678: my @Labels;
13679: if (defined($labels)) {
13680: @Labels = @$labels;
13681: } else {
13682: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13683: push(@Labels,$i+1);
1.225 matthew 13684: }
13685: }
13686: #
1.129 matthew 13687: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13688: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13689: my %ValuesHash;
13690: my $NumSets=1;
13691: foreach my $array (@Values) {
13692: next if (! ref($array));
1.136 matthew 13693: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13694: join(',',@$array);
1.129 matthew 13695: }
1.127 matthew 13696: #
1.136 matthew 13697: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13698: if ($NumBars < 3) {
13699: $width = 120+$NumBars*32;
1.220 matthew 13700: $xskip = 1;
1.225 matthew 13701: $bar_width = 30;
13702: } elsif ($NumBars < 5) {
13703: $width = 120+$NumBars*20;
13704: $xskip = 1;
13705: $bar_width = 20;
1.220 matthew 13706: } elsif ($NumBars < 10) {
1.136 matthew 13707: $width = 120+$NumBars*15;
13708: $xskip = 1;
13709: $bar_width = 15;
13710: } elsif ($NumBars <= 25) {
13711: $width = 120+$NumBars*11;
13712: $xskip = 5;
13713: $bar_width = 8;
13714: } elsif ($NumBars <= 50) {
13715: $width = 120+$NumBars*8;
13716: $xskip = 5;
13717: $bar_width = 4;
13718: } else {
13719: $width = 120+$NumBars*8;
13720: $xskip = 5;
13721: $bar_width = 4;
13722: }
13723: #
1.137 matthew 13724: $Max = 1 if ($Max < 1);
13725: if ( int($Max) < $Max ) {
13726: $Max++;
13727: $Max = int($Max);
13728: }
1.127 matthew 13729: $Title = '' if (! defined($Title));
13730: $xlabel = '' if (! defined($xlabel));
13731: $ylabel = '' if (! defined($ylabel));
1.369 www 13732: $ValuesHash{$id.'.title'} = &escape($Title);
13733: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13734: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13735: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13736: $ValuesHash{$id.'.NumBars'} = $NumBars;
13737: $ValuesHash{$id.'.NumSets'} = $NumSets;
13738: $ValuesHash{$id.'.PlotType'} = 'bar';
13739: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13740: $ValuesHash{$id.'.height'} = $height;
13741: $ValuesHash{$id.'.width'} = $width;
13742: $ValuesHash{$id.'.xskip'} = $xskip;
13743: $ValuesHash{$id.'.bar_width'} = $bar_width;
13744: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13745: #
1.228 matthew 13746: # Deal with other parameters
13747: while (my ($key,$value) = each(%$extra_settings)) {
13748: $ValuesHash{$id.'.'.$key} = $value;
13749: }
13750: #
1.646 raeburn 13751: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13752: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13753: }
13754:
13755: ############################################################
13756: ############################################################
13757:
13758: =pod
13759:
1.648 raeburn 13760: =item * &DrawXYGraph()
1.137 matthew 13761:
1.138 matthew 13762: Facilitates the plotting of data in an XY graph.
13763: Puts plot definition data into the users environment in order for
13764: graph.png to plot it. Returns an <img> tag for the plot.
13765:
13766: Inputs:
13767:
13768: =over 4
13769:
13770: =item $Title: string, the title of the plot
13771:
13772: =item $xlabel: string, text describing the X-axis of the plot
13773:
13774: =item $ylabel: string, text describing the Y-axis of the plot
13775:
13776: =item $Max: scalar, the maximum Y value to use in the plot
13777: If $Max is < any data point, the graph will not be rendered.
13778:
13779: =item $colors: Array ref containing the hex color codes for the data to be
13780: plotted in. If undefined, default values will be used.
13781:
13782: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13783:
13784: =item $Ydata: Array ref containing Array refs.
1.185 www 13785: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13786:
13787: =item %Values: hash indicating or overriding any default values which are
13788: passed to graph.png.
13789: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13790:
13791: =back
13792:
13793: Returns:
13794:
13795: An <img> tag which references graph.png and the appropriate identifying
13796: information for the plot.
13797:
1.137 matthew 13798: =cut
13799:
13800: ############################################################
13801: ############################################################
13802: sub DrawXYGraph {
13803: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13804: #
13805: # Create the identifier for the graph
13806: my $identifier = &get_cgi_id();
13807: my $id = 'cgi.'.$identifier;
13808: #
13809: $Title = '' if (! defined($Title));
13810: $xlabel = '' if (! defined($xlabel));
13811: $ylabel = '' if (! defined($ylabel));
13812: my %ValuesHash =
13813: (
1.369 www 13814: $id.'.title' => &escape($Title),
13815: $id.'.xlabel' => &escape($xlabel),
13816: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13817: $id.'.y_max_value'=> $Max,
13818: $id.'.labels' => join(',',@$Xlabels),
13819: $id.'.PlotType' => 'XY',
13820: );
13821: #
13822: if (defined($colors) && ref($colors) eq 'ARRAY') {
13823: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13824: }
13825: #
13826: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13827: return '';
13828: }
13829: my $NumSets=1;
1.138 matthew 13830: foreach my $array (@{$Ydata}){
1.137 matthew 13831: next if (! ref($array));
13832: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13833: }
1.138 matthew 13834: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13835: #
13836: # Deal with other parameters
13837: while (my ($key,$value) = each(%Values)) {
13838: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13839: }
13840: #
1.646 raeburn 13841: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13842: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13843: }
13844:
13845: ############################################################
13846: ############################################################
13847:
13848: =pod
13849:
1.648 raeburn 13850: =item * &DrawXYYGraph()
1.138 matthew 13851:
13852: Facilitates the plotting of data in an XY graph with two Y axes.
13853: Puts plot definition data into the users environment in order for
13854: graph.png to plot it. Returns an <img> tag for the plot.
13855:
13856: Inputs:
13857:
13858: =over 4
13859:
13860: =item $Title: string, the title of the plot
13861:
13862: =item $xlabel: string, text describing the X-axis of the plot
13863:
13864: =item $ylabel: string, text describing the Y-axis of the plot
13865:
13866: =item $colors: Array ref containing the hex color codes for the data to be
13867: plotted in. If undefined, default values will be used.
13868:
13869: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13870:
13871: =item $Ydata1: The first data set
13872:
13873: =item $Min1: The minimum value of the left Y-axis
13874:
13875: =item $Max1: The maximum value of the left Y-axis
13876:
13877: =item $Ydata2: The second data set
13878:
13879: =item $Min2: The minimum value of the right Y-axis
13880:
13881: =item $Max2: The maximum value of the left Y-axis
13882:
13883: =item %Values: hash indicating or overriding any default values which are
13884: passed to graph.png.
13885: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13886:
13887: =back
13888:
13889: Returns:
13890:
13891: An <img> tag which references graph.png and the appropriate identifying
13892: information for the plot.
1.136 matthew 13893:
13894: =cut
13895:
13896: ############################################################
13897: ############################################################
1.137 matthew 13898: sub DrawXYYGraph {
13899: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13900: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13901: #
13902: # Create the identifier for the graph
13903: my $identifier = &get_cgi_id();
13904: my $id = 'cgi.'.$identifier;
13905: #
13906: $Title = '' if (! defined($Title));
13907: $xlabel = '' if (! defined($xlabel));
13908: $ylabel = '' if (! defined($ylabel));
13909: my %ValuesHash =
13910: (
1.369 www 13911: $id.'.title' => &escape($Title),
13912: $id.'.xlabel' => &escape($xlabel),
13913: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13914: $id.'.labels' => join(',',@$Xlabels),
13915: $id.'.PlotType' => 'XY',
13916: $id.'.NumSets' => 2,
1.137 matthew 13917: $id.'.two_axes' => 1,
13918: $id.'.y1_max_value' => $Max1,
13919: $id.'.y1_min_value' => $Min1,
13920: $id.'.y2_max_value' => $Max2,
13921: $id.'.y2_min_value' => $Min2,
1.136 matthew 13922: );
13923: #
1.137 matthew 13924: if (defined($colors) && ref($colors) eq 'ARRAY') {
13925: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13926: }
13927: #
13928: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13929: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13930: return '';
13931: }
13932: my $NumSets=1;
1.137 matthew 13933: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13934: next if (! ref($array));
13935: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13936: }
13937: #
13938: # Deal with other parameters
13939: while (my ($key,$value) = each(%Values)) {
13940: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13941: }
13942: #
1.646 raeburn 13943: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13944: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13945: }
13946:
13947: ############################################################
13948: ############################################################
13949:
13950: =pod
13951:
1.157 matthew 13952: =back
13953:
1.139 matthew 13954: =head1 Statistics helper routines?
13955:
13956: Bad place for them but what the hell.
13957:
1.157 matthew 13958: =over 4
13959:
1.648 raeburn 13960: =item * &chartlink()
1.139 matthew 13961:
13962: Returns a link to the chart for a specific student.
13963:
13964: Inputs:
13965:
13966: =over 4
13967:
13968: =item $linktext: The text of the link
13969:
13970: =item $sname: The students username
13971:
13972: =item $sdomain: The students domain
13973:
13974: =back
13975:
1.157 matthew 13976: =back
13977:
1.139 matthew 13978: =cut
13979:
13980: ############################################################
13981: ############################################################
13982: sub chartlink {
13983: my ($linktext, $sname, $sdomain) = @_;
13984: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13985: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13986: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13987: '">'.$linktext.'</a>';
1.153 matthew 13988: }
13989:
13990: #######################################################
13991: #######################################################
13992:
13993: =pod
13994:
13995: =head1 Course Environment Routines
1.157 matthew 13996:
13997: =over 4
1.153 matthew 13998:
1.648 raeburn 13999: =item * &restore_course_settings()
1.153 matthew 14000:
1.648 raeburn 14001: =item * &store_course_settings()
1.153 matthew 14002:
14003: Restores/Store indicated form parameters from the course environment.
14004: Will not overwrite existing values of the form parameters.
14005:
14006: Inputs:
14007: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14008:
14009: a hash ref describing the data to be stored. For example:
14010:
14011: %Save_Parameters = ('Status' => 'scalar',
14012: 'chartoutputmode' => 'scalar',
14013: 'chartoutputdata' => 'scalar',
14014: 'Section' => 'array',
1.373 raeburn 14015: 'Group' => 'array',
1.153 matthew 14016: 'StudentData' => 'array',
14017: 'Maps' => 'array');
14018:
14019: Returns: both routines return nothing
14020:
1.631 raeburn 14021: =back
14022:
1.153 matthew 14023: =cut
14024:
14025: #######################################################
14026: #######################################################
14027: sub store_course_settings {
1.496 albertel 14028: return &store_settings($env{'request.course.id'},@_);
14029: }
14030:
14031: sub store_settings {
1.153 matthew 14032: # save to the environment
14033: # appenv the same items, just to be safe
1.300 albertel 14034: my $udom = $env{'user.domain'};
14035: my $uname = $env{'user.name'};
1.496 albertel 14036: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14037: my %SaveHash;
14038: my %AppHash;
14039: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14040: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14041: my $envname = 'environment.'.$basename;
1.258 albertel 14042: if (exists($env{'form.'.$setting})) {
1.153 matthew 14043: # Save this value away
14044: if ($type eq 'scalar' &&
1.258 albertel 14045: (! exists($env{$envname}) ||
14046: $env{$envname} ne $env{'form.'.$setting})) {
14047: $SaveHash{$basename} = $env{'form.'.$setting};
14048: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14049: } elsif ($type eq 'array') {
14050: my $stored_form;
1.258 albertel 14051: if (ref($env{'form.'.$setting})) {
1.153 matthew 14052: $stored_form = join(',',
14053: map {
1.369 www 14054: &escape($_);
1.258 albertel 14055: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14056: } else {
14057: $stored_form =
1.369 www 14058: &escape($env{'form.'.$setting});
1.153 matthew 14059: }
14060: # Determine if the array contents are the same.
1.258 albertel 14061: if ($stored_form ne $env{$envname}) {
1.153 matthew 14062: $SaveHash{$basename} = $stored_form;
14063: $AppHash{$envname} = $stored_form;
14064: }
14065: }
14066: }
14067: }
14068: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14069: $udom,$uname);
1.153 matthew 14070: if ($put_result !~ /^(ok|delayed)/) {
14071: &Apache::lonnet::logthis('unable to save form parameters, '.
14072: 'got error:'.$put_result);
14073: }
14074: # Make sure these settings stick around in this session, too
1.646 raeburn 14075: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14076: return;
14077: }
14078:
14079: sub restore_course_settings {
1.499 albertel 14080: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14081: }
14082:
14083: sub restore_settings {
14084: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14085: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14086: next if (exists($env{'form.'.$setting}));
1.496 albertel 14087: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14088: '.'.$setting;
1.258 albertel 14089: if (exists($env{$envname})) {
1.153 matthew 14090: if ($type eq 'scalar') {
1.258 albertel 14091: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14092: } elsif ($type eq 'array') {
1.258 albertel 14093: $env{'form.'.$setting} = [
1.153 matthew 14094: map {
1.369 www 14095: &unescape($_);
1.258 albertel 14096: } split(',',$env{$envname})
1.153 matthew 14097: ];
14098: }
14099: }
14100: }
1.127 matthew 14101: }
14102:
1.618 raeburn 14103: #######################################################
14104: #######################################################
14105:
14106: =pod
14107:
14108: =head1 Domain E-mail Routines
14109:
14110: =over 4
14111:
1.648 raeburn 14112: =item * &build_recipient_list()
1.618 raeburn 14113:
1.1075.2.44 raeburn 14114: Build recipient lists for following types of e-mail:
1.766 raeburn 14115: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14116: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14117: module change checking, student/employee ID conflict checks, as
14118: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14119: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14120:
14121: Inputs:
1.1075.2.44 raeburn 14122: defmail (scalar - email address of default recipient),
14123: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14124: requestsmail, updatesmail, or idconflictsmail).
14125:
1.619 raeburn 14126: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14127:
14128: origmail (scalar - email address of recipient from loncapa.conf,
14129: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14130:
1.1075.2.127. .2(raebu 14131:17): $requname username of requester (if mailing type is helpdeskmail)
14132:17):
14133:17): $requdom domain of requester (if mailing type is helpdeskmail)
14134:17):
14135:17): $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14136:17):
14137:17):
1.655 raeburn 14138: Returns: comma separated list of addresses to which to send e-mail.
14139:
14140: =back
1.618 raeburn 14141:
14142: =cut
14143:
14144: ############################################################
14145: ############################################################
14146: sub build_recipient_list {
1.1075.2.127. .2(raebu 14147:17): my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14148: my @recipients;
1.1075.2.122 raeburn 14149: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14150: my %domconfig =
1.1075.2.122 raeburn 14151: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14152: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14153: if (exists($domconfig{'contacts'}{$mailing})) {
14154: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14155: my @contacts = ('adminemail','supportemail');
14156: foreach my $item (@contacts) {
14157: if ($domconfig{'contacts'}{$mailing}{$item}) {
14158: my $addr = $domconfig{'contacts'}{$item};
14159: if (!grep(/^\Q$addr\E$/,@recipients)) {
14160: push(@recipients,$addr);
14161: }
1.619 raeburn 14162: }
1.1075.2.122 raeburn 14163: }
14164: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14165: if ($mailing eq 'helpdeskmail') {
14166: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14167: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14168: my @ok_bccs;
14169: foreach my $bcc (@bccs) {
14170: $bcc =~ s/^\s+//g;
14171: $bcc =~ s/\s+$//g;
14172: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14173: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14174: push(@ok_bccs,$bcc);
14175: }
14176: }
14177: }
14178: if (@ok_bccs > 0) {
14179: $allbcc = join(', ',@ok_bccs);
14180: }
14181: }
14182: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14183: }
14184: }
1.766 raeburn 14185: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14186: $lastresort = $origmail;
1.618 raeburn 14187: }
1.1075.2.127. .2(raebu 14188:17): if ($mailing eq 'helpdeskmail') {
14189:17): if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14190:17): (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14191:17): my ($inststatus,$inststatus_checked);
14192:17): if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14193:17): ($env{'user.domain'} ne 'public')) {
14194:17): $inststatus_checked = 1;
14195:17): $inststatus = $env{'environment.inststatus'};
14196:17): }
14197:17): unless ($inststatus_checked) {
14198:17): if (($requname ne '') && ($requdom ne '')) {
14199:17): if (($requname =~ /^$match_username$/) &&
14200:17): ($requdom =~ /^$match_domain$/) &&
14201:17): (&Apache::lonnet::domain($requdom))) {
14202:17): my $requhome = &Apache::lonnet::homeserver($requname,
14203:17): $requdom);
14204:17): unless ($requhome eq 'no_host') {
14205:17): my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14206:17): $inststatus = $userenv{'inststatus'};
14207:17): $inststatus_checked = 1;
14208:17): }
14209:17): }
14210:17): }
14211:17): }
14212:17): unless ($inststatus_checked) {
14213:17): if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14214:17): my %srch = (srchby => 'email',
14215:17): srchdomain => $defdom,
14216:17): srchterm => $reqemail,
14217:17): srchtype => 'exact');
14218:17): my %srch_results = &Apache::lonnet::usersearch(\%srch);
14219:17): foreach my $uname (keys(%srch_results)) {
14220:17): if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14221:17): $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14222:17): $inststatus_checked = 1;
14223:17): last;
14224:17): }
14225:17): }
14226:17): unless ($inststatus_checked) {
14227:17): my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14228:17): if ($dirsrchres eq 'ok') {
14229:17): foreach my $uname (keys(%srch_results)) {
14230:17): if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14231:17): $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14232:17): $inststatus_checked = 1;
14233:17): last;
14234:17): }
14235:17): }
14236:17): }
14237:17): }
14238:17): }
14239:17): }
14240:17): if ($inststatus ne '') {
14241:17): foreach my $status (split(/\:/,$inststatus)) {
14242:17): if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14243:17): my @contacts = ('adminemail','supportemail');
14244:17): foreach my $item (@contacts) {
14245:17): if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14246:17): my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14247:17): if (!grep(/^\Q$addr\E$/,@recipients)) {
14248:17): push(@recipients,$addr);
14249:17): }
14250:17): }
14251:17): }
14252:17): $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14253:17): if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14254:17): my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14255:17): my @ok_bccs;
14256:17): foreach my $bcc (@bccs) {
14257:17): $bcc =~ s/^\s+//g;
14258:17): $bcc =~ s/\s+$//g;
14259:17): if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14260:17): if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14261:17): push(@ok_bccs,$bcc);
14262:17): }
14263:17): }
14264:17): }
14265:17): if (@ok_bccs > 0) {
14266:17): $allbcc = join(', ',@ok_bccs);
14267:17): }
14268:17): }
14269:17): $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14270:17): last;
14271:17): }
14272:17): }
14273:17): }
14274:17): }
14275:17): }
1.619 raeburn 14276: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14277: $lastresort = $origmail;
14278: }
14279:
1.1075.2.127. .2(raebu 14280:17): if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14281: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14282: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14283: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14284: my %what = (
14285: perlvar => 1,
14286: );
14287: my $primary = &Apache::lonnet::domain($defdom,'primary');
14288: if ($primary) {
14289: my $gotaddr;
14290: my ($result,$returnhash) =
14291: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14292: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14293: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14294: $lastresort = $returnhash->{'lonSupportEMail'};
14295: $gotaddr = 1;
14296: }
14297: }
14298: unless ($gotaddr) {
14299: my $uintdom = &Apache::lonnet::internet_dom($primary);
14300: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14301: unless ($uintdom eq $intdom) {
14302: my %domconfig =
14303: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14304: if (ref($domconfig{'contacts'}) eq 'HASH') {
14305: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14306: my @contacts = ('adminemail','supportemail');
14307: foreach my $item (@contacts) {
14308: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14309: my $addr = $domconfig{'contacts'}{$item};
14310: if (!grep(/^\Q$addr\E$/,@recipients)) {
14311: push(@recipients,$addr);
14312: }
14313: }
14314: }
14315: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14316: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14317: }
14318: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14319: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14320: my @ok_bccs;
14321: foreach my $bcc (@bccs) {
14322: $bcc =~ s/^\s+//g;
14323: $bcc =~ s/\s+$//g;
14324: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14325: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14326: push(@ok_bccs,$bcc);
14327: }
14328: }
14329: }
14330: if (@ok_bccs > 0) {
14331: $allbcc = join(', ',@ok_bccs);
14332: }
14333: }
14334: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14335: }
14336: }
14337: }
14338: }
14339: }
14340: }
1.618 raeburn 14341: }
1.688 raeburn 14342: if (defined($defmail)) {
14343: if ($defmail ne '') {
14344: push(@recipients,$defmail);
14345: }
1.618 raeburn 14346: }
14347: if ($otheremails) {
1.619 raeburn 14348: my @others;
14349: if ($otheremails =~ /,/) {
14350: @others = split(/,/,$otheremails);
1.618 raeburn 14351: } else {
1.619 raeburn 14352: push(@others,$otheremails);
14353: }
14354: foreach my $addr (@others) {
14355: if (!grep(/^\Q$addr\E$/,@recipients)) {
14356: push(@recipients,$addr);
14357: }
1.618 raeburn 14358: }
14359: }
1.1075.2.127. .2(raebu 14360:17): if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14361: if ((!@recipients) && ($lastresort ne '')) {
14362: push(@recipients,$lastresort);
14363: }
14364: } elsif ($lastresort ne '') {
14365: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14366: push(@recipients,$lastresort);
14367: }
14368: }
14369: my $recipientlist = join(',',@recipients);
14370: if (wantarray) {
14371: return ($recipientlist,$allbcc,$addtext);
14372: } else {
14373: return $recipientlist;
14374: }
1.618 raeburn 14375: }
14376:
1.127 matthew 14377: ############################################################
14378: ############################################################
1.154 albertel 14379:
1.655 raeburn 14380: =pod
14381:
14382: =head1 Course Catalog Routines
14383:
14384: =over 4
14385:
14386: =item * &gather_categories()
14387:
14388: Converts category definitions - keys of categories hash stored in
14389: coursecategories in configuration.db on the primary library server in a
14390: domain - to an array. Also generates javascript and idx hash used to
14391: generate Domain Coordinator interface for editing Course Categories.
14392:
14393: Inputs:
1.663 raeburn 14394:
1.655 raeburn 14395: categories (reference to hash of category definitions).
1.663 raeburn 14396:
1.655 raeburn 14397: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14398: categories and subcategories).
1.663 raeburn 14399:
1.655 raeburn 14400: idx (reference to hash of counters used in Domain Coordinator interface for
14401: editing Course Categories).
1.663 raeburn 14402:
1.655 raeburn 14403: jsarray (reference to array of categories used to create Javascript arrays for
14404: Domain Coordinator interface for editing Course Categories).
14405:
14406: Returns: nothing
14407:
14408: Side effects: populates cats, idx and jsarray.
14409:
14410: =cut
14411:
14412: sub gather_categories {
14413: my ($categories,$cats,$idx,$jsarray) = @_;
14414: my %counters;
14415: my $num = 0;
14416: foreach my $item (keys(%{$categories})) {
14417: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14418: if ($container eq '' && $depth == 0) {
14419: $cats->[$depth][$categories->{$item}] = $cat;
14420: } else {
14421: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14422: }
14423: my ($escitem,$tail) = split(/:/,$item,2);
14424: if ($counters{$tail} eq '') {
14425: $counters{$tail} = $num;
14426: $num ++;
14427: }
14428: if (ref($idx) eq 'HASH') {
14429: $idx->{$item} = $counters{$tail};
14430: }
14431: if (ref($jsarray) eq 'ARRAY') {
14432: push(@{$jsarray->[$counters{$tail}]},$item);
14433: }
14434: }
14435: return;
14436: }
14437:
14438: =pod
14439:
14440: =item * &extract_categories()
14441:
14442: Used to generate breadcrumb trails for course categories.
14443:
14444: Inputs:
1.663 raeburn 14445:
1.655 raeburn 14446: categories (reference to hash of category definitions).
1.663 raeburn 14447:
1.655 raeburn 14448: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14449: categories and subcategories).
1.663 raeburn 14450:
1.655 raeburn 14451: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14452:
1.655 raeburn 14453: allitems (reference to hash - key is category key
14454: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14455:
1.655 raeburn 14456: idx (reference to hash of counters used in Domain Coordinator interface for
14457: editing Course Categories).
1.663 raeburn 14458:
1.655 raeburn 14459: jsarray (reference to array of categories used to create Javascript arrays for
14460: Domain Coordinator interface for editing Course Categories).
14461:
1.665 raeburn 14462: subcats (reference to hash of arrays containing all subcategories within each
14463: category, -recursive)
14464:
1.655 raeburn 14465: Returns: nothing
14466:
14467: Side effects: populates trails and allitems hash references.
14468:
14469: =cut
14470:
14471: sub extract_categories {
1.665 raeburn 14472: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14473: if (ref($categories) eq 'HASH') {
14474: &gather_categories($categories,$cats,$idx,$jsarray);
14475: if (ref($cats->[0]) eq 'ARRAY') {
14476: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14477: my $name = $cats->[0][$i];
14478: my $item = &escape($name).'::0';
14479: my $trailstr;
14480: if ($name eq 'instcode') {
14481: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14482: } elsif ($name eq 'communities') {
14483: $trailstr = &mt('Communities');
1.655 raeburn 14484: } else {
14485: $trailstr = $name;
14486: }
14487: if ($allitems->{$item} eq '') {
14488: push(@{$trails},$trailstr);
14489: $allitems->{$item} = scalar(@{$trails})-1;
14490: }
14491: my @parents = ($name);
14492: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14493: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14494: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14495: if (ref($subcats) eq 'HASH') {
14496: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14497: }
14498: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14499: }
14500: } else {
14501: if (ref($subcats) eq 'HASH') {
14502: $subcats->{$item} = [];
1.655 raeburn 14503: }
14504: }
14505: }
14506: }
14507: }
14508: return;
14509: }
14510:
14511: =pod
14512:
1.1075.2.56 raeburn 14513: =item * &recurse_categories()
1.655 raeburn 14514:
14515: Recursively used to generate breadcrumb trails for course categories.
14516:
14517: Inputs:
1.663 raeburn 14518:
1.655 raeburn 14519: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14520: categories and subcategories).
1.663 raeburn 14521:
1.655 raeburn 14522: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14523:
14524: category (current course category, for which breadcrumb trail is being generated).
14525:
14526: trails (reference to array of breadcrumb trails for each category).
14527:
1.655 raeburn 14528: allitems (reference to hash - key is category key
14529: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14530:
1.655 raeburn 14531: parents (array containing containers directories for current category,
14532: back to top level).
14533:
14534: Returns: nothing
14535:
14536: Side effects: populates trails and allitems hash references
14537:
14538: =cut
14539:
14540: sub recurse_categories {
1.665 raeburn 14541: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14542: my $shallower = $depth - 1;
14543: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14544: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14545: my $name = $cats->[$depth]{$category}[$k];
14546: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14547: my $trailstr = join(' -> ',(@{$parents},$category));
14548: if ($allitems->{$item} eq '') {
14549: push(@{$trails},$trailstr);
14550: $allitems->{$item} = scalar(@{$trails})-1;
14551: }
14552: my $deeper = $depth+1;
14553: push(@{$parents},$category);
1.665 raeburn 14554: if (ref($subcats) eq 'HASH') {
14555: my $subcat = &escape($name).':'.$category.':'.$depth;
14556: for (my $j=@{$parents}; $j>=0; $j--) {
14557: my $higher;
14558: if ($j > 0) {
14559: $higher = &escape($parents->[$j]).':'.
14560: &escape($parents->[$j-1]).':'.$j;
14561: } else {
14562: $higher = &escape($parents->[$j]).'::'.$j;
14563: }
14564: push(@{$subcats->{$higher}},$subcat);
14565: }
14566: }
14567: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14568: $subcats);
1.655 raeburn 14569: pop(@{$parents});
14570: }
14571: } else {
14572: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14573: my $trailstr = join(' -> ',(@{$parents},$category));
14574: if ($allitems->{$item} eq '') {
14575: push(@{$trails},$trailstr);
14576: $allitems->{$item} = scalar(@{$trails})-1;
14577: }
14578: }
14579: return;
14580: }
14581:
1.663 raeburn 14582: =pod
14583:
1.1075.2.56 raeburn 14584: =item * &assign_categories_table()
1.663 raeburn 14585:
14586: Create a datatable for display of hierarchical categories in a domain,
14587: with checkboxes to allow a course to be categorized.
14588:
14589: Inputs:
14590:
14591: cathash - reference to hash of categories defined for the domain (from
14592: configuration.db)
14593:
14594: currcat - scalar with an & separated list of categories assigned to a course.
14595:
1.919 raeburn 14596: type - scalar contains course type (Course or Community).
14597:
1.1075.2.117 raeburn 14598: disabled - scalar (optional) contains disabled="disabled" if input elements are
14599: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14600:
1.663 raeburn 14601: Returns: $output (markup to be displayed)
14602:
14603: =cut
14604:
14605: sub assign_categories_table {
1.1075.2.117 raeburn 14606: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14607: my $output;
14608: if (ref($cathash) eq 'HASH') {
14609: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14610: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14611: $maxdepth = scalar(@cats);
14612: if (@cats > 0) {
14613: my $itemcount = 0;
14614: if (ref($cats[0]) eq 'ARRAY') {
14615: my @currcategories;
14616: if ($currcat ne '') {
14617: @currcategories = split('&',$currcat);
14618: }
1.919 raeburn 14619: my $table;
1.663 raeburn 14620: for (my $i=0; $i<@{$cats[0]}; $i++) {
14621: my $parent = $cats[0][$i];
1.919 raeburn 14622: next if ($parent eq 'instcode');
14623: if ($type eq 'Community') {
14624: next unless ($parent eq 'communities');
14625: } else {
14626: next if ($parent eq 'communities');
14627: }
1.663 raeburn 14628: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14629: my $item = &escape($parent).'::0';
14630: my $checked = '';
14631: if (@currcategories > 0) {
14632: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14633: $checked = ' checked="checked"';
1.663 raeburn 14634: }
14635: }
1.919 raeburn 14636: my $parent_title = $parent;
14637: if ($parent eq 'communities') {
14638: $parent_title = &mt('Communities');
14639: }
14640: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14641: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14642: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14643: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14644: my $depth = 1;
14645: push(@path,$parent);
1.1075.2.117 raeburn 14646: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14647: pop(@path);
1.919 raeburn 14648: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14649: $itemcount ++;
14650: }
1.919 raeburn 14651: if ($itemcount) {
14652: $output = &Apache::loncommon::start_data_table().
14653: $table.
14654: &Apache::loncommon::end_data_table();
14655: }
1.663 raeburn 14656: }
14657: }
14658: }
14659: return $output;
14660: }
14661:
14662: =pod
14663:
1.1075.2.56 raeburn 14664: =item * &assign_category_rows()
1.663 raeburn 14665:
14666: Create a datatable row for display of nested categories in a domain,
14667: with checkboxes to allow a course to be categorized,called recursively.
14668:
14669: Inputs:
14670:
14671: itemcount - track row number for alternating colors
14672:
14673: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14674: categories and subcategories.
14675:
14676: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14677:
14678: parent - parent of current category item
14679:
14680: path - Array containing all categories back up through the hierarchy from the
14681: current category to the top level.
14682:
14683: currcategories - reference to array of current categories assigned to the course
14684:
1.1075.2.117 raeburn 14685: disabled - scalar (optional) contains disabled="disabled" if input elements are
14686: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14687:
1.663 raeburn 14688: Returns: $output (markup to be displayed).
14689:
14690: =cut
14691:
14692: sub assign_category_rows {
1.1075.2.117 raeburn 14693: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14694: my ($text,$name,$item,$chgstr);
14695: if (ref($cats) eq 'ARRAY') {
14696: my $maxdepth = scalar(@{$cats});
14697: if (ref($cats->[$depth]) eq 'HASH') {
14698: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14699: my $numchildren = @{$cats->[$depth]{$parent}};
14700: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14701: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14702: for (my $j=0; $j<$numchildren; $j++) {
14703: $name = $cats->[$depth]{$parent}[$j];
14704: $item = &escape($name).':'.&escape($parent).':'.$depth;
14705: my $deeper = $depth+1;
14706: my $checked = '';
14707: if (ref($currcategories) eq 'ARRAY') {
14708: if (@{$currcategories} > 0) {
14709: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14710: $checked = ' checked="checked"';
1.663 raeburn 14711: }
14712: }
14713: }
1.664 raeburn 14714: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14715: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14716: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14717: '<input type="hidden" name="catname" value="'.$name.'" />'.
14718: '</td><td>';
1.663 raeburn 14719: if (ref($path) eq 'ARRAY') {
14720: push(@{$path},$name);
1.1075.2.117 raeburn 14721: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14722: pop(@{$path});
14723: }
14724: $text .= '</td></tr>';
14725: }
14726: $text .= '</table></td>';
14727: }
14728: }
14729: }
14730: return $text;
14731: }
14732:
1.1075.2.69 raeburn 14733: =pod
14734:
14735: =back
14736:
14737: =cut
14738:
1.655 raeburn 14739: ############################################################
14740: ############################################################
14741:
14742:
1.443 albertel 14743: sub commit_customrole {
1.664 raeburn 14744: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14745: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14746: ($start?', '.&mt('starting').' '.localtime($start):'').
14747: ($end?', ending '.localtime($end):'').': <b>'.
14748: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14749: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14750: '</b><br />';
14751: return $output;
14752: }
14753:
14754: sub commit_standardrole {
1.1075.2.31 raeburn 14755: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14756: my ($output,$logmsg,$linefeed);
14757: if ($context eq 'auto') {
14758: $linefeed = "\n";
14759: } else {
14760: $linefeed = "<br />\n";
14761: }
1.443 albertel 14762: if ($three eq 'st') {
1.541 raeburn 14763: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14764: $one,$two,$sec,$context,$credits);
1.541 raeburn 14765: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14766: ($result eq 'unknown_course') || ($result eq 'refused')) {
14767: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14768: } else {
1.541 raeburn 14769: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14770: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14771: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14772: if ($context eq 'auto') {
14773: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14774: } else {
14775: $output .= '<b>'.$result.'</b>'.$linefeed.
14776: &mt('Add to classlist').': <b>ok</b>';
14777: }
14778: $output .= $linefeed;
1.443 albertel 14779: }
14780: } else {
14781: $output = &mt('Assigning').' '.$three.' in '.$url.
14782: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14783: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14784: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14785: if ($context eq 'auto') {
14786: $output .= $result.$linefeed;
14787: } else {
14788: $output .= '<b>'.$result.'</b>'.$linefeed;
14789: }
1.443 albertel 14790: }
14791: return $output;
14792: }
14793:
14794: sub commit_studentrole {
1.1075.2.31 raeburn 14795: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14796: $credits) = @_;
1.626 raeburn 14797: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14798: if ($context eq 'auto') {
14799: $linefeed = "\n";
14800: } else {
14801: $linefeed = '<br />'."\n";
14802: }
1.443 albertel 14803: if (defined($one) && defined($two)) {
14804: my $cid=$one.'_'.$two;
14805: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14806: my $secchange = 0;
14807: my $expire_role_result;
14808: my $modify_section_result;
1.628 raeburn 14809: if ($oldsec ne '-1') {
14810: if ($oldsec ne $sec) {
1.443 albertel 14811: $secchange = 1;
1.628 raeburn 14812: my $now = time;
1.443 albertel 14813: my $uurl='/'.$cid;
14814: $uurl=~s/\_/\//g;
14815: if ($oldsec) {
14816: $uurl.='/'.$oldsec;
14817: }
1.626 raeburn 14818: $oldsecurl = $uurl;
1.628 raeburn 14819: $expire_role_result =
1.652 raeburn 14820: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14821: if ($env{'request.course.sec'} ne '') {
14822: if ($expire_role_result eq 'refused') {
14823: my @roles = ('st');
14824: my @statuses = ('previous');
14825: my @roledoms = ($one);
14826: my $withsec = 1;
14827: my %roleshash =
14828: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14829: \@statuses,\@roles,\@roledoms,$withsec);
14830: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14831: my ($oldstart,$oldend) =
14832: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14833: if ($oldend > 0 && $oldend <= $now) {
14834: $expire_role_result = 'ok';
14835: }
14836: }
14837: }
14838: }
1.443 albertel 14839: $result = $expire_role_result;
14840: }
14841: }
14842: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14843: $modify_section_result =
14844: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14845: undef,undef,undef,$sec,
14846: $end,$start,'','',$cid,
14847: '',$context,$credits);
1.443 albertel 14848: if ($modify_section_result =~ /^ok/) {
14849: if ($secchange == 1) {
1.628 raeburn 14850: if ($sec eq '') {
14851: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14852: } else {
14853: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14854: }
1.443 albertel 14855: } elsif ($oldsec eq '-1') {
1.628 raeburn 14856: if ($sec eq '') {
14857: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14858: } else {
14859: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14860: }
1.443 albertel 14861: } else {
1.628 raeburn 14862: if ($sec eq '') {
14863: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14864: } else {
14865: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14866: }
1.443 albertel 14867: }
14868: } else {
1.628 raeburn 14869: if ($secchange) {
14870: $$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;
14871: } else {
14872: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14873: }
1.443 albertel 14874: }
14875: $result = $modify_section_result;
14876: } elsif ($secchange == 1) {
1.628 raeburn 14877: if ($oldsec eq '') {
1.1075.2.20 raeburn 14878: $$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 14879: } else {
14880: $$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;
14881: }
1.626 raeburn 14882: if ($expire_role_result eq 'refused') {
14883: my $newsecurl = '/'.$cid;
14884: $newsecurl =~ s/\_/\//g;
14885: if ($sec ne '') {
14886: $newsecurl.='/'.$sec;
14887: }
14888: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14889: if ($sec eq '') {
14890: $$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;
14891: } else {
14892: $$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;
14893: }
14894: }
14895: }
1.443 albertel 14896: }
14897: } else {
1.626 raeburn 14898: $$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 14899: $result = "error: incomplete course id\n";
14900: }
14901: return $result;
14902: }
14903:
1.1075.2.25 raeburn 14904: sub show_role_extent {
14905: my ($scope,$context,$role) = @_;
14906: $scope =~ s{^/}{};
14907: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14908: push(@courseroles,'co');
14909: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14910: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14911: $scope =~ s{/}{_};
14912: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14913: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14914: my ($audom,$auname) = split(/\//,$scope);
14915: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14916: &Apache::loncommon::plainname($auname,$audom).'</span>');
14917: } else {
14918: $scope =~ s{/$}{};
14919: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14920: &Apache::lonnet::domain($scope,'description').'</span>');
14921: }
14922: }
14923:
1.443 albertel 14924: ############################################################
14925: ############################################################
14926:
1.566 albertel 14927: sub check_clone {
1.578 raeburn 14928: my ($args,$linefeed) = @_;
1.566 albertel 14929: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14930: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14931: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14932: my $clonemsg;
14933: my $can_clone = 0;
1.944 raeburn 14934: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14935: if ($lctype ne 'community') {
14936: $lctype = 'course';
14937: }
1.566 albertel 14938: if ($clonehome eq 'no_host') {
1.944 raeburn 14939: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14940: $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'});
14941: } else {
14942: $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'});
14943: }
1.566 albertel 14944: } else {
14945: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14946: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14947: if ($clonedesc{'type'} ne 'Community') {
14948: $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'});
14949: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14950: }
14951: }
1.1075.2.119 raeburn 14952: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 14953: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14954: $can_clone = 1;
14955: } else {
1.1075.2.95 raeburn 14956: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14957: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14958: if ($clonehash{'cloners'} eq '') {
14959: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14960: if ($domdefs{'canclone'}) {
14961: unless ($domdefs{'canclone'} eq 'none') {
14962: if ($domdefs{'canclone'} eq 'domain') {
14963: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14964: $can_clone = 1;
14965: }
14966: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14967: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14968: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14969: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14970: $can_clone = 1;
14971: }
14972: }
14973: }
1.908 raeburn 14974: }
1.1075.2.95 raeburn 14975: } else {
14976: my @cloners = split(/,/,$clonehash{'cloners'});
14977: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14978: $can_clone = 1;
1.1075.2.95 raeburn 14979: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14980: $can_clone = 1;
1.1075.2.96 raeburn 14981: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14982: $can_clone = 1;
1.1075.2.95 raeburn 14983: }
14984: unless ($can_clone) {
1.1075.2.96 raeburn 14985: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14986: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14987: my (%gotdomdefaults,%gotcodedefaults);
14988: foreach my $cloner (@cloners) {
14989: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14990: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14991: my (%codedefaults,@code_order);
14992: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14993: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14994: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14995: }
14996: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14997: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14998: }
14999: } else {
15000: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15001: \%codedefaults,
15002: \@code_order);
15003: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15004: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15005: }
15006: if (@code_order > 0) {
15007: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15008: $cloner,$clonehash{'internal.coursecode'},
15009: $args->{'crscode'})) {
15010: $can_clone = 1;
15011: last;
15012: }
15013: }
15014: }
15015: }
15016: }
1.1075.2.96 raeburn 15017: }
15018: }
15019: unless ($can_clone) {
15020: my $ccrole = 'cc';
15021: if ($args->{'crstype'} eq 'Community') {
15022: $ccrole = 'co';
15023: }
15024: my %roleshash =
15025: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15026: $args->{'ccdomain'},
15027: 'userroles',['active'],[$ccrole],
15028: [$args->{'clonedomain'}]);
15029: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15030: $can_clone = 1;
15031: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15032: $args->{'ccuname'},$args->{'ccdomain'})) {
15033: $can_clone = 1;
1.1075.2.95 raeburn 15034: }
15035: }
15036: unless ($can_clone) {
15037: if ($args->{'crstype'} eq 'Community') {
15038: $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'});
15039: } else {
15040: $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'});
1.578 raeburn 15041: }
1.566 albertel 15042: }
1.578 raeburn 15043: }
1.566 albertel 15044: }
15045: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15046: }
15047:
1.444 albertel 15048: sub construct_course {
1.1075.2.119 raeburn 15049: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15050: $cnum,$category,$coderef) = @_;
1.444 albertel 15051: my $outcome;
1.541 raeburn 15052: my $linefeed = '<br />'."\n";
15053: if ($context eq 'auto') {
15054: $linefeed = "\n";
15055: }
1.566 albertel 15056:
15057: #
15058: # Are we cloning?
15059: #
15060: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15061: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15062: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15063: if ($context ne 'auto') {
1.578 raeburn 15064: if ($clonemsg ne '') {
15065: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15066: }
1.566 albertel 15067: }
15068: $outcome .= $clonemsg.$linefeed;
15069:
15070: if (!$can_clone) {
15071: return (0,$outcome);
15072: }
15073: }
15074:
1.444 albertel 15075: #
15076: # Open course
15077: #
15078: my $crstype = lc($args->{'crstype'});
15079: my %cenv=();
15080: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15081: $args->{'cdescr'},
15082: $args->{'curl'},
15083: $args->{'course_home'},
15084: $args->{'nonstandard'},
15085: $args->{'crscode'},
15086: $args->{'ccuname'}.':'.
15087: $args->{'ccdomain'},
1.882 raeburn 15088: $args->{'crstype'},
1.885 raeburn 15089: $cnum,$context,$category);
1.444 albertel 15090:
15091: # Note: The testing routines depend on this being output; see
15092: # Utils::Course. This needs to at least be output as a comment
15093: # if anyone ever decides to not show this, and Utils::Course::new
15094: # will need to be suitably modified.
1.541 raeburn 15095: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15096: if ($$courseid =~ /^error:/) {
15097: return (0,$outcome);
15098: }
15099:
1.444 albertel 15100: #
15101: # Check if created correctly
15102: #
1.479 albertel 15103: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15104: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15105: if ($crsuhome eq 'no_host') {
15106: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15107: return (0,$outcome);
15108: }
1.541 raeburn 15109: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15110:
1.444 albertel 15111: #
1.566 albertel 15112: # Do the cloning
15113: #
15114: if ($can_clone && $cloneid) {
15115: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15116: if ($context ne 'auto') {
15117: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15118: }
15119: $outcome .= $clonemsg.$linefeed;
15120: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15121: # Copy all files
1.637 www 15122: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15123: # Restore URL
1.566 albertel 15124: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15125: # Restore title
1.566 albertel 15126: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15127: # Restore creation date, creator and creation context.
15128: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15129: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15130: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15131: # Mark as cloned
1.566 albertel 15132: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15133: # Need to clone grading mode
15134: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15135: $cenv{'grading'}=$newenv{'grading'};
15136: # Do not clone these environment entries
15137: &Apache::lonnet::del('environment',
15138: ['default_enrollment_start_date',
15139: 'default_enrollment_end_date',
15140: 'question.email',
15141: 'policy.email',
15142: 'comment.email',
15143: 'pch.users.denied',
1.725 raeburn 15144: 'plc.users.denied',
15145: 'hidefromcat',
1.1075.2.36 raeburn 15146: 'checkforpriv',
1.1075.2.59 raeburn 15147: 'categories',
15148: 'internal.uniquecode'],
1.638 www 15149: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15150: if ($args->{'textbook'}) {
15151: $cenv{'internal.textbook'} = $args->{'textbook'};
15152: }
1.444 albertel 15153: }
1.566 albertel 15154:
1.444 albertel 15155: #
15156: # Set environment (will override cloned, if existing)
15157: #
15158: my @sections = ();
15159: my @xlists = ();
15160: if ($args->{'crstype'}) {
15161: $cenv{'type'}=$args->{'crstype'};
15162: }
15163: if ($args->{'crsid'}) {
15164: $cenv{'courseid'}=$args->{'crsid'};
15165: }
15166: if ($args->{'crscode'}) {
15167: $cenv{'internal.coursecode'}=$args->{'crscode'};
15168: }
15169: if ($args->{'crsquota'} ne '') {
15170: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15171: } else {
15172: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15173: }
15174: if ($args->{'ccuname'}) {
15175: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15176: ':'.$args->{'ccdomain'};
15177: } else {
15178: $cenv{'internal.courseowner'} = $args->{'curruser'};
15179: }
1.1075.2.31 raeburn 15180: if ($args->{'defaultcredits'}) {
15181: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15182: }
1.444 albertel 15183: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15184: if ($args->{'crssections'}) {
15185: $cenv{'internal.sectionnums'} = '';
15186: if ($args->{'crssections'} =~ m/,/) {
15187: @sections = split/,/,$args->{'crssections'};
15188: } else {
15189: $sections[0] = $args->{'crssections'};
15190: }
15191: if (@sections > 0) {
15192: foreach my $item (@sections) {
15193: my ($sec,$gp) = split/:/,$item;
15194: my $class = $args->{'crscode'}.$sec;
15195: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15196: $cenv{'internal.sectionnums'} .= $item.',';
15197: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15198: push(@badclasses,$class);
1.444 albertel 15199: }
15200: }
15201: $cenv{'internal.sectionnums'} =~ s/,$//;
15202: }
15203: }
15204: # do not hide course coordinator from staff listing,
15205: # even if privileged
15206: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15207: # add course coordinator's domain to domains to check for privileged users
15208: # if different to course domain
15209: if ($$crsudom ne $args->{'ccdomain'}) {
15210: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15211: }
1.444 albertel 15212: # add crosslistings
15213: if ($args->{'crsxlist'}) {
15214: $cenv{'internal.crosslistings'}='';
15215: if ($args->{'crsxlist'} =~ m/,/) {
15216: @xlists = split/,/,$args->{'crsxlist'};
15217: } else {
15218: $xlists[0] = $args->{'crsxlist'};
15219: }
15220: if (@xlists > 0) {
15221: foreach my $item (@xlists) {
15222: my ($xl,$gp) = split/:/,$item;
15223: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15224: $cenv{'internal.crosslistings'} .= $item.',';
15225: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15226: push(@badclasses,$xl);
1.444 albertel 15227: }
15228: }
15229: $cenv{'internal.crosslistings'} =~ s/,$//;
15230: }
15231: }
15232: if ($args->{'autoadds'}) {
15233: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15234: }
15235: if ($args->{'autodrops'}) {
15236: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15237: }
15238: # check for notification of enrollment changes
15239: my @notified = ();
15240: if ($args->{'notify_owner'}) {
15241: if ($args->{'ccuname'} ne '') {
15242: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15243: }
15244: }
15245: if ($args->{'notify_dc'}) {
15246: if ($uname ne '') {
1.630 raeburn 15247: push(@notified,$uname.':'.$udom);
1.444 albertel 15248: }
15249: }
15250: if (@notified > 0) {
15251: my $notifylist;
15252: if (@notified > 1) {
15253: $notifylist = join(',',@notified);
15254: } else {
15255: $notifylist = $notified[0];
15256: }
15257: $cenv{'internal.notifylist'} = $notifylist;
15258: }
15259: if (@badclasses > 0) {
15260: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15261: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15262: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15263: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15264: );
1.1075.2.119 raeburn 15265: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15266: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 15267: if ($context eq 'auto') {
15268: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15269: } else {
1.566 albertel 15270: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15271: }
15272: foreach my $item (@badclasses) {
1.541 raeburn 15273: if ($context eq 'auto') {
1.1075.2.119 raeburn 15274: $outcome .= " - $item\n";
1.541 raeburn 15275: } else {
1.1075.2.119 raeburn 15276: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15277: }
1.1075.2.119 raeburn 15278: }
15279: if ($context eq 'auto') {
15280: $outcome .= $linefeed;
15281: } else {
15282: $outcome .= "</ul><br /><br /></div>\n";
15283: }
1.444 albertel 15284: }
15285: if ($args->{'no_end_date'}) {
15286: $args->{'endaccess'} = 0;
15287: }
15288: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15289: $cenv{'internal.autoend'}=$args->{'enrollend'};
15290: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15291: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15292: if ($args->{'showphotos'}) {
15293: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15294: }
15295: $cenv{'internal.authtype'} = $args->{'authtype'};
15296: $cenv{'internal.autharg'} = $args->{'autharg'};
15297: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15298: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15299: 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');
15300: if ($context eq 'auto') {
15301: $outcome .= $krb_msg;
15302: } else {
1.566 albertel 15303: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15304: }
15305: $outcome .= $linefeed;
1.444 albertel 15306: }
15307: }
15308: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15309: if ($args->{'setpolicy'}) {
15310: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15311: }
15312: if ($args->{'setcontent'}) {
15313: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15314: }
1.1075.2.110 raeburn 15315: if ($args->{'setcomment'}) {
15316: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15317: }
1.444 albertel 15318: }
15319: if ($args->{'reshome'}) {
15320: $cenv{'reshome'}=$args->{'reshome'}.'/';
15321: $cenv{'reshome'}=~s/\/+$/\//;
15322: }
15323: #
15324: # course has keyed access
15325: #
15326: if ($args->{'setkeys'}) {
15327: $cenv{'keyaccess'}='yes';
15328: }
15329: # if specified, key authority is not course, but user
15330: # only active if keyaccess is yes
15331: if ($args->{'keyauth'}) {
1.487 albertel 15332: my ($user,$domain) = split(':',$args->{'keyauth'});
15333: $user = &LONCAPA::clean_username($user);
15334: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15335: if ($user ne '' && $domain ne '') {
1.487 albertel 15336: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15337: }
15338: }
15339:
1.1075.2.59 raeburn 15340: #
15341: # generate and store uniquecode (available to course requester), if course should have one.
15342: #
15343: if ($args->{'uniquecode'}) {
15344: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15345: if ($code) {
15346: $cenv{'internal.uniquecode'} = $code;
15347: my %crsinfo =
15348: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15349: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15350: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15351: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15352: }
15353: if (ref($coderef)) {
15354: $$coderef = $code;
15355: }
15356: }
15357: }
15358:
1.444 albertel 15359: if ($args->{'disresdis'}) {
15360: $cenv{'pch.roles.denied'}='st';
15361: }
15362: if ($args->{'disablechat'}) {
15363: $cenv{'plc.roles.denied'}='st';
15364: }
15365:
15366: # Record we've not yet viewed the Course Initialization Helper for this
15367: # course
15368: $cenv{'course.helper.not.run'} = 1;
15369: #
15370: # Use new Randomseed
15371: #
15372: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15373: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15374: #
15375: # The encryption code and receipt prefix for this course
15376: #
15377: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15378: $cenv{'internal.encpref'}=100+int(9*rand(99));
15379: #
15380: # By default, use standard grading
15381: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15382:
1.541 raeburn 15383: $outcome .= $linefeed.&mt('Setting environment').': '.
15384: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15385: #
15386: # Open all assignments
15387: #
15388: if ($args->{'openall'}) {
15389: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15390: my %storecontent = ($storeunder => time,
15391: $storeunder.'.type' => 'date_start');
15392:
15393: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15394: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15395: }
15396: #
15397: # Set first page
15398: #
15399: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15400: || ($cloneid)) {
1.445 albertel 15401: use LONCAPA::map;
1.444 albertel 15402: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15403:
15404: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15405: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15406:
1.444 albertel 15407: $outcome .= ($fatal?$errtext:'read ok').' - ';
15408: my $title; my $url;
15409: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15410: $title=&mt('Syllabus');
1.444 albertel 15411: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15412: } else {
1.963 raeburn 15413: $title=&mt('Table of Contents');
1.444 albertel 15414: $url='/adm/navmaps';
15415: }
1.445 albertel 15416:
15417: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15418: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15419:
15420: if ($errtext) { $fatal=2; }
1.541 raeburn 15421: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15422: }
1.566 albertel 15423:
15424: return (1,$outcome);
1.444 albertel 15425: }
15426:
1.1075.2.59 raeburn 15427: sub make_unique_code {
15428: my ($cdom,$cnum) = @_;
15429: # get lock on uniquecodes db
15430: my $lockhash = {
15431: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15432: ':'.$env{'user.domain'},
15433: };
15434: my $tries = 0;
15435: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15436: my ($code,$error);
15437:
15438: while (($gotlock ne 'ok') && ($tries<3)) {
15439: $tries ++;
15440: sleep 1;
15441: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15442: }
15443: if ($gotlock eq 'ok') {
15444: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15445: my $gotcode;
15446: my $attempts = 0;
15447: while ((!$gotcode) && ($attempts < 100)) {
15448: $code = &generate_code();
15449: if (!exists($currcodes{$code})) {
15450: $gotcode = 1;
15451: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15452: $error = 'nostore';
15453: }
15454: }
15455: $attempts ++;
15456: }
15457: my @del_lock = ($cnum."\0".'uniquecodes');
15458: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15459: } else {
15460: $error = 'nolock';
15461: }
15462: return ($code,$error);
15463: }
15464:
15465: sub generate_code {
15466: my $code;
15467: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15468: for (my $i=0; $i<6; $i++) {
15469: my $lettnum = int (rand 2);
15470: my $item = '';
15471: if ($lettnum) {
15472: $item = $letts[int( rand(18) )];
15473: } else {
15474: $item = 1+int( rand(8) );
15475: }
15476: $code .= $item;
15477: }
15478: return $code;
15479: }
15480:
1.444 albertel 15481: ############################################################
15482: ############################################################
15483:
1.953 droeschl 15484: #SD
15485: # only Community and Course, or anything else?
1.378 raeburn 15486: sub course_type {
15487: my ($cid) = @_;
15488: if (!defined($cid)) {
15489: $cid = $env{'request.course.id'};
15490: }
1.404 albertel 15491: if (defined($env{'course.'.$cid.'.type'})) {
15492: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15493: } else {
15494: return 'Course';
1.377 raeburn 15495: }
15496: }
1.156 albertel 15497:
1.406 raeburn 15498: sub group_term {
15499: my $crstype = &course_type();
15500: my %names = (
15501: 'Course' => 'group',
1.865 raeburn 15502: 'Community' => 'group',
1.406 raeburn 15503: );
15504: return $names{$crstype};
15505: }
15506:
1.902 raeburn 15507: sub course_types {
1.1075.2.59 raeburn 15508: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15509: my %typename = (
15510: official => 'Official course',
15511: unofficial => 'Unofficial course',
15512: community => 'Community',
1.1075.2.59 raeburn 15513: textbook => 'Textbook course',
1.902 raeburn 15514: );
15515: return (\@types,\%typename);
15516: }
15517:
1.156 albertel 15518: sub icon {
15519: my ($file)=@_;
1.505 albertel 15520: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15521: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15522: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15523: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15524: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15525: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15526: $curfext.".gif") {
15527: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15528: $curfext.".gif";
15529: }
15530: }
1.249 albertel 15531: return &lonhttpdurl($iconname);
1.154 albertel 15532: }
1.84 albertel 15533:
1.575 albertel 15534: sub lonhttpdurl {
1.692 www 15535: #
15536: # Had been used for "small fry" static images on separate port 8080.
15537: # Modify here if lightweight http functionality desired again.
15538: # Currently eliminated due to increasing firewall issues.
15539: #
1.575 albertel 15540: my ($url)=@_;
1.692 www 15541: return $url;
1.215 albertel 15542: }
15543:
1.213 albertel 15544: sub connection_aborted {
15545: my ($r)=@_;
15546: $r->print(" ");$r->rflush();
15547: my $c = $r->connection;
15548: return $c->aborted();
15549: }
15550:
1.221 foxr 15551: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15552: # strings as 'strings'.
15553: sub escape_single {
1.221 foxr 15554: my ($input) = @_;
1.223 albertel 15555: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15556: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15557: return $input;
15558: }
1.223 albertel 15559:
1.222 foxr 15560: # Same as escape_single, but escape's "'s This
15561: # can be used for "strings"
15562: sub escape_double {
15563: my ($input) = @_;
15564: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15565: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15566: return $input;
15567: }
1.223 albertel 15568:
1.222 foxr 15569: # Escapes the last element of a full URL.
15570: sub escape_url {
15571: my ($url) = @_;
1.238 raeburn 15572: my @urlslices = split(/\//, $url,-1);
1.369 www 15573: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15574: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15575: }
1.462 albertel 15576:
1.820 raeburn 15577: sub compare_arrays {
15578: my ($arrayref1,$arrayref2) = @_;
15579: my (@difference,%count);
15580: @difference = ();
15581: %count = ();
15582: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15583: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15584: foreach my $element (keys(%count)) {
15585: if ($count{$element} == 1) {
15586: push(@difference,$element);
15587: }
15588: }
15589: }
15590: return @difference;
15591: }
15592:
1.817 bisitz 15593: # -------------------------------------------------------- Initialize user login
1.462 albertel 15594: sub init_user_environment {
1.463 albertel 15595: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15596: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15597:
15598: my $public=($username eq 'public' && $domain eq 'public');
15599:
15600: # See if old ID present, if so, remove
15601:
1.1062 raeburn 15602: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15603: my $now=time;
15604:
15605: if ($public) {
15606: my $max_public=100;
15607: my $oldest;
15608: my $oldest_time=0;
15609: for(my $next=1;$next<=$max_public;$next++) {
15610: if (-e $lonids."/publicuser_$next.id") {
15611: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15612: if ($mtime<$oldest_time || !$oldest_time) {
15613: $oldest_time=$mtime;
15614: $oldest=$next;
15615: }
15616: } else {
15617: $cookie="publicuser_$next";
15618: last;
15619: }
15620: }
15621: if (!$cookie) { $cookie="publicuser_$oldest"; }
15622: } else {
1.463 albertel 15623: # if this isn't a robot, kill any existing non-robot sessions
15624: if (!$args->{'robot'}) {
15625: opendir(DIR,$lonids);
15626: while ($filename=readdir(DIR)) {
15627: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15628: unlink($lonids.'/'.$filename);
15629: }
1.462 albertel 15630: }
1.463 albertel 15631: closedir(DIR);
1.1075.2.84 raeburn 15632: # If there is a undeleted lockfile for the user's paste buffer remove it.
15633: my $namespace = 'nohist_courseeditor';
15634: my $lockingkey = 'paste'."\0".'locked_num';
15635: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15636: $domain,$username);
15637: if (exists($lockhash{$lockingkey})) {
15638: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15639: unless ($delresult eq 'ok') {
15640: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15641: }
15642: }
1.462 albertel 15643: }
15644: # Give them a new cookie
1.463 albertel 15645: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15646: : $now.$$.int(rand(10000)));
1.463 albertel 15647: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15648:
15649: # Initialize roles
15650:
1.1062 raeburn 15651: ($userroles,$firstaccenv,$timerintenv) =
15652: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15653: }
15654: # ------------------------------------ Check browser type and MathML capability
15655:
1.1075.2.77 raeburn 15656: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15657: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15658:
15659: # ------------------------------------------------------------- Get environment
15660:
15661: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15662: my ($tmp) = keys(%userenv);
1.1075.2.127. .4(raebu 15663:17): if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 15664: undef(%userenv);
15665: }
15666: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15667: $form->{'interface'}=$userenv{'interface'};
15668: }
15669: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15670:
15671: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15672: foreach my $option ('interface','localpath','localres') {
15673: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15674: }
15675: # --------------------------------------------------------- Write first profile
15676:
15677: {
15678: my %initial_env =
15679: ("user.name" => $username,
15680: "user.domain" => $domain,
15681: "user.home" => $authhost,
15682: "browser.type" => $clientbrowser,
15683: "browser.version" => $clientversion,
15684: "browser.mathml" => $clientmathml,
15685: "browser.unicode" => $clientunicode,
15686: "browser.os" => $clientos,
1.1075.2.42 raeburn 15687: "browser.mobile" => $clientmobile,
15688: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15689: "browser.osversion" => $clientosversion,
1.462 albertel 15690: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15691: "request.course.fn" => '',
15692: "request.course.uri" => '',
15693: "request.course.sec" => '',
15694: "request.role" => 'cm',
15695: "request.role.adv" => $env{'user.adv'},
15696: "request.host" => $ENV{'REMOTE_ADDR'},);
15697:
15698: if ($form->{'localpath'}) {
15699: $initial_env{"browser.localpath"} = $form->{'localpath'};
15700: $initial_env{"browser.localres"} = $form->{'localres'};
15701: }
15702:
15703: if ($form->{'interface'}) {
15704: $form->{'interface'}=~s/\W//gs;
15705: $initial_env{"browser.interface"} = $form->{'interface'};
15706: $env{'browser.interface'}=$form->{'interface'};
15707: }
15708:
1.1075.2.54 raeburn 15709: if ($form->{'iptoken'}) {
15710: my $lonhost = $r->dir_config('lonHostID');
15711: $initial_env{"user.noloadbalance"} = $lonhost;
15712: $env{'user.noloadbalance'} = $lonhost;
15713: }
15714:
1.1075.2.120 raeburn 15715: if ($form->{'noloadbalance'}) {
15716: my @hosts = &Apache::lonnet::current_machine_ids();
15717: my $hosthere = $form->{'noloadbalance'};
15718: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15719: $initial_env{"user.noloadbalance"} = $hosthere;
15720: $env{'user.noloadbalance'} = $hosthere;
15721: }
15722: }
15723:
1.1016 raeburn 15724: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15725: my %is_adv = ( is_adv => $env{'user.adv'} );
15726: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15727:
1.1075.2.125 raeburn 15728: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15729: $userenv{'availabletools.'.$tool} =
15730: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15731: undef,\%userenv,\%domdef,\%is_adv);
15732: }
1.724 raeburn 15733:
1.1075.2.125 raeburn 15734: foreach my $crstype ('official','unofficial','community','textbook') {
15735: $userenv{'canrequest.'.$crstype} =
15736: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15737: 'reload','requestcourses',
15738: \%userenv,\%domdef,\%is_adv);
15739: }
1.765 raeburn 15740:
1.1075.2.125 raeburn 15741: $userenv{'canrequest.author'} =
15742: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15743: 'reload','requestauthor',
15744: \%userenv,\%domdef,\%is_adv);
15745: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15746: $domain,$username);
15747: my $reqstatus = $reqauthor{'author_status'};
15748: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15749: if (ref($reqauthor{'author'}) eq 'HASH') {
15750: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15751: $reqauthor{'author'}{'timestamp'};
15752: }
1.1075.2.14 raeburn 15753: }
15754: }
15755:
1.462 albertel 15756: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15757:
1.462 albertel 15758: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15759: &GDBM_WRCREAT(),0640)) {
15760: &_add_to_env(\%disk_env,\%initial_env);
15761: &_add_to_env(\%disk_env,\%userenv,'environment.');
15762: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15763: if (ref($firstaccenv) eq 'HASH') {
15764: &_add_to_env(\%disk_env,$firstaccenv);
15765: }
15766: if (ref($timerintenv) eq 'HASH') {
15767: &_add_to_env(\%disk_env,$timerintenv);
15768: }
1.463 albertel 15769: if (ref($args->{'extra_env'})) {
15770: &_add_to_env(\%disk_env,$args->{'extra_env'});
15771: }
1.462 albertel 15772: untie(%disk_env);
15773: } else {
1.705 tempelho 15774: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15775: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15776: return 'error: '.$!;
15777: }
15778: }
15779: $env{'request.role'}='cm';
15780: $env{'request.role.adv'}=$env{'user.adv'};
15781: $env{'browser.type'}=$clientbrowser;
15782:
15783: return $cookie;
15784:
15785: }
15786:
15787: sub _add_to_env {
15788: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15789: if (ref($env_data) eq 'HASH') {
15790: while (my ($key,$value) = each(%$env_data)) {
15791: $idf->{$prefix.$key} = $value;
15792: $env{$prefix.$key} = $value;
15793: }
1.462 albertel 15794: }
15795: }
15796:
1.685 tempelho 15797: # --- Get the symbolic name of a problem and the url
15798: sub get_symb {
15799: my ($request,$silent) = @_;
1.726 raeburn 15800: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15801: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15802: if ($symb eq '') {
15803: if (!$silent) {
1.1071 raeburn 15804: if (ref($request)) {
15805: $request->print("Unable to handle ambiguous references:$url:.");
15806: }
1.685 tempelho 15807: return ();
15808: }
15809: }
15810: &Apache::lonenc::check_decrypt(\$symb);
15811: return ($symb);
15812: }
15813:
15814: # --------------------------------------------------------------Get annotation
15815:
15816: sub get_annotation {
15817: my ($symb,$enc) = @_;
15818:
15819: my $key = $symb;
15820: if (!$enc) {
15821: $key =
15822: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15823: }
15824: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15825: return $annotation{$key};
15826: }
15827:
15828: sub clean_symb {
1.731 raeburn 15829: my ($symb,$delete_enc) = @_;
1.685 tempelho 15830:
15831: &Apache::lonenc::check_decrypt(\$symb);
15832: my $enc = $env{'request.enc'};
1.731 raeburn 15833: if ($delete_enc) {
1.730 raeburn 15834: delete($env{'request.enc'});
15835: }
1.685 tempelho 15836:
15837: return ($symb,$enc);
15838: }
1.462 albertel 15839:
1.1075.2.69 raeburn 15840: ############################################################
15841: ############################################################
15842:
15843: =pod
15844:
15845: =head1 Routines for building display used to search for courses
15846:
15847:
15848: =over 4
15849:
15850: =item * &build_filters()
15851:
15852: Create markup for a table used to set filters to use when selecting
15853: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15854: and quotacheck.pl
15855:
15856:
15857: Inputs:
15858:
15859: filterlist - anonymous array of fields to include as potential filters
15860:
15861: crstype - course type
15862:
15863: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15864: to pop-open a course selector (will contain "extra element").
15865:
15866: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15867:
15868: filter - anonymous hash of criteria and their values
15869:
15870: action - form action
15871:
15872: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15873:
15874: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15875:
15876: cloneruname - username of owner of new course who wants to clone
15877:
15878: clonerudom - domain of owner of new course who wants to clone
15879:
15880: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15881:
15882: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15883:
15884: codedom - domain
15885:
15886: formname - value of form element named "form".
15887:
15888: fixeddom - domain, if fixed.
15889:
15890: prevphase - value to assign to form element named "phase" when going back to the previous screen
15891:
15892: cnameelement - name of form element in form on opener page which will receive title of selected course
15893:
15894: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15895:
15896: cdomelement - name of form element in form on opener page which will receive domain of selected course
15897:
15898: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15899:
15900: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15901:
15902: clonewarning - warning message about missing information for intended course owner when DC creates a course
15903:
15904:
15905: Returns: $output - HTML for display of search criteria, and hidden form elements.
15906:
15907:
15908: Side Effects: None
15909:
15910: =cut
15911:
15912: # ---------------------------------------------- search for courses based on last activity etc.
15913:
15914: sub build_filters {
15915: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15916: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15917: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15918: $cnameelement,$cnumelement,$cdomelement,$setroles,
15919: $clonetext,$clonewarning) = @_;
15920: my ($list,$jscript);
15921: my $onchange = 'javascript:updateFilters(this)';
15922: my ($domainselectform,$sincefilterform,$createdfilterform,
15923: $ownerdomselectform,$persondomselectform,$instcodeform,
15924: $typeselectform,$instcodetitle);
15925: if ($formname eq '') {
15926: $formname = $caller;
15927: }
15928: foreach my $item (@{$filterlist}) {
15929: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15930: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15931: if ($item eq 'domainfilter') {
15932: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15933: } elsif ($item eq 'coursefilter') {
15934: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15935: } elsif ($item eq 'ownerfilter') {
15936: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15937: } elsif ($item eq 'ownerdomfilter') {
15938: $filter->{'ownerdomfilter'} =
15939: &LONCAPA::clean_domain($filter->{$item});
15940: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15941: 'ownerdomfilter',1);
15942: } elsif ($item eq 'personfilter') {
15943: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15944: } elsif ($item eq 'persondomfilter') {
15945: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15946: 'persondomfilter',1);
15947: } else {
15948: $filter->{$item} =~ s/\W//g;
15949: }
15950: if (!$filter->{$item}) {
15951: $filter->{$item} = '';
15952: }
15953: }
15954: if ($item eq 'domainfilter') {
15955: my $allow_blank = 1;
15956: if ($formname eq 'portform') {
15957: $allow_blank=0;
15958: } elsif ($formname eq 'studentform') {
15959: $allow_blank=0;
15960: }
15961: if ($fixeddom) {
15962: $domainselectform = '<input type="hidden" name="domainfilter"'.
15963: ' value="'.$codedom.'" />'.
15964: &Apache::lonnet::domain($codedom,'description');
15965: } else {
15966: $domainselectform = &select_dom_form($filter->{$item},
15967: 'domainfilter',
15968: $allow_blank,'',$onchange);
15969: }
15970: } else {
15971: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15972: }
15973: }
15974:
15975: # last course activity filter and selection
15976: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15977:
15978: # course created filter and selection
15979: if (exists($filter->{'createdfilter'})) {
15980: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15981: }
15982:
15983: my %lt = &Apache::lonlocal::texthash(
15984: 'cac' => "$crstype Activity",
15985: 'ccr' => "$crstype Created",
15986: 'cde' => "$crstype Title",
15987: 'cdo' => "$crstype Domain",
15988: 'ins' => 'Institutional Code',
15989: 'inc' => 'Institutional Categorization',
15990: 'cow' => "$crstype Owner/Co-owner",
15991: 'cop' => "$crstype Personnel Includes",
15992: 'cog' => 'Type',
15993: );
15994:
15995: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15996: my $typeval = 'Course';
15997: if ($crstype eq 'Community') {
15998: $typeval = 'Community';
15999: }
16000: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16001: } else {
16002: $typeselectform = '<select name="type" size="1"';
16003: if ($onchange) {
16004: $typeselectform .= ' onchange="'.$onchange.'"';
16005: }
16006: $typeselectform .= '>'."\n";
16007: foreach my $posstype ('Course','Community') {
16008: $typeselectform.='<option value="'.$posstype.'"'.
16009: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16010: }
16011: $typeselectform.="</select>";
16012: }
16013:
16014: my ($cloneableonlyform,$cloneabletitle);
16015: if (exists($filter->{'cloneableonly'})) {
16016: my $cloneableon = '';
16017: my $cloneableoff = ' checked="checked"';
16018: if ($filter->{'cloneableonly'}) {
16019: $cloneableon = $cloneableoff;
16020: $cloneableoff = '';
16021: }
16022: $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
16023: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16024: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16025: } else {
16026: $cloneabletitle = &mt('Cloneable by you');
16027: }
16028: }
16029: my $officialjs;
16030: if ($crstype eq 'Course') {
16031: if (exists($filter->{'instcodefilter'})) {
16032: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16033: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16034: if ($codedom) {
16035: $officialjs = 1;
16036: ($instcodeform,$jscript,$$numtitlesref) =
16037: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16038: $officialjs,$codetitlesref);
16039: if ($jscript) {
16040: $jscript = '<script type="text/javascript">'."\n".
16041: '// <![CDATA['."\n".
16042: $jscript."\n".
16043: '// ]]>'."\n".
16044: '</script>'."\n";
16045: }
16046: }
16047: if ($instcodeform eq '') {
16048: $instcodeform =
16049: '<input type="text" name="instcodefilter" size="10" value="'.
16050: $list->{'instcodefilter'}.'" />';
16051: $instcodetitle = $lt{'ins'};
16052: } else {
16053: $instcodetitle = $lt{'inc'};
16054: }
16055: if ($fixeddom) {
16056: $instcodetitle .= '<br />('.$codedom.')';
16057: }
16058: }
16059: }
16060: my $output = qq|
16061: <form method="post" name="filterpicker" action="$action">
16062: <input type="hidden" name="form" value="$formname" />
16063: |;
16064: if ($formname eq 'modifycourse') {
16065: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16066: '<input type="hidden" name="prevphase" value="'.
16067: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16068: } elsif ($formname eq 'quotacheck') {
16069: $output .= qq|
16070: <input type="hidden" name="sortby" value="" />
16071: <input type="hidden" name="sortorder" value="" />
16072: |;
16073: } else {
1.1075.2.69 raeburn 16074: my $name_input;
16075: if ($cnameelement ne '') {
16076: $name_input = '<input type="hidden" name="cnameelement" value="'.
16077: $cnameelement.'" />';
16078: }
16079: $output .= qq|
16080: <input type="hidden" name="cnumelement" value="$cnumelement" />
16081: <input type="hidden" name="cdomelement" value="$cdomelement" />
16082: $name_input
16083: $roleelement
16084: $multelement
16085: $typeelement
16086: |;
16087: if ($formname eq 'portform') {
16088: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16089: }
16090: }
16091: if ($fixeddom) {
16092: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16093: }
16094: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16095: if ($sincefilterform) {
16096: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16097: .$sincefilterform
16098: .&Apache::lonhtmlcommon::row_closure();
16099: }
16100: if ($createdfilterform) {
16101: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16102: .$createdfilterform
16103: .&Apache::lonhtmlcommon::row_closure();
16104: }
16105: if ($domainselectform) {
16106: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16107: .$domainselectform
16108: .&Apache::lonhtmlcommon::row_closure();
16109: }
16110: if ($typeselectform) {
16111: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16112: $output .= $typeselectform;
16113: } else {
16114: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16115: .$typeselectform
16116: .&Apache::lonhtmlcommon::row_closure();
16117: }
16118: }
16119: if ($instcodeform) {
16120: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16121: .$instcodeform
16122: .&Apache::lonhtmlcommon::row_closure();
16123: }
16124: if (exists($filter->{'ownerfilter'})) {
16125: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16126: '<table><tr><td>'.&mt('Username').'<br />'.
16127: '<input type="text" name="ownerfilter" size="20" value="'.
16128: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16129: $ownerdomselectform.'</td></tr></table>'.
16130: &Apache::lonhtmlcommon::row_closure();
16131: }
16132: if (exists($filter->{'personfilter'})) {
16133: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16134: '<table><tr><td>'.&mt('Username').'<br />'.
16135: '<input type="text" name="personfilter" size="20" value="'.
16136: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16137: $persondomselectform.'</td></tr></table>'.
16138: &Apache::lonhtmlcommon::row_closure();
16139: }
16140: if (exists($filter->{'coursefilter'})) {
16141: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16142: .'<input type="text" name="coursefilter" size="25" value="'
16143: .$list->{'coursefilter'}.'" />'
16144: .&Apache::lonhtmlcommon::row_closure();
16145: }
16146: if ($cloneableonlyform) {
16147: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16148: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16149: }
16150: if (exists($filter->{'descriptfilter'})) {
16151: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16152: .'<input type="text" name="descriptfilter" size="40" value="'
16153: .$list->{'descriptfilter'}.'" />'
16154: .&Apache::lonhtmlcommon::row_closure(1);
16155: }
16156: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16157: '<input type="hidden" name="updater" value="" />'."\n".
16158: '<input type="submit" name="gosearch" value="'.
16159: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16160: return $jscript.$clonewarning.$output;
16161: }
16162:
16163: =pod
16164:
16165: =item * &timebased_select_form()
16166:
16167: Create markup for a dropdown list used to select a time-based
16168: filter e.g., Course Activity, Course Created, when searching for courses
16169: or communities
16170:
16171: Inputs:
16172:
16173: item - name of form element (sincefilter or createdfilter)
16174:
16175: filter - anonymous hash of criteria and their values
16176:
16177: Returns: HTML for a select box contained a blank, then six time selections,
16178: with value set in incoming form variables currently selected.
16179:
16180: Side Effects: None
16181:
16182: =cut
16183:
16184: sub timebased_select_form {
16185: my ($item,$filter) = @_;
16186: if (ref($filter) eq 'HASH') {
16187: $filter->{$item} =~ s/[^\d-]//g;
16188: if (!$filter->{$item}) { $filter->{$item}=-1; }
16189: return &select_form(
16190: $filter->{$item},
16191: $item,
16192: { '-1' => '',
16193: '86400' => &mt('today'),
16194: '604800' => &mt('last week'),
16195: '2592000' => &mt('last month'),
16196: '7776000' => &mt('last three months'),
16197: '15552000' => &mt('last six months'),
16198: '31104000' => &mt('last year'),
16199: 'select_form_order' =>
16200: ['-1','86400','604800','2592000','7776000',
16201: '15552000','31104000']});
16202: }
16203: }
16204:
16205: =pod
16206:
16207: =item * &js_changer()
16208:
16209: Create script tag containing Javascript used to submit course search form
16210: when course type or domain is changed, and also to hide 'Searching ...' on
16211: page load completion for page showing search result.
16212:
16213: Inputs: None
16214:
16215: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16216:
16217: Side Effects: None
16218:
16219: =cut
16220:
16221: sub js_changer {
16222: return <<ENDJS;
16223: <script type="text/javascript">
16224: // <![CDATA[
16225: function updateFilters(caller) {
16226: if (typeof(caller) != "undefined") {
16227: document.filterpicker.updater.value = caller.name;
16228: }
16229: document.filterpicker.submit();
16230: }
16231:
16232: function hideSearching() {
16233: if (document.getElementById('searching')) {
16234: document.getElementById('searching').style.display = 'none';
16235: }
16236: return;
16237: }
16238:
16239: // ]]>
16240: </script>
16241:
16242: ENDJS
16243: }
16244:
16245: =pod
16246:
16247: =item * &search_courses()
16248:
16249: Process selected filters form course search form and pass to lonnet::courseiddump
16250: to retrieve a hash for which keys are courseIDs which match the selected filters.
16251:
16252: Inputs:
16253:
16254: dom - domain being searched
16255:
16256: type - course type ('Course' or 'Community' or '.' if any).
16257:
16258: filter - anonymous hash of criteria and their values
16259:
16260: numtitles - for institutional codes - number of categories
16261:
16262: cloneruname - optional username of new course owner
16263:
16264: clonerudom - optional domain of new course owner
16265:
1.1075.2.95 raeburn 16266: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16267: (used when DC is using course creation form)
16268:
16269: codetitles - reference to array of titles of components in institutional codes (official courses).
16270:
1.1075.2.95 raeburn 16271: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16272: (and so can clone automatically)
16273:
16274: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16275:
16276: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16277: courses to clone
1.1075.2.69 raeburn 16278:
16279: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16280:
16281:
16282: Side Effects: None
16283:
16284: =cut
16285:
16286:
16287: sub search_courses {
1.1075.2.95 raeburn 16288: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16289: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16290: my (%courses,%showcourses,$cloner);
16291: if (($filter->{'ownerfilter'} ne '') ||
16292: ($filter->{'ownerdomfilter'} ne '')) {
16293: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16294: $filter->{'ownerdomfilter'};
16295: }
16296: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16297: if (!$filter->{$item}) {
16298: $filter->{$item}='.';
16299: }
16300: }
16301: my $now = time;
16302: my $timefilter =
16303: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16304: my ($createdbefore,$createdafter);
16305: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16306: $createdbefore = $now;
16307: $createdafter = $now-$filter->{'createdfilter'};
16308: }
16309: my ($instcodefilter,$regexpok);
16310: if ($numtitles) {
16311: if ($env{'form.official'} eq 'on') {
16312: $instcodefilter =
16313: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16314: $regexpok = 1;
16315: } elsif ($env{'form.official'} eq 'off') {
16316: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16317: unless ($instcodefilter eq '') {
16318: $regexpok = -1;
16319: }
16320: }
16321: } else {
16322: $instcodefilter = $filter->{'instcodefilter'};
16323: }
16324: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16325: if ($type eq '') { $type = '.'; }
16326:
16327: if (($clonerudom ne '') && ($cloneruname ne '')) {
16328: $cloner = $cloneruname.':'.$clonerudom;
16329: }
16330: %courses = &Apache::lonnet::courseiddump($dom,
16331: $filter->{'descriptfilter'},
16332: $timefilter,
16333: $instcodefilter,
16334: $filter->{'combownerfilter'},
16335: $filter->{'coursefilter'},
16336: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16337: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16338: $filter->{'cloneableonly'},
16339: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16340: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16341: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16342: my $ccrole;
16343: if ($type eq 'Community') {
16344: $ccrole = 'co';
16345: } else {
16346: $ccrole = 'cc';
16347: }
16348: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16349: $filter->{'persondomfilter'},
16350: 'userroles',undef,
16351: [$ccrole,'in','ad','ep','ta','cr'],
16352: $dom);
16353: foreach my $role (keys(%rolehash)) {
16354: my ($cnum,$cdom,$courserole) = split(':',$role);
16355: my $cid = $cdom.'_'.$cnum;
16356: if (exists($courses{$cid})) {
16357: if (ref($courses{$cid}) eq 'HASH') {
16358: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16359: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16360: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16361: }
16362: } else {
16363: $courses{$cid}{roles} = [$courserole];
16364: }
16365: $showcourses{$cid} = $courses{$cid};
16366: }
16367: }
16368: }
16369: %courses = %showcourses;
16370: }
16371: return %courses;
16372: }
16373:
16374: =pod
16375:
16376: =back
16377:
1.1075.2.88 raeburn 16378: =head1 Routines for version requirements for current course.
16379:
16380: =over 4
16381:
16382: =item * &check_release_required()
16383:
16384: Compares required LON-CAPA version with version on server, and
16385: if required version is newer looks for a server with the required version.
16386:
16387: Looks first at servers in user's owen domain; if none suitable, looks at
16388: servers in course's domain are permitted to host sessions for user's domain.
16389:
16390: Inputs:
16391:
16392: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16393:
16394: $courseid - Course ID of current course
16395:
16396: $rolecode - User's current role in course (for switchserver query string).
16397:
16398: $required - LON-CAPA version needed by course (format: Major.Minor).
16399:
16400:
16401: Returns:
16402:
16403: $switchserver - query string tp append to /adm/switchserver call (if
16404: current server's LON-CAPA version is too old.
16405:
16406: $warning - Message is displayed if no suitable server could be found.
16407:
16408: =cut
16409:
16410: sub check_release_required {
16411: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16412: my ($switchserver,$warning);
16413: if ($required ne '') {
16414: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16415: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16416: if ($reqdmajor ne '' && $reqdminor ne '') {
16417: my $otherserver;
16418: if (($major eq '' && $minor eq '') ||
16419: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16420: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16421: my $switchlcrev =
16422: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16423: $userdomserver);
16424: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16425: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16426: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16427: my $cdom = $env{'course.'.$courseid.'.domain'};
16428: if ($cdom ne $env{'user.domain'}) {
16429: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16430: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16431: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16432: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16433: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16434: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16435: my $canhost =
16436: &Apache::lonnet::can_host_session($env{'user.domain'},
16437: $coursedomserver,
16438: $remoterev,
16439: $udomdefaults{'remotesessions'},
16440: $defdomdefaults{'hostedsessions'});
16441:
16442: if ($canhost) {
16443: $otherserver = $coursedomserver;
16444: } else {
16445: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
16446: }
16447: } else {
16448: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
16449: }
16450: } else {
16451: $otherserver = $userdomserver;
16452: }
16453: }
16454: if ($otherserver ne '') {
16455: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16456: }
16457: }
16458: }
16459: return ($switchserver,$warning);
16460: }
16461:
16462: =pod
16463:
16464: =item * &check_release_result()
16465:
16466: Inputs:
16467:
16468: $switchwarning - Warning message if no suitable server found to host session.
16469:
16470: $switchserver - query string to append to /adm/switchserver containing lonHostID
16471: and current role.
16472:
16473: Returns: HTML to display with information about requirement to switch server.
16474: Either displaying warning with link to Roles/Courses screen or
16475: display link to switchserver.
16476:
1.1075.2.69 raeburn 16477: =cut
16478:
1.1075.2.88 raeburn 16479: sub check_release_result {
16480: my ($switchwarning,$switchserver) = @_;
16481: my $output = &start_page('Selected course unavailable on this server').
16482: '<p class="LC_warning">';
16483: if ($switchwarning) {
16484: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16485: if (&show_course()) {
16486: $output .= &mt('Display courses');
16487: } else {
16488: $output .= &mt('Display roles');
16489: }
16490: $output .= '</a>';
16491: } elsif ($switchserver) {
16492: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16493: '<br />'.
16494: '<a href="/adm/switchserver?'.$switchserver.'">'.
16495: &mt('Switch Server').
16496: '</a>';
16497: }
16498: $output .= '</p>'.&end_page();
16499: return $output;
16500: }
16501:
16502: =pod
16503:
16504: =item * &needs_coursereinit()
16505:
16506: Determine if course contents stored for user's session needs to be
16507: refreshed, because content has changed since "Big Hash" last tied.
16508:
16509: Check for change is made if time last checked is more than 10 minutes ago
16510: (by default).
16511:
16512: Inputs:
16513:
16514: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16515:
16516: $interval (optional) - Time which may elapse (in s) between last check for content
16517: change in current course. (default: 600 s).
16518:
16519: Returns: an array; first element is:
16520:
16521: =over 4
16522:
16523: 'switch' - if content updates mean user's session
16524: needs to be switched to a server running a newer LON-CAPA version
16525:
16526: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16527: on current server hosting user's session
16528:
16529: '' - if no action required.
16530:
16531: =back
16532:
16533: If first item element is 'switch':
16534:
16535: second item is $switchwarning - Warning message if no suitable server found to host session.
16536:
16537: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16538: and current role.
16539:
16540: otherwise: no other elements returned.
16541:
16542: =back
16543:
16544: =cut
16545:
16546: sub needs_coursereinit {
16547: my ($loncaparev,$interval) = @_;
16548: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16549: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16550: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16551: my $now = time;
16552: if ($interval eq '') {
16553: $interval = 600;
16554: }
16555: if (($now-$env{'request.course.timechecked'})>$interval) {
16556: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16557: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16558: if ($lastchange > $env{'request.course.tied'}) {
16559: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16560: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16561: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16562: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16563: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16564: $curr_reqd_hash{'internal.releaserequired'}});
16565: my ($switchserver,$switchwarning) =
16566: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16567: $curr_reqd_hash{'internal.releaserequired'});
16568: if ($switchwarning ne '' || $switchserver ne '') {
16569: return ('switch',$switchwarning,$switchserver);
16570: }
16571: }
16572: }
16573: return ('update');
16574: }
16575: }
16576: return ();
16577: }
1.1075.2.69 raeburn 16578:
1.1075.2.11 raeburn 16579: sub update_content_constraints {
16580: my ($cdom,$cnum,$chome,$cid) = @_;
16581: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16582: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16583: my %checkresponsetypes;
16584: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16585: my ($item,$name,$value) = split(/:/,$key);
16586: if ($item eq 'resourcetag') {
16587: if ($name eq 'responsetype') {
16588: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16589: }
16590: }
16591: }
16592: my $navmap = Apache::lonnavmaps::navmap->new();
16593: if (defined($navmap)) {
16594: my %allresponses;
16595: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16596: my %responses = $res->responseTypes();
16597: foreach my $key (keys(%responses)) {
16598: next unless(exists($checkresponsetypes{$key}));
16599: $allresponses{$key} += $responses{$key};
16600: }
16601: }
16602: foreach my $key (keys(%allresponses)) {
16603: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16604: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16605: ($reqdmajor,$reqdminor) = ($major,$minor);
16606: }
16607: }
16608: undef($navmap);
16609: }
16610: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16611: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16612: }
16613: return;
16614: }
16615:
1.1075.2.27 raeburn 16616: sub allmaps_incourse {
16617: my ($cdom,$cnum,$chome,$cid) = @_;
16618: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16619: $cid = $env{'request.course.id'};
16620: $cdom = $env{'course.'.$cid.'.domain'};
16621: $cnum = $env{'course.'.$cid.'.num'};
16622: $chome = $env{'course.'.$cid.'.home'};
16623: }
16624: my %allmaps = ();
16625: my $lastchange =
16626: &Apache::lonnet::get_coursechange($cdom,$cnum);
16627: if ($lastchange > $env{'request.course.tied'}) {
16628: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16629: unless ($ferr) {
16630: &update_content_constraints($cdom,$cnum,$chome,$cid);
16631: }
16632: }
16633: my $navmap = Apache::lonnavmaps::navmap->new();
16634: if (defined($navmap)) {
16635: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16636: $allmaps{$res->src()} = 1;
16637: }
16638: }
16639: return \%allmaps;
16640: }
16641:
1.1075.2.11 raeburn 16642: sub parse_supplemental_title {
16643: my ($title) = @_;
16644:
16645: my ($foldertitle,$renametitle);
16646: if ($title =~ /&&&/) {
16647: $title = &HTML::Entites::decode($title);
16648: }
16649: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16650: $renametitle=$4;
16651: my ($time,$uname,$udom) = ($1,$2,$3);
16652: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16653: my $name = &plainname($uname,$udom);
16654: $name = &HTML::Entities::encode($name,'"<>&\'');
16655: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16656: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16657: $name.': <br />'.$foldertitle;
16658: }
16659: if (wantarray) {
16660: return ($title,$foldertitle,$renametitle);
16661: }
16662: return $title;
16663: }
16664:
1.1075.2.43 raeburn 16665: sub recurse_supplemental {
16666: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16667: if ($suppmap) {
16668: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16669: if ($fatal) {
16670: $errors ++;
16671: } else {
16672: if ($#LONCAPA::map::resources > 0) {
16673: foreach my $res (@LONCAPA::map::resources) {
16674: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16675: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16676: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16677: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16678: } else {
16679: $numfiles ++;
16680: }
16681: }
16682: }
16683: }
16684: }
16685: }
16686: return ($numfiles,$errors);
16687: }
16688:
1.1075.2.18 raeburn 16689: sub symb_to_docspath {
1.1075.2.119 raeburn 16690: my ($symb,$navmapref) = @_;
16691: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16692: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16693: if ($resurl=~/\.(sequence|page)$/) {
16694: $mapurl=$resurl;
16695: } elsif ($resurl eq 'adm/navmaps') {
16696: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16697: }
16698: my $mapresobj;
1.1075.2.119 raeburn 16699: unless (ref($$navmapref)) {
16700: $$navmapref = Apache::lonnavmaps::navmap->new();
16701: }
16702: if (ref($$navmapref)) {
16703: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16704: }
16705: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16706: my $type=$2;
16707: my $path;
16708: if (ref($mapresobj)) {
16709: my $pcslist = $mapresobj->map_hierarchy();
16710: if ($pcslist ne '') {
16711: foreach my $pc (split(/,/,$pcslist)) {
16712: next if ($pc <= 1);
1.1075.2.119 raeburn 16713: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16714: if (ref($res)) {
16715: my $thisurl = $res->src();
16716: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16717: my $thistitle = $res->title();
16718: $path .= '&'.
16719: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16720: &escape($thistitle).
1.1075.2.18 raeburn 16721: ':'.$res->randompick().
16722: ':'.$res->randomout().
16723: ':'.$res->encrypted().
16724: ':'.$res->randomorder().
16725: ':'.$res->is_page();
16726: }
16727: }
16728: }
16729: $path =~ s/^\&//;
16730: my $maptitle = $mapresobj->title();
16731: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16732: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16733: }
16734: $path .= (($path ne '')? '&' : '').
16735: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16736: &escape($maptitle).
1.1075.2.18 raeburn 16737: ':'.$mapresobj->randompick().
16738: ':'.$mapresobj->randomout().
16739: ':'.$mapresobj->encrypted().
16740: ':'.$mapresobj->randomorder().
16741: ':'.$mapresobj->is_page();
16742: } else {
16743: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16744: my $ispage = (($type eq 'page')? 1 : '');
16745: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16746: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16747: }
16748: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16749: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16750: }
16751: unless ($mapurl eq 'default') {
16752: $path = 'default&'.
1.1075.2.46 raeburn 16753: &escape('Main Content').
1.1075.2.18 raeburn 16754: ':::::&'.$path;
16755: }
16756: return $path;
16757: }
16758:
1.1075.2.14 raeburn 16759: sub captcha_display {
16760: my ($context,$lonhost) = @_;
16761: my ($output,$error);
1.1075.2.107 raeburn 16762: my ($captcha,$pubkey,$privkey,$version) =
16763: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16764: if ($captcha eq 'original') {
16765: $output = &create_captcha();
16766: unless ($output) {
16767: $error = 'captcha';
16768: }
16769: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16770: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16771: unless ($output) {
16772: $error = 'recaptcha';
16773: }
16774: }
1.1075.2.107 raeburn 16775: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16776: }
16777:
16778: sub captcha_response {
16779: my ($context,$lonhost) = @_;
16780: my ($captcha_chk,$captcha_error);
1.1075.2.109 raeburn 16781: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16782: if ($captcha eq 'original') {
16783: ($captcha_chk,$captcha_error) = &check_captcha();
16784: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16785: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16786: } else {
16787: $captcha_chk = 1;
16788: }
16789: return ($captcha_chk,$captcha_error);
16790: }
16791:
16792: sub get_captcha_config {
16793: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16794: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16795: my $hostname = &Apache::lonnet::hostname($lonhost);
16796: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16797: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16798: if ($context eq 'usercreation') {
16799: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16800: if (ref($domconfig{$context}) eq 'HASH') {
16801: $hashtocheck = $domconfig{$context}{'cancreate'};
16802: if (ref($hashtocheck) eq 'HASH') {
16803: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16804: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16805: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16806: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16807: }
16808: if ($privkey && $pubkey) {
16809: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16810: $version = $hashtocheck->{'recaptchaversion'};
16811: if ($version ne '2') {
16812: $version = 1;
16813: }
1.1075.2.14 raeburn 16814: } else {
16815: $captcha = 'original';
16816: }
16817: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16818: $captcha = 'original';
16819: }
16820: }
16821: } else {
16822: $captcha = 'captcha';
16823: }
16824: } elsif ($context eq 'login') {
16825: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16826: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16827: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16828: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16829: if ($privkey && $pubkey) {
16830: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16831: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16832: if ($version ne '2') {
16833: $version = 1;
16834: }
1.1075.2.14 raeburn 16835: } else {
16836: $captcha = 'original';
16837: }
16838: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16839: $captcha = 'original';
16840: }
16841: }
1.1075.2.107 raeburn 16842: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16843: }
16844:
16845: sub create_captcha {
16846: my %captcha_params = &captcha_settings();
16847: my ($output,$maxtries,$tries) = ('',10,0);
16848: while ($tries < $maxtries) {
16849: $tries ++;
16850: my $captcha = Authen::Captcha->new (
16851: output_folder => $captcha_params{'output_dir'},
16852: data_folder => $captcha_params{'db_dir'},
16853: );
16854: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16855:
16856: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16857: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16858: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16859: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16860: '<br />'.
16861: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16862: last;
16863: }
16864: }
16865: return $output;
16866: }
16867:
16868: sub captcha_settings {
16869: my %captcha_params = (
16870: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16871: www_output_dir => "/captchaspool",
16872: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16873: numchars => '5',
16874: );
16875: return %captcha_params;
16876: }
16877:
16878: sub check_captcha {
16879: my ($captcha_chk,$captcha_error);
16880: my $code = $env{'form.code'};
16881: my $md5sum = $env{'form.crypt'};
16882: my %captcha_params = &captcha_settings();
16883: my $captcha = Authen::Captcha->new(
16884: output_folder => $captcha_params{'output_dir'},
16885: data_folder => $captcha_params{'db_dir'},
16886: );
1.1075.2.26 raeburn 16887: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16888: my %captcha_hash = (
16889: 0 => 'Code not checked (file error)',
16890: -1 => 'Failed: code expired',
16891: -2 => 'Failed: invalid code (not in database)',
16892: -3 => 'Failed: invalid code (code does not match crypt)',
16893: );
16894: if ($captcha_chk != 1) {
16895: $captcha_error = $captcha_hash{$captcha_chk}
16896: }
16897: return ($captcha_chk,$captcha_error);
16898: }
16899:
16900: sub create_recaptcha {
1.1075.2.107 raeburn 16901: my ($pubkey,$version) = @_;
16902: if ($version >= 2) {
16903: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16904: } else {
16905: my $use_ssl;
16906: if ($ENV{'SERVER_PORT'} == 443) {
16907: $use_ssl = 1;
16908: }
16909: my $captcha = Captcha::reCAPTCHA->new;
16910: return $captcha->get_options_setter({theme => 'white'})."\n".
16911: $captcha->get_html($pubkey,undef,$use_ssl).
16912: &mt('If the text is hard to read, [_1] will replace them.',
16913: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16914: '<br /><br />';
16915: }
1.1075.2.14 raeburn 16916: }
16917:
16918: sub check_recaptcha {
1.1075.2.107 raeburn 16919: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16920: my $captcha_chk;
1.1075.2.107 raeburn 16921: if ($version >= 2) {
16922: my $ua = LWP::UserAgent->new;
16923: $ua->timeout(10);
16924: my %info = (
16925: secret => $privkey,
16926: response => $env{'form.g-recaptcha-response'},
16927: remoteip => $ENV{'REMOTE_ADDR'},
16928: );
16929: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16930: if ($response->is_success) {
16931: my $data = JSON::DWIW->from_json($response->decoded_content);
16932: if (ref($data) eq 'HASH') {
16933: if ($data->{'success'}) {
16934: $captcha_chk = 1;
16935: }
16936: }
16937: }
16938: } else {
16939: my $captcha = Captcha::reCAPTCHA->new;
16940: my $captcha_result =
16941: $captcha->check_answer(
16942: $privkey,
16943: $ENV{'REMOTE_ADDR'},
16944: $env{'form.recaptcha_challenge_field'},
16945: $env{'form.recaptcha_response_field'},
16946: );
16947: if ($captcha_result->{is_valid}) {
16948: $captcha_chk = 1;
16949: }
1.1075.2.14 raeburn 16950: }
16951: return $captcha_chk;
16952: }
16953:
1.1075.2.64 raeburn 16954: sub emailusername_info {
1.1075.2.103 raeburn 16955: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16956: my %titles = &Apache::lonlocal::texthash (
16957: lastname => 'Last Name',
16958: firstname => 'First Name',
16959: institution => 'School/college/university',
16960: location => "School's city, state/province, country",
16961: web => "School's web address",
16962: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16963: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16964: );
16965: return (\@fields,\%titles);
16966: }
16967:
1.1075.2.56 raeburn 16968: sub cleanup_html {
16969: my ($incoming) = @_;
16970: my $outgoing;
16971: if ($incoming ne '') {
16972: $outgoing = $incoming;
16973: $outgoing =~ s/;/;/g;
16974: $outgoing =~ s/\#/#/g;
16975: $outgoing =~ s/\&/&/g;
16976: $outgoing =~ s/</</g;
16977: $outgoing =~ s/>/>/g;
16978: $outgoing =~ s/\(/(/g;
16979: $outgoing =~ s/\)/)/g;
16980: $outgoing =~ s/"/"/g;
16981: $outgoing =~ s/'/'/g;
16982: $outgoing =~ s/\$/$/g;
16983: $outgoing =~ s{/}{/}g;
16984: $outgoing =~ s/=/=/g;
16985: $outgoing =~ s/\\/\/g
16986: }
16987: return $outgoing;
16988: }
16989:
1.1075.2.74 raeburn 16990: # Checks for critical messages and returns a redirect url if one exists.
16991: # $interval indicates how often to check for messages.
16992: sub critical_redirect {
16993: my ($interval) = @_;
16994: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16995: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16996: $env{'user.name'});
16997: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16998: my $redirecturl;
16999: if ($what[0]) {
17000: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17001: $redirecturl='/adm/email?critical=display';
17002: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17003: return (1, $url);
17004: }
17005: }
17006: }
17007: return ();
17008: }
17009:
1.1075.2.64 raeburn 17010: # Use:
17011: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17012: #
17013: ##################################################
17014: # password associated functions #
17015: ##################################################
17016: sub des_keys {
17017: # Make a new key for DES encryption.
17018: # Each key has two parts which are returned separately.
17019: # Please note: Each key must be passed through the &hex function
17020: # before it is output to the web browser. The hex versions cannot
17021: # be used to decrypt.
17022: my @hexstr=('0','1','2','3','4','5','6','7',
17023: '8','9','a','b','c','d','e','f');
17024: my $lkey='';
17025: for (0..7) {
17026: $lkey.=$hexstr[rand(15)];
17027: }
17028: my $ukey='';
17029: for (0..7) {
17030: $ukey.=$hexstr[rand(15)];
17031: }
17032: return ($lkey,$ukey);
17033: }
17034:
17035: sub des_decrypt {
17036: my ($key,$cyphertext) = @_;
17037: my $keybin=pack("H16",$key);
17038: my $cypher;
17039: if ($Crypt::DES::VERSION>=2.03) {
17040: $cypher=new Crypt::DES $keybin;
17041: } else {
17042: $cypher=new DES $keybin;
17043: }
1.1075.2.106 raeburn 17044: my $plaintext='';
17045: my $cypherlength = length($cyphertext);
17046: my $numchunks = int($cypherlength/32);
17047: for (my $j=0; $j<$numchunks; $j++) {
17048: my $start = $j*32;
17049: my $cypherblock = substr($cyphertext,$start,32);
17050: my $chunk =
17051: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17052: $chunk .=
17053: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17054: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17055: $plaintext .= $chunk;
17056: }
1.1075.2.64 raeburn 17057: return $plaintext;
17058: }
17059:
1.1075.2.127. .7(raebu 17060:19): sub make_short_symbs {
17061:19): my ($cdom,$cnum,$navmap) = @_;
17062:19): return unless (ref($navmap));
17063:19): my ($numnew,@errors);
17064:19): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17065:19): if (@toshorten) {
17066:19): my (%maps,%resources,%titles);
17067:19): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17068:19): 'shorturls',$cdom,$cnum);
17069:19): my %tocreate;
17070:19): if (keys(%resources)) {
17071:19): foreach my $item (sort {$a <=> $b} (@toshorten)) {
17072:19): my $symb = $resources{$item};
17073:19): if ($symb) {
17074:19): $tocreate{$cnum.'&'.$symb} = 1;
17075:19): }
17076:19): }
17077:19): }
17078:19): if (keys(%tocreate)) {
17079:19): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17080:19): my $su = Short::URL->new(no_vowels => 1);
17081:19): my $init = '';
17082:19): my (%newunique,%addcourse,%courseonly,%failed);
17083:19): # get lock on tiny db
17084:19): my $now = time;
17085:19): my $lockhash = {
17086:19): "lock\0$now" => $env{'user.name'}.
17087:19): ':'.$env{'user.domain'},
17088:19): };
17089:19): my $tries = 0;
17090:19): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17091:19): my ($code,$error);
17092:19): while (($gotlock ne 'ok') && ($tries<3)) {
17093:19): $tries ++;
17094:19): sleep 1;
17095:19): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17096:19): }
17097:19): if ($gotlock eq 'ok') {
17098:19): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17099:19): \%addcourse,\%courseonly,\%failed);
17100:19): if (keys(%failed)) {
17101:19): my $numfailed = scalar(keys(%failed));
17102:19): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17103:19): }
17104:19): if (keys(%newunique)) {
17105:19): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17106:19): if ($putres eq 'ok') {
17107:19): $numnew = scalar(keys(%newunique));
17108:19): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17109:19): unless ($newputres eq 'ok') {
17110:19): push(@errors,&mt('error: could not store course look-up of short URLs'));
17111:19): }
17112:19): } else {
17113:19): push(@errors,&mt('error: could not store unique six character URLs'));
17114:19): }
17115:19): }
.8(raebu 17116:19): }
.7(raebu 17117:19): }
17118:19): }
17119:19): return ($numnew,\@errors);
17120:19): }
17121:19):
17122:19): sub shorten_symbs {
17123:19): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
17124:19): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
17125:19): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
17126:19): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
17127:19): my (%possibles,%collisions);
17128:19): foreach my $key (keys(%{$tocreate})) {
17129:19): my $num = String::CRC32::crc32($key);
17130:19): my $tiny = $su->encode($num,$init);
17131:19): if ($tiny) {
17132:19): $possibles{$tiny} = $key;
17133:19): }
17134:19): }
17135:19): if (!$init) {
17136:19): $init = 1;
17137:19): } else {
17138:19): $init ++;
17139:19): }
17140:19): if (keys(%possibles)) {
17141:19): my @posstiny = keys(%possibles);
17142:19): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
17143:19): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
17144:19): if (keys(%currtiny)) {
17145:19): foreach my $key (keys(%currtiny)) {
17146:19): next if ($currtiny{$key} eq '');
17147:19): if ($currtiny{$key} eq $possibles{$key}) {
17148:19): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
17149:19): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17150:19): $courseonly->{$tsymb} = $key;
17151:19): }
17152:19): } else {
17153:19): $collisions{$possibles{$key}} = 1;
17154:19): }
17155:19): delete($possibles{$key});
17156:19): }
17157:19): }
17158:19): foreach my $key (keys(%possibles)) {
17159:19): $newunique->{$key} = $possibles{$key};
17160:19): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
17161:19): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17162:19): $addcourse->{$tsymb} = $key;
17163:19): }
17164:19): }
17165:19): }
17166:19): if (keys(%collisions)) {
17167:19): if ($init <5) {
17168:19): if (!$init) {
17169:19): $init = 1;
17170:19): } else {
17171:19): $init ++;
17172:19): }
17173:19): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
17174:19): $newunique,$addcourse,$courseonly,$failed);
17175:19): } else {
17176:19): foreach my $key (keys(%collisions)) {
17177:19): $failed->{$key} = 1;
17178:19): }
17179:19): }
17180:19): }
17181:19): return $init;
17182:19): }
17183:19):
1.112 bowersj2 17184: 1;
17185: __END__;
1.41 ng 17186:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>