Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.141.2.13
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.141. .13(raeb 4:-21): # $Id: loncommon.pm,v 1.1075.2.141.2.12 2021/01/04 17:29:30 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.1075.2.135 raeburn 74: use HTTP::Request;
1.657 raeburn 75: use DateTime::TimeZone;
1.1075.2.102 raeburn 76: use DateTime::Locale;
1.1075.2.94 raeburn 77: use Encode();
1.1075.2.14 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 80: use JSON::DWIW;
81: use LWP::UserAgent;
1.1075.2.64 raeburn 82: use Crypt::DES;
83: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 84: use File::Copy();
85: use File::Path();
1.1075.2.141. .1(raebu 86:20): use String::CRC32();
87:20): use Short::URL();
1.117 www 88:
1.517 raeburn 89: # ---------------------------------------------- Designs
90: use vars qw(%defaultdesign);
91:
1.22 www 92: my $readit;
93:
1.517 raeburn 94:
1.157 matthew 95: ##
96: ## Global Variables
97: ##
1.46 matthew 98:
1.643 foxr 99:
100: # ----------------------------------------------- SSI with retries:
101: #
102:
103: =pod
104:
1.648 raeburn 105: =head1 Server Side include with retries:
1.643 foxr 106:
107: =over 4
108:
1.648 raeburn 109: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 110:
111: Performs an ssi with some number of retries. Retries continue either
112: until the result is ok or until the retry count supplied by the
113: caller is exhausted.
114:
115: Inputs:
1.648 raeburn 116:
117: =over 4
118:
1.643 foxr 119: resource - Identifies the resource to insert.
1.648 raeburn 120:
1.643 foxr 121: retries - Count of the number of retries allowed.
1.648 raeburn 122:
1.643 foxr 123: form - Hash that identifies the rendering options.
124:
1.648 raeburn 125: =back
126:
127: Returns:
128:
129: =over 4
130:
1.643 foxr 131: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 132:
1.643 foxr 133: response - The response from the last attempt (which may or may not have been successful.
134:
1.648 raeburn 135: =back
136:
137: =back
138:
1.643 foxr 139: =cut
140:
141: sub ssi_with_retries {
142: my ($resource, $retries, %form) = @_;
143:
144:
145: my $ok = 0; # True if we got a good response.
146: my $content;
147: my $response;
148:
149: # Try to get the ssi done. within the retries count:
150:
151: do {
152: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
153: $ok = $response->is_success;
1.650 www 154: if (!$ok) {
155: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
156: }
1.643 foxr 157: $retries--;
158: } while (!$ok && ($retries > 0));
159:
160: if (!$ok) {
161: $content = ''; # On error return an empty content.
162: }
163: return ($content, $response);
164:
165: }
166:
167:
168:
1.20 www 169: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 170: my %language;
1.124 www 171: my %supported_language;
1.1048 foxr 172: my %latex_language; # For choosing hyphenation in <transl..>
173: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 174: my %cprtag;
1.192 taceyjo1 175: my %scprtag;
1.351 www 176: my %fe; my %fd; my %fm;
1.41 ng 177: my %category_extensions;
1.12 harris41 178:
1.46 matthew 179: # ---------------------------------------------- Thesaurus variables
1.144 matthew 180: #
181: # %Keywords:
182: # A hash used by &keyword to determine if a word is considered a keyword.
183: # $thesaurus_db_file
184: # Scalar containing the full path to the thesaurus database.
1.46 matthew 185:
186: my %Keywords;
187: my $thesaurus_db_file;
188:
1.144 matthew 189: #
190: # Initialize values from language.tab, copyright.tab, filetypes.tab,
191: # thesaurus.tab, and filecategories.tab.
192: #
1.18 www 193: BEGIN {
1.46 matthew 194: # Variable initialization
195: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
196: #
1.22 www 197: unless ($readit) {
1.12 harris41 198: # ------------------------------------------------------------------- languages
199: {
1.158 raeburn 200: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
201: '/language.tab';
1.1075.2.128 raeburn 202: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
1.1048 foxr 206: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 207: $language{$key}=$val.' - '.$enc;
208: if ($sup) {
209: $supported_language{$key}=$sup;
210: }
1.1048 foxr 211: if ($latex) {
212: $latex_language_bykey{$key} = $latex;
213: $latex_language{$two} = $latex;
214: }
1.158 raeburn 215: }
216: close($fh);
217: }
1.12 harris41 218: }
219: # ------------------------------------------------------------------ copyrights
220: {
1.158 raeburn 221: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
222: '/copyright.tab';
1.1075.2.128 raeburn 223: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 224: while (my $line = <$fh>) {
225: next if ($line=~/^\#/);
226: chomp($line);
227: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 228: $cprtag{$key}=$val;
229: }
230: close($fh);
231: }
1.12 harris41 232: }
1.351 www 233: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 234: {
235: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
236: '/source_copyright.tab';
1.1075.2.128 raeburn 237: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 238: while (my $line = <$fh>) {
239: next if ($line =~ /^\#/);
240: chomp($line);
241: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 242: $scprtag{$key}=$val;
243: }
244: close($fh);
245: }
246: }
1.63 www 247:
1.517 raeburn 248: # -------------------------------------------------------------- default domain designs
1.63 www 249: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 250: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 251: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 252: while (my $line = <$fh>) {
253: next if ($line =~ /^\#/);
254: chomp($line);
255: my ($key,$val)=(split(/\=/,$line));
256: if ($val) { $defaultdesign{$key}=$val; }
257: }
258: close($fh);
1.63 www 259: }
260:
1.15 harris41 261: # ------------------------------------------------------------- file categories
262: {
1.158 raeburn 263: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
264: '/filecategories.tab';
1.1075.2.128 raeburn 265: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 266: while (my $line = <$fh>) {
267: next if ($line =~ /^\#/);
268: chomp($line);
269: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 270: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 271: }
272: close($fh);
273: }
274:
1.15 harris41 275: }
1.12 harris41 276: # ------------------------------------------------------------------ file types
277: {
1.158 raeburn 278: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
279: '/filetypes.tab';
1.1075.2.128 raeburn 280: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 281: while (my $line = <$fh>) {
282: next if ($line =~ /^\#/);
283: chomp($line);
284: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 285: if ($descr ne '') {
286: $fe{$ending}=lc($emb);
287: $fd{$ending}=$descr;
1.351 www 288: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 289: }
290: }
291: close($fh);
292: }
1.12 harris41 293: }
1.22 www 294: &Apache::lonnet::logthis(
1.705 tempelho 295: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 296: $readit=1;
1.46 matthew 297: } # end of unless($readit)
1.32 matthew 298:
299: }
1.112 bowersj2 300:
1.42 matthew 301: ###############################################################
302: ## HTML and Javascript Helper Functions ##
303: ###############################################################
304:
305: =pod
306:
1.112 bowersj2 307: =head1 HTML and Javascript Functions
1.42 matthew 308:
1.112 bowersj2 309: =over 4
310:
1.648 raeburn 311: =item * &browser_and_searcher_javascript()
1.112 bowersj2 312:
313: X<browsing, javascript>X<searching, javascript>Returns a string
314: containing javascript with two functions, C<openbrowser> and
315: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
316: tags.
1.42 matthew 317:
1.648 raeburn 318: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 319:
320: inputs: formname, elementname, only, omit
321:
322: formname and elementname indicate the name of the html form and name of
323: the element that the results of the browsing selection are to be placed in.
324:
325: Specifying 'only' will restrict the browser to displaying only files
1.185 www 326: with the given extension. Can be a comma separated list.
1.42 matthew 327:
328: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 329: with the given extension. Can be a comma separated list.
1.42 matthew 330:
1.648 raeburn 331: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 332:
333: Inputs: formname, elementname
334:
335: formname and elementname specify the name of the html form and the name
336: of the element the selection from the search results will be placed in.
1.542 raeburn 337:
1.42 matthew 338: =cut
339:
340: sub browser_and_searcher_javascript {
1.199 albertel 341: my ($mode)=@_;
342: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 343: my $resurl=&escape_single(&lastresurl());
1.42 matthew 344: return <<END;
1.219 albertel 345: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 346: var editbrowser = null;
1.135 albertel 347: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 348: var url = '$resurl/?';
1.42 matthew 349: if (editbrowser == null) {
350: url += 'launch=1&';
351: }
352: url += 'catalogmode=interactive&';
1.199 albertel 353: url += 'mode=$mode&';
1.611 albertel 354: url += 'inhibitmenu=yes&';
1.42 matthew 355: url += 'form=' + formname + '&';
356: if (only != null) {
357: url += 'only=' + only + '&';
1.217 albertel 358: } else {
359: url += 'only=&';
360: }
1.42 matthew 361: if (omit != null) {
362: url += 'omit=' + omit + '&';
1.217 albertel 363: } else {
364: url += 'omit=&';
365: }
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Browser';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editbrowser = open(url,title,options,'1');
376: editbrowser.focus();
377: }
378: var editsearcher;
1.135 albertel 379: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 380: var url = '/adm/searchcat?';
381: if (editsearcher == null) {
382: url += 'launch=1&';
383: }
384: url += 'catalogmode=interactive&';
1.199 albertel 385: url += 'mode=$mode&';
1.42 matthew 386: url += 'form=' + formname + '&';
1.135 albertel 387: if (titleelement != null) {
388: url += 'titleelement=' + titleelement + '&';
1.217 albertel 389: } else {
390: url += 'titleelement=&';
391: }
1.42 matthew 392: url += 'element=' + elementname + '';
393: var title = 'Search';
1.435 albertel 394: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 395: options += ',width=700,height=600';
396: editsearcher = open(url,title,options,'1');
397: editsearcher.focus();
398: }
1.219 albertel 399: // END LON-CAPA Internal -->
1.42 matthew 400: END
1.170 www 401: }
402:
403: sub lastresurl {
1.258 albertel 404: if ($env{'environment.lastresurl'}) {
405: return $env{'environment.lastresurl'}
1.170 www 406: } else {
407: return '/res';
408: }
409: }
410:
411: sub storeresurl {
412: my $resurl=&Apache::lonnet::clutter(shift);
413: unless ($resurl=~/^\/res/) { return 0; }
414: $resurl=~s/\/$//;
415: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 416: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 417: return 1;
1.42 matthew 418: }
419:
1.74 www 420: sub studentbrowser_javascript {
1.111 www 421: unless (
1.258 albertel 422: (($env{'request.course.id'}) &&
1.302 albertel 423: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
424: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
425: '/'.$env{'request.course.sec'})
426: ))
1.258 albertel 427: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 428: ) { return ''; }
1.74 www 429: return (<<'ENDSTDBRW');
1.776 bisitz 430: <script type="text/javascript" language="Javascript">
1.824 bisitz 431: // <![CDATA[
1.74 www 432: var stdeditbrowser;
1.1075.2.141. .3(raebu 433:20): function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 434: var url = '/adm/pickstudent?';
435: var filter;
1.558 albertel 436: if (!ignorefilter) {
437: eval('filter=document.'+formname+'.'+uname+'.value;');
438: }
1.74 www 439: if (filter != null) {
440: if (filter != '') {
441: url += 'filter='+filter+'&';
442: }
443: }
444: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 445: '&udomelement='+udom+
446: '&clicker='+clicker;
1.111 www 447: if (roleflag) { url+="&roles=1"; }
1.1075.2.141. .3(raebu 448:20): if (courseadv == 'condition') {
449:20): if (document.getElementById('courseadv')) {
450:20): courseadv = document.getElementById('courseadv').value;
451:20): }
452:20): }
453:20): if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 454: var title = 'Student_Browser';
1.74 www 455: var options = 'scrollbars=1,resizable=1,menubar=0';
456: options += ',width=700,height=600';
457: stdeditbrowser = open(url,title,options,'1');
458: stdeditbrowser.focus();
459: }
1.824 bisitz 460: // ]]>
1.74 www 461: </script>
462: ENDSTDBRW
463: }
1.42 matthew 464:
1.1003 www 465: sub resourcebrowser_javascript {
466: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 467: return (<<'ENDRESBRW');
1.1003 www 468: <script type="text/javascript" language="Javascript">
469: // <![CDATA[
470: var reseditbrowser;
1.1004 www 471: function openresbrowser(formname,reslink) {
1.1005 www 472: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 473: var title = 'Resource_Browser';
474: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 475: options += ',width=700,height=500';
1.1004 www 476: reseditbrowser = open(url,title,options,'1');
477: reseditbrowser.focus();
1.1003 www 478: }
479: // ]]>
480: </script>
1.1004 www 481: ENDRESBRW
1.1003 www 482: }
483:
1.74 www 484: sub selectstudent_link {
1.1075.2.141. .3(raebu 485:20): my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 486: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
487: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
488: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 489: if ($env{'request.course.id'}) {
1.302 albertel 490: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
491: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
492: '/'.$env{'request.course.sec'})) {
1.111 www 493: return '';
494: }
1.999 www 495: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1075.2.141. .3(raebu 496:20): if ($courseadv eq 'only') {
497:20): $callargs .= ",'',1,'$courseadv'";
498:20): } elsif ($courseadv eq 'none') {
499:20): $callargs .= ",'','','$courseadv'";
500:20): } elsif ($courseadv eq 'condition') {
501:20): $callargs .= ",'','','$courseadv'";
1.793 raeburn 502: }
503: return '<span class="LC_nobreak">'.
504: '<a href="javascript:openstdbrowser('.$callargs.');">'.
505: &mt('Select User').'</a></span>';
1.74 www 506: }
1.258 albertel 507: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 508: $callargs .= ",'',1";
1.793 raeburn 509: return '<span class="LC_nobreak">'.
510: '<a href="javascript:openstdbrowser('.$callargs.');">'.
511: &mt('Select User').'</a></span>';
1.111 www 512: }
513: return '';
1.91 www 514: }
515:
1.1004 www 516: sub selectresource_link {
517: my ($form,$reslink,$arg)=@_;
518:
519: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
520: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
521: unless ($env{'request.course.id'}) { return $arg; }
522: return '<span class="LC_nobreak">'.
523: '<a href="javascript:openresbrowser('.$callargs.');">'.
524: $arg.'</a></span>';
525: }
526:
527:
528:
1.653 raeburn 529: sub authorbrowser_javascript {
530: return <<"ENDAUTHORBRW";
1.776 bisitz 531: <script type="text/javascript" language="JavaScript">
1.824 bisitz 532: // <![CDATA[
1.653 raeburn 533: var stdeditbrowser;
534:
535: function openauthorbrowser(formname,udom) {
536: var url = '/adm/pickauthor?';
537: url += 'form='+formname+'&roledom='+udom;
538: var title = 'Author_Browser';
539: var options = 'scrollbars=1,resizable=1,menubar=0';
540: options += ',width=700,height=600';
541: stdeditbrowser = open(url,title,options,'1');
542: stdeditbrowser.focus();
543: }
544:
1.824 bisitz 545: // ]]>
1.653 raeburn 546: </script>
547: ENDAUTHORBRW
548: }
549:
1.91 www 550: sub coursebrowser_javascript {
1.1075.2.31 raeburn 551: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 552: $credits_element,$instcode) = @_;
1.932 raeburn 553: my $wintitle = 'Course_Browser';
1.931 raeburn 554: if ($crstype eq 'Community') {
1.932 raeburn 555: $wintitle = 'Community_Browser';
1.909 raeburn 556: }
1.876 raeburn 557: my $id_functions = &javascript_index_functions();
558: my $output = '
1.776 bisitz 559: <script type="text/javascript" language="JavaScript">
1.824 bisitz 560: // <![CDATA[
1.468 raeburn 561: var stdeditbrowser;'."\n";
1.876 raeburn 562:
563: $output .= <<"ENDSTDBRW";
1.909 raeburn 564: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 565: var url = '/adm/pickcourse?';
1.895 raeburn 566: var formid = getFormIdByName(formname);
1.876 raeburn 567: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 568: if (domainfilter != null) {
569: if (domainfilter != '') {
570: url += 'domainfilter='+domainfilter+'&';
571: }
572: }
1.91 www 573: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 574: '&cdomelement='+udom+
575: '&cnameelement='+desc;
1.468 raeburn 576: if (extra_element !=null && extra_element != '') {
1.594 raeburn 577: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 578: url += '&roleelement='+extra_element;
579: if (domainfilter == null || domainfilter == '') {
580: url += '&domainfilter='+extra_element;
581: }
1.234 raeburn 582: }
1.468 raeburn 583: else {
584: if (formname == 'portform') {
585: url += '&setroles='+extra_element;
1.800 raeburn 586: } else {
587: if (formname == 'rules') {
588: url += '&fixeddom='+extra_element;
589: }
1.468 raeburn 590: }
591: }
1.230 raeburn 592: }
1.909 raeburn 593: if (type != null && type != '') {
594: url += '&type='+type;
595: }
596: if (type_elem != null && type_elem != '') {
597: url += '&typeelement='+type_elem;
598: }
1.872 raeburn 599: if (formname == 'ccrs') {
600: var ownername = document.forms[formid].ccuname.value;
601: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 602: url += '&cloner='+ownername+':'+ownerdom;
603: if (type == 'Course') {
604: url += '&crscode='+document.forms[formid].crscode.value;
605: }
1.1075.2.95 raeburn 606: }
607: if (formname == 'requestcrs') {
608: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 609: }
1.293 raeburn 610: if (multflag !=null && multflag != '') {
611: url += '&multiple='+multflag;
612: }
1.909 raeburn 613: var title = '$wintitle';
1.91 www 614: var options = 'scrollbars=1,resizable=1,menubar=0';
615: options += ',width=700,height=600';
616: stdeditbrowser = open(url,title,options,'1');
617: stdeditbrowser.focus();
618: }
1.876 raeburn 619: $id_functions
620: ENDSTDBRW
1.1075.2.31 raeburn 621: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
622: $output .= &setsec_javascript($sec_element,$formname,$role_element,
623: $credits_element);
1.876 raeburn 624: }
625: $output .= '
626: // ]]>
627: </script>';
628: return $output;
629: }
630:
631: sub javascript_index_functions {
632: return <<"ENDJS";
633:
634: function getFormIdByName(formname) {
635: for (var i=0;i<document.forms.length;i++) {
636: if (document.forms[i].name == formname) {
637: return i;
638: }
639: }
640: return -1;
641: }
642:
643: function getIndexByName(formid,item) {
644: for (var i=0;i<document.forms[formid].elements.length;i++) {
645: if (document.forms[formid].elements[i].name == item) {
646: return i;
647: }
648: }
649: return -1;
650: }
1.468 raeburn 651:
1.876 raeburn 652: function getDomainFromSelectbox(formname,udom) {
653: var userdom;
654: var formid = getFormIdByName(formname);
655: if (formid > -1) {
656: var domid = getIndexByName(formid,udom);
657: if (domid > -1) {
658: if (document.forms[formid].elements[domid].type == 'select-one') {
659: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
660: }
661: if (document.forms[formid].elements[domid].type == 'hidden') {
662: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 663: }
664: }
665: }
1.876 raeburn 666: return userdom;
667: }
668:
669: ENDJS
1.468 raeburn 670:
1.876 raeburn 671: }
672:
1.1017 raeburn 673: sub javascript_array_indexof {
1.1018 raeburn 674: return <<ENDJS;
1.1017 raeburn 675: <script type="text/javascript" language="JavaScript">
676: // <![CDATA[
677:
678: if (!Array.prototype.indexOf) {
679: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
680: "use strict";
681: if (this === void 0 || this === null) {
682: throw new TypeError();
683: }
684: var t = Object(this);
685: var len = t.length >>> 0;
686: if (len === 0) {
687: return -1;
688: }
689: var n = 0;
690: if (arguments.length > 0) {
691: n = Number(arguments[1]);
692: if (n !== n) { // shortcut for verifying if it's NaN
693: n = 0;
694: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
695: n = (n > 0 || -1) * Math.floor(Math.abs(n));
696: }
697: }
698: if (n >= len) {
699: return -1;
700: }
701: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
702: for (; k < len; k++) {
703: if (k in t && t[k] === searchElement) {
704: return k;
705: }
706: }
707: return -1;
708: }
709: }
710:
711: // ]]>
712: </script>
713:
714: ENDJS
715:
716: }
717:
1.876 raeburn 718: sub userbrowser_javascript {
719: my $id_functions = &javascript_index_functions();
720: return <<"ENDUSERBRW";
721:
1.888 raeburn 722: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 723: var url = '/adm/pickuser?';
724: var userdom = getDomainFromSelectbox(formname,udom);
725: if (userdom != null) {
726: if (userdom != '') {
727: url += 'srchdom='+userdom+'&';
728: }
729: }
730: url += 'form=' + formname + '&unameelement='+uname+
731: '&udomelement='+udom+
732: '&ulastelement='+ulast+
733: '&ufirstelement='+ufirst+
734: '&uemailelement='+uemail+
1.881 raeburn 735: '&hideudomelement='+hideudom+
736: '&coursedom='+crsdom;
1.888 raeburn 737: if ((caller != null) && (caller != undefined)) {
738: url += '&caller='+caller;
739: }
1.876 raeburn 740: var title = 'User_Browser';
741: var options = 'scrollbars=1,resizable=1,menubar=0';
742: options += ',width=700,height=600';
743: var stdeditbrowser = open(url,title,options,'1');
744: stdeditbrowser.focus();
745: }
746:
1.888 raeburn 747: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 748: var formid = getFormIdByName(formname);
749: if (formid > -1) {
1.888 raeburn 750: var unameid = getIndexByName(formid,uname);
1.876 raeburn 751: var domid = getIndexByName(formid,udom);
752: var hidedomid = getIndexByName(formid,origdom);
753: if (hidedomid > -1) {
754: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 755: var unameval = document.forms[formid].elements[unameid].value;
756: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
757: if (domid > -1) {
758: var slct = document.forms[formid].elements[domid];
759: if (slct.type == 'select-one') {
760: var i;
761: for (i=0;i<slct.length;i++) {
762: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
763: }
764: }
765: if (slct.type == 'hidden') {
766: slct.value = fixeddom;
1.876 raeburn 767: }
768: }
1.468 raeburn 769: }
770: }
771: }
1.876 raeburn 772: return;
773: }
774:
775: $id_functions
776: ENDUSERBRW
1.468 raeburn 777: }
778:
779: sub setsec_javascript {
1.1075.2.31 raeburn 780: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 781: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
782: $communityrolestr);
783: if ($role_element ne '') {
784: my @allroles = ('st','ta','ep','in','ad');
785: foreach my $crstype ('Course','Community') {
786: if ($crstype eq 'Community') {
787: foreach my $role (@allroles) {
788: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
789: }
790: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
791: } else {
792: foreach my $role (@allroles) {
793: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
794: }
795: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
796: }
797: }
798: $rolestr = '"'.join('","',@allroles).'"';
799: $courserolestr = '"'.join('","',@courserolenames).'"';
800: $communityrolestr = '"'.join('","',@communityrolenames).'"';
801: }
1.468 raeburn 802: my $setsections = qq|
803: function setSect(sectionlist) {
1.629 raeburn 804: var sectionsArray = new Array();
805: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
806: sectionsArray = sectionlist.split(",");
807: }
1.468 raeburn 808: var numSections = sectionsArray.length;
809: document.$formname.$sec_element.length = 0;
810: if (numSections == 0) {
811: document.$formname.$sec_element.multiple=false;
812: document.$formname.$sec_element.size=1;
813: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
814: } else {
815: if (numSections == 1) {
816: document.$formname.$sec_element.multiple=false;
817: document.$formname.$sec_element.size=1;
818: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
819: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
820: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
821: } else {
822: for (var i=0; i<numSections; i++) {
823: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
824: }
825: document.$formname.$sec_element.multiple=true
826: if (numSections < 3) {
827: document.$formname.$sec_element.size=numSections;
828: } else {
829: document.$formname.$sec_element.size=3;
830: }
831: document.$formname.$sec_element.options[0].selected = false
832: }
833: }
1.91 www 834: }
1.905 raeburn 835:
836: function setRole(crstype) {
1.468 raeburn 837: |;
1.905 raeburn 838: if ($role_element eq '') {
839: $setsections .= ' return;
840: }
841: ';
842: } else {
843: $setsections .= qq|
844: var elementLength = document.$formname.$role_element.length;
845: var allroles = Array($rolestr);
846: var courserolenames = Array($courserolestr);
847: var communityrolenames = Array($communityrolestr);
848: if (elementLength != undefined) {
849: if (document.$formname.$role_element.options[5].value == 'cc') {
850: if (crstype == 'Course') {
851: return;
852: } else {
853: allroles[5] = 'co';
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 = communityrolenames[i];
857: }
858: }
859: } else {
860: if (crstype == 'Community') {
861: return;
862: } else {
863: allroles[5] = 'cc';
864: for (var i=0; i<6; i++) {
865: document.$formname.$role_element.options[i].value = allroles[i];
866: document.$formname.$role_element.options[i].text = courserolenames[i];
867: }
868: }
869: }
870: }
871: return;
872: }
873: |;
874: }
1.1075.2.31 raeburn 875: if ($credits_element) {
876: $setsections .= qq|
877: function setCredits(defaultcredits) {
878: document.$formname.$credits_element.value = defaultcredits;
879: return;
880: }
881: |;
882: }
1.468 raeburn 883: return $setsections;
884: }
885:
1.91 www 886: sub selectcourse_link {
1.909 raeburn 887: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
888: $typeelement) = @_;
889: my $type = $selecttype;
1.871 raeburn 890: my $linktext = &mt('Select Course');
891: if ($selecttype eq 'Community') {
1.909 raeburn 892: $linktext = &mt('Select Community');
1.906 raeburn 893: } elsif ($selecttype eq 'Course/Community') {
894: $linktext = &mt('Select Course/Community');
1.909 raeburn 895: $type = '';
1.1019 raeburn 896: } elsif ($selecttype eq 'Select') {
897: $linktext = &mt('Select');
898: $type = '';
1.871 raeburn 899: }
1.787 bisitz 900: return '<span class="LC_nobreak">'
901: ."<a href='"
902: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
903: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 904: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 905: ."'>".$linktext.'</a>'
1.787 bisitz 906: .'</span>';
1.74 www 907: }
1.42 matthew 908:
1.653 raeburn 909: sub selectauthor_link {
910: my ($form,$udom)=@_;
911: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
912: &mt('Select Author').'</a>';
913: }
914:
1.876 raeburn 915: sub selectuser_link {
1.881 raeburn 916: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 917: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 918: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 919: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 920: ');">'.$linktext.'</a>';
1.876 raeburn 921: }
922:
1.273 raeburn 923: sub check_uncheck_jscript {
924: my $jscript = <<"ENDSCRT";
925: function checkAll(field) {
926: if (field.length > 0) {
927: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 928: if (!field[i].disabled) {
929: field[i].checked = true;
930: }
1.273 raeburn 931: }
932: } else {
1.1075.2.14 raeburn 933: if (!field.disabled) {
934: field.checked = true;
935: }
1.273 raeburn 936: }
937: }
938:
939: function uncheckAll(field) {
940: if (field.length > 0) {
941: for (i = 0; i < field.length; i++) {
942: field[i].checked = false ;
1.543 albertel 943: }
944: } else {
1.273 raeburn 945: field.checked = false ;
946: }
947: }
948: ENDSCRT
949: return $jscript;
950: }
951:
1.656 www 952: sub select_timezone {
1.1075.2.115 raeburn 953: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
954: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 955: if ($includeempty) {
956: $output .= '<option value=""';
957: if (($selected eq '') || ($selected eq 'local')) {
958: $output .= ' selected="selected" ';
959: }
960: $output .= '> </option>';
961: }
1.657 raeburn 962: my @timezones = DateTime::TimeZone->all_names;
963: foreach my $tzone (@timezones) {
964: $output.= '<option value="'.$tzone.'"';
965: if ($tzone eq $selected) {
966: $output.=' selected="selected"';
967: }
968: $output.=">$tzone</option>\n";
1.656 www 969: }
970: $output.="</select>";
971: return $output;
972: }
1.273 raeburn 973:
1.687 raeburn 974: sub select_datelocale {
1.1075.2.115 raeburn 975: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
976: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 977: if ($includeempty) {
978: $output .= '<option value=""';
979: if ($selected eq '') {
980: $output .= ' selected="selected" ';
981: }
982: $output .= '> </option>';
983: }
1.1075.2.102 raeburn 984: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 985: my (@possibles,%locale_names);
1.1075.2.102 raeburn 986: my @locales = DateTime::Locale->ids();
987: foreach my $id (@locales) {
988: if ($id ne '') {
989: my ($en_terr,$native_terr);
990: my $loc = DateTime::Locale->load($id);
991: if (ref($loc)) {
992: $en_terr = $loc->name();
993: $native_terr = $loc->native_name();
1.687 raeburn 994: if (grep(/^en$/,@languages) || !@languages) {
995: if ($en_terr ne '') {
996: $locale_names{$id} = '('.$en_terr.')';
997: } elsif ($native_terr ne '') {
998: $locale_names{$id} = $native_terr;
999: }
1000: } else {
1001: if ($native_terr ne '') {
1002: $locale_names{$id} = $native_terr.' ';
1003: } elsif ($en_terr ne '') {
1004: $locale_names{$id} = '('.$en_terr.')';
1005: }
1006: }
1.1075.2.94 raeburn 1007: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1008: push(@possibles,$id);
1.687 raeburn 1009: }
1010: }
1011: }
1012: foreach my $item (sort(@possibles)) {
1013: $output.= '<option value="'.$item.'"';
1014: if ($item eq $selected) {
1015: $output.=' selected="selected"';
1016: }
1017: $output.=">$item";
1018: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1019: $output.=' '.$locale_names{$item};
1.687 raeburn 1020: }
1021: $output.="</option>\n";
1022: }
1023: $output.="</select>";
1024: return $output;
1025: }
1026:
1.792 raeburn 1027: sub select_language {
1.1075.2.115 raeburn 1028: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1029: my %langchoices;
1030: if ($includeempty) {
1.1075.2.32 raeburn 1031: %langchoices = ('' => 'No language preference');
1.792 raeburn 1032: }
1033: foreach my $id (&languageids()) {
1034: my $code = &supportedlanguagecode($id);
1035: if ($code) {
1036: $langchoices{$code} = &plainlanguagedescription($id);
1037: }
1038: }
1.1075.2.32 raeburn 1039: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1040: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1041: }
1042:
1.42 matthew 1043: =pod
1.36 matthew 1044:
1.648 raeburn 1045: =item * &linked_select_forms(...)
1.36 matthew 1046:
1047: linked_select_forms returns a string containing a <script></script> block
1048: and html for two <select> menus. The select menus will be linked in that
1049: changing the value of the first menu will result in new values being placed
1050: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1051: order unless a defined order is provided.
1.36 matthew 1052:
1053: linked_select_forms takes the following ordered inputs:
1054:
1055: =over 4
1056:
1.112 bowersj2 1057: =item * $formname, the name of the <form> tag
1.36 matthew 1058:
1.112 bowersj2 1059: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $firstdefault, the default value for the first menu
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1066:
1.112 bowersj2 1067: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1068:
1.609 raeburn 1069: =item * $menuorder, the order of values in the first menu
1070:
1.1075.2.31 raeburn 1071: =item * $onchangefirst, additional javascript call to execute for an onchange
1072: event for the first <select> tag
1073:
1074: =item * $onchangesecond, additional javascript call to execute for an onchange
1075: event for the second <select> tag
1076:
1.41 ng 1077: =back
1078:
1.36 matthew 1079: Below is an example of such a hash. Only the 'text', 'default', and
1080: 'select2' keys must appear as stated. keys(%menu) are the possible
1081: values for the first select menu. The text that coincides with the
1.41 ng 1082: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1083: and text for the second menu are given in the hash pointed to by
1084: $menu{$choice1}->{'select2'}.
1085:
1.112 bowersj2 1086: my %menu = ( A1 => { text =>"Choice A1" ,
1087: default => "B3",
1088: select2 => {
1089: B1 => "Choice B1",
1090: B2 => "Choice B2",
1091: B3 => "Choice B3",
1092: B4 => "Choice B4"
1.609 raeburn 1093: },
1094: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1095: },
1096: A2 => { text =>"Choice A2" ,
1097: default => "C2",
1098: select2 => {
1099: C1 => "Choice C1",
1100: C2 => "Choice C2",
1101: C3 => "Choice C3"
1.609 raeburn 1102: },
1103: order => ['C2','C1','C3'],
1.112 bowersj2 1104: },
1105: A3 => { text =>"Choice A3" ,
1106: default => "D6",
1107: select2 => {
1108: D1 => "Choice D1",
1109: D2 => "Choice D2",
1110: D3 => "Choice D3",
1111: D4 => "Choice D4",
1112: D5 => "Choice D5",
1113: D6 => "Choice D6",
1114: D7 => "Choice D7"
1.609 raeburn 1115: },
1116: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1117: }
1118: );
1.36 matthew 1119:
1120: =cut
1121:
1122: sub linked_select_forms {
1123: my ($formname,
1124: $middletext,
1125: $firstdefault,
1126: $firstselectname,
1127: $secondselectname,
1.609 raeburn 1128: $hashref,
1129: $menuorder,
1.1075.2.31 raeburn 1130: $onchangefirst,
1131: $onchangesecond
1.36 matthew 1132: ) = @_;
1133: my $second = "document.$formname.$secondselectname";
1134: my $first = "document.$formname.$firstselectname";
1135: # output the javascript to do the changing
1136: my $result = '';
1.776 bisitz 1137: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1138: $result.="// <![CDATA[\n";
1.36 matthew 1139: $result.="var select2data = new Object();\n";
1140: $" = '","';
1141: my $debug = '';
1142: foreach my $s1 (sort(keys(%$hashref))) {
1143: $result.="select2data.d_$s1 = new Object();\n";
1144: $result.="select2data.d_$s1.def = new String('".
1145: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1146: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1147: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1148: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1149: @s2values = @{$hashref->{$s1}->{'order'}};
1150: }
1.36 matthew 1151: $result.="\"@s2values\");\n";
1152: $result.="select2data.d_$s1.texts = new Array(";
1153: my @s2texts;
1154: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1155: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1156: }
1157: $result.="\"@s2texts\");\n";
1158: }
1159: $"=' ';
1160: $result.= <<"END";
1161:
1162: function select1_changed() {
1163: // Determine new choice
1164: var newvalue = "d_" + $first.value;
1165: // update select2
1166: var values = select2data[newvalue].values;
1167: var texts = select2data[newvalue].texts;
1168: var select2def = select2data[newvalue].def;
1169: var i;
1170: // out with the old
1171: for (i = 0; i < $second.options.length; i++) {
1172: $second.options[i] = null;
1173: }
1174: // in with the nuclear
1175: for (i=0;i<values.length; i++) {
1176: $second.options[i] = new Option(values[i]);
1.143 matthew 1177: $second.options[i].value = values[i];
1.36 matthew 1178: $second.options[i].text = texts[i];
1179: if (values[i] == select2def) {
1180: $second.options[i].selected = true;
1181: }
1182: }
1183: }
1.824 bisitz 1184: // ]]>
1.36 matthew 1185: </script>
1186: END
1187: # output the initial values for the selection lists
1.1075.2.31 raeburn 1188: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1189: my @order = sort(keys(%{$hashref}));
1190: if (ref($menuorder) eq 'ARRAY') {
1191: @order = @{$menuorder};
1192: }
1193: foreach my $value (@order) {
1.36 matthew 1194: $result.=" <option value=\"$value\" ";
1.253 albertel 1195: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1196: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1197: }
1198: $result .= "</select>\n";
1199: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1200: $result .= $middletext;
1.1075.2.31 raeburn 1201: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1202: if ($onchangesecond) {
1203: $result .= ' onchange="'.$onchangesecond.'"';
1204: }
1205: $result .= ">\n";
1.36 matthew 1206: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1207:
1208: my @secondorder = sort(keys(%select2));
1209: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1210: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1211: }
1212: foreach my $value (@secondorder) {
1.36 matthew 1213: $result.=" <option value=\"$value\" ";
1.253 albertel 1214: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1215: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1216: }
1217: $result .= "</select>\n";
1218: # return $debug;
1219: return $result;
1220: } # end of sub linked_select_forms {
1221:
1.45 matthew 1222: =pod
1.44 bowersj2 1223:
1.973 raeburn 1224: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1225:
1.112 bowersj2 1226: Returns a string corresponding to an HTML link to the given help
1227: $topic, where $topic corresponds to the name of a .tex file in
1228: /home/httpd/html/adm/help/tex, with underscores replaced by
1229: spaces.
1230:
1231: $text will optionally be linked to the same topic, allowing you to
1232: link text in addition to the graphic. If you do not want to link
1233: text, but wish to specify one of the later parameters, pass an
1234: empty string.
1235:
1236: $stayOnPage is a value that will be interpreted as a boolean. If true,
1237: the link will not open a new window. If false, the link will open
1238: a new window using Javascript. (Default is false.)
1239:
1240: $width and $height are optional numerical parameters that will
1241: override the width and height of the popped up window, which may
1.973 raeburn 1242: be useful for certain help topics with big pictures included.
1243:
1244: $imgid is the id of the img tag used for the help icon. This may be
1245: used in a javascript call to switch the image src. See
1246: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1247:
1248: =cut
1249:
1250: sub help_open_topic {
1.973 raeburn 1251: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1252: $text = "" if (not defined $text);
1.44 bowersj2 1253: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1254: $width = 500 if (not defined $width);
1.44 bowersj2 1255: $height = 400 if (not defined $height);
1256: my $filename = $topic;
1257: $filename =~ s/ /_/g;
1258:
1.48 bowersj2 1259: my $template = "";
1260: my $link;
1.572 banghart 1261:
1.159 www 1262: $topic=~s/\W/\_/g;
1.44 bowersj2 1263:
1.572 banghart 1264: if (!$stayOnPage) {
1.1075.2.50 raeburn 1265: if ($env{'browser.mobile'}) {
1266: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1267: } else {
1268: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1269: }
1.1037 www 1270: } elsif ($stayOnPage eq 'popup') {
1271: $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 1272: } else {
1.48 bowersj2 1273: $link = "/adm/help/${filename}.hlp";
1274: }
1275:
1276: # Add the text
1.755 neumanie 1277: if ($text ne "") {
1.763 bisitz 1278: $template.='<span class="LC_help_open_topic">'
1279: .'<a target="_top" href="'.$link.'">'
1280: .$text.'</a>';
1.48 bowersj2 1281: }
1282:
1.763 bisitz 1283: # (Always) Add the graphic
1.179 matthew 1284: my $title = &mt('Online Help');
1.667 raeburn 1285: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1286: if ($imgid ne '') {
1287: $imgid = ' id="'.$imgid.'"';
1288: }
1.763 bisitz 1289: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1290: .'<img src="'.$helpicon.'" border="0"'
1291: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1292: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1293: .' /></a>';
1294: if ($text ne "") {
1295: $template.='</span>';
1296: }
1.44 bowersj2 1297: return $template;
1298:
1.106 bowersj2 1299: }
1300:
1301: # This is a quicky function for Latex cheatsheet editing, since it
1302: # appears in at least four places
1303: sub helpLatexCheatsheet {
1.1037 www 1304: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1305: my $out;
1.106 bowersj2 1306: my $addOther = '';
1.732 raeburn 1307: if ($topic) {
1.1037 www 1308: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1309: }
1310: $out = '<span>' # Start cheatsheet
1311: .$addOther
1312: .'<span>'
1.1037 www 1313: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span> <span>'
1.1037 www 1315: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1316: .'</span>';
1.732 raeburn 1317: unless ($not_author) {
1.763 bisitz 1318: $out .= ' <span>'
1.1037 www 1319: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1320: .'</span> <span>'
1.1075.2.78 raeburn 1321: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1322: .'</span>';
1.732 raeburn 1323: }
1.763 bisitz 1324: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1325: return $out;
1.172 www 1326: }
1327:
1.430 albertel 1328: sub general_help {
1329: my $helptopic='Student_Intro';
1330: if ($env{'request.role'}=~/^(ca|au)/) {
1331: $helptopic='Authoring_Intro';
1.907 raeburn 1332: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1333: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1334: } elsif ($env{'request.role'}=~/^dc/) {
1335: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1336: }
1337: return $helptopic;
1338: }
1339:
1340: sub update_help_link {
1341: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1342: my $origurl = $ENV{'REQUEST_URI'};
1343: $origurl=~s|^/~|/priv/|;
1344: my $timestamp = time;
1345: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1346: $$datum = &escape($$datum);
1347: }
1348:
1349: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1350: my $output .= <<"ENDOUTPUT";
1351: <script type="text/javascript">
1.824 bisitz 1352: // <![CDATA[
1.430 albertel 1353: banner_link = '$banner_link';
1.824 bisitz 1354: // ]]>
1.430 albertel 1355: </script>
1356: ENDOUTPUT
1357: return $output;
1358: }
1359:
1360: # now just updates the help link and generates a blue icon
1.193 raeburn 1361: sub help_open_menu {
1.430 albertel 1362: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1363: = @_;
1.949 droeschl 1364: $stayOnPage = 1;
1.430 albertel 1365: my $output;
1366: if ($component_help) {
1367: if (!$text) {
1368: $output=&help_open_topic($component_help,undef,$stayOnPage,
1369: $width,$height);
1370: } else {
1371: my $help_text;
1372: $help_text=&unescape($topic);
1373: $output='<table><tr><td>'.
1374: &help_open_topic($component_help,$help_text,$stayOnPage,
1375: $width,$height).'</td></tr></table>';
1376: }
1377: }
1378: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1379: return $output.$banner_link;
1380: }
1381:
1382: sub top_nav_help {
1383: my ($text) = @_;
1.436 albertel 1384: $text = &mt($text);
1.1075.2.60 raeburn 1385: my $stay_on_page;
1386: unless ($env{'environment.remote'} eq 'on') {
1387: $stay_on_page = 1;
1388: }
1.1075.2.61 raeburn 1389: my ($link,$banner_link);
1390: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1391: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1392: : "javascript:helpMenu('open')";
1393: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1394: }
1.201 raeburn 1395: my $title = &mt('Get help');
1.1075.2.61 raeburn 1396: if ($link) {
1397: return <<"END";
1.436 albertel 1398: $banner_link
1.1075.2.56 raeburn 1399: <a href="$link" title="$title">$text</a>
1.436 albertel 1400: END
1.1075.2.61 raeburn 1401: } else {
1402: return ' '.$text.' ';
1403: }
1.436 albertel 1404: }
1405:
1406: sub help_menu_js {
1.1075.2.52 raeburn 1407: my ($httphost) = @_;
1.949 droeschl 1408: my $stayOnPage = 1;
1.436 albertel 1409: my $width = 620;
1410: my $height = 600;
1.430 albertel 1411: my $helptopic=&general_help();
1.1075.2.52 raeburn 1412: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1413: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1414: my $start_page =
1415: &Apache::loncommon::start_page('Help Menu', undef,
1416: {'frameset' => 1,
1417: 'js_ready' => 1,
1.1075.2.136 raeburn 1418: 'use_absolute' => $httphost,
1.331 albertel 1419: 'add_entries' => {
1420: 'border' => '0',
1.579 raeburn 1421: 'rows' => "110,*",},});
1.331 albertel 1422: my $end_page =
1423: &Apache::loncommon::end_page({'frameset' => 1,
1424: 'js_ready' => 1,});
1425:
1.436 albertel 1426: my $template .= <<"ENDTEMPLATE";
1427: <script type="text/javascript">
1.877 bisitz 1428: // <![CDATA[
1.253 albertel 1429: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1430: var banner_link = '';
1.243 raeburn 1431: function helpMenu(target) {
1432: var caller = this;
1433: if (target == 'open') {
1434: var newWindow = null;
1435: try {
1.262 albertel 1436: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1437: }
1438: catch(error) {
1439: writeHelp(caller);
1440: return;
1441: }
1442: if (newWindow) {
1443: caller = newWindow;
1444: }
1.193 raeburn 1445: }
1.243 raeburn 1446: writeHelp(caller);
1447: return;
1448: }
1449: function writeHelp(caller) {
1.1075.2.61 raeburn 1450: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1451: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1452: caller.document.close();
1453: caller.focus();
1.193 raeburn 1454: }
1.877 bisitz 1455: // END LON-CAPA Internal -->
1.253 albertel 1456: // ]]>
1.436 albertel 1457: </script>
1.193 raeburn 1458: ENDTEMPLATE
1459: return $template;
1460: }
1461:
1.172 www 1462: sub help_open_bug {
1463: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1464: unless ($env{'user.adv'}) { return ''; }
1.172 www 1465: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1466: $text = "" if (not defined $text);
1467: $stayOnPage=1;
1.184 albertel 1468: $width = 600 if (not defined $width);
1469: $height = 600 if (not defined $height);
1.172 www 1470:
1471: $topic=~s/\W+/\+/g;
1472: my $link='';
1473: my $template='';
1.379 albertel 1474: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1475: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1476: if (!$stayOnPage)
1477: {
1478: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1479: }
1480: else
1481: {
1482: $link = $url;
1483: }
1484: # Add the text
1485: if ($text ne "")
1486: {
1487: $template .=
1488: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1489: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1490: }
1491:
1492: # Add the graphic
1.179 matthew 1493: my $title = &mt('Report a Bug');
1.215 albertel 1494: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1495: $template .= <<"ENDTEMPLATE";
1.436 albertel 1496: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1497: ENDTEMPLATE
1498: if ($text ne '') { $template.='</td></tr></table>' };
1499: return $template;
1500:
1501: }
1502:
1503: sub help_open_faq {
1504: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1505: unless ($env{'user.adv'}) { return ''; }
1.172 www 1506: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1507: $text = "" if (not defined $text);
1508: $stayOnPage=1;
1509: $width = 350 if (not defined $width);
1510: $height = 400 if (not defined $height);
1511:
1512: $topic=~s/\W+/\+/g;
1513: my $link='';
1514: my $template='';
1515: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1516: if (!$stayOnPage)
1517: {
1518: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1519: }
1520: else
1521: {
1522: $link = $url;
1523: }
1524:
1525: # Add the text
1526: if ($text ne "")
1527: {
1528: $template .=
1.173 www 1529: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1530: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1531: }
1532:
1533: # Add the graphic
1.179 matthew 1534: my $title = &mt('View the FAQ');
1.215 albertel 1535: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1536: $template .= <<"ENDTEMPLATE";
1.436 albertel 1537: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1538: ENDTEMPLATE
1539: if ($text ne '') { $template.='</td></tr></table>' };
1540: return $template;
1541:
1.44 bowersj2 1542: }
1.37 matthew 1543:
1.180 matthew 1544: ###############################################################
1545: ###############################################################
1546:
1.45 matthew 1547: =pod
1548:
1.648 raeburn 1549: =item * &change_content_javascript():
1.256 matthew 1550:
1551: This and the next function allow you to create small sections of an
1552: otherwise static HTML page that you can update on the fly with
1553: Javascript, even in Netscape 4.
1554:
1555: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1556: must be written to the HTML page once. It will prove the Javascript
1557: function "change(name, content)". Calling the change function with the
1558: name of the section
1559: you want to update, matching the name passed to C<changable_area>, and
1560: the new content you want to put in there, will put the content into
1561: that area.
1562:
1563: B<Note>: Netscape 4 only reserves enough space for the changable area
1564: to contain room for the original contents. You need to "make space"
1565: for whatever changes you wish to make, and be B<sure> to check your
1566: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1567: it's adequate for updating a one-line status display, but little more.
1568: This script will set the space to 100% width, so you only need to
1569: worry about height in Netscape 4.
1570:
1571: Modern browsers are much less limiting, and if you can commit to the
1572: user not using Netscape 4, this feature may be used freely with
1573: pretty much any HTML.
1574:
1575: =cut
1576:
1577: sub change_content_javascript {
1578: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1579: if ($env{'browser.type'} eq 'netscape' &&
1580: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1581: return (<<NETSCAPE4);
1582: function change(name, content) {
1583: doc = document.layers[name+"___escape"].layers[0].document;
1584: doc.open();
1585: doc.write(content);
1586: doc.close();
1587: }
1588: NETSCAPE4
1589: } else {
1590: # Otherwise, we need to use semi-standards-compliant code
1591: # (technically, "innerHTML" isn't standard but the equivalent
1592: # is really scary, and every useful browser supports it
1593: return (<<DOMBASED);
1594: function change(name, content) {
1595: element = document.getElementById(name);
1596: element.innerHTML = content;
1597: }
1598: DOMBASED
1599: }
1600: }
1601:
1602: =pod
1603:
1.648 raeburn 1604: =item * &changable_area($name,$origContent):
1.256 matthew 1605:
1606: This provides a "changable area" that can be modified on the fly via
1607: the Javascript code provided in C<change_content_javascript>. $name is
1608: the name you will use to reference the area later; do not repeat the
1609: same name on a given HTML page more then once. $origContent is what
1610: the area will originally contain, which can be left blank.
1611:
1612: =cut
1613:
1614: sub changable_area {
1615: my ($name, $origContent) = @_;
1616:
1.258 albertel 1617: if ($env{'browser.type'} eq 'netscape' &&
1618: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1619: # If this is netscape 4, we need to use the Layer tag
1620: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1621: } else {
1622: return "<span id='$name'>$origContent</span>";
1623: }
1624: }
1625:
1626: =pod
1627:
1.648 raeburn 1628: =item * &viewport_geometry_js
1.590 raeburn 1629:
1630: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1631:
1632: =cut
1633:
1634:
1635: sub viewport_geometry_js {
1636: return <<"GEOMETRY";
1637: var Geometry = {};
1638: function init_geometry() {
1639: if (Geometry.init) { return };
1640: Geometry.init=1;
1641: if (window.innerHeight) {
1642: Geometry.getViewportHeight = function() { return window.innerHeight; };
1643: Geometry.getViewportWidth = function() { return window.innerWidth; };
1644: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1645: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1646: }
1647: else if (document.documentElement && document.documentElement.clientHeight) {
1648: Geometry.getViewportHeight =
1649: function() { return document.documentElement.clientHeight; };
1650: Geometry.getViewportWidth =
1651: function() { return document.documentElement.clientWidth; };
1652:
1653: Geometry.getHorizontalScroll =
1654: function() { return document.documentElement.scrollLeft; };
1655: Geometry.getVerticalScroll =
1656: function() { return document.documentElement.scrollTop; };
1657: }
1658: else if (document.body.clientHeight) {
1659: Geometry.getViewportHeight =
1660: function() { return document.body.clientHeight; };
1661: Geometry.getViewportWidth =
1662: function() { return document.body.clientWidth; };
1663: Geometry.getHorizontalScroll =
1664: function() { return document.body.scrollLeft; };
1665: Geometry.getVerticalScroll =
1666: function() { return document.body.scrollTop; };
1667: }
1668: }
1669:
1670: GEOMETRY
1671: }
1672:
1673: =pod
1674:
1.648 raeburn 1675: =item * &viewport_size_js()
1.590 raeburn 1676:
1677: 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.
1678:
1679: =cut
1680:
1681: sub viewport_size_js {
1682: my $geometry = &viewport_geometry_js();
1683: return <<"DIMS";
1684:
1685: $geometry
1686:
1687: function getViewportDims(width,height) {
1688: init_geometry();
1689: width.value = Geometry.getViewportWidth();
1690: height.value = Geometry.getViewportHeight();
1691: return;
1692: }
1693:
1694: DIMS
1695: }
1696:
1697: =pod
1698:
1.648 raeburn 1699: =item * &resize_textarea_js()
1.565 albertel 1700:
1701: emits the needed javascript to resize a textarea to be as big as possible
1702:
1703: creates a function resize_textrea that takes two IDs first should be
1704: the id of the element to resize, second should be the id of a div that
1705: surrounds everything that comes after the textarea, this routine needs
1706: to be attached to the <body> for the onload and onresize events.
1707:
1.648 raeburn 1708: =back
1.565 albertel 1709:
1710: =cut
1711:
1712: sub resize_textarea_js {
1.590 raeburn 1713: my $geometry = &viewport_geometry_js();
1.565 albertel 1714: return <<"RESIZE";
1715: <script type="text/javascript">
1.824 bisitz 1716: // <![CDATA[
1.590 raeburn 1717: $geometry
1.565 albertel 1718:
1.588 albertel 1719: function getX(element) {
1720: var x = 0;
1721: while (element) {
1722: x += element.offsetLeft;
1723: element = element.offsetParent;
1724: }
1725: return x;
1726: }
1727: function getY(element) {
1728: var y = 0;
1729: while (element) {
1730: y += element.offsetTop;
1731: element = element.offsetParent;
1732: }
1733: return y;
1734: }
1735:
1736:
1.565 albertel 1737: function resize_textarea(textarea_id,bottom_id) {
1738: init_geometry();
1739: var textarea = document.getElementById(textarea_id);
1740: //alert(textarea);
1741:
1.588 albertel 1742: var textarea_top = getY(textarea);
1.565 albertel 1743: var textarea_height = textarea.offsetHeight;
1744: var bottom = document.getElementById(bottom_id);
1.588 albertel 1745: var bottom_top = getY(bottom);
1.565 albertel 1746: var bottom_height = bottom.offsetHeight;
1747: var window_height = Geometry.getViewportHeight();
1.588 albertel 1748: var fudge = 23;
1.565 albertel 1749: var new_height = window_height-fudge-textarea_top-bottom_height;
1750: if (new_height < 300) {
1751: new_height = 300;
1752: }
1753: textarea.style.height=new_height+'px';
1754: }
1.824 bisitz 1755: // ]]>
1.565 albertel 1756: </script>
1757: RESIZE
1758:
1759: }
1760:
1.1075.2.112 raeburn 1761: sub colorfuleditor_js {
1762: return <<"COLORFULEDIT"
1763: <script type="text/javascript">
1764: // <![CDATA[>
1765: function fold_box(curDepth, lastresource){
1766:
1767: // we need a list because there can be several blocks you need to fold in one tag
1768: var block = document.getElementsByName('foldblock_'+curDepth);
1769: // but there is only one folding button per tag
1770: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1771:
1772: if(block.item(0).style.display == 'none'){
1773:
1774: foldbutton.value = '@{[&mt("Hide")]}';
1775: for (i = 0; i < block.length; i++){
1776: block.item(i).style.display = '';
1777: }
1778: }else{
1779:
1780: foldbutton.value = '@{[&mt("Show")]}';
1781: for (i = 0; i < block.length; i++){
1782: // block.item(i).style.visibility = 'collapse';
1783: block.item(i).style.display = 'none';
1784: }
1785: };
1786: saveState(lastresource);
1787: }
1788:
1789: function saveState (lastresource) {
1790:
1791: var tag_list = getTagList();
1792: if(tag_list != null){
1793: var timestamp = new Date().getTime();
1794: var key = lastresource;
1795:
1796: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1797: // starting with timestamp
1798: var value = timestamp+';';
1799:
1800: // building the list of key-value pairs
1801: for(var i = 0; i < tag_list.length; i++){
1802: value += tag_list[i]+',';
1803: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1804: }
1805:
1806: // only iterate whole storage if nothing to override
1807: if(localStorage.getItem(key) == null){
1808:
1809: // prevent storage from growing large
1810: if(localStorage.length > 50){
1811: var regex_getTimestamp = /^(?:\d)+;/;
1812: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1813: var oldest_key;
1814:
1815: for(var i = 1; i < localStorage.length; i++){
1816: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1817: oldest_key = localStorage.key(i);
1818: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1819: }
1820: }
1821: localStorage.removeItem(oldest_key);
1822: }
1823: }
1824: localStorage.setItem(key,value);
1825: }
1826: }
1827:
1828: // restore folding status of blocks (on page load)
1829: function restoreState (lastresource) {
1830: if(localStorage.getItem(lastresource) != null){
1831: var key = lastresource;
1832: var value = localStorage.getItem(key);
1833: var regex_delTimestamp = /^\d+;/;
1834:
1835: value.replace(regex_delTimestamp, '');
1836:
1837: var valueArr = value.split(';');
1838: var pairs;
1839: var elements;
1840: for (var i = 0; i < valueArr.length; i++){
1841: pairs = valueArr[i].split(',');
1842: elements = document.getElementsByName(pairs[0]);
1843:
1844: for (var j = 0; j < elements.length; j++){
1845: elements[j].style.display = pairs[1];
1846: if (pairs[1] == "none"){
1847: var regex_id = /([_\\d]+)\$/;
1848: regex_id.exec(pairs[0]);
1849: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1850: }
1851: }
1852: }
1853: }
1854: }
1855:
1856: function getTagList () {
1857:
1858: var stringToSearch = document.lonhomework.innerHTML;
1859:
1860: var ret = new Array();
1861: var regex_findBlock = /(foldblock_.*?)"/g;
1862: var tag_list = stringToSearch.match(regex_findBlock);
1863:
1864: if(tag_list != null){
1865: for(var i = 0; i < tag_list.length; i++){
1866: ret.push(tag_list[i].replace(/"/, ''));
1867: }
1868: }
1869: return ret;
1870: }
1871:
1872: function saveScrollPosition (resource) {
1873: var tag_list = getTagList();
1874:
1875: // we dont always want to jump to the first block
1876: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1877: if(\$(window).scrollTop() > 170){
1878: if(tag_list != null){
1879: var result;
1880: for(var i = 0; i < tag_list.length; i++){
1881: if(isElementInViewport(tag_list[i])){
1882: result += tag_list[i]+';';
1883: }
1884: }
1885: sessionStorage.setItem('anchor_'+resource, result);
1886: }
1887: } else {
1888: // we dont need to save zero, just delete the item to leave everything tidy
1889: sessionStorage.removeItem('anchor_'+resource);
1890: }
1891: }
1892:
1893: function restoreScrollPosition(resource){
1894:
1895: var elem = sessionStorage.getItem('anchor_'+resource);
1896: if(elem != null){
1897: var tag_list = elem.split(';');
1898: var elem_list;
1899:
1900: for(var i = 0; i < tag_list.length; i++){
1901: elem_list = document.getElementsByName(tag_list[i]);
1902:
1903: if(elem_list.length > 0){
1904: elem = elem_list[0];
1905: break;
1906: }
1907: }
1908: elem.scrollIntoView();
1909: }
1910: }
1911:
1912: function isElementInViewport(el) {
1913:
1914: // change to last element instead of first
1915: var elem = document.getElementsByName(el);
1916: var rect = elem[0].getBoundingClientRect();
1917:
1918: return (
1919: rect.top >= 0 &&
1920: rect.left >= 0 &&
1921: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1922: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1923: );
1924: }
1925:
1926: function autosize(depth){
1927: var cmInst = window['cm'+depth];
1928: var fitsizeButton = document.getElementById('fitsize'+depth);
1929:
1930: // is fixed size, switching to dynamic
1931: if (sessionStorage.getItem("autosized_"+depth) == null) {
1932: cmInst.setSize("","auto");
1933: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1934: sessionStorage.setItem("autosized_"+depth, "yes");
1935:
1936: // is dynamic size, switching to fixed
1937: } else {
1938: cmInst.setSize("","300px");
1939: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1940: sessionStorage.removeItem("autosized_"+depth);
1941: }
1942: }
1943:
1944:
1945:
1946: // ]]>
1947: </script>
1948: COLORFULEDIT
1949: }
1950:
1951: sub xmleditor_js {
1952: return <<XMLEDIT
1953: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1954: <script type="text/javascript">
1955: // <![CDATA[>
1956:
1957: function saveScrollPosition (resource) {
1958:
1959: var scrollPos = \$(window).scrollTop();
1960: sessionStorage.setItem(resource,scrollPos);
1961: }
1962:
1963: function restoreScrollPosition(resource){
1964:
1965: var scrollPos = sessionStorage.getItem(resource);
1966: \$(window).scrollTop(scrollPos);
1967: }
1968:
1969: // unless internet explorer
1970: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1971:
1972: \$(document).ready(function() {
1973: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1974: });
1975: }
1976:
1977: // inserts text at cursor position into codemirror (xml editor only)
1978: function insertText(text){
1979: cm.focus();
1980: var curPos = cm.getCursor();
1981: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1982: }
1983: // ]]>
1984: </script>
1985: XMLEDIT
1986: }
1987:
1988: sub insert_folding_button {
1989: my $curDepth = $Apache::lonxml::curdepth;
1990: my $lastresource = $env{'request.ambiguous'};
1991:
1992: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1993: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1994: }
1995:
1996:
1.565 albertel 1997: =pod
1998:
1.256 matthew 1999: =head1 Excel and CSV file utility routines
2000:
2001: =cut
2002:
2003: ###############################################################
2004: ###############################################################
2005:
2006: =pod
2007:
1.1075.2.56 raeburn 2008: =over 4
2009:
1.648 raeburn 2010: =item * &csv_translate($text)
1.37 matthew 2011:
1.185 www 2012: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2013: format.
2014:
2015: =cut
2016:
1.180 matthew 2017: ###############################################################
2018: ###############################################################
1.37 matthew 2019: sub csv_translate {
2020: my $text = shift;
2021: $text =~ s/\"/\"\"/g;
1.209 albertel 2022: $text =~ s/\n/ /g;
1.37 matthew 2023: return $text;
2024: }
1.180 matthew 2025:
2026: ###############################################################
2027: ###############################################################
2028:
2029: =pod
2030:
1.648 raeburn 2031: =item * &define_excel_formats()
1.180 matthew 2032:
2033: Define some commonly used Excel cell formats.
2034:
2035: Currently supported formats:
2036:
2037: =over 4
2038:
2039: =item header
2040:
2041: =item bold
2042:
2043: =item h1
2044:
2045: =item h2
2046:
2047: =item h3
2048:
1.256 matthew 2049: =item h4
2050:
2051: =item i
2052:
1.180 matthew 2053: =item date
2054:
2055: =back
2056:
2057: Inputs: $workbook
2058:
2059: Returns: $format, a hash reference.
2060:
1.1057 foxr 2061:
1.180 matthew 2062: =cut
2063:
2064: ###############################################################
2065: ###############################################################
2066: sub define_excel_formats {
2067: my ($workbook) = @_;
2068: my $format;
2069: $format->{'header'} = $workbook->add_format(bold => 1,
2070: bottom => 1,
2071: align => 'center');
2072: $format->{'bold'} = $workbook->add_format(bold=>1);
2073: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2074: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2075: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2076: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2077: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2078: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2079: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2080: return $format;
2081: }
2082:
2083: ###############################################################
2084: ###############################################################
1.113 bowersj2 2085:
2086: =pod
2087:
1.648 raeburn 2088: =item * &create_workbook()
1.255 matthew 2089:
2090: Create an Excel worksheet. If it fails, output message on the
2091: request object and return undefs.
2092:
2093: Inputs: Apache request object
2094:
2095: Returns (undef) on failure,
2096: Excel worksheet object, scalar with filename, and formats
2097: from &Apache::loncommon::define_excel_formats on success
2098:
2099: =cut
2100:
2101: ###############################################################
2102: ###############################################################
2103: sub create_workbook {
2104: my ($r) = @_;
2105: #
2106: # Create the excel spreadsheet
2107: my $filename = '/prtspool/'.
1.258 albertel 2108: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2109: time.'_'.rand(1000000000).'.xls';
2110: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2111: if (! defined($workbook)) {
2112: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2113: $r->print(
2114: '<p class="LC_error">'
2115: .&mt('Problems occurred in creating the new Excel file.')
2116: .' '.&mt('This error has been logged.')
2117: .' '.&mt('Please alert your LON-CAPA administrator.')
2118: .'</p>'
2119: );
1.255 matthew 2120: return (undef);
2121: }
2122: #
1.1014 foxr 2123: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2124: #
2125: my $format = &Apache::loncommon::define_excel_formats($workbook);
2126: return ($workbook,$filename,$format);
2127: }
2128:
2129: ###############################################################
2130: ###############################################################
2131:
2132: =pod
2133:
1.648 raeburn 2134: =item * &create_text_file()
1.113 bowersj2 2135:
1.542 raeburn 2136: Create a file to write to and eventually make available to the user.
1.256 matthew 2137: If file creation fails, outputs an error message on the request object and
2138: return undefs.
1.113 bowersj2 2139:
1.256 matthew 2140: Inputs: Apache request object, and file suffix
1.113 bowersj2 2141:
1.256 matthew 2142: Returns (undef) on failure,
2143: Filehandle and filename on success.
1.113 bowersj2 2144:
2145: =cut
2146:
1.256 matthew 2147: ###############################################################
2148: ###############################################################
2149: sub create_text_file {
2150: my ($r,$suffix) = @_;
2151: if (! defined($suffix)) { $suffix = 'txt'; };
2152: my $fh;
2153: my $filename = '/prtspool/'.
1.258 albertel 2154: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2155: time.'_'.rand(1000000000).'.'.$suffix;
2156: $fh = Apache::File->new('>/home/httpd'.$filename);
2157: if (! defined($fh)) {
2158: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2159: $r->print(
2160: '<p class="LC_error">'
2161: .&mt('Problems occurred in creating the output file.')
2162: .' '.&mt('This error has been logged.')
2163: .' '.&mt('Please alert your LON-CAPA administrator.')
2164: .'</p>'
2165: );
1.113 bowersj2 2166: }
1.256 matthew 2167: return ($fh,$filename)
1.113 bowersj2 2168: }
2169:
2170:
1.256 matthew 2171: =pod
1.113 bowersj2 2172:
2173: =back
2174:
2175: =cut
1.37 matthew 2176:
2177: ###############################################################
1.33 matthew 2178: ## Home server <option> list generating code ##
2179: ###############################################################
1.35 matthew 2180:
1.169 www 2181: # ------------------------------------------
2182:
2183: sub domain_select {
2184: my ($name,$value,$multiple)=@_;
2185: my %domains=map {
1.514 albertel 2186: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2187: } &Apache::lonnet::all_domains();
1.169 www 2188: if ($multiple) {
2189: $domains{''}=&mt('Any domain');
1.550 albertel 2190: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2191: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2192: } else {
1.550 albertel 2193: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2194: return &select_form($name,$value,\%domains);
1.169 www 2195: }
2196: }
2197:
1.282 albertel 2198: #-------------------------------------------
2199:
2200: =pod
2201:
1.519 raeburn 2202: =head1 Routines for form select boxes
2203:
2204: =over 4
2205:
1.648 raeburn 2206: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2207:
2208: Returns a string containing a <select> element int multiple mode
2209:
2210:
2211: Args:
2212: $name - name of the <select> element
1.506 raeburn 2213: $value - scalar or array ref of values that should already be selected
1.282 albertel 2214: $size - number of rows long the select element is
1.283 albertel 2215: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2216: (shown text should already have been &mt())
1.506 raeburn 2217: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2218:
1.282 albertel 2219: =cut
2220:
2221: #-------------------------------------------
1.169 www 2222: sub multiple_select_form {
1.284 albertel 2223: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2224: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2225: my $output='';
1.191 matthew 2226: if (! defined($size)) {
2227: $size = 4;
1.283 albertel 2228: if (scalar(keys(%$hash))<4) {
2229: $size = scalar(keys(%$hash));
1.191 matthew 2230: }
2231: }
1.734 bisitz 2232: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2233: my @order;
1.506 raeburn 2234: if (ref($order) eq 'ARRAY') {
2235: @order = @{$order};
2236: } else {
2237: @order = sort(keys(%$hash));
1.501 banghart 2238: }
2239: if (exists($$hash{'select_form_order'})) {
2240: @order = @{$$hash{'select_form_order'}};
2241: }
2242:
1.284 albertel 2243: foreach my $key (@order) {
1.356 albertel 2244: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2245: $output.='selected="selected" ' if ($selected{$key});
2246: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2247: }
2248: $output.="</select>\n";
2249: return $output;
2250: }
2251:
1.88 www 2252: #-------------------------------------------
2253:
2254: =pod
2255:
1.1075.2.115 raeburn 2256: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2257:
2258: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2259: allow a user to select options from a ref to a hash containing:
2260: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2261: a javascript onchange item, e.g., onchange="this.form.submit();".
2262: An optional arg -- $readonly -- if true will cause the select form
2263: to be disabled, e.g., for the case where an instructor has a section-
2264: specific role, and is viewing/modifying parameters.
1.970 raeburn 2265:
1.88 www 2266: See lonrights.pm for an example invocation and use.
2267:
2268: =cut
2269:
2270: #-------------------------------------------
2271: sub select_form {
1.1075.2.115 raeburn 2272: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2273: return unless (ref($hashref) eq 'HASH');
2274: if ($onchange) {
2275: $onchange = ' onchange="'.$onchange.'"';
2276: }
1.1075.2.129 raeburn 2277: my $disabled;
2278: if ($readonly) {
2279: $disabled = ' disabled="disabled"';
2280: }
2281: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2282: my @keys;
1.970 raeburn 2283: if (exists($hashref->{'select_form_order'})) {
2284: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2285: } else {
1.970 raeburn 2286: @keys=sort(keys(%{$hashref}));
1.128 albertel 2287: }
1.356 albertel 2288: foreach my $key (@keys) {
2289: $selectform.=
2290: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2291: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2292: ">".$hashref->{$key}."</option>\n";
1.88 www 2293: }
2294: $selectform.="</select>";
2295: return $selectform;
2296: }
2297:
1.475 www 2298: # For display filters
2299:
2300: sub display_filter {
1.1074 raeburn 2301: my ($context) = @_;
1.475 www 2302: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2303: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2304: my $phraseinput = 'hidden';
2305: my $includeinput = 'hidden';
2306: my ($checked,$includetypestext);
2307: if ($env{'form.displayfilter'} eq 'containing') {
2308: $phraseinput = 'text';
2309: if ($context eq 'parmslog') {
2310: $includeinput = 'checkbox';
2311: if ($env{'form.includetypes'}) {
2312: $checked = ' checked="checked"';
2313: }
2314: $includetypestext = &mt('Include parameter types');
2315: }
2316: } else {
2317: $includetypestext = ' ';
2318: }
2319: my ($additional,$secondid,$thirdid);
2320: if ($context eq 'parmslog') {
2321: $additional =
2322: '<label><input type="'.$includeinput.'" name="includetypes"'.
2323: $checked.' name="includetypes" value="1" id="includetypes" />'.
2324: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2325: '</label>';
2326: $secondid = 'includetypes';
2327: $thirdid = 'includetypestext';
2328: }
2329: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2330: '$secondid','$thirdid')";
2331: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2332: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2333: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2334: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2335: &mt('Filter: [_1]',
1.477 www 2336: &select_form($env{'form.displayfilter'},
2337: 'displayfilter',
1.970 raeburn 2338: {'currentfolder' => 'Current folder/page',
1.477 www 2339: 'containing' => 'Containing phrase',
1.1074 raeburn 2340: 'none' => 'None'},$onchange)).' '.
2341: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2342: &HTML::Entities::encode($env{'form.containingphrase'}).
2343: '" />'.$additional;
2344: }
2345:
2346: sub display_filter_js {
2347: my $includetext = &mt('Include parameter types');
2348: return <<"ENDJS";
2349:
2350: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2351: var firstType = 'hidden';
2352: if (setter.options[setter.selectedIndex].value == 'containing') {
2353: firstType = 'text';
2354: }
2355: firstObject = document.getElementById(firstid);
2356: if (typeof(firstObject) == 'object') {
2357: if (firstObject.type != firstType) {
2358: changeInputType(firstObject,firstType);
2359: }
2360: }
2361: if (context == 'parmslog') {
2362: var secondType = 'hidden';
2363: if (firstType == 'text') {
2364: secondType = 'checkbox';
2365: }
2366: secondObject = document.getElementById(secondid);
2367: if (typeof(secondObject) == 'object') {
2368: if (secondObject.type != secondType) {
2369: changeInputType(secondObject,secondType);
2370: }
2371: }
2372: var textItem = document.getElementById(thirdid);
2373: var currtext = textItem.innerHTML;
2374: var newtext;
2375: if (firstType == 'text') {
2376: newtext = '$includetext';
2377: } else {
2378: newtext = ' ';
2379: }
2380: if (currtext != newtext) {
2381: textItem.innerHTML = newtext;
2382: }
2383: }
2384: return;
2385: }
2386:
2387: function changeInputType(oldObject,newType) {
2388: var newObject = document.createElement('input');
2389: newObject.type = newType;
2390: if (oldObject.size) {
2391: newObject.size = oldObject.size;
2392: }
2393: if (oldObject.value) {
2394: newObject.value = oldObject.value;
2395: }
2396: if (oldObject.name) {
2397: newObject.name = oldObject.name;
2398: }
2399: if (oldObject.id) {
2400: newObject.id = oldObject.id;
2401: }
2402: oldObject.parentNode.replaceChild(newObject,oldObject);
2403: return;
2404: }
2405:
2406: ENDJS
1.475 www 2407: }
2408:
1.167 www 2409: sub gradeleveldescription {
2410: my $gradelevel=shift;
2411: my %gradelevels=(0 => 'Not specified',
2412: 1 => 'Grade 1',
2413: 2 => 'Grade 2',
2414: 3 => 'Grade 3',
2415: 4 => 'Grade 4',
2416: 5 => 'Grade 5',
2417: 6 => 'Grade 6',
2418: 7 => 'Grade 7',
2419: 8 => 'Grade 8',
2420: 9 => 'Grade 9',
2421: 10 => 'Grade 10',
2422: 11 => 'Grade 11',
2423: 12 => 'Grade 12',
2424: 13 => 'Grade 13',
2425: 14 => '100 Level',
2426: 15 => '200 Level',
2427: 16 => '300 Level',
2428: 17 => '400 Level',
2429: 18 => 'Graduate Level');
2430: return &mt($gradelevels{$gradelevel});
2431: }
2432:
1.163 www 2433: sub select_level_form {
2434: my ($deflevel,$name)=@_;
2435: unless ($deflevel) { $deflevel=0; }
1.167 www 2436: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2437: for (my $i=0; $i<=18; $i++) {
2438: $selectform.="<option value=\"$i\" ".
1.253 albertel 2439: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2440: ">".&gradeleveldescription($i)."</option>\n";
2441: }
2442: $selectform.="</select>";
2443: return $selectform;
1.163 www 2444: }
1.167 www 2445:
1.35 matthew 2446: #-------------------------------------------
2447:
1.45 matthew 2448: =pod
2449:
1.1075.2.115 raeburn 2450: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2451:
2452: Returns a string containing a <select name='$name' size='1'> form to
2453: allow a user to select the domain to preform an operation in.
2454: See loncreateuser.pm for an example invocation and use.
2455:
1.90 www 2456: If the $includeempty flag is set, it also includes an empty choice ("no domain
2457: selected");
2458:
1.743 raeburn 2459: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2460:
1.910 raeburn 2461: 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.
2462:
1.1075.2.36 raeburn 2463: The optional $incdoms is a reference to an array of domains which will be the only available options.
2464:
1.1075.2.115 raeburn 2465: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2466:
2467: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2468:
1.35 matthew 2469: =cut
2470:
2471: #-------------------------------------------
1.34 matthew 2472: sub select_dom_form {
1.1075.2.115 raeburn 2473: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2474: if ($onchange) {
1.874 raeburn 2475: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2476: }
1.1075.2.115 raeburn 2477: if ($disabled) {
2478: $disabled = ' disabled="disabled"';
2479: }
1.1075.2.36 raeburn 2480: my (@domains,%exclude);
1.910 raeburn 2481: if (ref($incdoms) eq 'ARRAY') {
2482: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2483: } else {
2484: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2485: }
1.90 www 2486: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2487: if (ref($excdoms) eq 'ARRAY') {
2488: map { $exclude{$_} = 1; } @{$excdoms};
2489: }
1.1075.2.115 raeburn 2490: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2491: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2492: next if ($exclude{$dom});
1.356 albertel 2493: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2494: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2495: if ($showdomdesc) {
2496: if ($dom ne '') {
2497: my $domdesc = &Apache::lonnet::domain($dom,'description');
2498: if ($domdesc ne '') {
2499: $selectdomain .= ' ('.$domdesc.')';
2500: }
2501: }
2502: }
2503: $selectdomain .= "</option>\n";
1.34 matthew 2504: }
2505: $selectdomain.="</select>";
2506: return $selectdomain;
2507: }
2508:
1.35 matthew 2509: #-------------------------------------------
2510:
1.45 matthew 2511: =pod
2512:
1.648 raeburn 2513: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2514:
1.586 raeburn 2515: input: 4 arguments (two required, two optional) -
2516: $domain - domain of new user
2517: $name - name of form element
2518: $default - Value of 'default' causes a default item to be first
2519: option, and selected by default.
2520: $hide - Value of 'hide' causes hiding of the name of the server,
2521: if 1 server found, or default, if 0 found.
1.594 raeburn 2522: output: returns 2 items:
1.586 raeburn 2523: (a) form element which contains either:
2524: (i) <select name="$name">
2525: <option value="$hostid1">$hostid $servers{$hostid}</option>
2526: <option value="$hostid2">$hostid $servers{$hostid}</option>
2527: </select>
2528: form item if there are multiple library servers in $domain, or
2529: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2530: if there is only one library server in $domain.
2531:
2532: (b) number of library servers found.
2533:
2534: See loncreateuser.pm for example of use.
1.35 matthew 2535:
2536: =cut
2537:
2538: #-------------------------------------------
1.586 raeburn 2539: sub home_server_form_item {
2540: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2541: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2542: my $result;
2543: my $numlib = keys(%servers);
2544: if ($numlib > 1) {
2545: $result .= '<select name="'.$name.'" />'."\n";
2546: if ($default) {
1.804 bisitz 2547: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2548: '</option>'."\n";
2549: }
2550: foreach my $hostid (sort(keys(%servers))) {
2551: $result.= '<option value="'.$hostid.'">'.
2552: $hostid.' '.$servers{$hostid}."</option>\n";
2553: }
2554: $result .= '</select>'."\n";
2555: } elsif ($numlib == 1) {
2556: my $hostid;
2557: foreach my $item (keys(%servers)) {
2558: $hostid = $item;
2559: }
2560: $result .= '<input type="hidden" name="'.$name.'" value="'.
2561: $hostid.'" />';
2562: if (!$hide) {
2563: $result .= $hostid.' '.$servers{$hostid};
2564: }
2565: $result .= "\n";
2566: } elsif ($default) {
2567: $result .= '<input type="hidden" name="'.$name.
2568: '" value="default" />';
2569: if (!$hide) {
2570: $result .= &mt('default');
2571: }
2572: $result .= "\n";
1.33 matthew 2573: }
1.586 raeburn 2574: return ($result,$numlib);
1.33 matthew 2575: }
1.112 bowersj2 2576:
2577: =pod
2578:
1.534 albertel 2579: =back
2580:
1.112 bowersj2 2581: =cut
1.87 matthew 2582:
2583: ###############################################################
1.112 bowersj2 2584: ## Decoding User Agent ##
1.87 matthew 2585: ###############################################################
2586:
2587: =pod
2588:
1.112 bowersj2 2589: =head1 Decoding the User Agent
2590:
2591: =over 4
2592:
2593: =item * &decode_user_agent()
1.87 matthew 2594:
2595: Inputs: $r
2596:
2597: Outputs:
2598:
2599: =over 4
2600:
1.112 bowersj2 2601: =item * $httpbrowser
1.87 matthew 2602:
1.112 bowersj2 2603: =item * $clientbrowser
1.87 matthew 2604:
1.112 bowersj2 2605: =item * $clientversion
1.87 matthew 2606:
1.112 bowersj2 2607: =item * $clientmathml
1.87 matthew 2608:
1.112 bowersj2 2609: =item * $clientunicode
1.87 matthew 2610:
1.112 bowersj2 2611: =item * $clientos
1.87 matthew 2612:
1.1075.2.42 raeburn 2613: =item * $clientmobile
2614:
2615: =item * $clientinfo
2616:
1.1075.2.77 raeburn 2617: =item * $clientosversion
2618:
1.87 matthew 2619: =back
2620:
1.157 matthew 2621: =back
2622:
1.87 matthew 2623: =cut
2624:
2625: ###############################################################
2626: ###############################################################
2627: sub decode_user_agent {
1.247 albertel 2628: my ($r)=@_;
1.87 matthew 2629: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2630: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2631: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2632: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2633: my $clientbrowser='unknown';
2634: my $clientversion='0';
2635: my $clientmathml='';
2636: my $clientunicode='0';
1.1075.2.42 raeburn 2637: my $clientmobile=0;
1.1075.2.77 raeburn 2638: my $clientosversion='';
1.87 matthew 2639: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2640: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2641: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2642: $clientbrowser=$bname;
2643: $httpbrowser=~/$vreg/i;
2644: $clientversion=$1;
2645: $clientmathml=($clientversion>=$minv);
2646: $clientunicode=($clientversion>=$univ);
2647: }
2648: }
2649: my $clientos='unknown';
1.1075.2.42 raeburn 2650: my $clientinfo;
1.87 matthew 2651: if (($httpbrowser=~/linux/i) ||
2652: ($httpbrowser=~/unix/i) ||
2653: ($httpbrowser=~/ux/i) ||
2654: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2655: if (($httpbrowser=~/vax/i) ||
2656: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2657: if ($httpbrowser=~/next/i) { $clientos='next'; }
2658: if (($httpbrowser=~/mac/i) ||
2659: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2660: if ($httpbrowser=~/win/i) {
2661: $clientos='win';
2662: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2663: $clientosversion = $1;
2664: }
2665: }
1.87 matthew 2666: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2667: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2668: $clientmobile=lc($1);
2669: }
2670: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2671: $clientinfo = 'firefox-'.$1;
2672: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2673: $clientinfo = 'chromeframe-'.$1;
2674: }
1.87 matthew 2675: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2676: $clientunicode,$clientos,$clientmobile,$clientinfo,
2677: $clientosversion);
1.87 matthew 2678: }
2679:
1.32 matthew 2680: ###############################################################
2681: ## Authentication changing form generation subroutines ##
2682: ###############################################################
2683: ##
2684: ## All of the authform_xxxxxxx subroutines take their inputs in a
2685: ## hash, and have reasonable default values.
2686: ##
2687: ## formname = the name given in the <form> tag.
1.35 matthew 2688: #-------------------------------------------
2689:
1.45 matthew 2690: =pod
2691:
1.112 bowersj2 2692: =head1 Authentication Routines
2693:
2694: =over 4
2695:
1.648 raeburn 2696: =item * &authform_xxxxxx()
1.35 matthew 2697:
2698: The authform_xxxxxx subroutines provide javascript and html forms which
2699: handle some of the conveniences required for authentication forms.
2700: This is not an optimal method, but it works.
2701:
2702: =over 4
2703:
1.112 bowersj2 2704: =item * authform_header
1.35 matthew 2705:
1.112 bowersj2 2706: =item * authform_authorwarning
1.35 matthew 2707:
1.112 bowersj2 2708: =item * authform_nochange
1.35 matthew 2709:
1.112 bowersj2 2710: =item * authform_kerberos
1.35 matthew 2711:
1.112 bowersj2 2712: =item * authform_internal
1.35 matthew 2713:
1.112 bowersj2 2714: =item * authform_filesystem
1.35 matthew 2715:
2716: =back
2717:
1.648 raeburn 2718: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2719:
1.35 matthew 2720: =cut
2721:
2722: #-------------------------------------------
1.32 matthew 2723: sub authform_header{
2724: my %in = (
2725: formname => 'cu',
1.80 albertel 2726: kerb_def_dom => '',
1.32 matthew 2727: @_,
2728: );
2729: $in{'formname'} = 'document.' . $in{'formname'};
2730: my $result='';
1.80 albertel 2731:
2732: #---------------------------------------------- Code for upper case translation
2733: my $Javascript_toUpperCase;
2734: unless ($in{kerb_def_dom}) {
2735: $Javascript_toUpperCase =<<"END";
2736: switch (choice) {
2737: case 'krb': currentform.elements[choicearg].value =
2738: currentform.elements[choicearg].value.toUpperCase();
2739: break;
2740: default:
2741: }
2742: END
2743: } else {
2744: $Javascript_toUpperCase = "";
2745: }
2746:
1.165 raeburn 2747: my $radioval = "'nochange'";
1.591 raeburn 2748: if (defined($in{'curr_authtype'})) {
2749: if ($in{'curr_authtype'} ne '') {
2750: $radioval = "'".$in{'curr_authtype'}."arg'";
2751: }
1.174 matthew 2752: }
1.165 raeburn 2753: my $argfield = 'null';
1.591 raeburn 2754: if (defined($in{'mode'})) {
1.165 raeburn 2755: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2756: if (defined($in{'curr_autharg'})) {
2757: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2758: $argfield = "'$in{'curr_autharg'}'";
2759: }
2760: }
2761: }
2762: }
2763:
1.32 matthew 2764: $result.=<<"END";
2765: var current = new Object();
1.165 raeburn 2766: current.radiovalue = $radioval;
2767: current.argfield = $argfield;
1.32 matthew 2768:
2769: function changed_radio(choice,currentform) {
2770: var choicearg = choice + 'arg';
2771: // If a radio button in changed, we need to change the argfield
2772: if (current.radiovalue != choice) {
2773: current.radiovalue = choice;
2774: if (current.argfield != null) {
2775: currentform.elements[current.argfield].value = '';
2776: }
2777: if (choice == 'nochange') {
2778: current.argfield = null;
2779: } else {
2780: current.argfield = choicearg;
2781: switch(choice) {
2782: case 'krb':
2783: currentform.elements[current.argfield].value =
2784: "$in{'kerb_def_dom'}";
2785: break;
2786: default:
2787: break;
2788: }
2789: }
2790: }
2791: return;
2792: }
1.22 www 2793:
1.32 matthew 2794: function changed_text(choice,currentform) {
2795: var choicearg = choice + 'arg';
2796: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2797: $Javascript_toUpperCase
1.32 matthew 2798: // clear old field
2799: if ((current.argfield != choicearg) && (current.argfield != null)) {
2800: currentform.elements[current.argfield].value = '';
2801: }
2802: current.argfield = choicearg;
2803: }
2804: set_auth_radio_buttons(choice,currentform);
2805: return;
1.20 www 2806: }
1.32 matthew 2807:
2808: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2809: var numauthchoices = currentform.login.length;
2810: if (typeof numauthchoices == "undefined") {
2811: return;
2812: }
1.32 matthew 2813: var i=0;
1.986 raeburn 2814: while (i < numauthchoices) {
1.32 matthew 2815: if (currentform.login[i].value == newvalue) { break; }
2816: i++;
2817: }
1.986 raeburn 2818: if (i == numauthchoices) {
1.32 matthew 2819: return;
2820: }
2821: current.radiovalue = newvalue;
2822: currentform.login[i].checked = true;
2823: return;
2824: }
2825: END
2826: return $result;
2827: }
2828:
1.1075.2.20 raeburn 2829: sub authform_authorwarning {
1.32 matthew 2830: my $result='';
1.144 matthew 2831: $result='<i>'.
2832: &mt('As a general rule, only authors or co-authors should be '.
2833: 'filesystem authenticated '.
2834: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2835: return $result;
2836: }
2837:
1.1075.2.20 raeburn 2838: sub authform_nochange {
1.32 matthew 2839: my %in = (
2840: formname => 'document.cu',
2841: kerb_def_dom => 'MSU.EDU',
2842: @_,
2843: );
1.1075.2.20 raeburn 2844: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2845: my $result;
1.1075.2.20 raeburn 2846: if (!$authnum) {
2847: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2848: } else {
2849: $result = '<label>'.&mt('[_1] Do not change login data',
2850: '<input type="radio" name="login" value="nochange" '.
2851: 'checked="checked" onclick="'.
1.281 albertel 2852: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2853: '</label>';
1.586 raeburn 2854: }
1.32 matthew 2855: return $result;
2856: }
2857:
1.591 raeburn 2858: sub authform_kerberos {
1.32 matthew 2859: my %in = (
2860: formname => 'document.cu',
2861: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2862: kerb_def_auth => 'krb4',
1.32 matthew 2863: @_,
2864: );
1.586 raeburn 2865: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2866: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2867: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2868: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2869: $check5 = ' checked="checked"';
1.80 albertel 2870: } else {
1.772 bisitz 2871: $check4 = ' checked="checked"';
1.80 albertel 2872: }
1.1075.2.117 raeburn 2873: if ($in{'readonly'}) {
2874: $disabled = ' disabled="disabled"';
2875: }
1.165 raeburn 2876: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2877: if (defined($in{'curr_authtype'})) {
2878: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2879: $krbcheck = ' checked="checked"';
1.623 raeburn 2880: if (defined($in{'mode'})) {
2881: if ($in{'mode'} eq 'modifyuser') {
2882: $krbcheck = '';
2883: }
2884: }
1.591 raeburn 2885: if (defined($in{'curr_kerb_ver'})) {
2886: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2887: $check5 = ' checked="checked"';
1.591 raeburn 2888: $check4 = '';
2889: } else {
1.772 bisitz 2890: $check4 = ' checked="checked"';
1.591 raeburn 2891: $check5 = '';
2892: }
1.586 raeburn 2893: }
1.591 raeburn 2894: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2895: $krbarg = $in{'curr_autharg'};
2896: }
1.586 raeburn 2897: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2898: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2899: $result =
2900: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2901: $in{'curr_autharg'},$krbver);
2902: } else {
2903: $result =
2904: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2905: }
2906: return $result;
2907: }
2908: }
2909: } else {
2910: if ($authnum == 1) {
1.784 bisitz 2911: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2912: }
2913: }
1.586 raeburn 2914: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2915: return;
1.587 raeburn 2916: } elsif ($authtype eq '') {
1.591 raeburn 2917: if (defined($in{'mode'})) {
1.587 raeburn 2918: if ($in{'mode'} eq 'modifycourse') {
2919: if ($authnum == 1) {
1.1075.2.117 raeburn 2920: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2921: }
2922: }
2923: }
1.586 raeburn 2924: }
2925: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2926: if ($authtype eq '') {
2927: $authtype = '<input type="radio" name="login" value="krb" '.
2928: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2929: $krbcheck.$disabled.' />';
1.586 raeburn 2930: }
2931: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2932: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2933: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2934: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2935: $in{'curr_authtype'} eq 'krb4')) {
2936: $result .= &mt
1.144 matthew 2937: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2938: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2939: '<label>'.$authtype,
1.281 albertel 2940: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2941: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2942: 'onchange="'.$jscall.'"'.$disabled.' />',
2943: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2944: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2945: '</label>');
1.586 raeburn 2946: } elsif ($can_assign{'krb4'}) {
2947: $result .= &mt
2948: ('[_1] Kerberos authenticated with domain [_2] '.
2949: '[_3] Version 4 [_4]',
2950: '<label>'.$authtype,
2951: '</label><input type="text" size="10" name="krbarg" '.
2952: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2953: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2954: '<label><input type="hidden" name="krbver" value="4" />',
2955: '</label>');
2956: } elsif ($can_assign{'krb5'}) {
2957: $result .= &mt
2958: ('[_1] Kerberos authenticated with domain [_2] '.
2959: '[_3] Version 5 [_4]',
2960: '<label>'.$authtype,
2961: '</label><input type="text" size="10" name="krbarg" '.
2962: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2963: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2964: '<label><input type="hidden" name="krbver" value="5" />',
2965: '</label>');
2966: }
1.32 matthew 2967: return $result;
2968: }
2969:
1.1075.2.20 raeburn 2970: sub authform_internal {
1.586 raeburn 2971: my %in = (
1.32 matthew 2972: formname => 'document.cu',
2973: kerb_def_dom => 'MSU.EDU',
2974: @_,
2975: );
1.1075.2.117 raeburn 2976: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2977: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2978: if ($in{'readonly'}) {
2979: $disabled = ' disabled="disabled"';
2980: }
1.591 raeburn 2981: if (defined($in{'curr_authtype'})) {
2982: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2983: if ($can_assign{'int'}) {
1.772 bisitz 2984: $intcheck = 'checked="checked" ';
1.623 raeburn 2985: if (defined($in{'mode'})) {
2986: if ($in{'mode'} eq 'modifyuser') {
2987: $intcheck = '';
2988: }
2989: }
1.591 raeburn 2990: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2991: $intarg = $in{'curr_autharg'};
2992: }
2993: } else {
2994: $result = &mt('Currently internally authenticated.');
2995: return $result;
1.165 raeburn 2996: }
2997: }
1.586 raeburn 2998: } else {
2999: if ($authnum == 1) {
1.784 bisitz 3000: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3001: }
3002: }
3003: if (!$can_assign{'int'}) {
3004: return;
1.587 raeburn 3005: } elsif ($authtype eq '') {
1.591 raeburn 3006: if (defined($in{'mode'})) {
1.587 raeburn 3007: if ($in{'mode'} eq 'modifycourse') {
3008: if ($authnum == 1) {
1.1075.2.117 raeburn 3009: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3010: }
3011: }
3012: }
1.165 raeburn 3013: }
1.586 raeburn 3014: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3015: if ($authtype eq '') {
3016: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3017: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3018: }
1.605 bisitz 3019: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3020: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3021: $result = &mt
1.144 matthew 3022: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3023: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3024: $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 3025: return $result;
3026: }
3027:
1.1075.2.20 raeburn 3028: sub authform_local {
1.32 matthew 3029: my %in = (
3030: formname => 'document.cu',
3031: kerb_def_dom => 'MSU.EDU',
3032: @_,
3033: );
1.1075.2.117 raeburn 3034: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3035: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3036: if ($in{'readonly'}) {
3037: $disabled = ' disabled="disabled"';
3038: }
1.591 raeburn 3039: if (defined($in{'curr_authtype'})) {
3040: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3041: if ($can_assign{'loc'}) {
1.772 bisitz 3042: $loccheck = 'checked="checked" ';
1.623 raeburn 3043: if (defined($in{'mode'})) {
3044: if ($in{'mode'} eq 'modifyuser') {
3045: $loccheck = '';
3046: }
3047: }
1.591 raeburn 3048: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3049: $locarg = $in{'curr_autharg'};
3050: }
3051: } else {
3052: $result = &mt('Currently using local (institutional) authentication.');
3053: return $result;
1.165 raeburn 3054: }
3055: }
1.586 raeburn 3056: } else {
3057: if ($authnum == 1) {
1.784 bisitz 3058: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3059: }
3060: }
3061: if (!$can_assign{'loc'}) {
3062: return;
1.587 raeburn 3063: } elsif ($authtype eq '') {
1.591 raeburn 3064: if (defined($in{'mode'})) {
1.587 raeburn 3065: if ($in{'mode'} eq 'modifycourse') {
3066: if ($authnum == 1) {
1.1075.2.117 raeburn 3067: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3068: }
3069: }
3070: }
1.165 raeburn 3071: }
1.586 raeburn 3072: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3073: if ($authtype eq '') {
3074: $authtype = '<input type="radio" name="login" value="loc" '.
3075: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3076: $jscall.'"'.$disabled.' />';
1.586 raeburn 3077: }
3078: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3079: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3080: $result = &mt('[_1] Local Authentication with argument [_2]',
3081: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3082: return $result;
3083: }
3084:
1.1075.2.20 raeburn 3085: sub authform_filesystem {
1.32 matthew 3086: my %in = (
3087: formname => 'document.cu',
3088: kerb_def_dom => 'MSU.EDU',
3089: @_,
3090: );
1.1075.2.117 raeburn 3091: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3092: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3093: if ($in{'readonly'}) {
3094: $disabled = ' disabled="disabled"';
3095: }
1.591 raeburn 3096: if (defined($in{'curr_authtype'})) {
3097: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3098: if ($can_assign{'fsys'}) {
1.772 bisitz 3099: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3100: if (defined($in{'mode'})) {
3101: if ($in{'mode'} eq 'modifyuser') {
3102: $fsyscheck = '';
3103: }
3104: }
1.586 raeburn 3105: } else {
3106: $result = &mt('Currently Filesystem Authenticated.');
3107: return $result;
3108: }
3109: }
3110: } else {
3111: if ($authnum == 1) {
1.784 bisitz 3112: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3113: }
3114: }
3115: if (!$can_assign{'fsys'}) {
3116: return;
1.587 raeburn 3117: } elsif ($authtype eq '') {
1.591 raeburn 3118: if (defined($in{'mode'})) {
1.587 raeburn 3119: if ($in{'mode'} eq 'modifycourse') {
3120: if ($authnum == 1) {
1.1075.2.117 raeburn 3121: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3122: }
3123: }
3124: }
1.586 raeburn 3125: }
3126: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3127: if ($authtype eq '') {
3128: $authtype = '<input type="radio" name="login" value="fsys" '.
3129: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3130: $jscall.'"'.$disabled.' />';
1.586 raeburn 3131: }
3132: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3133: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3134: $result = &mt
1.144 matthew 3135: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3136: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3137: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3138: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3139: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3140: return $result;
3141: }
3142:
1.586 raeburn 3143: sub get_assignable_auth {
3144: my ($dom) = @_;
3145: if ($dom eq '') {
3146: $dom = $env{'request.role.domain'};
3147: }
3148: my %can_assign = (
3149: krb4 => 1,
3150: krb5 => 1,
3151: int => 1,
3152: loc => 1,
3153: );
3154: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3155: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3156: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3157: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3158: my $context;
3159: if ($env{'request.role'} =~ /^au/) {
3160: $context = 'author';
1.1075.2.117 raeburn 3161: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3162: $context = 'domain';
3163: } elsif ($env{'request.course.id'}) {
3164: $context = 'course';
3165: }
3166: if ($context) {
3167: if (ref($authhash->{$context}) eq 'HASH') {
3168: %can_assign = %{$authhash->{$context}};
3169: }
3170: }
3171: }
3172: }
3173: my $authnum = 0;
3174: foreach my $key (keys(%can_assign)) {
3175: if ($can_assign{$key}) {
3176: $authnum ++;
3177: }
3178: }
3179: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3180: $authnum --;
3181: }
3182: return ($authnum,%can_assign);
3183: }
3184:
1.1075.2.137 raeburn 3185: sub check_passwd_rules {
3186: my ($domain,$plainpass) = @_;
3187: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3188: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3189: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3190: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3191: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3192: if ($passwdconf{'min'} > $min) {
3193: $min = $passwdconf{'min'};
3194: }
1.1075.2.137 raeburn 3195: }
3196: if ($passwdconf{'max'} =~ /^\d+$/) {
3197: $max = $passwdconf{'max'};
3198: }
3199: @chars = @{$passwdconf{'chars'}};
3200: }
3201: if (($min) && (length($plainpass) < $min)) {
3202: push(@brokerule,'min');
3203: }
3204: if (($max) && (length($plainpass) > $max)) {
3205: push(@brokerule,'max');
3206: }
3207: if (@chars) {
3208: my %rules;
3209: map { $rules{$_} = 1; } @chars;
3210: if ($rules{'uc'}) {
3211: unless ($plainpass =~ /[A-Z]/) {
3212: push(@brokerule,'uc');
3213: }
3214: }
3215: if ($rules{'lc'}) {
3216: unless ($plainpass =~ /[a-z]/) {
3217: push(@brokerule,'lc');
3218: }
3219: }
3220: if ($rules{'num'}) {
3221: unless ($plainpass =~ /\d/) {
3222: push(@brokerule,'num');
3223: }
3224: }
3225: if ($rules{'spec'}) {
3226: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3227: push(@brokerule,'spec');
3228: }
3229: }
3230: }
3231: if (@brokerule) {
3232: my %rulenames = &Apache::lonlocal::texthash(
3233: uc => 'At least one upper case letter',
3234: lc => 'At least one lower case letter',
3235: num => 'At least one number',
3236: spec => 'At least one non-alphanumeric',
3237: );
3238: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3239: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3240: $rulenames{'num'} .= ': 0123456789';
3241: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3242: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3243: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3244: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.141. .3(raebu 3245:20): foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3246: if (grep(/^$rule$/,@brokerule)) {
3247: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3248: }
3249: }
3250: $warning .= '</ul>';
3251: }
3252: if (wantarray) {
3253: return @brokerule;
3254: }
3255: return $warning;
3256: }
3257:
1.80 albertel 3258: ###############################################################
3259: ## Get Kerberos Defaults for Domain ##
3260: ###############################################################
3261: ##
3262: ## Returns default kerberos version and an associated argument
3263: ## as listed in file domain.tab. If not listed, provides
3264: ## appropriate default domain and kerberos version.
3265: ##
3266: #-------------------------------------------
3267:
3268: =pod
3269:
1.648 raeburn 3270: =item * &get_kerberos_defaults()
1.80 albertel 3271:
3272: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3273: version and domain. If not found, it defaults to version 4 and the
3274: domain of the server.
1.80 albertel 3275:
1.648 raeburn 3276: =over 4
3277:
1.80 albertel 3278: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3279:
1.648 raeburn 3280: =back
3281:
3282: =back
3283:
1.80 albertel 3284: =cut
3285:
3286: #-------------------------------------------
3287: sub get_kerberos_defaults {
3288: my $domain=shift;
1.641 raeburn 3289: my ($krbdef,$krbdefdom);
3290: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3291: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3292: $krbdef = $domdefaults{'auth_def'};
3293: $krbdefdom = $domdefaults{'auth_arg_def'};
3294: } else {
1.80 albertel 3295: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3296: my $krbdefdom=$1;
3297: $krbdefdom=~tr/a-z/A-Z/;
3298: $krbdef = "krb4";
3299: }
3300: return ($krbdef,$krbdefdom);
3301: }
1.112 bowersj2 3302:
1.32 matthew 3303:
1.46 matthew 3304: ###############################################################
3305: ## Thesaurus Functions ##
3306: ###############################################################
1.20 www 3307:
1.46 matthew 3308: =pod
1.20 www 3309:
1.112 bowersj2 3310: =head1 Thesaurus Functions
3311:
3312: =over 4
3313:
1.648 raeburn 3314: =item * &initialize_keywords()
1.46 matthew 3315:
3316: Initializes the package variable %Keywords if it is empty. Uses the
3317: package variable $thesaurus_db_file.
3318:
3319: =cut
3320:
3321: ###################################################
3322:
3323: sub initialize_keywords {
3324: return 1 if (scalar keys(%Keywords));
3325: # If we are here, %Keywords is empty, so fill it up
3326: # Make sure the file we need exists...
3327: if (! -e $thesaurus_db_file) {
3328: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3329: " failed because it does not exist");
3330: return 0;
3331: }
3332: # Set up the hash as a database
3333: my %thesaurus_db;
3334: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3335: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3336: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3337: $thesaurus_db_file);
3338: return 0;
3339: }
3340: # Get the average number of appearances of a word.
3341: my $avecount = $thesaurus_db{'average.count'};
3342: # Put keywords (those that appear > average) into %Keywords
3343: while (my ($word,$data)=each (%thesaurus_db)) {
3344: my ($count,undef) = split /:/,$data;
3345: $Keywords{$word}++ if ($count > $avecount);
3346: }
3347: untie %thesaurus_db;
3348: # Remove special values from %Keywords.
1.356 albertel 3349: foreach my $value ('total.count','average.count') {
3350: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3351: }
1.46 matthew 3352: return 1;
3353: }
3354:
3355: ###################################################
3356:
3357: =pod
3358:
1.648 raeburn 3359: =item * &keyword($word)
1.46 matthew 3360:
3361: Returns true if $word is a keyword. A keyword is a word that appears more
3362: than the average number of times in the thesaurus database. Calls
3363: &initialize_keywords
3364:
3365: =cut
3366:
3367: ###################################################
1.20 www 3368:
3369: sub keyword {
1.46 matthew 3370: return if (!&initialize_keywords());
3371: my $word=lc(shift());
3372: $word=~s/\W//g;
3373: return exists($Keywords{$word});
1.20 www 3374: }
1.46 matthew 3375:
3376: ###############################################################
3377:
3378: =pod
1.20 www 3379:
1.648 raeburn 3380: =item * &get_related_words()
1.46 matthew 3381:
1.160 matthew 3382: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3383: an array of words. If the keyword is not in the thesaurus, an empty array
3384: will be returned. The order of the words returned is determined by the
3385: database which holds them.
3386:
3387: Uses global $thesaurus_db_file.
3388:
1.1057 foxr 3389:
1.46 matthew 3390: =cut
3391:
3392: ###############################################################
3393: sub get_related_words {
3394: my $keyword = shift;
3395: my %thesaurus_db;
3396: if (! -e $thesaurus_db_file) {
3397: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3398: "failed because the file does not exist");
3399: return ();
3400: }
3401: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3402: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3403: return ();
3404: }
3405: my @Words=();
1.429 www 3406: my $count=0;
1.46 matthew 3407: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3408: # The first element is the number of times
3409: # the word appears. We do not need it now.
1.429 www 3410: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3411: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3412: my $threshold=$mostfrequentcount/10;
3413: foreach my $possibleword (@RelatedWords) {
3414: my ($word,$wordcount)=split(/\,/,$possibleword);
3415: if ($wordcount>$threshold) {
3416: push(@Words,$word);
3417: $count++;
3418: if ($count>10) { last; }
3419: }
1.20 www 3420: }
3421: }
1.46 matthew 3422: untie %thesaurus_db;
3423: return @Words;
1.14 harris41 3424: }
1.46 matthew 3425:
1.112 bowersj2 3426: =pod
3427:
3428: =back
3429:
3430: =cut
1.61 www 3431:
3432: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3433: =pod
3434:
1.112 bowersj2 3435: =head1 User Name Functions
3436:
3437: =over 4
3438:
1.648 raeburn 3439: =item * &plainname($uname,$udom,$first)
1.81 albertel 3440:
1.112 bowersj2 3441: Takes a users logon name and returns it as a string in
1.226 albertel 3442: "first middle last generation" form
3443: if $first is set to 'lastname' then it returns it as
3444: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3445:
3446: =cut
1.61 www 3447:
1.295 www 3448:
1.81 albertel 3449: ###############################################################
1.61 www 3450: sub plainname {
1.226 albertel 3451: my ($uname,$udom,$first)=@_;
1.537 albertel 3452: return if (!defined($uname) || !defined($udom));
1.295 www 3453: my %names=&getnames($uname,$udom);
1.226 albertel 3454: my $name=&Apache::lonnet::format_name($names{'firstname'},
3455: $names{'middlename'},
3456: $names{'lastname'},
3457: $names{'generation'},$first);
3458: $name=~s/^\s+//;
1.62 www 3459: $name=~s/\s+$//;
3460: $name=~s/\s+/ /g;
1.353 albertel 3461: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3462: return $name;
1.61 www 3463: }
1.66 www 3464:
3465: # -------------------------------------------------------------------- Nickname
1.81 albertel 3466: =pod
3467:
1.648 raeburn 3468: =item * &nickname($uname,$udom)
1.81 albertel 3469:
3470: Gets a users name and returns it as a string as
3471:
3472: ""nickname""
1.66 www 3473:
1.81 albertel 3474: if the user has a nickname or
3475:
3476: "first middle last generation"
3477:
3478: if the user does not
3479:
3480: =cut
1.66 www 3481:
3482: sub nickname {
3483: my ($uname,$udom)=@_;
1.537 albertel 3484: return if (!defined($uname) || !defined($udom));
1.295 www 3485: my %names=&getnames($uname,$udom);
1.68 albertel 3486: my $name=$names{'nickname'};
1.66 www 3487: if ($name) {
3488: $name='"'.$name.'"';
3489: } else {
3490: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3491: $names{'lastname'}.' '.$names{'generation'};
3492: $name=~s/\s+$//;
3493: $name=~s/\s+/ /g;
3494: }
3495: return $name;
3496: }
3497:
1.295 www 3498: sub getnames {
3499: my ($uname,$udom)=@_;
1.537 albertel 3500: return if (!defined($uname) || !defined($udom));
1.433 albertel 3501: if ($udom eq 'public' && $uname eq 'public') {
3502: return ('lastname' => &mt('Public'));
3503: }
1.295 www 3504: my $id=$uname.':'.$udom;
3505: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3506: if ($cached) {
3507: return %{$names};
3508: } else {
3509: my %loadnames=&Apache::lonnet::get('environment',
3510: ['firstname','middlename','lastname','generation','nickname'],
3511: $udom,$uname);
3512: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3513: return %loadnames;
3514: }
3515: }
1.61 www 3516:
1.542 raeburn 3517: # -------------------------------------------------------------------- getemails
1.648 raeburn 3518:
1.542 raeburn 3519: =pod
3520:
1.648 raeburn 3521: =item * &getemails($uname,$udom)
1.542 raeburn 3522:
3523: Gets a user's email information and returns it as a hash with keys:
3524: notification, critnotification, permanentemail
3525:
3526: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3527: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3528:
1.648 raeburn 3529:
1.542 raeburn 3530: =cut
3531:
1.648 raeburn 3532:
1.466 albertel 3533: sub getemails {
3534: my ($uname,$udom)=@_;
3535: if ($udom eq 'public' && $uname eq 'public') {
3536: return;
3537: }
1.467 www 3538: if (!$udom) { $udom=$env{'user.domain'}; }
3539: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3540: my $id=$uname.':'.$udom;
3541: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3542: if ($cached) {
3543: return %{$names};
3544: } else {
3545: my %loadnames=&Apache::lonnet::get('environment',
3546: ['notification','critnotification',
3547: 'permanentemail'],
3548: $udom,$uname);
3549: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3550: return %loadnames;
3551: }
3552: }
3553:
1.551 albertel 3554: sub flush_email_cache {
3555: my ($uname,$udom)=@_;
3556: if (!$udom) { $udom =$env{'user.domain'}; }
3557: if (!$uname) { $uname=$env{'user.name'}; }
3558: return if ($udom eq 'public' && $uname eq 'public');
3559: my $id=$uname.':'.$udom;
3560: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3561: }
3562:
1.728 raeburn 3563: # -------------------------------------------------------------------- getlangs
3564:
3565: =pod
3566:
3567: =item * &getlangs($uname,$udom)
3568:
3569: Gets a user's language preference and returns it as a hash with key:
3570: language.
3571:
3572: =cut
3573:
3574:
3575: sub getlangs {
3576: my ($uname,$udom) = @_;
3577: if (!$udom) { $udom =$env{'user.domain'}; }
3578: if (!$uname) { $uname=$env{'user.name'}; }
3579: my $id=$uname.':'.$udom;
3580: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3581: if ($cached) {
3582: return %{$langs};
3583: } else {
3584: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3585: $udom,$uname);
3586: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3587: return %loadlangs;
3588: }
3589: }
3590:
3591: sub flush_langs_cache {
3592: my ($uname,$udom)=@_;
3593: if (!$udom) { $udom =$env{'user.domain'}; }
3594: if (!$uname) { $uname=$env{'user.name'}; }
3595: return if ($udom eq 'public' && $uname eq 'public');
3596: my $id=$uname.':'.$udom;
3597: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3598: }
3599:
1.61 www 3600: # ------------------------------------------------------------------ Screenname
1.81 albertel 3601:
3602: =pod
3603:
1.648 raeburn 3604: =item * &screenname($uname,$udom)
1.81 albertel 3605:
3606: Gets a users screenname and returns it as a string
3607:
3608: =cut
1.61 www 3609:
3610: sub screenname {
3611: my ($uname,$udom)=@_;
1.258 albertel 3612: if ($uname eq $env{'user.name'} &&
3613: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3614: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3615: return $names{'screenname'};
1.62 www 3616: }
3617:
1.212 albertel 3618:
1.802 bisitz 3619: # ------------------------------------------------------------- Confirm Wrapper
3620: =pod
3621:
1.1075.2.42 raeburn 3622: =item * &confirmwrapper($message)
1.802 bisitz 3623:
3624: Wrap messages about completion of operation in box
3625:
3626: =cut
3627:
3628: sub confirmwrapper {
3629: my ($message)=@_;
3630: if ($message) {
3631: return "\n".'<div class="LC_confirm_box">'."\n"
3632: .$message."\n"
3633: .'</div>'."\n";
3634: } else {
3635: return $message;
3636: }
3637: }
3638:
1.62 www 3639: # ------------------------------------------------------------- Message Wrapper
3640:
3641: sub messagewrapper {
1.369 www 3642: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3643: return
1.441 albertel 3644: '<a href="/adm/email?compose=individual&'.
3645: 'recname='.$username.'&recdom='.$domain.
3646: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3647: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3648: }
1.802 bisitz 3649:
1.74 www 3650: # --------------------------------------------------------------- Notes Wrapper
3651:
3652: sub noteswrapper {
3653: my ($link,$un,$do)=@_;
3654: return
1.896 amueller 3655: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3656: }
1.802 bisitz 3657:
1.62 www 3658: # ------------------------------------------------------------- Aboutme Wrapper
3659:
3660: sub aboutmewrapper {
1.1070 raeburn 3661: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3662: if (!defined($username) && !defined($domain)) {
3663: return;
3664: }
1.1075.2.15 raeburn 3665: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3666: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3667: }
3668:
3669: # ------------------------------------------------------------ Syllabus Wrapper
3670:
3671: sub syllabuswrapper {
1.707 bisitz 3672: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3673: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3674: }
1.14 harris41 3675:
1.802 bisitz 3676: # -----------------------------------------------------------------------------
3677:
1.208 matthew 3678: sub track_student_link {
1.887 raeburn 3679: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3680: my $link ="/adm/trackstudent?";
1.208 matthew 3681: my $title = 'View recent activity';
3682: if (defined($sname) && $sname !~ /^\s*$/ &&
3683: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3684: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3685: $title .= ' of this student';
1.268 albertel 3686: }
1.208 matthew 3687: if (defined($target) && $target !~ /^\s*$/) {
3688: $target = qq{target="$target"};
3689: } else {
3690: $target = '';
3691: }
1.268 albertel 3692: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3693: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3694: $title = &mt($title);
3695: $linktext = &mt($linktext);
1.448 albertel 3696: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3697: &help_open_topic('View_recent_activity');
1.208 matthew 3698: }
3699:
1.781 raeburn 3700: sub slot_reservations_link {
3701: my ($linktext,$sname,$sdom,$target) = @_;
3702: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3703: my $title = 'View slot reservation history';
3704: if (defined($sname) && $sname !~ /^\s*$/ &&
3705: defined($sdom) && $sdom !~ /^\s*$/) {
3706: $link .= "&uname=$sname&udom=$sdom";
3707: $title .= ' of this student';
3708: }
3709: if (defined($target) && $target !~ /^\s*$/) {
3710: $target = qq{target="$target"};
3711: } else {
3712: $target = '';
3713: }
3714: $title = &mt($title);
3715: $linktext = &mt($linktext);
3716: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3717: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3718:
3719: }
3720:
1.508 www 3721: # ===================================================== Display a student photo
3722:
3723:
1.509 albertel 3724: sub student_image_tag {
1.508 www 3725: my ($domain,$user)=@_;
3726: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3727: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3728: return '<img src="'.$imgsrc.'" align="right" />';
3729: } else {
3730: return '';
3731: }
3732: }
3733:
1.112 bowersj2 3734: =pod
3735:
3736: =back
3737:
3738: =head1 Access .tab File Data
3739:
3740: =over 4
3741:
1.648 raeburn 3742: =item * &languageids()
1.112 bowersj2 3743:
3744: returns list of all language ids
3745:
3746: =cut
3747:
1.14 harris41 3748: sub languageids {
1.16 harris41 3749: return sort(keys(%language));
1.14 harris41 3750: }
3751:
1.112 bowersj2 3752: =pod
3753:
1.648 raeburn 3754: =item * &languagedescription()
1.112 bowersj2 3755:
3756: returns description of a specified language id
3757:
3758: =cut
3759:
1.14 harris41 3760: sub languagedescription {
1.125 www 3761: my $code=shift;
3762: return ($supported_language{$code}?'* ':'').
3763: $language{$code}.
1.126 www 3764: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3765: }
3766:
1.1048 foxr 3767: =pod
3768:
3769: =item * &plainlanguagedescription
3770:
3771: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3772: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3773:
3774: =cut
3775:
1.145 www 3776: sub plainlanguagedescription {
3777: my $code=shift;
3778: return $language{$code};
3779: }
3780:
1.1048 foxr 3781: =pod
3782:
3783: =item * &supportedlanguagecode
3784:
3785: Returns the supported language code (e.g. sptutf maps to pt) given a language
3786: code.
3787:
3788: =cut
3789:
1.145 www 3790: sub supportedlanguagecode {
3791: my $code=shift;
3792: return $supported_language{$code};
1.97 www 3793: }
3794:
1.112 bowersj2 3795: =pod
3796:
1.1048 foxr 3797: =item * &latexlanguage()
3798:
3799: Given a language key code returns the correspondnig language to use
3800: to select the correct hyphenation on LaTeX printouts. This is undef if there
3801: is no supported hyphenation for the language code.
3802:
3803: =cut
3804:
3805: sub latexlanguage {
3806: my $code = shift;
3807: return $latex_language{$code};
3808: }
3809:
3810: =pod
3811:
3812: =item * &latexhyphenation()
3813:
3814: Same as above but what's supplied is the language as it might be stored
3815: in the metadata.
3816:
3817: =cut
3818:
3819: sub latexhyphenation {
3820: my $key = shift;
3821: return $latex_language_bykey{$key};
3822: }
3823:
3824: =pod
3825:
1.648 raeburn 3826: =item * ©rightids()
1.112 bowersj2 3827:
3828: returns list of all copyrights
3829:
3830: =cut
3831:
3832: sub copyrightids {
3833: return sort(keys(%cprtag));
3834: }
3835:
3836: =pod
3837:
1.648 raeburn 3838: =item * ©rightdescription()
1.112 bowersj2 3839:
3840: returns description of a specified copyright id
3841:
3842: =cut
3843:
3844: sub copyrightdescription {
1.166 www 3845: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3846: }
1.197 matthew 3847:
3848: =pod
3849:
1.648 raeburn 3850: =item * &source_copyrightids()
1.192 taceyjo1 3851:
3852: returns list of all source copyrights
3853:
3854: =cut
3855:
3856: sub source_copyrightids {
3857: return sort(keys(%scprtag));
3858: }
3859:
3860: =pod
3861:
1.648 raeburn 3862: =item * &source_copyrightdescription()
1.192 taceyjo1 3863:
3864: returns description of a specified source copyright id
3865:
3866: =cut
3867:
3868: sub source_copyrightdescription {
3869: return &mt($scprtag{shift(@_)});
3870: }
1.112 bowersj2 3871:
3872: =pod
3873:
1.648 raeburn 3874: =item * &filecategories()
1.112 bowersj2 3875:
3876: returns list of all file categories
3877:
3878: =cut
3879:
3880: sub filecategories {
3881: return sort(keys(%category_extensions));
3882: }
3883:
3884: =pod
3885:
1.648 raeburn 3886: =item * &filecategorytypes()
1.112 bowersj2 3887:
3888: returns list of file types belonging to a given file
3889: category
3890:
3891: =cut
3892:
3893: sub filecategorytypes {
1.356 albertel 3894: my ($cat) = @_;
3895: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3896: }
3897:
3898: =pod
3899:
1.648 raeburn 3900: =item * &fileembstyle()
1.112 bowersj2 3901:
3902: returns embedding style for a specified file type
3903:
3904: =cut
3905:
3906: sub fileembstyle {
3907: return $fe{lc(shift(@_))};
1.169 www 3908: }
3909:
1.351 www 3910: sub filemimetype {
3911: return $fm{lc(shift(@_))};
3912: }
3913:
1.169 www 3914:
3915: sub filecategoryselect {
3916: my ($name,$value)=@_;
1.189 matthew 3917: return &select_form($value,$name,
1.970 raeburn 3918: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3919: }
3920:
3921: =pod
3922:
1.648 raeburn 3923: =item * &filedescription()
1.112 bowersj2 3924:
3925: returns description for a specified file type
3926:
3927: =cut
3928:
3929: sub filedescription {
1.188 matthew 3930: my $file_description = $fd{lc(shift())};
3931: $file_description =~ s:([\[\]]):~$1:g;
3932: return &mt($file_description);
1.112 bowersj2 3933: }
3934:
3935: =pod
3936:
1.648 raeburn 3937: =item * &filedescriptionex()
1.112 bowersj2 3938:
3939: returns description for a specified file type with
3940: extra formatting
3941:
3942: =cut
3943:
3944: sub filedescriptionex {
3945: my $ex=shift;
1.188 matthew 3946: my $file_description = $fd{lc($ex)};
3947: $file_description =~ s:([\[\]]):~$1:g;
3948: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3949: }
3950:
3951: # End of .tab access
3952: =pod
3953:
3954: =back
3955:
3956: =cut
3957:
3958: # ------------------------------------------------------------------ File Types
3959: sub fileextensions {
3960: return sort(keys(%fe));
3961: }
3962:
1.97 www 3963: # ----------------------------------------------------------- Display Languages
3964: # returns a hash with all desired display languages
3965: #
3966:
3967: sub display_languages {
3968: my %languages=();
1.695 raeburn 3969: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3970: $languages{$lang}=1;
1.97 www 3971: }
3972: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3973: if ($env{'form.displaylanguage'}) {
1.356 albertel 3974: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3975: $languages{$lang}=1;
1.97 www 3976: }
3977: }
3978: return %languages;
1.14 harris41 3979: }
3980:
1.582 albertel 3981: sub languages {
3982: my ($possible_langs) = @_;
1.695 raeburn 3983: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3984: if (!ref($possible_langs)) {
3985: if( wantarray ) {
3986: return @preferred_langs;
3987: } else {
3988: return $preferred_langs[0];
3989: }
3990: }
3991: my %possibilities = map { $_ => 1 } (@$possible_langs);
3992: my @preferred_possibilities;
3993: foreach my $preferred_lang (@preferred_langs) {
3994: if (exists($possibilities{$preferred_lang})) {
3995: push(@preferred_possibilities, $preferred_lang);
3996: }
3997: }
3998: if( wantarray ) {
3999: return @preferred_possibilities;
4000: }
4001: return $preferred_possibilities[0];
4002: }
4003:
1.742 raeburn 4004: sub user_lang {
4005: my ($touname,$toudom,$fromcid) = @_;
4006: my @userlangs;
4007: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4008: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4009: $env{'course.'.$fromcid.'.languages'}));
4010: } else {
4011: my %langhash = &getlangs($touname,$toudom);
4012: if ($langhash{'languages'} ne '') {
4013: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4014: } else {
4015: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4016: if ($domdefs{'lang_def'} ne '') {
4017: @userlangs = ($domdefs{'lang_def'});
4018: }
4019: }
4020: }
4021: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4022: my $user_lh = Apache::localize->get_handle(@languages);
4023: return $user_lh;
4024: }
4025:
4026:
1.112 bowersj2 4027: ###############################################################
4028: ## Student Answer Attempts ##
4029: ###############################################################
4030:
4031: =pod
4032:
4033: =head1 Alternate Problem Views
4034:
4035: =over 4
4036:
1.648 raeburn 4037: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4038: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4039:
4040: Return string with previous attempt on problem. Arguments:
4041:
4042: =over 4
4043:
4044: =item * $symb: Problem, including path
4045:
4046: =item * $username: username of the desired student
4047:
4048: =item * $domain: domain of the desired student
1.14 harris41 4049:
1.112 bowersj2 4050: =item * $course: Course ID
1.14 harris41 4051:
1.112 bowersj2 4052: =item * $getattempt: Leave blank for all attempts, otherwise put
4053: something
1.14 harris41 4054:
1.112 bowersj2 4055: =item * $regexp: if string matches this regexp, the string will be
4056: sent to $gradesub
1.14 harris41 4057:
1.112 bowersj2 4058: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4059:
1.1075.2.86 raeburn 4060: =item * $usec: section of the desired student
4061:
4062: =item * $identifier: counter for student (multiple students one problem) or
4063: problem (one student; whole sequence).
4064:
1.112 bowersj2 4065: =back
1.14 harris41 4066:
1.112 bowersj2 4067: The output string is a table containing all desired attempts, if any.
1.16 harris41 4068:
1.112 bowersj2 4069: =cut
1.1 albertel 4070:
4071: sub get_previous_attempt {
1.1075.2.86 raeburn 4072: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4073: my $prevattempts='';
1.43 ng 4074: no strict 'refs';
1.1 albertel 4075: if ($symb) {
1.3 albertel 4076: my (%returnhash)=
4077: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4078: if ($returnhash{'version'}) {
4079: my %lasthash=();
4080: my $version;
4081: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4082: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4083: if ($key =~ /\.rawrndseed$/) {
4084: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4085: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4086: } else {
4087: $lasthash{$key}=$returnhash{$version.':'.$key};
4088: }
1.19 harris41 4089: }
1.1 albertel 4090: }
1.596 albertel 4091: $prevattempts=&start_data_table().&start_data_table_header_row();
4092: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4093: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4094: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4095: foreach my $key (sort(keys(%lasthash))) {
4096: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4097: if ($#parts > 0) {
1.31 albertel 4098: my $data=$parts[-1];
1.989 raeburn 4099: next if ($data eq 'foilorder');
1.31 albertel 4100: pop(@parts);
1.1010 www 4101: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4102: if ($data eq 'type') {
4103: unless ($showsurv) {
4104: my $id = join(',',@parts);
4105: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4106: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4107: $lasthidden{$ign.'.'.$id} = 1;
4108: }
1.945 raeburn 4109: }
1.1075.2.86 raeburn 4110: if ($identifier ne '') {
4111: my $id = join(',',@parts);
4112: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4113: $domain,$username,$usec,undef,$course) =~ /^no/) {
4114: $hidestatus{$ign.'.'.$id} = 1;
4115: }
4116: }
4117: } elsif ($data eq 'regrader') {
4118: if (($identifier ne '') && (@parts)) {
4119: my $id = join(',',@parts);
4120: $regraded{$ign.'.'.$id} = 1;
4121: }
1.1010 www 4122: }
1.31 albertel 4123: } else {
1.41 ng 4124: if ($#parts == 0) {
4125: $prevattempts.='<th>'.$parts[0].'</th>';
4126: } else {
4127: $prevattempts.='<th>'.$ign.'</th>';
4128: }
1.31 albertel 4129: }
1.16 harris41 4130: }
1.596 albertel 4131: $prevattempts.=&end_data_table_header_row();
1.40 ng 4132: if ($getattempt eq '') {
1.1075.2.86 raeburn 4133: my (%solved,%resets,%probstatus);
4134: if (($identifier ne '') && (keys(%regraded) > 0)) {
4135: for ($version=1;$version<=$returnhash{'version'};$version++) {
4136: foreach my $id (keys(%regraded)) {
4137: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4138: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4139: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4140: push(@{$resets{$id}},$version);
4141: }
4142: }
4143: }
4144: }
1.40 ng 4145: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4146: my (@hidden,@unsolved);
1.945 raeburn 4147: if (%typeparts) {
4148: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4149: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4150: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4151: push(@hidden,$id);
1.1075.2.86 raeburn 4152: } elsif ($identifier ne '') {
4153: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4154: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4155: ($hidestatus{$id})) {
4156: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4157: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4158: push(@{$solved{$id}},$version);
4159: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4160: (ref($solved{$id}) eq 'ARRAY')) {
4161: my $skip;
4162: if (ref($resets{$id}) eq 'ARRAY') {
4163: foreach my $reset (@{$resets{$id}}) {
4164: if ($reset > $solved{$id}[-1]) {
4165: $skip=1;
4166: last;
4167: }
4168: }
4169: }
4170: unless ($skip) {
4171: my ($ign,$partslist) = split(/\./,$id,2);
4172: push(@unsolved,$partslist);
4173: }
4174: }
4175: }
1.945 raeburn 4176: }
4177: }
4178: }
4179: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4180: '<td>'.&mt('Transaction [_1]',$version);
4181: if (@unsolved) {
4182: $prevattempts .= '<span class="LC_nobreak"><label>'.
4183: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4184: &mt('Hide').'</label></span>';
4185: }
4186: $prevattempts .= '</td>';
1.945 raeburn 4187: if (@hidden) {
4188: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4189: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4190: my $hide;
4191: foreach my $id (@hidden) {
4192: if ($key =~ /^\Q$id\E/) {
4193: $hide = 1;
4194: last;
4195: }
4196: }
4197: if ($hide) {
4198: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4199: if (($data eq 'award') || ($data eq 'awarddetail')) {
4200: my $value = &format_previous_attempt_value($key,
4201: $returnhash{$version.':'.$key});
4202: $prevattempts.='<td>'.$value.' </td>';
4203: } else {
4204: $prevattempts.='<td> </td>';
4205: }
4206: } else {
4207: if ($key =~ /\./) {
1.1075.2.91 raeburn 4208: my $value = $returnhash{$version.':'.$key};
4209: if ($key =~ /\.rndseed$/) {
4210: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4211: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4212: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4213: }
4214: }
4215: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4216: ' </td>';
1.945 raeburn 4217: } else {
4218: $prevattempts.='<td> </td>';
4219: }
4220: }
4221: }
4222: } else {
4223: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4224: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4225: my $value = $returnhash{$version.':'.$key};
4226: if ($key =~ /\.rndseed$/) {
4227: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4228: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4229: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4230: }
4231: }
4232: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4233: ' </td>';
1.945 raeburn 4234: }
4235: }
4236: $prevattempts.=&end_data_table_row();
1.40 ng 4237: }
1.1 albertel 4238: }
1.945 raeburn 4239: my @currhidden = keys(%lasthidden);
1.596 albertel 4240: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4241: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4242: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4243: if (%typeparts) {
4244: my $hidden;
4245: foreach my $id (@currhidden) {
4246: if ($key =~ /^\Q$id\E/) {
4247: $hidden = 1;
4248: last;
4249: }
4250: }
4251: if ($hidden) {
4252: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4253: if (($data eq 'award') || ($data eq 'awarddetail')) {
4254: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4255: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4256: $value = &$gradesub($value);
4257: }
4258: $prevattempts.='<td>'.$value.' </td>';
4259: } else {
4260: $prevattempts.='<td> </td>';
4261: }
4262: } else {
4263: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4264: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4265: $value = &$gradesub($value);
4266: }
4267: $prevattempts.='<td>'.$value.' </td>';
4268: }
4269: } else {
4270: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4271: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4272: $value = &$gradesub($value);
4273: }
4274: $prevattempts.='<td>'.$value.' </td>';
4275: }
1.16 harris41 4276: }
1.596 albertel 4277: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4278: } else {
1.596 albertel 4279: $prevattempts=
4280: &start_data_table().&start_data_table_row().
4281: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4282: &end_data_table_row().&end_data_table();
1.1 albertel 4283: }
4284: } else {
1.596 albertel 4285: $prevattempts=
4286: &start_data_table().&start_data_table_row().
4287: '<td>'.&mt('No data.').'</td>'.
4288: &end_data_table_row().&end_data_table();
1.1 albertel 4289: }
1.10 albertel 4290: }
4291:
1.581 albertel 4292: sub format_previous_attempt_value {
4293: my ($key,$value) = @_;
1.1011 www 4294: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4295: $value = &Apache::lonlocal::locallocaltime($value);
4296: } elsif (ref($value) eq 'ARRAY') {
4297: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4298: } elsif ($key =~ /answerstring$/) {
4299: my %answers = &Apache::lonnet::str2hash($value);
4300: my @anskeys = sort(keys(%answers));
4301: if (@anskeys == 1) {
4302: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4303: if ($answer =~ m{\0}) {
4304: $answer =~ s{\0}{,}g;
1.988 raeburn 4305: }
4306: my $tag_internal_answer_name = 'INTERNAL';
4307: if ($anskeys[0] eq $tag_internal_answer_name) {
4308: $value = $answer;
4309: } else {
4310: $value = $anskeys[0].'='.$answer;
4311: }
4312: } else {
4313: foreach my $ans (@anskeys) {
4314: my $answer = $answers{$ans};
1.1001 raeburn 4315: if ($answer =~ m{\0}) {
4316: $answer =~ s{\0}{,}g;
1.988 raeburn 4317: }
4318: $value .= $ans.'='.$answer.'<br />';;
4319: }
4320: }
1.581 albertel 4321: } else {
4322: $value = &unescape($value);
4323: }
4324: return $value;
4325: }
4326:
4327:
1.107 albertel 4328: sub relative_to_absolute {
4329: my ($url,$output)=@_;
4330: my $parser=HTML::TokeParser->new(\$output);
4331: my $token;
4332: my $thisdir=$url;
4333: my @rlinks=();
4334: while ($token=$parser->get_token) {
4335: if ($token->[0] eq 'S') {
4336: if ($token->[1] eq 'a') {
4337: if ($token->[2]->{'href'}) {
4338: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4339: }
4340: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4341: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4342: } elsif ($token->[1] eq 'base') {
4343: $thisdir=$token->[2]->{'href'};
4344: }
4345: }
4346: }
4347: $thisdir=~s-/[^/]*$--;
1.356 albertel 4348: foreach my $link (@rlinks) {
1.726 raeburn 4349: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4350: ($link=~/^\//) ||
4351: ($link=~/^javascript:/i) ||
4352: ($link=~/^mailto:/i) ||
4353: ($link=~/^\#/)) {
4354: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4355: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4356: }
4357: }
4358: # -------------------------------------------------- Deal with Applet codebases
4359: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4360: return $output;
4361: }
4362:
1.112 bowersj2 4363: =pod
4364:
1.648 raeburn 4365: =item * &get_student_view()
1.112 bowersj2 4366:
4367: show a snapshot of what student was looking at
4368:
4369: =cut
4370:
1.10 albertel 4371: sub get_student_view {
1.186 albertel 4372: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4373: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4374: my (%form);
1.10 albertel 4375: my @elements=('symb','courseid','domain','username');
4376: foreach my $element (@elements) {
1.186 albertel 4377: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4378: }
1.186 albertel 4379: if (defined($moreenv)) {
4380: %form=(%form,%{$moreenv});
4381: }
1.236 albertel 4382: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4383: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4384: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4385: $userview=~s/\<body[^\>]*\>//gi;
4386: $userview=~s/\<\/body\>//gi;
4387: $userview=~s/\<html\>//gi;
4388: $userview=~s/\<\/html\>//gi;
4389: $userview=~s/\<head\>//gi;
4390: $userview=~s/\<\/head\>//gi;
4391: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4392: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4393: if (wantarray) {
4394: return ($userview,$response);
4395: } else {
4396: return $userview;
4397: }
4398: }
4399:
4400: sub get_student_view_with_retries {
4401: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4402:
4403: my $ok = 0; # True if we got a good response.
4404: my $content;
4405: my $response;
4406:
4407: # Try to get the student_view done. within the retries count:
4408:
4409: do {
4410: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4411: $ok = $response->is_success;
4412: if (!$ok) {
4413: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4414: }
4415: $retries--;
4416: } while (!$ok && ($retries > 0));
4417:
4418: if (!$ok) {
4419: $content = ''; # On error return an empty content.
4420: }
1.651 www 4421: if (wantarray) {
4422: return ($content, $response);
4423: } else {
4424: return $content;
4425: }
1.11 albertel 4426: }
4427:
1.1075.2.141. .10(raeb 4428:-20): sub css_links {
4429:-20): my ($currsymb,$level) = @_;
4430:-20): my ($links,@symbs,%cssrefs,%httpref);
4431:-20): if ($level eq 'map') {
4432:-20): my $navmap = Apache::lonnavmaps::navmap->new();
4433:-20): if (ref($navmap)) {
4434:-20): my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4435:-20): my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4436:-20): foreach my $res (@resources) {
4437:-20): if (ref($res) && $res->symb()) {
4438:-20): push(@symbs,$res->symb());
4439:-20): }
4440:-20): }
4441:-20): }
4442:-20): } else {
4443:-20): @symbs = ($currsymb);
4444:-20): }
4445:-20): foreach my $symb (@symbs) {
4446:-20): my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4447:-20): if ($css_href =~ /\S/) {
4448:-20): unless ($css_href =~ m{https?://}) {
4449:-20): my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4450:-20): my $proburl = &Apache::lonnet::clutter($url);
4451:-20): my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4452:-20): unless ($css_href =~ m{^/}) {
4453:-20): $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4454:-20): }
4455:-20): if ($css_href =~ m{^/(res|uploaded)/}) {
4456:-20): unless (($httpref{'httpref.'.$css_href}) ||
4457:-20): (&Apache::lonnet::is_on_map($css_href))) {
4458:-20): my $thisurl = $proburl;
4459:-20): if ($env{'httpref.'.$proburl}) {
4460:-20): $thisurl = $env{'httpref.'.$proburl};
4461:-20): }
4462:-20): $httpref{'httpref.'.$css_href} = $thisurl;
4463:-20): }
4464:-20): }
4465:-20): }
4466:-20): $cssrefs{$css_href} = 1;
4467:-20): }
4468:-20): }
4469:-20): if (keys(%httpref)) {
4470:-20): &Apache::lonnet::appenv(\%httpref);
4471:-20): }
4472:-20): if (keys(%cssrefs)) {
4473:-20): foreach my $css_href (keys(%cssrefs)) {
4474:-20): next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4475:-20): $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4476:-20): }
4477:-20): }
4478:-20): return $links;
4479:-20): }
4480:-20):
1.112 bowersj2 4481: =pod
4482:
1.648 raeburn 4483: =item * &get_student_answers()
1.112 bowersj2 4484:
4485: show a snapshot of how student was answering problem
4486:
4487: =cut
4488:
1.11 albertel 4489: sub get_student_answers {
1.100 sakharuk 4490: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4491: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4492: my (%moreenv);
1.11 albertel 4493: my @elements=('symb','courseid','domain','username');
4494: foreach my $element (@elements) {
1.186 albertel 4495: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4496: }
1.186 albertel 4497: $moreenv{'grade_target'}='answer';
4498: %moreenv=(%form,%moreenv);
1.497 raeburn 4499: $feedurl = &Apache::lonnet::clutter($feedurl);
4500: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4501: return $userview;
1.1 albertel 4502: }
1.116 albertel 4503:
4504: =pod
4505:
4506: =item * &submlink()
4507:
1.242 albertel 4508: Inputs: $text $uname $udom $symb $target
1.116 albertel 4509:
4510: Returns: A link to grades.pm such as to see the SUBM view of a student
4511:
4512: =cut
4513:
4514: ###############################################
4515: sub submlink {
1.242 albertel 4516: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4517: if (!($uname && $udom)) {
4518: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4519: &Apache::lonnet::whichuser($symb);
1.116 albertel 4520: if (!$symb) { $symb=$cursymb; }
4521: }
1.254 matthew 4522: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4523: $symb=&escape($symb);
1.960 bisitz 4524: if ($target) { $target=" target=\"$target\""; }
4525: return
4526: '<a href="/adm/grades?command=submission'.
4527: '&symb='.$symb.
4528: '&student='.$uname.
4529: '&userdom='.$udom.'"'.
4530: $target.'>'.$text.'</a>';
1.242 albertel 4531: }
4532: ##############################################
4533:
4534: =pod
4535:
4536: =item * &pgrdlink()
4537:
4538: Inputs: $text $uname $udom $symb $target
4539:
4540: Returns: A link to grades.pm such as to see the PGRD view of a student
4541:
4542: =cut
4543:
4544: ###############################################
4545: sub pgrdlink {
4546: my $link=&submlink(@_);
4547: $link=~s/(&command=submission)/$1&showgrading=yes/;
4548: return $link;
4549: }
4550: ##############################################
4551:
4552: =pod
4553:
4554: =item * &pprmlink()
4555:
4556: Inputs: $text $uname $udom $symb $target
4557:
4558: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4559: student and a specific resource
1.242 albertel 4560:
4561: =cut
4562:
4563: ###############################################
4564: sub pprmlink {
4565: my ($text,$uname,$udom,$symb,$target)=@_;
4566: if (!($uname && $udom)) {
4567: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4568: &Apache::lonnet::whichuser($symb);
1.242 albertel 4569: if (!$symb) { $symb=$cursymb; }
4570: }
1.254 matthew 4571: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4572: $symb=&escape($symb);
1.242 albertel 4573: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4574: return '<a href="/adm/parmset?command=set&'.
4575: 'symb='.$symb.'&uname='.$uname.
4576: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4577: }
4578: ##############################################
1.37 matthew 4579:
1.112 bowersj2 4580: =pod
4581:
4582: =back
4583:
4584: =cut
4585:
1.37 matthew 4586: ###############################################
1.51 www 4587:
4588:
4589: sub timehash {
1.687 raeburn 4590: my ($thistime) = @_;
4591: my $timezone = &Apache::lonlocal::gettimezone();
4592: my $dt = DateTime->from_epoch(epoch => $thistime)
4593: ->set_time_zone($timezone);
4594: my $wday = $dt->day_of_week();
4595: if ($wday == 7) { $wday = 0; }
4596: return ( 'second' => $dt->second(),
4597: 'minute' => $dt->minute(),
4598: 'hour' => $dt->hour(),
4599: 'day' => $dt->day_of_month(),
4600: 'month' => $dt->month(),
4601: 'year' => $dt->year(),
4602: 'weekday' => $wday,
4603: 'dayyear' => $dt->day_of_year(),
4604: 'dlsav' => $dt->is_dst() );
1.51 www 4605: }
4606:
1.370 www 4607: sub utc_string {
4608: my ($date)=@_;
1.371 www 4609: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4610: }
4611:
1.51 www 4612: sub maketime {
4613: my %th=@_;
1.687 raeburn 4614: my ($epoch_time,$timezone,$dt);
4615: $timezone = &Apache::lonlocal::gettimezone();
4616: eval {
4617: $dt = DateTime->new( year => $th{'year'},
4618: month => $th{'month'},
4619: day => $th{'day'},
4620: hour => $th{'hour'},
4621: minute => $th{'minute'},
4622: second => $th{'second'},
4623: time_zone => $timezone,
4624: );
4625: };
4626: if (!$@) {
4627: $epoch_time = $dt->epoch;
4628: if ($epoch_time) {
4629: return $epoch_time;
4630: }
4631: }
1.51 www 4632: return POSIX::mktime(
4633: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4634: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4635: }
4636:
4637: #########################################
1.51 www 4638:
4639: sub findallcourses {
1.482 raeburn 4640: my ($roles,$uname,$udom) = @_;
1.355 albertel 4641: my %roles;
4642: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4643: my %courses;
1.51 www 4644: my $now=time;
1.482 raeburn 4645: if (!defined($uname)) {
4646: $uname = $env{'user.name'};
4647: }
4648: if (!defined($udom)) {
4649: $udom = $env{'user.domain'};
4650: }
4651: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4652: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4653: if (!%roles) {
4654: %roles = (
4655: cc => 1,
1.907 raeburn 4656: co => 1,
1.482 raeburn 4657: in => 1,
4658: ep => 1,
4659: ta => 1,
4660: cr => 1,
4661: st => 1,
4662: );
4663: }
4664: foreach my $entry (keys(%roleshash)) {
4665: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4666: if ($trole =~ /^cr/) {
4667: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4668: } else {
4669: next if (!exists($roles{$trole}));
4670: }
4671: if ($tend) {
4672: next if ($tend < $now);
4673: }
4674: if ($tstart) {
4675: next if ($tstart > $now);
4676: }
1.1058 raeburn 4677: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4678: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4679: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4680: if ($secpart eq '') {
4681: ($cnum,$role) = split(/_/,$cnumpart);
4682: $sec = 'none';
1.1058 raeburn 4683: $value .= $cnum.'/';
1.482 raeburn 4684: } else {
4685: $cnum = $cnumpart;
4686: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4687: $value .= $cnum.'/'.$sec;
4688: }
4689: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4690: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4691: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4692: }
4693: } else {
4694: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4695: }
1.482 raeburn 4696: }
4697: } else {
4698: foreach my $key (keys(%env)) {
1.483 albertel 4699: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4700: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4701: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4702: next if ($role eq 'ca' || $role eq 'aa');
4703: next if (%roles && !exists($roles{$role}));
4704: my ($starttime,$endtime)=split(/\./,$env{$key});
4705: my $active=1;
4706: if ($starttime) {
4707: if ($now<$starttime) { $active=0; }
4708: }
4709: if ($endtime) {
4710: if ($now>$endtime) { $active=0; }
4711: }
4712: if ($active) {
1.1058 raeburn 4713: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4714: if ($sec eq '') {
4715: $sec = 'none';
1.1058 raeburn 4716: } else {
4717: $value .= $sec;
4718: }
4719: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4720: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4721: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4722: }
4723: } else {
4724: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4725: }
1.474 raeburn 4726: }
4727: }
1.51 www 4728: }
4729: }
1.474 raeburn 4730: return %courses;
1.51 www 4731: }
1.37 matthew 4732:
1.54 www 4733: ###############################################
1.474 raeburn 4734:
4735: sub blockcheck {
1.1075.2.141. .7(raebu 4736:20): my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4737:
1.1075.2.73 raeburn 4738: if (defined($udom) && defined($uname)) {
4739: # If uname and udom are for a course, check for blocks in the course.
4740: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4741: my ($startblock,$endblock,$triggerblock) =
1.1075.2.141. .7(raebu 4742:20): &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 4743: return ($startblock,$endblock,$triggerblock);
4744: }
4745: } else {
1.490 raeburn 4746: $udom = $env{'user.domain'};
4747: $uname = $env{'user.name'};
4748: }
4749:
1.502 raeburn 4750: my $startblock = 0;
4751: my $endblock = 0;
1.1062 raeburn 4752: my $triggerblock = '';
1.482 raeburn 4753: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4754:
1.490 raeburn 4755: # If uname is for a user, and activity is course-specific, i.e.,
4756: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4757:
1.490 raeburn 4758: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.141. .6(raebu 4759:20): $activity eq 'groups' || $activity eq 'printout' ||
.8(raebu 4760:20): $activity eq 'search' || $activity eq 'reinit' ||
4761:20): $activity eq 'alert') &&
1.1075.2.73 raeburn 4762: ($env{'request.course.id'})) {
1.490 raeburn 4763: foreach my $key (keys(%live_courses)) {
4764: if ($key ne $env{'request.course.id'}) {
4765: delete($live_courses{$key});
4766: }
4767: }
4768: }
4769:
4770: my $otheruser = 0;
4771: my %own_courses;
4772: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4773: # Resource belongs to user other than current user.
4774: $otheruser = 1;
4775: # Gather courses for current user
4776: %own_courses =
4777: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4778: }
4779:
4780: # Gather active course roles - course coordinator, instructor,
4781: # exam proctor, ta, student, or custom role.
1.474 raeburn 4782:
4783: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4784: my ($cdom,$cnum);
4785: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4786: $cdom = $env{'course.'.$course.'.domain'};
4787: $cnum = $env{'course.'.$course.'.num'};
4788: } else {
1.490 raeburn 4789: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4790: }
4791: my $no_ownblock = 0;
4792: my $no_userblock = 0;
1.533 raeburn 4793: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4794: # Check if current user has 'evb' priv for this
4795: if (defined($own_courses{$course})) {
4796: foreach my $sec (keys(%{$own_courses{$course}})) {
4797: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4798: if ($sec ne 'none') {
4799: $checkrole .= '/'.$sec;
4800: }
4801: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4802: $no_ownblock = 1;
4803: last;
4804: }
4805: }
4806: }
4807: # if they have 'evb' priv and are currently not playing student
4808: next if (($no_ownblock) &&
4809: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4810: }
1.474 raeburn 4811: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4812: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4813: if ($sec ne 'none') {
1.482 raeburn 4814: $checkrole .= '/'.$sec;
1.474 raeburn 4815: }
1.490 raeburn 4816: if ($otheruser) {
4817: # Resource belongs to user other than current user.
4818: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4819: my (%allroles,%userroles);
4820: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4821: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4822: my ($trole,$tdom,$tnum,$tsec);
4823: if ($entry =~ /^cr/) {
4824: ($trole,$tdom,$tnum,$tsec) =
4825: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4826: } else {
4827: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4828: }
4829: my ($spec,$area,$trest);
4830: $area = '/'.$tdom.'/'.$tnum;
4831: $trest = $tnum;
4832: if ($tsec ne '') {
4833: $area .= '/'.$tsec;
4834: $trest .= '/'.$tsec;
4835: }
4836: $spec = $trole.'.'.$area;
4837: if ($trole =~ /^cr/) {
4838: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4839: $tdom,$spec,$trest,$area);
4840: } else {
4841: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4842: $tdom,$spec,$trest,$area);
4843: }
4844: }
1.1075.2.124 raeburn 4845: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4846: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4847: if ($1) {
4848: $no_userblock = 1;
4849: last;
4850: }
1.486 raeburn 4851: }
4852: }
1.490 raeburn 4853: } else {
4854: # Resource belongs to current user
4855: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4856: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4857: $no_ownblock = 1;
4858: last;
4859: }
1.474 raeburn 4860: }
4861: }
4862: # if they have the evb priv and are currently not playing student
1.482 raeburn 4863: next if (($no_ownblock) &&
1.491 albertel 4864: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4865: next if ($no_userblock);
1.474 raeburn 4866:
1.1075.2.128 raeburn 4867: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4868: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4869:
1.1062 raeburn 4870: my ($start,$end,$trigger) =
1.1075.2.141. .7(raebu 4871:20): &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 4872: if (($start != 0) &&
4873: (($startblock == 0) || ($startblock > $start))) {
4874: $startblock = $start;
1.1062 raeburn 4875: if ($trigger ne '') {
4876: $triggerblock = $trigger;
4877: }
1.502 raeburn 4878: }
4879: if (($end != 0) &&
4880: (($endblock == 0) || ($endblock < $end))) {
4881: $endblock = $end;
1.1062 raeburn 4882: if ($trigger ne '') {
4883: $triggerblock = $trigger;
4884: }
1.502 raeburn 4885: }
1.490 raeburn 4886: }
1.1062 raeburn 4887: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4888: }
4889:
4890: sub get_blocks {
1.1075.2.141. .7(raebu 4891:20): my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 4892: my $startblock = 0;
4893: my $endblock = 0;
1.1062 raeburn 4894: my $triggerblock = '';
1.490 raeburn 4895: my $course = $cdom.'_'.$cnum;
4896: $setters->{$course} = {};
4897: $setters->{$course}{'staff'} = [];
4898: $setters->{$course}{'times'} = [];
1.1062 raeburn 4899: $setters->{$course}{'triggers'} = [];
4900: my (@blockers,%triggered);
4901: my $now = time;
4902: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4903: if ($activity eq 'docs') {
1.1075.2.141. .9(raebu 4904:20): my ($blocked,$nosymbcache,$noenccheck);
.7(raebu 4905:20): if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
4906:20): $blocked = 1;
4907:20): $nosymbcache = 1;
.9(raebu 4908:20): $noenccheck = 1;
.7(raebu 4909:20): }
.9(raebu 4910:20): @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 4911: foreach my $block (@blockers) {
4912: if ($block =~ /^firstaccess____(.+)$/) {
4913: my $item = $1;
4914: my $type = 'map';
4915: my $timersymb = $item;
4916: if ($item eq 'course') {
4917: $type = 'course';
4918: } elsif ($item =~ /___\d+___/) {
4919: $type = 'resource';
4920: } else {
4921: $timersymb = &Apache::lonnet::symbread($item);
4922: }
4923: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4924: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4925: $triggered{$block} = {
4926: start => $start,
4927: end => $end,
4928: type => $type,
4929: };
4930: }
4931: }
4932: } else {
4933: foreach my $block (keys(%commblocks)) {
4934: if ($block =~ m/^(\d+)____(\d+)$/) {
4935: my ($start,$end) = ($1,$2);
4936: if ($start <= time && $end >= time) {
4937: if (ref($commblocks{$block}) eq 'HASH') {
4938: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4939: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4940: unless(grep(/^\Q$block\E$/,@blockers)) {
4941: push(@blockers,$block);
4942: }
4943: }
4944: }
4945: }
4946: }
4947: } elsif ($block =~ /^firstaccess____(.+)$/) {
4948: my $item = $1;
4949: my $timersymb = $item;
4950: my $type = 'map';
4951: if ($item eq 'course') {
4952: $type = 'course';
4953: } elsif ($item =~ /___\d+___/) {
4954: $type = 'resource';
4955: } else {
4956: $timersymb = &Apache::lonnet::symbread($item);
4957: }
4958: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4959: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4960: if ($start && $end) {
4961: if (($start <= time) && ($end >= time)) {
4962: unless (grep(/^\Q$block\E$/,@blockers)) {
4963: push(@blockers,$block);
4964: $triggered{$block} = {
4965: start => $start,
4966: end => $end,
4967: type => $type,
4968: };
4969: }
4970: }
1.490 raeburn 4971: }
1.1062 raeburn 4972: }
4973: }
4974: }
4975: foreach my $blocker (@blockers) {
4976: my ($staff_name,$staff_dom,$title,$blocks) =
4977: &parse_block_record($commblocks{$blocker});
4978: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4979: my ($start,$end,$triggertype);
4980: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4981: ($start,$end) = ($1,$2);
4982: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4983: $start = $triggered{$blocker}{'start'};
4984: $end = $triggered{$blocker}{'end'};
4985: $triggertype = $triggered{$blocker}{'type'};
4986: }
4987: if ($start) {
4988: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4989: if ($triggertype) {
4990: push(@{$$setters{$course}{'triggers'}},$triggertype);
4991: } else {
4992: push(@{$$setters{$course}{'triggers'}},0);
4993: }
4994: if ( ($startblock == 0) || ($startblock > $start) ) {
4995: $startblock = $start;
4996: if ($triggertype) {
4997: $triggerblock = $blocker;
1.474 raeburn 4998: }
4999: }
1.1062 raeburn 5000: if ( ($endblock == 0) || ($endblock < $end) ) {
5001: $endblock = $end;
5002: if ($triggertype) {
5003: $triggerblock = $blocker;
5004: }
5005: }
1.474 raeburn 5006: }
5007: }
1.1062 raeburn 5008: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5009: }
5010:
5011: sub parse_block_record {
5012: my ($record) = @_;
5013: my ($setuname,$setudom,$title,$blocks);
5014: if (ref($record) eq 'HASH') {
5015: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5016: $title = &unescape($record->{'event'});
5017: $blocks = $record->{'blocks'};
5018: } else {
5019: my @data = split(/:/,$record,3);
5020: if (scalar(@data) eq 2) {
5021: $title = $data[1];
5022: ($setuname,$setudom) = split(/@/,$data[0]);
5023: } else {
5024: ($setuname,$setudom,$title) = @data;
5025: }
5026: $blocks = { 'com' => 'on' };
5027: }
5028: return ($setuname,$setudom,$title,$blocks);
5029: }
5030:
1.854 kalberla 5031: sub blocking_status {
1.1075.2.141. .7(raebu 5032:20): my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5033: my %setters;
1.890 droeschl 5034:
1.1061 raeburn 5035: # check for active blocking
1.1062 raeburn 5036: my ($startblock,$endblock,$triggerblock) =
1.1075.2.141. .7(raebu 5037:20): &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5038: my $blocked = 0;
5039: if ($startblock && $endblock) {
5040: $blocked = 1;
5041: }
1.890 droeschl 5042:
1.1061 raeburn 5043: # caller just wants to know whether a block is active
5044: if (!wantarray) { return $blocked; }
5045:
5046: # build a link to a popup window containing the details
5047: my $querystring = "?activity=$activity";
1.1075.2.141. .12(raeb 5048:-21): # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5049:-21): if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5050: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5051: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5052: } elsif ($activity eq 'docs') {
1.1075.2.141. .7(raebu 5053:20): my $showurl = &Apache::lonenc::check_encrypt($url);
5054:20): $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5055:20): if ($symb) {
5056:20): my $showsymb = &Apache::lonenc::check_encrypt($symb);
5057:20): $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5058:20): }
1.1062 raeburn 5059: }
1.1061 raeburn 5060:
5061: my $output .= <<'END_MYBLOCK';
5062: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5063: var options = "width=" + w + ",height=" + h + ",";
5064: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5065: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5066: var newWin = window.open(url, wdwName, options);
5067: newWin.focus();
5068: }
1.890 droeschl 5069: END_MYBLOCK
1.854 kalberla 5070:
1.1061 raeburn 5071: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5072:
1.1061 raeburn 5073: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5074: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5075: my $class = 'LC_comblock';
1.1062 raeburn 5076: if ($activity eq 'docs') {
5077: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5078: $class = '';
1.1063 raeburn 5079: } elsif ($activity eq 'printout') {
5080: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5081: } elsif ($activity eq 'passwd') {
5082: $text = &mt('Password Changing Blocked');
1.1075.2.141. .6(raebu 5083:20): } elsif ($activity eq 'grades') {
5084:20): $text = &mt('Gradebook Blocked');
.8(raebu 5085:20): } elsif ($activity eq 'search') {
5086:20): $text = &mt('Search Blocked');
.6(raebu 5087:20): } elsif ($activity eq 'alert') {
5088:20): $text = &mt('Checking Critical Messages Blocked');
5089:20): } elsif ($activity eq 'reinit') {
5090:20): $text = &mt('Checking Course Update Blocked');
.12(raeb 5091:-21): } elsif ($activity eq 'about') {
5092:-21): $text = &mt('Access to User Information Pages Blocked');
1.1062 raeburn 5093: }
1.1061 raeburn 5094: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5095: <div class='$class'>
1.869 kalberla 5096: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5097: title='$text'>
5098: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5099: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5100: title='$text'>$text</a>
1.867 kalberla 5101: </div>
5102:
5103: END_BLOCK
1.474 raeburn 5104:
1.1061 raeburn 5105: return ($blocked, $output);
1.854 kalberla 5106: }
1.490 raeburn 5107:
1.60 matthew 5108: ###############################################
5109:
1.682 raeburn 5110: sub check_ip_acc {
1.1075.2.105 raeburn 5111: my ($acc,$clientip)=@_;
1.682 raeburn 5112: &Apache::lonxml::debug("acc is $acc");
5113: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5114: return 1;
5115: }
1.1075.2.141. .4(raebu 5116:20): my ($ip,$allowed);
5117:20): if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5118:20): ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5119:20): $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5120:20): } else {
.11(raeb 5121:-21): my $remote_ip = &Apache::lonnet::get_requestor_ip();
5122:-21): $ip = $remote_ip || $env{'request.host'} || $clientip;
.4(raebu 5123:20): }
1.682 raeburn 5124:
5125: my $name;
1.1075.2.141. .1(raebu 5126:20): my %access = (
5127:20): allowfrom => 1,
5128:20): denyfrom => 0,
5129:20): );
5130:20): my @allows;
5131:20): my @denies;
5132:20): foreach my $item (split(',',$acc)) {
5133:20): $item =~ s/^\s*//;
5134:20): $item =~ s/\s*$//;
5135:20): if ($item =~ /^\!(.+)$/) {
5136:20): push(@denies,$1);
5137:20): } else {
5138:20): push(@allows,$item);
5139:20): }
5140:20): }
5141:20): my $numdenies = scalar(@denies);
5142:20): my $numallows = scalar(@allows);
5143:20): my $count = 0;
5144:20): foreach my $pattern (@denies,@allows) {
5145:20): $count ++;
5146:20): my $acctype = 'allowfrom';
5147:20): if ($count <= $numdenies) {
5148:20): $acctype = 'denyfrom';
5149:20): }
1.682 raeburn 5150: if ($pattern =~ /\*$/) {
5151: #35.8.*
5152: $pattern=~s/\*//;
1.1075.2.141. .1(raebu 5153:20): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5154: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5155: #35.8.3.[34-56]
5156: my $low=$2;
5157: my $high=$3;
5158: $pattern=$1;
5159: if ($ip =~ /^\Q$pattern\E/) {
5160: my $last=(split(/\./,$ip))[3];
1.1075.2.141. .1(raebu 5161:20): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5162: }
5163: } elsif ($pattern =~ /^\*/) {
5164: #*.msu.edu
5165: $pattern=~s/\*//;
5166: if (!defined($name)) {
5167: use Socket;
5168: my $netaddr=inet_aton($ip);
5169: ($name)=gethostbyaddr($netaddr,AF_INET);
5170: }
1.1075.2.141. .1(raebu 5171:20): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5172: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5173: #127.0.0.1
1.1075.2.141. .1(raebu 5174:20): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5175: } else {
5176: #some.name.com
5177: if (!defined($name)) {
5178: use Socket;
5179: my $netaddr=inet_aton($ip);
5180: ($name)=gethostbyaddr($netaddr,AF_INET);
5181: }
1.1075.2.141. .1(raebu 5182:20): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5183:20): }
5184:20): if ($allowed =~ /^(0|1)$/) { last; }
5185:20): }
5186:20): if ($allowed eq '') {
5187:20): if ($numdenies && !$numallows) {
5188:20): $allowed = 1;
5189:20): } else {
5190:20): $allowed = 0;
1.682 raeburn 5191: }
5192: }
5193: return $allowed;
5194: }
5195:
5196: ###############################################
5197:
1.60 matthew 5198: =pod
5199:
1.112 bowersj2 5200: =head1 Domain Template Functions
5201:
5202: =over 4
5203:
5204: =item * &determinedomain()
1.60 matthew 5205:
5206: Inputs: $domain (usually will be undef)
5207:
1.63 www 5208: Returns: Determines which domain should be used for designs
1.60 matthew 5209:
5210: =cut
1.54 www 5211:
1.60 matthew 5212: ###############################################
1.63 www 5213: sub determinedomain {
5214: my $domain=shift;
1.531 albertel 5215: if (! $domain) {
1.60 matthew 5216: # Determine domain if we have not been given one
1.893 raeburn 5217: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5218: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5219: if ($env{'request.role.domain'}) {
5220: $domain=$env{'request.role.domain'};
1.60 matthew 5221: }
5222: }
1.63 www 5223: return $domain;
5224: }
5225: ###############################################
1.517 raeburn 5226:
1.518 albertel 5227: sub devalidate_domconfig_cache {
5228: my ($udom)=@_;
5229: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5230: }
5231:
5232: # ---------------------- Get domain configuration for a domain
5233: sub get_domainconf {
5234: my ($udom) = @_;
5235: my $cachetime=1800;
5236: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5237: if (defined($cached)) { return %{$result}; }
5238:
5239: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5240: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5241: my (%designhash,%legacy);
1.518 albertel 5242: if (keys(%domconfig) > 0) {
5243: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5244: if (keys(%{$domconfig{'login'}})) {
5245: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5246: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5247: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5248: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5249: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5250: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5251: if ($key eq 'loginvia') {
5252: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5253: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5254: $designhash{$udom.'.login.loginvia'} = $server;
5255: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5256: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5257: } else {
5258: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5259: }
1.948 raeburn 5260: }
1.1075.2.87 raeburn 5261: } elsif ($key eq 'headtag') {
5262: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5263: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5264: }
1.946 raeburn 5265: }
1.1075.2.87 raeburn 5266: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5267: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5268: }
1.946 raeburn 5269: }
5270: }
5271: }
5272: } else {
5273: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5274: $designhash{$udom.'.login.'.$key.'_'.$img} =
5275: $domconfig{'login'}{$key}{$img};
5276: }
1.699 raeburn 5277: }
5278: } else {
5279: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5280: }
1.632 raeburn 5281: }
5282: } else {
5283: $legacy{'login'} = 1;
1.518 albertel 5284: }
1.632 raeburn 5285: } else {
5286: $legacy{'login'} = 1;
1.518 albertel 5287: }
5288: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5289: if (keys(%{$domconfig{'rolecolors'}})) {
5290: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5291: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5292: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5293: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5294: }
1.518 albertel 5295: }
5296: }
1.632 raeburn 5297: } else {
5298: $legacy{'rolecolors'} = 1;
1.518 albertel 5299: }
1.632 raeburn 5300: } else {
5301: $legacy{'rolecolors'} = 1;
1.518 albertel 5302: }
1.948 raeburn 5303: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5304: if ($domconfig{'autoenroll'}{'co-owners'}) {
5305: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5306: }
5307: }
1.632 raeburn 5308: if (keys(%legacy) > 0) {
5309: my %legacyhash = &get_legacy_domconf($udom);
5310: foreach my $item (keys(%legacyhash)) {
5311: if ($item =~ /^\Q$udom\E\.login/) {
5312: if ($legacy{'login'}) {
5313: $designhash{$item} = $legacyhash{$item};
5314: }
5315: } else {
5316: if ($legacy{'rolecolors'}) {
5317: $designhash{$item} = $legacyhash{$item};
5318: }
1.518 albertel 5319: }
5320: }
5321: }
1.632 raeburn 5322: } else {
5323: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5324: }
5325: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5326: $cachetime);
5327: return %designhash;
5328: }
5329:
1.632 raeburn 5330: sub get_legacy_domconf {
5331: my ($udom) = @_;
5332: my %legacyhash;
5333: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5334: my $designfile = $designdir.'/'.$udom.'.tab';
5335: if (-e $designfile) {
1.1075.2.128 raeburn 5336: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5337: while (my $line = <$fh>) {
5338: next if ($line =~ /^\#/);
5339: chomp($line);
5340: my ($key,$val)=(split(/\=/,$line));
5341: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5342: }
5343: close($fh);
5344: }
5345: }
1.1026 raeburn 5346: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5347: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5348: }
5349: return %legacyhash;
5350: }
5351:
1.63 www 5352: =pod
5353:
1.112 bowersj2 5354: =item * &domainlogo()
1.63 www 5355:
5356: Inputs: $domain (usually will be undef)
5357:
5358: Returns: A link to a domain logo, if the domain logo exists.
5359: If the domain logo does not exist, a description of the domain.
5360:
5361: =cut
1.112 bowersj2 5362:
1.63 www 5363: ###############################################
5364: sub domainlogo {
1.517 raeburn 5365: my $domain = &determinedomain(shift);
1.518 albertel 5366: my %designhash = &get_domainconf($domain);
1.517 raeburn 5367: # See if there is a logo
5368: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5369: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5370: if ($imgsrc =~ m{^/(adm|res)/}) {
5371: if ($imgsrc =~ m{^/res/}) {
5372: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5373: &Apache::lonnet::repcopy($local_name);
5374: }
5375: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5376: }
5377: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5378: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5379: return &Apache::lonnet::domain($domain,'description');
1.59 www 5380: } else {
1.60 matthew 5381: return '';
1.59 www 5382: }
5383: }
1.63 www 5384: ##############################################
5385:
5386: =pod
5387:
1.112 bowersj2 5388: =item * &designparm()
1.63 www 5389:
5390: Inputs: $which parameter; $domain (usually will be undef)
5391:
5392: Returns: value of designparamter $which
5393:
5394: =cut
1.112 bowersj2 5395:
1.397 albertel 5396:
1.400 albertel 5397: ##############################################
1.397 albertel 5398: sub designparm {
5399: my ($which,$domain)=@_;
5400: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5401: return $env{'environment.color.'.$which};
1.96 www 5402: }
1.63 www 5403: $domain=&determinedomain($domain);
1.1016 raeburn 5404: my %domdesign;
5405: unless ($domain eq 'public') {
5406: %domdesign = &get_domainconf($domain);
5407: }
1.520 raeburn 5408: my $output;
1.517 raeburn 5409: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5410: $output = $domdesign{$domain.'.'.$which};
1.63 www 5411: } else {
1.520 raeburn 5412: $output = $defaultdesign{$which};
5413: }
5414: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5415: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5416: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5417: if ($output =~ m{^/res/}) {
5418: my $local_name = &Apache::lonnet::filelocation('',$output);
5419: &Apache::lonnet::repcopy($local_name);
5420: }
1.520 raeburn 5421: $output = &lonhttpdurl($output);
5422: }
1.63 www 5423: }
1.520 raeburn 5424: return $output;
1.63 www 5425: }
1.59 www 5426:
1.822 bisitz 5427: ##############################################
5428: =pod
5429:
1.832 bisitz 5430: =item * &authorspace()
5431:
1.1028 raeburn 5432: Inputs: $url (usually will be undef).
1.832 bisitz 5433:
1.1075.2.40 raeburn 5434: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5435: directory being viewed (or for which action is being taken).
5436: If $url is provided, and begins /priv/<domain>/<uname>
5437: the path will be that portion of the $context argument.
5438: Otherwise the path will be for the author space of the current
5439: user when the current role is author, or for that of the
5440: co-author/assistant co-author space when the current role
5441: is co-author or assistant co-author.
1.832 bisitz 5442:
5443: =cut
5444:
5445: sub authorspace {
1.1028 raeburn 5446: my ($url) = @_;
5447: if ($url ne '') {
5448: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5449: return $1;
5450: }
5451: }
1.832 bisitz 5452: my $caname = '';
1.1024 www 5453: my $cadom = '';
1.1028 raeburn 5454: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5455: ($cadom,$caname) =
1.832 bisitz 5456: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5457: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5458: $caname = $env{'user.name'};
1.1024 www 5459: $cadom = $env{'user.domain'};
1.832 bisitz 5460: }
1.1028 raeburn 5461: if (($caname ne '') && ($cadom ne '')) {
5462: return "/priv/$cadom/$caname/";
5463: }
5464: return;
1.832 bisitz 5465: }
5466:
5467: ##############################################
5468: =pod
5469:
1.822 bisitz 5470: =item * &head_subbox()
5471:
5472: Inputs: $content (contains HTML code with page functions, etc.)
5473:
5474: Returns: HTML div with $content
5475: To be included in page header
5476:
5477: =cut
5478:
5479: sub head_subbox {
5480: my ($content)=@_;
5481: my $output =
1.993 raeburn 5482: '<div class="LC_head_subbox">'
1.822 bisitz 5483: .$content
5484: .'</div>'
5485: }
5486:
5487: ##############################################
5488: =pod
5489:
5490: =item * &CSTR_pageheader()
5491:
1.1026 raeburn 5492: Input: (optional) filename from which breadcrumb trail is built.
5493: In most cases no input as needed, as $env{'request.filename'}
5494: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5495:
5496: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5497: To be included on Authoring Space pages
1.822 bisitz 5498:
5499: =cut
5500:
5501: sub CSTR_pageheader {
1.1026 raeburn 5502: my ($trailfile) = @_;
5503: if ($trailfile eq '') {
5504: $trailfile = $env{'request.filename'};
5505: }
5506:
5507: # this is for resources; directories have customtitle, and crumbs
5508: # and select recent are created in lonpubdir.pm
5509:
5510: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5511: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5512: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5513: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5514: $formaction =~ s{/+}{/}g;
1.822 bisitz 5515:
5516: my $parentpath = '';
5517: my $lastitem = '';
5518: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5519: $parentpath = $1;
5520: $lastitem = $2;
5521: } else {
5522: $lastitem = $thisdisfn;
5523: }
1.921 bisitz 5524:
5525: my $output =
1.822 bisitz 5526: '<div>'
5527: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5528: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5529: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5530: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5531: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5532:
5533: if ($lastitem) {
5534: $output .=
5535: '<span class="LC_filename">'
5536: .$lastitem
5537: .'</span>';
5538: }
5539: $output .=
5540: '<br />'
1.822 bisitz 5541: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5542: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5543: .'</form>'
5544: .&Apache::lonmenu::constspaceform()
5545: .'</div>';
1.921 bisitz 5546:
5547: return $output;
1.822 bisitz 5548: }
5549:
1.60 matthew 5550: ###############################################
5551: ###############################################
5552:
5553: =pod
5554:
1.112 bowersj2 5555: =back
5556:
1.549 albertel 5557: =head1 HTML Helpers
1.112 bowersj2 5558:
5559: =over 4
5560:
5561: =item * &bodytag()
1.60 matthew 5562:
5563: Returns a uniform header for LON-CAPA web pages.
5564:
5565: Inputs:
5566:
1.112 bowersj2 5567: =over 4
5568:
5569: =item * $title, A title to be displayed on the page.
5570:
5571: =item * $function, the current role (can be undef).
5572:
5573: =item * $addentries, extra parameters for the <body> tag.
5574:
5575: =item * $bodyonly, if defined, only return the <body> tag.
5576:
5577: =item * $domain, if defined, force a given domain.
5578:
5579: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5580: text interface only)
1.60 matthew 5581:
1.814 bisitz 5582: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5583: navigational links
1.317 albertel 5584:
1.338 albertel 5585: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5586:
1.1075.2.12 raeburn 5587: =item * $no_inline_link, if true and in remote mode, don't show the
5588: 'Switch To Inline Menu' link
5589:
1.460 albertel 5590: =item * $args, optional argument valid values are
5591: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5592: use_absolute -> for external resource or syllabus, this will
5593: contain https://<hostname> if server uses
5594: https (as per hosts.tab), but request is for http
5595: hostname -> hostname, from $r->hostname().
1.460 albertel 5596:
1.1075.2.15 raeburn 5597: =item * $advtoolsref, optional argument, ref to an array containing
5598: inlineremote items to be added in "Functions" menu below
5599: breadcrumbs.
5600:
1.112 bowersj2 5601: =back
5602:
1.60 matthew 5603: Returns: A uniform header for LON-CAPA web pages.
5604: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5605: If $bodyonly is undef or zero, an html string containing a <body> tag and
5606: other decorations will be returned.
5607:
5608: =cut
5609:
1.54 www 5610: sub bodytag {
1.831 bisitz 5611: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5612: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5613:
1.954 raeburn 5614: my $public;
5615: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5616: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5617: $public = 1;
5618: }
1.460 albertel 5619: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5620: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5621: my $hostname = $args->{'hostname'};
1.339 albertel 5622:
1.183 matthew 5623: $function = &get_users_function() if (!$function);
1.339 albertel 5624: my $img = &designparm($function.'.img',$domain);
5625: my $font = &designparm($function.'.font',$domain);
5626: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5627:
1.803 bisitz 5628: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5629: 'bgcolor' => $pgbg,
1.339 albertel 5630: 'text' => $font,
5631: 'alink' => &designparm($function.'.alink',$domain),
5632: 'vlink' => &designparm($function.'.vlink',$domain),
5633: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5634: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5635:
1.63 www 5636: # role and realm
1.1075.2.68 raeburn 5637: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5638: if ($realm) {
5639: $realm = '/'.$realm;
5640: }
1.378 raeburn 5641: if ($role eq 'ca') {
1.479 albertel 5642: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5643: $realm = &plainname($rname,$rdom);
1.378 raeburn 5644: }
1.55 www 5645: # realm
1.258 albertel 5646: if ($env{'request.course.id'}) {
1.378 raeburn 5647: if ($env{'request.role'} !~ /^cr/) {
5648: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5649: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5650: if ($env{'request.role.desc'}) {
5651: $role = $env{'request.role.desc'};
5652: } else {
5653: $role = &mt('Helpdesk[_1]',' '.$2);
5654: }
1.1075.2.115 raeburn 5655: } else {
5656: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5657: }
1.898 raeburn 5658: if ($env{'request.course.sec'}) {
5659: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5660: }
1.359 albertel 5661: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5662: } else {
5663: $role = &Apache::lonnet::plaintext($role);
1.54 www 5664: }
1.433 albertel 5665:
1.359 albertel 5666: if (!$realm) { $realm=' '; }
1.330 albertel 5667:
1.438 albertel 5668: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5669:
1.101 www 5670: # construct main body tag
1.359 albertel 5671: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5672: &Apache::lontexconvert::init_math_support();
1.252 albertel 5673:
1.1075.2.38 raeburn 5674: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5675:
5676: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5677: return $bodytag;
1.1075.2.38 raeburn 5678: }
1.359 albertel 5679:
1.954 raeburn 5680: if ($public) {
1.433 albertel 5681: undef($role);
5682: }
1.359 albertel 5683:
1.762 bisitz 5684: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5685: #
5686: # Extra info if you are the DC
5687: my $dc_info = '';
5688: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5689: $env{'course.'.$env{'request.course.id'}.
5690: '.domain'}.'/'})) {
5691: my $cid = $env{'request.course.id'};
1.917 raeburn 5692: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5693: $dc_info =~ s/\s+$//;
1.359 albertel 5694: }
5695:
1.1075.2.108 raeburn 5696: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5697:
1.1075.2.13 raeburn 5698: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5699:
1.1075.2.38 raeburn 5700:
5701:
1.1075.2.21 raeburn 5702: my $funclist;
5703: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5704: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5705: Apache::lonmenu::serverform();
5706: my $forbodytag;
5707: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5708: $forcereg,$args->{'group'},
5709: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5710: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5711: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5712: $funclist = $forbodytag;
5713: }
5714: } else {
1.903 droeschl 5715:
5716: # if ($env{'request.state'} eq 'construct') {
5717: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5718: # }
5719:
1.1075.2.38 raeburn 5720: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5721: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5722:
1.1075.2.38 raeburn 5723: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5724:
1.916 droeschl 5725: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5726: if ($dc_info) {
5727: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5728: }
1.1075.2.38 raeburn 5729: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5730: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5731: return $bodytag;
5732: }
1.894 droeschl 5733:
1.927 raeburn 5734: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5735: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5736: }
1.916 droeschl 5737:
1.1075.2.38 raeburn 5738: $bodytag .= $right;
1.852 droeschl 5739:
1.917 raeburn 5740: if ($dc_info) {
5741: $dc_info = &dc_courseid_toggle($dc_info);
5742: }
5743: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5744:
1.1075.2.61 raeburn 5745: #if directed to not display the secondary menu, don't.
5746: if ($args->{'no_secondary_menu'}) {
5747: return $bodytag;
5748: }
1.903 droeschl 5749: #don't show menus for public users
1.954 raeburn 5750: if (!$public){
1.1075.2.52 raeburn 5751: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5752: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5753: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5754: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5755: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5756: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5757: } elsif ($forcereg) {
1.1075.2.22 raeburn 5758: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5759: $args->{'group'},
1.1075.2.133 raeburn 5760: $args->{'hide_buttons',
5761: $hostname});
1.1075.2.15 raeburn 5762: } else {
1.1075.2.21 raeburn 5763: my $forbodytag;
5764: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5765: $forcereg,$args->{'group'},
5766: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5767: $advtoolsref,'',$hostname,
5768: \$forbodytag);
1.1075.2.21 raeburn 5769: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5770: $bodytag .= $forbodytag;
5771: }
1.920 raeburn 5772: }
1.903 droeschl 5773: }else{
5774: # this is to seperate menu from content when there's no secondary
5775: # menu. Especially needed for public accessible ressources.
5776: $bodytag .= '<hr style="clear:both" />';
5777: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5778: }
1.903 droeschl 5779:
1.235 raeburn 5780: return $bodytag;
1.1075.2.12 raeburn 5781: }
5782:
5783: #
5784: # Top frame rendering, Remote is up
5785: #
5786:
5787: my $imgsrc = $img;
5788: if ($img =~ /^\/adm/) {
5789: $imgsrc = &lonhttpdurl($img);
5790: }
5791: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5792:
1.1075.2.60 raeburn 5793: my $help=($no_inline_link?''
5794: :&Apache::loncommon::top_nav_help('Help'));
5795:
1.1075.2.12 raeburn 5796: # Explicit link to get inline menu
5797: my $menu= ($no_inline_link?''
5798: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5799:
5800: if ($dc_info) {
5801: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5802: }
5803:
1.1075.2.38 raeburn 5804: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5805: unless ($public) {
5806: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5807: undef,'LC_menubuttons_link');
5808: }
5809:
1.1075.2.12 raeburn 5810: unless ($env{'form.inhibitmenu'}) {
5811: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5812: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5813: <li>$help</li>
1.1075.2.12 raeburn 5814: <li>$menu</li>
5815: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5816: }
1.1075.2.13 raeburn 5817: if ($env{'request.state'} eq 'construct') {
5818: if (!$public){
5819: if ($env{'request.state'} eq 'construct') {
5820: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5821: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5822: &Apache::lonhtmlcommon::scripttag('','end').
5823: &Apache::lonmenu::innerregister($forcereg,
5824: $args->{'bread_crumbs'});
5825: }
5826: }
5827: }
1.1075.2.21 raeburn 5828: return $bodytag."\n".$funclist;
1.182 matthew 5829: }
5830:
1.917 raeburn 5831: sub dc_courseid_toggle {
5832: my ($dc_info) = @_;
1.980 raeburn 5833: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5834: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5835: &mt('(More ...)').'</a></span>'.
5836: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5837: }
5838:
1.330 albertel 5839: sub make_attr_string {
5840: my ($register,$attr_ref) = @_;
5841:
5842: if ($attr_ref && !ref($attr_ref)) {
5843: die("addentries Must be a hash ref ".
5844: join(':',caller(1))." ".
5845: join(':',caller(0))." ");
5846: }
5847:
5848: if ($register) {
1.339 albertel 5849: my ($on_load,$on_unload);
5850: foreach my $key (keys(%{$attr_ref})) {
5851: if (lc($key) eq 'onload') {
5852: $on_load.=$attr_ref->{$key}.';';
5853: delete($attr_ref->{$key});
5854:
5855: } elsif (lc($key) eq 'onunload') {
5856: $on_unload.=$attr_ref->{$key}.';';
5857: delete($attr_ref->{$key});
5858: }
5859: }
1.1075.2.12 raeburn 5860: if ($env{'environment.remote'} eq 'on') {
5861: $attr_ref->{'onload'} =
5862: &Apache::lonmenu::loadevents(). $on_load;
5863: $attr_ref->{'onunload'}=
5864: &Apache::lonmenu::unloadevents().$on_unload;
5865: } else {
5866: $attr_ref->{'onload'} = $on_load;
5867: $attr_ref->{'onunload'}= $on_unload;
5868: }
1.330 albertel 5869: }
1.339 albertel 5870:
1.330 albertel 5871: my $attr_string;
1.1075.2.56 raeburn 5872: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5873: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5874: }
5875: return $attr_string;
5876: }
5877:
5878:
1.182 matthew 5879: ###############################################
1.251 albertel 5880: ###############################################
5881:
5882: =pod
5883:
5884: =item * &endbodytag()
5885:
5886: Returns a uniform footer for LON-CAPA web pages.
5887:
1.635 raeburn 5888: Inputs: 1 - optional reference to an args hash
5889: If in the hash, key for noredirectlink has a value which evaluates to true,
5890: a 'Continue' link is not displayed if the page contains an
5891: internal redirect in the <head></head> section,
5892: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5893:
5894: =cut
5895:
5896: sub endbodytag {
1.635 raeburn 5897: my ($args) = @_;
1.1075.2.6 raeburn 5898: my $endbodytag;
5899: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5900: $endbodytag='</body>';
5901: }
1.315 albertel 5902: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5903: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5904: $endbodytag=
5905: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5906: &mt('Continue').'</a>'.
5907: $endbodytag;
5908: }
1.315 albertel 5909: }
1.251 albertel 5910: return $endbodytag;
5911: }
5912:
1.352 albertel 5913: =pod
5914:
5915: =item * &standard_css()
5916:
5917: Returns a style sheet
5918:
5919: Inputs: (all optional)
5920: domain -> force to color decorate a page for a specific
5921: domain
5922: function -> force usage of a specific rolish color scheme
5923: bgcolor -> override the default page bgcolor
5924:
5925: =cut
5926:
1.343 albertel 5927: sub standard_css {
1.345 albertel 5928: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5929: $function = &get_users_function() if (!$function);
5930: my $img = &designparm($function.'.img', $domain);
5931: my $tabbg = &designparm($function.'.tabbg', $domain);
5932: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5933: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5934: #second colour for later usage
1.345 albertel 5935: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5936: my $pgbg_or_bgcolor =
5937: $bgcolor ||
1.352 albertel 5938: &designparm($function.'.pgbg', $domain);
1.382 albertel 5939: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5940: my $alink = &designparm($function.'.alink', $domain);
5941: my $vlink = &designparm($function.'.vlink', $domain);
5942: my $link = &designparm($function.'.link', $domain);
5943:
1.602 albertel 5944: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5945: my $mono = 'monospace';
1.850 bisitz 5946: my $data_table_head = $sidebg;
5947: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5948: my $data_table_dark = '#E0E0E0';
1.470 banghart 5949: my $data_table_darker = '#CCCCCC';
1.349 albertel 5950: my $data_table_highlight = '#FFFF00';
1.352 albertel 5951: my $mail_new = '#FFBB77';
5952: my $mail_new_hover = '#DD9955';
5953: my $mail_read = '#BBBB77';
5954: my $mail_read_hover = '#999944';
5955: my $mail_replied = '#AAAA88';
5956: my $mail_replied_hover = '#888855';
5957: my $mail_other = '#99BBBB';
5958: my $mail_other_hover = '#669999';
1.391 albertel 5959: my $table_header = '#DDDDDD';
1.489 raeburn 5960: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5961: my $lg_border_color = '#C8C8C8';
1.952 onken 5962: my $button_hover = '#BF2317';
1.392 albertel 5963:
1.608 albertel 5964: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5965: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5966: : '0 3px 0 4px';
1.448 albertel 5967:
1.523 albertel 5968:
1.343 albertel 5969: return <<END;
1.947 droeschl 5970:
5971: /* needed for iframe to allow 100% height in FF */
5972: body, html {
5973: margin: 0;
5974: padding: 0 0.5%;
5975: height: 99%; /* to avoid scrollbars */
5976: }
5977:
1.795 www 5978: body {
1.911 bisitz 5979: font-family: $sans;
5980: line-height:130%;
5981: font-size:0.83em;
5982: color:$font;
1.795 www 5983: }
5984:
1.959 onken 5985: a:focus,
5986: a:focus img {
1.795 www 5987: color: red;
5988: }
1.698 harmsja 5989:
1.911 bisitz 5990: form, .inline {
5991: display: inline;
1.795 www 5992: }
1.721 harmsja 5993:
1.795 www 5994: .LC_right {
1.911 bisitz 5995: text-align:right;
1.795 www 5996: }
5997:
5998: .LC_middle {
1.911 bisitz 5999: vertical-align:middle;
1.795 www 6000: }
1.721 harmsja 6001:
1.1075.2.38 raeburn 6002: .LC_floatleft {
6003: float: left;
6004: }
6005:
6006: .LC_floatright {
6007: float: right;
6008: }
6009:
1.911 bisitz 6010: .LC_400Box {
6011: width:400px;
6012: }
1.721 harmsja 6013:
1.947 droeschl 6014: .LC_iframecontainer {
6015: width: 98%;
6016: margin: 0;
6017: position: fixed;
6018: top: 8.5em;
6019: bottom: 0;
6020: }
6021:
6022: .LC_iframecontainer iframe{
6023: border: none;
6024: width: 100%;
6025: height: 100%;
6026: }
6027:
1.778 bisitz 6028: .LC_filename {
6029: font-family: $mono;
6030: white-space:pre;
1.921 bisitz 6031: font-size: 120%;
1.778 bisitz 6032: }
6033:
6034: .LC_fileicon {
6035: border: none;
6036: height: 1.3em;
6037: vertical-align: text-bottom;
6038: margin-right: 0.3em;
6039: text-decoration:none;
6040: }
6041:
1.1008 www 6042: .LC_setting {
6043: text-decoration:underline;
6044: }
6045:
1.350 albertel 6046: .LC_error {
6047: color: red;
6048: }
1.795 www 6049:
1.1075.2.15 raeburn 6050: .LC_warning {
6051: color: darkorange;
6052: }
6053:
1.457 albertel 6054: .LC_diff_removed {
1.733 bisitz 6055: color: red;
1.394 albertel 6056: }
1.532 albertel 6057:
6058: .LC_info,
1.457 albertel 6059: .LC_success,
6060: .LC_diff_added {
1.350 albertel 6061: color: green;
6062: }
1.795 www 6063:
1.802 bisitz 6064: div.LC_confirm_box {
6065: background-color: #FAFAFA;
6066: border: 1px solid $lg_border_color;
6067: margin-right: 0;
6068: padding: 5px;
6069: }
6070:
6071: div.LC_confirm_box .LC_error img,
6072: div.LC_confirm_box .LC_success img {
6073: vertical-align: middle;
6074: }
6075:
1.1075.2.108 raeburn 6076: .LC_maxwidth {
6077: max-width: 100%;
6078: height: auto;
6079: }
6080:
6081: .LC_textsize_mobile {
6082: \@media only screen and (max-device-width: 480px) {
6083: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6084: }
6085: }
6086:
1.440 albertel 6087: .LC_icon {
1.771 droeschl 6088: border: none;
1.790 droeschl 6089: vertical-align: middle;
1.771 droeschl 6090: }
6091:
1.543 albertel 6092: .LC_docs_spacer {
6093: width: 25px;
6094: height: 1px;
1.771 droeschl 6095: border: none;
1.543 albertel 6096: }
1.346 albertel 6097:
1.532 albertel 6098: .LC_internal_info {
1.735 bisitz 6099: color: #999999;
1.532 albertel 6100: }
6101:
1.794 www 6102: .LC_discussion {
1.1050 www 6103: background: $data_table_dark;
1.911 bisitz 6104: border: 1px solid black;
6105: margin: 2px;
1.794 www 6106: }
6107:
6108: .LC_disc_action_left {
1.1050 www 6109: background: $sidebg;
1.911 bisitz 6110: text-align: left;
1.1050 www 6111: padding: 4px;
6112: margin: 2px;
1.794 www 6113: }
6114:
6115: .LC_disc_action_right {
1.1050 www 6116: background: $sidebg;
1.911 bisitz 6117: text-align: right;
1.1050 www 6118: padding: 4px;
6119: margin: 2px;
1.794 www 6120: }
6121:
6122: .LC_disc_new_item {
1.911 bisitz 6123: background: white;
6124: border: 2px solid red;
1.1050 www 6125: margin: 4px;
6126: padding: 4px;
1.794 www 6127: }
6128:
6129: .LC_disc_old_item {
1.911 bisitz 6130: background: white;
1.1050 www 6131: margin: 4px;
6132: padding: 4px;
1.794 www 6133: }
6134:
1.458 albertel 6135: table.LC_pastsubmission {
6136: border: 1px solid black;
6137: margin: 2px;
6138: }
6139:
1.924 bisitz 6140: table#LC_menubuttons {
1.345 albertel 6141: width: 100%;
6142: background: $pgbg;
1.392 albertel 6143: border: 2px;
1.402 albertel 6144: border-collapse: separate;
1.803 bisitz 6145: padding: 0;
1.345 albertel 6146: }
1.392 albertel 6147:
1.801 tempelho 6148: table#LC_title_bar a {
6149: color: $fontmenu;
6150: }
1.836 bisitz 6151:
1.807 droeschl 6152: table#LC_title_bar {
1.819 tempelho 6153: clear: both;
1.836 bisitz 6154: display: none;
1.807 droeschl 6155: }
6156:
1.795 www 6157: table#LC_title_bar,
1.933 droeschl 6158: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6159: table#LC_title_bar.LC_with_remote {
1.359 albertel 6160: width: 100%;
1.392 albertel 6161: border-color: $pgbg;
6162: border-style: solid;
6163: border-width: $border;
1.379 albertel 6164: background: $pgbg;
1.801 tempelho 6165: color: $fontmenu;
1.392 albertel 6166: border-collapse: collapse;
1.803 bisitz 6167: padding: 0;
1.819 tempelho 6168: margin: 0;
1.359 albertel 6169: }
1.795 www 6170:
1.933 droeschl 6171: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6172: margin: 0;
6173: padding: 0;
1.933 droeschl 6174: position: relative;
6175: list-style: none;
1.913 droeschl 6176: }
1.933 droeschl 6177: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6178: display: inline;
6179: }
1.933 droeschl 6180:
6181: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6182: padding: 0;
1.933 droeschl 6183: margin: 0;
6184: float: left;
1.913 droeschl 6185: }
1.933 droeschl 6186: .LC_breadcrumb_tools_tools {
6187: padding: 0;
6188: margin: 0;
1.913 droeschl 6189: float: right;
6190: }
6191:
1.359 albertel 6192: table#LC_title_bar td {
6193: background: $tabbg;
6194: }
1.795 www 6195:
1.911 bisitz 6196: table#LC_menubuttons img {
1.803 bisitz 6197: border: none;
1.346 albertel 6198: }
1.795 www 6199:
1.842 droeschl 6200: .LC_breadcrumbs_component {
1.911 bisitz 6201: float: right;
6202: margin: 0 1em;
1.357 albertel 6203: }
1.842 droeschl 6204: .LC_breadcrumbs_component img {
1.911 bisitz 6205: vertical-align: middle;
1.777 tempelho 6206: }
1.795 www 6207:
1.1075.2.108 raeburn 6208: .LC_breadcrumbs_hoverable {
6209: background: $sidebg;
6210: }
6211:
1.383 albertel 6212: td.LC_table_cell_checkbox {
6213: text-align: center;
6214: }
1.795 www 6215:
6216: .LC_fontsize_small {
1.911 bisitz 6217: font-size: 70%;
1.705 tempelho 6218: }
6219:
1.844 bisitz 6220: #LC_breadcrumbs {
1.911 bisitz 6221: clear:both;
6222: background: $sidebg;
6223: border-bottom: 1px solid $lg_border_color;
6224: line-height: 2.5em;
1.933 droeschl 6225: overflow: hidden;
1.911 bisitz 6226: margin: 0;
6227: padding: 0;
1.995 raeburn 6228: text-align: left;
1.819 tempelho 6229: }
1.862 bisitz 6230:
1.1075.2.16 raeburn 6231: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6232: clear:both;
6233: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6234: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6235: margin: 0 0 10px 0;
1.966 bisitz 6236: padding: 3px;
1.995 raeburn 6237: text-align: left;
1.822 bisitz 6238: }
6239:
1.795 www 6240: .LC_fontsize_medium {
1.911 bisitz 6241: font-size: 85%;
1.705 tempelho 6242: }
6243:
1.795 www 6244: .LC_fontsize_large {
1.911 bisitz 6245: font-size: 120%;
1.705 tempelho 6246: }
6247:
1.346 albertel 6248: .LC_menubuttons_inline_text {
6249: color: $font;
1.698 harmsja 6250: font-size: 90%;
1.701 harmsja 6251: padding-left:3px;
1.346 albertel 6252: }
6253:
1.934 droeschl 6254: .LC_menubuttons_inline_text img{
6255: vertical-align: middle;
6256: }
6257:
1.1051 www 6258: li.LC_menubuttons_inline_text img {
1.951 onken 6259: cursor:pointer;
1.1002 droeschl 6260: text-decoration: none;
1.951 onken 6261: }
6262:
1.526 www 6263: .LC_menubuttons_link {
6264: text-decoration: none;
6265: }
1.795 www 6266:
1.522 albertel 6267: .LC_menubuttons_category {
1.521 www 6268: color: $font;
1.526 www 6269: background: $pgbg;
1.521 www 6270: font-size: larger;
6271: font-weight: bold;
6272: }
6273:
1.346 albertel 6274: td.LC_menubuttons_text {
1.911 bisitz 6275: color: $font;
1.346 albertel 6276: }
1.706 harmsja 6277:
1.346 albertel 6278: .LC_current_location {
6279: background: $tabbg;
6280: }
1.795 www 6281:
1.1075.2.134 raeburn 6282: td.LC_zero_height {
6283: line-height: 0;
6284: cellpadding: 0;
6285: }
6286:
1.938 bisitz 6287: table.LC_data_table {
1.347 albertel 6288: border: 1px solid #000000;
1.402 albertel 6289: border-collapse: separate;
1.426 albertel 6290: border-spacing: 1px;
1.610 albertel 6291: background: $pgbg;
1.347 albertel 6292: }
1.795 www 6293:
1.422 albertel 6294: .LC_data_table_dense {
6295: font-size: small;
6296: }
1.795 www 6297:
1.507 raeburn 6298: table.LC_nested_outer {
6299: border: 1px solid #000000;
1.589 raeburn 6300: border-collapse: collapse;
1.803 bisitz 6301: border-spacing: 0;
1.507 raeburn 6302: width: 100%;
6303: }
1.795 www 6304:
1.879 raeburn 6305: table.LC_innerpickbox,
1.507 raeburn 6306: table.LC_nested {
1.803 bisitz 6307: border: none;
1.589 raeburn 6308: border-collapse: collapse;
1.803 bisitz 6309: border-spacing: 0;
1.507 raeburn 6310: width: 100%;
6311: }
1.795 www 6312:
1.911 bisitz 6313: table.LC_data_table tr th,
6314: table.LC_calendar tr th,
1.879 raeburn 6315: table.LC_prior_tries tr th,
6316: table.LC_innerpickbox tr th {
1.349 albertel 6317: font-weight: bold;
6318: background-color: $data_table_head;
1.801 tempelho 6319: color:$fontmenu;
1.701 harmsja 6320: font-size:90%;
1.347 albertel 6321: }
1.795 www 6322:
1.879 raeburn 6323: table.LC_innerpickbox tr th,
6324: table.LC_innerpickbox tr td {
6325: vertical-align: top;
6326: }
6327:
1.711 raeburn 6328: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6329: background-color: #CCCCCC;
1.711 raeburn 6330: font-weight: bold;
6331: text-align: left;
6332: }
1.795 www 6333:
1.912 bisitz 6334: table.LC_data_table tr.LC_odd_row > td {
6335: background-color: $data_table_light;
6336: padding: 2px;
6337: vertical-align: top;
6338: }
6339:
1.809 bisitz 6340: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6341: background-color: $data_table_light;
1.912 bisitz 6342: vertical-align: top;
6343: }
6344:
6345: table.LC_data_table tr.LC_even_row > td {
6346: background-color: $data_table_dark;
1.425 albertel 6347: padding: 2px;
1.900 bisitz 6348: vertical-align: top;
1.347 albertel 6349: }
1.795 www 6350:
1.809 bisitz 6351: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6352: background-color: $data_table_dark;
1.900 bisitz 6353: vertical-align: top;
1.347 albertel 6354: }
1.795 www 6355:
1.425 albertel 6356: table.LC_data_table tr.LC_data_table_highlight td {
6357: background-color: $data_table_darker;
6358: }
1.795 www 6359:
1.639 raeburn 6360: table.LC_data_table tr td.LC_leftcol_header {
6361: background-color: $data_table_head;
6362: font-weight: bold;
6363: }
1.795 www 6364:
1.451 albertel 6365: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6366: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6367: font-weight: bold;
6368: font-style: italic;
6369: text-align: center;
6370: padding: 8px;
1.347 albertel 6371: }
1.795 www 6372:
1.1075.2.30 raeburn 6373: table.LC_data_table tr.LC_empty_row td,
6374: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6375: background-color: $sidebg;
6376: }
6377:
6378: table.LC_nested tr.LC_empty_row td {
6379: background-color: #FFFFFF;
6380: }
6381:
1.890 droeschl 6382: table.LC_caption {
6383: }
6384:
1.507 raeburn 6385: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6386: padding: 4ex
6387: }
1.795 www 6388:
1.507 raeburn 6389: table.LC_nested_outer tr th {
6390: font-weight: bold;
1.801 tempelho 6391: color:$fontmenu;
1.507 raeburn 6392: background-color: $data_table_head;
1.701 harmsja 6393: font-size: small;
1.507 raeburn 6394: border-bottom: 1px solid #000000;
6395: }
1.795 www 6396:
1.507 raeburn 6397: table.LC_nested_outer tr td.LC_subheader {
6398: background-color: $data_table_head;
6399: font-weight: bold;
6400: font-size: small;
6401: border-bottom: 1px solid #000000;
6402: text-align: right;
1.451 albertel 6403: }
1.795 www 6404:
1.507 raeburn 6405: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6406: background-color: #CCCCCC;
1.451 albertel 6407: font-weight: bold;
6408: font-size: small;
1.507 raeburn 6409: text-align: center;
6410: }
1.795 www 6411:
1.589 raeburn 6412: table.LC_nested tr.LC_info_row td.LC_left_item,
6413: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6414: text-align: left;
1.451 albertel 6415: }
1.795 www 6416:
1.507 raeburn 6417: table.LC_nested td {
1.735 bisitz 6418: background-color: #FFFFFF;
1.451 albertel 6419: font-size: small;
1.507 raeburn 6420: }
1.795 www 6421:
1.507 raeburn 6422: table.LC_nested_outer tr th.LC_right_item,
6423: table.LC_nested tr.LC_info_row td.LC_right_item,
6424: table.LC_nested tr.LC_odd_row td.LC_right_item,
6425: table.LC_nested tr td.LC_right_item {
1.451 albertel 6426: text-align: right;
6427: }
6428:
1.507 raeburn 6429: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6430: background-color: #EEEEEE;
1.451 albertel 6431: }
6432:
1.473 raeburn 6433: table.LC_createuser {
6434: }
6435:
6436: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6437: font-size: small;
1.473 raeburn 6438: }
6439:
6440: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6441: background-color: #CCCCCC;
1.473 raeburn 6442: font-weight: bold;
6443: text-align: center;
6444: }
6445:
1.349 albertel 6446: table.LC_calendar {
6447: border: 1px solid #000000;
6448: border-collapse: collapse;
1.917 raeburn 6449: width: 98%;
1.349 albertel 6450: }
1.795 www 6451:
1.349 albertel 6452: table.LC_calendar_pickdate {
6453: font-size: xx-small;
6454: }
1.795 www 6455:
1.349 albertel 6456: table.LC_calendar tr td {
6457: border: 1px solid #000000;
6458: vertical-align: top;
1.917 raeburn 6459: width: 14%;
1.349 albertel 6460: }
1.795 www 6461:
1.349 albertel 6462: table.LC_calendar tr td.LC_calendar_day_empty {
6463: background-color: $data_table_dark;
6464: }
1.795 www 6465:
1.779 bisitz 6466: table.LC_calendar tr td.LC_calendar_day_current {
6467: background-color: $data_table_highlight;
1.777 tempelho 6468: }
1.795 www 6469:
1.938 bisitz 6470: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6471: background-color: $mail_new;
6472: }
1.795 www 6473:
1.938 bisitz 6474: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6475: background-color: $mail_new_hover;
6476: }
1.795 www 6477:
1.938 bisitz 6478: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6479: background-color: $mail_read;
6480: }
1.795 www 6481:
1.938 bisitz 6482: /*
6483: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6484: background-color: $mail_read_hover;
6485: }
1.938 bisitz 6486: */
1.795 www 6487:
1.938 bisitz 6488: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6489: background-color: $mail_replied;
6490: }
1.795 www 6491:
1.938 bisitz 6492: /*
6493: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6494: background-color: $mail_replied_hover;
6495: }
1.938 bisitz 6496: */
1.795 www 6497:
1.938 bisitz 6498: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6499: background-color: $mail_other;
6500: }
1.795 www 6501:
1.938 bisitz 6502: /*
6503: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6504: background-color: $mail_other_hover;
6505: }
1.938 bisitz 6506: */
1.494 raeburn 6507:
1.777 tempelho 6508: table.LC_data_table tr > td.LC_browser_file,
6509: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6510: background: #AAEE77;
1.389 albertel 6511: }
1.795 www 6512:
1.777 tempelho 6513: table.LC_data_table tr > td.LC_browser_file_locked,
6514: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6515: background: #FFAA99;
1.387 albertel 6516: }
1.795 www 6517:
1.777 tempelho 6518: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6519: background: #888888;
1.779 bisitz 6520: }
1.795 www 6521:
1.777 tempelho 6522: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6523: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6524: background: #F8F866;
1.777 tempelho 6525: }
1.795 www 6526:
1.696 bisitz 6527: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6528: background: #E0E8FF;
1.387 albertel 6529: }
1.696 bisitz 6530:
1.707 bisitz 6531: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6532: /* background: #77FF77; */
1.707 bisitz 6533: }
1.795 www 6534:
1.707 bisitz 6535: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6536: border-right: 8px solid #FFFF77;
1.707 bisitz 6537: }
1.795 www 6538:
1.707 bisitz 6539: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6540: border-right: 8px solid #FFAA77;
1.707 bisitz 6541: }
1.795 www 6542:
1.707 bisitz 6543: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6544: border-right: 8px solid #FF7777;
1.707 bisitz 6545: }
1.795 www 6546:
1.707 bisitz 6547: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6548: border-right: 8px solid #AAFF77;
1.707 bisitz 6549: }
1.795 www 6550:
1.707 bisitz 6551: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6552: border-right: 8px solid #11CC55;
1.707 bisitz 6553: }
6554:
1.388 albertel 6555: span.LC_current_location {
1.701 harmsja 6556: font-size:larger;
1.388 albertel 6557: background: $pgbg;
6558: }
1.387 albertel 6559:
1.1029 www 6560: span.LC_current_nav_location {
6561: font-weight:bold;
6562: background: $sidebg;
6563: }
6564:
1.395 albertel 6565: span.LC_parm_menu_item {
6566: font-size: larger;
6567: }
1.795 www 6568:
1.395 albertel 6569: span.LC_parm_scope_all {
6570: color: red;
6571: }
1.795 www 6572:
1.395 albertel 6573: span.LC_parm_scope_folder {
6574: color: green;
6575: }
1.795 www 6576:
1.395 albertel 6577: span.LC_parm_scope_resource {
6578: color: orange;
6579: }
1.795 www 6580:
1.395 albertel 6581: span.LC_parm_part {
6582: color: blue;
6583: }
1.795 www 6584:
1.911 bisitz 6585: span.LC_parm_folder,
6586: span.LC_parm_symb {
1.395 albertel 6587: font-size: x-small;
6588: font-family: $mono;
6589: color: #AAAAAA;
6590: }
6591:
1.977 bisitz 6592: ul.LC_parm_parmlist li {
6593: display: inline-block;
6594: padding: 0.3em 0.8em;
6595: vertical-align: top;
6596: width: 150px;
6597: border-top:1px solid $lg_border_color;
6598: }
6599:
1.795 www 6600: td.LC_parm_overview_level_menu,
6601: td.LC_parm_overview_map_menu,
6602: td.LC_parm_overview_parm_selectors,
6603: td.LC_parm_overview_restrictions {
1.396 albertel 6604: border: 1px solid black;
6605: border-collapse: collapse;
6606: }
1.795 www 6607:
1.396 albertel 6608: table.LC_parm_overview_restrictions td {
6609: border-width: 1px 4px 1px 4px;
6610: border-style: solid;
6611: border-color: $pgbg;
6612: text-align: center;
6613: }
1.795 www 6614:
1.396 albertel 6615: table.LC_parm_overview_restrictions th {
6616: background: $tabbg;
6617: border-width: 1px 4px 1px 4px;
6618: border-style: solid;
6619: border-color: $pgbg;
6620: }
1.795 www 6621:
1.398 albertel 6622: table#LC_helpmenu {
1.803 bisitz 6623: border: none;
1.398 albertel 6624: height: 55px;
1.803 bisitz 6625: border-spacing: 0;
1.398 albertel 6626: }
6627:
6628: table#LC_helpmenu fieldset legend {
6629: font-size: larger;
6630: }
1.795 www 6631:
1.397 albertel 6632: table#LC_helpmenu_links {
6633: width: 100%;
6634: border: 1px solid black;
6635: background: $pgbg;
1.803 bisitz 6636: padding: 0;
1.397 albertel 6637: border-spacing: 1px;
6638: }
1.795 www 6639:
1.397 albertel 6640: table#LC_helpmenu_links tr td {
6641: padding: 1px;
6642: background: $tabbg;
1.399 albertel 6643: text-align: center;
6644: font-weight: bold;
1.397 albertel 6645: }
1.396 albertel 6646:
1.795 www 6647: table#LC_helpmenu_links a:link,
6648: table#LC_helpmenu_links a:visited,
1.397 albertel 6649: table#LC_helpmenu_links a:active {
6650: text-decoration: none;
6651: color: $font;
6652: }
1.795 www 6653:
1.397 albertel 6654: table#LC_helpmenu_links a:hover {
6655: text-decoration: underline;
6656: color: $vlink;
6657: }
1.396 albertel 6658:
1.417 albertel 6659: .LC_chrt_popup_exists {
6660: border: 1px solid #339933;
6661: margin: -1px;
6662: }
1.795 www 6663:
1.417 albertel 6664: .LC_chrt_popup_up {
6665: border: 1px solid yellow;
6666: margin: -1px;
6667: }
1.795 www 6668:
1.417 albertel 6669: .LC_chrt_popup {
6670: border: 1px solid #8888FF;
6671: background: #CCCCFF;
6672: }
1.795 www 6673:
1.421 albertel 6674: table.LC_pick_box {
6675: border-collapse: separate;
6676: background: white;
6677: border: 1px solid black;
6678: border-spacing: 1px;
6679: }
1.795 www 6680:
1.421 albertel 6681: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6682: background: $sidebg;
1.421 albertel 6683: font-weight: bold;
1.900 bisitz 6684: text-align: left;
1.740 bisitz 6685: vertical-align: top;
1.421 albertel 6686: width: 184px;
6687: padding: 8px;
6688: }
1.795 www 6689:
1.579 raeburn 6690: table.LC_pick_box td.LC_pick_box_value {
6691: text-align: left;
6692: padding: 8px;
6693: }
1.795 www 6694:
1.579 raeburn 6695: table.LC_pick_box td.LC_pick_box_select {
6696: text-align: left;
6697: padding: 8px;
6698: }
1.795 www 6699:
1.424 albertel 6700: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6701: padding: 0;
1.421 albertel 6702: height: 1px;
6703: background: black;
6704: }
1.795 www 6705:
1.421 albertel 6706: table.LC_pick_box td.LC_pick_box_submit {
6707: text-align: right;
6708: }
1.795 www 6709:
1.579 raeburn 6710: table.LC_pick_box td.LC_evenrow_value {
6711: text-align: left;
6712: padding: 8px;
6713: background-color: $data_table_light;
6714: }
1.795 www 6715:
1.579 raeburn 6716: table.LC_pick_box td.LC_oddrow_value {
6717: text-align: left;
6718: padding: 8px;
6719: background-color: $data_table_light;
6720: }
1.795 www 6721:
1.579 raeburn 6722: span.LC_helpform_receipt_cat {
6723: font-weight: bold;
6724: }
1.795 www 6725:
1.424 albertel 6726: table.LC_group_priv_box {
6727: background: white;
6728: border: 1px solid black;
6729: border-spacing: 1px;
6730: }
1.795 www 6731:
1.424 albertel 6732: table.LC_group_priv_box td.LC_pick_box_title {
6733: background: $tabbg;
6734: font-weight: bold;
6735: text-align: right;
6736: width: 184px;
6737: }
1.795 www 6738:
1.424 albertel 6739: table.LC_group_priv_box td.LC_groups_fixed {
6740: background: $data_table_light;
6741: text-align: center;
6742: }
1.795 www 6743:
1.424 albertel 6744: table.LC_group_priv_box td.LC_groups_optional {
6745: background: $data_table_dark;
6746: text-align: center;
6747: }
1.795 www 6748:
1.424 albertel 6749: table.LC_group_priv_box td.LC_groups_functionality {
6750: background: $data_table_darker;
6751: text-align: center;
6752: font-weight: bold;
6753: }
1.795 www 6754:
1.424 albertel 6755: table.LC_group_priv td {
6756: text-align: left;
1.803 bisitz 6757: padding: 0;
1.424 albertel 6758: }
6759:
6760: .LC_navbuttons {
6761: margin: 2ex 0ex 2ex 0ex;
6762: }
1.795 www 6763:
1.423 albertel 6764: .LC_topic_bar {
6765: font-weight: bold;
6766: background: $tabbg;
1.918 wenzelju 6767: margin: 1em 0em 1em 2em;
1.805 bisitz 6768: padding: 3px;
1.918 wenzelju 6769: font-size: 1.2em;
1.423 albertel 6770: }
1.795 www 6771:
1.423 albertel 6772: .LC_topic_bar span {
1.918 wenzelju 6773: left: 0.5em;
6774: position: absolute;
1.423 albertel 6775: vertical-align: middle;
1.918 wenzelju 6776: font-size: 1.2em;
1.423 albertel 6777: }
1.795 www 6778:
1.423 albertel 6779: table.LC_course_group_status {
6780: margin: 20px;
6781: }
1.795 www 6782:
1.423 albertel 6783: table.LC_status_selector td {
6784: vertical-align: top;
6785: text-align: center;
1.424 albertel 6786: padding: 4px;
6787: }
1.795 www 6788:
1.599 albertel 6789: div.LC_feedback_link {
1.616 albertel 6790: clear: both;
1.829 kalberla 6791: background: $sidebg;
1.779 bisitz 6792: width: 100%;
1.829 kalberla 6793: padding-bottom: 10px;
6794: border: 1px $tabbg solid;
1.833 kalberla 6795: height: 22px;
6796: line-height: 22px;
6797: padding-top: 5px;
6798: }
6799:
6800: div.LC_feedback_link img {
6801: height: 22px;
1.867 kalberla 6802: vertical-align:middle;
1.829 kalberla 6803: }
6804:
1.911 bisitz 6805: div.LC_feedback_link a {
1.829 kalberla 6806: text-decoration: none;
1.489 raeburn 6807: }
1.795 www 6808:
1.867 kalberla 6809: div.LC_comblock {
1.911 bisitz 6810: display:inline;
1.867 kalberla 6811: color:$font;
6812: font-size:90%;
6813: }
6814:
6815: div.LC_feedback_link div.LC_comblock {
6816: padding-left:5px;
6817: }
6818:
6819: div.LC_feedback_link div.LC_comblock a {
6820: color:$font;
6821: }
6822:
1.489 raeburn 6823: span.LC_feedback_link {
1.858 bisitz 6824: /* background: $feedback_link_bg; */
1.599 albertel 6825: font-size: larger;
6826: }
1.795 www 6827:
1.599 albertel 6828: span.LC_message_link {
1.858 bisitz 6829: /* background: $feedback_link_bg; */
1.599 albertel 6830: font-size: larger;
6831: position: absolute;
6832: right: 1em;
1.489 raeburn 6833: }
1.421 albertel 6834:
1.515 albertel 6835: table.LC_prior_tries {
1.524 albertel 6836: border: 1px solid #000000;
6837: border-collapse: separate;
6838: border-spacing: 1px;
1.515 albertel 6839: }
1.523 albertel 6840:
1.515 albertel 6841: table.LC_prior_tries td {
1.524 albertel 6842: padding: 2px;
1.515 albertel 6843: }
1.523 albertel 6844:
6845: .LC_answer_correct {
1.795 www 6846: background: lightgreen;
6847: color: darkgreen;
6848: padding: 6px;
1.523 albertel 6849: }
1.795 www 6850:
1.523 albertel 6851: .LC_answer_charged_try {
1.797 www 6852: background: #FFAAAA;
1.795 www 6853: color: darkred;
6854: padding: 6px;
1.523 albertel 6855: }
1.795 www 6856:
1.779 bisitz 6857: .LC_answer_not_charged_try,
1.523 albertel 6858: .LC_answer_no_grade,
6859: .LC_answer_late {
1.795 www 6860: background: lightyellow;
1.523 albertel 6861: color: black;
1.795 www 6862: padding: 6px;
1.523 albertel 6863: }
1.795 www 6864:
1.523 albertel 6865: .LC_answer_previous {
1.795 www 6866: background: lightblue;
6867: color: darkblue;
6868: padding: 6px;
1.523 albertel 6869: }
1.795 www 6870:
1.779 bisitz 6871: .LC_answer_no_message {
1.777 tempelho 6872: background: #FFFFFF;
6873: color: black;
1.795 www 6874: padding: 6px;
1.779 bisitz 6875: }
1.795 www 6876:
1.1075.2.140 raeburn 6877: .LC_answer_unknown,
6878: .LC_answer_warning {
1.779 bisitz 6879: background: orange;
6880: color: black;
1.795 www 6881: padding: 6px;
1.777 tempelho 6882: }
1.795 www 6883:
1.529 albertel 6884: span.LC_prior_numerical,
6885: span.LC_prior_string,
6886: span.LC_prior_custom,
6887: span.LC_prior_reaction,
6888: span.LC_prior_math {
1.925 bisitz 6889: font-family: $mono;
1.523 albertel 6890: white-space: pre;
6891: }
6892:
1.525 albertel 6893: span.LC_prior_string {
1.925 bisitz 6894: font-family: $mono;
1.525 albertel 6895: white-space: pre;
6896: }
6897:
1.523 albertel 6898: table.LC_prior_option {
6899: width: 100%;
6900: border-collapse: collapse;
6901: }
1.795 www 6902:
1.911 bisitz 6903: table.LC_prior_rank,
1.795 www 6904: table.LC_prior_match {
1.528 albertel 6905: border-collapse: collapse;
6906: }
1.795 www 6907:
1.528 albertel 6908: table.LC_prior_option tr td,
6909: table.LC_prior_rank tr td,
6910: table.LC_prior_match tr td {
1.524 albertel 6911: border: 1px solid #000000;
1.515 albertel 6912: }
6913:
1.855 bisitz 6914: .LC_nobreak {
1.544 albertel 6915: white-space: nowrap;
1.519 raeburn 6916: }
6917:
1.576 raeburn 6918: span.LC_cusr_emph {
6919: font-style: italic;
6920: }
6921:
1.633 raeburn 6922: span.LC_cusr_subheading {
6923: font-weight: normal;
6924: font-size: 85%;
6925: }
6926:
1.861 bisitz 6927: div.LC_docs_entry_move {
1.859 bisitz 6928: border: 1px solid #BBBBBB;
1.545 albertel 6929: background: #DDDDDD;
1.861 bisitz 6930: width: 22px;
1.859 bisitz 6931: padding: 1px;
6932: margin: 0;
1.545 albertel 6933: }
6934:
1.861 bisitz 6935: table.LC_data_table tr > td.LC_docs_entry_commands,
6936: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6937: font-size: x-small;
6938: }
1.795 www 6939:
1.861 bisitz 6940: .LC_docs_entry_parameter {
6941: white-space: nowrap;
6942: }
6943:
1.544 albertel 6944: .LC_docs_copy {
1.545 albertel 6945: color: #000099;
1.544 albertel 6946: }
1.795 www 6947:
1.544 albertel 6948: .LC_docs_cut {
1.545 albertel 6949: color: #550044;
1.544 albertel 6950: }
1.795 www 6951:
1.544 albertel 6952: .LC_docs_rename {
1.545 albertel 6953: color: #009900;
1.544 albertel 6954: }
1.795 www 6955:
1.544 albertel 6956: .LC_docs_remove {
1.545 albertel 6957: color: #990000;
6958: }
6959:
1.1075.2.134 raeburn 6960: .LC_domprefs_email,
1.547 albertel 6961: .LC_docs_reinit_warn,
6962: .LC_docs_ext_edit {
6963: font-size: x-small;
6964: }
6965:
1.545 albertel 6966: table.LC_docs_adddocs td,
6967: table.LC_docs_adddocs th {
6968: border: 1px solid #BBBBBB;
6969: padding: 4px;
6970: background: #DDDDDD;
1.543 albertel 6971: }
6972:
1.584 albertel 6973: table.LC_sty_begin {
6974: background: #BBFFBB;
6975: }
1.795 www 6976:
1.584 albertel 6977: table.LC_sty_end {
6978: background: #FFBBBB;
6979: }
6980:
1.589 raeburn 6981: table.LC_double_column {
1.803 bisitz 6982: border-width: 0;
1.589 raeburn 6983: border-collapse: collapse;
6984: width: 100%;
6985: padding: 2px;
6986: }
6987:
6988: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6989: top: 2px;
1.589 raeburn 6990: left: 2px;
6991: width: 47%;
6992: vertical-align: top;
6993: }
6994:
6995: table.LC_double_column tr td.LC_right_col {
6996: top: 2px;
1.779 bisitz 6997: right: 2px;
1.589 raeburn 6998: width: 47%;
6999: vertical-align: top;
7000: }
7001:
1.591 raeburn 7002: div.LC_left_float {
7003: float: left;
7004: padding-right: 5%;
1.597 albertel 7005: padding-bottom: 4px;
1.591 raeburn 7006: }
7007:
7008: div.LC_clear_float_header {
1.597 albertel 7009: padding-bottom: 2px;
1.591 raeburn 7010: }
7011:
7012: div.LC_clear_float_footer {
1.597 albertel 7013: padding-top: 10px;
1.591 raeburn 7014: clear: both;
7015: }
7016:
1.597 albertel 7017: div.LC_grade_show_user {
1.941 bisitz 7018: /* border-left: 5px solid $sidebg; */
7019: border-top: 5px solid #000000;
7020: margin: 50px 0 0 0;
1.936 bisitz 7021: padding: 15px 0 5px 10px;
1.597 albertel 7022: }
1.795 www 7023:
1.936 bisitz 7024: div.LC_grade_show_user_odd_row {
1.941 bisitz 7025: /* border-left: 5px solid #000000; */
7026: }
7027:
7028: div.LC_grade_show_user div.LC_Box {
7029: margin-right: 50px;
1.597 albertel 7030: }
7031:
7032: div.LC_grade_submissions,
7033: div.LC_grade_message_center,
1.936 bisitz 7034: div.LC_grade_info_links {
1.597 albertel 7035: margin: 5px;
7036: width: 99%;
7037: background: #FFFFFF;
7038: }
1.795 www 7039:
1.597 albertel 7040: div.LC_grade_submissions_header,
1.936 bisitz 7041: div.LC_grade_message_center_header {
1.705 tempelho 7042: font-weight: bold;
7043: font-size: large;
1.597 albertel 7044: }
1.795 www 7045:
1.597 albertel 7046: div.LC_grade_submissions_body,
1.936 bisitz 7047: div.LC_grade_message_center_body {
1.597 albertel 7048: border: 1px solid black;
7049: width: 99%;
7050: background: #FFFFFF;
7051: }
1.795 www 7052:
1.613 albertel 7053: table.LC_scantron_action {
7054: width: 100%;
7055: }
1.795 www 7056:
1.613 albertel 7057: table.LC_scantron_action tr th {
1.698 harmsja 7058: font-weight:bold;
7059: font-style:normal;
1.613 albertel 7060: }
1.795 www 7061:
1.779 bisitz 7062: .LC_edit_problem_header,
1.614 albertel 7063: div.LC_edit_problem_footer {
1.705 tempelho 7064: font-weight: normal;
7065: font-size: medium;
1.602 albertel 7066: margin: 2px;
1.1060 bisitz 7067: background-color: $sidebg;
1.600 albertel 7068: }
1.795 www 7069:
1.600 albertel 7070: div.LC_edit_problem_header,
1.602 albertel 7071: div.LC_edit_problem_header div,
1.614 albertel 7072: div.LC_edit_problem_footer,
7073: div.LC_edit_problem_footer div,
1.602 albertel 7074: div.LC_edit_problem_editxml_header,
7075: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7076: z-index: 100;
1.600 albertel 7077: }
1.795 www 7078:
1.600 albertel 7079: div.LC_edit_problem_header_title {
1.705 tempelho 7080: font-weight: bold;
7081: font-size: larger;
1.602 albertel 7082: background: $tabbg;
7083: padding: 3px;
1.1060 bisitz 7084: margin: 0 0 5px 0;
1.602 albertel 7085: }
1.795 www 7086:
1.602 albertel 7087: table.LC_edit_problem_header_title {
7088: width: 100%;
1.600 albertel 7089: background: $tabbg;
1.602 albertel 7090: }
7091:
1.1075.2.112 raeburn 7092: div.LC_edit_actionbar {
7093: background-color: $sidebg;
7094: margin: 0;
7095: padding: 0;
7096: line-height: 200%;
1.602 albertel 7097: }
1.795 www 7098:
1.1075.2.112 raeburn 7099: div.LC_edit_actionbar div{
7100: padding: 0;
7101: margin: 0;
7102: display: inline-block;
1.600 albertel 7103: }
1.795 www 7104:
1.1075.2.34 raeburn 7105: .LC_edit_opt {
7106: padding-left: 1em;
7107: white-space: nowrap;
7108: }
7109:
1.1075.2.57 raeburn 7110: .LC_edit_problem_latexhelper{
7111: text-align: right;
7112: }
7113:
7114: #LC_edit_problem_colorful div{
7115: margin-left: 40px;
7116: }
7117:
1.1075.2.112 raeburn 7118: #LC_edit_problem_codemirror div{
7119: margin-left: 0px;
7120: }
7121:
1.911 bisitz 7122: img.stift {
1.803 bisitz 7123: border-width: 0;
7124: vertical-align: middle;
1.677 riegler 7125: }
1.680 riegler 7126:
1.923 bisitz 7127: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7128: vertical-align: top;
1.777 tempelho 7129: }
1.795 www 7130:
1.716 raeburn 7131: div.LC_createcourse {
1.911 bisitz 7132: margin: 10px 10px 10px 10px;
1.716 raeburn 7133: }
7134:
1.917 raeburn 7135: .LC_dccid {
1.1075.2.38 raeburn 7136: float: right;
1.917 raeburn 7137: margin: 0.2em 0 0 0;
7138: padding: 0;
7139: font-size: 90%;
7140: display:none;
7141: }
7142:
1.897 wenzelju 7143: ol.LC_primary_menu a:hover,
1.721 harmsja 7144: ol#LC_MenuBreadcrumbs a:hover,
7145: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7146: ul#LC_secondary_menu a:hover,
1.721 harmsja 7147: .LC_FormSectionClearButton input:hover
1.795 www 7148: ul.LC_TabContent li:hover a {
1.952 onken 7149: color:$button_hover;
1.911 bisitz 7150: text-decoration:none;
1.693 droeschl 7151: }
7152:
1.779 bisitz 7153: h1 {
1.911 bisitz 7154: padding: 0;
7155: line-height:130%;
1.693 droeschl 7156: }
1.698 harmsja 7157:
1.911 bisitz 7158: h2,
7159: h3,
7160: h4,
7161: h5,
7162: h6 {
7163: margin: 5px 0 5px 0;
7164: padding: 0;
7165: line-height:130%;
1.693 droeschl 7166: }
1.795 www 7167:
7168: .LC_hcell {
1.911 bisitz 7169: padding:3px 15px 3px 15px;
7170: margin: 0;
7171: background-color:$tabbg;
7172: color:$fontmenu;
7173: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7174: }
1.795 www 7175:
1.840 bisitz 7176: .LC_Box > .LC_hcell {
1.911 bisitz 7177: margin: 0 -10px 10px -10px;
1.835 bisitz 7178: }
7179:
1.721 harmsja 7180: .LC_noBorder {
1.911 bisitz 7181: border: 0;
1.698 harmsja 7182: }
1.693 droeschl 7183:
1.721 harmsja 7184: .LC_FormSectionClearButton input {
1.911 bisitz 7185: background-color:transparent;
7186: border: none;
7187: cursor:pointer;
7188: text-decoration:underline;
1.693 droeschl 7189: }
1.763 bisitz 7190:
7191: .LC_help_open_topic {
1.911 bisitz 7192: color: #FFFFFF;
7193: background-color: #EEEEFF;
7194: margin: 1px;
7195: padding: 4px;
7196: border: 1px solid #000033;
7197: white-space: nowrap;
7198: /* vertical-align: middle; */
1.759 neumanie 7199: }
1.693 droeschl 7200:
1.911 bisitz 7201: dl,
7202: ul,
7203: div,
7204: fieldset {
7205: margin: 10px 10px 10px 0;
7206: /* overflow: hidden; */
1.693 droeschl 7207: }
1.795 www 7208:
1.1075.2.90 raeburn 7209: article.geogebraweb div {
7210: margin: 0;
7211: }
7212:
1.838 bisitz 7213: fieldset > legend {
1.911 bisitz 7214: font-weight: bold;
7215: padding: 0 5px 0 5px;
1.838 bisitz 7216: }
7217:
1.813 bisitz 7218: #LC_nav_bar {
1.911 bisitz 7219: float: left;
1.995 raeburn 7220: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7221: margin: 0 0 2px 0;
1.807 droeschl 7222: }
7223:
1.916 droeschl 7224: #LC_realm {
7225: margin: 0.2em 0 0 0;
7226: padding: 0;
7227: font-weight: bold;
7228: text-align: center;
1.995 raeburn 7229: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7230: }
7231:
1.911 bisitz 7232: #LC_nav_bar em {
7233: font-weight: bold;
7234: font-style: normal;
1.807 droeschl 7235: }
7236:
1.897 wenzelju 7237: ol.LC_primary_menu {
1.934 droeschl 7238: margin: 0;
1.1075.2.2 raeburn 7239: padding: 0;
1.807 droeschl 7240: }
7241:
1.852 droeschl 7242: ol#LC_PathBreadcrumbs {
1.911 bisitz 7243: margin: 0;
1.693 droeschl 7244: }
7245:
1.897 wenzelju 7246: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7247: color: RGB(80, 80, 80);
7248: vertical-align: middle;
7249: text-align: left;
7250: list-style: none;
1.1075.2.112 raeburn 7251: position: relative;
1.1075.2.2 raeburn 7252: float: left;
1.1075.2.112 raeburn 7253: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7254: line-height: 1.5em;
1.1075.2.2 raeburn 7255: }
7256:
1.1075.2.113 raeburn 7257: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7258: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7259: display: block;
7260: margin: 0;
7261: padding: 0 5px 0 10px;
7262: text-decoration: none;
7263: }
7264:
1.1075.2.112 raeburn 7265: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7266: display: inline-block;
7267: width: 95%;
7268: text-align: left;
7269: }
7270:
7271: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7272: display: inline-block;
7273: width: 5%;
7274: float: right;
7275: text-align: right;
7276: font-size: 70%;
7277: }
7278:
7279: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7280: display: none;
1.1075.2.112 raeburn 7281: width: 15em;
1.1075.2.2 raeburn 7282: background-color: $data_table_light;
1.1075.2.112 raeburn 7283: position: absolute;
7284: top: 100%;
7285: }
7286:
7287: ol.LC_primary_menu ul ul {
7288: left: 100%;
7289: top: 0;
1.1075.2.2 raeburn 7290: }
7291:
1.1075.2.112 raeburn 7292: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7293: display: block;
7294: position: absolute;
7295: margin: 0;
7296: padding: 0;
1.1075.2.5 raeburn 7297: z-index: 2;
1.1075.2.2 raeburn 7298: }
7299:
7300: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7301: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7302: font-size: 90%;
1.911 bisitz 7303: vertical-align: top;
1.1075.2.2 raeburn 7304: float: none;
1.1075.2.5 raeburn 7305: border-left: 1px solid black;
7306: border-right: 1px solid black;
1.1075.2.112 raeburn 7307: /* A dark bottom border to visualize different menu options;
7308: overwritten in the create_submenu routine for the last border-bottom of the menu */
7309: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7310: }
7311:
1.1075.2.112 raeburn 7312: ol.LC_primary_menu li li p:hover {
7313: color:$button_hover;
7314: text-decoration:none;
7315: background-color:$data_table_dark;
1.1075.2.2 raeburn 7316: }
7317:
7318: ol.LC_primary_menu li li a:hover {
7319: color:$button_hover;
7320: background-color:$data_table_dark;
1.693 droeschl 7321: }
7322:
1.1075.2.112 raeburn 7323: /* Font-size equal to the size of the predecessors*/
7324: ol.LC_primary_menu li:hover li li {
7325: font-size: 100%;
7326: }
7327:
1.897 wenzelju 7328: ol.LC_primary_menu li img {
1.911 bisitz 7329: vertical-align: bottom;
1.934 droeschl 7330: height: 1.1em;
1.1075.2.3 raeburn 7331: margin: 0.2em 0 0 0;
1.693 droeschl 7332: }
7333:
1.897 wenzelju 7334: ol.LC_primary_menu a {
1.911 bisitz 7335: color: RGB(80, 80, 80);
7336: text-decoration: none;
1.693 droeschl 7337: }
1.795 www 7338:
1.949 droeschl 7339: ol.LC_primary_menu a.LC_new_message {
7340: font-weight:bold;
7341: color: darkred;
7342: }
7343:
1.975 raeburn 7344: ol.LC_docs_parameters {
7345: margin-left: 0;
7346: padding: 0;
7347: list-style: none;
7348: }
7349:
7350: ol.LC_docs_parameters li {
7351: margin: 0;
7352: padding-right: 20px;
7353: display: inline;
7354: }
7355:
1.976 raeburn 7356: ol.LC_docs_parameters li:before {
7357: content: "\\002022 \\0020";
7358: }
7359:
7360: li.LC_docs_parameters_title {
7361: font-weight: bold;
7362: }
7363:
7364: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7365: content: "";
7366: }
7367:
1.897 wenzelju 7368: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7369: clear: right;
1.911 bisitz 7370: color: $fontmenu;
7371: background: $tabbg;
7372: list-style: none;
7373: padding: 0;
7374: margin: 0;
7375: width: 100%;
1.995 raeburn 7376: text-align: left;
1.1075.2.4 raeburn 7377: float: left;
1.808 droeschl 7378: }
7379:
1.897 wenzelju 7380: ul#LC_secondary_menu li {
1.911 bisitz 7381: font-weight: bold;
7382: line-height: 1.8em;
7383: border-right: 1px solid black;
1.1075.2.4 raeburn 7384: float: left;
7385: }
7386:
7387: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7388: background-color: $data_table_light;
7389: }
7390:
7391: ul#LC_secondary_menu li a {
7392: padding: 0 0.8em;
7393: }
7394:
7395: ul#LC_secondary_menu li ul {
7396: display: none;
7397: }
7398:
7399: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7400: display: block;
7401: position: absolute;
7402: margin: 0;
7403: padding: 0;
7404: list-style:none;
7405: float: none;
7406: background-color: $data_table_light;
1.1075.2.5 raeburn 7407: z-index: 2;
1.1075.2.10 raeburn 7408: margin-left: -1px;
1.1075.2.4 raeburn 7409: }
7410:
7411: ul#LC_secondary_menu li ul li {
7412: font-size: 90%;
7413: vertical-align: top;
7414: border-left: 1px solid black;
7415: border-right: 1px solid black;
1.1075.2.33 raeburn 7416: background-color: $data_table_light;
1.1075.2.4 raeburn 7417: list-style:none;
7418: float: none;
7419: }
7420:
7421: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7422: background-color: $data_table_dark;
1.807 droeschl 7423: }
7424:
1.847 tempelho 7425: ul.LC_TabContent {
1.911 bisitz 7426: display:block;
7427: background: $sidebg;
7428: border-bottom: solid 1px $lg_border_color;
7429: list-style:none;
1.1020 raeburn 7430: margin: -1px -10px 0 -10px;
1.911 bisitz 7431: padding: 0;
1.693 droeschl 7432: }
7433:
1.795 www 7434: ul.LC_TabContent li,
7435: ul.LC_TabContentBigger li {
1.911 bisitz 7436: float:left;
1.741 harmsja 7437: }
1.795 www 7438:
1.897 wenzelju 7439: ul#LC_secondary_menu li a {
1.911 bisitz 7440: color: $fontmenu;
7441: text-decoration: none;
1.693 droeschl 7442: }
1.795 www 7443:
1.721 harmsja 7444: ul.LC_TabContent {
1.952 onken 7445: min-height:20px;
1.721 harmsja 7446: }
1.795 www 7447:
7448: ul.LC_TabContent li {
1.911 bisitz 7449: vertical-align:middle;
1.959 onken 7450: padding: 0 16px 0 10px;
1.911 bisitz 7451: background-color:$tabbg;
7452: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7453: border-left: solid 1px $font;
1.721 harmsja 7454: }
1.795 www 7455:
1.847 tempelho 7456: ul.LC_TabContent .right {
1.911 bisitz 7457: float:right;
1.847 tempelho 7458: }
7459:
1.911 bisitz 7460: ul.LC_TabContent li a,
7461: ul.LC_TabContent li {
7462: color:rgb(47,47,47);
7463: text-decoration:none;
7464: font-size:95%;
7465: font-weight:bold;
1.952 onken 7466: min-height:20px;
7467: }
7468:
1.959 onken 7469: ul.LC_TabContent li a:hover,
7470: ul.LC_TabContent li a:focus {
1.952 onken 7471: color: $button_hover;
1.959 onken 7472: background:none;
7473: outline:none;
1.952 onken 7474: }
7475:
7476: ul.LC_TabContent li:hover {
7477: color: $button_hover;
7478: cursor:pointer;
1.721 harmsja 7479: }
1.795 www 7480:
1.911 bisitz 7481: ul.LC_TabContent li.active {
1.952 onken 7482: color: $font;
1.911 bisitz 7483: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7484: border-bottom:solid 1px #FFFFFF;
7485: cursor: default;
1.744 ehlerst 7486: }
1.795 www 7487:
1.959 onken 7488: ul.LC_TabContent li.active a {
7489: color:$font;
7490: background:#FFFFFF;
7491: outline: none;
7492: }
1.1047 raeburn 7493:
7494: ul.LC_TabContent li.goback {
7495: float: left;
7496: border-left: none;
7497: }
7498:
1.870 tempelho 7499: #maincoursedoc {
1.911 bisitz 7500: clear:both;
1.870 tempelho 7501: }
7502:
7503: ul.LC_TabContentBigger {
1.911 bisitz 7504: display:block;
7505: list-style:none;
7506: padding: 0;
1.870 tempelho 7507: }
7508:
1.795 www 7509: ul.LC_TabContentBigger li {
1.911 bisitz 7510: vertical-align:bottom;
7511: height: 30px;
7512: font-size:110%;
7513: font-weight:bold;
7514: color: #737373;
1.841 tempelho 7515: }
7516:
1.957 onken 7517: ul.LC_TabContentBigger li.active {
7518: position: relative;
7519: top: 1px;
7520: }
7521:
1.870 tempelho 7522: ul.LC_TabContentBigger li a {
1.911 bisitz 7523: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7524: height: 30px;
7525: line-height: 30px;
7526: text-align: center;
7527: display: block;
7528: text-decoration: none;
1.958 onken 7529: outline: none;
1.741 harmsja 7530: }
1.795 www 7531:
1.870 tempelho 7532: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7533: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7534: color:$font;
1.744 ehlerst 7535: }
1.795 www 7536:
1.870 tempelho 7537: ul.LC_TabContentBigger li b {
1.911 bisitz 7538: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7539: display: block;
7540: float: left;
7541: padding: 0 30px;
1.957 onken 7542: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7543: }
7544:
1.956 onken 7545: ul.LC_TabContentBigger li:hover b {
7546: color:$button_hover;
7547: }
7548:
1.870 tempelho 7549: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7550: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7551: color:$font;
1.957 onken 7552: border: 0;
1.741 harmsja 7553: }
1.693 droeschl 7554:
1.870 tempelho 7555:
1.862 bisitz 7556: ul.LC_CourseBreadcrumbs {
7557: background: $sidebg;
1.1020 raeburn 7558: height: 2em;
1.862 bisitz 7559: padding-left: 10px;
1.1020 raeburn 7560: margin: 0;
1.862 bisitz 7561: list-style-position: inside;
7562: }
7563:
1.911 bisitz 7564: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7565: ol#LC_PathBreadcrumbs {
1.911 bisitz 7566: padding-left: 10px;
7567: margin: 0;
1.933 droeschl 7568: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7569: }
7570:
1.911 bisitz 7571: ol#LC_MenuBreadcrumbs li,
7572: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7573: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7574: display: inline;
1.933 droeschl 7575: white-space: normal;
1.693 droeschl 7576: }
7577:
1.823 bisitz 7578: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7579: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7580: text-decoration: none;
7581: font-size:90%;
1.693 droeschl 7582: }
1.795 www 7583:
1.969 droeschl 7584: ol#LC_MenuBreadcrumbs h1 {
7585: display: inline;
7586: font-size: 90%;
7587: line-height: 2.5em;
7588: margin: 0;
7589: padding: 0;
7590: }
7591:
1.795 www 7592: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7593: text-decoration:none;
7594: font-size:100%;
7595: font-weight:bold;
1.693 droeschl 7596: }
1.795 www 7597:
1.840 bisitz 7598: .LC_Box {
1.911 bisitz 7599: border: solid 1px $lg_border_color;
7600: padding: 0 10px 10px 10px;
1.746 neumanie 7601: }
1.795 www 7602:
1.1020 raeburn 7603: .LC_DocsBox {
7604: border: solid 1px $lg_border_color;
7605: padding: 0 0 10px 10px;
7606: }
7607:
1.795 www 7608: .LC_AboutMe_Image {
1.911 bisitz 7609: float:left;
7610: margin-right:10px;
1.747 neumanie 7611: }
1.795 www 7612:
7613: .LC_Clear_AboutMe_Image {
1.911 bisitz 7614: clear:left;
1.747 neumanie 7615: }
1.795 www 7616:
1.721 harmsja 7617: dl.LC_ListStyleClean dt {
1.911 bisitz 7618: padding-right: 5px;
7619: display: table-header-group;
1.693 droeschl 7620: }
7621:
1.721 harmsja 7622: dl.LC_ListStyleClean dd {
1.911 bisitz 7623: display: table-row;
1.693 droeschl 7624: }
7625:
1.721 harmsja 7626: .LC_ListStyleClean,
7627: .LC_ListStyleSimple,
7628: .LC_ListStyleNormal,
1.795 www 7629: .LC_ListStyleSpecial {
1.911 bisitz 7630: /* display:block; */
7631: list-style-position: inside;
7632: list-style-type: none;
7633: overflow: hidden;
7634: padding: 0;
1.693 droeschl 7635: }
7636:
1.721 harmsja 7637: .LC_ListStyleSimple li,
7638: .LC_ListStyleSimple dd,
7639: .LC_ListStyleNormal li,
7640: .LC_ListStyleNormal dd,
7641: .LC_ListStyleSpecial li,
1.795 www 7642: .LC_ListStyleSpecial dd {
1.911 bisitz 7643: margin: 0;
7644: padding: 5px 5px 5px 10px;
7645: clear: both;
1.693 droeschl 7646: }
7647:
1.721 harmsja 7648: .LC_ListStyleClean li,
7649: .LC_ListStyleClean dd {
1.911 bisitz 7650: padding-top: 0;
7651: padding-bottom: 0;
1.693 droeschl 7652: }
7653:
1.721 harmsja 7654: .LC_ListStyleSimple dd,
1.795 www 7655: .LC_ListStyleSimple li {
1.911 bisitz 7656: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7657: }
7658:
1.721 harmsja 7659: .LC_ListStyleSpecial li,
7660: .LC_ListStyleSpecial dd {
1.911 bisitz 7661: list-style-type: none;
7662: background-color: RGB(220, 220, 220);
7663: margin-bottom: 4px;
1.693 droeschl 7664: }
7665:
1.721 harmsja 7666: table.LC_SimpleTable {
1.911 bisitz 7667: margin:5px;
7668: border:solid 1px $lg_border_color;
1.795 www 7669: }
1.693 droeschl 7670:
1.721 harmsja 7671: table.LC_SimpleTable tr {
1.911 bisitz 7672: padding: 0;
7673: border:solid 1px $lg_border_color;
1.693 droeschl 7674: }
1.795 www 7675:
7676: table.LC_SimpleTable thead {
1.911 bisitz 7677: background:rgb(220,220,220);
1.693 droeschl 7678: }
7679:
1.721 harmsja 7680: div.LC_columnSection {
1.911 bisitz 7681: display: block;
7682: clear: both;
7683: overflow: hidden;
7684: margin: 0;
1.693 droeschl 7685: }
7686:
1.721 harmsja 7687: div.LC_columnSection>* {
1.911 bisitz 7688: float: left;
7689: margin: 10px 20px 10px 0;
7690: overflow:hidden;
1.693 droeschl 7691: }
1.721 harmsja 7692:
1.795 www 7693: table em {
1.911 bisitz 7694: font-weight: bold;
7695: font-style: normal;
1.748 schulted 7696: }
1.795 www 7697:
1.779 bisitz 7698: table.LC_tableBrowseRes,
1.795 www 7699: table.LC_tableOfContent {
1.911 bisitz 7700: border:none;
7701: border-spacing: 1px;
7702: padding: 3px;
7703: background-color: #FFFFFF;
7704: font-size: 90%;
1.753 droeschl 7705: }
1.789 droeschl 7706:
1.911 bisitz 7707: table.LC_tableOfContent {
7708: border-collapse: collapse;
1.789 droeschl 7709: }
7710:
1.771 droeschl 7711: table.LC_tableBrowseRes a,
1.768 schulted 7712: table.LC_tableOfContent a {
1.911 bisitz 7713: background-color: transparent;
7714: text-decoration: none;
1.753 droeschl 7715: }
7716:
1.795 www 7717: table.LC_tableOfContent img {
1.911 bisitz 7718: border: none;
7719: height: 1.3em;
7720: vertical-align: text-bottom;
7721: margin-right: 0.3em;
1.753 droeschl 7722: }
1.757 schulted 7723:
1.795 www 7724: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7725: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7726: }
7727:
1.795 www 7728: a#LC_content_toolbar_everything {
1.911 bisitz 7729: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7730: }
7731:
1.795 www 7732: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7733: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7734: }
7735:
1.795 www 7736: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7737: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7738: }
7739:
1.795 www 7740: a#LC_content_toolbar_changefolder {
1.911 bisitz 7741: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7742: }
7743:
1.795 www 7744: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7745: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7746: }
7747:
1.1043 raeburn 7748: a#LC_content_toolbar_edittoplevel {
7749: background-image:url(/res/adm/pages/edittoplevel.gif);
7750: }
7751:
1.795 www 7752: ul#LC_toolbar li a:hover {
1.911 bisitz 7753: background-position: bottom center;
1.757 schulted 7754: }
7755:
1.795 www 7756: ul#LC_toolbar {
1.911 bisitz 7757: padding: 0;
7758: margin: 2px;
7759: list-style:none;
7760: position:relative;
7761: background-color:white;
1.1075.2.9 raeburn 7762: overflow: auto;
1.757 schulted 7763: }
7764:
1.795 www 7765: ul#LC_toolbar li {
1.911 bisitz 7766: border:1px solid white;
7767: padding: 0;
7768: margin: 0;
7769: float: left;
7770: display:inline;
7771: vertical-align:middle;
1.1075.2.9 raeburn 7772: white-space: nowrap;
1.911 bisitz 7773: }
1.757 schulted 7774:
1.783 amueller 7775:
1.795 www 7776: a.LC_toolbarItem {
1.911 bisitz 7777: display:block;
7778: padding: 0;
7779: margin: 0;
7780: height: 32px;
7781: width: 32px;
7782: color:white;
7783: border: none;
7784: background-repeat:no-repeat;
7785: background-color:transparent;
1.757 schulted 7786: }
7787:
1.915 droeschl 7788: ul.LC_funclist {
7789: margin: 0;
7790: padding: 0.5em 1em 0.5em 0;
7791: }
7792:
1.933 droeschl 7793: ul.LC_funclist > li:first-child {
7794: font-weight:bold;
7795: margin-left:0.8em;
7796: }
7797:
1.915 droeschl 7798: ul.LC_funclist + ul.LC_funclist {
7799: /*
7800: left border as a seperator if we have more than
7801: one list
7802: */
7803: border-left: 1px solid $sidebg;
7804: /*
7805: this hides the left border behind the border of the
7806: outer box if element is wrapped to the next 'line'
7807: */
7808: margin-left: -1px;
7809: }
7810:
1.843 bisitz 7811: ul.LC_funclist li {
1.915 droeschl 7812: display: inline;
1.782 bisitz 7813: white-space: nowrap;
1.915 droeschl 7814: margin: 0 0 0 25px;
7815: line-height: 150%;
1.782 bisitz 7816: }
7817:
1.974 wenzelju 7818: .LC_hidden {
7819: display: none;
7820: }
7821:
1.1030 www 7822: .LCmodal-overlay {
7823: position:fixed;
7824: top:0;
7825: right:0;
7826: bottom:0;
7827: left:0;
7828: height:100%;
7829: width:100%;
7830: margin:0;
7831: padding:0;
7832: background:#999;
7833: opacity:.75;
7834: filter: alpha(opacity=75);
7835: -moz-opacity: 0.75;
7836: z-index:101;
7837: }
7838:
7839: * html .LCmodal-overlay {
7840: position: absolute;
7841: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7842: }
7843:
7844: .LCmodal-window {
7845: position:fixed;
7846: top:50%;
7847: left:50%;
7848: margin:0;
7849: padding:0;
7850: z-index:102;
7851: }
7852:
7853: * html .LCmodal-window {
7854: position:absolute;
7855: }
7856:
7857: .LCclose-window {
7858: position:absolute;
7859: width:32px;
7860: height:32px;
7861: right:8px;
7862: top:8px;
7863: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7864: text-indent:-99999px;
7865: overflow:hidden;
7866: cursor:pointer;
7867: }
7868:
1.1075.2.141 raeburn 7869: pre.LC_wordwrap {
7870: white-space: pre-wrap;
7871: white-space: -moz-pre-wrap;
7872: white-space: -pre-wrap;
7873: white-space: -o-pre-wrap;
7874: word-wrap: break-word;
7875: }
7876:
1.1075.2.17 raeburn 7877: /*
7878: styles used by TTH when "Default set of options to pass to tth/m
7879: when converting TeX" in course settings has been set
7880:
7881: option passed: -t
7882:
7883: */
7884:
7885: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7886: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7887: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7888: td div.norm {line-height:normal;}
7889:
7890: /*
7891: option passed -y3
7892: */
7893:
7894: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7895: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7896: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7897:
1.1075.2.121 raeburn 7898: #LC_minitab_header {
7899: float:left;
7900: width:100%;
7901: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7902: font-size:93%;
7903: line-height:normal;
7904: margin: 0.5em 0 0.5em 0;
7905: }
7906: #LC_minitab_header ul {
7907: margin:0;
7908: padding:10px 10px 0;
7909: list-style:none;
7910: }
7911: #LC_minitab_header li {
7912: float:left;
7913: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7914: margin:0;
7915: padding:0 0 0 9px;
7916: }
7917: #LC_minitab_header a {
7918: display:block;
7919: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7920: padding:5px 15px 4px 6px;
7921: }
7922: #LC_minitab_header #LC_current_minitab {
7923: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7924: }
7925: #LC_minitab_header #LC_current_minitab a {
7926: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7927: padding-bottom:5px;
7928: }
7929:
7930:
1.343 albertel 7931: END
7932: }
7933:
1.306 albertel 7934: =pod
7935:
7936: =item * &headtag()
7937:
7938: Returns a uniform footer for LON-CAPA web pages.
7939:
1.307 albertel 7940: Inputs: $title - optional title for the head
7941: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7942: $args - optional arguments
1.319 albertel 7943: force_register - if is true call registerurl so the remote is
7944: informed
1.415 albertel 7945: redirect -> array ref of
7946: 1- seconds before redirect occurs
7947: 2- url to redirect to
7948: 3- whether the side effect should occur
1.315 albertel 7949: (side effect of setting
7950: $env{'internal.head.redirect'} to the url
7951: redirected too)
1.352 albertel 7952: domain -> force to color decorate a page for a specific
7953: domain
7954: function -> force usage of a specific rolish color scheme
7955: bgcolor -> override the default page bgcolor
1.460 albertel 7956: no_auto_mt_title
7957: -> prevent &mt()ing the title arg
1.464 albertel 7958:
1.306 albertel 7959: =cut
7960:
7961: sub headtag {
1.313 albertel 7962: my ($title,$head_extra,$args) = @_;
1.306 albertel 7963:
1.363 albertel 7964: my $function = $args->{'function'} || &get_users_function();
7965: my $domain = $args->{'domain'} || &determinedomain();
7966: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7967: my $httphost = $args->{'use_absolute'};
1.418 albertel 7968: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7969: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7970: #time(),
1.418 albertel 7971: $env{'environment.color.timestamp'},
1.363 albertel 7972: $function,$domain,$bgcolor);
7973:
1.369 www 7974: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7975:
1.308 albertel 7976: my $result =
7977: '<head>'.
1.1075.2.56 raeburn 7978: &font_settings($args);
1.319 albertel 7979:
1.1075.2.72 raeburn 7980: my $inhibitprint;
7981: if ($args->{'print_suppress'}) {
7982: $inhibitprint = &print_suppression();
7983: }
1.1064 raeburn 7984:
1.461 albertel 7985: if (!$args->{'frameset'}) {
7986: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7987: }
1.1075.2.12 raeburn 7988: if ($args->{'force_register'}) {
7989: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7990: }
1.436 albertel 7991: if (!$args->{'no_nav_bar'}
7992: && !$args->{'only_body'}
7993: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7994: $result .= &help_menu_js($httphost);
1.1032 www 7995: $result.=&modal_window();
1.1038 www 7996: $result.=&togglebox_script();
1.1034 www 7997: $result.=&wishlist_window();
1.1041 www 7998: $result.=&LCprogressbarUpdate_script();
1.1034 www 7999: } else {
8000: if ($args->{'add_modal'}) {
8001: $result.=&modal_window();
8002: }
8003: if ($args->{'add_wishlist'}) {
8004: $result.=&wishlist_window();
8005: }
1.1038 www 8006: if ($args->{'add_togglebox'}) {
8007: $result.=&togglebox_script();
8008: }
1.1041 www 8009: if ($args->{'add_progressbar'}) {
8010: $result.=&LCprogressbarUpdate_script();
8011: }
1.436 albertel 8012: }
1.314 albertel 8013: if (ref($args->{'redirect'})) {
1.414 albertel 8014: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8015: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8016: if (!$inhibit_continue) {
8017: $env{'internal.head.redirect'} = $url;
8018: }
1.313 albertel 8019: $result.=<<ADDMETA
8020: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8021: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8022: ADDMETA
1.1075.2.89 raeburn 8023: } else {
8024: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8025: my $requrl = $env{'request.uri'};
8026: if ($requrl eq '') {
8027: $requrl = $ENV{'REQUEST_URI'};
8028: $requrl =~ s/\?.+$//;
8029: }
8030: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8031: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8032: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8033: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8034: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8035: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.141. .4(raebu 8036:20): my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
.13(raeb 8037:-21): my ($offload,$offloadoth);
1.1075.2.89 raeburn 8038: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8039: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.141. .4(raebu 8040:20): $offload = 1;
.13(raeb 8041:-21): if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8042:-21): (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8043:-21): unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8044:-21): $offloadoth = 1;
8045:-21): $dom_in_use = $env{'user.domain'};
8046:-21): }
8047:-21): }
.4(raebu 8048:20): }
8049:20): }
8050:20): unless ($offload) {
8051:20): if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8052:20): if ($domdefs{'offloadoth'}{$lonhost}) {
8053:20): if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8054:20): (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8055:20): unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8056:20): $offload = 1;
.13(raeb 8057:-21): $offloadoth = 1;
.4(raebu 8058:20): $dom_in_use = $env{'user.domain'};
8059:20): }
1.1075.2.89 raeburn 8060: }
1.1075.2.141. .4(raebu 8061:20): }
8062:20): }
8063:20): }
8064:20): if ($offload) {
8065:20): my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
.13(raeb 8066:-21): if (($newserver eq '') && ($offloadoth)) {
8067:-21): my @domains = &Apache::lonnet::current_machine_domains();
8068:-21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8069:-21): ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8070:-21): }
8071:-21): }
.4(raebu 8072:20): if (($newserver) && ($newserver ne $lonhost)) {
8073:20): my $numsec = 5;
8074:20): my $timeout = $numsec * 1000;
8075:20): my ($newurl,$locknum,%locks,$msg);
8076:20): if ($env{'request.role.adv'}) {
8077:20): ($locknum,%locks) = &Apache::lonnet::get_locks();
8078:20): }
8079:20): my $disable_submit = 0;
8080:20): if ($requrl =~ /$LONCAPA::assess_re/) {
8081:20): $disable_submit = 1;
8082:20): }
8083:20): if ($locknum) {
8084:20): my @lockinfo = sort(values(%locks));
8085:20): $msg = &mt('Once the following tasks are complete: ')."\n".
8086:20): join(", ",sort(values(%locks)))."\n";
8087:20): if (&show_course()) {
8088:20): $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8089: } else {
1.1075.2.141. .4(raebu 8090:20): $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8091:20): }
8092:20): } else {
8093:20): if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8094:20): $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8095:20): }
8096:20): $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8097:20): $newurl = '/adm/switchserver?otherserver='.$newserver;
8098:20): if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8099:20): $newurl .= '&role='.$env{'request.role'};
8100:20): }
8101:20): if ($env{'request.symb'}) {
8102:20): my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8103:20): if ($shownsymb =~ m{^/enc/}) {
8104:20): my $reqdmajor = 2;
8105:20): my $reqdminor = 11;
8106:20): my $reqdsubminor = 3;
8107:20): my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8108:20): my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8109:20): my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8110:20): if (($major eq '' && $minor eq '') ||
8111:20): (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8112:20): (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8113:20): ($reqdsubminor > $subminor))))) {
8114:20): undef($shownsymb);
8115:20): }
1.1075.2.89 raeburn 8116: }
1.1075.2.141. .4(raebu 8117:20): if ($shownsymb) {
8118:20): &js_escape(\$shownsymb);
8119:20): $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8120: }
1.1075.2.141. .4(raebu 8121:20): } else {
8122:20): my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8123:20): &js_escape(\$shownurl);
8124:20): $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8125: }
1.1075.2.141. .4(raebu 8126:20): }
8127:20): &js_escape(\$msg);
8128:20): $result.=<<OFFLOAD
1.1075.2.89 raeburn 8129: <meta http-equiv="pragma" content="no-cache" />
8130: <script type="text/javascript">
1.1075.2.92 raeburn 8131: // <![CDATA[
1.1075.2.89 raeburn 8132: function LC_Offload_Now() {
8133: var dest = "$newurl";
8134: if (dest != '') {
8135: window.location.href="$newurl";
8136: }
8137: }
1.1075.2.92 raeburn 8138: \$(document).ready(function () {
8139: window.alert('$msg');
8140: if ($disable_submit) {
1.1075.2.89 raeburn 8141: \$(".LC_hwk_submit").prop("disabled", true);
8142: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8143: }
8144: setTimeout('LC_Offload_Now()', $timeout);
8145: });
8146: // ]]>
1.1075.2.89 raeburn 8147: </script>
8148: OFFLOAD
8149: }
8150: }
8151: }
8152: }
8153: }
1.313 albertel 8154: }
1.306 albertel 8155: if (!defined($title)) {
8156: $title = 'The LearningOnline Network with CAPA';
8157: }
1.460 albertel 8158: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8159: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8160: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8161: if (!$args->{'frameset'}) {
8162: $result .= ' /';
8163: }
8164: $result .= '>'
1.1064 raeburn 8165: .$inhibitprint
1.414 albertel 8166: .$head_extra;
1.1075.2.108 raeburn 8167: my $clientmobile;
8168: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8169: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8170: } else {
8171: $clientmobile = $env{'browser.mobile'};
8172: }
8173: if ($clientmobile) {
1.1075.2.42 raeburn 8174: $result .= '
8175: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8176: <meta name="apple-mobile-web-app-capable" content="yes" />';
8177: }
1.1075.2.126 raeburn 8178: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8179: return $result.'</head>';
1.306 albertel 8180: }
8181:
8182: =pod
8183:
1.340 albertel 8184: =item * &font_settings()
8185:
8186: Returns neccessary <meta> to set the proper encoding
8187:
1.1075.2.56 raeburn 8188: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8189:
8190: =cut
8191:
8192: sub font_settings {
1.1075.2.56 raeburn 8193: my ($args) = @_;
1.340 albertel 8194: my $headerstring='';
1.1075.2.56 raeburn 8195: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8196: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8197: $headerstring.=
1.1075.2.61 raeburn 8198: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8199: if (!$args->{'frameset'}) {
8200: $headerstring.= ' /';
8201: }
8202: $headerstring .= '>'."\n";
1.340 albertel 8203: }
8204: return $headerstring;
8205: }
8206:
1.341 albertel 8207: =pod
8208:
1.1064 raeburn 8209: =item * &print_suppression()
8210:
8211: In course context returns css which causes the body to be blank when media="print",
8212: if printout generation is unavailable for the current resource.
8213:
8214: This could be because:
8215:
8216: (a) printstartdate is in the future
8217:
8218: (b) printenddate is in the past
8219:
8220: (c) there is an active exam block with "printout"
8221: functionality blocked
8222:
8223: Users with pav, pfo or evb privileges are exempt.
8224:
8225: Inputs: none
8226:
8227: =cut
8228:
8229:
8230: sub print_suppression {
8231: my $noprint;
8232: if ($env{'request.course.id'}) {
8233: my $scope = $env{'request.course.id'};
8234: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8235: (&Apache::lonnet::allowed('pfo',$scope))) {
8236: return;
8237: }
8238: if ($env{'request.course.sec'} ne '') {
8239: $scope .= "/$env{'request.course.sec'}";
8240: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8241: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8242: return;
1.1064 raeburn 8243: }
8244: }
8245: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8246: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8247: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8248: if ($blocked) {
8249: my $checkrole = "cm./$cdom/$cnum";
8250: if ($env{'request.course.sec'} ne '') {
8251: $checkrole .= "/$env{'request.course.sec'}";
8252: }
8253: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8254: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8255: $noprint = 1;
8256: }
8257: }
8258: unless ($noprint) {
8259: my $symb = &Apache::lonnet::symbread();
8260: if ($symb ne '') {
8261: my $navmap = Apache::lonnavmaps::navmap->new();
8262: if (ref($navmap)) {
8263: my $res = $navmap->getBySymb($symb);
8264: if (ref($res)) {
8265: if (!$res->resprintable()) {
8266: $noprint = 1;
8267: }
8268: }
8269: }
8270: }
8271: }
8272: if ($noprint) {
8273: return <<"ENDSTYLE";
8274: <style type="text/css" media="print">
8275: body { display:none }
8276: </style>
8277: ENDSTYLE
8278: }
8279: }
8280: return;
8281: }
8282:
8283: =pod
8284:
1.341 albertel 8285: =item * &xml_begin()
8286:
8287: Returns the needed doctype and <html>
8288:
8289: Inputs: none
8290:
8291: =cut
8292:
8293: sub xml_begin {
1.1075.2.61 raeburn 8294: my ($is_frameset) = @_;
1.341 albertel 8295: my $output='';
8296:
8297: if ($env{'browser.mathml'}) {
8298: $output='<?xml version="1.0"?>'
8299: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8300: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8301:
8302: # .'<!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">] >'
8303: .'<!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">'
8304: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8305: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8306: } elsif ($is_frameset) {
8307: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8308: '<html>'."\n";
1.341 albertel 8309: } else {
1.1075.2.61 raeburn 8310: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8311: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8312: }
8313: return $output;
8314: }
1.340 albertel 8315:
8316: =pod
8317:
1.306 albertel 8318: =item * &start_page()
8319:
8320: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8321:
1.648 raeburn 8322: Inputs:
8323:
8324: =over 4
8325:
8326: $title - optional title for the page
8327:
8328: $head_extra - optional extra HTML to incude inside the <head>
8329:
8330: $args - additional optional args supported are:
8331:
8332: =over 8
8333:
8334: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8335: arg on
1.814 bisitz 8336: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8337: add_entries -> additional attributes to add to the <body>
8338: domain -> force to color decorate a page for a
1.317 albertel 8339: specific domain
1.648 raeburn 8340: function -> force usage of a specific rolish color
1.317 albertel 8341: scheme
1.648 raeburn 8342: redirect -> see &headtag()
8343: bgcolor -> override the default page bg color
8344: js_ready -> return a string ready for being used in
1.317 albertel 8345: a javascript writeln
1.648 raeburn 8346: html_encode -> return a string ready for being used in
1.320 albertel 8347: a html attribute
1.648 raeburn 8348: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8349: $forcereg arg
1.648 raeburn 8350: frameset -> if true will start with a <frameset>
1.330 albertel 8351: rather than <body>
1.648 raeburn 8352: skip_phases -> hash ref of
1.338 albertel 8353: head -> skip the <html><head> generation
8354: body -> skip all <body> generation
1.1075.2.12 raeburn 8355: no_inline_link -> if true and in remote mode, don't show the
8356: 'Switch To Inline Menu' link
1.648 raeburn 8357: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8358: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8359: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8360: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8361: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8362: group -> includes the current group, if page is for a
8363: specific group
1.1075.2.133 raeburn 8364: use_absolute -> for request for external resource or syllabus, this
8365: will contain https://<hostname> if server uses
8366: https (as per hosts.tab), but request is for http
8367: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8368:
1.648 raeburn 8369: =back
1.460 albertel 8370:
1.648 raeburn 8371: =back
1.562 albertel 8372:
1.306 albertel 8373: =cut
8374:
8375: sub start_page {
1.309 albertel 8376: my ($title,$head_extra,$args) = @_;
1.318 albertel 8377: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8378:
1.315 albertel 8379: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8380: my ($result,@advtools);
1.964 droeschl 8381:
1.338 albertel 8382: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8383: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8384: }
8385:
8386: if (! exists($args->{'skip_phases'}{'body'}) ) {
8387: if ($args->{'frameset'}) {
8388: my $attr_string = &make_attr_string($args->{'force_register'},
8389: $args->{'add_entries'});
8390: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8391: } else {
8392: $result .=
8393: &bodytag($title,
8394: $args->{'function'}, $args->{'add_entries'},
8395: $args->{'only_body'}, $args->{'domain'},
8396: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8397: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8398: $args, \@advtools);
1.831 bisitz 8399: }
1.330 albertel 8400: }
1.338 albertel 8401:
1.315 albertel 8402: if ($args->{'js_ready'}) {
1.713 kaisler 8403: $result = &js_ready($result);
1.315 albertel 8404: }
1.320 albertel 8405: if ($args->{'html_encode'}) {
1.713 kaisler 8406: $result = &html_encode($result);
8407: }
8408:
1.813 bisitz 8409: # Preparation for new and consistent functionlist at top of screen
8410: # if ($args->{'functionlist'}) {
8411: # $result .= &build_functionlist();
8412: #}
8413:
1.964 droeschl 8414: # Don't add anything more if only_body wanted or in const space
8415: return $result if $args->{'only_body'}
8416: || $env{'request.state'} eq 'construct';
1.813 bisitz 8417:
8418: #Breadcrumbs
1.758 kaisler 8419: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8420: &Apache::lonhtmlcommon::clear_breadcrumbs();
8421: #if any br links exists, add them to the breadcrumbs
8422: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8423: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8424: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8425: }
8426: }
1.1075.2.19 raeburn 8427: # if @advtools array contains items add then to the breadcrumbs
8428: if (@advtools > 0) {
8429: &Apache::lonmenu::advtools_crumbs(@advtools);
8430: }
1.1075.2.123 raeburn 8431: my $menulink;
8432: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8433: if (exists($args->{'bread_crumbs_nomenu'})) {
8434: $menulink = 0;
8435: } else {
8436: undef($menulink);
8437: }
1.758 kaisler 8438: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8439: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8440: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8441: }else{
1.1075.2.123 raeburn 8442: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8443: }
1.1075.2.24 raeburn 8444: } elsif (($env{'environment.remote'} eq 'on') &&
8445: ($env{'form.inhibitmenu'} ne 'yes') &&
8446: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8447: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8448: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8449: }
1.315 albertel 8450: return $result;
1.306 albertel 8451: }
8452:
8453: sub end_page {
1.315 albertel 8454: my ($args) = @_;
8455: $env{'internal.end_page'}++;
1.330 albertel 8456: my $result;
1.335 albertel 8457: if ($args->{'discussion'}) {
8458: my ($target,$parser);
8459: if (ref($args->{'discussion'})) {
8460: ($target,$parser) =($args->{'discussion'}{'target'},
8461: $args->{'discussion'}{'parser'});
8462: }
8463: $result .= &Apache::lonxml::xmlend($target,$parser);
8464: }
1.330 albertel 8465: if ($args->{'frameset'}) {
8466: $result .= '</frameset>';
8467: } else {
1.635 raeburn 8468: $result .= &endbodytag($args);
1.330 albertel 8469: }
1.1075.2.6 raeburn 8470: unless ($args->{'notbody'}) {
8471: $result .= "\n</html>";
8472: }
1.330 albertel 8473:
1.315 albertel 8474: if ($args->{'js_ready'}) {
1.317 albertel 8475: $result = &js_ready($result);
1.315 albertel 8476: }
1.335 albertel 8477:
1.320 albertel 8478: if ($args->{'html_encode'}) {
8479: $result = &html_encode($result);
8480: }
1.335 albertel 8481:
1.315 albertel 8482: return $result;
8483: }
8484:
1.1034 www 8485: sub wishlist_window {
8486: return(<<'ENDWISHLIST');
1.1046 raeburn 8487: <script type="text/javascript">
1.1034 www 8488: // <![CDATA[
8489: // <!-- BEGIN LON-CAPA Internal
8490: function set_wishlistlink(title, path) {
8491: if (!title) {
8492: title = document.title;
8493: title = title.replace(/^LON-CAPA /,'');
8494: }
1.1075.2.65 raeburn 8495: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8496: title = title.replace("'","\\\'");
1.1034 www 8497: if (!path) {
8498: path = location.pathname;
8499: }
1.1075.2.65 raeburn 8500: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8501: path = path.replace("'","\\\'");
1.1034 www 8502: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8503: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8504: }
8505: // END LON-CAPA Internal -->
8506: // ]]>
8507: </script>
8508: ENDWISHLIST
8509: }
8510:
1.1030 www 8511: sub modal_window {
8512: return(<<'ENDMODAL');
1.1046 raeburn 8513: <script type="text/javascript">
1.1030 www 8514: // <![CDATA[
8515: // <!-- BEGIN LON-CAPA Internal
8516: var modalWindow = {
8517: parent:"body",
8518: windowId:null,
8519: content:null,
8520: width:null,
8521: height:null,
8522: close:function()
8523: {
8524: $(".LCmodal-window").remove();
8525: $(".LCmodal-overlay").remove();
8526: },
8527: open:function()
8528: {
8529: var modal = "";
8530: modal += "<div class=\"LCmodal-overlay\"></div>";
8531: 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;\">";
8532: modal += this.content;
8533: modal += "</div>";
8534:
8535: $(this.parent).append(modal);
8536:
8537: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8538: $(".LCclose-window").click(function(){modalWindow.close();});
8539: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8540: }
8541: };
1.1075.2.42 raeburn 8542: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8543: {
1.1075.2.119 raeburn 8544: source = source.replace(/'/g,"'");
1.1030 www 8545: modalWindow.windowId = "myModal";
8546: modalWindow.width = width;
8547: modalWindow.height = height;
1.1075.2.80 raeburn 8548: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8549: modalWindow.open();
1.1075.2.87 raeburn 8550: };
1.1030 www 8551: // END LON-CAPA Internal -->
8552: // ]]>
8553: </script>
8554: ENDMODAL
8555: }
8556:
8557: sub modal_link {
1.1075.2.42 raeburn 8558: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8559: unless ($width) { $width=480; }
8560: unless ($height) { $height=400; }
1.1031 www 8561: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8562: unless ($transparency) { $transparency='true'; }
8563:
1.1074 raeburn 8564: my $target_attr;
8565: if (defined($target)) {
8566: $target_attr = 'target="'.$target.'"';
8567: }
8568: return <<"ENDLINK";
1.1075.2.141. .3(raebu 8569:20): <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8570: ENDLINK
1.1030 www 8571: }
8572:
1.1032 www 8573: sub modal_adhoc_script {
8574: my ($funcname,$width,$height,$content)=@_;
8575: return (<<ENDADHOC);
1.1046 raeburn 8576: <script type="text/javascript">
1.1032 www 8577: // <![CDATA[
8578: var $funcname = function()
8579: {
8580: modalWindow.windowId = "myModal";
8581: modalWindow.width = $width;
8582: modalWindow.height = $height;
8583: modalWindow.content = '$content';
8584: modalWindow.open();
8585: };
8586: // ]]>
8587: </script>
8588: ENDADHOC
8589: }
8590:
1.1041 www 8591: sub modal_adhoc_inner {
8592: my ($funcname,$width,$height,$content)=@_;
8593: my $innerwidth=$width-20;
8594: $content=&js_ready(
1.1042 www 8595: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8596: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8597: $content.
1.1041 www 8598: &end_scrollbox().
1.1075.2.42 raeburn 8599: &end_page()
1.1041 www 8600: );
8601: return &modal_adhoc_script($funcname,$width,$height,$content);
8602: }
8603:
8604: sub modal_adhoc_window {
8605: my ($funcname,$width,$height,$content,$linktext)=@_;
8606: return &modal_adhoc_inner($funcname,$width,$height,$content).
8607: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8608: }
8609:
8610: sub modal_adhoc_launch {
8611: my ($funcname,$width,$height,$content)=@_;
8612: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8613: <script type="text/javascript">
8614: // <![CDATA[
8615: $funcname();
8616: // ]]>
8617: </script>
8618: ENDLAUNCH
8619: }
8620:
8621: sub modal_adhoc_close {
8622: return (<<ENDCLOSE);
8623: <script type="text/javascript">
8624: // <![CDATA[
8625: modalWindow.close();
8626: // ]]>
8627: </script>
8628: ENDCLOSE
8629: }
8630:
1.1038 www 8631: sub togglebox_script {
8632: return(<<ENDTOGGLE);
8633: <script type="text/javascript">
8634: // <![CDATA[
8635: function LCtoggleDisplay(id,hidetext,showtext) {
8636: link = document.getElementById(id + "link").childNodes[0];
8637: with (document.getElementById(id).style) {
8638: if (display == "none" ) {
8639: display = "inline";
8640: link.nodeValue = hidetext;
8641: } else {
8642: display = "none";
8643: link.nodeValue = showtext;
8644: }
8645: }
8646: }
8647: // ]]>
8648: </script>
8649: ENDTOGGLE
8650: }
8651:
1.1039 www 8652: sub start_togglebox {
8653: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8654: unless ($heading) { $heading=''; } else { $heading.=' '; }
8655: unless ($showtext) { $showtext=&mt('show'); }
8656: unless ($hidetext) { $hidetext=&mt('hide'); }
8657: unless ($headerbg) { $headerbg='#FFFFFF'; }
8658: return &start_data_table().
8659: &start_data_table_header_row().
8660: '<td bgcolor="'.$headerbg.'">'.$heading.
8661: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8662: $showtext.'\')">'.$showtext.'</a>]</td>'.
8663: &end_data_table_header_row().
8664: '<tr id="'.$id.'" style="display:none""><td>';
8665: }
8666:
8667: sub end_togglebox {
8668: return '</td></tr>'.&end_data_table();
8669: }
8670:
1.1041 www 8671: sub LCprogressbar_script {
1.1075.2.130 raeburn 8672: my ($id,$number_to_do)=@_;
8673: if ($number_to_do) {
8674: return(<<ENDPROGRESS);
1.1041 www 8675: <script type="text/javascript">
8676: // <![CDATA[
1.1045 www 8677: \$('#progressbar$id').progressbar({
1.1041 www 8678: value: 0,
8679: change: function(event, ui) {
8680: var newVal = \$(this).progressbar('option', 'value');
8681: \$('.pblabel', this).text(LCprogressTxt);
8682: }
8683: });
8684: // ]]>
8685: </script>
8686: ENDPROGRESS
1.1075.2.130 raeburn 8687: } else {
8688: return(<<ENDPROGRESS);
8689: <script type="text/javascript">
8690: // <![CDATA[
8691: \$('#progressbar$id').progressbar({
8692: value: false,
8693: create: function(event, ui) {
8694: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8695: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8696: }
8697: });
8698: // ]]>
8699: </script>
8700: ENDPROGRESS
8701: }
1.1041 www 8702: }
8703:
8704: sub LCprogressbarUpdate_script {
8705: return(<<ENDPROGRESSUPDATE);
8706: <style type="text/css">
8707: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8708: .progress-label {position: absolute; width: 100%; text-align: center; top: 1px; font-weight: bold; text-shadow: 1px 1px 0 #fff;margin: 0; line-height: 200%; }
1.1041 www 8709: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8710: </style>
8711: <script type="text/javascript">
8712: // <![CDATA[
1.1045 www 8713: var LCprogressTxt='---';
8714:
1.1075.2.130 raeburn 8715: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8716: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8717: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8718: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8719: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8720: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8721: } else {
8722: \$('#progressbar'+id).progressbar('value',percent);
8723: }
1.1041 www 8724: }
8725: // ]]>
8726: </script>
8727: ENDPROGRESSUPDATE
8728: }
8729:
1.1042 www 8730: my $LClastpercent;
1.1045 www 8731: my $LCidcnt;
8732: my $LCcurrentid;
1.1042 www 8733:
1.1041 www 8734: sub LCprogressbar {
1.1075.2.130 raeburn 8735: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8736: $LClastpercent=0;
1.1045 www 8737: $LCidcnt++;
8738: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8739: my ($starting,$content);
8740: if ($number_to_do) {
8741: $starting=&mt('Starting');
8742: $content=(<<ENDPROGBAR);
8743: $preamble
1.1045 www 8744: <div id="progressbar$LCcurrentid">
1.1041 www 8745: <span class="pblabel">$starting</span>
8746: </div>
8747: ENDPROGBAR
1.1075.2.130 raeburn 8748: } else {
8749: $starting=&mt('Loading...');
8750: $LClastpercent='false';
8751: $content=(<<ENDPROGBAR);
8752: $preamble
8753: <div id="progressbar$LCcurrentid">
8754: <div class="progress-label">$starting</div>
8755: </div>
8756: ENDPROGBAR
8757: }
8758: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8759: }
8760:
8761: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8762: my ($r,$val,$text,$number_to_do)=@_;
8763: if ($number_to_do) {
8764: unless ($val) {
8765: if ($LClastpercent) {
8766: $val=$LClastpercent;
8767: } else {
8768: $val=0;
8769: }
8770: }
8771: if ($val<0) { $val=0; }
8772: if ($val>100) { $val=0; }
8773: $LClastpercent=$val;
8774: unless ($text) { $text=$val.'%'; }
8775: } else {
8776: $val = 'false';
1.1042 www 8777: }
1.1041 www 8778: $text=&js_ready($text);
1.1044 www 8779: &r_print($r,<<ENDUPDATE);
1.1041 www 8780: <script type="text/javascript">
8781: // <![CDATA[
1.1075.2.130 raeburn 8782: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8783: // ]]>
8784: </script>
8785: ENDUPDATE
1.1035 www 8786: }
8787:
1.1042 www 8788: sub LCprogressbarClose {
8789: my ($r)=@_;
8790: $LClastpercent=0;
1.1044 www 8791: &r_print($r,<<ENDCLOSE);
1.1042 www 8792: <script type="text/javascript">
8793: // <![CDATA[
1.1045 www 8794: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8795: // ]]>
8796: </script>
8797: ENDCLOSE
1.1044 www 8798: }
8799:
8800: sub r_print {
8801: my ($r,$to_print)=@_;
8802: if ($r) {
8803: $r->print($to_print);
8804: $r->rflush();
8805: } else {
8806: print($to_print);
8807: }
1.1042 www 8808: }
8809:
1.320 albertel 8810: sub html_encode {
8811: my ($result) = @_;
8812:
1.322 albertel 8813: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8814:
8815: return $result;
8816: }
1.1044 www 8817:
1.317 albertel 8818: sub js_ready {
8819: my ($result) = @_;
8820:
1.323 albertel 8821: $result =~ s/[\n\r]/ /xmsg;
8822: $result =~ s/\\/\\\\/xmsg;
8823: $result =~ s/'/\\'/xmsg;
1.372 albertel 8824: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8825:
8826: return $result;
8827: }
8828:
1.315 albertel 8829: sub validate_page {
8830: if ( exists($env{'internal.start_page'})
1.316 albertel 8831: && $env{'internal.start_page'} > 1) {
8832: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8833: $env{'internal.start_page'}.' '.
1.316 albertel 8834: $ENV{'request.filename'});
1.315 albertel 8835: }
8836: if ( exists($env{'internal.end_page'})
1.316 albertel 8837: && $env{'internal.end_page'} > 1) {
8838: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8839: $env{'internal.end_page'}.' '.
1.316 albertel 8840: $env{'request.filename'});
1.315 albertel 8841: }
8842: if ( exists($env{'internal.start_page'})
8843: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8844: &Apache::lonnet::logthis('start_page called without end_page '.
8845: $env{'request.filename'});
1.315 albertel 8846: }
8847: if ( ! exists($env{'internal.start_page'})
8848: && exists($env{'internal.end_page'})) {
1.316 albertel 8849: &Apache::lonnet::logthis('end_page called without start_page'.
8850: $env{'request.filename'});
1.315 albertel 8851: }
1.306 albertel 8852: }
1.315 albertel 8853:
1.996 www 8854:
8855: sub start_scrollbox {
1.1075.2.56 raeburn 8856: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8857: unless ($outerwidth) { $outerwidth='520px'; }
8858: unless ($width) { $width='500px'; }
8859: unless ($height) { $height='200px'; }
1.1075 raeburn 8860: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8861: if ($id ne '') {
1.1075.2.42 raeburn 8862: $table_id = ' id="table_'.$id.'"';
8863: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8864: }
1.1075 raeburn 8865: if ($bgcolor ne '') {
8866: $tdcol = "background-color: $bgcolor;";
8867: }
1.1075.2.42 raeburn 8868: my $nicescroll_js;
8869: if ($env{'browser.mobile'}) {
8870: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8871: }
1.1075 raeburn 8872: return <<"END";
1.1075.2.42 raeburn 8873: $nicescroll_js
8874:
8875: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8876: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8877: END
1.996 www 8878: }
8879:
8880: sub end_scrollbox {
1.1036 www 8881: return '</div></td></tr></table>';
1.996 www 8882: }
8883:
1.1075.2.42 raeburn 8884: sub nicescroll_javascript {
8885: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8886: my %options;
8887: if (ref($cursor) eq 'HASH') {
8888: %options = %{$cursor};
8889: }
8890: unless ($options{'railalign'} =~ /^left|right$/) {
8891: $options{'railalign'} = 'left';
8892: }
8893: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8894: my $function = &get_users_function();
8895: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8896: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8897: $options{'cursorcolor'} = '#00F';
8898: }
8899: }
8900: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8901: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8902: $options{'cursoropacity'}='1.0';
8903: }
8904: } else {
8905: $options{'cursoropacity'}='1.0';
8906: }
8907: if ($options{'cursorfixedheight'} eq 'none') {
8908: delete($options{'cursorfixedheight'});
8909: } else {
8910: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8911: }
8912: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8913: delete($options{'railoffset'});
8914: }
8915: my @niceoptions;
8916: while (my($key,$value) = each(%options)) {
8917: if ($value =~ /^\{.+\}$/) {
8918: push(@niceoptions,$key.':'.$value);
8919: } else {
8920: push(@niceoptions,$key.':"'.$value.'"');
8921: }
8922: }
8923: my $nicescroll_js = '
8924: $(document).ready(
8925: function() {
8926: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8927: }
8928: );
8929: ';
8930: if ($framecheck) {
8931: $nicescroll_js .= '
8932: function expand_div(caller) {
8933: if (top === self) {
8934: document.getElementById("'.$id.'").style.width = "auto";
8935: document.getElementById("'.$id.'").style.height = "auto";
8936: } else {
8937: try {
8938: if (parent.frames) {
8939: if (parent.frames.length > 1) {
8940: var framesrc = parent.frames[1].location.href;
8941: var currsrc = framesrc.replace(/\#.*$/,"");
8942: if ((caller == "search") || (currsrc == "'.$location.'")) {
8943: document.getElementById("'.$id.'").style.width = "auto";
8944: document.getElementById("'.$id.'").style.height = "auto";
8945: }
8946: }
8947: }
8948: } catch (e) {
8949: return;
8950: }
8951: }
8952: return;
8953: }
8954: ';
8955: }
8956: if ($needjsready) {
8957: $nicescroll_js = '
8958: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8959: } else {
8960: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8961: }
8962: return $nicescroll_js;
8963: }
8964:
1.318 albertel 8965: sub simple_error_page {
1.1075.2.49 raeburn 8966: my ($r,$title,$msg,$args) = @_;
8967: if (ref($args) eq 'HASH') {
8968: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8969: } else {
8970: $msg = &mt($msg);
8971: }
8972:
1.318 albertel 8973: my $page =
8974: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8975: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8976: &Apache::loncommon::end_page();
8977: if (ref($r)) {
8978: $r->print($page);
1.327 albertel 8979: return;
1.318 albertel 8980: }
8981: return $page;
8982: }
1.347 albertel 8983:
8984: {
1.610 albertel 8985: my @row_count;
1.961 onken 8986:
8987: sub start_data_table_count {
8988: unshift(@row_count, 0);
8989: return;
8990: }
8991:
8992: sub end_data_table_count {
8993: shift(@row_count);
8994: return;
8995: }
8996:
1.347 albertel 8997: sub start_data_table {
1.1018 raeburn 8998: my ($add_class,$id) = @_;
1.422 albertel 8999: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9000: my $table_id;
9001: if (defined($id)) {
9002: $table_id = ' id="'.$id.'"';
9003: }
1.961 onken 9004: &start_data_table_count();
1.1018 raeburn 9005: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9006: }
9007:
9008: sub end_data_table {
1.961 onken 9009: &end_data_table_count();
1.389 albertel 9010: return '</table>'."\n";;
1.347 albertel 9011: }
9012:
9013: sub start_data_table_row {
1.974 wenzelju 9014: my ($add_class, $id) = @_;
1.610 albertel 9015: $row_count[0]++;
9016: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9017: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9018: $id = (' id="'.$id.'"') unless ($id eq '');
9019: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9020: }
1.471 banghart 9021:
9022: sub continue_data_table_row {
1.974 wenzelju 9023: my ($add_class, $id) = @_;
1.610 albertel 9024: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9025: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9026: $id = (' id="'.$id.'"') unless ($id eq '');
9027: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9028: }
1.347 albertel 9029:
9030: sub end_data_table_row {
1.389 albertel 9031: return '</tr>'."\n";;
1.347 albertel 9032: }
1.367 www 9033:
1.421 albertel 9034: sub start_data_table_empty_row {
1.707 bisitz 9035: # $row_count[0]++;
1.421 albertel 9036: return '<tr class="LC_empty_row" >'."\n";;
9037: }
9038:
9039: sub end_data_table_empty_row {
9040: return '</tr>'."\n";;
9041: }
9042:
1.367 www 9043: sub start_data_table_header_row {
1.389 albertel 9044: return '<tr class="LC_header_row">'."\n";;
1.367 www 9045: }
9046:
9047: sub end_data_table_header_row {
1.389 albertel 9048: return '</tr>'."\n";;
1.367 www 9049: }
1.890 droeschl 9050:
9051: sub data_table_caption {
9052: my $caption = shift;
9053: return "<caption class=\"LC_caption\">$caption</caption>";
9054: }
1.347 albertel 9055: }
9056:
1.548 albertel 9057: =pod
9058:
9059: =item * &inhibit_menu_check($arg)
9060:
9061: Checks for a inhibitmenu state and generates output to preserve it
9062:
9063: Inputs: $arg - can be any of
9064: - undef - in which case the return value is a string
9065: to add into arguments list of a uri
9066: - 'input' - in which case the return value is a HTML
9067: <form> <input> field of type hidden to
9068: preserve the value
9069: - a url - in which case the return value is the url with
9070: the neccesary cgi args added to preserve the
9071: inhibitmenu state
9072: - a ref to a url - no return value, but the string is
9073: updated to include the neccessary cgi
9074: args to preserve the inhibitmenu state
9075:
9076: =cut
9077:
9078: sub inhibit_menu_check {
9079: my ($arg) = @_;
9080: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9081: if ($arg eq 'input') {
9082: if ($env{'form.inhibitmenu'}) {
9083: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9084: } else {
9085: return
9086: }
9087: }
9088: if ($env{'form.inhibitmenu'}) {
9089: if (ref($arg)) {
9090: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9091: } elsif ($arg eq '') {
9092: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9093: } else {
9094: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9095: }
9096: }
9097: if (!ref($arg)) {
9098: return $arg;
9099: }
9100: }
9101:
1.251 albertel 9102: ###############################################
1.182 matthew 9103:
9104: =pod
9105:
1.549 albertel 9106: =back
9107:
9108: =head1 User Information Routines
9109:
9110: =over 4
9111:
1.405 albertel 9112: =item * &get_users_function()
1.182 matthew 9113:
9114: Used by &bodytag to determine the current users primary role.
9115: Returns either 'student','coordinator','admin', or 'author'.
9116:
9117: =cut
9118:
9119: ###############################################
9120: sub get_users_function {
1.815 tempelho 9121: my $function = 'norole';
1.818 tempelho 9122: if ($env{'request.role'}=~/^(st)/) {
9123: $function='student';
9124: }
1.907 raeburn 9125: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9126: $function='coordinator';
9127: }
1.258 albertel 9128: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9129: $function='admin';
9130: }
1.826 bisitz 9131: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9132: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9133: $function='author';
9134: }
9135: return $function;
1.54 www 9136: }
1.99 www 9137:
9138: ###############################################
9139:
1.233 raeburn 9140: =pod
9141:
1.821 raeburn 9142: =item * &show_course()
9143:
9144: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9145: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9146:
9147: Inputs:
9148: None
9149:
9150: Outputs:
9151: Scalar: 1 if 'Course' to be used, 0 otherwise.
9152:
9153: =cut
9154:
9155: ###############################################
9156: sub show_course {
9157: my $course = !$env{'user.adv'};
9158: if (!$env{'user.adv'}) {
9159: foreach my $env (keys(%env)) {
9160: next if ($env !~ m/^user\.priv\./);
9161: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9162: $course = 0;
9163: last;
9164: }
9165: }
9166: }
9167: return $course;
9168: }
9169:
9170: ###############################################
9171:
9172: =pod
9173:
1.542 raeburn 9174: =item * &check_user_status()
1.274 raeburn 9175:
9176: Determines current status of supplied role for a
9177: specific user. Roles can be active, previous or future.
9178:
9179: Inputs:
9180: user's domain, user's username, course's domain,
1.375 raeburn 9181: course's number, optional section ID.
1.274 raeburn 9182:
9183: Outputs:
9184: role status: active, previous or future.
9185:
9186: =cut
9187:
9188: sub check_user_status {
1.412 raeburn 9189: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9190: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9191: my @uroles = keys(%userinfo);
1.274 raeburn 9192: my $srchstr;
9193: my $active_chk = 'none';
1.412 raeburn 9194: my $now = time;
1.274 raeburn 9195: if (@uroles > 0) {
1.908 raeburn 9196: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9197: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9198: } else {
1.412 raeburn 9199: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9200: }
9201: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9202: my $role_end = 0;
9203: my $role_start = 0;
9204: $active_chk = 'active';
1.412 raeburn 9205: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9206: $role_end = $1;
9207: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9208: $role_start = $1;
1.274 raeburn 9209: }
9210: }
9211: if ($role_start > 0) {
1.412 raeburn 9212: if ($now < $role_start) {
1.274 raeburn 9213: $active_chk = 'future';
9214: }
9215: }
9216: if ($role_end > 0) {
1.412 raeburn 9217: if ($now > $role_end) {
1.274 raeburn 9218: $active_chk = 'previous';
9219: }
9220: }
9221: }
9222: }
9223: return $active_chk;
9224: }
9225:
9226: ###############################################
9227:
9228: =pod
9229:
1.405 albertel 9230: =item * &get_sections()
1.233 raeburn 9231:
9232: Determines all the sections for a course including
9233: sections with students and sections containing other roles.
1.419 raeburn 9234: Incoming parameters:
9235:
9236: 1. domain
9237: 2. course number
9238: 3. reference to array containing roles for which sections should
9239: be gathered (optional).
9240: 4. reference to array containing status types for which sections
9241: should be gathered (optional).
9242:
9243: If the third argument is undefined, sections are gathered for any role.
9244: If the fourth argument is undefined, sections are gathered for any status.
9245: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9246:
1.374 raeburn 9247: Returns section hash (keys are section IDs, values are
9248: number of users in each section), subject to the
1.419 raeburn 9249: optional roles filter, optional status filter
1.233 raeburn 9250:
9251: =cut
9252:
9253: ###############################################
9254: sub get_sections {
1.419 raeburn 9255: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9256: if (!defined($cdom) || !defined($cnum)) {
9257: my $cid = $env{'request.course.id'};
9258:
9259: return if (!defined($cid));
9260:
9261: $cdom = $env{'course.'.$cid.'.domain'};
9262: $cnum = $env{'course.'.$cid.'.num'};
9263: }
9264:
9265: my %sectioncount;
1.419 raeburn 9266: my $now = time;
1.240 albertel 9267:
1.1075.2.33 raeburn 9268: my $check_students = 1;
9269: my $only_students = 0;
9270: if (ref($possible_roles) eq 'ARRAY') {
9271: if (grep(/^st$/,@{$possible_roles})) {
9272: if (@{$possible_roles} == 1) {
9273: $only_students = 1;
9274: }
9275: } else {
9276: $check_students = 0;
9277: }
9278: }
9279:
9280: if ($check_students) {
1.276 albertel 9281: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9282: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9283: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9284: my $start_index = &Apache::loncoursedata::CL_START();
9285: my $end_index = &Apache::loncoursedata::CL_END();
9286: my $status;
1.366 albertel 9287: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9288: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9289: $data->[$status_index],
9290: $data->[$start_index],
9291: $data->[$end_index]);
9292: if ($stu_status eq 'Active') {
9293: $status = 'active';
9294: } elsif ($end < $now) {
9295: $status = 'previous';
9296: } elsif ($start > $now) {
9297: $status = 'future';
9298: }
9299: if ($section ne '-1' && $section !~ /^\s*$/) {
9300: if ((!defined($possible_status)) || (($status ne '') &&
9301: (grep/^\Q$status\E$/,@{$possible_status}))) {
9302: $sectioncount{$section}++;
9303: }
1.240 albertel 9304: }
9305: }
9306: }
1.1075.2.33 raeburn 9307: if ($only_students) {
9308: return %sectioncount;
9309: }
1.240 albertel 9310: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9311: foreach my $user (sort(keys(%courseroles))) {
9312: if ($user !~ /^(\w{2})/) { next; }
9313: my ($role) = ($user =~ /^(\w{2})/);
9314: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9315: my ($section,$status);
1.240 albertel 9316: if ($role eq 'cr' &&
9317: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9318: $section=$1;
9319: }
9320: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9321: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9322: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9323: if ($end == -1 && $start == -1) {
9324: next; #deleted role
9325: }
9326: if (!defined($possible_status)) {
9327: $sectioncount{$section}++;
9328: } else {
9329: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9330: $status = 'active';
9331: } elsif ($end < $now) {
9332: $status = 'future';
9333: } elsif ($start > $now) {
9334: $status = 'previous';
9335: }
9336: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9337: $sectioncount{$section}++;
9338: }
9339: }
1.233 raeburn 9340: }
1.366 albertel 9341: return %sectioncount;
1.233 raeburn 9342: }
9343:
1.274 raeburn 9344: ###############################################
1.294 raeburn 9345:
9346: =pod
1.405 albertel 9347:
9348: =item * &get_course_users()
9349:
1.275 raeburn 9350: Retrieves usernames:domains for users in the specified course
9351: with specific role(s), and access status.
9352:
9353: Incoming parameters:
1.277 albertel 9354: 1. course domain
9355: 2. course number
9356: 3. access status: users must have - either active,
1.275 raeburn 9357: previous, future, or all.
1.277 albertel 9358: 4. reference to array of permissible roles
1.288 raeburn 9359: 5. reference to array of section restrictions (optional)
9360: 6. reference to results object (hash of hashes).
9361: 7. reference to optional userdata hash
1.609 raeburn 9362: 8. reference to optional statushash
1.630 raeburn 9363: 9. flag if privileged users (except those set to unhide in
9364: course settings) should be excluded
1.609 raeburn 9365: Keys of top level results hash are roles.
1.275 raeburn 9366: Keys of inner hashes are username:domain, with
9367: values set to access type.
1.288 raeburn 9368: Optional userdata hash returns an array with arguments in the
9369: same order as loncoursedata::get_classlist() for student data.
9370:
1.609 raeburn 9371: Optional statushash returns
9372:
1.288 raeburn 9373: Entries for end, start, section and status are blank because
9374: of the possibility of multiple values for non-student roles.
9375:
1.275 raeburn 9376: =cut
1.405 albertel 9377:
1.275 raeburn 9378: ###############################################
1.405 albertel 9379:
1.275 raeburn 9380: sub get_course_users {
1.630 raeburn 9381: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9382: my %idx = ();
1.419 raeburn 9383: my %seclists;
1.288 raeburn 9384:
9385: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9386: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9387: $idx{end} = &Apache::loncoursedata::CL_END();
9388: $idx{start} = &Apache::loncoursedata::CL_START();
9389: $idx{id} = &Apache::loncoursedata::CL_ID();
9390: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9391: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9392: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9393:
1.290 albertel 9394: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9395: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9396: my $now = time;
1.277 albertel 9397: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9398: my $match = 0;
1.412 raeburn 9399: my $secmatch = 0;
1.419 raeburn 9400: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9401: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9402: if ($section eq '') {
9403: $section = 'none';
9404: }
1.291 albertel 9405: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9406: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9407: $secmatch = 1;
9408: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9409: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9410: $secmatch = 1;
9411: }
9412: } else {
1.419 raeburn 9413: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9414: $secmatch = 1;
9415: }
1.290 albertel 9416: }
1.412 raeburn 9417: if (!$secmatch) {
9418: next;
9419: }
1.419 raeburn 9420: }
1.275 raeburn 9421: if (defined($$types{'active'})) {
1.288 raeburn 9422: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9423: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9424: $match = 1;
1.275 raeburn 9425: }
9426: }
9427: if (defined($$types{'previous'})) {
1.609 raeburn 9428: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9429: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9430: $match = 1;
1.275 raeburn 9431: }
9432: }
9433: if (defined($$types{'future'})) {
1.609 raeburn 9434: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9435: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9436: $match = 1;
1.275 raeburn 9437: }
9438: }
1.609 raeburn 9439: if ($match) {
9440: push(@{$seclists{$student}},$section);
9441: if (ref($userdata) eq 'HASH') {
9442: $$userdata{$student} = $$classlist{$student};
9443: }
9444: if (ref($statushash) eq 'HASH') {
9445: $statushash->{$student}{'st'}{$section} = $status;
9446: }
1.288 raeburn 9447: }
1.275 raeburn 9448: }
9449: }
1.412 raeburn 9450: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9451: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9452: my $now = time;
1.609 raeburn 9453: my %displaystatus = ( previous => 'Expired',
9454: active => 'Active',
9455: future => 'Future',
9456: );
1.1075.2.36 raeburn 9457: my (%nothide,@possdoms);
1.630 raeburn 9458: if ($hidepriv) {
9459: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9460: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9461: if ($user !~ /:/) {
9462: $nothide{join(':',split(/[\@]/,$user))}=1;
9463: } else {
9464: $nothide{$user} = 1;
9465: }
9466: }
1.1075.2.36 raeburn 9467: my @possdoms = ($cdom);
9468: if ($coursehash{'checkforpriv'}) {
9469: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9470: }
1.630 raeburn 9471: }
1.439 raeburn 9472: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9473: my $match = 0;
1.412 raeburn 9474: my $secmatch = 0;
1.439 raeburn 9475: my $status;
1.412 raeburn 9476: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9477: $user =~ s/:$//;
1.439 raeburn 9478: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9479: if ($end == -1 || $start == -1) {
9480: next;
9481: }
9482: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9483: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9484: my ($uname,$udom) = split(/:/,$user);
9485: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9486: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9487: $secmatch = 1;
9488: } elsif ($usec eq '') {
1.420 albertel 9489: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9490: $secmatch = 1;
9491: }
9492: } else {
9493: if (grep(/^\Q$usec\E$/,@{$sections})) {
9494: $secmatch = 1;
9495: }
9496: }
9497: if (!$secmatch) {
9498: next;
9499: }
1.288 raeburn 9500: }
1.419 raeburn 9501: if ($usec eq '') {
9502: $usec = 'none';
9503: }
1.275 raeburn 9504: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9505: if ($hidepriv) {
1.1075.2.36 raeburn 9506: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9507: (!$nothide{$uname.':'.$udom})) {
9508: next;
9509: }
9510: }
1.503 raeburn 9511: if ($end > 0 && $end < $now) {
1.439 raeburn 9512: $status = 'previous';
9513: } elsif ($start > $now) {
9514: $status = 'future';
9515: } else {
9516: $status = 'active';
9517: }
1.277 albertel 9518: foreach my $type (keys(%{$types})) {
1.275 raeburn 9519: if ($status eq $type) {
1.420 albertel 9520: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9521: push(@{$$users{$role}{$user}},$type);
9522: }
1.288 raeburn 9523: $match = 1;
9524: }
9525: }
1.419 raeburn 9526: if (($match) && (ref($userdata) eq 'HASH')) {
9527: if (!exists($$userdata{$uname.':'.$udom})) {
9528: &get_user_info($udom,$uname,\%idx,$userdata);
9529: }
1.420 albertel 9530: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9531: push(@{$seclists{$uname.':'.$udom}},$usec);
9532: }
1.609 raeburn 9533: if (ref($statushash) eq 'HASH') {
9534: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9535: }
1.275 raeburn 9536: }
9537: }
9538: }
9539: }
1.290 albertel 9540: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9541: if ((defined($cdom)) && (defined($cnum))) {
9542: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9543: if ( defined($csettings{'internal.courseowner'}) ) {
9544: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9545: next if ($owner eq '');
9546: my ($ownername,$ownerdom);
9547: if ($owner =~ /^([^:]+):([^:]+)$/) {
9548: $ownername = $1;
9549: $ownerdom = $2;
9550: } else {
9551: $ownername = $owner;
9552: $ownerdom = $cdom;
9553: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9554: }
9555: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9556: if (defined($userdata) &&
1.609 raeburn 9557: !exists($$userdata{$owner})) {
9558: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9559: if (!grep(/^none$/,@{$seclists{$owner}})) {
9560: push(@{$seclists{$owner}},'none');
9561: }
9562: if (ref($statushash) eq 'HASH') {
9563: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9564: }
1.290 albertel 9565: }
1.279 raeburn 9566: }
9567: }
9568: }
1.419 raeburn 9569: foreach my $user (keys(%seclists)) {
9570: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9571: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9572: }
1.275 raeburn 9573: }
9574: return;
9575: }
9576:
1.288 raeburn 9577: sub get_user_info {
9578: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9579: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9580: &plainname($uname,$udom,'lastname');
1.291 albertel 9581: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9582: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9583: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9584: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9585: return;
9586: }
1.275 raeburn 9587:
1.472 raeburn 9588: ###############################################
9589:
9590: =pod
9591:
9592: =item * &get_user_quota()
9593:
1.1075.2.41 raeburn 9594: Retrieves quota assigned for storage of user files.
9595: Default is to report quota for portfolio files.
1.472 raeburn 9596:
9597: Incoming parameters:
9598: 1. user's username
9599: 2. user's domain
1.1075.2.41 raeburn 9600: 3. quota name - portfolio, author, or course
9601: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9602: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9603: course
1.472 raeburn 9604:
9605: Returns:
1.1075.2.58 raeburn 9606: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9607: 2. (Optional) Type of setting: custom or default
9608: (individually assigned or default for user's
9609: institutional status).
9610: 3. (Optional) - User's institutional status (e.g., faculty, staff
9611: or student - types as defined in localenroll::inst_usertypes
9612: for user's domain, which determines default quota for user.
9613: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9614:
9615: If a value has been stored in the user's environment,
1.536 raeburn 9616: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9617: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9618:
9619: =cut
9620:
9621: ###############################################
9622:
9623:
9624: sub get_user_quota {
1.1075.2.42 raeburn 9625: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9626: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9627: if (!defined($udom)) {
9628: $udom = $env{'user.domain'};
9629: }
9630: if (!defined($uname)) {
9631: $uname = $env{'user.name'};
9632: }
9633: if (($udom eq '' || $uname eq '') ||
9634: ($udom eq 'public') && ($uname eq 'public')) {
9635: $quota = 0;
1.536 raeburn 9636: $quotatype = 'default';
9637: $defquota = 0;
1.472 raeburn 9638: } else {
1.536 raeburn 9639: my $inststatus;
1.1075.2.41 raeburn 9640: if ($quotaname eq 'course') {
9641: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9642: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9643: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9644: } else {
9645: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9646: $quota = $cenv{'internal.uploadquota'};
9647: }
1.536 raeburn 9648: } else {
1.1075.2.41 raeburn 9649: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9650: if ($quotaname eq 'author') {
9651: $quota = $env{'environment.authorquota'};
9652: } else {
9653: $quota = $env{'environment.portfolioquota'};
9654: }
9655: $inststatus = $env{'environment.inststatus'};
9656: } else {
9657: my %userenv =
9658: &Apache::lonnet::get('environment',['portfolioquota',
9659: 'authorquota','inststatus'],$udom,$uname);
9660: my ($tmp) = keys(%userenv);
9661: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9662: if ($quotaname eq 'author') {
9663: $quota = $userenv{'authorquota'};
9664: } else {
9665: $quota = $userenv{'portfolioquota'};
9666: }
9667: $inststatus = $userenv{'inststatus'};
9668: } else {
9669: undef(%userenv);
9670: }
9671: }
9672: }
9673: if ($quota eq '' || wantarray) {
9674: if ($quotaname eq 'course') {
9675: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9676: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9677: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9678: $defquota = $domdefs{$crstype.'quota'};
9679: }
9680: if ($defquota eq '') {
9681: $defquota = 500;
9682: }
1.1075.2.41 raeburn 9683: } else {
9684: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9685: }
9686: if ($quota eq '') {
9687: $quota = $defquota;
9688: $quotatype = 'default';
9689: } else {
9690: $quotatype = 'custom';
9691: }
1.472 raeburn 9692: }
9693: }
1.536 raeburn 9694: if (wantarray) {
9695: return ($quota,$quotatype,$settingstatus,$defquota);
9696: } else {
9697: return $quota;
9698: }
1.472 raeburn 9699: }
9700:
9701: ###############################################
9702:
9703: =pod
9704:
9705: =item * &default_quota()
9706:
1.536 raeburn 9707: Retrieves default quota assigned for storage of user portfolio files,
9708: given an (optional) user's institutional status.
1.472 raeburn 9709:
9710: Incoming parameters:
1.1075.2.42 raeburn 9711:
1.472 raeburn 9712: 1. domain
1.536 raeburn 9713: 2. (Optional) institutional status(es). This is a : separated list of
9714: status types (e.g., faculty, staff, student etc.)
9715: which apply to the user for whom the default is being retrieved.
9716: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9717: default quota will be returned.
9718: 3. quota name - portfolio, author, or course
9719: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9720:
9721: Returns:
1.1075.2.42 raeburn 9722:
1.1075.2.58 raeburn 9723: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9724: 2. (Optional) institutional type which determined the value of the
9725: default quota.
1.472 raeburn 9726:
9727: If a value has been stored in the domain's configuration db,
9728: it will return that, otherwise it returns 20 (for backwards
9729: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9730: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9731:
1.536 raeburn 9732: If the user's status includes multiple types (e.g., staff and student),
9733: the largest default quota which applies to the user determines the
9734: default quota returned.
9735:
1.472 raeburn 9736: =cut
9737:
9738: ###############################################
9739:
9740:
9741: sub default_quota {
1.1075.2.41 raeburn 9742: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9743: my ($defquota,$settingstatus);
9744: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9745: ['quotas'],$udom);
1.1075.2.41 raeburn 9746: my $key = 'defaultquota';
9747: if ($quotaname eq 'author') {
9748: $key = 'authorquota';
9749: }
1.622 raeburn 9750: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9751: if ($inststatus ne '') {
1.765 raeburn 9752: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9753: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9754: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9755: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9756: if ($defquota eq '') {
1.1075.2.41 raeburn 9757: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9758: $settingstatus = $item;
1.1075.2.41 raeburn 9759: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9760: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9761: $settingstatus = $item;
9762: }
9763: }
1.1075.2.41 raeburn 9764: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9765: if ($quotahash{'quotas'}{$item} ne '') {
9766: if ($defquota eq '') {
9767: $defquota = $quotahash{'quotas'}{$item};
9768: $settingstatus = $item;
9769: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9770: $defquota = $quotahash{'quotas'}{$item};
9771: $settingstatus = $item;
9772: }
1.536 raeburn 9773: }
9774: }
9775: }
9776: }
9777: if ($defquota eq '') {
1.1075.2.41 raeburn 9778: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9779: $defquota = $quotahash{'quotas'}{$key}{'default'};
9780: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9781: $defquota = $quotahash{'quotas'}{'default'};
9782: }
1.536 raeburn 9783: $settingstatus = 'default';
1.1075.2.42 raeburn 9784: if ($defquota eq '') {
9785: if ($quotaname eq 'author') {
9786: $defquota = 500;
9787: }
9788: }
1.536 raeburn 9789: }
9790: } else {
9791: $settingstatus = 'default';
1.1075.2.41 raeburn 9792: if ($quotaname eq 'author') {
9793: $defquota = 500;
9794: } else {
9795: $defquota = 20;
9796: }
1.536 raeburn 9797: }
9798: if (wantarray) {
9799: return ($defquota,$settingstatus);
1.472 raeburn 9800: } else {
1.536 raeburn 9801: return $defquota;
1.472 raeburn 9802: }
9803: }
9804:
1.1075.2.41 raeburn 9805: ###############################################
9806:
9807: =pod
9808:
1.1075.2.42 raeburn 9809: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9810:
9811: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9812: of existing file within authoring space will cause quota for the authoring
9813: space to be exceeded.
9814:
9815: Same, if upload of a file directly to a course/community via Course Editor
9816: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9817:
1.1075.2.61 raeburn 9818: Inputs: 7
1.1075.2.42 raeburn 9819: 1. username or coursenum
1.1075.2.41 raeburn 9820: 2. domain
1.1075.2.42 raeburn 9821: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9822: 4. filename of file for which action is being requested
9823: 5. filesize (kB) of file
9824: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9825: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9826:
9827: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9828: otherwise return null.
9829:
1.1075.2.42 raeburn 9830: =back
9831:
1.1075.2.41 raeburn 9832: =cut
9833:
1.1075.2.42 raeburn 9834: sub excess_filesize_warning {
1.1075.2.59 raeburn 9835: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9836: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9837: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9838: if ($context eq 'author') {
9839: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9840: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9841: } else {
9842: foreach my $subdir ('docs','supplemental') {
9843: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9844: }
9845: }
1.1075.2.41 raeburn 9846: $disk_quota = int($disk_quota * 1000);
9847: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9848: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9849: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9850: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9851: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9852: $disk_quota,$current_disk_usage).
9853: '</p>';
9854: }
9855: return;
9856: }
9857:
9858: ###############################################
9859:
9860:
1.384 raeburn 9861: sub get_secgrprole_info {
9862: my ($cdom,$cnum,$needroles,$type) = @_;
9863: my %sections_count = &get_sections($cdom,$cnum);
9864: my @sections = (sort {$a <=> $b} keys(%sections_count));
9865: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9866: my @groups = sort(keys(%curr_groups));
9867: my $allroles = [];
9868: my $rolehash;
9869: my $accesshash = {
9870: active => 'Currently has access',
9871: future => 'Will have future access',
9872: previous => 'Previously had access',
9873: };
9874: if ($needroles) {
9875: $rolehash = {'all' => 'all'};
1.385 albertel 9876: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9877: if (&Apache::lonnet::error(%user_roles)) {
9878: undef(%user_roles);
9879: }
9880: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9881: my ($role)=split(/\:/,$item,2);
9882: if ($role eq 'cr') { next; }
9883: if ($role =~ /^cr/) {
9884: $$rolehash{$role} = (split('/',$role))[3];
9885: } else {
9886: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9887: }
9888: }
9889: foreach my $key (sort(keys(%{$rolehash}))) {
9890: push(@{$allroles},$key);
9891: }
9892: push (@{$allroles},'st');
9893: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9894: }
9895: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9896: }
9897:
1.555 raeburn 9898: sub user_picker {
1.1075.2.127 raeburn 9899: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9900: my $currdom = $dom;
1.1075.2.114 raeburn 9901: my @alldoms = &Apache::lonnet::all_domains();
9902: if (@alldoms == 1) {
9903: my %domsrch = &Apache::lonnet::get_dom('configuration',
9904: ['directorysrch'],$alldoms[0]);
9905: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9906: my $showdom = $domdesc;
9907: if ($showdom eq '') {
9908: $showdom = $dom;
9909: }
9910: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9911: if ((!$domsrch{'directorysrch'}{'available'}) &&
9912: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9913: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9914: }
9915: }
9916: }
1.555 raeburn 9917: my %curr_selected = (
9918: srchin => 'dom',
1.580 raeburn 9919: srchby => 'lastname',
1.555 raeburn 9920: );
9921: my $srchterm;
1.625 raeburn 9922: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9923: if ($srch->{'srchby'} ne '') {
9924: $curr_selected{'srchby'} = $srch->{'srchby'};
9925: }
9926: if ($srch->{'srchin'} ne '') {
9927: $curr_selected{'srchin'} = $srch->{'srchin'};
9928: }
9929: if ($srch->{'srchtype'} ne '') {
9930: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9931: }
9932: if ($srch->{'srchdomain'} ne '') {
9933: $currdom = $srch->{'srchdomain'};
9934: }
9935: $srchterm = $srch->{'srchterm'};
9936: }
1.1075.2.98 raeburn 9937: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9938: 'usr' => 'Search criteria',
1.563 raeburn 9939: 'doma' => 'Domain/institution to search',
1.558 albertel 9940: 'uname' => 'username',
9941: 'lastname' => 'last name',
1.555 raeburn 9942: 'lastfirst' => 'last name, first name',
1.558 albertel 9943: 'crs' => 'in this course',
1.576 raeburn 9944: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9945: 'alc' => 'all LON-CAPA',
1.573 raeburn 9946: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9947: 'exact' => 'is',
9948: 'contains' => 'contains',
1.569 raeburn 9949: 'begins' => 'begins with',
1.1075.2.98 raeburn 9950: );
9951: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9952: 'youm' => "You must include some text to search for.",
9953: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9954: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9955: 'yomc' => "You must choose a domain when using an institutional directory search.",
9956: 'ymcd' => "You must choose a domain when using a domain search.",
9957: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9958: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9959: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9960: );
1.1075.2.98 raeburn 9961: &html_escape(\%html_lt);
9962: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9963: my $domform;
1.1075.2.126 raeburn 9964: my $allow_blank = 1;
1.1075.2.115 raeburn 9965: if ($fixeddom) {
1.1075.2.126 raeburn 9966: $allow_blank = 0;
9967: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9968: } else {
1.1075.2.126 raeburn 9969: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9970: }
1.563 raeburn 9971: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9972:
9973: my @srchins = ('crs','dom','alc','instd');
9974:
9975: foreach my $option (@srchins) {
9976: # FIXME 'alc' option unavailable until
9977: # loncreateuser::print_user_query_page()
9978: # has been completed.
9979: next if ($option eq 'alc');
1.880 raeburn 9980: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9981: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9982: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9983: if ($curr_selected{'srchin'} eq $option) {
9984: $srchinsel .= '
1.1075.2.98 raeburn 9985: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9986: } else {
9987: $srchinsel .= '
1.1075.2.98 raeburn 9988: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9989: }
1.555 raeburn 9990: }
1.563 raeburn 9991: $srchinsel .= "\n </select>\n";
1.555 raeburn 9992:
9993: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9994: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9995: if ($curr_selected{'srchby'} eq $option) {
9996: $srchbysel .= '
1.1075.2.98 raeburn 9997: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9998: } else {
9999: $srchbysel .= '
1.1075.2.98 raeburn 10000: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10001: }
10002: }
10003: $srchbysel .= "\n </select>\n";
10004:
10005: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10006: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10007: if ($curr_selected{'srchtype'} eq $option) {
10008: $srchtypesel .= '
1.1075.2.98 raeburn 10009: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10010: } else {
10011: $srchtypesel .= '
1.1075.2.98 raeburn 10012: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10013: }
10014: }
10015: $srchtypesel .= "\n </select>\n";
10016:
1.558 albertel 10017: my ($newuserscript,$new_user_create);
1.994 raeburn 10018: my $context_dom = $env{'request.role.domain'};
10019: if ($context eq 'requestcrs') {
10020: if ($env{'form.coursedom'} ne '') {
10021: $context_dom = $env{'form.coursedom'};
10022: }
10023: }
1.556 raeburn 10024: if ($forcenewuser) {
1.576 raeburn 10025: if (ref($srch) eq 'HASH') {
1.994 raeburn 10026: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10027: if ($cancreate) {
10028: $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>';
10029: } else {
1.799 bisitz 10030: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10031: my %usertypetext = (
10032: official => 'institutional',
10033: unofficial => 'non-institutional',
10034: );
1.799 bisitz 10035: $new_user_create = '<p class="LC_warning">'
10036: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10037: .' '
10038: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10039: ,'<a href="'.$helplink.'">','</a>')
10040: .'</p><br />';
1.627 raeburn 10041: }
1.576 raeburn 10042: }
10043: }
10044:
1.556 raeburn 10045: $newuserscript = <<"ENDSCRIPT";
10046:
1.570 raeburn 10047: function setSearch(createnew,callingForm) {
1.556 raeburn 10048: if (createnew == 1) {
1.570 raeburn 10049: for (var i=0; i<callingForm.srchby.length; i++) {
10050: if (callingForm.srchby.options[i].value == 'uname') {
10051: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10052: }
10053: }
1.570 raeburn 10054: for (var i=0; i<callingForm.srchin.length; i++) {
10055: if ( callingForm.srchin.options[i].value == 'dom') {
10056: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10057: }
10058: }
1.570 raeburn 10059: for (var i=0; i<callingForm.srchtype.length; i++) {
10060: if (callingForm.srchtype.options[i].value == 'exact') {
10061: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10062: }
10063: }
1.570 raeburn 10064: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10065: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10066: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10067: }
10068: }
10069: }
10070: }
10071: ENDSCRIPT
1.558 albertel 10072:
1.556 raeburn 10073: }
10074:
1.555 raeburn 10075: my $output = <<"END_BLOCK";
1.556 raeburn 10076: <script type="text/javascript">
1.824 bisitz 10077: // <![CDATA[
1.570 raeburn 10078: function validateEntry(callingForm) {
1.558 albertel 10079:
1.556 raeburn 10080: var checkok = 1;
1.558 albertel 10081: var srchin;
1.570 raeburn 10082: for (var i=0; i<callingForm.srchin.length; i++) {
10083: if ( callingForm.srchin[i].checked ) {
10084: srchin = callingForm.srchin[i].value;
1.558 albertel 10085: }
10086: }
10087:
1.570 raeburn 10088: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10089: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10090: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10091: var srchterm = callingForm.srchterm.value;
10092: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10093: var msg = "";
10094:
10095: if (srchterm == "") {
10096: checkok = 0;
1.1075.2.98 raeburn 10097: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10098: }
10099:
1.569 raeburn 10100: if (srchtype== 'begins') {
10101: if (srchterm.length < 2) {
10102: checkok = 0;
1.1075.2.98 raeburn 10103: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10104: }
10105: }
10106:
1.556 raeburn 10107: if (srchtype== 'contains') {
10108: if (srchterm.length < 3) {
10109: checkok = 0;
1.1075.2.98 raeburn 10110: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10111: }
10112: }
10113: if (srchin == 'instd') {
10114: if (srchdomain == '') {
10115: checkok = 0;
1.1075.2.98 raeburn 10116: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10117: }
10118: }
10119: if (srchin == 'dom') {
10120: if (srchdomain == '') {
10121: checkok = 0;
1.1075.2.98 raeburn 10122: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10123: }
10124: }
10125: if (srchby == 'lastfirst') {
10126: if (srchterm.indexOf(",") == -1) {
10127: checkok = 0;
1.1075.2.98 raeburn 10128: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10129: }
10130: if (srchterm.indexOf(",") == srchterm.length -1) {
10131: checkok = 0;
1.1075.2.98 raeburn 10132: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10133: }
10134: }
10135: if (checkok == 0) {
1.1075.2.98 raeburn 10136: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10137: return;
10138: }
10139: if (checkok == 1) {
1.570 raeburn 10140: callingForm.submit();
1.556 raeburn 10141: }
10142: }
10143:
10144: $newuserscript
10145:
1.824 bisitz 10146: // ]]>
1.556 raeburn 10147: </script>
1.558 albertel 10148:
10149: $new_user_create
10150:
1.555 raeburn 10151: END_BLOCK
1.558 albertel 10152:
1.876 raeburn 10153: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10154: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10155: $domform.
10156: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10157: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10158: $srchbysel.
10159: $srchtypesel.
10160: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10161: $srchinsel.
10162: &Apache::lonhtmlcommon::row_closure(1).
10163: &Apache::lonhtmlcommon::end_pick_box().
10164: '<br />';
1.1075.2.114 raeburn 10165: return ($output,1);
1.555 raeburn 10166: }
10167:
1.612 raeburn 10168: sub user_rule_check {
1.615 raeburn 10169: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10170: my ($response,%inst_response);
1.612 raeburn 10171: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10172: if (keys(%{$usershash}) > 1) {
10173: my (%by_username,%by_id,%userdoms);
10174: my $checkid;
1.612 raeburn 10175: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10176: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10177: $checkid = 1;
10178: }
10179: }
10180: foreach my $user (keys(%{$usershash})) {
10181: my ($uname,$udom) = split(/:/,$user);
10182: if ($checkid) {
10183: if (ref($usershash->{$user}) eq 'HASH') {
10184: if ($usershash->{$user}->{'id'} ne '') {
10185: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10186: $userdoms{$udom} = 1;
10187: if (ref($inst_results) eq 'HASH') {
10188: $inst_results->{$uname.':'.$udom} = {};
10189: }
10190: }
10191: }
10192: } else {
10193: $by_username{$udom}{$uname} = 1;
10194: $userdoms{$udom} = 1;
10195: if (ref($inst_results) eq 'HASH') {
10196: $inst_results->{$uname.':'.$udom} = {};
10197: }
10198: }
10199: }
10200: foreach my $udom (keys(%userdoms)) {
10201: if (!$got_rules->{$udom}) {
10202: my %domconfig = &Apache::lonnet::get_dom('configuration',
10203: ['usercreation'],$udom);
10204: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10205: foreach my $item ('username','id') {
10206: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10207: $$curr_rules{$udom}{$item} =
10208: $domconfig{'usercreation'}{$item.'_rule'};
10209: }
10210: }
10211: }
10212: $got_rules->{$udom} = 1;
10213: }
10214: }
10215: if ($checkid) {
10216: foreach my $udom (keys(%by_id)) {
10217: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10218: if ($outcome eq 'ok') {
10219: foreach my $id (keys(%{$by_id{$udom}})) {
10220: my $uname = $by_id{$udom}{$id};
10221: $inst_response{$uname.':'.$udom} = $outcome;
10222: }
10223: if (ref($results) eq 'HASH') {
10224: foreach my $uname (keys(%{$results})) {
10225: if (exists($inst_response{$uname.':'.$udom})) {
10226: $inst_response{$uname.':'.$udom} = $outcome;
10227: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10228: }
10229: }
10230: }
10231: }
1.612 raeburn 10232: }
1.615 raeburn 10233: } else {
1.1075.2.99 raeburn 10234: foreach my $udom (keys(%by_username)) {
10235: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10236: if ($outcome eq 'ok') {
10237: foreach my $uname (keys(%{$by_username{$udom}})) {
10238: $inst_response{$uname.':'.$udom} = $outcome;
10239: }
10240: if (ref($results) eq 'HASH') {
10241: foreach my $uname (keys(%{$results})) {
10242: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10243: }
10244: }
10245: }
10246: }
1.612 raeburn 10247: }
1.1075.2.99 raeburn 10248: } elsif (keys(%{$usershash}) == 1) {
10249: my $user = (keys(%{$usershash}))[0];
10250: my ($uname,$udom) = split(/:/,$user);
10251: if (($udom ne '') && ($uname ne '')) {
10252: if (ref($usershash->{$user}) eq 'HASH') {
10253: if (ref($checks) eq 'HASH') {
10254: if (defined($checks->{'username'})) {
10255: ($inst_response{$user},%{$inst_results->{$user}}) =
10256: &Apache::lonnet::get_instuser($udom,$uname);
10257: } elsif (defined($checks->{'id'})) {
10258: if ($usershash->{$user}->{'id'} ne '') {
10259: ($inst_response{$user},%{$inst_results->{$user}}) =
10260: &Apache::lonnet::get_instuser($udom,undef,
10261: $usershash->{$user}->{'id'});
10262: } else {
10263: ($inst_response{$user},%{$inst_results->{$user}}) =
10264: &Apache::lonnet::get_instuser($udom,$uname);
10265: }
10266: }
10267: } else {
10268: ($inst_response{$user},%{$inst_results->{$user}}) =
10269: &Apache::lonnet::get_instuser($udom,$uname);
10270: return;
10271: }
10272: if (!$got_rules->{$udom}) {
10273: my %domconfig = &Apache::lonnet::get_dom('configuration',
10274: ['usercreation'],$udom);
10275: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10276: foreach my $item ('username','id') {
10277: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10278: $$curr_rules{$udom}{$item} =
10279: $domconfig{'usercreation'}{$item.'_rule'};
10280: }
10281: }
1.585 raeburn 10282: }
1.1075.2.99 raeburn 10283: $got_rules->{$udom} = 1;
1.585 raeburn 10284: }
10285: }
1.1075.2.99 raeburn 10286: } else {
10287: return;
10288: }
10289: } else {
10290: return;
10291: }
10292: foreach my $user (keys(%{$usershash})) {
10293: my ($uname,$udom) = split(/:/,$user);
10294: next if (($udom eq '') || ($uname eq ''));
10295: my $id;
10296: if (ref($inst_results) eq 'HASH') {
10297: if (ref($inst_results->{$user}) eq 'HASH') {
10298: $id = $inst_results->{$user}->{'id'};
10299: }
10300: }
10301: if ($id eq '') {
10302: if (ref($usershash->{$user})) {
10303: $id = $usershash->{$user}->{'id'};
10304: }
1.585 raeburn 10305: }
1.612 raeburn 10306: foreach my $item (keys(%{$checks})) {
10307: if (ref($$curr_rules{$udom}) eq 'HASH') {
10308: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10309: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10310: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10311: $$curr_rules{$udom}{$item});
1.612 raeburn 10312: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10313: if ($rule_check{$rule}) {
10314: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10315: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10316: if (ref($inst_results) eq 'HASH') {
10317: if (ref($inst_results->{$user}) eq 'HASH') {
10318: if (keys(%{$inst_results->{$user}}) == 0) {
10319: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10320: } elsif ($item eq 'id') {
10321: if ($inst_results->{$user}->{'id'} eq '') {
10322: $$alerts{$item}{$udom}{$uname} = 1;
10323: }
1.615 raeburn 10324: }
1.612 raeburn 10325: }
10326: }
1.615 raeburn 10327: }
10328: last;
1.585 raeburn 10329: }
10330: }
10331: }
10332: }
10333: }
10334: }
10335: }
10336: }
1.612 raeburn 10337: return;
10338: }
10339:
10340: sub user_rule_formats {
10341: my ($domain,$domdesc,$curr_rules,$check) = @_;
10342: my %text = (
10343: 'username' => 'Usernames',
10344: 'id' => 'IDs',
10345: );
10346: my $output;
10347: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10348: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10349: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10350: $output = '<br />'.
10351: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10352: '<span class="LC_cusr_emph">','</span>',$domdesc).
10353: ' <ul>';
1.612 raeburn 10354: foreach my $rule (@{$ruleorder}) {
10355: if (ref($curr_rules) eq 'ARRAY') {
10356: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10357: if (ref($rules->{$rule}) eq 'HASH') {
10358: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10359: $rules->{$rule}{'desc'}.'</li>';
10360: }
10361: }
10362: }
10363: }
10364: $output .= '</ul>';
10365: }
10366: }
10367: return $output;
10368: }
10369:
10370: sub instrule_disallow_msg {
1.615 raeburn 10371: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10372: my $response;
10373: my %text = (
10374: item => 'username',
10375: items => 'usernames',
10376: match => 'matches',
10377: do => 'does',
10378: action => 'a username',
10379: one => 'one',
10380: );
10381: if ($count > 1) {
10382: $text{'item'} = 'usernames';
10383: $text{'match'} ='match';
10384: $text{'do'} = 'do';
10385: $text{'action'} = 'usernames',
10386: $text{'one'} = 'ones';
10387: }
10388: if ($checkitem eq 'id') {
10389: $text{'items'} = 'IDs';
10390: $text{'item'} = 'ID';
10391: $text{'action'} = 'an ID';
1.615 raeburn 10392: if ($count > 1) {
10393: $text{'item'} = 'IDs';
10394: $text{'action'} = 'IDs';
10395: }
1.612 raeburn 10396: }
1.674 bisitz 10397: $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 10398: if ($mode eq 'upload') {
10399: if ($checkitem eq 'username') {
10400: $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'}.");
10401: } elsif ($checkitem eq 'id') {
1.674 bisitz 10402: $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 10403: }
1.669 raeburn 10404: } elsif ($mode eq 'selfcreate') {
10405: if ($checkitem eq 'id') {
10406: $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.");
10407: }
1.615 raeburn 10408: } else {
10409: if ($checkitem eq 'username') {
10410: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10411: } elsif ($checkitem eq 'id') {
10412: $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.");
10413: }
1.612 raeburn 10414: }
10415: return $response;
1.585 raeburn 10416: }
10417:
1.624 raeburn 10418: sub personal_data_fieldtitles {
10419: my %fieldtitles = &Apache::lonlocal::texthash (
10420: id => 'Student/Employee ID',
10421: permanentemail => 'E-mail address',
10422: lastname => 'Last Name',
10423: firstname => 'First Name',
10424: middlename => 'Middle Name',
10425: generation => 'Generation',
10426: gen => 'Generation',
1.765 raeburn 10427: inststatus => 'Affiliation',
1.624 raeburn 10428: );
10429: return %fieldtitles;
10430: }
10431:
1.642 raeburn 10432: sub sorted_inst_types {
10433: my ($dom) = @_;
1.1075.2.70 raeburn 10434: my ($usertypes,$order);
10435: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10436: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10437: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10438: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10439: } else {
10440: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10441: }
1.642 raeburn 10442: my $othertitle = &mt('All users');
10443: if ($env{'request.course.id'}) {
1.668 raeburn 10444: $othertitle = &mt('Any users');
1.642 raeburn 10445: }
10446: my @types;
10447: if (ref($order) eq 'ARRAY') {
10448: @types = @{$order};
10449: }
10450: if (@types == 0) {
10451: if (ref($usertypes) eq 'HASH') {
10452: @types = sort(keys(%{$usertypes}));
10453: }
10454: }
10455: if (keys(%{$usertypes}) > 0) {
10456: $othertitle = &mt('Other users');
10457: }
10458: return ($othertitle,$usertypes,\@types);
10459: }
10460:
1.645 raeburn 10461: sub get_institutional_codes {
10462: my ($settings,$allcourses,$LC_code) = @_;
10463: # Get complete list of course sections to update
10464: my @currsections = ();
10465: my @currxlists = ();
10466: my $coursecode = $$settings{'internal.coursecode'};
10467:
10468: if ($$settings{'internal.sectionnums'} ne '') {
10469: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10470: }
10471:
10472: if ($$settings{'internal.crosslistings'} ne '') {
10473: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10474: }
10475:
10476: if (@currxlists > 0) {
10477: foreach (@currxlists) {
10478: if (m/^([^:]+):(\w*)$/) {
10479: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10480: push(@{$allcourses},$1);
1.645 raeburn 10481: $$LC_code{$1} = $2;
10482: }
10483: }
10484: }
10485: }
10486:
10487: if (@currsections > 0) {
10488: foreach (@currsections) {
10489: if (m/^(\w+):(\w*)$/) {
10490: my $sec = $coursecode.$1;
10491: my $lc_sec = $2;
10492: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10493: push(@{$allcourses},$sec);
1.645 raeburn 10494: $$LC_code{$sec} = $lc_sec;
10495: }
10496: }
10497: }
10498: }
10499: return;
10500: }
10501:
1.971 raeburn 10502: sub get_standard_codeitems {
10503: return ('Year','Semester','Department','Number','Section');
10504: }
10505:
1.112 bowersj2 10506: =pod
10507:
1.780 raeburn 10508: =head1 Slot Helpers
10509:
10510: =over 4
10511:
10512: =item * sorted_slots()
10513:
1.1040 raeburn 10514: Sorts an array of slot names in order of an optional sort key,
10515: default sort is by slot start time (earliest first).
1.780 raeburn 10516:
10517: Inputs:
10518:
10519: =over 4
10520:
10521: slotsarr - Reference to array of unsorted slot names.
10522:
10523: slots - Reference to hash of hash, where outer hash keys are slot names.
10524:
1.1040 raeburn 10525: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10526:
1.549 albertel 10527: =back
10528:
1.780 raeburn 10529: Returns:
10530:
10531: =over 4
10532:
1.1040 raeburn 10533: sorted - An array of slot names sorted by a specified sort key
10534: (default sort key is start time of the slot).
1.780 raeburn 10535:
10536: =back
10537:
10538: =cut
10539:
10540:
10541: sub sorted_slots {
1.1040 raeburn 10542: my ($slotsarr,$slots,$sortkey) = @_;
10543: if ($sortkey eq '') {
10544: $sortkey = 'starttime';
10545: }
1.780 raeburn 10546: my @sorted;
10547: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10548: @sorted =
10549: sort {
10550: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10551: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10552: }
10553: if (ref($slots->{$a})) { return -1;}
10554: if (ref($slots->{$b})) { return 1;}
10555: return 0;
10556: } @{$slotsarr};
10557: }
10558: return @sorted;
10559: }
10560:
1.1040 raeburn 10561: =pod
10562:
10563: =item * get_future_slots()
10564:
10565: Inputs:
10566:
10567: =over 4
10568:
10569: cnum - course number
10570:
10571: cdom - course domain
10572:
10573: now - current UNIX time
10574:
10575: symb - optional symb
10576:
10577: =back
10578:
10579: Returns:
10580:
10581: =over 4
10582:
10583: sorted_reservable - ref to array of student_schedulable slots currently
10584: reservable, ordered by end date of reservation period.
10585:
10586: reservable_now - ref to hash of student_schedulable slots currently
10587: reservable.
10588:
10589: Keys in inner hash are:
10590: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10591: (b) endreserve: end date of reservation period.
10592: (c) uniqueperiod: start,end dates when slot is to be uniquely
10593: selected.
1.1040 raeburn 10594:
10595: sorted_future - ref to array of student_schedulable slots reservable in
10596: the future, ordered by start date of reservation period.
10597:
10598: future_reservable - ref to hash of student_schedulable slots reservable
10599: in the future.
10600:
10601: Keys in inner hash are:
10602: (a) symb: either blank or symb to which slot use is restricted.
10603: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10604: (c) uniqueperiod: start,end dates when slot is to be uniquely
10605: selected.
1.1040 raeburn 10606:
10607: =back
10608:
10609: =cut
10610:
10611: sub get_future_slots {
10612: my ($cnum,$cdom,$now,$symb) = @_;
10613: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10614: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10615: foreach my $slot (keys(%slots)) {
10616: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10617: if ($symb) {
10618: next if (($slots{$slot}->{'symb'} ne '') &&
10619: ($slots{$slot}->{'symb'} ne $symb));
10620: }
10621: if (($slots{$slot}->{'starttime'} > $now) &&
10622: ($slots{$slot}->{'endtime'} > $now)) {
10623: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10624: my $userallowed = 0;
10625: if ($slots{$slot}->{'allowedsections'}) {
10626: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10627: if (!defined($env{'request.role.sec'})
10628: && grep(/^No section assigned$/,@allowed_sec)) {
10629: $userallowed=1;
10630: } else {
10631: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10632: $userallowed=1;
10633: }
10634: }
10635: unless ($userallowed) {
10636: if (defined($env{'request.course.groups'})) {
10637: my @groups = split(/:/,$env{'request.course.groups'});
10638: foreach my $group (@groups) {
10639: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10640: $userallowed=1;
10641: last;
10642: }
10643: }
10644: }
10645: }
10646: }
10647: if ($slots{$slot}->{'allowedusers'}) {
10648: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10649: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10650: if (grep(/^\Q$user\E$/,@allowed_users)) {
10651: $userallowed = 1;
10652: }
10653: }
10654: next unless($userallowed);
10655: }
10656: my $startreserve = $slots{$slot}->{'startreserve'};
10657: my $endreserve = $slots{$slot}->{'endreserve'};
10658: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10659: my $uniqueperiod;
10660: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10661: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10662: }
1.1040 raeburn 10663: if (($startreserve < $now) &&
10664: (!$endreserve || $endreserve > $now)) {
10665: my $lastres = $endreserve;
10666: if (!$lastres) {
10667: $lastres = $slots{$slot}->{'starttime'};
10668: }
10669: $reservable_now{$slot} = {
10670: symb => $symb,
1.1075.2.104 raeburn 10671: endreserve => $lastres,
10672: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10673: };
10674: } elsif (($startreserve > $now) &&
10675: (!$endreserve || $endreserve > $startreserve)) {
10676: $future_reservable{$slot} = {
10677: symb => $symb,
1.1075.2.104 raeburn 10678: startreserve => $startreserve,
10679: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10680: };
10681: }
10682: }
10683: }
10684: my @unsorted_reservable = keys(%reservable_now);
10685: if (@unsorted_reservable > 0) {
10686: @sorted_reservable =
10687: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10688: }
10689: my @unsorted_future = keys(%future_reservable);
10690: if (@unsorted_future > 0) {
10691: @sorted_future =
10692: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10693: }
10694: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10695: }
1.780 raeburn 10696:
10697: =pod
10698:
1.1057 foxr 10699: =back
10700:
1.549 albertel 10701: =head1 HTTP Helpers
10702:
10703: =over 4
10704:
1.648 raeburn 10705: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10706:
1.258 albertel 10707: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10708: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10709: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10710:
10711: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10712: $possible_names is an ref to an array of form element names. As an example:
10713: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10714: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10715:
10716: =cut
1.1 albertel 10717:
1.6 albertel 10718: sub get_unprocessed_cgi {
1.25 albertel 10719: my ($query,$possible_names)= @_;
1.26 matthew 10720: # $Apache::lonxml::debug=1;
1.356 albertel 10721: foreach my $pair (split(/&/,$query)) {
10722: my ($name, $value) = split(/=/,$pair);
1.369 www 10723: $name = &unescape($name);
1.25 albertel 10724: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10725: $value =~ tr/+/ /;
10726: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10727: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10728: }
1.16 harris41 10729: }
1.6 albertel 10730: }
10731:
1.112 bowersj2 10732: =pod
10733:
1.648 raeburn 10734: =item * &cacheheader()
1.112 bowersj2 10735:
10736: returns cache-controlling header code
10737:
10738: =cut
10739:
1.7 albertel 10740: sub cacheheader {
1.258 albertel 10741: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10742: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10743: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10744: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10745: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10746: return $output;
1.7 albertel 10747: }
10748:
1.112 bowersj2 10749: =pod
10750:
1.648 raeburn 10751: =item * &no_cache($r)
1.112 bowersj2 10752:
10753: specifies header code to not have cache
10754:
10755: =cut
10756:
1.9 albertel 10757: sub no_cache {
1.216 albertel 10758: my ($r) = @_;
10759: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10760: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10761: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10762: $r->no_cache(1);
10763: $r->header_out("Expires" => $date);
10764: $r->header_out("Pragma" => "no-cache");
1.123 www 10765: }
10766:
10767: sub content_type {
1.181 albertel 10768: my ($r,$type,$charset) = @_;
1.299 foxr 10769: if ($r) {
10770: # Note that printout.pl calls this with undef for $r.
10771: &no_cache($r);
10772: }
1.258 albertel 10773: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10774: unless ($charset) {
10775: $charset=&Apache::lonlocal::current_encoding;
10776: }
10777: if ($charset) { $type.='; charset='.$charset; }
10778: if ($r) {
10779: $r->content_type($type);
10780: } else {
10781: print("Content-type: $type\n\n");
10782: }
1.9 albertel 10783: }
1.25 albertel 10784:
1.112 bowersj2 10785: =pod
10786:
1.648 raeburn 10787: =item * &add_to_env($name,$value)
1.112 bowersj2 10788:
1.258 albertel 10789: adds $name to the %env hash with value
1.112 bowersj2 10790: $value, if $name already exists, the entry is converted to an array
10791: reference and $value is added to the array.
10792:
10793: =cut
10794:
1.25 albertel 10795: sub add_to_env {
10796: my ($name,$value)=@_;
1.258 albertel 10797: if (defined($env{$name})) {
10798: if (ref($env{$name})) {
1.25 albertel 10799: #already have multiple values
1.258 albertel 10800: push(@{ $env{$name} },$value);
1.25 albertel 10801: } else {
10802: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10803: my $first=$env{$name};
10804: undef($env{$name});
10805: push(@{ $env{$name} },$first,$value);
1.25 albertel 10806: }
10807: } else {
1.258 albertel 10808: $env{$name}=$value;
1.25 albertel 10809: }
1.31 albertel 10810: }
1.149 albertel 10811:
10812: =pod
10813:
1.648 raeburn 10814: =item * &get_env_multiple($name)
1.149 albertel 10815:
1.258 albertel 10816: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10817: values may be defined and end up as an array ref.
10818:
10819: returns an array of values
10820:
10821: =cut
10822:
10823: sub get_env_multiple {
10824: my ($name) = @_;
10825: my @values;
1.258 albertel 10826: if (defined($env{$name})) {
1.149 albertel 10827: # exists is it an array
1.258 albertel 10828: if (ref($env{$name})) {
10829: @values=@{ $env{$name} };
1.149 albertel 10830: } else {
1.258 albertel 10831: $values[0]=$env{$name};
1.149 albertel 10832: }
10833: }
10834: return(@values);
10835: }
10836:
1.660 raeburn 10837: sub ask_for_embedded_content {
10838: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10839: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10840: %currsubfile,%unused,$rem);
1.1071 raeburn 10841: my $counter = 0;
10842: my $numnew = 0;
1.987 raeburn 10843: my $numremref = 0;
10844: my $numinvalid = 0;
10845: my $numpathchg = 0;
10846: my $numexisting = 0;
1.1071 raeburn 10847: my $numunused = 0;
10848: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10849: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10850: my $heading = &mt('Upload embedded files');
10851: my $buttontext = &mt('Upload');
10852:
1.1075.2.11 raeburn 10853: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10854: if ($actionurl eq '/adm/dependencies') {
10855: $navmap = Apache::lonnavmaps::navmap->new();
10856: }
10857: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10858: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10859: }
1.1075.2.35 raeburn 10860: if (($actionurl eq '/adm/portfolio') ||
10861: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10862: my $current_path='/';
10863: if ($env{'form.currentpath'}) {
10864: $current_path = $env{'form.currentpath'};
10865: }
10866: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10867: $udom = $cdom;
10868: $uname = $cnum;
1.984 raeburn 10869: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10870: } else {
10871: $udom = $env{'user.domain'};
10872: $uname = $env{'user.name'};
10873: $url = '/userfiles/portfolio';
10874: }
1.987 raeburn 10875: $toplevel = $url.'/';
1.984 raeburn 10876: $url .= $current_path;
10877: $getpropath = 1;
1.987 raeburn 10878: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10879: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10880: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10881: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10882: $toplevel = $url;
1.984 raeburn 10883: if ($rest ne '') {
1.987 raeburn 10884: $url .= $rest;
10885: }
10886: } elsif ($actionurl eq '/adm/coursedocs') {
10887: if (ref($args) eq 'HASH') {
1.1071 raeburn 10888: $url = $args->{'docs_url'};
10889: $toplevel = $url;
1.1075.2.11 raeburn 10890: if ($args->{'context'} eq 'paste') {
10891: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10892: ($path) =
10893: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10894: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10895: $fileloc =~ s{^/}{};
10896: }
1.1071 raeburn 10897: }
10898: } elsif ($actionurl eq '/adm/dependencies') {
10899: if ($env{'request.course.id'} ne '') {
10900: if (ref($args) eq 'HASH') {
10901: $url = $args->{'docs_url'};
10902: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10903: $toplevel = $url;
10904: unless ($toplevel =~ m{^/}) {
10905: $toplevel = "/$url";
10906: }
1.1075.2.11 raeburn 10907: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10908: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10909: $path = $1;
10910: } else {
10911: ($path) =
10912: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10913: }
1.1075.2.79 raeburn 10914: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10915: $fileloc = $toplevel;
10916: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10917: my ($udom,$uname,$fname) =
10918: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10919: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10920: } else {
10921: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10922: }
1.1071 raeburn 10923: $fileloc =~ s{^/}{};
10924: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10925: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10926: }
1.987 raeburn 10927: }
1.1075.2.35 raeburn 10928: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10929: $udom = $cdom;
10930: $uname = $cnum;
10931: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10932: $toplevel = $url;
10933: $path = $url;
10934: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10935: $fileloc =~ s{^/}{};
10936: }
10937: foreach my $file (keys(%{$allfiles})) {
10938: my $embed_file;
10939: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10940: $embed_file = $1;
10941: } else {
10942: $embed_file = $file;
10943: }
1.1075.2.55 raeburn 10944: my ($absolutepath,$cleaned_file);
10945: if ($embed_file =~ m{^\w+://}) {
10946: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10947: $newfiles{$cleaned_file} = 1;
10948: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10949: } else {
1.1075.2.55 raeburn 10950: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10951: if ($embed_file =~ m{^/}) {
10952: $absolutepath = $embed_file;
10953: }
1.1075.2.47 raeburn 10954: if ($cleaned_file =~ m{/}) {
10955: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10956: $path = &check_for_traversal($path,$url,$toplevel);
10957: my $item = $fname;
10958: if ($path ne '') {
10959: $item = $path.'/'.$fname;
10960: $subdependencies{$path}{$fname} = 1;
10961: } else {
10962: $dependencies{$item} = 1;
10963: }
10964: if ($absolutepath) {
10965: $mapping{$item} = $absolutepath;
10966: } else {
10967: $mapping{$item} = $embed_file;
10968: }
10969: } else {
10970: $dependencies{$embed_file} = 1;
10971: if ($absolutepath) {
1.1075.2.47 raeburn 10972: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10973: } else {
1.1075.2.47 raeburn 10974: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10975: }
10976: }
1.984 raeburn 10977: }
10978: }
1.1071 raeburn 10979: my $dirptr = 16384;
1.984 raeburn 10980: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10981: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10982: if (($actionurl eq '/adm/portfolio') ||
10983: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10984: my ($sublistref,$listerror) =
10985: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10986: if (ref($sublistref) eq 'ARRAY') {
10987: foreach my $line (@{$sublistref}) {
10988: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10989: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10990: }
1.984 raeburn 10991: }
1.987 raeburn 10992: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10993: if (opendir(my $dir,$url.'/'.$path)) {
10994: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10995: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10996: }
1.1075.2.11 raeburn 10997: } elsif (($actionurl eq '/adm/dependencies') ||
10998: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10999: ($args->{'context'} eq 'paste')) ||
11000: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11001: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11002: my $dir;
11003: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11004: $dir = $fileloc;
11005: } else {
11006: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11007: }
1.1071 raeburn 11008: if ($dir ne '') {
11009: my ($sublistref,$listerror) =
11010: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11011: if (ref($sublistref) eq 'ARRAY') {
11012: foreach my $line (@{$sublistref}) {
11013: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11014: undef,$mtime)=split(/\&/,$line,12);
11015: unless (($testdir&$dirptr) ||
11016: ($file_name =~ /^\.\.?$/)) {
11017: $currsubfile{$path}{$file_name} = [$size,$mtime];
11018: }
11019: }
11020: }
11021: }
1.984 raeburn 11022: }
11023: }
11024: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11025: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11026: my $item = $path.'/'.$file;
11027: unless ($mapping{$item} eq $item) {
11028: $pathchanges{$item} = 1;
11029: }
11030: $existing{$item} = 1;
11031: $numexisting ++;
11032: } else {
11033: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11034: }
11035: }
1.1071 raeburn 11036: if ($actionurl eq '/adm/dependencies') {
11037: foreach my $path (keys(%currsubfile)) {
11038: if (ref($currsubfile{$path}) eq 'HASH') {
11039: foreach my $file (keys(%{$currsubfile{$path}})) {
11040: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11041: next if (($rem ne '') &&
11042: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11043: (ref($navmap) &&
11044: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11045: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11046: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11047: $unused{$path.'/'.$file} = 1;
11048: }
11049: }
11050: }
11051: }
11052: }
1.984 raeburn 11053: }
1.987 raeburn 11054: my %currfile;
1.1075.2.35 raeburn 11055: if (($actionurl eq '/adm/portfolio') ||
11056: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11057: my ($dirlistref,$listerror) =
11058: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11059: if (ref($dirlistref) eq 'ARRAY') {
11060: foreach my $line (@{$dirlistref}) {
11061: my ($file_name,$rest) = split(/\&/,$line,2);
11062: $currfile{$file_name} = 1;
11063: }
1.984 raeburn 11064: }
1.987 raeburn 11065: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11066: if (opendir(my $dir,$url)) {
1.987 raeburn 11067: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11068: map {$currfile{$_} = 1;} @dir_list;
11069: }
1.1075.2.11 raeburn 11070: } elsif (($actionurl eq '/adm/dependencies') ||
11071: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11072: ($args->{'context'} eq 'paste')) ||
11073: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11074: if ($env{'request.course.id'} ne '') {
11075: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11076: if ($dir ne '') {
11077: my ($dirlistref,$listerror) =
11078: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11079: if (ref($dirlistref) eq 'ARRAY') {
11080: foreach my $line (@{$dirlistref}) {
11081: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11082: $size,undef,$mtime)=split(/\&/,$line,12);
11083: unless (($testdir&$dirptr) ||
11084: ($file_name =~ /^\.\.?$/)) {
11085: $currfile{$file_name} = [$size,$mtime];
11086: }
11087: }
11088: }
11089: }
11090: }
1.984 raeburn 11091: }
11092: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11093: if (exists($currfile{$file})) {
1.987 raeburn 11094: unless ($mapping{$file} eq $file) {
11095: $pathchanges{$file} = 1;
11096: }
11097: $existing{$file} = 1;
11098: $numexisting ++;
11099: } else {
1.984 raeburn 11100: $newfiles{$file} = 1;
11101: }
11102: }
1.1071 raeburn 11103: foreach my $file (keys(%currfile)) {
11104: unless (($file eq $filename) ||
11105: ($file eq $filename.'.bak') ||
11106: ($dependencies{$file})) {
1.1075.2.11 raeburn 11107: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11108: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11109: next if (($rem ne '') &&
11110: (($env{"httpref.$rem".$file} ne '') ||
11111: (ref($navmap) &&
11112: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11113: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11114: ($navmap->getResourceByUrl($rem.$1)))))));
11115: }
1.1075.2.11 raeburn 11116: }
1.1071 raeburn 11117: $unused{$file} = 1;
11118: }
11119: }
1.1075.2.11 raeburn 11120: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11121: ($args->{'context'} eq 'paste')) {
11122: $counter = scalar(keys(%existing));
11123: $numpathchg = scalar(keys(%pathchanges));
11124: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11125: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11126: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11127: $counter = scalar(keys(%existing));
11128: $numpathchg = scalar(keys(%pathchanges));
11129: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11130: }
1.984 raeburn 11131: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11132: if ($actionurl eq '/adm/dependencies') {
11133: next if ($embed_file =~ m{^\w+://});
11134: }
1.660 raeburn 11135: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11136: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11137: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11138: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11139: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11140: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11141: }
1.1075.2.35 raeburn 11142: $upload_output .= '</td>';
1.1071 raeburn 11143: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11144: $upload_output.='<td align="right">'.
11145: '<span class="LC_info LC_fontsize_medium">'.
11146: &mt("URL points to web address").'</span>';
1.987 raeburn 11147: $numremref++;
1.660 raeburn 11148: } elsif ($args->{'error_on_invalid_names'}
11149: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11150: $upload_output.='<td align="right"><span class="LC_warning">'.
11151: &mt('Invalid characters').'</span>';
1.987 raeburn 11152: $numinvalid++;
1.660 raeburn 11153: } else {
1.1075.2.35 raeburn 11154: $upload_output .= '<td>'.
11155: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11156: $embed_file,\%mapping,
1.1071 raeburn 11157: $allfiles,$codebase,'upload');
11158: $counter ++;
11159: $numnew ++;
1.987 raeburn 11160: }
11161: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11162: }
11163: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11164: if ($actionurl eq '/adm/dependencies') {
11165: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11166: $modify_output .= &start_data_table_row().
11167: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11168: '<img src="'.&icon($embed_file).'" border="0" />'.
11169: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11170: '<td>'.$size.'</td>'.
11171: '<td>'.$mtime.'</td>'.
11172: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11173: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11174: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11175: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11176: &embedded_file_element('upload_embedded',$counter,
11177: $embed_file,\%mapping,
11178: $allfiles,$codebase,'modify').
11179: '</div></td>'.
11180: &end_data_table_row()."\n";
11181: $counter ++;
11182: } else {
11183: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11184: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11185: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11186: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11187: &Apache::loncommon::end_data_table_row()."\n";
11188: }
11189: }
11190: my $delidx = $counter;
11191: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11192: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11193: $delete_output .= &start_data_table_row().
11194: '<td><img src="'.&icon($oldfile).'" />'.
11195: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11196: '<td>'.$size.'</td>'.
11197: '<td>'.$mtime.'</td>'.
11198: '<td><label><input type="checkbox" name="del_upload_dep" '.
11199: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11200: &embedded_file_element('upload_embedded',$delidx,
11201: $oldfile,\%mapping,$allfiles,
11202: $codebase,'delete').'</td>'.
11203: &end_data_table_row()."\n";
11204: $numunused ++;
11205: $delidx ++;
1.987 raeburn 11206: }
11207: if ($upload_output) {
11208: $upload_output = &start_data_table().
11209: $upload_output.
11210: &end_data_table()."\n";
11211: }
1.1071 raeburn 11212: if ($modify_output) {
11213: $modify_output = &start_data_table().
11214: &start_data_table_header_row().
11215: '<th>'.&mt('File').'</th>'.
11216: '<th>'.&mt('Size (KB)').'</th>'.
11217: '<th>'.&mt('Modified').'</th>'.
11218: '<th>'.&mt('Upload replacement?').'</th>'.
11219: &end_data_table_header_row().
11220: $modify_output.
11221: &end_data_table()."\n";
11222: }
11223: if ($delete_output) {
11224: $delete_output = &start_data_table().
11225: &start_data_table_header_row().
11226: '<th>'.&mt('File').'</th>'.
11227: '<th>'.&mt('Size (KB)').'</th>'.
11228: '<th>'.&mt('Modified').'</th>'.
11229: '<th>'.&mt('Delete?').'</th>'.
11230: &end_data_table_header_row().
11231: $delete_output.
11232: &end_data_table()."\n";
11233: }
1.987 raeburn 11234: my $applies = 0;
11235: if ($numremref) {
11236: $applies ++;
11237: }
11238: if ($numinvalid) {
11239: $applies ++;
11240: }
11241: if ($numexisting) {
11242: $applies ++;
11243: }
1.1071 raeburn 11244: if ($counter || $numunused) {
1.987 raeburn 11245: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11246: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11247: $state.'<h3>'.$heading.'</h3>';
11248: if ($actionurl eq '/adm/dependencies') {
11249: if ($numnew) {
11250: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11251: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11252: $upload_output.'<br />'."\n";
11253: }
11254: if ($numexisting) {
11255: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11256: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11257: $modify_output.'<br />'."\n";
11258: $buttontext = &mt('Save changes');
11259: }
11260: if ($numunused) {
11261: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11262: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11263: $delete_output.'<br />'."\n";
11264: $buttontext = &mt('Save changes');
11265: }
11266: } else {
11267: $output .= $upload_output.'<br />'."\n";
11268: }
11269: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11270: $counter.'" />'."\n";
11271: if ($actionurl eq '/adm/dependencies') {
11272: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11273: $numnew.'" />'."\n";
11274: } elsif ($actionurl eq '') {
1.987 raeburn 11275: $output .= '<input type="hidden" name="phase" value="three" />';
11276: }
11277: } elsif ($applies) {
11278: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11279: if ($applies > 1) {
11280: $output .=
1.1075.2.35 raeburn 11281: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11282: if ($numremref) {
11283: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11284: }
11285: if ($numinvalid) {
11286: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11287: }
11288: if ($numexisting) {
11289: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11290: }
11291: $output .= '</ul><br />';
11292: } elsif ($numremref) {
11293: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11294: } elsif ($numinvalid) {
11295: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11296: } elsif ($numexisting) {
11297: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11298: }
11299: $output .= $upload_output.'<br />';
11300: }
11301: my ($pathchange_output,$chgcount);
1.1071 raeburn 11302: $chgcount = $counter;
1.987 raeburn 11303: if (keys(%pathchanges) > 0) {
11304: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11305: if ($counter) {
1.987 raeburn 11306: $output .= &embedded_file_element('pathchange',$chgcount,
11307: $embed_file,\%mapping,
1.1071 raeburn 11308: $allfiles,$codebase,'change');
1.987 raeburn 11309: } else {
11310: $pathchange_output .=
11311: &start_data_table_row().
11312: '<td><input type ="checkbox" name="namechange" value="'.
11313: $chgcount.'" checked="checked" /></td>'.
11314: '<td>'.$mapping{$embed_file}.'</td>'.
11315: '<td>'.$embed_file.
11316: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11317: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11318: '</td>'.&end_data_table_row();
1.660 raeburn 11319: }
1.987 raeburn 11320: $numpathchg ++;
11321: $chgcount ++;
1.660 raeburn 11322: }
11323: }
1.1075.2.35 raeburn 11324: if (($counter) || ($numunused)) {
1.987 raeburn 11325: if ($numpathchg) {
11326: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11327: $numpathchg.'" />'."\n";
11328: }
11329: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11330: ($actionurl eq '/adm/imsimport')) {
11331: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11332: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11333: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11334: } elsif ($actionurl eq '/adm/dependencies') {
11335: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11336: }
1.1075.2.35 raeburn 11337: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11338: } elsif ($numpathchg) {
11339: my %pathchange = ();
11340: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11341: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11342: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11343: }
1.987 raeburn 11344: }
1.1071 raeburn 11345: return ($output,$counter,$numpathchg);
1.987 raeburn 11346: }
11347:
1.1075.2.47 raeburn 11348: =pod
11349:
11350: =item * clean_path($name)
11351:
11352: Performs clean-up of directories, subdirectories and filename in an
11353: embedded object, referenced in an HTML file which is being uploaded
11354: to a course or portfolio, where
11355: "Upload embedded images/multimedia files if HTML file" checkbox was
11356: checked.
11357:
11358: Clean-up is similar to replacements in lonnet::clean_filename()
11359: except each / between sub-directory and next level is preserved.
11360:
11361: =cut
11362:
11363: sub clean_path {
11364: my ($embed_file) = @_;
11365: $embed_file =~s{^/+}{};
11366: my @contents;
11367: if ($embed_file =~ m{/}) {
11368: @contents = split(/\//,$embed_file);
11369: } else {
11370: @contents = ($embed_file);
11371: }
11372: my $lastidx = scalar(@contents)-1;
11373: for (my $i=0; $i<=$lastidx; $i++) {
11374: $contents[$i]=~s{\\}{/}g;
11375: $contents[$i]=~s/\s+/\_/g;
11376: $contents[$i]=~s{[^/\w\.\-]}{}g;
11377: if ($i == $lastidx) {
11378: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11379: }
11380: }
11381: if ($lastidx > 0) {
11382: return join('/',@contents);
11383: } else {
11384: return $contents[0];
11385: }
11386: }
11387:
1.987 raeburn 11388: sub embedded_file_element {
1.1071 raeburn 11389: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11390: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11391: (ref($codebase) eq 'HASH'));
11392: my $output;
1.1071 raeburn 11393: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11394: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11395: }
11396: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11397: &escape($embed_file).'" />';
11398: unless (($context eq 'upload_embedded') &&
11399: ($mapping->{$embed_file} eq $embed_file)) {
11400: $output .='
11401: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11402: }
11403: my $attrib;
11404: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11405: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11406: }
11407: $output .=
11408: "\n\t\t".
11409: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11410: $attrib.'" />';
11411: if (exists($codebase->{$mapping->{$embed_file}})) {
11412: $output .=
11413: "\n\t\t".
11414: '<input name="codebase_'.$num.'" type="hidden" value="'.
11415: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11416: }
1.987 raeburn 11417: return $output;
1.660 raeburn 11418: }
11419:
1.1071 raeburn 11420: sub get_dependency_details {
11421: my ($currfile,$currsubfile,$embed_file) = @_;
11422: my ($size,$mtime,$showsize,$showmtime);
11423: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11424: if ($embed_file =~ m{/}) {
11425: my ($path,$fname) = split(/\//,$embed_file);
11426: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11427: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11428: }
11429: } else {
11430: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11431: ($size,$mtime) = @{$currfile->{$embed_file}};
11432: }
11433: }
11434: $showsize = $size/1024.0;
11435: $showsize = sprintf("%.1f",$showsize);
11436: if ($mtime > 0) {
11437: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11438: }
11439: }
11440: return ($showsize,$showmtime);
11441: }
11442:
11443: sub ask_embedded_js {
11444: return <<"END";
11445: <script type="text/javascript"">
11446: // <![CDATA[
11447: function toggleBrowse(counter) {
11448: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11449: var fileid = document.getElementById('embedded_item_'+counter);
11450: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11451: if (chkboxid.checked == true) {
11452: uploaddivid.style.display='block';
11453: } else {
11454: uploaddivid.style.display='none';
11455: fileid.value = '';
11456: }
11457: }
11458: // ]]>
11459: </script>
11460:
11461: END
11462: }
11463:
1.661 raeburn 11464: sub upload_embedded {
11465: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11466: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11467: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11468: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11469: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11470: my $orig_uploaded_filename =
11471: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11472: foreach my $type ('orig','ref','attrib','codebase') {
11473: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11474: $env{'form.embedded_'.$type.'_'.$i} =
11475: &unescape($env{'form.embedded_'.$type.'_'.$i});
11476: }
11477: }
1.661 raeburn 11478: my ($path,$fname) =
11479: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11480: # no path, whole string is fname
11481: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11482: $fname = &Apache::lonnet::clean_filename($fname);
11483: # See if there is anything left
11484: next if ($fname eq '');
11485:
11486: # Check if file already exists as a file or directory.
11487: my ($state,$msg);
11488: if ($context eq 'portfolio') {
11489: my $port_path = $dirpath;
11490: if ($group ne '') {
11491: $port_path = "groups/$group/$port_path";
11492: }
1.987 raeburn 11493: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11494: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11495: $dir_root,$port_path,$disk_quota,
11496: $current_disk_usage,$uname,$udom);
11497: if ($state eq 'will_exceed_quota'
1.984 raeburn 11498: || $state eq 'file_locked') {
1.661 raeburn 11499: $output .= $msg;
11500: next;
11501: }
11502: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11503: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11504: if ($state eq 'exists') {
11505: $output .= $msg;
11506: next;
11507: }
11508: }
11509: # Check if extension is valid
11510: if (($fname =~ /\.(\w+)$/) &&
11511: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11512: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11513: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11514: next;
11515: } elsif (($fname =~ /\.(\w+)$/) &&
11516: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11517: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11518: next;
11519: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11520: $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 11521: next;
11522: }
11523: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11524: my $subdir = $path;
11525: $subdir =~ s{/+$}{};
1.661 raeburn 11526: if ($context eq 'portfolio') {
1.984 raeburn 11527: my $result;
11528: if ($state eq 'existingfile') {
11529: $result=
11530: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11531: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11532: } else {
1.984 raeburn 11533: $result=
11534: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11535: $dirpath.
1.1075.2.35 raeburn 11536: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11537: if ($result !~ m|^/uploaded/|) {
11538: $output .= '<span class="LC_error">'
11539: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11540: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11541: .'</span><br />';
11542: next;
11543: } else {
1.987 raeburn 11544: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11545: $path.$fname.'</span>').'<br />';
1.984 raeburn 11546: }
1.661 raeburn 11547: }
1.1075.2.35 raeburn 11548: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11549: my $extendedsubdir = $dirpath.'/'.$subdir;
11550: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11551: my $result =
1.1075.2.35 raeburn 11552: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11553: if ($result !~ m|^/uploaded/|) {
11554: $output .= '<span class="LC_error">'
11555: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11556: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11557: .'</span><br />';
11558: next;
11559: } else {
11560: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11561: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11562: if ($context eq 'syllabus') {
11563: &Apache::lonnet::make_public_indefinitely($result);
11564: }
1.987 raeburn 11565: }
1.661 raeburn 11566: } else {
11567: # Save the file
11568: my $target = $env{'form.embedded_item_'.$i};
11569: my $fullpath = $dir_root.$dirpath.'/'.$path;
11570: my $dest = $fullpath.$fname;
11571: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11572: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11573: my $count;
11574: my $filepath = $dir_root;
1.1027 raeburn 11575: foreach my $subdir (@parts) {
11576: $filepath .= "/$subdir";
11577: if (!-e $filepath) {
1.661 raeburn 11578: mkdir($filepath,0770);
11579: }
11580: }
11581: my $fh;
11582: if (!open($fh,'>'.$dest)) {
11583: &Apache::lonnet::logthis('Failed to create '.$dest);
11584: $output .= '<span class="LC_error">'.
1.1071 raeburn 11585: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11586: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11587: '</span><br />';
11588: } else {
11589: if (!print $fh $env{'form.embedded_item_'.$i}) {
11590: &Apache::lonnet::logthis('Failed to write to '.$dest);
11591: $output .= '<span class="LC_error">'.
1.1071 raeburn 11592: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11593: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11594: '</span><br />';
11595: } else {
1.987 raeburn 11596: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11597: $url.'</span>').'<br />';
11598: unless ($context eq 'testbank') {
11599: $footer .= &mt('View embedded file: [_1]',
11600: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11601: }
11602: }
11603: close($fh);
11604: }
11605: }
11606: if ($env{'form.embedded_ref_'.$i}) {
11607: $pathchange{$i} = 1;
11608: }
11609: }
11610: if ($output) {
11611: $output = '<p>'.$output.'</p>';
11612: }
11613: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11614: $returnflag = 'ok';
1.1071 raeburn 11615: my $numpathchgs = scalar(keys(%pathchange));
11616: if ($numpathchgs > 0) {
1.987 raeburn 11617: if ($context eq 'portfolio') {
11618: $output .= '<p>'.&mt('or').'</p>';
11619: } elsif ($context eq 'testbank') {
1.1071 raeburn 11620: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11621: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11622: $returnflag = 'modify_orightml';
11623: }
11624: }
1.1071 raeburn 11625: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11626: }
11627:
11628: sub modify_html_form {
11629: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11630: my $end = 0;
11631: my $modifyform;
11632: if ($context eq 'upload_embedded') {
11633: return unless (ref($pathchange) eq 'HASH');
11634: if ($env{'form.number_embedded_items'}) {
11635: $end += $env{'form.number_embedded_items'};
11636: }
11637: if ($env{'form.number_pathchange_items'}) {
11638: $end += $env{'form.number_pathchange_items'};
11639: }
11640: if ($end) {
11641: for (my $i=0; $i<$end; $i++) {
11642: if ($i < $env{'form.number_embedded_items'}) {
11643: next unless($pathchange->{$i});
11644: }
11645: $modifyform .=
11646: &start_data_table_row().
11647: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11648: 'checked="checked" /></td>'.
11649: '<td>'.$env{'form.embedded_ref_'.$i}.
11650: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11651: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11652: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11653: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11654: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11655: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11656: '<td>'.$env{'form.embedded_orig_'.$i}.
11657: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11658: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11659: &end_data_table_row();
1.1071 raeburn 11660: }
1.987 raeburn 11661: }
11662: } else {
11663: $modifyform = $pathchgtable;
11664: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11665: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11666: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11667: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11668: }
11669: }
11670: if ($modifyform) {
1.1071 raeburn 11671: if ($actionurl eq '/adm/dependencies') {
11672: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11673: }
1.987 raeburn 11674: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11675: '<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".
11676: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11677: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11678: '</ol></p>'."\n".'<p>'.
11679: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11680: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11681: &start_data_table()."\n".
11682: &start_data_table_header_row().
11683: '<th>'.&mt('Change?').'</th>'.
11684: '<th>'.&mt('Current reference').'</th>'.
11685: '<th>'.&mt('Required reference').'</th>'.
11686: &end_data_table_header_row()."\n".
11687: $modifyform.
11688: &end_data_table().'<br />'."\n".$hiddenstate.
11689: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11690: '</form>'."\n";
11691: }
11692: return;
11693: }
11694:
11695: sub modify_html_refs {
1.1075.2.35 raeburn 11696: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11697: my $container;
11698: if ($context eq 'portfolio') {
11699: $container = $env{'form.container'};
11700: } elsif ($context eq 'coursedoc') {
11701: $container = $env{'form.primaryurl'};
1.1071 raeburn 11702: } elsif ($context eq 'manage_dependencies') {
11703: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11704: $container = "/$container";
1.1075.2.35 raeburn 11705: } elsif ($context eq 'syllabus') {
11706: $container = $url;
1.987 raeburn 11707: } else {
1.1027 raeburn 11708: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11709: }
11710: my (%allfiles,%codebase,$output,$content);
11711: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11712: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11713: if (wantarray) {
11714: return ('',0,0);
11715: } else {
11716: return;
11717: }
11718: }
11719: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11720: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11721: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11722: if (wantarray) {
11723: return ('',0,0);
11724: } else {
11725: return;
11726: }
11727: }
1.987 raeburn 11728: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11729: if ($content eq '-1') {
11730: if (wantarray) {
11731: return ('',0,0);
11732: } else {
11733: return;
11734: }
11735: }
1.987 raeburn 11736: } else {
1.1071 raeburn 11737: unless ($container =~ /^\Q$dir_root\E/) {
11738: if (wantarray) {
11739: return ('',0,0);
11740: } else {
11741: return;
11742: }
11743: }
1.1075.2.128 raeburn 11744: if (open(my $fh,'<',$container)) {
1.987 raeburn 11745: $content = join('', <$fh>);
11746: close($fh);
11747: } else {
1.1071 raeburn 11748: if (wantarray) {
11749: return ('',0,0);
11750: } else {
11751: return;
11752: }
1.987 raeburn 11753: }
11754: }
11755: my ($count,$codebasecount) = (0,0);
11756: my $mm = new File::MMagic;
11757: my $mime_type = $mm->checktype_contents($content);
11758: if ($mime_type eq 'text/html') {
11759: my $parse_result =
11760: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11761: \%codebase,\$content);
11762: if ($parse_result eq 'ok') {
11763: foreach my $i (@changes) {
11764: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11765: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11766: if ($allfiles{$ref}) {
11767: my $newname = $orig;
11768: my ($attrib_regexp,$codebase);
1.1006 raeburn 11769: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11770: if ($attrib_regexp =~ /:/) {
11771: $attrib_regexp =~ s/\:/|/g;
11772: }
11773: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11774: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11775: $count += $numchg;
1.1075.2.35 raeburn 11776: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11777: delete($allfiles{$ref});
1.987 raeburn 11778: }
11779: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11780: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11781: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11782: $codebasecount ++;
11783: }
11784: }
11785: }
1.1075.2.35 raeburn 11786: my $skiprewrites;
1.987 raeburn 11787: if ($count || $codebasecount) {
11788: my $saveresult;
1.1071 raeburn 11789: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11790: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11791: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11792: if ($url eq $container) {
11793: my ($fname) = ($container =~ m{/([^/]+)$});
11794: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11795: $count,'<span class="LC_filename">'.
1.1071 raeburn 11796: $fname.'</span>').'</p>';
1.987 raeburn 11797: } else {
11798: $output = '<p class="LC_error">'.
11799: &mt('Error: update failed for: [_1].',
11800: '<span class="LC_filename">'.
11801: $container.'</span>').'</p>';
11802: }
1.1075.2.35 raeburn 11803: if ($context eq 'syllabus') {
11804: unless ($saveresult eq 'ok') {
11805: $skiprewrites = 1;
11806: }
11807: }
1.987 raeburn 11808: } else {
1.1075.2.128 raeburn 11809: if (open(my $fh,'>',$container)) {
1.987 raeburn 11810: print $fh $content;
11811: close($fh);
11812: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11813: $count,'<span class="LC_filename">'.
11814: $container.'</span>').'</p>';
1.661 raeburn 11815: } else {
1.987 raeburn 11816: $output = '<p class="LC_error">'.
11817: &mt('Error: could not update [_1].',
11818: '<span class="LC_filename">'.
11819: $container.'</span>').'</p>';
1.661 raeburn 11820: }
11821: }
11822: }
1.1075.2.35 raeburn 11823: if (($context eq 'syllabus') && (!$skiprewrites)) {
11824: my ($actionurl,$state);
11825: $actionurl = "/public/$udom/$uname/syllabus";
11826: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11827: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11828: \%codebase,
11829: {'context' => 'rewrites',
11830: 'ignore_remote_references' => 1,});
11831: if (ref($mapping) eq 'HASH') {
11832: my $rewrites = 0;
11833: foreach my $key (keys(%{$mapping})) {
11834: next if ($key =~ m{^https?://});
11835: my $ref = $mapping->{$key};
11836: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11837: my $attrib;
11838: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11839: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11840: }
11841: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11842: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11843: $rewrites += $numchg;
11844: }
11845: }
11846: if ($rewrites) {
11847: my $saveresult;
11848: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11849: if ($url eq $container) {
11850: my ($fname) = ($container =~ m{/([^/]+)$});
11851: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11852: $count,'<span class="LC_filename">'.
11853: $fname.'</span>').'</p>';
11854: } else {
11855: $output .= '<p class="LC_error">'.
11856: &mt('Error: could not update links in [_1].',
11857: '<span class="LC_filename">'.
11858: $container.'</span>').'</p>';
11859:
11860: }
11861: }
11862: }
11863: }
1.987 raeburn 11864: } else {
11865: &logthis('Failed to parse '.$container.
11866: ' to modify references: '.$parse_result);
1.661 raeburn 11867: }
11868: }
1.1071 raeburn 11869: if (wantarray) {
11870: return ($output,$count,$codebasecount);
11871: } else {
11872: return $output;
11873: }
1.661 raeburn 11874: }
11875:
11876: sub check_for_existing {
11877: my ($path,$fname,$element) = @_;
11878: my ($state,$msg);
11879: if (-d $path.'/'.$fname) {
11880: $state = 'exists';
11881: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11882: } elsif (-e $path.'/'.$fname) {
11883: $state = 'exists';
11884: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11885: }
11886: if ($state eq 'exists') {
11887: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11888: }
11889: return ($state,$msg);
11890: }
11891:
11892: sub check_for_upload {
11893: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11894: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11895: my $filesize = length($env{'form.'.$element});
11896: if (!$filesize) {
11897: my $msg = '<span class="LC_error">'.
11898: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11899: '<span class="LC_filename">'.$fname.'</span>',
11900: $filesize).'<br />'.
1.1007 raeburn 11901: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11902: '</span>';
11903: return ('zero_bytes',$msg);
11904: }
11905: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11906: my $getpropath = 1;
1.1021 raeburn 11907: my ($dirlistref,$listerror) =
11908: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11909: my $found_file = 0;
11910: my $locked_file = 0;
1.991 raeburn 11911: my @lockers;
11912: my $navmap;
11913: if ($env{'request.course.id'}) {
11914: $navmap = Apache::lonnavmaps::navmap->new();
11915: }
1.1021 raeburn 11916: if (ref($dirlistref) eq 'ARRAY') {
11917: foreach my $line (@{$dirlistref}) {
11918: my ($file_name,$rest)=split(/\&/,$line,2);
11919: if ($file_name eq $fname){
11920: $file_name = $path.$file_name;
11921: if ($group ne '') {
11922: $file_name = $group.$file_name;
11923: }
11924: $found_file = 1;
11925: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11926: foreach my $lock (@lockers) {
11927: if (ref($lock) eq 'ARRAY') {
11928: my ($symb,$crsid) = @{$lock};
11929: if ($crsid eq $env{'request.course.id'}) {
11930: if (ref($navmap)) {
11931: my $res = $navmap->getBySymb($symb);
11932: foreach my $part (@{$res->parts()}) {
11933: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11934: unless (($slot_status == $res->RESERVED) ||
11935: ($slot_status == $res->RESERVED_LOCATION)) {
11936: $locked_file = 1;
11937: }
1.991 raeburn 11938: }
1.1021 raeburn 11939: } else {
11940: $locked_file = 1;
1.991 raeburn 11941: }
11942: } else {
11943: $locked_file = 1;
11944: }
11945: }
1.1021 raeburn 11946: }
11947: } else {
11948: my @info = split(/\&/,$rest);
11949: my $currsize = $info[6]/1000;
11950: if ($currsize < $filesize) {
11951: my $extra = $filesize - $currsize;
11952: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11953: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11954: &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 11955: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11956: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11957: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11958: return ('will_exceed_quota',$msg);
11959: }
1.984 raeburn 11960: }
11961: }
1.661 raeburn 11962: }
11963: }
11964: }
11965: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11966: my $msg = '<p class="LC_warning">'.
11967: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11968: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11969: return ('will_exceed_quota',$msg);
11970: } elsif ($found_file) {
11971: if ($locked_file) {
1.1075.2.69 raeburn 11972: my $msg = '<p class="LC_warning">';
1.661 raeburn 11973: $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 11974: $msg .= '</p>';
1.661 raeburn 11975: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11976: return ('file_locked',$msg);
11977: } else {
1.1075.2.69 raeburn 11978: my $msg = '<p class="LC_error">';
1.984 raeburn 11979: $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 11980: $msg .= '</p>';
1.984 raeburn 11981: return ('existingfile',$msg);
1.661 raeburn 11982: }
11983: }
11984: }
11985:
1.987 raeburn 11986: sub check_for_traversal {
11987: my ($path,$url,$toplevel) = @_;
11988: my @parts=split(/\//,$path);
11989: my $cleanpath;
11990: my $fullpath = $url;
11991: for (my $i=0;$i<@parts;$i++) {
11992: next if ($parts[$i] eq '.');
11993: if ($parts[$i] eq '..') {
11994: $fullpath =~ s{([^/]+/)$}{};
11995: } else {
11996: $fullpath .= $parts[$i].'/';
11997: }
11998: }
11999: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12000: $cleanpath = $1;
12001: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12002: my $curr_toprel = $1;
12003: my @parts = split(/\//,$curr_toprel);
12004: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12005: my @urlparts = split(/\//,$url_toprel);
12006: my $doubledots;
12007: my $startdiff = -1;
12008: for (my $i=0; $i<@urlparts; $i++) {
12009: if ($startdiff == -1) {
12010: unless ($urlparts[$i] eq $parts[$i]) {
12011: $startdiff = $i;
12012: $doubledots .= '../';
12013: }
12014: } else {
12015: $doubledots .= '../';
12016: }
12017: }
12018: if ($startdiff > -1) {
12019: $cleanpath = $doubledots;
12020: for (my $i=$startdiff; $i<@parts; $i++) {
12021: $cleanpath .= $parts[$i].'/';
12022: }
12023: }
12024: }
12025: $cleanpath =~ s{(/)$}{};
12026: return $cleanpath;
12027: }
1.31 albertel 12028:
1.1053 raeburn 12029: sub is_archive_file {
12030: my ($mimetype) = @_;
12031: if (($mimetype eq 'application/octet-stream') ||
12032: ($mimetype eq 'application/x-stuffit') ||
12033: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12034: return 1;
12035: }
12036: return;
12037: }
12038:
12039: sub decompress_form {
1.1065 raeburn 12040: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12041: my %lt = &Apache::lonlocal::texthash (
12042: this => 'This file is an archive file.',
1.1067 raeburn 12043: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12044: itsc => 'Its contents are as follows:',
1.1053 raeburn 12045: youm => 'You may wish to extract its contents.',
12046: extr => 'Extract contents',
1.1067 raeburn 12047: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12048: proa => 'Process automatically?',
1.1053 raeburn 12049: yes => 'Yes',
12050: no => 'No',
1.1067 raeburn 12051: fold => 'Title for folder containing movie',
12052: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12053: );
1.1065 raeburn 12054: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12055: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12056: my $info = &list_archive_contents($fileloc,\@paths);
12057: if (@paths) {
12058: foreach my $path (@paths) {
12059: $path =~ s{^/}{};
1.1067 raeburn 12060: if ($path =~ m{^([^/]+)/$}) {
12061: $topdir = $1;
12062: }
1.1065 raeburn 12063: if ($path =~ m{^([^/]+)/}) {
12064: $toplevel{$1} = $path;
12065: } else {
12066: $toplevel{$path} = $path;
12067: }
12068: }
12069: }
1.1067 raeburn 12070: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12071: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12072: "$topdir/media/",
12073: "$topdir/media/$topdir.mp4",
12074: "$topdir/media/FirstFrame.png",
12075: "$topdir/media/player.swf",
12076: "$topdir/media/swfobject.js",
12077: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12078: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12079: "$topdir/$topdir.mp4",
12080: "$topdir/$topdir\_config.xml",
12081: "$topdir/$topdir\_controller.swf",
12082: "$topdir/$topdir\_embed.css",
12083: "$topdir/$topdir\_First_Frame.png",
12084: "$topdir/$topdir\_player.html",
12085: "$topdir/$topdir\_Thumbnails.png",
12086: "$topdir/playerProductInstall.swf",
12087: "$topdir/scripts/",
12088: "$topdir/scripts/config_xml.js",
12089: "$topdir/scripts/handlebars.js",
12090: "$topdir/scripts/jquery-1.7.1.min.js",
12091: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12092: "$topdir/scripts/modernizr.js",
12093: "$topdir/scripts/player-min.js",
12094: "$topdir/scripts/swfobject.js",
12095: "$topdir/skins/",
12096: "$topdir/skins/configuration_express.xml",
12097: "$topdir/skins/express_show/",
12098: "$topdir/skins/express_show/player-min.css",
12099: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12100: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12101: "$topdir/$topdir.mp4",
12102: "$topdir/$topdir\_config.xml",
12103: "$topdir/$topdir\_controller.swf",
12104: "$topdir/$topdir\_embed.css",
12105: "$topdir/$topdir\_First_Frame.png",
12106: "$topdir/$topdir\_player.html",
12107: "$topdir/$topdir\_Thumbnails.png",
12108: "$topdir/playerProductInstall.swf",
12109: "$topdir/scripts/",
12110: "$topdir/scripts/config_xml.js",
12111: "$topdir/scripts/techsmith-smart-player.min.js",
12112: "$topdir/skins/",
12113: "$topdir/skins/configuration_express.xml",
12114: "$topdir/skins/express_show/",
12115: "$topdir/skins/express_show/spritesheet.min.css",
12116: "$topdir/skins/express_show/spritesheet.png",
12117: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12118: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12119: if (@diffs == 0) {
1.1075.2.59 raeburn 12120: $is_camtasia = 6;
12121: } else {
1.1075.2.81 raeburn 12122: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12123: if (@diffs == 0) {
12124: $is_camtasia = 8;
1.1075.2.81 raeburn 12125: } else {
12126: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12127: if (@diffs == 0) {
12128: $is_camtasia = 8;
12129: }
1.1075.2.59 raeburn 12130: }
1.1067 raeburn 12131: }
12132: }
12133: my $output;
12134: if ($is_camtasia) {
12135: $output = <<"ENDCAM";
12136: <script type="text/javascript" language="Javascript">
12137: // <![CDATA[
12138:
12139: function camtasiaToggle() {
12140: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12141: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12142: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12143: document.getElementById('camtasia_titles').style.display='block';
12144: } else {
12145: document.getElementById('camtasia_titles').style.display='none';
12146: }
12147: }
12148: }
12149: return;
12150: }
12151:
12152: // ]]>
12153: </script>
12154: <p>$lt{'camt'}</p>
12155: ENDCAM
1.1065 raeburn 12156: } else {
1.1067 raeburn 12157: $output = '<p>'.$lt{'this'};
12158: if ($info eq '') {
12159: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12160: } else {
12161: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12162: '<div><pre>'.$info.'</pre></div>';
12163: }
1.1065 raeburn 12164: }
1.1067 raeburn 12165: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12166: my $duplicates;
12167: my $num = 0;
12168: if (ref($dirlist) eq 'ARRAY') {
12169: foreach my $item (@{$dirlist}) {
12170: if (ref($item) eq 'ARRAY') {
12171: if (exists($toplevel{$item->[0]})) {
12172: $duplicates .=
12173: &start_data_table_row().
12174: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12175: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12176: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12177: 'value="1" />'.&mt('Yes').'</label>'.
12178: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12179: '<td>'.$item->[0].'</td>';
12180: if ($item->[2]) {
12181: $duplicates .= '<td>'.&mt('Directory').'</td>';
12182: } else {
12183: $duplicates .= '<td>'.&mt('File').'</td>';
12184: }
12185: $duplicates .= '<td>'.$item->[3].'</td>'.
12186: '<td>'.
12187: &Apache::lonlocal::locallocaltime($item->[4]).
12188: '</td>'.
12189: &end_data_table_row();
12190: $num ++;
12191: }
12192: }
12193: }
12194: }
12195: my $itemcount;
12196: if (@paths > 0) {
12197: $itemcount = scalar(@paths);
12198: } else {
12199: $itemcount = 1;
12200: }
1.1067 raeburn 12201: if ($is_camtasia) {
12202: $output .= $lt{'auto'}.'<br />'.
12203: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12204: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12205: $lt{'yes'}.'</label> <label>'.
12206: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12207: $lt{'no'}.'</label></span><br />'.
12208: '<div id="camtasia_titles" style="display:block">'.
12209: &Apache::lonhtmlcommon::start_pick_box().
12210: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12211: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12212: &Apache::lonhtmlcommon::row_closure().
12213: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12214: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12215: &Apache::lonhtmlcommon::row_closure(1).
12216: &Apache::lonhtmlcommon::end_pick_box().
12217: '</div>';
12218: }
1.1065 raeburn 12219: $output .=
12220: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12221: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12222: "\n";
1.1065 raeburn 12223: if ($duplicates ne '') {
12224: $output .= '<p><span class="LC_warning">'.
12225: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12226: &start_data_table().
12227: &start_data_table_header_row().
12228: '<th>'.&mt('Overwrite?').'</th>'.
12229: '<th>'.&mt('Name').'</th>'.
12230: '<th>'.&mt('Type').'</th>'.
12231: '<th>'.&mt('Size').'</th>'.
12232: '<th>'.&mt('Last modified').'</th>'.
12233: &end_data_table_header_row().
12234: $duplicates.
12235: &end_data_table().
12236: '</p>';
12237: }
1.1067 raeburn 12238: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12239: if (ref($hiddenelements) eq 'HASH') {
12240: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12241: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12242: }
12243: }
12244: $output .= <<"END";
1.1067 raeburn 12245: <br />
1.1053 raeburn 12246: <input type="submit" name="decompress" value="$lt{'extr'}" />
12247: </form>
12248: $noextract
12249: END
12250: return $output;
12251: }
12252:
1.1065 raeburn 12253: sub decompression_utility {
12254: my ($program) = @_;
12255: my @utilities = ('tar','gunzip','bunzip2','unzip');
12256: my $location;
12257: if (grep(/^\Q$program\E$/,@utilities)) {
12258: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12259: '/usr/sbin/') {
12260: if (-x $dir.$program) {
12261: $location = $dir.$program;
12262: last;
12263: }
12264: }
12265: }
12266: return $location;
12267: }
12268:
12269: sub list_archive_contents {
12270: my ($file,$pathsref) = @_;
12271: my (@cmd,$output);
12272: my $needsregexp;
12273: if ($file =~ /\.zip$/) {
12274: @cmd = (&decompression_utility('unzip'),"-l");
12275: $needsregexp = 1;
12276: } elsif (($file =~ m/\.tar\.gz$/) ||
12277: ($file =~ /\.tgz$/)) {
12278: @cmd = (&decompression_utility('tar'),"-ztf");
12279: } elsif ($file =~ /\.tar\.bz2$/) {
12280: @cmd = (&decompression_utility('tar'),"-jtf");
12281: } elsif ($file =~ m|\.tar$|) {
12282: @cmd = (&decompression_utility('tar'),"-tf");
12283: }
12284: if (@cmd) {
12285: undef($!);
12286: undef($@);
12287: if (open(my $fh,"-|", @cmd, $file)) {
12288: while (my $line = <$fh>) {
12289: $output .= $line;
12290: chomp($line);
12291: my $item;
12292: if ($needsregexp) {
12293: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12294: } else {
12295: $item = $line;
12296: }
12297: if ($item ne '') {
12298: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12299: push(@{$pathsref},$item);
12300: }
12301: }
12302: }
12303: close($fh);
12304: }
12305: }
12306: return $output;
12307: }
12308:
1.1053 raeburn 12309: sub decompress_uploaded_file {
12310: my ($file,$dir) = @_;
12311: &Apache::lonnet::appenv({'cgi.file' => $file});
12312: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12313: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12314: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12315: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12316: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12317: my $decompressed = $env{'cgi.decompressed'};
12318: &Apache::lonnet::delenv('cgi.file');
12319: &Apache::lonnet::delenv('cgi.dir');
12320: &Apache::lonnet::delenv('cgi.decompressed');
12321: return ($decompressed,$result);
12322: }
12323:
1.1055 raeburn 12324: sub process_decompression {
12325: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12326: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12327: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12328: &mt('Unexpected file path.').'</p>'."\n";
12329: }
12330: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12331: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12332: &mt('Unexpected course context.').'</p>'."\n";
12333: }
12334: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12335: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12336: &mt('Filename contained unexpected characters.').'</p>'."\n";
12337: }
1.1055 raeburn 12338: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12339: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12340: $error = &mt('Filename not a supported archive file type.').
12341: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12342: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12343: } else {
12344: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12345: if ($docuhome eq 'no_host') {
12346: $error = &mt('Could not determine home server for course.');
12347: } else {
12348: my @ids=&Apache::lonnet::current_machine_ids();
12349: my $currdir = "$dir_root/$destination";
12350: if (grep(/^\Q$docuhome\E$/,@ids)) {
12351: $dir = &LONCAPA::propath($docudom,$docuname).
12352: "$dir_root/$destination";
12353: } else {
12354: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12355: "$dir_root/$docudom/$docuname/$destination";
12356: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12357: $error = &mt('Archive file not found.');
12358: }
12359: }
1.1065 raeburn 12360: my (@to_overwrite,@to_skip);
12361: if ($env{'form.archive_overwrite_total'} > 0) {
12362: my $total = $env{'form.archive_overwrite_total'};
12363: for (my $i=0; $i<$total; $i++) {
12364: if ($env{'form.archive_overwrite_'.$i} == 1) {
12365: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12366: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12367: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12368: }
12369: }
12370: }
12371: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12372: my $numoverwrite = scalar(@to_overwrite);
12373: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12374: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12375: } elsif ($dir eq '') {
1.1055 raeburn 12376: $error = &mt('Directory containing archive file unavailable.');
12377: } elsif (!$error) {
1.1065 raeburn 12378: my ($decompressed,$display);
1.1075.2.128 raeburn 12379: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12380: my $tempdir = time.'_'.$$.int(rand(10000));
12381: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12382: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12383: ($decompressed,$display) =
12384: &decompress_uploaded_file($file,"$dir/$tempdir");
12385: foreach my $item (@to_skip) {
12386: if (($item ne '') && ($item !~ /\.\./)) {
12387: if (-f "$dir/$tempdir/$item") {
12388: unlink("$dir/$tempdir/$item");
12389: } elsif (-d "$dir/$tempdir/$item") {
12390: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12391: }
12392: }
12393: }
12394: foreach my $item (@to_overwrite) {
12395: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12396: if (($item ne '') && ($item !~ /\.\./)) {
12397: if (-f "$dir/$item") {
12398: unlink("$dir/$item");
12399: } elsif (-d "$dir/$item") {
12400: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12401: }
12402: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12403: }
1.1065 raeburn 12404: }
12405: }
1.1075.2.128 raeburn 12406: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12407: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12408: }
1.1065 raeburn 12409: }
12410: } else {
12411: ($decompressed,$display) =
12412: &decompress_uploaded_file($file,$dir);
12413: }
1.1055 raeburn 12414: if ($decompressed eq 'ok') {
1.1065 raeburn 12415: $output = '<p class="LC_info">'.
12416: &mt('Files extracted successfully from archive.').
12417: '</p>'."\n";
1.1055 raeburn 12418: my ($warning,$result,@contents);
12419: my ($newdirlistref,$newlisterror) =
12420: &Apache::lonnet::dirlist($currdir,$docudom,
12421: $docuname,1);
12422: my (%is_dir,%changes,@newitems);
12423: my $dirptr = 16384;
1.1065 raeburn 12424: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12425: foreach my $dir_line (@{$newdirlistref}) {
12426: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12427: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12428: push(@newitems,$item);
12429: if ($dirptr&$testdir) {
12430: $is_dir{$item} = 1;
12431: }
12432: $changes{$item} = 1;
12433: }
12434: }
12435: }
12436: if (keys(%changes) > 0) {
12437: foreach my $item (sort(@newitems)) {
12438: if ($changes{$item}) {
12439: push(@contents,$item);
12440: }
12441: }
12442: }
12443: if (@contents > 0) {
1.1067 raeburn 12444: my $wantform;
12445: unless ($env{'form.autoextract_camtasia'}) {
12446: $wantform = 1;
12447: }
1.1056 raeburn 12448: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12449: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12450: $currdir,\%is_dir,
12451: \%children,\%parent,
1.1056 raeburn 12452: \@contents,\%dirorder,
12453: \%titles,$wantform);
1.1055 raeburn 12454: if ($datatable ne '') {
12455: $output .= &archive_options_form('decompressed',$datatable,
12456: $count,$hiddenelem);
1.1065 raeburn 12457: my $startcount = 6;
1.1055 raeburn 12458: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12459: \%titles,\%children);
1.1055 raeburn 12460: }
1.1067 raeburn 12461: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12462: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12463: my %displayed;
12464: my $total = 1;
12465: $env{'form.archive_directory'} = [];
12466: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12467: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12468: $path =~ s{/$}{};
12469: my $item;
12470: if ($path ne '') {
12471: $item = "$path/$titles{$i}";
12472: } else {
12473: $item = $titles{$i};
12474: }
12475: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12476: if ($item eq $contents[0]) {
12477: push(@{$env{'form.archive_directory'}},$i);
12478: $env{'form.archive_'.$i} = 'display';
12479: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12480: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12481: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12482: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12483: $env{'form.archive_'.$i} = 'display';
12484: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12485: $displayed{'web'} = $i;
12486: } else {
1.1075.2.59 raeburn 12487: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12488: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12489: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12490: push(@{$env{'form.archive_directory'}},$i);
12491: }
12492: $env{'form.archive_'.$i} = 'dependency';
12493: }
12494: $total ++;
12495: }
12496: for (my $i=1; $i<$total; $i++) {
12497: next if ($i == $displayed{'web'});
12498: next if ($i == $displayed{'folder'});
12499: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12500: }
12501: $env{'form.phase'} = 'decompress_cleanup';
12502: $env{'form.archivedelete'} = 1;
12503: $env{'form.archive_count'} = $total-1;
12504: $output .=
12505: &process_extracted_files('coursedocs',$docudom,
12506: $docuname,$destination,
12507: $dir_root,$hiddenelem);
12508: }
1.1055 raeburn 12509: } else {
12510: $warning = &mt('No new items extracted from archive file.');
12511: }
12512: } else {
12513: $output = $display;
12514: $error = &mt('An error occurred during extraction from the archive file.');
12515: }
12516: }
12517: }
12518: }
12519: if ($error) {
12520: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12521: $error.'</p>'."\n";
12522: }
12523: if ($warning) {
12524: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12525: }
12526: return $output;
12527: }
12528:
12529: sub get_extracted {
1.1056 raeburn 12530: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12531: $titles,$wantform) = @_;
1.1055 raeburn 12532: my $count = 0;
12533: my $depth = 0;
12534: my $datatable;
1.1056 raeburn 12535: my @hierarchy;
1.1055 raeburn 12536: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12537: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12538: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12539: foreach my $item (@{$contents}) {
12540: $count ++;
1.1056 raeburn 12541: @{$dirorder->{$count}} = @hierarchy;
12542: $titles->{$count} = $item;
1.1055 raeburn 12543: &archive_hierarchy($depth,$count,$parent,$children);
12544: if ($wantform) {
12545: $datatable .= &archive_row($is_dir->{$item},$item,
12546: $currdir,$depth,$count);
12547: }
12548: if ($is_dir->{$item}) {
12549: $depth ++;
1.1056 raeburn 12550: push(@hierarchy,$count);
12551: $parent->{$depth} = $count;
1.1055 raeburn 12552: $datatable .=
12553: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12554: \$depth,\$count,\@hierarchy,$dirorder,
12555: $children,$parent,$titles,$wantform);
1.1055 raeburn 12556: $depth --;
1.1056 raeburn 12557: pop(@hierarchy);
1.1055 raeburn 12558: }
12559: }
12560: return ($count,$datatable);
12561: }
12562:
12563: sub recurse_extracted_archive {
1.1056 raeburn 12564: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12565: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12566: my $result='';
1.1056 raeburn 12567: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12568: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12569: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12570: return $result;
12571: }
12572: my $dirptr = 16384;
12573: my ($newdirlistref,$newlisterror) =
12574: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12575: if (ref($newdirlistref) eq 'ARRAY') {
12576: foreach my $dir_line (@{$newdirlistref}) {
12577: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12578: unless ($item =~ /^\.+$/) {
12579: $$count ++;
1.1056 raeburn 12580: @{$dirorder->{$$count}} = @{$hierarchy};
12581: $titles->{$$count} = $item;
1.1055 raeburn 12582: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12583:
1.1055 raeburn 12584: my $is_dir;
12585: if ($dirptr&$testdir) {
12586: $is_dir = 1;
12587: }
12588: if ($wantform) {
12589: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12590: }
12591: if ($is_dir) {
12592: $$depth ++;
1.1056 raeburn 12593: push(@{$hierarchy},$$count);
12594: $parent->{$$depth} = $$count;
1.1055 raeburn 12595: $result .=
12596: &recurse_extracted_archive("$currdir/$item",$docudom,
12597: $docuname,$depth,$count,
1.1056 raeburn 12598: $hierarchy,$dirorder,$children,
12599: $parent,$titles,$wantform);
1.1055 raeburn 12600: $$depth --;
1.1056 raeburn 12601: pop(@{$hierarchy});
1.1055 raeburn 12602: }
12603: }
12604: }
12605: }
12606: return $result;
12607: }
12608:
12609: sub archive_hierarchy {
12610: my ($depth,$count,$parent,$children) =@_;
12611: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12612: if (exists($parent->{$depth})) {
12613: $children->{$parent->{$depth}} .= $count.':';
12614: }
12615: }
12616: return;
12617: }
12618:
12619: sub archive_row {
12620: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12621: my ($name) = ($item =~ m{([^/]+)$});
12622: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12623: 'display' => 'Add as file',
1.1055 raeburn 12624: 'dependency' => 'Include as dependency',
12625: 'discard' => 'Discard',
12626: );
12627: if ($is_dir) {
1.1059 raeburn 12628: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12629: }
1.1056 raeburn 12630: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12631: my $offset = 0;
1.1055 raeburn 12632: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12633: $offset ++;
1.1065 raeburn 12634: if ($action ne 'display') {
12635: $offset ++;
12636: }
1.1055 raeburn 12637: $output .= '<td><span class="LC_nobreak">'.
12638: '<label><input type="radio" name="archive_'.$count.
12639: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12640: my $text = $choices{$action};
12641: if ($is_dir) {
12642: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12643: if ($action eq 'display') {
1.1059 raeburn 12644: $text = &mt('Add as folder');
1.1055 raeburn 12645: }
1.1056 raeburn 12646: } else {
12647: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12648:
12649: }
12650: $output .= ' /> '.$choices{$action}.'</label></span>';
12651: if ($action eq 'dependency') {
12652: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12653: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12654: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12655: '<option value=""></option>'."\n".
12656: '</select>'."\n".
12657: '</div>';
1.1059 raeburn 12658: } elsif ($action eq 'display') {
12659: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12660: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12661: '</div>';
1.1055 raeburn 12662: }
1.1056 raeburn 12663: $output .= '</td>';
1.1055 raeburn 12664: }
12665: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12666: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12667: for (my $i=0; $i<$depth; $i++) {
12668: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12669: }
12670: if ($is_dir) {
12671: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12672: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12673: } else {
12674: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12675: }
12676: $output .= ' '.$name.'</td>'."\n".
12677: &end_data_table_row();
12678: return $output;
12679: }
12680:
12681: sub archive_options_form {
1.1065 raeburn 12682: my ($form,$display,$count,$hiddenelem) = @_;
12683: my %lt = &Apache::lonlocal::texthash(
12684: perm => 'Permanently remove archive file?',
12685: hows => 'How should each extracted item be incorporated in the course?',
12686: cont => 'Content actions for all',
12687: addf => 'Add as folder/file',
12688: incd => 'Include as dependency for a displayed file',
12689: disc => 'Discard',
12690: no => 'No',
12691: yes => 'Yes',
12692: save => 'Save',
12693: );
12694: my $output = <<"END";
12695: <form name="$form" method="post" action="">
12696: <p><span class="LC_nobreak">$lt{'perm'}
12697: <label>
12698: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12699: </label>
12700:
12701: <label>
12702: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12703: </span>
12704: </p>
12705: <input type="hidden" name="phase" value="decompress_cleanup" />
12706: <br />$lt{'hows'}
12707: <div class="LC_columnSection">
12708: <fieldset>
12709: <legend>$lt{'cont'}</legend>
12710: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12711: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12712: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12713: </fieldset>
12714: </div>
12715: END
12716: return $output.
1.1055 raeburn 12717: &start_data_table()."\n".
1.1065 raeburn 12718: $display."\n".
1.1055 raeburn 12719: &end_data_table()."\n".
12720: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12721: $hiddenelem.
1.1065 raeburn 12722: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12723: '</form>';
12724: }
12725:
12726: sub archive_javascript {
1.1056 raeburn 12727: my ($startcount,$numitems,$titles,$children) = @_;
12728: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12729: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12730: my $scripttag = <<START;
12731: <script type="text/javascript">
12732: // <![CDATA[
12733:
12734: function checkAll(form,prefix) {
12735: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12736: for (var i=0; i < form.elements.length; i++) {
12737: var id = form.elements[i].id;
12738: if ((id != '') && (id != undefined)) {
12739: if (idstr.test(id)) {
12740: if (form.elements[i].type == 'radio') {
12741: form.elements[i].checked = true;
1.1056 raeburn 12742: var nostart = i-$startcount;
1.1059 raeburn 12743: var offset = nostart%7;
12744: var count = (nostart-offset)/7;
1.1056 raeburn 12745: dependencyCheck(form,count,offset);
1.1055 raeburn 12746: }
12747: }
12748: }
12749: }
12750: }
12751:
12752: function propagateCheck(form,count) {
12753: if (count > 0) {
1.1059 raeburn 12754: var startelement = $startcount + ((count-1) * 7);
12755: for (var j=1; j<6; j++) {
12756: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12757: var item = startelement + j;
12758: if (form.elements[item].type == 'radio') {
12759: if (form.elements[item].checked) {
12760: containerCheck(form,count,j);
12761: break;
12762: }
1.1055 raeburn 12763: }
12764: }
12765: }
12766: }
12767: }
12768:
12769: numitems = $numitems
1.1056 raeburn 12770: var titles = new Array(numitems);
12771: var parents = new Array(numitems);
1.1055 raeburn 12772: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12773: parents[i] = new Array;
1.1055 raeburn 12774: }
1.1059 raeburn 12775: var maintitle = '$maintitle';
1.1055 raeburn 12776:
12777: START
12778:
1.1056 raeburn 12779: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12780: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12781: for (my $i=0; $i<@contents; $i ++) {
12782: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12783: }
12784: }
12785:
1.1056 raeburn 12786: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12787: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12788: }
12789:
1.1055 raeburn 12790: $scripttag .= <<END;
12791:
12792: function containerCheck(form,count,offset) {
12793: if (count > 0) {
1.1056 raeburn 12794: dependencyCheck(form,count,offset);
1.1059 raeburn 12795: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12796: form.elements[item].checked = true;
12797: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12798: if (parents[count].length > 0) {
12799: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12800: containerCheck(form,parents[count][j],offset);
12801: }
12802: }
12803: }
12804: }
12805: }
12806:
12807: function dependencyCheck(form,count,offset) {
12808: if (count > 0) {
1.1059 raeburn 12809: var chosen = (offset+$startcount)+7*(count-1);
12810: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12811: var currtype = form.elements[depitem].type;
12812: if (form.elements[chosen].value == 'dependency') {
12813: document.getElementById('arc_depon_'+count).style.display='block';
12814: form.elements[depitem].options.length = 0;
12815: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12816: for (var i=1; i<=numitems; i++) {
12817: if (i == count) {
12818: continue;
12819: }
1.1059 raeburn 12820: var startelement = $startcount + (i-1) * 7;
12821: for (var j=1; j<6; j++) {
12822: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12823: var item = startelement + j;
12824: if (form.elements[item].type == 'radio') {
12825: if (form.elements[item].checked) {
12826: if (form.elements[item].value == 'display') {
12827: var n = form.elements[depitem].options.length;
12828: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12829: }
12830: }
12831: }
12832: }
12833: }
12834: }
12835: } else {
12836: document.getElementById('arc_depon_'+count).style.display='none';
12837: form.elements[depitem].options.length = 0;
12838: form.elements[depitem].options[0] = new Option('Select','',true,true);
12839: }
1.1059 raeburn 12840: titleCheck(form,count,offset);
1.1056 raeburn 12841: }
12842: }
12843:
12844: function propagateSelect(form,count,offset) {
12845: if (count > 0) {
1.1065 raeburn 12846: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12847: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12848: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12849: if (parents[count].length > 0) {
12850: for (var j=0; j<parents[count].length; j++) {
12851: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12852: }
12853: }
12854: }
12855: }
12856: }
1.1056 raeburn 12857:
12858: function containerSelect(form,count,offset,picked) {
12859: if (count > 0) {
1.1065 raeburn 12860: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12861: if (form.elements[item].type == 'radio') {
12862: if (form.elements[item].value == 'dependency') {
12863: if (form.elements[item+1].type == 'select-one') {
12864: for (var i=0; i<form.elements[item+1].options.length; i++) {
12865: if (form.elements[item+1].options[i].value == picked) {
12866: form.elements[item+1].selectedIndex = i;
12867: break;
12868: }
12869: }
12870: }
12871: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12872: if (parents[count].length > 0) {
12873: for (var j=0; j<parents[count].length; j++) {
12874: containerSelect(form,parents[count][j],offset,picked);
12875: }
12876: }
12877: }
12878: }
12879: }
12880: }
12881: }
12882:
1.1059 raeburn 12883: function titleCheck(form,count,offset) {
12884: if (count > 0) {
12885: var chosen = (offset+$startcount)+7*(count-1);
12886: var depitem = $startcount + ((count-1) * 7) + 2;
12887: var currtype = form.elements[depitem].type;
12888: if (form.elements[chosen].value == 'display') {
12889: document.getElementById('arc_title_'+count).style.display='block';
12890: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12891: document.getElementById('archive_title_'+count).value=maintitle;
12892: }
12893: } else {
12894: document.getElementById('arc_title_'+count).style.display='none';
12895: if (currtype == 'text') {
12896: document.getElementById('archive_title_'+count).value='';
12897: }
12898: }
12899: }
12900: return;
12901: }
12902:
1.1055 raeburn 12903: // ]]>
12904: </script>
12905: END
12906: return $scripttag;
12907: }
12908:
12909: sub process_extracted_files {
1.1067 raeburn 12910: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12911: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12912: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12913: my @ids=&Apache::lonnet::current_machine_ids();
12914: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12915: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12916: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12917: if (grep(/^\Q$docuhome\E$/,@ids)) {
12918: $prefix = &LONCAPA::propath($docudom,$docuname);
12919: $pathtocheck = "$dir_root/$destination";
12920: $dir = $dir_root;
12921: $ishome = 1;
12922: } else {
12923: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12924: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12925: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12926: }
12927: my $currdir = "$dir_root/$destination";
12928: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12929: if ($env{'form.folderpath'}) {
12930: my @items = split('&',$env{'form.folderpath'});
12931: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12932: if ($env{'form.folderpath'} =~ /\:1$/) {
12933: $containers{'0'}='page';
12934: } else {
12935: $containers{'0'}='sequence';
12936: }
1.1055 raeburn 12937: }
12938: my @archdirs = &get_env_multiple('form.archive_directory');
12939: if ($numitems) {
12940: for (my $i=1; $i<=$numitems; $i++) {
12941: my $path = $env{'form.archive_content_'.$i};
12942: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12943: my $item = $1;
12944: $toplevelitems{$item} = $i;
12945: if (grep(/^\Q$i\E$/,@archdirs)) {
12946: $is_dir{$item} = 1;
12947: }
12948: }
12949: }
12950: }
1.1067 raeburn 12951: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12952: if (keys(%toplevelitems) > 0) {
12953: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12954: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12955: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12956: }
1.1066 raeburn 12957: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12958: if ($numitems) {
12959: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12960: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12961: my $path = $env{'form.archive_content_'.$i};
12962: if ($path =~ /^\Q$pathtocheck\E/) {
12963: if ($env{'form.archive_'.$i} eq 'discard') {
12964: if ($prefix ne '' && $path ne '') {
12965: if (-e $prefix.$path) {
1.1066 raeburn 12966: if ((@archdirs > 0) &&
12967: (grep(/^\Q$i\E$/,@archdirs))) {
12968: $todeletedir{$prefix.$path} = 1;
12969: } else {
12970: $todelete{$prefix.$path} = 1;
12971: }
1.1055 raeburn 12972: }
12973: }
12974: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12975: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12976: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12977: $docstitle = $env{'form.archive_title_'.$i};
12978: if ($docstitle eq '') {
12979: $docstitle = $title;
12980: }
1.1055 raeburn 12981: $outer = 0;
1.1056 raeburn 12982: if (ref($dirorder{$i}) eq 'ARRAY') {
12983: if (@{$dirorder{$i}} > 0) {
12984: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12985: if ($env{'form.archive_'.$item} eq 'display') {
12986: $outer = $item;
12987: last;
12988: }
12989: }
12990: }
12991: }
12992: my ($errtext,$fatal) =
12993: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12994: '/'.$folders{$outer}.'.'.
12995: $containers{$outer});
12996: next if ($fatal);
12997: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12998: if ($context eq 'coursedocs') {
1.1056 raeburn 12999: $mapinner{$i} = time;
1.1055 raeburn 13000: $folders{$i} = 'default_'.$mapinner{$i};
13001: $containers{$i} = 'sequence';
13002: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13003: $folders{$i}.'.'.$containers{$i};
13004: my $newidx = &LONCAPA::map::getresidx();
13005: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13006: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13007: push(@LONCAPA::map::order,$newidx);
13008: my ($outtext,$errtext) =
13009: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13010: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13011: '.'.$containers{$outer},1,1);
1.1056 raeburn 13012: $newseqid{$i} = $newidx;
1.1067 raeburn 13013: unless ($errtext) {
1.1075.2.128 raeburn 13014: $result .= '<li>'.&mt('Folder: [_1] added to course',
13015: &HTML::Entities::encode($docstitle,'<>&"'))..
13016: '</li>'."\n";
1.1067 raeburn 13017: }
1.1055 raeburn 13018: }
13019: } else {
13020: if ($context eq 'coursedocs') {
13021: my $newidx=&LONCAPA::map::getresidx();
13022: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13023: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13024: $title;
1.1075.2.128 raeburn 13025: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13026: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13027: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13028: }
1.1075.2.128 raeburn 13029: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13030: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13031: }
13032: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13033: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13034: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13035: unless ($ishome) {
13036: my $fetch = "$newdest{$i}/$title";
13037: $fetch =~ s/^\Q$prefix$dir\E//;
13038: $prompttofetch{$fetch} = 1;
13039: }
13040: }
13041: }
13042: $LONCAPA::map::resources[$newidx]=
13043: $docstitle.':'.$url.':false:normal:res';
13044: push(@LONCAPA::map::order, $newidx);
13045: my ($outtext,$errtext)=
13046: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13047: $docuname.'/'.$folders{$outer}.
13048: '.'.$containers{$outer},1,1);
13049: unless ($errtext) {
13050: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13051: $result .= '<li>'.&mt('File: [_1] added to course',
13052: &HTML::Entities::encode($docstitle,'<>&"')).
13053: '</li>'."\n";
13054: }
1.1067 raeburn 13055: }
1.1075.2.128 raeburn 13056: } else {
13057: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13058: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13059: }
1.1055 raeburn 13060: }
13061: }
1.1075.2.11 raeburn 13062: }
13063: } else {
1.1075.2.128 raeburn 13064: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13065: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13066: }
13067: }
13068: for (my $i=1; $i<=$numitems; $i++) {
13069: next unless ($env{'form.archive_'.$i} eq 'dependency');
13070: my $path = $env{'form.archive_content_'.$i};
13071: if ($path =~ /^\Q$pathtocheck\E/) {
13072: my ($title) = ($path =~ m{/([^/]+)$});
13073: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13074: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13075: if (ref($dirorder{$i}) eq 'ARRAY') {
13076: my ($itemidx,$fullpath,$relpath);
13077: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13078: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13079: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13080: if ($dirorder{$i}->[$j] eq $container) {
13081: $itemidx = $j;
1.1056 raeburn 13082: }
13083: }
1.1075.2.11 raeburn 13084: }
13085: if ($itemidx eq '') {
13086: $itemidx = 0;
13087: }
13088: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13089: if ($mapinner{$referrer{$i}}) {
13090: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13091: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13092: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13093: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13094: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13095: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13096: if (!-e $fullpath) {
13097: mkdir($fullpath,0755);
1.1056 raeburn 13098: }
13099: }
1.1075.2.11 raeburn 13100: } else {
13101: last;
1.1056 raeburn 13102: }
1.1075.2.11 raeburn 13103: }
13104: }
13105: } elsif ($newdest{$referrer{$i}}) {
13106: $fullpath = $newdest{$referrer{$i}};
13107: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13108: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13109: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13110: last;
13111: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13112: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13113: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13114: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13115: if (!-e $fullpath) {
13116: mkdir($fullpath,0755);
1.1056 raeburn 13117: }
13118: }
1.1075.2.11 raeburn 13119: } else {
13120: last;
1.1056 raeburn 13121: }
1.1075.2.11 raeburn 13122: }
13123: }
13124: if ($fullpath ne '') {
13125: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13126: unless (rename("$prefix$path","$fullpath/$title")) {
13127: $warning .= &mt('Failed to rename dependency').'<br />';
13128: }
1.1075.2.11 raeburn 13129: }
13130: if (-e "$fullpath/$title") {
13131: my $showpath;
13132: if ($relpath ne '') {
13133: $showpath = "$relpath/$title";
13134: } else {
13135: $showpath = "/$title";
1.1056 raeburn 13136: }
1.1075.2.128 raeburn 13137: $result .= '<li>'.&mt('[_1] included as a dependency',
13138: &HTML::Entities::encode($showpath,'<>&"')).
13139: '</li>'."\n";
13140: unless ($ishome) {
13141: my $fetch = "$fullpath/$title";
13142: $fetch =~ s/^\Q$prefix$dir\E//;
13143: $prompttofetch{$fetch} = 1;
13144: }
1.1055 raeburn 13145: }
13146: }
13147: }
1.1075.2.11 raeburn 13148: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13149: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13150: &HTML::Entities::encode($path,'<>&"'),
13151: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13152: '<br />';
1.1055 raeburn 13153: }
13154: } else {
1.1075.2.128 raeburn 13155: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13156: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13157: }
13158: }
13159: if (keys(%todelete)) {
13160: foreach my $key (keys(%todelete)) {
13161: unlink($key);
1.1066 raeburn 13162: }
13163: }
13164: if (keys(%todeletedir)) {
13165: foreach my $key (keys(%todeletedir)) {
13166: rmdir($key);
13167: }
13168: }
13169: foreach my $dir (sort(keys(%is_dir))) {
13170: if (($pathtocheck ne '') && ($dir ne '')) {
13171: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13172: }
13173: }
1.1067 raeburn 13174: if ($result ne '') {
13175: $output .= '<ul>'."\n".
13176: $result."\n".
13177: '</ul>';
13178: }
13179: unless ($ishome) {
13180: my $replicationfail;
13181: foreach my $item (keys(%prompttofetch)) {
13182: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13183: unless ($fetchresult eq 'ok') {
13184: $replicationfail .= '<li>'.$item.'</li>'."\n";
13185: }
13186: }
13187: if ($replicationfail) {
13188: $output .= '<p class="LC_error">'.
13189: &mt('Course home server failed to retrieve:').'<ul>'.
13190: $replicationfail.
13191: '</ul></p>';
13192: }
13193: }
1.1055 raeburn 13194: } else {
13195: $warning = &mt('No items found in archive.');
13196: }
13197: if ($error) {
13198: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13199: $error.'</p>'."\n";
13200: }
13201: if ($warning) {
13202: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13203: }
13204: return $output;
13205: }
13206:
1.1066 raeburn 13207: sub cleanup_empty_dirs {
13208: my ($path) = @_;
13209: if (($path ne '') && (-d $path)) {
13210: if (opendir(my $dirh,$path)) {
13211: my @dircontents = grep(!/^\./,readdir($dirh));
13212: my $numitems = 0;
13213: foreach my $item (@dircontents) {
13214: if (-d "$path/$item") {
1.1075.2.28 raeburn 13215: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13216: if (-e "$path/$item") {
13217: $numitems ++;
13218: }
13219: } else {
13220: $numitems ++;
13221: }
13222: }
13223: if ($numitems == 0) {
13224: rmdir($path);
13225: }
13226: closedir($dirh);
13227: }
13228: }
13229: return;
13230: }
13231:
1.41 ng 13232: =pod
1.45 matthew 13233:
1.1075.2.56 raeburn 13234: =item * &get_folder_hierarchy()
1.1068 raeburn 13235:
13236: Provides hierarchy of names of folders/sub-folders containing the current
13237: item,
13238:
13239: Inputs: 3
13240: - $navmap - navmaps object
13241:
13242: - $map - url for map (either the trigger itself, or map containing
13243: the resource, which is the trigger).
13244:
13245: - $showitem - 1 => show title for map itself; 0 => do not show.
13246:
13247: Outputs: 1 @pathitems - array of folder/subfolder names.
13248:
13249: =cut
13250:
13251: sub get_folder_hierarchy {
13252: my ($navmap,$map,$showitem) = @_;
13253: my @pathitems;
13254: if (ref($navmap)) {
13255: my $mapres = $navmap->getResourceByUrl($map);
13256: if (ref($mapres)) {
13257: my $pcslist = $mapres->map_hierarchy();
13258: if ($pcslist ne '') {
13259: my @pcs = split(/,/,$pcslist);
13260: foreach my $pc (@pcs) {
13261: if ($pc == 1) {
1.1075.2.38 raeburn 13262: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13263: } else {
13264: my $res = $navmap->getByMapPc($pc);
13265: if (ref($res)) {
13266: my $title = $res->compTitle();
13267: $title =~ s/\W+/_/g;
13268: if ($title ne '') {
13269: push(@pathitems,$title);
13270: }
13271: }
13272: }
13273: }
13274: }
1.1071 raeburn 13275: if ($showitem) {
13276: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13277: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13278: } else {
13279: my $maptitle = $mapres->compTitle();
13280: $maptitle =~ s/\W+/_/g;
13281: if ($maptitle ne '') {
13282: push(@pathitems,$maptitle);
13283: }
1.1068 raeburn 13284: }
13285: }
13286: }
13287: }
13288: return @pathitems;
13289: }
13290:
13291: =pod
13292:
1.1015 raeburn 13293: =item * &get_turnedin_filepath()
13294:
13295: Determines path in a user's portfolio file for storage of files uploaded
13296: to a specific essayresponse or dropbox item.
13297:
13298: Inputs: 3 required + 1 optional.
13299: $symb is symb for resource, $uname and $udom are for current user (required).
13300: $caller is optional (can be "submission", if routine is called when storing
13301: an upoaded file when "Submit Answer" button was pressed).
13302:
13303: Returns array containing $path and $multiresp.
13304: $path is path in portfolio. $multiresp is 1 if this resource contains more
13305: than one file upload item. Callers of routine should append partid as a
13306: subdirectory to $path in cases where $multiresp is 1.
13307:
13308: Called by: homework/essayresponse.pm and homework/structuretags.pm
13309:
13310: =cut
13311:
13312: sub get_turnedin_filepath {
13313: my ($symb,$uname,$udom,$caller) = @_;
13314: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13315: my $turnindir;
13316: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13317: $turnindir = $userhash{'turnindir'};
13318: my ($path,$multiresp);
13319: if ($turnindir eq '') {
13320: if ($caller eq 'submission') {
13321: $turnindir = &mt('turned in');
13322: $turnindir =~ s/\W+/_/g;
13323: my %newhash = (
13324: 'turnindir' => $turnindir,
13325: );
13326: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13327: }
13328: }
13329: if ($turnindir ne '') {
13330: $path = '/'.$turnindir.'/';
13331: my ($multipart,$turnin,@pathitems);
13332: my $navmap = Apache::lonnavmaps::navmap->new();
13333: if (defined($navmap)) {
13334: my $mapres = $navmap->getResourceByUrl($map);
13335: if (ref($mapres)) {
13336: my $pcslist = $mapres->map_hierarchy();
13337: if ($pcslist ne '') {
13338: foreach my $pc (split(/,/,$pcslist)) {
13339: my $res = $navmap->getByMapPc($pc);
13340: if (ref($res)) {
13341: my $title = $res->compTitle();
13342: $title =~ s/\W+/_/g;
13343: if ($title ne '') {
1.1075.2.48 raeburn 13344: if (($pc > 1) && (length($title) > 12)) {
13345: $title = substr($title,0,12);
13346: }
1.1015 raeburn 13347: push(@pathitems,$title);
13348: }
13349: }
13350: }
13351: }
13352: my $maptitle = $mapres->compTitle();
13353: $maptitle =~ s/\W+/_/g;
13354: if ($maptitle ne '') {
1.1075.2.48 raeburn 13355: if (length($maptitle) > 12) {
13356: $maptitle = substr($maptitle,0,12);
13357: }
1.1015 raeburn 13358: push(@pathitems,$maptitle);
13359: }
13360: unless ($env{'request.state'} eq 'construct') {
13361: my $res = $navmap->getBySymb($symb);
13362: if (ref($res)) {
13363: my $partlist = $res->parts();
13364: my $totaluploads = 0;
13365: if (ref($partlist) eq 'ARRAY') {
13366: foreach my $part (@{$partlist}) {
13367: my @types = $res->responseType($part);
13368: my @ids = $res->responseIds($part);
13369: for (my $i=0; $i < scalar(@ids); $i++) {
13370: if ($types[$i] eq 'essay') {
13371: my $partid = $part.'_'.$ids[$i];
13372: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13373: $totaluploads ++;
13374: }
13375: }
13376: }
13377: }
13378: if ($totaluploads > 1) {
13379: $multiresp = 1;
13380: }
13381: }
13382: }
13383: }
13384: } else {
13385: return;
13386: }
13387: } else {
13388: return;
13389: }
13390: my $restitle=&Apache::lonnet::gettitle($symb);
13391: $restitle =~ s/\W+/_/g;
13392: if ($restitle eq '') {
13393: $restitle = ($resurl =~ m{/[^/]+$});
13394: if ($restitle eq '') {
13395: $restitle = time;
13396: }
13397: }
1.1075.2.48 raeburn 13398: if (length($restitle) > 12) {
13399: $restitle = substr($restitle,0,12);
13400: }
1.1015 raeburn 13401: push(@pathitems,$restitle);
13402: $path .= join('/',@pathitems);
13403: }
13404: return ($path,$multiresp);
13405: }
13406:
13407: =pod
13408:
1.464 albertel 13409: =back
1.41 ng 13410:
1.112 bowersj2 13411: =head1 CSV Upload/Handling functions
1.38 albertel 13412:
1.41 ng 13413: =over 4
13414:
1.648 raeburn 13415: =item * &upfile_store($r)
1.41 ng 13416:
13417: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13418: needs $env{'form.upfile'}
1.41 ng 13419: returns $datatoken to be put into hidden field
13420:
13421: =cut
1.31 albertel 13422:
13423: sub upfile_store {
13424: my $r=shift;
1.258 albertel 13425: $env{'form.upfile'}=~s/\r/\n/gs;
13426: $env{'form.upfile'}=~s/\f/\n/gs;
13427: $env{'form.upfile'}=~s/\n+/\n/gs;
13428: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13429:
1.1075.2.128 raeburn 13430: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13431: '_enroll_'.$env{'request.course.id'}.'_'.
13432: time.'_'.$$);
13433: return if ($datatoken eq '');
13434:
1.31 albertel 13435: {
1.158 raeburn 13436: my $datafile = $r->dir_config('lonDaemons').
13437: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13438: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13439: print $fh $env{'form.upfile'};
1.158 raeburn 13440: close($fh);
13441: }
1.31 albertel 13442: }
13443: return $datatoken;
13444: }
13445:
1.56 matthew 13446: =pod
13447:
1.1075.2.128 raeburn 13448: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13449:
13450: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13451: $datatoken is the name to assign to the temporary file.
1.258 albertel 13452: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13453:
13454: =cut
1.31 albertel 13455:
13456: sub load_tmp_file {
1.1075.2.128 raeburn 13457: my ($r,$datatoken) = @_;
13458: return if ($datatoken eq '');
1.31 albertel 13459: my @studentdata=();
13460: {
1.158 raeburn 13461: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13462: '/tmp/'.$datatoken.'.tmp';
13463: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13464: @studentdata=<$fh>;
13465: close($fh);
13466: }
1.31 albertel 13467: }
1.258 albertel 13468: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13469: }
13470:
1.1075.2.128 raeburn 13471: sub valid_datatoken {
13472: my ($datatoken) = @_;
1.1075.2.131 raeburn 13473: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13474: return $datatoken;
13475: }
13476: return;
13477: }
13478:
1.56 matthew 13479: =pod
13480:
1.648 raeburn 13481: =item * &upfile_record_sep()
1.41 ng 13482:
13483: Separate uploaded file into records
13484: returns array of records,
1.258 albertel 13485: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13486:
13487: =cut
1.31 albertel 13488:
13489: sub upfile_record_sep {
1.258 albertel 13490: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13491: } else {
1.248 albertel 13492: my @records;
1.258 albertel 13493: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13494: if ($line=~/^\s*$/) { next; }
13495: push(@records,$line);
13496: }
13497: return @records;
1.31 albertel 13498: }
13499: }
13500:
1.56 matthew 13501: =pod
13502:
1.648 raeburn 13503: =item * &record_sep($record)
1.41 ng 13504:
1.258 albertel 13505: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13506:
13507: =cut
13508:
1.263 www 13509: sub takeleft {
13510: my $index=shift;
13511: return substr('0000'.$index,-4,4);
13512: }
13513:
1.31 albertel 13514: sub record_sep {
13515: my $record=shift;
13516: my %components=();
1.258 albertel 13517: if ($env{'form.upfiletype'} eq 'xml') {
13518: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13519: my $i=0;
1.356 albertel 13520: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13521: $field=~s/^(\"|\')//;
13522: $field=~s/(\"|\')$//;
1.263 www 13523: $components{&takeleft($i)}=$field;
1.31 albertel 13524: $i++;
13525: }
1.258 albertel 13526: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13527: my $i=0;
1.356 albertel 13528: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13529: $field=~s/^(\"|\')//;
13530: $field=~s/(\"|\')$//;
1.263 www 13531: $components{&takeleft($i)}=$field;
1.31 albertel 13532: $i++;
13533: }
13534: } else {
1.561 www 13535: my $separator=',';
1.480 banghart 13536: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13537: $separator=';';
1.480 banghart 13538: }
1.31 albertel 13539: my $i=0;
1.561 www 13540: # the character we are looking for to indicate the end of a quote or a record
13541: my $looking_for=$separator;
13542: # do not add the characters to the fields
13543: my $ignore=0;
13544: # we just encountered a separator (or the beginning of the record)
13545: my $just_found_separator=1;
13546: # store the field we are working on here
13547: my $field='';
13548: # work our way through all characters in record
13549: foreach my $character ($record=~/(.)/g) {
13550: if ($character eq $looking_for) {
13551: if ($character ne $separator) {
13552: # Found the end of a quote, again looking for separator
13553: $looking_for=$separator;
13554: $ignore=1;
13555: } else {
13556: # Found a separator, store away what we got
13557: $components{&takeleft($i)}=$field;
13558: $i++;
13559: $just_found_separator=1;
13560: $ignore=0;
13561: $field='';
13562: }
13563: next;
13564: }
13565: # single or double quotation marks after a separator indicate beginning of a quote
13566: # we are now looking for the end of the quote and need to ignore separators
13567: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13568: $looking_for=$character;
13569: next;
13570: }
13571: # ignore would be true after we reached the end of a quote
13572: if ($ignore) { next; }
13573: if (($just_found_separator) && ($character=~/\s/)) { next; }
13574: $field.=$character;
13575: $just_found_separator=0;
1.31 albertel 13576: }
1.561 www 13577: # catch the very last entry, since we never encountered the separator
13578: $components{&takeleft($i)}=$field;
1.31 albertel 13579: }
13580: return %components;
13581: }
13582:
1.144 matthew 13583: ######################################################
13584: ######################################################
13585:
1.56 matthew 13586: =pod
13587:
1.648 raeburn 13588: =item * &upfile_select_html()
1.41 ng 13589:
1.144 matthew 13590: Return HTML code to select a file from the users machine and specify
13591: the file type.
1.41 ng 13592:
13593: =cut
13594:
1.144 matthew 13595: ######################################################
13596: ######################################################
1.31 albertel 13597: sub upfile_select_html {
1.144 matthew 13598: my %Types = (
13599: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13600: semisv => &mt('Semicolon separated values'),
1.144 matthew 13601: space => &mt('Space separated'),
13602: tab => &mt('Tabulator separated'),
13603: # xml => &mt('HTML/XML'),
13604: );
13605: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13606: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13607: foreach my $type (sort(keys(%Types))) {
13608: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13609: }
13610: $Str .= "</select>\n";
13611: return $Str;
1.31 albertel 13612: }
13613:
1.301 albertel 13614: sub get_samples {
13615: my ($records,$toget) = @_;
13616: my @samples=({});
13617: my $got=0;
13618: foreach my $rec (@$records) {
13619: my %temp = &record_sep($rec);
13620: if (! grep(/\S/, values(%temp))) { next; }
13621: if (%temp) {
13622: $samples[$got]=\%temp;
13623: $got++;
13624: if ($got == $toget) { last; }
13625: }
13626: }
13627: return \@samples;
13628: }
13629:
1.144 matthew 13630: ######################################################
13631: ######################################################
13632:
1.56 matthew 13633: =pod
13634:
1.648 raeburn 13635: =item * &csv_print_samples($r,$records)
1.41 ng 13636:
13637: Prints a table of sample values from each column uploaded $r is an
13638: Apache Request ref, $records is an arrayref from
13639: &Apache::loncommon::upfile_record_sep
13640:
13641: =cut
13642:
1.144 matthew 13643: ######################################################
13644: ######################################################
1.31 albertel 13645: sub csv_print_samples {
13646: my ($r,$records) = @_;
1.662 bisitz 13647: my $samples = &get_samples($records,5);
1.301 albertel 13648:
1.594 raeburn 13649: $r->print(&mt('Samples').'<br />'.&start_data_table().
13650: &start_data_table_header_row());
1.356 albertel 13651: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13652: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13653: $r->print(&end_data_table_header_row());
1.301 albertel 13654: foreach my $hash (@$samples) {
1.594 raeburn 13655: $r->print(&start_data_table_row());
1.356 albertel 13656: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13657: $r->print('<td>');
1.356 albertel 13658: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13659: $r->print('</td>');
13660: }
1.594 raeburn 13661: $r->print(&end_data_table_row());
1.31 albertel 13662: }
1.594 raeburn 13663: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13664: }
13665:
1.144 matthew 13666: ######################################################
13667: ######################################################
13668:
1.56 matthew 13669: =pod
13670:
1.648 raeburn 13671: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13672:
13673: Prints a table to create associations between values and table columns.
1.144 matthew 13674:
1.41 ng 13675: $r is an Apache Request ref,
13676: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13677: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13678:
13679: =cut
13680:
1.144 matthew 13681: ######################################################
13682: ######################################################
1.31 albertel 13683: sub csv_print_select_table {
13684: my ($r,$records,$d) = @_;
1.301 albertel 13685: my $i=0;
13686: my $samples = &get_samples($records,1);
1.144 matthew 13687: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13688: &start_data_table().&start_data_table_header_row().
1.144 matthew 13689: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13690: '<th>'.&mt('Column').'</th>'.
13691: &end_data_table_header_row()."\n");
1.356 albertel 13692: foreach my $array_ref (@$d) {
13693: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13694: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13695:
1.875 bisitz 13696: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13697: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13698: $r->print('<option value="none"></option>');
1.356 albertel 13699: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13700: $r->print('<option value="'.$sample.'"'.
13701: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13702: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13703: }
1.594 raeburn 13704: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13705: $i++;
13706: }
1.594 raeburn 13707: $r->print(&end_data_table());
1.31 albertel 13708: $i--;
13709: return $i;
13710: }
1.56 matthew 13711:
1.144 matthew 13712: ######################################################
13713: ######################################################
13714:
1.56 matthew 13715: =pod
1.31 albertel 13716:
1.648 raeburn 13717: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13718:
13719: Prints a table of sample values from the upload and can make associate samples to internal names.
13720:
13721: $r is an Apache Request ref,
13722: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13723: $d is an array of 2 element arrays (internal name, displayed name)
13724:
13725: =cut
13726:
1.144 matthew 13727: ######################################################
13728: ######################################################
1.31 albertel 13729: sub csv_samples_select_table {
13730: my ($r,$records,$d) = @_;
13731: my $i=0;
1.144 matthew 13732: #
1.662 bisitz 13733: my $max_samples = 5;
13734: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13735: $r->print(&start_data_table().
13736: &start_data_table_header_row().'<th>'.
13737: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13738: &end_data_table_header_row());
1.301 albertel 13739:
13740: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13741: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13742: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13743: foreach my $option (@$d) {
13744: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13745: $r->print('<option value="'.$value.'"'.
1.253 albertel 13746: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13747: $display.'</option>');
1.31 albertel 13748: }
13749: $r->print('</select></td><td>');
1.662 bisitz 13750: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13751: if (defined($samples->[$line]{$key})) {
13752: $r->print($samples->[$line]{$key}."<br />\n");
13753: }
13754: }
1.594 raeburn 13755: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13756: $i++;
13757: }
1.594 raeburn 13758: $r->print(&end_data_table());
1.31 albertel 13759: $i--;
13760: return($i);
1.115 matthew 13761: }
13762:
1.144 matthew 13763: ######################################################
13764: ######################################################
13765:
1.115 matthew 13766: =pod
13767:
1.648 raeburn 13768: =item * &clean_excel_name($name)
1.115 matthew 13769:
13770: Returns a replacement for $name which does not contain any illegal characters.
13771:
13772: =cut
13773:
1.144 matthew 13774: ######################################################
13775: ######################################################
1.115 matthew 13776: sub clean_excel_name {
13777: my ($name) = @_;
13778: $name =~ s/[:\*\?\/\\]//g;
13779: if (length($name) > 31) {
13780: $name = substr($name,0,31);
13781: }
13782: return $name;
1.25 albertel 13783: }
1.84 albertel 13784:
1.85 albertel 13785: =pod
13786:
1.648 raeburn 13787: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13788:
13789: Returns either 1 or undef
13790:
13791: 1 if the part is to be hidden, undef if it is to be shown
13792:
13793: Arguments are:
13794:
13795: $id the id of the part to be checked
13796: $symb, optional the symb of the resource to check
13797: $udom, optional the domain of the user to check for
13798: $uname, optional the username of the user to check for
13799:
13800: =cut
1.84 albertel 13801:
13802: sub check_if_partid_hidden {
13803: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13804: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13805: $symb,$udom,$uname);
1.141 albertel 13806: my $truth=1;
13807: #if the string starts with !, then the list is the list to show not hide
13808: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13809: my @hiddenlist=split(/,/,$hiddenparts);
13810: foreach my $checkid (@hiddenlist) {
1.141 albertel 13811: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13812: }
1.141 albertel 13813: return !$truth;
1.84 albertel 13814: }
1.127 matthew 13815:
1.138 matthew 13816:
13817: ############################################################
13818: ############################################################
13819:
13820: =pod
13821:
1.157 matthew 13822: =back
13823:
1.138 matthew 13824: =head1 cgi-bin script and graphing routines
13825:
1.157 matthew 13826: =over 4
13827:
1.648 raeburn 13828: =item * &get_cgi_id()
1.138 matthew 13829:
13830: Inputs: none
13831:
13832: Returns an id which can be used to pass environment variables
13833: to various cgi-bin scripts. These environment variables will
13834: be removed from the users environment after a given time by
13835: the routine &Apache::lonnet::transfer_profile_to_env.
13836:
13837: =cut
13838:
13839: ############################################################
13840: ############################################################
1.152 albertel 13841: my $uniq=0;
1.136 matthew 13842: sub get_cgi_id {
1.154 albertel 13843: $uniq=($uniq+1)%100000;
1.280 albertel 13844: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13845: }
13846:
1.127 matthew 13847: ############################################################
13848: ############################################################
13849:
13850: =pod
13851:
1.648 raeburn 13852: =item * &DrawBarGraph()
1.127 matthew 13853:
1.138 matthew 13854: Facilitates the plotting of data in a (stacked) bar graph.
13855: Puts plot definition data into the users environment in order for
13856: graph.png to plot it. Returns an <img> tag for the plot.
13857: The bars on the plot are labeled '1','2',...,'n'.
13858:
13859: Inputs:
13860:
13861: =over 4
13862:
13863: =item $Title: string, the title of the plot
13864:
13865: =item $xlabel: string, text describing the X-axis of the plot
13866:
13867: =item $ylabel: string, text describing the Y-axis of the plot
13868:
13869: =item $Max: scalar, the maximum Y value to use in the plot
13870: If $Max is < any data point, the graph will not be rendered.
13871:
1.140 matthew 13872: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13873: they are plotted. If undefined, default values will be used.
13874:
1.178 matthew 13875: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13876:
1.138 matthew 13877: =item @Values: An array of array references. Each array reference holds data
13878: to be plotted in a stacked bar chart.
13879:
1.239 matthew 13880: =item If the final element of @Values is a hash reference the key/value
13881: pairs will be added to the graph definition.
13882:
1.138 matthew 13883: =back
13884:
13885: Returns:
13886:
13887: An <img> tag which references graph.png and the appropriate identifying
13888: information for the plot.
13889:
1.127 matthew 13890: =cut
13891:
13892: ############################################################
13893: ############################################################
1.134 matthew 13894: sub DrawBarGraph {
1.178 matthew 13895: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13896: #
13897: if (! defined($colors)) {
13898: $colors = ['#33ff00',
13899: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13900: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13901: ];
13902: }
1.228 matthew 13903: my $extra_settings = {};
13904: if (ref($Values[-1]) eq 'HASH') {
13905: $extra_settings = pop(@Values);
13906: }
1.127 matthew 13907: #
1.136 matthew 13908: my $identifier = &get_cgi_id();
13909: my $id = 'cgi.'.$identifier;
1.129 matthew 13910: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13911: return '';
13912: }
1.225 matthew 13913: #
13914: my @Labels;
13915: if (defined($labels)) {
13916: @Labels = @$labels;
13917: } else {
13918: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13919: push(@Labels,$i+1);
1.225 matthew 13920: }
13921: }
13922: #
1.129 matthew 13923: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13924: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13925: my %ValuesHash;
13926: my $NumSets=1;
13927: foreach my $array (@Values) {
13928: next if (! ref($array));
1.136 matthew 13929: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13930: join(',',@$array);
1.129 matthew 13931: }
1.127 matthew 13932: #
1.136 matthew 13933: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13934: if ($NumBars < 3) {
13935: $width = 120+$NumBars*32;
1.220 matthew 13936: $xskip = 1;
1.225 matthew 13937: $bar_width = 30;
13938: } elsif ($NumBars < 5) {
13939: $width = 120+$NumBars*20;
13940: $xskip = 1;
13941: $bar_width = 20;
1.220 matthew 13942: } elsif ($NumBars < 10) {
1.136 matthew 13943: $width = 120+$NumBars*15;
13944: $xskip = 1;
13945: $bar_width = 15;
13946: } elsif ($NumBars <= 25) {
13947: $width = 120+$NumBars*11;
13948: $xskip = 5;
13949: $bar_width = 8;
13950: } elsif ($NumBars <= 50) {
13951: $width = 120+$NumBars*8;
13952: $xskip = 5;
13953: $bar_width = 4;
13954: } else {
13955: $width = 120+$NumBars*8;
13956: $xskip = 5;
13957: $bar_width = 4;
13958: }
13959: #
1.137 matthew 13960: $Max = 1 if ($Max < 1);
13961: if ( int($Max) < $Max ) {
13962: $Max++;
13963: $Max = int($Max);
13964: }
1.127 matthew 13965: $Title = '' if (! defined($Title));
13966: $xlabel = '' if (! defined($xlabel));
13967: $ylabel = '' if (! defined($ylabel));
1.369 www 13968: $ValuesHash{$id.'.title'} = &escape($Title);
13969: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13970: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13971: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13972: $ValuesHash{$id.'.NumBars'} = $NumBars;
13973: $ValuesHash{$id.'.NumSets'} = $NumSets;
13974: $ValuesHash{$id.'.PlotType'} = 'bar';
13975: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13976: $ValuesHash{$id.'.height'} = $height;
13977: $ValuesHash{$id.'.width'} = $width;
13978: $ValuesHash{$id.'.xskip'} = $xskip;
13979: $ValuesHash{$id.'.bar_width'} = $bar_width;
13980: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13981: #
1.228 matthew 13982: # Deal with other parameters
13983: while (my ($key,$value) = each(%$extra_settings)) {
13984: $ValuesHash{$id.'.'.$key} = $value;
13985: }
13986: #
1.646 raeburn 13987: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13988: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13989: }
13990:
13991: ############################################################
13992: ############################################################
13993:
13994: =pod
13995:
1.648 raeburn 13996: =item * &DrawXYGraph()
1.137 matthew 13997:
1.138 matthew 13998: Facilitates the plotting of data in an XY graph.
13999: Puts plot definition data into the users environment in order for
14000: graph.png to plot it. Returns an <img> tag for the plot.
14001:
14002: Inputs:
14003:
14004: =over 4
14005:
14006: =item $Title: string, the title of the plot
14007:
14008: =item $xlabel: string, text describing the X-axis of the plot
14009:
14010: =item $ylabel: string, text describing the Y-axis of the plot
14011:
14012: =item $Max: scalar, the maximum Y value to use in the plot
14013: If $Max is < any data point, the graph will not be rendered.
14014:
14015: =item $colors: Array ref containing the hex color codes for the data to be
14016: plotted in. If undefined, default values will be used.
14017:
14018: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14019:
14020: =item $Ydata: Array ref containing Array refs.
1.185 www 14021: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14022:
14023: =item %Values: hash indicating or overriding any default values which are
14024: passed to graph.png.
14025: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14026:
14027: =back
14028:
14029: Returns:
14030:
14031: An <img> tag which references graph.png and the appropriate identifying
14032: information for the plot.
14033:
1.137 matthew 14034: =cut
14035:
14036: ############################################################
14037: ############################################################
14038: sub DrawXYGraph {
14039: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14040: #
14041: # Create the identifier for the graph
14042: my $identifier = &get_cgi_id();
14043: my $id = 'cgi.'.$identifier;
14044: #
14045: $Title = '' if (! defined($Title));
14046: $xlabel = '' if (! defined($xlabel));
14047: $ylabel = '' if (! defined($ylabel));
14048: my %ValuesHash =
14049: (
1.369 www 14050: $id.'.title' => &escape($Title),
14051: $id.'.xlabel' => &escape($xlabel),
14052: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14053: $id.'.y_max_value'=> $Max,
14054: $id.'.labels' => join(',',@$Xlabels),
14055: $id.'.PlotType' => 'XY',
14056: );
14057: #
14058: if (defined($colors) && ref($colors) eq 'ARRAY') {
14059: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14060: }
14061: #
14062: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14063: return '';
14064: }
14065: my $NumSets=1;
1.138 matthew 14066: foreach my $array (@{$Ydata}){
1.137 matthew 14067: next if (! ref($array));
14068: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14069: }
1.138 matthew 14070: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14071: #
14072: # Deal with other parameters
14073: while (my ($key,$value) = each(%Values)) {
14074: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14075: }
14076: #
1.646 raeburn 14077: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14078: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14079: }
14080:
14081: ############################################################
14082: ############################################################
14083:
14084: =pod
14085:
1.648 raeburn 14086: =item * &DrawXYYGraph()
1.138 matthew 14087:
14088: Facilitates the plotting of data in an XY graph with two Y axes.
14089: Puts plot definition data into the users environment in order for
14090: graph.png to plot it. Returns an <img> tag for the plot.
14091:
14092: Inputs:
14093:
14094: =over 4
14095:
14096: =item $Title: string, the title of the plot
14097:
14098: =item $xlabel: string, text describing the X-axis of the plot
14099:
14100: =item $ylabel: string, text describing the Y-axis of the plot
14101:
14102: =item $colors: Array ref containing the hex color codes for the data to be
14103: plotted in. If undefined, default values will be used.
14104:
14105: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14106:
14107: =item $Ydata1: The first data set
14108:
14109: =item $Min1: The minimum value of the left Y-axis
14110:
14111: =item $Max1: The maximum value of the left Y-axis
14112:
14113: =item $Ydata2: The second data set
14114:
14115: =item $Min2: The minimum value of the right Y-axis
14116:
14117: =item $Max2: The maximum value of the left Y-axis
14118:
14119: =item %Values: hash indicating or overriding any default values which are
14120: passed to graph.png.
14121: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14122:
14123: =back
14124:
14125: Returns:
14126:
14127: An <img> tag which references graph.png and the appropriate identifying
14128: information for the plot.
1.136 matthew 14129:
14130: =cut
14131:
14132: ############################################################
14133: ############################################################
1.137 matthew 14134: sub DrawXYYGraph {
14135: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14136: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14137: #
14138: # Create the identifier for the graph
14139: my $identifier = &get_cgi_id();
14140: my $id = 'cgi.'.$identifier;
14141: #
14142: $Title = '' if (! defined($Title));
14143: $xlabel = '' if (! defined($xlabel));
14144: $ylabel = '' if (! defined($ylabel));
14145: my %ValuesHash =
14146: (
1.369 www 14147: $id.'.title' => &escape($Title),
14148: $id.'.xlabel' => &escape($xlabel),
14149: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14150: $id.'.labels' => join(',',@$Xlabels),
14151: $id.'.PlotType' => 'XY',
14152: $id.'.NumSets' => 2,
1.137 matthew 14153: $id.'.two_axes' => 1,
14154: $id.'.y1_max_value' => $Max1,
14155: $id.'.y1_min_value' => $Min1,
14156: $id.'.y2_max_value' => $Max2,
14157: $id.'.y2_min_value' => $Min2,
1.136 matthew 14158: );
14159: #
1.137 matthew 14160: if (defined($colors) && ref($colors) eq 'ARRAY') {
14161: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14162: }
14163: #
14164: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14165: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14166: return '';
14167: }
14168: my $NumSets=1;
1.137 matthew 14169: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14170: next if (! ref($array));
14171: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14172: }
14173: #
14174: # Deal with other parameters
14175: while (my ($key,$value) = each(%Values)) {
14176: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14177: }
14178: #
1.646 raeburn 14179: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14180: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14181: }
14182:
14183: ############################################################
14184: ############################################################
14185:
14186: =pod
14187:
1.157 matthew 14188: =back
14189:
1.139 matthew 14190: =head1 Statistics helper routines?
14191:
14192: Bad place for them but what the hell.
14193:
1.157 matthew 14194: =over 4
14195:
1.648 raeburn 14196: =item * &chartlink()
1.139 matthew 14197:
14198: Returns a link to the chart for a specific student.
14199:
14200: Inputs:
14201:
14202: =over 4
14203:
14204: =item $linktext: The text of the link
14205:
14206: =item $sname: The students username
14207:
14208: =item $sdomain: The students domain
14209:
14210: =back
14211:
1.157 matthew 14212: =back
14213:
1.139 matthew 14214: =cut
14215:
14216: ############################################################
14217: ############################################################
14218: sub chartlink {
14219: my ($linktext, $sname, $sdomain) = @_;
14220: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14221: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14222: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14223: '">'.$linktext.'</a>';
1.153 matthew 14224: }
14225:
14226: #######################################################
14227: #######################################################
14228:
14229: =pod
14230:
14231: =head1 Course Environment Routines
1.157 matthew 14232:
14233: =over 4
1.153 matthew 14234:
1.648 raeburn 14235: =item * &restore_course_settings()
1.153 matthew 14236:
1.648 raeburn 14237: =item * &store_course_settings()
1.153 matthew 14238:
14239: Restores/Store indicated form parameters from the course environment.
14240: Will not overwrite existing values of the form parameters.
14241:
14242: Inputs:
14243: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14244:
14245: a hash ref describing the data to be stored. For example:
14246:
14247: %Save_Parameters = ('Status' => 'scalar',
14248: 'chartoutputmode' => 'scalar',
14249: 'chartoutputdata' => 'scalar',
14250: 'Section' => 'array',
1.373 raeburn 14251: 'Group' => 'array',
1.153 matthew 14252: 'StudentData' => 'array',
14253: 'Maps' => 'array');
14254:
14255: Returns: both routines return nothing
14256:
1.631 raeburn 14257: =back
14258:
1.153 matthew 14259: =cut
14260:
14261: #######################################################
14262: #######################################################
14263: sub store_course_settings {
1.496 albertel 14264: return &store_settings($env{'request.course.id'},@_);
14265: }
14266:
14267: sub store_settings {
1.153 matthew 14268: # save to the environment
14269: # appenv the same items, just to be safe
1.300 albertel 14270: my $udom = $env{'user.domain'};
14271: my $uname = $env{'user.name'};
1.496 albertel 14272: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14273: my %SaveHash;
14274: my %AppHash;
14275: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14276: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14277: my $envname = 'environment.'.$basename;
1.258 albertel 14278: if (exists($env{'form.'.$setting})) {
1.153 matthew 14279: # Save this value away
14280: if ($type eq 'scalar' &&
1.258 albertel 14281: (! exists($env{$envname}) ||
14282: $env{$envname} ne $env{'form.'.$setting})) {
14283: $SaveHash{$basename} = $env{'form.'.$setting};
14284: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14285: } elsif ($type eq 'array') {
14286: my $stored_form;
1.258 albertel 14287: if (ref($env{'form.'.$setting})) {
1.153 matthew 14288: $stored_form = join(',',
14289: map {
1.369 www 14290: &escape($_);
1.258 albertel 14291: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14292: } else {
14293: $stored_form =
1.369 www 14294: &escape($env{'form.'.$setting});
1.153 matthew 14295: }
14296: # Determine if the array contents are the same.
1.258 albertel 14297: if ($stored_form ne $env{$envname}) {
1.153 matthew 14298: $SaveHash{$basename} = $stored_form;
14299: $AppHash{$envname} = $stored_form;
14300: }
14301: }
14302: }
14303: }
14304: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14305: $udom,$uname);
1.153 matthew 14306: if ($put_result !~ /^(ok|delayed)/) {
14307: &Apache::lonnet::logthis('unable to save form parameters, '.
14308: 'got error:'.$put_result);
14309: }
14310: # Make sure these settings stick around in this session, too
1.646 raeburn 14311: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14312: return;
14313: }
14314:
14315: sub restore_course_settings {
1.499 albertel 14316: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14317: }
14318:
14319: sub restore_settings {
14320: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14321: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14322: next if (exists($env{'form.'.$setting}));
1.496 albertel 14323: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14324: '.'.$setting;
1.258 albertel 14325: if (exists($env{$envname})) {
1.153 matthew 14326: if ($type eq 'scalar') {
1.258 albertel 14327: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14328: } elsif ($type eq 'array') {
1.258 albertel 14329: $env{'form.'.$setting} = [
1.153 matthew 14330: map {
1.369 www 14331: &unescape($_);
1.258 albertel 14332: } split(',',$env{$envname})
1.153 matthew 14333: ];
14334: }
14335: }
14336: }
1.127 matthew 14337: }
14338:
1.618 raeburn 14339: #######################################################
14340: #######################################################
14341:
14342: =pod
14343:
14344: =head1 Domain E-mail Routines
14345:
14346: =over 4
14347:
1.648 raeburn 14348: =item * &build_recipient_list()
1.618 raeburn 14349:
1.1075.2.44 raeburn 14350: Build recipient lists for following types of e-mail:
1.766 raeburn 14351: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14352: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14353: module change checking, student/employee ID conflict checks, as
14354: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14355: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14356:
14357: Inputs:
1.1075.2.44 raeburn 14358: defmail (scalar - email address of default recipient),
14359: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14360: requestsmail, updatesmail, or idconflictsmail).
14361:
1.619 raeburn 14362: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14363:
14364: origmail (scalar - email address of recipient from loncapa.conf,
14365: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14366:
1.1075.2.139 raeburn 14367: $requname username of requester (if mailing type is helpdeskmail)
14368:
14369: $requdom domain of requester (if mailing type is helpdeskmail)
14370:
14371: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14372:
1.655 raeburn 14373: Returns: comma separated list of addresses to which to send e-mail.
14374:
14375: =back
1.618 raeburn 14376:
14377: =cut
14378:
14379: ############################################################
14380: ############################################################
14381: sub build_recipient_list {
1.1075.2.139 raeburn 14382: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14383: my @recipients;
1.1075.2.122 raeburn 14384: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14385: my %domconfig =
1.1075.2.122 raeburn 14386: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14387: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14388: if (exists($domconfig{'contacts'}{$mailing})) {
14389: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14390: my @contacts = ('adminemail','supportemail');
14391: foreach my $item (@contacts) {
14392: if ($domconfig{'contacts'}{$mailing}{$item}) {
14393: my $addr = $domconfig{'contacts'}{$item};
14394: if (!grep(/^\Q$addr\E$/,@recipients)) {
14395: push(@recipients,$addr);
14396: }
1.619 raeburn 14397: }
1.1075.2.122 raeburn 14398: }
14399: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14400: if ($mailing eq 'helpdeskmail') {
14401: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14402: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14403: my @ok_bccs;
14404: foreach my $bcc (@bccs) {
14405: $bcc =~ s/^\s+//g;
14406: $bcc =~ s/\s+$//g;
14407: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14408: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14409: push(@ok_bccs,$bcc);
14410: }
14411: }
14412: }
14413: if (@ok_bccs > 0) {
14414: $allbcc = join(', ',@ok_bccs);
14415: }
14416: }
14417: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14418: }
14419: }
1.766 raeburn 14420: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14421: $lastresort = $origmail;
1.618 raeburn 14422: }
1.1075.2.139 raeburn 14423: if ($mailing eq 'helpdeskmail') {
14424: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14425: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14426: my ($inststatus,$inststatus_checked);
14427: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14428: ($env{'user.domain'} ne 'public')) {
14429: $inststatus_checked = 1;
14430: $inststatus = $env{'environment.inststatus'};
14431: }
14432: unless ($inststatus_checked) {
14433: if (($requname ne '') && ($requdom ne '')) {
14434: if (($requname =~ /^$match_username$/) &&
14435: ($requdom =~ /^$match_domain$/) &&
14436: (&Apache::lonnet::domain($requdom))) {
14437: my $requhome = &Apache::lonnet::homeserver($requname,
14438: $requdom);
14439: unless ($requhome eq 'no_host') {
14440: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14441: $inststatus = $userenv{'inststatus'};
14442: $inststatus_checked = 1;
14443: }
14444: }
14445: }
14446: }
14447: unless ($inststatus_checked) {
14448: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14449: my %srch = (srchby => 'email',
14450: srchdomain => $defdom,
14451: srchterm => $reqemail,
14452: srchtype => 'exact');
14453: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14454: foreach my $uname (keys(%srch_results)) {
14455: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14456: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14457: $inststatus_checked = 1;
14458: last;
14459: }
14460: }
14461: unless ($inststatus_checked) {
14462: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14463: if ($dirsrchres eq 'ok') {
14464: foreach my $uname (keys(%srch_results)) {
14465: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14466: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14467: $inststatus_checked = 1;
14468: last;
14469: }
14470: }
14471: }
14472: }
14473: }
14474: }
14475: if ($inststatus ne '') {
14476: foreach my $status (split(/\:/,$inststatus)) {
14477: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14478: my @contacts = ('adminemail','supportemail');
14479: foreach my $item (@contacts) {
14480: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14481: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14482: if (!grep(/^\Q$addr\E$/,@recipients)) {
14483: push(@recipients,$addr);
14484: }
14485: }
14486: }
14487: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14488: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14489: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14490: my @ok_bccs;
14491: foreach my $bcc (@bccs) {
14492: $bcc =~ s/^\s+//g;
14493: $bcc =~ s/\s+$//g;
14494: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14495: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14496: push(@ok_bccs,$bcc);
14497: }
14498: }
14499: }
14500: if (@ok_bccs > 0) {
14501: $allbcc = join(', ',@ok_bccs);
14502: }
14503: }
14504: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14505: last;
14506: }
14507: }
14508: }
14509: }
14510: }
1.619 raeburn 14511: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14512: $lastresort = $origmail;
14513: }
1.1075.2.128 raeburn 14514: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14515: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14516: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14517: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14518: my %what = (
14519: perlvar => 1,
14520: );
14521: my $primary = &Apache::lonnet::domain($defdom,'primary');
14522: if ($primary) {
14523: my $gotaddr;
14524: my ($result,$returnhash) =
14525: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14526: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14527: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14528: $lastresort = $returnhash->{'lonSupportEMail'};
14529: $gotaddr = 1;
14530: }
14531: }
14532: unless ($gotaddr) {
14533: my $uintdom = &Apache::lonnet::internet_dom($primary);
14534: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14535: unless ($uintdom eq $intdom) {
14536: my %domconfig =
14537: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14538: if (ref($domconfig{'contacts'}) eq 'HASH') {
14539: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14540: my @contacts = ('adminemail','supportemail');
14541: foreach my $item (@contacts) {
14542: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14543: my $addr = $domconfig{'contacts'}{$item};
14544: if (!grep(/^\Q$addr\E$/,@recipients)) {
14545: push(@recipients,$addr);
14546: }
14547: }
14548: }
14549: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14550: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14551: }
14552: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14553: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14554: my @ok_bccs;
14555: foreach my $bcc (@bccs) {
14556: $bcc =~ s/^\s+//g;
14557: $bcc =~ s/\s+$//g;
14558: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14559: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14560: push(@ok_bccs,$bcc);
14561: }
14562: }
14563: }
14564: if (@ok_bccs > 0) {
14565: $allbcc = join(', ',@ok_bccs);
14566: }
14567: }
14568: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14569: }
14570: }
14571: }
14572: }
14573: }
14574: }
1.618 raeburn 14575: }
1.688 raeburn 14576: if (defined($defmail)) {
14577: if ($defmail ne '') {
14578: push(@recipients,$defmail);
14579: }
1.618 raeburn 14580: }
14581: if ($otheremails) {
1.619 raeburn 14582: my @others;
14583: if ($otheremails =~ /,/) {
14584: @others = split(/,/,$otheremails);
1.618 raeburn 14585: } else {
1.619 raeburn 14586: push(@others,$otheremails);
14587: }
14588: foreach my $addr (@others) {
14589: if (!grep(/^\Q$addr\E$/,@recipients)) {
14590: push(@recipients,$addr);
14591: }
1.618 raeburn 14592: }
14593: }
1.1075.2.128 raeburn 14594: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14595: if ((!@recipients) && ($lastresort ne '')) {
14596: push(@recipients,$lastresort);
14597: }
14598: } elsif ($lastresort ne '') {
14599: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14600: push(@recipients,$lastresort);
14601: }
14602: }
14603: my $recipientlist = join(',',@recipients);
14604: if (wantarray) {
14605: return ($recipientlist,$allbcc,$addtext);
14606: } else {
14607: return $recipientlist;
14608: }
1.618 raeburn 14609: }
14610:
1.127 matthew 14611: ############################################################
14612: ############################################################
1.154 albertel 14613:
1.655 raeburn 14614: =pod
14615:
14616: =head1 Course Catalog Routines
14617:
14618: =over 4
14619:
14620: =item * &gather_categories()
14621:
14622: Converts category definitions - keys of categories hash stored in
14623: coursecategories in configuration.db on the primary library server in a
14624: domain - to an array. Also generates javascript and idx hash used to
14625: generate Domain Coordinator interface for editing Course Categories.
14626:
14627: Inputs:
1.663 raeburn 14628:
1.655 raeburn 14629: categories (reference to hash of category definitions).
1.663 raeburn 14630:
1.655 raeburn 14631: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14632: categories and subcategories).
1.663 raeburn 14633:
1.655 raeburn 14634: idx (reference to hash of counters used in Domain Coordinator interface for
14635: editing Course Categories).
1.663 raeburn 14636:
1.655 raeburn 14637: jsarray (reference to array of categories used to create Javascript arrays for
14638: Domain Coordinator interface for editing Course Categories).
14639:
14640: Returns: nothing
14641:
14642: Side effects: populates cats, idx and jsarray.
14643:
14644: =cut
14645:
14646: sub gather_categories {
14647: my ($categories,$cats,$idx,$jsarray) = @_;
14648: my %counters;
14649: my $num = 0;
14650: foreach my $item (keys(%{$categories})) {
14651: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14652: if ($container eq '' && $depth == 0) {
14653: $cats->[$depth][$categories->{$item}] = $cat;
14654: } else {
14655: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14656: }
14657: my ($escitem,$tail) = split(/:/,$item,2);
14658: if ($counters{$tail} eq '') {
14659: $counters{$tail} = $num;
14660: $num ++;
14661: }
14662: if (ref($idx) eq 'HASH') {
14663: $idx->{$item} = $counters{$tail};
14664: }
14665: if (ref($jsarray) eq 'ARRAY') {
14666: push(@{$jsarray->[$counters{$tail}]},$item);
14667: }
14668: }
14669: return;
14670: }
14671:
14672: =pod
14673:
14674: =item * &extract_categories()
14675:
14676: Used to generate breadcrumb trails for course categories.
14677:
14678: Inputs:
1.663 raeburn 14679:
1.655 raeburn 14680: categories (reference to hash of category definitions).
1.663 raeburn 14681:
1.655 raeburn 14682: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14683: categories and subcategories).
1.663 raeburn 14684:
1.655 raeburn 14685: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14686:
1.655 raeburn 14687: allitems (reference to hash - key is category key
14688: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14689:
1.655 raeburn 14690: idx (reference to hash of counters used in Domain Coordinator interface for
14691: editing Course Categories).
1.663 raeburn 14692:
1.655 raeburn 14693: jsarray (reference to array of categories used to create Javascript arrays for
14694: Domain Coordinator interface for editing Course Categories).
14695:
1.665 raeburn 14696: subcats (reference to hash of arrays containing all subcategories within each
14697: category, -recursive)
14698:
1.1075.2.132 raeburn 14699: maxd (reference to hash used to hold max depth for all top-level categories).
14700:
1.655 raeburn 14701: Returns: nothing
14702:
14703: Side effects: populates trails and allitems hash references.
14704:
14705: =cut
14706:
14707: sub extract_categories {
1.1075.2.132 raeburn 14708: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14709: if (ref($categories) eq 'HASH') {
14710: &gather_categories($categories,$cats,$idx,$jsarray);
14711: if (ref($cats->[0]) eq 'ARRAY') {
14712: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14713: my $name = $cats->[0][$i];
14714: my $item = &escape($name).'::0';
14715: my $trailstr;
14716: if ($name eq 'instcode') {
14717: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14718: } elsif ($name eq 'communities') {
14719: $trailstr = &mt('Communities');
1.655 raeburn 14720: } else {
14721: $trailstr = $name;
14722: }
14723: if ($allitems->{$item} eq '') {
14724: push(@{$trails},$trailstr);
14725: $allitems->{$item} = scalar(@{$trails})-1;
14726: }
14727: my @parents = ($name);
14728: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14729: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14730: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14731: if (ref($subcats) eq 'HASH') {
14732: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14733: }
1.1075.2.132 raeburn 14734: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14735: }
14736: } else {
14737: if (ref($subcats) eq 'HASH') {
14738: $subcats->{$item} = [];
1.655 raeburn 14739: }
1.1075.2.132 raeburn 14740: if (ref($maxd) eq 'HASH') {
14741: $maxd->{$name} = 1;
14742: }
1.655 raeburn 14743: }
14744: }
14745: }
14746: }
14747: return;
14748: }
14749:
14750: =pod
14751:
1.1075.2.56 raeburn 14752: =item * &recurse_categories()
1.655 raeburn 14753:
14754: Recursively used to generate breadcrumb trails for course categories.
14755:
14756: Inputs:
1.663 raeburn 14757:
1.655 raeburn 14758: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14759: categories and subcategories).
1.663 raeburn 14760:
1.655 raeburn 14761: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14762:
14763: category (current course category, for which breadcrumb trail is being generated).
14764:
14765: trails (reference to array of breadcrumb trails for each category).
14766:
1.655 raeburn 14767: allitems (reference to hash - key is category key
14768: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14769:
1.655 raeburn 14770: parents (array containing containers directories for current category,
14771: back to top level).
14772:
14773: Returns: nothing
14774:
14775: Side effects: populates trails and allitems hash references
14776:
14777: =cut
14778:
14779: sub recurse_categories {
1.1075.2.132 raeburn 14780: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14781: my $shallower = $depth - 1;
14782: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14783: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14784: my $name = $cats->[$depth]{$category}[$k];
14785: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14786: my $trailstr = join(' -> ',(@{$parents},$category));
14787: if ($allitems->{$item} eq '') {
14788: push(@{$trails},$trailstr);
14789: $allitems->{$item} = scalar(@{$trails})-1;
14790: }
14791: my $deeper = $depth+1;
14792: push(@{$parents},$category);
1.665 raeburn 14793: if (ref($subcats) eq 'HASH') {
14794: my $subcat = &escape($name).':'.$category.':'.$depth;
14795: for (my $j=@{$parents}; $j>=0; $j--) {
14796: my $higher;
14797: if ($j > 0) {
14798: $higher = &escape($parents->[$j]).':'.
14799: &escape($parents->[$j-1]).':'.$j;
14800: } else {
14801: $higher = &escape($parents->[$j]).'::'.$j;
14802: }
14803: push(@{$subcats->{$higher}},$subcat);
14804: }
14805: }
14806: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14807: $subcats,$maxd);
1.655 raeburn 14808: pop(@{$parents});
14809: }
14810: } else {
14811: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14812: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14813: if ($allitems->{$item} eq '') {
14814: push(@{$trails},$trailstr);
14815: $allitems->{$item} = scalar(@{$trails})-1;
14816: }
1.1075.2.132 raeburn 14817: if (ref($maxd) eq 'HASH') {
14818: if ($depth > $maxd->{$parents->[0]}) {
14819: $maxd->{$parents->[0]} = $depth;
14820: }
14821: }
1.655 raeburn 14822: }
14823: return;
14824: }
14825:
1.663 raeburn 14826: =pod
14827:
1.1075.2.56 raeburn 14828: =item * &assign_categories_table()
1.663 raeburn 14829:
14830: Create a datatable for display of hierarchical categories in a domain,
14831: with checkboxes to allow a course to be categorized.
14832:
14833: Inputs:
14834:
14835: cathash - reference to hash of categories defined for the domain (from
14836: configuration.db)
14837:
14838: currcat - scalar with an & separated list of categories assigned to a course.
14839:
1.919 raeburn 14840: type - scalar contains course type (Course or Community).
14841:
1.1075.2.117 raeburn 14842: disabled - scalar (optional) contains disabled="disabled" if input elements are
14843: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14844:
1.663 raeburn 14845: Returns: $output (markup to be displayed)
14846:
14847: =cut
14848:
14849: sub assign_categories_table {
1.1075.2.117 raeburn 14850: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14851: my $output;
14852: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14853: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14854: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14855: $maxdepth = scalar(@cats);
14856: if (@cats > 0) {
14857: my $itemcount = 0;
14858: if (ref($cats[0]) eq 'ARRAY') {
14859: my @currcategories;
14860: if ($currcat ne '') {
14861: @currcategories = split('&',$currcat);
14862: }
1.919 raeburn 14863: my $table;
1.663 raeburn 14864: for (my $i=0; $i<@{$cats[0]}; $i++) {
14865: my $parent = $cats[0][$i];
1.919 raeburn 14866: next if ($parent eq 'instcode');
14867: if ($type eq 'Community') {
14868: next unless ($parent eq 'communities');
14869: } else {
14870: next if ($parent eq 'communities');
14871: }
1.663 raeburn 14872: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14873: my $item = &escape($parent).'::0';
14874: my $checked = '';
14875: if (@currcategories > 0) {
14876: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14877: $checked = ' checked="checked"';
1.663 raeburn 14878: }
14879: }
1.919 raeburn 14880: my $parent_title = $parent;
14881: if ($parent eq 'communities') {
14882: $parent_title = &mt('Communities');
14883: }
14884: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14885: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14886: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14887: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14888: my $depth = 1;
14889: push(@path,$parent);
1.1075.2.117 raeburn 14890: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14891: pop(@path);
1.919 raeburn 14892: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14893: $itemcount ++;
14894: }
1.919 raeburn 14895: if ($itemcount) {
14896: $output = &Apache::loncommon::start_data_table().
14897: $table.
14898: &Apache::loncommon::end_data_table();
14899: }
1.663 raeburn 14900: }
14901: }
14902: }
14903: return $output;
14904: }
14905:
14906: =pod
14907:
1.1075.2.56 raeburn 14908: =item * &assign_category_rows()
1.663 raeburn 14909:
14910: Create a datatable row for display of nested categories in a domain,
14911: with checkboxes to allow a course to be categorized,called recursively.
14912:
14913: Inputs:
14914:
14915: itemcount - track row number for alternating colors
14916:
14917: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14918: categories and subcategories.
14919:
14920: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14921:
14922: parent - parent of current category item
14923:
14924: path - Array containing all categories back up through the hierarchy from the
14925: current category to the top level.
14926:
14927: currcategories - reference to array of current categories assigned to the course
14928:
1.1075.2.117 raeburn 14929: disabled - scalar (optional) contains disabled="disabled" if input elements are
14930: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14931:
1.663 raeburn 14932: Returns: $output (markup to be displayed).
14933:
14934: =cut
14935:
14936: sub assign_category_rows {
1.1075.2.117 raeburn 14937: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14938: my ($text,$name,$item,$chgstr);
14939: if (ref($cats) eq 'ARRAY') {
14940: my $maxdepth = scalar(@{$cats});
14941: if (ref($cats->[$depth]) eq 'HASH') {
14942: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14943: my $numchildren = @{$cats->[$depth]{$parent}};
14944: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14945: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14946: for (my $j=0; $j<$numchildren; $j++) {
14947: $name = $cats->[$depth]{$parent}[$j];
14948: $item = &escape($name).':'.&escape($parent).':'.$depth;
14949: my $deeper = $depth+1;
14950: my $checked = '';
14951: if (ref($currcategories) eq 'ARRAY') {
14952: if (@{$currcategories} > 0) {
14953: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14954: $checked = ' checked="checked"';
1.663 raeburn 14955: }
14956: }
14957: }
1.664 raeburn 14958: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14959: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14960: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14961: '<input type="hidden" name="catname" value="'.$name.'" />'.
14962: '</td><td>';
1.663 raeburn 14963: if (ref($path) eq 'ARRAY') {
14964: push(@{$path},$name);
1.1075.2.117 raeburn 14965: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14966: pop(@{$path});
14967: }
14968: $text .= '</td></tr>';
14969: }
14970: $text .= '</table></td>';
14971: }
14972: }
14973: }
14974: return $text;
14975: }
14976:
1.1075.2.69 raeburn 14977: =pod
14978:
14979: =back
14980:
14981: =cut
14982:
1.655 raeburn 14983: ############################################################
14984: ############################################################
14985:
14986:
1.443 albertel 14987: sub commit_customrole {
1.664 raeburn 14988: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14989: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14990: ($start?', '.&mt('starting').' '.localtime($start):'').
14991: ($end?', ending '.localtime($end):'').': <b>'.
14992: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14993: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14994: '</b><br />';
14995: return $output;
14996: }
14997:
14998: sub commit_standardrole {
1.1075.2.31 raeburn 14999: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15000: my ($output,$logmsg,$linefeed);
15001: if ($context eq 'auto') {
15002: $linefeed = "\n";
15003: } else {
15004: $linefeed = "<br />\n";
15005: }
1.443 albertel 15006: if ($three eq 'st') {
1.541 raeburn 15007: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15008: $one,$two,$sec,$context,$credits);
1.541 raeburn 15009: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15010: ($result eq 'unknown_course') || ($result eq 'refused')) {
15011: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15012: } else {
1.541 raeburn 15013: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15014: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15015: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15016: if ($context eq 'auto') {
15017: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15018: } else {
15019: $output .= '<b>'.$result.'</b>'.$linefeed.
15020: &mt('Add to classlist').': <b>ok</b>';
15021: }
15022: $output .= $linefeed;
1.443 albertel 15023: }
15024: } else {
15025: $output = &mt('Assigning').' '.$three.' in '.$url.
15026: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15027: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15028: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15029: if ($context eq 'auto') {
15030: $output .= $result.$linefeed;
15031: } else {
15032: $output .= '<b>'.$result.'</b>'.$linefeed;
15033: }
1.443 albertel 15034: }
15035: return $output;
15036: }
15037:
15038: sub commit_studentrole {
1.1075.2.31 raeburn 15039: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15040: $credits) = @_;
1.626 raeburn 15041: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15042: if ($context eq 'auto') {
15043: $linefeed = "\n";
15044: } else {
15045: $linefeed = '<br />'."\n";
15046: }
1.443 albertel 15047: if (defined($one) && defined($two)) {
15048: my $cid=$one.'_'.$two;
15049: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15050: my $secchange = 0;
15051: my $expire_role_result;
15052: my $modify_section_result;
1.628 raeburn 15053: if ($oldsec ne '-1') {
15054: if ($oldsec ne $sec) {
1.443 albertel 15055: $secchange = 1;
1.628 raeburn 15056: my $now = time;
1.443 albertel 15057: my $uurl='/'.$cid;
15058: $uurl=~s/\_/\//g;
15059: if ($oldsec) {
15060: $uurl.='/'.$oldsec;
15061: }
1.626 raeburn 15062: $oldsecurl = $uurl;
1.628 raeburn 15063: $expire_role_result =
1.652 raeburn 15064: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15065: if ($env{'request.course.sec'} ne '') {
15066: if ($expire_role_result eq 'refused') {
15067: my @roles = ('st');
15068: my @statuses = ('previous');
15069: my @roledoms = ($one);
15070: my $withsec = 1;
15071: my %roleshash =
15072: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15073: \@statuses,\@roles,\@roledoms,$withsec);
15074: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15075: my ($oldstart,$oldend) =
15076: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15077: if ($oldend > 0 && $oldend <= $now) {
15078: $expire_role_result = 'ok';
15079: }
15080: }
15081: }
15082: }
1.443 albertel 15083: $result = $expire_role_result;
15084: }
15085: }
15086: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15087: $modify_section_result =
15088: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15089: undef,undef,undef,$sec,
15090: $end,$start,'','',$cid,
15091: '',$context,$credits);
1.443 albertel 15092: if ($modify_section_result =~ /^ok/) {
15093: if ($secchange == 1) {
1.628 raeburn 15094: if ($sec eq '') {
15095: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15096: } else {
15097: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15098: }
1.443 albertel 15099: } elsif ($oldsec eq '-1') {
1.628 raeburn 15100: if ($sec eq '') {
15101: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15102: } else {
15103: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15104: }
1.443 albertel 15105: } else {
1.628 raeburn 15106: if ($sec eq '') {
15107: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15108: } else {
15109: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15110: }
1.443 albertel 15111: }
15112: } else {
1.628 raeburn 15113: if ($secchange) {
15114: $$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;
15115: } else {
15116: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15117: }
1.443 albertel 15118: }
15119: $result = $modify_section_result;
15120: } elsif ($secchange == 1) {
1.628 raeburn 15121: if ($oldsec eq '') {
1.1075.2.20 raeburn 15122: $$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 15123: } else {
15124: $$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;
15125: }
1.626 raeburn 15126: if ($expire_role_result eq 'refused') {
15127: my $newsecurl = '/'.$cid;
15128: $newsecurl =~ s/\_/\//g;
15129: if ($sec ne '') {
15130: $newsecurl.='/'.$sec;
15131: }
15132: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15133: if ($sec eq '') {
15134: $$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;
15135: } else {
15136: $$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;
15137: }
15138: }
15139: }
1.443 albertel 15140: }
15141: } else {
1.626 raeburn 15142: $$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 15143: $result = "error: incomplete course id\n";
15144: }
15145: return $result;
15146: }
15147:
1.1075.2.25 raeburn 15148: sub show_role_extent {
15149: my ($scope,$context,$role) = @_;
15150: $scope =~ s{^/}{};
15151: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15152: push(@courseroles,'co');
15153: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15154: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15155: $scope =~ s{/}{_};
15156: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15157: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15158: my ($audom,$auname) = split(/\//,$scope);
15159: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15160: &Apache::loncommon::plainname($auname,$audom).'</span>');
15161: } else {
15162: $scope =~ s{/$}{};
15163: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15164: &Apache::lonnet::domain($scope,'description').'</span>');
15165: }
15166: }
15167:
1.443 albertel 15168: ############################################################
15169: ############################################################
15170:
1.566 albertel 15171: sub check_clone {
1.578 raeburn 15172: my ($args,$linefeed) = @_;
1.566 albertel 15173: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15174: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15175: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.141. .5(raebu 15176:20): my $clonetitle;
15177:20): my @clonemsg;
1.566 albertel 15178: my $can_clone = 0;
1.944 raeburn 15179: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15180: if ($lctype ne 'community') {
15181: $lctype = 'course';
15182: }
1.566 albertel 15183: if ($clonehome eq 'no_host') {
1.944 raeburn 15184: if ($args->{'crstype'} eq 'Community') {
1.1075.2.141. .5(raebu 15185:20): push(@clonemsg,({
15186:20): mt => 'No new community created.',
15187:20): args => [],
15188:20): },
15189:20): {
15190:20): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15191:20): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15192:20): }));
1.908 raeburn 15193: } else {
1.1075.2.141. .5(raebu 15194:20): push(@clonemsg,({
15195:20): mt => 'No new course created.',
15196:20): args => [],
15197:20): },
15198:20): {
15199:20): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15200:20): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15201:20): }));
15202:20): }
1.566 albertel 15203: } else {
15204: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.141. .5(raebu 15205:20): $clonetitle = $clonedesc{'description'};
1.944 raeburn 15206: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15207: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.141. .5(raebu 15208:20): push(@clonemsg,({
15209:20): mt => 'No new community created.',
15210:20): args => [],
15211:20): },
15212:20): {
15213:20): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
15214:20): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15215:20): }));
15216:20): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 15217: }
15218: }
1.1075.2.119 raeburn 15219: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15220: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15221: $can_clone = 1;
15222: } else {
1.1075.2.95 raeburn 15223: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15224: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15225: if ($clonehash{'cloners'} eq '') {
15226: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15227: if ($domdefs{'canclone'}) {
15228: unless ($domdefs{'canclone'} eq 'none') {
15229: if ($domdefs{'canclone'} eq 'domain') {
15230: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15231: $can_clone = 1;
15232: }
15233: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15234: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15235: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15236: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15237: $can_clone = 1;
15238: }
15239: }
15240: }
1.908 raeburn 15241: }
1.1075.2.95 raeburn 15242: } else {
15243: my @cloners = split(/,/,$clonehash{'cloners'});
15244: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15245: $can_clone = 1;
1.1075.2.95 raeburn 15246: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15247: $can_clone = 1;
1.1075.2.96 raeburn 15248: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15249: $can_clone = 1;
1.1075.2.95 raeburn 15250: }
15251: unless ($can_clone) {
1.1075.2.96 raeburn 15252: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15253: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15254: my (%gotdomdefaults,%gotcodedefaults);
15255: foreach my $cloner (@cloners) {
15256: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15257: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15258: my (%codedefaults,@code_order);
15259: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15260: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15261: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15262: }
15263: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15264: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15265: }
15266: } else {
15267: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15268: \%codedefaults,
15269: \@code_order);
15270: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15271: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15272: }
15273: if (@code_order > 0) {
15274: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15275: $cloner,$clonehash{'internal.coursecode'},
15276: $args->{'crscode'})) {
15277: $can_clone = 1;
15278: last;
15279: }
15280: }
15281: }
15282: }
15283: }
1.1075.2.96 raeburn 15284: }
15285: }
15286: unless ($can_clone) {
15287: my $ccrole = 'cc';
15288: if ($args->{'crstype'} eq 'Community') {
15289: $ccrole = 'co';
15290: }
15291: my %roleshash =
15292: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15293: $args->{'ccdomain'},
15294: 'userroles',['active'],[$ccrole],
15295: [$args->{'clonedomain'}]);
15296: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15297: $can_clone = 1;
15298: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15299: $args->{'ccuname'},$args->{'ccdomain'})) {
15300: $can_clone = 1;
1.1075.2.95 raeburn 15301: }
15302: }
15303: unless ($can_clone) {
15304: if ($args->{'crstype'} eq 'Community') {
1.1075.2.141. .5(raebu 15305:20): push(@clonemsg,({
15306:20): mt => 'No new community created.',
15307:20): args => [],
15308:20): },
15309:20): {
15310:20): 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]).',
15311:20): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15312:20): }));
1.1075.2.95 raeburn 15313: } else {
1.1075.2.141. .5(raebu 15314:20): push(@clonemsg,({
15315:20): mt => 'No new course created.',
15316:20): args => [],
15317:20): },
15318:20): {
15319:20): 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]).',
15320:20): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15321:20): }));
15322:20): }
1.566 albertel 15323: }
1.578 raeburn 15324: }
1.566 albertel 15325: }
1.1075.2.141. .5(raebu 15326:20): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15327: }
15328:
1.444 albertel 15329: sub construct_course {
1.1075.2.119 raeburn 15330: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.141. .5(raebu 15331:20): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
15332:20): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 15333: my $linefeed = '<br />'."\n";
15334: if ($context eq 'auto') {
15335: $linefeed = "\n";
15336: }
1.566 albertel 15337:
15338: #
15339: # Are we cloning?
15340: #
1.1075.2.141. .5(raebu 15341:20): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15342: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.141. .5(raebu 15343:20): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 15344: if (!$can_clone) {
1.1075.2.141. .5(raebu 15345:20): return (0,$outcome,$clonemsgref);
1.566 albertel 15346: }
15347: }
15348:
1.444 albertel 15349: #
15350: # Open course
15351: #
15352: my $crstype = lc($args->{'crstype'});
15353: my %cenv=();
15354: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15355: $args->{'cdescr'},
15356: $args->{'curl'},
15357: $args->{'course_home'},
15358: $args->{'nonstandard'},
15359: $args->{'crscode'},
15360: $args->{'ccuname'}.':'.
15361: $args->{'ccdomain'},
1.882 raeburn 15362: $args->{'crstype'},
1.1075.2.141. .5(raebu 15363:20): $cnum,$context,$category,
15364:20): $callercontext);
1.444 albertel 15365:
15366: # Note: The testing routines depend on this being output; see
15367: # Utils::Course. This needs to at least be output as a comment
15368: # if anyone ever decides to not show this, and Utils::Course::new
15369: # will need to be suitably modified.
1.1075.2.141. .5(raebu 15370:20): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15371:20): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15372:20): } else {
15373:20): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15374:20): }
1.943 raeburn 15375: if ($$courseid =~ /^error:/) {
1.1075.2.141. .5(raebu 15376:20): return (0,$outcome,$clonemsgref);
1.943 raeburn 15377: }
15378:
1.444 albertel 15379: #
15380: # Check if created correctly
15381: #
1.479 albertel 15382: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15383: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15384: if ($crsuhome eq 'no_host') {
1.1075.2.141. .5(raebu 15385:20): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15386:20): $outcome .= &mt_user($user_lh,
15387:20): 'Course creation failed, unrecognized course home server.');
15388:20): } else {
15389:20): $outcome .= &mt('Course creation failed, unrecognized course home server.');
15390:20): }
15391:20): $outcome .= $linefeed;
15392:20): return (0,$outcome,$clonemsgref);
1.943 raeburn 15393: }
1.541 raeburn 15394: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15395:
1.444 albertel 15396: #
1.566 albertel 15397: # Do the cloning
15398: #
1.1075.2.141. .5(raebu 15399:20): my @clonemsg;
1.566 albertel 15400: if ($can_clone && $cloneid) {
1.1075.2.141. .5(raebu 15401:20): push(@clonemsg,
15402:20): {
15403:20): mt => 'Created [_1] by cloning from [_2]',
15404:20): args => [$crstype,$clonetitle],
15405:20): });
1.566 albertel 15406: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15407: # Copy all files
1.1075.2.141. .5(raebu 15408:20): my @info =
15409:20): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
15410:20): $args->{'dateshift'},$args->{'crscode'},
15411:20): $args->{'ccuname'}.':'.$args->{'ccdomain'},
15412:20): $args->{'tinyurls'});
15413:20): if (@info) {
15414:20): push(@clonemsg,@info);
15415:20): }
1.444 albertel 15416: # Restore URL
1.566 albertel 15417: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15418: # Restore title
1.566 albertel 15419: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15420: # Restore creation date, creator and creation context.
15421: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15422: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15423: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15424: # Mark as cloned
1.566 albertel 15425: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15426: # Need to clone grading mode
15427: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15428: $cenv{'grading'}=$newenv{'grading'};
15429: # Do not clone these environment entries
15430: &Apache::lonnet::del('environment',
15431: ['default_enrollment_start_date',
15432: 'default_enrollment_end_date',
15433: 'question.email',
15434: 'policy.email',
15435: 'comment.email',
15436: 'pch.users.denied',
1.725 raeburn 15437: 'plc.users.denied',
15438: 'hidefromcat',
1.1075.2.36 raeburn 15439: 'checkforpriv',
1.1075.2.59 raeburn 15440: 'categories',
15441: 'internal.uniquecode'],
1.638 www 15442: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15443: if ($args->{'textbook'}) {
15444: $cenv{'internal.textbook'} = $args->{'textbook'};
15445: }
1.444 albertel 15446: }
1.566 albertel 15447:
1.444 albertel 15448: #
15449: # Set environment (will override cloned, if existing)
15450: #
15451: my @sections = ();
15452: my @xlists = ();
15453: if ($args->{'crstype'}) {
15454: $cenv{'type'}=$args->{'crstype'};
15455: }
15456: if ($args->{'crsid'}) {
15457: $cenv{'courseid'}=$args->{'crsid'};
15458: }
15459: if ($args->{'crscode'}) {
15460: $cenv{'internal.coursecode'}=$args->{'crscode'};
15461: }
15462: if ($args->{'crsquota'} ne '') {
15463: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15464: } else {
15465: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15466: }
15467: if ($args->{'ccuname'}) {
15468: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15469: ':'.$args->{'ccdomain'};
15470: } else {
15471: $cenv{'internal.courseowner'} = $args->{'curruser'};
15472: }
1.1075.2.31 raeburn 15473: if ($args->{'defaultcredits'}) {
15474: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15475: }
1.444 albertel 15476: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15477: if ($args->{'crssections'}) {
15478: $cenv{'internal.sectionnums'} = '';
15479: if ($args->{'crssections'} =~ m/,/) {
15480: @sections = split/,/,$args->{'crssections'};
15481: } else {
15482: $sections[0] = $args->{'crssections'};
15483: }
15484: if (@sections > 0) {
15485: foreach my $item (@sections) {
15486: my ($sec,$gp) = split/:/,$item;
15487: my $class = $args->{'crscode'}.$sec;
15488: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15489: $cenv{'internal.sectionnums'} .= $item.',';
15490: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15491: push(@badclasses,$class);
1.444 albertel 15492: }
15493: }
15494: $cenv{'internal.sectionnums'} =~ s/,$//;
15495: }
15496: }
15497: # do not hide course coordinator from staff listing,
15498: # even if privileged
15499: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15500: # add course coordinator's domain to domains to check for privileged users
15501: # if different to course domain
15502: if ($$crsudom ne $args->{'ccdomain'}) {
15503: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15504: }
1.444 albertel 15505: # add crosslistings
15506: if ($args->{'crsxlist'}) {
15507: $cenv{'internal.crosslistings'}='';
15508: if ($args->{'crsxlist'} =~ m/,/) {
15509: @xlists = split/,/,$args->{'crsxlist'};
15510: } else {
15511: $xlists[0] = $args->{'crsxlist'};
15512: }
15513: if (@xlists > 0) {
15514: foreach my $item (@xlists) {
15515: my ($xl,$gp) = split/:/,$item;
15516: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15517: $cenv{'internal.crosslistings'} .= $item.',';
15518: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15519: push(@badclasses,$xl);
1.444 albertel 15520: }
15521: }
15522: $cenv{'internal.crosslistings'} =~ s/,$//;
15523: }
15524: }
15525: if ($args->{'autoadds'}) {
15526: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15527: }
15528: if ($args->{'autodrops'}) {
15529: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15530: }
15531: # check for notification of enrollment changes
15532: my @notified = ();
15533: if ($args->{'notify_owner'}) {
15534: if ($args->{'ccuname'} ne '') {
15535: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15536: }
15537: }
15538: if ($args->{'notify_dc'}) {
15539: if ($uname ne '') {
1.630 raeburn 15540: push(@notified,$uname.':'.$udom);
1.444 albertel 15541: }
15542: }
15543: if (@notified > 0) {
15544: my $notifylist;
15545: if (@notified > 1) {
15546: $notifylist = join(',',@notified);
15547: } else {
15548: $notifylist = $notified[0];
15549: }
15550: $cenv{'internal.notifylist'} = $notifylist;
15551: }
15552: if (@badclasses > 0) {
15553: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15554: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15555: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15556: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15557: );
1.1075.2.119 raeburn 15558: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15559: &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 15560: if ($context eq 'auto') {
15561: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15562: } else {
1.566 albertel 15563: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15564: }
15565: foreach my $item (@badclasses) {
1.541 raeburn 15566: if ($context eq 'auto') {
1.1075.2.119 raeburn 15567: $outcome .= " - $item\n";
1.541 raeburn 15568: } else {
1.1075.2.119 raeburn 15569: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15570: }
1.1075.2.119 raeburn 15571: }
15572: if ($context eq 'auto') {
15573: $outcome .= $linefeed;
15574: } else {
15575: $outcome .= "</ul><br /><br /></div>\n";
15576: }
1.444 albertel 15577: }
15578: if ($args->{'no_end_date'}) {
15579: $args->{'endaccess'} = 0;
15580: }
15581: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15582: $cenv{'internal.autoend'}=$args->{'enrollend'};
15583: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15584: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15585: if ($args->{'showphotos'}) {
15586: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15587: }
15588: $cenv{'internal.authtype'} = $args->{'authtype'};
15589: $cenv{'internal.autharg'} = $args->{'autharg'};
15590: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15591: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15592: 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');
15593: if ($context eq 'auto') {
15594: $outcome .= $krb_msg;
15595: } else {
1.566 albertel 15596: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15597: }
15598: $outcome .= $linefeed;
1.444 albertel 15599: }
15600: }
15601: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15602: if ($args->{'setpolicy'}) {
15603: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15604: }
15605: if ($args->{'setcontent'}) {
15606: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15607: }
1.1075.2.110 raeburn 15608: if ($args->{'setcomment'}) {
15609: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15610: }
1.444 albertel 15611: }
15612: if ($args->{'reshome'}) {
15613: $cenv{'reshome'}=$args->{'reshome'}.'/';
15614: $cenv{'reshome'}=~s/\/+$/\//;
15615: }
15616: #
15617: # course has keyed access
15618: #
15619: if ($args->{'setkeys'}) {
15620: $cenv{'keyaccess'}='yes';
15621: }
15622: # if specified, key authority is not course, but user
15623: # only active if keyaccess is yes
15624: if ($args->{'keyauth'}) {
1.487 albertel 15625: my ($user,$domain) = split(':',$args->{'keyauth'});
15626: $user = &LONCAPA::clean_username($user);
15627: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15628: if ($user ne '' && $domain ne '') {
1.487 albertel 15629: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15630: }
15631: }
15632:
1.1075.2.59 raeburn 15633: #
15634: # generate and store uniquecode (available to course requester), if course should have one.
15635: #
15636: if ($args->{'uniquecode'}) {
15637: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15638: if ($code) {
15639: $cenv{'internal.uniquecode'} = $code;
15640: my %crsinfo =
15641: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15642: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15643: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15644: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15645: }
15646: if (ref($coderef)) {
15647: $$coderef = $code;
15648: }
15649: }
15650: }
15651:
1.444 albertel 15652: if ($args->{'disresdis'}) {
15653: $cenv{'pch.roles.denied'}='st';
15654: }
15655: if ($args->{'disablechat'}) {
15656: $cenv{'plc.roles.denied'}='st';
15657: }
15658:
15659: # Record we've not yet viewed the Course Initialization Helper for this
15660: # course
15661: $cenv{'course.helper.not.run'} = 1;
15662: #
15663: # Use new Randomseed
15664: #
15665: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15666: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15667: #
15668: # The encryption code and receipt prefix for this course
15669: #
15670: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15671: $cenv{'internal.encpref'}=100+int(9*rand(99));
15672: #
15673: # By default, use standard grading
15674: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15675:
1.541 raeburn 15676: $outcome .= $linefeed.&mt('Setting environment').': '.
15677: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15678: #
15679: # Open all assignments
15680: #
15681: if ($args->{'openall'}) {
1.1075.2.141. .4(raebu 15682:20): my $opendate = time;
15683:20): if ($args->{'openallfrom'} =~ /^\d+$/) {
15684:20): $opendate = $args->{'openallfrom'};
15685:20): }
1.444 albertel 15686: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.141. .4(raebu 15687:20): my %storecontent = ($storeunder => $opendate,
1.444 albertel 15688: $storeunder.'.type' => 'date_start');
1.1075.2.141. .4(raebu 15689:20): $outcome .= &mt('All assignments open starting [_1]',
15690:20): &Apache::lonlocal::locallocaltime($opendate)).': '.
15691:20): &Apache::lonnet::cput
15692:20): ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15693: }
15694: #
15695: # Set first page
15696: #
15697: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15698: || ($cloneid)) {
1.445 albertel 15699: use LONCAPA::map;
1.444 albertel 15700: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15701:
15702: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15703: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15704:
1.444 albertel 15705: $outcome .= ($fatal?$errtext:'read ok').' - ';
15706: my $title; my $url;
15707: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15708: $title=&mt('Syllabus');
1.444 albertel 15709: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15710: } else {
1.963 raeburn 15711: $title=&mt('Table of Contents');
1.444 albertel 15712: $url='/adm/navmaps';
15713: }
1.445 albertel 15714:
15715: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15716: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15717:
15718: if ($errtext) { $fatal=2; }
1.541 raeburn 15719: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15720: }
1.566 albertel 15721:
1.1075.2.141. .5(raebu 15722:20): return (1,$outcome,\@clonemsg);
1.444 albertel 15723: }
15724:
1.1075.2.59 raeburn 15725: sub make_unique_code {
15726: my ($cdom,$cnum) = @_;
15727: # get lock on uniquecodes db
15728: my $lockhash = {
15729: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15730: ':'.$env{'user.domain'},
15731: };
15732: my $tries = 0;
15733: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15734: my ($code,$error);
15735:
15736: while (($gotlock ne 'ok') && ($tries<3)) {
15737: $tries ++;
15738: sleep 1;
15739: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15740: }
15741: if ($gotlock eq 'ok') {
15742: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15743: my $gotcode;
15744: my $attempts = 0;
15745: while ((!$gotcode) && ($attempts < 100)) {
15746: $code = &generate_code();
15747: if (!exists($currcodes{$code})) {
15748: $gotcode = 1;
15749: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15750: $error = 'nostore';
15751: }
15752: }
15753: $attempts ++;
15754: }
15755: my @del_lock = ($cnum."\0".'uniquecodes');
15756: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15757: } else {
15758: $error = 'nolock';
15759: }
15760: return ($code,$error);
15761: }
15762:
15763: sub generate_code {
15764: my $code;
15765: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15766: for (my $i=0; $i<6; $i++) {
15767: my $lettnum = int (rand 2);
15768: my $item = '';
15769: if ($lettnum) {
15770: $item = $letts[int( rand(18) )];
15771: } else {
15772: $item = 1+int( rand(8) );
15773: }
15774: $code .= $item;
15775: }
15776: return $code;
15777: }
15778:
1.444 albertel 15779: ############################################################
15780: ############################################################
15781:
1.953 droeschl 15782: #SD
15783: # only Community and Course, or anything else?
1.378 raeburn 15784: sub course_type {
15785: my ($cid) = @_;
15786: if (!defined($cid)) {
15787: $cid = $env{'request.course.id'};
15788: }
1.404 albertel 15789: if (defined($env{'course.'.$cid.'.type'})) {
15790: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15791: } else {
15792: return 'Course';
1.377 raeburn 15793: }
15794: }
1.156 albertel 15795:
1.406 raeburn 15796: sub group_term {
15797: my $crstype = &course_type();
15798: my %names = (
15799: 'Course' => 'group',
1.865 raeburn 15800: 'Community' => 'group',
1.406 raeburn 15801: );
15802: return $names{$crstype};
15803: }
15804:
1.902 raeburn 15805: sub course_types {
1.1075.2.59 raeburn 15806: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15807: my %typename = (
15808: official => 'Official course',
15809: unofficial => 'Unofficial course',
15810: community => 'Community',
1.1075.2.59 raeburn 15811: textbook => 'Textbook course',
1.902 raeburn 15812: );
15813: return (\@types,\%typename);
15814: }
15815:
1.156 albertel 15816: sub icon {
15817: my ($file)=@_;
1.505 albertel 15818: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15819: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15820: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15821: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15822: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15823: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15824: $curfext.".gif") {
15825: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15826: $curfext.".gif";
15827: }
15828: }
1.249 albertel 15829: return &lonhttpdurl($iconname);
1.154 albertel 15830: }
1.84 albertel 15831:
1.575 albertel 15832: sub lonhttpdurl {
1.692 www 15833: #
15834: # Had been used for "small fry" static images on separate port 8080.
15835: # Modify here if lightweight http functionality desired again.
15836: # Currently eliminated due to increasing firewall issues.
15837: #
1.575 albertel 15838: my ($url)=@_;
1.692 www 15839: return $url;
1.215 albertel 15840: }
15841:
1.213 albertel 15842: sub connection_aborted {
15843: my ($r)=@_;
15844: $r->print(" ");$r->rflush();
15845: my $c = $r->connection;
15846: return $c->aborted();
15847: }
15848:
1.221 foxr 15849: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15850: # strings as 'strings'.
15851: sub escape_single {
1.221 foxr 15852: my ($input) = @_;
1.223 albertel 15853: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15854: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15855: return $input;
15856: }
1.223 albertel 15857:
1.222 foxr 15858: # Same as escape_single, but escape's "'s This
15859: # can be used for "strings"
15860: sub escape_double {
15861: my ($input) = @_;
15862: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15863: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15864: return $input;
15865: }
1.223 albertel 15866:
1.222 foxr 15867: # Escapes the last element of a full URL.
15868: sub escape_url {
15869: my ($url) = @_;
1.238 raeburn 15870: my @urlslices = split(/\//, $url,-1);
1.369 www 15871: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15872: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15873: }
1.462 albertel 15874:
1.820 raeburn 15875: sub compare_arrays {
15876: my ($arrayref1,$arrayref2) = @_;
15877: my (@difference,%count);
15878: @difference = ();
15879: %count = ();
15880: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15881: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15882: foreach my $element (keys(%count)) {
15883: if ($count{$element} == 1) {
15884: push(@difference,$element);
15885: }
15886: }
15887: }
15888: return @difference;
15889: }
15890:
1.817 bisitz 15891: # -------------------------------------------------------- Initialize user login
1.462 albertel 15892: sub init_user_environment {
1.463 albertel 15893: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15894: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15895:
15896: my $public=($username eq 'public' && $domain eq 'public');
15897:
15898: # See if old ID present, if so, remove
15899:
1.1062 raeburn 15900: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15901: my $now=time;
15902:
15903: if ($public) {
15904: my $max_public=100;
15905: my $oldest;
15906: my $oldest_time=0;
15907: for(my $next=1;$next<=$max_public;$next++) {
15908: if (-e $lonids."/publicuser_$next.id") {
15909: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15910: if ($mtime<$oldest_time || !$oldest_time) {
15911: $oldest_time=$mtime;
15912: $oldest=$next;
15913: }
15914: } else {
15915: $cookie="publicuser_$next";
15916: last;
15917: }
15918: }
15919: if (!$cookie) { $cookie="publicuser_$oldest"; }
15920: } else {
1.463 albertel 15921: # if this isn't a robot, kill any existing non-robot sessions
15922: if (!$args->{'robot'}) {
15923: opendir(DIR,$lonids);
15924: while ($filename=readdir(DIR)) {
15925: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15926: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15927: &GDBM_READER(),0640)) {
15928: my $linkedfile;
15929: if (exists($oldenv{'user.linkedenv'})) {
15930: $linkedfile = $oldenv{'user.linkedenv'};
15931: }
15932: untie(%oldenv);
15933: if (unlink("$lonids/$filename")) {
15934: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15935: if (-l "$lonids/$linkedfile.id") {
15936: unlink("$lonids/$linkedfile.id");
15937: }
15938: }
15939: }
15940: } else {
15941: unlink($lonids.'/'.$filename);
15942: }
1.463 albertel 15943: }
1.462 albertel 15944: }
1.463 albertel 15945: closedir(DIR);
1.1075.2.84 raeburn 15946: # If there is a undeleted lockfile for the user's paste buffer remove it.
15947: my $namespace = 'nohist_courseeditor';
15948: my $lockingkey = 'paste'."\0".'locked_num';
15949: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15950: $domain,$username);
15951: if (exists($lockhash{$lockingkey})) {
15952: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15953: unless ($delresult eq 'ok') {
15954: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15955: }
15956: }
1.462 albertel 15957: }
15958: # Give them a new cookie
1.463 albertel 15959: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15960: : $now.$$.int(rand(10000)));
1.463 albertel 15961: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15962:
15963: # Initialize roles
15964:
1.1062 raeburn 15965: ($userroles,$firstaccenv,$timerintenv) =
15966: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15967: }
15968: # ------------------------------------ Check browser type and MathML capability
15969:
1.1075.2.77 raeburn 15970: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15971: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15972:
15973: # ------------------------------------------------------------- Get environment
15974:
15975: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15976: my ($tmp) = keys(%userenv);
15977: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15978: } else {
15979: undef(%userenv);
15980: }
15981: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15982: $form->{'interface'}=$userenv{'interface'};
15983: }
15984: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15985:
15986: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15987: foreach my $option ('interface','localpath','localres') {
15988: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15989: }
15990: # --------------------------------------------------------- Write first profile
15991:
15992: {
1.1075.2.141. .11(raeb 15993:-21): my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 15994: my %initial_env =
15995: ("user.name" => $username,
15996: "user.domain" => $domain,
15997: "user.home" => $authhost,
15998: "browser.type" => $clientbrowser,
15999: "browser.version" => $clientversion,
16000: "browser.mathml" => $clientmathml,
16001: "browser.unicode" => $clientunicode,
16002: "browser.os" => $clientos,
1.1075.2.42 raeburn 16003: "browser.mobile" => $clientmobile,
16004: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16005: "browser.osversion" => $clientosversion,
1.462 albertel 16006: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16007: "request.course.fn" => '',
16008: "request.course.uri" => '',
16009: "request.course.sec" => '',
16010: "request.role" => 'cm',
16011: "request.role.adv" => $env{'user.adv'},
1.1075.2.141. .11(raeb 16012:-21): "request.host" => $ip,);
1.462 albertel 16013:
16014: if ($form->{'localpath'}) {
16015: $initial_env{"browser.localpath"} = $form->{'localpath'};
16016: $initial_env{"browser.localres"} = $form->{'localres'};
16017: }
16018:
16019: if ($form->{'interface'}) {
16020: $form->{'interface'}=~s/\W//gs;
16021: $initial_env{"browser.interface"} = $form->{'interface'};
16022: $env{'browser.interface'}=$form->{'interface'};
16023: }
16024:
1.1075.2.54 raeburn 16025: if ($form->{'iptoken'}) {
16026: my $lonhost = $r->dir_config('lonHostID');
16027: $initial_env{"user.noloadbalance"} = $lonhost;
16028: $env{'user.noloadbalance'} = $lonhost;
16029: }
16030:
1.1075.2.120 raeburn 16031: if ($form->{'noloadbalance'}) {
16032: my @hosts = &Apache::lonnet::current_machine_ids();
16033: my $hosthere = $form->{'noloadbalance'};
16034: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16035: $initial_env{"user.noloadbalance"} = $hosthere;
16036: $env{'user.noloadbalance'} = $hosthere;
16037: }
16038: }
16039:
1.1016 raeburn 16040: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16041: my %is_adv = ( is_adv => $env{'user.adv'} );
16042: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16043:
1.1075.2.125 raeburn 16044: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16045: $userenv{'availabletools.'.$tool} =
16046: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16047: undef,\%userenv,\%domdef,\%is_adv);
16048: }
1.724 raeburn 16049:
1.1075.2.125 raeburn 16050: foreach my $crstype ('official','unofficial','community','textbook') {
16051: $userenv{'canrequest.'.$crstype} =
16052: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16053: 'reload','requestcourses',
16054: \%userenv,\%domdef,\%is_adv);
16055: }
1.765 raeburn 16056:
1.1075.2.125 raeburn 16057: $userenv{'canrequest.author'} =
16058: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16059: 'reload','requestauthor',
16060: \%userenv,\%domdef,\%is_adv);
16061: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16062: $domain,$username);
16063: my $reqstatus = $reqauthor{'author_status'};
16064: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16065: if (ref($reqauthor{'author'}) eq 'HASH') {
16066: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16067: $reqauthor{'author'}{'timestamp'};
16068: }
1.1075.2.14 raeburn 16069: }
16070: }
16071:
1.462 albertel 16072: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16073:
1.462 albertel 16074: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16075: &GDBM_WRCREAT(),0640)) {
16076: &_add_to_env(\%disk_env,\%initial_env);
16077: &_add_to_env(\%disk_env,\%userenv,'environment.');
16078: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16079: if (ref($firstaccenv) eq 'HASH') {
16080: &_add_to_env(\%disk_env,$firstaccenv);
16081: }
16082: if (ref($timerintenv) eq 'HASH') {
16083: &_add_to_env(\%disk_env,$timerintenv);
16084: }
1.463 albertel 16085: if (ref($args->{'extra_env'})) {
16086: &_add_to_env(\%disk_env,$args->{'extra_env'});
16087: }
1.462 albertel 16088: untie(%disk_env);
16089: } else {
1.705 tempelho 16090: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16091: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16092: return 'error: '.$!;
16093: }
16094: }
16095: $env{'request.role'}='cm';
16096: $env{'request.role.adv'}=$env{'user.adv'};
16097: $env{'browser.type'}=$clientbrowser;
16098:
16099: return $cookie;
16100:
16101: }
16102:
16103: sub _add_to_env {
16104: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16105: if (ref($env_data) eq 'HASH') {
16106: while (my ($key,$value) = each(%$env_data)) {
16107: $idf->{$prefix.$key} = $value;
16108: $env{$prefix.$key} = $value;
16109: }
1.462 albertel 16110: }
16111: }
16112:
1.685 tempelho 16113: # --- Get the symbolic name of a problem and the url
16114: sub get_symb {
16115: my ($request,$silent) = @_;
1.726 raeburn 16116: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16117: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16118: if ($symb eq '') {
16119: if (!$silent) {
1.1071 raeburn 16120: if (ref($request)) {
16121: $request->print("Unable to handle ambiguous references:$url:.");
16122: }
1.685 tempelho 16123: return ();
16124: }
16125: }
16126: &Apache::lonenc::check_decrypt(\$symb);
16127: return ($symb);
16128: }
16129:
16130: # --------------------------------------------------------------Get annotation
16131:
16132: sub get_annotation {
16133: my ($symb,$enc) = @_;
16134:
16135: my $key = $symb;
16136: if (!$enc) {
16137: $key =
16138: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16139: }
16140: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16141: return $annotation{$key};
16142: }
16143:
16144: sub clean_symb {
1.731 raeburn 16145: my ($symb,$delete_enc) = @_;
1.685 tempelho 16146:
16147: &Apache::lonenc::check_decrypt(\$symb);
16148: my $enc = $env{'request.enc'};
1.731 raeburn 16149: if ($delete_enc) {
1.730 raeburn 16150: delete($env{'request.enc'});
16151: }
1.685 tempelho 16152:
16153: return ($symb,$enc);
16154: }
1.462 albertel 16155:
1.1075.2.69 raeburn 16156: ############################################################
16157: ############################################################
16158:
16159: =pod
16160:
16161: =head1 Routines for building display used to search for courses
16162:
16163:
16164: =over 4
16165:
16166: =item * &build_filters()
16167:
16168: Create markup for a table used to set filters to use when selecting
16169: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16170: and quotacheck.pl
16171:
16172:
16173: Inputs:
16174:
16175: filterlist - anonymous array of fields to include as potential filters
16176:
16177: crstype - course type
16178:
16179: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16180: to pop-open a course selector (will contain "extra element").
16181:
16182: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16183:
16184: filter - anonymous hash of criteria and their values
16185:
16186: action - form action
16187:
16188: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16189:
16190: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16191:
16192: cloneruname - username of owner of new course who wants to clone
16193:
16194: clonerudom - domain of owner of new course who wants to clone
16195:
16196: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16197:
16198: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16199:
16200: codedom - domain
16201:
16202: formname - value of form element named "form".
16203:
16204: fixeddom - domain, if fixed.
16205:
16206: prevphase - value to assign to form element named "phase" when going back to the previous screen
16207:
16208: cnameelement - name of form element in form on opener page which will receive title of selected course
16209:
16210: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16211:
16212: cdomelement - name of form element in form on opener page which will receive domain of selected course
16213:
16214: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16215:
16216: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16217:
16218: clonewarning - warning message about missing information for intended course owner when DC creates a course
16219:
16220:
16221: Returns: $output - HTML for display of search criteria, and hidden form elements.
16222:
16223:
16224: Side Effects: None
16225:
16226: =cut
16227:
16228: # ---------------------------------------------- search for courses based on last activity etc.
16229:
16230: sub build_filters {
16231: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16232: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16233: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16234: $cnameelement,$cnumelement,$cdomelement,$setroles,
16235: $clonetext,$clonewarning) = @_;
16236: my ($list,$jscript);
16237: my $onchange = 'javascript:updateFilters(this)';
16238: my ($domainselectform,$sincefilterform,$createdfilterform,
16239: $ownerdomselectform,$persondomselectform,$instcodeform,
16240: $typeselectform,$instcodetitle);
16241: if ($formname eq '') {
16242: $formname = $caller;
16243: }
16244: foreach my $item (@{$filterlist}) {
16245: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16246: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16247: if ($item eq 'domainfilter') {
16248: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16249: } elsif ($item eq 'coursefilter') {
16250: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16251: } elsif ($item eq 'ownerfilter') {
16252: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16253: } elsif ($item eq 'ownerdomfilter') {
16254: $filter->{'ownerdomfilter'} =
16255: &LONCAPA::clean_domain($filter->{$item});
16256: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16257: 'ownerdomfilter',1);
16258: } elsif ($item eq 'personfilter') {
16259: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16260: } elsif ($item eq 'persondomfilter') {
16261: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16262: 'persondomfilter',1);
16263: } else {
16264: $filter->{$item} =~ s/\W//g;
16265: }
16266: if (!$filter->{$item}) {
16267: $filter->{$item} = '';
16268: }
16269: }
16270: if ($item eq 'domainfilter') {
16271: my $allow_blank = 1;
16272: if ($formname eq 'portform') {
16273: $allow_blank=0;
16274: } elsif ($formname eq 'studentform') {
16275: $allow_blank=0;
16276: }
16277: if ($fixeddom) {
16278: $domainselectform = '<input type="hidden" name="domainfilter"'.
16279: ' value="'.$codedom.'" />'.
16280: &Apache::lonnet::domain($codedom,'description');
16281: } else {
16282: $domainselectform = &select_dom_form($filter->{$item},
16283: 'domainfilter',
16284: $allow_blank,'',$onchange);
16285: }
16286: } else {
16287: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16288: }
16289: }
16290:
16291: # last course activity filter and selection
16292: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16293:
16294: # course created filter and selection
16295: if (exists($filter->{'createdfilter'})) {
16296: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16297: }
16298:
16299: my %lt = &Apache::lonlocal::texthash(
16300: 'cac' => "$crstype Activity",
16301: 'ccr' => "$crstype Created",
16302: 'cde' => "$crstype Title",
16303: 'cdo' => "$crstype Domain",
16304: 'ins' => 'Institutional Code',
16305: 'inc' => 'Institutional Categorization',
16306: 'cow' => "$crstype Owner/Co-owner",
16307: 'cop' => "$crstype Personnel Includes",
16308: 'cog' => 'Type',
16309: );
16310:
16311: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16312: my $typeval = 'Course';
16313: if ($crstype eq 'Community') {
16314: $typeval = 'Community';
16315: }
16316: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16317: } else {
16318: $typeselectform = '<select name="type" size="1"';
16319: if ($onchange) {
16320: $typeselectform .= ' onchange="'.$onchange.'"';
16321: }
16322: $typeselectform .= '>'."\n";
16323: foreach my $posstype ('Course','Community') {
16324: $typeselectform.='<option value="'.$posstype.'"'.
16325: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16326: }
16327: $typeselectform.="</select>";
16328: }
16329:
16330: my ($cloneableonlyform,$cloneabletitle);
16331: if (exists($filter->{'cloneableonly'})) {
16332: my $cloneableon = '';
16333: my $cloneableoff = ' checked="checked"';
16334: if ($filter->{'cloneableonly'}) {
16335: $cloneableon = $cloneableoff;
16336: $cloneableoff = '';
16337: }
16338: $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>';
16339: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16340: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16341: } else {
16342: $cloneabletitle = &mt('Cloneable by you');
16343: }
16344: }
16345: my $officialjs;
16346: if ($crstype eq 'Course') {
16347: if (exists($filter->{'instcodefilter'})) {
16348: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16349: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16350: if ($codedom) {
16351: $officialjs = 1;
16352: ($instcodeform,$jscript,$$numtitlesref) =
16353: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16354: $officialjs,$codetitlesref);
16355: if ($jscript) {
16356: $jscript = '<script type="text/javascript">'."\n".
16357: '// <![CDATA['."\n".
16358: $jscript."\n".
16359: '// ]]>'."\n".
16360: '</script>'."\n";
16361: }
16362: }
16363: if ($instcodeform eq '') {
16364: $instcodeform =
16365: '<input type="text" name="instcodefilter" size="10" value="'.
16366: $list->{'instcodefilter'}.'" />';
16367: $instcodetitle = $lt{'ins'};
16368: } else {
16369: $instcodetitle = $lt{'inc'};
16370: }
16371: if ($fixeddom) {
16372: $instcodetitle .= '<br />('.$codedom.')';
16373: }
16374: }
16375: }
16376: my $output = qq|
16377: <form method="post" name="filterpicker" action="$action">
16378: <input type="hidden" name="form" value="$formname" />
16379: |;
16380: if ($formname eq 'modifycourse') {
16381: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16382: '<input type="hidden" name="prevphase" value="'.
16383: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16384: } elsif ($formname eq 'quotacheck') {
16385: $output .= qq|
16386: <input type="hidden" name="sortby" value="" />
16387: <input type="hidden" name="sortorder" value="" />
16388: |;
16389: } else {
1.1075.2.69 raeburn 16390: my $name_input;
16391: if ($cnameelement ne '') {
16392: $name_input = '<input type="hidden" name="cnameelement" value="'.
16393: $cnameelement.'" />';
16394: }
16395: $output .= qq|
16396: <input type="hidden" name="cnumelement" value="$cnumelement" />
16397: <input type="hidden" name="cdomelement" value="$cdomelement" />
16398: $name_input
16399: $roleelement
16400: $multelement
16401: $typeelement
16402: |;
16403: if ($formname eq 'portform') {
16404: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16405: }
16406: }
16407: if ($fixeddom) {
16408: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16409: }
16410: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16411: if ($sincefilterform) {
16412: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16413: .$sincefilterform
16414: .&Apache::lonhtmlcommon::row_closure();
16415: }
16416: if ($createdfilterform) {
16417: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16418: .$createdfilterform
16419: .&Apache::lonhtmlcommon::row_closure();
16420: }
16421: if ($domainselectform) {
16422: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16423: .$domainselectform
16424: .&Apache::lonhtmlcommon::row_closure();
16425: }
16426: if ($typeselectform) {
16427: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16428: $output .= $typeselectform;
16429: } else {
16430: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16431: .$typeselectform
16432: .&Apache::lonhtmlcommon::row_closure();
16433: }
16434: }
16435: if ($instcodeform) {
16436: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16437: .$instcodeform
16438: .&Apache::lonhtmlcommon::row_closure();
16439: }
16440: if (exists($filter->{'ownerfilter'})) {
16441: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16442: '<table><tr><td>'.&mt('Username').'<br />'.
16443: '<input type="text" name="ownerfilter" size="20" value="'.
16444: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16445: $ownerdomselectform.'</td></tr></table>'.
16446: &Apache::lonhtmlcommon::row_closure();
16447: }
16448: if (exists($filter->{'personfilter'})) {
16449: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16450: '<table><tr><td>'.&mt('Username').'<br />'.
16451: '<input type="text" name="personfilter" size="20" value="'.
16452: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16453: $persondomselectform.'</td></tr></table>'.
16454: &Apache::lonhtmlcommon::row_closure();
16455: }
16456: if (exists($filter->{'coursefilter'})) {
16457: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16458: .'<input type="text" name="coursefilter" size="25" value="'
16459: .$list->{'coursefilter'}.'" />'
16460: .&Apache::lonhtmlcommon::row_closure();
16461: }
16462: if ($cloneableonlyform) {
16463: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16464: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16465: }
16466: if (exists($filter->{'descriptfilter'})) {
16467: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16468: .'<input type="text" name="descriptfilter" size="40" value="'
16469: .$list->{'descriptfilter'}.'" />'
16470: .&Apache::lonhtmlcommon::row_closure(1);
16471: }
16472: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16473: '<input type="hidden" name="updater" value="" />'."\n".
16474: '<input type="submit" name="gosearch" value="'.
16475: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16476: return $jscript.$clonewarning.$output;
16477: }
16478:
16479: =pod
16480:
16481: =item * &timebased_select_form()
16482:
16483: Create markup for a dropdown list used to select a time-based
16484: filter e.g., Course Activity, Course Created, when searching for courses
16485: or communities
16486:
16487: Inputs:
16488:
16489: item - name of form element (sincefilter or createdfilter)
16490:
16491: filter - anonymous hash of criteria and their values
16492:
16493: Returns: HTML for a select box contained a blank, then six time selections,
16494: with value set in incoming form variables currently selected.
16495:
16496: Side Effects: None
16497:
16498: =cut
16499:
16500: sub timebased_select_form {
16501: my ($item,$filter) = @_;
16502: if (ref($filter) eq 'HASH') {
16503: $filter->{$item} =~ s/[^\d-]//g;
16504: if (!$filter->{$item}) { $filter->{$item}=-1; }
16505: return &select_form(
16506: $filter->{$item},
16507: $item,
16508: { '-1' => '',
16509: '86400' => &mt('today'),
16510: '604800' => &mt('last week'),
16511: '2592000' => &mt('last month'),
16512: '7776000' => &mt('last three months'),
16513: '15552000' => &mt('last six months'),
16514: '31104000' => &mt('last year'),
16515: 'select_form_order' =>
16516: ['-1','86400','604800','2592000','7776000',
16517: '15552000','31104000']});
16518: }
16519: }
16520:
16521: =pod
16522:
16523: =item * &js_changer()
16524:
16525: Create script tag containing Javascript used to submit course search form
16526: when course type or domain is changed, and also to hide 'Searching ...' on
16527: page load completion for page showing search result.
16528:
16529: Inputs: None
16530:
16531: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16532:
16533: Side Effects: None
16534:
16535: =cut
16536:
16537: sub js_changer {
16538: return <<ENDJS;
16539: <script type="text/javascript">
16540: // <![CDATA[
16541: function updateFilters(caller) {
16542: if (typeof(caller) != "undefined") {
16543: document.filterpicker.updater.value = caller.name;
16544: }
16545: document.filterpicker.submit();
16546: }
16547:
16548: function hideSearching() {
16549: if (document.getElementById('searching')) {
16550: document.getElementById('searching').style.display = 'none';
16551: }
16552: return;
16553: }
16554:
16555: // ]]>
16556: </script>
16557:
16558: ENDJS
16559: }
16560:
16561: =pod
16562:
16563: =item * &search_courses()
16564:
16565: Process selected filters form course search form and pass to lonnet::courseiddump
16566: to retrieve a hash for which keys are courseIDs which match the selected filters.
16567:
16568: Inputs:
16569:
16570: dom - domain being searched
16571:
16572: type - course type ('Course' or 'Community' or '.' if any).
16573:
16574: filter - anonymous hash of criteria and their values
16575:
16576: numtitles - for institutional codes - number of categories
16577:
16578: cloneruname - optional username of new course owner
16579:
16580: clonerudom - optional domain of new course owner
16581:
1.1075.2.95 raeburn 16582: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16583: (used when DC is using course creation form)
16584:
16585: codetitles - reference to array of titles of components in institutional codes (official courses).
16586:
1.1075.2.95 raeburn 16587: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16588: (and so can clone automatically)
16589:
16590: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16591:
16592: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16593: courses to clone
1.1075.2.69 raeburn 16594:
16595: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16596:
16597:
16598: Side Effects: None
16599:
16600: =cut
16601:
16602:
16603: sub search_courses {
1.1075.2.95 raeburn 16604: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16605: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16606: my (%courses,%showcourses,$cloner);
16607: if (($filter->{'ownerfilter'} ne '') ||
16608: ($filter->{'ownerdomfilter'} ne '')) {
16609: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16610: $filter->{'ownerdomfilter'};
16611: }
16612: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16613: if (!$filter->{$item}) {
16614: $filter->{$item}='.';
16615: }
16616: }
16617: my $now = time;
16618: my $timefilter =
16619: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16620: my ($createdbefore,$createdafter);
16621: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16622: $createdbefore = $now;
16623: $createdafter = $now-$filter->{'createdfilter'};
16624: }
16625: my ($instcodefilter,$regexpok);
16626: if ($numtitles) {
16627: if ($env{'form.official'} eq 'on') {
16628: $instcodefilter =
16629: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16630: $regexpok = 1;
16631: } elsif ($env{'form.official'} eq 'off') {
16632: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16633: unless ($instcodefilter eq '') {
16634: $regexpok = -1;
16635: }
16636: }
16637: } else {
16638: $instcodefilter = $filter->{'instcodefilter'};
16639: }
16640: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16641: if ($type eq '') { $type = '.'; }
16642:
16643: if (($clonerudom ne '') && ($cloneruname ne '')) {
16644: $cloner = $cloneruname.':'.$clonerudom;
16645: }
16646: %courses = &Apache::lonnet::courseiddump($dom,
16647: $filter->{'descriptfilter'},
16648: $timefilter,
16649: $instcodefilter,
16650: $filter->{'combownerfilter'},
16651: $filter->{'coursefilter'},
16652: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16653: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16654: $filter->{'cloneableonly'},
16655: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16656: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16657: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16658: my $ccrole;
16659: if ($type eq 'Community') {
16660: $ccrole = 'co';
16661: } else {
16662: $ccrole = 'cc';
16663: }
16664: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16665: $filter->{'persondomfilter'},
16666: 'userroles',undef,
16667: [$ccrole,'in','ad','ep','ta','cr'],
16668: $dom);
16669: foreach my $role (keys(%rolehash)) {
16670: my ($cnum,$cdom,$courserole) = split(':',$role);
16671: my $cid = $cdom.'_'.$cnum;
16672: if (exists($courses{$cid})) {
16673: if (ref($courses{$cid}) eq 'HASH') {
16674: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16675: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16676: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16677: }
16678: } else {
16679: $courses{$cid}{roles} = [$courserole];
16680: }
16681: $showcourses{$cid} = $courses{$cid};
16682: }
16683: }
16684: }
16685: %courses = %showcourses;
16686: }
16687: return %courses;
16688: }
16689:
16690: =pod
16691:
16692: =back
16693:
1.1075.2.88 raeburn 16694: =head1 Routines for version requirements for current course.
16695:
16696: =over 4
16697:
16698: =item * &check_release_required()
16699:
16700: Compares required LON-CAPA version with version on server, and
16701: if required version is newer looks for a server with the required version.
16702:
16703: Looks first at servers in user's owen domain; if none suitable, looks at
16704: servers in course's domain are permitted to host sessions for user's domain.
16705:
16706: Inputs:
16707:
16708: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16709:
16710: $courseid - Course ID of current course
16711:
16712: $rolecode - User's current role in course (for switchserver query string).
16713:
16714: $required - LON-CAPA version needed by course (format: Major.Minor).
16715:
16716:
16717: Returns:
16718:
16719: $switchserver - query string tp append to /adm/switchserver call (if
16720: current server's LON-CAPA version is too old.
16721:
16722: $warning - Message is displayed if no suitable server could be found.
16723:
16724: =cut
16725:
16726: sub check_release_required {
16727: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16728: my ($switchserver,$warning);
16729: if ($required ne '') {
16730: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16731: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16732: if ($reqdmajor ne '' && $reqdminor ne '') {
16733: my $otherserver;
16734: if (($major eq '' && $minor eq '') ||
16735: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16736: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16737: my $switchlcrev =
16738: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16739: $userdomserver);
16740: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16741: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16742: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16743: my $cdom = $env{'course.'.$courseid.'.domain'};
16744: if ($cdom ne $env{'user.domain'}) {
16745: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16746: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16747: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16748: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16749: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16750: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16751: my $canhost =
16752: &Apache::lonnet::can_host_session($env{'user.domain'},
16753: $coursedomserver,
16754: $remoterev,
16755: $udomdefaults{'remotesessions'},
16756: $defdomdefaults{'hostedsessions'});
16757:
16758: if ($canhost) {
16759: $otherserver = $coursedomserver;
16760: } else {
16761: $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.");
16762: }
16763: } else {
16764: $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).");
16765: }
16766: } else {
16767: $otherserver = $userdomserver;
16768: }
16769: }
16770: if ($otherserver ne '') {
16771: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16772: }
16773: }
16774: }
16775: return ($switchserver,$warning);
16776: }
16777:
16778: =pod
16779:
16780: =item * &check_release_result()
16781:
16782: Inputs:
16783:
16784: $switchwarning - Warning message if no suitable server found to host session.
16785:
16786: $switchserver - query string to append to /adm/switchserver containing lonHostID
16787: and current role.
16788:
16789: Returns: HTML to display with information about requirement to switch server.
16790: Either displaying warning with link to Roles/Courses screen or
16791: display link to switchserver.
16792:
1.1075.2.69 raeburn 16793: =cut
16794:
1.1075.2.88 raeburn 16795: sub check_release_result {
16796: my ($switchwarning,$switchserver) = @_;
16797: my $output = &start_page('Selected course unavailable on this server').
16798: '<p class="LC_warning">';
16799: if ($switchwarning) {
16800: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16801: if (&show_course()) {
16802: $output .= &mt('Display courses');
16803: } else {
16804: $output .= &mt('Display roles');
16805: }
16806: $output .= '</a>';
16807: } elsif ($switchserver) {
16808: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16809: '<br />'.
16810: '<a href="/adm/switchserver?'.$switchserver.'">'.
16811: &mt('Switch Server').
16812: '</a>';
16813: }
16814: $output .= '</p>'.&end_page();
16815: return $output;
16816: }
16817:
16818: =pod
16819:
16820: =item * &needs_coursereinit()
16821:
16822: Determine if course contents stored for user's session needs to be
16823: refreshed, because content has changed since "Big Hash" last tied.
16824:
16825: Check for change is made if time last checked is more than 10 minutes ago
16826: (by default).
16827:
16828: Inputs:
16829:
16830: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16831:
16832: $interval (optional) - Time which may elapse (in s) between last check for content
16833: change in current course. (default: 600 s).
16834:
16835: Returns: an array; first element is:
16836:
16837: =over 4
16838:
16839: 'switch' - if content updates mean user's session
16840: needs to be switched to a server running a newer LON-CAPA version
16841:
16842: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16843: on current server hosting user's session
16844:
16845: '' - if no action required.
16846:
16847: =back
16848:
16849: If first item element is 'switch':
16850:
16851: second item is $switchwarning - Warning message if no suitable server found to host session.
16852:
16853: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16854: and current role.
16855:
16856: otherwise: no other elements returned.
16857:
16858: =back
16859:
16860: =cut
16861:
16862: sub needs_coursereinit {
16863: my ($loncaparev,$interval) = @_;
16864: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16865: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16866: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16867: my $now = time;
16868: if ($interval eq '') {
16869: $interval = 600;
16870: }
16871: if (($now-$env{'request.course.timechecked'})>$interval) {
16872: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.141. .6(raebu 16873:20): my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
16874:20): if ($blocked) {
16875:20): return ();
16876:20): }
16877:20): my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
1.1075.2.88 raeburn 16878: if ($lastchange > $env{'request.course.tied'}) {
16879: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16880: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16881: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16882: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16883: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16884: $curr_reqd_hash{'internal.releaserequired'}});
16885: my ($switchserver,$switchwarning) =
16886: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16887: $curr_reqd_hash{'internal.releaserequired'});
16888: if ($switchwarning ne '' || $switchserver ne '') {
16889: return ('switch',$switchwarning,$switchserver);
16890: }
16891: }
16892: }
16893: return ('update');
16894: }
16895: }
16896: return ();
16897: }
1.1075.2.69 raeburn 16898:
1.1075.2.11 raeburn 16899: sub update_content_constraints {
16900: my ($cdom,$cnum,$chome,$cid) = @_;
16901: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16902: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16903: my %checkresponsetypes;
16904: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16905: my ($item,$name,$value) = split(/:/,$key);
16906: if ($item eq 'resourcetag') {
16907: if ($name eq 'responsetype') {
16908: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16909: }
16910: }
16911: }
16912: my $navmap = Apache::lonnavmaps::navmap->new();
16913: if (defined($navmap)) {
16914: my %allresponses;
16915: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16916: my %responses = $res->responseTypes();
16917: foreach my $key (keys(%responses)) {
16918: next unless(exists($checkresponsetypes{$key}));
16919: $allresponses{$key} += $responses{$key};
16920: }
16921: }
16922: foreach my $key (keys(%allresponses)) {
16923: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16924: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16925: ($reqdmajor,$reqdminor) = ($major,$minor);
16926: }
16927: }
16928: undef($navmap);
16929: }
16930: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16931: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16932: }
16933: return;
16934: }
16935:
1.1075.2.27 raeburn 16936: sub allmaps_incourse {
16937: my ($cdom,$cnum,$chome,$cid) = @_;
16938: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16939: $cid = $env{'request.course.id'};
16940: $cdom = $env{'course.'.$cid.'.domain'};
16941: $cnum = $env{'course.'.$cid.'.num'};
16942: $chome = $env{'course.'.$cid.'.home'};
16943: }
16944: my %allmaps = ();
16945: my $lastchange =
16946: &Apache::lonnet::get_coursechange($cdom,$cnum);
16947: if ($lastchange > $env{'request.course.tied'}) {
16948: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16949: unless ($ferr) {
16950: &update_content_constraints($cdom,$cnum,$chome,$cid);
16951: }
16952: }
16953: my $navmap = Apache::lonnavmaps::navmap->new();
16954: if (defined($navmap)) {
16955: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16956: $allmaps{$res->src()} = 1;
16957: }
16958: }
16959: return \%allmaps;
16960: }
16961:
1.1075.2.11 raeburn 16962: sub parse_supplemental_title {
16963: my ($title) = @_;
16964:
16965: my ($foldertitle,$renametitle);
16966: if ($title =~ /&&&/) {
16967: $title = &HTML::Entites::decode($title);
16968: }
16969: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16970: $renametitle=$4;
16971: my ($time,$uname,$udom) = ($1,$2,$3);
16972: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16973: my $name = &plainname($uname,$udom);
16974: $name = &HTML::Entities::encode($name,'"<>&\'');
16975: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16976: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16977: $name.': <br />'.$foldertitle;
16978: }
16979: if (wantarray) {
16980: return ($title,$foldertitle,$renametitle);
16981: }
16982: return $title;
16983: }
16984:
1.1075.2.43 raeburn 16985: sub recurse_supplemental {
16986: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16987: if ($suppmap) {
16988: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16989: if ($fatal) {
16990: $errors ++;
16991: } else {
16992: if ($#LONCAPA::map::resources > 0) {
16993: foreach my $res (@LONCAPA::map::resources) {
16994: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16995: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16996: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16997: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16998: } else {
16999: $numfiles ++;
17000: }
17001: }
17002: }
17003: }
17004: }
17005: }
17006: return ($numfiles,$errors);
17007: }
17008:
1.1075.2.18 raeburn 17009: sub symb_to_docspath {
1.1075.2.119 raeburn 17010: my ($symb,$navmapref) = @_;
17011: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17012: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17013: if ($resurl=~/\.(sequence|page)$/) {
17014: $mapurl=$resurl;
17015: } elsif ($resurl eq 'adm/navmaps') {
17016: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17017: }
17018: my $mapresobj;
1.1075.2.119 raeburn 17019: unless (ref($$navmapref)) {
17020: $$navmapref = Apache::lonnavmaps::navmap->new();
17021: }
17022: if (ref($$navmapref)) {
17023: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17024: }
17025: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17026: my $type=$2;
17027: my $path;
17028: if (ref($mapresobj)) {
17029: my $pcslist = $mapresobj->map_hierarchy();
17030: if ($pcslist ne '') {
17031: foreach my $pc (split(/,/,$pcslist)) {
17032: next if ($pc <= 1);
1.1075.2.119 raeburn 17033: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17034: if (ref($res)) {
17035: my $thisurl = $res->src();
17036: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17037: my $thistitle = $res->title();
17038: $path .= '&'.
17039: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17040: &escape($thistitle).
1.1075.2.18 raeburn 17041: ':'.$res->randompick().
17042: ':'.$res->randomout().
17043: ':'.$res->encrypted().
17044: ':'.$res->randomorder().
17045: ':'.$res->is_page();
17046: }
17047: }
17048: }
17049: $path =~ s/^\&//;
17050: my $maptitle = $mapresobj->title();
17051: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17052: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17053: }
17054: $path .= (($path ne '')? '&' : '').
17055: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17056: &escape($maptitle).
1.1075.2.18 raeburn 17057: ':'.$mapresobj->randompick().
17058: ':'.$mapresobj->randomout().
17059: ':'.$mapresobj->encrypted().
17060: ':'.$mapresobj->randomorder().
17061: ':'.$mapresobj->is_page();
17062: } else {
17063: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17064: my $ispage = (($type eq 'page')? 1 : '');
17065: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17066: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17067: }
17068: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17069: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17070: }
17071: unless ($mapurl eq 'default') {
17072: $path = 'default&'.
1.1075.2.46 raeburn 17073: &escape('Main Content').
1.1075.2.18 raeburn 17074: ':::::&'.$path;
17075: }
17076: return $path;
17077: }
17078:
1.1075.2.14 raeburn 17079: sub captcha_display {
1.1075.2.137 raeburn 17080: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17081: my ($output,$error);
1.1075.2.107 raeburn 17082: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17083: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17084: if ($captcha eq 'original') {
17085: $output = &create_captcha();
17086: unless ($output) {
17087: $error = 'captcha';
17088: }
17089: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17090: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17091: unless ($output) {
17092: $error = 'recaptcha';
17093: }
17094: }
1.1075.2.107 raeburn 17095: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17096: }
17097:
17098: sub captcha_response {
1.1075.2.137 raeburn 17099: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17100: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17101: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17102: if ($captcha eq 'original') {
17103: ($captcha_chk,$captcha_error) = &check_captcha();
17104: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17105: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17106: } else {
17107: $captcha_chk = 1;
17108: }
17109: return ($captcha_chk,$captcha_error);
17110: }
17111:
17112: sub get_captcha_config {
1.1075.2.137 raeburn 17113: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17114: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17115: my $hostname = &Apache::lonnet::hostname($lonhost);
17116: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17117: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17118: if ($context eq 'usercreation') {
17119: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17120: if (ref($domconfig{$context}) eq 'HASH') {
17121: $hashtocheck = $domconfig{$context}{'cancreate'};
17122: if (ref($hashtocheck) eq 'HASH') {
17123: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17124: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17125: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17126: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17127: }
17128: if ($privkey && $pubkey) {
17129: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17130: $version = $hashtocheck->{'recaptchaversion'};
17131: if ($version ne '2') {
17132: $version = 1;
17133: }
1.1075.2.14 raeburn 17134: } else {
17135: $captcha = 'original';
17136: }
17137: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17138: $captcha = 'original';
17139: }
17140: }
17141: } else {
17142: $captcha = 'captcha';
17143: }
17144: } elsif ($context eq 'login') {
17145: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17146: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17147: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17148: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17149: if ($privkey && $pubkey) {
17150: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17151: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17152: if ($version ne '2') {
17153: $version = 1;
17154: }
1.1075.2.14 raeburn 17155: } else {
17156: $captcha = 'original';
17157: }
17158: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17159: $captcha = 'original';
17160: }
1.1075.2.137 raeburn 17161: } elsif ($context eq 'passwords') {
17162: if ($dom_in_effect) {
17163: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17164: if ($passwdconf{'captcha'} eq 'recaptcha') {
17165: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17166: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17167: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17168: }
17169: if ($privkey && $pubkey) {
17170: $captcha = 'recaptcha';
17171: $version = $passwdconf{'recaptchaversion'};
17172: if ($version ne '2') {
17173: $version = 1;
17174: }
17175: } else {
17176: $captcha = 'original';
17177: }
17178: } elsif ($passwdconf{'captcha'} ne 'notused') {
17179: $captcha = 'original';
17180: }
17181: }
1.1075.2.14 raeburn 17182: }
1.1075.2.107 raeburn 17183: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17184: }
17185:
17186: sub create_captcha {
17187: my %captcha_params = &captcha_settings();
17188: my ($output,$maxtries,$tries) = ('',10,0);
17189: while ($tries < $maxtries) {
17190: $tries ++;
17191: my $captcha = Authen::Captcha->new (
17192: output_folder => $captcha_params{'output_dir'},
17193: data_folder => $captcha_params{'db_dir'},
17194: );
17195: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17196:
17197: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17198: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17199: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17200: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17201: '<br />'.
17202: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17203: last;
17204: }
17205: }
17206: return $output;
17207: }
17208:
17209: sub captcha_settings {
17210: my %captcha_params = (
17211: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17212: www_output_dir => "/captchaspool",
17213: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17214: numchars => '5',
17215: );
17216: return %captcha_params;
17217: }
17218:
17219: sub check_captcha {
17220: my ($captcha_chk,$captcha_error);
17221: my $code = $env{'form.code'};
17222: my $md5sum = $env{'form.crypt'};
17223: my %captcha_params = &captcha_settings();
17224: my $captcha = Authen::Captcha->new(
17225: output_folder => $captcha_params{'output_dir'},
17226: data_folder => $captcha_params{'db_dir'},
17227: );
1.1075.2.26 raeburn 17228: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17229: my %captcha_hash = (
17230: 0 => 'Code not checked (file error)',
17231: -1 => 'Failed: code expired',
17232: -2 => 'Failed: invalid code (not in database)',
17233: -3 => 'Failed: invalid code (code does not match crypt)',
17234: );
17235: if ($captcha_chk != 1) {
17236: $captcha_error = $captcha_hash{$captcha_chk}
17237: }
17238: return ($captcha_chk,$captcha_error);
17239: }
17240:
17241: sub create_recaptcha {
1.1075.2.107 raeburn 17242: my ($pubkey,$version) = @_;
17243: if ($version >= 2) {
17244: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17245: } else {
17246: my $use_ssl;
17247: if ($ENV{'SERVER_PORT'} == 443) {
17248: $use_ssl = 1;
17249: }
17250: my $captcha = Captcha::reCAPTCHA->new;
17251: return $captcha->get_options_setter({theme => 'white'})."\n".
17252: $captcha->get_html($pubkey,undef,$use_ssl).
17253: &mt('If the text is hard to read, [_1] will replace them.',
17254: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17255: '<br /><br />';
17256: }
1.1075.2.14 raeburn 17257: }
17258:
17259: sub check_recaptcha {
1.1075.2.107 raeburn 17260: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17261: my $captcha_chk;
1.1075.2.141. .11(raeb 17262:-21): my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17263: if ($version >= 2) {
17264: my $ua = LWP::UserAgent->new;
17265: $ua->timeout(10);
17266: my %info = (
17267: secret => $privkey,
17268: response => $env{'form.g-recaptcha-response'},
1.1075.2.141. .11(raeb 17269:-21): remoteip => $ip,
1.1075.2.107 raeburn 17270: );
17271: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17272: if ($response->is_success) {
17273: my $data = JSON::DWIW->from_json($response->decoded_content);
17274: if (ref($data) eq 'HASH') {
17275: if ($data->{'success'}) {
17276: $captcha_chk = 1;
17277: }
17278: }
17279: }
17280: } else {
17281: my $captcha = Captcha::reCAPTCHA->new;
17282: my $captcha_result =
17283: $captcha->check_answer(
17284: $privkey,
1.1075.2.141. .11(raeb 17285:-21): $ip,
1.1075.2.107 raeburn 17286: $env{'form.recaptcha_challenge_field'},
17287: $env{'form.recaptcha_response_field'},
17288: );
17289: if ($captcha_result->{is_valid}) {
17290: $captcha_chk = 1;
17291: }
1.1075.2.14 raeburn 17292: }
17293: return $captcha_chk;
17294: }
17295:
1.1075.2.64 raeburn 17296: sub emailusername_info {
1.1075.2.103 raeburn 17297: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17298: my %titles = &Apache::lonlocal::texthash (
17299: lastname => 'Last Name',
17300: firstname => 'First Name',
17301: institution => 'School/college/university',
17302: location => "School's city, state/province, country",
17303: web => "School's web address",
17304: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17305: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17306: );
17307: return (\@fields,\%titles);
17308: }
17309:
1.1075.2.56 raeburn 17310: sub cleanup_html {
17311: my ($incoming) = @_;
17312: my $outgoing;
17313: if ($incoming ne '') {
17314: $outgoing = $incoming;
17315: $outgoing =~ s/;/;/g;
17316: $outgoing =~ s/\#/#/g;
17317: $outgoing =~ s/\&/&/g;
17318: $outgoing =~ s/</</g;
17319: $outgoing =~ s/>/>/g;
17320: $outgoing =~ s/\(/(/g;
17321: $outgoing =~ s/\)/)/g;
17322: $outgoing =~ s/"/"/g;
17323: $outgoing =~ s/'/'/g;
17324: $outgoing =~ s/\$/$/g;
17325: $outgoing =~ s{/}{/}g;
17326: $outgoing =~ s/=/=/g;
17327: $outgoing =~ s/\\/\/g
17328: }
17329: return $outgoing;
17330: }
17331:
1.1075.2.74 raeburn 17332: # Checks for critical messages and returns a redirect url if one exists.
17333: # $interval indicates how often to check for messages.
1.1075.2.141. .6(raebu 17334:20): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 17335: sub critical_redirect {
1.1075.2.141. .6(raebu 17336:20): my ($interval,$context) = @_;
1.1075.2.74 raeburn 17337: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.141. .6(raebu 17338:20): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17339:20): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17340:20): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17341:20): my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17342:20): if ($blocked) {
17343:20): my $checkrole = "cm./$cdom/$cnum";
17344:20): if ($env{'request.course.sec'} ne '') {
17345:20): $checkrole .= "/$env{'request.course.sec'}";
17346:20): }
17347:20): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17348:20): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17349:20): return;
17350:20): }
17351:20): }
17352:20): }
1.1075.2.74 raeburn 17353: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17354: $env{'user.name'});
17355: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17356: my $redirecturl;
17357: if ($what[0]) {
17358: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17359: $redirecturl='/adm/email?critical=display';
17360: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17361: return (1, $url);
17362: }
17363: }
17364: }
17365: return ();
17366: }
17367:
1.1075.2.64 raeburn 17368: # Use:
17369: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17370: #
17371: ##################################################
17372: # password associated functions #
17373: ##################################################
17374: sub des_keys {
17375: # Make a new key for DES encryption.
17376: # Each key has two parts which are returned separately.
17377: # Please note: Each key must be passed through the &hex function
17378: # before it is output to the web browser. The hex versions cannot
17379: # be used to decrypt.
17380: my @hexstr=('0','1','2','3','4','5','6','7',
17381: '8','9','a','b','c','d','e','f');
17382: my $lkey='';
17383: for (0..7) {
17384: $lkey.=$hexstr[rand(15)];
17385: }
17386: my $ukey='';
17387: for (0..7) {
17388: $ukey.=$hexstr[rand(15)];
17389: }
17390: return ($lkey,$ukey);
17391: }
17392:
17393: sub des_decrypt {
17394: my ($key,$cyphertext) = @_;
17395: my $keybin=pack("H16",$key);
17396: my $cypher;
17397: if ($Crypt::DES::VERSION>=2.03) {
17398: $cypher=new Crypt::DES $keybin;
17399: } else {
17400: $cypher=new DES $keybin;
17401: }
1.1075.2.106 raeburn 17402: my $plaintext='';
17403: my $cypherlength = length($cyphertext);
17404: my $numchunks = int($cypherlength/32);
17405: for (my $j=0; $j<$numchunks; $j++) {
17406: my $start = $j*32;
17407: my $cypherblock = substr($cyphertext,$start,32);
17408: my $chunk =
17409: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17410: $chunk .=
17411: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17412: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17413: $plaintext .= $chunk;
17414: }
1.1075.2.64 raeburn 17415: return $plaintext;
17416: }
17417:
1.1075.2.141. .5(raebu 17418:20): sub get_requested_shorturls {
.1(raebu 17419:20): my ($cdom,$cnum,$navmap) = @_;
17420:20): return unless (ref($navmap));
.5(raebu 17421:20): my ($numnew,$errors);
.1(raebu 17422:20): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17423:20): if (@toshorten) {
17424:20): my (%maps,%resources,%titles);
17425:20): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17426:20): 'shorturls',$cdom,$cnum);
17427:20): if (keys(%resources)) {
.5(raebu 17428:20): my %tocreate;
.1(raebu 17429:20): foreach my $item (sort {$a <=> $b} (@toshorten)) {
17430:20): my $symb = $resources{$item};
17431:20): if ($symb) {
17432:20): $tocreate{$cnum.'&'.$symb} = 1;
17433:20): }
17434:20): }
.5(raebu 17435:20): if (keys(%tocreate)) {
17436:20): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
17437:20): \%tocreate);
17438:20): }
.1(raebu 17439:20): }
.5(raebu 17440:20): }
17441:20): return ($numnew,$errors);
17442:20): }
17443:20):
17444:20): sub make_short_symbs {
17445:20): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
17446:20): my ($numnew,@errors);
17447:20): if (ref($tocreateref) eq 'HASH') {
17448:20): my %tocreate = %{$tocreateref};
.1(raebu 17449:20): if (keys(%tocreate)) {
17450:20): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17451:20): my $su = Short::URL->new(no_vowels => 1);
17452:20): my $init = '';
17453:20): my (%newunique,%addcourse,%courseonly,%failed);
17454:20): # get lock on tiny db
17455:20): my $now = time;
.5(raebu 17456:20): if ($lockuser eq '') {
17457:20): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
17458:20): }
.1(raebu 17459:20): my $lockhash = {
.5(raebu 17460:20): "lock\0$now" => $lockuser,
.1(raebu 17461:20): };
17462:20): my $tries = 0;
17463:20): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17464:20): my ($code,$error);
17465:20): while (($gotlock ne 'ok') && ($tries<3)) {
17466:20): $tries ++;
17467:20): sleep 1;
17468:20): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17469:20): }
17470:20): if ($gotlock eq 'ok') {
17471:20): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17472:20): \%addcourse,\%courseonly,\%failed);
17473:20): if (keys(%failed)) {
17474:20): my $numfailed = scalar(keys(%failed));
17475:20): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17476:20): }
17477:20): if (keys(%newunique)) {
17478:20): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17479:20): if ($putres eq 'ok') {
17480:20): $numnew = scalar(keys(%newunique));
17481:20): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17482:20): unless ($newputres eq 'ok') {
17483:20): push(@errors,&mt('error: could not store course look-up of short URLs'));
17484:20): }
17485:20): } else {
17486:20): push(@errors,&mt('error: could not store unique six character URLs'));
17487:20): }
17488:20): }
17489:20): }
17490:20): }
17491:20): }
17492:20): return ($numnew,\@errors);
17493:20): }
17494:20):
17495:20): sub shorten_symbs {
17496:20): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
17497:20): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
17498:20): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
17499:20): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
17500:20): my (%possibles,%collisions);
17501:20): foreach my $key (keys(%{$tocreate})) {
17502:20): my $num = String::CRC32::crc32($key);
17503:20): my $tiny = $su->encode($num,$init);
17504:20): if ($tiny) {
17505:20): $possibles{$tiny} = $key;
17506:20): }
17507:20): }
17508:20): if (!$init) {
17509:20): $init = 1;
17510:20): } else {
17511:20): $init ++;
17512:20): }
17513:20): if (keys(%possibles)) {
17514:20): my @posstiny = keys(%possibles);
17515:20): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
17516:20): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
17517:20): if (keys(%currtiny)) {
17518:20): foreach my $key (keys(%currtiny)) {
17519:20): next if ($currtiny{$key} eq '');
17520:20): if ($currtiny{$key} eq $possibles{$key}) {
17521:20): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
17522:20): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17523:20): $courseonly->{$tsymb} = $key;
17524:20): }
17525:20): } else {
17526:20): $collisions{$possibles{$key}} = 1;
17527:20): }
17528:20): delete($possibles{$key});
17529:20): }
17530:20): }
17531:20): foreach my $key (keys(%possibles)) {
17532:20): $newunique->{$key} = $possibles{$key};
17533:20): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
17534:20): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17535:20): $addcourse->{$tsymb} = $key;
17536:20): }
17537:20): }
17538:20): }
17539:20): if (keys(%collisions)) {
17540:20): if ($init <5) {
17541:20): if (!$init) {
17542:20): $init = 1;
17543:20): } else {
17544:20): $init ++;
17545:20): }
17546:20): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
17547:20): $newunique,$addcourse,$courseonly,$failed);
17548:20): } else {
17549:20): foreach my $key (keys(%collisions)) {
17550:20): $failed->{$key} = 1;
17551:20): $failed->{$key} = 1;
17552:20): }
17553:20): }
17554:20): }
17555:20): return $init;
17556:20): }
17557:20):
1.1075.2.135 raeburn 17558: sub is_nonframeable {
17559: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17560: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17561: return if (($remprotocol eq '') || ($remhost eq ''));
17562:
17563: $remprotocol = lc($remprotocol);
17564: $remhost = lc($remhost);
17565: my $remport = 80;
17566: if ($remprotocol eq 'https') {
17567: $remport = 443;
17568: }
17569: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17570: if ($cached) {
17571: unless ($nocache) {
17572: if ($result) {
17573: return 1;
17574: } else {
17575: return 0;
17576: }
17577: }
17578: }
17579: my $uselink;
17580: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.141. .2(raebu 17581:20): my $ua = LWP::UserAgent->new;
17582:20): $ua->timeout(5);
17583:20): my $response=$ua->request($request);
1.1075.2.135 raeburn 17584: if ($response->is_success()) {
17585: my $secpolicy = lc($response->header('content-security-policy'));
17586: my $xframeop = lc($response->header('x-frame-options'));
17587: $secpolicy =~ s/^\s+|\s+$//g;
17588: $xframeop =~ s/^\s+|\s+$//g;
17589: if (($secpolicy ne '') || ($xframeop ne '')) {
17590: my $remotehost = $remprotocol.'://'.$remhost;
17591: my ($origin,$protocol,$port);
17592: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17593: $port = $ENV{'SERVER_PORT'};
17594: } else {
17595: $port = 80;
17596: }
17597: if ($absolute eq '') {
17598: $protocol = 'http:';
17599: if ($port == 443) {
17600: $protocol = 'https:';
17601: }
17602: $origin = $protocol.'//'.lc($hostname);
17603: } else {
17604: $origin = lc($absolute);
17605: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17606: }
17607: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17608: my $framepolicy = $1;
17609: $framepolicy =~ s/^\s+|\s+$//g;
17610: my @policies = split(/\s+/,$framepolicy);
17611: if (@policies) {
17612: if (grep(/^\Q'none'\E$/,@policies)) {
17613: $uselink = 1;
17614: } else {
17615: $uselink = 1;
17616: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17617: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17618: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17619: undef($uselink);
17620: }
17621: if ($uselink) {
17622: if (grep(/^\Q'self'\E$/,@policies)) {
17623: if (($origin ne '') && ($remotehost eq $origin)) {
17624: undef($uselink);
17625: }
17626: }
17627: }
17628: if ($uselink) {
17629: my @possok;
17630: if ($ip ne '') {
17631: push(@possok,$ip);
17632: }
17633: my $hoststr = '';
17634: foreach my $part (reverse(split(/\./,$hostname))) {
17635: if ($hoststr eq '') {
17636: $hoststr = $part;
17637: } else {
17638: $hoststr = "$part.$hoststr";
17639: }
17640: if ($hoststr eq $hostname) {
17641: push(@possok,$hostname);
17642: } else {
17643: push(@possok,"*.$hoststr");
17644: }
17645: }
17646: if (@possok) {
17647: foreach my $poss (@possok) {
17648: last if (!$uselink);
17649: foreach my $policy (@policies) {
17650: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17651: undef($uselink);
17652: last;
17653: }
17654: }
17655: }
17656: }
17657: }
17658: }
17659: }
17660: } elsif ($xframeop ne '') {
17661: $uselink = 1;
17662: my @policies = split(/\s*,\s*/,$xframeop);
17663: if (@policies) {
17664: unless (grep(/^deny$/,@policies)) {
17665: if ($origin ne '') {
17666: if (grep(/^sameorigin$/,@policies)) {
17667: if ($remotehost eq $origin) {
17668: undef($uselink);
17669: }
17670: }
17671: if ($uselink) {
17672: foreach my $policy (@policies) {
17673: if ($policy =~ /^allow-from\s*(.+)$/) {
17674: my $allowfrom = $1;
17675: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17676: undef($uselink);
17677: last;
17678: }
17679: }
17680: }
17681: }
17682: }
17683: }
17684: }
17685: }
17686: }
17687: }
17688: if ($nocache) {
17689: if ($cached) {
17690: my $devalidate;
17691: if ($uselink && !$result) {
17692: $devalidate = 1;
17693: } elsif (!$uselink && $result) {
17694: $devalidate = 1;
17695: }
17696: if ($devalidate) {
17697: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17698: }
17699: }
17700: } else {
17701: if ($uselink) {
17702: $result = 1;
17703: } else {
17704: $result = 0;
17705: }
17706: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17707: }
17708: return $uselink;
17709: }
17710:
1.112 bowersj2 17711: 1;
17712: __END__;
1.41 ng 17713:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>