Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.141.2.11
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. .11(raeb 4:-21): # $Id: loncommon.pm,v 1.1075.2.141.2.10 2020/11/13 02:50:39 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";
5048: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 5049: if (($activity eq 'port') || ($activity eq 'passwd')) {
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');
1.1062 raeburn 5091: }
1.1061 raeburn 5092: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5093: <div class='$class'>
1.869 kalberla 5094: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5095: title='$text'>
5096: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5097: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5098: title='$text'>$text</a>
1.867 kalberla 5099: </div>
5100:
5101: END_BLOCK
1.474 raeburn 5102:
1.1061 raeburn 5103: return ($blocked, $output);
1.854 kalberla 5104: }
1.490 raeburn 5105:
1.60 matthew 5106: ###############################################
5107:
1.682 raeburn 5108: sub check_ip_acc {
1.1075.2.105 raeburn 5109: my ($acc,$clientip)=@_;
1.682 raeburn 5110: &Apache::lonxml::debug("acc is $acc");
5111: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5112: return 1;
5113: }
1.1075.2.141. .4(raebu 5114:20): my ($ip,$allowed);
5115:20): if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5116:20): ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5117:20): $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5118:20): } else {
.11(raeb 5119:-21): my $remote_ip = &Apache::lonnet::get_requestor_ip();
5120:-21): $ip = $remote_ip || $env{'request.host'} || $clientip;
.4(raebu 5121:20): }
1.682 raeburn 5122:
5123: my $name;
1.1075.2.141. .1(raebu 5124:20): my %access = (
5125:20): allowfrom => 1,
5126:20): denyfrom => 0,
5127:20): );
5128:20): my @allows;
5129:20): my @denies;
5130:20): foreach my $item (split(',',$acc)) {
5131:20): $item =~ s/^\s*//;
5132:20): $item =~ s/\s*$//;
5133:20): if ($item =~ /^\!(.+)$/) {
5134:20): push(@denies,$1);
5135:20): } else {
5136:20): push(@allows,$item);
5137:20): }
5138:20): }
5139:20): my $numdenies = scalar(@denies);
5140:20): my $numallows = scalar(@allows);
5141:20): my $count = 0;
5142:20): foreach my $pattern (@denies,@allows) {
5143:20): $count ++;
5144:20): my $acctype = 'allowfrom';
5145:20): if ($count <= $numdenies) {
5146:20): $acctype = 'denyfrom';
5147:20): }
1.682 raeburn 5148: if ($pattern =~ /\*$/) {
5149: #35.8.*
5150: $pattern=~s/\*//;
1.1075.2.141. .1(raebu 5151:20): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5152: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5153: #35.8.3.[34-56]
5154: my $low=$2;
5155: my $high=$3;
5156: $pattern=$1;
5157: if ($ip =~ /^\Q$pattern\E/) {
5158: my $last=(split(/\./,$ip))[3];
1.1075.2.141. .1(raebu 5159:20): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5160: }
5161: } elsif ($pattern =~ /^\*/) {
5162: #*.msu.edu
5163: $pattern=~s/\*//;
5164: if (!defined($name)) {
5165: use Socket;
5166: my $netaddr=inet_aton($ip);
5167: ($name)=gethostbyaddr($netaddr,AF_INET);
5168: }
1.1075.2.141. .1(raebu 5169:20): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5170: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5171: #127.0.0.1
1.1075.2.141. .1(raebu 5172:20): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5173: } else {
5174: #some.name.com
5175: if (!defined($name)) {
5176: use Socket;
5177: my $netaddr=inet_aton($ip);
5178: ($name)=gethostbyaddr($netaddr,AF_INET);
5179: }
1.1075.2.141. .1(raebu 5180:20): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5181:20): }
5182:20): if ($allowed =~ /^(0|1)$/) { last; }
5183:20): }
5184:20): if ($allowed eq '') {
5185:20): if ($numdenies && !$numallows) {
5186:20): $allowed = 1;
5187:20): } else {
5188:20): $allowed = 0;
1.682 raeburn 5189: }
5190: }
5191: return $allowed;
5192: }
5193:
5194: ###############################################
5195:
1.60 matthew 5196: =pod
5197:
1.112 bowersj2 5198: =head1 Domain Template Functions
5199:
5200: =over 4
5201:
5202: =item * &determinedomain()
1.60 matthew 5203:
5204: Inputs: $domain (usually will be undef)
5205:
1.63 www 5206: Returns: Determines which domain should be used for designs
1.60 matthew 5207:
5208: =cut
1.54 www 5209:
1.60 matthew 5210: ###############################################
1.63 www 5211: sub determinedomain {
5212: my $domain=shift;
1.531 albertel 5213: if (! $domain) {
1.60 matthew 5214: # Determine domain if we have not been given one
1.893 raeburn 5215: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5216: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5217: if ($env{'request.role.domain'}) {
5218: $domain=$env{'request.role.domain'};
1.60 matthew 5219: }
5220: }
1.63 www 5221: return $domain;
5222: }
5223: ###############################################
1.517 raeburn 5224:
1.518 albertel 5225: sub devalidate_domconfig_cache {
5226: my ($udom)=@_;
5227: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5228: }
5229:
5230: # ---------------------- Get domain configuration for a domain
5231: sub get_domainconf {
5232: my ($udom) = @_;
5233: my $cachetime=1800;
5234: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5235: if (defined($cached)) { return %{$result}; }
5236:
5237: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5238: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5239: my (%designhash,%legacy);
1.518 albertel 5240: if (keys(%domconfig) > 0) {
5241: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5242: if (keys(%{$domconfig{'login'}})) {
5243: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5244: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5245: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5246: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5247: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5248: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5249: if ($key eq 'loginvia') {
5250: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5251: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5252: $designhash{$udom.'.login.loginvia'} = $server;
5253: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5254: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5255: } else {
5256: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5257: }
1.948 raeburn 5258: }
1.1075.2.87 raeburn 5259: } elsif ($key eq 'headtag') {
5260: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5261: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5262: }
1.946 raeburn 5263: }
1.1075.2.87 raeburn 5264: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5265: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5266: }
1.946 raeburn 5267: }
5268: }
5269: }
5270: } else {
5271: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5272: $designhash{$udom.'.login.'.$key.'_'.$img} =
5273: $domconfig{'login'}{$key}{$img};
5274: }
1.699 raeburn 5275: }
5276: } else {
5277: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5278: }
1.632 raeburn 5279: }
5280: } else {
5281: $legacy{'login'} = 1;
1.518 albertel 5282: }
1.632 raeburn 5283: } else {
5284: $legacy{'login'} = 1;
1.518 albertel 5285: }
5286: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5287: if (keys(%{$domconfig{'rolecolors'}})) {
5288: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5289: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5290: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5291: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5292: }
1.518 albertel 5293: }
5294: }
1.632 raeburn 5295: } else {
5296: $legacy{'rolecolors'} = 1;
1.518 albertel 5297: }
1.632 raeburn 5298: } else {
5299: $legacy{'rolecolors'} = 1;
1.518 albertel 5300: }
1.948 raeburn 5301: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5302: if ($domconfig{'autoenroll'}{'co-owners'}) {
5303: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5304: }
5305: }
1.632 raeburn 5306: if (keys(%legacy) > 0) {
5307: my %legacyhash = &get_legacy_domconf($udom);
5308: foreach my $item (keys(%legacyhash)) {
5309: if ($item =~ /^\Q$udom\E\.login/) {
5310: if ($legacy{'login'}) {
5311: $designhash{$item} = $legacyhash{$item};
5312: }
5313: } else {
5314: if ($legacy{'rolecolors'}) {
5315: $designhash{$item} = $legacyhash{$item};
5316: }
1.518 albertel 5317: }
5318: }
5319: }
1.632 raeburn 5320: } else {
5321: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5322: }
5323: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5324: $cachetime);
5325: return %designhash;
5326: }
5327:
1.632 raeburn 5328: sub get_legacy_domconf {
5329: my ($udom) = @_;
5330: my %legacyhash;
5331: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5332: my $designfile = $designdir.'/'.$udom.'.tab';
5333: if (-e $designfile) {
1.1075.2.128 raeburn 5334: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5335: while (my $line = <$fh>) {
5336: next if ($line =~ /^\#/);
5337: chomp($line);
5338: my ($key,$val)=(split(/\=/,$line));
5339: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5340: }
5341: close($fh);
5342: }
5343: }
1.1026 raeburn 5344: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5345: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5346: }
5347: return %legacyhash;
5348: }
5349:
1.63 www 5350: =pod
5351:
1.112 bowersj2 5352: =item * &domainlogo()
1.63 www 5353:
5354: Inputs: $domain (usually will be undef)
5355:
5356: Returns: A link to a domain logo, if the domain logo exists.
5357: If the domain logo does not exist, a description of the domain.
5358:
5359: =cut
1.112 bowersj2 5360:
1.63 www 5361: ###############################################
5362: sub domainlogo {
1.517 raeburn 5363: my $domain = &determinedomain(shift);
1.518 albertel 5364: my %designhash = &get_domainconf($domain);
1.517 raeburn 5365: # See if there is a logo
5366: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5367: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5368: if ($imgsrc =~ m{^/(adm|res)/}) {
5369: if ($imgsrc =~ m{^/res/}) {
5370: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5371: &Apache::lonnet::repcopy($local_name);
5372: }
5373: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5374: }
5375: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5376: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5377: return &Apache::lonnet::domain($domain,'description');
1.59 www 5378: } else {
1.60 matthew 5379: return '';
1.59 www 5380: }
5381: }
1.63 www 5382: ##############################################
5383:
5384: =pod
5385:
1.112 bowersj2 5386: =item * &designparm()
1.63 www 5387:
5388: Inputs: $which parameter; $domain (usually will be undef)
5389:
5390: Returns: value of designparamter $which
5391:
5392: =cut
1.112 bowersj2 5393:
1.397 albertel 5394:
1.400 albertel 5395: ##############################################
1.397 albertel 5396: sub designparm {
5397: my ($which,$domain)=@_;
5398: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5399: return $env{'environment.color.'.$which};
1.96 www 5400: }
1.63 www 5401: $domain=&determinedomain($domain);
1.1016 raeburn 5402: my %domdesign;
5403: unless ($domain eq 'public') {
5404: %domdesign = &get_domainconf($domain);
5405: }
1.520 raeburn 5406: my $output;
1.517 raeburn 5407: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5408: $output = $domdesign{$domain.'.'.$which};
1.63 www 5409: } else {
1.520 raeburn 5410: $output = $defaultdesign{$which};
5411: }
5412: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5413: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5414: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5415: if ($output =~ m{^/res/}) {
5416: my $local_name = &Apache::lonnet::filelocation('',$output);
5417: &Apache::lonnet::repcopy($local_name);
5418: }
1.520 raeburn 5419: $output = &lonhttpdurl($output);
5420: }
1.63 www 5421: }
1.520 raeburn 5422: return $output;
1.63 www 5423: }
1.59 www 5424:
1.822 bisitz 5425: ##############################################
5426: =pod
5427:
1.832 bisitz 5428: =item * &authorspace()
5429:
1.1028 raeburn 5430: Inputs: $url (usually will be undef).
1.832 bisitz 5431:
1.1075.2.40 raeburn 5432: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5433: directory being viewed (or for which action is being taken).
5434: If $url is provided, and begins /priv/<domain>/<uname>
5435: the path will be that portion of the $context argument.
5436: Otherwise the path will be for the author space of the current
5437: user when the current role is author, or for that of the
5438: co-author/assistant co-author space when the current role
5439: is co-author or assistant co-author.
1.832 bisitz 5440:
5441: =cut
5442:
5443: sub authorspace {
1.1028 raeburn 5444: my ($url) = @_;
5445: if ($url ne '') {
5446: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5447: return $1;
5448: }
5449: }
1.832 bisitz 5450: my $caname = '';
1.1024 www 5451: my $cadom = '';
1.1028 raeburn 5452: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5453: ($cadom,$caname) =
1.832 bisitz 5454: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5455: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5456: $caname = $env{'user.name'};
1.1024 www 5457: $cadom = $env{'user.domain'};
1.832 bisitz 5458: }
1.1028 raeburn 5459: if (($caname ne '') && ($cadom ne '')) {
5460: return "/priv/$cadom/$caname/";
5461: }
5462: return;
1.832 bisitz 5463: }
5464:
5465: ##############################################
5466: =pod
5467:
1.822 bisitz 5468: =item * &head_subbox()
5469:
5470: Inputs: $content (contains HTML code with page functions, etc.)
5471:
5472: Returns: HTML div with $content
5473: To be included in page header
5474:
5475: =cut
5476:
5477: sub head_subbox {
5478: my ($content)=@_;
5479: my $output =
1.993 raeburn 5480: '<div class="LC_head_subbox">'
1.822 bisitz 5481: .$content
5482: .'</div>'
5483: }
5484:
5485: ##############################################
5486: =pod
5487:
5488: =item * &CSTR_pageheader()
5489:
1.1026 raeburn 5490: Input: (optional) filename from which breadcrumb trail is built.
5491: In most cases no input as needed, as $env{'request.filename'}
5492: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5493:
5494: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5495: To be included on Authoring Space pages
1.822 bisitz 5496:
5497: =cut
5498:
5499: sub CSTR_pageheader {
1.1026 raeburn 5500: my ($trailfile) = @_;
5501: if ($trailfile eq '') {
5502: $trailfile = $env{'request.filename'};
5503: }
5504:
5505: # this is for resources; directories have customtitle, and crumbs
5506: # and select recent are created in lonpubdir.pm
5507:
5508: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5509: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5510: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5511: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5512: $formaction =~ s{/+}{/}g;
1.822 bisitz 5513:
5514: my $parentpath = '';
5515: my $lastitem = '';
5516: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5517: $parentpath = $1;
5518: $lastitem = $2;
5519: } else {
5520: $lastitem = $thisdisfn;
5521: }
1.921 bisitz 5522:
5523: my $output =
1.822 bisitz 5524: '<div>'
5525: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5526: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5527: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5528: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5529: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5530:
5531: if ($lastitem) {
5532: $output .=
5533: '<span class="LC_filename">'
5534: .$lastitem
5535: .'</span>';
5536: }
5537: $output .=
5538: '<br />'
1.822 bisitz 5539: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5540: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5541: .'</form>'
5542: .&Apache::lonmenu::constspaceform()
5543: .'</div>';
1.921 bisitz 5544:
5545: return $output;
1.822 bisitz 5546: }
5547:
1.60 matthew 5548: ###############################################
5549: ###############################################
5550:
5551: =pod
5552:
1.112 bowersj2 5553: =back
5554:
1.549 albertel 5555: =head1 HTML Helpers
1.112 bowersj2 5556:
5557: =over 4
5558:
5559: =item * &bodytag()
1.60 matthew 5560:
5561: Returns a uniform header for LON-CAPA web pages.
5562:
5563: Inputs:
5564:
1.112 bowersj2 5565: =over 4
5566:
5567: =item * $title, A title to be displayed on the page.
5568:
5569: =item * $function, the current role (can be undef).
5570:
5571: =item * $addentries, extra parameters for the <body> tag.
5572:
5573: =item * $bodyonly, if defined, only return the <body> tag.
5574:
5575: =item * $domain, if defined, force a given domain.
5576:
5577: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5578: text interface only)
1.60 matthew 5579:
1.814 bisitz 5580: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5581: navigational links
1.317 albertel 5582:
1.338 albertel 5583: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5584:
1.1075.2.12 raeburn 5585: =item * $no_inline_link, if true and in remote mode, don't show the
5586: 'Switch To Inline Menu' link
5587:
1.460 albertel 5588: =item * $args, optional argument valid values are
5589: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5590: use_absolute -> for external resource or syllabus, this will
5591: contain https://<hostname> if server uses
5592: https (as per hosts.tab), but request is for http
5593: hostname -> hostname, from $r->hostname().
1.460 albertel 5594:
1.1075.2.15 raeburn 5595: =item * $advtoolsref, optional argument, ref to an array containing
5596: inlineremote items to be added in "Functions" menu below
5597: breadcrumbs.
5598:
1.112 bowersj2 5599: =back
5600:
1.60 matthew 5601: Returns: A uniform header for LON-CAPA web pages.
5602: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5603: If $bodyonly is undef or zero, an html string containing a <body> tag and
5604: other decorations will be returned.
5605:
5606: =cut
5607:
1.54 www 5608: sub bodytag {
1.831 bisitz 5609: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5610: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5611:
1.954 raeburn 5612: my $public;
5613: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5614: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5615: $public = 1;
5616: }
1.460 albertel 5617: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5618: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5619: my $hostname = $args->{'hostname'};
1.339 albertel 5620:
1.183 matthew 5621: $function = &get_users_function() if (!$function);
1.339 albertel 5622: my $img = &designparm($function.'.img',$domain);
5623: my $font = &designparm($function.'.font',$domain);
5624: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5625:
1.803 bisitz 5626: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5627: 'bgcolor' => $pgbg,
1.339 albertel 5628: 'text' => $font,
5629: 'alink' => &designparm($function.'.alink',$domain),
5630: 'vlink' => &designparm($function.'.vlink',$domain),
5631: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5632: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5633:
1.63 www 5634: # role and realm
1.1075.2.68 raeburn 5635: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5636: if ($realm) {
5637: $realm = '/'.$realm;
5638: }
1.378 raeburn 5639: if ($role eq 'ca') {
1.479 albertel 5640: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5641: $realm = &plainname($rname,$rdom);
1.378 raeburn 5642: }
1.55 www 5643: # realm
1.258 albertel 5644: if ($env{'request.course.id'}) {
1.378 raeburn 5645: if ($env{'request.role'} !~ /^cr/) {
5646: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5647: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5648: if ($env{'request.role.desc'}) {
5649: $role = $env{'request.role.desc'};
5650: } else {
5651: $role = &mt('Helpdesk[_1]',' '.$2);
5652: }
1.1075.2.115 raeburn 5653: } else {
5654: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5655: }
1.898 raeburn 5656: if ($env{'request.course.sec'}) {
5657: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5658: }
1.359 albertel 5659: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5660: } else {
5661: $role = &Apache::lonnet::plaintext($role);
1.54 www 5662: }
1.433 albertel 5663:
1.359 albertel 5664: if (!$realm) { $realm=' '; }
1.330 albertel 5665:
1.438 albertel 5666: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5667:
1.101 www 5668: # construct main body tag
1.359 albertel 5669: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5670: &Apache::lontexconvert::init_math_support();
1.252 albertel 5671:
1.1075.2.38 raeburn 5672: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5673:
5674: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5675: return $bodytag;
1.1075.2.38 raeburn 5676: }
1.359 albertel 5677:
1.954 raeburn 5678: if ($public) {
1.433 albertel 5679: undef($role);
5680: }
1.359 albertel 5681:
1.762 bisitz 5682: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5683: #
5684: # Extra info if you are the DC
5685: my $dc_info = '';
5686: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5687: $env{'course.'.$env{'request.course.id'}.
5688: '.domain'}.'/'})) {
5689: my $cid = $env{'request.course.id'};
1.917 raeburn 5690: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5691: $dc_info =~ s/\s+$//;
1.359 albertel 5692: }
5693:
1.1075.2.108 raeburn 5694: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5695:
1.1075.2.13 raeburn 5696: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5697:
1.1075.2.38 raeburn 5698:
5699:
1.1075.2.21 raeburn 5700: my $funclist;
5701: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5702: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5703: Apache::lonmenu::serverform();
5704: my $forbodytag;
5705: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5706: $forcereg,$args->{'group'},
5707: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5708: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5709: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5710: $funclist = $forbodytag;
5711: }
5712: } else {
1.903 droeschl 5713:
5714: # if ($env{'request.state'} eq 'construct') {
5715: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5716: # }
5717:
1.1075.2.38 raeburn 5718: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5719: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5720:
1.1075.2.38 raeburn 5721: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5722:
1.916 droeschl 5723: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5724: if ($dc_info) {
5725: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5726: }
1.1075.2.38 raeburn 5727: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5728: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5729: return $bodytag;
5730: }
1.894 droeschl 5731:
1.927 raeburn 5732: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5733: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5734: }
1.916 droeschl 5735:
1.1075.2.38 raeburn 5736: $bodytag .= $right;
1.852 droeschl 5737:
1.917 raeburn 5738: if ($dc_info) {
5739: $dc_info = &dc_courseid_toggle($dc_info);
5740: }
5741: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5742:
1.1075.2.61 raeburn 5743: #if directed to not display the secondary menu, don't.
5744: if ($args->{'no_secondary_menu'}) {
5745: return $bodytag;
5746: }
1.903 droeschl 5747: #don't show menus for public users
1.954 raeburn 5748: if (!$public){
1.1075.2.52 raeburn 5749: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5750: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5751: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5752: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5753: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5754: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5755: } elsif ($forcereg) {
1.1075.2.22 raeburn 5756: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5757: $args->{'group'},
1.1075.2.133 raeburn 5758: $args->{'hide_buttons',
5759: $hostname});
1.1075.2.15 raeburn 5760: } else {
1.1075.2.21 raeburn 5761: my $forbodytag;
5762: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5763: $forcereg,$args->{'group'},
5764: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5765: $advtoolsref,'',$hostname,
5766: \$forbodytag);
1.1075.2.21 raeburn 5767: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5768: $bodytag .= $forbodytag;
5769: }
1.920 raeburn 5770: }
1.903 droeschl 5771: }else{
5772: # this is to seperate menu from content when there's no secondary
5773: # menu. Especially needed for public accessible ressources.
5774: $bodytag .= '<hr style="clear:both" />';
5775: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5776: }
1.903 droeschl 5777:
1.235 raeburn 5778: return $bodytag;
1.1075.2.12 raeburn 5779: }
5780:
5781: #
5782: # Top frame rendering, Remote is up
5783: #
5784:
5785: my $imgsrc = $img;
5786: if ($img =~ /^\/adm/) {
5787: $imgsrc = &lonhttpdurl($img);
5788: }
5789: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5790:
1.1075.2.60 raeburn 5791: my $help=($no_inline_link?''
5792: :&Apache::loncommon::top_nav_help('Help'));
5793:
1.1075.2.12 raeburn 5794: # Explicit link to get inline menu
5795: my $menu= ($no_inline_link?''
5796: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5797:
5798: if ($dc_info) {
5799: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5800: }
5801:
1.1075.2.38 raeburn 5802: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5803: unless ($public) {
5804: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5805: undef,'LC_menubuttons_link');
5806: }
5807:
1.1075.2.12 raeburn 5808: unless ($env{'form.inhibitmenu'}) {
5809: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5810: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5811: <li>$help</li>
1.1075.2.12 raeburn 5812: <li>$menu</li>
5813: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5814: }
1.1075.2.13 raeburn 5815: if ($env{'request.state'} eq 'construct') {
5816: if (!$public){
5817: if ($env{'request.state'} eq 'construct') {
5818: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5819: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5820: &Apache::lonhtmlcommon::scripttag('','end').
5821: &Apache::lonmenu::innerregister($forcereg,
5822: $args->{'bread_crumbs'});
5823: }
5824: }
5825: }
1.1075.2.21 raeburn 5826: return $bodytag."\n".$funclist;
1.182 matthew 5827: }
5828:
1.917 raeburn 5829: sub dc_courseid_toggle {
5830: my ($dc_info) = @_;
1.980 raeburn 5831: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5832: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5833: &mt('(More ...)').'</a></span>'.
5834: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5835: }
5836:
1.330 albertel 5837: sub make_attr_string {
5838: my ($register,$attr_ref) = @_;
5839:
5840: if ($attr_ref && !ref($attr_ref)) {
5841: die("addentries Must be a hash ref ".
5842: join(':',caller(1))." ".
5843: join(':',caller(0))." ");
5844: }
5845:
5846: if ($register) {
1.339 albertel 5847: my ($on_load,$on_unload);
5848: foreach my $key (keys(%{$attr_ref})) {
5849: if (lc($key) eq 'onload') {
5850: $on_load.=$attr_ref->{$key}.';';
5851: delete($attr_ref->{$key});
5852:
5853: } elsif (lc($key) eq 'onunload') {
5854: $on_unload.=$attr_ref->{$key}.';';
5855: delete($attr_ref->{$key});
5856: }
5857: }
1.1075.2.12 raeburn 5858: if ($env{'environment.remote'} eq 'on') {
5859: $attr_ref->{'onload'} =
5860: &Apache::lonmenu::loadevents(). $on_load;
5861: $attr_ref->{'onunload'}=
5862: &Apache::lonmenu::unloadevents().$on_unload;
5863: } else {
5864: $attr_ref->{'onload'} = $on_load;
5865: $attr_ref->{'onunload'}= $on_unload;
5866: }
1.330 albertel 5867: }
1.339 albertel 5868:
1.330 albertel 5869: my $attr_string;
1.1075.2.56 raeburn 5870: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5871: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5872: }
5873: return $attr_string;
5874: }
5875:
5876:
1.182 matthew 5877: ###############################################
1.251 albertel 5878: ###############################################
5879:
5880: =pod
5881:
5882: =item * &endbodytag()
5883:
5884: Returns a uniform footer for LON-CAPA web pages.
5885:
1.635 raeburn 5886: Inputs: 1 - optional reference to an args hash
5887: If in the hash, key for noredirectlink has a value which evaluates to true,
5888: a 'Continue' link is not displayed if the page contains an
5889: internal redirect in the <head></head> section,
5890: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5891:
5892: =cut
5893:
5894: sub endbodytag {
1.635 raeburn 5895: my ($args) = @_;
1.1075.2.6 raeburn 5896: my $endbodytag;
5897: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5898: $endbodytag='</body>';
5899: }
1.315 albertel 5900: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5901: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5902: $endbodytag=
5903: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5904: &mt('Continue').'</a>'.
5905: $endbodytag;
5906: }
1.315 albertel 5907: }
1.251 albertel 5908: return $endbodytag;
5909: }
5910:
1.352 albertel 5911: =pod
5912:
5913: =item * &standard_css()
5914:
5915: Returns a style sheet
5916:
5917: Inputs: (all optional)
5918: domain -> force to color decorate a page for a specific
5919: domain
5920: function -> force usage of a specific rolish color scheme
5921: bgcolor -> override the default page bgcolor
5922:
5923: =cut
5924:
1.343 albertel 5925: sub standard_css {
1.345 albertel 5926: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5927: $function = &get_users_function() if (!$function);
5928: my $img = &designparm($function.'.img', $domain);
5929: my $tabbg = &designparm($function.'.tabbg', $domain);
5930: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5931: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5932: #second colour for later usage
1.345 albertel 5933: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5934: my $pgbg_or_bgcolor =
5935: $bgcolor ||
1.352 albertel 5936: &designparm($function.'.pgbg', $domain);
1.382 albertel 5937: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5938: my $alink = &designparm($function.'.alink', $domain);
5939: my $vlink = &designparm($function.'.vlink', $domain);
5940: my $link = &designparm($function.'.link', $domain);
5941:
1.602 albertel 5942: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5943: my $mono = 'monospace';
1.850 bisitz 5944: my $data_table_head = $sidebg;
5945: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5946: my $data_table_dark = '#E0E0E0';
1.470 banghart 5947: my $data_table_darker = '#CCCCCC';
1.349 albertel 5948: my $data_table_highlight = '#FFFF00';
1.352 albertel 5949: my $mail_new = '#FFBB77';
5950: my $mail_new_hover = '#DD9955';
5951: my $mail_read = '#BBBB77';
5952: my $mail_read_hover = '#999944';
5953: my $mail_replied = '#AAAA88';
5954: my $mail_replied_hover = '#888855';
5955: my $mail_other = '#99BBBB';
5956: my $mail_other_hover = '#669999';
1.391 albertel 5957: my $table_header = '#DDDDDD';
1.489 raeburn 5958: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5959: my $lg_border_color = '#C8C8C8';
1.952 onken 5960: my $button_hover = '#BF2317';
1.392 albertel 5961:
1.608 albertel 5962: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5963: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5964: : '0 3px 0 4px';
1.448 albertel 5965:
1.523 albertel 5966:
1.343 albertel 5967: return <<END;
1.947 droeschl 5968:
5969: /* needed for iframe to allow 100% height in FF */
5970: body, html {
5971: margin: 0;
5972: padding: 0 0.5%;
5973: height: 99%; /* to avoid scrollbars */
5974: }
5975:
1.795 www 5976: body {
1.911 bisitz 5977: font-family: $sans;
5978: line-height:130%;
5979: font-size:0.83em;
5980: color:$font;
1.795 www 5981: }
5982:
1.959 onken 5983: a:focus,
5984: a:focus img {
1.795 www 5985: color: red;
5986: }
1.698 harmsja 5987:
1.911 bisitz 5988: form, .inline {
5989: display: inline;
1.795 www 5990: }
1.721 harmsja 5991:
1.795 www 5992: .LC_right {
1.911 bisitz 5993: text-align:right;
1.795 www 5994: }
5995:
5996: .LC_middle {
1.911 bisitz 5997: vertical-align:middle;
1.795 www 5998: }
1.721 harmsja 5999:
1.1075.2.38 raeburn 6000: .LC_floatleft {
6001: float: left;
6002: }
6003:
6004: .LC_floatright {
6005: float: right;
6006: }
6007:
1.911 bisitz 6008: .LC_400Box {
6009: width:400px;
6010: }
1.721 harmsja 6011:
1.947 droeschl 6012: .LC_iframecontainer {
6013: width: 98%;
6014: margin: 0;
6015: position: fixed;
6016: top: 8.5em;
6017: bottom: 0;
6018: }
6019:
6020: .LC_iframecontainer iframe{
6021: border: none;
6022: width: 100%;
6023: height: 100%;
6024: }
6025:
1.778 bisitz 6026: .LC_filename {
6027: font-family: $mono;
6028: white-space:pre;
1.921 bisitz 6029: font-size: 120%;
1.778 bisitz 6030: }
6031:
6032: .LC_fileicon {
6033: border: none;
6034: height: 1.3em;
6035: vertical-align: text-bottom;
6036: margin-right: 0.3em;
6037: text-decoration:none;
6038: }
6039:
1.1008 www 6040: .LC_setting {
6041: text-decoration:underline;
6042: }
6043:
1.350 albertel 6044: .LC_error {
6045: color: red;
6046: }
1.795 www 6047:
1.1075.2.15 raeburn 6048: .LC_warning {
6049: color: darkorange;
6050: }
6051:
1.457 albertel 6052: .LC_diff_removed {
1.733 bisitz 6053: color: red;
1.394 albertel 6054: }
1.532 albertel 6055:
6056: .LC_info,
1.457 albertel 6057: .LC_success,
6058: .LC_diff_added {
1.350 albertel 6059: color: green;
6060: }
1.795 www 6061:
1.802 bisitz 6062: div.LC_confirm_box {
6063: background-color: #FAFAFA;
6064: border: 1px solid $lg_border_color;
6065: margin-right: 0;
6066: padding: 5px;
6067: }
6068:
6069: div.LC_confirm_box .LC_error img,
6070: div.LC_confirm_box .LC_success img {
6071: vertical-align: middle;
6072: }
6073:
1.1075.2.108 raeburn 6074: .LC_maxwidth {
6075: max-width: 100%;
6076: height: auto;
6077: }
6078:
6079: .LC_textsize_mobile {
6080: \@media only screen and (max-device-width: 480px) {
6081: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6082: }
6083: }
6084:
1.440 albertel 6085: .LC_icon {
1.771 droeschl 6086: border: none;
1.790 droeschl 6087: vertical-align: middle;
1.771 droeschl 6088: }
6089:
1.543 albertel 6090: .LC_docs_spacer {
6091: width: 25px;
6092: height: 1px;
1.771 droeschl 6093: border: none;
1.543 albertel 6094: }
1.346 albertel 6095:
1.532 albertel 6096: .LC_internal_info {
1.735 bisitz 6097: color: #999999;
1.532 albertel 6098: }
6099:
1.794 www 6100: .LC_discussion {
1.1050 www 6101: background: $data_table_dark;
1.911 bisitz 6102: border: 1px solid black;
6103: margin: 2px;
1.794 www 6104: }
6105:
6106: .LC_disc_action_left {
1.1050 www 6107: background: $sidebg;
1.911 bisitz 6108: text-align: left;
1.1050 www 6109: padding: 4px;
6110: margin: 2px;
1.794 www 6111: }
6112:
6113: .LC_disc_action_right {
1.1050 www 6114: background: $sidebg;
1.911 bisitz 6115: text-align: right;
1.1050 www 6116: padding: 4px;
6117: margin: 2px;
1.794 www 6118: }
6119:
6120: .LC_disc_new_item {
1.911 bisitz 6121: background: white;
6122: border: 2px solid red;
1.1050 www 6123: margin: 4px;
6124: padding: 4px;
1.794 www 6125: }
6126:
6127: .LC_disc_old_item {
1.911 bisitz 6128: background: white;
1.1050 www 6129: margin: 4px;
6130: padding: 4px;
1.794 www 6131: }
6132:
1.458 albertel 6133: table.LC_pastsubmission {
6134: border: 1px solid black;
6135: margin: 2px;
6136: }
6137:
1.924 bisitz 6138: table#LC_menubuttons {
1.345 albertel 6139: width: 100%;
6140: background: $pgbg;
1.392 albertel 6141: border: 2px;
1.402 albertel 6142: border-collapse: separate;
1.803 bisitz 6143: padding: 0;
1.345 albertel 6144: }
1.392 albertel 6145:
1.801 tempelho 6146: table#LC_title_bar a {
6147: color: $fontmenu;
6148: }
1.836 bisitz 6149:
1.807 droeschl 6150: table#LC_title_bar {
1.819 tempelho 6151: clear: both;
1.836 bisitz 6152: display: none;
1.807 droeschl 6153: }
6154:
1.795 www 6155: table#LC_title_bar,
1.933 droeschl 6156: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6157: table#LC_title_bar.LC_with_remote {
1.359 albertel 6158: width: 100%;
1.392 albertel 6159: border-color: $pgbg;
6160: border-style: solid;
6161: border-width: $border;
1.379 albertel 6162: background: $pgbg;
1.801 tempelho 6163: color: $fontmenu;
1.392 albertel 6164: border-collapse: collapse;
1.803 bisitz 6165: padding: 0;
1.819 tempelho 6166: margin: 0;
1.359 albertel 6167: }
1.795 www 6168:
1.933 droeschl 6169: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6170: margin: 0;
6171: padding: 0;
1.933 droeschl 6172: position: relative;
6173: list-style: none;
1.913 droeschl 6174: }
1.933 droeschl 6175: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6176: display: inline;
6177: }
1.933 droeschl 6178:
6179: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6180: padding: 0;
1.933 droeschl 6181: margin: 0;
6182: float: left;
1.913 droeschl 6183: }
1.933 droeschl 6184: .LC_breadcrumb_tools_tools {
6185: padding: 0;
6186: margin: 0;
1.913 droeschl 6187: float: right;
6188: }
6189:
1.359 albertel 6190: table#LC_title_bar td {
6191: background: $tabbg;
6192: }
1.795 www 6193:
1.911 bisitz 6194: table#LC_menubuttons img {
1.803 bisitz 6195: border: none;
1.346 albertel 6196: }
1.795 www 6197:
1.842 droeschl 6198: .LC_breadcrumbs_component {
1.911 bisitz 6199: float: right;
6200: margin: 0 1em;
1.357 albertel 6201: }
1.842 droeschl 6202: .LC_breadcrumbs_component img {
1.911 bisitz 6203: vertical-align: middle;
1.777 tempelho 6204: }
1.795 www 6205:
1.1075.2.108 raeburn 6206: .LC_breadcrumbs_hoverable {
6207: background: $sidebg;
6208: }
6209:
1.383 albertel 6210: td.LC_table_cell_checkbox {
6211: text-align: center;
6212: }
1.795 www 6213:
6214: .LC_fontsize_small {
1.911 bisitz 6215: font-size: 70%;
1.705 tempelho 6216: }
6217:
1.844 bisitz 6218: #LC_breadcrumbs {
1.911 bisitz 6219: clear:both;
6220: background: $sidebg;
6221: border-bottom: 1px solid $lg_border_color;
6222: line-height: 2.5em;
1.933 droeschl 6223: overflow: hidden;
1.911 bisitz 6224: margin: 0;
6225: padding: 0;
1.995 raeburn 6226: text-align: left;
1.819 tempelho 6227: }
1.862 bisitz 6228:
1.1075.2.16 raeburn 6229: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6230: clear:both;
6231: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6232: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6233: margin: 0 0 10px 0;
1.966 bisitz 6234: padding: 3px;
1.995 raeburn 6235: text-align: left;
1.822 bisitz 6236: }
6237:
1.795 www 6238: .LC_fontsize_medium {
1.911 bisitz 6239: font-size: 85%;
1.705 tempelho 6240: }
6241:
1.795 www 6242: .LC_fontsize_large {
1.911 bisitz 6243: font-size: 120%;
1.705 tempelho 6244: }
6245:
1.346 albertel 6246: .LC_menubuttons_inline_text {
6247: color: $font;
1.698 harmsja 6248: font-size: 90%;
1.701 harmsja 6249: padding-left:3px;
1.346 albertel 6250: }
6251:
1.934 droeschl 6252: .LC_menubuttons_inline_text img{
6253: vertical-align: middle;
6254: }
6255:
1.1051 www 6256: li.LC_menubuttons_inline_text img {
1.951 onken 6257: cursor:pointer;
1.1002 droeschl 6258: text-decoration: none;
1.951 onken 6259: }
6260:
1.526 www 6261: .LC_menubuttons_link {
6262: text-decoration: none;
6263: }
1.795 www 6264:
1.522 albertel 6265: .LC_menubuttons_category {
1.521 www 6266: color: $font;
1.526 www 6267: background: $pgbg;
1.521 www 6268: font-size: larger;
6269: font-weight: bold;
6270: }
6271:
1.346 albertel 6272: td.LC_menubuttons_text {
1.911 bisitz 6273: color: $font;
1.346 albertel 6274: }
1.706 harmsja 6275:
1.346 albertel 6276: .LC_current_location {
6277: background: $tabbg;
6278: }
1.795 www 6279:
1.1075.2.134 raeburn 6280: td.LC_zero_height {
6281: line-height: 0;
6282: cellpadding: 0;
6283: }
6284:
1.938 bisitz 6285: table.LC_data_table {
1.347 albertel 6286: border: 1px solid #000000;
1.402 albertel 6287: border-collapse: separate;
1.426 albertel 6288: border-spacing: 1px;
1.610 albertel 6289: background: $pgbg;
1.347 albertel 6290: }
1.795 www 6291:
1.422 albertel 6292: .LC_data_table_dense {
6293: font-size: small;
6294: }
1.795 www 6295:
1.507 raeburn 6296: table.LC_nested_outer {
6297: border: 1px solid #000000;
1.589 raeburn 6298: border-collapse: collapse;
1.803 bisitz 6299: border-spacing: 0;
1.507 raeburn 6300: width: 100%;
6301: }
1.795 www 6302:
1.879 raeburn 6303: table.LC_innerpickbox,
1.507 raeburn 6304: table.LC_nested {
1.803 bisitz 6305: border: none;
1.589 raeburn 6306: border-collapse: collapse;
1.803 bisitz 6307: border-spacing: 0;
1.507 raeburn 6308: width: 100%;
6309: }
1.795 www 6310:
1.911 bisitz 6311: table.LC_data_table tr th,
6312: table.LC_calendar tr th,
1.879 raeburn 6313: table.LC_prior_tries tr th,
6314: table.LC_innerpickbox tr th {
1.349 albertel 6315: font-weight: bold;
6316: background-color: $data_table_head;
1.801 tempelho 6317: color:$fontmenu;
1.701 harmsja 6318: font-size:90%;
1.347 albertel 6319: }
1.795 www 6320:
1.879 raeburn 6321: table.LC_innerpickbox tr th,
6322: table.LC_innerpickbox tr td {
6323: vertical-align: top;
6324: }
6325:
1.711 raeburn 6326: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6327: background-color: #CCCCCC;
1.711 raeburn 6328: font-weight: bold;
6329: text-align: left;
6330: }
1.795 www 6331:
1.912 bisitz 6332: table.LC_data_table tr.LC_odd_row > td {
6333: background-color: $data_table_light;
6334: padding: 2px;
6335: vertical-align: top;
6336: }
6337:
1.809 bisitz 6338: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6339: background-color: $data_table_light;
1.912 bisitz 6340: vertical-align: top;
6341: }
6342:
6343: table.LC_data_table tr.LC_even_row > td {
6344: background-color: $data_table_dark;
1.425 albertel 6345: padding: 2px;
1.900 bisitz 6346: vertical-align: top;
1.347 albertel 6347: }
1.795 www 6348:
1.809 bisitz 6349: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6350: background-color: $data_table_dark;
1.900 bisitz 6351: vertical-align: top;
1.347 albertel 6352: }
1.795 www 6353:
1.425 albertel 6354: table.LC_data_table tr.LC_data_table_highlight td {
6355: background-color: $data_table_darker;
6356: }
1.795 www 6357:
1.639 raeburn 6358: table.LC_data_table tr td.LC_leftcol_header {
6359: background-color: $data_table_head;
6360: font-weight: bold;
6361: }
1.795 www 6362:
1.451 albertel 6363: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6364: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6365: font-weight: bold;
6366: font-style: italic;
6367: text-align: center;
6368: padding: 8px;
1.347 albertel 6369: }
1.795 www 6370:
1.1075.2.30 raeburn 6371: table.LC_data_table tr.LC_empty_row td,
6372: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6373: background-color: $sidebg;
6374: }
6375:
6376: table.LC_nested tr.LC_empty_row td {
6377: background-color: #FFFFFF;
6378: }
6379:
1.890 droeschl 6380: table.LC_caption {
6381: }
6382:
1.507 raeburn 6383: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6384: padding: 4ex
6385: }
1.795 www 6386:
1.507 raeburn 6387: table.LC_nested_outer tr th {
6388: font-weight: bold;
1.801 tempelho 6389: color:$fontmenu;
1.507 raeburn 6390: background-color: $data_table_head;
1.701 harmsja 6391: font-size: small;
1.507 raeburn 6392: border-bottom: 1px solid #000000;
6393: }
1.795 www 6394:
1.507 raeburn 6395: table.LC_nested_outer tr td.LC_subheader {
6396: background-color: $data_table_head;
6397: font-weight: bold;
6398: font-size: small;
6399: border-bottom: 1px solid #000000;
6400: text-align: right;
1.451 albertel 6401: }
1.795 www 6402:
1.507 raeburn 6403: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6404: background-color: #CCCCCC;
1.451 albertel 6405: font-weight: bold;
6406: font-size: small;
1.507 raeburn 6407: text-align: center;
6408: }
1.795 www 6409:
1.589 raeburn 6410: table.LC_nested tr.LC_info_row td.LC_left_item,
6411: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6412: text-align: left;
1.451 albertel 6413: }
1.795 www 6414:
1.507 raeburn 6415: table.LC_nested td {
1.735 bisitz 6416: background-color: #FFFFFF;
1.451 albertel 6417: font-size: small;
1.507 raeburn 6418: }
1.795 www 6419:
1.507 raeburn 6420: table.LC_nested_outer tr th.LC_right_item,
6421: table.LC_nested tr.LC_info_row td.LC_right_item,
6422: table.LC_nested tr.LC_odd_row td.LC_right_item,
6423: table.LC_nested tr td.LC_right_item {
1.451 albertel 6424: text-align: right;
6425: }
6426:
1.507 raeburn 6427: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6428: background-color: #EEEEEE;
1.451 albertel 6429: }
6430:
1.473 raeburn 6431: table.LC_createuser {
6432: }
6433:
6434: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6435: font-size: small;
1.473 raeburn 6436: }
6437:
6438: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6439: background-color: #CCCCCC;
1.473 raeburn 6440: font-weight: bold;
6441: text-align: center;
6442: }
6443:
1.349 albertel 6444: table.LC_calendar {
6445: border: 1px solid #000000;
6446: border-collapse: collapse;
1.917 raeburn 6447: width: 98%;
1.349 albertel 6448: }
1.795 www 6449:
1.349 albertel 6450: table.LC_calendar_pickdate {
6451: font-size: xx-small;
6452: }
1.795 www 6453:
1.349 albertel 6454: table.LC_calendar tr td {
6455: border: 1px solid #000000;
6456: vertical-align: top;
1.917 raeburn 6457: width: 14%;
1.349 albertel 6458: }
1.795 www 6459:
1.349 albertel 6460: table.LC_calendar tr td.LC_calendar_day_empty {
6461: background-color: $data_table_dark;
6462: }
1.795 www 6463:
1.779 bisitz 6464: table.LC_calendar tr td.LC_calendar_day_current {
6465: background-color: $data_table_highlight;
1.777 tempelho 6466: }
1.795 www 6467:
1.938 bisitz 6468: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6469: background-color: $mail_new;
6470: }
1.795 www 6471:
1.938 bisitz 6472: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6473: background-color: $mail_new_hover;
6474: }
1.795 www 6475:
1.938 bisitz 6476: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6477: background-color: $mail_read;
6478: }
1.795 www 6479:
1.938 bisitz 6480: /*
6481: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6482: background-color: $mail_read_hover;
6483: }
1.938 bisitz 6484: */
1.795 www 6485:
1.938 bisitz 6486: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6487: background-color: $mail_replied;
6488: }
1.795 www 6489:
1.938 bisitz 6490: /*
6491: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6492: background-color: $mail_replied_hover;
6493: }
1.938 bisitz 6494: */
1.795 www 6495:
1.938 bisitz 6496: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6497: background-color: $mail_other;
6498: }
1.795 www 6499:
1.938 bisitz 6500: /*
6501: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6502: background-color: $mail_other_hover;
6503: }
1.938 bisitz 6504: */
1.494 raeburn 6505:
1.777 tempelho 6506: table.LC_data_table tr > td.LC_browser_file,
6507: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6508: background: #AAEE77;
1.389 albertel 6509: }
1.795 www 6510:
1.777 tempelho 6511: table.LC_data_table tr > td.LC_browser_file_locked,
6512: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6513: background: #FFAA99;
1.387 albertel 6514: }
1.795 www 6515:
1.777 tempelho 6516: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6517: background: #888888;
1.779 bisitz 6518: }
1.795 www 6519:
1.777 tempelho 6520: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6521: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6522: background: #F8F866;
1.777 tempelho 6523: }
1.795 www 6524:
1.696 bisitz 6525: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6526: background: #E0E8FF;
1.387 albertel 6527: }
1.696 bisitz 6528:
1.707 bisitz 6529: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6530: /* background: #77FF77; */
1.707 bisitz 6531: }
1.795 www 6532:
1.707 bisitz 6533: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6534: border-right: 8px solid #FFFF77;
1.707 bisitz 6535: }
1.795 www 6536:
1.707 bisitz 6537: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6538: border-right: 8px solid #FFAA77;
1.707 bisitz 6539: }
1.795 www 6540:
1.707 bisitz 6541: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6542: border-right: 8px solid #FF7777;
1.707 bisitz 6543: }
1.795 www 6544:
1.707 bisitz 6545: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6546: border-right: 8px solid #AAFF77;
1.707 bisitz 6547: }
1.795 www 6548:
1.707 bisitz 6549: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6550: border-right: 8px solid #11CC55;
1.707 bisitz 6551: }
6552:
1.388 albertel 6553: span.LC_current_location {
1.701 harmsja 6554: font-size:larger;
1.388 albertel 6555: background: $pgbg;
6556: }
1.387 albertel 6557:
1.1029 www 6558: span.LC_current_nav_location {
6559: font-weight:bold;
6560: background: $sidebg;
6561: }
6562:
1.395 albertel 6563: span.LC_parm_menu_item {
6564: font-size: larger;
6565: }
1.795 www 6566:
1.395 albertel 6567: span.LC_parm_scope_all {
6568: color: red;
6569: }
1.795 www 6570:
1.395 albertel 6571: span.LC_parm_scope_folder {
6572: color: green;
6573: }
1.795 www 6574:
1.395 albertel 6575: span.LC_parm_scope_resource {
6576: color: orange;
6577: }
1.795 www 6578:
1.395 albertel 6579: span.LC_parm_part {
6580: color: blue;
6581: }
1.795 www 6582:
1.911 bisitz 6583: span.LC_parm_folder,
6584: span.LC_parm_symb {
1.395 albertel 6585: font-size: x-small;
6586: font-family: $mono;
6587: color: #AAAAAA;
6588: }
6589:
1.977 bisitz 6590: ul.LC_parm_parmlist li {
6591: display: inline-block;
6592: padding: 0.3em 0.8em;
6593: vertical-align: top;
6594: width: 150px;
6595: border-top:1px solid $lg_border_color;
6596: }
6597:
1.795 www 6598: td.LC_parm_overview_level_menu,
6599: td.LC_parm_overview_map_menu,
6600: td.LC_parm_overview_parm_selectors,
6601: td.LC_parm_overview_restrictions {
1.396 albertel 6602: border: 1px solid black;
6603: border-collapse: collapse;
6604: }
1.795 www 6605:
1.396 albertel 6606: table.LC_parm_overview_restrictions td {
6607: border-width: 1px 4px 1px 4px;
6608: border-style: solid;
6609: border-color: $pgbg;
6610: text-align: center;
6611: }
1.795 www 6612:
1.396 albertel 6613: table.LC_parm_overview_restrictions th {
6614: background: $tabbg;
6615: border-width: 1px 4px 1px 4px;
6616: border-style: solid;
6617: border-color: $pgbg;
6618: }
1.795 www 6619:
1.398 albertel 6620: table#LC_helpmenu {
1.803 bisitz 6621: border: none;
1.398 albertel 6622: height: 55px;
1.803 bisitz 6623: border-spacing: 0;
1.398 albertel 6624: }
6625:
6626: table#LC_helpmenu fieldset legend {
6627: font-size: larger;
6628: }
1.795 www 6629:
1.397 albertel 6630: table#LC_helpmenu_links {
6631: width: 100%;
6632: border: 1px solid black;
6633: background: $pgbg;
1.803 bisitz 6634: padding: 0;
1.397 albertel 6635: border-spacing: 1px;
6636: }
1.795 www 6637:
1.397 albertel 6638: table#LC_helpmenu_links tr td {
6639: padding: 1px;
6640: background: $tabbg;
1.399 albertel 6641: text-align: center;
6642: font-weight: bold;
1.397 albertel 6643: }
1.396 albertel 6644:
1.795 www 6645: table#LC_helpmenu_links a:link,
6646: table#LC_helpmenu_links a:visited,
1.397 albertel 6647: table#LC_helpmenu_links a:active {
6648: text-decoration: none;
6649: color: $font;
6650: }
1.795 www 6651:
1.397 albertel 6652: table#LC_helpmenu_links a:hover {
6653: text-decoration: underline;
6654: color: $vlink;
6655: }
1.396 albertel 6656:
1.417 albertel 6657: .LC_chrt_popup_exists {
6658: border: 1px solid #339933;
6659: margin: -1px;
6660: }
1.795 www 6661:
1.417 albertel 6662: .LC_chrt_popup_up {
6663: border: 1px solid yellow;
6664: margin: -1px;
6665: }
1.795 www 6666:
1.417 albertel 6667: .LC_chrt_popup {
6668: border: 1px solid #8888FF;
6669: background: #CCCCFF;
6670: }
1.795 www 6671:
1.421 albertel 6672: table.LC_pick_box {
6673: border-collapse: separate;
6674: background: white;
6675: border: 1px solid black;
6676: border-spacing: 1px;
6677: }
1.795 www 6678:
1.421 albertel 6679: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6680: background: $sidebg;
1.421 albertel 6681: font-weight: bold;
1.900 bisitz 6682: text-align: left;
1.740 bisitz 6683: vertical-align: top;
1.421 albertel 6684: width: 184px;
6685: padding: 8px;
6686: }
1.795 www 6687:
1.579 raeburn 6688: table.LC_pick_box td.LC_pick_box_value {
6689: text-align: left;
6690: padding: 8px;
6691: }
1.795 www 6692:
1.579 raeburn 6693: table.LC_pick_box td.LC_pick_box_select {
6694: text-align: left;
6695: padding: 8px;
6696: }
1.795 www 6697:
1.424 albertel 6698: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6699: padding: 0;
1.421 albertel 6700: height: 1px;
6701: background: black;
6702: }
1.795 www 6703:
1.421 albertel 6704: table.LC_pick_box td.LC_pick_box_submit {
6705: text-align: right;
6706: }
1.795 www 6707:
1.579 raeburn 6708: table.LC_pick_box td.LC_evenrow_value {
6709: text-align: left;
6710: padding: 8px;
6711: background-color: $data_table_light;
6712: }
1.795 www 6713:
1.579 raeburn 6714: table.LC_pick_box td.LC_oddrow_value {
6715: text-align: left;
6716: padding: 8px;
6717: background-color: $data_table_light;
6718: }
1.795 www 6719:
1.579 raeburn 6720: span.LC_helpform_receipt_cat {
6721: font-weight: bold;
6722: }
1.795 www 6723:
1.424 albertel 6724: table.LC_group_priv_box {
6725: background: white;
6726: border: 1px solid black;
6727: border-spacing: 1px;
6728: }
1.795 www 6729:
1.424 albertel 6730: table.LC_group_priv_box td.LC_pick_box_title {
6731: background: $tabbg;
6732: font-weight: bold;
6733: text-align: right;
6734: width: 184px;
6735: }
1.795 www 6736:
1.424 albertel 6737: table.LC_group_priv_box td.LC_groups_fixed {
6738: background: $data_table_light;
6739: text-align: center;
6740: }
1.795 www 6741:
1.424 albertel 6742: table.LC_group_priv_box td.LC_groups_optional {
6743: background: $data_table_dark;
6744: text-align: center;
6745: }
1.795 www 6746:
1.424 albertel 6747: table.LC_group_priv_box td.LC_groups_functionality {
6748: background: $data_table_darker;
6749: text-align: center;
6750: font-weight: bold;
6751: }
1.795 www 6752:
1.424 albertel 6753: table.LC_group_priv td {
6754: text-align: left;
1.803 bisitz 6755: padding: 0;
1.424 albertel 6756: }
6757:
6758: .LC_navbuttons {
6759: margin: 2ex 0ex 2ex 0ex;
6760: }
1.795 www 6761:
1.423 albertel 6762: .LC_topic_bar {
6763: font-weight: bold;
6764: background: $tabbg;
1.918 wenzelju 6765: margin: 1em 0em 1em 2em;
1.805 bisitz 6766: padding: 3px;
1.918 wenzelju 6767: font-size: 1.2em;
1.423 albertel 6768: }
1.795 www 6769:
1.423 albertel 6770: .LC_topic_bar span {
1.918 wenzelju 6771: left: 0.5em;
6772: position: absolute;
1.423 albertel 6773: vertical-align: middle;
1.918 wenzelju 6774: font-size: 1.2em;
1.423 albertel 6775: }
1.795 www 6776:
1.423 albertel 6777: table.LC_course_group_status {
6778: margin: 20px;
6779: }
1.795 www 6780:
1.423 albertel 6781: table.LC_status_selector td {
6782: vertical-align: top;
6783: text-align: center;
1.424 albertel 6784: padding: 4px;
6785: }
1.795 www 6786:
1.599 albertel 6787: div.LC_feedback_link {
1.616 albertel 6788: clear: both;
1.829 kalberla 6789: background: $sidebg;
1.779 bisitz 6790: width: 100%;
1.829 kalberla 6791: padding-bottom: 10px;
6792: border: 1px $tabbg solid;
1.833 kalberla 6793: height: 22px;
6794: line-height: 22px;
6795: padding-top: 5px;
6796: }
6797:
6798: div.LC_feedback_link img {
6799: height: 22px;
1.867 kalberla 6800: vertical-align:middle;
1.829 kalberla 6801: }
6802:
1.911 bisitz 6803: div.LC_feedback_link a {
1.829 kalberla 6804: text-decoration: none;
1.489 raeburn 6805: }
1.795 www 6806:
1.867 kalberla 6807: div.LC_comblock {
1.911 bisitz 6808: display:inline;
1.867 kalberla 6809: color:$font;
6810: font-size:90%;
6811: }
6812:
6813: div.LC_feedback_link div.LC_comblock {
6814: padding-left:5px;
6815: }
6816:
6817: div.LC_feedback_link div.LC_comblock a {
6818: color:$font;
6819: }
6820:
1.489 raeburn 6821: span.LC_feedback_link {
1.858 bisitz 6822: /* background: $feedback_link_bg; */
1.599 albertel 6823: font-size: larger;
6824: }
1.795 www 6825:
1.599 albertel 6826: span.LC_message_link {
1.858 bisitz 6827: /* background: $feedback_link_bg; */
1.599 albertel 6828: font-size: larger;
6829: position: absolute;
6830: right: 1em;
1.489 raeburn 6831: }
1.421 albertel 6832:
1.515 albertel 6833: table.LC_prior_tries {
1.524 albertel 6834: border: 1px solid #000000;
6835: border-collapse: separate;
6836: border-spacing: 1px;
1.515 albertel 6837: }
1.523 albertel 6838:
1.515 albertel 6839: table.LC_prior_tries td {
1.524 albertel 6840: padding: 2px;
1.515 albertel 6841: }
1.523 albertel 6842:
6843: .LC_answer_correct {
1.795 www 6844: background: lightgreen;
6845: color: darkgreen;
6846: padding: 6px;
1.523 albertel 6847: }
1.795 www 6848:
1.523 albertel 6849: .LC_answer_charged_try {
1.797 www 6850: background: #FFAAAA;
1.795 www 6851: color: darkred;
6852: padding: 6px;
1.523 albertel 6853: }
1.795 www 6854:
1.779 bisitz 6855: .LC_answer_not_charged_try,
1.523 albertel 6856: .LC_answer_no_grade,
6857: .LC_answer_late {
1.795 www 6858: background: lightyellow;
1.523 albertel 6859: color: black;
1.795 www 6860: padding: 6px;
1.523 albertel 6861: }
1.795 www 6862:
1.523 albertel 6863: .LC_answer_previous {
1.795 www 6864: background: lightblue;
6865: color: darkblue;
6866: padding: 6px;
1.523 albertel 6867: }
1.795 www 6868:
1.779 bisitz 6869: .LC_answer_no_message {
1.777 tempelho 6870: background: #FFFFFF;
6871: color: black;
1.795 www 6872: padding: 6px;
1.779 bisitz 6873: }
1.795 www 6874:
1.1075.2.140 raeburn 6875: .LC_answer_unknown,
6876: .LC_answer_warning {
1.779 bisitz 6877: background: orange;
6878: color: black;
1.795 www 6879: padding: 6px;
1.777 tempelho 6880: }
1.795 www 6881:
1.529 albertel 6882: span.LC_prior_numerical,
6883: span.LC_prior_string,
6884: span.LC_prior_custom,
6885: span.LC_prior_reaction,
6886: span.LC_prior_math {
1.925 bisitz 6887: font-family: $mono;
1.523 albertel 6888: white-space: pre;
6889: }
6890:
1.525 albertel 6891: span.LC_prior_string {
1.925 bisitz 6892: font-family: $mono;
1.525 albertel 6893: white-space: pre;
6894: }
6895:
1.523 albertel 6896: table.LC_prior_option {
6897: width: 100%;
6898: border-collapse: collapse;
6899: }
1.795 www 6900:
1.911 bisitz 6901: table.LC_prior_rank,
1.795 www 6902: table.LC_prior_match {
1.528 albertel 6903: border-collapse: collapse;
6904: }
1.795 www 6905:
1.528 albertel 6906: table.LC_prior_option tr td,
6907: table.LC_prior_rank tr td,
6908: table.LC_prior_match tr td {
1.524 albertel 6909: border: 1px solid #000000;
1.515 albertel 6910: }
6911:
1.855 bisitz 6912: .LC_nobreak {
1.544 albertel 6913: white-space: nowrap;
1.519 raeburn 6914: }
6915:
1.576 raeburn 6916: span.LC_cusr_emph {
6917: font-style: italic;
6918: }
6919:
1.633 raeburn 6920: span.LC_cusr_subheading {
6921: font-weight: normal;
6922: font-size: 85%;
6923: }
6924:
1.861 bisitz 6925: div.LC_docs_entry_move {
1.859 bisitz 6926: border: 1px solid #BBBBBB;
1.545 albertel 6927: background: #DDDDDD;
1.861 bisitz 6928: width: 22px;
1.859 bisitz 6929: padding: 1px;
6930: margin: 0;
1.545 albertel 6931: }
6932:
1.861 bisitz 6933: table.LC_data_table tr > td.LC_docs_entry_commands,
6934: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6935: font-size: x-small;
6936: }
1.795 www 6937:
1.861 bisitz 6938: .LC_docs_entry_parameter {
6939: white-space: nowrap;
6940: }
6941:
1.544 albertel 6942: .LC_docs_copy {
1.545 albertel 6943: color: #000099;
1.544 albertel 6944: }
1.795 www 6945:
1.544 albertel 6946: .LC_docs_cut {
1.545 albertel 6947: color: #550044;
1.544 albertel 6948: }
1.795 www 6949:
1.544 albertel 6950: .LC_docs_rename {
1.545 albertel 6951: color: #009900;
1.544 albertel 6952: }
1.795 www 6953:
1.544 albertel 6954: .LC_docs_remove {
1.545 albertel 6955: color: #990000;
6956: }
6957:
1.1075.2.134 raeburn 6958: .LC_domprefs_email,
1.547 albertel 6959: .LC_docs_reinit_warn,
6960: .LC_docs_ext_edit {
6961: font-size: x-small;
6962: }
6963:
1.545 albertel 6964: table.LC_docs_adddocs td,
6965: table.LC_docs_adddocs th {
6966: border: 1px solid #BBBBBB;
6967: padding: 4px;
6968: background: #DDDDDD;
1.543 albertel 6969: }
6970:
1.584 albertel 6971: table.LC_sty_begin {
6972: background: #BBFFBB;
6973: }
1.795 www 6974:
1.584 albertel 6975: table.LC_sty_end {
6976: background: #FFBBBB;
6977: }
6978:
1.589 raeburn 6979: table.LC_double_column {
1.803 bisitz 6980: border-width: 0;
1.589 raeburn 6981: border-collapse: collapse;
6982: width: 100%;
6983: padding: 2px;
6984: }
6985:
6986: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6987: top: 2px;
1.589 raeburn 6988: left: 2px;
6989: width: 47%;
6990: vertical-align: top;
6991: }
6992:
6993: table.LC_double_column tr td.LC_right_col {
6994: top: 2px;
1.779 bisitz 6995: right: 2px;
1.589 raeburn 6996: width: 47%;
6997: vertical-align: top;
6998: }
6999:
1.591 raeburn 7000: div.LC_left_float {
7001: float: left;
7002: padding-right: 5%;
1.597 albertel 7003: padding-bottom: 4px;
1.591 raeburn 7004: }
7005:
7006: div.LC_clear_float_header {
1.597 albertel 7007: padding-bottom: 2px;
1.591 raeburn 7008: }
7009:
7010: div.LC_clear_float_footer {
1.597 albertel 7011: padding-top: 10px;
1.591 raeburn 7012: clear: both;
7013: }
7014:
1.597 albertel 7015: div.LC_grade_show_user {
1.941 bisitz 7016: /* border-left: 5px solid $sidebg; */
7017: border-top: 5px solid #000000;
7018: margin: 50px 0 0 0;
1.936 bisitz 7019: padding: 15px 0 5px 10px;
1.597 albertel 7020: }
1.795 www 7021:
1.936 bisitz 7022: div.LC_grade_show_user_odd_row {
1.941 bisitz 7023: /* border-left: 5px solid #000000; */
7024: }
7025:
7026: div.LC_grade_show_user div.LC_Box {
7027: margin-right: 50px;
1.597 albertel 7028: }
7029:
7030: div.LC_grade_submissions,
7031: div.LC_grade_message_center,
1.936 bisitz 7032: div.LC_grade_info_links {
1.597 albertel 7033: margin: 5px;
7034: width: 99%;
7035: background: #FFFFFF;
7036: }
1.795 www 7037:
1.597 albertel 7038: div.LC_grade_submissions_header,
1.936 bisitz 7039: div.LC_grade_message_center_header {
1.705 tempelho 7040: font-weight: bold;
7041: font-size: large;
1.597 albertel 7042: }
1.795 www 7043:
1.597 albertel 7044: div.LC_grade_submissions_body,
1.936 bisitz 7045: div.LC_grade_message_center_body {
1.597 albertel 7046: border: 1px solid black;
7047: width: 99%;
7048: background: #FFFFFF;
7049: }
1.795 www 7050:
1.613 albertel 7051: table.LC_scantron_action {
7052: width: 100%;
7053: }
1.795 www 7054:
1.613 albertel 7055: table.LC_scantron_action tr th {
1.698 harmsja 7056: font-weight:bold;
7057: font-style:normal;
1.613 albertel 7058: }
1.795 www 7059:
1.779 bisitz 7060: .LC_edit_problem_header,
1.614 albertel 7061: div.LC_edit_problem_footer {
1.705 tempelho 7062: font-weight: normal;
7063: font-size: medium;
1.602 albertel 7064: margin: 2px;
1.1060 bisitz 7065: background-color: $sidebg;
1.600 albertel 7066: }
1.795 www 7067:
1.600 albertel 7068: div.LC_edit_problem_header,
1.602 albertel 7069: div.LC_edit_problem_header div,
1.614 albertel 7070: div.LC_edit_problem_footer,
7071: div.LC_edit_problem_footer div,
1.602 albertel 7072: div.LC_edit_problem_editxml_header,
7073: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7074: z-index: 100;
1.600 albertel 7075: }
1.795 www 7076:
1.600 albertel 7077: div.LC_edit_problem_header_title {
1.705 tempelho 7078: font-weight: bold;
7079: font-size: larger;
1.602 albertel 7080: background: $tabbg;
7081: padding: 3px;
1.1060 bisitz 7082: margin: 0 0 5px 0;
1.602 albertel 7083: }
1.795 www 7084:
1.602 albertel 7085: table.LC_edit_problem_header_title {
7086: width: 100%;
1.600 albertel 7087: background: $tabbg;
1.602 albertel 7088: }
7089:
1.1075.2.112 raeburn 7090: div.LC_edit_actionbar {
7091: background-color: $sidebg;
7092: margin: 0;
7093: padding: 0;
7094: line-height: 200%;
1.602 albertel 7095: }
1.795 www 7096:
1.1075.2.112 raeburn 7097: div.LC_edit_actionbar div{
7098: padding: 0;
7099: margin: 0;
7100: display: inline-block;
1.600 albertel 7101: }
1.795 www 7102:
1.1075.2.34 raeburn 7103: .LC_edit_opt {
7104: padding-left: 1em;
7105: white-space: nowrap;
7106: }
7107:
1.1075.2.57 raeburn 7108: .LC_edit_problem_latexhelper{
7109: text-align: right;
7110: }
7111:
7112: #LC_edit_problem_colorful div{
7113: margin-left: 40px;
7114: }
7115:
1.1075.2.112 raeburn 7116: #LC_edit_problem_codemirror div{
7117: margin-left: 0px;
7118: }
7119:
1.911 bisitz 7120: img.stift {
1.803 bisitz 7121: border-width: 0;
7122: vertical-align: middle;
1.677 riegler 7123: }
1.680 riegler 7124:
1.923 bisitz 7125: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7126: vertical-align: top;
1.777 tempelho 7127: }
1.795 www 7128:
1.716 raeburn 7129: div.LC_createcourse {
1.911 bisitz 7130: margin: 10px 10px 10px 10px;
1.716 raeburn 7131: }
7132:
1.917 raeburn 7133: .LC_dccid {
1.1075.2.38 raeburn 7134: float: right;
1.917 raeburn 7135: margin: 0.2em 0 0 0;
7136: padding: 0;
7137: font-size: 90%;
7138: display:none;
7139: }
7140:
1.897 wenzelju 7141: ol.LC_primary_menu a:hover,
1.721 harmsja 7142: ol#LC_MenuBreadcrumbs a:hover,
7143: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7144: ul#LC_secondary_menu a:hover,
1.721 harmsja 7145: .LC_FormSectionClearButton input:hover
1.795 www 7146: ul.LC_TabContent li:hover a {
1.952 onken 7147: color:$button_hover;
1.911 bisitz 7148: text-decoration:none;
1.693 droeschl 7149: }
7150:
1.779 bisitz 7151: h1 {
1.911 bisitz 7152: padding: 0;
7153: line-height:130%;
1.693 droeschl 7154: }
1.698 harmsja 7155:
1.911 bisitz 7156: h2,
7157: h3,
7158: h4,
7159: h5,
7160: h6 {
7161: margin: 5px 0 5px 0;
7162: padding: 0;
7163: line-height:130%;
1.693 droeschl 7164: }
1.795 www 7165:
7166: .LC_hcell {
1.911 bisitz 7167: padding:3px 15px 3px 15px;
7168: margin: 0;
7169: background-color:$tabbg;
7170: color:$fontmenu;
7171: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7172: }
1.795 www 7173:
1.840 bisitz 7174: .LC_Box > .LC_hcell {
1.911 bisitz 7175: margin: 0 -10px 10px -10px;
1.835 bisitz 7176: }
7177:
1.721 harmsja 7178: .LC_noBorder {
1.911 bisitz 7179: border: 0;
1.698 harmsja 7180: }
1.693 droeschl 7181:
1.721 harmsja 7182: .LC_FormSectionClearButton input {
1.911 bisitz 7183: background-color:transparent;
7184: border: none;
7185: cursor:pointer;
7186: text-decoration:underline;
1.693 droeschl 7187: }
1.763 bisitz 7188:
7189: .LC_help_open_topic {
1.911 bisitz 7190: color: #FFFFFF;
7191: background-color: #EEEEFF;
7192: margin: 1px;
7193: padding: 4px;
7194: border: 1px solid #000033;
7195: white-space: nowrap;
7196: /* vertical-align: middle; */
1.759 neumanie 7197: }
1.693 droeschl 7198:
1.911 bisitz 7199: dl,
7200: ul,
7201: div,
7202: fieldset {
7203: margin: 10px 10px 10px 0;
7204: /* overflow: hidden; */
1.693 droeschl 7205: }
1.795 www 7206:
1.1075.2.90 raeburn 7207: article.geogebraweb div {
7208: margin: 0;
7209: }
7210:
1.838 bisitz 7211: fieldset > legend {
1.911 bisitz 7212: font-weight: bold;
7213: padding: 0 5px 0 5px;
1.838 bisitz 7214: }
7215:
1.813 bisitz 7216: #LC_nav_bar {
1.911 bisitz 7217: float: left;
1.995 raeburn 7218: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7219: margin: 0 0 2px 0;
1.807 droeschl 7220: }
7221:
1.916 droeschl 7222: #LC_realm {
7223: margin: 0.2em 0 0 0;
7224: padding: 0;
7225: font-weight: bold;
7226: text-align: center;
1.995 raeburn 7227: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7228: }
7229:
1.911 bisitz 7230: #LC_nav_bar em {
7231: font-weight: bold;
7232: font-style: normal;
1.807 droeschl 7233: }
7234:
1.897 wenzelju 7235: ol.LC_primary_menu {
1.934 droeschl 7236: margin: 0;
1.1075.2.2 raeburn 7237: padding: 0;
1.807 droeschl 7238: }
7239:
1.852 droeschl 7240: ol#LC_PathBreadcrumbs {
1.911 bisitz 7241: margin: 0;
1.693 droeschl 7242: }
7243:
1.897 wenzelju 7244: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7245: color: RGB(80, 80, 80);
7246: vertical-align: middle;
7247: text-align: left;
7248: list-style: none;
1.1075.2.112 raeburn 7249: position: relative;
1.1075.2.2 raeburn 7250: float: left;
1.1075.2.112 raeburn 7251: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7252: line-height: 1.5em;
1.1075.2.2 raeburn 7253: }
7254:
1.1075.2.113 raeburn 7255: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7256: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7257: display: block;
7258: margin: 0;
7259: padding: 0 5px 0 10px;
7260: text-decoration: none;
7261: }
7262:
1.1075.2.112 raeburn 7263: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7264: display: inline-block;
7265: width: 95%;
7266: text-align: left;
7267: }
7268:
7269: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7270: display: inline-block;
7271: width: 5%;
7272: float: right;
7273: text-align: right;
7274: font-size: 70%;
7275: }
7276:
7277: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7278: display: none;
1.1075.2.112 raeburn 7279: width: 15em;
1.1075.2.2 raeburn 7280: background-color: $data_table_light;
1.1075.2.112 raeburn 7281: position: absolute;
7282: top: 100%;
7283: }
7284:
7285: ol.LC_primary_menu ul ul {
7286: left: 100%;
7287: top: 0;
1.1075.2.2 raeburn 7288: }
7289:
1.1075.2.112 raeburn 7290: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7291: display: block;
7292: position: absolute;
7293: margin: 0;
7294: padding: 0;
1.1075.2.5 raeburn 7295: z-index: 2;
1.1075.2.2 raeburn 7296: }
7297:
7298: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7299: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7300: font-size: 90%;
1.911 bisitz 7301: vertical-align: top;
1.1075.2.2 raeburn 7302: float: none;
1.1075.2.5 raeburn 7303: border-left: 1px solid black;
7304: border-right: 1px solid black;
1.1075.2.112 raeburn 7305: /* A dark bottom border to visualize different menu options;
7306: overwritten in the create_submenu routine for the last border-bottom of the menu */
7307: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7308: }
7309:
1.1075.2.112 raeburn 7310: ol.LC_primary_menu li li p:hover {
7311: color:$button_hover;
7312: text-decoration:none;
7313: background-color:$data_table_dark;
1.1075.2.2 raeburn 7314: }
7315:
7316: ol.LC_primary_menu li li a:hover {
7317: color:$button_hover;
7318: background-color:$data_table_dark;
1.693 droeschl 7319: }
7320:
1.1075.2.112 raeburn 7321: /* Font-size equal to the size of the predecessors*/
7322: ol.LC_primary_menu li:hover li li {
7323: font-size: 100%;
7324: }
7325:
1.897 wenzelju 7326: ol.LC_primary_menu li img {
1.911 bisitz 7327: vertical-align: bottom;
1.934 droeschl 7328: height: 1.1em;
1.1075.2.3 raeburn 7329: margin: 0.2em 0 0 0;
1.693 droeschl 7330: }
7331:
1.897 wenzelju 7332: ol.LC_primary_menu a {
1.911 bisitz 7333: color: RGB(80, 80, 80);
7334: text-decoration: none;
1.693 droeschl 7335: }
1.795 www 7336:
1.949 droeschl 7337: ol.LC_primary_menu a.LC_new_message {
7338: font-weight:bold;
7339: color: darkred;
7340: }
7341:
1.975 raeburn 7342: ol.LC_docs_parameters {
7343: margin-left: 0;
7344: padding: 0;
7345: list-style: none;
7346: }
7347:
7348: ol.LC_docs_parameters li {
7349: margin: 0;
7350: padding-right: 20px;
7351: display: inline;
7352: }
7353:
1.976 raeburn 7354: ol.LC_docs_parameters li:before {
7355: content: "\\002022 \\0020";
7356: }
7357:
7358: li.LC_docs_parameters_title {
7359: font-weight: bold;
7360: }
7361:
7362: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7363: content: "";
7364: }
7365:
1.897 wenzelju 7366: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7367: clear: right;
1.911 bisitz 7368: color: $fontmenu;
7369: background: $tabbg;
7370: list-style: none;
7371: padding: 0;
7372: margin: 0;
7373: width: 100%;
1.995 raeburn 7374: text-align: left;
1.1075.2.4 raeburn 7375: float: left;
1.808 droeschl 7376: }
7377:
1.897 wenzelju 7378: ul#LC_secondary_menu li {
1.911 bisitz 7379: font-weight: bold;
7380: line-height: 1.8em;
7381: border-right: 1px solid black;
1.1075.2.4 raeburn 7382: float: left;
7383: }
7384:
7385: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7386: background-color: $data_table_light;
7387: }
7388:
7389: ul#LC_secondary_menu li a {
7390: padding: 0 0.8em;
7391: }
7392:
7393: ul#LC_secondary_menu li ul {
7394: display: none;
7395: }
7396:
7397: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7398: display: block;
7399: position: absolute;
7400: margin: 0;
7401: padding: 0;
7402: list-style:none;
7403: float: none;
7404: background-color: $data_table_light;
1.1075.2.5 raeburn 7405: z-index: 2;
1.1075.2.10 raeburn 7406: margin-left: -1px;
1.1075.2.4 raeburn 7407: }
7408:
7409: ul#LC_secondary_menu li ul li {
7410: font-size: 90%;
7411: vertical-align: top;
7412: border-left: 1px solid black;
7413: border-right: 1px solid black;
1.1075.2.33 raeburn 7414: background-color: $data_table_light;
1.1075.2.4 raeburn 7415: list-style:none;
7416: float: none;
7417: }
7418:
7419: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7420: background-color: $data_table_dark;
1.807 droeschl 7421: }
7422:
1.847 tempelho 7423: ul.LC_TabContent {
1.911 bisitz 7424: display:block;
7425: background: $sidebg;
7426: border-bottom: solid 1px $lg_border_color;
7427: list-style:none;
1.1020 raeburn 7428: margin: -1px -10px 0 -10px;
1.911 bisitz 7429: padding: 0;
1.693 droeschl 7430: }
7431:
1.795 www 7432: ul.LC_TabContent li,
7433: ul.LC_TabContentBigger li {
1.911 bisitz 7434: float:left;
1.741 harmsja 7435: }
1.795 www 7436:
1.897 wenzelju 7437: ul#LC_secondary_menu li a {
1.911 bisitz 7438: color: $fontmenu;
7439: text-decoration: none;
1.693 droeschl 7440: }
1.795 www 7441:
1.721 harmsja 7442: ul.LC_TabContent {
1.952 onken 7443: min-height:20px;
1.721 harmsja 7444: }
1.795 www 7445:
7446: ul.LC_TabContent li {
1.911 bisitz 7447: vertical-align:middle;
1.959 onken 7448: padding: 0 16px 0 10px;
1.911 bisitz 7449: background-color:$tabbg;
7450: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7451: border-left: solid 1px $font;
1.721 harmsja 7452: }
1.795 www 7453:
1.847 tempelho 7454: ul.LC_TabContent .right {
1.911 bisitz 7455: float:right;
1.847 tempelho 7456: }
7457:
1.911 bisitz 7458: ul.LC_TabContent li a,
7459: ul.LC_TabContent li {
7460: color:rgb(47,47,47);
7461: text-decoration:none;
7462: font-size:95%;
7463: font-weight:bold;
1.952 onken 7464: min-height:20px;
7465: }
7466:
1.959 onken 7467: ul.LC_TabContent li a:hover,
7468: ul.LC_TabContent li a:focus {
1.952 onken 7469: color: $button_hover;
1.959 onken 7470: background:none;
7471: outline:none;
1.952 onken 7472: }
7473:
7474: ul.LC_TabContent li:hover {
7475: color: $button_hover;
7476: cursor:pointer;
1.721 harmsja 7477: }
1.795 www 7478:
1.911 bisitz 7479: ul.LC_TabContent li.active {
1.952 onken 7480: color: $font;
1.911 bisitz 7481: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7482: border-bottom:solid 1px #FFFFFF;
7483: cursor: default;
1.744 ehlerst 7484: }
1.795 www 7485:
1.959 onken 7486: ul.LC_TabContent li.active a {
7487: color:$font;
7488: background:#FFFFFF;
7489: outline: none;
7490: }
1.1047 raeburn 7491:
7492: ul.LC_TabContent li.goback {
7493: float: left;
7494: border-left: none;
7495: }
7496:
1.870 tempelho 7497: #maincoursedoc {
1.911 bisitz 7498: clear:both;
1.870 tempelho 7499: }
7500:
7501: ul.LC_TabContentBigger {
1.911 bisitz 7502: display:block;
7503: list-style:none;
7504: padding: 0;
1.870 tempelho 7505: }
7506:
1.795 www 7507: ul.LC_TabContentBigger li {
1.911 bisitz 7508: vertical-align:bottom;
7509: height: 30px;
7510: font-size:110%;
7511: font-weight:bold;
7512: color: #737373;
1.841 tempelho 7513: }
7514:
1.957 onken 7515: ul.LC_TabContentBigger li.active {
7516: position: relative;
7517: top: 1px;
7518: }
7519:
1.870 tempelho 7520: ul.LC_TabContentBigger li a {
1.911 bisitz 7521: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7522: height: 30px;
7523: line-height: 30px;
7524: text-align: center;
7525: display: block;
7526: text-decoration: none;
1.958 onken 7527: outline: none;
1.741 harmsja 7528: }
1.795 www 7529:
1.870 tempelho 7530: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7531: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7532: color:$font;
1.744 ehlerst 7533: }
1.795 www 7534:
1.870 tempelho 7535: ul.LC_TabContentBigger li b {
1.911 bisitz 7536: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7537: display: block;
7538: float: left;
7539: padding: 0 30px;
1.957 onken 7540: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7541: }
7542:
1.956 onken 7543: ul.LC_TabContentBigger li:hover b {
7544: color:$button_hover;
7545: }
7546:
1.870 tempelho 7547: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7548: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7549: color:$font;
1.957 onken 7550: border: 0;
1.741 harmsja 7551: }
1.693 droeschl 7552:
1.870 tempelho 7553:
1.862 bisitz 7554: ul.LC_CourseBreadcrumbs {
7555: background: $sidebg;
1.1020 raeburn 7556: height: 2em;
1.862 bisitz 7557: padding-left: 10px;
1.1020 raeburn 7558: margin: 0;
1.862 bisitz 7559: list-style-position: inside;
7560: }
7561:
1.911 bisitz 7562: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7563: ol#LC_PathBreadcrumbs {
1.911 bisitz 7564: padding-left: 10px;
7565: margin: 0;
1.933 droeschl 7566: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7567: }
7568:
1.911 bisitz 7569: ol#LC_MenuBreadcrumbs li,
7570: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7571: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7572: display: inline;
1.933 droeschl 7573: white-space: normal;
1.693 droeschl 7574: }
7575:
1.823 bisitz 7576: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7577: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7578: text-decoration: none;
7579: font-size:90%;
1.693 droeschl 7580: }
1.795 www 7581:
1.969 droeschl 7582: ol#LC_MenuBreadcrumbs h1 {
7583: display: inline;
7584: font-size: 90%;
7585: line-height: 2.5em;
7586: margin: 0;
7587: padding: 0;
7588: }
7589:
1.795 www 7590: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7591: text-decoration:none;
7592: font-size:100%;
7593: font-weight:bold;
1.693 droeschl 7594: }
1.795 www 7595:
1.840 bisitz 7596: .LC_Box {
1.911 bisitz 7597: border: solid 1px $lg_border_color;
7598: padding: 0 10px 10px 10px;
1.746 neumanie 7599: }
1.795 www 7600:
1.1020 raeburn 7601: .LC_DocsBox {
7602: border: solid 1px $lg_border_color;
7603: padding: 0 0 10px 10px;
7604: }
7605:
1.795 www 7606: .LC_AboutMe_Image {
1.911 bisitz 7607: float:left;
7608: margin-right:10px;
1.747 neumanie 7609: }
1.795 www 7610:
7611: .LC_Clear_AboutMe_Image {
1.911 bisitz 7612: clear:left;
1.747 neumanie 7613: }
1.795 www 7614:
1.721 harmsja 7615: dl.LC_ListStyleClean dt {
1.911 bisitz 7616: padding-right: 5px;
7617: display: table-header-group;
1.693 droeschl 7618: }
7619:
1.721 harmsja 7620: dl.LC_ListStyleClean dd {
1.911 bisitz 7621: display: table-row;
1.693 droeschl 7622: }
7623:
1.721 harmsja 7624: .LC_ListStyleClean,
7625: .LC_ListStyleSimple,
7626: .LC_ListStyleNormal,
1.795 www 7627: .LC_ListStyleSpecial {
1.911 bisitz 7628: /* display:block; */
7629: list-style-position: inside;
7630: list-style-type: none;
7631: overflow: hidden;
7632: padding: 0;
1.693 droeschl 7633: }
7634:
1.721 harmsja 7635: .LC_ListStyleSimple li,
7636: .LC_ListStyleSimple dd,
7637: .LC_ListStyleNormal li,
7638: .LC_ListStyleNormal dd,
7639: .LC_ListStyleSpecial li,
1.795 www 7640: .LC_ListStyleSpecial dd {
1.911 bisitz 7641: margin: 0;
7642: padding: 5px 5px 5px 10px;
7643: clear: both;
1.693 droeschl 7644: }
7645:
1.721 harmsja 7646: .LC_ListStyleClean li,
7647: .LC_ListStyleClean dd {
1.911 bisitz 7648: padding-top: 0;
7649: padding-bottom: 0;
1.693 droeschl 7650: }
7651:
1.721 harmsja 7652: .LC_ListStyleSimple dd,
1.795 www 7653: .LC_ListStyleSimple li {
1.911 bisitz 7654: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7655: }
7656:
1.721 harmsja 7657: .LC_ListStyleSpecial li,
7658: .LC_ListStyleSpecial dd {
1.911 bisitz 7659: list-style-type: none;
7660: background-color: RGB(220, 220, 220);
7661: margin-bottom: 4px;
1.693 droeschl 7662: }
7663:
1.721 harmsja 7664: table.LC_SimpleTable {
1.911 bisitz 7665: margin:5px;
7666: border:solid 1px $lg_border_color;
1.795 www 7667: }
1.693 droeschl 7668:
1.721 harmsja 7669: table.LC_SimpleTable tr {
1.911 bisitz 7670: padding: 0;
7671: border:solid 1px $lg_border_color;
1.693 droeschl 7672: }
1.795 www 7673:
7674: table.LC_SimpleTable thead {
1.911 bisitz 7675: background:rgb(220,220,220);
1.693 droeschl 7676: }
7677:
1.721 harmsja 7678: div.LC_columnSection {
1.911 bisitz 7679: display: block;
7680: clear: both;
7681: overflow: hidden;
7682: margin: 0;
1.693 droeschl 7683: }
7684:
1.721 harmsja 7685: div.LC_columnSection>* {
1.911 bisitz 7686: float: left;
7687: margin: 10px 20px 10px 0;
7688: overflow:hidden;
1.693 droeschl 7689: }
1.721 harmsja 7690:
1.795 www 7691: table em {
1.911 bisitz 7692: font-weight: bold;
7693: font-style: normal;
1.748 schulted 7694: }
1.795 www 7695:
1.779 bisitz 7696: table.LC_tableBrowseRes,
1.795 www 7697: table.LC_tableOfContent {
1.911 bisitz 7698: border:none;
7699: border-spacing: 1px;
7700: padding: 3px;
7701: background-color: #FFFFFF;
7702: font-size: 90%;
1.753 droeschl 7703: }
1.789 droeschl 7704:
1.911 bisitz 7705: table.LC_tableOfContent {
7706: border-collapse: collapse;
1.789 droeschl 7707: }
7708:
1.771 droeschl 7709: table.LC_tableBrowseRes a,
1.768 schulted 7710: table.LC_tableOfContent a {
1.911 bisitz 7711: background-color: transparent;
7712: text-decoration: none;
1.753 droeschl 7713: }
7714:
1.795 www 7715: table.LC_tableOfContent img {
1.911 bisitz 7716: border: none;
7717: height: 1.3em;
7718: vertical-align: text-bottom;
7719: margin-right: 0.3em;
1.753 droeschl 7720: }
1.757 schulted 7721:
1.795 www 7722: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7723: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7724: }
7725:
1.795 www 7726: a#LC_content_toolbar_everything {
1.911 bisitz 7727: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7728: }
7729:
1.795 www 7730: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7731: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7732: }
7733:
1.795 www 7734: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7735: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7736: }
7737:
1.795 www 7738: a#LC_content_toolbar_changefolder {
1.911 bisitz 7739: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7740: }
7741:
1.795 www 7742: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7743: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7744: }
7745:
1.1043 raeburn 7746: a#LC_content_toolbar_edittoplevel {
7747: background-image:url(/res/adm/pages/edittoplevel.gif);
7748: }
7749:
1.795 www 7750: ul#LC_toolbar li a:hover {
1.911 bisitz 7751: background-position: bottom center;
1.757 schulted 7752: }
7753:
1.795 www 7754: ul#LC_toolbar {
1.911 bisitz 7755: padding: 0;
7756: margin: 2px;
7757: list-style:none;
7758: position:relative;
7759: background-color:white;
1.1075.2.9 raeburn 7760: overflow: auto;
1.757 schulted 7761: }
7762:
1.795 www 7763: ul#LC_toolbar li {
1.911 bisitz 7764: border:1px solid white;
7765: padding: 0;
7766: margin: 0;
7767: float: left;
7768: display:inline;
7769: vertical-align:middle;
1.1075.2.9 raeburn 7770: white-space: nowrap;
1.911 bisitz 7771: }
1.757 schulted 7772:
1.783 amueller 7773:
1.795 www 7774: a.LC_toolbarItem {
1.911 bisitz 7775: display:block;
7776: padding: 0;
7777: margin: 0;
7778: height: 32px;
7779: width: 32px;
7780: color:white;
7781: border: none;
7782: background-repeat:no-repeat;
7783: background-color:transparent;
1.757 schulted 7784: }
7785:
1.915 droeschl 7786: ul.LC_funclist {
7787: margin: 0;
7788: padding: 0.5em 1em 0.5em 0;
7789: }
7790:
1.933 droeschl 7791: ul.LC_funclist > li:first-child {
7792: font-weight:bold;
7793: margin-left:0.8em;
7794: }
7795:
1.915 droeschl 7796: ul.LC_funclist + ul.LC_funclist {
7797: /*
7798: left border as a seperator if we have more than
7799: one list
7800: */
7801: border-left: 1px solid $sidebg;
7802: /*
7803: this hides the left border behind the border of the
7804: outer box if element is wrapped to the next 'line'
7805: */
7806: margin-left: -1px;
7807: }
7808:
1.843 bisitz 7809: ul.LC_funclist li {
1.915 droeschl 7810: display: inline;
1.782 bisitz 7811: white-space: nowrap;
1.915 droeschl 7812: margin: 0 0 0 25px;
7813: line-height: 150%;
1.782 bisitz 7814: }
7815:
1.974 wenzelju 7816: .LC_hidden {
7817: display: none;
7818: }
7819:
1.1030 www 7820: .LCmodal-overlay {
7821: position:fixed;
7822: top:0;
7823: right:0;
7824: bottom:0;
7825: left:0;
7826: height:100%;
7827: width:100%;
7828: margin:0;
7829: padding:0;
7830: background:#999;
7831: opacity:.75;
7832: filter: alpha(opacity=75);
7833: -moz-opacity: 0.75;
7834: z-index:101;
7835: }
7836:
7837: * html .LCmodal-overlay {
7838: position: absolute;
7839: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7840: }
7841:
7842: .LCmodal-window {
7843: position:fixed;
7844: top:50%;
7845: left:50%;
7846: margin:0;
7847: padding:0;
7848: z-index:102;
7849: }
7850:
7851: * html .LCmodal-window {
7852: position:absolute;
7853: }
7854:
7855: .LCclose-window {
7856: position:absolute;
7857: width:32px;
7858: height:32px;
7859: right:8px;
7860: top:8px;
7861: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7862: text-indent:-99999px;
7863: overflow:hidden;
7864: cursor:pointer;
7865: }
7866:
1.1075.2.141 raeburn 7867: pre.LC_wordwrap {
7868: white-space: pre-wrap;
7869: white-space: -moz-pre-wrap;
7870: white-space: -pre-wrap;
7871: white-space: -o-pre-wrap;
7872: word-wrap: break-word;
7873: }
7874:
1.1075.2.17 raeburn 7875: /*
7876: styles used by TTH when "Default set of options to pass to tth/m
7877: when converting TeX" in course settings has been set
7878:
7879: option passed: -t
7880:
7881: */
7882:
7883: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7884: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7885: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7886: td div.norm {line-height:normal;}
7887:
7888: /*
7889: option passed -y3
7890: */
7891:
7892: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7893: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7894: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7895:
1.1075.2.121 raeburn 7896: #LC_minitab_header {
7897: float:left;
7898: width:100%;
7899: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7900: font-size:93%;
7901: line-height:normal;
7902: margin: 0.5em 0 0.5em 0;
7903: }
7904: #LC_minitab_header ul {
7905: margin:0;
7906: padding:10px 10px 0;
7907: list-style:none;
7908: }
7909: #LC_minitab_header li {
7910: float:left;
7911: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7912: margin:0;
7913: padding:0 0 0 9px;
7914: }
7915: #LC_minitab_header a {
7916: display:block;
7917: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7918: padding:5px 15px 4px 6px;
7919: }
7920: #LC_minitab_header #LC_current_minitab {
7921: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7922: }
7923: #LC_minitab_header #LC_current_minitab a {
7924: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7925: padding-bottom:5px;
7926: }
7927:
7928:
1.343 albertel 7929: END
7930: }
7931:
1.306 albertel 7932: =pod
7933:
7934: =item * &headtag()
7935:
7936: Returns a uniform footer for LON-CAPA web pages.
7937:
1.307 albertel 7938: Inputs: $title - optional title for the head
7939: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7940: $args - optional arguments
1.319 albertel 7941: force_register - if is true call registerurl so the remote is
7942: informed
1.415 albertel 7943: redirect -> array ref of
7944: 1- seconds before redirect occurs
7945: 2- url to redirect to
7946: 3- whether the side effect should occur
1.315 albertel 7947: (side effect of setting
7948: $env{'internal.head.redirect'} to the url
7949: redirected too)
1.352 albertel 7950: domain -> force to color decorate a page for a specific
7951: domain
7952: function -> force usage of a specific rolish color scheme
7953: bgcolor -> override the default page bgcolor
1.460 albertel 7954: no_auto_mt_title
7955: -> prevent &mt()ing the title arg
1.464 albertel 7956:
1.306 albertel 7957: =cut
7958:
7959: sub headtag {
1.313 albertel 7960: my ($title,$head_extra,$args) = @_;
1.306 albertel 7961:
1.363 albertel 7962: my $function = $args->{'function'} || &get_users_function();
7963: my $domain = $args->{'domain'} || &determinedomain();
7964: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7965: my $httphost = $args->{'use_absolute'};
1.418 albertel 7966: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7967: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7968: #time(),
1.418 albertel 7969: $env{'environment.color.timestamp'},
1.363 albertel 7970: $function,$domain,$bgcolor);
7971:
1.369 www 7972: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7973:
1.308 albertel 7974: my $result =
7975: '<head>'.
1.1075.2.56 raeburn 7976: &font_settings($args);
1.319 albertel 7977:
1.1075.2.72 raeburn 7978: my $inhibitprint;
7979: if ($args->{'print_suppress'}) {
7980: $inhibitprint = &print_suppression();
7981: }
1.1064 raeburn 7982:
1.461 albertel 7983: if (!$args->{'frameset'}) {
7984: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7985: }
1.1075.2.12 raeburn 7986: if ($args->{'force_register'}) {
7987: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7988: }
1.436 albertel 7989: if (!$args->{'no_nav_bar'}
7990: && !$args->{'only_body'}
7991: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7992: $result .= &help_menu_js($httphost);
1.1032 www 7993: $result.=&modal_window();
1.1038 www 7994: $result.=&togglebox_script();
1.1034 www 7995: $result.=&wishlist_window();
1.1041 www 7996: $result.=&LCprogressbarUpdate_script();
1.1034 www 7997: } else {
7998: if ($args->{'add_modal'}) {
7999: $result.=&modal_window();
8000: }
8001: if ($args->{'add_wishlist'}) {
8002: $result.=&wishlist_window();
8003: }
1.1038 www 8004: if ($args->{'add_togglebox'}) {
8005: $result.=&togglebox_script();
8006: }
1.1041 www 8007: if ($args->{'add_progressbar'}) {
8008: $result.=&LCprogressbarUpdate_script();
8009: }
1.436 albertel 8010: }
1.314 albertel 8011: if (ref($args->{'redirect'})) {
1.414 albertel 8012: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8013: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8014: if (!$inhibit_continue) {
8015: $env{'internal.head.redirect'} = $url;
8016: }
1.313 albertel 8017: $result.=<<ADDMETA
8018: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8019: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8020: ADDMETA
1.1075.2.89 raeburn 8021: } else {
8022: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8023: my $requrl = $env{'request.uri'};
8024: if ($requrl eq '') {
8025: $requrl = $ENV{'REQUEST_URI'};
8026: $requrl =~ s/\?.+$//;
8027: }
8028: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8029: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8030: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8031: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8032: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8033: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.141. .4(raebu 8034:20): my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8035:20): my $offload;
1.1075.2.89 raeburn 8036: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8037: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.141. .4(raebu 8038:20): $offload = 1;
8039:20): }
8040:20): }
8041:20): unless ($offload) {
8042:20): if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8043:20): if ($domdefs{'offloadoth'}{$lonhost}) {
8044:20): if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8045:20): (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8046:20): unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8047:20): $offload = 1;
8048:20): $dom_in_use = $env{'user.domain'};
8049:20): }
1.1075.2.89 raeburn 8050: }
1.1075.2.141. .4(raebu 8051:20): }
8052:20): }
8053:20): }
8054:20): if ($offload) {
8055:20): my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8056:20): if (($newserver) && ($newserver ne $lonhost)) {
8057:20): my $numsec = 5;
8058:20): my $timeout = $numsec * 1000;
8059:20): my ($newurl,$locknum,%locks,$msg);
8060:20): if ($env{'request.role.adv'}) {
8061:20): ($locknum,%locks) = &Apache::lonnet::get_locks();
8062:20): }
8063:20): my $disable_submit = 0;
8064:20): if ($requrl =~ /$LONCAPA::assess_re/) {
8065:20): $disable_submit = 1;
8066:20): }
8067:20): if ($locknum) {
8068:20): my @lockinfo = sort(values(%locks));
8069:20): $msg = &mt('Once the following tasks are complete: ')."\n".
8070:20): join(", ",sort(values(%locks)))."\n";
8071:20): if (&show_course()) {
8072:20): $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8073: } else {
1.1075.2.141. .4(raebu 8074:20): $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8075:20): }
8076:20): } else {
8077:20): if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8078:20): $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8079:20): }
8080:20): $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8081:20): $newurl = '/adm/switchserver?otherserver='.$newserver;
8082:20): if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8083:20): $newurl .= '&role='.$env{'request.role'};
8084:20): }
8085:20): if ($env{'request.symb'}) {
8086:20): my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8087:20): if ($shownsymb =~ m{^/enc/}) {
8088:20): my $reqdmajor = 2;
8089:20): my $reqdminor = 11;
8090:20): my $reqdsubminor = 3;
8091:20): my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8092:20): my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8093:20): my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8094:20): if (($major eq '' && $minor eq '') ||
8095:20): (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8096:20): (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8097:20): ($reqdsubminor > $subminor))))) {
8098:20): undef($shownsymb);
8099:20): }
1.1075.2.89 raeburn 8100: }
1.1075.2.141. .4(raebu 8101:20): if ($shownsymb) {
8102:20): &js_escape(\$shownsymb);
8103:20): $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8104: }
1.1075.2.141. .4(raebu 8105:20): } else {
8106:20): my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8107:20): &js_escape(\$shownurl);
8108:20): $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8109: }
1.1075.2.141. .4(raebu 8110:20): }
8111:20): &js_escape(\$msg);
8112:20): $result.=<<OFFLOAD
1.1075.2.89 raeburn 8113: <meta http-equiv="pragma" content="no-cache" />
8114: <script type="text/javascript">
1.1075.2.92 raeburn 8115: // <![CDATA[
1.1075.2.89 raeburn 8116: function LC_Offload_Now() {
8117: var dest = "$newurl";
8118: if (dest != '') {
8119: window.location.href="$newurl";
8120: }
8121: }
1.1075.2.92 raeburn 8122: \$(document).ready(function () {
8123: window.alert('$msg');
8124: if ($disable_submit) {
1.1075.2.89 raeburn 8125: \$(".LC_hwk_submit").prop("disabled", true);
8126: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8127: }
8128: setTimeout('LC_Offload_Now()', $timeout);
8129: });
8130: // ]]>
1.1075.2.89 raeburn 8131: </script>
8132: OFFLOAD
8133: }
8134: }
8135: }
8136: }
8137: }
1.313 albertel 8138: }
1.306 albertel 8139: if (!defined($title)) {
8140: $title = 'The LearningOnline Network with CAPA';
8141: }
1.460 albertel 8142: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8143: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8144: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8145: if (!$args->{'frameset'}) {
8146: $result .= ' /';
8147: }
8148: $result .= '>'
1.1064 raeburn 8149: .$inhibitprint
1.414 albertel 8150: .$head_extra;
1.1075.2.108 raeburn 8151: my $clientmobile;
8152: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8153: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8154: } else {
8155: $clientmobile = $env{'browser.mobile'};
8156: }
8157: if ($clientmobile) {
1.1075.2.42 raeburn 8158: $result .= '
8159: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8160: <meta name="apple-mobile-web-app-capable" content="yes" />';
8161: }
1.1075.2.126 raeburn 8162: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8163: return $result.'</head>';
1.306 albertel 8164: }
8165:
8166: =pod
8167:
1.340 albertel 8168: =item * &font_settings()
8169:
8170: Returns neccessary <meta> to set the proper encoding
8171:
1.1075.2.56 raeburn 8172: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8173:
8174: =cut
8175:
8176: sub font_settings {
1.1075.2.56 raeburn 8177: my ($args) = @_;
1.340 albertel 8178: my $headerstring='';
1.1075.2.56 raeburn 8179: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8180: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8181: $headerstring.=
1.1075.2.61 raeburn 8182: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8183: if (!$args->{'frameset'}) {
8184: $headerstring.= ' /';
8185: }
8186: $headerstring .= '>'."\n";
1.340 albertel 8187: }
8188: return $headerstring;
8189: }
8190:
1.341 albertel 8191: =pod
8192:
1.1064 raeburn 8193: =item * &print_suppression()
8194:
8195: In course context returns css which causes the body to be blank when media="print",
8196: if printout generation is unavailable for the current resource.
8197:
8198: This could be because:
8199:
8200: (a) printstartdate is in the future
8201:
8202: (b) printenddate is in the past
8203:
8204: (c) there is an active exam block with "printout"
8205: functionality blocked
8206:
8207: Users with pav, pfo or evb privileges are exempt.
8208:
8209: Inputs: none
8210:
8211: =cut
8212:
8213:
8214: sub print_suppression {
8215: my $noprint;
8216: if ($env{'request.course.id'}) {
8217: my $scope = $env{'request.course.id'};
8218: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8219: (&Apache::lonnet::allowed('pfo',$scope))) {
8220: return;
8221: }
8222: if ($env{'request.course.sec'} ne '') {
8223: $scope .= "/$env{'request.course.sec'}";
8224: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8225: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8226: return;
1.1064 raeburn 8227: }
8228: }
8229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8230: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8231: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8232: if ($blocked) {
8233: my $checkrole = "cm./$cdom/$cnum";
8234: if ($env{'request.course.sec'} ne '') {
8235: $checkrole .= "/$env{'request.course.sec'}";
8236: }
8237: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8238: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8239: $noprint = 1;
8240: }
8241: }
8242: unless ($noprint) {
8243: my $symb = &Apache::lonnet::symbread();
8244: if ($symb ne '') {
8245: my $navmap = Apache::lonnavmaps::navmap->new();
8246: if (ref($navmap)) {
8247: my $res = $navmap->getBySymb($symb);
8248: if (ref($res)) {
8249: if (!$res->resprintable()) {
8250: $noprint = 1;
8251: }
8252: }
8253: }
8254: }
8255: }
8256: if ($noprint) {
8257: return <<"ENDSTYLE";
8258: <style type="text/css" media="print">
8259: body { display:none }
8260: </style>
8261: ENDSTYLE
8262: }
8263: }
8264: return;
8265: }
8266:
8267: =pod
8268:
1.341 albertel 8269: =item * &xml_begin()
8270:
8271: Returns the needed doctype and <html>
8272:
8273: Inputs: none
8274:
8275: =cut
8276:
8277: sub xml_begin {
1.1075.2.61 raeburn 8278: my ($is_frameset) = @_;
1.341 albertel 8279: my $output='';
8280:
8281: if ($env{'browser.mathml'}) {
8282: $output='<?xml version="1.0"?>'
8283: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8284: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8285:
8286: # .'<!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">] >'
8287: .'<!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">'
8288: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8289: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8290: } elsif ($is_frameset) {
8291: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8292: '<html>'."\n";
1.341 albertel 8293: } else {
1.1075.2.61 raeburn 8294: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8295: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8296: }
8297: return $output;
8298: }
1.340 albertel 8299:
8300: =pod
8301:
1.306 albertel 8302: =item * &start_page()
8303:
8304: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8305:
1.648 raeburn 8306: Inputs:
8307:
8308: =over 4
8309:
8310: $title - optional title for the page
8311:
8312: $head_extra - optional extra HTML to incude inside the <head>
8313:
8314: $args - additional optional args supported are:
8315:
8316: =over 8
8317:
8318: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8319: arg on
1.814 bisitz 8320: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8321: add_entries -> additional attributes to add to the <body>
8322: domain -> force to color decorate a page for a
1.317 albertel 8323: specific domain
1.648 raeburn 8324: function -> force usage of a specific rolish color
1.317 albertel 8325: scheme
1.648 raeburn 8326: redirect -> see &headtag()
8327: bgcolor -> override the default page bg color
8328: js_ready -> return a string ready for being used in
1.317 albertel 8329: a javascript writeln
1.648 raeburn 8330: html_encode -> return a string ready for being used in
1.320 albertel 8331: a html attribute
1.648 raeburn 8332: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8333: $forcereg arg
1.648 raeburn 8334: frameset -> if true will start with a <frameset>
1.330 albertel 8335: rather than <body>
1.648 raeburn 8336: skip_phases -> hash ref of
1.338 albertel 8337: head -> skip the <html><head> generation
8338: body -> skip all <body> generation
1.1075.2.12 raeburn 8339: no_inline_link -> if true and in remote mode, don't show the
8340: 'Switch To Inline Menu' link
1.648 raeburn 8341: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8342: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8343: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8344: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8345: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8346: group -> includes the current group, if page is for a
8347: specific group
1.1075.2.133 raeburn 8348: use_absolute -> for request for external resource or syllabus, this
8349: will contain https://<hostname> if server uses
8350: https (as per hosts.tab), but request is for http
8351: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8352:
1.648 raeburn 8353: =back
1.460 albertel 8354:
1.648 raeburn 8355: =back
1.562 albertel 8356:
1.306 albertel 8357: =cut
8358:
8359: sub start_page {
1.309 albertel 8360: my ($title,$head_extra,$args) = @_;
1.318 albertel 8361: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8362:
1.315 albertel 8363: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8364: my ($result,@advtools);
1.964 droeschl 8365:
1.338 albertel 8366: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8367: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8368: }
8369:
8370: if (! exists($args->{'skip_phases'}{'body'}) ) {
8371: if ($args->{'frameset'}) {
8372: my $attr_string = &make_attr_string($args->{'force_register'},
8373: $args->{'add_entries'});
8374: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8375: } else {
8376: $result .=
8377: &bodytag($title,
8378: $args->{'function'}, $args->{'add_entries'},
8379: $args->{'only_body'}, $args->{'domain'},
8380: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8381: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8382: $args, \@advtools);
1.831 bisitz 8383: }
1.330 albertel 8384: }
1.338 albertel 8385:
1.315 albertel 8386: if ($args->{'js_ready'}) {
1.713 kaisler 8387: $result = &js_ready($result);
1.315 albertel 8388: }
1.320 albertel 8389: if ($args->{'html_encode'}) {
1.713 kaisler 8390: $result = &html_encode($result);
8391: }
8392:
1.813 bisitz 8393: # Preparation for new and consistent functionlist at top of screen
8394: # if ($args->{'functionlist'}) {
8395: # $result .= &build_functionlist();
8396: #}
8397:
1.964 droeschl 8398: # Don't add anything more if only_body wanted or in const space
8399: return $result if $args->{'only_body'}
8400: || $env{'request.state'} eq 'construct';
1.813 bisitz 8401:
8402: #Breadcrumbs
1.758 kaisler 8403: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8404: &Apache::lonhtmlcommon::clear_breadcrumbs();
8405: #if any br links exists, add them to the breadcrumbs
8406: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8407: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8408: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8409: }
8410: }
1.1075.2.19 raeburn 8411: # if @advtools array contains items add then to the breadcrumbs
8412: if (@advtools > 0) {
8413: &Apache::lonmenu::advtools_crumbs(@advtools);
8414: }
1.1075.2.123 raeburn 8415: my $menulink;
8416: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8417: if (exists($args->{'bread_crumbs_nomenu'})) {
8418: $menulink = 0;
8419: } else {
8420: undef($menulink);
8421: }
1.758 kaisler 8422: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8423: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8424: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8425: }else{
1.1075.2.123 raeburn 8426: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8427: }
1.1075.2.24 raeburn 8428: } elsif (($env{'environment.remote'} eq 'on') &&
8429: ($env{'form.inhibitmenu'} ne 'yes') &&
8430: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8431: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8432: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8433: }
1.315 albertel 8434: return $result;
1.306 albertel 8435: }
8436:
8437: sub end_page {
1.315 albertel 8438: my ($args) = @_;
8439: $env{'internal.end_page'}++;
1.330 albertel 8440: my $result;
1.335 albertel 8441: if ($args->{'discussion'}) {
8442: my ($target,$parser);
8443: if (ref($args->{'discussion'})) {
8444: ($target,$parser) =($args->{'discussion'}{'target'},
8445: $args->{'discussion'}{'parser'});
8446: }
8447: $result .= &Apache::lonxml::xmlend($target,$parser);
8448: }
1.330 albertel 8449: if ($args->{'frameset'}) {
8450: $result .= '</frameset>';
8451: } else {
1.635 raeburn 8452: $result .= &endbodytag($args);
1.330 albertel 8453: }
1.1075.2.6 raeburn 8454: unless ($args->{'notbody'}) {
8455: $result .= "\n</html>";
8456: }
1.330 albertel 8457:
1.315 albertel 8458: if ($args->{'js_ready'}) {
1.317 albertel 8459: $result = &js_ready($result);
1.315 albertel 8460: }
1.335 albertel 8461:
1.320 albertel 8462: if ($args->{'html_encode'}) {
8463: $result = &html_encode($result);
8464: }
1.335 albertel 8465:
1.315 albertel 8466: return $result;
8467: }
8468:
1.1034 www 8469: sub wishlist_window {
8470: return(<<'ENDWISHLIST');
1.1046 raeburn 8471: <script type="text/javascript">
1.1034 www 8472: // <![CDATA[
8473: // <!-- BEGIN LON-CAPA Internal
8474: function set_wishlistlink(title, path) {
8475: if (!title) {
8476: title = document.title;
8477: title = title.replace(/^LON-CAPA /,'');
8478: }
1.1075.2.65 raeburn 8479: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8480: title = title.replace("'","\\\'");
1.1034 www 8481: if (!path) {
8482: path = location.pathname;
8483: }
1.1075.2.65 raeburn 8484: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8485: path = path.replace("'","\\\'");
1.1034 www 8486: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8487: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8488: }
8489: // END LON-CAPA Internal -->
8490: // ]]>
8491: </script>
8492: ENDWISHLIST
8493: }
8494:
1.1030 www 8495: sub modal_window {
8496: return(<<'ENDMODAL');
1.1046 raeburn 8497: <script type="text/javascript">
1.1030 www 8498: // <![CDATA[
8499: // <!-- BEGIN LON-CAPA Internal
8500: var modalWindow = {
8501: parent:"body",
8502: windowId:null,
8503: content:null,
8504: width:null,
8505: height:null,
8506: close:function()
8507: {
8508: $(".LCmodal-window").remove();
8509: $(".LCmodal-overlay").remove();
8510: },
8511: open:function()
8512: {
8513: var modal = "";
8514: modal += "<div class=\"LCmodal-overlay\"></div>";
8515: 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;\">";
8516: modal += this.content;
8517: modal += "</div>";
8518:
8519: $(this.parent).append(modal);
8520:
8521: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8522: $(".LCclose-window").click(function(){modalWindow.close();});
8523: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8524: }
8525: };
1.1075.2.42 raeburn 8526: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8527: {
1.1075.2.119 raeburn 8528: source = source.replace(/'/g,"'");
1.1030 www 8529: modalWindow.windowId = "myModal";
8530: modalWindow.width = width;
8531: modalWindow.height = height;
1.1075.2.80 raeburn 8532: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8533: modalWindow.open();
1.1075.2.87 raeburn 8534: };
1.1030 www 8535: // END LON-CAPA Internal -->
8536: // ]]>
8537: </script>
8538: ENDMODAL
8539: }
8540:
8541: sub modal_link {
1.1075.2.42 raeburn 8542: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8543: unless ($width) { $width=480; }
8544: unless ($height) { $height=400; }
1.1031 www 8545: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8546: unless ($transparency) { $transparency='true'; }
8547:
1.1074 raeburn 8548: my $target_attr;
8549: if (defined($target)) {
8550: $target_attr = 'target="'.$target.'"';
8551: }
8552: return <<"ENDLINK";
1.1075.2.141. .3(raebu 8553:20): <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8554: ENDLINK
1.1030 www 8555: }
8556:
1.1032 www 8557: sub modal_adhoc_script {
8558: my ($funcname,$width,$height,$content)=@_;
8559: return (<<ENDADHOC);
1.1046 raeburn 8560: <script type="text/javascript">
1.1032 www 8561: // <![CDATA[
8562: var $funcname = function()
8563: {
8564: modalWindow.windowId = "myModal";
8565: modalWindow.width = $width;
8566: modalWindow.height = $height;
8567: modalWindow.content = '$content';
8568: modalWindow.open();
8569: };
8570: // ]]>
8571: </script>
8572: ENDADHOC
8573: }
8574:
1.1041 www 8575: sub modal_adhoc_inner {
8576: my ($funcname,$width,$height,$content)=@_;
8577: my $innerwidth=$width-20;
8578: $content=&js_ready(
1.1042 www 8579: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8580: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8581: $content.
1.1041 www 8582: &end_scrollbox().
1.1075.2.42 raeburn 8583: &end_page()
1.1041 www 8584: );
8585: return &modal_adhoc_script($funcname,$width,$height,$content);
8586: }
8587:
8588: sub modal_adhoc_window {
8589: my ($funcname,$width,$height,$content,$linktext)=@_;
8590: return &modal_adhoc_inner($funcname,$width,$height,$content).
8591: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8592: }
8593:
8594: sub modal_adhoc_launch {
8595: my ($funcname,$width,$height,$content)=@_;
8596: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8597: <script type="text/javascript">
8598: // <![CDATA[
8599: $funcname();
8600: // ]]>
8601: </script>
8602: ENDLAUNCH
8603: }
8604:
8605: sub modal_adhoc_close {
8606: return (<<ENDCLOSE);
8607: <script type="text/javascript">
8608: // <![CDATA[
8609: modalWindow.close();
8610: // ]]>
8611: </script>
8612: ENDCLOSE
8613: }
8614:
1.1038 www 8615: sub togglebox_script {
8616: return(<<ENDTOGGLE);
8617: <script type="text/javascript">
8618: // <![CDATA[
8619: function LCtoggleDisplay(id,hidetext,showtext) {
8620: link = document.getElementById(id + "link").childNodes[0];
8621: with (document.getElementById(id).style) {
8622: if (display == "none" ) {
8623: display = "inline";
8624: link.nodeValue = hidetext;
8625: } else {
8626: display = "none";
8627: link.nodeValue = showtext;
8628: }
8629: }
8630: }
8631: // ]]>
8632: </script>
8633: ENDTOGGLE
8634: }
8635:
1.1039 www 8636: sub start_togglebox {
8637: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8638: unless ($heading) { $heading=''; } else { $heading.=' '; }
8639: unless ($showtext) { $showtext=&mt('show'); }
8640: unless ($hidetext) { $hidetext=&mt('hide'); }
8641: unless ($headerbg) { $headerbg='#FFFFFF'; }
8642: return &start_data_table().
8643: &start_data_table_header_row().
8644: '<td bgcolor="'.$headerbg.'">'.$heading.
8645: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8646: $showtext.'\')">'.$showtext.'</a>]</td>'.
8647: &end_data_table_header_row().
8648: '<tr id="'.$id.'" style="display:none""><td>';
8649: }
8650:
8651: sub end_togglebox {
8652: return '</td></tr>'.&end_data_table();
8653: }
8654:
1.1041 www 8655: sub LCprogressbar_script {
1.1075.2.130 raeburn 8656: my ($id,$number_to_do)=@_;
8657: if ($number_to_do) {
8658: return(<<ENDPROGRESS);
1.1041 www 8659: <script type="text/javascript">
8660: // <![CDATA[
1.1045 www 8661: \$('#progressbar$id').progressbar({
1.1041 www 8662: value: 0,
8663: change: function(event, ui) {
8664: var newVal = \$(this).progressbar('option', 'value');
8665: \$('.pblabel', this).text(LCprogressTxt);
8666: }
8667: });
8668: // ]]>
8669: </script>
8670: ENDPROGRESS
1.1075.2.130 raeburn 8671: } else {
8672: return(<<ENDPROGRESS);
8673: <script type="text/javascript">
8674: // <![CDATA[
8675: \$('#progressbar$id').progressbar({
8676: value: false,
8677: create: function(event, ui) {
8678: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8679: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8680: }
8681: });
8682: // ]]>
8683: </script>
8684: ENDPROGRESS
8685: }
1.1041 www 8686: }
8687:
8688: sub LCprogressbarUpdate_script {
8689: return(<<ENDPROGRESSUPDATE);
8690: <style type="text/css">
8691: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8692: .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 8693: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8694: </style>
8695: <script type="text/javascript">
8696: // <![CDATA[
1.1045 www 8697: var LCprogressTxt='---';
8698:
1.1075.2.130 raeburn 8699: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8700: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8701: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8702: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8703: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8704: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8705: } else {
8706: \$('#progressbar'+id).progressbar('value',percent);
8707: }
1.1041 www 8708: }
8709: // ]]>
8710: </script>
8711: ENDPROGRESSUPDATE
8712: }
8713:
1.1042 www 8714: my $LClastpercent;
1.1045 www 8715: my $LCidcnt;
8716: my $LCcurrentid;
1.1042 www 8717:
1.1041 www 8718: sub LCprogressbar {
1.1075.2.130 raeburn 8719: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8720: $LClastpercent=0;
1.1045 www 8721: $LCidcnt++;
8722: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8723: my ($starting,$content);
8724: if ($number_to_do) {
8725: $starting=&mt('Starting');
8726: $content=(<<ENDPROGBAR);
8727: $preamble
1.1045 www 8728: <div id="progressbar$LCcurrentid">
1.1041 www 8729: <span class="pblabel">$starting</span>
8730: </div>
8731: ENDPROGBAR
1.1075.2.130 raeburn 8732: } else {
8733: $starting=&mt('Loading...');
8734: $LClastpercent='false';
8735: $content=(<<ENDPROGBAR);
8736: $preamble
8737: <div id="progressbar$LCcurrentid">
8738: <div class="progress-label">$starting</div>
8739: </div>
8740: ENDPROGBAR
8741: }
8742: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8743: }
8744:
8745: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8746: my ($r,$val,$text,$number_to_do)=@_;
8747: if ($number_to_do) {
8748: unless ($val) {
8749: if ($LClastpercent) {
8750: $val=$LClastpercent;
8751: } else {
8752: $val=0;
8753: }
8754: }
8755: if ($val<0) { $val=0; }
8756: if ($val>100) { $val=0; }
8757: $LClastpercent=$val;
8758: unless ($text) { $text=$val.'%'; }
8759: } else {
8760: $val = 'false';
1.1042 www 8761: }
1.1041 www 8762: $text=&js_ready($text);
1.1044 www 8763: &r_print($r,<<ENDUPDATE);
1.1041 www 8764: <script type="text/javascript">
8765: // <![CDATA[
1.1075.2.130 raeburn 8766: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8767: // ]]>
8768: </script>
8769: ENDUPDATE
1.1035 www 8770: }
8771:
1.1042 www 8772: sub LCprogressbarClose {
8773: my ($r)=@_;
8774: $LClastpercent=0;
1.1044 www 8775: &r_print($r,<<ENDCLOSE);
1.1042 www 8776: <script type="text/javascript">
8777: // <![CDATA[
1.1045 www 8778: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8779: // ]]>
8780: </script>
8781: ENDCLOSE
1.1044 www 8782: }
8783:
8784: sub r_print {
8785: my ($r,$to_print)=@_;
8786: if ($r) {
8787: $r->print($to_print);
8788: $r->rflush();
8789: } else {
8790: print($to_print);
8791: }
1.1042 www 8792: }
8793:
1.320 albertel 8794: sub html_encode {
8795: my ($result) = @_;
8796:
1.322 albertel 8797: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8798:
8799: return $result;
8800: }
1.1044 www 8801:
1.317 albertel 8802: sub js_ready {
8803: my ($result) = @_;
8804:
1.323 albertel 8805: $result =~ s/[\n\r]/ /xmsg;
8806: $result =~ s/\\/\\\\/xmsg;
8807: $result =~ s/'/\\'/xmsg;
1.372 albertel 8808: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8809:
8810: return $result;
8811: }
8812:
1.315 albertel 8813: sub validate_page {
8814: if ( exists($env{'internal.start_page'})
1.316 albertel 8815: && $env{'internal.start_page'} > 1) {
8816: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8817: $env{'internal.start_page'}.' '.
1.316 albertel 8818: $ENV{'request.filename'});
1.315 albertel 8819: }
8820: if ( exists($env{'internal.end_page'})
1.316 albertel 8821: && $env{'internal.end_page'} > 1) {
8822: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8823: $env{'internal.end_page'}.' '.
1.316 albertel 8824: $env{'request.filename'});
1.315 albertel 8825: }
8826: if ( exists($env{'internal.start_page'})
8827: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8828: &Apache::lonnet::logthis('start_page called without end_page '.
8829: $env{'request.filename'});
1.315 albertel 8830: }
8831: if ( ! exists($env{'internal.start_page'})
8832: && exists($env{'internal.end_page'})) {
1.316 albertel 8833: &Apache::lonnet::logthis('end_page called without start_page'.
8834: $env{'request.filename'});
1.315 albertel 8835: }
1.306 albertel 8836: }
1.315 albertel 8837:
1.996 www 8838:
8839: sub start_scrollbox {
1.1075.2.56 raeburn 8840: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8841: unless ($outerwidth) { $outerwidth='520px'; }
8842: unless ($width) { $width='500px'; }
8843: unless ($height) { $height='200px'; }
1.1075 raeburn 8844: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8845: if ($id ne '') {
1.1075.2.42 raeburn 8846: $table_id = ' id="table_'.$id.'"';
8847: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8848: }
1.1075 raeburn 8849: if ($bgcolor ne '') {
8850: $tdcol = "background-color: $bgcolor;";
8851: }
1.1075.2.42 raeburn 8852: my $nicescroll_js;
8853: if ($env{'browser.mobile'}) {
8854: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8855: }
1.1075 raeburn 8856: return <<"END";
1.1075.2.42 raeburn 8857: $nicescroll_js
8858:
8859: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8860: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8861: END
1.996 www 8862: }
8863:
8864: sub end_scrollbox {
1.1036 www 8865: return '</div></td></tr></table>';
1.996 www 8866: }
8867:
1.1075.2.42 raeburn 8868: sub nicescroll_javascript {
8869: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8870: my %options;
8871: if (ref($cursor) eq 'HASH') {
8872: %options = %{$cursor};
8873: }
8874: unless ($options{'railalign'} =~ /^left|right$/) {
8875: $options{'railalign'} = 'left';
8876: }
8877: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8878: my $function = &get_users_function();
8879: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8880: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8881: $options{'cursorcolor'} = '#00F';
8882: }
8883: }
8884: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8885: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8886: $options{'cursoropacity'}='1.0';
8887: }
8888: } else {
8889: $options{'cursoropacity'}='1.0';
8890: }
8891: if ($options{'cursorfixedheight'} eq 'none') {
8892: delete($options{'cursorfixedheight'});
8893: } else {
8894: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8895: }
8896: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8897: delete($options{'railoffset'});
8898: }
8899: my @niceoptions;
8900: while (my($key,$value) = each(%options)) {
8901: if ($value =~ /^\{.+\}$/) {
8902: push(@niceoptions,$key.':'.$value);
8903: } else {
8904: push(@niceoptions,$key.':"'.$value.'"');
8905: }
8906: }
8907: my $nicescroll_js = '
8908: $(document).ready(
8909: function() {
8910: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8911: }
8912: );
8913: ';
8914: if ($framecheck) {
8915: $nicescroll_js .= '
8916: function expand_div(caller) {
8917: if (top === self) {
8918: document.getElementById("'.$id.'").style.width = "auto";
8919: document.getElementById("'.$id.'").style.height = "auto";
8920: } else {
8921: try {
8922: if (parent.frames) {
8923: if (parent.frames.length > 1) {
8924: var framesrc = parent.frames[1].location.href;
8925: var currsrc = framesrc.replace(/\#.*$/,"");
8926: if ((caller == "search") || (currsrc == "'.$location.'")) {
8927: document.getElementById("'.$id.'").style.width = "auto";
8928: document.getElementById("'.$id.'").style.height = "auto";
8929: }
8930: }
8931: }
8932: } catch (e) {
8933: return;
8934: }
8935: }
8936: return;
8937: }
8938: ';
8939: }
8940: if ($needjsready) {
8941: $nicescroll_js = '
8942: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8943: } else {
8944: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8945: }
8946: return $nicescroll_js;
8947: }
8948:
1.318 albertel 8949: sub simple_error_page {
1.1075.2.49 raeburn 8950: my ($r,$title,$msg,$args) = @_;
8951: if (ref($args) eq 'HASH') {
8952: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8953: } else {
8954: $msg = &mt($msg);
8955: }
8956:
1.318 albertel 8957: my $page =
8958: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8959: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8960: &Apache::loncommon::end_page();
8961: if (ref($r)) {
8962: $r->print($page);
1.327 albertel 8963: return;
1.318 albertel 8964: }
8965: return $page;
8966: }
1.347 albertel 8967:
8968: {
1.610 albertel 8969: my @row_count;
1.961 onken 8970:
8971: sub start_data_table_count {
8972: unshift(@row_count, 0);
8973: return;
8974: }
8975:
8976: sub end_data_table_count {
8977: shift(@row_count);
8978: return;
8979: }
8980:
1.347 albertel 8981: sub start_data_table {
1.1018 raeburn 8982: my ($add_class,$id) = @_;
1.422 albertel 8983: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8984: my $table_id;
8985: if (defined($id)) {
8986: $table_id = ' id="'.$id.'"';
8987: }
1.961 onken 8988: &start_data_table_count();
1.1018 raeburn 8989: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8990: }
8991:
8992: sub end_data_table {
1.961 onken 8993: &end_data_table_count();
1.389 albertel 8994: return '</table>'."\n";;
1.347 albertel 8995: }
8996:
8997: sub start_data_table_row {
1.974 wenzelju 8998: my ($add_class, $id) = @_;
1.610 albertel 8999: $row_count[0]++;
9000: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9001: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9002: $id = (' id="'.$id.'"') unless ($id eq '');
9003: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9004: }
1.471 banghart 9005:
9006: sub continue_data_table_row {
1.974 wenzelju 9007: my ($add_class, $id) = @_;
1.610 albertel 9008: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9009: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9010: $id = (' id="'.$id.'"') unless ($id eq '');
9011: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9012: }
1.347 albertel 9013:
9014: sub end_data_table_row {
1.389 albertel 9015: return '</tr>'."\n";;
1.347 albertel 9016: }
1.367 www 9017:
1.421 albertel 9018: sub start_data_table_empty_row {
1.707 bisitz 9019: # $row_count[0]++;
1.421 albertel 9020: return '<tr class="LC_empty_row" >'."\n";;
9021: }
9022:
9023: sub end_data_table_empty_row {
9024: return '</tr>'."\n";;
9025: }
9026:
1.367 www 9027: sub start_data_table_header_row {
1.389 albertel 9028: return '<tr class="LC_header_row">'."\n";;
1.367 www 9029: }
9030:
9031: sub end_data_table_header_row {
1.389 albertel 9032: return '</tr>'."\n";;
1.367 www 9033: }
1.890 droeschl 9034:
9035: sub data_table_caption {
9036: my $caption = shift;
9037: return "<caption class=\"LC_caption\">$caption</caption>";
9038: }
1.347 albertel 9039: }
9040:
1.548 albertel 9041: =pod
9042:
9043: =item * &inhibit_menu_check($arg)
9044:
9045: Checks for a inhibitmenu state and generates output to preserve it
9046:
9047: Inputs: $arg - can be any of
9048: - undef - in which case the return value is a string
9049: to add into arguments list of a uri
9050: - 'input' - in which case the return value is a HTML
9051: <form> <input> field of type hidden to
9052: preserve the value
9053: - a url - in which case the return value is the url with
9054: the neccesary cgi args added to preserve the
9055: inhibitmenu state
9056: - a ref to a url - no return value, but the string is
9057: updated to include the neccessary cgi
9058: args to preserve the inhibitmenu state
9059:
9060: =cut
9061:
9062: sub inhibit_menu_check {
9063: my ($arg) = @_;
9064: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9065: if ($arg eq 'input') {
9066: if ($env{'form.inhibitmenu'}) {
9067: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9068: } else {
9069: return
9070: }
9071: }
9072: if ($env{'form.inhibitmenu'}) {
9073: if (ref($arg)) {
9074: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9075: } elsif ($arg eq '') {
9076: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9077: } else {
9078: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9079: }
9080: }
9081: if (!ref($arg)) {
9082: return $arg;
9083: }
9084: }
9085:
1.251 albertel 9086: ###############################################
1.182 matthew 9087:
9088: =pod
9089:
1.549 albertel 9090: =back
9091:
9092: =head1 User Information Routines
9093:
9094: =over 4
9095:
1.405 albertel 9096: =item * &get_users_function()
1.182 matthew 9097:
9098: Used by &bodytag to determine the current users primary role.
9099: Returns either 'student','coordinator','admin', or 'author'.
9100:
9101: =cut
9102:
9103: ###############################################
9104: sub get_users_function {
1.815 tempelho 9105: my $function = 'norole';
1.818 tempelho 9106: if ($env{'request.role'}=~/^(st)/) {
9107: $function='student';
9108: }
1.907 raeburn 9109: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9110: $function='coordinator';
9111: }
1.258 albertel 9112: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9113: $function='admin';
9114: }
1.826 bisitz 9115: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9116: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9117: $function='author';
9118: }
9119: return $function;
1.54 www 9120: }
1.99 www 9121:
9122: ###############################################
9123:
1.233 raeburn 9124: =pod
9125:
1.821 raeburn 9126: =item * &show_course()
9127:
9128: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9129: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9130:
9131: Inputs:
9132: None
9133:
9134: Outputs:
9135: Scalar: 1 if 'Course' to be used, 0 otherwise.
9136:
9137: =cut
9138:
9139: ###############################################
9140: sub show_course {
9141: my $course = !$env{'user.adv'};
9142: if (!$env{'user.adv'}) {
9143: foreach my $env (keys(%env)) {
9144: next if ($env !~ m/^user\.priv\./);
9145: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9146: $course = 0;
9147: last;
9148: }
9149: }
9150: }
9151: return $course;
9152: }
9153:
9154: ###############################################
9155:
9156: =pod
9157:
1.542 raeburn 9158: =item * &check_user_status()
1.274 raeburn 9159:
9160: Determines current status of supplied role for a
9161: specific user. Roles can be active, previous or future.
9162:
9163: Inputs:
9164: user's domain, user's username, course's domain,
1.375 raeburn 9165: course's number, optional section ID.
1.274 raeburn 9166:
9167: Outputs:
9168: role status: active, previous or future.
9169:
9170: =cut
9171:
9172: sub check_user_status {
1.412 raeburn 9173: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9174: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9175: my @uroles = keys(%userinfo);
1.274 raeburn 9176: my $srchstr;
9177: my $active_chk = 'none';
1.412 raeburn 9178: my $now = time;
1.274 raeburn 9179: if (@uroles > 0) {
1.908 raeburn 9180: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9181: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9182: } else {
1.412 raeburn 9183: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9184: }
9185: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9186: my $role_end = 0;
9187: my $role_start = 0;
9188: $active_chk = 'active';
1.412 raeburn 9189: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9190: $role_end = $1;
9191: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9192: $role_start = $1;
1.274 raeburn 9193: }
9194: }
9195: if ($role_start > 0) {
1.412 raeburn 9196: if ($now < $role_start) {
1.274 raeburn 9197: $active_chk = 'future';
9198: }
9199: }
9200: if ($role_end > 0) {
1.412 raeburn 9201: if ($now > $role_end) {
1.274 raeburn 9202: $active_chk = 'previous';
9203: }
9204: }
9205: }
9206: }
9207: return $active_chk;
9208: }
9209:
9210: ###############################################
9211:
9212: =pod
9213:
1.405 albertel 9214: =item * &get_sections()
1.233 raeburn 9215:
9216: Determines all the sections for a course including
9217: sections with students and sections containing other roles.
1.419 raeburn 9218: Incoming parameters:
9219:
9220: 1. domain
9221: 2. course number
9222: 3. reference to array containing roles for which sections should
9223: be gathered (optional).
9224: 4. reference to array containing status types for which sections
9225: should be gathered (optional).
9226:
9227: If the third argument is undefined, sections are gathered for any role.
9228: If the fourth argument is undefined, sections are gathered for any status.
9229: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9230:
1.374 raeburn 9231: Returns section hash (keys are section IDs, values are
9232: number of users in each section), subject to the
1.419 raeburn 9233: optional roles filter, optional status filter
1.233 raeburn 9234:
9235: =cut
9236:
9237: ###############################################
9238: sub get_sections {
1.419 raeburn 9239: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9240: if (!defined($cdom) || !defined($cnum)) {
9241: my $cid = $env{'request.course.id'};
9242:
9243: return if (!defined($cid));
9244:
9245: $cdom = $env{'course.'.$cid.'.domain'};
9246: $cnum = $env{'course.'.$cid.'.num'};
9247: }
9248:
9249: my %sectioncount;
1.419 raeburn 9250: my $now = time;
1.240 albertel 9251:
1.1075.2.33 raeburn 9252: my $check_students = 1;
9253: my $only_students = 0;
9254: if (ref($possible_roles) eq 'ARRAY') {
9255: if (grep(/^st$/,@{$possible_roles})) {
9256: if (@{$possible_roles} == 1) {
9257: $only_students = 1;
9258: }
9259: } else {
9260: $check_students = 0;
9261: }
9262: }
9263:
9264: if ($check_students) {
1.276 albertel 9265: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9266: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9267: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9268: my $start_index = &Apache::loncoursedata::CL_START();
9269: my $end_index = &Apache::loncoursedata::CL_END();
9270: my $status;
1.366 albertel 9271: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9272: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9273: $data->[$status_index],
9274: $data->[$start_index],
9275: $data->[$end_index]);
9276: if ($stu_status eq 'Active') {
9277: $status = 'active';
9278: } elsif ($end < $now) {
9279: $status = 'previous';
9280: } elsif ($start > $now) {
9281: $status = 'future';
9282: }
9283: if ($section ne '-1' && $section !~ /^\s*$/) {
9284: if ((!defined($possible_status)) || (($status ne '') &&
9285: (grep/^\Q$status\E$/,@{$possible_status}))) {
9286: $sectioncount{$section}++;
9287: }
1.240 albertel 9288: }
9289: }
9290: }
1.1075.2.33 raeburn 9291: if ($only_students) {
9292: return %sectioncount;
9293: }
1.240 albertel 9294: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9295: foreach my $user (sort(keys(%courseroles))) {
9296: if ($user !~ /^(\w{2})/) { next; }
9297: my ($role) = ($user =~ /^(\w{2})/);
9298: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9299: my ($section,$status);
1.240 albertel 9300: if ($role eq 'cr' &&
9301: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9302: $section=$1;
9303: }
9304: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9305: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9306: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9307: if ($end == -1 && $start == -1) {
9308: next; #deleted role
9309: }
9310: if (!defined($possible_status)) {
9311: $sectioncount{$section}++;
9312: } else {
9313: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9314: $status = 'active';
9315: } elsif ($end < $now) {
9316: $status = 'future';
9317: } elsif ($start > $now) {
9318: $status = 'previous';
9319: }
9320: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9321: $sectioncount{$section}++;
9322: }
9323: }
1.233 raeburn 9324: }
1.366 albertel 9325: return %sectioncount;
1.233 raeburn 9326: }
9327:
1.274 raeburn 9328: ###############################################
1.294 raeburn 9329:
9330: =pod
1.405 albertel 9331:
9332: =item * &get_course_users()
9333:
1.275 raeburn 9334: Retrieves usernames:domains for users in the specified course
9335: with specific role(s), and access status.
9336:
9337: Incoming parameters:
1.277 albertel 9338: 1. course domain
9339: 2. course number
9340: 3. access status: users must have - either active,
1.275 raeburn 9341: previous, future, or all.
1.277 albertel 9342: 4. reference to array of permissible roles
1.288 raeburn 9343: 5. reference to array of section restrictions (optional)
9344: 6. reference to results object (hash of hashes).
9345: 7. reference to optional userdata hash
1.609 raeburn 9346: 8. reference to optional statushash
1.630 raeburn 9347: 9. flag if privileged users (except those set to unhide in
9348: course settings) should be excluded
1.609 raeburn 9349: Keys of top level results hash are roles.
1.275 raeburn 9350: Keys of inner hashes are username:domain, with
9351: values set to access type.
1.288 raeburn 9352: Optional userdata hash returns an array with arguments in the
9353: same order as loncoursedata::get_classlist() for student data.
9354:
1.609 raeburn 9355: Optional statushash returns
9356:
1.288 raeburn 9357: Entries for end, start, section and status are blank because
9358: of the possibility of multiple values for non-student roles.
9359:
1.275 raeburn 9360: =cut
1.405 albertel 9361:
1.275 raeburn 9362: ###############################################
1.405 albertel 9363:
1.275 raeburn 9364: sub get_course_users {
1.630 raeburn 9365: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9366: my %idx = ();
1.419 raeburn 9367: my %seclists;
1.288 raeburn 9368:
9369: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9370: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9371: $idx{end} = &Apache::loncoursedata::CL_END();
9372: $idx{start} = &Apache::loncoursedata::CL_START();
9373: $idx{id} = &Apache::loncoursedata::CL_ID();
9374: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9375: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9376: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9377:
1.290 albertel 9378: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9379: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9380: my $now = time;
1.277 albertel 9381: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9382: my $match = 0;
1.412 raeburn 9383: my $secmatch = 0;
1.419 raeburn 9384: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9385: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9386: if ($section eq '') {
9387: $section = 'none';
9388: }
1.291 albertel 9389: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9390: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9391: $secmatch = 1;
9392: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9393: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9394: $secmatch = 1;
9395: }
9396: } else {
1.419 raeburn 9397: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9398: $secmatch = 1;
9399: }
1.290 albertel 9400: }
1.412 raeburn 9401: if (!$secmatch) {
9402: next;
9403: }
1.419 raeburn 9404: }
1.275 raeburn 9405: if (defined($$types{'active'})) {
1.288 raeburn 9406: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9407: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9408: $match = 1;
1.275 raeburn 9409: }
9410: }
9411: if (defined($$types{'previous'})) {
1.609 raeburn 9412: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9413: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9414: $match = 1;
1.275 raeburn 9415: }
9416: }
9417: if (defined($$types{'future'})) {
1.609 raeburn 9418: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9419: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9420: $match = 1;
1.275 raeburn 9421: }
9422: }
1.609 raeburn 9423: if ($match) {
9424: push(@{$seclists{$student}},$section);
9425: if (ref($userdata) eq 'HASH') {
9426: $$userdata{$student} = $$classlist{$student};
9427: }
9428: if (ref($statushash) eq 'HASH') {
9429: $statushash->{$student}{'st'}{$section} = $status;
9430: }
1.288 raeburn 9431: }
1.275 raeburn 9432: }
9433: }
1.412 raeburn 9434: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9435: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9436: my $now = time;
1.609 raeburn 9437: my %displaystatus = ( previous => 'Expired',
9438: active => 'Active',
9439: future => 'Future',
9440: );
1.1075.2.36 raeburn 9441: my (%nothide,@possdoms);
1.630 raeburn 9442: if ($hidepriv) {
9443: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9444: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9445: if ($user !~ /:/) {
9446: $nothide{join(':',split(/[\@]/,$user))}=1;
9447: } else {
9448: $nothide{$user} = 1;
9449: }
9450: }
1.1075.2.36 raeburn 9451: my @possdoms = ($cdom);
9452: if ($coursehash{'checkforpriv'}) {
9453: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9454: }
1.630 raeburn 9455: }
1.439 raeburn 9456: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9457: my $match = 0;
1.412 raeburn 9458: my $secmatch = 0;
1.439 raeburn 9459: my $status;
1.412 raeburn 9460: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9461: $user =~ s/:$//;
1.439 raeburn 9462: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9463: if ($end == -1 || $start == -1) {
9464: next;
9465: }
9466: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9467: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9468: my ($uname,$udom) = split(/:/,$user);
9469: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9470: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9471: $secmatch = 1;
9472: } elsif ($usec eq '') {
1.420 albertel 9473: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9474: $secmatch = 1;
9475: }
9476: } else {
9477: if (grep(/^\Q$usec\E$/,@{$sections})) {
9478: $secmatch = 1;
9479: }
9480: }
9481: if (!$secmatch) {
9482: next;
9483: }
1.288 raeburn 9484: }
1.419 raeburn 9485: if ($usec eq '') {
9486: $usec = 'none';
9487: }
1.275 raeburn 9488: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9489: if ($hidepriv) {
1.1075.2.36 raeburn 9490: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9491: (!$nothide{$uname.':'.$udom})) {
9492: next;
9493: }
9494: }
1.503 raeburn 9495: if ($end > 0 && $end < $now) {
1.439 raeburn 9496: $status = 'previous';
9497: } elsif ($start > $now) {
9498: $status = 'future';
9499: } else {
9500: $status = 'active';
9501: }
1.277 albertel 9502: foreach my $type (keys(%{$types})) {
1.275 raeburn 9503: if ($status eq $type) {
1.420 albertel 9504: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9505: push(@{$$users{$role}{$user}},$type);
9506: }
1.288 raeburn 9507: $match = 1;
9508: }
9509: }
1.419 raeburn 9510: if (($match) && (ref($userdata) eq 'HASH')) {
9511: if (!exists($$userdata{$uname.':'.$udom})) {
9512: &get_user_info($udom,$uname,\%idx,$userdata);
9513: }
1.420 albertel 9514: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9515: push(@{$seclists{$uname.':'.$udom}},$usec);
9516: }
1.609 raeburn 9517: if (ref($statushash) eq 'HASH') {
9518: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9519: }
1.275 raeburn 9520: }
9521: }
9522: }
9523: }
1.290 albertel 9524: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9525: if ((defined($cdom)) && (defined($cnum))) {
9526: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9527: if ( defined($csettings{'internal.courseowner'}) ) {
9528: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9529: next if ($owner eq '');
9530: my ($ownername,$ownerdom);
9531: if ($owner =~ /^([^:]+):([^:]+)$/) {
9532: $ownername = $1;
9533: $ownerdom = $2;
9534: } else {
9535: $ownername = $owner;
9536: $ownerdom = $cdom;
9537: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9538: }
9539: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9540: if (defined($userdata) &&
1.609 raeburn 9541: !exists($$userdata{$owner})) {
9542: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9543: if (!grep(/^none$/,@{$seclists{$owner}})) {
9544: push(@{$seclists{$owner}},'none');
9545: }
9546: if (ref($statushash) eq 'HASH') {
9547: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9548: }
1.290 albertel 9549: }
1.279 raeburn 9550: }
9551: }
9552: }
1.419 raeburn 9553: foreach my $user (keys(%seclists)) {
9554: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9555: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9556: }
1.275 raeburn 9557: }
9558: return;
9559: }
9560:
1.288 raeburn 9561: sub get_user_info {
9562: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9563: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9564: &plainname($uname,$udom,'lastname');
1.291 albertel 9565: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9566: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9567: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9568: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9569: return;
9570: }
1.275 raeburn 9571:
1.472 raeburn 9572: ###############################################
9573:
9574: =pod
9575:
9576: =item * &get_user_quota()
9577:
1.1075.2.41 raeburn 9578: Retrieves quota assigned for storage of user files.
9579: Default is to report quota for portfolio files.
1.472 raeburn 9580:
9581: Incoming parameters:
9582: 1. user's username
9583: 2. user's domain
1.1075.2.41 raeburn 9584: 3. quota name - portfolio, author, or course
9585: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9586: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9587: course
1.472 raeburn 9588:
9589: Returns:
1.1075.2.58 raeburn 9590: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9591: 2. (Optional) Type of setting: custom or default
9592: (individually assigned or default for user's
9593: institutional status).
9594: 3. (Optional) - User's institutional status (e.g., faculty, staff
9595: or student - types as defined in localenroll::inst_usertypes
9596: for user's domain, which determines default quota for user.
9597: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9598:
9599: If a value has been stored in the user's environment,
1.536 raeburn 9600: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9601: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9602:
9603: =cut
9604:
9605: ###############################################
9606:
9607:
9608: sub get_user_quota {
1.1075.2.42 raeburn 9609: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9610: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9611: if (!defined($udom)) {
9612: $udom = $env{'user.domain'};
9613: }
9614: if (!defined($uname)) {
9615: $uname = $env{'user.name'};
9616: }
9617: if (($udom eq '' || $uname eq '') ||
9618: ($udom eq 'public') && ($uname eq 'public')) {
9619: $quota = 0;
1.536 raeburn 9620: $quotatype = 'default';
9621: $defquota = 0;
1.472 raeburn 9622: } else {
1.536 raeburn 9623: my $inststatus;
1.1075.2.41 raeburn 9624: if ($quotaname eq 'course') {
9625: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9626: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9627: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9628: } else {
9629: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9630: $quota = $cenv{'internal.uploadquota'};
9631: }
1.536 raeburn 9632: } else {
1.1075.2.41 raeburn 9633: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9634: if ($quotaname eq 'author') {
9635: $quota = $env{'environment.authorquota'};
9636: } else {
9637: $quota = $env{'environment.portfolioquota'};
9638: }
9639: $inststatus = $env{'environment.inststatus'};
9640: } else {
9641: my %userenv =
9642: &Apache::lonnet::get('environment',['portfolioquota',
9643: 'authorquota','inststatus'],$udom,$uname);
9644: my ($tmp) = keys(%userenv);
9645: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9646: if ($quotaname eq 'author') {
9647: $quota = $userenv{'authorquota'};
9648: } else {
9649: $quota = $userenv{'portfolioquota'};
9650: }
9651: $inststatus = $userenv{'inststatus'};
9652: } else {
9653: undef(%userenv);
9654: }
9655: }
9656: }
9657: if ($quota eq '' || wantarray) {
9658: if ($quotaname eq 'course') {
9659: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9660: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9661: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9662: $defquota = $domdefs{$crstype.'quota'};
9663: }
9664: if ($defquota eq '') {
9665: $defquota = 500;
9666: }
1.1075.2.41 raeburn 9667: } else {
9668: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9669: }
9670: if ($quota eq '') {
9671: $quota = $defquota;
9672: $quotatype = 'default';
9673: } else {
9674: $quotatype = 'custom';
9675: }
1.472 raeburn 9676: }
9677: }
1.536 raeburn 9678: if (wantarray) {
9679: return ($quota,$quotatype,$settingstatus,$defquota);
9680: } else {
9681: return $quota;
9682: }
1.472 raeburn 9683: }
9684:
9685: ###############################################
9686:
9687: =pod
9688:
9689: =item * &default_quota()
9690:
1.536 raeburn 9691: Retrieves default quota assigned for storage of user portfolio files,
9692: given an (optional) user's institutional status.
1.472 raeburn 9693:
9694: Incoming parameters:
1.1075.2.42 raeburn 9695:
1.472 raeburn 9696: 1. domain
1.536 raeburn 9697: 2. (Optional) institutional status(es). This is a : separated list of
9698: status types (e.g., faculty, staff, student etc.)
9699: which apply to the user for whom the default is being retrieved.
9700: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9701: default quota will be returned.
9702: 3. quota name - portfolio, author, or course
9703: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9704:
9705: Returns:
1.1075.2.42 raeburn 9706:
1.1075.2.58 raeburn 9707: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9708: 2. (Optional) institutional type which determined the value of the
9709: default quota.
1.472 raeburn 9710:
9711: If a value has been stored in the domain's configuration db,
9712: it will return that, otherwise it returns 20 (for backwards
9713: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9714: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9715:
1.536 raeburn 9716: If the user's status includes multiple types (e.g., staff and student),
9717: the largest default quota which applies to the user determines the
9718: default quota returned.
9719:
1.472 raeburn 9720: =cut
9721:
9722: ###############################################
9723:
9724:
9725: sub default_quota {
1.1075.2.41 raeburn 9726: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9727: my ($defquota,$settingstatus);
9728: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9729: ['quotas'],$udom);
1.1075.2.41 raeburn 9730: my $key = 'defaultquota';
9731: if ($quotaname eq 'author') {
9732: $key = 'authorquota';
9733: }
1.622 raeburn 9734: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9735: if ($inststatus ne '') {
1.765 raeburn 9736: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9737: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9738: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9739: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9740: if ($defquota eq '') {
1.1075.2.41 raeburn 9741: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9742: $settingstatus = $item;
1.1075.2.41 raeburn 9743: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9744: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9745: $settingstatus = $item;
9746: }
9747: }
1.1075.2.41 raeburn 9748: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9749: if ($quotahash{'quotas'}{$item} ne '') {
9750: if ($defquota eq '') {
9751: $defquota = $quotahash{'quotas'}{$item};
9752: $settingstatus = $item;
9753: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9754: $defquota = $quotahash{'quotas'}{$item};
9755: $settingstatus = $item;
9756: }
1.536 raeburn 9757: }
9758: }
9759: }
9760: }
9761: if ($defquota eq '') {
1.1075.2.41 raeburn 9762: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9763: $defquota = $quotahash{'quotas'}{$key}{'default'};
9764: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9765: $defquota = $quotahash{'quotas'}{'default'};
9766: }
1.536 raeburn 9767: $settingstatus = 'default';
1.1075.2.42 raeburn 9768: if ($defquota eq '') {
9769: if ($quotaname eq 'author') {
9770: $defquota = 500;
9771: }
9772: }
1.536 raeburn 9773: }
9774: } else {
9775: $settingstatus = 'default';
1.1075.2.41 raeburn 9776: if ($quotaname eq 'author') {
9777: $defquota = 500;
9778: } else {
9779: $defquota = 20;
9780: }
1.536 raeburn 9781: }
9782: if (wantarray) {
9783: return ($defquota,$settingstatus);
1.472 raeburn 9784: } else {
1.536 raeburn 9785: return $defquota;
1.472 raeburn 9786: }
9787: }
9788:
1.1075.2.41 raeburn 9789: ###############################################
9790:
9791: =pod
9792:
1.1075.2.42 raeburn 9793: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9794:
9795: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9796: of existing file within authoring space will cause quota for the authoring
9797: space to be exceeded.
9798:
9799: Same, if upload of a file directly to a course/community via Course Editor
9800: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9801:
1.1075.2.61 raeburn 9802: Inputs: 7
1.1075.2.42 raeburn 9803: 1. username or coursenum
1.1075.2.41 raeburn 9804: 2. domain
1.1075.2.42 raeburn 9805: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9806: 4. filename of file for which action is being requested
9807: 5. filesize (kB) of file
9808: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9809: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9810:
9811: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9812: otherwise return null.
9813:
1.1075.2.42 raeburn 9814: =back
9815:
1.1075.2.41 raeburn 9816: =cut
9817:
1.1075.2.42 raeburn 9818: sub excess_filesize_warning {
1.1075.2.59 raeburn 9819: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9820: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9821: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9822: if ($context eq 'author') {
9823: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9824: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9825: } else {
9826: foreach my $subdir ('docs','supplemental') {
9827: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9828: }
9829: }
1.1075.2.41 raeburn 9830: $disk_quota = int($disk_quota * 1000);
9831: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9832: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9833: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9834: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9835: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9836: $disk_quota,$current_disk_usage).
9837: '</p>';
9838: }
9839: return;
9840: }
9841:
9842: ###############################################
9843:
9844:
1.384 raeburn 9845: sub get_secgrprole_info {
9846: my ($cdom,$cnum,$needroles,$type) = @_;
9847: my %sections_count = &get_sections($cdom,$cnum);
9848: my @sections = (sort {$a <=> $b} keys(%sections_count));
9849: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9850: my @groups = sort(keys(%curr_groups));
9851: my $allroles = [];
9852: my $rolehash;
9853: my $accesshash = {
9854: active => 'Currently has access',
9855: future => 'Will have future access',
9856: previous => 'Previously had access',
9857: };
9858: if ($needroles) {
9859: $rolehash = {'all' => 'all'};
1.385 albertel 9860: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9861: if (&Apache::lonnet::error(%user_roles)) {
9862: undef(%user_roles);
9863: }
9864: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9865: my ($role)=split(/\:/,$item,2);
9866: if ($role eq 'cr') { next; }
9867: if ($role =~ /^cr/) {
9868: $$rolehash{$role} = (split('/',$role))[3];
9869: } else {
9870: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9871: }
9872: }
9873: foreach my $key (sort(keys(%{$rolehash}))) {
9874: push(@{$allroles},$key);
9875: }
9876: push (@{$allroles},'st');
9877: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9878: }
9879: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9880: }
9881:
1.555 raeburn 9882: sub user_picker {
1.1075.2.127 raeburn 9883: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9884: my $currdom = $dom;
1.1075.2.114 raeburn 9885: my @alldoms = &Apache::lonnet::all_domains();
9886: if (@alldoms == 1) {
9887: my %domsrch = &Apache::lonnet::get_dom('configuration',
9888: ['directorysrch'],$alldoms[0]);
9889: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9890: my $showdom = $domdesc;
9891: if ($showdom eq '') {
9892: $showdom = $dom;
9893: }
9894: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9895: if ((!$domsrch{'directorysrch'}{'available'}) &&
9896: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9897: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9898: }
9899: }
9900: }
1.555 raeburn 9901: my %curr_selected = (
9902: srchin => 'dom',
1.580 raeburn 9903: srchby => 'lastname',
1.555 raeburn 9904: );
9905: my $srchterm;
1.625 raeburn 9906: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9907: if ($srch->{'srchby'} ne '') {
9908: $curr_selected{'srchby'} = $srch->{'srchby'};
9909: }
9910: if ($srch->{'srchin'} ne '') {
9911: $curr_selected{'srchin'} = $srch->{'srchin'};
9912: }
9913: if ($srch->{'srchtype'} ne '') {
9914: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9915: }
9916: if ($srch->{'srchdomain'} ne '') {
9917: $currdom = $srch->{'srchdomain'};
9918: }
9919: $srchterm = $srch->{'srchterm'};
9920: }
1.1075.2.98 raeburn 9921: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9922: 'usr' => 'Search criteria',
1.563 raeburn 9923: 'doma' => 'Domain/institution to search',
1.558 albertel 9924: 'uname' => 'username',
9925: 'lastname' => 'last name',
1.555 raeburn 9926: 'lastfirst' => 'last name, first name',
1.558 albertel 9927: 'crs' => 'in this course',
1.576 raeburn 9928: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9929: 'alc' => 'all LON-CAPA',
1.573 raeburn 9930: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9931: 'exact' => 'is',
9932: 'contains' => 'contains',
1.569 raeburn 9933: 'begins' => 'begins with',
1.1075.2.98 raeburn 9934: );
9935: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9936: 'youm' => "You must include some text to search for.",
9937: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9938: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9939: 'yomc' => "You must choose a domain when using an institutional directory search.",
9940: 'ymcd' => "You must choose a domain when using a domain search.",
9941: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9942: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9943: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9944: );
1.1075.2.98 raeburn 9945: &html_escape(\%html_lt);
9946: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9947: my $domform;
1.1075.2.126 raeburn 9948: my $allow_blank = 1;
1.1075.2.115 raeburn 9949: if ($fixeddom) {
1.1075.2.126 raeburn 9950: $allow_blank = 0;
9951: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9952: } else {
1.1075.2.126 raeburn 9953: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9954: }
1.563 raeburn 9955: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9956:
9957: my @srchins = ('crs','dom','alc','instd');
9958:
9959: foreach my $option (@srchins) {
9960: # FIXME 'alc' option unavailable until
9961: # loncreateuser::print_user_query_page()
9962: # has been completed.
9963: next if ($option eq 'alc');
1.880 raeburn 9964: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9965: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9966: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9967: if ($curr_selected{'srchin'} eq $option) {
9968: $srchinsel .= '
1.1075.2.98 raeburn 9969: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9970: } else {
9971: $srchinsel .= '
1.1075.2.98 raeburn 9972: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9973: }
1.555 raeburn 9974: }
1.563 raeburn 9975: $srchinsel .= "\n </select>\n";
1.555 raeburn 9976:
9977: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9978: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9979: if ($curr_selected{'srchby'} eq $option) {
9980: $srchbysel .= '
1.1075.2.98 raeburn 9981: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9982: } else {
9983: $srchbysel .= '
1.1075.2.98 raeburn 9984: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9985: }
9986: }
9987: $srchbysel .= "\n </select>\n";
9988:
9989: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9990: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9991: if ($curr_selected{'srchtype'} eq $option) {
9992: $srchtypesel .= '
1.1075.2.98 raeburn 9993: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9994: } else {
9995: $srchtypesel .= '
1.1075.2.98 raeburn 9996: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9997: }
9998: }
9999: $srchtypesel .= "\n </select>\n";
10000:
1.558 albertel 10001: my ($newuserscript,$new_user_create);
1.994 raeburn 10002: my $context_dom = $env{'request.role.domain'};
10003: if ($context eq 'requestcrs') {
10004: if ($env{'form.coursedom'} ne '') {
10005: $context_dom = $env{'form.coursedom'};
10006: }
10007: }
1.556 raeburn 10008: if ($forcenewuser) {
1.576 raeburn 10009: if (ref($srch) eq 'HASH') {
1.994 raeburn 10010: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10011: if ($cancreate) {
10012: $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>';
10013: } else {
1.799 bisitz 10014: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10015: my %usertypetext = (
10016: official => 'institutional',
10017: unofficial => 'non-institutional',
10018: );
1.799 bisitz 10019: $new_user_create = '<p class="LC_warning">'
10020: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10021: .' '
10022: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10023: ,'<a href="'.$helplink.'">','</a>')
10024: .'</p><br />';
1.627 raeburn 10025: }
1.576 raeburn 10026: }
10027: }
10028:
1.556 raeburn 10029: $newuserscript = <<"ENDSCRIPT";
10030:
1.570 raeburn 10031: function setSearch(createnew,callingForm) {
1.556 raeburn 10032: if (createnew == 1) {
1.570 raeburn 10033: for (var i=0; i<callingForm.srchby.length; i++) {
10034: if (callingForm.srchby.options[i].value == 'uname') {
10035: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10036: }
10037: }
1.570 raeburn 10038: for (var i=0; i<callingForm.srchin.length; i++) {
10039: if ( callingForm.srchin.options[i].value == 'dom') {
10040: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10041: }
10042: }
1.570 raeburn 10043: for (var i=0; i<callingForm.srchtype.length; i++) {
10044: if (callingForm.srchtype.options[i].value == 'exact') {
10045: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10046: }
10047: }
1.570 raeburn 10048: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10049: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10050: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10051: }
10052: }
10053: }
10054: }
10055: ENDSCRIPT
1.558 albertel 10056:
1.556 raeburn 10057: }
10058:
1.555 raeburn 10059: my $output = <<"END_BLOCK";
1.556 raeburn 10060: <script type="text/javascript">
1.824 bisitz 10061: // <![CDATA[
1.570 raeburn 10062: function validateEntry(callingForm) {
1.558 albertel 10063:
1.556 raeburn 10064: var checkok = 1;
1.558 albertel 10065: var srchin;
1.570 raeburn 10066: for (var i=0; i<callingForm.srchin.length; i++) {
10067: if ( callingForm.srchin[i].checked ) {
10068: srchin = callingForm.srchin[i].value;
1.558 albertel 10069: }
10070: }
10071:
1.570 raeburn 10072: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10073: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10074: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10075: var srchterm = callingForm.srchterm.value;
10076: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10077: var msg = "";
10078:
10079: if (srchterm == "") {
10080: checkok = 0;
1.1075.2.98 raeburn 10081: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10082: }
10083:
1.569 raeburn 10084: if (srchtype== 'begins') {
10085: if (srchterm.length < 2) {
10086: checkok = 0;
1.1075.2.98 raeburn 10087: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10088: }
10089: }
10090:
1.556 raeburn 10091: if (srchtype== 'contains') {
10092: if (srchterm.length < 3) {
10093: checkok = 0;
1.1075.2.98 raeburn 10094: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10095: }
10096: }
10097: if (srchin == 'instd') {
10098: if (srchdomain == '') {
10099: checkok = 0;
1.1075.2.98 raeburn 10100: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10101: }
10102: }
10103: if (srchin == 'dom') {
10104: if (srchdomain == '') {
10105: checkok = 0;
1.1075.2.98 raeburn 10106: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10107: }
10108: }
10109: if (srchby == 'lastfirst') {
10110: if (srchterm.indexOf(",") == -1) {
10111: checkok = 0;
1.1075.2.98 raeburn 10112: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10113: }
10114: if (srchterm.indexOf(",") == srchterm.length -1) {
10115: checkok = 0;
1.1075.2.98 raeburn 10116: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10117: }
10118: }
10119: if (checkok == 0) {
1.1075.2.98 raeburn 10120: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10121: return;
10122: }
10123: if (checkok == 1) {
1.570 raeburn 10124: callingForm.submit();
1.556 raeburn 10125: }
10126: }
10127:
10128: $newuserscript
10129:
1.824 bisitz 10130: // ]]>
1.556 raeburn 10131: </script>
1.558 albertel 10132:
10133: $new_user_create
10134:
1.555 raeburn 10135: END_BLOCK
1.558 albertel 10136:
1.876 raeburn 10137: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10138: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10139: $domform.
10140: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10141: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10142: $srchbysel.
10143: $srchtypesel.
10144: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10145: $srchinsel.
10146: &Apache::lonhtmlcommon::row_closure(1).
10147: &Apache::lonhtmlcommon::end_pick_box().
10148: '<br />';
1.1075.2.114 raeburn 10149: return ($output,1);
1.555 raeburn 10150: }
10151:
1.612 raeburn 10152: sub user_rule_check {
1.615 raeburn 10153: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10154: my ($response,%inst_response);
1.612 raeburn 10155: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10156: if (keys(%{$usershash}) > 1) {
10157: my (%by_username,%by_id,%userdoms);
10158: my $checkid;
1.612 raeburn 10159: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10160: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10161: $checkid = 1;
10162: }
10163: }
10164: foreach my $user (keys(%{$usershash})) {
10165: my ($uname,$udom) = split(/:/,$user);
10166: if ($checkid) {
10167: if (ref($usershash->{$user}) eq 'HASH') {
10168: if ($usershash->{$user}->{'id'} ne '') {
10169: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10170: $userdoms{$udom} = 1;
10171: if (ref($inst_results) eq 'HASH') {
10172: $inst_results->{$uname.':'.$udom} = {};
10173: }
10174: }
10175: }
10176: } else {
10177: $by_username{$udom}{$uname} = 1;
10178: $userdoms{$udom} = 1;
10179: if (ref($inst_results) eq 'HASH') {
10180: $inst_results->{$uname.':'.$udom} = {};
10181: }
10182: }
10183: }
10184: foreach my $udom (keys(%userdoms)) {
10185: if (!$got_rules->{$udom}) {
10186: my %domconfig = &Apache::lonnet::get_dom('configuration',
10187: ['usercreation'],$udom);
10188: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10189: foreach my $item ('username','id') {
10190: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10191: $$curr_rules{$udom}{$item} =
10192: $domconfig{'usercreation'}{$item.'_rule'};
10193: }
10194: }
10195: }
10196: $got_rules->{$udom} = 1;
10197: }
10198: }
10199: if ($checkid) {
10200: foreach my $udom (keys(%by_id)) {
10201: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10202: if ($outcome eq 'ok') {
10203: foreach my $id (keys(%{$by_id{$udom}})) {
10204: my $uname = $by_id{$udom}{$id};
10205: $inst_response{$uname.':'.$udom} = $outcome;
10206: }
10207: if (ref($results) eq 'HASH') {
10208: foreach my $uname (keys(%{$results})) {
10209: if (exists($inst_response{$uname.':'.$udom})) {
10210: $inst_response{$uname.':'.$udom} = $outcome;
10211: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10212: }
10213: }
10214: }
10215: }
1.612 raeburn 10216: }
1.615 raeburn 10217: } else {
1.1075.2.99 raeburn 10218: foreach my $udom (keys(%by_username)) {
10219: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10220: if ($outcome eq 'ok') {
10221: foreach my $uname (keys(%{$by_username{$udom}})) {
10222: $inst_response{$uname.':'.$udom} = $outcome;
10223: }
10224: if (ref($results) eq 'HASH') {
10225: foreach my $uname (keys(%{$results})) {
10226: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10227: }
10228: }
10229: }
10230: }
1.612 raeburn 10231: }
1.1075.2.99 raeburn 10232: } elsif (keys(%{$usershash}) == 1) {
10233: my $user = (keys(%{$usershash}))[0];
10234: my ($uname,$udom) = split(/:/,$user);
10235: if (($udom ne '') && ($uname ne '')) {
10236: if (ref($usershash->{$user}) eq 'HASH') {
10237: if (ref($checks) eq 'HASH') {
10238: if (defined($checks->{'username'})) {
10239: ($inst_response{$user},%{$inst_results->{$user}}) =
10240: &Apache::lonnet::get_instuser($udom,$uname);
10241: } elsif (defined($checks->{'id'})) {
10242: if ($usershash->{$user}->{'id'} ne '') {
10243: ($inst_response{$user},%{$inst_results->{$user}}) =
10244: &Apache::lonnet::get_instuser($udom,undef,
10245: $usershash->{$user}->{'id'});
10246: } else {
10247: ($inst_response{$user},%{$inst_results->{$user}}) =
10248: &Apache::lonnet::get_instuser($udom,$uname);
10249: }
10250: }
10251: } else {
10252: ($inst_response{$user},%{$inst_results->{$user}}) =
10253: &Apache::lonnet::get_instuser($udom,$uname);
10254: return;
10255: }
10256: if (!$got_rules->{$udom}) {
10257: my %domconfig = &Apache::lonnet::get_dom('configuration',
10258: ['usercreation'],$udom);
10259: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10260: foreach my $item ('username','id') {
10261: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10262: $$curr_rules{$udom}{$item} =
10263: $domconfig{'usercreation'}{$item.'_rule'};
10264: }
10265: }
1.585 raeburn 10266: }
1.1075.2.99 raeburn 10267: $got_rules->{$udom} = 1;
1.585 raeburn 10268: }
10269: }
1.1075.2.99 raeburn 10270: } else {
10271: return;
10272: }
10273: } else {
10274: return;
10275: }
10276: foreach my $user (keys(%{$usershash})) {
10277: my ($uname,$udom) = split(/:/,$user);
10278: next if (($udom eq '') || ($uname eq ''));
10279: my $id;
10280: if (ref($inst_results) eq 'HASH') {
10281: if (ref($inst_results->{$user}) eq 'HASH') {
10282: $id = $inst_results->{$user}->{'id'};
10283: }
10284: }
10285: if ($id eq '') {
10286: if (ref($usershash->{$user})) {
10287: $id = $usershash->{$user}->{'id'};
10288: }
1.585 raeburn 10289: }
1.612 raeburn 10290: foreach my $item (keys(%{$checks})) {
10291: if (ref($$curr_rules{$udom}) eq 'HASH') {
10292: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10293: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10294: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10295: $$curr_rules{$udom}{$item});
1.612 raeburn 10296: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10297: if ($rule_check{$rule}) {
10298: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10299: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10300: if (ref($inst_results) eq 'HASH') {
10301: if (ref($inst_results->{$user}) eq 'HASH') {
10302: if (keys(%{$inst_results->{$user}}) == 0) {
10303: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10304: } elsif ($item eq 'id') {
10305: if ($inst_results->{$user}->{'id'} eq '') {
10306: $$alerts{$item}{$udom}{$uname} = 1;
10307: }
1.615 raeburn 10308: }
1.612 raeburn 10309: }
10310: }
1.615 raeburn 10311: }
10312: last;
1.585 raeburn 10313: }
10314: }
10315: }
10316: }
10317: }
10318: }
10319: }
10320: }
1.612 raeburn 10321: return;
10322: }
10323:
10324: sub user_rule_formats {
10325: my ($domain,$domdesc,$curr_rules,$check) = @_;
10326: my %text = (
10327: 'username' => 'Usernames',
10328: 'id' => 'IDs',
10329: );
10330: my $output;
10331: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10332: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10333: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10334: $output = '<br />'.
10335: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10336: '<span class="LC_cusr_emph">','</span>',$domdesc).
10337: ' <ul>';
1.612 raeburn 10338: foreach my $rule (@{$ruleorder}) {
10339: if (ref($curr_rules) eq 'ARRAY') {
10340: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10341: if (ref($rules->{$rule}) eq 'HASH') {
10342: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10343: $rules->{$rule}{'desc'}.'</li>';
10344: }
10345: }
10346: }
10347: }
10348: $output .= '</ul>';
10349: }
10350: }
10351: return $output;
10352: }
10353:
10354: sub instrule_disallow_msg {
1.615 raeburn 10355: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10356: my $response;
10357: my %text = (
10358: item => 'username',
10359: items => 'usernames',
10360: match => 'matches',
10361: do => 'does',
10362: action => 'a username',
10363: one => 'one',
10364: );
10365: if ($count > 1) {
10366: $text{'item'} = 'usernames';
10367: $text{'match'} ='match';
10368: $text{'do'} = 'do';
10369: $text{'action'} = 'usernames',
10370: $text{'one'} = 'ones';
10371: }
10372: if ($checkitem eq 'id') {
10373: $text{'items'} = 'IDs';
10374: $text{'item'} = 'ID';
10375: $text{'action'} = 'an ID';
1.615 raeburn 10376: if ($count > 1) {
10377: $text{'item'} = 'IDs';
10378: $text{'action'} = 'IDs';
10379: }
1.612 raeburn 10380: }
1.674 bisitz 10381: $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 10382: if ($mode eq 'upload') {
10383: if ($checkitem eq 'username') {
10384: $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'}.");
10385: } elsif ($checkitem eq 'id') {
1.674 bisitz 10386: $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 10387: }
1.669 raeburn 10388: } elsif ($mode eq 'selfcreate') {
10389: if ($checkitem eq 'id') {
10390: $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.");
10391: }
1.615 raeburn 10392: } else {
10393: if ($checkitem eq 'username') {
10394: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10395: } elsif ($checkitem eq 'id') {
10396: $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.");
10397: }
1.612 raeburn 10398: }
10399: return $response;
1.585 raeburn 10400: }
10401:
1.624 raeburn 10402: sub personal_data_fieldtitles {
10403: my %fieldtitles = &Apache::lonlocal::texthash (
10404: id => 'Student/Employee ID',
10405: permanentemail => 'E-mail address',
10406: lastname => 'Last Name',
10407: firstname => 'First Name',
10408: middlename => 'Middle Name',
10409: generation => 'Generation',
10410: gen => 'Generation',
1.765 raeburn 10411: inststatus => 'Affiliation',
1.624 raeburn 10412: );
10413: return %fieldtitles;
10414: }
10415:
1.642 raeburn 10416: sub sorted_inst_types {
10417: my ($dom) = @_;
1.1075.2.70 raeburn 10418: my ($usertypes,$order);
10419: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10420: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10421: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10422: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10423: } else {
10424: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10425: }
1.642 raeburn 10426: my $othertitle = &mt('All users');
10427: if ($env{'request.course.id'}) {
1.668 raeburn 10428: $othertitle = &mt('Any users');
1.642 raeburn 10429: }
10430: my @types;
10431: if (ref($order) eq 'ARRAY') {
10432: @types = @{$order};
10433: }
10434: if (@types == 0) {
10435: if (ref($usertypes) eq 'HASH') {
10436: @types = sort(keys(%{$usertypes}));
10437: }
10438: }
10439: if (keys(%{$usertypes}) > 0) {
10440: $othertitle = &mt('Other users');
10441: }
10442: return ($othertitle,$usertypes,\@types);
10443: }
10444:
1.645 raeburn 10445: sub get_institutional_codes {
10446: my ($settings,$allcourses,$LC_code) = @_;
10447: # Get complete list of course sections to update
10448: my @currsections = ();
10449: my @currxlists = ();
10450: my $coursecode = $$settings{'internal.coursecode'};
10451:
10452: if ($$settings{'internal.sectionnums'} ne '') {
10453: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10454: }
10455:
10456: if ($$settings{'internal.crosslistings'} ne '') {
10457: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10458: }
10459:
10460: if (@currxlists > 0) {
10461: foreach (@currxlists) {
10462: if (m/^([^:]+):(\w*)$/) {
10463: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10464: push(@{$allcourses},$1);
1.645 raeburn 10465: $$LC_code{$1} = $2;
10466: }
10467: }
10468: }
10469: }
10470:
10471: if (@currsections > 0) {
10472: foreach (@currsections) {
10473: if (m/^(\w+):(\w*)$/) {
10474: my $sec = $coursecode.$1;
10475: my $lc_sec = $2;
10476: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10477: push(@{$allcourses},$sec);
1.645 raeburn 10478: $$LC_code{$sec} = $lc_sec;
10479: }
10480: }
10481: }
10482: }
10483: return;
10484: }
10485:
1.971 raeburn 10486: sub get_standard_codeitems {
10487: return ('Year','Semester','Department','Number','Section');
10488: }
10489:
1.112 bowersj2 10490: =pod
10491:
1.780 raeburn 10492: =head1 Slot Helpers
10493:
10494: =over 4
10495:
10496: =item * sorted_slots()
10497:
1.1040 raeburn 10498: Sorts an array of slot names in order of an optional sort key,
10499: default sort is by slot start time (earliest first).
1.780 raeburn 10500:
10501: Inputs:
10502:
10503: =over 4
10504:
10505: slotsarr - Reference to array of unsorted slot names.
10506:
10507: slots - Reference to hash of hash, where outer hash keys are slot names.
10508:
1.1040 raeburn 10509: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10510:
1.549 albertel 10511: =back
10512:
1.780 raeburn 10513: Returns:
10514:
10515: =over 4
10516:
1.1040 raeburn 10517: sorted - An array of slot names sorted by a specified sort key
10518: (default sort key is start time of the slot).
1.780 raeburn 10519:
10520: =back
10521:
10522: =cut
10523:
10524:
10525: sub sorted_slots {
1.1040 raeburn 10526: my ($slotsarr,$slots,$sortkey) = @_;
10527: if ($sortkey eq '') {
10528: $sortkey = 'starttime';
10529: }
1.780 raeburn 10530: my @sorted;
10531: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10532: @sorted =
10533: sort {
10534: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10535: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10536: }
10537: if (ref($slots->{$a})) { return -1;}
10538: if (ref($slots->{$b})) { return 1;}
10539: return 0;
10540: } @{$slotsarr};
10541: }
10542: return @sorted;
10543: }
10544:
1.1040 raeburn 10545: =pod
10546:
10547: =item * get_future_slots()
10548:
10549: Inputs:
10550:
10551: =over 4
10552:
10553: cnum - course number
10554:
10555: cdom - course domain
10556:
10557: now - current UNIX time
10558:
10559: symb - optional symb
10560:
10561: =back
10562:
10563: Returns:
10564:
10565: =over 4
10566:
10567: sorted_reservable - ref to array of student_schedulable slots currently
10568: reservable, ordered by end date of reservation period.
10569:
10570: reservable_now - ref to hash of student_schedulable slots currently
10571: reservable.
10572:
10573: Keys in inner hash are:
10574: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10575: (b) endreserve: end date of reservation period.
10576: (c) uniqueperiod: start,end dates when slot is to be uniquely
10577: selected.
1.1040 raeburn 10578:
10579: sorted_future - ref to array of student_schedulable slots reservable in
10580: the future, ordered by start date of reservation period.
10581:
10582: future_reservable - ref to hash of student_schedulable slots reservable
10583: in the future.
10584:
10585: Keys in inner hash are:
10586: (a) symb: either blank or symb to which slot use is restricted.
10587: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10588: (c) uniqueperiod: start,end dates when slot is to be uniquely
10589: selected.
1.1040 raeburn 10590:
10591: =back
10592:
10593: =cut
10594:
10595: sub get_future_slots {
10596: my ($cnum,$cdom,$now,$symb) = @_;
10597: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10598: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10599: foreach my $slot (keys(%slots)) {
10600: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10601: if ($symb) {
10602: next if (($slots{$slot}->{'symb'} ne '') &&
10603: ($slots{$slot}->{'symb'} ne $symb));
10604: }
10605: if (($slots{$slot}->{'starttime'} > $now) &&
10606: ($slots{$slot}->{'endtime'} > $now)) {
10607: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10608: my $userallowed = 0;
10609: if ($slots{$slot}->{'allowedsections'}) {
10610: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10611: if (!defined($env{'request.role.sec'})
10612: && grep(/^No section assigned$/,@allowed_sec)) {
10613: $userallowed=1;
10614: } else {
10615: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10616: $userallowed=1;
10617: }
10618: }
10619: unless ($userallowed) {
10620: if (defined($env{'request.course.groups'})) {
10621: my @groups = split(/:/,$env{'request.course.groups'});
10622: foreach my $group (@groups) {
10623: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10624: $userallowed=1;
10625: last;
10626: }
10627: }
10628: }
10629: }
10630: }
10631: if ($slots{$slot}->{'allowedusers'}) {
10632: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10633: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10634: if (grep(/^\Q$user\E$/,@allowed_users)) {
10635: $userallowed = 1;
10636: }
10637: }
10638: next unless($userallowed);
10639: }
10640: my $startreserve = $slots{$slot}->{'startreserve'};
10641: my $endreserve = $slots{$slot}->{'endreserve'};
10642: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10643: my $uniqueperiod;
10644: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10645: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10646: }
1.1040 raeburn 10647: if (($startreserve < $now) &&
10648: (!$endreserve || $endreserve > $now)) {
10649: my $lastres = $endreserve;
10650: if (!$lastres) {
10651: $lastres = $slots{$slot}->{'starttime'};
10652: }
10653: $reservable_now{$slot} = {
10654: symb => $symb,
1.1075.2.104 raeburn 10655: endreserve => $lastres,
10656: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10657: };
10658: } elsif (($startreserve > $now) &&
10659: (!$endreserve || $endreserve > $startreserve)) {
10660: $future_reservable{$slot} = {
10661: symb => $symb,
1.1075.2.104 raeburn 10662: startreserve => $startreserve,
10663: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10664: };
10665: }
10666: }
10667: }
10668: my @unsorted_reservable = keys(%reservable_now);
10669: if (@unsorted_reservable > 0) {
10670: @sorted_reservable =
10671: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10672: }
10673: my @unsorted_future = keys(%future_reservable);
10674: if (@unsorted_future > 0) {
10675: @sorted_future =
10676: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10677: }
10678: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10679: }
1.780 raeburn 10680:
10681: =pod
10682:
1.1057 foxr 10683: =back
10684:
1.549 albertel 10685: =head1 HTTP Helpers
10686:
10687: =over 4
10688:
1.648 raeburn 10689: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10690:
1.258 albertel 10691: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10692: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10693: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10694:
10695: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10696: $possible_names is an ref to an array of form element names. As an example:
10697: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10698: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10699:
10700: =cut
1.1 albertel 10701:
1.6 albertel 10702: sub get_unprocessed_cgi {
1.25 albertel 10703: my ($query,$possible_names)= @_;
1.26 matthew 10704: # $Apache::lonxml::debug=1;
1.356 albertel 10705: foreach my $pair (split(/&/,$query)) {
10706: my ($name, $value) = split(/=/,$pair);
1.369 www 10707: $name = &unescape($name);
1.25 albertel 10708: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10709: $value =~ tr/+/ /;
10710: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10711: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10712: }
1.16 harris41 10713: }
1.6 albertel 10714: }
10715:
1.112 bowersj2 10716: =pod
10717:
1.648 raeburn 10718: =item * &cacheheader()
1.112 bowersj2 10719:
10720: returns cache-controlling header code
10721:
10722: =cut
10723:
1.7 albertel 10724: sub cacheheader {
1.258 albertel 10725: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10726: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10727: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10728: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10729: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10730: return $output;
1.7 albertel 10731: }
10732:
1.112 bowersj2 10733: =pod
10734:
1.648 raeburn 10735: =item * &no_cache($r)
1.112 bowersj2 10736:
10737: specifies header code to not have cache
10738:
10739: =cut
10740:
1.9 albertel 10741: sub no_cache {
1.216 albertel 10742: my ($r) = @_;
10743: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10744: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10745: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10746: $r->no_cache(1);
10747: $r->header_out("Expires" => $date);
10748: $r->header_out("Pragma" => "no-cache");
1.123 www 10749: }
10750:
10751: sub content_type {
1.181 albertel 10752: my ($r,$type,$charset) = @_;
1.299 foxr 10753: if ($r) {
10754: # Note that printout.pl calls this with undef for $r.
10755: &no_cache($r);
10756: }
1.258 albertel 10757: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10758: unless ($charset) {
10759: $charset=&Apache::lonlocal::current_encoding;
10760: }
10761: if ($charset) { $type.='; charset='.$charset; }
10762: if ($r) {
10763: $r->content_type($type);
10764: } else {
10765: print("Content-type: $type\n\n");
10766: }
1.9 albertel 10767: }
1.25 albertel 10768:
1.112 bowersj2 10769: =pod
10770:
1.648 raeburn 10771: =item * &add_to_env($name,$value)
1.112 bowersj2 10772:
1.258 albertel 10773: adds $name to the %env hash with value
1.112 bowersj2 10774: $value, if $name already exists, the entry is converted to an array
10775: reference and $value is added to the array.
10776:
10777: =cut
10778:
1.25 albertel 10779: sub add_to_env {
10780: my ($name,$value)=@_;
1.258 albertel 10781: if (defined($env{$name})) {
10782: if (ref($env{$name})) {
1.25 albertel 10783: #already have multiple values
1.258 albertel 10784: push(@{ $env{$name} },$value);
1.25 albertel 10785: } else {
10786: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10787: my $first=$env{$name};
10788: undef($env{$name});
10789: push(@{ $env{$name} },$first,$value);
1.25 albertel 10790: }
10791: } else {
1.258 albertel 10792: $env{$name}=$value;
1.25 albertel 10793: }
1.31 albertel 10794: }
1.149 albertel 10795:
10796: =pod
10797:
1.648 raeburn 10798: =item * &get_env_multiple($name)
1.149 albertel 10799:
1.258 albertel 10800: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10801: values may be defined and end up as an array ref.
10802:
10803: returns an array of values
10804:
10805: =cut
10806:
10807: sub get_env_multiple {
10808: my ($name) = @_;
10809: my @values;
1.258 albertel 10810: if (defined($env{$name})) {
1.149 albertel 10811: # exists is it an array
1.258 albertel 10812: if (ref($env{$name})) {
10813: @values=@{ $env{$name} };
1.149 albertel 10814: } else {
1.258 albertel 10815: $values[0]=$env{$name};
1.149 albertel 10816: }
10817: }
10818: return(@values);
10819: }
10820:
1.660 raeburn 10821: sub ask_for_embedded_content {
10822: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10823: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10824: %currsubfile,%unused,$rem);
1.1071 raeburn 10825: my $counter = 0;
10826: my $numnew = 0;
1.987 raeburn 10827: my $numremref = 0;
10828: my $numinvalid = 0;
10829: my $numpathchg = 0;
10830: my $numexisting = 0;
1.1071 raeburn 10831: my $numunused = 0;
10832: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10833: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10834: my $heading = &mt('Upload embedded files');
10835: my $buttontext = &mt('Upload');
10836:
1.1075.2.11 raeburn 10837: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10838: if ($actionurl eq '/adm/dependencies') {
10839: $navmap = Apache::lonnavmaps::navmap->new();
10840: }
10841: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10842: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10843: }
1.1075.2.35 raeburn 10844: if (($actionurl eq '/adm/portfolio') ||
10845: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10846: my $current_path='/';
10847: if ($env{'form.currentpath'}) {
10848: $current_path = $env{'form.currentpath'};
10849: }
10850: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10851: $udom = $cdom;
10852: $uname = $cnum;
1.984 raeburn 10853: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10854: } else {
10855: $udom = $env{'user.domain'};
10856: $uname = $env{'user.name'};
10857: $url = '/userfiles/portfolio';
10858: }
1.987 raeburn 10859: $toplevel = $url.'/';
1.984 raeburn 10860: $url .= $current_path;
10861: $getpropath = 1;
1.987 raeburn 10862: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10863: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10864: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10865: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10866: $toplevel = $url;
1.984 raeburn 10867: if ($rest ne '') {
1.987 raeburn 10868: $url .= $rest;
10869: }
10870: } elsif ($actionurl eq '/adm/coursedocs') {
10871: if (ref($args) eq 'HASH') {
1.1071 raeburn 10872: $url = $args->{'docs_url'};
10873: $toplevel = $url;
1.1075.2.11 raeburn 10874: if ($args->{'context'} eq 'paste') {
10875: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10876: ($path) =
10877: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10878: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10879: $fileloc =~ s{^/}{};
10880: }
1.1071 raeburn 10881: }
10882: } elsif ($actionurl eq '/adm/dependencies') {
10883: if ($env{'request.course.id'} ne '') {
10884: if (ref($args) eq 'HASH') {
10885: $url = $args->{'docs_url'};
10886: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10887: $toplevel = $url;
10888: unless ($toplevel =~ m{^/}) {
10889: $toplevel = "/$url";
10890: }
1.1075.2.11 raeburn 10891: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10892: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10893: $path = $1;
10894: } else {
10895: ($path) =
10896: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10897: }
1.1075.2.79 raeburn 10898: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10899: $fileloc = $toplevel;
10900: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10901: my ($udom,$uname,$fname) =
10902: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10903: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10904: } else {
10905: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10906: }
1.1071 raeburn 10907: $fileloc =~ s{^/}{};
10908: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10909: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10910: }
1.987 raeburn 10911: }
1.1075.2.35 raeburn 10912: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10913: $udom = $cdom;
10914: $uname = $cnum;
10915: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10916: $toplevel = $url;
10917: $path = $url;
10918: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10919: $fileloc =~ s{^/}{};
10920: }
10921: foreach my $file (keys(%{$allfiles})) {
10922: my $embed_file;
10923: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10924: $embed_file = $1;
10925: } else {
10926: $embed_file = $file;
10927: }
1.1075.2.55 raeburn 10928: my ($absolutepath,$cleaned_file);
10929: if ($embed_file =~ m{^\w+://}) {
10930: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10931: $newfiles{$cleaned_file} = 1;
10932: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10933: } else {
1.1075.2.55 raeburn 10934: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10935: if ($embed_file =~ m{^/}) {
10936: $absolutepath = $embed_file;
10937: }
1.1075.2.47 raeburn 10938: if ($cleaned_file =~ m{/}) {
10939: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10940: $path = &check_for_traversal($path,$url,$toplevel);
10941: my $item = $fname;
10942: if ($path ne '') {
10943: $item = $path.'/'.$fname;
10944: $subdependencies{$path}{$fname} = 1;
10945: } else {
10946: $dependencies{$item} = 1;
10947: }
10948: if ($absolutepath) {
10949: $mapping{$item} = $absolutepath;
10950: } else {
10951: $mapping{$item} = $embed_file;
10952: }
10953: } else {
10954: $dependencies{$embed_file} = 1;
10955: if ($absolutepath) {
1.1075.2.47 raeburn 10956: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10957: } else {
1.1075.2.47 raeburn 10958: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10959: }
10960: }
1.984 raeburn 10961: }
10962: }
1.1071 raeburn 10963: my $dirptr = 16384;
1.984 raeburn 10964: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10965: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10966: if (($actionurl eq '/adm/portfolio') ||
10967: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10968: my ($sublistref,$listerror) =
10969: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10970: if (ref($sublistref) eq 'ARRAY') {
10971: foreach my $line (@{$sublistref}) {
10972: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10973: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10974: }
1.984 raeburn 10975: }
1.987 raeburn 10976: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10977: if (opendir(my $dir,$url.'/'.$path)) {
10978: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10979: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10980: }
1.1075.2.11 raeburn 10981: } elsif (($actionurl eq '/adm/dependencies') ||
10982: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10983: ($args->{'context'} eq 'paste')) ||
10984: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10985: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10986: my $dir;
10987: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10988: $dir = $fileloc;
10989: } else {
10990: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10991: }
1.1071 raeburn 10992: if ($dir ne '') {
10993: my ($sublistref,$listerror) =
10994: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10995: if (ref($sublistref) eq 'ARRAY') {
10996: foreach my $line (@{$sublistref}) {
10997: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10998: undef,$mtime)=split(/\&/,$line,12);
10999: unless (($testdir&$dirptr) ||
11000: ($file_name =~ /^\.\.?$/)) {
11001: $currsubfile{$path}{$file_name} = [$size,$mtime];
11002: }
11003: }
11004: }
11005: }
1.984 raeburn 11006: }
11007: }
11008: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11009: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11010: my $item = $path.'/'.$file;
11011: unless ($mapping{$item} eq $item) {
11012: $pathchanges{$item} = 1;
11013: }
11014: $existing{$item} = 1;
11015: $numexisting ++;
11016: } else {
11017: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11018: }
11019: }
1.1071 raeburn 11020: if ($actionurl eq '/adm/dependencies') {
11021: foreach my $path (keys(%currsubfile)) {
11022: if (ref($currsubfile{$path}) eq 'HASH') {
11023: foreach my $file (keys(%{$currsubfile{$path}})) {
11024: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11025: next if (($rem ne '') &&
11026: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11027: (ref($navmap) &&
11028: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11029: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11030: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11031: $unused{$path.'/'.$file} = 1;
11032: }
11033: }
11034: }
11035: }
11036: }
1.984 raeburn 11037: }
1.987 raeburn 11038: my %currfile;
1.1075.2.35 raeburn 11039: if (($actionurl eq '/adm/portfolio') ||
11040: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11041: my ($dirlistref,$listerror) =
11042: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11043: if (ref($dirlistref) eq 'ARRAY') {
11044: foreach my $line (@{$dirlistref}) {
11045: my ($file_name,$rest) = split(/\&/,$line,2);
11046: $currfile{$file_name} = 1;
11047: }
1.984 raeburn 11048: }
1.987 raeburn 11049: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11050: if (opendir(my $dir,$url)) {
1.987 raeburn 11051: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11052: map {$currfile{$_} = 1;} @dir_list;
11053: }
1.1075.2.11 raeburn 11054: } elsif (($actionurl eq '/adm/dependencies') ||
11055: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11056: ($args->{'context'} eq 'paste')) ||
11057: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11058: if ($env{'request.course.id'} ne '') {
11059: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11060: if ($dir ne '') {
11061: my ($dirlistref,$listerror) =
11062: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11063: if (ref($dirlistref) eq 'ARRAY') {
11064: foreach my $line (@{$dirlistref}) {
11065: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11066: $size,undef,$mtime)=split(/\&/,$line,12);
11067: unless (($testdir&$dirptr) ||
11068: ($file_name =~ /^\.\.?$/)) {
11069: $currfile{$file_name} = [$size,$mtime];
11070: }
11071: }
11072: }
11073: }
11074: }
1.984 raeburn 11075: }
11076: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11077: if (exists($currfile{$file})) {
1.987 raeburn 11078: unless ($mapping{$file} eq $file) {
11079: $pathchanges{$file} = 1;
11080: }
11081: $existing{$file} = 1;
11082: $numexisting ++;
11083: } else {
1.984 raeburn 11084: $newfiles{$file} = 1;
11085: }
11086: }
1.1071 raeburn 11087: foreach my $file (keys(%currfile)) {
11088: unless (($file eq $filename) ||
11089: ($file eq $filename.'.bak') ||
11090: ($dependencies{$file})) {
1.1075.2.11 raeburn 11091: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11092: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11093: next if (($rem ne '') &&
11094: (($env{"httpref.$rem".$file} ne '') ||
11095: (ref($navmap) &&
11096: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11097: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11098: ($navmap->getResourceByUrl($rem.$1)))))));
11099: }
1.1075.2.11 raeburn 11100: }
1.1071 raeburn 11101: $unused{$file} = 1;
11102: }
11103: }
1.1075.2.11 raeburn 11104: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11105: ($args->{'context'} eq 'paste')) {
11106: $counter = scalar(keys(%existing));
11107: $numpathchg = scalar(keys(%pathchanges));
11108: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11109: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11110: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11111: $counter = scalar(keys(%existing));
11112: $numpathchg = scalar(keys(%pathchanges));
11113: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11114: }
1.984 raeburn 11115: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11116: if ($actionurl eq '/adm/dependencies') {
11117: next if ($embed_file =~ m{^\w+://});
11118: }
1.660 raeburn 11119: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11120: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11121: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11122: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11123: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11124: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11125: }
1.1075.2.35 raeburn 11126: $upload_output .= '</td>';
1.1071 raeburn 11127: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11128: $upload_output.='<td align="right">'.
11129: '<span class="LC_info LC_fontsize_medium">'.
11130: &mt("URL points to web address").'</span>';
1.987 raeburn 11131: $numremref++;
1.660 raeburn 11132: } elsif ($args->{'error_on_invalid_names'}
11133: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11134: $upload_output.='<td align="right"><span class="LC_warning">'.
11135: &mt('Invalid characters').'</span>';
1.987 raeburn 11136: $numinvalid++;
1.660 raeburn 11137: } else {
1.1075.2.35 raeburn 11138: $upload_output .= '<td>'.
11139: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11140: $embed_file,\%mapping,
1.1071 raeburn 11141: $allfiles,$codebase,'upload');
11142: $counter ++;
11143: $numnew ++;
1.987 raeburn 11144: }
11145: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11146: }
11147: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11148: if ($actionurl eq '/adm/dependencies') {
11149: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11150: $modify_output .= &start_data_table_row().
11151: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11152: '<img src="'.&icon($embed_file).'" border="0" />'.
11153: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11154: '<td>'.$size.'</td>'.
11155: '<td>'.$mtime.'</td>'.
11156: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11157: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11158: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11159: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11160: &embedded_file_element('upload_embedded',$counter,
11161: $embed_file,\%mapping,
11162: $allfiles,$codebase,'modify').
11163: '</div></td>'.
11164: &end_data_table_row()."\n";
11165: $counter ++;
11166: } else {
11167: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11168: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11169: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11170: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11171: &Apache::loncommon::end_data_table_row()."\n";
11172: }
11173: }
11174: my $delidx = $counter;
11175: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11176: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11177: $delete_output .= &start_data_table_row().
11178: '<td><img src="'.&icon($oldfile).'" />'.
11179: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11180: '<td>'.$size.'</td>'.
11181: '<td>'.$mtime.'</td>'.
11182: '<td><label><input type="checkbox" name="del_upload_dep" '.
11183: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11184: &embedded_file_element('upload_embedded',$delidx,
11185: $oldfile,\%mapping,$allfiles,
11186: $codebase,'delete').'</td>'.
11187: &end_data_table_row()."\n";
11188: $numunused ++;
11189: $delidx ++;
1.987 raeburn 11190: }
11191: if ($upload_output) {
11192: $upload_output = &start_data_table().
11193: $upload_output.
11194: &end_data_table()."\n";
11195: }
1.1071 raeburn 11196: if ($modify_output) {
11197: $modify_output = &start_data_table().
11198: &start_data_table_header_row().
11199: '<th>'.&mt('File').'</th>'.
11200: '<th>'.&mt('Size (KB)').'</th>'.
11201: '<th>'.&mt('Modified').'</th>'.
11202: '<th>'.&mt('Upload replacement?').'</th>'.
11203: &end_data_table_header_row().
11204: $modify_output.
11205: &end_data_table()."\n";
11206: }
11207: if ($delete_output) {
11208: $delete_output = &start_data_table().
11209: &start_data_table_header_row().
11210: '<th>'.&mt('File').'</th>'.
11211: '<th>'.&mt('Size (KB)').'</th>'.
11212: '<th>'.&mt('Modified').'</th>'.
11213: '<th>'.&mt('Delete?').'</th>'.
11214: &end_data_table_header_row().
11215: $delete_output.
11216: &end_data_table()."\n";
11217: }
1.987 raeburn 11218: my $applies = 0;
11219: if ($numremref) {
11220: $applies ++;
11221: }
11222: if ($numinvalid) {
11223: $applies ++;
11224: }
11225: if ($numexisting) {
11226: $applies ++;
11227: }
1.1071 raeburn 11228: if ($counter || $numunused) {
1.987 raeburn 11229: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11230: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11231: $state.'<h3>'.$heading.'</h3>';
11232: if ($actionurl eq '/adm/dependencies') {
11233: if ($numnew) {
11234: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11235: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11236: $upload_output.'<br />'."\n";
11237: }
11238: if ($numexisting) {
11239: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11240: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11241: $modify_output.'<br />'."\n";
11242: $buttontext = &mt('Save changes');
11243: }
11244: if ($numunused) {
11245: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11246: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11247: $delete_output.'<br />'."\n";
11248: $buttontext = &mt('Save changes');
11249: }
11250: } else {
11251: $output .= $upload_output.'<br />'."\n";
11252: }
11253: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11254: $counter.'" />'."\n";
11255: if ($actionurl eq '/adm/dependencies') {
11256: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11257: $numnew.'" />'."\n";
11258: } elsif ($actionurl eq '') {
1.987 raeburn 11259: $output .= '<input type="hidden" name="phase" value="three" />';
11260: }
11261: } elsif ($applies) {
11262: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11263: if ($applies > 1) {
11264: $output .=
1.1075.2.35 raeburn 11265: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11266: if ($numremref) {
11267: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11268: }
11269: if ($numinvalid) {
11270: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11271: }
11272: if ($numexisting) {
11273: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11274: }
11275: $output .= '</ul><br />';
11276: } elsif ($numremref) {
11277: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11278: } elsif ($numinvalid) {
11279: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11280: } elsif ($numexisting) {
11281: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11282: }
11283: $output .= $upload_output.'<br />';
11284: }
11285: my ($pathchange_output,$chgcount);
1.1071 raeburn 11286: $chgcount = $counter;
1.987 raeburn 11287: if (keys(%pathchanges) > 0) {
11288: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11289: if ($counter) {
1.987 raeburn 11290: $output .= &embedded_file_element('pathchange',$chgcount,
11291: $embed_file,\%mapping,
1.1071 raeburn 11292: $allfiles,$codebase,'change');
1.987 raeburn 11293: } else {
11294: $pathchange_output .=
11295: &start_data_table_row().
11296: '<td><input type ="checkbox" name="namechange" value="'.
11297: $chgcount.'" checked="checked" /></td>'.
11298: '<td>'.$mapping{$embed_file}.'</td>'.
11299: '<td>'.$embed_file.
11300: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11301: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11302: '</td>'.&end_data_table_row();
1.660 raeburn 11303: }
1.987 raeburn 11304: $numpathchg ++;
11305: $chgcount ++;
1.660 raeburn 11306: }
11307: }
1.1075.2.35 raeburn 11308: if (($counter) || ($numunused)) {
1.987 raeburn 11309: if ($numpathchg) {
11310: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11311: $numpathchg.'" />'."\n";
11312: }
11313: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11314: ($actionurl eq '/adm/imsimport')) {
11315: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11316: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11317: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11318: } elsif ($actionurl eq '/adm/dependencies') {
11319: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11320: }
1.1075.2.35 raeburn 11321: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11322: } elsif ($numpathchg) {
11323: my %pathchange = ();
11324: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11325: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11326: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11327: }
1.987 raeburn 11328: }
1.1071 raeburn 11329: return ($output,$counter,$numpathchg);
1.987 raeburn 11330: }
11331:
1.1075.2.47 raeburn 11332: =pod
11333:
11334: =item * clean_path($name)
11335:
11336: Performs clean-up of directories, subdirectories and filename in an
11337: embedded object, referenced in an HTML file which is being uploaded
11338: to a course or portfolio, where
11339: "Upload embedded images/multimedia files if HTML file" checkbox was
11340: checked.
11341:
11342: Clean-up is similar to replacements in lonnet::clean_filename()
11343: except each / between sub-directory and next level is preserved.
11344:
11345: =cut
11346:
11347: sub clean_path {
11348: my ($embed_file) = @_;
11349: $embed_file =~s{^/+}{};
11350: my @contents;
11351: if ($embed_file =~ m{/}) {
11352: @contents = split(/\//,$embed_file);
11353: } else {
11354: @contents = ($embed_file);
11355: }
11356: my $lastidx = scalar(@contents)-1;
11357: for (my $i=0; $i<=$lastidx; $i++) {
11358: $contents[$i]=~s{\\}{/}g;
11359: $contents[$i]=~s/\s+/\_/g;
11360: $contents[$i]=~s{[^/\w\.\-]}{}g;
11361: if ($i == $lastidx) {
11362: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11363: }
11364: }
11365: if ($lastidx > 0) {
11366: return join('/',@contents);
11367: } else {
11368: return $contents[0];
11369: }
11370: }
11371:
1.987 raeburn 11372: sub embedded_file_element {
1.1071 raeburn 11373: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11374: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11375: (ref($codebase) eq 'HASH'));
11376: my $output;
1.1071 raeburn 11377: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11378: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11379: }
11380: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11381: &escape($embed_file).'" />';
11382: unless (($context eq 'upload_embedded') &&
11383: ($mapping->{$embed_file} eq $embed_file)) {
11384: $output .='
11385: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11386: }
11387: my $attrib;
11388: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11389: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11390: }
11391: $output .=
11392: "\n\t\t".
11393: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11394: $attrib.'" />';
11395: if (exists($codebase->{$mapping->{$embed_file}})) {
11396: $output .=
11397: "\n\t\t".
11398: '<input name="codebase_'.$num.'" type="hidden" value="'.
11399: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11400: }
1.987 raeburn 11401: return $output;
1.660 raeburn 11402: }
11403:
1.1071 raeburn 11404: sub get_dependency_details {
11405: my ($currfile,$currsubfile,$embed_file) = @_;
11406: my ($size,$mtime,$showsize,$showmtime);
11407: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11408: if ($embed_file =~ m{/}) {
11409: my ($path,$fname) = split(/\//,$embed_file);
11410: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11411: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11412: }
11413: } else {
11414: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11415: ($size,$mtime) = @{$currfile->{$embed_file}};
11416: }
11417: }
11418: $showsize = $size/1024.0;
11419: $showsize = sprintf("%.1f",$showsize);
11420: if ($mtime > 0) {
11421: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11422: }
11423: }
11424: return ($showsize,$showmtime);
11425: }
11426:
11427: sub ask_embedded_js {
11428: return <<"END";
11429: <script type="text/javascript"">
11430: // <![CDATA[
11431: function toggleBrowse(counter) {
11432: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11433: var fileid = document.getElementById('embedded_item_'+counter);
11434: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11435: if (chkboxid.checked == true) {
11436: uploaddivid.style.display='block';
11437: } else {
11438: uploaddivid.style.display='none';
11439: fileid.value = '';
11440: }
11441: }
11442: // ]]>
11443: </script>
11444:
11445: END
11446: }
11447:
1.661 raeburn 11448: sub upload_embedded {
11449: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11450: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11451: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11452: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11453: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11454: my $orig_uploaded_filename =
11455: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11456: foreach my $type ('orig','ref','attrib','codebase') {
11457: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11458: $env{'form.embedded_'.$type.'_'.$i} =
11459: &unescape($env{'form.embedded_'.$type.'_'.$i});
11460: }
11461: }
1.661 raeburn 11462: my ($path,$fname) =
11463: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11464: # no path, whole string is fname
11465: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11466: $fname = &Apache::lonnet::clean_filename($fname);
11467: # See if there is anything left
11468: next if ($fname eq '');
11469:
11470: # Check if file already exists as a file or directory.
11471: my ($state,$msg);
11472: if ($context eq 'portfolio') {
11473: my $port_path = $dirpath;
11474: if ($group ne '') {
11475: $port_path = "groups/$group/$port_path";
11476: }
1.987 raeburn 11477: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11478: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11479: $dir_root,$port_path,$disk_quota,
11480: $current_disk_usage,$uname,$udom);
11481: if ($state eq 'will_exceed_quota'
1.984 raeburn 11482: || $state eq 'file_locked') {
1.661 raeburn 11483: $output .= $msg;
11484: next;
11485: }
11486: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11487: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11488: if ($state eq 'exists') {
11489: $output .= $msg;
11490: next;
11491: }
11492: }
11493: # Check if extension is valid
11494: if (($fname =~ /\.(\w+)$/) &&
11495: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11496: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11497: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11498: next;
11499: } elsif (($fname =~ /\.(\w+)$/) &&
11500: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11501: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11502: next;
11503: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11504: $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 11505: next;
11506: }
11507: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11508: my $subdir = $path;
11509: $subdir =~ s{/+$}{};
1.661 raeburn 11510: if ($context eq 'portfolio') {
1.984 raeburn 11511: my $result;
11512: if ($state eq 'existingfile') {
11513: $result=
11514: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11515: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11516: } else {
1.984 raeburn 11517: $result=
11518: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11519: $dirpath.
1.1075.2.35 raeburn 11520: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11521: if ($result !~ m|^/uploaded/|) {
11522: $output .= '<span class="LC_error">'
11523: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11524: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11525: .'</span><br />';
11526: next;
11527: } else {
1.987 raeburn 11528: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11529: $path.$fname.'</span>').'<br />';
1.984 raeburn 11530: }
1.661 raeburn 11531: }
1.1075.2.35 raeburn 11532: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11533: my $extendedsubdir = $dirpath.'/'.$subdir;
11534: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11535: my $result =
1.1075.2.35 raeburn 11536: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 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 {
11544: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11545: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11546: if ($context eq 'syllabus') {
11547: &Apache::lonnet::make_public_indefinitely($result);
11548: }
1.987 raeburn 11549: }
1.661 raeburn 11550: } else {
11551: # Save the file
11552: my $target = $env{'form.embedded_item_'.$i};
11553: my $fullpath = $dir_root.$dirpath.'/'.$path;
11554: my $dest = $fullpath.$fname;
11555: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11556: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11557: my $count;
11558: my $filepath = $dir_root;
1.1027 raeburn 11559: foreach my $subdir (@parts) {
11560: $filepath .= "/$subdir";
11561: if (!-e $filepath) {
1.661 raeburn 11562: mkdir($filepath,0770);
11563: }
11564: }
11565: my $fh;
11566: if (!open($fh,'>'.$dest)) {
11567: &Apache::lonnet::logthis('Failed to create '.$dest);
11568: $output .= '<span class="LC_error">'.
1.1071 raeburn 11569: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11570: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11571: '</span><br />';
11572: } else {
11573: if (!print $fh $env{'form.embedded_item_'.$i}) {
11574: &Apache::lonnet::logthis('Failed to write to '.$dest);
11575: $output .= '<span class="LC_error">'.
1.1071 raeburn 11576: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11577: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11578: '</span><br />';
11579: } else {
1.987 raeburn 11580: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11581: $url.'</span>').'<br />';
11582: unless ($context eq 'testbank') {
11583: $footer .= &mt('View embedded file: [_1]',
11584: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11585: }
11586: }
11587: close($fh);
11588: }
11589: }
11590: if ($env{'form.embedded_ref_'.$i}) {
11591: $pathchange{$i} = 1;
11592: }
11593: }
11594: if ($output) {
11595: $output = '<p>'.$output.'</p>';
11596: }
11597: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11598: $returnflag = 'ok';
1.1071 raeburn 11599: my $numpathchgs = scalar(keys(%pathchange));
11600: if ($numpathchgs > 0) {
1.987 raeburn 11601: if ($context eq 'portfolio') {
11602: $output .= '<p>'.&mt('or').'</p>';
11603: } elsif ($context eq 'testbank') {
1.1071 raeburn 11604: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11605: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11606: $returnflag = 'modify_orightml';
11607: }
11608: }
1.1071 raeburn 11609: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11610: }
11611:
11612: sub modify_html_form {
11613: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11614: my $end = 0;
11615: my $modifyform;
11616: if ($context eq 'upload_embedded') {
11617: return unless (ref($pathchange) eq 'HASH');
11618: if ($env{'form.number_embedded_items'}) {
11619: $end += $env{'form.number_embedded_items'};
11620: }
11621: if ($env{'form.number_pathchange_items'}) {
11622: $end += $env{'form.number_pathchange_items'};
11623: }
11624: if ($end) {
11625: for (my $i=0; $i<$end; $i++) {
11626: if ($i < $env{'form.number_embedded_items'}) {
11627: next unless($pathchange->{$i});
11628: }
11629: $modifyform .=
11630: &start_data_table_row().
11631: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11632: 'checked="checked" /></td>'.
11633: '<td>'.$env{'form.embedded_ref_'.$i}.
11634: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11635: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11636: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11637: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11638: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11639: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11640: '<td>'.$env{'form.embedded_orig_'.$i}.
11641: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11642: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11643: &end_data_table_row();
1.1071 raeburn 11644: }
1.987 raeburn 11645: }
11646: } else {
11647: $modifyform = $pathchgtable;
11648: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11649: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11650: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11651: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11652: }
11653: }
11654: if ($modifyform) {
1.1071 raeburn 11655: if ($actionurl eq '/adm/dependencies') {
11656: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11657: }
1.987 raeburn 11658: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11659: '<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".
11660: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11661: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11662: '</ol></p>'."\n".'<p>'.
11663: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11664: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11665: &start_data_table()."\n".
11666: &start_data_table_header_row().
11667: '<th>'.&mt('Change?').'</th>'.
11668: '<th>'.&mt('Current reference').'</th>'.
11669: '<th>'.&mt('Required reference').'</th>'.
11670: &end_data_table_header_row()."\n".
11671: $modifyform.
11672: &end_data_table().'<br />'."\n".$hiddenstate.
11673: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11674: '</form>'."\n";
11675: }
11676: return;
11677: }
11678:
11679: sub modify_html_refs {
1.1075.2.35 raeburn 11680: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11681: my $container;
11682: if ($context eq 'portfolio') {
11683: $container = $env{'form.container'};
11684: } elsif ($context eq 'coursedoc') {
11685: $container = $env{'form.primaryurl'};
1.1071 raeburn 11686: } elsif ($context eq 'manage_dependencies') {
11687: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11688: $container = "/$container";
1.1075.2.35 raeburn 11689: } elsif ($context eq 'syllabus') {
11690: $container = $url;
1.987 raeburn 11691: } else {
1.1027 raeburn 11692: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11693: }
11694: my (%allfiles,%codebase,$output,$content);
11695: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11696: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11697: if (wantarray) {
11698: return ('',0,0);
11699: } else {
11700: return;
11701: }
11702: }
11703: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11704: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11705: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11706: if (wantarray) {
11707: return ('',0,0);
11708: } else {
11709: return;
11710: }
11711: }
1.987 raeburn 11712: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11713: if ($content eq '-1') {
11714: if (wantarray) {
11715: return ('',0,0);
11716: } else {
11717: return;
11718: }
11719: }
1.987 raeburn 11720: } else {
1.1071 raeburn 11721: unless ($container =~ /^\Q$dir_root\E/) {
11722: if (wantarray) {
11723: return ('',0,0);
11724: } else {
11725: return;
11726: }
11727: }
1.1075.2.128 raeburn 11728: if (open(my $fh,'<',$container)) {
1.987 raeburn 11729: $content = join('', <$fh>);
11730: close($fh);
11731: } else {
1.1071 raeburn 11732: if (wantarray) {
11733: return ('',0,0);
11734: } else {
11735: return;
11736: }
1.987 raeburn 11737: }
11738: }
11739: my ($count,$codebasecount) = (0,0);
11740: my $mm = new File::MMagic;
11741: my $mime_type = $mm->checktype_contents($content);
11742: if ($mime_type eq 'text/html') {
11743: my $parse_result =
11744: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11745: \%codebase,\$content);
11746: if ($parse_result eq 'ok') {
11747: foreach my $i (@changes) {
11748: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11749: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11750: if ($allfiles{$ref}) {
11751: my $newname = $orig;
11752: my ($attrib_regexp,$codebase);
1.1006 raeburn 11753: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11754: if ($attrib_regexp =~ /:/) {
11755: $attrib_regexp =~ s/\:/|/g;
11756: }
11757: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11758: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11759: $count += $numchg;
1.1075.2.35 raeburn 11760: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11761: delete($allfiles{$ref});
1.987 raeburn 11762: }
11763: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11764: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11765: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11766: $codebasecount ++;
11767: }
11768: }
11769: }
1.1075.2.35 raeburn 11770: my $skiprewrites;
1.987 raeburn 11771: if ($count || $codebasecount) {
11772: my $saveresult;
1.1071 raeburn 11773: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11774: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11775: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11776: if ($url eq $container) {
11777: my ($fname) = ($container =~ m{/([^/]+)$});
11778: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11779: $count,'<span class="LC_filename">'.
1.1071 raeburn 11780: $fname.'</span>').'</p>';
1.987 raeburn 11781: } else {
11782: $output = '<p class="LC_error">'.
11783: &mt('Error: update failed for: [_1].',
11784: '<span class="LC_filename">'.
11785: $container.'</span>').'</p>';
11786: }
1.1075.2.35 raeburn 11787: if ($context eq 'syllabus') {
11788: unless ($saveresult eq 'ok') {
11789: $skiprewrites = 1;
11790: }
11791: }
1.987 raeburn 11792: } else {
1.1075.2.128 raeburn 11793: if (open(my $fh,'>',$container)) {
1.987 raeburn 11794: print $fh $content;
11795: close($fh);
11796: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11797: $count,'<span class="LC_filename">'.
11798: $container.'</span>').'</p>';
1.661 raeburn 11799: } else {
1.987 raeburn 11800: $output = '<p class="LC_error">'.
11801: &mt('Error: could not update [_1].',
11802: '<span class="LC_filename">'.
11803: $container.'</span>').'</p>';
1.661 raeburn 11804: }
11805: }
11806: }
1.1075.2.35 raeburn 11807: if (($context eq 'syllabus') && (!$skiprewrites)) {
11808: my ($actionurl,$state);
11809: $actionurl = "/public/$udom/$uname/syllabus";
11810: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11811: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11812: \%codebase,
11813: {'context' => 'rewrites',
11814: 'ignore_remote_references' => 1,});
11815: if (ref($mapping) eq 'HASH') {
11816: my $rewrites = 0;
11817: foreach my $key (keys(%{$mapping})) {
11818: next if ($key =~ m{^https?://});
11819: my $ref = $mapping->{$key};
11820: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11821: my $attrib;
11822: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11823: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11824: }
11825: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11826: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11827: $rewrites += $numchg;
11828: }
11829: }
11830: if ($rewrites) {
11831: my $saveresult;
11832: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11833: if ($url eq $container) {
11834: my ($fname) = ($container =~ m{/([^/]+)$});
11835: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11836: $count,'<span class="LC_filename">'.
11837: $fname.'</span>').'</p>';
11838: } else {
11839: $output .= '<p class="LC_error">'.
11840: &mt('Error: could not update links in [_1].',
11841: '<span class="LC_filename">'.
11842: $container.'</span>').'</p>';
11843:
11844: }
11845: }
11846: }
11847: }
1.987 raeburn 11848: } else {
11849: &logthis('Failed to parse '.$container.
11850: ' to modify references: '.$parse_result);
1.661 raeburn 11851: }
11852: }
1.1071 raeburn 11853: if (wantarray) {
11854: return ($output,$count,$codebasecount);
11855: } else {
11856: return $output;
11857: }
1.661 raeburn 11858: }
11859:
11860: sub check_for_existing {
11861: my ($path,$fname,$element) = @_;
11862: my ($state,$msg);
11863: if (-d $path.'/'.$fname) {
11864: $state = 'exists';
11865: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11866: } elsif (-e $path.'/'.$fname) {
11867: $state = 'exists';
11868: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11869: }
11870: if ($state eq 'exists') {
11871: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11872: }
11873: return ($state,$msg);
11874: }
11875:
11876: sub check_for_upload {
11877: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11878: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11879: my $filesize = length($env{'form.'.$element});
11880: if (!$filesize) {
11881: my $msg = '<span class="LC_error">'.
11882: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11883: '<span class="LC_filename">'.$fname.'</span>',
11884: $filesize).'<br />'.
1.1007 raeburn 11885: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11886: '</span>';
11887: return ('zero_bytes',$msg);
11888: }
11889: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11890: my $getpropath = 1;
1.1021 raeburn 11891: my ($dirlistref,$listerror) =
11892: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11893: my $found_file = 0;
11894: my $locked_file = 0;
1.991 raeburn 11895: my @lockers;
11896: my $navmap;
11897: if ($env{'request.course.id'}) {
11898: $navmap = Apache::lonnavmaps::navmap->new();
11899: }
1.1021 raeburn 11900: if (ref($dirlistref) eq 'ARRAY') {
11901: foreach my $line (@{$dirlistref}) {
11902: my ($file_name,$rest)=split(/\&/,$line,2);
11903: if ($file_name eq $fname){
11904: $file_name = $path.$file_name;
11905: if ($group ne '') {
11906: $file_name = $group.$file_name;
11907: }
11908: $found_file = 1;
11909: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11910: foreach my $lock (@lockers) {
11911: if (ref($lock) eq 'ARRAY') {
11912: my ($symb,$crsid) = @{$lock};
11913: if ($crsid eq $env{'request.course.id'}) {
11914: if (ref($navmap)) {
11915: my $res = $navmap->getBySymb($symb);
11916: foreach my $part (@{$res->parts()}) {
11917: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11918: unless (($slot_status == $res->RESERVED) ||
11919: ($slot_status == $res->RESERVED_LOCATION)) {
11920: $locked_file = 1;
11921: }
1.991 raeburn 11922: }
1.1021 raeburn 11923: } else {
11924: $locked_file = 1;
1.991 raeburn 11925: }
11926: } else {
11927: $locked_file = 1;
11928: }
11929: }
1.1021 raeburn 11930: }
11931: } else {
11932: my @info = split(/\&/,$rest);
11933: my $currsize = $info[6]/1000;
11934: if ($currsize < $filesize) {
11935: my $extra = $filesize - $currsize;
11936: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11937: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11938: &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 11939: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11940: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11941: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11942: return ('will_exceed_quota',$msg);
11943: }
1.984 raeburn 11944: }
11945: }
1.661 raeburn 11946: }
11947: }
11948: }
11949: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11950: my $msg = '<p class="LC_warning">'.
11951: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11952: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11953: return ('will_exceed_quota',$msg);
11954: } elsif ($found_file) {
11955: if ($locked_file) {
1.1075.2.69 raeburn 11956: my $msg = '<p class="LC_warning">';
1.661 raeburn 11957: $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 11958: $msg .= '</p>';
1.661 raeburn 11959: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11960: return ('file_locked',$msg);
11961: } else {
1.1075.2.69 raeburn 11962: my $msg = '<p class="LC_error">';
1.984 raeburn 11963: $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 11964: $msg .= '</p>';
1.984 raeburn 11965: return ('existingfile',$msg);
1.661 raeburn 11966: }
11967: }
11968: }
11969:
1.987 raeburn 11970: sub check_for_traversal {
11971: my ($path,$url,$toplevel) = @_;
11972: my @parts=split(/\//,$path);
11973: my $cleanpath;
11974: my $fullpath = $url;
11975: for (my $i=0;$i<@parts;$i++) {
11976: next if ($parts[$i] eq '.');
11977: if ($parts[$i] eq '..') {
11978: $fullpath =~ s{([^/]+/)$}{};
11979: } else {
11980: $fullpath .= $parts[$i].'/';
11981: }
11982: }
11983: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11984: $cleanpath = $1;
11985: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11986: my $curr_toprel = $1;
11987: my @parts = split(/\//,$curr_toprel);
11988: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11989: my @urlparts = split(/\//,$url_toprel);
11990: my $doubledots;
11991: my $startdiff = -1;
11992: for (my $i=0; $i<@urlparts; $i++) {
11993: if ($startdiff == -1) {
11994: unless ($urlparts[$i] eq $parts[$i]) {
11995: $startdiff = $i;
11996: $doubledots .= '../';
11997: }
11998: } else {
11999: $doubledots .= '../';
12000: }
12001: }
12002: if ($startdiff > -1) {
12003: $cleanpath = $doubledots;
12004: for (my $i=$startdiff; $i<@parts; $i++) {
12005: $cleanpath .= $parts[$i].'/';
12006: }
12007: }
12008: }
12009: $cleanpath =~ s{(/)$}{};
12010: return $cleanpath;
12011: }
1.31 albertel 12012:
1.1053 raeburn 12013: sub is_archive_file {
12014: my ($mimetype) = @_;
12015: if (($mimetype eq 'application/octet-stream') ||
12016: ($mimetype eq 'application/x-stuffit') ||
12017: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12018: return 1;
12019: }
12020: return;
12021: }
12022:
12023: sub decompress_form {
1.1065 raeburn 12024: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12025: my %lt = &Apache::lonlocal::texthash (
12026: this => 'This file is an archive file.',
1.1067 raeburn 12027: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12028: itsc => 'Its contents are as follows:',
1.1053 raeburn 12029: youm => 'You may wish to extract its contents.',
12030: extr => 'Extract contents',
1.1067 raeburn 12031: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12032: proa => 'Process automatically?',
1.1053 raeburn 12033: yes => 'Yes',
12034: no => 'No',
1.1067 raeburn 12035: fold => 'Title for folder containing movie',
12036: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12037: );
1.1065 raeburn 12038: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12039: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12040: my $info = &list_archive_contents($fileloc,\@paths);
12041: if (@paths) {
12042: foreach my $path (@paths) {
12043: $path =~ s{^/}{};
1.1067 raeburn 12044: if ($path =~ m{^([^/]+)/$}) {
12045: $topdir = $1;
12046: }
1.1065 raeburn 12047: if ($path =~ m{^([^/]+)/}) {
12048: $toplevel{$1} = $path;
12049: } else {
12050: $toplevel{$path} = $path;
12051: }
12052: }
12053: }
1.1067 raeburn 12054: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12055: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12056: "$topdir/media/",
12057: "$topdir/media/$topdir.mp4",
12058: "$topdir/media/FirstFrame.png",
12059: "$topdir/media/player.swf",
12060: "$topdir/media/swfobject.js",
12061: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12062: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12063: "$topdir/$topdir.mp4",
12064: "$topdir/$topdir\_config.xml",
12065: "$topdir/$topdir\_controller.swf",
12066: "$topdir/$topdir\_embed.css",
12067: "$topdir/$topdir\_First_Frame.png",
12068: "$topdir/$topdir\_player.html",
12069: "$topdir/$topdir\_Thumbnails.png",
12070: "$topdir/playerProductInstall.swf",
12071: "$topdir/scripts/",
12072: "$topdir/scripts/config_xml.js",
12073: "$topdir/scripts/handlebars.js",
12074: "$topdir/scripts/jquery-1.7.1.min.js",
12075: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12076: "$topdir/scripts/modernizr.js",
12077: "$topdir/scripts/player-min.js",
12078: "$topdir/scripts/swfobject.js",
12079: "$topdir/skins/",
12080: "$topdir/skins/configuration_express.xml",
12081: "$topdir/skins/express_show/",
12082: "$topdir/skins/express_show/player-min.css",
12083: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12084: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12085: "$topdir/$topdir.mp4",
12086: "$topdir/$topdir\_config.xml",
12087: "$topdir/$topdir\_controller.swf",
12088: "$topdir/$topdir\_embed.css",
12089: "$topdir/$topdir\_First_Frame.png",
12090: "$topdir/$topdir\_player.html",
12091: "$topdir/$topdir\_Thumbnails.png",
12092: "$topdir/playerProductInstall.swf",
12093: "$topdir/scripts/",
12094: "$topdir/scripts/config_xml.js",
12095: "$topdir/scripts/techsmith-smart-player.min.js",
12096: "$topdir/skins/",
12097: "$topdir/skins/configuration_express.xml",
12098: "$topdir/skins/express_show/",
12099: "$topdir/skins/express_show/spritesheet.min.css",
12100: "$topdir/skins/express_show/spritesheet.png",
12101: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12102: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12103: if (@diffs == 0) {
1.1075.2.59 raeburn 12104: $is_camtasia = 6;
12105: } else {
1.1075.2.81 raeburn 12106: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12107: if (@diffs == 0) {
12108: $is_camtasia = 8;
1.1075.2.81 raeburn 12109: } else {
12110: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12111: if (@diffs == 0) {
12112: $is_camtasia = 8;
12113: }
1.1075.2.59 raeburn 12114: }
1.1067 raeburn 12115: }
12116: }
12117: my $output;
12118: if ($is_camtasia) {
12119: $output = <<"ENDCAM";
12120: <script type="text/javascript" language="Javascript">
12121: // <![CDATA[
12122:
12123: function camtasiaToggle() {
12124: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12125: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12126: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12127: document.getElementById('camtasia_titles').style.display='block';
12128: } else {
12129: document.getElementById('camtasia_titles').style.display='none';
12130: }
12131: }
12132: }
12133: return;
12134: }
12135:
12136: // ]]>
12137: </script>
12138: <p>$lt{'camt'}</p>
12139: ENDCAM
1.1065 raeburn 12140: } else {
1.1067 raeburn 12141: $output = '<p>'.$lt{'this'};
12142: if ($info eq '') {
12143: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12144: } else {
12145: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12146: '<div><pre>'.$info.'</pre></div>';
12147: }
1.1065 raeburn 12148: }
1.1067 raeburn 12149: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12150: my $duplicates;
12151: my $num = 0;
12152: if (ref($dirlist) eq 'ARRAY') {
12153: foreach my $item (@{$dirlist}) {
12154: if (ref($item) eq 'ARRAY') {
12155: if (exists($toplevel{$item->[0]})) {
12156: $duplicates .=
12157: &start_data_table_row().
12158: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12159: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12160: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12161: 'value="1" />'.&mt('Yes').'</label>'.
12162: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12163: '<td>'.$item->[0].'</td>';
12164: if ($item->[2]) {
12165: $duplicates .= '<td>'.&mt('Directory').'</td>';
12166: } else {
12167: $duplicates .= '<td>'.&mt('File').'</td>';
12168: }
12169: $duplicates .= '<td>'.$item->[3].'</td>'.
12170: '<td>'.
12171: &Apache::lonlocal::locallocaltime($item->[4]).
12172: '</td>'.
12173: &end_data_table_row();
12174: $num ++;
12175: }
12176: }
12177: }
12178: }
12179: my $itemcount;
12180: if (@paths > 0) {
12181: $itemcount = scalar(@paths);
12182: } else {
12183: $itemcount = 1;
12184: }
1.1067 raeburn 12185: if ($is_camtasia) {
12186: $output .= $lt{'auto'}.'<br />'.
12187: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12188: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12189: $lt{'yes'}.'</label> <label>'.
12190: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12191: $lt{'no'}.'</label></span><br />'.
12192: '<div id="camtasia_titles" style="display:block">'.
12193: &Apache::lonhtmlcommon::start_pick_box().
12194: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12195: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12196: &Apache::lonhtmlcommon::row_closure().
12197: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12198: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12199: &Apache::lonhtmlcommon::row_closure(1).
12200: &Apache::lonhtmlcommon::end_pick_box().
12201: '</div>';
12202: }
1.1065 raeburn 12203: $output .=
12204: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12205: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12206: "\n";
1.1065 raeburn 12207: if ($duplicates ne '') {
12208: $output .= '<p><span class="LC_warning">'.
12209: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12210: &start_data_table().
12211: &start_data_table_header_row().
12212: '<th>'.&mt('Overwrite?').'</th>'.
12213: '<th>'.&mt('Name').'</th>'.
12214: '<th>'.&mt('Type').'</th>'.
12215: '<th>'.&mt('Size').'</th>'.
12216: '<th>'.&mt('Last modified').'</th>'.
12217: &end_data_table_header_row().
12218: $duplicates.
12219: &end_data_table().
12220: '</p>';
12221: }
1.1067 raeburn 12222: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12223: if (ref($hiddenelements) eq 'HASH') {
12224: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12225: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12226: }
12227: }
12228: $output .= <<"END";
1.1067 raeburn 12229: <br />
1.1053 raeburn 12230: <input type="submit" name="decompress" value="$lt{'extr'}" />
12231: </form>
12232: $noextract
12233: END
12234: return $output;
12235: }
12236:
1.1065 raeburn 12237: sub decompression_utility {
12238: my ($program) = @_;
12239: my @utilities = ('tar','gunzip','bunzip2','unzip');
12240: my $location;
12241: if (grep(/^\Q$program\E$/,@utilities)) {
12242: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12243: '/usr/sbin/') {
12244: if (-x $dir.$program) {
12245: $location = $dir.$program;
12246: last;
12247: }
12248: }
12249: }
12250: return $location;
12251: }
12252:
12253: sub list_archive_contents {
12254: my ($file,$pathsref) = @_;
12255: my (@cmd,$output);
12256: my $needsregexp;
12257: if ($file =~ /\.zip$/) {
12258: @cmd = (&decompression_utility('unzip'),"-l");
12259: $needsregexp = 1;
12260: } elsif (($file =~ m/\.tar\.gz$/) ||
12261: ($file =~ /\.tgz$/)) {
12262: @cmd = (&decompression_utility('tar'),"-ztf");
12263: } elsif ($file =~ /\.tar\.bz2$/) {
12264: @cmd = (&decompression_utility('tar'),"-jtf");
12265: } elsif ($file =~ m|\.tar$|) {
12266: @cmd = (&decompression_utility('tar'),"-tf");
12267: }
12268: if (@cmd) {
12269: undef($!);
12270: undef($@);
12271: if (open(my $fh,"-|", @cmd, $file)) {
12272: while (my $line = <$fh>) {
12273: $output .= $line;
12274: chomp($line);
12275: my $item;
12276: if ($needsregexp) {
12277: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12278: } else {
12279: $item = $line;
12280: }
12281: if ($item ne '') {
12282: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12283: push(@{$pathsref},$item);
12284: }
12285: }
12286: }
12287: close($fh);
12288: }
12289: }
12290: return $output;
12291: }
12292:
1.1053 raeburn 12293: sub decompress_uploaded_file {
12294: my ($file,$dir) = @_;
12295: &Apache::lonnet::appenv({'cgi.file' => $file});
12296: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12297: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12298: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12299: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12300: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12301: my $decompressed = $env{'cgi.decompressed'};
12302: &Apache::lonnet::delenv('cgi.file');
12303: &Apache::lonnet::delenv('cgi.dir');
12304: &Apache::lonnet::delenv('cgi.decompressed');
12305: return ($decompressed,$result);
12306: }
12307:
1.1055 raeburn 12308: sub process_decompression {
12309: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12310: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12311: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12312: &mt('Unexpected file path.').'</p>'."\n";
12313: }
12314: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12315: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12316: &mt('Unexpected course context.').'</p>'."\n";
12317: }
12318: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12319: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12320: &mt('Filename contained unexpected characters.').'</p>'."\n";
12321: }
1.1055 raeburn 12322: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12323: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12324: $error = &mt('Filename not a supported archive file type.').
12325: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12326: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12327: } else {
12328: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12329: if ($docuhome eq 'no_host') {
12330: $error = &mt('Could not determine home server for course.');
12331: } else {
12332: my @ids=&Apache::lonnet::current_machine_ids();
12333: my $currdir = "$dir_root/$destination";
12334: if (grep(/^\Q$docuhome\E$/,@ids)) {
12335: $dir = &LONCAPA::propath($docudom,$docuname).
12336: "$dir_root/$destination";
12337: } else {
12338: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12339: "$dir_root/$docudom/$docuname/$destination";
12340: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12341: $error = &mt('Archive file not found.');
12342: }
12343: }
1.1065 raeburn 12344: my (@to_overwrite,@to_skip);
12345: if ($env{'form.archive_overwrite_total'} > 0) {
12346: my $total = $env{'form.archive_overwrite_total'};
12347: for (my $i=0; $i<$total; $i++) {
12348: if ($env{'form.archive_overwrite_'.$i} == 1) {
12349: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12350: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12351: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12352: }
12353: }
12354: }
12355: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12356: my $numoverwrite = scalar(@to_overwrite);
12357: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12358: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12359: } elsif ($dir eq '') {
1.1055 raeburn 12360: $error = &mt('Directory containing archive file unavailable.');
12361: } elsif (!$error) {
1.1065 raeburn 12362: my ($decompressed,$display);
1.1075.2.128 raeburn 12363: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12364: my $tempdir = time.'_'.$$.int(rand(10000));
12365: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12366: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12367: ($decompressed,$display) =
12368: &decompress_uploaded_file($file,"$dir/$tempdir");
12369: foreach my $item (@to_skip) {
12370: if (($item ne '') && ($item !~ /\.\./)) {
12371: if (-f "$dir/$tempdir/$item") {
12372: unlink("$dir/$tempdir/$item");
12373: } elsif (-d "$dir/$tempdir/$item") {
12374: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12375: }
12376: }
12377: }
12378: foreach my $item (@to_overwrite) {
12379: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12380: if (($item ne '') && ($item !~ /\.\./)) {
12381: if (-f "$dir/$item") {
12382: unlink("$dir/$item");
12383: } elsif (-d "$dir/$item") {
12384: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12385: }
12386: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12387: }
1.1065 raeburn 12388: }
12389: }
1.1075.2.128 raeburn 12390: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12391: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12392: }
1.1065 raeburn 12393: }
12394: } else {
12395: ($decompressed,$display) =
12396: &decompress_uploaded_file($file,$dir);
12397: }
1.1055 raeburn 12398: if ($decompressed eq 'ok') {
1.1065 raeburn 12399: $output = '<p class="LC_info">'.
12400: &mt('Files extracted successfully from archive.').
12401: '</p>'."\n";
1.1055 raeburn 12402: my ($warning,$result,@contents);
12403: my ($newdirlistref,$newlisterror) =
12404: &Apache::lonnet::dirlist($currdir,$docudom,
12405: $docuname,1);
12406: my (%is_dir,%changes,@newitems);
12407: my $dirptr = 16384;
1.1065 raeburn 12408: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12409: foreach my $dir_line (@{$newdirlistref}) {
12410: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12411: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12412: push(@newitems,$item);
12413: if ($dirptr&$testdir) {
12414: $is_dir{$item} = 1;
12415: }
12416: $changes{$item} = 1;
12417: }
12418: }
12419: }
12420: if (keys(%changes) > 0) {
12421: foreach my $item (sort(@newitems)) {
12422: if ($changes{$item}) {
12423: push(@contents,$item);
12424: }
12425: }
12426: }
12427: if (@contents > 0) {
1.1067 raeburn 12428: my $wantform;
12429: unless ($env{'form.autoextract_camtasia'}) {
12430: $wantform = 1;
12431: }
1.1056 raeburn 12432: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12433: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12434: $currdir,\%is_dir,
12435: \%children,\%parent,
1.1056 raeburn 12436: \@contents,\%dirorder,
12437: \%titles,$wantform);
1.1055 raeburn 12438: if ($datatable ne '') {
12439: $output .= &archive_options_form('decompressed',$datatable,
12440: $count,$hiddenelem);
1.1065 raeburn 12441: my $startcount = 6;
1.1055 raeburn 12442: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12443: \%titles,\%children);
1.1055 raeburn 12444: }
1.1067 raeburn 12445: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12446: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12447: my %displayed;
12448: my $total = 1;
12449: $env{'form.archive_directory'} = [];
12450: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12451: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12452: $path =~ s{/$}{};
12453: my $item;
12454: if ($path ne '') {
12455: $item = "$path/$titles{$i}";
12456: } else {
12457: $item = $titles{$i};
12458: }
12459: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12460: if ($item eq $contents[0]) {
12461: push(@{$env{'form.archive_directory'}},$i);
12462: $env{'form.archive_'.$i} = 'display';
12463: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12464: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12465: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12466: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12467: $env{'form.archive_'.$i} = 'display';
12468: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12469: $displayed{'web'} = $i;
12470: } else {
1.1075.2.59 raeburn 12471: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12472: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12473: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12474: push(@{$env{'form.archive_directory'}},$i);
12475: }
12476: $env{'form.archive_'.$i} = 'dependency';
12477: }
12478: $total ++;
12479: }
12480: for (my $i=1; $i<$total; $i++) {
12481: next if ($i == $displayed{'web'});
12482: next if ($i == $displayed{'folder'});
12483: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12484: }
12485: $env{'form.phase'} = 'decompress_cleanup';
12486: $env{'form.archivedelete'} = 1;
12487: $env{'form.archive_count'} = $total-1;
12488: $output .=
12489: &process_extracted_files('coursedocs',$docudom,
12490: $docuname,$destination,
12491: $dir_root,$hiddenelem);
12492: }
1.1055 raeburn 12493: } else {
12494: $warning = &mt('No new items extracted from archive file.');
12495: }
12496: } else {
12497: $output = $display;
12498: $error = &mt('An error occurred during extraction from the archive file.');
12499: }
12500: }
12501: }
12502: }
12503: if ($error) {
12504: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12505: $error.'</p>'."\n";
12506: }
12507: if ($warning) {
12508: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12509: }
12510: return $output;
12511: }
12512:
12513: sub get_extracted {
1.1056 raeburn 12514: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12515: $titles,$wantform) = @_;
1.1055 raeburn 12516: my $count = 0;
12517: my $depth = 0;
12518: my $datatable;
1.1056 raeburn 12519: my @hierarchy;
1.1055 raeburn 12520: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12521: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12522: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12523: foreach my $item (@{$contents}) {
12524: $count ++;
1.1056 raeburn 12525: @{$dirorder->{$count}} = @hierarchy;
12526: $titles->{$count} = $item;
1.1055 raeburn 12527: &archive_hierarchy($depth,$count,$parent,$children);
12528: if ($wantform) {
12529: $datatable .= &archive_row($is_dir->{$item},$item,
12530: $currdir,$depth,$count);
12531: }
12532: if ($is_dir->{$item}) {
12533: $depth ++;
1.1056 raeburn 12534: push(@hierarchy,$count);
12535: $parent->{$depth} = $count;
1.1055 raeburn 12536: $datatable .=
12537: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12538: \$depth,\$count,\@hierarchy,$dirorder,
12539: $children,$parent,$titles,$wantform);
1.1055 raeburn 12540: $depth --;
1.1056 raeburn 12541: pop(@hierarchy);
1.1055 raeburn 12542: }
12543: }
12544: return ($count,$datatable);
12545: }
12546:
12547: sub recurse_extracted_archive {
1.1056 raeburn 12548: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12549: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12550: my $result='';
1.1056 raeburn 12551: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12552: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12553: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12554: return $result;
12555: }
12556: my $dirptr = 16384;
12557: my ($newdirlistref,$newlisterror) =
12558: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12559: if (ref($newdirlistref) eq 'ARRAY') {
12560: foreach my $dir_line (@{$newdirlistref}) {
12561: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12562: unless ($item =~ /^\.+$/) {
12563: $$count ++;
1.1056 raeburn 12564: @{$dirorder->{$$count}} = @{$hierarchy};
12565: $titles->{$$count} = $item;
1.1055 raeburn 12566: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12567:
1.1055 raeburn 12568: my $is_dir;
12569: if ($dirptr&$testdir) {
12570: $is_dir = 1;
12571: }
12572: if ($wantform) {
12573: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12574: }
12575: if ($is_dir) {
12576: $$depth ++;
1.1056 raeburn 12577: push(@{$hierarchy},$$count);
12578: $parent->{$$depth} = $$count;
1.1055 raeburn 12579: $result .=
12580: &recurse_extracted_archive("$currdir/$item",$docudom,
12581: $docuname,$depth,$count,
1.1056 raeburn 12582: $hierarchy,$dirorder,$children,
12583: $parent,$titles,$wantform);
1.1055 raeburn 12584: $$depth --;
1.1056 raeburn 12585: pop(@{$hierarchy});
1.1055 raeburn 12586: }
12587: }
12588: }
12589: }
12590: return $result;
12591: }
12592:
12593: sub archive_hierarchy {
12594: my ($depth,$count,$parent,$children) =@_;
12595: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12596: if (exists($parent->{$depth})) {
12597: $children->{$parent->{$depth}} .= $count.':';
12598: }
12599: }
12600: return;
12601: }
12602:
12603: sub archive_row {
12604: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12605: my ($name) = ($item =~ m{([^/]+)$});
12606: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12607: 'display' => 'Add as file',
1.1055 raeburn 12608: 'dependency' => 'Include as dependency',
12609: 'discard' => 'Discard',
12610: );
12611: if ($is_dir) {
1.1059 raeburn 12612: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12613: }
1.1056 raeburn 12614: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12615: my $offset = 0;
1.1055 raeburn 12616: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12617: $offset ++;
1.1065 raeburn 12618: if ($action ne 'display') {
12619: $offset ++;
12620: }
1.1055 raeburn 12621: $output .= '<td><span class="LC_nobreak">'.
12622: '<label><input type="radio" name="archive_'.$count.
12623: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12624: my $text = $choices{$action};
12625: if ($is_dir) {
12626: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12627: if ($action eq 'display') {
1.1059 raeburn 12628: $text = &mt('Add as folder');
1.1055 raeburn 12629: }
1.1056 raeburn 12630: } else {
12631: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12632:
12633: }
12634: $output .= ' /> '.$choices{$action}.'</label></span>';
12635: if ($action eq 'dependency') {
12636: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12637: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12638: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12639: '<option value=""></option>'."\n".
12640: '</select>'."\n".
12641: '</div>';
1.1059 raeburn 12642: } elsif ($action eq 'display') {
12643: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12644: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12645: '</div>';
1.1055 raeburn 12646: }
1.1056 raeburn 12647: $output .= '</td>';
1.1055 raeburn 12648: }
12649: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12650: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12651: for (my $i=0; $i<$depth; $i++) {
12652: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12653: }
12654: if ($is_dir) {
12655: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12656: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12657: } else {
12658: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12659: }
12660: $output .= ' '.$name.'</td>'."\n".
12661: &end_data_table_row();
12662: return $output;
12663: }
12664:
12665: sub archive_options_form {
1.1065 raeburn 12666: my ($form,$display,$count,$hiddenelem) = @_;
12667: my %lt = &Apache::lonlocal::texthash(
12668: perm => 'Permanently remove archive file?',
12669: hows => 'How should each extracted item be incorporated in the course?',
12670: cont => 'Content actions for all',
12671: addf => 'Add as folder/file',
12672: incd => 'Include as dependency for a displayed file',
12673: disc => 'Discard',
12674: no => 'No',
12675: yes => 'Yes',
12676: save => 'Save',
12677: );
12678: my $output = <<"END";
12679: <form name="$form" method="post" action="">
12680: <p><span class="LC_nobreak">$lt{'perm'}
12681: <label>
12682: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12683: </label>
12684:
12685: <label>
12686: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12687: </span>
12688: </p>
12689: <input type="hidden" name="phase" value="decompress_cleanup" />
12690: <br />$lt{'hows'}
12691: <div class="LC_columnSection">
12692: <fieldset>
12693: <legend>$lt{'cont'}</legend>
12694: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12695: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12696: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12697: </fieldset>
12698: </div>
12699: END
12700: return $output.
1.1055 raeburn 12701: &start_data_table()."\n".
1.1065 raeburn 12702: $display."\n".
1.1055 raeburn 12703: &end_data_table()."\n".
12704: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12705: $hiddenelem.
1.1065 raeburn 12706: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12707: '</form>';
12708: }
12709:
12710: sub archive_javascript {
1.1056 raeburn 12711: my ($startcount,$numitems,$titles,$children) = @_;
12712: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12713: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12714: my $scripttag = <<START;
12715: <script type="text/javascript">
12716: // <![CDATA[
12717:
12718: function checkAll(form,prefix) {
12719: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12720: for (var i=0; i < form.elements.length; i++) {
12721: var id = form.elements[i].id;
12722: if ((id != '') && (id != undefined)) {
12723: if (idstr.test(id)) {
12724: if (form.elements[i].type == 'radio') {
12725: form.elements[i].checked = true;
1.1056 raeburn 12726: var nostart = i-$startcount;
1.1059 raeburn 12727: var offset = nostart%7;
12728: var count = (nostart-offset)/7;
1.1056 raeburn 12729: dependencyCheck(form,count,offset);
1.1055 raeburn 12730: }
12731: }
12732: }
12733: }
12734: }
12735:
12736: function propagateCheck(form,count) {
12737: if (count > 0) {
1.1059 raeburn 12738: var startelement = $startcount + ((count-1) * 7);
12739: for (var j=1; j<6; j++) {
12740: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12741: var item = startelement + j;
12742: if (form.elements[item].type == 'radio') {
12743: if (form.elements[item].checked) {
12744: containerCheck(form,count,j);
12745: break;
12746: }
1.1055 raeburn 12747: }
12748: }
12749: }
12750: }
12751: }
12752:
12753: numitems = $numitems
1.1056 raeburn 12754: var titles = new Array(numitems);
12755: var parents = new Array(numitems);
1.1055 raeburn 12756: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12757: parents[i] = new Array;
1.1055 raeburn 12758: }
1.1059 raeburn 12759: var maintitle = '$maintitle';
1.1055 raeburn 12760:
12761: START
12762:
1.1056 raeburn 12763: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12764: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12765: for (my $i=0; $i<@contents; $i ++) {
12766: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12767: }
12768: }
12769:
1.1056 raeburn 12770: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12771: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12772: }
12773:
1.1055 raeburn 12774: $scripttag .= <<END;
12775:
12776: function containerCheck(form,count,offset) {
12777: if (count > 0) {
1.1056 raeburn 12778: dependencyCheck(form,count,offset);
1.1059 raeburn 12779: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12780: form.elements[item].checked = true;
12781: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12782: if (parents[count].length > 0) {
12783: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12784: containerCheck(form,parents[count][j],offset);
12785: }
12786: }
12787: }
12788: }
12789: }
12790:
12791: function dependencyCheck(form,count,offset) {
12792: if (count > 0) {
1.1059 raeburn 12793: var chosen = (offset+$startcount)+7*(count-1);
12794: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12795: var currtype = form.elements[depitem].type;
12796: if (form.elements[chosen].value == 'dependency') {
12797: document.getElementById('arc_depon_'+count).style.display='block';
12798: form.elements[depitem].options.length = 0;
12799: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12800: for (var i=1; i<=numitems; i++) {
12801: if (i == count) {
12802: continue;
12803: }
1.1059 raeburn 12804: var startelement = $startcount + (i-1) * 7;
12805: for (var j=1; j<6; j++) {
12806: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12807: var item = startelement + j;
12808: if (form.elements[item].type == 'radio') {
12809: if (form.elements[item].checked) {
12810: if (form.elements[item].value == 'display') {
12811: var n = form.elements[depitem].options.length;
12812: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12813: }
12814: }
12815: }
12816: }
12817: }
12818: }
12819: } else {
12820: document.getElementById('arc_depon_'+count).style.display='none';
12821: form.elements[depitem].options.length = 0;
12822: form.elements[depitem].options[0] = new Option('Select','',true,true);
12823: }
1.1059 raeburn 12824: titleCheck(form,count,offset);
1.1056 raeburn 12825: }
12826: }
12827:
12828: function propagateSelect(form,count,offset) {
12829: if (count > 0) {
1.1065 raeburn 12830: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12831: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12832: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12833: if (parents[count].length > 0) {
12834: for (var j=0; j<parents[count].length; j++) {
12835: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12836: }
12837: }
12838: }
12839: }
12840: }
1.1056 raeburn 12841:
12842: function containerSelect(form,count,offset,picked) {
12843: if (count > 0) {
1.1065 raeburn 12844: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12845: if (form.elements[item].type == 'radio') {
12846: if (form.elements[item].value == 'dependency') {
12847: if (form.elements[item+1].type == 'select-one') {
12848: for (var i=0; i<form.elements[item+1].options.length; i++) {
12849: if (form.elements[item+1].options[i].value == picked) {
12850: form.elements[item+1].selectedIndex = i;
12851: break;
12852: }
12853: }
12854: }
12855: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12856: if (parents[count].length > 0) {
12857: for (var j=0; j<parents[count].length; j++) {
12858: containerSelect(form,parents[count][j],offset,picked);
12859: }
12860: }
12861: }
12862: }
12863: }
12864: }
12865: }
12866:
1.1059 raeburn 12867: function titleCheck(form,count,offset) {
12868: if (count > 0) {
12869: var chosen = (offset+$startcount)+7*(count-1);
12870: var depitem = $startcount + ((count-1) * 7) + 2;
12871: var currtype = form.elements[depitem].type;
12872: if (form.elements[chosen].value == 'display') {
12873: document.getElementById('arc_title_'+count).style.display='block';
12874: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12875: document.getElementById('archive_title_'+count).value=maintitle;
12876: }
12877: } else {
12878: document.getElementById('arc_title_'+count).style.display='none';
12879: if (currtype == 'text') {
12880: document.getElementById('archive_title_'+count).value='';
12881: }
12882: }
12883: }
12884: return;
12885: }
12886:
1.1055 raeburn 12887: // ]]>
12888: </script>
12889: END
12890: return $scripttag;
12891: }
12892:
12893: sub process_extracted_files {
1.1067 raeburn 12894: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12895: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12896: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12897: my @ids=&Apache::lonnet::current_machine_ids();
12898: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12899: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12900: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12901: if (grep(/^\Q$docuhome\E$/,@ids)) {
12902: $prefix = &LONCAPA::propath($docudom,$docuname);
12903: $pathtocheck = "$dir_root/$destination";
12904: $dir = $dir_root;
12905: $ishome = 1;
12906: } else {
12907: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12908: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12909: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12910: }
12911: my $currdir = "$dir_root/$destination";
12912: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12913: if ($env{'form.folderpath'}) {
12914: my @items = split('&',$env{'form.folderpath'});
12915: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12916: if ($env{'form.folderpath'} =~ /\:1$/) {
12917: $containers{'0'}='page';
12918: } else {
12919: $containers{'0'}='sequence';
12920: }
1.1055 raeburn 12921: }
12922: my @archdirs = &get_env_multiple('form.archive_directory');
12923: if ($numitems) {
12924: for (my $i=1; $i<=$numitems; $i++) {
12925: my $path = $env{'form.archive_content_'.$i};
12926: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12927: my $item = $1;
12928: $toplevelitems{$item} = $i;
12929: if (grep(/^\Q$i\E$/,@archdirs)) {
12930: $is_dir{$item} = 1;
12931: }
12932: }
12933: }
12934: }
1.1067 raeburn 12935: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12936: if (keys(%toplevelitems) > 0) {
12937: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12938: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12939: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12940: }
1.1066 raeburn 12941: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12942: if ($numitems) {
12943: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12944: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12945: my $path = $env{'form.archive_content_'.$i};
12946: if ($path =~ /^\Q$pathtocheck\E/) {
12947: if ($env{'form.archive_'.$i} eq 'discard') {
12948: if ($prefix ne '' && $path ne '') {
12949: if (-e $prefix.$path) {
1.1066 raeburn 12950: if ((@archdirs > 0) &&
12951: (grep(/^\Q$i\E$/,@archdirs))) {
12952: $todeletedir{$prefix.$path} = 1;
12953: } else {
12954: $todelete{$prefix.$path} = 1;
12955: }
1.1055 raeburn 12956: }
12957: }
12958: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12959: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12960: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12961: $docstitle = $env{'form.archive_title_'.$i};
12962: if ($docstitle eq '') {
12963: $docstitle = $title;
12964: }
1.1055 raeburn 12965: $outer = 0;
1.1056 raeburn 12966: if (ref($dirorder{$i}) eq 'ARRAY') {
12967: if (@{$dirorder{$i}} > 0) {
12968: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12969: if ($env{'form.archive_'.$item} eq 'display') {
12970: $outer = $item;
12971: last;
12972: }
12973: }
12974: }
12975: }
12976: my ($errtext,$fatal) =
12977: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12978: '/'.$folders{$outer}.'.'.
12979: $containers{$outer});
12980: next if ($fatal);
12981: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12982: if ($context eq 'coursedocs') {
1.1056 raeburn 12983: $mapinner{$i} = time;
1.1055 raeburn 12984: $folders{$i} = 'default_'.$mapinner{$i};
12985: $containers{$i} = 'sequence';
12986: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12987: $folders{$i}.'.'.$containers{$i};
12988: my $newidx = &LONCAPA::map::getresidx();
12989: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12990: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12991: push(@LONCAPA::map::order,$newidx);
12992: my ($outtext,$errtext) =
12993: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12994: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12995: '.'.$containers{$outer},1,1);
1.1056 raeburn 12996: $newseqid{$i} = $newidx;
1.1067 raeburn 12997: unless ($errtext) {
1.1075.2.128 raeburn 12998: $result .= '<li>'.&mt('Folder: [_1] added to course',
12999: &HTML::Entities::encode($docstitle,'<>&"'))..
13000: '</li>'."\n";
1.1067 raeburn 13001: }
1.1055 raeburn 13002: }
13003: } else {
13004: if ($context eq 'coursedocs') {
13005: my $newidx=&LONCAPA::map::getresidx();
13006: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13007: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13008: $title;
1.1075.2.128 raeburn 13009: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13010: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13011: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13012: }
1.1075.2.128 raeburn 13013: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13014: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13015: }
13016: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13017: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13018: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13019: unless ($ishome) {
13020: my $fetch = "$newdest{$i}/$title";
13021: $fetch =~ s/^\Q$prefix$dir\E//;
13022: $prompttofetch{$fetch} = 1;
13023: }
13024: }
13025: }
13026: $LONCAPA::map::resources[$newidx]=
13027: $docstitle.':'.$url.':false:normal:res';
13028: push(@LONCAPA::map::order, $newidx);
13029: my ($outtext,$errtext)=
13030: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13031: $docuname.'/'.$folders{$outer}.
13032: '.'.$containers{$outer},1,1);
13033: unless ($errtext) {
13034: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13035: $result .= '<li>'.&mt('File: [_1] added to course',
13036: &HTML::Entities::encode($docstitle,'<>&"')).
13037: '</li>'."\n";
13038: }
1.1067 raeburn 13039: }
1.1075.2.128 raeburn 13040: } else {
13041: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13042: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13043: }
1.1055 raeburn 13044: }
13045: }
1.1075.2.11 raeburn 13046: }
13047: } else {
1.1075.2.128 raeburn 13048: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13049: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13050: }
13051: }
13052: for (my $i=1; $i<=$numitems; $i++) {
13053: next unless ($env{'form.archive_'.$i} eq 'dependency');
13054: my $path = $env{'form.archive_content_'.$i};
13055: if ($path =~ /^\Q$pathtocheck\E/) {
13056: my ($title) = ($path =~ m{/([^/]+)$});
13057: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13058: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13059: if (ref($dirorder{$i}) eq 'ARRAY') {
13060: my ($itemidx,$fullpath,$relpath);
13061: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13062: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13063: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13064: if ($dirorder{$i}->[$j] eq $container) {
13065: $itemidx = $j;
1.1056 raeburn 13066: }
13067: }
1.1075.2.11 raeburn 13068: }
13069: if ($itemidx eq '') {
13070: $itemidx = 0;
13071: }
13072: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13073: if ($mapinner{$referrer{$i}}) {
13074: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13075: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13076: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13077: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13078: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13079: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13080: if (!-e $fullpath) {
13081: mkdir($fullpath,0755);
1.1056 raeburn 13082: }
13083: }
1.1075.2.11 raeburn 13084: } else {
13085: last;
1.1056 raeburn 13086: }
1.1075.2.11 raeburn 13087: }
13088: }
13089: } elsif ($newdest{$referrer{$i}}) {
13090: $fullpath = $newdest{$referrer{$i}};
13091: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13092: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13093: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13094: last;
13095: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13096: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13097: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13098: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13099: if (!-e $fullpath) {
13100: mkdir($fullpath,0755);
1.1056 raeburn 13101: }
13102: }
1.1075.2.11 raeburn 13103: } else {
13104: last;
1.1056 raeburn 13105: }
1.1075.2.11 raeburn 13106: }
13107: }
13108: if ($fullpath ne '') {
13109: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13110: unless (rename("$prefix$path","$fullpath/$title")) {
13111: $warning .= &mt('Failed to rename dependency').'<br />';
13112: }
1.1075.2.11 raeburn 13113: }
13114: if (-e "$fullpath/$title") {
13115: my $showpath;
13116: if ($relpath ne '') {
13117: $showpath = "$relpath/$title";
13118: } else {
13119: $showpath = "/$title";
1.1056 raeburn 13120: }
1.1075.2.128 raeburn 13121: $result .= '<li>'.&mt('[_1] included as a dependency',
13122: &HTML::Entities::encode($showpath,'<>&"')).
13123: '</li>'."\n";
13124: unless ($ishome) {
13125: my $fetch = "$fullpath/$title";
13126: $fetch =~ s/^\Q$prefix$dir\E//;
13127: $prompttofetch{$fetch} = 1;
13128: }
1.1055 raeburn 13129: }
13130: }
13131: }
1.1075.2.11 raeburn 13132: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13133: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13134: &HTML::Entities::encode($path,'<>&"'),
13135: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13136: '<br />';
1.1055 raeburn 13137: }
13138: } else {
1.1075.2.128 raeburn 13139: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13140: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13141: }
13142: }
13143: if (keys(%todelete)) {
13144: foreach my $key (keys(%todelete)) {
13145: unlink($key);
1.1066 raeburn 13146: }
13147: }
13148: if (keys(%todeletedir)) {
13149: foreach my $key (keys(%todeletedir)) {
13150: rmdir($key);
13151: }
13152: }
13153: foreach my $dir (sort(keys(%is_dir))) {
13154: if (($pathtocheck ne '') && ($dir ne '')) {
13155: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13156: }
13157: }
1.1067 raeburn 13158: if ($result ne '') {
13159: $output .= '<ul>'."\n".
13160: $result."\n".
13161: '</ul>';
13162: }
13163: unless ($ishome) {
13164: my $replicationfail;
13165: foreach my $item (keys(%prompttofetch)) {
13166: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13167: unless ($fetchresult eq 'ok') {
13168: $replicationfail .= '<li>'.$item.'</li>'."\n";
13169: }
13170: }
13171: if ($replicationfail) {
13172: $output .= '<p class="LC_error">'.
13173: &mt('Course home server failed to retrieve:').'<ul>'.
13174: $replicationfail.
13175: '</ul></p>';
13176: }
13177: }
1.1055 raeburn 13178: } else {
13179: $warning = &mt('No items found in archive.');
13180: }
13181: if ($error) {
13182: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13183: $error.'</p>'."\n";
13184: }
13185: if ($warning) {
13186: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13187: }
13188: return $output;
13189: }
13190:
1.1066 raeburn 13191: sub cleanup_empty_dirs {
13192: my ($path) = @_;
13193: if (($path ne '') && (-d $path)) {
13194: if (opendir(my $dirh,$path)) {
13195: my @dircontents = grep(!/^\./,readdir($dirh));
13196: my $numitems = 0;
13197: foreach my $item (@dircontents) {
13198: if (-d "$path/$item") {
1.1075.2.28 raeburn 13199: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13200: if (-e "$path/$item") {
13201: $numitems ++;
13202: }
13203: } else {
13204: $numitems ++;
13205: }
13206: }
13207: if ($numitems == 0) {
13208: rmdir($path);
13209: }
13210: closedir($dirh);
13211: }
13212: }
13213: return;
13214: }
13215:
1.41 ng 13216: =pod
1.45 matthew 13217:
1.1075.2.56 raeburn 13218: =item * &get_folder_hierarchy()
1.1068 raeburn 13219:
13220: Provides hierarchy of names of folders/sub-folders containing the current
13221: item,
13222:
13223: Inputs: 3
13224: - $navmap - navmaps object
13225:
13226: - $map - url for map (either the trigger itself, or map containing
13227: the resource, which is the trigger).
13228:
13229: - $showitem - 1 => show title for map itself; 0 => do not show.
13230:
13231: Outputs: 1 @pathitems - array of folder/subfolder names.
13232:
13233: =cut
13234:
13235: sub get_folder_hierarchy {
13236: my ($navmap,$map,$showitem) = @_;
13237: my @pathitems;
13238: if (ref($navmap)) {
13239: my $mapres = $navmap->getResourceByUrl($map);
13240: if (ref($mapres)) {
13241: my $pcslist = $mapres->map_hierarchy();
13242: if ($pcslist ne '') {
13243: my @pcs = split(/,/,$pcslist);
13244: foreach my $pc (@pcs) {
13245: if ($pc == 1) {
1.1075.2.38 raeburn 13246: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13247: } else {
13248: my $res = $navmap->getByMapPc($pc);
13249: if (ref($res)) {
13250: my $title = $res->compTitle();
13251: $title =~ s/\W+/_/g;
13252: if ($title ne '') {
13253: push(@pathitems,$title);
13254: }
13255: }
13256: }
13257: }
13258: }
1.1071 raeburn 13259: if ($showitem) {
13260: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13261: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13262: } else {
13263: my $maptitle = $mapres->compTitle();
13264: $maptitle =~ s/\W+/_/g;
13265: if ($maptitle ne '') {
13266: push(@pathitems,$maptitle);
13267: }
1.1068 raeburn 13268: }
13269: }
13270: }
13271: }
13272: return @pathitems;
13273: }
13274:
13275: =pod
13276:
1.1015 raeburn 13277: =item * &get_turnedin_filepath()
13278:
13279: Determines path in a user's portfolio file for storage of files uploaded
13280: to a specific essayresponse or dropbox item.
13281:
13282: Inputs: 3 required + 1 optional.
13283: $symb is symb for resource, $uname and $udom are for current user (required).
13284: $caller is optional (can be "submission", if routine is called when storing
13285: an upoaded file when "Submit Answer" button was pressed).
13286:
13287: Returns array containing $path and $multiresp.
13288: $path is path in portfolio. $multiresp is 1 if this resource contains more
13289: than one file upload item. Callers of routine should append partid as a
13290: subdirectory to $path in cases where $multiresp is 1.
13291:
13292: Called by: homework/essayresponse.pm and homework/structuretags.pm
13293:
13294: =cut
13295:
13296: sub get_turnedin_filepath {
13297: my ($symb,$uname,$udom,$caller) = @_;
13298: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13299: my $turnindir;
13300: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13301: $turnindir = $userhash{'turnindir'};
13302: my ($path,$multiresp);
13303: if ($turnindir eq '') {
13304: if ($caller eq 'submission') {
13305: $turnindir = &mt('turned in');
13306: $turnindir =~ s/\W+/_/g;
13307: my %newhash = (
13308: 'turnindir' => $turnindir,
13309: );
13310: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13311: }
13312: }
13313: if ($turnindir ne '') {
13314: $path = '/'.$turnindir.'/';
13315: my ($multipart,$turnin,@pathitems);
13316: my $navmap = Apache::lonnavmaps::navmap->new();
13317: if (defined($navmap)) {
13318: my $mapres = $navmap->getResourceByUrl($map);
13319: if (ref($mapres)) {
13320: my $pcslist = $mapres->map_hierarchy();
13321: if ($pcslist ne '') {
13322: foreach my $pc (split(/,/,$pcslist)) {
13323: my $res = $navmap->getByMapPc($pc);
13324: if (ref($res)) {
13325: my $title = $res->compTitle();
13326: $title =~ s/\W+/_/g;
13327: if ($title ne '') {
1.1075.2.48 raeburn 13328: if (($pc > 1) && (length($title) > 12)) {
13329: $title = substr($title,0,12);
13330: }
1.1015 raeburn 13331: push(@pathitems,$title);
13332: }
13333: }
13334: }
13335: }
13336: my $maptitle = $mapres->compTitle();
13337: $maptitle =~ s/\W+/_/g;
13338: if ($maptitle ne '') {
1.1075.2.48 raeburn 13339: if (length($maptitle) > 12) {
13340: $maptitle = substr($maptitle,0,12);
13341: }
1.1015 raeburn 13342: push(@pathitems,$maptitle);
13343: }
13344: unless ($env{'request.state'} eq 'construct') {
13345: my $res = $navmap->getBySymb($symb);
13346: if (ref($res)) {
13347: my $partlist = $res->parts();
13348: my $totaluploads = 0;
13349: if (ref($partlist) eq 'ARRAY') {
13350: foreach my $part (@{$partlist}) {
13351: my @types = $res->responseType($part);
13352: my @ids = $res->responseIds($part);
13353: for (my $i=0; $i < scalar(@ids); $i++) {
13354: if ($types[$i] eq 'essay') {
13355: my $partid = $part.'_'.$ids[$i];
13356: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13357: $totaluploads ++;
13358: }
13359: }
13360: }
13361: }
13362: if ($totaluploads > 1) {
13363: $multiresp = 1;
13364: }
13365: }
13366: }
13367: }
13368: } else {
13369: return;
13370: }
13371: } else {
13372: return;
13373: }
13374: my $restitle=&Apache::lonnet::gettitle($symb);
13375: $restitle =~ s/\W+/_/g;
13376: if ($restitle eq '') {
13377: $restitle = ($resurl =~ m{/[^/]+$});
13378: if ($restitle eq '') {
13379: $restitle = time;
13380: }
13381: }
1.1075.2.48 raeburn 13382: if (length($restitle) > 12) {
13383: $restitle = substr($restitle,0,12);
13384: }
1.1015 raeburn 13385: push(@pathitems,$restitle);
13386: $path .= join('/',@pathitems);
13387: }
13388: return ($path,$multiresp);
13389: }
13390:
13391: =pod
13392:
1.464 albertel 13393: =back
1.41 ng 13394:
1.112 bowersj2 13395: =head1 CSV Upload/Handling functions
1.38 albertel 13396:
1.41 ng 13397: =over 4
13398:
1.648 raeburn 13399: =item * &upfile_store($r)
1.41 ng 13400:
13401: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13402: needs $env{'form.upfile'}
1.41 ng 13403: returns $datatoken to be put into hidden field
13404:
13405: =cut
1.31 albertel 13406:
13407: sub upfile_store {
13408: my $r=shift;
1.258 albertel 13409: $env{'form.upfile'}=~s/\r/\n/gs;
13410: $env{'form.upfile'}=~s/\f/\n/gs;
13411: $env{'form.upfile'}=~s/\n+/\n/gs;
13412: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13413:
1.1075.2.128 raeburn 13414: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13415: '_enroll_'.$env{'request.course.id'}.'_'.
13416: time.'_'.$$);
13417: return if ($datatoken eq '');
13418:
1.31 albertel 13419: {
1.158 raeburn 13420: my $datafile = $r->dir_config('lonDaemons').
13421: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13422: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13423: print $fh $env{'form.upfile'};
1.158 raeburn 13424: close($fh);
13425: }
1.31 albertel 13426: }
13427: return $datatoken;
13428: }
13429:
1.56 matthew 13430: =pod
13431:
1.1075.2.128 raeburn 13432: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13433:
13434: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13435: $datatoken is the name to assign to the temporary file.
1.258 albertel 13436: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13437:
13438: =cut
1.31 albertel 13439:
13440: sub load_tmp_file {
1.1075.2.128 raeburn 13441: my ($r,$datatoken) = @_;
13442: return if ($datatoken eq '');
1.31 albertel 13443: my @studentdata=();
13444: {
1.158 raeburn 13445: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13446: '/tmp/'.$datatoken.'.tmp';
13447: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13448: @studentdata=<$fh>;
13449: close($fh);
13450: }
1.31 albertel 13451: }
1.258 albertel 13452: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13453: }
13454:
1.1075.2.128 raeburn 13455: sub valid_datatoken {
13456: my ($datatoken) = @_;
1.1075.2.131 raeburn 13457: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13458: return $datatoken;
13459: }
13460: return;
13461: }
13462:
1.56 matthew 13463: =pod
13464:
1.648 raeburn 13465: =item * &upfile_record_sep()
1.41 ng 13466:
13467: Separate uploaded file into records
13468: returns array of records,
1.258 albertel 13469: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13470:
13471: =cut
1.31 albertel 13472:
13473: sub upfile_record_sep {
1.258 albertel 13474: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13475: } else {
1.248 albertel 13476: my @records;
1.258 albertel 13477: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13478: if ($line=~/^\s*$/) { next; }
13479: push(@records,$line);
13480: }
13481: return @records;
1.31 albertel 13482: }
13483: }
13484:
1.56 matthew 13485: =pod
13486:
1.648 raeburn 13487: =item * &record_sep($record)
1.41 ng 13488:
1.258 albertel 13489: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13490:
13491: =cut
13492:
1.263 www 13493: sub takeleft {
13494: my $index=shift;
13495: return substr('0000'.$index,-4,4);
13496: }
13497:
1.31 albertel 13498: sub record_sep {
13499: my $record=shift;
13500: my %components=();
1.258 albertel 13501: if ($env{'form.upfiletype'} eq 'xml') {
13502: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13503: my $i=0;
1.356 albertel 13504: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13505: $field=~s/^(\"|\')//;
13506: $field=~s/(\"|\')$//;
1.263 www 13507: $components{&takeleft($i)}=$field;
1.31 albertel 13508: $i++;
13509: }
1.258 albertel 13510: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13511: my $i=0;
1.356 albertel 13512: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13513: $field=~s/^(\"|\')//;
13514: $field=~s/(\"|\')$//;
1.263 www 13515: $components{&takeleft($i)}=$field;
1.31 albertel 13516: $i++;
13517: }
13518: } else {
1.561 www 13519: my $separator=',';
1.480 banghart 13520: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13521: $separator=';';
1.480 banghart 13522: }
1.31 albertel 13523: my $i=0;
1.561 www 13524: # the character we are looking for to indicate the end of a quote or a record
13525: my $looking_for=$separator;
13526: # do not add the characters to the fields
13527: my $ignore=0;
13528: # we just encountered a separator (or the beginning of the record)
13529: my $just_found_separator=1;
13530: # store the field we are working on here
13531: my $field='';
13532: # work our way through all characters in record
13533: foreach my $character ($record=~/(.)/g) {
13534: if ($character eq $looking_for) {
13535: if ($character ne $separator) {
13536: # Found the end of a quote, again looking for separator
13537: $looking_for=$separator;
13538: $ignore=1;
13539: } else {
13540: # Found a separator, store away what we got
13541: $components{&takeleft($i)}=$field;
13542: $i++;
13543: $just_found_separator=1;
13544: $ignore=0;
13545: $field='';
13546: }
13547: next;
13548: }
13549: # single or double quotation marks after a separator indicate beginning of a quote
13550: # we are now looking for the end of the quote and need to ignore separators
13551: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13552: $looking_for=$character;
13553: next;
13554: }
13555: # ignore would be true after we reached the end of a quote
13556: if ($ignore) { next; }
13557: if (($just_found_separator) && ($character=~/\s/)) { next; }
13558: $field.=$character;
13559: $just_found_separator=0;
1.31 albertel 13560: }
1.561 www 13561: # catch the very last entry, since we never encountered the separator
13562: $components{&takeleft($i)}=$field;
1.31 albertel 13563: }
13564: return %components;
13565: }
13566:
1.144 matthew 13567: ######################################################
13568: ######################################################
13569:
1.56 matthew 13570: =pod
13571:
1.648 raeburn 13572: =item * &upfile_select_html()
1.41 ng 13573:
1.144 matthew 13574: Return HTML code to select a file from the users machine and specify
13575: the file type.
1.41 ng 13576:
13577: =cut
13578:
1.144 matthew 13579: ######################################################
13580: ######################################################
1.31 albertel 13581: sub upfile_select_html {
1.144 matthew 13582: my %Types = (
13583: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13584: semisv => &mt('Semicolon separated values'),
1.144 matthew 13585: space => &mt('Space separated'),
13586: tab => &mt('Tabulator separated'),
13587: # xml => &mt('HTML/XML'),
13588: );
13589: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13590: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13591: foreach my $type (sort(keys(%Types))) {
13592: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13593: }
13594: $Str .= "</select>\n";
13595: return $Str;
1.31 albertel 13596: }
13597:
1.301 albertel 13598: sub get_samples {
13599: my ($records,$toget) = @_;
13600: my @samples=({});
13601: my $got=0;
13602: foreach my $rec (@$records) {
13603: my %temp = &record_sep($rec);
13604: if (! grep(/\S/, values(%temp))) { next; }
13605: if (%temp) {
13606: $samples[$got]=\%temp;
13607: $got++;
13608: if ($got == $toget) { last; }
13609: }
13610: }
13611: return \@samples;
13612: }
13613:
1.144 matthew 13614: ######################################################
13615: ######################################################
13616:
1.56 matthew 13617: =pod
13618:
1.648 raeburn 13619: =item * &csv_print_samples($r,$records)
1.41 ng 13620:
13621: Prints a table of sample values from each column uploaded $r is an
13622: Apache Request ref, $records is an arrayref from
13623: &Apache::loncommon::upfile_record_sep
13624:
13625: =cut
13626:
1.144 matthew 13627: ######################################################
13628: ######################################################
1.31 albertel 13629: sub csv_print_samples {
13630: my ($r,$records) = @_;
1.662 bisitz 13631: my $samples = &get_samples($records,5);
1.301 albertel 13632:
1.594 raeburn 13633: $r->print(&mt('Samples').'<br />'.&start_data_table().
13634: &start_data_table_header_row());
1.356 albertel 13635: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13636: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13637: $r->print(&end_data_table_header_row());
1.301 albertel 13638: foreach my $hash (@$samples) {
1.594 raeburn 13639: $r->print(&start_data_table_row());
1.356 albertel 13640: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13641: $r->print('<td>');
1.356 albertel 13642: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13643: $r->print('</td>');
13644: }
1.594 raeburn 13645: $r->print(&end_data_table_row());
1.31 albertel 13646: }
1.594 raeburn 13647: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13648: }
13649:
1.144 matthew 13650: ######################################################
13651: ######################################################
13652:
1.56 matthew 13653: =pod
13654:
1.648 raeburn 13655: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13656:
13657: Prints a table to create associations between values and table columns.
1.144 matthew 13658:
1.41 ng 13659: $r is an Apache Request ref,
13660: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13661: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13662:
13663: =cut
13664:
1.144 matthew 13665: ######################################################
13666: ######################################################
1.31 albertel 13667: sub csv_print_select_table {
13668: my ($r,$records,$d) = @_;
1.301 albertel 13669: my $i=0;
13670: my $samples = &get_samples($records,1);
1.144 matthew 13671: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13672: &start_data_table().&start_data_table_header_row().
1.144 matthew 13673: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13674: '<th>'.&mt('Column').'</th>'.
13675: &end_data_table_header_row()."\n");
1.356 albertel 13676: foreach my $array_ref (@$d) {
13677: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13678: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13679:
1.875 bisitz 13680: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13681: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13682: $r->print('<option value="none"></option>');
1.356 albertel 13683: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13684: $r->print('<option value="'.$sample.'"'.
13685: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13686: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13687: }
1.594 raeburn 13688: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13689: $i++;
13690: }
1.594 raeburn 13691: $r->print(&end_data_table());
1.31 albertel 13692: $i--;
13693: return $i;
13694: }
1.56 matthew 13695:
1.144 matthew 13696: ######################################################
13697: ######################################################
13698:
1.56 matthew 13699: =pod
1.31 albertel 13700:
1.648 raeburn 13701: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13702:
13703: Prints a table of sample values from the upload and can make associate samples to internal names.
13704:
13705: $r is an Apache Request ref,
13706: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13707: $d is an array of 2 element arrays (internal name, displayed name)
13708:
13709: =cut
13710:
1.144 matthew 13711: ######################################################
13712: ######################################################
1.31 albertel 13713: sub csv_samples_select_table {
13714: my ($r,$records,$d) = @_;
13715: my $i=0;
1.144 matthew 13716: #
1.662 bisitz 13717: my $max_samples = 5;
13718: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13719: $r->print(&start_data_table().
13720: &start_data_table_header_row().'<th>'.
13721: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13722: &end_data_table_header_row());
1.301 albertel 13723:
13724: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13725: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13726: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13727: foreach my $option (@$d) {
13728: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13729: $r->print('<option value="'.$value.'"'.
1.253 albertel 13730: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13731: $display.'</option>');
1.31 albertel 13732: }
13733: $r->print('</select></td><td>');
1.662 bisitz 13734: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13735: if (defined($samples->[$line]{$key})) {
13736: $r->print($samples->[$line]{$key}."<br />\n");
13737: }
13738: }
1.594 raeburn 13739: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13740: $i++;
13741: }
1.594 raeburn 13742: $r->print(&end_data_table());
1.31 albertel 13743: $i--;
13744: return($i);
1.115 matthew 13745: }
13746:
1.144 matthew 13747: ######################################################
13748: ######################################################
13749:
1.115 matthew 13750: =pod
13751:
1.648 raeburn 13752: =item * &clean_excel_name($name)
1.115 matthew 13753:
13754: Returns a replacement for $name which does not contain any illegal characters.
13755:
13756: =cut
13757:
1.144 matthew 13758: ######################################################
13759: ######################################################
1.115 matthew 13760: sub clean_excel_name {
13761: my ($name) = @_;
13762: $name =~ s/[:\*\?\/\\]//g;
13763: if (length($name) > 31) {
13764: $name = substr($name,0,31);
13765: }
13766: return $name;
1.25 albertel 13767: }
1.84 albertel 13768:
1.85 albertel 13769: =pod
13770:
1.648 raeburn 13771: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13772:
13773: Returns either 1 or undef
13774:
13775: 1 if the part is to be hidden, undef if it is to be shown
13776:
13777: Arguments are:
13778:
13779: $id the id of the part to be checked
13780: $symb, optional the symb of the resource to check
13781: $udom, optional the domain of the user to check for
13782: $uname, optional the username of the user to check for
13783:
13784: =cut
1.84 albertel 13785:
13786: sub check_if_partid_hidden {
13787: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13788: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13789: $symb,$udom,$uname);
1.141 albertel 13790: my $truth=1;
13791: #if the string starts with !, then the list is the list to show not hide
13792: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13793: my @hiddenlist=split(/,/,$hiddenparts);
13794: foreach my $checkid (@hiddenlist) {
1.141 albertel 13795: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13796: }
1.141 albertel 13797: return !$truth;
1.84 albertel 13798: }
1.127 matthew 13799:
1.138 matthew 13800:
13801: ############################################################
13802: ############################################################
13803:
13804: =pod
13805:
1.157 matthew 13806: =back
13807:
1.138 matthew 13808: =head1 cgi-bin script and graphing routines
13809:
1.157 matthew 13810: =over 4
13811:
1.648 raeburn 13812: =item * &get_cgi_id()
1.138 matthew 13813:
13814: Inputs: none
13815:
13816: Returns an id which can be used to pass environment variables
13817: to various cgi-bin scripts. These environment variables will
13818: be removed from the users environment after a given time by
13819: the routine &Apache::lonnet::transfer_profile_to_env.
13820:
13821: =cut
13822:
13823: ############################################################
13824: ############################################################
1.152 albertel 13825: my $uniq=0;
1.136 matthew 13826: sub get_cgi_id {
1.154 albertel 13827: $uniq=($uniq+1)%100000;
1.280 albertel 13828: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13829: }
13830:
1.127 matthew 13831: ############################################################
13832: ############################################################
13833:
13834: =pod
13835:
1.648 raeburn 13836: =item * &DrawBarGraph()
1.127 matthew 13837:
1.138 matthew 13838: Facilitates the plotting of data in a (stacked) bar graph.
13839: Puts plot definition data into the users environment in order for
13840: graph.png to plot it. Returns an <img> tag for the plot.
13841: The bars on the plot are labeled '1','2',...,'n'.
13842:
13843: Inputs:
13844:
13845: =over 4
13846:
13847: =item $Title: string, the title of the plot
13848:
13849: =item $xlabel: string, text describing the X-axis of the plot
13850:
13851: =item $ylabel: string, text describing the Y-axis of the plot
13852:
13853: =item $Max: scalar, the maximum Y value to use in the plot
13854: If $Max is < any data point, the graph will not be rendered.
13855:
1.140 matthew 13856: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13857: they are plotted. If undefined, default values will be used.
13858:
1.178 matthew 13859: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13860:
1.138 matthew 13861: =item @Values: An array of array references. Each array reference holds data
13862: to be plotted in a stacked bar chart.
13863:
1.239 matthew 13864: =item If the final element of @Values is a hash reference the key/value
13865: pairs will be added to the graph definition.
13866:
1.138 matthew 13867: =back
13868:
13869: Returns:
13870:
13871: An <img> tag which references graph.png and the appropriate identifying
13872: information for the plot.
13873:
1.127 matthew 13874: =cut
13875:
13876: ############################################################
13877: ############################################################
1.134 matthew 13878: sub DrawBarGraph {
1.178 matthew 13879: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13880: #
13881: if (! defined($colors)) {
13882: $colors = ['#33ff00',
13883: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13884: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13885: ];
13886: }
1.228 matthew 13887: my $extra_settings = {};
13888: if (ref($Values[-1]) eq 'HASH') {
13889: $extra_settings = pop(@Values);
13890: }
1.127 matthew 13891: #
1.136 matthew 13892: my $identifier = &get_cgi_id();
13893: my $id = 'cgi.'.$identifier;
1.129 matthew 13894: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13895: return '';
13896: }
1.225 matthew 13897: #
13898: my @Labels;
13899: if (defined($labels)) {
13900: @Labels = @$labels;
13901: } else {
13902: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13903: push(@Labels,$i+1);
1.225 matthew 13904: }
13905: }
13906: #
1.129 matthew 13907: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13908: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13909: my %ValuesHash;
13910: my $NumSets=1;
13911: foreach my $array (@Values) {
13912: next if (! ref($array));
1.136 matthew 13913: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13914: join(',',@$array);
1.129 matthew 13915: }
1.127 matthew 13916: #
1.136 matthew 13917: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13918: if ($NumBars < 3) {
13919: $width = 120+$NumBars*32;
1.220 matthew 13920: $xskip = 1;
1.225 matthew 13921: $bar_width = 30;
13922: } elsif ($NumBars < 5) {
13923: $width = 120+$NumBars*20;
13924: $xskip = 1;
13925: $bar_width = 20;
1.220 matthew 13926: } elsif ($NumBars < 10) {
1.136 matthew 13927: $width = 120+$NumBars*15;
13928: $xskip = 1;
13929: $bar_width = 15;
13930: } elsif ($NumBars <= 25) {
13931: $width = 120+$NumBars*11;
13932: $xskip = 5;
13933: $bar_width = 8;
13934: } elsif ($NumBars <= 50) {
13935: $width = 120+$NumBars*8;
13936: $xskip = 5;
13937: $bar_width = 4;
13938: } else {
13939: $width = 120+$NumBars*8;
13940: $xskip = 5;
13941: $bar_width = 4;
13942: }
13943: #
1.137 matthew 13944: $Max = 1 if ($Max < 1);
13945: if ( int($Max) < $Max ) {
13946: $Max++;
13947: $Max = int($Max);
13948: }
1.127 matthew 13949: $Title = '' if (! defined($Title));
13950: $xlabel = '' if (! defined($xlabel));
13951: $ylabel = '' if (! defined($ylabel));
1.369 www 13952: $ValuesHash{$id.'.title'} = &escape($Title);
13953: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13954: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13955: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13956: $ValuesHash{$id.'.NumBars'} = $NumBars;
13957: $ValuesHash{$id.'.NumSets'} = $NumSets;
13958: $ValuesHash{$id.'.PlotType'} = 'bar';
13959: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13960: $ValuesHash{$id.'.height'} = $height;
13961: $ValuesHash{$id.'.width'} = $width;
13962: $ValuesHash{$id.'.xskip'} = $xskip;
13963: $ValuesHash{$id.'.bar_width'} = $bar_width;
13964: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13965: #
1.228 matthew 13966: # Deal with other parameters
13967: while (my ($key,$value) = each(%$extra_settings)) {
13968: $ValuesHash{$id.'.'.$key} = $value;
13969: }
13970: #
1.646 raeburn 13971: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13972: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13973: }
13974:
13975: ############################################################
13976: ############################################################
13977:
13978: =pod
13979:
1.648 raeburn 13980: =item * &DrawXYGraph()
1.137 matthew 13981:
1.138 matthew 13982: Facilitates the plotting of data in an XY graph.
13983: Puts plot definition data into the users environment in order for
13984: graph.png to plot it. Returns an <img> tag for the plot.
13985:
13986: Inputs:
13987:
13988: =over 4
13989:
13990: =item $Title: string, the title of the plot
13991:
13992: =item $xlabel: string, text describing the X-axis of the plot
13993:
13994: =item $ylabel: string, text describing the Y-axis of the plot
13995:
13996: =item $Max: scalar, the maximum Y value to use in the plot
13997: If $Max is < any data point, the graph will not be rendered.
13998:
13999: =item $colors: Array ref containing the hex color codes for the data to be
14000: plotted in. If undefined, default values will be used.
14001:
14002: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14003:
14004: =item $Ydata: Array ref containing Array refs.
1.185 www 14005: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14006:
14007: =item %Values: hash indicating or overriding any default values which are
14008: passed to graph.png.
14009: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14010:
14011: =back
14012:
14013: Returns:
14014:
14015: An <img> tag which references graph.png and the appropriate identifying
14016: information for the plot.
14017:
1.137 matthew 14018: =cut
14019:
14020: ############################################################
14021: ############################################################
14022: sub DrawXYGraph {
14023: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14024: #
14025: # Create the identifier for the graph
14026: my $identifier = &get_cgi_id();
14027: my $id = 'cgi.'.$identifier;
14028: #
14029: $Title = '' if (! defined($Title));
14030: $xlabel = '' if (! defined($xlabel));
14031: $ylabel = '' if (! defined($ylabel));
14032: my %ValuesHash =
14033: (
1.369 www 14034: $id.'.title' => &escape($Title),
14035: $id.'.xlabel' => &escape($xlabel),
14036: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14037: $id.'.y_max_value'=> $Max,
14038: $id.'.labels' => join(',',@$Xlabels),
14039: $id.'.PlotType' => 'XY',
14040: );
14041: #
14042: if (defined($colors) && ref($colors) eq 'ARRAY') {
14043: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14044: }
14045: #
14046: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14047: return '';
14048: }
14049: my $NumSets=1;
1.138 matthew 14050: foreach my $array (@{$Ydata}){
1.137 matthew 14051: next if (! ref($array));
14052: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14053: }
1.138 matthew 14054: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14055: #
14056: # Deal with other parameters
14057: while (my ($key,$value) = each(%Values)) {
14058: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14059: }
14060: #
1.646 raeburn 14061: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14062: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14063: }
14064:
14065: ############################################################
14066: ############################################################
14067:
14068: =pod
14069:
1.648 raeburn 14070: =item * &DrawXYYGraph()
1.138 matthew 14071:
14072: Facilitates the plotting of data in an XY graph with two Y axes.
14073: Puts plot definition data into the users environment in order for
14074: graph.png to plot it. Returns an <img> tag for the plot.
14075:
14076: Inputs:
14077:
14078: =over 4
14079:
14080: =item $Title: string, the title of the plot
14081:
14082: =item $xlabel: string, text describing the X-axis of the plot
14083:
14084: =item $ylabel: string, text describing the Y-axis of the plot
14085:
14086: =item $colors: Array ref containing the hex color codes for the data to be
14087: plotted in. If undefined, default values will be used.
14088:
14089: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14090:
14091: =item $Ydata1: The first data set
14092:
14093: =item $Min1: The minimum value of the left Y-axis
14094:
14095: =item $Max1: The maximum value of the left Y-axis
14096:
14097: =item $Ydata2: The second data set
14098:
14099: =item $Min2: The minimum value of the right Y-axis
14100:
14101: =item $Max2: The maximum value of the left Y-axis
14102:
14103: =item %Values: hash indicating or overriding any default values which are
14104: passed to graph.png.
14105: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14106:
14107: =back
14108:
14109: Returns:
14110:
14111: An <img> tag which references graph.png and the appropriate identifying
14112: information for the plot.
1.136 matthew 14113:
14114: =cut
14115:
14116: ############################################################
14117: ############################################################
1.137 matthew 14118: sub DrawXYYGraph {
14119: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14120: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14121: #
14122: # Create the identifier for the graph
14123: my $identifier = &get_cgi_id();
14124: my $id = 'cgi.'.$identifier;
14125: #
14126: $Title = '' if (! defined($Title));
14127: $xlabel = '' if (! defined($xlabel));
14128: $ylabel = '' if (! defined($ylabel));
14129: my %ValuesHash =
14130: (
1.369 www 14131: $id.'.title' => &escape($Title),
14132: $id.'.xlabel' => &escape($xlabel),
14133: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14134: $id.'.labels' => join(',',@$Xlabels),
14135: $id.'.PlotType' => 'XY',
14136: $id.'.NumSets' => 2,
1.137 matthew 14137: $id.'.two_axes' => 1,
14138: $id.'.y1_max_value' => $Max1,
14139: $id.'.y1_min_value' => $Min1,
14140: $id.'.y2_max_value' => $Max2,
14141: $id.'.y2_min_value' => $Min2,
1.136 matthew 14142: );
14143: #
1.137 matthew 14144: if (defined($colors) && ref($colors) eq 'ARRAY') {
14145: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14146: }
14147: #
14148: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14149: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14150: return '';
14151: }
14152: my $NumSets=1;
1.137 matthew 14153: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14154: next if (! ref($array));
14155: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14156: }
14157: #
14158: # Deal with other parameters
14159: while (my ($key,$value) = each(%Values)) {
14160: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14161: }
14162: #
1.646 raeburn 14163: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14164: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14165: }
14166:
14167: ############################################################
14168: ############################################################
14169:
14170: =pod
14171:
1.157 matthew 14172: =back
14173:
1.139 matthew 14174: =head1 Statistics helper routines?
14175:
14176: Bad place for them but what the hell.
14177:
1.157 matthew 14178: =over 4
14179:
1.648 raeburn 14180: =item * &chartlink()
1.139 matthew 14181:
14182: Returns a link to the chart for a specific student.
14183:
14184: Inputs:
14185:
14186: =over 4
14187:
14188: =item $linktext: The text of the link
14189:
14190: =item $sname: The students username
14191:
14192: =item $sdomain: The students domain
14193:
14194: =back
14195:
1.157 matthew 14196: =back
14197:
1.139 matthew 14198: =cut
14199:
14200: ############################################################
14201: ############################################################
14202: sub chartlink {
14203: my ($linktext, $sname, $sdomain) = @_;
14204: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14205: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14206: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14207: '">'.$linktext.'</a>';
1.153 matthew 14208: }
14209:
14210: #######################################################
14211: #######################################################
14212:
14213: =pod
14214:
14215: =head1 Course Environment Routines
1.157 matthew 14216:
14217: =over 4
1.153 matthew 14218:
1.648 raeburn 14219: =item * &restore_course_settings()
1.153 matthew 14220:
1.648 raeburn 14221: =item * &store_course_settings()
1.153 matthew 14222:
14223: Restores/Store indicated form parameters from the course environment.
14224: Will not overwrite existing values of the form parameters.
14225:
14226: Inputs:
14227: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14228:
14229: a hash ref describing the data to be stored. For example:
14230:
14231: %Save_Parameters = ('Status' => 'scalar',
14232: 'chartoutputmode' => 'scalar',
14233: 'chartoutputdata' => 'scalar',
14234: 'Section' => 'array',
1.373 raeburn 14235: 'Group' => 'array',
1.153 matthew 14236: 'StudentData' => 'array',
14237: 'Maps' => 'array');
14238:
14239: Returns: both routines return nothing
14240:
1.631 raeburn 14241: =back
14242:
1.153 matthew 14243: =cut
14244:
14245: #######################################################
14246: #######################################################
14247: sub store_course_settings {
1.496 albertel 14248: return &store_settings($env{'request.course.id'},@_);
14249: }
14250:
14251: sub store_settings {
1.153 matthew 14252: # save to the environment
14253: # appenv the same items, just to be safe
1.300 albertel 14254: my $udom = $env{'user.domain'};
14255: my $uname = $env{'user.name'};
1.496 albertel 14256: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14257: my %SaveHash;
14258: my %AppHash;
14259: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14260: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14261: my $envname = 'environment.'.$basename;
1.258 albertel 14262: if (exists($env{'form.'.$setting})) {
1.153 matthew 14263: # Save this value away
14264: if ($type eq 'scalar' &&
1.258 albertel 14265: (! exists($env{$envname}) ||
14266: $env{$envname} ne $env{'form.'.$setting})) {
14267: $SaveHash{$basename} = $env{'form.'.$setting};
14268: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14269: } elsif ($type eq 'array') {
14270: my $stored_form;
1.258 albertel 14271: if (ref($env{'form.'.$setting})) {
1.153 matthew 14272: $stored_form = join(',',
14273: map {
1.369 www 14274: &escape($_);
1.258 albertel 14275: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14276: } else {
14277: $stored_form =
1.369 www 14278: &escape($env{'form.'.$setting});
1.153 matthew 14279: }
14280: # Determine if the array contents are the same.
1.258 albertel 14281: if ($stored_form ne $env{$envname}) {
1.153 matthew 14282: $SaveHash{$basename} = $stored_form;
14283: $AppHash{$envname} = $stored_form;
14284: }
14285: }
14286: }
14287: }
14288: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14289: $udom,$uname);
1.153 matthew 14290: if ($put_result !~ /^(ok|delayed)/) {
14291: &Apache::lonnet::logthis('unable to save form parameters, '.
14292: 'got error:'.$put_result);
14293: }
14294: # Make sure these settings stick around in this session, too
1.646 raeburn 14295: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14296: return;
14297: }
14298:
14299: sub restore_course_settings {
1.499 albertel 14300: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14301: }
14302:
14303: sub restore_settings {
14304: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14305: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14306: next if (exists($env{'form.'.$setting}));
1.496 albertel 14307: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14308: '.'.$setting;
1.258 albertel 14309: if (exists($env{$envname})) {
1.153 matthew 14310: if ($type eq 'scalar') {
1.258 albertel 14311: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14312: } elsif ($type eq 'array') {
1.258 albertel 14313: $env{'form.'.$setting} = [
1.153 matthew 14314: map {
1.369 www 14315: &unescape($_);
1.258 albertel 14316: } split(',',$env{$envname})
1.153 matthew 14317: ];
14318: }
14319: }
14320: }
1.127 matthew 14321: }
14322:
1.618 raeburn 14323: #######################################################
14324: #######################################################
14325:
14326: =pod
14327:
14328: =head1 Domain E-mail Routines
14329:
14330: =over 4
14331:
1.648 raeburn 14332: =item * &build_recipient_list()
1.618 raeburn 14333:
1.1075.2.44 raeburn 14334: Build recipient lists for following types of e-mail:
1.766 raeburn 14335: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14336: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14337: module change checking, student/employee ID conflict checks, as
14338: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14339: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14340:
14341: Inputs:
1.1075.2.44 raeburn 14342: defmail (scalar - email address of default recipient),
14343: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14344: requestsmail, updatesmail, or idconflictsmail).
14345:
1.619 raeburn 14346: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14347:
14348: origmail (scalar - email address of recipient from loncapa.conf,
14349: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14350:
1.1075.2.139 raeburn 14351: $requname username of requester (if mailing type is helpdeskmail)
14352:
14353: $requdom domain of requester (if mailing type is helpdeskmail)
14354:
14355: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14356:
1.655 raeburn 14357: Returns: comma separated list of addresses to which to send e-mail.
14358:
14359: =back
1.618 raeburn 14360:
14361: =cut
14362:
14363: ############################################################
14364: ############################################################
14365: sub build_recipient_list {
1.1075.2.139 raeburn 14366: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14367: my @recipients;
1.1075.2.122 raeburn 14368: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14369: my %domconfig =
1.1075.2.122 raeburn 14370: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14371: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14372: if (exists($domconfig{'contacts'}{$mailing})) {
14373: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14374: my @contacts = ('adminemail','supportemail');
14375: foreach my $item (@contacts) {
14376: if ($domconfig{'contacts'}{$mailing}{$item}) {
14377: my $addr = $domconfig{'contacts'}{$item};
14378: if (!grep(/^\Q$addr\E$/,@recipients)) {
14379: push(@recipients,$addr);
14380: }
1.619 raeburn 14381: }
1.1075.2.122 raeburn 14382: }
14383: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14384: if ($mailing eq 'helpdeskmail') {
14385: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14386: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14387: my @ok_bccs;
14388: foreach my $bcc (@bccs) {
14389: $bcc =~ s/^\s+//g;
14390: $bcc =~ s/\s+$//g;
14391: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14392: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14393: push(@ok_bccs,$bcc);
14394: }
14395: }
14396: }
14397: if (@ok_bccs > 0) {
14398: $allbcc = join(', ',@ok_bccs);
14399: }
14400: }
14401: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14402: }
14403: }
1.766 raeburn 14404: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14405: $lastresort = $origmail;
1.618 raeburn 14406: }
1.1075.2.139 raeburn 14407: if ($mailing eq 'helpdeskmail') {
14408: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14409: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14410: my ($inststatus,$inststatus_checked);
14411: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14412: ($env{'user.domain'} ne 'public')) {
14413: $inststatus_checked = 1;
14414: $inststatus = $env{'environment.inststatus'};
14415: }
14416: unless ($inststatus_checked) {
14417: if (($requname ne '') && ($requdom ne '')) {
14418: if (($requname =~ /^$match_username$/) &&
14419: ($requdom =~ /^$match_domain$/) &&
14420: (&Apache::lonnet::domain($requdom))) {
14421: my $requhome = &Apache::lonnet::homeserver($requname,
14422: $requdom);
14423: unless ($requhome eq 'no_host') {
14424: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14425: $inststatus = $userenv{'inststatus'};
14426: $inststatus_checked = 1;
14427: }
14428: }
14429: }
14430: }
14431: unless ($inststatus_checked) {
14432: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14433: my %srch = (srchby => 'email',
14434: srchdomain => $defdom,
14435: srchterm => $reqemail,
14436: srchtype => 'exact');
14437: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14438: foreach my $uname (keys(%srch_results)) {
14439: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14440: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14441: $inststatus_checked = 1;
14442: last;
14443: }
14444: }
14445: unless ($inststatus_checked) {
14446: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14447: if ($dirsrchres eq 'ok') {
14448: foreach my $uname (keys(%srch_results)) {
14449: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14450: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14451: $inststatus_checked = 1;
14452: last;
14453: }
14454: }
14455: }
14456: }
14457: }
14458: }
14459: if ($inststatus ne '') {
14460: foreach my $status (split(/\:/,$inststatus)) {
14461: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14462: my @contacts = ('adminemail','supportemail');
14463: foreach my $item (@contacts) {
14464: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14465: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14466: if (!grep(/^\Q$addr\E$/,@recipients)) {
14467: push(@recipients,$addr);
14468: }
14469: }
14470: }
14471: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14472: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14473: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14474: my @ok_bccs;
14475: foreach my $bcc (@bccs) {
14476: $bcc =~ s/^\s+//g;
14477: $bcc =~ s/\s+$//g;
14478: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14479: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14480: push(@ok_bccs,$bcc);
14481: }
14482: }
14483: }
14484: if (@ok_bccs > 0) {
14485: $allbcc = join(', ',@ok_bccs);
14486: }
14487: }
14488: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14489: last;
14490: }
14491: }
14492: }
14493: }
14494: }
1.619 raeburn 14495: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14496: $lastresort = $origmail;
14497: }
1.1075.2.128 raeburn 14498: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14499: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14500: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14501: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14502: my %what = (
14503: perlvar => 1,
14504: );
14505: my $primary = &Apache::lonnet::domain($defdom,'primary');
14506: if ($primary) {
14507: my $gotaddr;
14508: my ($result,$returnhash) =
14509: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14510: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14511: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14512: $lastresort = $returnhash->{'lonSupportEMail'};
14513: $gotaddr = 1;
14514: }
14515: }
14516: unless ($gotaddr) {
14517: my $uintdom = &Apache::lonnet::internet_dom($primary);
14518: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14519: unless ($uintdom eq $intdom) {
14520: my %domconfig =
14521: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14522: if (ref($domconfig{'contacts'}) eq 'HASH') {
14523: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14524: my @contacts = ('adminemail','supportemail');
14525: foreach my $item (@contacts) {
14526: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14527: my $addr = $domconfig{'contacts'}{$item};
14528: if (!grep(/^\Q$addr\E$/,@recipients)) {
14529: push(@recipients,$addr);
14530: }
14531: }
14532: }
14533: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14534: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14535: }
14536: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14537: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14538: my @ok_bccs;
14539: foreach my $bcc (@bccs) {
14540: $bcc =~ s/^\s+//g;
14541: $bcc =~ s/\s+$//g;
14542: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14543: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14544: push(@ok_bccs,$bcc);
14545: }
14546: }
14547: }
14548: if (@ok_bccs > 0) {
14549: $allbcc = join(', ',@ok_bccs);
14550: }
14551: }
14552: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14553: }
14554: }
14555: }
14556: }
14557: }
14558: }
1.618 raeburn 14559: }
1.688 raeburn 14560: if (defined($defmail)) {
14561: if ($defmail ne '') {
14562: push(@recipients,$defmail);
14563: }
1.618 raeburn 14564: }
14565: if ($otheremails) {
1.619 raeburn 14566: my @others;
14567: if ($otheremails =~ /,/) {
14568: @others = split(/,/,$otheremails);
1.618 raeburn 14569: } else {
1.619 raeburn 14570: push(@others,$otheremails);
14571: }
14572: foreach my $addr (@others) {
14573: if (!grep(/^\Q$addr\E$/,@recipients)) {
14574: push(@recipients,$addr);
14575: }
1.618 raeburn 14576: }
14577: }
1.1075.2.128 raeburn 14578: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14579: if ((!@recipients) && ($lastresort ne '')) {
14580: push(@recipients,$lastresort);
14581: }
14582: } elsif ($lastresort ne '') {
14583: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14584: push(@recipients,$lastresort);
14585: }
14586: }
14587: my $recipientlist = join(',',@recipients);
14588: if (wantarray) {
14589: return ($recipientlist,$allbcc,$addtext);
14590: } else {
14591: return $recipientlist;
14592: }
1.618 raeburn 14593: }
14594:
1.127 matthew 14595: ############################################################
14596: ############################################################
1.154 albertel 14597:
1.655 raeburn 14598: =pod
14599:
14600: =head1 Course Catalog Routines
14601:
14602: =over 4
14603:
14604: =item * &gather_categories()
14605:
14606: Converts category definitions - keys of categories hash stored in
14607: coursecategories in configuration.db on the primary library server in a
14608: domain - to an array. Also generates javascript and idx hash used to
14609: generate Domain Coordinator interface for editing Course Categories.
14610:
14611: Inputs:
1.663 raeburn 14612:
1.655 raeburn 14613: categories (reference to hash of category definitions).
1.663 raeburn 14614:
1.655 raeburn 14615: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14616: categories and subcategories).
1.663 raeburn 14617:
1.655 raeburn 14618: idx (reference to hash of counters used in Domain Coordinator interface for
14619: editing Course Categories).
1.663 raeburn 14620:
1.655 raeburn 14621: jsarray (reference to array of categories used to create Javascript arrays for
14622: Domain Coordinator interface for editing Course Categories).
14623:
14624: Returns: nothing
14625:
14626: Side effects: populates cats, idx and jsarray.
14627:
14628: =cut
14629:
14630: sub gather_categories {
14631: my ($categories,$cats,$idx,$jsarray) = @_;
14632: my %counters;
14633: my $num = 0;
14634: foreach my $item (keys(%{$categories})) {
14635: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14636: if ($container eq '' && $depth == 0) {
14637: $cats->[$depth][$categories->{$item}] = $cat;
14638: } else {
14639: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14640: }
14641: my ($escitem,$tail) = split(/:/,$item,2);
14642: if ($counters{$tail} eq '') {
14643: $counters{$tail} = $num;
14644: $num ++;
14645: }
14646: if (ref($idx) eq 'HASH') {
14647: $idx->{$item} = $counters{$tail};
14648: }
14649: if (ref($jsarray) eq 'ARRAY') {
14650: push(@{$jsarray->[$counters{$tail}]},$item);
14651: }
14652: }
14653: return;
14654: }
14655:
14656: =pod
14657:
14658: =item * &extract_categories()
14659:
14660: Used to generate breadcrumb trails for course categories.
14661:
14662: Inputs:
1.663 raeburn 14663:
1.655 raeburn 14664: categories (reference to hash of category definitions).
1.663 raeburn 14665:
1.655 raeburn 14666: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14667: categories and subcategories).
1.663 raeburn 14668:
1.655 raeburn 14669: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14670:
1.655 raeburn 14671: allitems (reference to hash - key is category key
14672: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14673:
1.655 raeburn 14674: idx (reference to hash of counters used in Domain Coordinator interface for
14675: editing Course Categories).
1.663 raeburn 14676:
1.655 raeburn 14677: jsarray (reference to array of categories used to create Javascript arrays for
14678: Domain Coordinator interface for editing Course Categories).
14679:
1.665 raeburn 14680: subcats (reference to hash of arrays containing all subcategories within each
14681: category, -recursive)
14682:
1.1075.2.132 raeburn 14683: maxd (reference to hash used to hold max depth for all top-level categories).
14684:
1.655 raeburn 14685: Returns: nothing
14686:
14687: Side effects: populates trails and allitems hash references.
14688:
14689: =cut
14690:
14691: sub extract_categories {
1.1075.2.132 raeburn 14692: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14693: if (ref($categories) eq 'HASH') {
14694: &gather_categories($categories,$cats,$idx,$jsarray);
14695: if (ref($cats->[0]) eq 'ARRAY') {
14696: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14697: my $name = $cats->[0][$i];
14698: my $item = &escape($name).'::0';
14699: my $trailstr;
14700: if ($name eq 'instcode') {
14701: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14702: } elsif ($name eq 'communities') {
14703: $trailstr = &mt('Communities');
1.655 raeburn 14704: } else {
14705: $trailstr = $name;
14706: }
14707: if ($allitems->{$item} eq '') {
14708: push(@{$trails},$trailstr);
14709: $allitems->{$item} = scalar(@{$trails})-1;
14710: }
14711: my @parents = ($name);
14712: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14713: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14714: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14715: if (ref($subcats) eq 'HASH') {
14716: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14717: }
1.1075.2.132 raeburn 14718: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14719: }
14720: } else {
14721: if (ref($subcats) eq 'HASH') {
14722: $subcats->{$item} = [];
1.655 raeburn 14723: }
1.1075.2.132 raeburn 14724: if (ref($maxd) eq 'HASH') {
14725: $maxd->{$name} = 1;
14726: }
1.655 raeburn 14727: }
14728: }
14729: }
14730: }
14731: return;
14732: }
14733:
14734: =pod
14735:
1.1075.2.56 raeburn 14736: =item * &recurse_categories()
1.655 raeburn 14737:
14738: Recursively used to generate breadcrumb trails for course categories.
14739:
14740: Inputs:
1.663 raeburn 14741:
1.655 raeburn 14742: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14743: categories and subcategories).
1.663 raeburn 14744:
1.655 raeburn 14745: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14746:
14747: category (current course category, for which breadcrumb trail is being generated).
14748:
14749: trails (reference to array of breadcrumb trails for each category).
14750:
1.655 raeburn 14751: allitems (reference to hash - key is category key
14752: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14753:
1.655 raeburn 14754: parents (array containing containers directories for current category,
14755: back to top level).
14756:
14757: Returns: nothing
14758:
14759: Side effects: populates trails and allitems hash references
14760:
14761: =cut
14762:
14763: sub recurse_categories {
1.1075.2.132 raeburn 14764: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14765: my $shallower = $depth - 1;
14766: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14767: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14768: my $name = $cats->[$depth]{$category}[$k];
14769: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14770: my $trailstr = join(' -> ',(@{$parents},$category));
14771: if ($allitems->{$item} eq '') {
14772: push(@{$trails},$trailstr);
14773: $allitems->{$item} = scalar(@{$trails})-1;
14774: }
14775: my $deeper = $depth+1;
14776: push(@{$parents},$category);
1.665 raeburn 14777: if (ref($subcats) eq 'HASH') {
14778: my $subcat = &escape($name).':'.$category.':'.$depth;
14779: for (my $j=@{$parents}; $j>=0; $j--) {
14780: my $higher;
14781: if ($j > 0) {
14782: $higher = &escape($parents->[$j]).':'.
14783: &escape($parents->[$j-1]).':'.$j;
14784: } else {
14785: $higher = &escape($parents->[$j]).'::'.$j;
14786: }
14787: push(@{$subcats->{$higher}},$subcat);
14788: }
14789: }
14790: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14791: $subcats,$maxd);
1.655 raeburn 14792: pop(@{$parents});
14793: }
14794: } else {
14795: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14796: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14797: if ($allitems->{$item} eq '') {
14798: push(@{$trails},$trailstr);
14799: $allitems->{$item} = scalar(@{$trails})-1;
14800: }
1.1075.2.132 raeburn 14801: if (ref($maxd) eq 'HASH') {
14802: if ($depth > $maxd->{$parents->[0]}) {
14803: $maxd->{$parents->[0]} = $depth;
14804: }
14805: }
1.655 raeburn 14806: }
14807: return;
14808: }
14809:
1.663 raeburn 14810: =pod
14811:
1.1075.2.56 raeburn 14812: =item * &assign_categories_table()
1.663 raeburn 14813:
14814: Create a datatable for display of hierarchical categories in a domain,
14815: with checkboxes to allow a course to be categorized.
14816:
14817: Inputs:
14818:
14819: cathash - reference to hash of categories defined for the domain (from
14820: configuration.db)
14821:
14822: currcat - scalar with an & separated list of categories assigned to a course.
14823:
1.919 raeburn 14824: type - scalar contains course type (Course or Community).
14825:
1.1075.2.117 raeburn 14826: disabled - scalar (optional) contains disabled="disabled" if input elements are
14827: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14828:
1.663 raeburn 14829: Returns: $output (markup to be displayed)
14830:
14831: =cut
14832:
14833: sub assign_categories_table {
1.1075.2.117 raeburn 14834: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14835: my $output;
14836: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14837: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14838: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14839: $maxdepth = scalar(@cats);
14840: if (@cats > 0) {
14841: my $itemcount = 0;
14842: if (ref($cats[0]) eq 'ARRAY') {
14843: my @currcategories;
14844: if ($currcat ne '') {
14845: @currcategories = split('&',$currcat);
14846: }
1.919 raeburn 14847: my $table;
1.663 raeburn 14848: for (my $i=0; $i<@{$cats[0]}; $i++) {
14849: my $parent = $cats[0][$i];
1.919 raeburn 14850: next if ($parent eq 'instcode');
14851: if ($type eq 'Community') {
14852: next unless ($parent eq 'communities');
14853: } else {
14854: next if ($parent eq 'communities');
14855: }
1.663 raeburn 14856: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14857: my $item = &escape($parent).'::0';
14858: my $checked = '';
14859: if (@currcategories > 0) {
14860: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14861: $checked = ' checked="checked"';
1.663 raeburn 14862: }
14863: }
1.919 raeburn 14864: my $parent_title = $parent;
14865: if ($parent eq 'communities') {
14866: $parent_title = &mt('Communities');
14867: }
14868: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14869: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14870: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14871: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14872: my $depth = 1;
14873: push(@path,$parent);
1.1075.2.117 raeburn 14874: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14875: pop(@path);
1.919 raeburn 14876: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14877: $itemcount ++;
14878: }
1.919 raeburn 14879: if ($itemcount) {
14880: $output = &Apache::loncommon::start_data_table().
14881: $table.
14882: &Apache::loncommon::end_data_table();
14883: }
1.663 raeburn 14884: }
14885: }
14886: }
14887: return $output;
14888: }
14889:
14890: =pod
14891:
1.1075.2.56 raeburn 14892: =item * &assign_category_rows()
1.663 raeburn 14893:
14894: Create a datatable row for display of nested categories in a domain,
14895: with checkboxes to allow a course to be categorized,called recursively.
14896:
14897: Inputs:
14898:
14899: itemcount - track row number for alternating colors
14900:
14901: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14902: categories and subcategories.
14903:
14904: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14905:
14906: parent - parent of current category item
14907:
14908: path - Array containing all categories back up through the hierarchy from the
14909: current category to the top level.
14910:
14911: currcategories - reference to array of current categories assigned to the course
14912:
1.1075.2.117 raeburn 14913: disabled - scalar (optional) contains disabled="disabled" if input elements are
14914: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14915:
1.663 raeburn 14916: Returns: $output (markup to be displayed).
14917:
14918: =cut
14919:
14920: sub assign_category_rows {
1.1075.2.117 raeburn 14921: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14922: my ($text,$name,$item,$chgstr);
14923: if (ref($cats) eq 'ARRAY') {
14924: my $maxdepth = scalar(@{$cats});
14925: if (ref($cats->[$depth]) eq 'HASH') {
14926: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14927: my $numchildren = @{$cats->[$depth]{$parent}};
14928: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14929: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14930: for (my $j=0; $j<$numchildren; $j++) {
14931: $name = $cats->[$depth]{$parent}[$j];
14932: $item = &escape($name).':'.&escape($parent).':'.$depth;
14933: my $deeper = $depth+1;
14934: my $checked = '';
14935: if (ref($currcategories) eq 'ARRAY') {
14936: if (@{$currcategories} > 0) {
14937: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14938: $checked = ' checked="checked"';
1.663 raeburn 14939: }
14940: }
14941: }
1.664 raeburn 14942: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14943: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14944: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14945: '<input type="hidden" name="catname" value="'.$name.'" />'.
14946: '</td><td>';
1.663 raeburn 14947: if (ref($path) eq 'ARRAY') {
14948: push(@{$path},$name);
1.1075.2.117 raeburn 14949: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14950: pop(@{$path});
14951: }
14952: $text .= '</td></tr>';
14953: }
14954: $text .= '</table></td>';
14955: }
14956: }
14957: }
14958: return $text;
14959: }
14960:
1.1075.2.69 raeburn 14961: =pod
14962:
14963: =back
14964:
14965: =cut
14966:
1.655 raeburn 14967: ############################################################
14968: ############################################################
14969:
14970:
1.443 albertel 14971: sub commit_customrole {
1.664 raeburn 14972: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14973: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14974: ($start?', '.&mt('starting').' '.localtime($start):'').
14975: ($end?', ending '.localtime($end):'').': <b>'.
14976: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14977: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14978: '</b><br />';
14979: return $output;
14980: }
14981:
14982: sub commit_standardrole {
1.1075.2.31 raeburn 14983: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14984: my ($output,$logmsg,$linefeed);
14985: if ($context eq 'auto') {
14986: $linefeed = "\n";
14987: } else {
14988: $linefeed = "<br />\n";
14989: }
1.443 albertel 14990: if ($three eq 'st') {
1.541 raeburn 14991: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14992: $one,$two,$sec,$context,$credits);
1.541 raeburn 14993: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14994: ($result eq 'unknown_course') || ($result eq 'refused')) {
14995: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14996: } else {
1.541 raeburn 14997: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14998: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14999: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15000: if ($context eq 'auto') {
15001: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15002: } else {
15003: $output .= '<b>'.$result.'</b>'.$linefeed.
15004: &mt('Add to classlist').': <b>ok</b>';
15005: }
15006: $output .= $linefeed;
1.443 albertel 15007: }
15008: } else {
15009: $output = &mt('Assigning').' '.$three.' in '.$url.
15010: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15011: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15012: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15013: if ($context eq 'auto') {
15014: $output .= $result.$linefeed;
15015: } else {
15016: $output .= '<b>'.$result.'</b>'.$linefeed;
15017: }
1.443 albertel 15018: }
15019: return $output;
15020: }
15021:
15022: sub commit_studentrole {
1.1075.2.31 raeburn 15023: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15024: $credits) = @_;
1.626 raeburn 15025: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15026: if ($context eq 'auto') {
15027: $linefeed = "\n";
15028: } else {
15029: $linefeed = '<br />'."\n";
15030: }
1.443 albertel 15031: if (defined($one) && defined($two)) {
15032: my $cid=$one.'_'.$two;
15033: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15034: my $secchange = 0;
15035: my $expire_role_result;
15036: my $modify_section_result;
1.628 raeburn 15037: if ($oldsec ne '-1') {
15038: if ($oldsec ne $sec) {
1.443 albertel 15039: $secchange = 1;
1.628 raeburn 15040: my $now = time;
1.443 albertel 15041: my $uurl='/'.$cid;
15042: $uurl=~s/\_/\//g;
15043: if ($oldsec) {
15044: $uurl.='/'.$oldsec;
15045: }
1.626 raeburn 15046: $oldsecurl = $uurl;
1.628 raeburn 15047: $expire_role_result =
1.652 raeburn 15048: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15049: if ($env{'request.course.sec'} ne '') {
15050: if ($expire_role_result eq 'refused') {
15051: my @roles = ('st');
15052: my @statuses = ('previous');
15053: my @roledoms = ($one);
15054: my $withsec = 1;
15055: my %roleshash =
15056: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15057: \@statuses,\@roles,\@roledoms,$withsec);
15058: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15059: my ($oldstart,$oldend) =
15060: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15061: if ($oldend > 0 && $oldend <= $now) {
15062: $expire_role_result = 'ok';
15063: }
15064: }
15065: }
15066: }
1.443 albertel 15067: $result = $expire_role_result;
15068: }
15069: }
15070: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15071: $modify_section_result =
15072: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15073: undef,undef,undef,$sec,
15074: $end,$start,'','',$cid,
15075: '',$context,$credits);
1.443 albertel 15076: if ($modify_section_result =~ /^ok/) {
15077: if ($secchange == 1) {
1.628 raeburn 15078: if ($sec eq '') {
15079: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15080: } else {
15081: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15082: }
1.443 albertel 15083: } elsif ($oldsec eq '-1') {
1.628 raeburn 15084: if ($sec eq '') {
15085: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15086: } else {
15087: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15088: }
1.443 albertel 15089: } else {
1.628 raeburn 15090: if ($sec eq '') {
15091: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15092: } else {
15093: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15094: }
1.443 albertel 15095: }
15096: } else {
1.628 raeburn 15097: if ($secchange) {
15098: $$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;
15099: } else {
15100: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15101: }
1.443 albertel 15102: }
15103: $result = $modify_section_result;
15104: } elsif ($secchange == 1) {
1.628 raeburn 15105: if ($oldsec eq '') {
1.1075.2.20 raeburn 15106: $$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 15107: } else {
15108: $$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;
15109: }
1.626 raeburn 15110: if ($expire_role_result eq 'refused') {
15111: my $newsecurl = '/'.$cid;
15112: $newsecurl =~ s/\_/\//g;
15113: if ($sec ne '') {
15114: $newsecurl.='/'.$sec;
15115: }
15116: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15117: if ($sec eq '') {
15118: $$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;
15119: } else {
15120: $$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;
15121: }
15122: }
15123: }
1.443 albertel 15124: }
15125: } else {
1.626 raeburn 15126: $$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 15127: $result = "error: incomplete course id\n";
15128: }
15129: return $result;
15130: }
15131:
1.1075.2.25 raeburn 15132: sub show_role_extent {
15133: my ($scope,$context,$role) = @_;
15134: $scope =~ s{^/}{};
15135: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15136: push(@courseroles,'co');
15137: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15138: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15139: $scope =~ s{/}{_};
15140: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15141: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15142: my ($audom,$auname) = split(/\//,$scope);
15143: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15144: &Apache::loncommon::plainname($auname,$audom).'</span>');
15145: } else {
15146: $scope =~ s{/$}{};
15147: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15148: &Apache::lonnet::domain($scope,'description').'</span>');
15149: }
15150: }
15151:
1.443 albertel 15152: ############################################################
15153: ############################################################
15154:
1.566 albertel 15155: sub check_clone {
1.578 raeburn 15156: my ($args,$linefeed) = @_;
1.566 albertel 15157: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15158: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15159: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.141. .5(raebu 15160:20): my $clonetitle;
15161:20): my @clonemsg;
1.566 albertel 15162: my $can_clone = 0;
1.944 raeburn 15163: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15164: if ($lctype ne 'community') {
15165: $lctype = 'course';
15166: }
1.566 albertel 15167: if ($clonehome eq 'no_host') {
1.944 raeburn 15168: if ($args->{'crstype'} eq 'Community') {
1.1075.2.141. .5(raebu 15169:20): push(@clonemsg,({
15170:20): mt => 'No new community created.',
15171:20): args => [],
15172:20): },
15173:20): {
15174:20): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15175:20): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15176:20): }));
1.908 raeburn 15177: } else {
1.1075.2.141. .5(raebu 15178:20): push(@clonemsg,({
15179:20): mt => 'No new course created.',
15180:20): args => [],
15181:20): },
15182:20): {
15183:20): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15184:20): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15185:20): }));
15186:20): }
1.566 albertel 15187: } else {
15188: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.141. .5(raebu 15189:20): $clonetitle = $clonedesc{'description'};
1.944 raeburn 15190: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15191: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.141. .5(raebu 15192:20): push(@clonemsg,({
15193:20): mt => 'No new community created.',
15194:20): args => [],
15195:20): },
15196:20): {
15197:20): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
15198:20): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15199:20): }));
15200:20): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 15201: }
15202: }
1.1075.2.119 raeburn 15203: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15204: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15205: $can_clone = 1;
15206: } else {
1.1075.2.95 raeburn 15207: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15208: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15209: if ($clonehash{'cloners'} eq '') {
15210: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15211: if ($domdefs{'canclone'}) {
15212: unless ($domdefs{'canclone'} eq 'none') {
15213: if ($domdefs{'canclone'} eq 'domain') {
15214: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15215: $can_clone = 1;
15216: }
15217: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15218: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15219: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15220: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15221: $can_clone = 1;
15222: }
15223: }
15224: }
1.908 raeburn 15225: }
1.1075.2.95 raeburn 15226: } else {
15227: my @cloners = split(/,/,$clonehash{'cloners'});
15228: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15229: $can_clone = 1;
1.1075.2.95 raeburn 15230: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15231: $can_clone = 1;
1.1075.2.96 raeburn 15232: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15233: $can_clone = 1;
1.1075.2.95 raeburn 15234: }
15235: unless ($can_clone) {
1.1075.2.96 raeburn 15236: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15237: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15238: my (%gotdomdefaults,%gotcodedefaults);
15239: foreach my $cloner (@cloners) {
15240: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15241: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15242: my (%codedefaults,@code_order);
15243: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15244: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15245: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15246: }
15247: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15248: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15249: }
15250: } else {
15251: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15252: \%codedefaults,
15253: \@code_order);
15254: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15255: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15256: }
15257: if (@code_order > 0) {
15258: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15259: $cloner,$clonehash{'internal.coursecode'},
15260: $args->{'crscode'})) {
15261: $can_clone = 1;
15262: last;
15263: }
15264: }
15265: }
15266: }
15267: }
1.1075.2.96 raeburn 15268: }
15269: }
15270: unless ($can_clone) {
15271: my $ccrole = 'cc';
15272: if ($args->{'crstype'} eq 'Community') {
15273: $ccrole = 'co';
15274: }
15275: my %roleshash =
15276: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15277: $args->{'ccdomain'},
15278: 'userroles',['active'],[$ccrole],
15279: [$args->{'clonedomain'}]);
15280: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15281: $can_clone = 1;
15282: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15283: $args->{'ccuname'},$args->{'ccdomain'})) {
15284: $can_clone = 1;
1.1075.2.95 raeburn 15285: }
15286: }
15287: unless ($can_clone) {
15288: if ($args->{'crstype'} eq 'Community') {
1.1075.2.141. .5(raebu 15289:20): push(@clonemsg,({
15290:20): mt => 'No new community created.',
15291:20): args => [],
15292:20): },
15293:20): {
15294: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]).',
15295:20): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15296:20): }));
1.1075.2.95 raeburn 15297: } else {
1.1075.2.141. .5(raebu 15298:20): push(@clonemsg,({
15299:20): mt => 'No new course created.',
15300:20): args => [],
15301:20): },
15302:20): {
15303: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]).',
15304:20): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15305:20): }));
15306:20): }
1.566 albertel 15307: }
1.578 raeburn 15308: }
1.566 albertel 15309: }
1.1075.2.141. .5(raebu 15310:20): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15311: }
15312:
1.444 albertel 15313: sub construct_course {
1.1075.2.119 raeburn 15314: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.141. .5(raebu 15315:20): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
15316:20): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 15317: my $linefeed = '<br />'."\n";
15318: if ($context eq 'auto') {
15319: $linefeed = "\n";
15320: }
1.566 albertel 15321:
15322: #
15323: # Are we cloning?
15324: #
1.1075.2.141. .5(raebu 15325:20): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15326: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.141. .5(raebu 15327:20): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 15328: if (!$can_clone) {
1.1075.2.141. .5(raebu 15329:20): return (0,$outcome,$clonemsgref);
1.566 albertel 15330: }
15331: }
15332:
1.444 albertel 15333: #
15334: # Open course
15335: #
15336: my $crstype = lc($args->{'crstype'});
15337: my %cenv=();
15338: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15339: $args->{'cdescr'},
15340: $args->{'curl'},
15341: $args->{'course_home'},
15342: $args->{'nonstandard'},
15343: $args->{'crscode'},
15344: $args->{'ccuname'}.':'.
15345: $args->{'ccdomain'},
1.882 raeburn 15346: $args->{'crstype'},
1.1075.2.141. .5(raebu 15347:20): $cnum,$context,$category,
15348:20): $callercontext);
1.444 albertel 15349:
15350: # Note: The testing routines depend on this being output; see
15351: # Utils::Course. This needs to at least be output as a comment
15352: # if anyone ever decides to not show this, and Utils::Course::new
15353: # will need to be suitably modified.
1.1075.2.141. .5(raebu 15354:20): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15355:20): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15356:20): } else {
15357:20): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15358:20): }
1.943 raeburn 15359: if ($$courseid =~ /^error:/) {
1.1075.2.141. .5(raebu 15360:20): return (0,$outcome,$clonemsgref);
1.943 raeburn 15361: }
15362:
1.444 albertel 15363: #
15364: # Check if created correctly
15365: #
1.479 albertel 15366: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15367: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15368: if ($crsuhome eq 'no_host') {
1.1075.2.141. .5(raebu 15369:20): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15370:20): $outcome .= &mt_user($user_lh,
15371:20): 'Course creation failed, unrecognized course home server.');
15372:20): } else {
15373:20): $outcome .= &mt('Course creation failed, unrecognized course home server.');
15374:20): }
15375:20): $outcome .= $linefeed;
15376:20): return (0,$outcome,$clonemsgref);
1.943 raeburn 15377: }
1.541 raeburn 15378: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15379:
1.444 albertel 15380: #
1.566 albertel 15381: # Do the cloning
15382: #
1.1075.2.141. .5(raebu 15383:20): my @clonemsg;
1.566 albertel 15384: if ($can_clone && $cloneid) {
1.1075.2.141. .5(raebu 15385:20): push(@clonemsg,
15386:20): {
15387:20): mt => 'Created [_1] by cloning from [_2]',
15388:20): args => [$crstype,$clonetitle],
15389:20): });
1.566 albertel 15390: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15391: # Copy all files
1.1075.2.141. .5(raebu 15392:20): my @info =
15393:20): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
15394:20): $args->{'dateshift'},$args->{'crscode'},
15395:20): $args->{'ccuname'}.':'.$args->{'ccdomain'},
15396:20): $args->{'tinyurls'});
15397:20): if (@info) {
15398:20): push(@clonemsg,@info);
15399:20): }
1.444 albertel 15400: # Restore URL
1.566 albertel 15401: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15402: # Restore title
1.566 albertel 15403: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15404: # Restore creation date, creator and creation context.
15405: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15406: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15407: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15408: # Mark as cloned
1.566 albertel 15409: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15410: # Need to clone grading mode
15411: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15412: $cenv{'grading'}=$newenv{'grading'};
15413: # Do not clone these environment entries
15414: &Apache::lonnet::del('environment',
15415: ['default_enrollment_start_date',
15416: 'default_enrollment_end_date',
15417: 'question.email',
15418: 'policy.email',
15419: 'comment.email',
15420: 'pch.users.denied',
1.725 raeburn 15421: 'plc.users.denied',
15422: 'hidefromcat',
1.1075.2.36 raeburn 15423: 'checkforpriv',
1.1075.2.59 raeburn 15424: 'categories',
15425: 'internal.uniquecode'],
1.638 www 15426: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15427: if ($args->{'textbook'}) {
15428: $cenv{'internal.textbook'} = $args->{'textbook'};
15429: }
1.444 albertel 15430: }
1.566 albertel 15431:
1.444 albertel 15432: #
15433: # Set environment (will override cloned, if existing)
15434: #
15435: my @sections = ();
15436: my @xlists = ();
15437: if ($args->{'crstype'}) {
15438: $cenv{'type'}=$args->{'crstype'};
15439: }
15440: if ($args->{'crsid'}) {
15441: $cenv{'courseid'}=$args->{'crsid'};
15442: }
15443: if ($args->{'crscode'}) {
15444: $cenv{'internal.coursecode'}=$args->{'crscode'};
15445: }
15446: if ($args->{'crsquota'} ne '') {
15447: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15448: } else {
15449: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15450: }
15451: if ($args->{'ccuname'}) {
15452: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15453: ':'.$args->{'ccdomain'};
15454: } else {
15455: $cenv{'internal.courseowner'} = $args->{'curruser'};
15456: }
1.1075.2.31 raeburn 15457: if ($args->{'defaultcredits'}) {
15458: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15459: }
1.444 albertel 15460: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15461: if ($args->{'crssections'}) {
15462: $cenv{'internal.sectionnums'} = '';
15463: if ($args->{'crssections'} =~ m/,/) {
15464: @sections = split/,/,$args->{'crssections'};
15465: } else {
15466: $sections[0] = $args->{'crssections'};
15467: }
15468: if (@sections > 0) {
15469: foreach my $item (@sections) {
15470: my ($sec,$gp) = split/:/,$item;
15471: my $class = $args->{'crscode'}.$sec;
15472: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15473: $cenv{'internal.sectionnums'} .= $item.',';
15474: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15475: push(@badclasses,$class);
1.444 albertel 15476: }
15477: }
15478: $cenv{'internal.sectionnums'} =~ s/,$//;
15479: }
15480: }
15481: # do not hide course coordinator from staff listing,
15482: # even if privileged
15483: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15484: # add course coordinator's domain to domains to check for privileged users
15485: # if different to course domain
15486: if ($$crsudom ne $args->{'ccdomain'}) {
15487: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15488: }
1.444 albertel 15489: # add crosslistings
15490: if ($args->{'crsxlist'}) {
15491: $cenv{'internal.crosslistings'}='';
15492: if ($args->{'crsxlist'} =~ m/,/) {
15493: @xlists = split/,/,$args->{'crsxlist'};
15494: } else {
15495: $xlists[0] = $args->{'crsxlist'};
15496: }
15497: if (@xlists > 0) {
15498: foreach my $item (@xlists) {
15499: my ($xl,$gp) = split/:/,$item;
15500: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15501: $cenv{'internal.crosslistings'} .= $item.',';
15502: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15503: push(@badclasses,$xl);
1.444 albertel 15504: }
15505: }
15506: $cenv{'internal.crosslistings'} =~ s/,$//;
15507: }
15508: }
15509: if ($args->{'autoadds'}) {
15510: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15511: }
15512: if ($args->{'autodrops'}) {
15513: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15514: }
15515: # check for notification of enrollment changes
15516: my @notified = ();
15517: if ($args->{'notify_owner'}) {
15518: if ($args->{'ccuname'} ne '') {
15519: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15520: }
15521: }
15522: if ($args->{'notify_dc'}) {
15523: if ($uname ne '') {
1.630 raeburn 15524: push(@notified,$uname.':'.$udom);
1.444 albertel 15525: }
15526: }
15527: if (@notified > 0) {
15528: my $notifylist;
15529: if (@notified > 1) {
15530: $notifylist = join(',',@notified);
15531: } else {
15532: $notifylist = $notified[0];
15533: }
15534: $cenv{'internal.notifylist'} = $notifylist;
15535: }
15536: if (@badclasses > 0) {
15537: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15538: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15539: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15540: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15541: );
1.1075.2.119 raeburn 15542: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15543: &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 15544: if ($context eq 'auto') {
15545: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15546: } else {
1.566 albertel 15547: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15548: }
15549: foreach my $item (@badclasses) {
1.541 raeburn 15550: if ($context eq 'auto') {
1.1075.2.119 raeburn 15551: $outcome .= " - $item\n";
1.541 raeburn 15552: } else {
1.1075.2.119 raeburn 15553: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15554: }
1.1075.2.119 raeburn 15555: }
15556: if ($context eq 'auto') {
15557: $outcome .= $linefeed;
15558: } else {
15559: $outcome .= "</ul><br /><br /></div>\n";
15560: }
1.444 albertel 15561: }
15562: if ($args->{'no_end_date'}) {
15563: $args->{'endaccess'} = 0;
15564: }
15565: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15566: $cenv{'internal.autoend'}=$args->{'enrollend'};
15567: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15568: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15569: if ($args->{'showphotos'}) {
15570: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15571: }
15572: $cenv{'internal.authtype'} = $args->{'authtype'};
15573: $cenv{'internal.autharg'} = $args->{'autharg'};
15574: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15575: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15576: 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');
15577: if ($context eq 'auto') {
15578: $outcome .= $krb_msg;
15579: } else {
1.566 albertel 15580: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15581: }
15582: $outcome .= $linefeed;
1.444 albertel 15583: }
15584: }
15585: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15586: if ($args->{'setpolicy'}) {
15587: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15588: }
15589: if ($args->{'setcontent'}) {
15590: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15591: }
1.1075.2.110 raeburn 15592: if ($args->{'setcomment'}) {
15593: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15594: }
1.444 albertel 15595: }
15596: if ($args->{'reshome'}) {
15597: $cenv{'reshome'}=$args->{'reshome'}.'/';
15598: $cenv{'reshome'}=~s/\/+$/\//;
15599: }
15600: #
15601: # course has keyed access
15602: #
15603: if ($args->{'setkeys'}) {
15604: $cenv{'keyaccess'}='yes';
15605: }
15606: # if specified, key authority is not course, but user
15607: # only active if keyaccess is yes
15608: if ($args->{'keyauth'}) {
1.487 albertel 15609: my ($user,$domain) = split(':',$args->{'keyauth'});
15610: $user = &LONCAPA::clean_username($user);
15611: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15612: if ($user ne '' && $domain ne '') {
1.487 albertel 15613: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15614: }
15615: }
15616:
1.1075.2.59 raeburn 15617: #
15618: # generate and store uniquecode (available to course requester), if course should have one.
15619: #
15620: if ($args->{'uniquecode'}) {
15621: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15622: if ($code) {
15623: $cenv{'internal.uniquecode'} = $code;
15624: my %crsinfo =
15625: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15626: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15627: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15628: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15629: }
15630: if (ref($coderef)) {
15631: $$coderef = $code;
15632: }
15633: }
15634: }
15635:
1.444 albertel 15636: if ($args->{'disresdis'}) {
15637: $cenv{'pch.roles.denied'}='st';
15638: }
15639: if ($args->{'disablechat'}) {
15640: $cenv{'plc.roles.denied'}='st';
15641: }
15642:
15643: # Record we've not yet viewed the Course Initialization Helper for this
15644: # course
15645: $cenv{'course.helper.not.run'} = 1;
15646: #
15647: # Use new Randomseed
15648: #
15649: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15650: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15651: #
15652: # The encryption code and receipt prefix for this course
15653: #
15654: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15655: $cenv{'internal.encpref'}=100+int(9*rand(99));
15656: #
15657: # By default, use standard grading
15658: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15659:
1.541 raeburn 15660: $outcome .= $linefeed.&mt('Setting environment').': '.
15661: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15662: #
15663: # Open all assignments
15664: #
15665: if ($args->{'openall'}) {
1.1075.2.141. .4(raebu 15666:20): my $opendate = time;
15667:20): if ($args->{'openallfrom'} =~ /^\d+$/) {
15668:20): $opendate = $args->{'openallfrom'};
15669:20): }
1.444 albertel 15670: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.141. .4(raebu 15671:20): my %storecontent = ($storeunder => $opendate,
1.444 albertel 15672: $storeunder.'.type' => 'date_start');
1.1075.2.141. .4(raebu 15673:20): $outcome .= &mt('All assignments open starting [_1]',
15674:20): &Apache::lonlocal::locallocaltime($opendate)).': '.
15675:20): &Apache::lonnet::cput
15676:20): ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15677: }
15678: #
15679: # Set first page
15680: #
15681: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15682: || ($cloneid)) {
1.445 albertel 15683: use LONCAPA::map;
1.444 albertel 15684: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15685:
15686: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15687: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15688:
1.444 albertel 15689: $outcome .= ($fatal?$errtext:'read ok').' - ';
15690: my $title; my $url;
15691: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15692: $title=&mt('Syllabus');
1.444 albertel 15693: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15694: } else {
1.963 raeburn 15695: $title=&mt('Table of Contents');
1.444 albertel 15696: $url='/adm/navmaps';
15697: }
1.445 albertel 15698:
15699: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15700: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15701:
15702: if ($errtext) { $fatal=2; }
1.541 raeburn 15703: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15704: }
1.566 albertel 15705:
1.1075.2.141. .5(raebu 15706:20): return (1,$outcome,\@clonemsg);
1.444 albertel 15707: }
15708:
1.1075.2.59 raeburn 15709: sub make_unique_code {
15710: my ($cdom,$cnum) = @_;
15711: # get lock on uniquecodes db
15712: my $lockhash = {
15713: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15714: ':'.$env{'user.domain'},
15715: };
15716: my $tries = 0;
15717: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15718: my ($code,$error);
15719:
15720: while (($gotlock ne 'ok') && ($tries<3)) {
15721: $tries ++;
15722: sleep 1;
15723: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15724: }
15725: if ($gotlock eq 'ok') {
15726: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15727: my $gotcode;
15728: my $attempts = 0;
15729: while ((!$gotcode) && ($attempts < 100)) {
15730: $code = &generate_code();
15731: if (!exists($currcodes{$code})) {
15732: $gotcode = 1;
15733: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15734: $error = 'nostore';
15735: }
15736: }
15737: $attempts ++;
15738: }
15739: my @del_lock = ($cnum."\0".'uniquecodes');
15740: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15741: } else {
15742: $error = 'nolock';
15743: }
15744: return ($code,$error);
15745: }
15746:
15747: sub generate_code {
15748: my $code;
15749: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15750: for (my $i=0; $i<6; $i++) {
15751: my $lettnum = int (rand 2);
15752: my $item = '';
15753: if ($lettnum) {
15754: $item = $letts[int( rand(18) )];
15755: } else {
15756: $item = 1+int( rand(8) );
15757: }
15758: $code .= $item;
15759: }
15760: return $code;
15761: }
15762:
1.444 albertel 15763: ############################################################
15764: ############################################################
15765:
1.953 droeschl 15766: #SD
15767: # only Community and Course, or anything else?
1.378 raeburn 15768: sub course_type {
15769: my ($cid) = @_;
15770: if (!defined($cid)) {
15771: $cid = $env{'request.course.id'};
15772: }
1.404 albertel 15773: if (defined($env{'course.'.$cid.'.type'})) {
15774: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15775: } else {
15776: return 'Course';
1.377 raeburn 15777: }
15778: }
1.156 albertel 15779:
1.406 raeburn 15780: sub group_term {
15781: my $crstype = &course_type();
15782: my %names = (
15783: 'Course' => 'group',
1.865 raeburn 15784: 'Community' => 'group',
1.406 raeburn 15785: );
15786: return $names{$crstype};
15787: }
15788:
1.902 raeburn 15789: sub course_types {
1.1075.2.59 raeburn 15790: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15791: my %typename = (
15792: official => 'Official course',
15793: unofficial => 'Unofficial course',
15794: community => 'Community',
1.1075.2.59 raeburn 15795: textbook => 'Textbook course',
1.902 raeburn 15796: );
15797: return (\@types,\%typename);
15798: }
15799:
1.156 albertel 15800: sub icon {
15801: my ($file)=@_;
1.505 albertel 15802: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15803: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15804: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15805: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15806: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15807: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15808: $curfext.".gif") {
15809: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15810: $curfext.".gif";
15811: }
15812: }
1.249 albertel 15813: return &lonhttpdurl($iconname);
1.154 albertel 15814: }
1.84 albertel 15815:
1.575 albertel 15816: sub lonhttpdurl {
1.692 www 15817: #
15818: # Had been used for "small fry" static images on separate port 8080.
15819: # Modify here if lightweight http functionality desired again.
15820: # Currently eliminated due to increasing firewall issues.
15821: #
1.575 albertel 15822: my ($url)=@_;
1.692 www 15823: return $url;
1.215 albertel 15824: }
15825:
1.213 albertel 15826: sub connection_aborted {
15827: my ($r)=@_;
15828: $r->print(" ");$r->rflush();
15829: my $c = $r->connection;
15830: return $c->aborted();
15831: }
15832:
1.221 foxr 15833: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15834: # strings as 'strings'.
15835: sub escape_single {
1.221 foxr 15836: my ($input) = @_;
1.223 albertel 15837: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15838: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15839: return $input;
15840: }
1.223 albertel 15841:
1.222 foxr 15842: # Same as escape_single, but escape's "'s This
15843: # can be used for "strings"
15844: sub escape_double {
15845: my ($input) = @_;
15846: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15847: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15848: return $input;
15849: }
1.223 albertel 15850:
1.222 foxr 15851: # Escapes the last element of a full URL.
15852: sub escape_url {
15853: my ($url) = @_;
1.238 raeburn 15854: my @urlslices = split(/\//, $url,-1);
1.369 www 15855: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15856: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15857: }
1.462 albertel 15858:
1.820 raeburn 15859: sub compare_arrays {
15860: my ($arrayref1,$arrayref2) = @_;
15861: my (@difference,%count);
15862: @difference = ();
15863: %count = ();
15864: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15865: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15866: foreach my $element (keys(%count)) {
15867: if ($count{$element} == 1) {
15868: push(@difference,$element);
15869: }
15870: }
15871: }
15872: return @difference;
15873: }
15874:
1.817 bisitz 15875: # -------------------------------------------------------- Initialize user login
1.462 albertel 15876: sub init_user_environment {
1.463 albertel 15877: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15878: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15879:
15880: my $public=($username eq 'public' && $domain eq 'public');
15881:
15882: # See if old ID present, if so, remove
15883:
1.1062 raeburn 15884: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15885: my $now=time;
15886:
15887: if ($public) {
15888: my $max_public=100;
15889: my $oldest;
15890: my $oldest_time=0;
15891: for(my $next=1;$next<=$max_public;$next++) {
15892: if (-e $lonids."/publicuser_$next.id") {
15893: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15894: if ($mtime<$oldest_time || !$oldest_time) {
15895: $oldest_time=$mtime;
15896: $oldest=$next;
15897: }
15898: } else {
15899: $cookie="publicuser_$next";
15900: last;
15901: }
15902: }
15903: if (!$cookie) { $cookie="publicuser_$oldest"; }
15904: } else {
1.463 albertel 15905: # if this isn't a robot, kill any existing non-robot sessions
15906: if (!$args->{'robot'}) {
15907: opendir(DIR,$lonids);
15908: while ($filename=readdir(DIR)) {
15909: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15910: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15911: &GDBM_READER(),0640)) {
15912: my $linkedfile;
15913: if (exists($oldenv{'user.linkedenv'})) {
15914: $linkedfile = $oldenv{'user.linkedenv'};
15915: }
15916: untie(%oldenv);
15917: if (unlink("$lonids/$filename")) {
15918: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15919: if (-l "$lonids/$linkedfile.id") {
15920: unlink("$lonids/$linkedfile.id");
15921: }
15922: }
15923: }
15924: } else {
15925: unlink($lonids.'/'.$filename);
15926: }
1.463 albertel 15927: }
1.462 albertel 15928: }
1.463 albertel 15929: closedir(DIR);
1.1075.2.84 raeburn 15930: # If there is a undeleted lockfile for the user's paste buffer remove it.
15931: my $namespace = 'nohist_courseeditor';
15932: my $lockingkey = 'paste'."\0".'locked_num';
15933: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15934: $domain,$username);
15935: if (exists($lockhash{$lockingkey})) {
15936: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15937: unless ($delresult eq 'ok') {
15938: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15939: }
15940: }
1.462 albertel 15941: }
15942: # Give them a new cookie
1.463 albertel 15943: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15944: : $now.$$.int(rand(10000)));
1.463 albertel 15945: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15946:
15947: # Initialize roles
15948:
1.1062 raeburn 15949: ($userroles,$firstaccenv,$timerintenv) =
15950: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15951: }
15952: # ------------------------------------ Check browser type and MathML capability
15953:
1.1075.2.77 raeburn 15954: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15955: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15956:
15957: # ------------------------------------------------------------- Get environment
15958:
15959: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15960: my ($tmp) = keys(%userenv);
15961: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15962: } else {
15963: undef(%userenv);
15964: }
15965: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15966: $form->{'interface'}=$userenv{'interface'};
15967: }
15968: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15969:
15970: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15971: foreach my $option ('interface','localpath','localres') {
15972: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15973: }
15974: # --------------------------------------------------------- Write first profile
15975:
15976: {
1.1075.2.141. .11(raeb 15977:-21): my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 15978: my %initial_env =
15979: ("user.name" => $username,
15980: "user.domain" => $domain,
15981: "user.home" => $authhost,
15982: "browser.type" => $clientbrowser,
15983: "browser.version" => $clientversion,
15984: "browser.mathml" => $clientmathml,
15985: "browser.unicode" => $clientunicode,
15986: "browser.os" => $clientos,
1.1075.2.42 raeburn 15987: "browser.mobile" => $clientmobile,
15988: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15989: "browser.osversion" => $clientosversion,
1.462 albertel 15990: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15991: "request.course.fn" => '',
15992: "request.course.uri" => '',
15993: "request.course.sec" => '',
15994: "request.role" => 'cm',
15995: "request.role.adv" => $env{'user.adv'},
1.1075.2.141. .11(raeb 15996:-21): "request.host" => $ip,);
1.462 albertel 15997:
15998: if ($form->{'localpath'}) {
15999: $initial_env{"browser.localpath"} = $form->{'localpath'};
16000: $initial_env{"browser.localres"} = $form->{'localres'};
16001: }
16002:
16003: if ($form->{'interface'}) {
16004: $form->{'interface'}=~s/\W//gs;
16005: $initial_env{"browser.interface"} = $form->{'interface'};
16006: $env{'browser.interface'}=$form->{'interface'};
16007: }
16008:
1.1075.2.54 raeburn 16009: if ($form->{'iptoken'}) {
16010: my $lonhost = $r->dir_config('lonHostID');
16011: $initial_env{"user.noloadbalance"} = $lonhost;
16012: $env{'user.noloadbalance'} = $lonhost;
16013: }
16014:
1.1075.2.120 raeburn 16015: if ($form->{'noloadbalance'}) {
16016: my @hosts = &Apache::lonnet::current_machine_ids();
16017: my $hosthere = $form->{'noloadbalance'};
16018: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16019: $initial_env{"user.noloadbalance"} = $hosthere;
16020: $env{'user.noloadbalance'} = $hosthere;
16021: }
16022: }
16023:
1.1016 raeburn 16024: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16025: my %is_adv = ( is_adv => $env{'user.adv'} );
16026: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16027:
1.1075.2.125 raeburn 16028: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16029: $userenv{'availabletools.'.$tool} =
16030: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16031: undef,\%userenv,\%domdef,\%is_adv);
16032: }
1.724 raeburn 16033:
1.1075.2.125 raeburn 16034: foreach my $crstype ('official','unofficial','community','textbook') {
16035: $userenv{'canrequest.'.$crstype} =
16036: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16037: 'reload','requestcourses',
16038: \%userenv,\%domdef,\%is_adv);
16039: }
1.765 raeburn 16040:
1.1075.2.125 raeburn 16041: $userenv{'canrequest.author'} =
16042: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16043: 'reload','requestauthor',
16044: \%userenv,\%domdef,\%is_adv);
16045: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16046: $domain,$username);
16047: my $reqstatus = $reqauthor{'author_status'};
16048: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16049: if (ref($reqauthor{'author'}) eq 'HASH') {
16050: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16051: $reqauthor{'author'}{'timestamp'};
16052: }
1.1075.2.14 raeburn 16053: }
16054: }
16055:
1.462 albertel 16056: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16057:
1.462 albertel 16058: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16059: &GDBM_WRCREAT(),0640)) {
16060: &_add_to_env(\%disk_env,\%initial_env);
16061: &_add_to_env(\%disk_env,\%userenv,'environment.');
16062: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16063: if (ref($firstaccenv) eq 'HASH') {
16064: &_add_to_env(\%disk_env,$firstaccenv);
16065: }
16066: if (ref($timerintenv) eq 'HASH') {
16067: &_add_to_env(\%disk_env,$timerintenv);
16068: }
1.463 albertel 16069: if (ref($args->{'extra_env'})) {
16070: &_add_to_env(\%disk_env,$args->{'extra_env'});
16071: }
1.462 albertel 16072: untie(%disk_env);
16073: } else {
1.705 tempelho 16074: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16075: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16076: return 'error: '.$!;
16077: }
16078: }
16079: $env{'request.role'}='cm';
16080: $env{'request.role.adv'}=$env{'user.adv'};
16081: $env{'browser.type'}=$clientbrowser;
16082:
16083: return $cookie;
16084:
16085: }
16086:
16087: sub _add_to_env {
16088: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16089: if (ref($env_data) eq 'HASH') {
16090: while (my ($key,$value) = each(%$env_data)) {
16091: $idf->{$prefix.$key} = $value;
16092: $env{$prefix.$key} = $value;
16093: }
1.462 albertel 16094: }
16095: }
16096:
1.685 tempelho 16097: # --- Get the symbolic name of a problem and the url
16098: sub get_symb {
16099: my ($request,$silent) = @_;
1.726 raeburn 16100: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16101: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16102: if ($symb eq '') {
16103: if (!$silent) {
1.1071 raeburn 16104: if (ref($request)) {
16105: $request->print("Unable to handle ambiguous references:$url:.");
16106: }
1.685 tempelho 16107: return ();
16108: }
16109: }
16110: &Apache::lonenc::check_decrypt(\$symb);
16111: return ($symb);
16112: }
16113:
16114: # --------------------------------------------------------------Get annotation
16115:
16116: sub get_annotation {
16117: my ($symb,$enc) = @_;
16118:
16119: my $key = $symb;
16120: if (!$enc) {
16121: $key =
16122: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16123: }
16124: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16125: return $annotation{$key};
16126: }
16127:
16128: sub clean_symb {
1.731 raeburn 16129: my ($symb,$delete_enc) = @_;
1.685 tempelho 16130:
16131: &Apache::lonenc::check_decrypt(\$symb);
16132: my $enc = $env{'request.enc'};
1.731 raeburn 16133: if ($delete_enc) {
1.730 raeburn 16134: delete($env{'request.enc'});
16135: }
1.685 tempelho 16136:
16137: return ($symb,$enc);
16138: }
1.462 albertel 16139:
1.1075.2.69 raeburn 16140: ############################################################
16141: ############################################################
16142:
16143: =pod
16144:
16145: =head1 Routines for building display used to search for courses
16146:
16147:
16148: =over 4
16149:
16150: =item * &build_filters()
16151:
16152: Create markup for a table used to set filters to use when selecting
16153: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16154: and quotacheck.pl
16155:
16156:
16157: Inputs:
16158:
16159: filterlist - anonymous array of fields to include as potential filters
16160:
16161: crstype - course type
16162:
16163: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16164: to pop-open a course selector (will contain "extra element").
16165:
16166: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16167:
16168: filter - anonymous hash of criteria and their values
16169:
16170: action - form action
16171:
16172: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16173:
16174: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16175:
16176: cloneruname - username of owner of new course who wants to clone
16177:
16178: clonerudom - domain of owner of new course who wants to clone
16179:
16180: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16181:
16182: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16183:
16184: codedom - domain
16185:
16186: formname - value of form element named "form".
16187:
16188: fixeddom - domain, if fixed.
16189:
16190: prevphase - value to assign to form element named "phase" when going back to the previous screen
16191:
16192: cnameelement - name of form element in form on opener page which will receive title of selected course
16193:
16194: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16195:
16196: cdomelement - name of form element in form on opener page which will receive domain of selected course
16197:
16198: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16199:
16200: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16201:
16202: clonewarning - warning message about missing information for intended course owner when DC creates a course
16203:
16204:
16205: Returns: $output - HTML for display of search criteria, and hidden form elements.
16206:
16207:
16208: Side Effects: None
16209:
16210: =cut
16211:
16212: # ---------------------------------------------- search for courses based on last activity etc.
16213:
16214: sub build_filters {
16215: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16216: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16217: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16218: $cnameelement,$cnumelement,$cdomelement,$setroles,
16219: $clonetext,$clonewarning) = @_;
16220: my ($list,$jscript);
16221: my $onchange = 'javascript:updateFilters(this)';
16222: my ($domainselectform,$sincefilterform,$createdfilterform,
16223: $ownerdomselectform,$persondomselectform,$instcodeform,
16224: $typeselectform,$instcodetitle);
16225: if ($formname eq '') {
16226: $formname = $caller;
16227: }
16228: foreach my $item (@{$filterlist}) {
16229: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16230: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16231: if ($item eq 'domainfilter') {
16232: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16233: } elsif ($item eq 'coursefilter') {
16234: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16235: } elsif ($item eq 'ownerfilter') {
16236: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16237: } elsif ($item eq 'ownerdomfilter') {
16238: $filter->{'ownerdomfilter'} =
16239: &LONCAPA::clean_domain($filter->{$item});
16240: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16241: 'ownerdomfilter',1);
16242: } elsif ($item eq 'personfilter') {
16243: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16244: } elsif ($item eq 'persondomfilter') {
16245: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16246: 'persondomfilter',1);
16247: } else {
16248: $filter->{$item} =~ s/\W//g;
16249: }
16250: if (!$filter->{$item}) {
16251: $filter->{$item} = '';
16252: }
16253: }
16254: if ($item eq 'domainfilter') {
16255: my $allow_blank = 1;
16256: if ($formname eq 'portform') {
16257: $allow_blank=0;
16258: } elsif ($formname eq 'studentform') {
16259: $allow_blank=0;
16260: }
16261: if ($fixeddom) {
16262: $domainselectform = '<input type="hidden" name="domainfilter"'.
16263: ' value="'.$codedom.'" />'.
16264: &Apache::lonnet::domain($codedom,'description');
16265: } else {
16266: $domainselectform = &select_dom_form($filter->{$item},
16267: 'domainfilter',
16268: $allow_blank,'',$onchange);
16269: }
16270: } else {
16271: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16272: }
16273: }
16274:
16275: # last course activity filter and selection
16276: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16277:
16278: # course created filter and selection
16279: if (exists($filter->{'createdfilter'})) {
16280: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16281: }
16282:
16283: my %lt = &Apache::lonlocal::texthash(
16284: 'cac' => "$crstype Activity",
16285: 'ccr' => "$crstype Created",
16286: 'cde' => "$crstype Title",
16287: 'cdo' => "$crstype Domain",
16288: 'ins' => 'Institutional Code',
16289: 'inc' => 'Institutional Categorization',
16290: 'cow' => "$crstype Owner/Co-owner",
16291: 'cop' => "$crstype Personnel Includes",
16292: 'cog' => 'Type',
16293: );
16294:
16295: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16296: my $typeval = 'Course';
16297: if ($crstype eq 'Community') {
16298: $typeval = 'Community';
16299: }
16300: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16301: } else {
16302: $typeselectform = '<select name="type" size="1"';
16303: if ($onchange) {
16304: $typeselectform .= ' onchange="'.$onchange.'"';
16305: }
16306: $typeselectform .= '>'."\n";
16307: foreach my $posstype ('Course','Community') {
16308: $typeselectform.='<option value="'.$posstype.'"'.
16309: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16310: }
16311: $typeselectform.="</select>";
16312: }
16313:
16314: my ($cloneableonlyform,$cloneabletitle);
16315: if (exists($filter->{'cloneableonly'})) {
16316: my $cloneableon = '';
16317: my $cloneableoff = ' checked="checked"';
16318: if ($filter->{'cloneableonly'}) {
16319: $cloneableon = $cloneableoff;
16320: $cloneableoff = '';
16321: }
16322: $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>';
16323: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16324: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16325: } else {
16326: $cloneabletitle = &mt('Cloneable by you');
16327: }
16328: }
16329: my $officialjs;
16330: if ($crstype eq 'Course') {
16331: if (exists($filter->{'instcodefilter'})) {
16332: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16333: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16334: if ($codedom) {
16335: $officialjs = 1;
16336: ($instcodeform,$jscript,$$numtitlesref) =
16337: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16338: $officialjs,$codetitlesref);
16339: if ($jscript) {
16340: $jscript = '<script type="text/javascript">'."\n".
16341: '// <![CDATA['."\n".
16342: $jscript."\n".
16343: '// ]]>'."\n".
16344: '</script>'."\n";
16345: }
16346: }
16347: if ($instcodeform eq '') {
16348: $instcodeform =
16349: '<input type="text" name="instcodefilter" size="10" value="'.
16350: $list->{'instcodefilter'}.'" />';
16351: $instcodetitle = $lt{'ins'};
16352: } else {
16353: $instcodetitle = $lt{'inc'};
16354: }
16355: if ($fixeddom) {
16356: $instcodetitle .= '<br />('.$codedom.')';
16357: }
16358: }
16359: }
16360: my $output = qq|
16361: <form method="post" name="filterpicker" action="$action">
16362: <input type="hidden" name="form" value="$formname" />
16363: |;
16364: if ($formname eq 'modifycourse') {
16365: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16366: '<input type="hidden" name="prevphase" value="'.
16367: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16368: } elsif ($formname eq 'quotacheck') {
16369: $output .= qq|
16370: <input type="hidden" name="sortby" value="" />
16371: <input type="hidden" name="sortorder" value="" />
16372: |;
16373: } else {
1.1075.2.69 raeburn 16374: my $name_input;
16375: if ($cnameelement ne '') {
16376: $name_input = '<input type="hidden" name="cnameelement" value="'.
16377: $cnameelement.'" />';
16378: }
16379: $output .= qq|
16380: <input type="hidden" name="cnumelement" value="$cnumelement" />
16381: <input type="hidden" name="cdomelement" value="$cdomelement" />
16382: $name_input
16383: $roleelement
16384: $multelement
16385: $typeelement
16386: |;
16387: if ($formname eq 'portform') {
16388: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16389: }
16390: }
16391: if ($fixeddom) {
16392: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16393: }
16394: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16395: if ($sincefilterform) {
16396: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16397: .$sincefilterform
16398: .&Apache::lonhtmlcommon::row_closure();
16399: }
16400: if ($createdfilterform) {
16401: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16402: .$createdfilterform
16403: .&Apache::lonhtmlcommon::row_closure();
16404: }
16405: if ($domainselectform) {
16406: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16407: .$domainselectform
16408: .&Apache::lonhtmlcommon::row_closure();
16409: }
16410: if ($typeselectform) {
16411: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16412: $output .= $typeselectform;
16413: } else {
16414: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16415: .$typeselectform
16416: .&Apache::lonhtmlcommon::row_closure();
16417: }
16418: }
16419: if ($instcodeform) {
16420: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16421: .$instcodeform
16422: .&Apache::lonhtmlcommon::row_closure();
16423: }
16424: if (exists($filter->{'ownerfilter'})) {
16425: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16426: '<table><tr><td>'.&mt('Username').'<br />'.
16427: '<input type="text" name="ownerfilter" size="20" value="'.
16428: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16429: $ownerdomselectform.'</td></tr></table>'.
16430: &Apache::lonhtmlcommon::row_closure();
16431: }
16432: if (exists($filter->{'personfilter'})) {
16433: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16434: '<table><tr><td>'.&mt('Username').'<br />'.
16435: '<input type="text" name="personfilter" size="20" value="'.
16436: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16437: $persondomselectform.'</td></tr></table>'.
16438: &Apache::lonhtmlcommon::row_closure();
16439: }
16440: if (exists($filter->{'coursefilter'})) {
16441: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16442: .'<input type="text" name="coursefilter" size="25" value="'
16443: .$list->{'coursefilter'}.'" />'
16444: .&Apache::lonhtmlcommon::row_closure();
16445: }
16446: if ($cloneableonlyform) {
16447: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16448: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16449: }
16450: if (exists($filter->{'descriptfilter'})) {
16451: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16452: .'<input type="text" name="descriptfilter" size="40" value="'
16453: .$list->{'descriptfilter'}.'" />'
16454: .&Apache::lonhtmlcommon::row_closure(1);
16455: }
16456: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16457: '<input type="hidden" name="updater" value="" />'."\n".
16458: '<input type="submit" name="gosearch" value="'.
16459: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16460: return $jscript.$clonewarning.$output;
16461: }
16462:
16463: =pod
16464:
16465: =item * &timebased_select_form()
16466:
16467: Create markup for a dropdown list used to select a time-based
16468: filter e.g., Course Activity, Course Created, when searching for courses
16469: or communities
16470:
16471: Inputs:
16472:
16473: item - name of form element (sincefilter or createdfilter)
16474:
16475: filter - anonymous hash of criteria and their values
16476:
16477: Returns: HTML for a select box contained a blank, then six time selections,
16478: with value set in incoming form variables currently selected.
16479:
16480: Side Effects: None
16481:
16482: =cut
16483:
16484: sub timebased_select_form {
16485: my ($item,$filter) = @_;
16486: if (ref($filter) eq 'HASH') {
16487: $filter->{$item} =~ s/[^\d-]//g;
16488: if (!$filter->{$item}) { $filter->{$item}=-1; }
16489: return &select_form(
16490: $filter->{$item},
16491: $item,
16492: { '-1' => '',
16493: '86400' => &mt('today'),
16494: '604800' => &mt('last week'),
16495: '2592000' => &mt('last month'),
16496: '7776000' => &mt('last three months'),
16497: '15552000' => &mt('last six months'),
16498: '31104000' => &mt('last year'),
16499: 'select_form_order' =>
16500: ['-1','86400','604800','2592000','7776000',
16501: '15552000','31104000']});
16502: }
16503: }
16504:
16505: =pod
16506:
16507: =item * &js_changer()
16508:
16509: Create script tag containing Javascript used to submit course search form
16510: when course type or domain is changed, and also to hide 'Searching ...' on
16511: page load completion for page showing search result.
16512:
16513: Inputs: None
16514:
16515: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16516:
16517: Side Effects: None
16518:
16519: =cut
16520:
16521: sub js_changer {
16522: return <<ENDJS;
16523: <script type="text/javascript">
16524: // <![CDATA[
16525: function updateFilters(caller) {
16526: if (typeof(caller) != "undefined") {
16527: document.filterpicker.updater.value = caller.name;
16528: }
16529: document.filterpicker.submit();
16530: }
16531:
16532: function hideSearching() {
16533: if (document.getElementById('searching')) {
16534: document.getElementById('searching').style.display = 'none';
16535: }
16536: return;
16537: }
16538:
16539: // ]]>
16540: </script>
16541:
16542: ENDJS
16543: }
16544:
16545: =pod
16546:
16547: =item * &search_courses()
16548:
16549: Process selected filters form course search form and pass to lonnet::courseiddump
16550: to retrieve a hash for which keys are courseIDs which match the selected filters.
16551:
16552: Inputs:
16553:
16554: dom - domain being searched
16555:
16556: type - course type ('Course' or 'Community' or '.' if any).
16557:
16558: filter - anonymous hash of criteria and their values
16559:
16560: numtitles - for institutional codes - number of categories
16561:
16562: cloneruname - optional username of new course owner
16563:
16564: clonerudom - optional domain of new course owner
16565:
1.1075.2.95 raeburn 16566: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16567: (used when DC is using course creation form)
16568:
16569: codetitles - reference to array of titles of components in institutional codes (official courses).
16570:
1.1075.2.95 raeburn 16571: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16572: (and so can clone automatically)
16573:
16574: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16575:
16576: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16577: courses to clone
1.1075.2.69 raeburn 16578:
16579: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16580:
16581:
16582: Side Effects: None
16583:
16584: =cut
16585:
16586:
16587: sub search_courses {
1.1075.2.95 raeburn 16588: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16589: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16590: my (%courses,%showcourses,$cloner);
16591: if (($filter->{'ownerfilter'} ne '') ||
16592: ($filter->{'ownerdomfilter'} ne '')) {
16593: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16594: $filter->{'ownerdomfilter'};
16595: }
16596: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16597: if (!$filter->{$item}) {
16598: $filter->{$item}='.';
16599: }
16600: }
16601: my $now = time;
16602: my $timefilter =
16603: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16604: my ($createdbefore,$createdafter);
16605: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16606: $createdbefore = $now;
16607: $createdafter = $now-$filter->{'createdfilter'};
16608: }
16609: my ($instcodefilter,$regexpok);
16610: if ($numtitles) {
16611: if ($env{'form.official'} eq 'on') {
16612: $instcodefilter =
16613: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16614: $regexpok = 1;
16615: } elsif ($env{'form.official'} eq 'off') {
16616: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16617: unless ($instcodefilter eq '') {
16618: $regexpok = -1;
16619: }
16620: }
16621: } else {
16622: $instcodefilter = $filter->{'instcodefilter'};
16623: }
16624: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16625: if ($type eq '') { $type = '.'; }
16626:
16627: if (($clonerudom ne '') && ($cloneruname ne '')) {
16628: $cloner = $cloneruname.':'.$clonerudom;
16629: }
16630: %courses = &Apache::lonnet::courseiddump($dom,
16631: $filter->{'descriptfilter'},
16632: $timefilter,
16633: $instcodefilter,
16634: $filter->{'combownerfilter'},
16635: $filter->{'coursefilter'},
16636: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16637: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16638: $filter->{'cloneableonly'},
16639: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16640: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16641: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16642: my $ccrole;
16643: if ($type eq 'Community') {
16644: $ccrole = 'co';
16645: } else {
16646: $ccrole = 'cc';
16647: }
16648: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16649: $filter->{'persondomfilter'},
16650: 'userroles',undef,
16651: [$ccrole,'in','ad','ep','ta','cr'],
16652: $dom);
16653: foreach my $role (keys(%rolehash)) {
16654: my ($cnum,$cdom,$courserole) = split(':',$role);
16655: my $cid = $cdom.'_'.$cnum;
16656: if (exists($courses{$cid})) {
16657: if (ref($courses{$cid}) eq 'HASH') {
16658: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16659: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16660: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16661: }
16662: } else {
16663: $courses{$cid}{roles} = [$courserole];
16664: }
16665: $showcourses{$cid} = $courses{$cid};
16666: }
16667: }
16668: }
16669: %courses = %showcourses;
16670: }
16671: return %courses;
16672: }
16673:
16674: =pod
16675:
16676: =back
16677:
1.1075.2.88 raeburn 16678: =head1 Routines for version requirements for current course.
16679:
16680: =over 4
16681:
16682: =item * &check_release_required()
16683:
16684: Compares required LON-CAPA version with version on server, and
16685: if required version is newer looks for a server with the required version.
16686:
16687: Looks first at servers in user's owen domain; if none suitable, looks at
16688: servers in course's domain are permitted to host sessions for user's domain.
16689:
16690: Inputs:
16691:
16692: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16693:
16694: $courseid - Course ID of current course
16695:
16696: $rolecode - User's current role in course (for switchserver query string).
16697:
16698: $required - LON-CAPA version needed by course (format: Major.Minor).
16699:
16700:
16701: Returns:
16702:
16703: $switchserver - query string tp append to /adm/switchserver call (if
16704: current server's LON-CAPA version is too old.
16705:
16706: $warning - Message is displayed if no suitable server could be found.
16707:
16708: =cut
16709:
16710: sub check_release_required {
16711: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16712: my ($switchserver,$warning);
16713: if ($required ne '') {
16714: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16715: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16716: if ($reqdmajor ne '' && $reqdminor ne '') {
16717: my $otherserver;
16718: if (($major eq '' && $minor eq '') ||
16719: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16720: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16721: my $switchlcrev =
16722: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16723: $userdomserver);
16724: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16725: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16726: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16727: my $cdom = $env{'course.'.$courseid.'.domain'};
16728: if ($cdom ne $env{'user.domain'}) {
16729: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16730: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16731: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16732: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16733: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16734: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16735: my $canhost =
16736: &Apache::lonnet::can_host_session($env{'user.domain'},
16737: $coursedomserver,
16738: $remoterev,
16739: $udomdefaults{'remotesessions'},
16740: $defdomdefaults{'hostedsessions'});
16741:
16742: if ($canhost) {
16743: $otherserver = $coursedomserver;
16744: } else {
16745: $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.");
16746: }
16747: } else {
16748: $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).");
16749: }
16750: } else {
16751: $otherserver = $userdomserver;
16752: }
16753: }
16754: if ($otherserver ne '') {
16755: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16756: }
16757: }
16758: }
16759: return ($switchserver,$warning);
16760: }
16761:
16762: =pod
16763:
16764: =item * &check_release_result()
16765:
16766: Inputs:
16767:
16768: $switchwarning - Warning message if no suitable server found to host session.
16769:
16770: $switchserver - query string to append to /adm/switchserver containing lonHostID
16771: and current role.
16772:
16773: Returns: HTML to display with information about requirement to switch server.
16774: Either displaying warning with link to Roles/Courses screen or
16775: display link to switchserver.
16776:
1.1075.2.69 raeburn 16777: =cut
16778:
1.1075.2.88 raeburn 16779: sub check_release_result {
16780: my ($switchwarning,$switchserver) = @_;
16781: my $output = &start_page('Selected course unavailable on this server').
16782: '<p class="LC_warning">';
16783: if ($switchwarning) {
16784: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16785: if (&show_course()) {
16786: $output .= &mt('Display courses');
16787: } else {
16788: $output .= &mt('Display roles');
16789: }
16790: $output .= '</a>';
16791: } elsif ($switchserver) {
16792: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16793: '<br />'.
16794: '<a href="/adm/switchserver?'.$switchserver.'">'.
16795: &mt('Switch Server').
16796: '</a>';
16797: }
16798: $output .= '</p>'.&end_page();
16799: return $output;
16800: }
16801:
16802: =pod
16803:
16804: =item * &needs_coursereinit()
16805:
16806: Determine if course contents stored for user's session needs to be
16807: refreshed, because content has changed since "Big Hash" last tied.
16808:
16809: Check for change is made if time last checked is more than 10 minutes ago
16810: (by default).
16811:
16812: Inputs:
16813:
16814: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16815:
16816: $interval (optional) - Time which may elapse (in s) between last check for content
16817: change in current course. (default: 600 s).
16818:
16819: Returns: an array; first element is:
16820:
16821: =over 4
16822:
16823: 'switch' - if content updates mean user's session
16824: needs to be switched to a server running a newer LON-CAPA version
16825:
16826: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16827: on current server hosting user's session
16828:
16829: '' - if no action required.
16830:
16831: =back
16832:
16833: If first item element is 'switch':
16834:
16835: second item is $switchwarning - Warning message if no suitable server found to host session.
16836:
16837: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16838: and current role.
16839:
16840: otherwise: no other elements returned.
16841:
16842: =back
16843:
16844: =cut
16845:
16846: sub needs_coursereinit {
16847: my ($loncaparev,$interval) = @_;
16848: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16849: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16850: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16851: my $now = time;
16852: if ($interval eq '') {
16853: $interval = 600;
16854: }
16855: if (($now-$env{'request.course.timechecked'})>$interval) {
16856: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.141. .6(raebu 16857:20): my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
16858:20): if ($blocked) {
16859:20): return ();
16860:20): }
16861:20): my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
1.1075.2.88 raeburn 16862: if ($lastchange > $env{'request.course.tied'}) {
16863: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16864: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16865: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16866: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16867: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16868: $curr_reqd_hash{'internal.releaserequired'}});
16869: my ($switchserver,$switchwarning) =
16870: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16871: $curr_reqd_hash{'internal.releaserequired'});
16872: if ($switchwarning ne '' || $switchserver ne '') {
16873: return ('switch',$switchwarning,$switchserver);
16874: }
16875: }
16876: }
16877: return ('update');
16878: }
16879: }
16880: return ();
16881: }
1.1075.2.69 raeburn 16882:
1.1075.2.11 raeburn 16883: sub update_content_constraints {
16884: my ($cdom,$cnum,$chome,$cid) = @_;
16885: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16886: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16887: my %checkresponsetypes;
16888: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16889: my ($item,$name,$value) = split(/:/,$key);
16890: if ($item eq 'resourcetag') {
16891: if ($name eq 'responsetype') {
16892: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16893: }
16894: }
16895: }
16896: my $navmap = Apache::lonnavmaps::navmap->new();
16897: if (defined($navmap)) {
16898: my %allresponses;
16899: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16900: my %responses = $res->responseTypes();
16901: foreach my $key (keys(%responses)) {
16902: next unless(exists($checkresponsetypes{$key}));
16903: $allresponses{$key} += $responses{$key};
16904: }
16905: }
16906: foreach my $key (keys(%allresponses)) {
16907: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16908: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16909: ($reqdmajor,$reqdminor) = ($major,$minor);
16910: }
16911: }
16912: undef($navmap);
16913: }
16914: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16915: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16916: }
16917: return;
16918: }
16919:
1.1075.2.27 raeburn 16920: sub allmaps_incourse {
16921: my ($cdom,$cnum,$chome,$cid) = @_;
16922: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16923: $cid = $env{'request.course.id'};
16924: $cdom = $env{'course.'.$cid.'.domain'};
16925: $cnum = $env{'course.'.$cid.'.num'};
16926: $chome = $env{'course.'.$cid.'.home'};
16927: }
16928: my %allmaps = ();
16929: my $lastchange =
16930: &Apache::lonnet::get_coursechange($cdom,$cnum);
16931: if ($lastchange > $env{'request.course.tied'}) {
16932: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16933: unless ($ferr) {
16934: &update_content_constraints($cdom,$cnum,$chome,$cid);
16935: }
16936: }
16937: my $navmap = Apache::lonnavmaps::navmap->new();
16938: if (defined($navmap)) {
16939: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16940: $allmaps{$res->src()} = 1;
16941: }
16942: }
16943: return \%allmaps;
16944: }
16945:
1.1075.2.11 raeburn 16946: sub parse_supplemental_title {
16947: my ($title) = @_;
16948:
16949: my ($foldertitle,$renametitle);
16950: if ($title =~ /&&&/) {
16951: $title = &HTML::Entites::decode($title);
16952: }
16953: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16954: $renametitle=$4;
16955: my ($time,$uname,$udom) = ($1,$2,$3);
16956: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16957: my $name = &plainname($uname,$udom);
16958: $name = &HTML::Entities::encode($name,'"<>&\'');
16959: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16960: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16961: $name.': <br />'.$foldertitle;
16962: }
16963: if (wantarray) {
16964: return ($title,$foldertitle,$renametitle);
16965: }
16966: return $title;
16967: }
16968:
1.1075.2.43 raeburn 16969: sub recurse_supplemental {
16970: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16971: if ($suppmap) {
16972: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16973: if ($fatal) {
16974: $errors ++;
16975: } else {
16976: if ($#LONCAPA::map::resources > 0) {
16977: foreach my $res (@LONCAPA::map::resources) {
16978: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16979: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16980: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16981: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16982: } else {
16983: $numfiles ++;
16984: }
16985: }
16986: }
16987: }
16988: }
16989: }
16990: return ($numfiles,$errors);
16991: }
16992:
1.1075.2.18 raeburn 16993: sub symb_to_docspath {
1.1075.2.119 raeburn 16994: my ($symb,$navmapref) = @_;
16995: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16996: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16997: if ($resurl=~/\.(sequence|page)$/) {
16998: $mapurl=$resurl;
16999: } elsif ($resurl eq 'adm/navmaps') {
17000: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17001: }
17002: my $mapresobj;
1.1075.2.119 raeburn 17003: unless (ref($$navmapref)) {
17004: $$navmapref = Apache::lonnavmaps::navmap->new();
17005: }
17006: if (ref($$navmapref)) {
17007: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17008: }
17009: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17010: my $type=$2;
17011: my $path;
17012: if (ref($mapresobj)) {
17013: my $pcslist = $mapresobj->map_hierarchy();
17014: if ($pcslist ne '') {
17015: foreach my $pc (split(/,/,$pcslist)) {
17016: next if ($pc <= 1);
1.1075.2.119 raeburn 17017: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17018: if (ref($res)) {
17019: my $thisurl = $res->src();
17020: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17021: my $thistitle = $res->title();
17022: $path .= '&'.
17023: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17024: &escape($thistitle).
1.1075.2.18 raeburn 17025: ':'.$res->randompick().
17026: ':'.$res->randomout().
17027: ':'.$res->encrypted().
17028: ':'.$res->randomorder().
17029: ':'.$res->is_page();
17030: }
17031: }
17032: }
17033: $path =~ s/^\&//;
17034: my $maptitle = $mapresobj->title();
17035: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17036: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17037: }
17038: $path .= (($path ne '')? '&' : '').
17039: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17040: &escape($maptitle).
1.1075.2.18 raeburn 17041: ':'.$mapresobj->randompick().
17042: ':'.$mapresobj->randomout().
17043: ':'.$mapresobj->encrypted().
17044: ':'.$mapresobj->randomorder().
17045: ':'.$mapresobj->is_page();
17046: } else {
17047: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17048: my $ispage = (($type eq 'page')? 1 : '');
17049: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17050: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17051: }
17052: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17053: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17054: }
17055: unless ($mapurl eq 'default') {
17056: $path = 'default&'.
1.1075.2.46 raeburn 17057: &escape('Main Content').
1.1075.2.18 raeburn 17058: ':::::&'.$path;
17059: }
17060: return $path;
17061: }
17062:
1.1075.2.14 raeburn 17063: sub captcha_display {
1.1075.2.137 raeburn 17064: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17065: my ($output,$error);
1.1075.2.107 raeburn 17066: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17067: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17068: if ($captcha eq 'original') {
17069: $output = &create_captcha();
17070: unless ($output) {
17071: $error = 'captcha';
17072: }
17073: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17074: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17075: unless ($output) {
17076: $error = 'recaptcha';
17077: }
17078: }
1.1075.2.107 raeburn 17079: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17080: }
17081:
17082: sub captcha_response {
1.1075.2.137 raeburn 17083: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17084: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17085: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17086: if ($captcha eq 'original') {
17087: ($captcha_chk,$captcha_error) = &check_captcha();
17088: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17089: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17090: } else {
17091: $captcha_chk = 1;
17092: }
17093: return ($captcha_chk,$captcha_error);
17094: }
17095:
17096: sub get_captcha_config {
1.1075.2.137 raeburn 17097: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17098: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17099: my $hostname = &Apache::lonnet::hostname($lonhost);
17100: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17101: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17102: if ($context eq 'usercreation') {
17103: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17104: if (ref($domconfig{$context}) eq 'HASH') {
17105: $hashtocheck = $domconfig{$context}{'cancreate'};
17106: if (ref($hashtocheck) eq 'HASH') {
17107: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17108: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17109: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17110: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17111: }
17112: if ($privkey && $pubkey) {
17113: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17114: $version = $hashtocheck->{'recaptchaversion'};
17115: if ($version ne '2') {
17116: $version = 1;
17117: }
1.1075.2.14 raeburn 17118: } else {
17119: $captcha = 'original';
17120: }
17121: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17122: $captcha = 'original';
17123: }
17124: }
17125: } else {
17126: $captcha = 'captcha';
17127: }
17128: } elsif ($context eq 'login') {
17129: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17130: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17131: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17132: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17133: if ($privkey && $pubkey) {
17134: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17135: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17136: if ($version ne '2') {
17137: $version = 1;
17138: }
1.1075.2.14 raeburn 17139: } else {
17140: $captcha = 'original';
17141: }
17142: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17143: $captcha = 'original';
17144: }
1.1075.2.137 raeburn 17145: } elsif ($context eq 'passwords') {
17146: if ($dom_in_effect) {
17147: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17148: if ($passwdconf{'captcha'} eq 'recaptcha') {
17149: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17150: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17151: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17152: }
17153: if ($privkey && $pubkey) {
17154: $captcha = 'recaptcha';
17155: $version = $passwdconf{'recaptchaversion'};
17156: if ($version ne '2') {
17157: $version = 1;
17158: }
17159: } else {
17160: $captcha = 'original';
17161: }
17162: } elsif ($passwdconf{'captcha'} ne 'notused') {
17163: $captcha = 'original';
17164: }
17165: }
1.1075.2.14 raeburn 17166: }
1.1075.2.107 raeburn 17167: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17168: }
17169:
17170: sub create_captcha {
17171: my %captcha_params = &captcha_settings();
17172: my ($output,$maxtries,$tries) = ('',10,0);
17173: while ($tries < $maxtries) {
17174: $tries ++;
17175: my $captcha = Authen::Captcha->new (
17176: output_folder => $captcha_params{'output_dir'},
17177: data_folder => $captcha_params{'db_dir'},
17178: );
17179: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17180:
17181: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17182: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17183: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17184: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17185: '<br />'.
17186: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17187: last;
17188: }
17189: }
17190: return $output;
17191: }
17192:
17193: sub captcha_settings {
17194: my %captcha_params = (
17195: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17196: www_output_dir => "/captchaspool",
17197: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17198: numchars => '5',
17199: );
17200: return %captcha_params;
17201: }
17202:
17203: sub check_captcha {
17204: my ($captcha_chk,$captcha_error);
17205: my $code = $env{'form.code'};
17206: my $md5sum = $env{'form.crypt'};
17207: my %captcha_params = &captcha_settings();
17208: my $captcha = Authen::Captcha->new(
17209: output_folder => $captcha_params{'output_dir'},
17210: data_folder => $captcha_params{'db_dir'},
17211: );
1.1075.2.26 raeburn 17212: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17213: my %captcha_hash = (
17214: 0 => 'Code not checked (file error)',
17215: -1 => 'Failed: code expired',
17216: -2 => 'Failed: invalid code (not in database)',
17217: -3 => 'Failed: invalid code (code does not match crypt)',
17218: );
17219: if ($captcha_chk != 1) {
17220: $captcha_error = $captcha_hash{$captcha_chk}
17221: }
17222: return ($captcha_chk,$captcha_error);
17223: }
17224:
17225: sub create_recaptcha {
1.1075.2.107 raeburn 17226: my ($pubkey,$version) = @_;
17227: if ($version >= 2) {
17228: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17229: } else {
17230: my $use_ssl;
17231: if ($ENV{'SERVER_PORT'} == 443) {
17232: $use_ssl = 1;
17233: }
17234: my $captcha = Captcha::reCAPTCHA->new;
17235: return $captcha->get_options_setter({theme => 'white'})."\n".
17236: $captcha->get_html($pubkey,undef,$use_ssl).
17237: &mt('If the text is hard to read, [_1] will replace them.',
17238: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17239: '<br /><br />';
17240: }
1.1075.2.14 raeburn 17241: }
17242:
17243: sub check_recaptcha {
1.1075.2.107 raeburn 17244: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17245: my $captcha_chk;
1.1075.2.141. .11(raeb 17246:-21): my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17247: if ($version >= 2) {
17248: my $ua = LWP::UserAgent->new;
17249: $ua->timeout(10);
17250: my %info = (
17251: secret => $privkey,
17252: response => $env{'form.g-recaptcha-response'},
1.1075.2.141. .11(raeb 17253:-21): remoteip => $ip,
1.1075.2.107 raeburn 17254: );
17255: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17256: if ($response->is_success) {
17257: my $data = JSON::DWIW->from_json($response->decoded_content);
17258: if (ref($data) eq 'HASH') {
17259: if ($data->{'success'}) {
17260: $captcha_chk = 1;
17261: }
17262: }
17263: }
17264: } else {
17265: my $captcha = Captcha::reCAPTCHA->new;
17266: my $captcha_result =
17267: $captcha->check_answer(
17268: $privkey,
1.1075.2.141. .11(raeb 17269:-21): $ip,
1.1075.2.107 raeburn 17270: $env{'form.recaptcha_challenge_field'},
17271: $env{'form.recaptcha_response_field'},
17272: );
17273: if ($captcha_result->{is_valid}) {
17274: $captcha_chk = 1;
17275: }
1.1075.2.14 raeburn 17276: }
17277: return $captcha_chk;
17278: }
17279:
1.1075.2.64 raeburn 17280: sub emailusername_info {
1.1075.2.103 raeburn 17281: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17282: my %titles = &Apache::lonlocal::texthash (
17283: lastname => 'Last Name',
17284: firstname => 'First Name',
17285: institution => 'School/college/university',
17286: location => "School's city, state/province, country",
17287: web => "School's web address",
17288: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17289: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17290: );
17291: return (\@fields,\%titles);
17292: }
17293:
1.1075.2.56 raeburn 17294: sub cleanup_html {
17295: my ($incoming) = @_;
17296: my $outgoing;
17297: if ($incoming ne '') {
17298: $outgoing = $incoming;
17299: $outgoing =~ s/;/;/g;
17300: $outgoing =~ s/\#/#/g;
17301: $outgoing =~ s/\&/&/g;
17302: $outgoing =~ s/</</g;
17303: $outgoing =~ s/>/>/g;
17304: $outgoing =~ s/\(/(/g;
17305: $outgoing =~ s/\)/)/g;
17306: $outgoing =~ s/"/"/g;
17307: $outgoing =~ s/'/'/g;
17308: $outgoing =~ s/\$/$/g;
17309: $outgoing =~ s{/}{/}g;
17310: $outgoing =~ s/=/=/g;
17311: $outgoing =~ s/\\/\/g
17312: }
17313: return $outgoing;
17314: }
17315:
1.1075.2.74 raeburn 17316: # Checks for critical messages and returns a redirect url if one exists.
17317: # $interval indicates how often to check for messages.
1.1075.2.141. .6(raebu 17318:20): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 17319: sub critical_redirect {
1.1075.2.141. .6(raebu 17320:20): my ($interval,$context) = @_;
1.1075.2.74 raeburn 17321: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.141. .6(raebu 17322:20): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17323:20): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17324:20): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17325:20): my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17326:20): if ($blocked) {
17327:20): my $checkrole = "cm./$cdom/$cnum";
17328:20): if ($env{'request.course.sec'} ne '') {
17329:20): $checkrole .= "/$env{'request.course.sec'}";
17330:20): }
17331:20): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17332:20): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17333:20): return;
17334:20): }
17335:20): }
17336:20): }
1.1075.2.74 raeburn 17337: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17338: $env{'user.name'});
17339: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17340: my $redirecturl;
17341: if ($what[0]) {
17342: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17343: $redirecturl='/adm/email?critical=display';
17344: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17345: return (1, $url);
17346: }
17347: }
17348: }
17349: return ();
17350: }
17351:
1.1075.2.64 raeburn 17352: # Use:
17353: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17354: #
17355: ##################################################
17356: # password associated functions #
17357: ##################################################
17358: sub des_keys {
17359: # Make a new key for DES encryption.
17360: # Each key has two parts which are returned separately.
17361: # Please note: Each key must be passed through the &hex function
17362: # before it is output to the web browser. The hex versions cannot
17363: # be used to decrypt.
17364: my @hexstr=('0','1','2','3','4','5','6','7',
17365: '8','9','a','b','c','d','e','f');
17366: my $lkey='';
17367: for (0..7) {
17368: $lkey.=$hexstr[rand(15)];
17369: }
17370: my $ukey='';
17371: for (0..7) {
17372: $ukey.=$hexstr[rand(15)];
17373: }
17374: return ($lkey,$ukey);
17375: }
17376:
17377: sub des_decrypt {
17378: my ($key,$cyphertext) = @_;
17379: my $keybin=pack("H16",$key);
17380: my $cypher;
17381: if ($Crypt::DES::VERSION>=2.03) {
17382: $cypher=new Crypt::DES $keybin;
17383: } else {
17384: $cypher=new DES $keybin;
17385: }
1.1075.2.106 raeburn 17386: my $plaintext='';
17387: my $cypherlength = length($cyphertext);
17388: my $numchunks = int($cypherlength/32);
17389: for (my $j=0; $j<$numchunks; $j++) {
17390: my $start = $j*32;
17391: my $cypherblock = substr($cyphertext,$start,32);
17392: my $chunk =
17393: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17394: $chunk .=
17395: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17396: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17397: $plaintext .= $chunk;
17398: }
1.1075.2.64 raeburn 17399: return $plaintext;
17400: }
17401:
1.1075.2.141. .5(raebu 17402:20): sub get_requested_shorturls {
.1(raebu 17403:20): my ($cdom,$cnum,$navmap) = @_;
17404:20): return unless (ref($navmap));
.5(raebu 17405:20): my ($numnew,$errors);
.1(raebu 17406:20): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17407:20): if (@toshorten) {
17408:20): my (%maps,%resources,%titles);
17409:20): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17410:20): 'shorturls',$cdom,$cnum);
17411:20): if (keys(%resources)) {
.5(raebu 17412:20): my %tocreate;
.1(raebu 17413:20): foreach my $item (sort {$a <=> $b} (@toshorten)) {
17414:20): my $symb = $resources{$item};
17415:20): if ($symb) {
17416:20): $tocreate{$cnum.'&'.$symb} = 1;
17417:20): }
17418:20): }
.5(raebu 17419:20): if (keys(%tocreate)) {
17420:20): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
17421:20): \%tocreate);
17422:20): }
.1(raebu 17423:20): }
.5(raebu 17424:20): }
17425:20): return ($numnew,$errors);
17426:20): }
17427:20):
17428:20): sub make_short_symbs {
17429:20): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
17430:20): my ($numnew,@errors);
17431:20): if (ref($tocreateref) eq 'HASH') {
17432:20): my %tocreate = %{$tocreateref};
.1(raebu 17433:20): if (keys(%tocreate)) {
17434:20): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17435:20): my $su = Short::URL->new(no_vowels => 1);
17436:20): my $init = '';
17437:20): my (%newunique,%addcourse,%courseonly,%failed);
17438:20): # get lock on tiny db
17439:20): my $now = time;
.5(raebu 17440:20): if ($lockuser eq '') {
17441:20): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
17442:20): }
.1(raebu 17443:20): my $lockhash = {
.5(raebu 17444:20): "lock\0$now" => $lockuser,
.1(raebu 17445:20): };
17446:20): my $tries = 0;
17447:20): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17448:20): my ($code,$error);
17449:20): while (($gotlock ne 'ok') && ($tries<3)) {
17450:20): $tries ++;
17451:20): sleep 1;
17452:20): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17453:20): }
17454:20): if ($gotlock eq 'ok') {
17455:20): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17456:20): \%addcourse,\%courseonly,\%failed);
17457:20): if (keys(%failed)) {
17458:20): my $numfailed = scalar(keys(%failed));
17459:20): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17460:20): }
17461:20): if (keys(%newunique)) {
17462:20): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17463:20): if ($putres eq 'ok') {
17464:20): $numnew = scalar(keys(%newunique));
17465:20): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17466:20): unless ($newputres eq 'ok') {
17467:20): push(@errors,&mt('error: could not store course look-up of short URLs'));
17468:20): }
17469:20): } else {
17470:20): push(@errors,&mt('error: could not store unique six character URLs'));
17471:20): }
17472:20): }
17473:20): }
17474:20): }
17475:20): }
17476:20): return ($numnew,\@errors);
17477:20): }
17478:20):
17479:20): sub shorten_symbs {
17480:20): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
17481:20): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
17482:20): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
17483:20): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
17484:20): my (%possibles,%collisions);
17485:20): foreach my $key (keys(%{$tocreate})) {
17486:20): my $num = String::CRC32::crc32($key);
17487:20): my $tiny = $su->encode($num,$init);
17488:20): if ($tiny) {
17489:20): $possibles{$tiny} = $key;
17490:20): }
17491:20): }
17492:20): if (!$init) {
17493:20): $init = 1;
17494:20): } else {
17495:20): $init ++;
17496:20): }
17497:20): if (keys(%possibles)) {
17498:20): my @posstiny = keys(%possibles);
17499:20): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
17500:20): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
17501:20): if (keys(%currtiny)) {
17502:20): foreach my $key (keys(%currtiny)) {
17503:20): next if ($currtiny{$key} eq '');
17504:20): if ($currtiny{$key} eq $possibles{$key}) {
17505:20): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
17506:20): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17507:20): $courseonly->{$tsymb} = $key;
17508:20): }
17509:20): } else {
17510:20): $collisions{$possibles{$key}} = 1;
17511:20): }
17512:20): delete($possibles{$key});
17513:20): }
17514:20): }
17515:20): foreach my $key (keys(%possibles)) {
17516:20): $newunique->{$key} = $possibles{$key};
17517:20): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
17518:20): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17519:20): $addcourse->{$tsymb} = $key;
17520:20): }
17521:20): }
17522:20): }
17523:20): if (keys(%collisions)) {
17524:20): if ($init <5) {
17525:20): if (!$init) {
17526:20): $init = 1;
17527:20): } else {
17528:20): $init ++;
17529:20): }
17530:20): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
17531:20): $newunique,$addcourse,$courseonly,$failed);
17532:20): } else {
17533:20): foreach my $key (keys(%collisions)) {
17534:20): $failed->{$key} = 1;
17535:20): $failed->{$key} = 1;
17536:20): }
17537:20): }
17538:20): }
17539:20): return $init;
17540:20): }
17541:20):
1.1075.2.135 raeburn 17542: sub is_nonframeable {
17543: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17544: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17545: return if (($remprotocol eq '') || ($remhost eq ''));
17546:
17547: $remprotocol = lc($remprotocol);
17548: $remhost = lc($remhost);
17549: my $remport = 80;
17550: if ($remprotocol eq 'https') {
17551: $remport = 443;
17552: }
17553: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17554: if ($cached) {
17555: unless ($nocache) {
17556: if ($result) {
17557: return 1;
17558: } else {
17559: return 0;
17560: }
17561: }
17562: }
17563: my $uselink;
17564: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.141. .2(raebu 17565:20): my $ua = LWP::UserAgent->new;
17566:20): $ua->timeout(5);
17567:20): my $response=$ua->request($request);
1.1075.2.135 raeburn 17568: if ($response->is_success()) {
17569: my $secpolicy = lc($response->header('content-security-policy'));
17570: my $xframeop = lc($response->header('x-frame-options'));
17571: $secpolicy =~ s/^\s+|\s+$//g;
17572: $xframeop =~ s/^\s+|\s+$//g;
17573: if (($secpolicy ne '') || ($xframeop ne '')) {
17574: my $remotehost = $remprotocol.'://'.$remhost;
17575: my ($origin,$protocol,$port);
17576: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17577: $port = $ENV{'SERVER_PORT'};
17578: } else {
17579: $port = 80;
17580: }
17581: if ($absolute eq '') {
17582: $protocol = 'http:';
17583: if ($port == 443) {
17584: $protocol = 'https:';
17585: }
17586: $origin = $protocol.'//'.lc($hostname);
17587: } else {
17588: $origin = lc($absolute);
17589: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17590: }
17591: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17592: my $framepolicy = $1;
17593: $framepolicy =~ s/^\s+|\s+$//g;
17594: my @policies = split(/\s+/,$framepolicy);
17595: if (@policies) {
17596: if (grep(/^\Q'none'\E$/,@policies)) {
17597: $uselink = 1;
17598: } else {
17599: $uselink = 1;
17600: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17601: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17602: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17603: undef($uselink);
17604: }
17605: if ($uselink) {
17606: if (grep(/^\Q'self'\E$/,@policies)) {
17607: if (($origin ne '') && ($remotehost eq $origin)) {
17608: undef($uselink);
17609: }
17610: }
17611: }
17612: if ($uselink) {
17613: my @possok;
17614: if ($ip ne '') {
17615: push(@possok,$ip);
17616: }
17617: my $hoststr = '';
17618: foreach my $part (reverse(split(/\./,$hostname))) {
17619: if ($hoststr eq '') {
17620: $hoststr = $part;
17621: } else {
17622: $hoststr = "$part.$hoststr";
17623: }
17624: if ($hoststr eq $hostname) {
17625: push(@possok,$hostname);
17626: } else {
17627: push(@possok,"*.$hoststr");
17628: }
17629: }
17630: if (@possok) {
17631: foreach my $poss (@possok) {
17632: last if (!$uselink);
17633: foreach my $policy (@policies) {
17634: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17635: undef($uselink);
17636: last;
17637: }
17638: }
17639: }
17640: }
17641: }
17642: }
17643: }
17644: } elsif ($xframeop ne '') {
17645: $uselink = 1;
17646: my @policies = split(/\s*,\s*/,$xframeop);
17647: if (@policies) {
17648: unless (grep(/^deny$/,@policies)) {
17649: if ($origin ne '') {
17650: if (grep(/^sameorigin$/,@policies)) {
17651: if ($remotehost eq $origin) {
17652: undef($uselink);
17653: }
17654: }
17655: if ($uselink) {
17656: foreach my $policy (@policies) {
17657: if ($policy =~ /^allow-from\s*(.+)$/) {
17658: my $allowfrom = $1;
17659: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17660: undef($uselink);
17661: last;
17662: }
17663: }
17664: }
17665: }
17666: }
17667: }
17668: }
17669: }
17670: }
17671: }
17672: if ($nocache) {
17673: if ($cached) {
17674: my $devalidate;
17675: if ($uselink && !$result) {
17676: $devalidate = 1;
17677: } elsif (!$uselink && $result) {
17678: $devalidate = 1;
17679: }
17680: if ($devalidate) {
17681: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17682: }
17683: }
17684: } else {
17685: if ($uselink) {
17686: $result = 1;
17687: } else {
17688: $result = 0;
17689: }
17690: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17691: }
17692: return $uselink;
17693: }
17694:
1.112 bowersj2 17695: 1;
17696: __END__;
1.41 ng 17697:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>