Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.8
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.161. .8(raebu 4:22): # $Id: loncommon.pm,v 1.1075.2.161.2.7 2022/05/31 23:11:47 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.1075.2.161. .7(raebu 64:22): use Apache::lonnavmaps();
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.161. .1(raebu 86:21): use String::CRC32();
87:21): 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.143 raeburn 433: 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.143 raeburn 448: if (courseadv == 'condition') {
449: if (document.getElementById('courseadv')) {
450: courseadv = document.getElementById('courseadv').value;
451: }
452: }
453: 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.143 raeburn 485: 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.143 raeburn 496: if ($courseadv eq 'only') {
497: $callargs .= ",'',1,'$courseadv'";
498: } elsif ($courseadv eq 'none') {
499: $callargs .= ",'','','$courseadv'";
500: } elsif ($courseadv eq 'condition') {
501: $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.1075.2.161. .6(raebu 1224:22): =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
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:
1.1075.2.161. .6(raebu 1248:22): $links_target will optionally be set to a target (_top, _parent or _self).
1249:22):
1.44 bowersj2 1250: =cut
1251:
1252: sub help_open_topic {
1.1075.2.161. .6(raebu 1253:22): my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1254: $text = "" if (not defined $text);
1.44 bowersj2 1255: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1256: $width = 500 if (not defined $width);
1.44 bowersj2 1257: $height = 400 if (not defined $height);
1258: my $filename = $topic;
1259: $filename =~ s/ /_/g;
1260:
1.48 bowersj2 1261: my $template = "";
1262: my $link;
1.572 banghart 1263:
1.159 www 1264: $topic=~s/\W/\_/g;
1.44 bowersj2 1265:
1.572 banghart 1266: if (!$stayOnPage) {
1.1075.2.50 raeburn 1267: if ($env{'browser.mobile'}) {
1268: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1269: } else {
1270: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1271: }
1.1037 www 1272: } elsif ($stayOnPage eq 'popup') {
1273: $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 1274: } else {
1.48 bowersj2 1275: $link = "/adm/help/${filename}.hlp";
1276: }
1277:
1278: # Add the text
1.1075.2.161. .6(raebu 1279:22): my $target = ' target="_top"';
1280:22): if ($links_target) {
1281:22): $target = ' target="'.$links_target.'"';
1282:22): } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
1283:22): $target = '';
1284:22): }
1.755 neumanie 1285: if ($text ne "") {
1.763 bisitz 1286: $template.='<span class="LC_help_open_topic">'
1.1075.2.161. .6(raebu 1287:22): .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1288: .$text.'</a>';
1.48 bowersj2 1289: }
1290:
1.763 bisitz 1291: # (Always) Add the graphic
1.179 matthew 1292: my $title = &mt('Online Help');
1.667 raeburn 1293: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1294: if ($imgid ne '') {
1295: $imgid = ' id="'.$imgid.'"';
1296: }
1.1075.2.161. .6(raebu 1297:22): $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1298: .'<img src="'.$helpicon.'" border="0"'
1299: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1300: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1301: .' /></a>';
1302: if ($text ne "") {
1303: $template.='</span>';
1304: }
1.44 bowersj2 1305: return $template;
1306:
1.106 bowersj2 1307: }
1308:
1309: # This is a quicky function for Latex cheatsheet editing, since it
1310: # appears in at least four places
1311: sub helpLatexCheatsheet {
1.1037 www 1312: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1313: my $out;
1.106 bowersj2 1314: my $addOther = '';
1.732 raeburn 1315: if ($topic) {
1.1037 www 1316: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1317: }
1318: $out = '<span>' # Start cheatsheet
1319: .$addOther
1320: .'<span>'
1.1037 www 1321: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1322: .'</span> <span>'
1.1037 www 1323: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1324: .'</span>';
1.732 raeburn 1325: unless ($not_author) {
1.763 bisitz 1326: $out .= ' <span>'
1.1037 www 1327: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1328: .'</span> <span>'
1.1075.2.78 raeburn 1329: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1330: .'</span>';
1.732 raeburn 1331: }
1.763 bisitz 1332: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1333: return $out;
1.172 www 1334: }
1335:
1.430 albertel 1336: sub general_help {
1337: my $helptopic='Student_Intro';
1338: if ($env{'request.role'}=~/^(ca|au)/) {
1339: $helptopic='Authoring_Intro';
1.907 raeburn 1340: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1341: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1342: } elsif ($env{'request.role'}=~/^dc/) {
1343: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1344: }
1345: return $helptopic;
1346: }
1347:
1348: sub update_help_link {
1349: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1350: my $origurl = $ENV{'REQUEST_URI'};
1351: $origurl=~s|^/~|/priv/|;
1352: my $timestamp = time;
1353: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1354: $$datum = &escape($$datum);
1355: }
1356:
1357: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1358: my $output .= <<"ENDOUTPUT";
1359: <script type="text/javascript">
1.824 bisitz 1360: // <![CDATA[
1.430 albertel 1361: banner_link = '$banner_link';
1.824 bisitz 1362: // ]]>
1.430 albertel 1363: </script>
1364: ENDOUTPUT
1365: return $output;
1366: }
1367:
1368: # now just updates the help link and generates a blue icon
1.193 raeburn 1369: sub help_open_menu {
1.1075.2.161. .6(raebu 1370:22): my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1371: = @_;
1.949 droeschl 1372: $stayOnPage = 1;
1.430 albertel 1373: my $output;
1374: if ($component_help) {
1375: if (!$text) {
1376: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1075.2.161. .6(raebu 1377:22): $width,$height,'',$links_target);
1.430 albertel 1378: } else {
1379: my $help_text;
1380: $help_text=&unescape($topic);
1381: $output='<table><tr><td>'.
1382: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1075.2.161. .6(raebu 1383:22): $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1384: }
1385: }
1386: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1387: return $output.$banner_link;
1388: }
1389:
1390: sub top_nav_help {
1.1075.2.158 raeburn 1391: my ($text,$linkattr) = @_;
1.436 albertel 1392: $text = &mt($text);
1.1075.2.60 raeburn 1393: my $stay_on_page;
1394: unless ($env{'environment.remote'} eq 'on') {
1395: $stay_on_page = 1;
1396: }
1.1075.2.61 raeburn 1397: my ($link,$banner_link);
1398: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1399: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1400: : "javascript:helpMenu('open')";
1401: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1402: }
1.201 raeburn 1403: my $title = &mt('Get help');
1.1075.2.61 raeburn 1404: if ($link) {
1405: return <<"END";
1.436 albertel 1406: $banner_link
1.1075.2.158 raeburn 1407: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1408: END
1.1075.2.61 raeburn 1409: } else {
1410: return ' '.$text.' ';
1411: }
1.436 albertel 1412: }
1413:
1414: sub help_menu_js {
1.1075.2.52 raeburn 1415: my ($httphost) = @_;
1.949 droeschl 1416: my $stayOnPage = 1;
1.436 albertel 1417: my $width = 620;
1418: my $height = 600;
1.430 albertel 1419: my $helptopic=&general_help();
1.1075.2.52 raeburn 1420: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1421: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1422: my $start_page =
1423: &Apache::loncommon::start_page('Help Menu', undef,
1424: {'frameset' => 1,
1425: 'js_ready' => 1,
1.1075.2.136 raeburn 1426: 'use_absolute' => $httphost,
1.331 albertel 1427: 'add_entries' => {
1428: 'border' => '0',
1.579 raeburn 1429: 'rows' => "110,*",},});
1.331 albertel 1430: my $end_page =
1431: &Apache::loncommon::end_page({'frameset' => 1,
1432: 'js_ready' => 1,});
1433:
1.436 albertel 1434: my $template .= <<"ENDTEMPLATE";
1435: <script type="text/javascript">
1.877 bisitz 1436: // <![CDATA[
1.253 albertel 1437: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1438: var banner_link = '';
1.243 raeburn 1439: function helpMenu(target) {
1440: var caller = this;
1441: if (target == 'open') {
1442: var newWindow = null;
1443: try {
1.262 albertel 1444: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1445: }
1446: catch(error) {
1447: writeHelp(caller);
1448: return;
1449: }
1450: if (newWindow) {
1451: caller = newWindow;
1452: }
1.193 raeburn 1453: }
1.243 raeburn 1454: writeHelp(caller);
1455: return;
1456: }
1457: function writeHelp(caller) {
1.1075.2.61 raeburn 1458: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1459: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1460: caller.document.close();
1461: caller.focus();
1.193 raeburn 1462: }
1.877 bisitz 1463: // END LON-CAPA Internal -->
1.253 albertel 1464: // ]]>
1.436 albertel 1465: </script>
1.193 raeburn 1466: ENDTEMPLATE
1467: return $template;
1468: }
1469:
1.172 www 1470: sub help_open_bug {
1471: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1472: unless ($env{'user.adv'}) { return ''; }
1.172 www 1473: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1474: $text = "" if (not defined $text);
1475: $stayOnPage=1;
1.184 albertel 1476: $width = 600 if (not defined $width);
1477: $height = 600 if (not defined $height);
1.172 www 1478:
1479: $topic=~s/\W+/\+/g;
1480: my $link='';
1481: my $template='';
1.379 albertel 1482: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1483: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1484: if (!$stayOnPage)
1485: {
1486: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1487: }
1488: else
1489: {
1490: $link = $url;
1491: }
1.1075.2.161. .6(raebu 1492:22):
1493:22): my $target = '_top';
1494:22): if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1495:22): (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1496:22): $target = '_blank';
1497:22): }
1498:22):
1.172 www 1499: # Add the text
1500: if ($text ne "")
1501: {
1502: $template .=
1503: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1075.2.161. .6(raebu 1504:22): "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1505: }
1506:
1507: # Add the graphic
1.179 matthew 1508: my $title = &mt('Report a Bug');
1.215 albertel 1509: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1510: $template .= <<"ENDTEMPLATE";
1.1075.2.161. .6(raebu 1511:22): <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1512: ENDTEMPLATE
1513: if ($text ne '') { $template.='</td></tr></table>' };
1514: return $template;
1515:
1516: }
1517:
1518: sub help_open_faq {
1519: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1520: unless ($env{'user.adv'}) { return ''; }
1.172 www 1521: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1522: $text = "" if (not defined $text);
1523: $stayOnPage=1;
1524: $width = 350 if (not defined $width);
1525: $height = 400 if (not defined $height);
1526:
1527: $topic=~s/\W+/\+/g;
1528: my $link='';
1529: my $template='';
1530: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1531: if (!$stayOnPage)
1532: {
1533: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1534: }
1535: else
1536: {
1537: $link = $url;
1538: }
1539:
1540: # Add the text
1541: if ($text ne "")
1542: {
1543: $template .=
1.173 www 1544: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1545: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1546: }
1547:
1548: # Add the graphic
1.179 matthew 1549: my $title = &mt('View the FAQ');
1.215 albertel 1550: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1551: $template .= <<"ENDTEMPLATE";
1.436 albertel 1552: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1553: ENDTEMPLATE
1554: if ($text ne '') { $template.='</td></tr></table>' };
1555: return $template;
1556:
1.44 bowersj2 1557: }
1.37 matthew 1558:
1.180 matthew 1559: ###############################################################
1560: ###############################################################
1561:
1.45 matthew 1562: =pod
1563:
1.648 raeburn 1564: =item * &change_content_javascript():
1.256 matthew 1565:
1566: This and the next function allow you to create small sections of an
1567: otherwise static HTML page that you can update on the fly with
1568: Javascript, even in Netscape 4.
1569:
1570: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1571: must be written to the HTML page once. It will prove the Javascript
1572: function "change(name, content)". Calling the change function with the
1573: name of the section
1574: you want to update, matching the name passed to C<changable_area>, and
1575: the new content you want to put in there, will put the content into
1576: that area.
1577:
1578: B<Note>: Netscape 4 only reserves enough space for the changable area
1579: to contain room for the original contents. You need to "make space"
1580: for whatever changes you wish to make, and be B<sure> to check your
1581: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1582: it's adequate for updating a one-line status display, but little more.
1583: This script will set the space to 100% width, so you only need to
1584: worry about height in Netscape 4.
1585:
1586: Modern browsers are much less limiting, and if you can commit to the
1587: user not using Netscape 4, this feature may be used freely with
1588: pretty much any HTML.
1589:
1590: =cut
1591:
1592: sub change_content_javascript {
1593: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1594: if ($env{'browser.type'} eq 'netscape' &&
1595: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1596: return (<<NETSCAPE4);
1597: function change(name, content) {
1598: doc = document.layers[name+"___escape"].layers[0].document;
1599: doc.open();
1600: doc.write(content);
1601: doc.close();
1602: }
1603: NETSCAPE4
1604: } else {
1605: # Otherwise, we need to use semi-standards-compliant code
1606: # (technically, "innerHTML" isn't standard but the equivalent
1607: # is really scary, and every useful browser supports it
1608: return (<<DOMBASED);
1609: function change(name, content) {
1610: element = document.getElementById(name);
1611: element.innerHTML = content;
1612: }
1613: DOMBASED
1614: }
1615: }
1616:
1617: =pod
1618:
1.648 raeburn 1619: =item * &changable_area($name,$origContent):
1.256 matthew 1620:
1621: This provides a "changable area" that can be modified on the fly via
1622: the Javascript code provided in C<change_content_javascript>. $name is
1623: the name you will use to reference the area later; do not repeat the
1624: same name on a given HTML page more then once. $origContent is what
1625: the area will originally contain, which can be left blank.
1626:
1627: =cut
1628:
1629: sub changable_area {
1630: my ($name, $origContent) = @_;
1631:
1.258 albertel 1632: if ($env{'browser.type'} eq 'netscape' &&
1633: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1634: # If this is netscape 4, we need to use the Layer tag
1635: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1636: } else {
1637: return "<span id='$name'>$origContent</span>";
1638: }
1639: }
1640:
1641: =pod
1642:
1.648 raeburn 1643: =item * &viewport_geometry_js
1.590 raeburn 1644:
1645: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1646:
1647: =cut
1648:
1649:
1650: sub viewport_geometry_js {
1651: return <<"GEOMETRY";
1652: var Geometry = {};
1653: function init_geometry() {
1654: if (Geometry.init) { return };
1655: Geometry.init=1;
1656: if (window.innerHeight) {
1657: Geometry.getViewportHeight = function() { return window.innerHeight; };
1658: Geometry.getViewportWidth = function() { return window.innerWidth; };
1659: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1660: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1661: }
1662: else if (document.documentElement && document.documentElement.clientHeight) {
1663: Geometry.getViewportHeight =
1664: function() { return document.documentElement.clientHeight; };
1665: Geometry.getViewportWidth =
1666: function() { return document.documentElement.clientWidth; };
1667:
1668: Geometry.getHorizontalScroll =
1669: function() { return document.documentElement.scrollLeft; };
1670: Geometry.getVerticalScroll =
1671: function() { return document.documentElement.scrollTop; };
1672: }
1673: else if (document.body.clientHeight) {
1674: Geometry.getViewportHeight =
1675: function() { return document.body.clientHeight; };
1676: Geometry.getViewportWidth =
1677: function() { return document.body.clientWidth; };
1678: Geometry.getHorizontalScroll =
1679: function() { return document.body.scrollLeft; };
1680: Geometry.getVerticalScroll =
1681: function() { return document.body.scrollTop; };
1682: }
1683: }
1684:
1685: GEOMETRY
1686: }
1687:
1688: =pod
1689:
1.648 raeburn 1690: =item * &viewport_size_js()
1.590 raeburn 1691:
1692: 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.
1693:
1694: =cut
1695:
1696: sub viewport_size_js {
1697: my $geometry = &viewport_geometry_js();
1698: return <<"DIMS";
1699:
1700: $geometry
1701:
1702: function getViewportDims(width,height) {
1703: init_geometry();
1704: width.value = Geometry.getViewportWidth();
1705: height.value = Geometry.getViewportHeight();
1706: return;
1707: }
1708:
1709: DIMS
1710: }
1711:
1712: =pod
1713:
1.648 raeburn 1714: =item * &resize_textarea_js()
1.565 albertel 1715:
1716: emits the needed javascript to resize a textarea to be as big as possible
1717:
1718: creates a function resize_textrea that takes two IDs first should be
1719: the id of the element to resize, second should be the id of a div that
1720: surrounds everything that comes after the textarea, this routine needs
1721: to be attached to the <body> for the onload and onresize events.
1722:
1.648 raeburn 1723: =back
1.565 albertel 1724:
1725: =cut
1726:
1727: sub resize_textarea_js {
1.590 raeburn 1728: my $geometry = &viewport_geometry_js();
1.565 albertel 1729: return <<"RESIZE";
1730: <script type="text/javascript">
1.824 bisitz 1731: // <![CDATA[
1.590 raeburn 1732: $geometry
1.565 albertel 1733:
1.588 albertel 1734: function getX(element) {
1735: var x = 0;
1736: while (element) {
1737: x += element.offsetLeft;
1738: element = element.offsetParent;
1739: }
1740: return x;
1741: }
1742: function getY(element) {
1743: var y = 0;
1744: while (element) {
1745: y += element.offsetTop;
1746: element = element.offsetParent;
1747: }
1748: return y;
1749: }
1750:
1751:
1.565 albertel 1752: function resize_textarea(textarea_id,bottom_id) {
1753: init_geometry();
1754: var textarea = document.getElementById(textarea_id);
1755: //alert(textarea);
1756:
1.588 albertel 1757: var textarea_top = getY(textarea);
1.565 albertel 1758: var textarea_height = textarea.offsetHeight;
1759: var bottom = document.getElementById(bottom_id);
1.588 albertel 1760: var bottom_top = getY(bottom);
1.565 albertel 1761: var bottom_height = bottom.offsetHeight;
1762: var window_height = Geometry.getViewportHeight();
1.588 albertel 1763: var fudge = 23;
1.565 albertel 1764: var new_height = window_height-fudge-textarea_top-bottom_height;
1765: if (new_height < 300) {
1766: new_height = 300;
1767: }
1768: textarea.style.height=new_height+'px';
1769: }
1.824 bisitz 1770: // ]]>
1.565 albertel 1771: </script>
1772: RESIZE
1773:
1774: }
1775:
1.1075.2.112 raeburn 1776: sub colorfuleditor_js {
1777: return <<"COLORFULEDIT"
1778: <script type="text/javascript">
1779: // <![CDATA[>
1780: function fold_box(curDepth, lastresource){
1781:
1782: // we need a list because there can be several blocks you need to fold in one tag
1783: var block = document.getElementsByName('foldblock_'+curDepth);
1784: // but there is only one folding button per tag
1785: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1786:
1787: if(block.item(0).style.display == 'none'){
1788:
1789: foldbutton.value = '@{[&mt("Hide")]}';
1790: for (i = 0; i < block.length; i++){
1791: block.item(i).style.display = '';
1792: }
1793: }else{
1794:
1795: foldbutton.value = '@{[&mt("Show")]}';
1796: for (i = 0; i < block.length; i++){
1797: // block.item(i).style.visibility = 'collapse';
1798: block.item(i).style.display = 'none';
1799: }
1800: };
1801: saveState(lastresource);
1802: }
1803:
1804: function saveState (lastresource) {
1805:
1806: var tag_list = getTagList();
1807: if(tag_list != null){
1808: var timestamp = new Date().getTime();
1809: var key = lastresource;
1810:
1811: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1812: // starting with timestamp
1813: var value = timestamp+';';
1814:
1815: // building the list of key-value pairs
1816: for(var i = 0; i < tag_list.length; i++){
1817: value += tag_list[i]+',';
1818: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1819: }
1820:
1821: // only iterate whole storage if nothing to override
1822: if(localStorage.getItem(key) == null){
1823:
1824: // prevent storage from growing large
1825: if(localStorage.length > 50){
1826: var regex_getTimestamp = /^(?:\d)+;/;
1827: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1828: var oldest_key;
1829:
1830: for(var i = 1; i < localStorage.length; i++){
1831: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1832: oldest_key = localStorage.key(i);
1833: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1834: }
1835: }
1836: localStorage.removeItem(oldest_key);
1837: }
1838: }
1839: localStorage.setItem(key,value);
1840: }
1841: }
1842:
1843: // restore folding status of blocks (on page load)
1844: function restoreState (lastresource) {
1845: if(localStorage.getItem(lastresource) != null){
1846: var key = lastresource;
1847: var value = localStorage.getItem(key);
1848: var regex_delTimestamp = /^\d+;/;
1849:
1850: value.replace(regex_delTimestamp, '');
1851:
1852: var valueArr = value.split(';');
1853: var pairs;
1854: var elements;
1855: for (var i = 0; i < valueArr.length; i++){
1856: pairs = valueArr[i].split(',');
1857: elements = document.getElementsByName(pairs[0]);
1858:
1859: for (var j = 0; j < elements.length; j++){
1860: elements[j].style.display = pairs[1];
1861: if (pairs[1] == "none"){
1862: var regex_id = /([_\\d]+)\$/;
1863: regex_id.exec(pairs[0]);
1864: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1865: }
1866: }
1867: }
1868: }
1869: }
1870:
1871: function getTagList () {
1872:
1873: var stringToSearch = document.lonhomework.innerHTML;
1874:
1875: var ret = new Array();
1876: var regex_findBlock = /(foldblock_.*?)"/g;
1877: var tag_list = stringToSearch.match(regex_findBlock);
1878:
1879: if(tag_list != null){
1880: for(var i = 0; i < tag_list.length; i++){
1881: ret.push(tag_list[i].replace(/"/, ''));
1882: }
1883: }
1884: return ret;
1885: }
1886:
1887: function saveScrollPosition (resource) {
1888: var tag_list = getTagList();
1889:
1890: // we dont always want to jump to the first block
1891: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1892: if(\$(window).scrollTop() > 170){
1893: if(tag_list != null){
1894: var result;
1895: for(var i = 0; i < tag_list.length; i++){
1896: if(isElementInViewport(tag_list[i])){
1897: result += tag_list[i]+';';
1898: }
1899: }
1900: sessionStorage.setItem('anchor_'+resource, result);
1901: }
1902: } else {
1903: // we dont need to save zero, just delete the item to leave everything tidy
1904: sessionStorage.removeItem('anchor_'+resource);
1905: }
1906: }
1907:
1908: function restoreScrollPosition(resource){
1909:
1910: var elem = sessionStorage.getItem('anchor_'+resource);
1911: if(elem != null){
1912: var tag_list = elem.split(';');
1913: var elem_list;
1914:
1915: for(var i = 0; i < tag_list.length; i++){
1916: elem_list = document.getElementsByName(tag_list[i]);
1917:
1918: if(elem_list.length > 0){
1919: elem = elem_list[0];
1920: break;
1921: }
1922: }
1923: elem.scrollIntoView();
1924: }
1925: }
1926:
1927: function isElementInViewport(el) {
1928:
1929: // change to last element instead of first
1930: var elem = document.getElementsByName(el);
1931: var rect = elem[0].getBoundingClientRect();
1932:
1933: return (
1934: rect.top >= 0 &&
1935: rect.left >= 0 &&
1936: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1937: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1938: );
1939: }
1940:
1941: function autosize(depth){
1942: var cmInst = window['cm'+depth];
1943: var fitsizeButton = document.getElementById('fitsize'+depth);
1944:
1945: // is fixed size, switching to dynamic
1946: if (sessionStorage.getItem("autosized_"+depth) == null) {
1947: cmInst.setSize("","auto");
1948: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1949: sessionStorage.setItem("autosized_"+depth, "yes");
1950:
1951: // is dynamic size, switching to fixed
1952: } else {
1953: cmInst.setSize("","300px");
1954: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1955: sessionStorage.removeItem("autosized_"+depth);
1956: }
1957: }
1958:
1959:
1960:
1961: // ]]>
1962: </script>
1963: COLORFULEDIT
1964: }
1965:
1966: sub xmleditor_js {
1967: return <<XMLEDIT
1968: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1969: <script type="text/javascript">
1970: // <![CDATA[>
1971:
1972: function saveScrollPosition (resource) {
1973:
1974: var scrollPos = \$(window).scrollTop();
1975: sessionStorage.setItem(resource,scrollPos);
1976: }
1977:
1978: function restoreScrollPosition(resource){
1979:
1980: var scrollPos = sessionStorage.getItem(resource);
1981: \$(window).scrollTop(scrollPos);
1982: }
1983:
1984: // unless internet explorer
1985: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1986:
1987: \$(document).ready(function() {
1988: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1989: });
1990: }
1991:
1992: // inserts text at cursor position into codemirror (xml editor only)
1993: function insertText(text){
1994: cm.focus();
1995: var curPos = cm.getCursor();
1996: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1997: }
1998: // ]]>
1999: </script>
2000: XMLEDIT
2001: }
2002:
2003: sub insert_folding_button {
2004: my $curDepth = $Apache::lonxml::curdepth;
2005: my $lastresource = $env{'request.ambiguous'};
2006:
2007: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2008: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2009: }
2010:
2011:
1.565 albertel 2012: =pod
2013:
1.256 matthew 2014: =head1 Excel and CSV file utility routines
2015:
2016: =cut
2017:
2018: ###############################################################
2019: ###############################################################
2020:
2021: =pod
2022:
1.1075.2.56 raeburn 2023: =over 4
2024:
1.648 raeburn 2025: =item * &csv_translate($text)
1.37 matthew 2026:
1.185 www 2027: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2028: format.
2029:
2030: =cut
2031:
1.180 matthew 2032: ###############################################################
2033: ###############################################################
1.37 matthew 2034: sub csv_translate {
2035: my $text = shift;
2036: $text =~ s/\"/\"\"/g;
1.209 albertel 2037: $text =~ s/\n/ /g;
1.37 matthew 2038: return $text;
2039: }
1.180 matthew 2040:
2041: ###############################################################
2042: ###############################################################
2043:
2044: =pod
2045:
1.648 raeburn 2046: =item * &define_excel_formats()
1.180 matthew 2047:
2048: Define some commonly used Excel cell formats.
2049:
2050: Currently supported formats:
2051:
2052: =over 4
2053:
2054: =item header
2055:
2056: =item bold
2057:
2058: =item h1
2059:
2060: =item h2
2061:
2062: =item h3
2063:
1.256 matthew 2064: =item h4
2065:
2066: =item i
2067:
1.180 matthew 2068: =item date
2069:
2070: =back
2071:
2072: Inputs: $workbook
2073:
2074: Returns: $format, a hash reference.
2075:
1.1057 foxr 2076:
1.180 matthew 2077: =cut
2078:
2079: ###############################################################
2080: ###############################################################
2081: sub define_excel_formats {
2082: my ($workbook) = @_;
2083: my $format;
2084: $format->{'header'} = $workbook->add_format(bold => 1,
2085: bottom => 1,
2086: align => 'center');
2087: $format->{'bold'} = $workbook->add_format(bold=>1);
2088: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2089: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2090: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2091: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2092: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2093: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2094: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2095: return $format;
2096: }
2097:
2098: ###############################################################
2099: ###############################################################
1.113 bowersj2 2100:
2101: =pod
2102:
1.648 raeburn 2103: =item * &create_workbook()
1.255 matthew 2104:
2105: Create an Excel worksheet. If it fails, output message on the
2106: request object and return undefs.
2107:
2108: Inputs: Apache request object
2109:
2110: Returns (undef) on failure,
2111: Excel worksheet object, scalar with filename, and formats
2112: from &Apache::loncommon::define_excel_formats on success
2113:
2114: =cut
2115:
2116: ###############################################################
2117: ###############################################################
2118: sub create_workbook {
2119: my ($r) = @_;
2120: #
2121: # Create the excel spreadsheet
2122: my $filename = '/prtspool/'.
1.258 albertel 2123: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2124: time.'_'.rand(1000000000).'.xls';
2125: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2126: if (! defined($workbook)) {
2127: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2128: $r->print(
2129: '<p class="LC_error">'
2130: .&mt('Problems occurred in creating the new Excel file.')
2131: .' '.&mt('This error has been logged.')
2132: .' '.&mt('Please alert your LON-CAPA administrator.')
2133: .'</p>'
2134: );
1.255 matthew 2135: return (undef);
2136: }
2137: #
1.1014 foxr 2138: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2139: #
2140: my $format = &Apache::loncommon::define_excel_formats($workbook);
2141: return ($workbook,$filename,$format);
2142: }
2143:
2144: ###############################################################
2145: ###############################################################
2146:
2147: =pod
2148:
1.648 raeburn 2149: =item * &create_text_file()
1.113 bowersj2 2150:
1.542 raeburn 2151: Create a file to write to and eventually make available to the user.
1.256 matthew 2152: If file creation fails, outputs an error message on the request object and
2153: return undefs.
1.113 bowersj2 2154:
1.256 matthew 2155: Inputs: Apache request object, and file suffix
1.113 bowersj2 2156:
1.256 matthew 2157: Returns (undef) on failure,
2158: Filehandle and filename on success.
1.113 bowersj2 2159:
2160: =cut
2161:
1.256 matthew 2162: ###############################################################
2163: ###############################################################
2164: sub create_text_file {
2165: my ($r,$suffix) = @_;
2166: if (! defined($suffix)) { $suffix = 'txt'; };
2167: my $fh;
2168: my $filename = '/prtspool/'.
1.258 albertel 2169: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2170: time.'_'.rand(1000000000).'.'.$suffix;
2171: $fh = Apache::File->new('>/home/httpd'.$filename);
2172: if (! defined($fh)) {
2173: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2174: $r->print(
2175: '<p class="LC_error">'
2176: .&mt('Problems occurred in creating the output file.')
2177: .' '.&mt('This error has been logged.')
2178: .' '.&mt('Please alert your LON-CAPA administrator.')
2179: .'</p>'
2180: );
1.113 bowersj2 2181: }
1.256 matthew 2182: return ($fh,$filename)
1.113 bowersj2 2183: }
2184:
2185:
1.256 matthew 2186: =pod
1.113 bowersj2 2187:
2188: =back
2189:
2190: =cut
1.37 matthew 2191:
2192: ###############################################################
1.33 matthew 2193: ## Home server <option> list generating code ##
2194: ###############################################################
1.35 matthew 2195:
1.169 www 2196: # ------------------------------------------
2197:
2198: sub domain_select {
2199: my ($name,$value,$multiple)=@_;
2200: my %domains=map {
1.514 albertel 2201: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2202: } &Apache::lonnet::all_domains();
1.169 www 2203: if ($multiple) {
2204: $domains{''}=&mt('Any domain');
1.550 albertel 2205: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2206: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2207: } else {
1.550 albertel 2208: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2209: return &select_form($name,$value,\%domains);
1.169 www 2210: }
2211: }
2212:
1.282 albertel 2213: #-------------------------------------------
2214:
2215: =pod
2216:
1.519 raeburn 2217: =head1 Routines for form select boxes
2218:
2219: =over 4
2220:
1.648 raeburn 2221: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2222:
2223: Returns a string containing a <select> element int multiple mode
2224:
2225:
2226: Args:
2227: $name - name of the <select> element
1.506 raeburn 2228: $value - scalar or array ref of values that should already be selected
1.282 albertel 2229: $size - number of rows long the select element is
1.283 albertel 2230: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2231: (shown text should already have been &mt())
1.506 raeburn 2232: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2233:
1.282 albertel 2234: =cut
2235:
2236: #-------------------------------------------
1.169 www 2237: sub multiple_select_form {
1.284 albertel 2238: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2239: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2240: my $output='';
1.191 matthew 2241: if (! defined($size)) {
2242: $size = 4;
1.283 albertel 2243: if (scalar(keys(%$hash))<4) {
2244: $size = scalar(keys(%$hash));
1.191 matthew 2245: }
2246: }
1.734 bisitz 2247: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2248: my @order;
1.506 raeburn 2249: if (ref($order) eq 'ARRAY') {
2250: @order = @{$order};
2251: } else {
2252: @order = sort(keys(%$hash));
1.501 banghart 2253: }
2254: if (exists($$hash{'select_form_order'})) {
2255: @order = @{$$hash{'select_form_order'}};
2256: }
2257:
1.284 albertel 2258: foreach my $key (@order) {
1.356 albertel 2259: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2260: $output.='selected="selected" ' if ($selected{$key});
2261: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2262: }
2263: $output.="</select>\n";
2264: return $output;
2265: }
2266:
1.88 www 2267: #-------------------------------------------
2268:
2269: =pod
2270:
1.1075.2.115 raeburn 2271: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2272:
2273: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2274: allow a user to select options from a ref to a hash containing:
2275: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2276: a javascript onchange item, e.g., onchange="this.form.submit();".
2277: An optional arg -- $readonly -- if true will cause the select form
2278: to be disabled, e.g., for the case where an instructor has a section-
2279: specific role, and is viewing/modifying parameters.
1.970 raeburn 2280:
1.88 www 2281: See lonrights.pm for an example invocation and use.
2282:
2283: =cut
2284:
2285: #-------------------------------------------
2286: sub select_form {
1.1075.2.115 raeburn 2287: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2288: return unless (ref($hashref) eq 'HASH');
2289: if ($onchange) {
2290: $onchange = ' onchange="'.$onchange.'"';
2291: }
1.1075.2.129 raeburn 2292: my $disabled;
2293: if ($readonly) {
2294: $disabled = ' disabled="disabled"';
2295: }
2296: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2297: my @keys;
1.970 raeburn 2298: if (exists($hashref->{'select_form_order'})) {
2299: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2300: } else {
1.970 raeburn 2301: @keys=sort(keys(%{$hashref}));
1.128 albertel 2302: }
1.356 albertel 2303: foreach my $key (@keys) {
2304: $selectform.=
2305: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2306: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2307: ">".$hashref->{$key}."</option>\n";
1.88 www 2308: }
2309: $selectform.="</select>";
2310: return $selectform;
2311: }
2312:
1.475 www 2313: # For display filters
2314:
2315: sub display_filter {
1.1074 raeburn 2316: my ($context) = @_;
1.475 www 2317: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2318: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2319: my $phraseinput = 'hidden';
2320: my $includeinput = 'hidden';
2321: my ($checked,$includetypestext);
2322: if ($env{'form.displayfilter'} eq 'containing') {
2323: $phraseinput = 'text';
2324: if ($context eq 'parmslog') {
2325: $includeinput = 'checkbox';
2326: if ($env{'form.includetypes'}) {
2327: $checked = ' checked="checked"';
2328: }
2329: $includetypestext = &mt('Include parameter types');
2330: }
2331: } else {
2332: $includetypestext = ' ';
2333: }
2334: my ($additional,$secondid,$thirdid);
2335: if ($context eq 'parmslog') {
2336: $additional =
2337: '<label><input type="'.$includeinput.'" name="includetypes"'.
2338: $checked.' name="includetypes" value="1" id="includetypes" />'.
2339: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2340: '</label>';
2341: $secondid = 'includetypes';
2342: $thirdid = 'includetypestext';
2343: }
2344: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2345: '$secondid','$thirdid')";
2346: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2347: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2348: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2349: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2350: &mt('Filter: [_1]',
1.477 www 2351: &select_form($env{'form.displayfilter'},
2352: 'displayfilter',
1.970 raeburn 2353: {'currentfolder' => 'Current folder/page',
1.477 www 2354: 'containing' => 'Containing phrase',
1.1074 raeburn 2355: 'none' => 'None'},$onchange)).' '.
2356: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2357: &HTML::Entities::encode($env{'form.containingphrase'}).
2358: '" />'.$additional;
2359: }
2360:
2361: sub display_filter_js {
2362: my $includetext = &mt('Include parameter types');
2363: return <<"ENDJS";
2364:
2365: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2366: var firstType = 'hidden';
2367: if (setter.options[setter.selectedIndex].value == 'containing') {
2368: firstType = 'text';
2369: }
2370: firstObject = document.getElementById(firstid);
2371: if (typeof(firstObject) == 'object') {
2372: if (firstObject.type != firstType) {
2373: changeInputType(firstObject,firstType);
2374: }
2375: }
2376: if (context == 'parmslog') {
2377: var secondType = 'hidden';
2378: if (firstType == 'text') {
2379: secondType = 'checkbox';
2380: }
2381: secondObject = document.getElementById(secondid);
2382: if (typeof(secondObject) == 'object') {
2383: if (secondObject.type != secondType) {
2384: changeInputType(secondObject,secondType);
2385: }
2386: }
2387: var textItem = document.getElementById(thirdid);
2388: var currtext = textItem.innerHTML;
2389: var newtext;
2390: if (firstType == 'text') {
2391: newtext = '$includetext';
2392: } else {
2393: newtext = ' ';
2394: }
2395: if (currtext != newtext) {
2396: textItem.innerHTML = newtext;
2397: }
2398: }
2399: return;
2400: }
2401:
2402: function changeInputType(oldObject,newType) {
2403: var newObject = document.createElement('input');
2404: newObject.type = newType;
2405: if (oldObject.size) {
2406: newObject.size = oldObject.size;
2407: }
2408: if (oldObject.value) {
2409: newObject.value = oldObject.value;
2410: }
2411: if (oldObject.name) {
2412: newObject.name = oldObject.name;
2413: }
2414: if (oldObject.id) {
2415: newObject.id = oldObject.id;
2416: }
2417: oldObject.parentNode.replaceChild(newObject,oldObject);
2418: return;
2419: }
2420:
2421: ENDJS
1.475 www 2422: }
2423:
1.167 www 2424: sub gradeleveldescription {
2425: my $gradelevel=shift;
2426: my %gradelevels=(0 => 'Not specified',
2427: 1 => 'Grade 1',
2428: 2 => 'Grade 2',
2429: 3 => 'Grade 3',
2430: 4 => 'Grade 4',
2431: 5 => 'Grade 5',
2432: 6 => 'Grade 6',
2433: 7 => 'Grade 7',
2434: 8 => 'Grade 8',
2435: 9 => 'Grade 9',
2436: 10 => 'Grade 10',
2437: 11 => 'Grade 11',
2438: 12 => 'Grade 12',
2439: 13 => 'Grade 13',
2440: 14 => '100 Level',
2441: 15 => '200 Level',
2442: 16 => '300 Level',
2443: 17 => '400 Level',
2444: 18 => 'Graduate Level');
2445: return &mt($gradelevels{$gradelevel});
2446: }
2447:
1.163 www 2448: sub select_level_form {
2449: my ($deflevel,$name)=@_;
2450: unless ($deflevel) { $deflevel=0; }
1.167 www 2451: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2452: for (my $i=0; $i<=18; $i++) {
2453: $selectform.="<option value=\"$i\" ".
1.253 albertel 2454: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2455: ">".&gradeleveldescription($i)."</option>\n";
2456: }
2457: $selectform.="</select>";
2458: return $selectform;
1.163 www 2459: }
1.167 www 2460:
1.35 matthew 2461: #-------------------------------------------
2462:
1.45 matthew 2463: =pod
2464:
1.1075.2.115 raeburn 2465: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2466:
2467: Returns a string containing a <select name='$name' size='1'> form to
2468: allow a user to select the domain to preform an operation in.
2469: See loncreateuser.pm for an example invocation and use.
2470:
1.90 www 2471: If the $includeempty flag is set, it also includes an empty choice ("no domain
2472: selected");
2473:
1.743 raeburn 2474: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2475:
1.910 raeburn 2476: 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.
2477:
1.1075.2.36 raeburn 2478: The optional $incdoms is a reference to an array of domains which will be the only available options.
2479:
1.1075.2.115 raeburn 2480: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2481:
2482: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2483:
1.35 matthew 2484: =cut
2485:
2486: #-------------------------------------------
1.34 matthew 2487: sub select_dom_form {
1.1075.2.115 raeburn 2488: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2489: if ($onchange) {
1.874 raeburn 2490: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2491: }
1.1075.2.115 raeburn 2492: if ($disabled) {
2493: $disabled = ' disabled="disabled"';
2494: }
1.1075.2.36 raeburn 2495: my (@domains,%exclude);
1.910 raeburn 2496: if (ref($incdoms) eq 'ARRAY') {
2497: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2498: } else {
2499: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2500: }
1.90 www 2501: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2502: if (ref($excdoms) eq 'ARRAY') {
2503: map { $exclude{$_} = 1; } @{$excdoms};
2504: }
1.1075.2.115 raeburn 2505: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2506: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2507: next if ($exclude{$dom});
1.356 albertel 2508: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2509: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2510: if ($showdomdesc) {
2511: if ($dom ne '') {
2512: my $domdesc = &Apache::lonnet::domain($dom,'description');
2513: if ($domdesc ne '') {
2514: $selectdomain .= ' ('.$domdesc.')';
2515: }
2516: }
2517: }
2518: $selectdomain .= "</option>\n";
1.34 matthew 2519: }
2520: $selectdomain.="</select>";
2521: return $selectdomain;
2522: }
2523:
1.35 matthew 2524: #-------------------------------------------
2525:
1.45 matthew 2526: =pod
2527:
1.648 raeburn 2528: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2529:
1.586 raeburn 2530: input: 4 arguments (two required, two optional) -
2531: $domain - domain of new user
2532: $name - name of form element
2533: $default - Value of 'default' causes a default item to be first
2534: option, and selected by default.
2535: $hide - Value of 'hide' causes hiding of the name of the server,
2536: if 1 server found, or default, if 0 found.
1.594 raeburn 2537: output: returns 2 items:
1.586 raeburn 2538: (a) form element which contains either:
2539: (i) <select name="$name">
2540: <option value="$hostid1">$hostid $servers{$hostid}</option>
2541: <option value="$hostid2">$hostid $servers{$hostid}</option>
2542: </select>
2543: form item if there are multiple library servers in $domain, or
2544: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2545: if there is only one library server in $domain.
2546:
2547: (b) number of library servers found.
2548:
2549: See loncreateuser.pm for example of use.
1.35 matthew 2550:
2551: =cut
2552:
2553: #-------------------------------------------
1.586 raeburn 2554: sub home_server_form_item {
2555: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2556: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2557: my $result;
2558: my $numlib = keys(%servers);
2559: if ($numlib > 1) {
2560: $result .= '<select name="'.$name.'" />'."\n";
2561: if ($default) {
1.804 bisitz 2562: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2563: '</option>'."\n";
2564: }
2565: foreach my $hostid (sort(keys(%servers))) {
2566: $result.= '<option value="'.$hostid.'">'.
2567: $hostid.' '.$servers{$hostid}."</option>\n";
2568: }
2569: $result .= '</select>'."\n";
2570: } elsif ($numlib == 1) {
2571: my $hostid;
2572: foreach my $item (keys(%servers)) {
2573: $hostid = $item;
2574: }
2575: $result .= '<input type="hidden" name="'.$name.'" value="'.
2576: $hostid.'" />';
2577: if (!$hide) {
2578: $result .= $hostid.' '.$servers{$hostid};
2579: }
2580: $result .= "\n";
2581: } elsif ($default) {
2582: $result .= '<input type="hidden" name="'.$name.
2583: '" value="default" />';
2584: if (!$hide) {
2585: $result .= &mt('default');
2586: }
2587: $result .= "\n";
1.33 matthew 2588: }
1.586 raeburn 2589: return ($result,$numlib);
1.33 matthew 2590: }
1.112 bowersj2 2591:
2592: =pod
2593:
1.534 albertel 2594: =back
2595:
1.112 bowersj2 2596: =cut
1.87 matthew 2597:
2598: ###############################################################
1.112 bowersj2 2599: ## Decoding User Agent ##
1.87 matthew 2600: ###############################################################
2601:
2602: =pod
2603:
1.112 bowersj2 2604: =head1 Decoding the User Agent
2605:
2606: =over 4
2607:
2608: =item * &decode_user_agent()
1.87 matthew 2609:
2610: Inputs: $r
2611:
2612: Outputs:
2613:
2614: =over 4
2615:
1.112 bowersj2 2616: =item * $httpbrowser
1.87 matthew 2617:
1.112 bowersj2 2618: =item * $clientbrowser
1.87 matthew 2619:
1.112 bowersj2 2620: =item * $clientversion
1.87 matthew 2621:
1.112 bowersj2 2622: =item * $clientmathml
1.87 matthew 2623:
1.112 bowersj2 2624: =item * $clientunicode
1.87 matthew 2625:
1.112 bowersj2 2626: =item * $clientos
1.87 matthew 2627:
1.1075.2.42 raeburn 2628: =item * $clientmobile
2629:
2630: =item * $clientinfo
2631:
1.1075.2.77 raeburn 2632: =item * $clientosversion
2633:
1.87 matthew 2634: =back
2635:
1.157 matthew 2636: =back
2637:
1.87 matthew 2638: =cut
2639:
2640: ###############################################################
2641: ###############################################################
2642: sub decode_user_agent {
1.247 albertel 2643: my ($r)=@_;
1.87 matthew 2644: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2645: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2646: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2647: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2648: my $clientbrowser='unknown';
2649: my $clientversion='0';
2650: my $clientmathml='';
2651: my $clientunicode='0';
1.1075.2.42 raeburn 2652: my $clientmobile=0;
1.1075.2.77 raeburn 2653: my $clientosversion='';
1.87 matthew 2654: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2655: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2656: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2657: $clientbrowser=$bname;
2658: $httpbrowser=~/$vreg/i;
2659: $clientversion=$1;
2660: $clientmathml=($clientversion>=$minv);
2661: $clientunicode=($clientversion>=$univ);
2662: }
2663: }
2664: my $clientos='unknown';
1.1075.2.42 raeburn 2665: my $clientinfo;
1.87 matthew 2666: if (($httpbrowser=~/linux/i) ||
2667: ($httpbrowser=~/unix/i) ||
2668: ($httpbrowser=~/ux/i) ||
2669: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2670: if (($httpbrowser=~/vax/i) ||
2671: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2672: if ($httpbrowser=~/next/i) { $clientos='next'; }
2673: if (($httpbrowser=~/mac/i) ||
2674: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2675: if ($httpbrowser=~/win/i) {
2676: $clientos='win';
2677: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2678: $clientosversion = $1;
2679: }
2680: }
1.87 matthew 2681: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2682: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2683: $clientmobile=lc($1);
2684: }
2685: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2686: $clientinfo = 'firefox-'.$1;
2687: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2688: $clientinfo = 'chromeframe-'.$1;
2689: }
1.87 matthew 2690: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2691: $clientunicode,$clientos,$clientmobile,$clientinfo,
2692: $clientosversion);
1.87 matthew 2693: }
2694:
1.32 matthew 2695: ###############################################################
2696: ## Authentication changing form generation subroutines ##
2697: ###############################################################
2698: ##
2699: ## All of the authform_xxxxxxx subroutines take their inputs in a
2700: ## hash, and have reasonable default values.
2701: ##
2702: ## formname = the name given in the <form> tag.
1.35 matthew 2703: #-------------------------------------------
2704:
1.45 matthew 2705: =pod
2706:
1.112 bowersj2 2707: =head1 Authentication Routines
2708:
2709: =over 4
2710:
1.648 raeburn 2711: =item * &authform_xxxxxx()
1.35 matthew 2712:
2713: The authform_xxxxxx subroutines provide javascript and html forms which
2714: handle some of the conveniences required for authentication forms.
2715: This is not an optimal method, but it works.
2716:
2717: =over 4
2718:
1.112 bowersj2 2719: =item * authform_header
1.35 matthew 2720:
1.112 bowersj2 2721: =item * authform_authorwarning
1.35 matthew 2722:
1.112 bowersj2 2723: =item * authform_nochange
1.35 matthew 2724:
1.112 bowersj2 2725: =item * authform_kerberos
1.35 matthew 2726:
1.112 bowersj2 2727: =item * authform_internal
1.35 matthew 2728:
1.112 bowersj2 2729: =item * authform_filesystem
1.35 matthew 2730:
2731: =back
2732:
1.648 raeburn 2733: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2734:
1.35 matthew 2735: =cut
2736:
2737: #-------------------------------------------
1.32 matthew 2738: sub authform_header{
2739: my %in = (
2740: formname => 'cu',
1.80 albertel 2741: kerb_def_dom => '',
1.32 matthew 2742: @_,
2743: );
2744: $in{'formname'} = 'document.' . $in{'formname'};
2745: my $result='';
1.80 albertel 2746:
2747: #---------------------------------------------- Code for upper case translation
2748: my $Javascript_toUpperCase;
2749: unless ($in{kerb_def_dom}) {
2750: $Javascript_toUpperCase =<<"END";
2751: switch (choice) {
2752: case 'krb': currentform.elements[choicearg].value =
2753: currentform.elements[choicearg].value.toUpperCase();
2754: break;
2755: default:
2756: }
2757: END
2758: } else {
2759: $Javascript_toUpperCase = "";
2760: }
2761:
1.165 raeburn 2762: my $radioval = "'nochange'";
1.591 raeburn 2763: if (defined($in{'curr_authtype'})) {
2764: if ($in{'curr_authtype'} ne '') {
2765: $radioval = "'".$in{'curr_authtype'}."arg'";
2766: }
1.174 matthew 2767: }
1.165 raeburn 2768: my $argfield = 'null';
1.591 raeburn 2769: if (defined($in{'mode'})) {
1.165 raeburn 2770: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2771: if (defined($in{'curr_autharg'})) {
2772: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2773: $argfield = "'$in{'curr_autharg'}'";
2774: }
2775: }
2776: }
2777: }
2778:
1.32 matthew 2779: $result.=<<"END";
2780: var current = new Object();
1.165 raeburn 2781: current.radiovalue = $radioval;
2782: current.argfield = $argfield;
1.32 matthew 2783:
2784: function changed_radio(choice,currentform) {
2785: var choicearg = choice + 'arg';
2786: // If a radio button in changed, we need to change the argfield
2787: if (current.radiovalue != choice) {
2788: current.radiovalue = choice;
2789: if (current.argfield != null) {
2790: currentform.elements[current.argfield].value = '';
2791: }
2792: if (choice == 'nochange') {
2793: current.argfield = null;
2794: } else {
2795: current.argfield = choicearg;
2796: switch(choice) {
2797: case 'krb':
2798: currentform.elements[current.argfield].value =
2799: "$in{'kerb_def_dom'}";
2800: break;
2801: default:
2802: break;
2803: }
2804: }
2805: }
2806: return;
2807: }
1.22 www 2808:
1.32 matthew 2809: function changed_text(choice,currentform) {
2810: var choicearg = choice + 'arg';
2811: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2812: $Javascript_toUpperCase
1.32 matthew 2813: // clear old field
2814: if ((current.argfield != choicearg) && (current.argfield != null)) {
2815: currentform.elements[current.argfield].value = '';
2816: }
2817: current.argfield = choicearg;
2818: }
2819: set_auth_radio_buttons(choice,currentform);
2820: return;
1.20 www 2821: }
1.32 matthew 2822:
2823: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2824: var numauthchoices = currentform.login.length;
2825: if (typeof numauthchoices == "undefined") {
2826: return;
2827: }
1.32 matthew 2828: var i=0;
1.986 raeburn 2829: while (i < numauthchoices) {
1.32 matthew 2830: if (currentform.login[i].value == newvalue) { break; }
2831: i++;
2832: }
1.986 raeburn 2833: if (i == numauthchoices) {
1.32 matthew 2834: return;
2835: }
2836: current.radiovalue = newvalue;
2837: currentform.login[i].checked = true;
2838: return;
2839: }
2840: END
2841: return $result;
2842: }
2843:
1.1075.2.20 raeburn 2844: sub authform_authorwarning {
1.32 matthew 2845: my $result='';
1.144 matthew 2846: $result='<i>'.
2847: &mt('As a general rule, only authors or co-authors should be '.
2848: 'filesystem authenticated '.
2849: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2850: return $result;
2851: }
2852:
1.1075.2.20 raeburn 2853: sub authform_nochange {
1.32 matthew 2854: my %in = (
2855: formname => 'document.cu',
2856: kerb_def_dom => 'MSU.EDU',
2857: @_,
2858: );
1.1075.2.20 raeburn 2859: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2860: my $result;
1.1075.2.20 raeburn 2861: if (!$authnum) {
2862: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2863: } else {
2864: $result = '<label>'.&mt('[_1] Do not change login data',
2865: '<input type="radio" name="login" value="nochange" '.
2866: 'checked="checked" onclick="'.
1.281 albertel 2867: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2868: '</label>';
1.586 raeburn 2869: }
1.32 matthew 2870: return $result;
2871: }
2872:
1.591 raeburn 2873: sub authform_kerberos {
1.32 matthew 2874: my %in = (
2875: formname => 'document.cu',
2876: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2877: kerb_def_auth => 'krb4',
1.32 matthew 2878: @_,
2879: );
1.586 raeburn 2880: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2881: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2882: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2883: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2884: $check5 = ' checked="checked"';
1.80 albertel 2885: } else {
1.772 bisitz 2886: $check4 = ' checked="checked"';
1.80 albertel 2887: }
1.1075.2.117 raeburn 2888: if ($in{'readonly'}) {
2889: $disabled = ' disabled="disabled"';
2890: }
1.165 raeburn 2891: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2892: if (defined($in{'curr_authtype'})) {
2893: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2894: $krbcheck = ' checked="checked"';
1.623 raeburn 2895: if (defined($in{'mode'})) {
2896: if ($in{'mode'} eq 'modifyuser') {
2897: $krbcheck = '';
2898: }
2899: }
1.591 raeburn 2900: if (defined($in{'curr_kerb_ver'})) {
2901: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2902: $check5 = ' checked="checked"';
1.591 raeburn 2903: $check4 = '';
2904: } else {
1.772 bisitz 2905: $check4 = ' checked="checked"';
1.591 raeburn 2906: $check5 = '';
2907: }
1.586 raeburn 2908: }
1.591 raeburn 2909: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2910: $krbarg = $in{'curr_autharg'};
2911: }
1.586 raeburn 2912: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2913: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2914: $result =
2915: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2916: $in{'curr_autharg'},$krbver);
2917: } else {
2918: $result =
2919: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2920: }
2921: return $result;
2922: }
2923: }
2924: } else {
2925: if ($authnum == 1) {
1.784 bisitz 2926: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2927: }
2928: }
1.586 raeburn 2929: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2930: return;
1.587 raeburn 2931: } elsif ($authtype eq '') {
1.591 raeburn 2932: if (defined($in{'mode'})) {
1.587 raeburn 2933: if ($in{'mode'} eq 'modifycourse') {
2934: if ($authnum == 1) {
1.1075.2.117 raeburn 2935: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2936: }
2937: }
2938: }
1.586 raeburn 2939: }
2940: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2941: if ($authtype eq '') {
2942: $authtype = '<input type="radio" name="login" value="krb" '.
2943: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2944: $krbcheck.$disabled.' />';
1.586 raeburn 2945: }
2946: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2947: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2948: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2949: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2950: $in{'curr_authtype'} eq 'krb4')) {
2951: $result .= &mt
1.144 matthew 2952: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2953: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2954: '<label>'.$authtype,
1.281 albertel 2955: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2956: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2957: 'onchange="'.$jscall.'"'.$disabled.' />',
2958: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2959: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2960: '</label>');
1.586 raeburn 2961: } elsif ($can_assign{'krb4'}) {
2962: $result .= &mt
2963: ('[_1] Kerberos authenticated with domain [_2] '.
2964: '[_3] Version 4 [_4]',
2965: '<label>'.$authtype,
2966: '</label><input type="text" size="10" name="krbarg" '.
2967: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2968: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2969: '<label><input type="hidden" name="krbver" value="4" />',
2970: '</label>');
2971: } elsif ($can_assign{'krb5'}) {
2972: $result .= &mt
2973: ('[_1] Kerberos authenticated with domain [_2] '.
2974: '[_3] Version 5 [_4]',
2975: '<label>'.$authtype,
2976: '</label><input type="text" size="10" name="krbarg" '.
2977: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2978: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2979: '<label><input type="hidden" name="krbver" value="5" />',
2980: '</label>');
2981: }
1.32 matthew 2982: return $result;
2983: }
2984:
1.1075.2.20 raeburn 2985: sub authform_internal {
1.586 raeburn 2986: my %in = (
1.32 matthew 2987: formname => 'document.cu',
2988: kerb_def_dom => 'MSU.EDU',
2989: @_,
2990: );
1.1075.2.117 raeburn 2991: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2992: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2993: if ($in{'readonly'}) {
2994: $disabled = ' disabled="disabled"';
2995: }
1.591 raeburn 2996: if (defined($in{'curr_authtype'})) {
2997: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2998: if ($can_assign{'int'}) {
1.772 bisitz 2999: $intcheck = 'checked="checked" ';
1.623 raeburn 3000: if (defined($in{'mode'})) {
3001: if ($in{'mode'} eq 'modifyuser') {
3002: $intcheck = '';
3003: }
3004: }
1.591 raeburn 3005: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3006: $intarg = $in{'curr_autharg'};
3007: }
3008: } else {
3009: $result = &mt('Currently internally authenticated.');
3010: return $result;
1.165 raeburn 3011: }
3012: }
1.586 raeburn 3013: } else {
3014: if ($authnum == 1) {
1.784 bisitz 3015: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3016: }
3017: }
3018: if (!$can_assign{'int'}) {
3019: return;
1.587 raeburn 3020: } elsif ($authtype eq '') {
1.591 raeburn 3021: if (defined($in{'mode'})) {
1.587 raeburn 3022: if ($in{'mode'} eq 'modifycourse') {
3023: if ($authnum == 1) {
1.1075.2.117 raeburn 3024: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3025: }
3026: }
3027: }
1.165 raeburn 3028: }
1.586 raeburn 3029: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3030: if ($authtype eq '') {
3031: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3032: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3033: }
1.605 bisitz 3034: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3035: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3036: $result = &mt
1.144 matthew 3037: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3038: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3039: $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 3040: return $result;
3041: }
3042:
1.1075.2.20 raeburn 3043: sub authform_local {
1.32 matthew 3044: my %in = (
3045: formname => 'document.cu',
3046: kerb_def_dom => 'MSU.EDU',
3047: @_,
3048: );
1.1075.2.117 raeburn 3049: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3050: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3051: if ($in{'readonly'}) {
3052: $disabled = ' disabled="disabled"';
3053: }
1.591 raeburn 3054: if (defined($in{'curr_authtype'})) {
3055: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3056: if ($can_assign{'loc'}) {
1.772 bisitz 3057: $loccheck = 'checked="checked" ';
1.623 raeburn 3058: if (defined($in{'mode'})) {
3059: if ($in{'mode'} eq 'modifyuser') {
3060: $loccheck = '';
3061: }
3062: }
1.591 raeburn 3063: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3064: $locarg = $in{'curr_autharg'};
3065: }
3066: } else {
3067: $result = &mt('Currently using local (institutional) authentication.');
3068: return $result;
1.165 raeburn 3069: }
3070: }
1.586 raeburn 3071: } else {
3072: if ($authnum == 1) {
1.784 bisitz 3073: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3074: }
3075: }
3076: if (!$can_assign{'loc'}) {
3077: return;
1.587 raeburn 3078: } elsif ($authtype eq '') {
1.591 raeburn 3079: if (defined($in{'mode'})) {
1.587 raeburn 3080: if ($in{'mode'} eq 'modifycourse') {
3081: if ($authnum == 1) {
1.1075.2.117 raeburn 3082: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3083: }
3084: }
3085: }
1.165 raeburn 3086: }
1.586 raeburn 3087: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3088: if ($authtype eq '') {
3089: $authtype = '<input type="radio" name="login" value="loc" '.
3090: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3091: $jscall.'"'.$disabled.' />';
1.586 raeburn 3092: }
3093: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3094: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3095: $result = &mt('[_1] Local Authentication with argument [_2]',
3096: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3097: return $result;
3098: }
3099:
1.1075.2.20 raeburn 3100: sub authform_filesystem {
1.32 matthew 3101: my %in = (
3102: formname => 'document.cu',
3103: kerb_def_dom => 'MSU.EDU',
3104: @_,
3105: );
1.1075.2.117 raeburn 3106: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3107: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3108: if ($in{'readonly'}) {
3109: $disabled = ' disabled="disabled"';
3110: }
1.591 raeburn 3111: if (defined($in{'curr_authtype'})) {
3112: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3113: if ($can_assign{'fsys'}) {
1.772 bisitz 3114: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3115: if (defined($in{'mode'})) {
3116: if ($in{'mode'} eq 'modifyuser') {
3117: $fsyscheck = '';
3118: }
3119: }
1.586 raeburn 3120: } else {
3121: $result = &mt('Currently Filesystem Authenticated.');
3122: return $result;
3123: }
3124: }
3125: } else {
3126: if ($authnum == 1) {
1.784 bisitz 3127: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3128: }
3129: }
3130: if (!$can_assign{'fsys'}) {
3131: return;
1.587 raeburn 3132: } elsif ($authtype eq '') {
1.591 raeburn 3133: if (defined($in{'mode'})) {
1.587 raeburn 3134: if ($in{'mode'} eq 'modifycourse') {
3135: if ($authnum == 1) {
1.1075.2.117 raeburn 3136: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3137: }
3138: }
3139: }
1.586 raeburn 3140: }
3141: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3142: if ($authtype eq '') {
3143: $authtype = '<input type="radio" name="login" value="fsys" '.
3144: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3145: $jscall.'"'.$disabled.' />';
1.586 raeburn 3146: }
1.1075.2.158 raeburn 3147: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3148: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3149: $result = &mt
1.144 matthew 3150: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1075.2.158 raeburn 3151: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3152: return $result;
3153: }
3154:
1.586 raeburn 3155: sub get_assignable_auth {
3156: my ($dom) = @_;
3157: if ($dom eq '') {
3158: $dom = $env{'request.role.domain'};
3159: }
3160: my %can_assign = (
3161: krb4 => 1,
3162: krb5 => 1,
3163: int => 1,
3164: loc => 1,
3165: );
3166: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3167: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3168: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3169: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3170: my $context;
3171: if ($env{'request.role'} =~ /^au/) {
3172: $context = 'author';
1.1075.2.117 raeburn 3173: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3174: $context = 'domain';
3175: } elsif ($env{'request.course.id'}) {
3176: $context = 'course';
3177: }
3178: if ($context) {
3179: if (ref($authhash->{$context}) eq 'HASH') {
3180: %can_assign = %{$authhash->{$context}};
3181: }
3182: }
3183: }
3184: }
3185: my $authnum = 0;
3186: foreach my $key (keys(%can_assign)) {
3187: if ($can_assign{$key}) {
3188: $authnum ++;
3189: }
3190: }
3191: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3192: $authnum --;
3193: }
3194: return ($authnum,%can_assign);
3195: }
3196:
1.1075.2.137 raeburn 3197: sub check_passwd_rules {
3198: my ($domain,$plainpass) = @_;
3199: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3200: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3201: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3202: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3203: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3204: if ($passwdconf{'min'} > $min) {
3205: $min = $passwdconf{'min'};
3206: }
1.1075.2.137 raeburn 3207: }
3208: if ($passwdconf{'max'} =~ /^\d+$/) {
3209: $max = $passwdconf{'max'};
3210: }
3211: @chars = @{$passwdconf{'chars'}};
3212: }
3213: if (($min) && (length($plainpass) < $min)) {
3214: push(@brokerule,'min');
3215: }
3216: if (($max) && (length($plainpass) > $max)) {
3217: push(@brokerule,'max');
3218: }
3219: if (@chars) {
3220: my %rules;
3221: map { $rules{$_} = 1; } @chars;
3222: if ($rules{'uc'}) {
3223: unless ($plainpass =~ /[A-Z]/) {
3224: push(@brokerule,'uc');
3225: }
3226: }
3227: if ($rules{'lc'}) {
3228: unless ($plainpass =~ /[a-z]/) {
3229: push(@brokerule,'lc');
3230: }
3231: }
3232: if ($rules{'num'}) {
3233: unless ($plainpass =~ /\d/) {
3234: push(@brokerule,'num');
3235: }
3236: }
3237: if ($rules{'spec'}) {
3238: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3239: push(@brokerule,'spec');
3240: }
3241: }
3242: }
3243: if (@brokerule) {
3244: my %rulenames = &Apache::lonlocal::texthash(
3245: uc => 'At least one upper case letter',
3246: lc => 'At least one lower case letter',
3247: num => 'At least one number',
3248: spec => 'At least one non-alphanumeric',
3249: );
3250: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3251: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3252: $rulenames{'num'} .= ': 0123456789';
3253: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3254: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3255: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3256: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3257: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3258: if (grep(/^$rule$/,@brokerule)) {
3259: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3260: }
3261: }
3262: $warning .= '</ul>';
3263: }
3264: if (wantarray) {
3265: return @brokerule;
3266: }
3267: return $warning;
3268: }
3269:
1.1075.2.161. .5(raebu 3270:22): sub passwd_validation_js {
3271:22): my ($currpasswdval,$domain,$context,$id) = @_;
3272:22): my (%passwdconf,$alertmsg);
3273:22): if ($context eq 'linkprot') {
3274:22): my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3275:22): if (ref($domconfig{'ltisec'}) eq 'HASH') {
3276:22): if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3277:22): %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3278:22): }
3279:22): }
3280:22): if ($id eq 'add') {
3281:22): $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3282:22): } elsif ($id =~ /^\d+$/) {
3283:22): my $pos = $id+1;
3284:22): $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3285:22): } else {
3286:22): $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3287:22): }
3288:22): } else {
3289:22): %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3290:22): $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3291:22): }
3292:22): my ($min,$max,@chars,$numrules,$intargjs,%alert);
3293:22): $numrules = 0;
3294:22): $min = $Apache::lonnet::passwdmin;
3295:22): if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3296:22): if ($passwdconf{'min'} =~ /^\d+$/) {
3297:22): if ($passwdconf{'min'} > $min) {
3298:22): $min = $passwdconf{'min'};
3299:22): }
3300:22): }
3301:22): if ($passwdconf{'max'} =~ /^\d+$/) {
3302:22): $max = $passwdconf{'max'};
3303:22): $numrules ++;
3304:22): }
3305:22): @chars = @{$passwdconf{'chars'}};
3306:22): if (@chars) {
3307:22): $numrules ++;
3308:22): }
3309:22): }
3310:22): if ($min > 0) {
3311:22): $numrules ++;
3312:22): }
3313:22): if (($min > 0) || ($max ne '') || (@chars > 0)) {
3314:22): if ($min) {
3315:22): $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3316:22): }
3317:22): if ($max) {
3318:22): $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3319:22): }
3320:22): my (@charalerts,@charrules);
3321:22): if (@chars) {
3322:22): if (grep(/^uc$/,@chars)) {
3323:22): push(@charalerts,&mt('contain at least one upper case letter'));
3324:22): push(@charrules,'uc');
3325:22): }
3326:22): if (grep(/^lc$/,@chars)) {
3327:22): push(@charalerts,&mt('contain at least one lower case letter'));
3328:22): push(@charrules,'lc');
3329:22): }
3330:22): if (grep(/^num$/,@chars)) {
3331:22): push(@charalerts,&mt('contain at least one number'));
3332:22): push(@charrules,'num');
3333:22): }
3334:22): if (grep(/^spec$/,@chars)) {
3335:22): push(@charalerts,&mt('contain at least one non-alphanumeric'));
3336:22): push(@charrules,'spec');
3337:22): }
3338:22): }
3339:22): $intargjs = qq| var rulesmsg = '';\n|.
3340:22): qq| var currpwval = $currpasswdval;\n|;
3341:22): if ($min) {
3342:22): $intargjs .= qq|
3343:22): if (currpwval.length < $min) {
3344:22): rulesmsg += ' - $alert{min}';
3345:22): }
3346:22): |;
3347:22): }
3348:22): if ($max) {
3349:22): $intargjs .= qq|
3350:22): if (currpwval.length > $max) {
3351:22): rulesmsg += ' - $alert{max}';
3352:22): }
3353:22): |;
3354:22): }
3355:22): if (@chars > 0) {
3356:22): my $charrulestr = '"'.join('","',@charrules).'"';
3357:22): my $charalertstr = '"'.join('","',@charalerts).'"';
3358:22): $intargjs .= qq| var brokerules = new Array();\n|.
3359:22): qq| var charrules = new Array($charrulestr);\n|.
3360:22): qq| var charalerts = new Array($charalertstr);\n|;
3361:22): my %rules;
3362:22): map { $rules{$_} = 1; } @chars;
3363:22): if ($rules{'uc'}) {
3364:22): $intargjs .= qq|
3365:22): var ucRegExp = /[A-Z]/;
3366:22): if (!ucRegExp.test(currpwval)) {
3367:22): brokerules.push('uc');
3368:22): }
3369:22): |;
3370:22): }
3371:22): if ($rules{'lc'}) {
3372:22): $intargjs .= qq|
3373:22): var lcRegExp = /[a-z]/;
3374:22): if (!lcRegExp.test(currpwval)) {
3375:22): brokerules.push('lc');
3376:22): }
3377:22): |;
3378:22): }
3379:22): if ($rules{'num'}) {
3380:22): $intargjs .= qq|
3381:22): var numRegExp = /[0-9]/;
3382:22): if (!numRegExp.test(currpwval)) {
3383:22): brokerules.push('num');
3384:22): }
3385:22): |;
3386:22): }
3387:22): if ($rules{'spec'}) {
3388:22): $intargjs .= q|
3389:22): var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3390:22): if (!specRegExp.test(currpwval)) {
3391:22): brokerules.push('spec');
3392:22): }
3393:22): |;
3394:22): }
3395:22): $intargjs .= qq|
3396:22): if (brokerules.length > 0) {
3397:22): for (var i=0; i<brokerules.length; i++) {
3398:22): for (var j=0; j<charrules.length; j++) {
3399:22): if (brokerules[i] == charrules[j]) {
3400:22): rulesmsg += ' - '+charalerts[j]+'\\n';
3401:22): break;
3402:22): }
3403:22): }
3404:22): }
3405:22): }
3406:22): |;
3407:22): }
3408:22): $intargjs .= qq|
3409:22): if (rulesmsg != '') {
3410:22): rulesmsg = '$alertmsg'+rulesmsg;
3411:22): alert(rulesmsg);
3412:22): return false;
3413:22): }
3414:22): |;
3415:22): }
3416:22): return ($numrules,$intargjs);
3417:22): }
3418:22):
1.80 albertel 3419: ###############################################################
3420: ## Get Kerberos Defaults for Domain ##
3421: ###############################################################
3422: ##
3423: ## Returns default kerberos version and an associated argument
3424: ## as listed in file domain.tab. If not listed, provides
3425: ## appropriate default domain and kerberos version.
3426: ##
3427: #-------------------------------------------
3428:
3429: =pod
3430:
1.648 raeburn 3431: =item * &get_kerberos_defaults()
1.80 albertel 3432:
3433: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3434: version and domain. If not found, it defaults to version 4 and the
3435: domain of the server.
1.80 albertel 3436:
1.648 raeburn 3437: =over 4
3438:
1.80 albertel 3439: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3440:
1.648 raeburn 3441: =back
3442:
3443: =back
3444:
1.80 albertel 3445: =cut
3446:
3447: #-------------------------------------------
3448: sub get_kerberos_defaults {
3449: my $domain=shift;
1.641 raeburn 3450: my ($krbdef,$krbdefdom);
3451: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3452: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3453: $krbdef = $domdefaults{'auth_def'};
3454: $krbdefdom = $domdefaults{'auth_arg_def'};
3455: } else {
1.80 albertel 3456: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3457: my $krbdefdom=$1;
3458: $krbdefdom=~tr/a-z/A-Z/;
3459: $krbdef = "krb4";
3460: }
3461: return ($krbdef,$krbdefdom);
3462: }
1.112 bowersj2 3463:
1.32 matthew 3464:
1.46 matthew 3465: ###############################################################
3466: ## Thesaurus Functions ##
3467: ###############################################################
1.20 www 3468:
1.46 matthew 3469: =pod
1.20 www 3470:
1.112 bowersj2 3471: =head1 Thesaurus Functions
3472:
3473: =over 4
3474:
1.648 raeburn 3475: =item * &initialize_keywords()
1.46 matthew 3476:
3477: Initializes the package variable %Keywords if it is empty. Uses the
3478: package variable $thesaurus_db_file.
3479:
3480: =cut
3481:
3482: ###################################################
3483:
3484: sub initialize_keywords {
3485: return 1 if (scalar keys(%Keywords));
3486: # If we are here, %Keywords is empty, so fill it up
3487: # Make sure the file we need exists...
3488: if (! -e $thesaurus_db_file) {
3489: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3490: " failed because it does not exist");
3491: return 0;
3492: }
3493: # Set up the hash as a database
3494: my %thesaurus_db;
3495: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3496: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3497: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3498: $thesaurus_db_file);
3499: return 0;
3500: }
3501: # Get the average number of appearances of a word.
3502: my $avecount = $thesaurus_db{'average.count'};
3503: # Put keywords (those that appear > average) into %Keywords
3504: while (my ($word,$data)=each (%thesaurus_db)) {
3505: my ($count,undef) = split /:/,$data;
3506: $Keywords{$word}++ if ($count > $avecount);
3507: }
3508: untie %thesaurus_db;
3509: # Remove special values from %Keywords.
1.356 albertel 3510: foreach my $value ('total.count','average.count') {
3511: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3512: }
1.46 matthew 3513: return 1;
3514: }
3515:
3516: ###################################################
3517:
3518: =pod
3519:
1.648 raeburn 3520: =item * &keyword($word)
1.46 matthew 3521:
3522: Returns true if $word is a keyword. A keyword is a word that appears more
3523: than the average number of times in the thesaurus database. Calls
3524: &initialize_keywords
3525:
3526: =cut
3527:
3528: ###################################################
1.20 www 3529:
3530: sub keyword {
1.46 matthew 3531: return if (!&initialize_keywords());
3532: my $word=lc(shift());
3533: $word=~s/\W//g;
3534: return exists($Keywords{$word});
1.20 www 3535: }
1.46 matthew 3536:
3537: ###############################################################
3538:
3539: =pod
1.20 www 3540:
1.648 raeburn 3541: =item * &get_related_words()
1.46 matthew 3542:
1.160 matthew 3543: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3544: an array of words. If the keyword is not in the thesaurus, an empty array
3545: will be returned. The order of the words returned is determined by the
3546: database which holds them.
3547:
3548: Uses global $thesaurus_db_file.
3549:
1.1057 foxr 3550:
1.46 matthew 3551: =cut
3552:
3553: ###############################################################
3554: sub get_related_words {
3555: my $keyword = shift;
3556: my %thesaurus_db;
3557: if (! -e $thesaurus_db_file) {
3558: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3559: "failed because the file does not exist");
3560: return ();
3561: }
3562: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3563: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3564: return ();
3565: }
3566: my @Words=();
1.429 www 3567: my $count=0;
1.46 matthew 3568: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3569: # The first element is the number of times
3570: # the word appears. We do not need it now.
1.429 www 3571: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3572: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3573: my $threshold=$mostfrequentcount/10;
3574: foreach my $possibleword (@RelatedWords) {
3575: my ($word,$wordcount)=split(/\,/,$possibleword);
3576: if ($wordcount>$threshold) {
3577: push(@Words,$word);
3578: $count++;
3579: if ($count>10) { last; }
3580: }
1.20 www 3581: }
3582: }
1.46 matthew 3583: untie %thesaurus_db;
3584: return @Words;
1.14 harris41 3585: }
1.46 matthew 3586:
1.112 bowersj2 3587: =pod
3588:
3589: =back
3590:
3591: =cut
1.61 www 3592:
3593: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3594: =pod
3595:
1.112 bowersj2 3596: =head1 User Name Functions
3597:
3598: =over 4
3599:
1.648 raeburn 3600: =item * &plainname($uname,$udom,$first)
1.81 albertel 3601:
1.112 bowersj2 3602: Takes a users logon name and returns it as a string in
1.226 albertel 3603: "first middle last generation" form
3604: if $first is set to 'lastname' then it returns it as
3605: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3606:
3607: =cut
1.61 www 3608:
1.295 www 3609:
1.81 albertel 3610: ###############################################################
1.61 www 3611: sub plainname {
1.226 albertel 3612: my ($uname,$udom,$first)=@_;
1.537 albertel 3613: return if (!defined($uname) || !defined($udom));
1.295 www 3614: my %names=&getnames($uname,$udom);
1.226 albertel 3615: my $name=&Apache::lonnet::format_name($names{'firstname'},
3616: $names{'middlename'},
3617: $names{'lastname'},
3618: $names{'generation'},$first);
3619: $name=~s/^\s+//;
1.62 www 3620: $name=~s/\s+$//;
3621: $name=~s/\s+/ /g;
1.353 albertel 3622: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3623: return $name;
1.61 www 3624: }
1.66 www 3625:
3626: # -------------------------------------------------------------------- Nickname
1.81 albertel 3627: =pod
3628:
1.648 raeburn 3629: =item * &nickname($uname,$udom)
1.81 albertel 3630:
3631: Gets a users name and returns it as a string as
3632:
3633: ""nickname""
1.66 www 3634:
1.81 albertel 3635: if the user has a nickname or
3636:
3637: "first middle last generation"
3638:
3639: if the user does not
3640:
3641: =cut
1.66 www 3642:
3643: sub nickname {
3644: my ($uname,$udom)=@_;
1.537 albertel 3645: return if (!defined($uname) || !defined($udom));
1.295 www 3646: my %names=&getnames($uname,$udom);
1.68 albertel 3647: my $name=$names{'nickname'};
1.66 www 3648: if ($name) {
3649: $name='"'.$name.'"';
3650: } else {
3651: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3652: $names{'lastname'}.' '.$names{'generation'};
3653: $name=~s/\s+$//;
3654: $name=~s/\s+/ /g;
3655: }
3656: return $name;
3657: }
3658:
1.295 www 3659: sub getnames {
3660: my ($uname,$udom)=@_;
1.537 albertel 3661: return if (!defined($uname) || !defined($udom));
1.433 albertel 3662: if ($udom eq 'public' && $uname eq 'public') {
3663: return ('lastname' => &mt('Public'));
3664: }
1.295 www 3665: my $id=$uname.':'.$udom;
3666: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3667: if ($cached) {
3668: return %{$names};
3669: } else {
3670: my %loadnames=&Apache::lonnet::get('environment',
3671: ['firstname','middlename','lastname','generation','nickname'],
3672: $udom,$uname);
3673: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3674: return %loadnames;
3675: }
3676: }
1.61 www 3677:
1.542 raeburn 3678: # -------------------------------------------------------------------- getemails
1.648 raeburn 3679:
1.542 raeburn 3680: =pod
3681:
1.648 raeburn 3682: =item * &getemails($uname,$udom)
1.542 raeburn 3683:
3684: Gets a user's email information and returns it as a hash with keys:
3685: notification, critnotification, permanentemail
3686:
3687: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3688: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3689:
1.648 raeburn 3690:
1.542 raeburn 3691: =cut
3692:
1.648 raeburn 3693:
1.466 albertel 3694: sub getemails {
3695: my ($uname,$udom)=@_;
3696: if ($udom eq 'public' && $uname eq 'public') {
3697: return;
3698: }
1.467 www 3699: if (!$udom) { $udom=$env{'user.domain'}; }
3700: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3701: my $id=$uname.':'.$udom;
3702: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3703: if ($cached) {
3704: return %{$names};
3705: } else {
3706: my %loadnames=&Apache::lonnet::get('environment',
3707: ['notification','critnotification',
3708: 'permanentemail'],
3709: $udom,$uname);
3710: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3711: return %loadnames;
3712: }
3713: }
3714:
1.551 albertel 3715: sub flush_email_cache {
3716: my ($uname,$udom)=@_;
3717: if (!$udom) { $udom =$env{'user.domain'}; }
3718: if (!$uname) { $uname=$env{'user.name'}; }
3719: return if ($udom eq 'public' && $uname eq 'public');
3720: my $id=$uname.':'.$udom;
3721: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3722: }
3723:
1.728 raeburn 3724: # -------------------------------------------------------------------- getlangs
3725:
3726: =pod
3727:
3728: =item * &getlangs($uname,$udom)
3729:
3730: Gets a user's language preference and returns it as a hash with key:
3731: language.
3732:
3733: =cut
3734:
3735:
3736: sub getlangs {
3737: my ($uname,$udom) = @_;
3738: if (!$udom) { $udom =$env{'user.domain'}; }
3739: if (!$uname) { $uname=$env{'user.name'}; }
3740: my $id=$uname.':'.$udom;
3741: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3742: if ($cached) {
3743: return %{$langs};
3744: } else {
3745: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3746: $udom,$uname);
3747: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3748: return %loadlangs;
3749: }
3750: }
3751:
3752: sub flush_langs_cache {
3753: my ($uname,$udom)=@_;
3754: if (!$udom) { $udom =$env{'user.domain'}; }
3755: if (!$uname) { $uname=$env{'user.name'}; }
3756: return if ($udom eq 'public' && $uname eq 'public');
3757: my $id=$uname.':'.$udom;
3758: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3759: }
3760:
1.61 www 3761: # ------------------------------------------------------------------ Screenname
1.81 albertel 3762:
3763: =pod
3764:
1.648 raeburn 3765: =item * &screenname($uname,$udom)
1.81 albertel 3766:
3767: Gets a users screenname and returns it as a string
3768:
3769: =cut
1.61 www 3770:
3771: sub screenname {
3772: my ($uname,$udom)=@_;
1.258 albertel 3773: if ($uname eq $env{'user.name'} &&
3774: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3775: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3776: return $names{'screenname'};
1.62 www 3777: }
3778:
1.212 albertel 3779:
1.802 bisitz 3780: # ------------------------------------------------------------- Confirm Wrapper
3781: =pod
3782:
1.1075.2.42 raeburn 3783: =item * &confirmwrapper($message)
1.802 bisitz 3784:
3785: Wrap messages about completion of operation in box
3786:
3787: =cut
3788:
3789: sub confirmwrapper {
3790: my ($message)=@_;
3791: if ($message) {
3792: return "\n".'<div class="LC_confirm_box">'."\n"
3793: .$message."\n"
3794: .'</div>'."\n";
3795: } else {
3796: return $message;
3797: }
3798: }
3799:
1.62 www 3800: # ------------------------------------------------------------- Message Wrapper
3801:
3802: sub messagewrapper {
1.369 www 3803: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3804: return
1.441 albertel 3805: '<a href="/adm/email?compose=individual&'.
3806: 'recname='.$username.'&recdom='.$domain.
3807: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3808: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3809: }
1.802 bisitz 3810:
1.74 www 3811: # --------------------------------------------------------------- Notes Wrapper
3812:
3813: sub noteswrapper {
3814: my ($link,$un,$do)=@_;
3815: return
1.896 amueller 3816: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3817: }
1.802 bisitz 3818:
1.62 www 3819: # ------------------------------------------------------------- Aboutme Wrapper
3820:
3821: sub aboutmewrapper {
1.1070 raeburn 3822: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3823: if (!defined($username) && !defined($domain)) {
3824: return;
3825: }
1.1075.2.15 raeburn 3826: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3827: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3828: }
3829:
3830: # ------------------------------------------------------------ Syllabus Wrapper
3831:
3832: sub syllabuswrapper {
1.707 bisitz 3833: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3834: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3835: }
1.14 harris41 3836:
1.802 bisitz 3837: # -----------------------------------------------------------------------------
3838:
1.208 matthew 3839: sub track_student_link {
1.887 raeburn 3840: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3841: my $link ="/adm/trackstudent?";
1.208 matthew 3842: my $title = 'View recent activity';
3843: if (defined($sname) && $sname !~ /^\s*$/ &&
3844: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3845: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3846: $title .= ' of this student';
1.268 albertel 3847: }
1.208 matthew 3848: if (defined($target) && $target !~ /^\s*$/) {
3849: $target = qq{target="$target"};
3850: } else {
3851: $target = '';
3852: }
1.268 albertel 3853: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3854: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3855: $title = &mt($title);
3856: $linktext = &mt($linktext);
1.448 albertel 3857: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3858: &help_open_topic('View_recent_activity');
1.208 matthew 3859: }
3860:
1.781 raeburn 3861: sub slot_reservations_link {
3862: my ($linktext,$sname,$sdom,$target) = @_;
3863: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3864: my $title = 'View slot reservation history';
3865: if (defined($sname) && $sname !~ /^\s*$/ &&
3866: defined($sdom) && $sdom !~ /^\s*$/) {
3867: $link .= "&uname=$sname&udom=$sdom";
3868: $title .= ' of this student';
3869: }
3870: if (defined($target) && $target !~ /^\s*$/) {
3871: $target = qq{target="$target"};
3872: } else {
3873: $target = '';
3874: }
3875: $title = &mt($title);
3876: $linktext = &mt($linktext);
3877: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3878: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3879:
3880: }
3881:
1.508 www 3882: # ===================================================== Display a student photo
3883:
3884:
1.509 albertel 3885: sub student_image_tag {
1.508 www 3886: my ($domain,$user)=@_;
3887: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3888: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3889: return '<img src="'.$imgsrc.'" align="right" />';
3890: } else {
3891: return '';
3892: }
3893: }
3894:
1.112 bowersj2 3895: =pod
3896:
3897: =back
3898:
3899: =head1 Access .tab File Data
3900:
3901: =over 4
3902:
1.648 raeburn 3903: =item * &languageids()
1.112 bowersj2 3904:
3905: returns list of all language ids
3906:
3907: =cut
3908:
1.14 harris41 3909: sub languageids {
1.16 harris41 3910: return sort(keys(%language));
1.14 harris41 3911: }
3912:
1.112 bowersj2 3913: =pod
3914:
1.648 raeburn 3915: =item * &languagedescription()
1.112 bowersj2 3916:
3917: returns description of a specified language id
3918:
3919: =cut
3920:
1.14 harris41 3921: sub languagedescription {
1.125 www 3922: my $code=shift;
3923: return ($supported_language{$code}?'* ':'').
3924: $language{$code}.
1.126 www 3925: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3926: }
3927:
1.1048 foxr 3928: =pod
3929:
3930: =item * &plainlanguagedescription
3931:
3932: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3933: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3934:
3935: =cut
3936:
1.145 www 3937: sub plainlanguagedescription {
3938: my $code=shift;
3939: return $language{$code};
3940: }
3941:
1.1048 foxr 3942: =pod
3943:
3944: =item * &supportedlanguagecode
3945:
3946: Returns the supported language code (e.g. sptutf maps to pt) given a language
3947: code.
3948:
3949: =cut
3950:
1.145 www 3951: sub supportedlanguagecode {
3952: my $code=shift;
3953: return $supported_language{$code};
1.97 www 3954: }
3955:
1.112 bowersj2 3956: =pod
3957:
1.1048 foxr 3958: =item * &latexlanguage()
3959:
3960: Given a language key code returns the correspondnig language to use
3961: to select the correct hyphenation on LaTeX printouts. This is undef if there
3962: is no supported hyphenation for the language code.
3963:
3964: =cut
3965:
3966: sub latexlanguage {
3967: my $code = shift;
3968: return $latex_language{$code};
3969: }
3970:
3971: =pod
3972:
3973: =item * &latexhyphenation()
3974:
3975: Same as above but what's supplied is the language as it might be stored
3976: in the metadata.
3977:
3978: =cut
3979:
3980: sub latexhyphenation {
3981: my $key = shift;
3982: return $latex_language_bykey{$key};
3983: }
3984:
3985: =pod
3986:
1.648 raeburn 3987: =item * ©rightids()
1.112 bowersj2 3988:
3989: returns list of all copyrights
3990:
3991: =cut
3992:
3993: sub copyrightids {
3994: return sort(keys(%cprtag));
3995: }
3996:
3997: =pod
3998:
1.648 raeburn 3999: =item * ©rightdescription()
1.112 bowersj2 4000:
4001: returns description of a specified copyright id
4002:
4003: =cut
4004:
4005: sub copyrightdescription {
1.166 www 4006: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4007: }
1.197 matthew 4008:
4009: =pod
4010:
1.648 raeburn 4011: =item * &source_copyrightids()
1.192 taceyjo1 4012:
4013: returns list of all source copyrights
4014:
4015: =cut
4016:
4017: sub source_copyrightids {
4018: return sort(keys(%scprtag));
4019: }
4020:
4021: =pod
4022:
1.648 raeburn 4023: =item * &source_copyrightdescription()
1.192 taceyjo1 4024:
4025: returns description of a specified source copyright id
4026:
4027: =cut
4028:
4029: sub source_copyrightdescription {
4030: return &mt($scprtag{shift(@_)});
4031: }
1.112 bowersj2 4032:
4033: =pod
4034:
1.648 raeburn 4035: =item * &filecategories()
1.112 bowersj2 4036:
4037: returns list of all file categories
4038:
4039: =cut
4040:
4041: sub filecategories {
4042: return sort(keys(%category_extensions));
4043: }
4044:
4045: =pod
4046:
1.648 raeburn 4047: =item * &filecategorytypes()
1.112 bowersj2 4048:
4049: returns list of file types belonging to a given file
4050: category
4051:
4052: =cut
4053:
4054: sub filecategorytypes {
1.356 albertel 4055: my ($cat) = @_;
4056: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 4057: }
4058:
4059: =pod
4060:
1.648 raeburn 4061: =item * &fileembstyle()
1.112 bowersj2 4062:
4063: returns embedding style for a specified file type
4064:
4065: =cut
4066:
4067: sub fileembstyle {
4068: return $fe{lc(shift(@_))};
1.169 www 4069: }
4070:
1.351 www 4071: sub filemimetype {
4072: return $fm{lc(shift(@_))};
4073: }
4074:
1.169 www 4075:
4076: sub filecategoryselect {
4077: my ($name,$value)=@_;
1.189 matthew 4078: return &select_form($value,$name,
1.970 raeburn 4079: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4080: }
4081:
4082: =pod
4083:
1.648 raeburn 4084: =item * &filedescription()
1.112 bowersj2 4085:
4086: returns description for a specified file type
4087:
4088: =cut
4089:
4090: sub filedescription {
1.188 matthew 4091: my $file_description = $fd{lc(shift())};
4092: $file_description =~ s:([\[\]]):~$1:g;
4093: return &mt($file_description);
1.112 bowersj2 4094: }
4095:
4096: =pod
4097:
1.648 raeburn 4098: =item * &filedescriptionex()
1.112 bowersj2 4099:
4100: returns description for a specified file type with
4101: extra formatting
4102:
4103: =cut
4104:
4105: sub filedescriptionex {
4106: my $ex=shift;
1.188 matthew 4107: my $file_description = $fd{lc($ex)};
4108: $file_description =~ s:([\[\]]):~$1:g;
4109: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4110: }
4111:
4112: # End of .tab access
4113: =pod
4114:
4115: =back
4116:
4117: =cut
4118:
4119: # ------------------------------------------------------------------ File Types
4120: sub fileextensions {
4121: return sort(keys(%fe));
4122: }
4123:
1.97 www 4124: # ----------------------------------------------------------- Display Languages
4125: # returns a hash with all desired display languages
4126: #
4127:
4128: sub display_languages {
4129: my %languages=();
1.695 raeburn 4130: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4131: $languages{$lang}=1;
1.97 www 4132: }
4133: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4134: if ($env{'form.displaylanguage'}) {
1.356 albertel 4135: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4136: $languages{$lang}=1;
1.97 www 4137: }
4138: }
4139: return %languages;
1.14 harris41 4140: }
4141:
1.582 albertel 4142: sub languages {
4143: my ($possible_langs) = @_;
1.695 raeburn 4144: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4145: if (!ref($possible_langs)) {
4146: if( wantarray ) {
4147: return @preferred_langs;
4148: } else {
4149: return $preferred_langs[0];
4150: }
4151: }
4152: my %possibilities = map { $_ => 1 } (@$possible_langs);
4153: my @preferred_possibilities;
4154: foreach my $preferred_lang (@preferred_langs) {
4155: if (exists($possibilities{$preferred_lang})) {
4156: push(@preferred_possibilities, $preferred_lang);
4157: }
4158: }
4159: if( wantarray ) {
4160: return @preferred_possibilities;
4161: }
4162: return $preferred_possibilities[0];
4163: }
4164:
1.742 raeburn 4165: sub user_lang {
4166: my ($touname,$toudom,$fromcid) = @_;
4167: my @userlangs;
4168: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4169: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4170: $env{'course.'.$fromcid.'.languages'}));
4171: } else {
4172: my %langhash = &getlangs($touname,$toudom);
4173: if ($langhash{'languages'} ne '') {
4174: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4175: } else {
4176: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4177: if ($domdefs{'lang_def'} ne '') {
4178: @userlangs = ($domdefs{'lang_def'});
4179: }
4180: }
4181: }
4182: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4183: my $user_lh = Apache::localize->get_handle(@languages);
4184: return $user_lh;
4185: }
4186:
4187:
1.112 bowersj2 4188: ###############################################################
4189: ## Student Answer Attempts ##
4190: ###############################################################
4191:
4192: =pod
4193:
4194: =head1 Alternate Problem Views
4195:
4196: =over 4
4197:
1.648 raeburn 4198: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4199: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4200:
4201: Return string with previous attempt on problem. Arguments:
4202:
4203: =over 4
4204:
4205: =item * $symb: Problem, including path
4206:
4207: =item * $username: username of the desired student
4208:
4209: =item * $domain: domain of the desired student
1.14 harris41 4210:
1.112 bowersj2 4211: =item * $course: Course ID
1.14 harris41 4212:
1.112 bowersj2 4213: =item * $getattempt: Leave blank for all attempts, otherwise put
4214: something
1.14 harris41 4215:
1.112 bowersj2 4216: =item * $regexp: if string matches this regexp, the string will be
4217: sent to $gradesub
1.14 harris41 4218:
1.112 bowersj2 4219: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4220:
1.1075.2.86 raeburn 4221: =item * $usec: section of the desired student
4222:
4223: =item * $identifier: counter for student (multiple students one problem) or
4224: problem (one student; whole sequence).
4225:
1.112 bowersj2 4226: =back
1.14 harris41 4227:
1.112 bowersj2 4228: The output string is a table containing all desired attempts, if any.
1.16 harris41 4229:
1.112 bowersj2 4230: =cut
1.1 albertel 4231:
4232: sub get_previous_attempt {
1.1075.2.86 raeburn 4233: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4234: my $prevattempts='';
1.43 ng 4235: no strict 'refs';
1.1 albertel 4236: if ($symb) {
1.3 albertel 4237: my (%returnhash)=
4238: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4239: if ($returnhash{'version'}) {
4240: my %lasthash=();
4241: my $version;
4242: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4243: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4244: if ($key =~ /\.rawrndseed$/) {
4245: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4246: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4247: } else {
4248: $lasthash{$key}=$returnhash{$version.':'.$key};
4249: }
1.19 harris41 4250: }
1.1 albertel 4251: }
1.596 albertel 4252: $prevattempts=&start_data_table().&start_data_table_header_row();
4253: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4254: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4255: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4256: foreach my $key (sort(keys(%lasthash))) {
4257: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4258: if ($#parts > 0) {
1.31 albertel 4259: my $data=$parts[-1];
1.989 raeburn 4260: next if ($data eq 'foilorder');
1.31 albertel 4261: pop(@parts);
1.1010 www 4262: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4263: if ($data eq 'type') {
4264: unless ($showsurv) {
4265: my $id = join(',',@parts);
4266: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4267: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4268: $lasthidden{$ign.'.'.$id} = 1;
4269: }
1.945 raeburn 4270: }
1.1075.2.86 raeburn 4271: if ($identifier ne '') {
4272: my $id = join(',',@parts);
4273: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4274: $domain,$username,$usec,undef,$course) =~ /^no/) {
4275: $hidestatus{$ign.'.'.$id} = 1;
4276: }
4277: }
4278: } elsif ($data eq 'regrader') {
4279: if (($identifier ne '') && (@parts)) {
4280: my $id = join(',',@parts);
4281: $regraded{$ign.'.'.$id} = 1;
4282: }
1.1010 www 4283: }
1.31 albertel 4284: } else {
1.41 ng 4285: if ($#parts == 0) {
4286: $prevattempts.='<th>'.$parts[0].'</th>';
4287: } else {
4288: $prevattempts.='<th>'.$ign.'</th>';
4289: }
1.31 albertel 4290: }
1.16 harris41 4291: }
1.596 albertel 4292: $prevattempts.=&end_data_table_header_row();
1.40 ng 4293: if ($getattempt eq '') {
1.1075.2.86 raeburn 4294: my (%solved,%resets,%probstatus);
4295: if (($identifier ne '') && (keys(%regraded) > 0)) {
4296: for ($version=1;$version<=$returnhash{'version'};$version++) {
4297: foreach my $id (keys(%regraded)) {
4298: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4299: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4300: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4301: push(@{$resets{$id}},$version);
4302: }
4303: }
4304: }
4305: }
1.40 ng 4306: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4307: my (@hidden,@unsolved);
1.945 raeburn 4308: if (%typeparts) {
4309: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4310: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4311: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4312: push(@hidden,$id);
1.1075.2.86 raeburn 4313: } elsif ($identifier ne '') {
4314: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4315: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4316: ($hidestatus{$id})) {
4317: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4318: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4319: push(@{$solved{$id}},$version);
4320: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4321: (ref($solved{$id}) eq 'ARRAY')) {
4322: my $skip;
4323: if (ref($resets{$id}) eq 'ARRAY') {
4324: foreach my $reset (@{$resets{$id}}) {
4325: if ($reset > $solved{$id}[-1]) {
4326: $skip=1;
4327: last;
4328: }
4329: }
4330: }
4331: unless ($skip) {
4332: my ($ign,$partslist) = split(/\./,$id,2);
4333: push(@unsolved,$partslist);
4334: }
4335: }
4336: }
1.945 raeburn 4337: }
4338: }
4339: }
4340: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4341: '<td>'.&mt('Transaction [_1]',$version);
4342: if (@unsolved) {
4343: $prevattempts .= '<span class="LC_nobreak"><label>'.
4344: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4345: &mt('Hide').'</label></span>';
4346: }
4347: $prevattempts .= '</td>';
1.945 raeburn 4348: if (@hidden) {
4349: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4350: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4351: my $hide;
4352: foreach my $id (@hidden) {
4353: if ($key =~ /^\Q$id\E/) {
4354: $hide = 1;
4355: last;
4356: }
4357: }
4358: if ($hide) {
4359: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4360: if (($data eq 'award') || ($data eq 'awarddetail')) {
4361: my $value = &format_previous_attempt_value($key,
4362: $returnhash{$version.':'.$key});
4363: $prevattempts.='<td>'.$value.' </td>';
4364: } else {
4365: $prevattempts.='<td> </td>';
4366: }
4367: } else {
4368: if ($key =~ /\./) {
1.1075.2.91 raeburn 4369: my $value = $returnhash{$version.':'.$key};
4370: if ($key =~ /\.rndseed$/) {
4371: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4372: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4373: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4374: }
4375: }
4376: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4377: ' </td>';
1.945 raeburn 4378: } else {
4379: $prevattempts.='<td> </td>';
4380: }
4381: }
4382: }
4383: } else {
4384: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4385: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4386: my $value = $returnhash{$version.':'.$key};
4387: if ($key =~ /\.rndseed$/) {
4388: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4389: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4390: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4391: }
4392: }
4393: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4394: ' </td>';
1.945 raeburn 4395: }
4396: }
4397: $prevattempts.=&end_data_table_row();
1.40 ng 4398: }
1.1 albertel 4399: }
1.945 raeburn 4400: my @currhidden = keys(%lasthidden);
1.596 albertel 4401: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4402: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4403: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4404: if (%typeparts) {
4405: my $hidden;
4406: foreach my $id (@currhidden) {
4407: if ($key =~ /^\Q$id\E/) {
4408: $hidden = 1;
4409: last;
4410: }
4411: }
4412: if ($hidden) {
4413: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4414: if (($data eq 'award') || ($data eq 'awarddetail')) {
4415: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4416: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4417: $value = &$gradesub($value);
4418: }
4419: $prevattempts.='<td>'.$value.' </td>';
4420: } else {
4421: $prevattempts.='<td> </td>';
4422: }
4423: } else {
4424: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4425: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4426: $value = &$gradesub($value);
4427: }
4428: $prevattempts.='<td>'.$value.' </td>';
4429: }
4430: } else {
4431: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4432: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4433: $value = &$gradesub($value);
4434: }
4435: $prevattempts.='<td>'.$value.' </td>';
4436: }
1.16 harris41 4437: }
1.596 albertel 4438: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4439: } else {
1.596 albertel 4440: $prevattempts=
4441: &start_data_table().&start_data_table_row().
4442: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4443: &end_data_table_row().&end_data_table();
1.1 albertel 4444: }
4445: } else {
1.596 albertel 4446: $prevattempts=
4447: &start_data_table().&start_data_table_row().
4448: '<td>'.&mt('No data.').'</td>'.
4449: &end_data_table_row().&end_data_table();
1.1 albertel 4450: }
1.10 albertel 4451: }
4452:
1.581 albertel 4453: sub format_previous_attempt_value {
4454: my ($key,$value) = @_;
1.1011 www 4455: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4456: $value = &Apache::lonlocal::locallocaltime($value);
4457: } elsif (ref($value) eq 'ARRAY') {
4458: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4459: } elsif ($key =~ /answerstring$/) {
4460: my %answers = &Apache::lonnet::str2hash($value);
4461: my @anskeys = sort(keys(%answers));
4462: if (@anskeys == 1) {
4463: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4464: if ($answer =~ m{\0}) {
4465: $answer =~ s{\0}{,}g;
1.988 raeburn 4466: }
4467: my $tag_internal_answer_name = 'INTERNAL';
4468: if ($anskeys[0] eq $tag_internal_answer_name) {
4469: $value = $answer;
4470: } else {
4471: $value = $anskeys[0].'='.$answer;
4472: }
4473: } else {
4474: foreach my $ans (@anskeys) {
4475: my $answer = $answers{$ans};
1.1001 raeburn 4476: if ($answer =~ m{\0}) {
4477: $answer =~ s{\0}{,}g;
1.988 raeburn 4478: }
4479: $value .= $ans.'='.$answer.'<br />';;
4480: }
4481: }
1.581 albertel 4482: } else {
4483: $value = &unescape($value);
4484: }
4485: return $value;
4486: }
4487:
4488:
1.107 albertel 4489: sub relative_to_absolute {
4490: my ($url,$output)=@_;
4491: my $parser=HTML::TokeParser->new(\$output);
4492: my $token;
4493: my $thisdir=$url;
4494: my @rlinks=();
4495: while ($token=$parser->get_token) {
4496: if ($token->[0] eq 'S') {
4497: if ($token->[1] eq 'a') {
4498: if ($token->[2]->{'href'}) {
4499: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4500: }
4501: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4502: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4503: } elsif ($token->[1] eq 'base') {
4504: $thisdir=$token->[2]->{'href'};
4505: }
4506: }
4507: }
4508: $thisdir=~s-/[^/]*$--;
1.356 albertel 4509: foreach my $link (@rlinks) {
1.726 raeburn 4510: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4511: ($link=~/^\//) ||
4512: ($link=~/^javascript:/i) ||
4513: ($link=~/^mailto:/i) ||
4514: ($link=~/^\#/)) {
4515: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4516: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4517: }
4518: }
4519: # -------------------------------------------------- Deal with Applet codebases
4520: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4521: return $output;
4522: }
4523:
1.112 bowersj2 4524: =pod
4525:
1.648 raeburn 4526: =item * &get_student_view()
1.112 bowersj2 4527:
4528: show a snapshot of what student was looking at
4529:
4530: =cut
4531:
1.10 albertel 4532: sub get_student_view {
1.186 albertel 4533: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4534: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4535: my (%form);
1.10 albertel 4536: my @elements=('symb','courseid','domain','username');
4537: foreach my $element (@elements) {
1.186 albertel 4538: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4539: }
1.186 albertel 4540: if (defined($moreenv)) {
4541: %form=(%form,%{$moreenv});
4542: }
1.236 albertel 4543: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4544: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4545: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4546: $userview=~s/\<body[^\>]*\>//gi;
4547: $userview=~s/\<\/body\>//gi;
4548: $userview=~s/\<html\>//gi;
4549: $userview=~s/\<\/html\>//gi;
4550: $userview=~s/\<head\>//gi;
4551: $userview=~s/\<\/head\>//gi;
4552: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4553: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4554: if (wantarray) {
4555: return ($userview,$response);
4556: } else {
4557: return $userview;
4558: }
4559: }
4560:
4561: sub get_student_view_with_retries {
4562: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4563:
4564: my $ok = 0; # True if we got a good response.
4565: my $content;
4566: my $response;
4567:
4568: # Try to get the student_view done. within the retries count:
4569:
4570: do {
4571: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4572: $ok = $response->is_success;
4573: if (!$ok) {
4574: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4575: }
4576: $retries--;
4577: } while (!$ok && ($retries > 0));
4578:
4579: if (!$ok) {
4580: $content = ''; # On error return an empty content.
4581: }
1.651 www 4582: if (wantarray) {
4583: return ($content, $response);
4584: } else {
4585: return $content;
4586: }
1.11 albertel 4587: }
4588:
1.1075.2.149 raeburn 4589: sub css_links {
4590: my ($currsymb,$level) = @_;
4591: my ($links,@symbs,%cssrefs,%httpref);
4592: if ($level eq 'map') {
4593: my $navmap = Apache::lonnavmaps::navmap->new();
4594: if (ref($navmap)) {
4595: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4596: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4597: foreach my $res (@resources) {
4598: if (ref($res) && $res->symb()) {
4599: push(@symbs,$res->symb());
4600: }
4601: }
4602: }
4603: } else {
4604: @symbs = ($currsymb);
4605: }
4606: foreach my $symb (@symbs) {
4607: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4608: if ($css_href =~ /\S/) {
4609: unless ($css_href =~ m{https?://}) {
4610: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4611: my $proburl = &Apache::lonnet::clutter($url);
4612: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4613: unless ($css_href =~ m{^/}) {
4614: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4615: }
4616: if ($css_href =~ m{^/(res|uploaded)/}) {
4617: unless (($httpref{'httpref.'.$css_href}) ||
4618: (&Apache::lonnet::is_on_map($css_href))) {
4619: my $thisurl = $proburl;
4620: if ($env{'httpref.'.$proburl}) {
4621: $thisurl = $env{'httpref.'.$proburl};
4622: }
4623: $httpref{'httpref.'.$css_href} = $thisurl;
4624: }
4625: }
4626: }
4627: $cssrefs{$css_href} = 1;
4628: }
4629: }
4630: if (keys(%httpref)) {
4631: &Apache::lonnet::appenv(\%httpref);
4632: }
4633: if (keys(%cssrefs)) {
4634: foreach my $css_href (keys(%cssrefs)) {
4635: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4636: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4637: }
4638: }
4639: return $links;
4640: }
4641:
1.112 bowersj2 4642: =pod
4643:
1.648 raeburn 4644: =item * &get_student_answers()
1.112 bowersj2 4645:
4646: show a snapshot of how student was answering problem
4647:
4648: =cut
4649:
1.11 albertel 4650: sub get_student_answers {
1.100 sakharuk 4651: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4652: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4653: my (%moreenv);
1.11 albertel 4654: my @elements=('symb','courseid','domain','username');
4655: foreach my $element (@elements) {
1.186 albertel 4656: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4657: }
1.186 albertel 4658: $moreenv{'grade_target'}='answer';
4659: %moreenv=(%form,%moreenv);
1.497 raeburn 4660: $feedurl = &Apache::lonnet::clutter($feedurl);
4661: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4662: return $userview;
1.1 albertel 4663: }
1.116 albertel 4664:
4665: =pod
4666:
4667: =item * &submlink()
4668:
1.242 albertel 4669: Inputs: $text $uname $udom $symb $target
1.116 albertel 4670:
4671: Returns: A link to grades.pm such as to see the SUBM view of a student
4672:
4673: =cut
4674:
4675: ###############################################
4676: sub submlink {
1.242 albertel 4677: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4678: if (!($uname && $udom)) {
4679: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4680: &Apache::lonnet::whichuser($symb);
1.116 albertel 4681: if (!$symb) { $symb=$cursymb; }
4682: }
1.254 matthew 4683: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4684: $symb=&escape($symb);
1.960 bisitz 4685: if ($target) { $target=" target=\"$target\""; }
4686: return
4687: '<a href="/adm/grades?command=submission'.
4688: '&symb='.$symb.
4689: '&student='.$uname.
4690: '&userdom='.$udom.'"'.
4691: $target.'>'.$text.'</a>';
1.242 albertel 4692: }
4693: ##############################################
4694:
4695: =pod
4696:
4697: =item * &pgrdlink()
4698:
4699: Inputs: $text $uname $udom $symb $target
4700:
4701: Returns: A link to grades.pm such as to see the PGRD view of a student
4702:
4703: =cut
4704:
4705: ###############################################
4706: sub pgrdlink {
4707: my $link=&submlink(@_);
4708: $link=~s/(&command=submission)/$1&showgrading=yes/;
4709: return $link;
4710: }
4711: ##############################################
4712:
4713: =pod
4714:
4715: =item * &pprmlink()
4716:
4717: Inputs: $text $uname $udom $symb $target
4718:
4719: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4720: student and a specific resource
1.242 albertel 4721:
4722: =cut
4723:
4724: ###############################################
4725: sub pprmlink {
4726: my ($text,$uname,$udom,$symb,$target)=@_;
4727: if (!($uname && $udom)) {
4728: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4729: &Apache::lonnet::whichuser($symb);
1.242 albertel 4730: if (!$symb) { $symb=$cursymb; }
4731: }
1.254 matthew 4732: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4733: $symb=&escape($symb);
1.242 albertel 4734: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4735: return '<a href="/adm/parmset?command=set&'.
4736: 'symb='.$symb.'&uname='.$uname.
4737: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4738: }
4739: ##############################################
1.37 matthew 4740:
1.112 bowersj2 4741: =pod
4742:
4743: =back
4744:
4745: =cut
4746:
1.37 matthew 4747: ###############################################
1.51 www 4748:
4749:
4750: sub timehash {
1.687 raeburn 4751: my ($thistime) = @_;
4752: my $timezone = &Apache::lonlocal::gettimezone();
4753: my $dt = DateTime->from_epoch(epoch => $thistime)
4754: ->set_time_zone($timezone);
4755: my $wday = $dt->day_of_week();
4756: if ($wday == 7) { $wday = 0; }
4757: return ( 'second' => $dt->second(),
4758: 'minute' => $dt->minute(),
4759: 'hour' => $dt->hour(),
4760: 'day' => $dt->day_of_month(),
4761: 'month' => $dt->month(),
4762: 'year' => $dt->year(),
4763: 'weekday' => $wday,
4764: 'dayyear' => $dt->day_of_year(),
4765: 'dlsav' => $dt->is_dst() );
1.51 www 4766: }
4767:
1.370 www 4768: sub utc_string {
4769: my ($date)=@_;
1.371 www 4770: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4771: }
4772:
1.51 www 4773: sub maketime {
4774: my %th=@_;
1.687 raeburn 4775: my ($epoch_time,$timezone,$dt);
4776: $timezone = &Apache::lonlocal::gettimezone();
4777: eval {
4778: $dt = DateTime->new( year => $th{'year'},
4779: month => $th{'month'},
4780: day => $th{'day'},
4781: hour => $th{'hour'},
4782: minute => $th{'minute'},
4783: second => $th{'second'},
4784: time_zone => $timezone,
4785: );
4786: };
4787: if (!$@) {
4788: $epoch_time = $dt->epoch;
4789: if ($epoch_time) {
4790: return $epoch_time;
4791: }
4792: }
1.51 www 4793: return POSIX::mktime(
4794: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4795: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4796: }
4797:
4798: #########################################
1.51 www 4799:
4800: sub findallcourses {
1.482 raeburn 4801: my ($roles,$uname,$udom) = @_;
1.355 albertel 4802: my %roles;
4803: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4804: my %courses;
1.51 www 4805: my $now=time;
1.482 raeburn 4806: if (!defined($uname)) {
4807: $uname = $env{'user.name'};
4808: }
4809: if (!defined($udom)) {
4810: $udom = $env{'user.domain'};
4811: }
4812: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4813: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4814: if (!%roles) {
4815: %roles = (
4816: cc => 1,
1.907 raeburn 4817: co => 1,
1.482 raeburn 4818: in => 1,
4819: ep => 1,
4820: ta => 1,
4821: cr => 1,
4822: st => 1,
4823: );
4824: }
4825: foreach my $entry (keys(%roleshash)) {
4826: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4827: if ($trole =~ /^cr/) {
4828: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4829: } else {
4830: next if (!exists($roles{$trole}));
4831: }
4832: if ($tend) {
4833: next if ($tend < $now);
4834: }
4835: if ($tstart) {
4836: next if ($tstart > $now);
4837: }
1.1058 raeburn 4838: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4839: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4840: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4841: if ($secpart eq '') {
4842: ($cnum,$role) = split(/_/,$cnumpart);
4843: $sec = 'none';
1.1058 raeburn 4844: $value .= $cnum.'/';
1.482 raeburn 4845: } else {
4846: $cnum = $cnumpart;
4847: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4848: $value .= $cnum.'/'.$sec;
4849: }
4850: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4851: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4852: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4853: }
4854: } else {
4855: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4856: }
1.482 raeburn 4857: }
4858: } else {
4859: foreach my $key (keys(%env)) {
1.483 albertel 4860: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4861: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4862: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4863: next if ($role eq 'ca' || $role eq 'aa');
4864: next if (%roles && !exists($roles{$role}));
4865: my ($starttime,$endtime)=split(/\./,$env{$key});
4866: my $active=1;
4867: if ($starttime) {
4868: if ($now<$starttime) { $active=0; }
4869: }
4870: if ($endtime) {
4871: if ($now>$endtime) { $active=0; }
4872: }
4873: if ($active) {
1.1058 raeburn 4874: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4875: if ($sec eq '') {
4876: $sec = 'none';
1.1058 raeburn 4877: } else {
4878: $value .= $sec;
4879: }
4880: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4881: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4882: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4883: }
4884: } else {
4885: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4886: }
1.474 raeburn 4887: }
4888: }
1.51 www 4889: }
4890: }
1.474 raeburn 4891: return %courses;
1.51 www 4892: }
1.37 matthew 4893:
1.54 www 4894: ###############################################
1.474 raeburn 4895:
4896: sub blockcheck {
1.1075.2.158 raeburn 4897: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4898:
1.1075.2.161. .4(raebu 4899:22): unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
1.1075.2.158 raeburn 4900: my ($has_evb,$check_ipaccess);
4901: my $dom = $env{'user.domain'};
4902: if ($env{'request.course.id'}) {
4903: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4904: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4905: my $checkrole = "cm./$cdom/$cnum";
4906: my $sec = $env{'request.course.sec'};
4907: if ($sec ne '') {
4908: $checkrole .= "/$sec";
4909: }
4910: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
4911: ($env{'request.role'} !~ /^st/)) {
4912: $has_evb = 1;
4913: }
4914: unless ($has_evb) {
4915: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
4916: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
4917: if ($udom eq $cdom) {
4918: $check_ipaccess = 1;
4919: }
4920: }
4921: }
1.1075.2.161. .3(raebu 4922:22): } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
4923:22): ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
4924:22): my $checkrole;
4925:22): if ($env{'request.role.domain'} eq '') {
4926:22): $checkrole = "cm./$env{'user.domain'}/";
4927:22): } else {
4928:22): $checkrole = "cm./$env{'request.role.domain'}/";
4929:22): }
4930:22): if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
4931:22): $has_evb = 1;
4932:22): }
1.1075.2.158 raeburn 4933: }
4934: unless ($has_evb || $check_ipaccess) {
4935: my @machinedoms = &Apache::lonnet::current_machine_domains();
4936: if (($dom eq 'public') && ($activity eq 'port')) {
4937: $dom = $udom;
4938: }
4939: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
4940: $check_ipaccess = 1;
4941: } else {
4942: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
4943: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
4944: my $prim = &Apache::lonnet::domain($dom,'primary');
4945: my $intdom = &Apache::lonnet::internet_dom($prim);
4946: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
4947: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4948: $check_ipaccess = 1;
4949: }
4950: }
4951: }
4952: }
4953: if ($check_ipaccess) {
4954: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
4955: unless (defined($cached)) {
4956: my %domconfig =
4957: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
4958: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
4959: }
4960: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
4961: foreach my $id (keys(%{$ipaccessref})) {
4962: if (ref($ipaccessref->{$id}) eq 'HASH') {
4963: my $range = $ipaccessref->{$id}->{'ip'};
4964: if ($range) {
4965: if (&Apache::lonnet::ip_match($clientip,$range)) {
4966: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
4967: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
4968: return ('','','',$id,$dom);
4969: last;
4970: }
4971: }
4972: }
4973: }
4974: }
4975: }
4976: }
4977: }
1.1075.2.161. .4(raebu 4978:22): if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
4979:22): return ();
4980:22): }
1.1075.2.158 raeburn 4981: }
1.1075.2.73 raeburn 4982: if (defined($udom) && defined($uname)) {
4983: # If uname and udom are for a course, check for blocks in the course.
4984: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4985: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 4986: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 4987: return ($startblock,$endblock,$triggerblock);
4988: }
4989: } else {
1.490 raeburn 4990: $udom = $env{'user.domain'};
4991: $uname = $env{'user.name'};
4992: }
4993:
1.502 raeburn 4994: my $startblock = 0;
4995: my $endblock = 0;
1.1062 raeburn 4996: my $triggerblock = '';
1.1075.2.160 raeburn 4997: my %live_courses;
4998: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
4999: %live_courses = &findallcourses(undef,$uname,$udom);
5000: }
1.474 raeburn 5001:
1.490 raeburn 5002: # If uname is for a user, and activity is course-specific, i.e.,
5003: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5004:
1.490 raeburn 5005: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.161. .1(raebu 5006:21): $activity eq 'groups' || $activity eq 'printout' ||
5007:21): $activity eq 'search' || $activity eq 'reinit' ||
5008:21): $activity eq 'alert') && ($env{'request.course.id'})) {
1.490 raeburn 5009: foreach my $key (keys(%live_courses)) {
5010: if ($key ne $env{'request.course.id'}) {
5011: delete($live_courses{$key});
5012: }
5013: }
5014: }
5015:
5016: my $otheruser = 0;
5017: my %own_courses;
5018: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5019: # Resource belongs to user other than current user.
5020: $otheruser = 1;
5021: # Gather courses for current user
5022: %own_courses =
5023: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5024: }
5025:
5026: # Gather active course roles - course coordinator, instructor,
5027: # exam proctor, ta, student, or custom role.
1.474 raeburn 5028:
5029: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5030: my ($cdom,$cnum);
5031: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5032: $cdom = $env{'course.'.$course.'.domain'};
5033: $cnum = $env{'course.'.$course.'.num'};
5034: } else {
1.490 raeburn 5035: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5036: }
5037: my $no_ownblock = 0;
5038: my $no_userblock = 0;
1.533 raeburn 5039: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5040: # Check if current user has 'evb' priv for this
5041: if (defined($own_courses{$course})) {
5042: foreach my $sec (keys(%{$own_courses{$course}})) {
5043: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5044: if ($sec ne 'none') {
5045: $checkrole .= '/'.$sec;
5046: }
5047: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5048: $no_ownblock = 1;
5049: last;
5050: }
5051: }
5052: }
5053: # if they have 'evb' priv and are currently not playing student
5054: next if (($no_ownblock) &&
5055: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5056: }
1.474 raeburn 5057: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5058: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5059: if ($sec ne 'none') {
1.482 raeburn 5060: $checkrole .= '/'.$sec;
1.474 raeburn 5061: }
1.490 raeburn 5062: if ($otheruser) {
5063: # Resource belongs to user other than current user.
5064: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5065: my (%allroles,%userroles);
5066: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5067: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5068: my ($trole,$tdom,$tnum,$tsec);
5069: if ($entry =~ /^cr/) {
5070: ($trole,$tdom,$tnum,$tsec) =
5071: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5072: } else {
5073: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5074: }
5075: my ($spec,$area,$trest);
5076: $area = '/'.$tdom.'/'.$tnum;
5077: $trest = $tnum;
5078: if ($tsec ne '') {
5079: $area .= '/'.$tsec;
5080: $trest .= '/'.$tsec;
5081: }
5082: $spec = $trole.'.'.$area;
5083: if ($trole =~ /^cr/) {
5084: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5085: $tdom,$spec,$trest,$area);
5086: } else {
5087: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5088: $tdom,$spec,$trest,$area);
5089: }
5090: }
1.1075.2.124 raeburn 5091: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5092: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5093: if ($1) {
5094: $no_userblock = 1;
5095: last;
5096: }
1.486 raeburn 5097: }
5098: }
1.490 raeburn 5099: } else {
5100: # Resource belongs to current user
5101: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5102: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5103: $no_ownblock = 1;
5104: last;
5105: }
1.474 raeburn 5106: }
5107: }
5108: # if they have the evb priv and are currently not playing student
1.482 raeburn 5109: next if (($no_ownblock) &&
1.491 albertel 5110: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5111: next if ($no_userblock);
1.474 raeburn 5112:
1.1075.2.128 raeburn 5113: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5114: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5115:
1.1062 raeburn 5116: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 5117: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5118: if (($start != 0) &&
5119: (($startblock == 0) || ($startblock > $start))) {
5120: $startblock = $start;
1.1062 raeburn 5121: if ($trigger ne '') {
5122: $triggerblock = $trigger;
5123: }
1.502 raeburn 5124: }
5125: if (($end != 0) &&
5126: (($endblock == 0) || ($endblock < $end))) {
5127: $endblock = $end;
1.1062 raeburn 5128: if ($trigger ne '') {
5129: $triggerblock = $trigger;
5130: }
1.502 raeburn 5131: }
1.490 raeburn 5132: }
1.1062 raeburn 5133: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5134: }
5135:
5136: sub get_blocks {
1.1075.2.147 raeburn 5137: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5138: my $startblock = 0;
5139: my $endblock = 0;
1.1062 raeburn 5140: my $triggerblock = '';
1.490 raeburn 5141: my $course = $cdom.'_'.$cnum;
5142: $setters->{$course} = {};
5143: $setters->{$course}{'staff'} = [];
5144: $setters->{$course}{'times'} = [];
1.1062 raeburn 5145: $setters->{$course}{'triggers'} = [];
5146: my (@blockers,%triggered);
5147: my $now = time;
5148: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5149: if ($activity eq 'docs') {
1.1075.2.148 raeburn 5150: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 5151: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5152: $blocked = 1;
5153: $nosymbcache = 1;
1.1075.2.148 raeburn 5154: $noenccheck = 1;
1.1075.2.147 raeburn 5155: }
1.1075.2.148 raeburn 5156: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5157: foreach my $block (@blockers) {
5158: if ($block =~ /^firstaccess____(.+)$/) {
5159: my $item = $1;
5160: my $type = 'map';
5161: my $timersymb = $item;
5162: if ($item eq 'course') {
5163: $type = 'course';
5164: } elsif ($item =~ /___\d+___/) {
5165: $type = 'resource';
5166: } else {
5167: $timersymb = &Apache::lonnet::symbread($item);
5168: }
5169: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5170: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5171: $triggered{$block} = {
5172: start => $start,
5173: end => $end,
5174: type => $type,
5175: };
5176: }
5177: }
5178: } else {
5179: foreach my $block (keys(%commblocks)) {
5180: if ($block =~ m/^(\d+)____(\d+)$/) {
5181: my ($start,$end) = ($1,$2);
5182: if ($start <= time && $end >= time) {
5183: if (ref($commblocks{$block}) eq 'HASH') {
5184: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5185: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5186: unless(grep(/^\Q$block\E$/,@blockers)) {
5187: push(@blockers,$block);
5188: }
5189: }
5190: }
5191: }
5192: }
5193: } elsif ($block =~ /^firstaccess____(.+)$/) {
5194: my $item = $1;
5195: my $timersymb = $item;
5196: my $type = 'map';
5197: if ($item eq 'course') {
5198: $type = 'course';
5199: } elsif ($item =~ /___\d+___/) {
5200: $type = 'resource';
5201: } else {
5202: $timersymb = &Apache::lonnet::symbread($item);
5203: }
5204: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5205: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5206: if ($start && $end) {
5207: if (($start <= time) && ($end >= time)) {
1.1075.2.158 raeburn 5208: if (ref($commblocks{$block}) eq 'HASH') {
5209: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5210: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5211: unless(grep(/^\Q$block\E$/,@blockers)) {
5212: push(@blockers,$block);
5213: $triggered{$block} = {
5214: start => $start,
5215: end => $end,
5216: type => $type,
5217: };
5218: }
5219: }
5220: }
1.1062 raeburn 5221: }
5222: }
1.490 raeburn 5223: }
1.1062 raeburn 5224: }
5225: }
5226: }
5227: foreach my $blocker (@blockers) {
5228: my ($staff_name,$staff_dom,$title,$blocks) =
5229: &parse_block_record($commblocks{$blocker});
5230: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5231: my ($start,$end,$triggertype);
5232: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5233: ($start,$end) = ($1,$2);
5234: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5235: $start = $triggered{$blocker}{'start'};
5236: $end = $triggered{$blocker}{'end'};
5237: $triggertype = $triggered{$blocker}{'type'};
5238: }
5239: if ($start) {
5240: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5241: if ($triggertype) {
5242: push(@{$$setters{$course}{'triggers'}},$triggertype);
5243: } else {
5244: push(@{$$setters{$course}{'triggers'}},0);
5245: }
5246: if ( ($startblock == 0) || ($startblock > $start) ) {
5247: $startblock = $start;
5248: if ($triggertype) {
5249: $triggerblock = $blocker;
1.474 raeburn 5250: }
5251: }
1.1062 raeburn 5252: if ( ($endblock == 0) || ($endblock < $end) ) {
5253: $endblock = $end;
5254: if ($triggertype) {
5255: $triggerblock = $blocker;
5256: }
5257: }
1.474 raeburn 5258: }
5259: }
1.1062 raeburn 5260: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5261: }
5262:
5263: sub parse_block_record {
5264: my ($record) = @_;
5265: my ($setuname,$setudom,$title,$blocks);
5266: if (ref($record) eq 'HASH') {
5267: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5268: $title = &unescape($record->{'event'});
5269: $blocks = $record->{'blocks'};
5270: } else {
5271: my @data = split(/:/,$record,3);
5272: if (scalar(@data) eq 2) {
5273: $title = $data[1];
5274: ($setuname,$setudom) = split(/@/,$data[0]);
5275: } else {
5276: ($setuname,$setudom,$title) = @data;
5277: }
5278: $blocks = { 'com' => 'on' };
5279: }
5280: return ($setuname,$setudom,$title,$blocks);
5281: }
5282:
1.854 kalberla 5283: sub blocking_status {
1.1075.2.158 raeburn 5284: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5285: my %setters;
1.890 droeschl 5286:
1.1061 raeburn 5287: # check for active blocking
1.1075.2.158 raeburn 5288: if ($clientip eq '') {
5289: $clientip = &Apache::lonnet::get_requestor_ip();
5290: }
5291: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5292: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5293: my $blocked = 0;
1.1075.2.158 raeburn 5294: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5295: $blocked = 1;
5296: }
1.890 droeschl 5297:
1.1061 raeburn 5298: # caller just wants to know whether a block is active
5299: if (!wantarray) { return $blocked; }
5300:
5301: # build a link to a popup window containing the details
5302: my $querystring = "?activity=$activity";
1.1075.2.158 raeburn 5303: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5304: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5305: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5306: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5307: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 5308: my $showurl = &Apache::lonenc::check_encrypt($url);
5309: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5310: if ($symb) {
5311: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5312: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5313: }
1.1062 raeburn 5314: }
1.1061 raeburn 5315:
5316: my $output .= <<'END_MYBLOCK';
5317: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5318: var options = "width=" + w + ",height=" + h + ",";
5319: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5320: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5321: var newWin = window.open(url, wdwName, options);
5322: newWin.focus();
5323: }
1.890 droeschl 5324: END_MYBLOCK
1.854 kalberla 5325:
1.1061 raeburn 5326: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5327:
1.1061 raeburn 5328: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5329: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5330: my $class = 'LC_comblock';
1.1062 raeburn 5331: if ($activity eq 'docs') {
5332: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5333: $class = '';
1.1063 raeburn 5334: } elsif ($activity eq 'printout') {
5335: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5336: } elsif ($activity eq 'passwd') {
5337: $text = &mt('Password Changing Blocked');
1.1075.2.158 raeburn 5338: } elsif ($activity eq 'grades') {
5339: $text = &mt('Gradebook Blocked');
5340: } elsif ($activity eq 'search') {
5341: $text = &mt('Search Blocked');
1.1075.2.161. .1(raebu 5342:21): } elsif ($activity eq 'alert') {
5343:21): $text = &mt('Checking Critical Messages Blocked');
5344:21): } elsif ($activity eq 'reinit') {
5345:21): $text = &mt('Checking Course Update Blocked');
1.1075.2.158 raeburn 5346: } elsif ($activity eq 'about') {
5347: $text = &mt('Access to User Information Pages Blocked');
1.1075.2.160 raeburn 5348: } elsif ($activity eq 'wishlist') {
5349: $text = &mt('Access to Stored Links Blocked');
5350: } elsif ($activity eq 'annotate') {
5351: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5352: }
1.1061 raeburn 5353: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5354: <div class='$class'>
1.869 kalberla 5355: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5356: title='$text'>
5357: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5358: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5359: title='$text'>$text</a>
1.867 kalberla 5360: </div>
5361:
5362: END_BLOCK
1.474 raeburn 5363:
1.1061 raeburn 5364: return ($blocked, $output);
1.854 kalberla 5365: }
1.490 raeburn 5366:
1.60 matthew 5367: ###############################################
5368:
1.682 raeburn 5369: sub check_ip_acc {
1.1075.2.105 raeburn 5370: my ($acc,$clientip)=@_;
1.682 raeburn 5371: &Apache::lonxml::debug("acc is $acc");
5372: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5373: return 1;
5374: }
5375: my $allowed=0;
1.1075.2.144 raeburn 5376: my $ip;
5377: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5378: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5379: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5380: } else {
1.1075.2.150 raeburn 5381: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5382: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1075.2.144 raeburn 5383: }
1.682 raeburn 5384:
5385: my $name;
1.1075.2.161. .1(raebu 5386:21): my %access = (
5387:21): allowfrom => 1,
5388:21): denyfrom => 0,
5389:21): );
5390:21): my @allows;
5391:21): my @denies;
5392:21): foreach my $item (split(',',$acc)) {
5393:21): $item =~ s/^\s*//;
5394:21): $item =~ s/\s*$//;
5395:21): if ($item =~ /^\!(.+)$/) {
5396:21): push(@denies,$1);
5397:21): } else {
5398:21): push(@allows,$item);
5399:21): }
5400:21): }
5401:21): my $numdenies = scalar(@denies);
5402:21): my $numallows = scalar(@allows);
5403:21): my $count = 0;
5404:21): foreach my $pattern (@denies,@allows) {
5405:21): $count ++;
5406:21): my $acctype = 'allowfrom';
5407:21): if ($count <= $numdenies) {
5408:21): $acctype = 'denyfrom';
5409:21): }
1.682 raeburn 5410: if ($pattern =~ /\*$/) {
5411: #35.8.*
5412: $pattern=~s/\*//;
1.1075.2.161. .1(raebu 5413:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5414: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5415: #35.8.3.[34-56]
5416: my $low=$2;
5417: my $high=$3;
5418: $pattern=$1;
5419: if ($ip =~ /^\Q$pattern\E/) {
5420: my $last=(split(/\./,$ip))[3];
1.1075.2.161. .1(raebu 5421:21): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5422: }
5423: } elsif ($pattern =~ /^\*/) {
5424: #*.msu.edu
5425: $pattern=~s/\*//;
5426: if (!defined($name)) {
5427: use Socket;
5428: my $netaddr=inet_aton($ip);
5429: ($name)=gethostbyaddr($netaddr,AF_INET);
5430: }
1.1075.2.161. .1(raebu 5431:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5432: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5433: #127.0.0.1
1.1075.2.161. .1(raebu 5434:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5435: } else {
5436: #some.name.com
5437: if (!defined($name)) {
5438: use Socket;
5439: my $netaddr=inet_aton($ip);
5440: ($name)=gethostbyaddr($netaddr,AF_INET);
5441: }
1.1075.2.161. .1(raebu 5442:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5443:21): }
5444:21): if ($allowed =~ /^(0|1)$/) { last; }
5445:21): }
5446:21): if ($allowed eq '') {
5447:21): if ($numdenies && !$numallows) {
5448:21): $allowed = 1;
5449:21): } else {
5450:21): $allowed = 0;
1.682 raeburn 5451: }
5452: }
5453: return $allowed;
5454: }
5455:
5456: ###############################################
5457:
1.60 matthew 5458: =pod
5459:
1.112 bowersj2 5460: =head1 Domain Template Functions
5461:
5462: =over 4
5463:
5464: =item * &determinedomain()
1.60 matthew 5465:
5466: Inputs: $domain (usually will be undef)
5467:
1.63 www 5468: Returns: Determines which domain should be used for designs
1.60 matthew 5469:
5470: =cut
1.54 www 5471:
1.60 matthew 5472: ###############################################
1.63 www 5473: sub determinedomain {
5474: my $domain=shift;
1.531 albertel 5475: if (! $domain) {
1.60 matthew 5476: # Determine domain if we have not been given one
1.893 raeburn 5477: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5478: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5479: if ($env{'request.role.domain'}) {
5480: $domain=$env{'request.role.domain'};
1.60 matthew 5481: }
5482: }
1.63 www 5483: return $domain;
5484: }
5485: ###############################################
1.517 raeburn 5486:
1.518 albertel 5487: sub devalidate_domconfig_cache {
5488: my ($udom)=@_;
5489: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5490: }
5491:
5492: # ---------------------- Get domain configuration for a domain
5493: sub get_domainconf {
5494: my ($udom) = @_;
5495: my $cachetime=1800;
5496: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5497: if (defined($cached)) { return %{$result}; }
5498:
5499: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5500: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5501: my (%designhash,%legacy);
1.518 albertel 5502: if (keys(%domconfig) > 0) {
5503: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5504: if (keys(%{$domconfig{'login'}})) {
5505: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5506: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5507: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5508: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5509: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5510: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5511: if ($key eq 'loginvia') {
5512: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5513: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5514: $designhash{$udom.'.login.loginvia'} = $server;
5515: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5516: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5517: } else {
5518: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5519: }
1.948 raeburn 5520: }
1.1075.2.87 raeburn 5521: } elsif ($key eq 'headtag') {
5522: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5523: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5524: }
1.946 raeburn 5525: }
1.1075.2.87 raeburn 5526: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5527: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5528: }
1.946 raeburn 5529: }
5530: }
5531: }
1.1075.2.158 raeburn 5532: } elsif ($key eq 'saml') {
5533: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5534: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5535: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5536: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
5537: foreach my $item ('text','img','alt','url','title','notsso') {
5538: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5539: }
5540: }
5541: }
5542: }
1.946 raeburn 5543: } else {
5544: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5545: $designhash{$udom.'.login.'.$key.'_'.$img} =
5546: $domconfig{'login'}{$key}{$img};
5547: }
1.699 raeburn 5548: }
5549: } else {
5550: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5551: }
1.632 raeburn 5552: }
5553: } else {
5554: $legacy{'login'} = 1;
1.518 albertel 5555: }
1.632 raeburn 5556: } else {
5557: $legacy{'login'} = 1;
1.518 albertel 5558: }
5559: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5560: if (keys(%{$domconfig{'rolecolors'}})) {
5561: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5562: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5563: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5564: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5565: }
1.518 albertel 5566: }
5567: }
1.632 raeburn 5568: } else {
5569: $legacy{'rolecolors'} = 1;
1.518 albertel 5570: }
1.632 raeburn 5571: } else {
5572: $legacy{'rolecolors'} = 1;
1.518 albertel 5573: }
1.948 raeburn 5574: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5575: if ($domconfig{'autoenroll'}{'co-owners'}) {
5576: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5577: }
5578: }
1.632 raeburn 5579: if (keys(%legacy) > 0) {
5580: my %legacyhash = &get_legacy_domconf($udom);
5581: foreach my $item (keys(%legacyhash)) {
5582: if ($item =~ /^\Q$udom\E\.login/) {
5583: if ($legacy{'login'}) {
5584: $designhash{$item} = $legacyhash{$item};
5585: }
5586: } else {
5587: if ($legacy{'rolecolors'}) {
5588: $designhash{$item} = $legacyhash{$item};
5589: }
1.518 albertel 5590: }
5591: }
5592: }
1.632 raeburn 5593: } else {
5594: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5595: }
5596: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5597: $cachetime);
5598: return %designhash;
5599: }
5600:
1.632 raeburn 5601: sub get_legacy_domconf {
5602: my ($udom) = @_;
5603: my %legacyhash;
5604: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5605: my $designfile = $designdir.'/'.$udom.'.tab';
5606: if (-e $designfile) {
1.1075.2.128 raeburn 5607: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5608: while (my $line = <$fh>) {
5609: next if ($line =~ /^\#/);
5610: chomp($line);
5611: my ($key,$val)=(split(/\=/,$line));
5612: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5613: }
5614: close($fh);
5615: }
5616: }
1.1026 raeburn 5617: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5618: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5619: }
5620: return %legacyhash;
5621: }
5622:
1.63 www 5623: =pod
5624:
1.112 bowersj2 5625: =item * &domainlogo()
1.63 www 5626:
5627: Inputs: $domain (usually will be undef)
5628:
5629: Returns: A link to a domain logo, if the domain logo exists.
5630: If the domain logo does not exist, a description of the domain.
5631:
5632: =cut
1.112 bowersj2 5633:
1.63 www 5634: ###############################################
5635: sub domainlogo {
1.517 raeburn 5636: my $domain = &determinedomain(shift);
1.518 albertel 5637: my %designhash = &get_domainconf($domain);
1.517 raeburn 5638: # See if there is a logo
5639: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5640: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5641: if ($imgsrc =~ m{^/(adm|res)/}) {
5642: if ($imgsrc =~ m{^/res/}) {
5643: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5644: &Apache::lonnet::repcopy($local_name);
5645: }
5646: $imgsrc = &lonhttpdurl($imgsrc);
1.1075.2.161. .2(raebu 5647:22): }
5648:22): my $alttext = $domain;
5649:22): if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5650:22): $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5651:22): }
5652:22): return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5653: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5654: return &Apache::lonnet::domain($domain,'description');
1.59 www 5655: } else {
1.60 matthew 5656: return '';
1.59 www 5657: }
5658: }
1.63 www 5659: ##############################################
5660:
5661: =pod
5662:
1.112 bowersj2 5663: =item * &designparm()
1.63 www 5664:
5665: Inputs: $which parameter; $domain (usually will be undef)
5666:
5667: Returns: value of designparamter $which
5668:
5669: =cut
1.112 bowersj2 5670:
1.397 albertel 5671:
1.400 albertel 5672: ##############################################
1.397 albertel 5673: sub designparm {
5674: my ($which,$domain)=@_;
5675: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5676: return $env{'environment.color.'.$which};
1.96 www 5677: }
1.63 www 5678: $domain=&determinedomain($domain);
1.1016 raeburn 5679: my %domdesign;
5680: unless ($domain eq 'public') {
5681: %domdesign = &get_domainconf($domain);
5682: }
1.520 raeburn 5683: my $output;
1.517 raeburn 5684: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5685: $output = $domdesign{$domain.'.'.$which};
1.63 www 5686: } else {
1.520 raeburn 5687: $output = $defaultdesign{$which};
5688: }
5689: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5690: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5691: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5692: if ($output =~ m{^/res/}) {
5693: my $local_name = &Apache::lonnet::filelocation('',$output);
5694: &Apache::lonnet::repcopy($local_name);
5695: }
1.520 raeburn 5696: $output = &lonhttpdurl($output);
5697: }
1.63 www 5698: }
1.520 raeburn 5699: return $output;
1.63 www 5700: }
1.59 www 5701:
1.822 bisitz 5702: ##############################################
5703: =pod
5704:
1.832 bisitz 5705: =item * &authorspace()
5706:
1.1028 raeburn 5707: Inputs: $url (usually will be undef).
1.832 bisitz 5708:
1.1075.2.40 raeburn 5709: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5710: directory being viewed (or for which action is being taken).
5711: If $url is provided, and begins /priv/<domain>/<uname>
5712: the path will be that portion of the $context argument.
5713: Otherwise the path will be for the author space of the current
5714: user when the current role is author, or for that of the
5715: co-author/assistant co-author space when the current role
5716: is co-author or assistant co-author.
1.832 bisitz 5717:
5718: =cut
5719:
5720: sub authorspace {
1.1028 raeburn 5721: my ($url) = @_;
5722: if ($url ne '') {
5723: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5724: return $1;
5725: }
5726: }
1.832 bisitz 5727: my $caname = '';
1.1024 www 5728: my $cadom = '';
1.1028 raeburn 5729: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5730: ($cadom,$caname) =
1.832 bisitz 5731: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5732: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5733: $caname = $env{'user.name'};
1.1024 www 5734: $cadom = $env{'user.domain'};
1.832 bisitz 5735: }
1.1028 raeburn 5736: if (($caname ne '') && ($cadom ne '')) {
5737: return "/priv/$cadom/$caname/";
5738: }
5739: return;
1.832 bisitz 5740: }
5741:
5742: ##############################################
5743: =pod
5744:
1.822 bisitz 5745: =item * &head_subbox()
5746:
5747: Inputs: $content (contains HTML code with page functions, etc.)
5748:
5749: Returns: HTML div with $content
5750: To be included in page header
5751:
5752: =cut
5753:
5754: sub head_subbox {
5755: my ($content)=@_;
5756: my $output =
1.993 raeburn 5757: '<div class="LC_head_subbox">'
1.822 bisitz 5758: .$content
5759: .'</div>'
5760: }
5761:
5762: ##############################################
5763: =pod
5764:
5765: =item * &CSTR_pageheader()
5766:
1.1026 raeburn 5767: Input: (optional) filename from which breadcrumb trail is built.
5768: In most cases no input as needed, as $env{'request.filename'}
5769: is appropriate for use in building the breadcrumb trail.
1.1075.2.161. .6(raebu 5770:22): frameset flag
5771:22): If page header is being requested for use in a frameset, then
5772:22): the second (option) argument -- frameset will be true, and
5773:22): the target attribute set for links should be target="_parent".
1.822 bisitz 5774:
5775: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5776: To be included on Authoring Space pages
1.822 bisitz 5777:
5778: =cut
5779:
5780: sub CSTR_pageheader {
1.1075.2.161. .6(raebu 5781:22): my ($trailfile,$frameset) = @_;
1.1026 raeburn 5782: if ($trailfile eq '') {
5783: $trailfile = $env{'request.filename'};
5784: }
5785:
5786: # this is for resources; directories have customtitle, and crumbs
5787: # and select recent are created in lonpubdir.pm
5788:
5789: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5790: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5791: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5792: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5793: $formaction =~ s{/+}{/}g;
1.822 bisitz 5794:
5795: my $parentpath = '';
5796: my $lastitem = '';
5797: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5798: $parentpath = $1;
5799: $lastitem = $2;
5800: } else {
5801: $lastitem = $thisdisfn;
5802: }
1.921 bisitz 5803:
1.1075.2.161. .6(raebu 5804:22): my ($target,$crumbtarget) = (' target="_top"','_top');
5805:22): if ($frameset) {
5806:22): $target = ' target="_parent"';
5807:22): $crumbtarget = '_parent';
5808:22): } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
5809:22): $target = ' target="'.$env{'request.deeplink.target'}.'"';
5810:22): $crumbtarget = $env{'request.deeplink.target'};
5811:22): }
5812:22):
1.921 bisitz 5813: my $output =
1.822 bisitz 5814: '<div>'
5815: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5816: .'<b>'.&mt('Authoring Space:').'</b> '
1.1075.2.161. .6(raebu 5817:22): .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5818:22): .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5819:
5820: if ($lastitem) {
5821: $output .=
5822: '<span class="LC_filename">'
5823: .$lastitem
5824: .'</span>';
5825: }
5826: $output .=
5827: '<br />'
1.1075.2.161. .6(raebu 5828:22): #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.822 bisitz 5829: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5830: .'</form>'
1.1075.2.161. .6(raebu 5831:22): .&Apache::lonmenu::constspaceform($frameset)
1.822 bisitz 5832: .'</div>';
1.921 bisitz 5833:
5834: return $output;
1.822 bisitz 5835: }
5836:
1.60 matthew 5837: ###############################################
5838: ###############################################
5839:
5840: =pod
5841:
1.112 bowersj2 5842: =back
5843:
1.549 albertel 5844: =head1 HTML Helpers
1.112 bowersj2 5845:
5846: =over 4
5847:
5848: =item * &bodytag()
1.60 matthew 5849:
5850: Returns a uniform header for LON-CAPA web pages.
5851:
5852: Inputs:
5853:
1.112 bowersj2 5854: =over 4
5855:
5856: =item * $title, A title to be displayed on the page.
5857:
5858: =item * $function, the current role (can be undef).
5859:
5860: =item * $addentries, extra parameters for the <body> tag.
5861:
5862: =item * $bodyonly, if defined, only return the <body> tag.
5863:
5864: =item * $domain, if defined, force a given domain.
5865:
5866: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5867: text interface only)
1.60 matthew 5868:
1.814 bisitz 5869: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5870: navigational links
1.317 albertel 5871:
1.338 albertel 5872: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5873:
1.1075.2.12 raeburn 5874: =item * $no_inline_link, if true and in remote mode, don't show the
5875: 'Switch To Inline Menu' link
5876:
1.460 albertel 5877: =item * $args, optional argument valid values are
5878: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5879: use_absolute -> for external resource or syllabus, this will
5880: contain https://<hostname> if server uses
5881: https (as per hosts.tab), but request is for http
5882: hostname -> hostname, from $r->hostname().
1.460 albertel 5883:
1.1075.2.15 raeburn 5884: =item * $advtoolsref, optional argument, ref to an array containing
5885: inlineremote items to be added in "Functions" menu below
5886: breadcrumbs.
5887:
1.1075.2.161. .1(raebu 5888:21): =item * $ltiscope, optional argument, will be one of: resource, map or
5889:21): course, if LON-CAPA is in LTI Provider context. Value is
5890:21): the scope of use, i.e., launch was for access to a single, a map
5891:21): or the entire course.
5892:21):
5893:21): =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
5894:21): context, this will contain the URL for the landing item in
5895:21): the course, after launch from an LTI Consumer
5896:21):
5897:21): =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
5898:21): context, this will contain a reference to hash of items
5899:21): to be included in the page header and/or inline menu.
5900:21):
.8(raebu 5901:22): =item * $menucoll, optional argument, if specific menu collection is in
5902:22): effect, either set as the default for the course, or set for
5903:22): the deeplink paramater for $env{'request.deeplink.login'}
5904:22): then $menucoll will be the number of that collection.
5905:22):
5906:22): =item * $menuref, optional argument, reference to a hash, containing the
5907:22): menu options included for the menu in effect, based on the
5908:22): configuration for the numbered menu collection in use.
5909:22):
5910:22): =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
5911:22): within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
5912:22): if so, $showncrumbsref is set there to 1, and will propagate back
5913:22): via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
5914:22): being called a second time.
5915:22):
1.112 bowersj2 5916: =back
5917:
1.60 matthew 5918: Returns: A uniform header for LON-CAPA web pages.
5919: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5920: If $bodyonly is undef or zero, an html string containing a <body> tag and
5921: other decorations will be returned.
5922:
5923: =cut
5924:
1.54 www 5925: sub bodytag {
1.831 bisitz 5926: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.161. .1(raebu 5927:21): $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref,
.8(raebu 5928:22): $ltiscope,$ltiuri,$ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 5929:
1.954 raeburn 5930: my $public;
5931: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5932: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5933: $public = 1;
5934: }
1.460 albertel 5935: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5936: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5937: my $hostname = $args->{'hostname'};
1.339 albertel 5938:
1.183 matthew 5939: $function = &get_users_function() if (!$function);
1.339 albertel 5940: my $img = &designparm($function.'.img',$domain);
5941: my $font = &designparm($function.'.font',$domain);
5942: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5943:
1.803 bisitz 5944: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5945: 'bgcolor' => $pgbg,
1.339 albertel 5946: 'text' => $font,
5947: 'alink' => &designparm($function.'.alink',$domain),
5948: 'vlink' => &designparm($function.'.vlink',$domain),
5949: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5950: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5951:
1.63 www 5952: # role and realm
1.1075.2.68 raeburn 5953: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5954: if ($realm) {
5955: $realm = '/'.$realm;
5956: }
1.1075.2.159 raeburn 5957: if ($role eq 'ca') {
1.479 albertel 5958: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5959: $realm = &plainname($rname,$rdom);
1.378 raeburn 5960: }
1.55 www 5961: # realm
1.1075.2.158 raeburn 5962: my ($cid,$sec);
1.258 albertel 5963: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 5964: $cid = $env{'request.course.id'};
5965: if ($env{'request.course.sec'}) {
5966: $sec = $env{'request.course.sec'};
5967: }
5968: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
5969: if (&Apache::lonnet::is_course($1,$2)) {
5970: $cid = $1.'_'.$2;
5971: $sec = $3;
5972: }
5973: }
5974: if ($cid) {
1.378 raeburn 5975: if ($env{'request.role'} !~ /^cr/) {
5976: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5977: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5978: if ($env{'request.role.desc'}) {
5979: $role = $env{'request.role.desc'};
5980: } else {
5981: $role = &mt('Helpdesk[_1]',' '.$2);
5982: }
1.1075.2.115 raeburn 5983: } else {
5984: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5985: }
1.1075.2.158 raeburn 5986: if ($sec) {
5987: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 5988: }
1.1075.2.158 raeburn 5989: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 5990: } else {
5991: $role = &Apache::lonnet::plaintext($role);
1.54 www 5992: }
1.433 albertel 5993:
1.359 albertel 5994: if (!$realm) { $realm=' '; }
1.330 albertel 5995:
1.438 albertel 5996: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5997:
1.101 www 5998: # construct main body tag
1.359 albertel 5999: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 6000: &Apache::lontexconvert::init_math_support();
1.252 albertel 6001:
1.1075.2.38 raeburn 6002: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6003:
6004: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6005: return $bodytag;
1.1075.2.38 raeburn 6006: }
1.359 albertel 6007:
1.954 raeburn 6008: if ($public) {
1.433 albertel 6009: undef($role);
6010: }
1.1075.2.158 raeburn 6011:
1.1075.2.161. .1(raebu 6012:21): my $showcrstitle = 1;
6013:21): if (($cid) && ($env{'request.lti.login'})) {
6014:21): if (ref($ltimenu) eq 'HASH') {
6015:21): unless ($ltimenu->{'role'}) {
6016:21): undef($role);
6017:21): }
6018:21): unless ($ltimenu->{'coursetitle'}) {
6019:21): $realm=' ';
6020:21): $showcrstitle = 0;
6021:21): }
6022:21): }
6023:21): } elsif (($cid) && ($menucoll)) {
6024:21): if (ref($menuref) eq 'HASH') {
6025:21): unless ($menuref->{'role'}) {
6026:21): undef($role);
6027:21): }
6028:21): unless ($menuref->{'crs'}) {
6029:21): $realm=' ';
6030:21): $showcrstitle = 0;
6031:21): }
6032:21): }
6033:21): }
6034:21):
1.762 bisitz 6035: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6036: #
6037: # Extra info if you are the DC
6038: my $dc_info = '';
1.1075.2.161. .1(raebu 6039:21): if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1075.2.158 raeburn 6040: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6041: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6042: $dc_info =~ s/\s+$//;
1.359 albertel 6043: }
6044:
1.1075.2.161. .1(raebu 6045:21): my $crstype;
6046:21): if ($cid) {
6047:21): $crstype = $env{'course.'.$cid.'.type'};
6048:21): } elsif ($args->{'crstype'}) {
6049:21): $crstype = $args->{'crstype'};
6050:21): }
6051:21):
1.1075.2.108 raeburn 6052: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 6053:
1.1075.2.13 raeburn 6054: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6055:
1.1075.2.38 raeburn 6056:
6057:
1.1075.2.21 raeburn 6058: my $funclist;
6059: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 6060: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 6061: Apache::lonmenu::serverform();
6062: my $forbodytag;
6063: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6064: $forcereg,$args->{'group'},
6065: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6066: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 6067: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6068: $funclist = $forbodytag;
6069: }
6070: } else {
1.903 droeschl 6071:
6072: # if ($env{'request.state'} eq 'construct') {
6073: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6074: # }
6075:
1.1075.2.38 raeburn 6076: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6077: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6078:
1.1075.2.161. .1(raebu 6079:21): unless ($args->{'no_primary_menu'}) {
.4(raebu 6080:22): my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
.6(raebu 6081:22): $args->{'links_disabled'},
6082:22): $args->{'links_target'});
.1(raebu 6083:21): if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6084:21): if ($dc_info) {
6085:21): $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6086:21): }
6087:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6088:21): <em>$realm</em> $dc_info</div>|;
6089:21): return $bodytag;
1.1075.2.1 raeburn 6090: }
1.894 droeschl 6091:
1.1075.2.161. .1(raebu 6092:21): unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6093:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6094:21): }
1.916 droeschl 6095:
1.1075.2.161. .1(raebu 6096:21): $bodytag .= $right;
1.852 droeschl 6097:
1.1075.2.161. .1(raebu 6098:21): if ($dc_info) {
6099:21): $dc_info = &dc_courseid_toggle($dc_info);
6100:21): }
6101:21): $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6102: }
1.916 droeschl 6103:
1.1075.2.61 raeburn 6104: #if directed to not display the secondary menu, don't.
6105: if ($args->{'no_secondary_menu'}) {
6106: return $bodytag;
6107: }
1.903 droeschl 6108: #don't show menus for public users
1.954 raeburn 6109: if (!$public){
1.1075.2.161. .1(raebu 6110:21): unless ($args->{'no_inline_menu'}) {
6111:21): $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6112:21): $args->{'no_primary_menu'},
6113:21): $menucoll,$menuref,
.6(raebu 6114:22): $args->{'links_disabled'},
6115:22): $args->{'links_target'});
.1(raebu 6116:21): }
1.903 droeschl 6117: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6118: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6119: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6120: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.161. .8(raebu 6121:22): $args->{'bread_crumbs'},'','',$hostname,
6122:22): $ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.116 raeburn 6123: } elsif ($forcereg) {
1.1075.2.22 raeburn 6124: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.161. .8(raebu 6125:22): $args->{'group'},$args->{'hide_buttons'},
6126:22): $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.15 raeburn 6127: } else {
1.1075.2.21 raeburn 6128: my $forbodytag;
6129: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6130: $forcereg,$args->{'group'},
6131: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6132: $advtoolsref,'',$hostname,
6133: \$forbodytag);
1.1075.2.21 raeburn 6134: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6135: $bodytag .= $forbodytag;
6136: }
1.920 raeburn 6137: }
1.903 droeschl 6138: }else{
6139: # this is to seperate menu from content when there's no secondary
6140: # menu. Especially needed for public accessible ressources.
6141: $bodytag .= '<hr style="clear:both" />';
6142: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6143: }
1.903 droeschl 6144:
1.235 raeburn 6145: return $bodytag;
1.1075.2.12 raeburn 6146: }
6147:
6148: #
6149: # Top frame rendering, Remote is up
6150: #
6151:
6152: my $imgsrc = $img;
6153: if ($img =~ /^\/adm/) {
6154: $imgsrc = &lonhttpdurl($img);
6155: }
6156: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
6157:
1.1075.2.60 raeburn 6158: my $help=($no_inline_link?''
6159: :&Apache::loncommon::top_nav_help('Help'));
6160:
1.1075.2.12 raeburn 6161: # Explicit link to get inline menu
6162: my $menu= ($no_inline_link?''
6163: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
6164:
6165: if ($dc_info) {
6166: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
6167: }
6168:
1.1075.2.38 raeburn 6169: my $name = &plainname($env{'user.name'},$env{'user.domain'});
6170: unless ($public) {
6171: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
6172: undef,'LC_menubuttons_link');
6173: }
6174:
1.1075.2.12 raeburn 6175: unless ($env{'form.inhibitmenu'}) {
6176: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 6177: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 6178: <li>$help</li>
1.1075.2.12 raeburn 6179: <li>$menu</li>
6180: </ol><div id="LC_realm"> $realm $dc_info</div>|;
6181: }
1.1075.2.13 raeburn 6182: if ($env{'request.state'} eq 'construct') {
6183: if (!$public){
6184: if ($env{'request.state'} eq 'construct') {
6185: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6186: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 6187: &Apache::lonhtmlcommon::scripttag('','end').
6188: &Apache::lonmenu::innerregister($forcereg,
6189: $args->{'bread_crumbs'});
6190: }
6191: }
6192: }
1.1075.2.21 raeburn 6193: return $bodytag."\n".$funclist;
1.182 matthew 6194: }
6195:
1.917 raeburn 6196: sub dc_courseid_toggle {
6197: my ($dc_info) = @_;
1.980 raeburn 6198: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6199: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6200: &mt('(More ...)').'</a></span>'.
6201: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6202: }
6203:
1.330 albertel 6204: sub make_attr_string {
6205: my ($register,$attr_ref) = @_;
6206:
6207: if ($attr_ref && !ref($attr_ref)) {
6208: die("addentries Must be a hash ref ".
6209: join(':',caller(1))." ".
6210: join(':',caller(0))." ");
6211: }
6212:
6213: if ($register) {
1.339 albertel 6214: my ($on_load,$on_unload);
6215: foreach my $key (keys(%{$attr_ref})) {
6216: if (lc($key) eq 'onload') {
6217: $on_load.=$attr_ref->{$key}.';';
6218: delete($attr_ref->{$key});
6219:
6220: } elsif (lc($key) eq 'onunload') {
6221: $on_unload.=$attr_ref->{$key}.';';
6222: delete($attr_ref->{$key});
6223: }
6224: }
1.1075.2.12 raeburn 6225: if ($env{'environment.remote'} eq 'on') {
6226: $attr_ref->{'onload'} =
6227: &Apache::lonmenu::loadevents(). $on_load;
6228: $attr_ref->{'onunload'}=
6229: &Apache::lonmenu::unloadevents().$on_unload;
6230: } else {
6231: $attr_ref->{'onload'} = $on_load;
6232: $attr_ref->{'onunload'}= $on_unload;
6233: }
1.330 albertel 6234: }
1.339 albertel 6235:
1.330 albertel 6236: my $attr_string;
1.1075.2.56 raeburn 6237: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6238: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6239: }
6240: return $attr_string;
6241: }
6242:
6243:
1.182 matthew 6244: ###############################################
1.251 albertel 6245: ###############################################
6246:
6247: =pod
6248:
6249: =item * &endbodytag()
6250:
6251: Returns a uniform footer for LON-CAPA web pages.
6252:
1.635 raeburn 6253: Inputs: 1 - optional reference to an args hash
6254: If in the hash, key for noredirectlink has a value which evaluates to true,
6255: a 'Continue' link is not displayed if the page contains an
6256: internal redirect in the <head></head> section,
6257: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6258:
6259: =cut
6260:
6261: sub endbodytag {
1.635 raeburn 6262: my ($args) = @_;
1.1075.2.6 raeburn 6263: my $endbodytag;
6264: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6265: $endbodytag='</body>';
6266: }
1.315 albertel 6267: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6268: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6269: $endbodytag=
6270: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6271: &mt('Continue').'</a>'.
6272: $endbodytag;
6273: }
1.315 albertel 6274: }
1.251 albertel 6275: return $endbodytag;
6276: }
6277:
1.352 albertel 6278: =pod
6279:
6280: =item * &standard_css()
6281:
6282: Returns a style sheet
6283:
6284: Inputs: (all optional)
6285: domain -> force to color decorate a page for a specific
6286: domain
6287: function -> force usage of a specific rolish color scheme
6288: bgcolor -> override the default page bgcolor
6289:
6290: =cut
6291:
1.343 albertel 6292: sub standard_css {
1.345 albertel 6293: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6294: $function = &get_users_function() if (!$function);
6295: my $img = &designparm($function.'.img', $domain);
6296: my $tabbg = &designparm($function.'.tabbg', $domain);
6297: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6298: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6299: #second colour for later usage
1.345 albertel 6300: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6301: my $pgbg_or_bgcolor =
6302: $bgcolor ||
1.352 albertel 6303: &designparm($function.'.pgbg', $domain);
1.382 albertel 6304: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6305: my $alink = &designparm($function.'.alink', $domain);
6306: my $vlink = &designparm($function.'.vlink', $domain);
6307: my $link = &designparm($function.'.link', $domain);
6308:
1.602 albertel 6309: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6310: my $mono = 'monospace';
1.850 bisitz 6311: my $data_table_head = $sidebg;
6312: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6313: my $data_table_dark = '#E0E0E0';
1.470 banghart 6314: my $data_table_darker = '#CCCCCC';
1.349 albertel 6315: my $data_table_highlight = '#FFFF00';
1.352 albertel 6316: my $mail_new = '#FFBB77';
6317: my $mail_new_hover = '#DD9955';
6318: my $mail_read = '#BBBB77';
6319: my $mail_read_hover = '#999944';
6320: my $mail_replied = '#AAAA88';
6321: my $mail_replied_hover = '#888855';
6322: my $mail_other = '#99BBBB';
6323: my $mail_other_hover = '#669999';
1.391 albertel 6324: my $table_header = '#DDDDDD';
1.489 raeburn 6325: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6326: my $lg_border_color = '#C8C8C8';
1.952 onken 6327: my $button_hover = '#BF2317';
1.392 albertel 6328:
1.608 albertel 6329: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6330: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6331: : '0 3px 0 4px';
1.448 albertel 6332:
1.523 albertel 6333:
1.343 albertel 6334: return <<END;
1.947 droeschl 6335:
6336: /* needed for iframe to allow 100% height in FF */
6337: body, html {
6338: margin: 0;
6339: padding: 0 0.5%;
6340: height: 99%; /* to avoid scrollbars */
6341: }
6342:
1.795 www 6343: body {
1.911 bisitz 6344: font-family: $sans;
6345: line-height:130%;
6346: font-size:0.83em;
6347: color:$font;
1.795 www 6348: }
6349:
1.959 onken 6350: a:focus,
6351: a:focus img {
1.795 www 6352: color: red;
6353: }
1.698 harmsja 6354:
1.911 bisitz 6355: form, .inline {
6356: display: inline;
1.795 www 6357: }
1.721 harmsja 6358:
1.795 www 6359: .LC_right {
1.911 bisitz 6360: text-align:right;
1.795 www 6361: }
6362:
6363: .LC_middle {
1.911 bisitz 6364: vertical-align:middle;
1.795 www 6365: }
1.721 harmsja 6366:
1.1075.2.38 raeburn 6367: .LC_floatleft {
6368: float: left;
6369: }
6370:
6371: .LC_floatright {
6372: float: right;
6373: }
6374:
1.911 bisitz 6375: .LC_400Box {
6376: width:400px;
6377: }
1.721 harmsja 6378:
1.947 droeschl 6379: .LC_iframecontainer {
6380: width: 98%;
6381: margin: 0;
6382: position: fixed;
6383: top: 8.5em;
6384: bottom: 0;
6385: }
6386:
6387: .LC_iframecontainer iframe{
6388: border: none;
6389: width: 100%;
6390: height: 100%;
6391: }
6392:
1.778 bisitz 6393: .LC_filename {
6394: font-family: $mono;
6395: white-space:pre;
1.921 bisitz 6396: font-size: 120%;
1.778 bisitz 6397: }
6398:
6399: .LC_fileicon {
6400: border: none;
6401: height: 1.3em;
6402: vertical-align: text-bottom;
6403: margin-right: 0.3em;
6404: text-decoration:none;
6405: }
6406:
1.1008 www 6407: .LC_setting {
6408: text-decoration:underline;
6409: }
6410:
1.350 albertel 6411: .LC_error {
6412: color: red;
6413: }
1.795 www 6414:
1.1075.2.15 raeburn 6415: .LC_warning {
6416: color: darkorange;
6417: }
6418:
1.457 albertel 6419: .LC_diff_removed {
1.733 bisitz 6420: color: red;
1.394 albertel 6421: }
1.532 albertel 6422:
6423: .LC_info,
1.457 albertel 6424: .LC_success,
6425: .LC_diff_added {
1.350 albertel 6426: color: green;
6427: }
1.795 www 6428:
1.802 bisitz 6429: div.LC_confirm_box {
6430: background-color: #FAFAFA;
6431: border: 1px solid $lg_border_color;
6432: margin-right: 0;
6433: padding: 5px;
6434: }
6435:
6436: div.LC_confirm_box .LC_error img,
6437: div.LC_confirm_box .LC_success img {
6438: vertical-align: middle;
6439: }
6440:
1.1075.2.108 raeburn 6441: .LC_maxwidth {
6442: max-width: 100%;
6443: height: auto;
6444: }
6445:
6446: .LC_textsize_mobile {
6447: \@media only screen and (max-device-width: 480px) {
6448: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6449: }
6450: }
6451:
1.440 albertel 6452: .LC_icon {
1.771 droeschl 6453: border: none;
1.790 droeschl 6454: vertical-align: middle;
1.771 droeschl 6455: }
6456:
1.543 albertel 6457: .LC_docs_spacer {
6458: width: 25px;
6459: height: 1px;
1.771 droeschl 6460: border: none;
1.543 albertel 6461: }
1.346 albertel 6462:
1.532 albertel 6463: .LC_internal_info {
1.735 bisitz 6464: color: #999999;
1.532 albertel 6465: }
6466:
1.794 www 6467: .LC_discussion {
1.1050 www 6468: background: $data_table_dark;
1.911 bisitz 6469: border: 1px solid black;
6470: margin: 2px;
1.794 www 6471: }
6472:
6473: .LC_disc_action_left {
1.1050 www 6474: background: $sidebg;
1.911 bisitz 6475: text-align: left;
1.1050 www 6476: padding: 4px;
6477: margin: 2px;
1.794 www 6478: }
6479:
6480: .LC_disc_action_right {
1.1050 www 6481: background: $sidebg;
1.911 bisitz 6482: text-align: right;
1.1050 www 6483: padding: 4px;
6484: margin: 2px;
1.794 www 6485: }
6486:
6487: .LC_disc_new_item {
1.911 bisitz 6488: background: white;
6489: border: 2px solid red;
1.1050 www 6490: margin: 4px;
6491: padding: 4px;
1.794 www 6492: }
6493:
6494: .LC_disc_old_item {
1.911 bisitz 6495: background: white;
1.1050 www 6496: margin: 4px;
6497: padding: 4px;
1.794 www 6498: }
6499:
1.458 albertel 6500: table.LC_pastsubmission {
6501: border: 1px solid black;
6502: margin: 2px;
6503: }
6504:
1.924 bisitz 6505: table#LC_menubuttons {
1.345 albertel 6506: width: 100%;
6507: background: $pgbg;
1.392 albertel 6508: border: 2px;
1.402 albertel 6509: border-collapse: separate;
1.803 bisitz 6510: padding: 0;
1.345 albertel 6511: }
1.392 albertel 6512:
1.801 tempelho 6513: table#LC_title_bar a {
6514: color: $fontmenu;
6515: }
1.836 bisitz 6516:
1.807 droeschl 6517: table#LC_title_bar {
1.819 tempelho 6518: clear: both;
1.836 bisitz 6519: display: none;
1.807 droeschl 6520: }
6521:
1.795 www 6522: table#LC_title_bar,
1.933 droeschl 6523: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6524: table#LC_title_bar.LC_with_remote {
1.359 albertel 6525: width: 100%;
1.392 albertel 6526: border-color: $pgbg;
6527: border-style: solid;
6528: border-width: $border;
1.379 albertel 6529: background: $pgbg;
1.801 tempelho 6530: color: $fontmenu;
1.392 albertel 6531: border-collapse: collapse;
1.803 bisitz 6532: padding: 0;
1.819 tempelho 6533: margin: 0;
1.359 albertel 6534: }
1.795 www 6535:
1.933 droeschl 6536: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6537: margin: 0;
6538: padding: 0;
1.933 droeschl 6539: position: relative;
6540: list-style: none;
1.913 droeschl 6541: }
1.933 droeschl 6542: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6543: display: inline;
6544: }
1.933 droeschl 6545:
6546: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6547: padding: 0;
1.933 droeschl 6548: margin: 0;
6549: float: left;
1.913 droeschl 6550: }
1.933 droeschl 6551: .LC_breadcrumb_tools_tools {
6552: padding: 0;
6553: margin: 0;
1.913 droeschl 6554: float: right;
6555: }
6556:
1.359 albertel 6557: table#LC_title_bar td {
6558: background: $tabbg;
6559: }
1.795 www 6560:
1.911 bisitz 6561: table#LC_menubuttons img {
1.803 bisitz 6562: border: none;
1.346 albertel 6563: }
1.795 www 6564:
1.842 droeschl 6565: .LC_breadcrumbs_component {
1.911 bisitz 6566: float: right;
6567: margin: 0 1em;
1.357 albertel 6568: }
1.842 droeschl 6569: .LC_breadcrumbs_component img {
1.911 bisitz 6570: vertical-align: middle;
1.777 tempelho 6571: }
1.795 www 6572:
1.1075.2.108 raeburn 6573: .LC_breadcrumbs_hoverable {
6574: background: $sidebg;
6575: }
6576:
1.383 albertel 6577: td.LC_table_cell_checkbox {
6578: text-align: center;
6579: }
1.795 www 6580:
6581: .LC_fontsize_small {
1.911 bisitz 6582: font-size: 70%;
1.705 tempelho 6583: }
6584:
1.844 bisitz 6585: #LC_breadcrumbs {
1.911 bisitz 6586: clear:both;
6587: background: $sidebg;
6588: border-bottom: 1px solid $lg_border_color;
6589: line-height: 2.5em;
1.933 droeschl 6590: overflow: hidden;
1.911 bisitz 6591: margin: 0;
6592: padding: 0;
1.995 raeburn 6593: text-align: left;
1.819 tempelho 6594: }
1.862 bisitz 6595:
1.1075.2.16 raeburn 6596: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6597: clear:both;
6598: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6599: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6600: margin: 0 0 10px 0;
1.966 bisitz 6601: padding: 3px;
1.995 raeburn 6602: text-align: left;
1.822 bisitz 6603: }
6604:
1.795 www 6605: .LC_fontsize_medium {
1.911 bisitz 6606: font-size: 85%;
1.705 tempelho 6607: }
6608:
1.795 www 6609: .LC_fontsize_large {
1.911 bisitz 6610: font-size: 120%;
1.705 tempelho 6611: }
6612:
1.346 albertel 6613: .LC_menubuttons_inline_text {
6614: color: $font;
1.698 harmsja 6615: font-size: 90%;
1.701 harmsja 6616: padding-left:3px;
1.346 albertel 6617: }
6618:
1.934 droeschl 6619: .LC_menubuttons_inline_text img{
6620: vertical-align: middle;
6621: }
6622:
1.1051 www 6623: li.LC_menubuttons_inline_text img {
1.951 onken 6624: cursor:pointer;
1.1002 droeschl 6625: text-decoration: none;
1.951 onken 6626: }
6627:
1.526 www 6628: .LC_menubuttons_link {
6629: text-decoration: none;
6630: }
1.795 www 6631:
1.522 albertel 6632: .LC_menubuttons_category {
1.521 www 6633: color: $font;
1.526 www 6634: background: $pgbg;
1.521 www 6635: font-size: larger;
6636: font-weight: bold;
6637: }
6638:
1.346 albertel 6639: td.LC_menubuttons_text {
1.911 bisitz 6640: color: $font;
1.346 albertel 6641: }
1.706 harmsja 6642:
1.346 albertel 6643: .LC_current_location {
6644: background: $tabbg;
6645: }
1.795 www 6646:
1.1075.2.134 raeburn 6647: td.LC_zero_height {
6648: line-height: 0;
6649: cellpadding: 0;
6650: }
6651:
1.938 bisitz 6652: table.LC_data_table {
1.347 albertel 6653: border: 1px solid #000000;
1.402 albertel 6654: border-collapse: separate;
1.426 albertel 6655: border-spacing: 1px;
1.610 albertel 6656: background: $pgbg;
1.347 albertel 6657: }
1.795 www 6658:
1.422 albertel 6659: .LC_data_table_dense {
6660: font-size: small;
6661: }
1.795 www 6662:
1.507 raeburn 6663: table.LC_nested_outer {
6664: border: 1px solid #000000;
1.589 raeburn 6665: border-collapse: collapse;
1.803 bisitz 6666: border-spacing: 0;
1.507 raeburn 6667: width: 100%;
6668: }
1.795 www 6669:
1.879 raeburn 6670: table.LC_innerpickbox,
1.507 raeburn 6671: table.LC_nested {
1.803 bisitz 6672: border: none;
1.589 raeburn 6673: border-collapse: collapse;
1.803 bisitz 6674: border-spacing: 0;
1.507 raeburn 6675: width: 100%;
6676: }
1.795 www 6677:
1.911 bisitz 6678: table.LC_data_table tr th,
6679: table.LC_calendar tr th,
1.879 raeburn 6680: table.LC_prior_tries tr th,
6681: table.LC_innerpickbox tr th {
1.349 albertel 6682: font-weight: bold;
6683: background-color: $data_table_head;
1.801 tempelho 6684: color:$fontmenu;
1.701 harmsja 6685: font-size:90%;
1.347 albertel 6686: }
1.795 www 6687:
1.879 raeburn 6688: table.LC_innerpickbox tr th,
6689: table.LC_innerpickbox tr td {
6690: vertical-align: top;
6691: }
6692:
1.711 raeburn 6693: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6694: background-color: #CCCCCC;
1.711 raeburn 6695: font-weight: bold;
6696: text-align: left;
6697: }
1.795 www 6698:
1.912 bisitz 6699: table.LC_data_table tr.LC_odd_row > td {
6700: background-color: $data_table_light;
6701: padding: 2px;
6702: vertical-align: top;
6703: }
6704:
1.809 bisitz 6705: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6706: background-color: $data_table_light;
1.912 bisitz 6707: vertical-align: top;
6708: }
6709:
6710: table.LC_data_table tr.LC_even_row > td {
6711: background-color: $data_table_dark;
1.425 albertel 6712: padding: 2px;
1.900 bisitz 6713: vertical-align: top;
1.347 albertel 6714: }
1.795 www 6715:
1.809 bisitz 6716: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6717: background-color: $data_table_dark;
1.900 bisitz 6718: vertical-align: top;
1.347 albertel 6719: }
1.795 www 6720:
1.425 albertel 6721: table.LC_data_table tr.LC_data_table_highlight td {
6722: background-color: $data_table_darker;
6723: }
1.795 www 6724:
1.639 raeburn 6725: table.LC_data_table tr td.LC_leftcol_header {
6726: background-color: $data_table_head;
6727: font-weight: bold;
6728: }
1.795 www 6729:
1.451 albertel 6730: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6731: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6732: font-weight: bold;
6733: font-style: italic;
6734: text-align: center;
6735: padding: 8px;
1.347 albertel 6736: }
1.795 www 6737:
1.1075.2.30 raeburn 6738: table.LC_data_table tr.LC_empty_row td,
6739: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6740: background-color: $sidebg;
6741: }
6742:
6743: table.LC_nested tr.LC_empty_row td {
6744: background-color: #FFFFFF;
6745: }
6746:
1.890 droeschl 6747: table.LC_caption {
6748: }
6749:
1.507 raeburn 6750: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6751: padding: 4ex
6752: }
1.795 www 6753:
1.507 raeburn 6754: table.LC_nested_outer tr th {
6755: font-weight: bold;
1.801 tempelho 6756: color:$fontmenu;
1.507 raeburn 6757: background-color: $data_table_head;
1.701 harmsja 6758: font-size: small;
1.507 raeburn 6759: border-bottom: 1px solid #000000;
6760: }
1.795 www 6761:
1.507 raeburn 6762: table.LC_nested_outer tr td.LC_subheader {
6763: background-color: $data_table_head;
6764: font-weight: bold;
6765: font-size: small;
6766: border-bottom: 1px solid #000000;
6767: text-align: right;
1.451 albertel 6768: }
1.795 www 6769:
1.507 raeburn 6770: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6771: background-color: #CCCCCC;
1.451 albertel 6772: font-weight: bold;
6773: font-size: small;
1.507 raeburn 6774: text-align: center;
6775: }
1.795 www 6776:
1.589 raeburn 6777: table.LC_nested tr.LC_info_row td.LC_left_item,
6778: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6779: text-align: left;
1.451 albertel 6780: }
1.795 www 6781:
1.507 raeburn 6782: table.LC_nested td {
1.735 bisitz 6783: background-color: #FFFFFF;
1.451 albertel 6784: font-size: small;
1.507 raeburn 6785: }
1.795 www 6786:
1.507 raeburn 6787: table.LC_nested_outer tr th.LC_right_item,
6788: table.LC_nested tr.LC_info_row td.LC_right_item,
6789: table.LC_nested tr.LC_odd_row td.LC_right_item,
6790: table.LC_nested tr td.LC_right_item {
1.451 albertel 6791: text-align: right;
6792: }
6793:
1.507 raeburn 6794: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6795: background-color: #EEEEEE;
1.451 albertel 6796: }
6797:
1.473 raeburn 6798: table.LC_createuser {
6799: }
6800:
6801: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6802: font-size: small;
1.473 raeburn 6803: }
6804:
6805: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6806: background-color: #CCCCCC;
1.473 raeburn 6807: font-weight: bold;
6808: text-align: center;
6809: }
6810:
1.349 albertel 6811: table.LC_calendar {
6812: border: 1px solid #000000;
6813: border-collapse: collapse;
1.917 raeburn 6814: width: 98%;
1.349 albertel 6815: }
1.795 www 6816:
1.349 albertel 6817: table.LC_calendar_pickdate {
6818: font-size: xx-small;
6819: }
1.795 www 6820:
1.349 albertel 6821: table.LC_calendar tr td {
6822: border: 1px solid #000000;
6823: vertical-align: top;
1.917 raeburn 6824: width: 14%;
1.349 albertel 6825: }
1.795 www 6826:
1.349 albertel 6827: table.LC_calendar tr td.LC_calendar_day_empty {
6828: background-color: $data_table_dark;
6829: }
1.795 www 6830:
1.779 bisitz 6831: table.LC_calendar tr td.LC_calendar_day_current {
6832: background-color: $data_table_highlight;
1.777 tempelho 6833: }
1.795 www 6834:
1.938 bisitz 6835: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6836: background-color: $mail_new;
6837: }
1.795 www 6838:
1.938 bisitz 6839: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6840: background-color: $mail_new_hover;
6841: }
1.795 www 6842:
1.938 bisitz 6843: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6844: background-color: $mail_read;
6845: }
1.795 www 6846:
1.938 bisitz 6847: /*
6848: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6849: background-color: $mail_read_hover;
6850: }
1.938 bisitz 6851: */
1.795 www 6852:
1.938 bisitz 6853: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6854: background-color: $mail_replied;
6855: }
1.795 www 6856:
1.938 bisitz 6857: /*
6858: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6859: background-color: $mail_replied_hover;
6860: }
1.938 bisitz 6861: */
1.795 www 6862:
1.938 bisitz 6863: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6864: background-color: $mail_other;
6865: }
1.795 www 6866:
1.938 bisitz 6867: /*
6868: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6869: background-color: $mail_other_hover;
6870: }
1.938 bisitz 6871: */
1.494 raeburn 6872:
1.777 tempelho 6873: table.LC_data_table tr > td.LC_browser_file,
6874: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6875: background: #AAEE77;
1.389 albertel 6876: }
1.795 www 6877:
1.777 tempelho 6878: table.LC_data_table tr > td.LC_browser_file_locked,
6879: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6880: background: #FFAA99;
1.387 albertel 6881: }
1.795 www 6882:
1.777 tempelho 6883: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6884: background: #888888;
1.779 bisitz 6885: }
1.795 www 6886:
1.777 tempelho 6887: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6888: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6889: background: #F8F866;
1.777 tempelho 6890: }
1.795 www 6891:
1.696 bisitz 6892: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6893: background: #E0E8FF;
1.387 albertel 6894: }
1.696 bisitz 6895:
1.707 bisitz 6896: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6897: /* background: #77FF77; */
1.707 bisitz 6898: }
1.795 www 6899:
1.707 bisitz 6900: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6901: border-right: 8px solid #FFFF77;
1.707 bisitz 6902: }
1.795 www 6903:
1.707 bisitz 6904: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6905: border-right: 8px solid #FFAA77;
1.707 bisitz 6906: }
1.795 www 6907:
1.707 bisitz 6908: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6909: border-right: 8px solid #FF7777;
1.707 bisitz 6910: }
1.795 www 6911:
1.707 bisitz 6912: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6913: border-right: 8px solid #AAFF77;
1.707 bisitz 6914: }
1.795 www 6915:
1.707 bisitz 6916: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6917: border-right: 8px solid #11CC55;
1.707 bisitz 6918: }
6919:
1.388 albertel 6920: span.LC_current_location {
1.701 harmsja 6921: font-size:larger;
1.388 albertel 6922: background: $pgbg;
6923: }
1.387 albertel 6924:
1.1029 www 6925: span.LC_current_nav_location {
6926: font-weight:bold;
6927: background: $sidebg;
6928: }
6929:
1.395 albertel 6930: span.LC_parm_menu_item {
6931: font-size: larger;
6932: }
1.795 www 6933:
1.395 albertel 6934: span.LC_parm_scope_all {
6935: color: red;
6936: }
1.795 www 6937:
1.395 albertel 6938: span.LC_parm_scope_folder {
6939: color: green;
6940: }
1.795 www 6941:
1.395 albertel 6942: span.LC_parm_scope_resource {
6943: color: orange;
6944: }
1.795 www 6945:
1.395 albertel 6946: span.LC_parm_part {
6947: color: blue;
6948: }
1.795 www 6949:
1.911 bisitz 6950: span.LC_parm_folder,
6951: span.LC_parm_symb {
1.395 albertel 6952: font-size: x-small;
6953: font-family: $mono;
6954: color: #AAAAAA;
6955: }
6956:
1.977 bisitz 6957: ul.LC_parm_parmlist li {
6958: display: inline-block;
6959: padding: 0.3em 0.8em;
6960: vertical-align: top;
6961: width: 150px;
6962: border-top:1px solid $lg_border_color;
6963: }
6964:
1.795 www 6965: td.LC_parm_overview_level_menu,
6966: td.LC_parm_overview_map_menu,
6967: td.LC_parm_overview_parm_selectors,
6968: td.LC_parm_overview_restrictions {
1.396 albertel 6969: border: 1px solid black;
6970: border-collapse: collapse;
6971: }
1.795 www 6972:
1.396 albertel 6973: table.LC_parm_overview_restrictions td {
6974: border-width: 1px 4px 1px 4px;
6975: border-style: solid;
6976: border-color: $pgbg;
6977: text-align: center;
6978: }
1.795 www 6979:
1.396 albertel 6980: table.LC_parm_overview_restrictions th {
6981: background: $tabbg;
6982: border-width: 1px 4px 1px 4px;
6983: border-style: solid;
6984: border-color: $pgbg;
6985: }
1.795 www 6986:
1.398 albertel 6987: table#LC_helpmenu {
1.803 bisitz 6988: border: none;
1.398 albertel 6989: height: 55px;
1.803 bisitz 6990: border-spacing: 0;
1.398 albertel 6991: }
6992:
6993: table#LC_helpmenu fieldset legend {
6994: font-size: larger;
6995: }
1.795 www 6996:
1.397 albertel 6997: table#LC_helpmenu_links {
6998: width: 100%;
6999: border: 1px solid black;
7000: background: $pgbg;
1.803 bisitz 7001: padding: 0;
1.397 albertel 7002: border-spacing: 1px;
7003: }
1.795 www 7004:
1.397 albertel 7005: table#LC_helpmenu_links tr td {
7006: padding: 1px;
7007: background: $tabbg;
1.399 albertel 7008: text-align: center;
7009: font-weight: bold;
1.397 albertel 7010: }
1.396 albertel 7011:
1.795 www 7012: table#LC_helpmenu_links a:link,
7013: table#LC_helpmenu_links a:visited,
1.397 albertel 7014: table#LC_helpmenu_links a:active {
7015: text-decoration: none;
7016: color: $font;
7017: }
1.795 www 7018:
1.397 albertel 7019: table#LC_helpmenu_links a:hover {
7020: text-decoration: underline;
7021: color: $vlink;
7022: }
1.396 albertel 7023:
1.417 albertel 7024: .LC_chrt_popup_exists {
7025: border: 1px solid #339933;
7026: margin: -1px;
7027: }
1.795 www 7028:
1.417 albertel 7029: .LC_chrt_popup_up {
7030: border: 1px solid yellow;
7031: margin: -1px;
7032: }
1.795 www 7033:
1.417 albertel 7034: .LC_chrt_popup {
7035: border: 1px solid #8888FF;
7036: background: #CCCCFF;
7037: }
1.795 www 7038:
1.421 albertel 7039: table.LC_pick_box {
7040: border-collapse: separate;
7041: background: white;
7042: border: 1px solid black;
7043: border-spacing: 1px;
7044: }
1.795 www 7045:
1.421 albertel 7046: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7047: background: $sidebg;
1.421 albertel 7048: font-weight: bold;
1.900 bisitz 7049: text-align: left;
1.740 bisitz 7050: vertical-align: top;
1.421 albertel 7051: width: 184px;
7052: padding: 8px;
7053: }
1.795 www 7054:
1.579 raeburn 7055: table.LC_pick_box td.LC_pick_box_value {
7056: text-align: left;
7057: padding: 8px;
7058: }
1.795 www 7059:
1.579 raeburn 7060: table.LC_pick_box td.LC_pick_box_select {
7061: text-align: left;
7062: padding: 8px;
7063: }
1.795 www 7064:
1.424 albertel 7065: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7066: padding: 0;
1.421 albertel 7067: height: 1px;
7068: background: black;
7069: }
1.795 www 7070:
1.421 albertel 7071: table.LC_pick_box td.LC_pick_box_submit {
7072: text-align: right;
7073: }
1.795 www 7074:
1.579 raeburn 7075: table.LC_pick_box td.LC_evenrow_value {
7076: text-align: left;
7077: padding: 8px;
7078: background-color: $data_table_light;
7079: }
1.795 www 7080:
1.579 raeburn 7081: table.LC_pick_box td.LC_oddrow_value {
7082: text-align: left;
7083: padding: 8px;
7084: background-color: $data_table_light;
7085: }
1.795 www 7086:
1.579 raeburn 7087: span.LC_helpform_receipt_cat {
7088: font-weight: bold;
7089: }
1.795 www 7090:
1.424 albertel 7091: table.LC_group_priv_box {
7092: background: white;
7093: border: 1px solid black;
7094: border-spacing: 1px;
7095: }
1.795 www 7096:
1.424 albertel 7097: table.LC_group_priv_box td.LC_pick_box_title {
7098: background: $tabbg;
7099: font-weight: bold;
7100: text-align: right;
7101: width: 184px;
7102: }
1.795 www 7103:
1.424 albertel 7104: table.LC_group_priv_box td.LC_groups_fixed {
7105: background: $data_table_light;
7106: text-align: center;
7107: }
1.795 www 7108:
1.424 albertel 7109: table.LC_group_priv_box td.LC_groups_optional {
7110: background: $data_table_dark;
7111: text-align: center;
7112: }
1.795 www 7113:
1.424 albertel 7114: table.LC_group_priv_box td.LC_groups_functionality {
7115: background: $data_table_darker;
7116: text-align: center;
7117: font-weight: bold;
7118: }
1.795 www 7119:
1.424 albertel 7120: table.LC_group_priv td {
7121: text-align: left;
1.803 bisitz 7122: padding: 0;
1.424 albertel 7123: }
7124:
7125: .LC_navbuttons {
7126: margin: 2ex 0ex 2ex 0ex;
7127: }
1.795 www 7128:
1.423 albertel 7129: .LC_topic_bar {
7130: font-weight: bold;
7131: background: $tabbg;
1.918 wenzelju 7132: margin: 1em 0em 1em 2em;
1.805 bisitz 7133: padding: 3px;
1.918 wenzelju 7134: font-size: 1.2em;
1.423 albertel 7135: }
1.795 www 7136:
1.423 albertel 7137: .LC_topic_bar span {
1.918 wenzelju 7138: left: 0.5em;
7139: position: absolute;
1.423 albertel 7140: vertical-align: middle;
1.918 wenzelju 7141: font-size: 1.2em;
1.423 albertel 7142: }
1.795 www 7143:
1.423 albertel 7144: table.LC_course_group_status {
7145: margin: 20px;
7146: }
1.795 www 7147:
1.423 albertel 7148: table.LC_status_selector td {
7149: vertical-align: top;
7150: text-align: center;
1.424 albertel 7151: padding: 4px;
7152: }
1.795 www 7153:
1.599 albertel 7154: div.LC_feedback_link {
1.616 albertel 7155: clear: both;
1.829 kalberla 7156: background: $sidebg;
1.779 bisitz 7157: width: 100%;
1.829 kalberla 7158: padding-bottom: 10px;
7159: border: 1px $tabbg solid;
1.833 kalberla 7160: height: 22px;
7161: line-height: 22px;
7162: padding-top: 5px;
7163: }
7164:
7165: div.LC_feedback_link img {
7166: height: 22px;
1.867 kalberla 7167: vertical-align:middle;
1.829 kalberla 7168: }
7169:
1.911 bisitz 7170: div.LC_feedback_link a {
1.829 kalberla 7171: text-decoration: none;
1.489 raeburn 7172: }
1.795 www 7173:
1.867 kalberla 7174: div.LC_comblock {
1.911 bisitz 7175: display:inline;
1.867 kalberla 7176: color:$font;
7177: font-size:90%;
7178: }
7179:
7180: div.LC_feedback_link div.LC_comblock {
7181: padding-left:5px;
7182: }
7183:
7184: div.LC_feedback_link div.LC_comblock a {
7185: color:$font;
7186: }
7187:
1.489 raeburn 7188: span.LC_feedback_link {
1.858 bisitz 7189: /* background: $feedback_link_bg; */
1.599 albertel 7190: font-size: larger;
7191: }
1.795 www 7192:
1.599 albertel 7193: span.LC_message_link {
1.858 bisitz 7194: /* background: $feedback_link_bg; */
1.599 albertel 7195: font-size: larger;
7196: position: absolute;
7197: right: 1em;
1.489 raeburn 7198: }
1.421 albertel 7199:
1.515 albertel 7200: table.LC_prior_tries {
1.524 albertel 7201: border: 1px solid #000000;
7202: border-collapse: separate;
7203: border-spacing: 1px;
1.515 albertel 7204: }
1.523 albertel 7205:
1.515 albertel 7206: table.LC_prior_tries td {
1.524 albertel 7207: padding: 2px;
1.515 albertel 7208: }
1.523 albertel 7209:
7210: .LC_answer_correct {
1.795 www 7211: background: lightgreen;
7212: color: darkgreen;
7213: padding: 6px;
1.523 albertel 7214: }
1.795 www 7215:
1.523 albertel 7216: .LC_answer_charged_try {
1.797 www 7217: background: #FFAAAA;
1.795 www 7218: color: darkred;
7219: padding: 6px;
1.523 albertel 7220: }
1.795 www 7221:
1.779 bisitz 7222: .LC_answer_not_charged_try,
1.523 albertel 7223: .LC_answer_no_grade,
7224: .LC_answer_late {
1.795 www 7225: background: lightyellow;
1.523 albertel 7226: color: black;
1.795 www 7227: padding: 6px;
1.523 albertel 7228: }
1.795 www 7229:
1.523 albertel 7230: .LC_answer_previous {
1.795 www 7231: background: lightblue;
7232: color: darkblue;
7233: padding: 6px;
1.523 albertel 7234: }
1.795 www 7235:
1.779 bisitz 7236: .LC_answer_no_message {
1.777 tempelho 7237: background: #FFFFFF;
7238: color: black;
1.795 www 7239: padding: 6px;
1.779 bisitz 7240: }
1.795 www 7241:
1.1075.2.140 raeburn 7242: .LC_answer_unknown,
7243: .LC_answer_warning {
1.779 bisitz 7244: background: orange;
7245: color: black;
1.795 www 7246: padding: 6px;
1.777 tempelho 7247: }
1.795 www 7248:
1.529 albertel 7249: span.LC_prior_numerical,
7250: span.LC_prior_string,
7251: span.LC_prior_custom,
7252: span.LC_prior_reaction,
7253: span.LC_prior_math {
1.925 bisitz 7254: font-family: $mono;
1.523 albertel 7255: white-space: pre;
7256: }
7257:
1.525 albertel 7258: span.LC_prior_string {
1.925 bisitz 7259: font-family: $mono;
1.525 albertel 7260: white-space: pre;
7261: }
7262:
1.523 albertel 7263: table.LC_prior_option {
7264: width: 100%;
7265: border-collapse: collapse;
7266: }
1.795 www 7267:
1.911 bisitz 7268: table.LC_prior_rank,
1.795 www 7269: table.LC_prior_match {
1.528 albertel 7270: border-collapse: collapse;
7271: }
1.795 www 7272:
1.528 albertel 7273: table.LC_prior_option tr td,
7274: table.LC_prior_rank tr td,
7275: table.LC_prior_match tr td {
1.524 albertel 7276: border: 1px solid #000000;
1.515 albertel 7277: }
7278:
1.855 bisitz 7279: .LC_nobreak {
1.544 albertel 7280: white-space: nowrap;
1.519 raeburn 7281: }
7282:
1.576 raeburn 7283: span.LC_cusr_emph {
7284: font-style: italic;
7285: }
7286:
1.633 raeburn 7287: span.LC_cusr_subheading {
7288: font-weight: normal;
7289: font-size: 85%;
7290: }
7291:
1.861 bisitz 7292: div.LC_docs_entry_move {
1.859 bisitz 7293: border: 1px solid #BBBBBB;
1.545 albertel 7294: background: #DDDDDD;
1.861 bisitz 7295: width: 22px;
1.859 bisitz 7296: padding: 1px;
7297: margin: 0;
1.545 albertel 7298: }
7299:
1.861 bisitz 7300: table.LC_data_table tr > td.LC_docs_entry_commands,
7301: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7302: font-size: x-small;
7303: }
1.795 www 7304:
1.861 bisitz 7305: .LC_docs_entry_parameter {
7306: white-space: nowrap;
7307: }
7308:
1.544 albertel 7309: .LC_docs_copy {
1.545 albertel 7310: color: #000099;
1.544 albertel 7311: }
1.795 www 7312:
1.544 albertel 7313: .LC_docs_cut {
1.545 albertel 7314: color: #550044;
1.544 albertel 7315: }
1.795 www 7316:
1.544 albertel 7317: .LC_docs_rename {
1.545 albertel 7318: color: #009900;
1.544 albertel 7319: }
1.795 www 7320:
1.544 albertel 7321: .LC_docs_remove {
1.545 albertel 7322: color: #990000;
7323: }
7324:
1.1075.2.134 raeburn 7325: .LC_domprefs_email,
1.547 albertel 7326: .LC_docs_reinit_warn,
7327: .LC_docs_ext_edit {
7328: font-size: x-small;
7329: }
7330:
1.545 albertel 7331: table.LC_docs_adddocs td,
7332: table.LC_docs_adddocs th {
7333: border: 1px solid #BBBBBB;
7334: padding: 4px;
7335: background: #DDDDDD;
1.543 albertel 7336: }
7337:
1.584 albertel 7338: table.LC_sty_begin {
7339: background: #BBFFBB;
7340: }
1.795 www 7341:
1.584 albertel 7342: table.LC_sty_end {
7343: background: #FFBBBB;
7344: }
7345:
1.589 raeburn 7346: table.LC_double_column {
1.803 bisitz 7347: border-width: 0;
1.589 raeburn 7348: border-collapse: collapse;
7349: width: 100%;
7350: padding: 2px;
7351: }
7352:
7353: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7354: top: 2px;
1.589 raeburn 7355: left: 2px;
7356: width: 47%;
7357: vertical-align: top;
7358: }
7359:
7360: table.LC_double_column tr td.LC_right_col {
7361: top: 2px;
1.779 bisitz 7362: right: 2px;
1.589 raeburn 7363: width: 47%;
7364: vertical-align: top;
7365: }
7366:
1.591 raeburn 7367: div.LC_left_float {
7368: float: left;
7369: padding-right: 5%;
1.597 albertel 7370: padding-bottom: 4px;
1.591 raeburn 7371: }
7372:
7373: div.LC_clear_float_header {
1.597 albertel 7374: padding-bottom: 2px;
1.591 raeburn 7375: }
7376:
7377: div.LC_clear_float_footer {
1.597 albertel 7378: padding-top: 10px;
1.591 raeburn 7379: clear: both;
7380: }
7381:
1.597 albertel 7382: div.LC_grade_show_user {
1.941 bisitz 7383: /* border-left: 5px solid $sidebg; */
7384: border-top: 5px solid #000000;
7385: margin: 50px 0 0 0;
1.936 bisitz 7386: padding: 15px 0 5px 10px;
1.597 albertel 7387: }
1.795 www 7388:
1.936 bisitz 7389: div.LC_grade_show_user_odd_row {
1.941 bisitz 7390: /* border-left: 5px solid #000000; */
7391: }
7392:
7393: div.LC_grade_show_user div.LC_Box {
7394: margin-right: 50px;
1.597 albertel 7395: }
7396:
7397: div.LC_grade_submissions,
7398: div.LC_grade_message_center,
1.936 bisitz 7399: div.LC_grade_info_links {
1.597 albertel 7400: margin: 5px;
7401: width: 99%;
7402: background: #FFFFFF;
7403: }
1.795 www 7404:
1.597 albertel 7405: div.LC_grade_submissions_header,
1.936 bisitz 7406: div.LC_grade_message_center_header {
1.705 tempelho 7407: font-weight: bold;
7408: font-size: large;
1.597 albertel 7409: }
1.795 www 7410:
1.597 albertel 7411: div.LC_grade_submissions_body,
1.936 bisitz 7412: div.LC_grade_message_center_body {
1.597 albertel 7413: border: 1px solid black;
7414: width: 99%;
7415: background: #FFFFFF;
7416: }
1.795 www 7417:
1.613 albertel 7418: table.LC_scantron_action {
7419: width: 100%;
7420: }
1.795 www 7421:
1.613 albertel 7422: table.LC_scantron_action tr th {
1.698 harmsja 7423: font-weight:bold;
7424: font-style:normal;
1.613 albertel 7425: }
1.795 www 7426:
1.779 bisitz 7427: .LC_edit_problem_header,
1.614 albertel 7428: div.LC_edit_problem_footer {
1.705 tempelho 7429: font-weight: normal;
7430: font-size: medium;
1.602 albertel 7431: margin: 2px;
1.1060 bisitz 7432: background-color: $sidebg;
1.600 albertel 7433: }
1.795 www 7434:
1.600 albertel 7435: div.LC_edit_problem_header,
1.602 albertel 7436: div.LC_edit_problem_header div,
1.614 albertel 7437: div.LC_edit_problem_footer,
7438: div.LC_edit_problem_footer div,
1.602 albertel 7439: div.LC_edit_problem_editxml_header,
7440: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7441: z-index: 100;
1.600 albertel 7442: }
1.795 www 7443:
1.600 albertel 7444: div.LC_edit_problem_header_title {
1.705 tempelho 7445: font-weight: bold;
7446: font-size: larger;
1.602 albertel 7447: background: $tabbg;
7448: padding: 3px;
1.1060 bisitz 7449: margin: 0 0 5px 0;
1.602 albertel 7450: }
1.795 www 7451:
1.602 albertel 7452: table.LC_edit_problem_header_title {
7453: width: 100%;
1.600 albertel 7454: background: $tabbg;
1.602 albertel 7455: }
7456:
1.1075.2.112 raeburn 7457: div.LC_edit_actionbar {
7458: background-color: $sidebg;
7459: margin: 0;
7460: padding: 0;
7461: line-height: 200%;
1.602 albertel 7462: }
1.795 www 7463:
1.1075.2.112 raeburn 7464: div.LC_edit_actionbar div{
7465: padding: 0;
7466: margin: 0;
7467: display: inline-block;
1.600 albertel 7468: }
1.795 www 7469:
1.1075.2.34 raeburn 7470: .LC_edit_opt {
7471: padding-left: 1em;
7472: white-space: nowrap;
7473: }
7474:
1.1075.2.57 raeburn 7475: .LC_edit_problem_latexhelper{
7476: text-align: right;
7477: }
7478:
7479: #LC_edit_problem_colorful div{
7480: margin-left: 40px;
7481: }
7482:
1.1075.2.112 raeburn 7483: #LC_edit_problem_codemirror div{
7484: margin-left: 0px;
7485: }
7486:
1.911 bisitz 7487: img.stift {
1.803 bisitz 7488: border-width: 0;
7489: vertical-align: middle;
1.677 riegler 7490: }
1.680 riegler 7491:
1.923 bisitz 7492: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7493: vertical-align: top;
1.777 tempelho 7494: }
1.795 www 7495:
1.716 raeburn 7496: div.LC_createcourse {
1.911 bisitz 7497: margin: 10px 10px 10px 10px;
1.716 raeburn 7498: }
7499:
1.917 raeburn 7500: .LC_dccid {
1.1075.2.38 raeburn 7501: float: right;
1.917 raeburn 7502: margin: 0.2em 0 0 0;
7503: padding: 0;
7504: font-size: 90%;
7505: display:none;
7506: }
7507:
1.897 wenzelju 7508: ol.LC_primary_menu a:hover,
1.721 harmsja 7509: ol#LC_MenuBreadcrumbs a:hover,
7510: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7511: ul#LC_secondary_menu a:hover,
1.721 harmsja 7512: .LC_FormSectionClearButton input:hover
1.795 www 7513: ul.LC_TabContent li:hover a {
1.952 onken 7514: color:$button_hover;
1.911 bisitz 7515: text-decoration:none;
1.693 droeschl 7516: }
7517:
1.779 bisitz 7518: h1 {
1.911 bisitz 7519: padding: 0;
7520: line-height:130%;
1.693 droeschl 7521: }
1.698 harmsja 7522:
1.911 bisitz 7523: h2,
7524: h3,
7525: h4,
7526: h5,
7527: h6 {
7528: margin: 5px 0 5px 0;
7529: padding: 0;
7530: line-height:130%;
1.693 droeschl 7531: }
1.795 www 7532:
7533: .LC_hcell {
1.911 bisitz 7534: padding:3px 15px 3px 15px;
7535: margin: 0;
7536: background-color:$tabbg;
7537: color:$fontmenu;
7538: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7539: }
1.795 www 7540:
1.840 bisitz 7541: .LC_Box > .LC_hcell {
1.911 bisitz 7542: margin: 0 -10px 10px -10px;
1.835 bisitz 7543: }
7544:
1.721 harmsja 7545: .LC_noBorder {
1.911 bisitz 7546: border: 0;
1.698 harmsja 7547: }
1.693 droeschl 7548:
1.721 harmsja 7549: .LC_FormSectionClearButton input {
1.911 bisitz 7550: background-color:transparent;
7551: border: none;
7552: cursor:pointer;
7553: text-decoration:underline;
1.693 droeschl 7554: }
1.763 bisitz 7555:
7556: .LC_help_open_topic {
1.911 bisitz 7557: color: #FFFFFF;
7558: background-color: #EEEEFF;
7559: margin: 1px;
7560: padding: 4px;
7561: border: 1px solid #000033;
7562: white-space: nowrap;
7563: /* vertical-align: middle; */
1.759 neumanie 7564: }
1.693 droeschl 7565:
1.911 bisitz 7566: dl,
7567: ul,
7568: div,
7569: fieldset {
7570: margin: 10px 10px 10px 0;
7571: /* overflow: hidden; */
1.693 droeschl 7572: }
1.795 www 7573:
1.1075.2.90 raeburn 7574: article.geogebraweb div {
7575: margin: 0;
7576: }
7577:
1.838 bisitz 7578: fieldset > legend {
1.911 bisitz 7579: font-weight: bold;
7580: padding: 0 5px 0 5px;
1.838 bisitz 7581: }
7582:
1.813 bisitz 7583: #LC_nav_bar {
1.911 bisitz 7584: float: left;
1.995 raeburn 7585: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7586: margin: 0 0 2px 0;
1.807 droeschl 7587: }
7588:
1.916 droeschl 7589: #LC_realm {
7590: margin: 0.2em 0 0 0;
7591: padding: 0;
7592: font-weight: bold;
7593: text-align: center;
1.995 raeburn 7594: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7595: }
7596:
1.911 bisitz 7597: #LC_nav_bar em {
7598: font-weight: bold;
7599: font-style: normal;
1.807 droeschl 7600: }
7601:
1.897 wenzelju 7602: ol.LC_primary_menu {
1.934 droeschl 7603: margin: 0;
1.1075.2.2 raeburn 7604: padding: 0;
1.807 droeschl 7605: }
7606:
1.852 droeschl 7607: ol#LC_PathBreadcrumbs {
1.911 bisitz 7608: margin: 0;
1.693 droeschl 7609: }
7610:
1.897 wenzelju 7611: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7612: color: RGB(80, 80, 80);
7613: vertical-align: middle;
7614: text-align: left;
7615: list-style: none;
1.1075.2.112 raeburn 7616: position: relative;
1.1075.2.2 raeburn 7617: float: left;
1.1075.2.112 raeburn 7618: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7619: line-height: 1.5em;
1.1075.2.2 raeburn 7620: }
7621:
1.1075.2.113 raeburn 7622: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7623: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7624: display: block;
7625: margin: 0;
7626: padding: 0 5px 0 10px;
7627: text-decoration: none;
7628: }
7629:
1.1075.2.112 raeburn 7630: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7631: display: inline-block;
7632: width: 95%;
7633: text-align: left;
7634: }
7635:
7636: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7637: display: inline-block;
7638: width: 5%;
7639: float: right;
7640: text-align: right;
7641: font-size: 70%;
7642: }
7643:
7644: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7645: display: none;
1.1075.2.112 raeburn 7646: width: 15em;
1.1075.2.2 raeburn 7647: background-color: $data_table_light;
1.1075.2.112 raeburn 7648: position: absolute;
7649: top: 100%;
7650: }
7651:
7652: ol.LC_primary_menu ul ul {
7653: left: 100%;
7654: top: 0;
1.1075.2.2 raeburn 7655: }
7656:
1.1075.2.112 raeburn 7657: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7658: display: block;
7659: position: absolute;
7660: margin: 0;
7661: padding: 0;
1.1075.2.5 raeburn 7662: z-index: 2;
1.1075.2.2 raeburn 7663: }
7664:
7665: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7666: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7667: font-size: 90%;
1.911 bisitz 7668: vertical-align: top;
1.1075.2.2 raeburn 7669: float: none;
1.1075.2.5 raeburn 7670: border-left: 1px solid black;
7671: border-right: 1px solid black;
1.1075.2.112 raeburn 7672: /* A dark bottom border to visualize different menu options;
7673: overwritten in the create_submenu routine for the last border-bottom of the menu */
7674: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7675: }
7676:
1.1075.2.112 raeburn 7677: ol.LC_primary_menu li li p:hover {
7678: color:$button_hover;
7679: text-decoration:none;
7680: background-color:$data_table_dark;
1.1075.2.2 raeburn 7681: }
7682:
7683: ol.LC_primary_menu li li a:hover {
7684: color:$button_hover;
7685: background-color:$data_table_dark;
1.693 droeschl 7686: }
7687:
1.1075.2.112 raeburn 7688: /* Font-size equal to the size of the predecessors*/
7689: ol.LC_primary_menu li:hover li li {
7690: font-size: 100%;
7691: }
7692:
1.897 wenzelju 7693: ol.LC_primary_menu li img {
1.911 bisitz 7694: vertical-align: bottom;
1.934 droeschl 7695: height: 1.1em;
1.1075.2.3 raeburn 7696: margin: 0.2em 0 0 0;
1.693 droeschl 7697: }
7698:
1.897 wenzelju 7699: ol.LC_primary_menu a {
1.911 bisitz 7700: color: RGB(80, 80, 80);
7701: text-decoration: none;
1.693 droeschl 7702: }
1.795 www 7703:
1.949 droeschl 7704: ol.LC_primary_menu a.LC_new_message {
7705: font-weight:bold;
7706: color: darkred;
7707: }
7708:
1.975 raeburn 7709: ol.LC_docs_parameters {
7710: margin-left: 0;
7711: padding: 0;
7712: list-style: none;
7713: }
7714:
7715: ol.LC_docs_parameters li {
7716: margin: 0;
7717: padding-right: 20px;
7718: display: inline;
7719: }
7720:
1.976 raeburn 7721: ol.LC_docs_parameters li:before {
7722: content: "\\002022 \\0020";
7723: }
7724:
7725: li.LC_docs_parameters_title {
7726: font-weight: bold;
7727: }
7728:
7729: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7730: content: "";
7731: }
7732:
1.897 wenzelju 7733: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7734: clear: right;
1.911 bisitz 7735: color: $fontmenu;
7736: background: $tabbg;
7737: list-style: none;
7738: padding: 0;
7739: margin: 0;
7740: width: 100%;
1.995 raeburn 7741: text-align: left;
1.1075.2.4 raeburn 7742: float: left;
1.808 droeschl 7743: }
7744:
1.897 wenzelju 7745: ul#LC_secondary_menu li {
1.911 bisitz 7746: font-weight: bold;
7747: line-height: 1.8em;
7748: border-right: 1px solid black;
1.1075.2.4 raeburn 7749: float: left;
7750: }
7751:
7752: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7753: background-color: $data_table_light;
7754: }
7755:
7756: ul#LC_secondary_menu li a {
7757: padding: 0 0.8em;
7758: }
7759:
7760: ul#LC_secondary_menu li ul {
7761: display: none;
7762: }
7763:
7764: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7765: display: block;
7766: position: absolute;
7767: margin: 0;
7768: padding: 0;
7769: list-style:none;
7770: float: none;
7771: background-color: $data_table_light;
1.1075.2.5 raeburn 7772: z-index: 2;
1.1075.2.10 raeburn 7773: margin-left: -1px;
1.1075.2.4 raeburn 7774: }
7775:
7776: ul#LC_secondary_menu li ul li {
7777: font-size: 90%;
7778: vertical-align: top;
7779: border-left: 1px solid black;
7780: border-right: 1px solid black;
1.1075.2.33 raeburn 7781: background-color: $data_table_light;
1.1075.2.4 raeburn 7782: list-style:none;
7783: float: none;
7784: }
7785:
7786: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7787: background-color: $data_table_dark;
1.807 droeschl 7788: }
7789:
1.847 tempelho 7790: ul.LC_TabContent {
1.911 bisitz 7791: display:block;
7792: background: $sidebg;
7793: border-bottom: solid 1px $lg_border_color;
7794: list-style:none;
1.1020 raeburn 7795: margin: -1px -10px 0 -10px;
1.911 bisitz 7796: padding: 0;
1.693 droeschl 7797: }
7798:
1.795 www 7799: ul.LC_TabContent li,
7800: ul.LC_TabContentBigger li {
1.911 bisitz 7801: float:left;
1.741 harmsja 7802: }
1.795 www 7803:
1.897 wenzelju 7804: ul#LC_secondary_menu li a {
1.911 bisitz 7805: color: $fontmenu;
7806: text-decoration: none;
1.693 droeschl 7807: }
1.795 www 7808:
1.721 harmsja 7809: ul.LC_TabContent {
1.952 onken 7810: min-height:20px;
1.721 harmsja 7811: }
1.795 www 7812:
7813: ul.LC_TabContent li {
1.911 bisitz 7814: vertical-align:middle;
1.959 onken 7815: padding: 0 16px 0 10px;
1.911 bisitz 7816: background-color:$tabbg;
7817: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7818: border-left: solid 1px $font;
1.721 harmsja 7819: }
1.795 www 7820:
1.847 tempelho 7821: ul.LC_TabContent .right {
1.911 bisitz 7822: float:right;
1.847 tempelho 7823: }
7824:
1.911 bisitz 7825: ul.LC_TabContent li a,
7826: ul.LC_TabContent li {
7827: color:rgb(47,47,47);
7828: text-decoration:none;
7829: font-size:95%;
7830: font-weight:bold;
1.952 onken 7831: min-height:20px;
7832: }
7833:
1.959 onken 7834: ul.LC_TabContent li a:hover,
7835: ul.LC_TabContent li a:focus {
1.952 onken 7836: color: $button_hover;
1.959 onken 7837: background:none;
7838: outline:none;
1.952 onken 7839: }
7840:
7841: ul.LC_TabContent li:hover {
7842: color: $button_hover;
7843: cursor:pointer;
1.721 harmsja 7844: }
1.795 www 7845:
1.911 bisitz 7846: ul.LC_TabContent li.active {
1.952 onken 7847: color: $font;
1.911 bisitz 7848: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7849: border-bottom:solid 1px #FFFFFF;
7850: cursor: default;
1.744 ehlerst 7851: }
1.795 www 7852:
1.959 onken 7853: ul.LC_TabContent li.active a {
7854: color:$font;
7855: background:#FFFFFF;
7856: outline: none;
7857: }
1.1047 raeburn 7858:
7859: ul.LC_TabContent li.goback {
7860: float: left;
7861: border-left: none;
7862: }
7863:
1.870 tempelho 7864: #maincoursedoc {
1.911 bisitz 7865: clear:both;
1.870 tempelho 7866: }
7867:
7868: ul.LC_TabContentBigger {
1.911 bisitz 7869: display:block;
7870: list-style:none;
7871: padding: 0;
1.870 tempelho 7872: }
7873:
1.795 www 7874: ul.LC_TabContentBigger li {
1.911 bisitz 7875: vertical-align:bottom;
7876: height: 30px;
7877: font-size:110%;
7878: font-weight:bold;
7879: color: #737373;
1.841 tempelho 7880: }
7881:
1.957 onken 7882: ul.LC_TabContentBigger li.active {
7883: position: relative;
7884: top: 1px;
7885: }
7886:
1.870 tempelho 7887: ul.LC_TabContentBigger li a {
1.911 bisitz 7888: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7889: height: 30px;
7890: line-height: 30px;
7891: text-align: center;
7892: display: block;
7893: text-decoration: none;
1.958 onken 7894: outline: none;
1.741 harmsja 7895: }
1.795 www 7896:
1.870 tempelho 7897: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7898: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7899: color:$font;
1.744 ehlerst 7900: }
1.795 www 7901:
1.870 tempelho 7902: ul.LC_TabContentBigger li b {
1.911 bisitz 7903: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7904: display: block;
7905: float: left;
7906: padding: 0 30px;
1.957 onken 7907: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7908: }
7909:
1.956 onken 7910: ul.LC_TabContentBigger li:hover b {
7911: color:$button_hover;
7912: }
7913:
1.870 tempelho 7914: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7915: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7916: color:$font;
1.957 onken 7917: border: 0;
1.741 harmsja 7918: }
1.693 droeschl 7919:
1.870 tempelho 7920:
1.862 bisitz 7921: ul.LC_CourseBreadcrumbs {
7922: background: $sidebg;
1.1020 raeburn 7923: height: 2em;
1.862 bisitz 7924: padding-left: 10px;
1.1020 raeburn 7925: margin: 0;
1.862 bisitz 7926: list-style-position: inside;
7927: }
7928:
1.911 bisitz 7929: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7930: ol#LC_PathBreadcrumbs {
1.911 bisitz 7931: padding-left: 10px;
7932: margin: 0;
1.933 droeschl 7933: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7934: }
7935:
1.911 bisitz 7936: ol#LC_MenuBreadcrumbs li,
7937: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7938: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7939: display: inline;
1.933 droeschl 7940: white-space: normal;
1.693 droeschl 7941: }
7942:
1.823 bisitz 7943: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7944: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7945: text-decoration: none;
7946: font-size:90%;
1.693 droeschl 7947: }
1.795 www 7948:
1.969 droeschl 7949: ol#LC_MenuBreadcrumbs h1 {
7950: display: inline;
7951: font-size: 90%;
7952: line-height: 2.5em;
7953: margin: 0;
7954: padding: 0;
7955: }
7956:
1.795 www 7957: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7958: text-decoration:none;
7959: font-size:100%;
7960: font-weight:bold;
1.693 droeschl 7961: }
1.795 www 7962:
1.840 bisitz 7963: .LC_Box {
1.911 bisitz 7964: border: solid 1px $lg_border_color;
7965: padding: 0 10px 10px 10px;
1.746 neumanie 7966: }
1.795 www 7967:
1.1020 raeburn 7968: .LC_DocsBox {
7969: border: solid 1px $lg_border_color;
7970: padding: 0 0 10px 10px;
7971: }
7972:
1.795 www 7973: .LC_AboutMe_Image {
1.911 bisitz 7974: float:left;
7975: margin-right:10px;
1.747 neumanie 7976: }
1.795 www 7977:
7978: .LC_Clear_AboutMe_Image {
1.911 bisitz 7979: clear:left;
1.747 neumanie 7980: }
1.795 www 7981:
1.721 harmsja 7982: dl.LC_ListStyleClean dt {
1.911 bisitz 7983: padding-right: 5px;
7984: display: table-header-group;
1.693 droeschl 7985: }
7986:
1.721 harmsja 7987: dl.LC_ListStyleClean dd {
1.911 bisitz 7988: display: table-row;
1.693 droeschl 7989: }
7990:
1.721 harmsja 7991: .LC_ListStyleClean,
7992: .LC_ListStyleSimple,
7993: .LC_ListStyleNormal,
1.795 www 7994: .LC_ListStyleSpecial {
1.911 bisitz 7995: /* display:block; */
7996: list-style-position: inside;
7997: list-style-type: none;
7998: overflow: hidden;
7999: padding: 0;
1.693 droeschl 8000: }
8001:
1.721 harmsja 8002: .LC_ListStyleSimple li,
8003: .LC_ListStyleSimple dd,
8004: .LC_ListStyleNormal li,
8005: .LC_ListStyleNormal dd,
8006: .LC_ListStyleSpecial li,
1.795 www 8007: .LC_ListStyleSpecial dd {
1.911 bisitz 8008: margin: 0;
8009: padding: 5px 5px 5px 10px;
8010: clear: both;
1.693 droeschl 8011: }
8012:
1.721 harmsja 8013: .LC_ListStyleClean li,
8014: .LC_ListStyleClean dd {
1.911 bisitz 8015: padding-top: 0;
8016: padding-bottom: 0;
1.693 droeschl 8017: }
8018:
1.721 harmsja 8019: .LC_ListStyleSimple dd,
1.795 www 8020: .LC_ListStyleSimple li {
1.911 bisitz 8021: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8022: }
8023:
1.721 harmsja 8024: .LC_ListStyleSpecial li,
8025: .LC_ListStyleSpecial dd {
1.911 bisitz 8026: list-style-type: none;
8027: background-color: RGB(220, 220, 220);
8028: margin-bottom: 4px;
1.693 droeschl 8029: }
8030:
1.721 harmsja 8031: table.LC_SimpleTable {
1.911 bisitz 8032: margin:5px;
8033: border:solid 1px $lg_border_color;
1.795 www 8034: }
1.693 droeschl 8035:
1.721 harmsja 8036: table.LC_SimpleTable tr {
1.911 bisitz 8037: padding: 0;
8038: border:solid 1px $lg_border_color;
1.693 droeschl 8039: }
1.795 www 8040:
8041: table.LC_SimpleTable thead {
1.911 bisitz 8042: background:rgb(220,220,220);
1.693 droeschl 8043: }
8044:
1.721 harmsja 8045: div.LC_columnSection {
1.911 bisitz 8046: display: block;
8047: clear: both;
8048: overflow: hidden;
8049: margin: 0;
1.693 droeschl 8050: }
8051:
1.721 harmsja 8052: div.LC_columnSection>* {
1.911 bisitz 8053: float: left;
8054: margin: 10px 20px 10px 0;
8055: overflow:hidden;
1.693 droeschl 8056: }
1.721 harmsja 8057:
1.795 www 8058: table em {
1.911 bisitz 8059: font-weight: bold;
8060: font-style: normal;
1.748 schulted 8061: }
1.795 www 8062:
1.779 bisitz 8063: table.LC_tableBrowseRes,
1.795 www 8064: table.LC_tableOfContent {
1.911 bisitz 8065: border:none;
8066: border-spacing: 1px;
8067: padding: 3px;
8068: background-color: #FFFFFF;
8069: font-size: 90%;
1.753 droeschl 8070: }
1.789 droeschl 8071:
1.911 bisitz 8072: table.LC_tableOfContent {
8073: border-collapse: collapse;
1.789 droeschl 8074: }
8075:
1.771 droeschl 8076: table.LC_tableBrowseRes a,
1.768 schulted 8077: table.LC_tableOfContent a {
1.911 bisitz 8078: background-color: transparent;
8079: text-decoration: none;
1.753 droeschl 8080: }
8081:
1.795 www 8082: table.LC_tableOfContent img {
1.911 bisitz 8083: border: none;
8084: height: 1.3em;
8085: vertical-align: text-bottom;
8086: margin-right: 0.3em;
1.753 droeschl 8087: }
1.757 schulted 8088:
1.795 www 8089: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8090: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8091: }
8092:
1.795 www 8093: a#LC_content_toolbar_everything {
1.911 bisitz 8094: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8095: }
8096:
1.795 www 8097: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8098: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8099: }
8100:
1.795 www 8101: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8102: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8103: }
8104:
1.795 www 8105: a#LC_content_toolbar_changefolder {
1.911 bisitz 8106: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8107: }
8108:
1.795 www 8109: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8110: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8111: }
8112:
1.1043 raeburn 8113: a#LC_content_toolbar_edittoplevel {
8114: background-image:url(/res/adm/pages/edittoplevel.gif);
8115: }
8116:
1.795 www 8117: ul#LC_toolbar li a:hover {
1.911 bisitz 8118: background-position: bottom center;
1.757 schulted 8119: }
8120:
1.795 www 8121: ul#LC_toolbar {
1.911 bisitz 8122: padding: 0;
8123: margin: 2px;
8124: list-style:none;
8125: position:relative;
8126: background-color:white;
1.1075.2.9 raeburn 8127: overflow: auto;
1.757 schulted 8128: }
8129:
1.795 www 8130: ul#LC_toolbar li {
1.911 bisitz 8131: border:1px solid white;
8132: padding: 0;
8133: margin: 0;
8134: float: left;
8135: display:inline;
8136: vertical-align:middle;
1.1075.2.9 raeburn 8137: white-space: nowrap;
1.911 bisitz 8138: }
1.757 schulted 8139:
1.783 amueller 8140:
1.795 www 8141: a.LC_toolbarItem {
1.911 bisitz 8142: display:block;
8143: padding: 0;
8144: margin: 0;
8145: height: 32px;
8146: width: 32px;
8147: color:white;
8148: border: none;
8149: background-repeat:no-repeat;
8150: background-color:transparent;
1.757 schulted 8151: }
8152:
1.915 droeschl 8153: ul.LC_funclist {
8154: margin: 0;
8155: padding: 0.5em 1em 0.5em 0;
8156: }
8157:
1.933 droeschl 8158: ul.LC_funclist > li:first-child {
8159: font-weight:bold;
8160: margin-left:0.8em;
8161: }
8162:
1.915 droeschl 8163: ul.LC_funclist + ul.LC_funclist {
8164: /*
8165: left border as a seperator if we have more than
8166: one list
8167: */
8168: border-left: 1px solid $sidebg;
8169: /*
8170: this hides the left border behind the border of the
8171: outer box if element is wrapped to the next 'line'
8172: */
8173: margin-left: -1px;
8174: }
8175:
1.843 bisitz 8176: ul.LC_funclist li {
1.915 droeschl 8177: display: inline;
1.782 bisitz 8178: white-space: nowrap;
1.915 droeschl 8179: margin: 0 0 0 25px;
8180: line-height: 150%;
1.782 bisitz 8181: }
8182:
1.974 wenzelju 8183: .LC_hidden {
8184: display: none;
8185: }
8186:
1.1030 www 8187: .LCmodal-overlay {
8188: position:fixed;
8189: top:0;
8190: right:0;
8191: bottom:0;
8192: left:0;
8193: height:100%;
8194: width:100%;
8195: margin:0;
8196: padding:0;
8197: background:#999;
8198: opacity:.75;
8199: filter: alpha(opacity=75);
8200: -moz-opacity: 0.75;
8201: z-index:101;
8202: }
8203:
8204: * html .LCmodal-overlay {
8205: position: absolute;
8206: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8207: }
8208:
8209: .LCmodal-window {
8210: position:fixed;
8211: top:50%;
8212: left:50%;
8213: margin:0;
8214: padding:0;
8215: z-index:102;
8216: }
8217:
8218: * html .LCmodal-window {
8219: position:absolute;
8220: }
8221:
8222: .LCclose-window {
8223: position:absolute;
8224: width:32px;
8225: height:32px;
8226: right:8px;
8227: top:8px;
8228: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8229: text-indent:-99999px;
8230: overflow:hidden;
8231: cursor:pointer;
8232: }
8233:
1.1075.2.158 raeburn 8234: .LCisDisabled {
8235: cursor: not-allowed;
8236: opacity: 0.5;
8237: }
8238:
8239: a[aria-disabled="true"] {
8240: color: currentColor;
8241: display: inline-block; /* For IE11/ MS Edge bug */
8242: pointer-events: none;
8243: text-decoration: none;
8244: }
8245:
1.1075.2.141 raeburn 8246: pre.LC_wordwrap {
8247: white-space: pre-wrap;
8248: white-space: -moz-pre-wrap;
8249: white-space: -pre-wrap;
8250: white-space: -o-pre-wrap;
8251: word-wrap: break-word;
8252: }
8253:
1.1075.2.17 raeburn 8254: /*
8255: styles used by TTH when "Default set of options to pass to tth/m
8256: when converting TeX" in course settings has been set
8257:
8258: option passed: -t
8259:
8260: */
8261:
8262: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8263: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8264: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8265: td div.norm {line-height:normal;}
8266:
8267: /*
8268: option passed -y3
8269: */
8270:
8271: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8272: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8273: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8274:
1.1075.2.121 raeburn 8275: #LC_minitab_header {
8276: float:left;
8277: width:100%;
8278: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8279: font-size:93%;
8280: line-height:normal;
8281: margin: 0.5em 0 0.5em 0;
8282: }
8283: #LC_minitab_header ul {
8284: margin:0;
8285: padding:10px 10px 0;
8286: list-style:none;
8287: }
8288: #LC_minitab_header li {
8289: float:left;
8290: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8291: margin:0;
8292: padding:0 0 0 9px;
8293: }
8294: #LC_minitab_header a {
8295: display:block;
8296: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8297: padding:5px 15px 4px 6px;
8298: }
8299: #LC_minitab_header #LC_current_minitab {
8300: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8301: }
8302: #LC_minitab_header #LC_current_minitab a {
8303: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8304: padding-bottom:5px;
8305: }
8306:
8307:
1.343 albertel 8308: END
8309: }
8310:
1.306 albertel 8311: =pod
8312:
8313: =item * &headtag()
8314:
8315: Returns a uniform footer for LON-CAPA web pages.
8316:
1.307 albertel 8317: Inputs: $title - optional title for the head
8318: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8319: $args - optional arguments
1.319 albertel 8320: force_register - if is true call registerurl so the remote is
8321: informed
1.415 albertel 8322: redirect -> array ref of
8323: 1- seconds before redirect occurs
8324: 2- url to redirect to
8325: 3- whether the side effect should occur
1.315 albertel 8326: (side effect of setting
8327: $env{'internal.head.redirect'} to the url
8328: redirected too)
1.352 albertel 8329: domain -> force to color decorate a page for a specific
8330: domain
8331: function -> force usage of a specific rolish color scheme
8332: bgcolor -> override the default page bgcolor
1.460 albertel 8333: no_auto_mt_title
8334: -> prevent &mt()ing the title arg
1.464 albertel 8335:
1.306 albertel 8336: =cut
8337:
8338: sub headtag {
1.313 albertel 8339: my ($title,$head_extra,$args) = @_;
1.306 albertel 8340:
1.363 albertel 8341: my $function = $args->{'function'} || &get_users_function();
8342: my $domain = $args->{'domain'} || &determinedomain();
8343: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8344: my $httphost = $args->{'use_absolute'};
1.418 albertel 8345: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8346: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8347: #time(),
1.418 albertel 8348: $env{'environment.color.timestamp'},
1.363 albertel 8349: $function,$domain,$bgcolor);
8350:
1.369 www 8351: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8352:
1.308 albertel 8353: my $result =
8354: '<head>'.
1.1075.2.56 raeburn 8355: &font_settings($args);
1.319 albertel 8356:
1.1075.2.72 raeburn 8357: my $inhibitprint;
8358: if ($args->{'print_suppress'}) {
8359: $inhibitprint = &print_suppression();
8360: }
1.1064 raeburn 8361:
1.461 albertel 8362: if (!$args->{'frameset'}) {
8363: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8364: }
1.1075.2.12 raeburn 8365: if ($args->{'force_register'}) {
8366: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8367: }
1.436 albertel 8368: if (!$args->{'no_nav_bar'}
8369: && !$args->{'only_body'}
8370: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8371: $result .= &help_menu_js($httphost);
1.1032 www 8372: $result.=&modal_window();
1.1038 www 8373: $result.=&togglebox_script();
1.1034 www 8374: $result.=&wishlist_window();
1.1041 www 8375: $result.=&LCprogressbarUpdate_script();
1.1034 www 8376: } else {
8377: if ($args->{'add_modal'}) {
8378: $result.=&modal_window();
8379: }
8380: if ($args->{'add_wishlist'}) {
8381: $result.=&wishlist_window();
8382: }
1.1038 www 8383: if ($args->{'add_togglebox'}) {
8384: $result.=&togglebox_script();
8385: }
1.1041 www 8386: if ($args->{'add_progressbar'}) {
8387: $result.=&LCprogressbarUpdate_script();
8388: }
1.436 albertel 8389: }
1.314 albertel 8390: if (ref($args->{'redirect'})) {
1.414 albertel 8391: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8392: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8393: if (!$inhibit_continue) {
8394: $env{'internal.head.redirect'} = $url;
8395: }
1.313 albertel 8396: $result.=<<ADDMETA
8397: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8398: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8399: ADDMETA
1.1075.2.89 raeburn 8400: } else {
8401: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8402: my $requrl = $env{'request.uri'};
8403: if ($requrl eq '') {
8404: $requrl = $ENV{'REQUEST_URI'};
8405: $requrl =~ s/\?.+$//;
8406: }
8407: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8408: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8409: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8410: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8411: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8412: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8413: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8414: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8415: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8416: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8417: $offload = 1;
1.1075.2.151 raeburn 8418: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8419: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8420: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8421: $offloadoth = 1;
8422: $dom_in_use = $env{'user.domain'};
8423: }
8424: }
1.1075.2.145 raeburn 8425: }
8426: }
8427: unless ($offload) {
8428: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8429: if ($domdefs{'offloadoth'}{$lonhost}) {
8430: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8431: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8432: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8433: $offload = 1;
1.1075.2.151 raeburn 8434: $offloadoth = 1;
1.1075.2.145 raeburn 8435: $dom_in_use = $env{'user.domain'};
8436: }
1.1075.2.89 raeburn 8437: }
1.1075.2.145 raeburn 8438: }
8439: }
8440: }
8441: if ($offload) {
1.1075.2.158 raeburn 8442: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8443: if (($newserver eq '') && ($offloadoth)) {
8444: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 8445:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 8446: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8447: }
8448: }
1.1075.2.145 raeburn 8449: if (($newserver) && ($newserver ne $lonhost)) {
8450: my $numsec = 5;
8451: my $timeout = $numsec * 1000;
8452: my ($newurl,$locknum,%locks,$msg);
8453: if ($env{'request.role.adv'}) {
8454: ($locknum,%locks) = &Apache::lonnet::get_locks();
8455: }
8456: my $disable_submit = 0;
8457: if ($requrl =~ /$LONCAPA::assess_re/) {
8458: $disable_submit = 1;
8459: }
8460: if ($locknum) {
8461: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8462: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8463: join(", ",sort(values(%locks)))."\n";
8464: if (&show_course()) {
8465: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8466: } else {
1.1075.2.145 raeburn 8467: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8468: }
8469: } else {
8470: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8471: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8472: }
8473: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8474: $newurl = '/adm/switchserver?otherserver='.$newserver;
8475: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8476: $newurl .= '&role='.$env{'request.role'};
8477: }
8478: if ($env{'request.symb'}) {
8479: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8480: if ($shownsymb =~ m{^/enc/}) {
8481: my $reqdmajor = 2;
8482: my $reqdminor = 11;
8483: my $reqdsubminor = 3;
8484: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8485: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8486: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8487: if (($major eq '' && $minor eq '') ||
8488: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8489: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8490: ($reqdsubminor > $subminor))))) {
8491: undef($shownsymb);
8492: }
1.1075.2.89 raeburn 8493: }
1.1075.2.145 raeburn 8494: if ($shownsymb) {
8495: &js_escape(\$shownsymb);
8496: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8497: }
1.1075.2.145 raeburn 8498: } else {
8499: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8500: &js_escape(\$shownurl);
8501: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8502: }
1.1075.2.145 raeburn 8503: }
8504: &js_escape(\$msg);
8505: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8506: <meta http-equiv="pragma" content="no-cache" />
8507: <script type="text/javascript">
1.1075.2.92 raeburn 8508: // <![CDATA[
1.1075.2.89 raeburn 8509: function LC_Offload_Now() {
8510: var dest = "$newurl";
8511: if (dest != '') {
8512: window.location.href="$newurl";
8513: }
8514: }
1.1075.2.92 raeburn 8515: \$(document).ready(function () {
8516: window.alert('$msg');
8517: if ($disable_submit) {
1.1075.2.89 raeburn 8518: \$(".LC_hwk_submit").prop("disabled", true);
8519: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8520: }
8521: setTimeout('LC_Offload_Now()', $timeout);
8522: });
8523: // ]]>
1.1075.2.89 raeburn 8524: </script>
8525: OFFLOAD
8526: }
8527: }
8528: }
8529: }
8530: }
1.313 albertel 8531: }
1.306 albertel 8532: if (!defined($title)) {
8533: $title = 'The LearningOnline Network with CAPA';
8534: }
1.460 albertel 8535: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8536: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8537: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8538: if (!$args->{'frameset'}) {
8539: $result .= ' /';
8540: }
8541: $result .= '>'
1.1064 raeburn 8542: .$inhibitprint
1.414 albertel 8543: .$head_extra;
1.1075.2.108 raeburn 8544: my $clientmobile;
8545: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8546: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8547: } else {
8548: $clientmobile = $env{'browser.mobile'};
8549: }
8550: if ($clientmobile) {
1.1075.2.42 raeburn 8551: $result .= '
8552: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8553: <meta name="apple-mobile-web-app-capable" content="yes" />';
8554: }
1.1075.2.126 raeburn 8555: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8556: return $result.'</head>';
1.306 albertel 8557: }
8558:
8559: =pod
8560:
1.340 albertel 8561: =item * &font_settings()
8562:
8563: Returns neccessary <meta> to set the proper encoding
8564:
1.1075.2.56 raeburn 8565: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8566:
8567: =cut
8568:
8569: sub font_settings {
1.1075.2.56 raeburn 8570: my ($args) = @_;
1.340 albertel 8571: my $headerstring='';
1.1075.2.56 raeburn 8572: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8573: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8574: $headerstring.=
1.1075.2.61 raeburn 8575: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8576: if (!$args->{'frameset'}) {
8577: $headerstring.= ' /';
8578: }
8579: $headerstring .= '>'."\n";
1.340 albertel 8580: }
8581: return $headerstring;
8582: }
8583:
1.341 albertel 8584: =pod
8585:
1.1064 raeburn 8586: =item * &print_suppression()
8587:
8588: In course context returns css which causes the body to be blank when media="print",
8589: if printout generation is unavailable for the current resource.
8590:
8591: This could be because:
8592:
8593: (a) printstartdate is in the future
8594:
8595: (b) printenddate is in the past
8596:
8597: (c) there is an active exam block with "printout"
8598: functionality blocked
8599:
8600: Users with pav, pfo or evb privileges are exempt.
8601:
8602: Inputs: none
8603:
8604: =cut
8605:
8606:
8607: sub print_suppression {
8608: my $noprint;
8609: if ($env{'request.course.id'}) {
8610: my $scope = $env{'request.course.id'};
8611: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8612: (&Apache::lonnet::allowed('pfo',$scope))) {
8613: return;
8614: }
8615: if ($env{'request.course.sec'} ne '') {
8616: $scope .= "/$env{'request.course.sec'}";
8617: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8618: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8619: return;
1.1064 raeburn 8620: }
8621: }
8622: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8623: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8624: my $clientip = &Apache::lonnet::get_requestor_ip();
8625: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8626: if ($blocked) {
8627: my $checkrole = "cm./$cdom/$cnum";
8628: if ($env{'request.course.sec'} ne '') {
8629: $checkrole .= "/$env{'request.course.sec'}";
8630: }
8631: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8632: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8633: $noprint = 1;
8634: }
8635: }
8636: unless ($noprint) {
8637: my $symb = &Apache::lonnet::symbread();
8638: if ($symb ne '') {
8639: my $navmap = Apache::lonnavmaps::navmap->new();
8640: if (ref($navmap)) {
8641: my $res = $navmap->getBySymb($symb);
8642: if (ref($res)) {
8643: if (!$res->resprintable()) {
8644: $noprint = 1;
8645: }
8646: }
8647: }
8648: }
8649: }
8650: if ($noprint) {
8651: return <<"ENDSTYLE";
8652: <style type="text/css" media="print">
8653: body { display:none }
8654: </style>
8655: ENDSTYLE
8656: }
8657: }
8658: return;
8659: }
8660:
8661: =pod
8662:
1.341 albertel 8663: =item * &xml_begin()
8664:
8665: Returns the needed doctype and <html>
8666:
8667: Inputs: none
8668:
8669: =cut
8670:
8671: sub xml_begin {
1.1075.2.61 raeburn 8672: my ($is_frameset) = @_;
1.341 albertel 8673: my $output='';
8674:
8675: if ($env{'browser.mathml'}) {
8676: $output='<?xml version="1.0"?>'
8677: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8678: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8679:
8680: # .'<!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">] >'
8681: .'<!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">'
8682: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8683: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8684: } elsif ($is_frameset) {
8685: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8686: '<html>'."\n";
1.341 albertel 8687: } else {
1.1075.2.61 raeburn 8688: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8689: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8690: }
8691: return $output;
8692: }
1.340 albertel 8693:
8694: =pod
8695:
1.306 albertel 8696: =item * &start_page()
8697:
8698: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8699:
1.648 raeburn 8700: Inputs:
8701:
8702: =over 4
8703:
8704: $title - optional title for the page
8705:
8706: $head_extra - optional extra HTML to incude inside the <head>
8707:
8708: $args - additional optional args supported are:
8709:
8710: =over 8
8711:
8712: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8713: arg on
1.814 bisitz 8714: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8715: add_entries -> additional attributes to add to the <body>
8716: domain -> force to color decorate a page for a
1.317 albertel 8717: specific domain
1.648 raeburn 8718: function -> force usage of a specific rolish color
1.317 albertel 8719: scheme
1.648 raeburn 8720: redirect -> see &headtag()
8721: bgcolor -> override the default page bg color
8722: js_ready -> return a string ready for being used in
1.317 albertel 8723: a javascript writeln
1.648 raeburn 8724: html_encode -> return a string ready for being used in
1.320 albertel 8725: a html attribute
1.648 raeburn 8726: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8727: $forcereg arg
1.648 raeburn 8728: frameset -> if true will start with a <frameset>
1.330 albertel 8729: rather than <body>
1.648 raeburn 8730: skip_phases -> hash ref of
1.338 albertel 8731: head -> skip the <html><head> generation
8732: body -> skip all <body> generation
1.1075.2.12 raeburn 8733: no_inline_link -> if true and in remote mode, don't show the
8734: 'Switch To Inline Menu' link
1.648 raeburn 8735: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8736: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8737: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8738: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8739: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8740: group -> includes the current group, if page is for a
8741: specific group
1.1075.2.133 raeburn 8742: use_absolute -> for request for external resource or syllabus, this
8743: will contain https://<hostname> if server uses
8744: https (as per hosts.tab), but request is for http
8745: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8746: links_disabled -> Links in primary and secondary menus are disabled
8747: (Can enable them once page has loaded - see lonroles.pm
8748: for an example).
1.1075.2.161. .6(raebu 8749:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 8750:
1.648 raeburn 8751: =back
1.460 albertel 8752:
1.648 raeburn 8753: =back
1.562 albertel 8754:
1.306 albertel 8755: =cut
8756:
8757: sub start_page {
1.309 albertel 8758: my ($title,$head_extra,$args) = @_;
1.318 albertel 8759: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8760:
1.315 albertel 8761: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 8762:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 8763:
1.338 albertel 8764: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8765: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8766: }
1.1075.2.161. .1(raebu 8767:21):
8768:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
8769:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8770:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8771:21): $args->{'no_primary_menu'} = 1;
8772:21): }
8773:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8774:21): $args->{'no_inline_menu'} = 1;
8775:21): }
8776:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8777:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8778:21): }
8779:21): } else {
8780:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8781:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8782:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8783:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8784:21): $args->{'no_primary_menu'} = 1;
8785:21): }
8786:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8787:21): $args->{'no_inline_menu'} = 1;
8788:21): }
8789:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8790:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8791:21): }
8792:21): }
8793:21): }
8794:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8795:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
8796:21): $env{'course.'.$env{'request.course.id'}.'.num'});
8797:21): } elsif ($env{'request.course.id'}) {
8798:21): my $expiretime=600;
8799:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
8800:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
8801:21): }
8802:21): my ($deeplinkmenu,$menuref);
8803:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
8804:21): if ($menucoll) {
8805:21): if (ref($menuref) eq 'HASH') {
8806:21): %menu = %{$menuref};
8807:21): }
8808:21): if ($menu{'top'} eq 'n') {
8809:21): $args->{'no_primary_menu'} = 1;
8810:21): }
8811:21): if ($menu{'inline'} eq 'n') {
8812:21): unless (&Apache::lonnet::allowed('opa')) {
8813:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8814:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8815:21): my $crstype = &course_type();
8816:21): my $now = time;
8817:21): my $ccrole;
8818:21): if ($crstype eq 'Community') {
8819:21): $ccrole = 'co';
8820:21): } else {
8821:21): $ccrole = 'cc';
8822:21): }
8823:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
8824:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
8825:21): if ((($start) && ($start<0)) ||
8826:21): (($end) && ($end<$now)) ||
8827:21): (($start) && ($now<$start))) {
8828:21): $args->{'no_inline_menu'} = 1;
8829:21): }
8830:21): } else {
8831:21): $args->{'no_inline_menu'} = 1;
8832:21): }
8833:21): }
8834:21): }
8835:21): }
8836:21): }
.4(raebu 8837:22):
.8(raebu 8838:22): my $showncrumbs;
1.338 albertel 8839: if (! exists($args->{'skip_phases'}{'body'}) ) {
8840: if ($args->{'frameset'}) {
8841: my $attr_string = &make_attr_string($args->{'force_register'},
8842: $args->{'add_entries'});
8843: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8844: } else {
8845: $result .=
8846: &bodytag($title,
8847: $args->{'function'}, $args->{'add_entries'},
8848: $args->{'only_body'}, $args->{'domain'},
8849: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8850: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 8851:21): $args, \@advtools,
.8(raebu 8852:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 8853: }
1.330 albertel 8854: }
1.338 albertel 8855:
1.315 albertel 8856: if ($args->{'js_ready'}) {
1.713 kaisler 8857: $result = &js_ready($result);
1.315 albertel 8858: }
1.320 albertel 8859: if ($args->{'html_encode'}) {
1.713 kaisler 8860: $result = &html_encode($result);
8861: }
8862:
1.813 bisitz 8863: # Preparation for new and consistent functionlist at top of screen
8864: # if ($args->{'functionlist'}) {
8865: # $result .= &build_functionlist();
8866: #}
8867:
1.964 droeschl 8868: # Don't add anything more if only_body wanted or in const space
8869: return $result if $args->{'only_body'}
8870: || $env{'request.state'} eq 'construct';
1.813 bisitz 8871:
8872: #Breadcrumbs
1.758 kaisler 8873: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 8874:22): unless ($showncrumbs) {
1.758 kaisler 8875: &Apache::lonhtmlcommon::clear_breadcrumbs();
8876: #if any br links exists, add them to the breadcrumbs
8877: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8878: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8879: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8880: }
8881: }
1.1075.2.19 raeburn 8882: # if @advtools array contains items add then to the breadcrumbs
8883: if (@advtools > 0) {
8884: &Apache::lonmenu::advtools_crumbs(@advtools);
8885: }
1.1075.2.123 raeburn 8886: my $menulink;
8887: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 8888:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
8889:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 8890: $menulink = 0;
8891: } else {
8892: undef($menulink);
8893: }
1.1075.2.161. .8(raebu 8894:22): my $linkprotout;
8895:22): if ($env{'request.deeplink.login'}) {
8896:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
8897:22): if ($linkprotout) {
8898:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
8899:22): }
8900:22): }
1.758 kaisler 8901: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8902: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8903: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1075.2.161. .1(raebu 8904:21): } else {
1.1075.2.123 raeburn 8905: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8906: }
1.1075.2.161. .8(raebu 8907:22): }
1.1075.2.24 raeburn 8908: } elsif (($env{'environment.remote'} eq 'on') &&
8909: ($env{'form.inhibitmenu'} ne 'yes') &&
8910: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8911: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8912: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8913: }
1.315 albertel 8914: return $result;
1.306 albertel 8915: }
8916:
8917: sub end_page {
1.315 albertel 8918: my ($args) = @_;
8919: $env{'internal.end_page'}++;
1.330 albertel 8920: my $result;
1.335 albertel 8921: if ($args->{'discussion'}) {
8922: my ($target,$parser);
8923: if (ref($args->{'discussion'})) {
8924: ($target,$parser) =($args->{'discussion'}{'target'},
8925: $args->{'discussion'}{'parser'});
8926: }
8927: $result .= &Apache::lonxml::xmlend($target,$parser);
8928: }
1.330 albertel 8929: if ($args->{'frameset'}) {
8930: $result .= '</frameset>';
8931: } else {
1.635 raeburn 8932: $result .= &endbodytag($args);
1.330 albertel 8933: }
1.1075.2.6 raeburn 8934: unless ($args->{'notbody'}) {
8935: $result .= "\n</html>";
8936: }
1.330 albertel 8937:
1.315 albertel 8938: if ($args->{'js_ready'}) {
1.317 albertel 8939: $result = &js_ready($result);
1.315 albertel 8940: }
1.335 albertel 8941:
1.320 albertel 8942: if ($args->{'html_encode'}) {
8943: $result = &html_encode($result);
8944: }
1.335 albertel 8945:
1.315 albertel 8946: return $result;
8947: }
8948:
1.1075.2.161. .1(raebu 8949:21): sub menucoll_in_effect {
8950:21): my ($menucoll,$deeplinkmenu,%menu);
8951:21): if ($env{'request.course.id'}) {
8952:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
8953:21): if ($env{'request.deeplink.login'}) {
8954:21): my ($deeplink_symb,$deeplink,$check_login_symb);
8955:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8956:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8957:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
8958:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
8959:21): my $navmap = Apache::lonnavmaps::navmap->new();
8960:21): if (ref($navmap)) {
8961:21): $deeplink = $navmap->get_mapparam(undef,
8962:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
8963:21): '0.deeplink');
8964:21): } else {
8965:21): $check_login_symb = 1;
8966:21): }
8967:21): } else {
8968:21): my $symb=&Apache::lonnet::symbread();
8969:21): if ($symb) {
8970:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
8971:21): } else {
8972:21): $check_login_symb = 1;
8973:21): }
8974:21): }
8975:21): } else {
8976:21): $check_login_symb = 1;
8977:21): }
8978:21): if ($check_login_symb) {
8979:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
8980:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
8981:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
8982:21): my $navmap = Apache::lonnavmaps::navmap->new();
8983:21): if (ref($navmap)) {
8984:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
8985:21): }
8986:21): } else {
8987:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
8988:21): }
8989:21): }
8990:21): if ($deeplink ne '') {
.6(raebu 8991:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 8992:21): if ($display =~ /^\d+$/) {
8993:21): $deeplinkmenu = 1;
8994:21): $menucoll = $display;
8995:21): }
8996:21): }
8997:21): }
8998:21): if ($menucoll) {
8999:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9000:21): }
9001:21): }
9002:21): return ($menucoll,$deeplinkmenu,\%menu);
9003:21): }
9004:21):
9005:21): sub deeplink_login_symb {
9006:21): my ($cnum,$cdom) = @_;
9007:21): my $login_symb;
9008:21): if ($env{'request.deeplink.login'}) {
9009:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9010:21): }
9011:21): return $login_symb;
9012:21): }
9013:21):
9014:21): sub symb_from_tinyurl {
9015:21): my ($url,$cnum,$cdom) = @_;
9016:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9017:21): my $key = $1;
9018:21): my ($tinyurl,$login);
9019:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9020:21): if (defined($cached)) {
9021:21): $tinyurl = $result;
9022:21): } else {
9023:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9024:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9025:21): if ($currtiny{$key} ne '') {
9026:21): $tinyurl = $currtiny{$key};
9027:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9028:21): }
9029:21): }
9030:21): if ($tinyurl ne '') {
9031:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9032:21): if (wantarray) {
9033:21): return ($cnumreq,$symb);
9034:21): } elsif ($cnumreq eq $cnum) {
9035:21): return $symb;
9036:21): }
9037:21): }
9038:21): }
9039:21): if (wantarray) {
9040:21): return ();
9041:21): } else {
9042:21): return;
9043:21): }
9044:21): }
9045:21):
1.1034 www 9046: sub wishlist_window {
9047: return(<<'ENDWISHLIST');
1.1046 raeburn 9048: <script type="text/javascript">
1.1034 www 9049: // <![CDATA[
9050: // <!-- BEGIN LON-CAPA Internal
9051: function set_wishlistlink(title, path) {
9052: if (!title) {
9053: title = document.title;
9054: title = title.replace(/^LON-CAPA /,'');
9055: }
1.1075.2.65 raeburn 9056: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9057: title = title.replace("'","\\\'");
1.1034 www 9058: if (!path) {
9059: path = location.pathname;
9060: }
1.1075.2.65 raeburn 9061: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9062: path = path.replace("'","\\\'");
1.1034 www 9063: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9064: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9065: }
9066: // END LON-CAPA Internal -->
9067: // ]]>
9068: </script>
9069: ENDWISHLIST
9070: }
9071:
1.1030 www 9072: sub modal_window {
9073: return(<<'ENDMODAL');
1.1046 raeburn 9074: <script type="text/javascript">
1.1030 www 9075: // <![CDATA[
9076: // <!-- BEGIN LON-CAPA Internal
9077: var modalWindow = {
9078: parent:"body",
9079: windowId:null,
9080: content:null,
9081: width:null,
9082: height:null,
9083: close:function()
9084: {
9085: $(".LCmodal-window").remove();
9086: $(".LCmodal-overlay").remove();
9087: },
9088: open:function()
9089: {
9090: var modal = "";
9091: modal += "<div class=\"LCmodal-overlay\"></div>";
9092: 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;\">";
9093: modal += this.content;
9094: modal += "</div>";
9095:
9096: $(this.parent).append(modal);
9097:
9098: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9099: $(".LCclose-window").click(function(){modalWindow.close();});
9100: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9101: }
9102: };
1.1075.2.42 raeburn 9103: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9104: {
1.1075.2.119 raeburn 9105: source = source.replace(/'/g,"'");
1.1030 www 9106: modalWindow.windowId = "myModal";
9107: modalWindow.width = width;
9108: modalWindow.height = height;
1.1075.2.80 raeburn 9109: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9110: modalWindow.open();
1.1075.2.87 raeburn 9111: };
1.1030 www 9112: // END LON-CAPA Internal -->
9113: // ]]>
9114: </script>
9115: ENDMODAL
9116: }
9117:
9118: sub modal_link {
1.1075.2.42 raeburn 9119: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9120: unless ($width) { $width=480; }
9121: unless ($height) { $height=400; }
1.1031 www 9122: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9123: unless ($transparency) { $transparency='true'; }
9124:
1.1074 raeburn 9125: my $target_attr;
9126: if (defined($target)) {
9127: $target_attr = 'target="'.$target.'"';
9128: }
9129: return <<"ENDLINK";
1.1075.2.143 raeburn 9130: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9131: ENDLINK
1.1030 www 9132: }
9133:
1.1032 www 9134: sub modal_adhoc_script {
1.1075.2.155 raeburn 9135: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9136: my $mathjax;
9137: if ($possmathjax) {
9138: $mathjax = <<'ENDJAX';
9139: if (typeof MathJax == 'object') {
9140: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9141: }
9142: ENDJAX
9143: }
1.1032 www 9144: return (<<ENDADHOC);
1.1046 raeburn 9145: <script type="text/javascript">
1.1032 www 9146: // <![CDATA[
9147: var $funcname = function()
9148: {
9149: modalWindow.windowId = "myModal";
9150: modalWindow.width = $width;
9151: modalWindow.height = $height;
9152: modalWindow.content = '$content';
9153: modalWindow.open();
1.1075.2.155 raeburn 9154: $mathjax
1.1032 www 9155: };
9156: // ]]>
9157: </script>
9158: ENDADHOC
9159: }
9160:
1.1041 www 9161: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9162: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9163: my $innerwidth=$width-20;
9164: $content=&js_ready(
1.1042 www 9165: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9166: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9167: $content.
1.1041 www 9168: &end_scrollbox().
1.1075.2.42 raeburn 9169: &end_page()
1.1041 www 9170: );
1.1075.2.155 raeburn 9171: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9172: }
9173:
9174: sub modal_adhoc_window {
1.1075.2.155 raeburn 9175: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9176: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9177: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9178: }
9179:
9180: sub modal_adhoc_launch {
9181: my ($funcname,$width,$height,$content)=@_;
9182: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9183: <script type="text/javascript">
9184: // <![CDATA[
9185: $funcname();
9186: // ]]>
9187: </script>
9188: ENDLAUNCH
9189: }
9190:
9191: sub modal_adhoc_close {
9192: return (<<ENDCLOSE);
9193: <script type="text/javascript">
9194: // <![CDATA[
9195: modalWindow.close();
9196: // ]]>
9197: </script>
9198: ENDCLOSE
9199: }
9200:
1.1038 www 9201: sub togglebox_script {
9202: return(<<ENDTOGGLE);
9203: <script type="text/javascript">
9204: // <![CDATA[
9205: function LCtoggleDisplay(id,hidetext,showtext) {
9206: link = document.getElementById(id + "link").childNodes[0];
9207: with (document.getElementById(id).style) {
9208: if (display == "none" ) {
9209: display = "inline";
9210: link.nodeValue = hidetext;
9211: } else {
9212: display = "none";
9213: link.nodeValue = showtext;
9214: }
9215: }
9216: }
9217: // ]]>
9218: </script>
9219: ENDTOGGLE
9220: }
9221:
1.1039 www 9222: sub start_togglebox {
9223: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9224: unless ($heading) { $heading=''; } else { $heading.=' '; }
9225: unless ($showtext) { $showtext=&mt('show'); }
9226: unless ($hidetext) { $hidetext=&mt('hide'); }
9227: unless ($headerbg) { $headerbg='#FFFFFF'; }
9228: return &start_data_table().
9229: &start_data_table_header_row().
9230: '<td bgcolor="'.$headerbg.'">'.$heading.
9231: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9232: $showtext.'\')">'.$showtext.'</a>]</td>'.
9233: &end_data_table_header_row().
9234: '<tr id="'.$id.'" style="display:none""><td>';
9235: }
9236:
9237: sub end_togglebox {
9238: return '</td></tr>'.&end_data_table();
9239: }
9240:
1.1041 www 9241: sub LCprogressbar_script {
1.1075.2.130 raeburn 9242: my ($id,$number_to_do)=@_;
9243: if ($number_to_do) {
9244: return(<<ENDPROGRESS);
1.1041 www 9245: <script type="text/javascript">
9246: // <![CDATA[
1.1045 www 9247: \$('#progressbar$id').progressbar({
1.1041 www 9248: value: 0,
9249: change: function(event, ui) {
9250: var newVal = \$(this).progressbar('option', 'value');
9251: \$('.pblabel', this).text(LCprogressTxt);
9252: }
9253: });
9254: // ]]>
9255: </script>
9256: ENDPROGRESS
1.1075.2.130 raeburn 9257: } else {
9258: return(<<ENDPROGRESS);
9259: <script type="text/javascript">
9260: // <![CDATA[
9261: \$('#progressbar$id').progressbar({
9262: value: false,
9263: create: function(event, ui) {
9264: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9265: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9266: }
9267: });
9268: // ]]>
9269: </script>
9270: ENDPROGRESS
9271: }
1.1041 www 9272: }
9273:
9274: sub LCprogressbarUpdate_script {
9275: return(<<ENDPROGRESSUPDATE);
9276: <style type="text/css">
9277: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9278: .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 9279: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9280: </style>
9281: <script type="text/javascript">
9282: // <![CDATA[
1.1045 www 9283: var LCprogressTxt='---';
9284:
1.1075.2.130 raeburn 9285: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9286: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9287: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9288: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9289: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9290: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9291: } else {
9292: \$('#progressbar'+id).progressbar('value',percent);
9293: }
1.1041 www 9294: }
9295: // ]]>
9296: </script>
9297: ENDPROGRESSUPDATE
9298: }
9299:
1.1042 www 9300: my $LClastpercent;
1.1045 www 9301: my $LCidcnt;
9302: my $LCcurrentid;
1.1042 www 9303:
1.1041 www 9304: sub LCprogressbar {
1.1075.2.130 raeburn 9305: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9306: $LClastpercent=0;
1.1045 www 9307: $LCidcnt++;
9308: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9309: my ($starting,$content);
9310: if ($number_to_do) {
9311: $starting=&mt('Starting');
9312: $content=(<<ENDPROGBAR);
9313: $preamble
1.1045 www 9314: <div id="progressbar$LCcurrentid">
1.1041 www 9315: <span class="pblabel">$starting</span>
9316: </div>
9317: ENDPROGBAR
1.1075.2.130 raeburn 9318: } else {
9319: $starting=&mt('Loading...');
9320: $LClastpercent='false';
9321: $content=(<<ENDPROGBAR);
9322: $preamble
9323: <div id="progressbar$LCcurrentid">
9324: <div class="progress-label">$starting</div>
9325: </div>
9326: ENDPROGBAR
9327: }
9328: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9329: }
9330:
9331: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9332: my ($r,$val,$text,$number_to_do)=@_;
9333: if ($number_to_do) {
9334: unless ($val) {
9335: if ($LClastpercent) {
9336: $val=$LClastpercent;
9337: } else {
9338: $val=0;
9339: }
9340: }
9341: if ($val<0) { $val=0; }
9342: if ($val>100) { $val=0; }
9343: $LClastpercent=$val;
9344: unless ($text) { $text=$val.'%'; }
9345: } else {
9346: $val = 'false';
1.1042 www 9347: }
1.1041 www 9348: $text=&js_ready($text);
1.1044 www 9349: &r_print($r,<<ENDUPDATE);
1.1041 www 9350: <script type="text/javascript">
9351: // <![CDATA[
1.1075.2.130 raeburn 9352: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9353: // ]]>
9354: </script>
9355: ENDUPDATE
1.1035 www 9356: }
9357:
1.1042 www 9358: sub LCprogressbarClose {
9359: my ($r)=@_;
9360: $LClastpercent=0;
1.1044 www 9361: &r_print($r,<<ENDCLOSE);
1.1042 www 9362: <script type="text/javascript">
9363: // <![CDATA[
1.1045 www 9364: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9365: // ]]>
9366: </script>
9367: ENDCLOSE
1.1044 www 9368: }
9369:
9370: sub r_print {
9371: my ($r,$to_print)=@_;
9372: if ($r) {
9373: $r->print($to_print);
9374: $r->rflush();
9375: } else {
9376: print($to_print);
9377: }
1.1042 www 9378: }
9379:
1.320 albertel 9380: sub html_encode {
9381: my ($result) = @_;
9382:
1.322 albertel 9383: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9384:
9385: return $result;
9386: }
1.1044 www 9387:
1.317 albertel 9388: sub js_ready {
9389: my ($result) = @_;
9390:
1.323 albertel 9391: $result =~ s/[\n\r]/ /xmsg;
9392: $result =~ s/\\/\\\\/xmsg;
9393: $result =~ s/'/\\'/xmsg;
1.372 albertel 9394: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9395:
9396: return $result;
9397: }
9398:
1.315 albertel 9399: sub validate_page {
9400: if ( exists($env{'internal.start_page'})
1.316 albertel 9401: && $env{'internal.start_page'} > 1) {
9402: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9403: $env{'internal.start_page'}.' '.
1.316 albertel 9404: $ENV{'request.filename'});
1.315 albertel 9405: }
9406: if ( exists($env{'internal.end_page'})
1.316 albertel 9407: && $env{'internal.end_page'} > 1) {
9408: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9409: $env{'internal.end_page'}.' '.
1.316 albertel 9410: $env{'request.filename'});
1.315 albertel 9411: }
9412: if ( exists($env{'internal.start_page'})
9413: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9414: &Apache::lonnet::logthis('start_page called without end_page '.
9415: $env{'request.filename'});
1.315 albertel 9416: }
9417: if ( ! exists($env{'internal.start_page'})
9418: && exists($env{'internal.end_page'})) {
1.316 albertel 9419: &Apache::lonnet::logthis('end_page called without start_page'.
9420: $env{'request.filename'});
1.315 albertel 9421: }
1.306 albertel 9422: }
1.315 albertel 9423:
1.996 www 9424:
9425: sub start_scrollbox {
1.1075.2.56 raeburn 9426: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9427: unless ($outerwidth) { $outerwidth='520px'; }
9428: unless ($width) { $width='500px'; }
9429: unless ($height) { $height='200px'; }
1.1075 raeburn 9430: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9431: if ($id ne '') {
1.1075.2.42 raeburn 9432: $table_id = ' id="table_'.$id.'"';
9433: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9434: }
1.1075 raeburn 9435: if ($bgcolor ne '') {
9436: $tdcol = "background-color: $bgcolor;";
9437: }
1.1075.2.42 raeburn 9438: my $nicescroll_js;
9439: if ($env{'browser.mobile'}) {
9440: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9441: }
1.1075 raeburn 9442: return <<"END";
1.1075.2.42 raeburn 9443: $nicescroll_js
9444:
9445: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 9446: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 9447: END
1.996 www 9448: }
9449:
9450: sub end_scrollbox {
1.1036 www 9451: return '</div></td></tr></table>';
1.996 www 9452: }
9453:
1.1075.2.42 raeburn 9454: sub nicescroll_javascript {
9455: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9456: my %options;
9457: if (ref($cursor) eq 'HASH') {
9458: %options = %{$cursor};
9459: }
9460: unless ($options{'railalign'} =~ /^left|right$/) {
9461: $options{'railalign'} = 'left';
9462: }
9463: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9464: my $function = &get_users_function();
9465: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9466: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9467: $options{'cursorcolor'} = '#00F';
9468: }
9469: }
9470: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9471: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9472: $options{'cursoropacity'}='1.0';
9473: }
9474: } else {
9475: $options{'cursoropacity'}='1.0';
9476: }
9477: if ($options{'cursorfixedheight'} eq 'none') {
9478: delete($options{'cursorfixedheight'});
9479: } else {
9480: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9481: }
9482: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9483: delete($options{'railoffset'});
9484: }
9485: my @niceoptions;
9486: while (my($key,$value) = each(%options)) {
9487: if ($value =~ /^\{.+\}$/) {
9488: push(@niceoptions,$key.':'.$value);
9489: } else {
9490: push(@niceoptions,$key.':"'.$value.'"');
9491: }
9492: }
9493: my $nicescroll_js = '
9494: $(document).ready(
9495: function() {
9496: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9497: }
9498: );
9499: ';
9500: if ($framecheck) {
9501: $nicescroll_js .= '
9502: function expand_div(caller) {
9503: if (top === self) {
9504: document.getElementById("'.$id.'").style.width = "auto";
9505: document.getElementById("'.$id.'").style.height = "auto";
9506: } else {
9507: try {
9508: if (parent.frames) {
9509: if (parent.frames.length > 1) {
9510: var framesrc = parent.frames[1].location.href;
9511: var currsrc = framesrc.replace(/\#.*$/,"");
9512: if ((caller == "search") || (currsrc == "'.$location.'")) {
9513: document.getElementById("'.$id.'").style.width = "auto";
9514: document.getElementById("'.$id.'").style.height = "auto";
9515: }
9516: }
9517: }
9518: } catch (e) {
9519: return;
9520: }
9521: }
9522: return;
9523: }
9524: ';
9525: }
9526: if ($needjsready) {
9527: $nicescroll_js = '
9528: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9529: } else {
9530: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9531: }
9532: return $nicescroll_js;
9533: }
9534:
1.318 albertel 9535: sub simple_error_page {
1.1075.2.49 raeburn 9536: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 9537:22): my %displayargs;
1.1075.2.49 raeburn 9538: if (ref($args) eq 'HASH') {
9539: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 9540:22): if ($args->{'only_body'}) {
9541:22): $displayargs{'only_body'} = 1;
9542:22): }
9543:22): if ($args->{'no_nav_bar'}) {
9544:22): $displayargs{'no_nav_bar'} = 1;
9545:22): }
1.1075.2.49 raeburn 9546: } else {
9547: $msg = &mt($msg);
9548: }
9549:
1.318 albertel 9550: my $page =
1.1075.2.161. .4(raebu 9551:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 9552: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9553: &Apache::loncommon::end_page();
9554: if (ref($r)) {
9555: $r->print($page);
1.327 albertel 9556: return;
1.318 albertel 9557: }
9558: return $page;
9559: }
1.347 albertel 9560:
9561: {
1.610 albertel 9562: my @row_count;
1.961 onken 9563:
9564: sub start_data_table_count {
9565: unshift(@row_count, 0);
9566: return;
9567: }
9568:
9569: sub end_data_table_count {
9570: shift(@row_count);
9571: return;
9572: }
9573:
1.347 albertel 9574: sub start_data_table {
1.1018 raeburn 9575: my ($add_class,$id) = @_;
1.422 albertel 9576: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9577: my $table_id;
9578: if (defined($id)) {
9579: $table_id = ' id="'.$id.'"';
9580: }
1.961 onken 9581: &start_data_table_count();
1.1018 raeburn 9582: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9583: }
9584:
9585: sub end_data_table {
1.961 onken 9586: &end_data_table_count();
1.389 albertel 9587: return '</table>'."\n";;
1.347 albertel 9588: }
9589:
9590: sub start_data_table_row {
1.974 wenzelju 9591: my ($add_class, $id) = @_;
1.610 albertel 9592: $row_count[0]++;
9593: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9594: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9595: $id = (' id="'.$id.'"') unless ($id eq '');
9596: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9597: }
1.471 banghart 9598:
9599: sub continue_data_table_row {
1.974 wenzelju 9600: my ($add_class, $id) = @_;
1.610 albertel 9601: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9602: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9603: $id = (' id="'.$id.'"') unless ($id eq '');
9604: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9605: }
1.347 albertel 9606:
9607: sub end_data_table_row {
1.389 albertel 9608: return '</tr>'."\n";;
1.347 albertel 9609: }
1.367 www 9610:
1.421 albertel 9611: sub start_data_table_empty_row {
1.707 bisitz 9612: # $row_count[0]++;
1.421 albertel 9613: return '<tr class="LC_empty_row" >'."\n";;
9614: }
9615:
9616: sub end_data_table_empty_row {
9617: return '</tr>'."\n";;
9618: }
9619:
1.367 www 9620: sub start_data_table_header_row {
1.389 albertel 9621: return '<tr class="LC_header_row">'."\n";;
1.367 www 9622: }
9623:
9624: sub end_data_table_header_row {
1.389 albertel 9625: return '</tr>'."\n";;
1.367 www 9626: }
1.890 droeschl 9627:
9628: sub data_table_caption {
9629: my $caption = shift;
9630: return "<caption class=\"LC_caption\">$caption</caption>";
9631: }
1.347 albertel 9632: }
9633:
1.548 albertel 9634: =pod
9635:
9636: =item * &inhibit_menu_check($arg)
9637:
9638: Checks for a inhibitmenu state and generates output to preserve it
9639:
9640: Inputs: $arg - can be any of
9641: - undef - in which case the return value is a string
9642: to add into arguments list of a uri
9643: - 'input' - in which case the return value is a HTML
9644: <form> <input> field of type hidden to
9645: preserve the value
9646: - a url - in which case the return value is the url with
9647: the neccesary cgi args added to preserve the
9648: inhibitmenu state
9649: - a ref to a url - no return value, but the string is
9650: updated to include the neccessary cgi
9651: args to preserve the inhibitmenu state
9652:
9653: =cut
9654:
9655: sub inhibit_menu_check {
9656: my ($arg) = @_;
9657: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9658: if ($arg eq 'input') {
9659: if ($env{'form.inhibitmenu'}) {
9660: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9661: } else {
9662: return
9663: }
9664: }
9665: if ($env{'form.inhibitmenu'}) {
9666: if (ref($arg)) {
9667: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9668: } elsif ($arg eq '') {
9669: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9670: } else {
9671: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9672: }
9673: }
9674: if (!ref($arg)) {
9675: return $arg;
9676: }
9677: }
9678:
1.251 albertel 9679: ###############################################
1.182 matthew 9680:
9681: =pod
9682:
1.549 albertel 9683: =back
9684:
9685: =head1 User Information Routines
9686:
9687: =over 4
9688:
1.405 albertel 9689: =item * &get_users_function()
1.182 matthew 9690:
9691: Used by &bodytag to determine the current users primary role.
9692: Returns either 'student','coordinator','admin', or 'author'.
9693:
9694: =cut
9695:
9696: ###############################################
9697: sub get_users_function {
1.815 tempelho 9698: my $function = 'norole';
1.818 tempelho 9699: if ($env{'request.role'}=~/^(st)/) {
9700: $function='student';
9701: }
1.907 raeburn 9702: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9703: $function='coordinator';
9704: }
1.258 albertel 9705: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9706: $function='admin';
9707: }
1.826 bisitz 9708: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9709: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9710: $function='author';
9711: }
9712: return $function;
1.54 www 9713: }
1.99 www 9714:
9715: ###############################################
9716:
1.233 raeburn 9717: =pod
9718:
1.821 raeburn 9719: =item * &show_course()
9720:
9721: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9722: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9723:
9724: Inputs:
9725: None
9726:
9727: Outputs:
9728: Scalar: 1 if 'Course' to be used, 0 otherwise.
9729:
9730: =cut
9731:
9732: ###############################################
9733: sub show_course {
9734: my $course = !$env{'user.adv'};
9735: if (!$env{'user.adv'}) {
9736: foreach my $env (keys(%env)) {
9737: next if ($env !~ m/^user\.priv\./);
9738: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9739: $course = 0;
9740: last;
9741: }
9742: }
9743: }
9744: return $course;
9745: }
9746:
9747: ###############################################
9748:
9749: =pod
9750:
1.542 raeburn 9751: =item * &check_user_status()
1.274 raeburn 9752:
9753: Determines current status of supplied role for a
9754: specific user. Roles can be active, previous or future.
9755:
9756: Inputs:
9757: user's domain, user's username, course's domain,
1.375 raeburn 9758: course's number, optional section ID.
1.274 raeburn 9759:
9760: Outputs:
9761: role status: active, previous or future.
9762:
9763: =cut
9764:
9765: sub check_user_status {
1.412 raeburn 9766: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9767: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9768: my @uroles = keys(%userinfo);
1.274 raeburn 9769: my $srchstr;
9770: my $active_chk = 'none';
1.412 raeburn 9771: my $now = time;
1.274 raeburn 9772: if (@uroles > 0) {
1.908 raeburn 9773: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9774: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9775: } else {
1.412 raeburn 9776: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9777: }
9778: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9779: my $role_end = 0;
9780: my $role_start = 0;
9781: $active_chk = 'active';
1.412 raeburn 9782: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9783: $role_end = $1;
9784: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9785: $role_start = $1;
1.274 raeburn 9786: }
9787: }
9788: if ($role_start > 0) {
1.412 raeburn 9789: if ($now < $role_start) {
1.274 raeburn 9790: $active_chk = 'future';
9791: }
9792: }
9793: if ($role_end > 0) {
1.412 raeburn 9794: if ($now > $role_end) {
1.274 raeburn 9795: $active_chk = 'previous';
9796: }
9797: }
9798: }
9799: }
9800: return $active_chk;
9801: }
9802:
9803: ###############################################
9804:
9805: =pod
9806:
1.405 albertel 9807: =item * &get_sections()
1.233 raeburn 9808:
9809: Determines all the sections for a course including
9810: sections with students and sections containing other roles.
1.419 raeburn 9811: Incoming parameters:
9812:
9813: 1. domain
9814: 2. course number
9815: 3. reference to array containing roles for which sections should
9816: be gathered (optional).
9817: 4. reference to array containing status types for which sections
9818: should be gathered (optional).
9819:
9820: If the third argument is undefined, sections are gathered for any role.
9821: If the fourth argument is undefined, sections are gathered for any status.
9822: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9823:
1.374 raeburn 9824: Returns section hash (keys are section IDs, values are
9825: number of users in each section), subject to the
1.419 raeburn 9826: optional roles filter, optional status filter
1.233 raeburn 9827:
9828: =cut
9829:
9830: ###############################################
9831: sub get_sections {
1.419 raeburn 9832: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9833: if (!defined($cdom) || !defined($cnum)) {
9834: my $cid = $env{'request.course.id'};
9835:
9836: return if (!defined($cid));
9837:
9838: $cdom = $env{'course.'.$cid.'.domain'};
9839: $cnum = $env{'course.'.$cid.'.num'};
9840: }
9841:
9842: my %sectioncount;
1.419 raeburn 9843: my $now = time;
1.240 albertel 9844:
1.1075.2.33 raeburn 9845: my $check_students = 1;
9846: my $only_students = 0;
9847: if (ref($possible_roles) eq 'ARRAY') {
9848: if (grep(/^st$/,@{$possible_roles})) {
9849: if (@{$possible_roles} == 1) {
9850: $only_students = 1;
9851: }
9852: } else {
9853: $check_students = 0;
9854: }
9855: }
9856:
9857: if ($check_students) {
1.276 albertel 9858: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9859: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9860: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9861: my $start_index = &Apache::loncoursedata::CL_START();
9862: my $end_index = &Apache::loncoursedata::CL_END();
9863: my $status;
1.366 albertel 9864: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9865: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9866: $data->[$status_index],
9867: $data->[$start_index],
9868: $data->[$end_index]);
9869: if ($stu_status eq 'Active') {
9870: $status = 'active';
9871: } elsif ($end < $now) {
9872: $status = 'previous';
9873: } elsif ($start > $now) {
9874: $status = 'future';
9875: }
9876: if ($section ne '-1' && $section !~ /^\s*$/) {
9877: if ((!defined($possible_status)) || (($status ne '') &&
9878: (grep/^\Q$status\E$/,@{$possible_status}))) {
9879: $sectioncount{$section}++;
9880: }
1.240 albertel 9881: }
9882: }
9883: }
1.1075.2.33 raeburn 9884: if ($only_students) {
9885: return %sectioncount;
9886: }
1.240 albertel 9887: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9888: foreach my $user (sort(keys(%courseroles))) {
9889: if ($user !~ /^(\w{2})/) { next; }
9890: my ($role) = ($user =~ /^(\w{2})/);
9891: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9892: my ($section,$status);
1.240 albertel 9893: if ($role eq 'cr' &&
9894: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9895: $section=$1;
9896: }
9897: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9898: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9899: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9900: if ($end == -1 && $start == -1) {
9901: next; #deleted role
9902: }
9903: if (!defined($possible_status)) {
9904: $sectioncount{$section}++;
9905: } else {
9906: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9907: $status = 'active';
9908: } elsif ($end < $now) {
9909: $status = 'future';
9910: } elsif ($start > $now) {
9911: $status = 'previous';
9912: }
9913: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9914: $sectioncount{$section}++;
9915: }
9916: }
1.233 raeburn 9917: }
1.366 albertel 9918: return %sectioncount;
1.233 raeburn 9919: }
9920:
1.274 raeburn 9921: ###############################################
1.294 raeburn 9922:
9923: =pod
1.405 albertel 9924:
9925: =item * &get_course_users()
9926:
1.275 raeburn 9927: Retrieves usernames:domains for users in the specified course
9928: with specific role(s), and access status.
9929:
9930: Incoming parameters:
1.277 albertel 9931: 1. course domain
9932: 2. course number
9933: 3. access status: users must have - either active,
1.275 raeburn 9934: previous, future, or all.
1.277 albertel 9935: 4. reference to array of permissible roles
1.288 raeburn 9936: 5. reference to array of section restrictions (optional)
9937: 6. reference to results object (hash of hashes).
9938: 7. reference to optional userdata hash
1.609 raeburn 9939: 8. reference to optional statushash
1.630 raeburn 9940: 9. flag if privileged users (except those set to unhide in
9941: course settings) should be excluded
1.609 raeburn 9942: Keys of top level results hash are roles.
1.275 raeburn 9943: Keys of inner hashes are username:domain, with
9944: values set to access type.
1.288 raeburn 9945: Optional userdata hash returns an array with arguments in the
9946: same order as loncoursedata::get_classlist() for student data.
9947:
1.609 raeburn 9948: Optional statushash returns
9949:
1.288 raeburn 9950: Entries for end, start, section and status are blank because
9951: of the possibility of multiple values for non-student roles.
9952:
1.275 raeburn 9953: =cut
1.405 albertel 9954:
1.275 raeburn 9955: ###############################################
1.405 albertel 9956:
1.275 raeburn 9957: sub get_course_users {
1.630 raeburn 9958: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9959: my %idx = ();
1.419 raeburn 9960: my %seclists;
1.288 raeburn 9961:
9962: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9963: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9964: $idx{end} = &Apache::loncoursedata::CL_END();
9965: $idx{start} = &Apache::loncoursedata::CL_START();
9966: $idx{id} = &Apache::loncoursedata::CL_ID();
9967: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9968: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9969: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9970:
1.290 albertel 9971: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9972: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9973: my $now = time;
1.277 albertel 9974: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9975: my $match = 0;
1.412 raeburn 9976: my $secmatch = 0;
1.419 raeburn 9977: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9978: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9979: if ($section eq '') {
9980: $section = 'none';
9981: }
1.291 albertel 9982: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9983: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9984: $secmatch = 1;
9985: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9986: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9987: $secmatch = 1;
9988: }
9989: } else {
1.419 raeburn 9990: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9991: $secmatch = 1;
9992: }
1.290 albertel 9993: }
1.412 raeburn 9994: if (!$secmatch) {
9995: next;
9996: }
1.419 raeburn 9997: }
1.275 raeburn 9998: if (defined($$types{'active'})) {
1.288 raeburn 9999: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10000: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10001: $match = 1;
1.275 raeburn 10002: }
10003: }
10004: if (defined($$types{'previous'})) {
1.609 raeburn 10005: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10006: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10007: $match = 1;
1.275 raeburn 10008: }
10009: }
10010: if (defined($$types{'future'})) {
1.609 raeburn 10011: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10012: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10013: $match = 1;
1.275 raeburn 10014: }
10015: }
1.609 raeburn 10016: if ($match) {
10017: push(@{$seclists{$student}},$section);
10018: if (ref($userdata) eq 'HASH') {
10019: $$userdata{$student} = $$classlist{$student};
10020: }
10021: if (ref($statushash) eq 'HASH') {
10022: $statushash->{$student}{'st'}{$section} = $status;
10023: }
1.288 raeburn 10024: }
1.275 raeburn 10025: }
10026: }
1.412 raeburn 10027: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10028: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10029: my $now = time;
1.609 raeburn 10030: my %displaystatus = ( previous => 'Expired',
10031: active => 'Active',
10032: future => 'Future',
10033: );
1.1075.2.36 raeburn 10034: my (%nothide,@possdoms);
1.630 raeburn 10035: if ($hidepriv) {
10036: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10037: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10038: if ($user !~ /:/) {
10039: $nothide{join(':',split(/[\@]/,$user))}=1;
10040: } else {
10041: $nothide{$user} = 1;
10042: }
10043: }
1.1075.2.36 raeburn 10044: my @possdoms = ($cdom);
10045: if ($coursehash{'checkforpriv'}) {
10046: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10047: }
1.630 raeburn 10048: }
1.439 raeburn 10049: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10050: my $match = 0;
1.412 raeburn 10051: my $secmatch = 0;
1.439 raeburn 10052: my $status;
1.412 raeburn 10053: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10054: $user =~ s/:$//;
1.439 raeburn 10055: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10056: if ($end == -1 || $start == -1) {
10057: next;
10058: }
10059: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10060: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10061: my ($uname,$udom) = split(/:/,$user);
10062: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10063: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10064: $secmatch = 1;
10065: } elsif ($usec eq '') {
1.420 albertel 10066: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10067: $secmatch = 1;
10068: }
10069: } else {
10070: if (grep(/^\Q$usec\E$/,@{$sections})) {
10071: $secmatch = 1;
10072: }
10073: }
10074: if (!$secmatch) {
10075: next;
10076: }
1.288 raeburn 10077: }
1.419 raeburn 10078: if ($usec eq '') {
10079: $usec = 'none';
10080: }
1.275 raeburn 10081: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10082: if ($hidepriv) {
1.1075.2.36 raeburn 10083: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10084: (!$nothide{$uname.':'.$udom})) {
10085: next;
10086: }
10087: }
1.503 raeburn 10088: if ($end > 0 && $end < $now) {
1.439 raeburn 10089: $status = 'previous';
10090: } elsif ($start > $now) {
10091: $status = 'future';
10092: } else {
10093: $status = 'active';
10094: }
1.277 albertel 10095: foreach my $type (keys(%{$types})) {
1.275 raeburn 10096: if ($status eq $type) {
1.420 albertel 10097: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10098: push(@{$$users{$role}{$user}},$type);
10099: }
1.288 raeburn 10100: $match = 1;
10101: }
10102: }
1.419 raeburn 10103: if (($match) && (ref($userdata) eq 'HASH')) {
10104: if (!exists($$userdata{$uname.':'.$udom})) {
10105: &get_user_info($udom,$uname,\%idx,$userdata);
10106: }
1.420 albertel 10107: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10108: push(@{$seclists{$uname.':'.$udom}},$usec);
10109: }
1.609 raeburn 10110: if (ref($statushash) eq 'HASH') {
10111: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10112: }
1.275 raeburn 10113: }
10114: }
10115: }
10116: }
1.290 albertel 10117: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10118: if ((defined($cdom)) && (defined($cnum))) {
10119: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10120: if ( defined($csettings{'internal.courseowner'}) ) {
10121: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10122: next if ($owner eq '');
10123: my ($ownername,$ownerdom);
10124: if ($owner =~ /^([^:]+):([^:]+)$/) {
10125: $ownername = $1;
10126: $ownerdom = $2;
10127: } else {
10128: $ownername = $owner;
10129: $ownerdom = $cdom;
10130: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10131: }
10132: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10133: if (defined($userdata) &&
1.609 raeburn 10134: !exists($$userdata{$owner})) {
10135: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10136: if (!grep(/^none$/,@{$seclists{$owner}})) {
10137: push(@{$seclists{$owner}},'none');
10138: }
10139: if (ref($statushash) eq 'HASH') {
10140: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10141: }
1.290 albertel 10142: }
1.279 raeburn 10143: }
10144: }
10145: }
1.419 raeburn 10146: foreach my $user (keys(%seclists)) {
10147: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10148: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10149: }
1.275 raeburn 10150: }
10151: return;
10152: }
10153:
1.288 raeburn 10154: sub get_user_info {
10155: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10156: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10157: &plainname($uname,$udom,'lastname');
1.291 albertel 10158: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10159: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10160: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10161: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10162: return;
10163: }
1.275 raeburn 10164:
1.472 raeburn 10165: ###############################################
10166:
10167: =pod
10168:
10169: =item * &get_user_quota()
10170:
1.1075.2.41 raeburn 10171: Retrieves quota assigned for storage of user files.
10172: Default is to report quota for portfolio files.
1.472 raeburn 10173:
10174: Incoming parameters:
10175: 1. user's username
10176: 2. user's domain
1.1075.2.41 raeburn 10177: 3. quota name - portfolio, author, or course
10178: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10179: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10180: course
1.472 raeburn 10181:
10182: Returns:
1.1075.2.58 raeburn 10183: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10184: 2. (Optional) Type of setting: custom or default
10185: (individually assigned or default for user's
10186: institutional status).
10187: 3. (Optional) - User's institutional status (e.g., faculty, staff
10188: or student - types as defined in localenroll::inst_usertypes
10189: for user's domain, which determines default quota for user.
10190: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10191:
10192: If a value has been stored in the user's environment,
1.536 raeburn 10193: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10194: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10195:
10196: =cut
10197:
10198: ###############################################
10199:
10200:
10201: sub get_user_quota {
1.1075.2.42 raeburn 10202: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10203: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10204: if (!defined($udom)) {
10205: $udom = $env{'user.domain'};
10206: }
10207: if (!defined($uname)) {
10208: $uname = $env{'user.name'};
10209: }
10210: if (($udom eq '' || $uname eq '') ||
10211: ($udom eq 'public') && ($uname eq 'public')) {
10212: $quota = 0;
1.536 raeburn 10213: $quotatype = 'default';
10214: $defquota = 0;
1.472 raeburn 10215: } else {
1.536 raeburn 10216: my $inststatus;
1.1075.2.41 raeburn 10217: if ($quotaname eq 'course') {
10218: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10219: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10220: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10221: } else {
10222: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10223: $quota = $cenv{'internal.uploadquota'};
10224: }
1.536 raeburn 10225: } else {
1.1075.2.41 raeburn 10226: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10227: if ($quotaname eq 'author') {
10228: $quota = $env{'environment.authorquota'};
10229: } else {
10230: $quota = $env{'environment.portfolioquota'};
10231: }
10232: $inststatus = $env{'environment.inststatus'};
10233: } else {
10234: my %userenv =
10235: &Apache::lonnet::get('environment',['portfolioquota',
10236: 'authorquota','inststatus'],$udom,$uname);
10237: my ($tmp) = keys(%userenv);
10238: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10239: if ($quotaname eq 'author') {
10240: $quota = $userenv{'authorquota'};
10241: } else {
10242: $quota = $userenv{'portfolioquota'};
10243: }
10244: $inststatus = $userenv{'inststatus'};
10245: } else {
10246: undef(%userenv);
10247: }
10248: }
10249: }
10250: if ($quota eq '' || wantarray) {
10251: if ($quotaname eq 'course') {
10252: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10253: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10254: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10255: $defquota = $domdefs{$crstype.'quota'};
10256: }
10257: if ($defquota eq '') {
10258: $defquota = 500;
10259: }
1.1075.2.41 raeburn 10260: } else {
10261: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10262: }
10263: if ($quota eq '') {
10264: $quota = $defquota;
10265: $quotatype = 'default';
10266: } else {
10267: $quotatype = 'custom';
10268: }
1.472 raeburn 10269: }
10270: }
1.536 raeburn 10271: if (wantarray) {
10272: return ($quota,$quotatype,$settingstatus,$defquota);
10273: } else {
10274: return $quota;
10275: }
1.472 raeburn 10276: }
10277:
10278: ###############################################
10279:
10280: =pod
10281:
10282: =item * &default_quota()
10283:
1.536 raeburn 10284: Retrieves default quota assigned for storage of user portfolio files,
10285: given an (optional) user's institutional status.
1.472 raeburn 10286:
10287: Incoming parameters:
1.1075.2.42 raeburn 10288:
1.472 raeburn 10289: 1. domain
1.536 raeburn 10290: 2. (Optional) institutional status(es). This is a : separated list of
10291: status types (e.g., faculty, staff, student etc.)
10292: which apply to the user for whom the default is being retrieved.
10293: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10294: default quota will be returned.
10295: 3. quota name - portfolio, author, or course
10296: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10297:
10298: Returns:
1.1075.2.42 raeburn 10299:
1.1075.2.58 raeburn 10300: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10301: 2. (Optional) institutional type which determined the value of the
10302: default quota.
1.472 raeburn 10303:
10304: If a value has been stored in the domain's configuration db,
10305: it will return that, otherwise it returns 20 (for backwards
10306: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10307: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10308:
1.536 raeburn 10309: If the user's status includes multiple types (e.g., staff and student),
10310: the largest default quota which applies to the user determines the
10311: default quota returned.
10312:
1.472 raeburn 10313: =cut
10314:
10315: ###############################################
10316:
10317:
10318: sub default_quota {
1.1075.2.41 raeburn 10319: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10320: my ($defquota,$settingstatus);
10321: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10322: ['quotas'],$udom);
1.1075.2.41 raeburn 10323: my $key = 'defaultquota';
10324: if ($quotaname eq 'author') {
10325: $key = 'authorquota';
10326: }
1.622 raeburn 10327: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10328: if ($inststatus ne '') {
1.765 raeburn 10329: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10330: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10331: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10332: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10333: if ($defquota eq '') {
1.1075.2.41 raeburn 10334: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10335: $settingstatus = $item;
1.1075.2.41 raeburn 10336: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10337: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10338: $settingstatus = $item;
10339: }
10340: }
1.1075.2.41 raeburn 10341: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10342: if ($quotahash{'quotas'}{$item} ne '') {
10343: if ($defquota eq '') {
10344: $defquota = $quotahash{'quotas'}{$item};
10345: $settingstatus = $item;
10346: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10347: $defquota = $quotahash{'quotas'}{$item};
10348: $settingstatus = $item;
10349: }
1.536 raeburn 10350: }
10351: }
10352: }
10353: }
10354: if ($defquota eq '') {
1.1075.2.41 raeburn 10355: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10356: $defquota = $quotahash{'quotas'}{$key}{'default'};
10357: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10358: $defquota = $quotahash{'quotas'}{'default'};
10359: }
1.536 raeburn 10360: $settingstatus = 'default';
1.1075.2.42 raeburn 10361: if ($defquota eq '') {
10362: if ($quotaname eq 'author') {
10363: $defquota = 500;
10364: }
10365: }
1.536 raeburn 10366: }
10367: } else {
10368: $settingstatus = 'default';
1.1075.2.41 raeburn 10369: if ($quotaname eq 'author') {
10370: $defquota = 500;
10371: } else {
10372: $defquota = 20;
10373: }
1.536 raeburn 10374: }
10375: if (wantarray) {
10376: return ($defquota,$settingstatus);
1.472 raeburn 10377: } else {
1.536 raeburn 10378: return $defquota;
1.472 raeburn 10379: }
10380: }
10381:
1.1075.2.41 raeburn 10382: ###############################################
10383:
10384: =pod
10385:
1.1075.2.42 raeburn 10386: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 10387:
10388: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 10389: of existing file within authoring space will cause quota for the authoring
10390: space to be exceeded.
10391:
10392: Same, if upload of a file directly to a course/community via Course Editor
10393: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 10394:
1.1075.2.61 raeburn 10395: Inputs: 7
1.1075.2.42 raeburn 10396: 1. username or coursenum
1.1075.2.41 raeburn 10397: 2. domain
1.1075.2.42 raeburn 10398: 3. context ('author' or 'course')
1.1075.2.41 raeburn 10399: 4. filename of file for which action is being requested
10400: 5. filesize (kB) of file
10401: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 10402: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 10403:
10404: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
10405: otherwise return null.
10406:
1.1075.2.42 raeburn 10407: =back
10408:
1.1075.2.41 raeburn 10409: =cut
10410:
1.1075.2.42 raeburn 10411: sub excess_filesize_warning {
1.1075.2.59 raeburn 10412: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 10413: my $current_disk_usage = 0;
1.1075.2.59 raeburn 10414: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 10415: if ($context eq 'author') {
10416: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10417: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10418: } else {
10419: foreach my $subdir ('docs','supplemental') {
10420: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10421: }
10422: }
1.1075.2.41 raeburn 10423: $disk_quota = int($disk_quota * 1000);
10424: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 10425: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 10426: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 10427: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10428: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 10429: $disk_quota,$current_disk_usage).
10430: '</p>';
10431: }
10432: return;
10433: }
10434:
10435: ###############################################
10436:
10437:
1.384 raeburn 10438: sub get_secgrprole_info {
10439: my ($cdom,$cnum,$needroles,$type) = @_;
10440: my %sections_count = &get_sections($cdom,$cnum);
10441: my @sections = (sort {$a <=> $b} keys(%sections_count));
10442: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10443: my @groups = sort(keys(%curr_groups));
10444: my $allroles = [];
10445: my $rolehash;
10446: my $accesshash = {
10447: active => 'Currently has access',
10448: future => 'Will have future access',
10449: previous => 'Previously had access',
10450: };
10451: if ($needroles) {
10452: $rolehash = {'all' => 'all'};
1.385 albertel 10453: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10454: if (&Apache::lonnet::error(%user_roles)) {
10455: undef(%user_roles);
10456: }
10457: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10458: my ($role)=split(/\:/,$item,2);
10459: if ($role eq 'cr') { next; }
10460: if ($role =~ /^cr/) {
10461: $$rolehash{$role} = (split('/',$role))[3];
10462: } else {
10463: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10464: }
10465: }
10466: foreach my $key (sort(keys(%{$rolehash}))) {
10467: push(@{$allroles},$key);
10468: }
10469: push (@{$allroles},'st');
10470: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10471: }
10472: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10473: }
10474:
1.555 raeburn 10475: sub user_picker {
1.1075.2.127 raeburn 10476: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10477: my $currdom = $dom;
1.1075.2.114 raeburn 10478: my @alldoms = &Apache::lonnet::all_domains();
10479: if (@alldoms == 1) {
10480: my %domsrch = &Apache::lonnet::get_dom('configuration',
10481: ['directorysrch'],$alldoms[0]);
10482: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10483: my $showdom = $domdesc;
10484: if ($showdom eq '') {
10485: $showdom = $dom;
10486: }
10487: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10488: if ((!$domsrch{'directorysrch'}{'available'}) &&
10489: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10490: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10491: }
10492: }
10493: }
1.555 raeburn 10494: my %curr_selected = (
10495: srchin => 'dom',
1.580 raeburn 10496: srchby => 'lastname',
1.555 raeburn 10497: );
10498: my $srchterm;
1.625 raeburn 10499: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10500: if ($srch->{'srchby'} ne '') {
10501: $curr_selected{'srchby'} = $srch->{'srchby'};
10502: }
10503: if ($srch->{'srchin'} ne '') {
10504: $curr_selected{'srchin'} = $srch->{'srchin'};
10505: }
10506: if ($srch->{'srchtype'} ne '') {
10507: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10508: }
10509: if ($srch->{'srchdomain'} ne '') {
10510: $currdom = $srch->{'srchdomain'};
10511: }
10512: $srchterm = $srch->{'srchterm'};
10513: }
1.1075.2.98 raeburn 10514: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10515: 'usr' => 'Search criteria',
1.563 raeburn 10516: 'doma' => 'Domain/institution to search',
1.558 albertel 10517: 'uname' => 'username',
10518: 'lastname' => 'last name',
1.555 raeburn 10519: 'lastfirst' => 'last name, first name',
1.558 albertel 10520: 'crs' => 'in this course',
1.576 raeburn 10521: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10522: 'alc' => 'all LON-CAPA',
1.573 raeburn 10523: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10524: 'exact' => 'is',
10525: 'contains' => 'contains',
1.569 raeburn 10526: 'begins' => 'begins with',
1.1075.2.98 raeburn 10527: );
10528: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10529: 'youm' => "You must include some text to search for.",
10530: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10531: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10532: 'yomc' => "You must choose a domain when using an institutional directory search.",
10533: 'ymcd' => "You must choose a domain when using a domain search.",
10534: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10535: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10536: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10537: );
1.1075.2.98 raeburn 10538: &html_escape(\%html_lt);
10539: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10540: my $domform;
1.1075.2.126 raeburn 10541: my $allow_blank = 1;
1.1075.2.115 raeburn 10542: if ($fixeddom) {
1.1075.2.126 raeburn 10543: $allow_blank = 0;
10544: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10545: } else {
1.1075.2.126 raeburn 10546: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10547: }
1.563 raeburn 10548: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10549:
10550: my @srchins = ('crs','dom','alc','instd');
10551:
10552: foreach my $option (@srchins) {
10553: # FIXME 'alc' option unavailable until
10554: # loncreateuser::print_user_query_page()
10555: # has been completed.
10556: next if ($option eq 'alc');
1.880 raeburn 10557: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10558: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10559: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10560: if ($curr_selected{'srchin'} eq $option) {
10561: $srchinsel .= '
1.1075.2.98 raeburn 10562: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10563: } else {
10564: $srchinsel .= '
1.1075.2.98 raeburn 10565: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10566: }
1.555 raeburn 10567: }
1.563 raeburn 10568: $srchinsel .= "\n </select>\n";
1.555 raeburn 10569:
10570: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10571: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10572: if ($curr_selected{'srchby'} eq $option) {
10573: $srchbysel .= '
1.1075.2.98 raeburn 10574: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10575: } else {
10576: $srchbysel .= '
1.1075.2.98 raeburn 10577: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10578: }
10579: }
10580: $srchbysel .= "\n </select>\n";
10581:
10582: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10583: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10584: if ($curr_selected{'srchtype'} eq $option) {
10585: $srchtypesel .= '
1.1075.2.98 raeburn 10586: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10587: } else {
10588: $srchtypesel .= '
1.1075.2.98 raeburn 10589: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10590: }
10591: }
10592: $srchtypesel .= "\n </select>\n";
10593:
1.558 albertel 10594: my ($newuserscript,$new_user_create);
1.994 raeburn 10595: my $context_dom = $env{'request.role.domain'};
10596: if ($context eq 'requestcrs') {
10597: if ($env{'form.coursedom'} ne '') {
10598: $context_dom = $env{'form.coursedom'};
10599: }
10600: }
1.556 raeburn 10601: if ($forcenewuser) {
1.576 raeburn 10602: if (ref($srch) eq 'HASH') {
1.994 raeburn 10603: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10604: if ($cancreate) {
10605: $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>';
10606: } else {
1.799 bisitz 10607: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10608: my %usertypetext = (
10609: official => 'institutional',
10610: unofficial => 'non-institutional',
10611: );
1.799 bisitz 10612: $new_user_create = '<p class="LC_warning">'
10613: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10614: .' '
10615: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10616: ,'<a href="'.$helplink.'">','</a>')
10617: .'</p><br />';
1.627 raeburn 10618: }
1.576 raeburn 10619: }
10620: }
10621:
1.556 raeburn 10622: $newuserscript = <<"ENDSCRIPT";
10623:
1.570 raeburn 10624: function setSearch(createnew,callingForm) {
1.556 raeburn 10625: if (createnew == 1) {
1.570 raeburn 10626: for (var i=0; i<callingForm.srchby.length; i++) {
10627: if (callingForm.srchby.options[i].value == 'uname') {
10628: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10629: }
10630: }
1.570 raeburn 10631: for (var i=0; i<callingForm.srchin.length; i++) {
10632: if ( callingForm.srchin.options[i].value == 'dom') {
10633: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10634: }
10635: }
1.570 raeburn 10636: for (var i=0; i<callingForm.srchtype.length; i++) {
10637: if (callingForm.srchtype.options[i].value == 'exact') {
10638: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10639: }
10640: }
1.570 raeburn 10641: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10642: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10643: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10644: }
10645: }
10646: }
10647: }
10648: ENDSCRIPT
1.558 albertel 10649:
1.556 raeburn 10650: }
10651:
1.555 raeburn 10652: my $output = <<"END_BLOCK";
1.556 raeburn 10653: <script type="text/javascript">
1.824 bisitz 10654: // <![CDATA[
1.570 raeburn 10655: function validateEntry(callingForm) {
1.558 albertel 10656:
1.556 raeburn 10657: var checkok = 1;
1.558 albertel 10658: var srchin;
1.570 raeburn 10659: for (var i=0; i<callingForm.srchin.length; i++) {
10660: if ( callingForm.srchin[i].checked ) {
10661: srchin = callingForm.srchin[i].value;
1.558 albertel 10662: }
10663: }
10664:
1.570 raeburn 10665: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10666: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10667: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10668: var srchterm = callingForm.srchterm.value;
10669: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10670: var msg = "";
10671:
10672: if (srchterm == "") {
10673: checkok = 0;
1.1075.2.98 raeburn 10674: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10675: }
10676:
1.569 raeburn 10677: if (srchtype== 'begins') {
10678: if (srchterm.length < 2) {
10679: checkok = 0;
1.1075.2.98 raeburn 10680: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10681: }
10682: }
10683:
1.556 raeburn 10684: if (srchtype== 'contains') {
10685: if (srchterm.length < 3) {
10686: checkok = 0;
1.1075.2.98 raeburn 10687: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10688: }
10689: }
10690: if (srchin == 'instd') {
10691: if (srchdomain == '') {
10692: checkok = 0;
1.1075.2.98 raeburn 10693: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10694: }
10695: }
10696: if (srchin == 'dom') {
10697: if (srchdomain == '') {
10698: checkok = 0;
1.1075.2.98 raeburn 10699: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10700: }
10701: }
10702: if (srchby == 'lastfirst') {
10703: if (srchterm.indexOf(",") == -1) {
10704: checkok = 0;
1.1075.2.98 raeburn 10705: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10706: }
10707: if (srchterm.indexOf(",") == srchterm.length -1) {
10708: checkok = 0;
1.1075.2.98 raeburn 10709: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10710: }
10711: }
10712: if (checkok == 0) {
1.1075.2.98 raeburn 10713: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10714: return;
10715: }
10716: if (checkok == 1) {
1.570 raeburn 10717: callingForm.submit();
1.556 raeburn 10718: }
10719: }
10720:
10721: $newuserscript
10722:
1.824 bisitz 10723: // ]]>
1.556 raeburn 10724: </script>
1.558 albertel 10725:
10726: $new_user_create
10727:
1.555 raeburn 10728: END_BLOCK
1.558 albertel 10729:
1.876 raeburn 10730: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10731: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10732: $domform.
10733: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10734: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10735: $srchbysel.
10736: $srchtypesel.
10737: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10738: $srchinsel.
10739: &Apache::lonhtmlcommon::row_closure(1).
10740: &Apache::lonhtmlcommon::end_pick_box().
10741: '<br />';
1.1075.2.114 raeburn 10742: return ($output,1);
1.555 raeburn 10743: }
10744:
1.612 raeburn 10745: sub user_rule_check {
1.615 raeburn 10746: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10747: my ($response,%inst_response);
1.612 raeburn 10748: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10749: if (keys(%{$usershash}) > 1) {
10750: my (%by_username,%by_id,%userdoms);
10751: my $checkid;
1.612 raeburn 10752: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10753: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10754: $checkid = 1;
10755: }
10756: }
10757: foreach my $user (keys(%{$usershash})) {
10758: my ($uname,$udom) = split(/:/,$user);
10759: if ($checkid) {
10760: if (ref($usershash->{$user}) eq 'HASH') {
10761: if ($usershash->{$user}->{'id'} ne '') {
10762: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10763: $userdoms{$udom} = 1;
10764: if (ref($inst_results) eq 'HASH') {
10765: $inst_results->{$uname.':'.$udom} = {};
10766: }
10767: }
10768: }
10769: } else {
10770: $by_username{$udom}{$uname} = 1;
10771: $userdoms{$udom} = 1;
10772: if (ref($inst_results) eq 'HASH') {
10773: $inst_results->{$uname.':'.$udom} = {};
10774: }
10775: }
10776: }
10777: foreach my $udom (keys(%userdoms)) {
10778: if (!$got_rules->{$udom}) {
10779: my %domconfig = &Apache::lonnet::get_dom('configuration',
10780: ['usercreation'],$udom);
10781: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10782: foreach my $item ('username','id') {
10783: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10784: $$curr_rules{$udom}{$item} =
10785: $domconfig{'usercreation'}{$item.'_rule'};
10786: }
10787: }
10788: }
10789: $got_rules->{$udom} = 1;
10790: }
10791: }
10792: if ($checkid) {
10793: foreach my $udom (keys(%by_id)) {
10794: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10795: if ($outcome eq 'ok') {
10796: foreach my $id (keys(%{$by_id{$udom}})) {
10797: my $uname = $by_id{$udom}{$id};
10798: $inst_response{$uname.':'.$udom} = $outcome;
10799: }
10800: if (ref($results) eq 'HASH') {
10801: foreach my $uname (keys(%{$results})) {
10802: if (exists($inst_response{$uname.':'.$udom})) {
10803: $inst_response{$uname.':'.$udom} = $outcome;
10804: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10805: }
10806: }
10807: }
10808: }
1.612 raeburn 10809: }
1.615 raeburn 10810: } else {
1.1075.2.99 raeburn 10811: foreach my $udom (keys(%by_username)) {
10812: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10813: if ($outcome eq 'ok') {
10814: foreach my $uname (keys(%{$by_username{$udom}})) {
10815: $inst_response{$uname.':'.$udom} = $outcome;
10816: }
10817: if (ref($results) eq 'HASH') {
10818: foreach my $uname (keys(%{$results})) {
10819: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10820: }
10821: }
10822: }
10823: }
1.612 raeburn 10824: }
1.1075.2.99 raeburn 10825: } elsif (keys(%{$usershash}) == 1) {
10826: my $user = (keys(%{$usershash}))[0];
10827: my ($uname,$udom) = split(/:/,$user);
10828: if (($udom ne '') && ($uname ne '')) {
10829: if (ref($usershash->{$user}) eq 'HASH') {
10830: if (ref($checks) eq 'HASH') {
10831: if (defined($checks->{'username'})) {
10832: ($inst_response{$user},%{$inst_results->{$user}}) =
10833: &Apache::lonnet::get_instuser($udom,$uname);
10834: } elsif (defined($checks->{'id'})) {
10835: if ($usershash->{$user}->{'id'} ne '') {
10836: ($inst_response{$user},%{$inst_results->{$user}}) =
10837: &Apache::lonnet::get_instuser($udom,undef,
10838: $usershash->{$user}->{'id'});
10839: } else {
10840: ($inst_response{$user},%{$inst_results->{$user}}) =
10841: &Apache::lonnet::get_instuser($udom,$uname);
10842: }
10843: }
10844: } else {
10845: ($inst_response{$user},%{$inst_results->{$user}}) =
10846: &Apache::lonnet::get_instuser($udom,$uname);
10847: return;
10848: }
10849: if (!$got_rules->{$udom}) {
10850: my %domconfig = &Apache::lonnet::get_dom('configuration',
10851: ['usercreation'],$udom);
10852: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10853: foreach my $item ('username','id') {
10854: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10855: $$curr_rules{$udom}{$item} =
10856: $domconfig{'usercreation'}{$item.'_rule'};
10857: }
10858: }
1.585 raeburn 10859: }
1.1075.2.99 raeburn 10860: $got_rules->{$udom} = 1;
1.585 raeburn 10861: }
10862: }
1.1075.2.99 raeburn 10863: } else {
10864: return;
10865: }
10866: } else {
10867: return;
10868: }
10869: foreach my $user (keys(%{$usershash})) {
10870: my ($uname,$udom) = split(/:/,$user);
10871: next if (($udom eq '') || ($uname eq ''));
10872: my $id;
10873: if (ref($inst_results) eq 'HASH') {
10874: if (ref($inst_results->{$user}) eq 'HASH') {
10875: $id = $inst_results->{$user}->{'id'};
10876: }
10877: }
10878: if ($id eq '') {
10879: if (ref($usershash->{$user})) {
10880: $id = $usershash->{$user}->{'id'};
10881: }
1.585 raeburn 10882: }
1.612 raeburn 10883: foreach my $item (keys(%{$checks})) {
10884: if (ref($$curr_rules{$udom}) eq 'HASH') {
10885: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10886: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10887: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10888: $$curr_rules{$udom}{$item});
1.612 raeburn 10889: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10890: if ($rule_check{$rule}) {
10891: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10892: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10893: if (ref($inst_results) eq 'HASH') {
10894: if (ref($inst_results->{$user}) eq 'HASH') {
10895: if (keys(%{$inst_results->{$user}}) == 0) {
10896: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10897: } elsif ($item eq 'id') {
10898: if ($inst_results->{$user}->{'id'} eq '') {
10899: $$alerts{$item}{$udom}{$uname} = 1;
10900: }
1.615 raeburn 10901: }
1.612 raeburn 10902: }
10903: }
1.615 raeburn 10904: }
10905: last;
1.585 raeburn 10906: }
10907: }
10908: }
10909: }
10910: }
10911: }
10912: }
10913: }
1.612 raeburn 10914: return;
10915: }
10916:
10917: sub user_rule_formats {
10918: my ($domain,$domdesc,$curr_rules,$check) = @_;
10919: my %text = (
10920: 'username' => 'Usernames',
10921: 'id' => 'IDs',
10922: );
10923: my $output;
10924: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10925: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10926: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10927: $output = '<br />'.
10928: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10929: '<span class="LC_cusr_emph">','</span>',$domdesc).
10930: ' <ul>';
1.612 raeburn 10931: foreach my $rule (@{$ruleorder}) {
10932: if (ref($curr_rules) eq 'ARRAY') {
10933: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10934: if (ref($rules->{$rule}) eq 'HASH') {
10935: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10936: $rules->{$rule}{'desc'}.'</li>';
10937: }
10938: }
10939: }
10940: }
10941: $output .= '</ul>';
10942: }
10943: }
10944: return $output;
10945: }
10946:
10947: sub instrule_disallow_msg {
1.615 raeburn 10948: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10949: my $response;
10950: my %text = (
10951: item => 'username',
10952: items => 'usernames',
10953: match => 'matches',
10954: do => 'does',
10955: action => 'a username',
10956: one => 'one',
10957: );
10958: if ($count > 1) {
10959: $text{'item'} = 'usernames';
10960: $text{'match'} ='match';
10961: $text{'do'} = 'do';
10962: $text{'action'} = 'usernames',
10963: $text{'one'} = 'ones';
10964: }
10965: if ($checkitem eq 'id') {
10966: $text{'items'} = 'IDs';
10967: $text{'item'} = 'ID';
10968: $text{'action'} = 'an ID';
1.615 raeburn 10969: if ($count > 1) {
10970: $text{'item'} = 'IDs';
10971: $text{'action'} = 'IDs';
10972: }
1.612 raeburn 10973: }
1.674 bisitz 10974: $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 10975: if ($mode eq 'upload') {
10976: if ($checkitem eq 'username') {
10977: $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'}.");
10978: } elsif ($checkitem eq 'id') {
1.674 bisitz 10979: $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 10980: }
1.669 raeburn 10981: } elsif ($mode eq 'selfcreate') {
10982: if ($checkitem eq 'id') {
10983: $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.");
10984: }
1.615 raeburn 10985: } else {
10986: if ($checkitem eq 'username') {
10987: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10988: } elsif ($checkitem eq 'id') {
10989: $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.");
10990: }
1.612 raeburn 10991: }
10992: return $response;
1.585 raeburn 10993: }
10994:
1.624 raeburn 10995: sub personal_data_fieldtitles {
10996: my %fieldtitles = &Apache::lonlocal::texthash (
10997: id => 'Student/Employee ID',
10998: permanentemail => 'E-mail address',
10999: lastname => 'Last Name',
11000: firstname => 'First Name',
11001: middlename => 'Middle Name',
11002: generation => 'Generation',
11003: gen => 'Generation',
1.765 raeburn 11004: inststatus => 'Affiliation',
1.624 raeburn 11005: );
11006: return %fieldtitles;
11007: }
11008:
1.642 raeburn 11009: sub sorted_inst_types {
11010: my ($dom) = @_;
1.1075.2.70 raeburn 11011: my ($usertypes,$order);
11012: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11013: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11014: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11015: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11016: } else {
11017: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11018: }
1.642 raeburn 11019: my $othertitle = &mt('All users');
11020: if ($env{'request.course.id'}) {
1.668 raeburn 11021: $othertitle = &mt('Any users');
1.642 raeburn 11022: }
11023: my @types;
11024: if (ref($order) eq 'ARRAY') {
11025: @types = @{$order};
11026: }
11027: if (@types == 0) {
11028: if (ref($usertypes) eq 'HASH') {
11029: @types = sort(keys(%{$usertypes}));
11030: }
11031: }
11032: if (keys(%{$usertypes}) > 0) {
11033: $othertitle = &mt('Other users');
11034: }
11035: return ($othertitle,$usertypes,\@types);
11036: }
11037:
1.645 raeburn 11038: sub get_institutional_codes {
1.1075.2.157 raeburn 11039: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11040: # Get complete list of course sections to update
11041: my @currsections = ();
11042: my @currxlists = ();
1.1075.2.157 raeburn 11043: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11044: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11045: my $crskey = $crs.':'.$coursecode;
11046: @{$unclutteredsec{$crskey}} = ();
11047: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11048:
11049: if ($$settings{'internal.sectionnums'} ne '') {
11050: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11051: }
11052:
11053: if ($$settings{'internal.crosslistings'} ne '') {
11054: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11055: }
11056:
11057: if (@currxlists > 0) {
1.1075.2.157 raeburn 11058: foreach my $xl (@currxlists) {
11059: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11060: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11061: push(@{$allcourses},$1);
1.645 raeburn 11062: $$LC_code{$1} = $2;
11063: }
11064: }
11065: }
11066: }
1.1075.2.157 raeburn 11067:
1.645 raeburn 11068: if (@currsections > 0) {
1.1075.2.157 raeburn 11069: foreach my $sec (@currsections) {
11070: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11071: my $instsec = $1;
1.645 raeburn 11072: my $lc_sec = $2;
1.1075.2.157 raeburn 11073: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11074: push(@{$unclutteredsec{$crskey}},$instsec);
11075: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11076: }
11077: }
11078: }
11079: }
11080:
11081: if (@{$unclutteredsec{$crskey}} > 0) {
11082: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11083: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11084: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11085: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11086: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11087: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11088: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11089: }
11090: }
11091: }
11092: }
11093: return;
11094: }
11095:
1.971 raeburn 11096: sub get_standard_codeitems {
11097: return ('Year','Semester','Department','Number','Section');
11098: }
11099:
1.112 bowersj2 11100: =pod
11101:
1.780 raeburn 11102: =head1 Slot Helpers
11103:
11104: =over 4
11105:
11106: =item * sorted_slots()
11107:
1.1040 raeburn 11108: Sorts an array of slot names in order of an optional sort key,
11109: default sort is by slot start time (earliest first).
1.780 raeburn 11110:
11111: Inputs:
11112:
11113: =over 4
11114:
11115: slotsarr - Reference to array of unsorted slot names.
11116:
11117: slots - Reference to hash of hash, where outer hash keys are slot names.
11118:
1.1040 raeburn 11119: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11120:
1.549 albertel 11121: =back
11122:
1.780 raeburn 11123: Returns:
11124:
11125: =over 4
11126:
1.1040 raeburn 11127: sorted - An array of slot names sorted by a specified sort key
11128: (default sort key is start time of the slot).
1.780 raeburn 11129:
11130: =back
11131:
11132: =cut
11133:
11134:
11135: sub sorted_slots {
1.1040 raeburn 11136: my ($slotsarr,$slots,$sortkey) = @_;
11137: if ($sortkey eq '') {
11138: $sortkey = 'starttime';
11139: }
1.780 raeburn 11140: my @sorted;
11141: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11142: @sorted =
11143: sort {
11144: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11145: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11146: }
11147: if (ref($slots->{$a})) { return -1;}
11148: if (ref($slots->{$b})) { return 1;}
11149: return 0;
11150: } @{$slotsarr};
11151: }
11152: return @sorted;
11153: }
11154:
1.1040 raeburn 11155: =pod
11156:
11157: =item * get_future_slots()
11158:
11159: Inputs:
11160:
11161: =over 4
11162:
11163: cnum - course number
11164:
11165: cdom - course domain
11166:
11167: now - current UNIX time
11168:
11169: symb - optional symb
11170:
11171: =back
11172:
11173: Returns:
11174:
11175: =over 4
11176:
11177: sorted_reservable - ref to array of student_schedulable slots currently
11178: reservable, ordered by end date of reservation period.
11179:
11180: reservable_now - ref to hash of student_schedulable slots currently
11181: reservable.
11182:
11183: Keys in inner hash are:
11184: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11185: (b) endreserve: end date of reservation period.
11186: (c) uniqueperiod: start,end dates when slot is to be uniquely
11187: selected.
1.1040 raeburn 11188:
11189: sorted_future - ref to array of student_schedulable slots reservable in
11190: the future, ordered by start date of reservation period.
11191:
11192: future_reservable - ref to hash of student_schedulable slots reservable
11193: in the future.
11194:
11195: Keys in inner hash are:
11196: (a) symb: either blank or symb to which slot use is restricted.
11197: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11198: (c) uniqueperiod: start,end dates when slot is to be uniquely
11199: selected.
1.1040 raeburn 11200:
11201: =back
11202:
11203: =cut
11204:
11205: sub get_future_slots {
11206: my ($cnum,$cdom,$now,$symb) = @_;
11207: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11208: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11209: foreach my $slot (keys(%slots)) {
11210: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11211: if ($symb) {
11212: next if (($slots{$slot}->{'symb'} ne '') &&
11213: ($slots{$slot}->{'symb'} ne $symb));
11214: }
11215: if (($slots{$slot}->{'starttime'} > $now) &&
11216: ($slots{$slot}->{'endtime'} > $now)) {
11217: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11218: my $userallowed = 0;
11219: if ($slots{$slot}->{'allowedsections'}) {
11220: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11221: if (!defined($env{'request.role.sec'})
11222: && grep(/^No section assigned$/,@allowed_sec)) {
11223: $userallowed=1;
11224: } else {
11225: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11226: $userallowed=1;
11227: }
11228: }
11229: unless ($userallowed) {
11230: if (defined($env{'request.course.groups'})) {
11231: my @groups = split(/:/,$env{'request.course.groups'});
11232: foreach my $group (@groups) {
11233: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11234: $userallowed=1;
11235: last;
11236: }
11237: }
11238: }
11239: }
11240: }
11241: if ($slots{$slot}->{'allowedusers'}) {
11242: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11243: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11244: if (grep(/^\Q$user\E$/,@allowed_users)) {
11245: $userallowed = 1;
11246: }
11247: }
11248: next unless($userallowed);
11249: }
11250: my $startreserve = $slots{$slot}->{'startreserve'};
11251: my $endreserve = $slots{$slot}->{'endreserve'};
11252: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11253: my $uniqueperiod;
11254: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11255: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11256: }
1.1040 raeburn 11257: if (($startreserve < $now) &&
11258: (!$endreserve || $endreserve > $now)) {
11259: my $lastres = $endreserve;
11260: if (!$lastres) {
11261: $lastres = $slots{$slot}->{'starttime'};
11262: }
11263: $reservable_now{$slot} = {
11264: symb => $symb,
1.1075.2.104 raeburn 11265: endreserve => $lastres,
11266: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11267: };
11268: } elsif (($startreserve > $now) &&
11269: (!$endreserve || $endreserve > $startreserve)) {
11270: $future_reservable{$slot} = {
11271: symb => $symb,
1.1075.2.104 raeburn 11272: startreserve => $startreserve,
11273: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11274: };
11275: }
11276: }
11277: }
11278: my @unsorted_reservable = keys(%reservable_now);
11279: if (@unsorted_reservable > 0) {
11280: @sorted_reservable =
11281: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11282: }
11283: my @unsorted_future = keys(%future_reservable);
11284: if (@unsorted_future > 0) {
11285: @sorted_future =
11286: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11287: }
11288: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11289: }
1.780 raeburn 11290:
11291: =pod
11292:
1.1057 foxr 11293: =back
11294:
1.549 albertel 11295: =head1 HTTP Helpers
11296:
11297: =over 4
11298:
1.648 raeburn 11299: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11300:
1.258 albertel 11301: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11302: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11303: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11304:
11305: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11306: $possible_names is an ref to an array of form element names. As an example:
11307: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11308: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11309:
11310: =cut
1.1 albertel 11311:
1.6 albertel 11312: sub get_unprocessed_cgi {
1.25 albertel 11313: my ($query,$possible_names)= @_;
1.26 matthew 11314: # $Apache::lonxml::debug=1;
1.356 albertel 11315: foreach my $pair (split(/&/,$query)) {
11316: my ($name, $value) = split(/=/,$pair);
1.369 www 11317: $name = &unescape($name);
1.25 albertel 11318: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11319: $value =~ tr/+/ /;
11320: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11321: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11322: }
1.16 harris41 11323: }
1.6 albertel 11324: }
11325:
1.112 bowersj2 11326: =pod
11327:
1.648 raeburn 11328: =item * &cacheheader()
1.112 bowersj2 11329:
11330: returns cache-controlling header code
11331:
11332: =cut
11333:
1.7 albertel 11334: sub cacheheader {
1.258 albertel 11335: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11336: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11337: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11338: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11339: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11340: return $output;
1.7 albertel 11341: }
11342:
1.112 bowersj2 11343: =pod
11344:
1.648 raeburn 11345: =item * &no_cache($r)
1.112 bowersj2 11346:
11347: specifies header code to not have cache
11348:
11349: =cut
11350:
1.9 albertel 11351: sub no_cache {
1.216 albertel 11352: my ($r) = @_;
11353: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11354: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11355: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11356: $r->no_cache(1);
11357: $r->header_out("Expires" => $date);
11358: $r->header_out("Pragma" => "no-cache");
1.123 www 11359: }
11360:
11361: sub content_type {
1.181 albertel 11362: my ($r,$type,$charset) = @_;
1.299 foxr 11363: if ($r) {
11364: # Note that printout.pl calls this with undef for $r.
11365: &no_cache($r);
11366: }
1.258 albertel 11367: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11368: unless ($charset) {
11369: $charset=&Apache::lonlocal::current_encoding;
11370: }
11371: if ($charset) { $type.='; charset='.$charset; }
11372: if ($r) {
11373: $r->content_type($type);
11374: } else {
11375: print("Content-type: $type\n\n");
11376: }
1.9 albertel 11377: }
1.25 albertel 11378:
1.112 bowersj2 11379: =pod
11380:
1.648 raeburn 11381: =item * &add_to_env($name,$value)
1.112 bowersj2 11382:
1.258 albertel 11383: adds $name to the %env hash with value
1.112 bowersj2 11384: $value, if $name already exists, the entry is converted to an array
11385: reference and $value is added to the array.
11386:
11387: =cut
11388:
1.25 albertel 11389: sub add_to_env {
11390: my ($name,$value)=@_;
1.258 albertel 11391: if (defined($env{$name})) {
11392: if (ref($env{$name})) {
1.25 albertel 11393: #already have multiple values
1.258 albertel 11394: push(@{ $env{$name} },$value);
1.25 albertel 11395: } else {
11396: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11397: my $first=$env{$name};
11398: undef($env{$name});
11399: push(@{ $env{$name} },$first,$value);
1.25 albertel 11400: }
11401: } else {
1.258 albertel 11402: $env{$name}=$value;
1.25 albertel 11403: }
1.31 albertel 11404: }
1.149 albertel 11405:
11406: =pod
11407:
1.648 raeburn 11408: =item * &get_env_multiple($name)
1.149 albertel 11409:
1.258 albertel 11410: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11411: values may be defined and end up as an array ref.
11412:
11413: returns an array of values
11414:
11415: =cut
11416:
11417: sub get_env_multiple {
11418: my ($name) = @_;
11419: my @values;
1.258 albertel 11420: if (defined($env{$name})) {
1.149 albertel 11421: # exists is it an array
1.258 albertel 11422: if (ref($env{$name})) {
11423: @values=@{ $env{$name} };
1.149 albertel 11424: } else {
1.258 albertel 11425: $values[0]=$env{$name};
1.149 albertel 11426: }
11427: }
11428: return(@values);
11429: }
11430:
1.660 raeburn 11431: sub ask_for_embedded_content {
11432: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11433: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11434: %currsubfile,%unused,$rem);
1.1071 raeburn 11435: my $counter = 0;
11436: my $numnew = 0;
1.987 raeburn 11437: my $numremref = 0;
11438: my $numinvalid = 0;
11439: my $numpathchg = 0;
11440: my $numexisting = 0;
1.1071 raeburn 11441: my $numunused = 0;
11442: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 11443: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11444: my $heading = &mt('Upload embedded files');
11445: my $buttontext = &mt('Upload');
11446:
1.1075.2.11 raeburn 11447: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 11448: if ($actionurl eq '/adm/dependencies') {
11449: $navmap = Apache::lonnavmaps::navmap->new();
11450: }
11451: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11452: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 11453: }
1.1075.2.35 raeburn 11454: if (($actionurl eq '/adm/portfolio') ||
11455: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11456: my $current_path='/';
11457: if ($env{'form.currentpath'}) {
11458: $current_path = $env{'form.currentpath'};
11459: }
11460: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11461: $udom = $cdom;
11462: $uname = $cnum;
1.984 raeburn 11463: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11464: } else {
11465: $udom = $env{'user.domain'};
11466: $uname = $env{'user.name'};
11467: $url = '/userfiles/portfolio';
11468: }
1.987 raeburn 11469: $toplevel = $url.'/';
1.984 raeburn 11470: $url .= $current_path;
11471: $getpropath = 1;
1.987 raeburn 11472: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11473: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11474: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11475: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11476: $toplevel = $url;
1.984 raeburn 11477: if ($rest ne '') {
1.987 raeburn 11478: $url .= $rest;
11479: }
11480: } elsif ($actionurl eq '/adm/coursedocs') {
11481: if (ref($args) eq 'HASH') {
1.1071 raeburn 11482: $url = $args->{'docs_url'};
11483: $toplevel = $url;
1.1075.2.11 raeburn 11484: if ($args->{'context'} eq 'paste') {
11485: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11486: ($path) =
11487: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11488: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11489: $fileloc =~ s{^/}{};
11490: }
1.1071 raeburn 11491: }
11492: } elsif ($actionurl eq '/adm/dependencies') {
11493: if ($env{'request.course.id'} ne '') {
11494: if (ref($args) eq 'HASH') {
11495: $url = $args->{'docs_url'};
11496: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11497: $toplevel = $url;
11498: unless ($toplevel =~ m{^/}) {
11499: $toplevel = "/$url";
11500: }
1.1075.2.11 raeburn 11501: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11502: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11503: $path = $1;
11504: } else {
11505: ($path) =
11506: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11507: }
1.1075.2.79 raeburn 11508: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11509: $fileloc = $toplevel;
11510: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11511: my ($udom,$uname,$fname) =
11512: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11513: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11514: } else {
11515: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11516: }
1.1071 raeburn 11517: $fileloc =~ s{^/}{};
11518: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11519: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11520: }
1.987 raeburn 11521: }
1.1075.2.35 raeburn 11522: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11523: $udom = $cdom;
11524: $uname = $cnum;
11525: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11526: $toplevel = $url;
11527: $path = $url;
11528: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11529: $fileloc =~ s{^/}{};
11530: }
11531: foreach my $file (keys(%{$allfiles})) {
11532: my $embed_file;
11533: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11534: $embed_file = $1;
11535: } else {
11536: $embed_file = $file;
11537: }
1.1075.2.55 raeburn 11538: my ($absolutepath,$cleaned_file);
11539: if ($embed_file =~ m{^\w+://}) {
11540: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11541: $newfiles{$cleaned_file} = 1;
11542: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11543: } else {
1.1075.2.55 raeburn 11544: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11545: if ($embed_file =~ m{^/}) {
11546: $absolutepath = $embed_file;
11547: }
1.1075.2.47 raeburn 11548: if ($cleaned_file =~ m{/}) {
11549: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11550: $path = &check_for_traversal($path,$url,$toplevel);
11551: my $item = $fname;
11552: if ($path ne '') {
11553: $item = $path.'/'.$fname;
11554: $subdependencies{$path}{$fname} = 1;
11555: } else {
11556: $dependencies{$item} = 1;
11557: }
11558: if ($absolutepath) {
11559: $mapping{$item} = $absolutepath;
11560: } else {
11561: $mapping{$item} = $embed_file;
11562: }
11563: } else {
11564: $dependencies{$embed_file} = 1;
11565: if ($absolutepath) {
1.1075.2.47 raeburn 11566: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11567: } else {
1.1075.2.47 raeburn 11568: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11569: }
11570: }
1.984 raeburn 11571: }
11572: }
1.1071 raeburn 11573: my $dirptr = 16384;
1.984 raeburn 11574: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11575: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11576: if (($actionurl eq '/adm/portfolio') ||
11577: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11578: my ($sublistref,$listerror) =
11579: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11580: if (ref($sublistref) eq 'ARRAY') {
11581: foreach my $line (@{$sublistref}) {
11582: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11583: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11584: }
1.984 raeburn 11585: }
1.987 raeburn 11586: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11587: if (opendir(my $dir,$url.'/'.$path)) {
11588: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11589: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11590: }
1.1075.2.11 raeburn 11591: } elsif (($actionurl eq '/adm/dependencies') ||
11592: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11593: ($args->{'context'} eq 'paste')) ||
11594: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11595: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11596: my $dir;
11597: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11598: $dir = $fileloc;
11599: } else {
11600: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11601: }
1.1071 raeburn 11602: if ($dir ne '') {
11603: my ($sublistref,$listerror) =
11604: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11605: if (ref($sublistref) eq 'ARRAY') {
11606: foreach my $line (@{$sublistref}) {
11607: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11608: undef,$mtime)=split(/\&/,$line,12);
11609: unless (($testdir&$dirptr) ||
11610: ($file_name =~ /^\.\.?$/)) {
11611: $currsubfile{$path}{$file_name} = [$size,$mtime];
11612: }
11613: }
11614: }
11615: }
1.984 raeburn 11616: }
11617: }
11618: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11619: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11620: my $item = $path.'/'.$file;
11621: unless ($mapping{$item} eq $item) {
11622: $pathchanges{$item} = 1;
11623: }
11624: $existing{$item} = 1;
11625: $numexisting ++;
11626: } else {
11627: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11628: }
11629: }
1.1071 raeburn 11630: if ($actionurl eq '/adm/dependencies') {
11631: foreach my $path (keys(%currsubfile)) {
11632: if (ref($currsubfile{$path}) eq 'HASH') {
11633: foreach my $file (keys(%{$currsubfile{$path}})) {
11634: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11635: next if (($rem ne '') &&
11636: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11637: (ref($navmap) &&
11638: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11639: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11640: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11641: $unused{$path.'/'.$file} = 1;
11642: }
11643: }
11644: }
11645: }
11646: }
1.984 raeburn 11647: }
1.987 raeburn 11648: my %currfile;
1.1075.2.35 raeburn 11649: if (($actionurl eq '/adm/portfolio') ||
11650: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11651: my ($dirlistref,$listerror) =
11652: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11653: if (ref($dirlistref) eq 'ARRAY') {
11654: foreach my $line (@{$dirlistref}) {
11655: my ($file_name,$rest) = split(/\&/,$line,2);
11656: $currfile{$file_name} = 1;
11657: }
1.984 raeburn 11658: }
1.987 raeburn 11659: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11660: if (opendir(my $dir,$url)) {
1.987 raeburn 11661: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11662: map {$currfile{$_} = 1;} @dir_list;
11663: }
1.1075.2.11 raeburn 11664: } elsif (($actionurl eq '/adm/dependencies') ||
11665: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11666: ($args->{'context'} eq 'paste')) ||
11667: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11668: if ($env{'request.course.id'} ne '') {
11669: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11670: if ($dir ne '') {
11671: my ($dirlistref,$listerror) =
11672: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11673: if (ref($dirlistref) eq 'ARRAY') {
11674: foreach my $line (@{$dirlistref}) {
11675: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11676: $size,undef,$mtime)=split(/\&/,$line,12);
11677: unless (($testdir&$dirptr) ||
11678: ($file_name =~ /^\.\.?$/)) {
11679: $currfile{$file_name} = [$size,$mtime];
11680: }
11681: }
11682: }
11683: }
11684: }
1.984 raeburn 11685: }
11686: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11687: if (exists($currfile{$file})) {
1.987 raeburn 11688: unless ($mapping{$file} eq $file) {
11689: $pathchanges{$file} = 1;
11690: }
11691: $existing{$file} = 1;
11692: $numexisting ++;
11693: } else {
1.984 raeburn 11694: $newfiles{$file} = 1;
11695: }
11696: }
1.1071 raeburn 11697: foreach my $file (keys(%currfile)) {
11698: unless (($file eq $filename) ||
11699: ($file eq $filename.'.bak') ||
11700: ($dependencies{$file})) {
1.1075.2.11 raeburn 11701: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11702: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11703: next if (($rem ne '') &&
11704: (($env{"httpref.$rem".$file} ne '') ||
11705: (ref($navmap) &&
11706: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11707: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11708: ($navmap->getResourceByUrl($rem.$1)))))));
11709: }
1.1075.2.11 raeburn 11710: }
1.1071 raeburn 11711: $unused{$file} = 1;
11712: }
11713: }
1.1075.2.11 raeburn 11714: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11715: ($args->{'context'} eq 'paste')) {
11716: $counter = scalar(keys(%existing));
11717: $numpathchg = scalar(keys(%pathchanges));
11718: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11719: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11720: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11721: $counter = scalar(keys(%existing));
11722: $numpathchg = scalar(keys(%pathchanges));
11723: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11724: }
1.984 raeburn 11725: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11726: if ($actionurl eq '/adm/dependencies') {
11727: next if ($embed_file =~ m{^\w+://});
11728: }
1.660 raeburn 11729: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11730: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11731: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11732: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11733: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11734: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11735: }
1.1075.2.35 raeburn 11736: $upload_output .= '</td>';
1.1071 raeburn 11737: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11738: $upload_output.='<td align="right">'.
11739: '<span class="LC_info LC_fontsize_medium">'.
11740: &mt("URL points to web address").'</span>';
1.987 raeburn 11741: $numremref++;
1.660 raeburn 11742: } elsif ($args->{'error_on_invalid_names'}
11743: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11744: $upload_output.='<td align="right"><span class="LC_warning">'.
11745: &mt('Invalid characters').'</span>';
1.987 raeburn 11746: $numinvalid++;
1.660 raeburn 11747: } else {
1.1075.2.35 raeburn 11748: $upload_output .= '<td>'.
11749: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11750: $embed_file,\%mapping,
1.1071 raeburn 11751: $allfiles,$codebase,'upload');
11752: $counter ++;
11753: $numnew ++;
1.987 raeburn 11754: }
11755: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11756: }
11757: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11758: if ($actionurl eq '/adm/dependencies') {
11759: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11760: $modify_output .= &start_data_table_row().
11761: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11762: '<img src="'.&icon($embed_file).'" border="0" />'.
11763: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11764: '<td>'.$size.'</td>'.
11765: '<td>'.$mtime.'</td>'.
11766: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11767: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11768: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11769: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11770: &embedded_file_element('upload_embedded',$counter,
11771: $embed_file,\%mapping,
11772: $allfiles,$codebase,'modify').
11773: '</div></td>'.
11774: &end_data_table_row()."\n";
11775: $counter ++;
11776: } else {
11777: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11778: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11779: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11780: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11781: &Apache::loncommon::end_data_table_row()."\n";
11782: }
11783: }
11784: my $delidx = $counter;
11785: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11786: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11787: $delete_output .= &start_data_table_row().
11788: '<td><img src="'.&icon($oldfile).'" />'.
11789: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11790: '<td>'.$size.'</td>'.
11791: '<td>'.$mtime.'</td>'.
11792: '<td><label><input type="checkbox" name="del_upload_dep" '.
11793: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11794: &embedded_file_element('upload_embedded',$delidx,
11795: $oldfile,\%mapping,$allfiles,
11796: $codebase,'delete').'</td>'.
11797: &end_data_table_row()."\n";
11798: $numunused ++;
11799: $delidx ++;
1.987 raeburn 11800: }
11801: if ($upload_output) {
11802: $upload_output = &start_data_table().
11803: $upload_output.
11804: &end_data_table()."\n";
11805: }
1.1071 raeburn 11806: if ($modify_output) {
11807: $modify_output = &start_data_table().
11808: &start_data_table_header_row().
11809: '<th>'.&mt('File').'</th>'.
11810: '<th>'.&mt('Size (KB)').'</th>'.
11811: '<th>'.&mt('Modified').'</th>'.
11812: '<th>'.&mt('Upload replacement?').'</th>'.
11813: &end_data_table_header_row().
11814: $modify_output.
11815: &end_data_table()."\n";
11816: }
11817: if ($delete_output) {
11818: $delete_output = &start_data_table().
11819: &start_data_table_header_row().
11820: '<th>'.&mt('File').'</th>'.
11821: '<th>'.&mt('Size (KB)').'</th>'.
11822: '<th>'.&mt('Modified').'</th>'.
11823: '<th>'.&mt('Delete?').'</th>'.
11824: &end_data_table_header_row().
11825: $delete_output.
11826: &end_data_table()."\n";
11827: }
1.987 raeburn 11828: my $applies = 0;
11829: if ($numremref) {
11830: $applies ++;
11831: }
11832: if ($numinvalid) {
11833: $applies ++;
11834: }
11835: if ($numexisting) {
11836: $applies ++;
11837: }
1.1071 raeburn 11838: if ($counter || $numunused) {
1.987 raeburn 11839: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11840: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11841: $state.'<h3>'.$heading.'</h3>';
11842: if ($actionurl eq '/adm/dependencies') {
11843: if ($numnew) {
11844: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11845: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11846: $upload_output.'<br />'."\n";
11847: }
11848: if ($numexisting) {
11849: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11850: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11851: $modify_output.'<br />'."\n";
11852: $buttontext = &mt('Save changes');
11853: }
11854: if ($numunused) {
11855: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11856: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11857: $delete_output.'<br />'."\n";
11858: $buttontext = &mt('Save changes');
11859: }
11860: } else {
11861: $output .= $upload_output.'<br />'."\n";
11862: }
11863: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11864: $counter.'" />'."\n";
11865: if ($actionurl eq '/adm/dependencies') {
11866: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11867: $numnew.'" />'."\n";
11868: } elsif ($actionurl eq '') {
1.987 raeburn 11869: $output .= '<input type="hidden" name="phase" value="three" />';
11870: }
11871: } elsif ($applies) {
11872: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11873: if ($applies > 1) {
11874: $output .=
1.1075.2.35 raeburn 11875: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11876: if ($numremref) {
11877: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11878: }
11879: if ($numinvalid) {
11880: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11881: }
11882: if ($numexisting) {
11883: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11884: }
11885: $output .= '</ul><br />';
11886: } elsif ($numremref) {
11887: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11888: } elsif ($numinvalid) {
11889: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11890: } elsif ($numexisting) {
11891: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11892: }
11893: $output .= $upload_output.'<br />';
11894: }
11895: my ($pathchange_output,$chgcount);
1.1071 raeburn 11896: $chgcount = $counter;
1.987 raeburn 11897: if (keys(%pathchanges) > 0) {
11898: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11899: if ($counter) {
1.987 raeburn 11900: $output .= &embedded_file_element('pathchange',$chgcount,
11901: $embed_file,\%mapping,
1.1071 raeburn 11902: $allfiles,$codebase,'change');
1.987 raeburn 11903: } else {
11904: $pathchange_output .=
11905: &start_data_table_row().
11906: '<td><input type ="checkbox" name="namechange" value="'.
11907: $chgcount.'" checked="checked" /></td>'.
11908: '<td>'.$mapping{$embed_file}.'</td>'.
11909: '<td>'.$embed_file.
11910: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11911: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11912: '</td>'.&end_data_table_row();
1.660 raeburn 11913: }
1.987 raeburn 11914: $numpathchg ++;
11915: $chgcount ++;
1.660 raeburn 11916: }
11917: }
1.1075.2.35 raeburn 11918: if (($counter) || ($numunused)) {
1.987 raeburn 11919: if ($numpathchg) {
11920: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11921: $numpathchg.'" />'."\n";
11922: }
11923: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11924: ($actionurl eq '/adm/imsimport')) {
11925: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11926: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11927: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11928: } elsif ($actionurl eq '/adm/dependencies') {
11929: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11930: }
1.1075.2.35 raeburn 11931: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11932: } elsif ($numpathchg) {
11933: my %pathchange = ();
11934: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11935: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11936: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11937: }
1.987 raeburn 11938: }
1.1071 raeburn 11939: return ($output,$counter,$numpathchg);
1.987 raeburn 11940: }
11941:
1.1075.2.47 raeburn 11942: =pod
11943:
11944: =item * clean_path($name)
11945:
11946: Performs clean-up of directories, subdirectories and filename in an
11947: embedded object, referenced in an HTML file which is being uploaded
11948: to a course or portfolio, where
11949: "Upload embedded images/multimedia files if HTML file" checkbox was
11950: checked.
11951:
11952: Clean-up is similar to replacements in lonnet::clean_filename()
11953: except each / between sub-directory and next level is preserved.
11954:
11955: =cut
11956:
11957: sub clean_path {
11958: my ($embed_file) = @_;
11959: $embed_file =~s{^/+}{};
11960: my @contents;
11961: if ($embed_file =~ m{/}) {
11962: @contents = split(/\//,$embed_file);
11963: } else {
11964: @contents = ($embed_file);
11965: }
11966: my $lastidx = scalar(@contents)-1;
11967: for (my $i=0; $i<=$lastidx; $i++) {
11968: $contents[$i]=~s{\\}{/}g;
11969: $contents[$i]=~s/\s+/\_/g;
11970: $contents[$i]=~s{[^/\w\.\-]}{}g;
11971: if ($i == $lastidx) {
11972: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11973: }
11974: }
11975: if ($lastidx > 0) {
11976: return join('/',@contents);
11977: } else {
11978: return $contents[0];
11979: }
11980: }
11981:
1.987 raeburn 11982: sub embedded_file_element {
1.1071 raeburn 11983: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11984: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11985: (ref($codebase) eq 'HASH'));
11986: my $output;
1.1071 raeburn 11987: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11988: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11989: }
11990: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11991: &escape($embed_file).'" />';
11992: unless (($context eq 'upload_embedded') &&
11993: ($mapping->{$embed_file} eq $embed_file)) {
11994: $output .='
11995: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11996: }
11997: my $attrib;
11998: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11999: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12000: }
12001: $output .=
12002: "\n\t\t".
12003: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12004: $attrib.'" />';
12005: if (exists($codebase->{$mapping->{$embed_file}})) {
12006: $output .=
12007: "\n\t\t".
12008: '<input name="codebase_'.$num.'" type="hidden" value="'.
12009: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12010: }
1.987 raeburn 12011: return $output;
1.660 raeburn 12012: }
12013:
1.1071 raeburn 12014: sub get_dependency_details {
12015: my ($currfile,$currsubfile,$embed_file) = @_;
12016: my ($size,$mtime,$showsize,$showmtime);
12017: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12018: if ($embed_file =~ m{/}) {
12019: my ($path,$fname) = split(/\//,$embed_file);
12020: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12021: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12022: }
12023: } else {
12024: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12025: ($size,$mtime) = @{$currfile->{$embed_file}};
12026: }
12027: }
12028: $showsize = $size/1024.0;
12029: $showsize = sprintf("%.1f",$showsize);
12030: if ($mtime > 0) {
12031: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12032: }
12033: }
12034: return ($showsize,$showmtime);
12035: }
12036:
12037: sub ask_embedded_js {
12038: return <<"END";
12039: <script type="text/javascript"">
12040: // <![CDATA[
12041: function toggleBrowse(counter) {
12042: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12043: var fileid = document.getElementById('embedded_item_'+counter);
12044: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12045: if (chkboxid.checked == true) {
12046: uploaddivid.style.display='block';
12047: } else {
12048: uploaddivid.style.display='none';
12049: fileid.value = '';
12050: }
12051: }
12052: // ]]>
12053: </script>
12054:
12055: END
12056: }
12057:
1.661 raeburn 12058: sub upload_embedded {
12059: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12060: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12061: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12062: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12063: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12064: my $orig_uploaded_filename =
12065: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12066: foreach my $type ('orig','ref','attrib','codebase') {
12067: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12068: $env{'form.embedded_'.$type.'_'.$i} =
12069: &unescape($env{'form.embedded_'.$type.'_'.$i});
12070: }
12071: }
1.661 raeburn 12072: my ($path,$fname) =
12073: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12074: # no path, whole string is fname
12075: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12076: $fname = &Apache::lonnet::clean_filename($fname);
12077: # See if there is anything left
12078: next if ($fname eq '');
12079:
12080: # Check if file already exists as a file or directory.
12081: my ($state,$msg);
12082: if ($context eq 'portfolio') {
12083: my $port_path = $dirpath;
12084: if ($group ne '') {
12085: $port_path = "groups/$group/$port_path";
12086: }
1.987 raeburn 12087: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12088: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12089: $dir_root,$port_path,$disk_quota,
12090: $current_disk_usage,$uname,$udom);
12091: if ($state eq 'will_exceed_quota'
1.984 raeburn 12092: || $state eq 'file_locked') {
1.661 raeburn 12093: $output .= $msg;
12094: next;
12095: }
12096: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12097: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12098: if ($state eq 'exists') {
12099: $output .= $msg;
12100: next;
12101: }
12102: }
12103: # Check if extension is valid
12104: if (($fname =~ /\.(\w+)$/) &&
12105: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12106: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12107: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12108: next;
12109: } elsif (($fname =~ /\.(\w+)$/) &&
12110: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12111: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12112: next;
12113: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12114: $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 12115: next;
12116: }
12117: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12118: my $subdir = $path;
12119: $subdir =~ s{/+$}{};
1.661 raeburn 12120: if ($context eq 'portfolio') {
1.984 raeburn 12121: my $result;
12122: if ($state eq 'existingfile') {
12123: $result=
12124: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12125: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12126: } else {
1.984 raeburn 12127: $result=
12128: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12129: $dirpath.
1.1075.2.35 raeburn 12130: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12131: if ($result !~ m|^/uploaded/|) {
12132: $output .= '<span class="LC_error">'
12133: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12134: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12135: .'</span><br />';
12136: next;
12137: } else {
1.987 raeburn 12138: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12139: $path.$fname.'</span>').'<br />';
1.984 raeburn 12140: }
1.661 raeburn 12141: }
1.1075.2.35 raeburn 12142: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12143: my $extendedsubdir = $dirpath.'/'.$subdir;
12144: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12145: my $result =
1.1075.2.35 raeburn 12146: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12147: if ($result !~ m|^/uploaded/|) {
12148: $output .= '<span class="LC_error">'
12149: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12150: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12151: .'</span><br />';
12152: next;
12153: } else {
12154: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12155: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12156: if ($context eq 'syllabus') {
12157: &Apache::lonnet::make_public_indefinitely($result);
12158: }
1.987 raeburn 12159: }
1.661 raeburn 12160: } else {
12161: # Save the file
12162: my $target = $env{'form.embedded_item_'.$i};
12163: my $fullpath = $dir_root.$dirpath.'/'.$path;
12164: my $dest = $fullpath.$fname;
12165: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12166: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12167: my $count;
12168: my $filepath = $dir_root;
1.1027 raeburn 12169: foreach my $subdir (@parts) {
12170: $filepath .= "/$subdir";
12171: if (!-e $filepath) {
1.661 raeburn 12172: mkdir($filepath,0770);
12173: }
12174: }
12175: my $fh;
12176: if (!open($fh,'>'.$dest)) {
12177: &Apache::lonnet::logthis('Failed to create '.$dest);
12178: $output .= '<span class="LC_error">'.
1.1071 raeburn 12179: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12180: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12181: '</span><br />';
12182: } else {
12183: if (!print $fh $env{'form.embedded_item_'.$i}) {
12184: &Apache::lonnet::logthis('Failed to write to '.$dest);
12185: $output .= '<span class="LC_error">'.
1.1071 raeburn 12186: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12187: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12188: '</span><br />';
12189: } else {
1.987 raeburn 12190: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12191: $url.'</span>').'<br />';
12192: unless ($context eq 'testbank') {
12193: $footer .= &mt('View embedded file: [_1]',
12194: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12195: }
12196: }
12197: close($fh);
12198: }
12199: }
12200: if ($env{'form.embedded_ref_'.$i}) {
12201: $pathchange{$i} = 1;
12202: }
12203: }
12204: if ($output) {
12205: $output = '<p>'.$output.'</p>';
12206: }
12207: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12208: $returnflag = 'ok';
1.1071 raeburn 12209: my $numpathchgs = scalar(keys(%pathchange));
12210: if ($numpathchgs > 0) {
1.987 raeburn 12211: if ($context eq 'portfolio') {
12212: $output .= '<p>'.&mt('or').'</p>';
12213: } elsif ($context eq 'testbank') {
1.1071 raeburn 12214: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12215: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12216: $returnflag = 'modify_orightml';
12217: }
12218: }
1.1071 raeburn 12219: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12220: }
12221:
12222: sub modify_html_form {
12223: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12224: my $end = 0;
12225: my $modifyform;
12226: if ($context eq 'upload_embedded') {
12227: return unless (ref($pathchange) eq 'HASH');
12228: if ($env{'form.number_embedded_items'}) {
12229: $end += $env{'form.number_embedded_items'};
12230: }
12231: if ($env{'form.number_pathchange_items'}) {
12232: $end += $env{'form.number_pathchange_items'};
12233: }
12234: if ($end) {
12235: for (my $i=0; $i<$end; $i++) {
12236: if ($i < $env{'form.number_embedded_items'}) {
12237: next unless($pathchange->{$i});
12238: }
12239: $modifyform .=
12240: &start_data_table_row().
12241: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12242: 'checked="checked" /></td>'.
12243: '<td>'.$env{'form.embedded_ref_'.$i}.
12244: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12245: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12246: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12247: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12248: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12249: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12250: '<td>'.$env{'form.embedded_orig_'.$i}.
12251: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12252: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12253: &end_data_table_row();
1.1071 raeburn 12254: }
1.987 raeburn 12255: }
12256: } else {
12257: $modifyform = $pathchgtable;
12258: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12259: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12260: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12261: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12262: }
12263: }
12264: if ($modifyform) {
1.1071 raeburn 12265: if ($actionurl eq '/adm/dependencies') {
12266: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12267: }
1.987 raeburn 12268: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12269: '<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".
12270: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12271: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12272: '</ol></p>'."\n".'<p>'.
12273: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12274: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12275: &start_data_table()."\n".
12276: &start_data_table_header_row().
12277: '<th>'.&mt('Change?').'</th>'.
12278: '<th>'.&mt('Current reference').'</th>'.
12279: '<th>'.&mt('Required reference').'</th>'.
12280: &end_data_table_header_row()."\n".
12281: $modifyform.
12282: &end_data_table().'<br />'."\n".$hiddenstate.
12283: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12284: '</form>'."\n";
12285: }
12286: return;
12287: }
12288:
12289: sub modify_html_refs {
1.1075.2.35 raeburn 12290: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12291: my $container;
12292: if ($context eq 'portfolio') {
12293: $container = $env{'form.container'};
12294: } elsif ($context eq 'coursedoc') {
12295: $container = $env{'form.primaryurl'};
1.1071 raeburn 12296: } elsif ($context eq 'manage_dependencies') {
12297: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12298: $container = "/$container";
1.1075.2.35 raeburn 12299: } elsif ($context eq 'syllabus') {
12300: $container = $url;
1.987 raeburn 12301: } else {
1.1027 raeburn 12302: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12303: }
12304: my (%allfiles,%codebase,$output,$content);
12305: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12306: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12307: if (wantarray) {
12308: return ('',0,0);
12309: } else {
12310: return;
12311: }
12312: }
12313: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12314: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12315: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12316: if (wantarray) {
12317: return ('',0,0);
12318: } else {
12319: return;
12320: }
12321: }
1.987 raeburn 12322: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12323: if ($content eq '-1') {
12324: if (wantarray) {
12325: return ('',0,0);
12326: } else {
12327: return;
12328: }
12329: }
1.987 raeburn 12330: } else {
1.1071 raeburn 12331: unless ($container =~ /^\Q$dir_root\E/) {
12332: if (wantarray) {
12333: return ('',0,0);
12334: } else {
12335: return;
12336: }
12337: }
1.1075.2.128 raeburn 12338: if (open(my $fh,'<',$container)) {
1.987 raeburn 12339: $content = join('', <$fh>);
12340: close($fh);
12341: } else {
1.1071 raeburn 12342: if (wantarray) {
12343: return ('',0,0);
12344: } else {
12345: return;
12346: }
1.987 raeburn 12347: }
12348: }
12349: my ($count,$codebasecount) = (0,0);
12350: my $mm = new File::MMagic;
12351: my $mime_type = $mm->checktype_contents($content);
12352: if ($mime_type eq 'text/html') {
12353: my $parse_result =
12354: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12355: \%codebase,\$content);
12356: if ($parse_result eq 'ok') {
12357: foreach my $i (@changes) {
12358: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12359: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12360: if ($allfiles{$ref}) {
12361: my $newname = $orig;
12362: my ($attrib_regexp,$codebase);
1.1006 raeburn 12363: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12364: if ($attrib_regexp =~ /:/) {
12365: $attrib_regexp =~ s/\:/|/g;
12366: }
12367: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12368: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12369: $count += $numchg;
1.1075.2.35 raeburn 12370: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 12371: delete($allfiles{$ref});
1.987 raeburn 12372: }
12373: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12374: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12375: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12376: $codebasecount ++;
12377: }
12378: }
12379: }
1.1075.2.35 raeburn 12380: my $skiprewrites;
1.987 raeburn 12381: if ($count || $codebasecount) {
12382: my $saveresult;
1.1071 raeburn 12383: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12384: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12385: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12386: if ($url eq $container) {
12387: my ($fname) = ($container =~ m{/([^/]+)$});
12388: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12389: $count,'<span class="LC_filename">'.
1.1071 raeburn 12390: $fname.'</span>').'</p>';
1.987 raeburn 12391: } else {
12392: $output = '<p class="LC_error">'.
12393: &mt('Error: update failed for: [_1].',
12394: '<span class="LC_filename">'.
12395: $container.'</span>').'</p>';
12396: }
1.1075.2.35 raeburn 12397: if ($context eq 'syllabus') {
12398: unless ($saveresult eq 'ok') {
12399: $skiprewrites = 1;
12400: }
12401: }
1.987 raeburn 12402: } else {
1.1075.2.128 raeburn 12403: if (open(my $fh,'>',$container)) {
1.987 raeburn 12404: print $fh $content;
12405: close($fh);
12406: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12407: $count,'<span class="LC_filename">'.
12408: $container.'</span>').'</p>';
1.661 raeburn 12409: } else {
1.987 raeburn 12410: $output = '<p class="LC_error">'.
12411: &mt('Error: could not update [_1].',
12412: '<span class="LC_filename">'.
12413: $container.'</span>').'</p>';
1.661 raeburn 12414: }
12415: }
12416: }
1.1075.2.35 raeburn 12417: if (($context eq 'syllabus') && (!$skiprewrites)) {
12418: my ($actionurl,$state);
12419: $actionurl = "/public/$udom/$uname/syllabus";
12420: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12421: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12422: \%codebase,
12423: {'context' => 'rewrites',
12424: 'ignore_remote_references' => 1,});
12425: if (ref($mapping) eq 'HASH') {
12426: my $rewrites = 0;
12427: foreach my $key (keys(%{$mapping})) {
12428: next if ($key =~ m{^https?://});
12429: my $ref = $mapping->{$key};
12430: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12431: my $attrib;
12432: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12433: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12434: }
12435: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12436: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12437: $rewrites += $numchg;
12438: }
12439: }
12440: if ($rewrites) {
12441: my $saveresult;
12442: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12443: if ($url eq $container) {
12444: my ($fname) = ($container =~ m{/([^/]+)$});
12445: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12446: $count,'<span class="LC_filename">'.
12447: $fname.'</span>').'</p>';
12448: } else {
12449: $output .= '<p class="LC_error">'.
12450: &mt('Error: could not update links in [_1].',
12451: '<span class="LC_filename">'.
12452: $container.'</span>').'</p>';
12453:
12454: }
12455: }
12456: }
12457: }
1.987 raeburn 12458: } else {
12459: &logthis('Failed to parse '.$container.
12460: ' to modify references: '.$parse_result);
1.661 raeburn 12461: }
12462: }
1.1071 raeburn 12463: if (wantarray) {
12464: return ($output,$count,$codebasecount);
12465: } else {
12466: return $output;
12467: }
1.661 raeburn 12468: }
12469:
12470: sub check_for_existing {
12471: my ($path,$fname,$element) = @_;
12472: my ($state,$msg);
12473: if (-d $path.'/'.$fname) {
12474: $state = 'exists';
12475: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12476: } elsif (-e $path.'/'.$fname) {
12477: $state = 'exists';
12478: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12479: }
12480: if ($state eq 'exists') {
12481: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12482: }
12483: return ($state,$msg);
12484: }
12485:
12486: sub check_for_upload {
12487: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12488: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12489: my $filesize = length($env{'form.'.$element});
12490: if (!$filesize) {
12491: my $msg = '<span class="LC_error">'.
12492: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12493: '<span class="LC_filename">'.$fname.'</span>',
12494: $filesize).'<br />'.
1.1007 raeburn 12495: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12496: '</span>';
12497: return ('zero_bytes',$msg);
12498: }
12499: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12500: my $getpropath = 1;
1.1021 raeburn 12501: my ($dirlistref,$listerror) =
12502: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12503: my $found_file = 0;
12504: my $locked_file = 0;
1.991 raeburn 12505: my @lockers;
12506: my $navmap;
12507: if ($env{'request.course.id'}) {
12508: $navmap = Apache::lonnavmaps::navmap->new();
12509: }
1.1021 raeburn 12510: if (ref($dirlistref) eq 'ARRAY') {
12511: foreach my $line (@{$dirlistref}) {
12512: my ($file_name,$rest)=split(/\&/,$line,2);
12513: if ($file_name eq $fname){
12514: $file_name = $path.$file_name;
12515: if ($group ne '') {
12516: $file_name = $group.$file_name;
12517: }
12518: $found_file = 1;
12519: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12520: foreach my $lock (@lockers) {
12521: if (ref($lock) eq 'ARRAY') {
12522: my ($symb,$crsid) = @{$lock};
12523: if ($crsid eq $env{'request.course.id'}) {
12524: if (ref($navmap)) {
12525: my $res = $navmap->getBySymb($symb);
12526: foreach my $part (@{$res->parts()}) {
12527: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12528: unless (($slot_status == $res->RESERVED) ||
12529: ($slot_status == $res->RESERVED_LOCATION)) {
12530: $locked_file = 1;
12531: }
1.991 raeburn 12532: }
1.1021 raeburn 12533: } else {
12534: $locked_file = 1;
1.991 raeburn 12535: }
12536: } else {
12537: $locked_file = 1;
12538: }
12539: }
1.1021 raeburn 12540: }
12541: } else {
12542: my @info = split(/\&/,$rest);
12543: my $currsize = $info[6]/1000;
12544: if ($currsize < $filesize) {
12545: my $extra = $filesize - $currsize;
12546: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12547: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12548: &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 12549: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12550: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12551: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12552: return ('will_exceed_quota',$msg);
12553: }
1.984 raeburn 12554: }
12555: }
1.661 raeburn 12556: }
12557: }
12558: }
12559: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12560: my $msg = '<p class="LC_warning">'.
12561: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12562: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12563: return ('will_exceed_quota',$msg);
12564: } elsif ($found_file) {
12565: if ($locked_file) {
1.1075.2.69 raeburn 12566: my $msg = '<p class="LC_warning">';
1.661 raeburn 12567: $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 12568: $msg .= '</p>';
1.661 raeburn 12569: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12570: return ('file_locked',$msg);
12571: } else {
1.1075.2.69 raeburn 12572: my $msg = '<p class="LC_error">';
1.984 raeburn 12573: $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 12574: $msg .= '</p>';
1.984 raeburn 12575: return ('existingfile',$msg);
1.661 raeburn 12576: }
12577: }
12578: }
12579:
1.987 raeburn 12580: sub check_for_traversal {
12581: my ($path,$url,$toplevel) = @_;
12582: my @parts=split(/\//,$path);
12583: my $cleanpath;
12584: my $fullpath = $url;
12585: for (my $i=0;$i<@parts;$i++) {
12586: next if ($parts[$i] eq '.');
12587: if ($parts[$i] eq '..') {
12588: $fullpath =~ s{([^/]+/)$}{};
12589: } else {
12590: $fullpath .= $parts[$i].'/';
12591: }
12592: }
12593: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12594: $cleanpath = $1;
12595: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12596: my $curr_toprel = $1;
12597: my @parts = split(/\//,$curr_toprel);
12598: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12599: my @urlparts = split(/\//,$url_toprel);
12600: my $doubledots;
12601: my $startdiff = -1;
12602: for (my $i=0; $i<@urlparts; $i++) {
12603: if ($startdiff == -1) {
12604: unless ($urlparts[$i] eq $parts[$i]) {
12605: $startdiff = $i;
12606: $doubledots .= '../';
12607: }
12608: } else {
12609: $doubledots .= '../';
12610: }
12611: }
12612: if ($startdiff > -1) {
12613: $cleanpath = $doubledots;
12614: for (my $i=$startdiff; $i<@parts; $i++) {
12615: $cleanpath .= $parts[$i].'/';
12616: }
12617: }
12618: }
12619: $cleanpath =~ s{(/)$}{};
12620: return $cleanpath;
12621: }
1.31 albertel 12622:
1.1053 raeburn 12623: sub is_archive_file {
12624: my ($mimetype) = @_;
12625: if (($mimetype eq 'application/octet-stream') ||
12626: ($mimetype eq 'application/x-stuffit') ||
12627: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12628: return 1;
12629: }
12630: return;
12631: }
12632:
12633: sub decompress_form {
1.1065 raeburn 12634: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12635: my %lt = &Apache::lonlocal::texthash (
12636: this => 'This file is an archive file.',
1.1067 raeburn 12637: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12638: itsc => 'Its contents are as follows:',
1.1053 raeburn 12639: youm => 'You may wish to extract its contents.',
12640: extr => 'Extract contents',
1.1067 raeburn 12641: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12642: proa => 'Process automatically?',
1.1053 raeburn 12643: yes => 'Yes',
12644: no => 'No',
1.1067 raeburn 12645: fold => 'Title for folder containing movie',
12646: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12647: );
1.1065 raeburn 12648: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12649: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12650: my $info = &list_archive_contents($fileloc,\@paths);
12651: if (@paths) {
12652: foreach my $path (@paths) {
12653: $path =~ s{^/}{};
1.1067 raeburn 12654: if ($path =~ m{^([^/]+)/$}) {
12655: $topdir = $1;
12656: }
1.1065 raeburn 12657: if ($path =~ m{^([^/]+)/}) {
12658: $toplevel{$1} = $path;
12659: } else {
12660: $toplevel{$path} = $path;
12661: }
12662: }
12663: }
1.1067 raeburn 12664: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12665: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12666: "$topdir/media/",
12667: "$topdir/media/$topdir.mp4",
12668: "$topdir/media/FirstFrame.png",
12669: "$topdir/media/player.swf",
12670: "$topdir/media/swfobject.js",
12671: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12672: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12673: "$topdir/$topdir.mp4",
12674: "$topdir/$topdir\_config.xml",
12675: "$topdir/$topdir\_controller.swf",
12676: "$topdir/$topdir\_embed.css",
12677: "$topdir/$topdir\_First_Frame.png",
12678: "$topdir/$topdir\_player.html",
12679: "$topdir/$topdir\_Thumbnails.png",
12680: "$topdir/playerProductInstall.swf",
12681: "$topdir/scripts/",
12682: "$topdir/scripts/config_xml.js",
12683: "$topdir/scripts/handlebars.js",
12684: "$topdir/scripts/jquery-1.7.1.min.js",
12685: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12686: "$topdir/scripts/modernizr.js",
12687: "$topdir/scripts/player-min.js",
12688: "$topdir/scripts/swfobject.js",
12689: "$topdir/skins/",
12690: "$topdir/skins/configuration_express.xml",
12691: "$topdir/skins/express_show/",
12692: "$topdir/skins/express_show/player-min.css",
12693: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12694: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12695: "$topdir/$topdir.mp4",
12696: "$topdir/$topdir\_config.xml",
12697: "$topdir/$topdir\_controller.swf",
12698: "$topdir/$topdir\_embed.css",
12699: "$topdir/$topdir\_First_Frame.png",
12700: "$topdir/$topdir\_player.html",
12701: "$topdir/$topdir\_Thumbnails.png",
12702: "$topdir/playerProductInstall.swf",
12703: "$topdir/scripts/",
12704: "$topdir/scripts/config_xml.js",
12705: "$topdir/scripts/techsmith-smart-player.min.js",
12706: "$topdir/skins/",
12707: "$topdir/skins/configuration_express.xml",
12708: "$topdir/skins/express_show/",
12709: "$topdir/skins/express_show/spritesheet.min.css",
12710: "$topdir/skins/express_show/spritesheet.png",
12711: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12712: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12713: if (@diffs == 0) {
1.1075.2.59 raeburn 12714: $is_camtasia = 6;
12715: } else {
1.1075.2.81 raeburn 12716: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12717: if (@diffs == 0) {
12718: $is_camtasia = 8;
1.1075.2.81 raeburn 12719: } else {
12720: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12721: if (@diffs == 0) {
12722: $is_camtasia = 8;
12723: }
1.1075.2.59 raeburn 12724: }
1.1067 raeburn 12725: }
12726: }
12727: my $output;
12728: if ($is_camtasia) {
12729: $output = <<"ENDCAM";
12730: <script type="text/javascript" language="Javascript">
12731: // <![CDATA[
12732:
12733: function camtasiaToggle() {
12734: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12735: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12736: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12737: document.getElementById('camtasia_titles').style.display='block';
12738: } else {
12739: document.getElementById('camtasia_titles').style.display='none';
12740: }
12741: }
12742: }
12743: return;
12744: }
12745:
12746: // ]]>
12747: </script>
12748: <p>$lt{'camt'}</p>
12749: ENDCAM
1.1065 raeburn 12750: } else {
1.1067 raeburn 12751: $output = '<p>'.$lt{'this'};
12752: if ($info eq '') {
12753: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12754: } else {
12755: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12756: '<div><pre>'.$info.'</pre></div>';
12757: }
1.1065 raeburn 12758: }
1.1067 raeburn 12759: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12760: my $duplicates;
12761: my $num = 0;
12762: if (ref($dirlist) eq 'ARRAY') {
12763: foreach my $item (@{$dirlist}) {
12764: if (ref($item) eq 'ARRAY') {
12765: if (exists($toplevel{$item->[0]})) {
12766: $duplicates .=
12767: &start_data_table_row().
12768: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12769: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12770: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12771: 'value="1" />'.&mt('Yes').'</label>'.
12772: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12773: '<td>'.$item->[0].'</td>';
12774: if ($item->[2]) {
12775: $duplicates .= '<td>'.&mt('Directory').'</td>';
12776: } else {
12777: $duplicates .= '<td>'.&mt('File').'</td>';
12778: }
12779: $duplicates .= '<td>'.$item->[3].'</td>'.
12780: '<td>'.
12781: &Apache::lonlocal::locallocaltime($item->[4]).
12782: '</td>'.
12783: &end_data_table_row();
12784: $num ++;
12785: }
12786: }
12787: }
12788: }
12789: my $itemcount;
12790: if (@paths > 0) {
12791: $itemcount = scalar(@paths);
12792: } else {
12793: $itemcount = 1;
12794: }
1.1067 raeburn 12795: if ($is_camtasia) {
12796: $output .= $lt{'auto'}.'<br />'.
12797: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12798: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12799: $lt{'yes'}.'</label> <label>'.
12800: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12801: $lt{'no'}.'</label></span><br />'.
12802: '<div id="camtasia_titles" style="display:block">'.
12803: &Apache::lonhtmlcommon::start_pick_box().
12804: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12805: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12806: &Apache::lonhtmlcommon::row_closure().
12807: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12808: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12809: &Apache::lonhtmlcommon::row_closure(1).
12810: &Apache::lonhtmlcommon::end_pick_box().
12811: '</div>';
12812: }
1.1065 raeburn 12813: $output .=
12814: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12815: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12816: "\n";
1.1065 raeburn 12817: if ($duplicates ne '') {
12818: $output .= '<p><span class="LC_warning">'.
12819: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12820: &start_data_table().
12821: &start_data_table_header_row().
12822: '<th>'.&mt('Overwrite?').'</th>'.
12823: '<th>'.&mt('Name').'</th>'.
12824: '<th>'.&mt('Type').'</th>'.
12825: '<th>'.&mt('Size').'</th>'.
12826: '<th>'.&mt('Last modified').'</th>'.
12827: &end_data_table_header_row().
12828: $duplicates.
12829: &end_data_table().
12830: '</p>';
12831: }
1.1067 raeburn 12832: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12833: if (ref($hiddenelements) eq 'HASH') {
12834: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12835: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12836: }
12837: }
12838: $output .= <<"END";
1.1067 raeburn 12839: <br />
1.1053 raeburn 12840: <input type="submit" name="decompress" value="$lt{'extr'}" />
12841: </form>
12842: $noextract
12843: END
12844: return $output;
12845: }
12846:
1.1065 raeburn 12847: sub decompression_utility {
12848: my ($program) = @_;
12849: my @utilities = ('tar','gunzip','bunzip2','unzip');
12850: my $location;
12851: if (grep(/^\Q$program\E$/,@utilities)) {
12852: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12853: '/usr/sbin/') {
12854: if (-x $dir.$program) {
12855: $location = $dir.$program;
12856: last;
12857: }
12858: }
12859: }
12860: return $location;
12861: }
12862:
12863: sub list_archive_contents {
12864: my ($file,$pathsref) = @_;
12865: my (@cmd,$output);
12866: my $needsregexp;
12867: if ($file =~ /\.zip$/) {
12868: @cmd = (&decompression_utility('unzip'),"-l");
12869: $needsregexp = 1;
12870: } elsif (($file =~ m/\.tar\.gz$/) ||
12871: ($file =~ /\.tgz$/)) {
12872: @cmd = (&decompression_utility('tar'),"-ztf");
12873: } elsif ($file =~ /\.tar\.bz2$/) {
12874: @cmd = (&decompression_utility('tar'),"-jtf");
12875: } elsif ($file =~ m|\.tar$|) {
12876: @cmd = (&decompression_utility('tar'),"-tf");
12877: }
12878: if (@cmd) {
12879: undef($!);
12880: undef($@);
12881: if (open(my $fh,"-|", @cmd, $file)) {
12882: while (my $line = <$fh>) {
12883: $output .= $line;
12884: chomp($line);
12885: my $item;
12886: if ($needsregexp) {
12887: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12888: } else {
12889: $item = $line;
12890: }
12891: if ($item ne '') {
12892: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12893: push(@{$pathsref},$item);
12894: }
12895: }
12896: }
12897: close($fh);
12898: }
12899: }
12900: return $output;
12901: }
12902:
1.1053 raeburn 12903: sub decompress_uploaded_file {
12904: my ($file,$dir) = @_;
12905: &Apache::lonnet::appenv({'cgi.file' => $file});
12906: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12907: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12908: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12909: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12910: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12911: my $decompressed = $env{'cgi.decompressed'};
12912: &Apache::lonnet::delenv('cgi.file');
12913: &Apache::lonnet::delenv('cgi.dir');
12914: &Apache::lonnet::delenv('cgi.decompressed');
12915: return ($decompressed,$result);
12916: }
12917:
1.1055 raeburn 12918: sub process_decompression {
12919: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12920: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12921: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12922: &mt('Unexpected file path.').'</p>'."\n";
12923: }
12924: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12925: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12926: &mt('Unexpected course context.').'</p>'."\n";
12927: }
12928: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12929: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12930: &mt('Filename contained unexpected characters.').'</p>'."\n";
12931: }
1.1055 raeburn 12932: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12933: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12934: $error = &mt('Filename not a supported archive file type.').
12935: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12936: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12937: } else {
12938: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12939: if ($docuhome eq 'no_host') {
12940: $error = &mt('Could not determine home server for course.');
12941: } else {
12942: my @ids=&Apache::lonnet::current_machine_ids();
12943: my $currdir = "$dir_root/$destination";
12944: if (grep(/^\Q$docuhome\E$/,@ids)) {
12945: $dir = &LONCAPA::propath($docudom,$docuname).
12946: "$dir_root/$destination";
12947: } else {
12948: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12949: "$dir_root/$docudom/$docuname/$destination";
12950: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12951: $error = &mt('Archive file not found.');
12952: }
12953: }
1.1065 raeburn 12954: my (@to_overwrite,@to_skip);
12955: if ($env{'form.archive_overwrite_total'} > 0) {
12956: my $total = $env{'form.archive_overwrite_total'};
12957: for (my $i=0; $i<$total; $i++) {
12958: if ($env{'form.archive_overwrite_'.$i} == 1) {
12959: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12960: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12961: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12962: }
12963: }
12964: }
12965: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12966: my $numoverwrite = scalar(@to_overwrite);
12967: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12968: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12969: } elsif ($dir eq '') {
1.1055 raeburn 12970: $error = &mt('Directory containing archive file unavailable.');
12971: } elsif (!$error) {
1.1065 raeburn 12972: my ($decompressed,$display);
1.1075.2.128 raeburn 12973: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12974: my $tempdir = time.'_'.$$.int(rand(10000));
12975: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12976: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12977: ($decompressed,$display) =
12978: &decompress_uploaded_file($file,"$dir/$tempdir");
12979: foreach my $item (@to_skip) {
12980: if (($item ne '') && ($item !~ /\.\./)) {
12981: if (-f "$dir/$tempdir/$item") {
12982: unlink("$dir/$tempdir/$item");
12983: } elsif (-d "$dir/$tempdir/$item") {
12984: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12985: }
12986: }
12987: }
12988: foreach my $item (@to_overwrite) {
12989: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12990: if (($item ne '') && ($item !~ /\.\./)) {
12991: if (-f "$dir/$item") {
12992: unlink("$dir/$item");
12993: } elsif (-d "$dir/$item") {
12994: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12995: }
12996: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12997: }
1.1065 raeburn 12998: }
12999: }
1.1075.2.128 raeburn 13000: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13001: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13002: }
1.1065 raeburn 13003: }
13004: } else {
13005: ($decompressed,$display) =
13006: &decompress_uploaded_file($file,$dir);
13007: }
1.1055 raeburn 13008: if ($decompressed eq 'ok') {
1.1065 raeburn 13009: $output = '<p class="LC_info">'.
13010: &mt('Files extracted successfully from archive.').
13011: '</p>'."\n";
1.1055 raeburn 13012: my ($warning,$result,@contents);
13013: my ($newdirlistref,$newlisterror) =
13014: &Apache::lonnet::dirlist($currdir,$docudom,
13015: $docuname,1);
13016: my (%is_dir,%changes,@newitems);
13017: my $dirptr = 16384;
1.1065 raeburn 13018: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13019: foreach my $dir_line (@{$newdirlistref}) {
13020: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13021: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13022: push(@newitems,$item);
13023: if ($dirptr&$testdir) {
13024: $is_dir{$item} = 1;
13025: }
13026: $changes{$item} = 1;
13027: }
13028: }
13029: }
13030: if (keys(%changes) > 0) {
13031: foreach my $item (sort(@newitems)) {
13032: if ($changes{$item}) {
13033: push(@contents,$item);
13034: }
13035: }
13036: }
13037: if (@contents > 0) {
1.1067 raeburn 13038: my $wantform;
13039: unless ($env{'form.autoextract_camtasia'}) {
13040: $wantform = 1;
13041: }
1.1056 raeburn 13042: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13043: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13044: $currdir,\%is_dir,
13045: \%children,\%parent,
1.1056 raeburn 13046: \@contents,\%dirorder,
13047: \%titles,$wantform);
1.1055 raeburn 13048: if ($datatable ne '') {
13049: $output .= &archive_options_form('decompressed',$datatable,
13050: $count,$hiddenelem);
1.1065 raeburn 13051: my $startcount = 6;
1.1055 raeburn 13052: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13053: \%titles,\%children);
1.1055 raeburn 13054: }
1.1067 raeburn 13055: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13056: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13057: my %displayed;
13058: my $total = 1;
13059: $env{'form.archive_directory'} = [];
13060: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13061: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13062: $path =~ s{/$}{};
13063: my $item;
13064: if ($path ne '') {
13065: $item = "$path/$titles{$i}";
13066: } else {
13067: $item = $titles{$i};
13068: }
13069: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13070: if ($item eq $contents[0]) {
13071: push(@{$env{'form.archive_directory'}},$i);
13072: $env{'form.archive_'.$i} = 'display';
13073: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13074: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13075: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13076: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13077: $env{'form.archive_'.$i} = 'display';
13078: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13079: $displayed{'web'} = $i;
13080: } else {
1.1075.2.59 raeburn 13081: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13082: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13083: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13084: push(@{$env{'form.archive_directory'}},$i);
13085: }
13086: $env{'form.archive_'.$i} = 'dependency';
13087: }
13088: $total ++;
13089: }
13090: for (my $i=1; $i<$total; $i++) {
13091: next if ($i == $displayed{'web'});
13092: next if ($i == $displayed{'folder'});
13093: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13094: }
13095: $env{'form.phase'} = 'decompress_cleanup';
13096: $env{'form.archivedelete'} = 1;
13097: $env{'form.archive_count'} = $total-1;
13098: $output .=
13099: &process_extracted_files('coursedocs',$docudom,
13100: $docuname,$destination,
13101: $dir_root,$hiddenelem);
13102: }
1.1055 raeburn 13103: } else {
13104: $warning = &mt('No new items extracted from archive file.');
13105: }
13106: } else {
13107: $output = $display;
13108: $error = &mt('An error occurred during extraction from the archive file.');
13109: }
13110: }
13111: }
13112: }
13113: if ($error) {
13114: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13115: $error.'</p>'."\n";
13116: }
13117: if ($warning) {
13118: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13119: }
13120: return $output;
13121: }
13122:
13123: sub get_extracted {
1.1056 raeburn 13124: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13125: $titles,$wantform) = @_;
1.1055 raeburn 13126: my $count = 0;
13127: my $depth = 0;
13128: my $datatable;
1.1056 raeburn 13129: my @hierarchy;
1.1055 raeburn 13130: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13131: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13132: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13133: foreach my $item (@{$contents}) {
13134: $count ++;
1.1056 raeburn 13135: @{$dirorder->{$count}} = @hierarchy;
13136: $titles->{$count} = $item;
1.1055 raeburn 13137: &archive_hierarchy($depth,$count,$parent,$children);
13138: if ($wantform) {
13139: $datatable .= &archive_row($is_dir->{$item},$item,
13140: $currdir,$depth,$count);
13141: }
13142: if ($is_dir->{$item}) {
13143: $depth ++;
1.1056 raeburn 13144: push(@hierarchy,$count);
13145: $parent->{$depth} = $count;
1.1055 raeburn 13146: $datatable .=
13147: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13148: \$depth,\$count,\@hierarchy,$dirorder,
13149: $children,$parent,$titles,$wantform);
1.1055 raeburn 13150: $depth --;
1.1056 raeburn 13151: pop(@hierarchy);
1.1055 raeburn 13152: }
13153: }
13154: return ($count,$datatable);
13155: }
13156:
13157: sub recurse_extracted_archive {
1.1056 raeburn 13158: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13159: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13160: my $result='';
1.1056 raeburn 13161: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13162: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13163: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13164: return $result;
13165: }
13166: my $dirptr = 16384;
13167: my ($newdirlistref,$newlisterror) =
13168: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13169: if (ref($newdirlistref) eq 'ARRAY') {
13170: foreach my $dir_line (@{$newdirlistref}) {
13171: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13172: unless ($item =~ /^\.+$/) {
13173: $$count ++;
1.1056 raeburn 13174: @{$dirorder->{$$count}} = @{$hierarchy};
13175: $titles->{$$count} = $item;
1.1055 raeburn 13176: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13177:
1.1055 raeburn 13178: my $is_dir;
13179: if ($dirptr&$testdir) {
13180: $is_dir = 1;
13181: }
13182: if ($wantform) {
13183: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13184: }
13185: if ($is_dir) {
13186: $$depth ++;
1.1056 raeburn 13187: push(@{$hierarchy},$$count);
13188: $parent->{$$depth} = $$count;
1.1055 raeburn 13189: $result .=
13190: &recurse_extracted_archive("$currdir/$item",$docudom,
13191: $docuname,$depth,$count,
1.1056 raeburn 13192: $hierarchy,$dirorder,$children,
13193: $parent,$titles,$wantform);
1.1055 raeburn 13194: $$depth --;
1.1056 raeburn 13195: pop(@{$hierarchy});
1.1055 raeburn 13196: }
13197: }
13198: }
13199: }
13200: return $result;
13201: }
13202:
13203: sub archive_hierarchy {
13204: my ($depth,$count,$parent,$children) =@_;
13205: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13206: if (exists($parent->{$depth})) {
13207: $children->{$parent->{$depth}} .= $count.':';
13208: }
13209: }
13210: return;
13211: }
13212:
13213: sub archive_row {
13214: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13215: my ($name) = ($item =~ m{([^/]+)$});
13216: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13217: 'display' => 'Add as file',
1.1055 raeburn 13218: 'dependency' => 'Include as dependency',
13219: 'discard' => 'Discard',
13220: );
13221: if ($is_dir) {
1.1059 raeburn 13222: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13223: }
1.1056 raeburn 13224: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13225: my $offset = 0;
1.1055 raeburn 13226: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13227: $offset ++;
1.1065 raeburn 13228: if ($action ne 'display') {
13229: $offset ++;
13230: }
1.1055 raeburn 13231: $output .= '<td><span class="LC_nobreak">'.
13232: '<label><input type="radio" name="archive_'.$count.
13233: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13234: my $text = $choices{$action};
13235: if ($is_dir) {
13236: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13237: if ($action eq 'display') {
1.1059 raeburn 13238: $text = &mt('Add as folder');
1.1055 raeburn 13239: }
1.1056 raeburn 13240: } else {
13241: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13242:
13243: }
13244: $output .= ' /> '.$choices{$action}.'</label></span>';
13245: if ($action eq 'dependency') {
13246: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13247: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13248: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13249: '<option value=""></option>'."\n".
13250: '</select>'."\n".
13251: '</div>';
1.1059 raeburn 13252: } elsif ($action eq 'display') {
13253: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13254: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13255: '</div>';
1.1055 raeburn 13256: }
1.1056 raeburn 13257: $output .= '</td>';
1.1055 raeburn 13258: }
13259: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13260: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13261: for (my $i=0; $i<$depth; $i++) {
13262: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13263: }
13264: if ($is_dir) {
13265: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13266: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13267: } else {
13268: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13269: }
13270: $output .= ' '.$name.'</td>'."\n".
13271: &end_data_table_row();
13272: return $output;
13273: }
13274:
13275: sub archive_options_form {
1.1065 raeburn 13276: my ($form,$display,$count,$hiddenelem) = @_;
13277: my %lt = &Apache::lonlocal::texthash(
13278: perm => 'Permanently remove archive file?',
13279: hows => 'How should each extracted item be incorporated in the course?',
13280: cont => 'Content actions for all',
13281: addf => 'Add as folder/file',
13282: incd => 'Include as dependency for a displayed file',
13283: disc => 'Discard',
13284: no => 'No',
13285: yes => 'Yes',
13286: save => 'Save',
13287: );
13288: my $output = <<"END";
13289: <form name="$form" method="post" action="">
13290: <p><span class="LC_nobreak">$lt{'perm'}
13291: <label>
13292: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13293: </label>
13294:
13295: <label>
13296: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13297: </span>
13298: </p>
13299: <input type="hidden" name="phase" value="decompress_cleanup" />
13300: <br />$lt{'hows'}
13301: <div class="LC_columnSection">
13302: <fieldset>
13303: <legend>$lt{'cont'}</legend>
13304: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13305: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13306: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13307: </fieldset>
13308: </div>
13309: END
13310: return $output.
1.1055 raeburn 13311: &start_data_table()."\n".
1.1065 raeburn 13312: $display."\n".
1.1055 raeburn 13313: &end_data_table()."\n".
13314: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13315: $hiddenelem.
1.1065 raeburn 13316: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13317: '</form>';
13318: }
13319:
13320: sub archive_javascript {
1.1056 raeburn 13321: my ($startcount,$numitems,$titles,$children) = @_;
13322: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13323: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13324: my $scripttag = <<START;
13325: <script type="text/javascript">
13326: // <![CDATA[
13327:
13328: function checkAll(form,prefix) {
13329: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13330: for (var i=0; i < form.elements.length; i++) {
13331: var id = form.elements[i].id;
13332: if ((id != '') && (id != undefined)) {
13333: if (idstr.test(id)) {
13334: if (form.elements[i].type == 'radio') {
13335: form.elements[i].checked = true;
1.1056 raeburn 13336: var nostart = i-$startcount;
1.1059 raeburn 13337: var offset = nostart%7;
13338: var count = (nostart-offset)/7;
1.1056 raeburn 13339: dependencyCheck(form,count,offset);
1.1055 raeburn 13340: }
13341: }
13342: }
13343: }
13344: }
13345:
13346: function propagateCheck(form,count) {
13347: if (count > 0) {
1.1059 raeburn 13348: var startelement = $startcount + ((count-1) * 7);
13349: for (var j=1; j<6; j++) {
13350: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13351: var item = startelement + j;
13352: if (form.elements[item].type == 'radio') {
13353: if (form.elements[item].checked) {
13354: containerCheck(form,count,j);
13355: break;
13356: }
1.1055 raeburn 13357: }
13358: }
13359: }
13360: }
13361: }
13362:
13363: numitems = $numitems
1.1056 raeburn 13364: var titles = new Array(numitems);
13365: var parents = new Array(numitems);
1.1055 raeburn 13366: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13367: parents[i] = new Array;
1.1055 raeburn 13368: }
1.1059 raeburn 13369: var maintitle = '$maintitle';
1.1055 raeburn 13370:
13371: START
13372:
1.1056 raeburn 13373: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13374: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13375: for (my $i=0; $i<@contents; $i ++) {
13376: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13377: }
13378: }
13379:
1.1056 raeburn 13380: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13381: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13382: }
13383:
1.1055 raeburn 13384: $scripttag .= <<END;
13385:
13386: function containerCheck(form,count,offset) {
13387: if (count > 0) {
1.1056 raeburn 13388: dependencyCheck(form,count,offset);
1.1059 raeburn 13389: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13390: form.elements[item].checked = true;
13391: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13392: if (parents[count].length > 0) {
13393: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13394: containerCheck(form,parents[count][j],offset);
13395: }
13396: }
13397: }
13398: }
13399: }
13400:
13401: function dependencyCheck(form,count,offset) {
13402: if (count > 0) {
1.1059 raeburn 13403: var chosen = (offset+$startcount)+7*(count-1);
13404: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13405: var currtype = form.elements[depitem].type;
13406: if (form.elements[chosen].value == 'dependency') {
13407: document.getElementById('arc_depon_'+count).style.display='block';
13408: form.elements[depitem].options.length = 0;
13409: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 13410: for (var i=1; i<=numitems; i++) {
13411: if (i == count) {
13412: continue;
13413: }
1.1059 raeburn 13414: var startelement = $startcount + (i-1) * 7;
13415: for (var j=1; j<6; j++) {
13416: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13417: var item = startelement + j;
13418: if (form.elements[item].type == 'radio') {
13419: if (form.elements[item].checked) {
13420: if (form.elements[item].value == 'display') {
13421: var n = form.elements[depitem].options.length;
13422: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13423: }
13424: }
13425: }
13426: }
13427: }
13428: }
13429: } else {
13430: document.getElementById('arc_depon_'+count).style.display='none';
13431: form.elements[depitem].options.length = 0;
13432: form.elements[depitem].options[0] = new Option('Select','',true,true);
13433: }
1.1059 raeburn 13434: titleCheck(form,count,offset);
1.1056 raeburn 13435: }
13436: }
13437:
13438: function propagateSelect(form,count,offset) {
13439: if (count > 0) {
1.1065 raeburn 13440: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13441: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13442: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13443: if (parents[count].length > 0) {
13444: for (var j=0; j<parents[count].length; j++) {
13445: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13446: }
13447: }
13448: }
13449: }
13450: }
1.1056 raeburn 13451:
13452: function containerSelect(form,count,offset,picked) {
13453: if (count > 0) {
1.1065 raeburn 13454: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13455: if (form.elements[item].type == 'radio') {
13456: if (form.elements[item].value == 'dependency') {
13457: if (form.elements[item+1].type == 'select-one') {
13458: for (var i=0; i<form.elements[item+1].options.length; i++) {
13459: if (form.elements[item+1].options[i].value == picked) {
13460: form.elements[item+1].selectedIndex = i;
13461: break;
13462: }
13463: }
13464: }
13465: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13466: if (parents[count].length > 0) {
13467: for (var j=0; j<parents[count].length; j++) {
13468: containerSelect(form,parents[count][j],offset,picked);
13469: }
13470: }
13471: }
13472: }
13473: }
13474: }
13475: }
13476:
1.1059 raeburn 13477: function titleCheck(form,count,offset) {
13478: if (count > 0) {
13479: var chosen = (offset+$startcount)+7*(count-1);
13480: var depitem = $startcount + ((count-1) * 7) + 2;
13481: var currtype = form.elements[depitem].type;
13482: if (form.elements[chosen].value == 'display') {
13483: document.getElementById('arc_title_'+count).style.display='block';
13484: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13485: document.getElementById('archive_title_'+count).value=maintitle;
13486: }
13487: } else {
13488: document.getElementById('arc_title_'+count).style.display='none';
13489: if (currtype == 'text') {
13490: document.getElementById('archive_title_'+count).value='';
13491: }
13492: }
13493: }
13494: return;
13495: }
13496:
1.1055 raeburn 13497: // ]]>
13498: </script>
13499: END
13500: return $scripttag;
13501: }
13502:
13503: sub process_extracted_files {
1.1067 raeburn 13504: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13505: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13506: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13507: my @ids=&Apache::lonnet::current_machine_ids();
13508: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13509: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13510: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13511: if (grep(/^\Q$docuhome\E$/,@ids)) {
13512: $prefix = &LONCAPA::propath($docudom,$docuname);
13513: $pathtocheck = "$dir_root/$destination";
13514: $dir = $dir_root;
13515: $ishome = 1;
13516: } else {
13517: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13518: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13519: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13520: }
13521: my $currdir = "$dir_root/$destination";
13522: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13523: if ($env{'form.folderpath'}) {
13524: my @items = split('&',$env{'form.folderpath'});
13525: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13526: if ($env{'form.folderpath'} =~ /\:1$/) {
13527: $containers{'0'}='page';
13528: } else {
13529: $containers{'0'}='sequence';
13530: }
1.1055 raeburn 13531: }
13532: my @archdirs = &get_env_multiple('form.archive_directory');
13533: if ($numitems) {
13534: for (my $i=1; $i<=$numitems; $i++) {
13535: my $path = $env{'form.archive_content_'.$i};
13536: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13537: my $item = $1;
13538: $toplevelitems{$item} = $i;
13539: if (grep(/^\Q$i\E$/,@archdirs)) {
13540: $is_dir{$item} = 1;
13541: }
13542: }
13543: }
13544: }
1.1067 raeburn 13545: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13546: if (keys(%toplevelitems) > 0) {
13547: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13548: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13549: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13550: }
1.1066 raeburn 13551: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13552: if ($numitems) {
13553: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13554: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13555: my $path = $env{'form.archive_content_'.$i};
13556: if ($path =~ /^\Q$pathtocheck\E/) {
13557: if ($env{'form.archive_'.$i} eq 'discard') {
13558: if ($prefix ne '' && $path ne '') {
13559: if (-e $prefix.$path) {
1.1066 raeburn 13560: if ((@archdirs > 0) &&
13561: (grep(/^\Q$i\E$/,@archdirs))) {
13562: $todeletedir{$prefix.$path} = 1;
13563: } else {
13564: $todelete{$prefix.$path} = 1;
13565: }
1.1055 raeburn 13566: }
13567: }
13568: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13569: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13570: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13571: $docstitle = $env{'form.archive_title_'.$i};
13572: if ($docstitle eq '') {
13573: $docstitle = $title;
13574: }
1.1055 raeburn 13575: $outer = 0;
1.1056 raeburn 13576: if (ref($dirorder{$i}) eq 'ARRAY') {
13577: if (@{$dirorder{$i}} > 0) {
13578: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13579: if ($env{'form.archive_'.$item} eq 'display') {
13580: $outer = $item;
13581: last;
13582: }
13583: }
13584: }
13585: }
13586: my ($errtext,$fatal) =
13587: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13588: '/'.$folders{$outer}.'.'.
13589: $containers{$outer});
13590: next if ($fatal);
13591: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13592: if ($context eq 'coursedocs') {
1.1056 raeburn 13593: $mapinner{$i} = time;
1.1055 raeburn 13594: $folders{$i} = 'default_'.$mapinner{$i};
13595: $containers{$i} = 'sequence';
13596: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13597: $folders{$i}.'.'.$containers{$i};
13598: my $newidx = &LONCAPA::map::getresidx();
13599: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13600: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13601: push(@LONCAPA::map::order,$newidx);
13602: my ($outtext,$errtext) =
13603: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13604: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13605: '.'.$containers{$outer},1,1);
1.1056 raeburn 13606: $newseqid{$i} = $newidx;
1.1067 raeburn 13607: unless ($errtext) {
1.1075.2.128 raeburn 13608: $result .= '<li>'.&mt('Folder: [_1] added to course',
13609: &HTML::Entities::encode($docstitle,'<>&"'))..
13610: '</li>'."\n";
1.1067 raeburn 13611: }
1.1055 raeburn 13612: }
13613: } else {
13614: if ($context eq 'coursedocs') {
13615: my $newidx=&LONCAPA::map::getresidx();
13616: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13617: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13618: $title;
1.1075.2.128 raeburn 13619: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13620: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13621: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13622: }
1.1075.2.128 raeburn 13623: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13624: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13625: }
13626: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13627: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13628: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13629: unless ($ishome) {
13630: my $fetch = "$newdest{$i}/$title";
13631: $fetch =~ s/^\Q$prefix$dir\E//;
13632: $prompttofetch{$fetch} = 1;
13633: }
13634: }
13635: }
13636: $LONCAPA::map::resources[$newidx]=
13637: $docstitle.':'.$url.':false:normal:res';
13638: push(@LONCAPA::map::order, $newidx);
13639: my ($outtext,$errtext)=
13640: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13641: $docuname.'/'.$folders{$outer}.
13642: '.'.$containers{$outer},1,1);
13643: unless ($errtext) {
13644: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13645: $result .= '<li>'.&mt('File: [_1] added to course',
13646: &HTML::Entities::encode($docstitle,'<>&"')).
13647: '</li>'."\n";
13648: }
1.1067 raeburn 13649: }
1.1075.2.128 raeburn 13650: } else {
13651: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13652: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13653: }
1.1055 raeburn 13654: }
13655: }
1.1075.2.11 raeburn 13656: }
13657: } else {
1.1075.2.128 raeburn 13658: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13659: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13660: }
13661: }
13662: for (my $i=1; $i<=$numitems; $i++) {
13663: next unless ($env{'form.archive_'.$i} eq 'dependency');
13664: my $path = $env{'form.archive_content_'.$i};
13665: if ($path =~ /^\Q$pathtocheck\E/) {
13666: my ($title) = ($path =~ m{/([^/]+)$});
13667: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13668: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13669: if (ref($dirorder{$i}) eq 'ARRAY') {
13670: my ($itemidx,$fullpath,$relpath);
13671: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13672: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13673: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13674: if ($dirorder{$i}->[$j] eq $container) {
13675: $itemidx = $j;
1.1056 raeburn 13676: }
13677: }
1.1075.2.11 raeburn 13678: }
13679: if ($itemidx eq '') {
13680: $itemidx = 0;
13681: }
13682: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13683: if ($mapinner{$referrer{$i}}) {
13684: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13685: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13686: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13687: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13688: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13689: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13690: if (!-e $fullpath) {
13691: mkdir($fullpath,0755);
1.1056 raeburn 13692: }
13693: }
1.1075.2.11 raeburn 13694: } else {
13695: last;
1.1056 raeburn 13696: }
1.1075.2.11 raeburn 13697: }
13698: }
13699: } elsif ($newdest{$referrer{$i}}) {
13700: $fullpath = $newdest{$referrer{$i}};
13701: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13702: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13703: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13704: last;
13705: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13706: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13707: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13708: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13709: if (!-e $fullpath) {
13710: mkdir($fullpath,0755);
1.1056 raeburn 13711: }
13712: }
1.1075.2.11 raeburn 13713: } else {
13714: last;
1.1056 raeburn 13715: }
1.1075.2.11 raeburn 13716: }
13717: }
13718: if ($fullpath ne '') {
13719: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13720: unless (rename("$prefix$path","$fullpath/$title")) {
13721: $warning .= &mt('Failed to rename dependency').'<br />';
13722: }
1.1075.2.11 raeburn 13723: }
13724: if (-e "$fullpath/$title") {
13725: my $showpath;
13726: if ($relpath ne '') {
13727: $showpath = "$relpath/$title";
13728: } else {
13729: $showpath = "/$title";
1.1056 raeburn 13730: }
1.1075.2.128 raeburn 13731: $result .= '<li>'.&mt('[_1] included as a dependency',
13732: &HTML::Entities::encode($showpath,'<>&"')).
13733: '</li>'."\n";
13734: unless ($ishome) {
13735: my $fetch = "$fullpath/$title";
13736: $fetch =~ s/^\Q$prefix$dir\E//;
13737: $prompttofetch{$fetch} = 1;
13738: }
1.1055 raeburn 13739: }
13740: }
13741: }
1.1075.2.11 raeburn 13742: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13743: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13744: &HTML::Entities::encode($path,'<>&"'),
13745: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13746: '<br />';
1.1055 raeburn 13747: }
13748: } else {
1.1075.2.128 raeburn 13749: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13750: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13751: }
13752: }
13753: if (keys(%todelete)) {
13754: foreach my $key (keys(%todelete)) {
13755: unlink($key);
1.1066 raeburn 13756: }
13757: }
13758: if (keys(%todeletedir)) {
13759: foreach my $key (keys(%todeletedir)) {
13760: rmdir($key);
13761: }
13762: }
13763: foreach my $dir (sort(keys(%is_dir))) {
13764: if (($pathtocheck ne '') && ($dir ne '')) {
13765: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13766: }
13767: }
1.1067 raeburn 13768: if ($result ne '') {
13769: $output .= '<ul>'."\n".
13770: $result."\n".
13771: '</ul>';
13772: }
13773: unless ($ishome) {
13774: my $replicationfail;
13775: foreach my $item (keys(%prompttofetch)) {
13776: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13777: unless ($fetchresult eq 'ok') {
13778: $replicationfail .= '<li>'.$item.'</li>'."\n";
13779: }
13780: }
13781: if ($replicationfail) {
13782: $output .= '<p class="LC_error">'.
13783: &mt('Course home server failed to retrieve:').'<ul>'.
13784: $replicationfail.
13785: '</ul></p>';
13786: }
13787: }
1.1055 raeburn 13788: } else {
13789: $warning = &mt('No items found in archive.');
13790: }
13791: if ($error) {
13792: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13793: $error.'</p>'."\n";
13794: }
13795: if ($warning) {
13796: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13797: }
13798: return $output;
13799: }
13800:
1.1066 raeburn 13801: sub cleanup_empty_dirs {
13802: my ($path) = @_;
13803: if (($path ne '') && (-d $path)) {
13804: if (opendir(my $dirh,$path)) {
13805: my @dircontents = grep(!/^\./,readdir($dirh));
13806: my $numitems = 0;
13807: foreach my $item (@dircontents) {
13808: if (-d "$path/$item") {
1.1075.2.28 raeburn 13809: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13810: if (-e "$path/$item") {
13811: $numitems ++;
13812: }
13813: } else {
13814: $numitems ++;
13815: }
13816: }
13817: if ($numitems == 0) {
13818: rmdir($path);
13819: }
13820: closedir($dirh);
13821: }
13822: }
13823: return;
13824: }
13825:
1.41 ng 13826: =pod
1.45 matthew 13827:
1.1075.2.56 raeburn 13828: =item * &get_folder_hierarchy()
1.1068 raeburn 13829:
13830: Provides hierarchy of names of folders/sub-folders containing the current
13831: item,
13832:
13833: Inputs: 3
13834: - $navmap - navmaps object
13835:
13836: - $map - url for map (either the trigger itself, or map containing
13837: the resource, which is the trigger).
13838:
13839: - $showitem - 1 => show title for map itself; 0 => do not show.
13840:
13841: Outputs: 1 @pathitems - array of folder/subfolder names.
13842:
13843: =cut
13844:
13845: sub get_folder_hierarchy {
13846: my ($navmap,$map,$showitem) = @_;
13847: my @pathitems;
13848: if (ref($navmap)) {
13849: my $mapres = $navmap->getResourceByUrl($map);
13850: if (ref($mapres)) {
13851: my $pcslist = $mapres->map_hierarchy();
13852: if ($pcslist ne '') {
13853: my @pcs = split(/,/,$pcslist);
13854: foreach my $pc (@pcs) {
13855: if ($pc == 1) {
1.1075.2.38 raeburn 13856: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13857: } else {
13858: my $res = $navmap->getByMapPc($pc);
13859: if (ref($res)) {
13860: my $title = $res->compTitle();
13861: $title =~ s/\W+/_/g;
13862: if ($title ne '') {
13863: push(@pathitems,$title);
13864: }
13865: }
13866: }
13867: }
13868: }
1.1071 raeburn 13869: if ($showitem) {
13870: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13871: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13872: } else {
13873: my $maptitle = $mapres->compTitle();
13874: $maptitle =~ s/\W+/_/g;
13875: if ($maptitle ne '') {
13876: push(@pathitems,$maptitle);
13877: }
1.1068 raeburn 13878: }
13879: }
13880: }
13881: }
13882: return @pathitems;
13883: }
13884:
13885: =pod
13886:
1.1015 raeburn 13887: =item * &get_turnedin_filepath()
13888:
13889: Determines path in a user's portfolio file for storage of files uploaded
13890: to a specific essayresponse or dropbox item.
13891:
13892: Inputs: 3 required + 1 optional.
13893: $symb is symb for resource, $uname and $udom are for current user (required).
13894: $caller is optional (can be "submission", if routine is called when storing
13895: an upoaded file when "Submit Answer" button was pressed).
13896:
13897: Returns array containing $path and $multiresp.
13898: $path is path in portfolio. $multiresp is 1 if this resource contains more
13899: than one file upload item. Callers of routine should append partid as a
13900: subdirectory to $path in cases where $multiresp is 1.
13901:
13902: Called by: homework/essayresponse.pm and homework/structuretags.pm
13903:
13904: =cut
13905:
13906: sub get_turnedin_filepath {
13907: my ($symb,$uname,$udom,$caller) = @_;
13908: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13909: my $turnindir;
13910: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13911: $turnindir = $userhash{'turnindir'};
13912: my ($path,$multiresp);
13913: if ($turnindir eq '') {
13914: if ($caller eq 'submission') {
13915: $turnindir = &mt('turned in');
13916: $turnindir =~ s/\W+/_/g;
13917: my %newhash = (
13918: 'turnindir' => $turnindir,
13919: );
13920: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13921: }
13922: }
13923: if ($turnindir ne '') {
13924: $path = '/'.$turnindir.'/';
13925: my ($multipart,$turnin,@pathitems);
13926: my $navmap = Apache::lonnavmaps::navmap->new();
13927: if (defined($navmap)) {
13928: my $mapres = $navmap->getResourceByUrl($map);
13929: if (ref($mapres)) {
13930: my $pcslist = $mapres->map_hierarchy();
13931: if ($pcslist ne '') {
13932: foreach my $pc (split(/,/,$pcslist)) {
13933: my $res = $navmap->getByMapPc($pc);
13934: if (ref($res)) {
13935: my $title = $res->compTitle();
13936: $title =~ s/\W+/_/g;
13937: if ($title ne '') {
1.1075.2.48 raeburn 13938: if (($pc > 1) && (length($title) > 12)) {
13939: $title = substr($title,0,12);
13940: }
1.1015 raeburn 13941: push(@pathitems,$title);
13942: }
13943: }
13944: }
13945: }
13946: my $maptitle = $mapres->compTitle();
13947: $maptitle =~ s/\W+/_/g;
13948: if ($maptitle ne '') {
1.1075.2.48 raeburn 13949: if (length($maptitle) > 12) {
13950: $maptitle = substr($maptitle,0,12);
13951: }
1.1015 raeburn 13952: push(@pathitems,$maptitle);
13953: }
13954: unless ($env{'request.state'} eq 'construct') {
13955: my $res = $navmap->getBySymb($symb);
13956: if (ref($res)) {
13957: my $partlist = $res->parts();
13958: my $totaluploads = 0;
13959: if (ref($partlist) eq 'ARRAY') {
13960: foreach my $part (@{$partlist}) {
13961: my @types = $res->responseType($part);
13962: my @ids = $res->responseIds($part);
13963: for (my $i=0; $i < scalar(@ids); $i++) {
13964: if ($types[$i] eq 'essay') {
13965: my $partid = $part.'_'.$ids[$i];
13966: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13967: $totaluploads ++;
13968: }
13969: }
13970: }
13971: }
13972: if ($totaluploads > 1) {
13973: $multiresp = 1;
13974: }
13975: }
13976: }
13977: }
13978: } else {
13979: return;
13980: }
13981: } else {
13982: return;
13983: }
13984: my $restitle=&Apache::lonnet::gettitle($symb);
13985: $restitle =~ s/\W+/_/g;
13986: if ($restitle eq '') {
13987: $restitle = ($resurl =~ m{/[^/]+$});
13988: if ($restitle eq '') {
13989: $restitle = time;
13990: }
13991: }
1.1075.2.48 raeburn 13992: if (length($restitle) > 12) {
13993: $restitle = substr($restitle,0,12);
13994: }
1.1015 raeburn 13995: push(@pathitems,$restitle);
13996: $path .= join('/',@pathitems);
13997: }
13998: return ($path,$multiresp);
13999: }
14000:
14001: =pod
14002:
1.464 albertel 14003: =back
1.41 ng 14004:
1.112 bowersj2 14005: =head1 CSV Upload/Handling functions
1.38 albertel 14006:
1.41 ng 14007: =over 4
14008:
1.648 raeburn 14009: =item * &upfile_store($r)
1.41 ng 14010:
14011: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14012: needs $env{'form.upfile'}
1.41 ng 14013: returns $datatoken to be put into hidden field
14014:
14015: =cut
1.31 albertel 14016:
14017: sub upfile_store {
14018: my $r=shift;
1.258 albertel 14019: $env{'form.upfile'}=~s/\r/\n/gs;
14020: $env{'form.upfile'}=~s/\f/\n/gs;
14021: $env{'form.upfile'}=~s/\n+/\n/gs;
14022: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14023:
1.1075.2.128 raeburn 14024: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14025: '_enroll_'.$env{'request.course.id'}.'_'.
14026: time.'_'.$$);
14027: return if ($datatoken eq '');
14028:
1.31 albertel 14029: {
1.158 raeburn 14030: my $datafile = $r->dir_config('lonDaemons').
14031: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14032: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14033: print $fh $env{'form.upfile'};
1.158 raeburn 14034: close($fh);
14035: }
1.31 albertel 14036: }
14037: return $datatoken;
14038: }
14039:
1.56 matthew 14040: =pod
14041:
1.1075.2.128 raeburn 14042: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14043:
14044: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14045: $datatoken is the name to assign to the temporary file.
1.258 albertel 14046: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14047:
14048: =cut
1.31 albertel 14049:
14050: sub load_tmp_file {
1.1075.2.128 raeburn 14051: my ($r,$datatoken) = @_;
14052: return if ($datatoken eq '');
1.31 albertel 14053: my @studentdata=();
14054: {
1.158 raeburn 14055: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14056: '/tmp/'.$datatoken.'.tmp';
14057: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14058: @studentdata=<$fh>;
14059: close($fh);
14060: }
1.31 albertel 14061: }
1.258 albertel 14062: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14063: }
14064:
1.1075.2.128 raeburn 14065: sub valid_datatoken {
14066: my ($datatoken) = @_;
1.1075.2.131 raeburn 14067: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14068: return $datatoken;
14069: }
14070: return;
14071: }
14072:
1.56 matthew 14073: =pod
14074:
1.648 raeburn 14075: =item * &upfile_record_sep()
1.41 ng 14076:
14077: Separate uploaded file into records
14078: returns array of records,
1.258 albertel 14079: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14080:
14081: =cut
1.31 albertel 14082:
14083: sub upfile_record_sep {
1.258 albertel 14084: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14085: } else {
1.248 albertel 14086: my @records;
1.258 albertel 14087: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14088: if ($line=~/^\s*$/) { next; }
14089: push(@records,$line);
14090: }
14091: return @records;
1.31 albertel 14092: }
14093: }
14094:
1.56 matthew 14095: =pod
14096:
1.648 raeburn 14097: =item * &record_sep($record)
1.41 ng 14098:
1.258 albertel 14099: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14100:
14101: =cut
14102:
1.263 www 14103: sub takeleft {
14104: my $index=shift;
14105: return substr('0000'.$index,-4,4);
14106: }
14107:
1.31 albertel 14108: sub record_sep {
14109: my $record=shift;
14110: my %components=();
1.258 albertel 14111: if ($env{'form.upfiletype'} eq 'xml') {
14112: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14113: my $i=0;
1.356 albertel 14114: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14115: $field=~s/^(\"|\')//;
14116: $field=~s/(\"|\')$//;
1.263 www 14117: $components{&takeleft($i)}=$field;
1.31 albertel 14118: $i++;
14119: }
1.258 albertel 14120: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14121: my $i=0;
1.356 albertel 14122: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14123: $field=~s/^(\"|\')//;
14124: $field=~s/(\"|\')$//;
1.263 www 14125: $components{&takeleft($i)}=$field;
1.31 albertel 14126: $i++;
14127: }
14128: } else {
1.561 www 14129: my $separator=',';
1.480 banghart 14130: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14131: $separator=';';
1.480 banghart 14132: }
1.31 albertel 14133: my $i=0;
1.561 www 14134: # the character we are looking for to indicate the end of a quote or a record
14135: my $looking_for=$separator;
14136: # do not add the characters to the fields
14137: my $ignore=0;
14138: # we just encountered a separator (or the beginning of the record)
14139: my $just_found_separator=1;
14140: # store the field we are working on here
14141: my $field='';
14142: # work our way through all characters in record
14143: foreach my $character ($record=~/(.)/g) {
14144: if ($character eq $looking_for) {
14145: if ($character ne $separator) {
14146: # Found the end of a quote, again looking for separator
14147: $looking_for=$separator;
14148: $ignore=1;
14149: } else {
14150: # Found a separator, store away what we got
14151: $components{&takeleft($i)}=$field;
14152: $i++;
14153: $just_found_separator=1;
14154: $ignore=0;
14155: $field='';
14156: }
14157: next;
14158: }
14159: # single or double quotation marks after a separator indicate beginning of a quote
14160: # we are now looking for the end of the quote and need to ignore separators
14161: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14162: $looking_for=$character;
14163: next;
14164: }
14165: # ignore would be true after we reached the end of a quote
14166: if ($ignore) { next; }
14167: if (($just_found_separator) && ($character=~/\s/)) { next; }
14168: $field.=$character;
14169: $just_found_separator=0;
1.31 albertel 14170: }
1.561 www 14171: # catch the very last entry, since we never encountered the separator
14172: $components{&takeleft($i)}=$field;
1.31 albertel 14173: }
14174: return %components;
14175: }
14176:
1.144 matthew 14177: ######################################################
14178: ######################################################
14179:
1.56 matthew 14180: =pod
14181:
1.648 raeburn 14182: =item * &upfile_select_html()
1.41 ng 14183:
1.144 matthew 14184: Return HTML code to select a file from the users machine and specify
14185: the file type.
1.41 ng 14186:
14187: =cut
14188:
1.144 matthew 14189: ######################################################
14190: ######################################################
1.31 albertel 14191: sub upfile_select_html {
1.144 matthew 14192: my %Types = (
14193: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14194: semisv => &mt('Semicolon separated values'),
1.144 matthew 14195: space => &mt('Space separated'),
14196: tab => &mt('Tabulator separated'),
14197: # xml => &mt('HTML/XML'),
14198: );
14199: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14200: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14201: foreach my $type (sort(keys(%Types))) {
14202: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14203: }
14204: $Str .= "</select>\n";
14205: return $Str;
1.31 albertel 14206: }
14207:
1.301 albertel 14208: sub get_samples {
14209: my ($records,$toget) = @_;
14210: my @samples=({});
14211: my $got=0;
14212: foreach my $rec (@$records) {
14213: my %temp = &record_sep($rec);
14214: if (! grep(/\S/, values(%temp))) { next; }
14215: if (%temp) {
14216: $samples[$got]=\%temp;
14217: $got++;
14218: if ($got == $toget) { last; }
14219: }
14220: }
14221: return \@samples;
14222: }
14223:
1.144 matthew 14224: ######################################################
14225: ######################################################
14226:
1.56 matthew 14227: =pod
14228:
1.648 raeburn 14229: =item * &csv_print_samples($r,$records)
1.41 ng 14230:
14231: Prints a table of sample values from each column uploaded $r is an
14232: Apache Request ref, $records is an arrayref from
14233: &Apache::loncommon::upfile_record_sep
14234:
14235: =cut
14236:
1.144 matthew 14237: ######################################################
14238: ######################################################
1.31 albertel 14239: sub csv_print_samples {
14240: my ($r,$records) = @_;
1.662 bisitz 14241: my $samples = &get_samples($records,5);
1.301 albertel 14242:
1.594 raeburn 14243: $r->print(&mt('Samples').'<br />'.&start_data_table().
14244: &start_data_table_header_row());
1.356 albertel 14245: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14246: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14247: $r->print(&end_data_table_header_row());
1.301 albertel 14248: foreach my $hash (@$samples) {
1.594 raeburn 14249: $r->print(&start_data_table_row());
1.356 albertel 14250: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14251: $r->print('<td>');
1.356 albertel 14252: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14253: $r->print('</td>');
14254: }
1.594 raeburn 14255: $r->print(&end_data_table_row());
1.31 albertel 14256: }
1.594 raeburn 14257: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14258: }
14259:
1.144 matthew 14260: ######################################################
14261: ######################################################
14262:
1.56 matthew 14263: =pod
14264:
1.648 raeburn 14265: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14266:
14267: Prints a table to create associations between values and table columns.
1.144 matthew 14268:
1.41 ng 14269: $r is an Apache Request ref,
14270: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14271: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14272:
14273: =cut
14274:
1.144 matthew 14275: ######################################################
14276: ######################################################
1.31 albertel 14277: sub csv_print_select_table {
14278: my ($r,$records,$d) = @_;
1.301 albertel 14279: my $i=0;
14280: my $samples = &get_samples($records,1);
1.144 matthew 14281: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14282: &start_data_table().&start_data_table_header_row().
1.144 matthew 14283: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14284: '<th>'.&mt('Column').'</th>'.
14285: &end_data_table_header_row()."\n");
1.356 albertel 14286: foreach my $array_ref (@$d) {
14287: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14288: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14289:
1.875 bisitz 14290: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14291: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14292: $r->print('<option value="none"></option>');
1.356 albertel 14293: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14294: $r->print('<option value="'.$sample.'"'.
14295: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14296: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14297: }
1.594 raeburn 14298: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14299: $i++;
14300: }
1.594 raeburn 14301: $r->print(&end_data_table());
1.31 albertel 14302: $i--;
14303: return $i;
14304: }
1.56 matthew 14305:
1.144 matthew 14306: ######################################################
14307: ######################################################
14308:
1.56 matthew 14309: =pod
1.31 albertel 14310:
1.648 raeburn 14311: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14312:
14313: Prints a table of sample values from the upload and can make associate samples to internal names.
14314:
14315: $r is an Apache Request ref,
14316: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14317: $d is an array of 2 element arrays (internal name, displayed name)
14318:
14319: =cut
14320:
1.144 matthew 14321: ######################################################
14322: ######################################################
1.31 albertel 14323: sub csv_samples_select_table {
14324: my ($r,$records,$d) = @_;
14325: my $i=0;
1.144 matthew 14326: #
1.662 bisitz 14327: my $max_samples = 5;
14328: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14329: $r->print(&start_data_table().
14330: &start_data_table_header_row().'<th>'.
14331: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14332: &end_data_table_header_row());
1.301 albertel 14333:
14334: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14335: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14336: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14337: foreach my $option (@$d) {
14338: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14339: $r->print('<option value="'.$value.'"'.
1.253 albertel 14340: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14341: $display.'</option>');
1.31 albertel 14342: }
14343: $r->print('</select></td><td>');
1.662 bisitz 14344: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14345: if (defined($samples->[$line]{$key})) {
14346: $r->print($samples->[$line]{$key}."<br />\n");
14347: }
14348: }
1.594 raeburn 14349: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14350: $i++;
14351: }
1.594 raeburn 14352: $r->print(&end_data_table());
1.31 albertel 14353: $i--;
14354: return($i);
1.115 matthew 14355: }
14356:
1.144 matthew 14357: ######################################################
14358: ######################################################
14359:
1.115 matthew 14360: =pod
14361:
1.648 raeburn 14362: =item * &clean_excel_name($name)
1.115 matthew 14363:
14364: Returns a replacement for $name which does not contain any illegal characters.
14365:
14366: =cut
14367:
1.144 matthew 14368: ######################################################
14369: ######################################################
1.115 matthew 14370: sub clean_excel_name {
14371: my ($name) = @_;
14372: $name =~ s/[:\*\?\/\\]//g;
14373: if (length($name) > 31) {
14374: $name = substr($name,0,31);
14375: }
14376: return $name;
1.25 albertel 14377: }
1.84 albertel 14378:
1.85 albertel 14379: =pod
14380:
1.648 raeburn 14381: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14382:
14383: Returns either 1 or undef
14384:
14385: 1 if the part is to be hidden, undef if it is to be shown
14386:
14387: Arguments are:
14388:
14389: $id the id of the part to be checked
14390: $symb, optional the symb of the resource to check
14391: $udom, optional the domain of the user to check for
14392: $uname, optional the username of the user to check for
14393:
14394: =cut
1.84 albertel 14395:
14396: sub check_if_partid_hidden {
14397: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14398: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14399: $symb,$udom,$uname);
1.141 albertel 14400: my $truth=1;
14401: #if the string starts with !, then the list is the list to show not hide
14402: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14403: my @hiddenlist=split(/,/,$hiddenparts);
14404: foreach my $checkid (@hiddenlist) {
1.141 albertel 14405: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14406: }
1.141 albertel 14407: return !$truth;
1.84 albertel 14408: }
1.127 matthew 14409:
1.138 matthew 14410:
14411: ############################################################
14412: ############################################################
14413:
14414: =pod
14415:
1.157 matthew 14416: =back
14417:
1.138 matthew 14418: =head1 cgi-bin script and graphing routines
14419:
1.157 matthew 14420: =over 4
14421:
1.648 raeburn 14422: =item * &get_cgi_id()
1.138 matthew 14423:
14424: Inputs: none
14425:
14426: Returns an id which can be used to pass environment variables
14427: to various cgi-bin scripts. These environment variables will
14428: be removed from the users environment after a given time by
14429: the routine &Apache::lonnet::transfer_profile_to_env.
14430:
14431: =cut
14432:
14433: ############################################################
14434: ############################################################
1.152 albertel 14435: my $uniq=0;
1.136 matthew 14436: sub get_cgi_id {
1.154 albertel 14437: $uniq=($uniq+1)%100000;
1.280 albertel 14438: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14439: }
14440:
1.127 matthew 14441: ############################################################
14442: ############################################################
14443:
14444: =pod
14445:
1.648 raeburn 14446: =item * &DrawBarGraph()
1.127 matthew 14447:
1.138 matthew 14448: Facilitates the plotting of data in a (stacked) bar graph.
14449: Puts plot definition data into the users environment in order for
14450: graph.png to plot it. Returns an <img> tag for the plot.
14451: The bars on the plot are labeled '1','2',...,'n'.
14452:
14453: Inputs:
14454:
14455: =over 4
14456:
14457: =item $Title: string, the title of the plot
14458:
14459: =item $xlabel: string, text describing the X-axis of the plot
14460:
14461: =item $ylabel: string, text describing the Y-axis of the plot
14462:
14463: =item $Max: scalar, the maximum Y value to use in the plot
14464: If $Max is < any data point, the graph will not be rendered.
14465:
1.140 matthew 14466: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14467: they are plotted. If undefined, default values will be used.
14468:
1.178 matthew 14469: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14470:
1.138 matthew 14471: =item @Values: An array of array references. Each array reference holds data
14472: to be plotted in a stacked bar chart.
14473:
1.239 matthew 14474: =item If the final element of @Values is a hash reference the key/value
14475: pairs will be added to the graph definition.
14476:
1.138 matthew 14477: =back
14478:
14479: Returns:
14480:
14481: An <img> tag which references graph.png and the appropriate identifying
14482: information for the plot.
14483:
1.127 matthew 14484: =cut
14485:
14486: ############################################################
14487: ############################################################
1.134 matthew 14488: sub DrawBarGraph {
1.178 matthew 14489: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14490: #
14491: if (! defined($colors)) {
14492: $colors = ['#33ff00',
14493: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14494: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14495: ];
14496: }
1.228 matthew 14497: my $extra_settings = {};
14498: if (ref($Values[-1]) eq 'HASH') {
14499: $extra_settings = pop(@Values);
14500: }
1.127 matthew 14501: #
1.136 matthew 14502: my $identifier = &get_cgi_id();
14503: my $id = 'cgi.'.$identifier;
1.129 matthew 14504: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14505: return '';
14506: }
1.225 matthew 14507: #
14508: my @Labels;
14509: if (defined($labels)) {
14510: @Labels = @$labels;
14511: } else {
14512: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14513: push(@Labels,$i+1);
1.225 matthew 14514: }
14515: }
14516: #
1.129 matthew 14517: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14518: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14519: my %ValuesHash;
14520: my $NumSets=1;
14521: foreach my $array (@Values) {
14522: next if (! ref($array));
1.136 matthew 14523: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14524: join(',',@$array);
1.129 matthew 14525: }
1.127 matthew 14526: #
1.136 matthew 14527: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14528: if ($NumBars < 3) {
14529: $width = 120+$NumBars*32;
1.220 matthew 14530: $xskip = 1;
1.225 matthew 14531: $bar_width = 30;
14532: } elsif ($NumBars < 5) {
14533: $width = 120+$NumBars*20;
14534: $xskip = 1;
14535: $bar_width = 20;
1.220 matthew 14536: } elsif ($NumBars < 10) {
1.136 matthew 14537: $width = 120+$NumBars*15;
14538: $xskip = 1;
14539: $bar_width = 15;
14540: } elsif ($NumBars <= 25) {
14541: $width = 120+$NumBars*11;
14542: $xskip = 5;
14543: $bar_width = 8;
14544: } elsif ($NumBars <= 50) {
14545: $width = 120+$NumBars*8;
14546: $xskip = 5;
14547: $bar_width = 4;
14548: } else {
14549: $width = 120+$NumBars*8;
14550: $xskip = 5;
14551: $bar_width = 4;
14552: }
14553: #
1.137 matthew 14554: $Max = 1 if ($Max < 1);
14555: if ( int($Max) < $Max ) {
14556: $Max++;
14557: $Max = int($Max);
14558: }
1.127 matthew 14559: $Title = '' if (! defined($Title));
14560: $xlabel = '' if (! defined($xlabel));
14561: $ylabel = '' if (! defined($ylabel));
1.369 www 14562: $ValuesHash{$id.'.title'} = &escape($Title);
14563: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14564: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14565: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14566: $ValuesHash{$id.'.NumBars'} = $NumBars;
14567: $ValuesHash{$id.'.NumSets'} = $NumSets;
14568: $ValuesHash{$id.'.PlotType'} = 'bar';
14569: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14570: $ValuesHash{$id.'.height'} = $height;
14571: $ValuesHash{$id.'.width'} = $width;
14572: $ValuesHash{$id.'.xskip'} = $xskip;
14573: $ValuesHash{$id.'.bar_width'} = $bar_width;
14574: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14575: #
1.228 matthew 14576: # Deal with other parameters
14577: while (my ($key,$value) = each(%$extra_settings)) {
14578: $ValuesHash{$id.'.'.$key} = $value;
14579: }
14580: #
1.646 raeburn 14581: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14582: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14583: }
14584:
14585: ############################################################
14586: ############################################################
14587:
14588: =pod
14589:
1.648 raeburn 14590: =item * &DrawXYGraph()
1.137 matthew 14591:
1.138 matthew 14592: Facilitates the plotting of data in an XY graph.
14593: Puts plot definition data into the users environment in order for
14594: graph.png to plot it. Returns an <img> tag for the plot.
14595:
14596: Inputs:
14597:
14598: =over 4
14599:
14600: =item $Title: string, the title of the plot
14601:
14602: =item $xlabel: string, text describing the X-axis of the plot
14603:
14604: =item $ylabel: string, text describing the Y-axis of the plot
14605:
14606: =item $Max: scalar, the maximum Y value to use in the plot
14607: If $Max is < any data point, the graph will not be rendered.
14608:
14609: =item $colors: Array ref containing the hex color codes for the data to be
14610: plotted in. If undefined, default values will be used.
14611:
14612: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14613:
14614: =item $Ydata: Array ref containing Array refs.
1.185 www 14615: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14616:
14617: =item %Values: hash indicating or overriding any default values which are
14618: passed to graph.png.
14619: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14620:
14621: =back
14622:
14623: Returns:
14624:
14625: An <img> tag which references graph.png and the appropriate identifying
14626: information for the plot.
14627:
1.137 matthew 14628: =cut
14629:
14630: ############################################################
14631: ############################################################
14632: sub DrawXYGraph {
14633: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14634: #
14635: # Create the identifier for the graph
14636: my $identifier = &get_cgi_id();
14637: my $id = 'cgi.'.$identifier;
14638: #
14639: $Title = '' if (! defined($Title));
14640: $xlabel = '' if (! defined($xlabel));
14641: $ylabel = '' if (! defined($ylabel));
14642: my %ValuesHash =
14643: (
1.369 www 14644: $id.'.title' => &escape($Title),
14645: $id.'.xlabel' => &escape($xlabel),
14646: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14647: $id.'.y_max_value'=> $Max,
14648: $id.'.labels' => join(',',@$Xlabels),
14649: $id.'.PlotType' => 'XY',
14650: );
14651: #
14652: if (defined($colors) && ref($colors) eq 'ARRAY') {
14653: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14654: }
14655: #
14656: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14657: return '';
14658: }
14659: my $NumSets=1;
1.138 matthew 14660: foreach my $array (@{$Ydata}){
1.137 matthew 14661: next if (! ref($array));
14662: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14663: }
1.138 matthew 14664: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14665: #
14666: # Deal with other parameters
14667: while (my ($key,$value) = each(%Values)) {
14668: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14669: }
14670: #
1.646 raeburn 14671: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14672: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14673: }
14674:
14675: ############################################################
14676: ############################################################
14677:
14678: =pod
14679:
1.648 raeburn 14680: =item * &DrawXYYGraph()
1.138 matthew 14681:
14682: Facilitates the plotting of data in an XY graph with two Y axes.
14683: Puts plot definition data into the users environment in order for
14684: graph.png to plot it. Returns an <img> tag for the plot.
14685:
14686: Inputs:
14687:
14688: =over 4
14689:
14690: =item $Title: string, the title of the plot
14691:
14692: =item $xlabel: string, text describing the X-axis of the plot
14693:
14694: =item $ylabel: string, text describing the Y-axis of the plot
14695:
14696: =item $colors: Array ref containing the hex color codes for the data to be
14697: plotted in. If undefined, default values will be used.
14698:
14699: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14700:
14701: =item $Ydata1: The first data set
14702:
14703: =item $Min1: The minimum value of the left Y-axis
14704:
14705: =item $Max1: The maximum value of the left Y-axis
14706:
14707: =item $Ydata2: The second data set
14708:
14709: =item $Min2: The minimum value of the right Y-axis
14710:
14711: =item $Max2: The maximum value of the left Y-axis
14712:
14713: =item %Values: hash indicating or overriding any default values which are
14714: passed to graph.png.
14715: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14716:
14717: =back
14718:
14719: Returns:
14720:
14721: An <img> tag which references graph.png and the appropriate identifying
14722: information for the plot.
1.136 matthew 14723:
14724: =cut
14725:
14726: ############################################################
14727: ############################################################
1.137 matthew 14728: sub DrawXYYGraph {
14729: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14730: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14731: #
14732: # Create the identifier for the graph
14733: my $identifier = &get_cgi_id();
14734: my $id = 'cgi.'.$identifier;
14735: #
14736: $Title = '' if (! defined($Title));
14737: $xlabel = '' if (! defined($xlabel));
14738: $ylabel = '' if (! defined($ylabel));
14739: my %ValuesHash =
14740: (
1.369 www 14741: $id.'.title' => &escape($Title),
14742: $id.'.xlabel' => &escape($xlabel),
14743: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14744: $id.'.labels' => join(',',@$Xlabels),
14745: $id.'.PlotType' => 'XY',
14746: $id.'.NumSets' => 2,
1.137 matthew 14747: $id.'.two_axes' => 1,
14748: $id.'.y1_max_value' => $Max1,
14749: $id.'.y1_min_value' => $Min1,
14750: $id.'.y2_max_value' => $Max2,
14751: $id.'.y2_min_value' => $Min2,
1.136 matthew 14752: );
14753: #
1.137 matthew 14754: if (defined($colors) && ref($colors) eq 'ARRAY') {
14755: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14756: }
14757: #
14758: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14759: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14760: return '';
14761: }
14762: my $NumSets=1;
1.137 matthew 14763: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14764: next if (! ref($array));
14765: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14766: }
14767: #
14768: # Deal with other parameters
14769: while (my ($key,$value) = each(%Values)) {
14770: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14771: }
14772: #
1.646 raeburn 14773: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14774: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14775: }
14776:
14777: ############################################################
14778: ############################################################
14779:
14780: =pod
14781:
1.157 matthew 14782: =back
14783:
1.139 matthew 14784: =head1 Statistics helper routines?
14785:
14786: Bad place for them but what the hell.
14787:
1.157 matthew 14788: =over 4
14789:
1.648 raeburn 14790: =item * &chartlink()
1.139 matthew 14791:
14792: Returns a link to the chart for a specific student.
14793:
14794: Inputs:
14795:
14796: =over 4
14797:
14798: =item $linktext: The text of the link
14799:
14800: =item $sname: The students username
14801:
14802: =item $sdomain: The students domain
14803:
14804: =back
14805:
1.157 matthew 14806: =back
14807:
1.139 matthew 14808: =cut
14809:
14810: ############################################################
14811: ############################################################
14812: sub chartlink {
14813: my ($linktext, $sname, $sdomain) = @_;
14814: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14815: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14816: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14817: '">'.$linktext.'</a>';
1.153 matthew 14818: }
14819:
14820: #######################################################
14821: #######################################################
14822:
14823: =pod
14824:
14825: =head1 Course Environment Routines
1.157 matthew 14826:
14827: =over 4
1.153 matthew 14828:
1.648 raeburn 14829: =item * &restore_course_settings()
1.153 matthew 14830:
1.648 raeburn 14831: =item * &store_course_settings()
1.153 matthew 14832:
14833: Restores/Store indicated form parameters from the course environment.
14834: Will not overwrite existing values of the form parameters.
14835:
14836: Inputs:
14837: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14838:
14839: a hash ref describing the data to be stored. For example:
14840:
14841: %Save_Parameters = ('Status' => 'scalar',
14842: 'chartoutputmode' => 'scalar',
14843: 'chartoutputdata' => 'scalar',
14844: 'Section' => 'array',
1.373 raeburn 14845: 'Group' => 'array',
1.153 matthew 14846: 'StudentData' => 'array',
14847: 'Maps' => 'array');
14848:
14849: Returns: both routines return nothing
14850:
1.631 raeburn 14851: =back
14852:
1.153 matthew 14853: =cut
14854:
14855: #######################################################
14856: #######################################################
14857: sub store_course_settings {
1.496 albertel 14858: return &store_settings($env{'request.course.id'},@_);
14859: }
14860:
14861: sub store_settings {
1.153 matthew 14862: # save to the environment
14863: # appenv the same items, just to be safe
1.300 albertel 14864: my $udom = $env{'user.domain'};
14865: my $uname = $env{'user.name'};
1.496 albertel 14866: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14867: my %SaveHash;
14868: my %AppHash;
14869: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14870: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14871: my $envname = 'environment.'.$basename;
1.258 albertel 14872: if (exists($env{'form.'.$setting})) {
1.153 matthew 14873: # Save this value away
14874: if ($type eq 'scalar' &&
1.258 albertel 14875: (! exists($env{$envname}) ||
14876: $env{$envname} ne $env{'form.'.$setting})) {
14877: $SaveHash{$basename} = $env{'form.'.$setting};
14878: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14879: } elsif ($type eq 'array') {
14880: my $stored_form;
1.258 albertel 14881: if (ref($env{'form.'.$setting})) {
1.153 matthew 14882: $stored_form = join(',',
14883: map {
1.369 www 14884: &escape($_);
1.258 albertel 14885: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14886: } else {
14887: $stored_form =
1.369 www 14888: &escape($env{'form.'.$setting});
1.153 matthew 14889: }
14890: # Determine if the array contents are the same.
1.258 albertel 14891: if ($stored_form ne $env{$envname}) {
1.153 matthew 14892: $SaveHash{$basename} = $stored_form;
14893: $AppHash{$envname} = $stored_form;
14894: }
14895: }
14896: }
14897: }
14898: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14899: $udom,$uname);
1.153 matthew 14900: if ($put_result !~ /^(ok|delayed)/) {
14901: &Apache::lonnet::logthis('unable to save form parameters, '.
14902: 'got error:'.$put_result);
14903: }
14904: # Make sure these settings stick around in this session, too
1.646 raeburn 14905: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14906: return;
14907: }
14908:
14909: sub restore_course_settings {
1.499 albertel 14910: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14911: }
14912:
14913: sub restore_settings {
14914: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14915: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14916: next if (exists($env{'form.'.$setting}));
1.496 albertel 14917: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14918: '.'.$setting;
1.258 albertel 14919: if (exists($env{$envname})) {
1.153 matthew 14920: if ($type eq 'scalar') {
1.258 albertel 14921: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14922: } elsif ($type eq 'array') {
1.258 albertel 14923: $env{'form.'.$setting} = [
1.153 matthew 14924: map {
1.369 www 14925: &unescape($_);
1.258 albertel 14926: } split(',',$env{$envname})
1.153 matthew 14927: ];
14928: }
14929: }
14930: }
1.127 matthew 14931: }
14932:
1.618 raeburn 14933: #######################################################
14934: #######################################################
14935:
14936: =pod
14937:
14938: =head1 Domain E-mail Routines
14939:
14940: =over 4
14941:
1.648 raeburn 14942: =item * &build_recipient_list()
1.618 raeburn 14943:
1.1075.2.44 raeburn 14944: Build recipient lists for following types of e-mail:
1.766 raeburn 14945: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14946: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14947: module change checking, student/employee ID conflict checks, as
14948: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14949: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14950:
14951: Inputs:
1.1075.2.44 raeburn 14952: defmail (scalar - email address of default recipient),
14953: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14954: requestsmail, updatesmail, or idconflictsmail).
14955:
1.619 raeburn 14956: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14957:
14958: origmail (scalar - email address of recipient from loncapa.conf,
14959: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14960:
1.1075.2.139 raeburn 14961: $requname username of requester (if mailing type is helpdeskmail)
14962:
14963: $requdom domain of requester (if mailing type is helpdeskmail)
14964:
14965: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14966:
1.655 raeburn 14967: Returns: comma separated list of addresses to which to send e-mail.
14968:
14969: =back
1.618 raeburn 14970:
14971: =cut
14972:
14973: ############################################################
14974: ############################################################
14975: sub build_recipient_list {
1.1075.2.139 raeburn 14976: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14977: my @recipients;
1.1075.2.122 raeburn 14978: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14979: my %domconfig =
1.1075.2.122 raeburn 14980: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14981: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14982: if (exists($domconfig{'contacts'}{$mailing})) {
14983: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14984: my @contacts = ('adminemail','supportemail');
14985: foreach my $item (@contacts) {
14986: if ($domconfig{'contacts'}{$mailing}{$item}) {
14987: my $addr = $domconfig{'contacts'}{$item};
14988: if (!grep(/^\Q$addr\E$/,@recipients)) {
14989: push(@recipients,$addr);
14990: }
1.619 raeburn 14991: }
1.1075.2.122 raeburn 14992: }
14993: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14994: if ($mailing eq 'helpdeskmail') {
14995: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14996: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14997: my @ok_bccs;
14998: foreach my $bcc (@bccs) {
14999: $bcc =~ s/^\s+//g;
15000: $bcc =~ s/\s+$//g;
15001: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15002: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15003: push(@ok_bccs,$bcc);
15004: }
15005: }
15006: }
15007: if (@ok_bccs > 0) {
15008: $allbcc = join(', ',@ok_bccs);
15009: }
15010: }
15011: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15012: }
15013: }
1.766 raeburn 15014: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15015: $lastresort = $origmail;
1.618 raeburn 15016: }
1.1075.2.139 raeburn 15017: if ($mailing eq 'helpdeskmail') {
15018: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15019: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15020: my ($inststatus,$inststatus_checked);
15021: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15022: ($env{'user.domain'} ne 'public')) {
15023: $inststatus_checked = 1;
15024: $inststatus = $env{'environment.inststatus'};
15025: }
15026: unless ($inststatus_checked) {
15027: if (($requname ne '') && ($requdom ne '')) {
15028: if (($requname =~ /^$match_username$/) &&
15029: ($requdom =~ /^$match_domain$/) &&
15030: (&Apache::lonnet::domain($requdom))) {
15031: my $requhome = &Apache::lonnet::homeserver($requname,
15032: $requdom);
15033: unless ($requhome eq 'no_host') {
15034: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15035: $inststatus = $userenv{'inststatus'};
15036: $inststatus_checked = 1;
15037: }
15038: }
15039: }
15040: }
15041: unless ($inststatus_checked) {
15042: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15043: my %srch = (srchby => 'email',
15044: srchdomain => $defdom,
15045: srchterm => $reqemail,
15046: srchtype => 'exact');
15047: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15048: foreach my $uname (keys(%srch_results)) {
15049: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15050: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15051: $inststatus_checked = 1;
15052: last;
15053: }
15054: }
15055: unless ($inststatus_checked) {
15056: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15057: if ($dirsrchres eq 'ok') {
15058: foreach my $uname (keys(%srch_results)) {
15059: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15060: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15061: $inststatus_checked = 1;
15062: last;
15063: }
15064: }
15065: }
15066: }
15067: }
15068: }
15069: if ($inststatus ne '') {
15070: foreach my $status (split(/\:/,$inststatus)) {
15071: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15072: my @contacts = ('adminemail','supportemail');
15073: foreach my $item (@contacts) {
15074: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15075: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15076: if (!grep(/^\Q$addr\E$/,@recipients)) {
15077: push(@recipients,$addr);
15078: }
15079: }
15080: }
15081: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15082: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15083: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15084: my @ok_bccs;
15085: foreach my $bcc (@bccs) {
15086: $bcc =~ s/^\s+//g;
15087: $bcc =~ s/\s+$//g;
15088: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15089: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15090: push(@ok_bccs,$bcc);
15091: }
15092: }
15093: }
15094: if (@ok_bccs > 0) {
15095: $allbcc = join(', ',@ok_bccs);
15096: }
15097: }
15098: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15099: last;
15100: }
15101: }
15102: }
15103: }
15104: }
1.619 raeburn 15105: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15106: $lastresort = $origmail;
15107: }
1.1075.2.128 raeburn 15108: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15109: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15110: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15111: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15112: my %what = (
15113: perlvar => 1,
15114: );
15115: my $primary = &Apache::lonnet::domain($defdom,'primary');
15116: if ($primary) {
15117: my $gotaddr;
15118: my ($result,$returnhash) =
15119: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15120: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15121: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15122: $lastresort = $returnhash->{'lonSupportEMail'};
15123: $gotaddr = 1;
15124: }
15125: }
15126: unless ($gotaddr) {
15127: my $uintdom = &Apache::lonnet::internet_dom($primary);
15128: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15129: unless ($uintdom eq $intdom) {
15130: my %domconfig =
15131: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15132: if (ref($domconfig{'contacts'}) eq 'HASH') {
15133: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15134: my @contacts = ('adminemail','supportemail');
15135: foreach my $item (@contacts) {
15136: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15137: my $addr = $domconfig{'contacts'}{$item};
15138: if (!grep(/^\Q$addr\E$/,@recipients)) {
15139: push(@recipients,$addr);
15140: }
15141: }
15142: }
15143: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15144: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15145: }
15146: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15147: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15148: my @ok_bccs;
15149: foreach my $bcc (@bccs) {
15150: $bcc =~ s/^\s+//g;
15151: $bcc =~ s/\s+$//g;
15152: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15153: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15154: push(@ok_bccs,$bcc);
15155: }
15156: }
15157: }
15158: if (@ok_bccs > 0) {
15159: $allbcc = join(', ',@ok_bccs);
15160: }
15161: }
15162: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15163: }
15164: }
15165: }
15166: }
15167: }
15168: }
1.618 raeburn 15169: }
1.688 raeburn 15170: if (defined($defmail)) {
15171: if ($defmail ne '') {
15172: push(@recipients,$defmail);
15173: }
1.618 raeburn 15174: }
15175: if ($otheremails) {
1.619 raeburn 15176: my @others;
15177: if ($otheremails =~ /,/) {
15178: @others = split(/,/,$otheremails);
1.618 raeburn 15179: } else {
1.619 raeburn 15180: push(@others,$otheremails);
15181: }
15182: foreach my $addr (@others) {
15183: if (!grep(/^\Q$addr\E$/,@recipients)) {
15184: push(@recipients,$addr);
15185: }
1.618 raeburn 15186: }
15187: }
1.1075.2.128 raeburn 15188: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15189: if ((!@recipients) && ($lastresort ne '')) {
15190: push(@recipients,$lastresort);
15191: }
15192: } elsif ($lastresort ne '') {
15193: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15194: push(@recipients,$lastresort);
15195: }
15196: }
15197: my $recipientlist = join(',',@recipients);
15198: if (wantarray) {
15199: return ($recipientlist,$allbcc,$addtext);
15200: } else {
15201: return $recipientlist;
15202: }
1.618 raeburn 15203: }
15204:
1.127 matthew 15205: ############################################################
15206: ############################################################
1.154 albertel 15207:
1.655 raeburn 15208: =pod
15209:
15210: =head1 Course Catalog Routines
15211:
15212: =over 4
15213:
15214: =item * &gather_categories()
15215:
15216: Converts category definitions - keys of categories hash stored in
15217: coursecategories in configuration.db on the primary library server in a
15218: domain - to an array. Also generates javascript and idx hash used to
15219: generate Domain Coordinator interface for editing Course Categories.
15220:
15221: Inputs:
1.663 raeburn 15222:
1.655 raeburn 15223: categories (reference to hash of category definitions).
1.663 raeburn 15224:
1.655 raeburn 15225: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15226: categories and subcategories).
1.663 raeburn 15227:
1.655 raeburn 15228: idx (reference to hash of counters used in Domain Coordinator interface for
15229: editing Course Categories).
1.663 raeburn 15230:
1.655 raeburn 15231: jsarray (reference to array of categories used to create Javascript arrays for
15232: Domain Coordinator interface for editing Course Categories).
15233:
15234: Returns: nothing
15235:
15236: Side effects: populates cats, idx and jsarray.
15237:
15238: =cut
15239:
15240: sub gather_categories {
15241: my ($categories,$cats,$idx,$jsarray) = @_;
15242: my %counters;
15243: my $num = 0;
15244: foreach my $item (keys(%{$categories})) {
15245: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15246: if ($container eq '' && $depth == 0) {
15247: $cats->[$depth][$categories->{$item}] = $cat;
15248: } else {
15249: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15250: }
15251: my ($escitem,$tail) = split(/:/,$item,2);
15252: if ($counters{$tail} eq '') {
15253: $counters{$tail} = $num;
15254: $num ++;
15255: }
15256: if (ref($idx) eq 'HASH') {
15257: $idx->{$item} = $counters{$tail};
15258: }
15259: if (ref($jsarray) eq 'ARRAY') {
15260: push(@{$jsarray->[$counters{$tail}]},$item);
15261: }
15262: }
15263: return;
15264: }
15265:
15266: =pod
15267:
15268: =item * &extract_categories()
15269:
15270: Used to generate breadcrumb trails for course categories.
15271:
15272: Inputs:
1.663 raeburn 15273:
1.655 raeburn 15274: categories (reference to hash of category definitions).
1.663 raeburn 15275:
1.655 raeburn 15276: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15277: categories and subcategories).
1.663 raeburn 15278:
1.655 raeburn 15279: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15280:
1.655 raeburn 15281: allitems (reference to hash - key is category key
15282: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15283:
1.655 raeburn 15284: idx (reference to hash of counters used in Domain Coordinator interface for
15285: editing Course Categories).
1.663 raeburn 15286:
1.655 raeburn 15287: jsarray (reference to array of categories used to create Javascript arrays for
15288: Domain Coordinator interface for editing Course Categories).
15289:
1.665 raeburn 15290: subcats (reference to hash of arrays containing all subcategories within each
15291: category, -recursive)
15292:
1.1075.2.132 raeburn 15293: maxd (reference to hash used to hold max depth for all top-level categories).
15294:
1.655 raeburn 15295: Returns: nothing
15296:
15297: Side effects: populates trails and allitems hash references.
15298:
15299: =cut
15300:
15301: sub extract_categories {
1.1075.2.132 raeburn 15302: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15303: if (ref($categories) eq 'HASH') {
15304: &gather_categories($categories,$cats,$idx,$jsarray);
15305: if (ref($cats->[0]) eq 'ARRAY') {
15306: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15307: my $name = $cats->[0][$i];
15308: my $item = &escape($name).'::0';
15309: my $trailstr;
15310: if ($name eq 'instcode') {
15311: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15312: } elsif ($name eq 'communities') {
15313: $trailstr = &mt('Communities');
1.655 raeburn 15314: } else {
15315: $trailstr = $name;
15316: }
15317: if ($allitems->{$item} eq '') {
15318: push(@{$trails},$trailstr);
15319: $allitems->{$item} = scalar(@{$trails})-1;
15320: }
15321: my @parents = ($name);
15322: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15323: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15324: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15325: if (ref($subcats) eq 'HASH') {
15326: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15327: }
1.1075.2.132 raeburn 15328: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15329: }
15330: } else {
15331: if (ref($subcats) eq 'HASH') {
15332: $subcats->{$item} = [];
1.655 raeburn 15333: }
1.1075.2.132 raeburn 15334: if (ref($maxd) eq 'HASH') {
15335: $maxd->{$name} = 1;
15336: }
1.655 raeburn 15337: }
15338: }
15339: }
15340: }
15341: return;
15342: }
15343:
15344: =pod
15345:
1.1075.2.56 raeburn 15346: =item * &recurse_categories()
1.655 raeburn 15347:
15348: Recursively used to generate breadcrumb trails for course categories.
15349:
15350: Inputs:
1.663 raeburn 15351:
1.655 raeburn 15352: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15353: categories and subcategories).
1.663 raeburn 15354:
1.655 raeburn 15355: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15356:
15357: category (current course category, for which breadcrumb trail is being generated).
15358:
15359: trails (reference to array of breadcrumb trails for each category).
15360:
1.655 raeburn 15361: allitems (reference to hash - key is category key
15362: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15363:
1.655 raeburn 15364: parents (array containing containers directories for current category,
15365: back to top level).
15366:
15367: Returns: nothing
15368:
15369: Side effects: populates trails and allitems hash references
15370:
15371: =cut
15372:
15373: sub recurse_categories {
1.1075.2.132 raeburn 15374: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15375: my $shallower = $depth - 1;
15376: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15377: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15378: my $name = $cats->[$depth]{$category}[$k];
15379: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 15380:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15381: if ($allitems->{$item} eq '') {
15382: push(@{$trails},$trailstr);
15383: $allitems->{$item} = scalar(@{$trails})-1;
15384: }
15385: my $deeper = $depth+1;
15386: push(@{$parents},$category);
1.665 raeburn 15387: if (ref($subcats) eq 'HASH') {
15388: my $subcat = &escape($name).':'.$category.':'.$depth;
15389: for (my $j=@{$parents}; $j>=0; $j--) {
15390: my $higher;
15391: if ($j > 0) {
15392: $higher = &escape($parents->[$j]).':'.
15393: &escape($parents->[$j-1]).':'.$j;
15394: } else {
15395: $higher = &escape($parents->[$j]).'::'.$j;
15396: }
15397: push(@{$subcats->{$higher}},$subcat);
15398: }
15399: }
15400: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 15401: $subcats,$maxd);
1.655 raeburn 15402: pop(@{$parents});
15403: }
15404: } else {
15405: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 15406: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15407: if ($allitems->{$item} eq '') {
15408: push(@{$trails},$trailstr);
15409: $allitems->{$item} = scalar(@{$trails})-1;
15410: }
1.1075.2.132 raeburn 15411: if (ref($maxd) eq 'HASH') {
15412: if ($depth > $maxd->{$parents->[0]}) {
15413: $maxd->{$parents->[0]} = $depth;
15414: }
15415: }
1.655 raeburn 15416: }
15417: return;
15418: }
15419:
1.663 raeburn 15420: =pod
15421:
1.1075.2.56 raeburn 15422: =item * &assign_categories_table()
1.663 raeburn 15423:
15424: Create a datatable for display of hierarchical categories in a domain,
15425: with checkboxes to allow a course to be categorized.
15426:
15427: Inputs:
15428:
15429: cathash - reference to hash of categories defined for the domain (from
15430: configuration.db)
15431:
15432: currcat - scalar with an & separated list of categories assigned to a course.
15433:
1.919 raeburn 15434: type - scalar contains course type (Course or Community).
15435:
1.1075.2.117 raeburn 15436: disabled - scalar (optional) contains disabled="disabled" if input elements are
15437: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15438:
1.663 raeburn 15439: Returns: $output (markup to be displayed)
15440:
15441: =cut
15442:
15443: sub assign_categories_table {
1.1075.2.117 raeburn 15444: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15445: my $output;
15446: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 15447: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15448: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15449: $maxdepth = scalar(@cats);
15450: if (@cats > 0) {
15451: my $itemcount = 0;
15452: if (ref($cats[0]) eq 'ARRAY') {
15453: my @currcategories;
15454: if ($currcat ne '') {
15455: @currcategories = split('&',$currcat);
15456: }
1.919 raeburn 15457: my $table;
1.663 raeburn 15458: for (my $i=0; $i<@{$cats[0]}; $i++) {
15459: my $parent = $cats[0][$i];
1.919 raeburn 15460: next if ($parent eq 'instcode');
15461: if ($type eq 'Community') {
15462: next unless ($parent eq 'communities');
15463: } else {
15464: next if ($parent eq 'communities');
15465: }
1.663 raeburn 15466: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15467: my $item = &escape($parent).'::0';
15468: my $checked = '';
15469: if (@currcategories > 0) {
15470: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15471: $checked = ' checked="checked"';
1.663 raeburn 15472: }
15473: }
1.919 raeburn 15474: my $parent_title = $parent;
15475: if ($parent eq 'communities') {
15476: $parent_title = &mt('Communities');
15477: }
15478: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15479: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15480: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15481: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15482: my $depth = 1;
15483: push(@path,$parent);
1.1075.2.117 raeburn 15484: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15485: pop(@path);
1.919 raeburn 15486: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15487: $itemcount ++;
15488: }
1.919 raeburn 15489: if ($itemcount) {
15490: $output = &Apache::loncommon::start_data_table().
15491: $table.
15492: &Apache::loncommon::end_data_table();
15493: }
1.663 raeburn 15494: }
15495: }
15496: }
15497: return $output;
15498: }
15499:
15500: =pod
15501:
1.1075.2.56 raeburn 15502: =item * &assign_category_rows()
1.663 raeburn 15503:
15504: Create a datatable row for display of nested categories in a domain,
15505: with checkboxes to allow a course to be categorized,called recursively.
15506:
15507: Inputs:
15508:
15509: itemcount - track row number for alternating colors
15510:
15511: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15512: categories and subcategories.
15513:
15514: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15515:
15516: parent - parent of current category item
15517:
15518: path - Array containing all categories back up through the hierarchy from the
15519: current category to the top level.
15520:
15521: currcategories - reference to array of current categories assigned to the course
15522:
1.1075.2.117 raeburn 15523: disabled - scalar (optional) contains disabled="disabled" if input elements are
15524: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15525:
1.663 raeburn 15526: Returns: $output (markup to be displayed).
15527:
15528: =cut
15529:
15530: sub assign_category_rows {
1.1075.2.117 raeburn 15531: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15532: my ($text,$name,$item,$chgstr);
15533: if (ref($cats) eq 'ARRAY') {
15534: my $maxdepth = scalar(@{$cats});
15535: if (ref($cats->[$depth]) eq 'HASH') {
15536: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15537: my $numchildren = @{$cats->[$depth]{$parent}};
15538: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15539: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15540: for (my $j=0; $j<$numchildren; $j++) {
15541: $name = $cats->[$depth]{$parent}[$j];
15542: $item = &escape($name).':'.&escape($parent).':'.$depth;
15543: my $deeper = $depth+1;
15544: my $checked = '';
15545: if (ref($currcategories) eq 'ARRAY') {
15546: if (@{$currcategories} > 0) {
15547: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15548: $checked = ' checked="checked"';
1.663 raeburn 15549: }
15550: }
15551: }
1.664 raeburn 15552: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15553: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15554: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15555: '<input type="hidden" name="catname" value="'.$name.'" />'.
15556: '</td><td>';
1.663 raeburn 15557: if (ref($path) eq 'ARRAY') {
15558: push(@{$path},$name);
1.1075.2.117 raeburn 15559: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15560: pop(@{$path});
15561: }
15562: $text .= '</td></tr>';
15563: }
15564: $text .= '</table></td>';
15565: }
15566: }
15567: }
15568: return $text;
15569: }
15570:
1.1075.2.69 raeburn 15571: =pod
15572:
15573: =back
15574:
15575: =cut
15576:
1.655 raeburn 15577: ############################################################
15578: ############################################################
15579:
15580:
1.443 albertel 15581: sub commit_customrole {
1.664 raeburn 15582: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15583: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15584: ($start?', '.&mt('starting').' '.localtime($start):'').
15585: ($end?', ending '.localtime($end):'').': <b>'.
15586: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15587: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15588: '</b><br />';
15589: return $output;
15590: }
15591:
15592: sub commit_standardrole {
1.1075.2.31 raeburn 15593: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15594: my ($output,$logmsg,$linefeed);
15595: if ($context eq 'auto') {
15596: $linefeed = "\n";
15597: } else {
15598: $linefeed = "<br />\n";
15599: }
1.443 albertel 15600: if ($three eq 'st') {
1.541 raeburn 15601: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15602: $one,$two,$sec,$context,$credits);
1.541 raeburn 15603: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15604: ($result eq 'unknown_course') || ($result eq 'refused')) {
15605: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15606: } else {
1.541 raeburn 15607: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15608: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15609: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15610: if ($context eq 'auto') {
15611: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15612: } else {
15613: $output .= '<b>'.$result.'</b>'.$linefeed.
15614: &mt('Add to classlist').': <b>ok</b>';
15615: }
15616: $output .= $linefeed;
1.443 albertel 15617: }
15618: } else {
15619: $output = &mt('Assigning').' '.$three.' in '.$url.
15620: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15621: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15622: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15623: if ($context eq 'auto') {
15624: $output .= $result.$linefeed;
15625: } else {
15626: $output .= '<b>'.$result.'</b>'.$linefeed;
15627: }
1.443 albertel 15628: }
15629: return $output;
15630: }
15631:
15632: sub commit_studentrole {
1.1075.2.31 raeburn 15633: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15634: $credits) = @_;
1.626 raeburn 15635: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15636: if ($context eq 'auto') {
15637: $linefeed = "\n";
15638: } else {
15639: $linefeed = '<br />'."\n";
15640: }
1.443 albertel 15641: if (defined($one) && defined($two)) {
15642: my $cid=$one.'_'.$two;
15643: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15644: my $secchange = 0;
15645: my $expire_role_result;
15646: my $modify_section_result;
1.628 raeburn 15647: if ($oldsec ne '-1') {
15648: if ($oldsec ne $sec) {
1.443 albertel 15649: $secchange = 1;
1.628 raeburn 15650: my $now = time;
1.443 albertel 15651: my $uurl='/'.$cid;
15652: $uurl=~s/\_/\//g;
15653: if ($oldsec) {
15654: $uurl.='/'.$oldsec;
15655: }
1.626 raeburn 15656: $oldsecurl = $uurl;
1.628 raeburn 15657: $expire_role_result =
1.652 raeburn 15658: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15659: if ($env{'request.course.sec'} ne '') {
15660: if ($expire_role_result eq 'refused') {
15661: my @roles = ('st');
15662: my @statuses = ('previous');
15663: my @roledoms = ($one);
15664: my $withsec = 1;
15665: my %roleshash =
15666: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15667: \@statuses,\@roles,\@roledoms,$withsec);
15668: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15669: my ($oldstart,$oldend) =
15670: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15671: if ($oldend > 0 && $oldend <= $now) {
15672: $expire_role_result = 'ok';
15673: }
15674: }
15675: }
15676: }
1.443 albertel 15677: $result = $expire_role_result;
15678: }
15679: }
15680: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15681: $modify_section_result =
15682: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15683: undef,undef,undef,$sec,
15684: $end,$start,'','',$cid,
15685: '',$context,$credits);
1.443 albertel 15686: if ($modify_section_result =~ /^ok/) {
15687: if ($secchange == 1) {
1.628 raeburn 15688: if ($sec eq '') {
15689: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15690: } else {
15691: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15692: }
1.443 albertel 15693: } elsif ($oldsec eq '-1') {
1.628 raeburn 15694: if ($sec eq '') {
15695: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15696: } else {
15697: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15698: }
1.443 albertel 15699: } else {
1.628 raeburn 15700: if ($sec eq '') {
15701: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15702: } else {
15703: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15704: }
1.443 albertel 15705: }
15706: } else {
1.628 raeburn 15707: if ($secchange) {
15708: $$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;
15709: } else {
15710: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15711: }
1.443 albertel 15712: }
15713: $result = $modify_section_result;
15714: } elsif ($secchange == 1) {
1.628 raeburn 15715: if ($oldsec eq '') {
1.1075.2.20 raeburn 15716: $$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 15717: } else {
15718: $$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;
15719: }
1.626 raeburn 15720: if ($expire_role_result eq 'refused') {
15721: my $newsecurl = '/'.$cid;
15722: $newsecurl =~ s/\_/\//g;
15723: if ($sec ne '') {
15724: $newsecurl.='/'.$sec;
15725: }
15726: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15727: if ($sec eq '') {
15728: $$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;
15729: } else {
15730: $$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;
15731: }
15732: }
15733: }
1.443 albertel 15734: }
15735: } else {
1.626 raeburn 15736: $$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 15737: $result = "error: incomplete course id\n";
15738: }
15739: return $result;
15740: }
15741:
1.1075.2.25 raeburn 15742: sub show_role_extent {
15743: my ($scope,$context,$role) = @_;
15744: $scope =~ s{^/}{};
15745: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15746: push(@courseroles,'co');
15747: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15748: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15749: $scope =~ s{/}{_};
15750: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15751: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15752: my ($audom,$auname) = split(/\//,$scope);
15753: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15754: &Apache::loncommon::plainname($auname,$audom).'</span>');
15755: } else {
15756: $scope =~ s{/$}{};
15757: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15758: &Apache::lonnet::domain($scope,'description').'</span>');
15759: }
15760: }
15761:
1.443 albertel 15762: ############################################################
15763: ############################################################
15764:
1.566 albertel 15765: sub check_clone {
1.578 raeburn 15766: my ($args,$linefeed) = @_;
1.566 albertel 15767: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15768: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15769: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 15770:21): my $clonetitle;
15771:21): my @clonemsg;
1.566 albertel 15772: my $can_clone = 0;
1.944 raeburn 15773: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15774: if ($lctype ne 'community') {
15775: $lctype = 'course';
15776: }
1.566 albertel 15777: if ($clonehome eq 'no_host') {
1.944 raeburn 15778: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 15779:21): push(@clonemsg,({
15780:21): mt => 'No new community created.',
15781:21): args => [],
15782:21): },
15783:21): {
15784:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15785:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15786:21): }));
1.908 raeburn 15787: } else {
1.1075.2.161. .1(raebu 15788:21): push(@clonemsg,({
15789:21): mt => 'No new course created.',
15790:21): args => [],
15791:21): },
15792:21): {
15793:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15794:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15795:21): }));
15796:21): }
1.566 albertel 15797: } else {
15798: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 15799:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 15800: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15801: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 15802:21): push(@clonemsg,({
15803:21): mt => 'No new community created.',
15804:21): args => [],
15805:21): },
15806:21): {
15807:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
15808:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15809:21): }));
15810:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 15811: }
15812: }
1.1075.2.119 raeburn 15813: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15814: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15815: $can_clone = 1;
15816: } else {
1.1075.2.95 raeburn 15817: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15818: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15819: if ($clonehash{'cloners'} eq '') {
15820: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15821: if ($domdefs{'canclone'}) {
15822: unless ($domdefs{'canclone'} eq 'none') {
15823: if ($domdefs{'canclone'} eq 'domain') {
15824: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15825: $can_clone = 1;
15826: }
15827: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15828: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15829: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15830: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15831: $can_clone = 1;
15832: }
15833: }
15834: }
1.908 raeburn 15835: }
1.1075.2.95 raeburn 15836: } else {
15837: my @cloners = split(/,/,$clonehash{'cloners'});
15838: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15839: $can_clone = 1;
1.1075.2.95 raeburn 15840: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15841: $can_clone = 1;
1.1075.2.96 raeburn 15842: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15843: $can_clone = 1;
1.1075.2.95 raeburn 15844: }
15845: unless ($can_clone) {
1.1075.2.96 raeburn 15846: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15847: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15848: my (%gotdomdefaults,%gotcodedefaults);
15849: foreach my $cloner (@cloners) {
15850: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15851: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15852: my (%codedefaults,@code_order);
15853: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15854: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15855: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15856: }
15857: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15858: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15859: }
15860: } else {
15861: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15862: \%codedefaults,
15863: \@code_order);
15864: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15865: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15866: }
15867: if (@code_order > 0) {
15868: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15869: $cloner,$clonehash{'internal.coursecode'},
15870: $args->{'crscode'})) {
15871: $can_clone = 1;
15872: last;
15873: }
15874: }
15875: }
15876: }
15877: }
1.1075.2.96 raeburn 15878: }
15879: }
15880: unless ($can_clone) {
15881: my $ccrole = 'cc';
15882: if ($args->{'crstype'} eq 'Community') {
15883: $ccrole = 'co';
15884: }
15885: my %roleshash =
15886: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15887: $args->{'ccdomain'},
15888: 'userroles',['active'],[$ccrole],
15889: [$args->{'clonedomain'}]);
15890: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15891: $can_clone = 1;
15892: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15893: $args->{'ccuname'},$args->{'ccdomain'})) {
15894: $can_clone = 1;
1.1075.2.95 raeburn 15895: }
15896: }
15897: unless ($can_clone) {
15898: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 15899:21): push(@clonemsg,({
15900:21): mt => 'No new community created.',
15901:21): args => [],
15902:21): },
15903:21): {
15904:21): 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]).',
15905:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15906:21): }));
1.1075.2.95 raeburn 15907: } else {
1.1075.2.161. .1(raebu 15908:21): push(@clonemsg,({
15909:21): mt => 'No new course created.',
15910:21): args => [],
15911:21): },
15912:21): {
15913:21): 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]).',
15914:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15915:21): }));
1.578 raeburn 15916: }
1.566 albertel 15917: }
1.578 raeburn 15918: }
1.566 albertel 15919: }
1.1075.2.161. .1(raebu 15920:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15921: }
15922:
1.444 albertel 15923: sub construct_course {
1.1075.2.119 raeburn 15924: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 15925:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
15926:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 15927: my $linefeed = '<br />'."\n";
15928: if ($context eq 'auto') {
15929: $linefeed = "\n";
15930: }
1.566 albertel 15931:
15932: #
15933: # Are we cloning?
15934: #
1.1075.2.161. .1(raebu 15935:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15936: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 15937:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 15938: if (!$can_clone) {
1.1075.2.161. .1(raebu 15939:21): return (0,$outcome,$clonemsgref);
1.566 albertel 15940: }
15941: }
15942:
1.444 albertel 15943: #
15944: # Open course
15945: #
15946: my $crstype = lc($args->{'crstype'});
15947: my %cenv=();
15948: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15949: $args->{'cdescr'},
15950: $args->{'curl'},
15951: $args->{'course_home'},
15952: $args->{'nonstandard'},
15953: $args->{'crscode'},
15954: $args->{'ccuname'}.':'.
15955: $args->{'ccdomain'},
1.882 raeburn 15956: $args->{'crstype'},
1.1075.2.161. .1(raebu 15957:21): $cnum,$context,$category,
15958:21): $callercontext);
1.444 albertel 15959:
15960: # Note: The testing routines depend on this being output; see
15961: # Utils::Course. This needs to at least be output as a comment
15962: # if anyone ever decides to not show this, and Utils::Course::new
15963: # will need to be suitably modified.
1.1075.2.161. .1(raebu 15964:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15965:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15966:21): } else {
15967:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15968:21): }
1.943 raeburn 15969: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 15970:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 15971: }
15972:
1.444 albertel 15973: #
15974: # Check if created correctly
15975: #
1.479 albertel 15976: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15977: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15978: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 15979:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15980:21): $outcome .= &mt_user($user_lh,
15981:21): 'Course creation failed, unrecognized course home server.');
15982:21): } else {
15983:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
15984:21): }
15985:21): $outcome .= $linefeed;
15986:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 15987: }
1.541 raeburn 15988: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15989:
1.444 albertel 15990: #
1.566 albertel 15991: # Do the cloning
1.1075.2.161. .1(raebu 15992:21): #
15993:21): my @clonemsg;
1.566 albertel 15994: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 15995:21): push(@clonemsg,
15996:21): {
15997:21): mt => 'Created [_1] by cloning from [_2]',
15998:21): args => [$crstype,$clonetitle],
15999:21): });
1.566 albertel 16000: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16001: # Copy all files
1.1075.2.161. .1(raebu 16002:21): my @info =
16003:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16004:21): $args->{'dateshift'},$args->{'crscode'},
16005:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16006:21): $args->{'tinyurls'});
16007:21): if (@info) {
16008:21): push(@clonemsg,@info);
16009:21): }
1.444 albertel 16010: # Restore URL
1.566 albertel 16011: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16012: # Restore title
1.566 albertel 16013: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16014: # Restore creation date, creator and creation context.
16015: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16016: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16017: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16018: # Mark as cloned
1.566 albertel 16019: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16020: # Need to clone grading mode
16021: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16022: $cenv{'grading'}=$newenv{'grading'};
16023: # Do not clone these environment entries
16024: &Apache::lonnet::del('environment',
16025: ['default_enrollment_start_date',
16026: 'default_enrollment_end_date',
16027: 'question.email',
16028: 'policy.email',
16029: 'comment.email',
16030: 'pch.users.denied',
1.725 raeburn 16031: 'plc.users.denied',
16032: 'hidefromcat',
1.1075.2.36 raeburn 16033: 'checkforpriv',
1.1075.2.158 raeburn 16034: 'categories'],
1.638 www 16035: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16036: if ($args->{'textbook'}) {
16037: $cenv{'internal.textbook'} = $args->{'textbook'};
16038: }
1.444 albertel 16039: }
1.566 albertel 16040:
1.444 albertel 16041: #
16042: # Set environment (will override cloned, if existing)
16043: #
16044: my @sections = ();
16045: my @xlists = ();
16046: if ($args->{'crstype'}) {
16047: $cenv{'type'}=$args->{'crstype'};
16048: }
16049: if ($args->{'crsid'}) {
16050: $cenv{'courseid'}=$args->{'crsid'};
16051: }
16052: if ($args->{'crscode'}) {
16053: $cenv{'internal.coursecode'}=$args->{'crscode'};
16054: }
16055: if ($args->{'crsquota'} ne '') {
16056: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16057: } else {
16058: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16059: }
16060: if ($args->{'ccuname'}) {
16061: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16062: ':'.$args->{'ccdomain'};
16063: } else {
16064: $cenv{'internal.courseowner'} = $args->{'curruser'};
16065: }
1.1075.2.31 raeburn 16066: if ($args->{'defaultcredits'}) {
16067: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16068: }
1.444 albertel 16069: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16070: if ($args->{'crssections'}) {
16071: $cenv{'internal.sectionnums'} = '';
16072: if ($args->{'crssections'} =~ m/,/) {
16073: @sections = split/,/,$args->{'crssections'};
16074: } else {
16075: $sections[0] = $args->{'crssections'};
16076: }
16077: if (@sections > 0) {
16078: foreach my $item (@sections) {
16079: my ($sec,$gp) = split/:/,$item;
16080: my $class = $args->{'crscode'}.$sec;
16081: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16082: $cenv{'internal.sectionnums'} .= $item.',';
16083: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 16084: push(@badclasses,$class);
1.444 albertel 16085: }
16086: }
16087: $cenv{'internal.sectionnums'} =~ s/,$//;
16088: }
16089: }
16090: # do not hide course coordinator from staff listing,
16091: # even if privileged
16092: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16093: # add course coordinator's domain to domains to check for privileged users
16094: # if different to course domain
16095: if ($$crsudom ne $args->{'ccdomain'}) {
16096: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16097: }
1.444 albertel 16098: # add crosslistings
16099: if ($args->{'crsxlist'}) {
16100: $cenv{'internal.crosslistings'}='';
16101: if ($args->{'crsxlist'} =~ m/,/) {
16102: @xlists = split/,/,$args->{'crsxlist'};
16103: } else {
16104: $xlists[0] = $args->{'crsxlist'};
16105: }
16106: if (@xlists > 0) {
16107: foreach my $item (@xlists) {
16108: my ($xl,$gp) = split/:/,$item;
16109: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16110: $cenv{'internal.crosslistings'} .= $item.',';
16111: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 16112: push(@badclasses,$xl);
1.444 albertel 16113: }
16114: }
16115: $cenv{'internal.crosslistings'} =~ s/,$//;
16116: }
16117: }
16118: if ($args->{'autoadds'}) {
16119: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16120: }
16121: if ($args->{'autodrops'}) {
16122: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16123: }
16124: # check for notification of enrollment changes
16125: my @notified = ();
16126: if ($args->{'notify_owner'}) {
16127: if ($args->{'ccuname'} ne '') {
16128: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16129: }
16130: }
16131: if ($args->{'notify_dc'}) {
16132: if ($uname ne '') {
1.630 raeburn 16133: push(@notified,$uname.':'.$udom);
1.444 albertel 16134: }
16135: }
16136: if (@notified > 0) {
16137: my $notifylist;
16138: if (@notified > 1) {
16139: $notifylist = join(',',@notified);
16140: } else {
16141: $notifylist = $notified[0];
16142: }
16143: $cenv{'internal.notifylist'} = $notifylist;
16144: }
16145: if (@badclasses > 0) {
16146: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16147: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16148: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16149: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16150: );
1.1075.2.119 raeburn 16151: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16152: &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 16153: if ($context eq 'auto') {
16154: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16155: } else {
1.566 albertel 16156: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16157: }
16158: foreach my $item (@badclasses) {
1.541 raeburn 16159: if ($context eq 'auto') {
1.1075.2.119 raeburn 16160: $outcome .= " - $item\n";
1.541 raeburn 16161: } else {
1.1075.2.119 raeburn 16162: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16163: }
1.1075.2.119 raeburn 16164: }
16165: if ($context eq 'auto') {
16166: $outcome .= $linefeed;
16167: } else {
16168: $outcome .= "</ul><br /><br /></div>\n";
16169: }
1.444 albertel 16170: }
16171: if ($args->{'no_end_date'}) {
16172: $args->{'endaccess'} = 0;
16173: }
16174: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16175: $cenv{'internal.autoend'}=$args->{'enrollend'};
16176: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16177: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16178: if ($args->{'showphotos'}) {
16179: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16180: }
16181: $cenv{'internal.authtype'} = $args->{'authtype'};
16182: $cenv{'internal.autharg'} = $args->{'autharg'};
16183: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16184: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16185: 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');
16186: if ($context eq 'auto') {
16187: $outcome .= $krb_msg;
16188: } else {
1.566 albertel 16189: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16190: }
16191: $outcome .= $linefeed;
1.444 albertel 16192: }
16193: }
16194: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16195: if ($args->{'setpolicy'}) {
16196: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16197: }
16198: if ($args->{'setcontent'}) {
16199: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16200: }
1.1075.2.110 raeburn 16201: if ($args->{'setcomment'}) {
16202: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16203: }
1.444 albertel 16204: }
16205: if ($args->{'reshome'}) {
16206: $cenv{'reshome'}=$args->{'reshome'}.'/';
16207: $cenv{'reshome'}=~s/\/+$/\//;
16208: }
16209: #
16210: # course has keyed access
16211: #
16212: if ($args->{'setkeys'}) {
16213: $cenv{'keyaccess'}='yes';
16214: }
16215: # if specified, key authority is not course, but user
16216: # only active if keyaccess is yes
16217: if ($args->{'keyauth'}) {
1.487 albertel 16218: my ($user,$domain) = split(':',$args->{'keyauth'});
16219: $user = &LONCAPA::clean_username($user);
16220: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16221: if ($user ne '' && $domain ne '') {
1.487 albertel 16222: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16223: }
16224: }
16225:
1.1075.2.59 raeburn 16226: #
16227: # generate and store uniquecode (available to course requester), if course should have one.
16228: #
16229: if ($args->{'uniquecode'}) {
16230: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16231: if ($code) {
16232: $cenv{'internal.uniquecode'} = $code;
16233: my %crsinfo =
16234: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16235: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16236: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16237: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16238: }
16239: if (ref($coderef)) {
16240: $$coderef = $code;
16241: }
16242: }
16243: }
16244:
1.444 albertel 16245: if ($args->{'disresdis'}) {
16246: $cenv{'pch.roles.denied'}='st';
16247: }
16248: if ($args->{'disablechat'}) {
16249: $cenv{'plc.roles.denied'}='st';
16250: }
16251:
16252: # Record we've not yet viewed the Course Initialization Helper for this
16253: # course
16254: $cenv{'course.helper.not.run'} = 1;
16255: #
16256: # Use new Randomseed
16257: #
16258: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16259: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16260: #
16261: # The encryption code and receipt prefix for this course
16262: #
16263: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16264: $cenv{'internal.encpref'}=100+int(9*rand(99));
16265: #
16266: # By default, use standard grading
16267: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16268:
1.541 raeburn 16269: $outcome .= $linefeed.&mt('Setting environment').': '.
16270: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16271: #
16272: # Open all assignments
16273: #
16274: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16275: my $opendate = time;
16276: if ($args->{'openallfrom'} =~ /^\d+$/) {
16277: $opendate = $args->{'openallfrom'};
16278: }
1.444 albertel 16279: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16280: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16281: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16282: $outcome .= &mt('All assignments open starting [_1]',
16283: &Apache::lonlocal::locallocaltime($opendate)).': '.
16284: &Apache::lonnet::cput
16285: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16286: }
16287: #
16288: # Set first page
16289: #
16290: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16291: || ($cloneid)) {
1.445 albertel 16292: use LONCAPA::map;
1.444 albertel 16293: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16294:
16295: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16296: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16297:
1.444 albertel 16298: $outcome .= ($fatal?$errtext:'read ok').' - ';
16299: my $title; my $url;
16300: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16301: $title=&mt('Syllabus');
1.444 albertel 16302: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16303: } else {
1.963 raeburn 16304: $title=&mt('Table of Contents');
1.444 albertel 16305: $url='/adm/navmaps';
16306: }
1.445 albertel 16307:
16308: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16309: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16310:
16311: if ($errtext) { $fatal=2; }
1.541 raeburn 16312: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16313: }
1.566 albertel 16314:
1.1075.2.161. .1(raebu 16315:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16316: }
16317:
1.1075.2.59 raeburn 16318: sub make_unique_code {
16319: my ($cdom,$cnum) = @_;
16320: # get lock on uniquecodes db
16321: my $lockhash = {
16322: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16323: ':'.$env{'user.domain'},
16324: };
16325: my $tries = 0;
16326: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16327: my ($code,$error);
16328:
16329: while (($gotlock ne 'ok') && ($tries<3)) {
16330: $tries ++;
16331: sleep 1;
16332: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16333: }
16334: if ($gotlock eq 'ok') {
16335: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16336: my $gotcode;
16337: my $attempts = 0;
16338: while ((!$gotcode) && ($attempts < 100)) {
16339: $code = &generate_code();
16340: if (!exists($currcodes{$code})) {
16341: $gotcode = 1;
16342: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16343: $error = 'nostore';
16344: }
16345: }
16346: $attempts ++;
16347: }
16348: my @del_lock = ($cnum."\0".'uniquecodes');
16349: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16350: } else {
16351: $error = 'nolock';
16352: }
16353: return ($code,$error);
16354: }
16355:
16356: sub generate_code {
16357: my $code;
16358: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16359: for (my $i=0; $i<6; $i++) {
16360: my $lettnum = int (rand 2);
16361: my $item = '';
16362: if ($lettnum) {
16363: $item = $letts[int( rand(18) )];
16364: } else {
16365: $item = 1+int( rand(8) );
16366: }
16367: $code .= $item;
16368: }
16369: return $code;
16370: }
16371:
1.444 albertel 16372: ############################################################
16373: ############################################################
16374:
1.953 droeschl 16375: #SD
16376: # only Community and Course, or anything else?
1.378 raeburn 16377: sub course_type {
16378: my ($cid) = @_;
16379: if (!defined($cid)) {
16380: $cid = $env{'request.course.id'};
16381: }
1.404 albertel 16382: if (defined($env{'course.'.$cid.'.type'})) {
16383: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16384: } else {
16385: return 'Course';
1.377 raeburn 16386: }
16387: }
1.156 albertel 16388:
1.406 raeburn 16389: sub group_term {
16390: my $crstype = &course_type();
16391: my %names = (
16392: 'Course' => 'group',
1.865 raeburn 16393: 'Community' => 'group',
1.406 raeburn 16394: );
16395: return $names{$crstype};
16396: }
16397:
1.902 raeburn 16398: sub course_types {
1.1075.2.59 raeburn 16399: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 16400: my %typename = (
16401: official => 'Official course',
16402: unofficial => 'Unofficial course',
16403: community => 'Community',
1.1075.2.59 raeburn 16404: textbook => 'Textbook course',
1.902 raeburn 16405: );
16406: return (\@types,\%typename);
16407: }
16408:
1.156 albertel 16409: sub icon {
16410: my ($file)=@_;
1.505 albertel 16411: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16412: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16413: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16414: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16415: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16416: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16417: $curfext.".gif") {
16418: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16419: $curfext.".gif";
16420: }
16421: }
1.249 albertel 16422: return &lonhttpdurl($iconname);
1.154 albertel 16423: }
1.84 albertel 16424:
1.575 albertel 16425: sub lonhttpdurl {
1.692 www 16426: #
16427: # Had been used for "small fry" static images on separate port 8080.
16428: # Modify here if lightweight http functionality desired again.
16429: # Currently eliminated due to increasing firewall issues.
16430: #
1.575 albertel 16431: my ($url)=@_;
1.692 www 16432: return $url;
1.215 albertel 16433: }
16434:
1.213 albertel 16435: sub connection_aborted {
16436: my ($r)=@_;
16437: $r->print(" ");$r->rflush();
16438: my $c = $r->connection;
16439: return $c->aborted();
16440: }
16441:
1.221 foxr 16442: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16443: # strings as 'strings'.
16444: sub escape_single {
1.221 foxr 16445: my ($input) = @_;
1.223 albertel 16446: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16447: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16448: return $input;
16449: }
1.223 albertel 16450:
1.222 foxr 16451: # Same as escape_single, but escape's "'s This
16452: # can be used for "strings"
16453: sub escape_double {
16454: my ($input) = @_;
16455: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16456: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16457: return $input;
16458: }
1.223 albertel 16459:
1.222 foxr 16460: # Escapes the last element of a full URL.
16461: sub escape_url {
16462: my ($url) = @_;
1.238 raeburn 16463: my @urlslices = split(/\//, $url,-1);
1.369 www 16464: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 16465: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16466: }
1.462 albertel 16467:
1.820 raeburn 16468: sub compare_arrays {
16469: my ($arrayref1,$arrayref2) = @_;
16470: my (@difference,%count);
16471: @difference = ();
16472: %count = ();
16473: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16474: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16475: foreach my $element (keys(%count)) {
16476: if ($count{$element} == 1) {
16477: push(@difference,$element);
16478: }
16479: }
16480: }
16481: return @difference;
16482: }
16483:
1.1075.2.152 raeburn 16484: sub lon_status_items {
16485: my %defaults = (
16486: E => 100,
16487: W => 4,
16488: N => 1,
16489: U => 5,
16490: threshold => 200,
16491: sysmail => 2500,
16492: );
16493: my %names = (
16494: E => 'Errors',
16495: W => 'Warnings',
16496: N => 'Notices',
16497: U => 'Unsent',
16498: );
16499: return (\%defaults,\%names);
16500: }
16501:
1.817 bisitz 16502: # -------------------------------------------------------- Initialize user login
1.462 albertel 16503: sub init_user_environment {
1.463 albertel 16504: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16505: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16506:
16507: my $public=($username eq 'public' && $domain eq 'public');
16508:
16509: # See if old ID present, if so, remove
16510:
1.1062 raeburn 16511: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16512: my $now=time;
16513:
16514: if ($public) {
16515: my $max_public=100;
16516: my $oldest;
16517: my $oldest_time=0;
16518: for(my $next=1;$next<=$max_public;$next++) {
16519: if (-e $lonids."/publicuser_$next.id") {
16520: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16521: if ($mtime<$oldest_time || !$oldest_time) {
16522: $oldest_time=$mtime;
16523: $oldest=$next;
16524: }
16525: } else {
16526: $cookie="publicuser_$next";
16527: last;
16528: }
16529: }
16530: if (!$cookie) { $cookie="publicuser_$oldest"; }
16531: } else {
1.463 albertel 16532: # if this isn't a robot, kill any existing non-robot sessions
16533: if (!$args->{'robot'}) {
16534: opendir(DIR,$lonids);
16535: while ($filename=readdir(DIR)) {
16536: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16537: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16538: &GDBM_READER(),0640)) {
16539: my $linkedfile;
16540: if (exists($oldenv{'user.linkedenv'})) {
16541: $linkedfile = $oldenv{'user.linkedenv'};
16542: }
16543: untie(%oldenv);
16544: if (unlink("$lonids/$filename")) {
16545: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16546: if (-l "$lonids/$linkedfile.id") {
16547: unlink("$lonids/$linkedfile.id");
16548: }
16549: }
16550: }
16551: } else {
16552: unlink($lonids.'/'.$filename);
16553: }
1.463 albertel 16554: }
1.462 albertel 16555: }
1.463 albertel 16556: closedir(DIR);
1.1075.2.84 raeburn 16557: # If there is a undeleted lockfile for the user's paste buffer remove it.
16558: my $namespace = 'nohist_courseeditor';
16559: my $lockingkey = 'paste'."\0".'locked_num';
16560: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16561: $domain,$username);
16562: if (exists($lockhash{$lockingkey})) {
16563: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16564: unless ($delresult eq 'ok') {
16565: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16566: }
16567: }
1.462 albertel 16568: }
16569: # Give them a new cookie
1.463 albertel 16570: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16571: : $now.$$.int(rand(10000)));
1.463 albertel 16572: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16573:
16574: # Initialize roles
16575:
1.1062 raeburn 16576: ($userroles,$firstaccenv,$timerintenv) =
16577: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16578: }
16579: # ------------------------------------ Check browser type and MathML capability
16580:
1.1075.2.77 raeburn 16581: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16582: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16583:
16584: # ------------------------------------------------------------- Get environment
16585:
16586: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16587: my ($tmp) = keys(%userenv);
16588: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16589: } else {
16590: undef(%userenv);
16591: }
16592: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16593: $form->{'interface'}=$userenv{'interface'};
16594: }
16595: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16596:
16597: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16598: foreach my $option ('interface','localpath','localres') {
16599: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16600: }
16601: # --------------------------------------------------------- Write first profile
16602:
16603: {
1.1075.2.150 raeburn 16604: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16605: my %initial_env =
16606: ("user.name" => $username,
16607: "user.domain" => $domain,
16608: "user.home" => $authhost,
16609: "browser.type" => $clientbrowser,
16610: "browser.version" => $clientversion,
16611: "browser.mathml" => $clientmathml,
16612: "browser.unicode" => $clientunicode,
16613: "browser.os" => $clientos,
1.1075.2.42 raeburn 16614: "browser.mobile" => $clientmobile,
16615: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16616: "browser.osversion" => $clientosversion,
1.462 albertel 16617: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16618: "request.course.fn" => '',
16619: "request.course.uri" => '',
16620: "request.course.sec" => '',
16621: "request.role" => 'cm',
16622: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16623: "request.host" => $ip,);
1.462 albertel 16624:
16625: if ($form->{'localpath'}) {
16626: $initial_env{"browser.localpath"} = $form->{'localpath'};
16627: $initial_env{"browser.localres"} = $form->{'localres'};
16628: }
16629:
16630: if ($form->{'interface'}) {
16631: $form->{'interface'}=~s/\W//gs;
16632: $initial_env{"browser.interface"} = $form->{'interface'};
16633: $env{'browser.interface'}=$form->{'interface'};
16634: }
16635:
1.1075.2.54 raeburn 16636: if ($form->{'iptoken'}) {
16637: my $lonhost = $r->dir_config('lonHostID');
16638: $initial_env{"user.noloadbalance"} = $lonhost;
16639: $env{'user.noloadbalance'} = $lonhost;
16640: }
16641:
1.1075.2.120 raeburn 16642: if ($form->{'noloadbalance'}) {
16643: my @hosts = &Apache::lonnet::current_machine_ids();
16644: my $hosthere = $form->{'noloadbalance'};
16645: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16646: $initial_env{"user.noloadbalance"} = $hosthere;
16647: $env{'user.noloadbalance'} = $hosthere;
16648: }
16649: }
16650:
1.1016 raeburn 16651: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16652: my %is_adv = ( is_adv => $env{'user.adv'} );
16653: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16654:
1.1075.2.125 raeburn 16655: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16656: $userenv{'availabletools.'.$tool} =
16657: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16658: undef,\%userenv,\%domdef,\%is_adv);
16659: }
1.724 raeburn 16660:
1.1075.2.125 raeburn 16661: foreach my $crstype ('official','unofficial','community','textbook') {
16662: $userenv{'canrequest.'.$crstype} =
16663: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16664: 'reload','requestcourses',
16665: \%userenv,\%domdef,\%is_adv);
16666: }
1.765 raeburn 16667:
1.1075.2.125 raeburn 16668: $userenv{'canrequest.author'} =
16669: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16670: 'reload','requestauthor',
16671: \%userenv,\%domdef,\%is_adv);
16672: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16673: $domain,$username);
16674: my $reqstatus = $reqauthor{'author_status'};
16675: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16676: if (ref($reqauthor{'author'}) eq 'HASH') {
16677: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16678: $reqauthor{'author'}{'timestamp'};
16679: }
1.1075.2.14 raeburn 16680: }
16681: }
16682:
1.462 albertel 16683: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16684:
1.462 albertel 16685: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16686: &GDBM_WRCREAT(),0640)) {
16687: &_add_to_env(\%disk_env,\%initial_env);
16688: &_add_to_env(\%disk_env,\%userenv,'environment.');
16689: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16690: if (ref($firstaccenv) eq 'HASH') {
16691: &_add_to_env(\%disk_env,$firstaccenv);
16692: }
16693: if (ref($timerintenv) eq 'HASH') {
16694: &_add_to_env(\%disk_env,$timerintenv);
16695: }
1.463 albertel 16696: if (ref($args->{'extra_env'})) {
16697: &_add_to_env(\%disk_env,$args->{'extra_env'});
16698: }
1.462 albertel 16699: untie(%disk_env);
16700: } else {
1.705 tempelho 16701: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16702: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16703: return 'error: '.$!;
16704: }
16705: }
16706: $env{'request.role'}='cm';
16707: $env{'request.role.adv'}=$env{'user.adv'};
16708: $env{'browser.type'}=$clientbrowser;
16709:
16710: return $cookie;
16711:
16712: }
16713:
16714: sub _add_to_env {
16715: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16716: if (ref($env_data) eq 'HASH') {
16717: while (my ($key,$value) = each(%$env_data)) {
16718: $idf->{$prefix.$key} = $value;
16719: $env{$prefix.$key} = $value;
16720: }
1.462 albertel 16721: }
16722: }
16723:
1.685 tempelho 16724: # --- Get the symbolic name of a problem and the url
16725: sub get_symb {
16726: my ($request,$silent) = @_;
1.726 raeburn 16727: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16728: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16729: if ($symb eq '') {
16730: if (!$silent) {
1.1071 raeburn 16731: if (ref($request)) {
16732: $request->print("Unable to handle ambiguous references:$url:.");
16733: }
1.685 tempelho 16734: return ();
16735: }
16736: }
16737: &Apache::lonenc::check_decrypt(\$symb);
16738: return ($symb);
16739: }
16740:
16741: # --------------------------------------------------------------Get annotation
16742:
16743: sub get_annotation {
16744: my ($symb,$enc) = @_;
16745:
16746: my $key = $symb;
16747: if (!$enc) {
16748: $key =
16749: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16750: }
16751: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16752: return $annotation{$key};
16753: }
16754:
16755: sub clean_symb {
1.731 raeburn 16756: my ($symb,$delete_enc) = @_;
1.685 tempelho 16757:
16758: &Apache::lonenc::check_decrypt(\$symb);
16759: my $enc = $env{'request.enc'};
1.731 raeburn 16760: if ($delete_enc) {
1.730 raeburn 16761: delete($env{'request.enc'});
16762: }
1.685 tempelho 16763:
16764: return ($symb,$enc);
16765: }
1.462 albertel 16766:
1.1075.2.69 raeburn 16767: ############################################################
16768: ############################################################
16769:
16770: =pod
16771:
16772: =head1 Routines for building display used to search for courses
16773:
16774:
16775: =over 4
16776:
16777: =item * &build_filters()
16778:
16779: Create markup for a table used to set filters to use when selecting
16780: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16781: and quotacheck.pl
16782:
16783:
16784: Inputs:
16785:
16786: filterlist - anonymous array of fields to include as potential filters
16787:
16788: crstype - course type
16789:
16790: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16791: to pop-open a course selector (will contain "extra element").
16792:
16793: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16794:
16795: filter - anonymous hash of criteria and their values
16796:
16797: action - form action
16798:
16799: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16800:
16801: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16802:
16803: cloneruname - username of owner of new course who wants to clone
16804:
16805: clonerudom - domain of owner of new course who wants to clone
16806:
16807: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16808:
16809: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16810:
16811: codedom - domain
16812:
16813: formname - value of form element named "form".
16814:
16815: fixeddom - domain, if fixed.
16816:
16817: prevphase - value to assign to form element named "phase" when going back to the previous screen
16818:
16819: cnameelement - name of form element in form on opener page which will receive title of selected course
16820:
16821: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16822:
16823: cdomelement - name of form element in form on opener page which will receive domain of selected course
16824:
16825: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16826:
16827: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16828:
16829: clonewarning - warning message about missing information for intended course owner when DC creates a course
16830:
16831:
16832: Returns: $output - HTML for display of search criteria, and hidden form elements.
16833:
16834:
16835: Side Effects: None
16836:
16837: =cut
16838:
16839: # ---------------------------------------------- search for courses based on last activity etc.
16840:
16841: sub build_filters {
16842: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16843: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16844: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16845: $cnameelement,$cnumelement,$cdomelement,$setroles,
16846: $clonetext,$clonewarning) = @_;
16847: my ($list,$jscript);
16848: my $onchange = 'javascript:updateFilters(this)';
16849: my ($domainselectform,$sincefilterform,$createdfilterform,
16850: $ownerdomselectform,$persondomselectform,$instcodeform,
16851: $typeselectform,$instcodetitle);
16852: if ($formname eq '') {
16853: $formname = $caller;
16854: }
16855: foreach my $item (@{$filterlist}) {
16856: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16857: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16858: if ($item eq 'domainfilter') {
16859: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16860: } elsif ($item eq 'coursefilter') {
16861: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16862: } elsif ($item eq 'ownerfilter') {
16863: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16864: } elsif ($item eq 'ownerdomfilter') {
16865: $filter->{'ownerdomfilter'} =
16866: &LONCAPA::clean_domain($filter->{$item});
16867: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16868: 'ownerdomfilter',1);
16869: } elsif ($item eq 'personfilter') {
16870: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16871: } elsif ($item eq 'persondomfilter') {
16872: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16873: 'persondomfilter',1);
16874: } else {
16875: $filter->{$item} =~ s/\W//g;
16876: }
16877: if (!$filter->{$item}) {
16878: $filter->{$item} = '';
16879: }
16880: }
16881: if ($item eq 'domainfilter') {
16882: my $allow_blank = 1;
16883: if ($formname eq 'portform') {
16884: $allow_blank=0;
16885: } elsif ($formname eq 'studentform') {
16886: $allow_blank=0;
16887: }
16888: if ($fixeddom) {
16889: $domainselectform = '<input type="hidden" name="domainfilter"'.
16890: ' value="'.$codedom.'" />'.
16891: &Apache::lonnet::domain($codedom,'description');
16892: } else {
16893: $domainselectform = &select_dom_form($filter->{$item},
16894: 'domainfilter',
16895: $allow_blank,'',$onchange);
16896: }
16897: } else {
16898: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16899: }
16900: }
16901:
16902: # last course activity filter and selection
16903: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16904:
16905: # course created filter and selection
16906: if (exists($filter->{'createdfilter'})) {
16907: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16908: }
16909:
16910: my %lt = &Apache::lonlocal::texthash(
16911: 'cac' => "$crstype Activity",
16912: 'ccr' => "$crstype Created",
16913: 'cde' => "$crstype Title",
16914: 'cdo' => "$crstype Domain",
16915: 'ins' => 'Institutional Code',
16916: 'inc' => 'Institutional Categorization',
16917: 'cow' => "$crstype Owner/Co-owner",
16918: 'cop' => "$crstype Personnel Includes",
16919: 'cog' => 'Type',
16920: );
16921:
16922: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16923: my $typeval = 'Course';
16924: if ($crstype eq 'Community') {
16925: $typeval = 'Community';
16926: }
16927: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16928: } else {
16929: $typeselectform = '<select name="type" size="1"';
16930: if ($onchange) {
16931: $typeselectform .= ' onchange="'.$onchange.'"';
16932: }
16933: $typeselectform .= '>'."\n";
16934: foreach my $posstype ('Course','Community') {
16935: $typeselectform.='<option value="'.$posstype.'"'.
16936: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16937: }
16938: $typeselectform.="</select>";
16939: }
16940:
16941: my ($cloneableonlyform,$cloneabletitle);
16942: if (exists($filter->{'cloneableonly'})) {
16943: my $cloneableon = '';
16944: my $cloneableoff = ' checked="checked"';
16945: if ($filter->{'cloneableonly'}) {
16946: $cloneableon = $cloneableoff;
16947: $cloneableoff = '';
16948: }
16949: $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>';
16950: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16951: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16952: } else {
16953: $cloneabletitle = &mt('Cloneable by you');
16954: }
16955: }
16956: my $officialjs;
16957: if ($crstype eq 'Course') {
16958: if (exists($filter->{'instcodefilter'})) {
16959: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16960: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16961: if ($codedom) {
16962: $officialjs = 1;
16963: ($instcodeform,$jscript,$$numtitlesref) =
16964: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16965: $officialjs,$codetitlesref);
16966: if ($jscript) {
16967: $jscript = '<script type="text/javascript">'."\n".
16968: '// <![CDATA['."\n".
16969: $jscript."\n".
16970: '// ]]>'."\n".
16971: '</script>'."\n";
16972: }
16973: }
16974: if ($instcodeform eq '') {
16975: $instcodeform =
16976: '<input type="text" name="instcodefilter" size="10" value="'.
16977: $list->{'instcodefilter'}.'" />';
16978: $instcodetitle = $lt{'ins'};
16979: } else {
16980: $instcodetitle = $lt{'inc'};
16981: }
16982: if ($fixeddom) {
16983: $instcodetitle .= '<br />('.$codedom.')';
16984: }
16985: }
16986: }
16987: my $output = qq|
16988: <form method="post" name="filterpicker" action="$action">
16989: <input type="hidden" name="form" value="$formname" />
16990: |;
16991: if ($formname eq 'modifycourse') {
16992: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16993: '<input type="hidden" name="prevphase" value="'.
16994: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16995: } elsif ($formname eq 'quotacheck') {
16996: $output .= qq|
16997: <input type="hidden" name="sortby" value="" />
16998: <input type="hidden" name="sortorder" value="" />
16999: |;
17000: } else {
1.1075.2.69 raeburn 17001: my $name_input;
17002: if ($cnameelement ne '') {
17003: $name_input = '<input type="hidden" name="cnameelement" value="'.
17004: $cnameelement.'" />';
17005: }
17006: $output .= qq|
17007: <input type="hidden" name="cnumelement" value="$cnumelement" />
17008: <input type="hidden" name="cdomelement" value="$cdomelement" />
17009: $name_input
17010: $roleelement
17011: $multelement
17012: $typeelement
17013: |;
17014: if ($formname eq 'portform') {
17015: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17016: }
17017: }
17018: if ($fixeddom) {
17019: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17020: }
17021: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17022: if ($sincefilterform) {
17023: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17024: .$sincefilterform
17025: .&Apache::lonhtmlcommon::row_closure();
17026: }
17027: if ($createdfilterform) {
17028: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17029: .$createdfilterform
17030: .&Apache::lonhtmlcommon::row_closure();
17031: }
17032: if ($domainselectform) {
17033: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17034: .$domainselectform
17035: .&Apache::lonhtmlcommon::row_closure();
17036: }
17037: if ($typeselectform) {
17038: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17039: $output .= $typeselectform;
17040: } else {
17041: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17042: .$typeselectform
17043: .&Apache::lonhtmlcommon::row_closure();
17044: }
17045: }
17046: if ($instcodeform) {
17047: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17048: .$instcodeform
17049: .&Apache::lonhtmlcommon::row_closure();
17050: }
17051: if (exists($filter->{'ownerfilter'})) {
17052: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17053: '<table><tr><td>'.&mt('Username').'<br />'.
17054: '<input type="text" name="ownerfilter" size="20" value="'.
17055: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17056: $ownerdomselectform.'</td></tr></table>'.
17057: &Apache::lonhtmlcommon::row_closure();
17058: }
17059: if (exists($filter->{'personfilter'})) {
17060: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17061: '<table><tr><td>'.&mt('Username').'<br />'.
17062: '<input type="text" name="personfilter" size="20" value="'.
17063: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17064: $persondomselectform.'</td></tr></table>'.
17065: &Apache::lonhtmlcommon::row_closure();
17066: }
17067: if (exists($filter->{'coursefilter'})) {
17068: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17069: .'<input type="text" name="coursefilter" size="25" value="'
17070: .$list->{'coursefilter'}.'" />'
17071: .&Apache::lonhtmlcommon::row_closure();
17072: }
17073: if ($cloneableonlyform) {
17074: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17075: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17076: }
17077: if (exists($filter->{'descriptfilter'})) {
17078: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17079: .'<input type="text" name="descriptfilter" size="40" value="'
17080: .$list->{'descriptfilter'}.'" />'
17081: .&Apache::lonhtmlcommon::row_closure(1);
17082: }
17083: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17084: '<input type="hidden" name="updater" value="" />'."\n".
17085: '<input type="submit" name="gosearch" value="'.
17086: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17087: return $jscript.$clonewarning.$output;
17088: }
17089:
17090: =pod
17091:
17092: =item * &timebased_select_form()
17093:
17094: Create markup for a dropdown list used to select a time-based
17095: filter e.g., Course Activity, Course Created, when searching for courses
17096: or communities
17097:
17098: Inputs:
17099:
17100: item - name of form element (sincefilter or createdfilter)
17101:
17102: filter - anonymous hash of criteria and their values
17103:
17104: Returns: HTML for a select box contained a blank, then six time selections,
17105: with value set in incoming form variables currently selected.
17106:
17107: Side Effects: None
17108:
17109: =cut
17110:
17111: sub timebased_select_form {
17112: my ($item,$filter) = @_;
17113: if (ref($filter) eq 'HASH') {
17114: $filter->{$item} =~ s/[^\d-]//g;
17115: if (!$filter->{$item}) { $filter->{$item}=-1; }
17116: return &select_form(
17117: $filter->{$item},
17118: $item,
17119: { '-1' => '',
17120: '86400' => &mt('today'),
17121: '604800' => &mt('last week'),
17122: '2592000' => &mt('last month'),
17123: '7776000' => &mt('last three months'),
17124: '15552000' => &mt('last six months'),
17125: '31104000' => &mt('last year'),
17126: 'select_form_order' =>
17127: ['-1','86400','604800','2592000','7776000',
17128: '15552000','31104000']});
17129: }
17130: }
17131:
17132: =pod
17133:
17134: =item * &js_changer()
17135:
17136: Create script tag containing Javascript used to submit course search form
17137: when course type or domain is changed, and also to hide 'Searching ...' on
17138: page load completion for page showing search result.
17139:
17140: Inputs: None
17141:
17142: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17143:
17144: Side Effects: None
17145:
17146: =cut
17147:
17148: sub js_changer {
17149: return <<ENDJS;
17150: <script type="text/javascript">
17151: // <![CDATA[
17152: function updateFilters(caller) {
17153: if (typeof(caller) != "undefined") {
17154: document.filterpicker.updater.value = caller.name;
17155: }
17156: document.filterpicker.submit();
17157: }
17158:
17159: function hideSearching() {
17160: if (document.getElementById('searching')) {
17161: document.getElementById('searching').style.display = 'none';
17162: }
17163: return;
17164: }
17165:
17166: // ]]>
17167: </script>
17168:
17169: ENDJS
17170: }
17171:
17172: =pod
17173:
17174: =item * &search_courses()
17175:
17176: Process selected filters form course search form and pass to lonnet::courseiddump
17177: to retrieve a hash for which keys are courseIDs which match the selected filters.
17178:
17179: Inputs:
17180:
17181: dom - domain being searched
17182:
17183: type - course type ('Course' or 'Community' or '.' if any).
17184:
17185: filter - anonymous hash of criteria and their values
17186:
17187: numtitles - for institutional codes - number of categories
17188:
17189: cloneruname - optional username of new course owner
17190:
17191: clonerudom - optional domain of new course owner
17192:
1.1075.2.95 raeburn 17193: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17194: (used when DC is using course creation form)
17195:
17196: codetitles - reference to array of titles of components in institutional codes (official courses).
17197:
1.1075.2.95 raeburn 17198: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17199: (and so can clone automatically)
17200:
17201: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17202:
17203: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17204: courses to clone
1.1075.2.69 raeburn 17205:
17206: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17207:
17208:
17209: Side Effects: None
17210:
17211: =cut
17212:
17213:
17214: sub search_courses {
1.1075.2.95 raeburn 17215: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17216: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17217: my (%courses,%showcourses,$cloner);
17218: if (($filter->{'ownerfilter'} ne '') ||
17219: ($filter->{'ownerdomfilter'} ne '')) {
17220: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17221: $filter->{'ownerdomfilter'};
17222: }
17223: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17224: if (!$filter->{$item}) {
17225: $filter->{$item}='.';
17226: }
17227: }
17228: my $now = time;
17229: my $timefilter =
17230: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17231: my ($createdbefore,$createdafter);
17232: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17233: $createdbefore = $now;
17234: $createdafter = $now-$filter->{'createdfilter'};
17235: }
17236: my ($instcodefilter,$regexpok);
17237: if ($numtitles) {
17238: if ($env{'form.official'} eq 'on') {
17239: $instcodefilter =
17240: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17241: $regexpok = 1;
17242: } elsif ($env{'form.official'} eq 'off') {
17243: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17244: unless ($instcodefilter eq '') {
17245: $regexpok = -1;
17246: }
17247: }
17248: } else {
17249: $instcodefilter = $filter->{'instcodefilter'};
17250: }
17251: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17252: if ($type eq '') { $type = '.'; }
17253:
17254: if (($clonerudom ne '') && ($cloneruname ne '')) {
17255: $cloner = $cloneruname.':'.$clonerudom;
17256: }
17257: %courses = &Apache::lonnet::courseiddump($dom,
17258: $filter->{'descriptfilter'},
17259: $timefilter,
17260: $instcodefilter,
17261: $filter->{'combownerfilter'},
17262: $filter->{'coursefilter'},
17263: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17264: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17265: $filter->{'cloneableonly'},
17266: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17267: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17268: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17269: my $ccrole;
17270: if ($type eq 'Community') {
17271: $ccrole = 'co';
17272: } else {
17273: $ccrole = 'cc';
17274: }
17275: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17276: $filter->{'persondomfilter'},
17277: 'userroles',undef,
17278: [$ccrole,'in','ad','ep','ta','cr'],
17279: $dom);
17280: foreach my $role (keys(%rolehash)) {
17281: my ($cnum,$cdom,$courserole) = split(':',$role);
17282: my $cid = $cdom.'_'.$cnum;
17283: if (exists($courses{$cid})) {
17284: if (ref($courses{$cid}) eq 'HASH') {
17285: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17286: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17287: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17288: }
17289: } else {
17290: $courses{$cid}{roles} = [$courserole];
17291: }
17292: $showcourses{$cid} = $courses{$cid};
17293: }
17294: }
17295: }
17296: %courses = %showcourses;
17297: }
17298: return %courses;
17299: }
17300:
17301: =pod
17302:
17303: =back
17304:
1.1075.2.88 raeburn 17305: =head1 Routines for version requirements for current course.
17306:
17307: =over 4
17308:
17309: =item * &check_release_required()
17310:
17311: Compares required LON-CAPA version with version on server, and
17312: if required version is newer looks for a server with the required version.
17313:
17314: Looks first at servers in user's owen domain; if none suitable, looks at
17315: servers in course's domain are permitted to host sessions for user's domain.
17316:
17317: Inputs:
17318:
17319: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17320:
17321: $courseid - Course ID of current course
17322:
17323: $rolecode - User's current role in course (for switchserver query string).
17324:
17325: $required - LON-CAPA version needed by course (format: Major.Minor).
17326:
17327:
17328: Returns:
17329:
17330: $switchserver - query string tp append to /adm/switchserver call (if
17331: current server's LON-CAPA version is too old.
17332:
17333: $warning - Message is displayed if no suitable server could be found.
17334:
17335: =cut
17336:
17337: sub check_release_required {
17338: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17339: my ($switchserver,$warning);
17340: if ($required ne '') {
17341: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17342: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17343: if ($reqdmajor ne '' && $reqdminor ne '') {
17344: my $otherserver;
17345: if (($major eq '' && $minor eq '') ||
17346: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17347: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17348: my $switchlcrev =
17349: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17350: $userdomserver);
17351: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17352: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17353: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17354: my $cdom = $env{'course.'.$courseid.'.domain'};
17355: if ($cdom ne $env{'user.domain'}) {
17356: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17357: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17358: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17359: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17360: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17361: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17362: my $canhost =
17363: &Apache::lonnet::can_host_session($env{'user.domain'},
17364: $coursedomserver,
17365: $remoterev,
17366: $udomdefaults{'remotesessions'},
17367: $defdomdefaults{'hostedsessions'});
17368:
17369: if ($canhost) {
17370: $otherserver = $coursedomserver;
17371: } else {
17372: $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.");
17373: }
17374: } else {
17375: $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).");
17376: }
17377: } else {
17378: $otherserver = $userdomserver;
17379: }
17380: }
17381: if ($otherserver ne '') {
17382: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17383: }
17384: }
17385: }
17386: return ($switchserver,$warning);
17387: }
17388:
17389: =pod
17390:
17391: =item * &check_release_result()
17392:
17393: Inputs:
17394:
17395: $switchwarning - Warning message if no suitable server found to host session.
17396:
17397: $switchserver - query string to append to /adm/switchserver containing lonHostID
17398: and current role.
17399:
17400: Returns: HTML to display with information about requirement to switch server.
17401: Either displaying warning with link to Roles/Courses screen or
17402: display link to switchserver.
17403:
1.1075.2.69 raeburn 17404: =cut
17405:
1.1075.2.88 raeburn 17406: sub check_release_result {
17407: my ($switchwarning,$switchserver) = @_;
17408: my $output = &start_page('Selected course unavailable on this server').
17409: '<p class="LC_warning">';
17410: if ($switchwarning) {
17411: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17412: if (&show_course()) {
17413: $output .= &mt('Display courses');
17414: } else {
17415: $output .= &mt('Display roles');
17416: }
17417: $output .= '</a>';
17418: } elsif ($switchserver) {
17419: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17420: '<br />'.
17421: '<a href="/adm/switchserver?'.$switchserver.'">'.
17422: &mt('Switch Server').
17423: '</a>';
17424: }
17425: $output .= '</p>'.&end_page();
17426: return $output;
17427: }
17428:
17429: =pod
17430:
17431: =item * &needs_coursereinit()
17432:
17433: Determine if course contents stored for user's session needs to be
17434: refreshed, because content has changed since "Big Hash" last tied.
17435:
17436: Check for change is made if time last checked is more than 10 minutes ago
17437: (by default).
17438:
17439: Inputs:
17440:
17441: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17442:
17443: $interval (optional) - Time which may elapse (in s) between last check for content
17444: change in current course. (default: 600 s).
17445:
17446: Returns: an array; first element is:
17447:
17448: =over 4
17449:
17450: 'switch' - if content updates mean user's session
17451: needs to be switched to a server running a newer LON-CAPA version
17452:
17453: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17454: on current server hosting user's session
17455:
17456: '' - if no action required.
17457:
17458: =back
17459:
17460: If first item element is 'switch':
17461:
17462: second item is $switchwarning - Warning message if no suitable server found to host session.
17463:
17464: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17465: and current role.
17466:
17467: otherwise: no other elements returned.
17468:
17469: =back
17470:
17471: =cut
17472:
17473: sub needs_coursereinit {
17474: my ($loncaparev,$interval) = @_;
17475: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17476: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17477: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17478: my $now = time;
17479: if ($interval eq '') {
17480: $interval = 600;
17481: }
17482: if (($now-$env{'request.course.timechecked'})>$interval) {
17483: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 17484:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 17485:21): if ($blocked) {
17486:21): return ();
17487:21): }
17488:21): my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
1.1075.2.88 raeburn 17489: if ($lastchange > $env{'request.course.tied'}) {
17490: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17491: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17492: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17493: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17494: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17495: $curr_reqd_hash{'internal.releaserequired'}});
17496: my ($switchserver,$switchwarning) =
17497: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17498: $curr_reqd_hash{'internal.releaserequired'});
17499: if ($switchwarning ne '' || $switchserver ne '') {
17500: return ('switch',$switchwarning,$switchserver);
17501: }
17502: }
17503: }
17504: return ('update');
17505: }
17506: }
17507: return ();
17508: }
1.1075.2.69 raeburn 17509:
1.1075.2.11 raeburn 17510: sub update_content_constraints {
17511: my ($cdom,$cnum,$chome,$cid) = @_;
17512: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17513: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17514: my %checkresponsetypes;
17515: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17516: my ($item,$name,$value) = split(/:/,$key);
17517: if ($item eq 'resourcetag') {
17518: if ($name eq 'responsetype') {
17519: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17520: }
17521: }
17522: }
17523: my $navmap = Apache::lonnavmaps::navmap->new();
17524: if (defined($navmap)) {
17525: my %allresponses;
17526: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17527: my %responses = $res->responseTypes();
17528: foreach my $key (keys(%responses)) {
17529: next unless(exists($checkresponsetypes{$key}));
17530: $allresponses{$key} += $responses{$key};
17531: }
17532: }
17533: foreach my $key (keys(%allresponses)) {
17534: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17535: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17536: ($reqdmajor,$reqdminor) = ($major,$minor);
17537: }
17538: }
17539: undef($navmap);
17540: }
17541: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17542: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17543: }
17544: return;
17545: }
17546:
1.1075.2.27 raeburn 17547: sub allmaps_incourse {
17548: my ($cdom,$cnum,$chome,$cid) = @_;
17549: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17550: $cid = $env{'request.course.id'};
17551: $cdom = $env{'course.'.$cid.'.domain'};
17552: $cnum = $env{'course.'.$cid.'.num'};
17553: $chome = $env{'course.'.$cid.'.home'};
17554: }
17555: my %allmaps = ();
17556: my $lastchange =
17557: &Apache::lonnet::get_coursechange($cdom,$cnum);
17558: if ($lastchange > $env{'request.course.tied'}) {
17559: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17560: unless ($ferr) {
17561: &update_content_constraints($cdom,$cnum,$chome,$cid);
17562: }
17563: }
17564: my $navmap = Apache::lonnavmaps::navmap->new();
17565: if (defined($navmap)) {
17566: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17567: $allmaps{$res->src()} = 1;
17568: }
17569: }
17570: return \%allmaps;
17571: }
17572:
1.1075.2.11 raeburn 17573: sub parse_supplemental_title {
17574: my ($title) = @_;
17575:
17576: my ($foldertitle,$renametitle);
17577: if ($title =~ /&&&/) {
17578: $title = &HTML::Entites::decode($title);
17579: }
17580: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17581: $renametitle=$4;
17582: my ($time,$uname,$udom) = ($1,$2,$3);
17583: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17584: my $name = &plainname($uname,$udom);
17585: $name = &HTML::Entities::encode($name,'"<>&\'');
17586: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17587: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17588: $name.': <br />'.$foldertitle;
17589: }
17590: if (wantarray) {
17591: return ($title,$foldertitle,$renametitle);
17592: }
17593: return $title;
17594: }
17595:
1.1075.2.43 raeburn 17596: sub recurse_supplemental {
17597: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17598: if ($suppmap) {
17599: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17600: if ($fatal) {
17601: $errors ++;
17602: } else {
17603: if ($#LONCAPA::map::resources > 0) {
17604: foreach my $res (@LONCAPA::map::resources) {
17605: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17606: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17607: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17608: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17609: } else {
17610: $numfiles ++;
17611: }
17612: }
17613: }
17614: }
17615: }
17616: }
17617: return ($numfiles,$errors);
17618: }
17619:
1.1075.2.18 raeburn 17620: sub symb_to_docspath {
1.1075.2.119 raeburn 17621: my ($symb,$navmapref) = @_;
17622: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17623: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17624: if ($resurl=~/\.(sequence|page)$/) {
17625: $mapurl=$resurl;
17626: } elsif ($resurl eq 'adm/navmaps') {
17627: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17628: }
17629: my $mapresobj;
1.1075.2.119 raeburn 17630: unless (ref($$navmapref)) {
17631: $$navmapref = Apache::lonnavmaps::navmap->new();
17632: }
17633: if (ref($$navmapref)) {
17634: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17635: }
17636: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17637: my $type=$2;
17638: my $path;
17639: if (ref($mapresobj)) {
17640: my $pcslist = $mapresobj->map_hierarchy();
17641: if ($pcslist ne '') {
17642: foreach my $pc (split(/,/,$pcslist)) {
17643: next if ($pc <= 1);
1.1075.2.119 raeburn 17644: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17645: if (ref($res)) {
17646: my $thisurl = $res->src();
17647: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17648: my $thistitle = $res->title();
17649: $path .= '&'.
17650: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17651: &escape($thistitle).
1.1075.2.18 raeburn 17652: ':'.$res->randompick().
17653: ':'.$res->randomout().
17654: ':'.$res->encrypted().
17655: ':'.$res->randomorder().
17656: ':'.$res->is_page();
17657: }
17658: }
17659: }
17660: $path =~ s/^\&//;
17661: my $maptitle = $mapresobj->title();
17662: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17663: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17664: }
17665: $path .= (($path ne '')? '&' : '').
17666: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17667: &escape($maptitle).
1.1075.2.18 raeburn 17668: ':'.$mapresobj->randompick().
17669: ':'.$mapresobj->randomout().
17670: ':'.$mapresobj->encrypted().
17671: ':'.$mapresobj->randomorder().
17672: ':'.$mapresobj->is_page();
17673: } else {
17674: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17675: my $ispage = (($type eq 'page')? 1 : '');
17676: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17677: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17678: }
17679: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17680: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17681: }
17682: unless ($mapurl eq 'default') {
17683: $path = 'default&'.
1.1075.2.46 raeburn 17684: &escape('Main Content').
1.1075.2.18 raeburn 17685: ':::::&'.$path;
17686: }
17687: return $path;
17688: }
17689:
1.1075.2.14 raeburn 17690: sub captcha_display {
1.1075.2.137 raeburn 17691: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17692: my ($output,$error);
1.1075.2.107 raeburn 17693: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17694: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17695: if ($captcha eq 'original') {
17696: $output = &create_captcha();
17697: unless ($output) {
17698: $error = 'captcha';
17699: }
17700: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17701: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17702: unless ($output) {
17703: $error = 'recaptcha';
17704: }
17705: }
1.1075.2.107 raeburn 17706: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17707: }
17708:
17709: sub captcha_response {
1.1075.2.137 raeburn 17710: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17711: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17712: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17713: if ($captcha eq 'original') {
17714: ($captcha_chk,$captcha_error) = &check_captcha();
17715: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17716: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17717: } else {
17718: $captcha_chk = 1;
17719: }
17720: return ($captcha_chk,$captcha_error);
17721: }
17722:
17723: sub get_captcha_config {
1.1075.2.137 raeburn 17724: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17725: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17726: my $hostname = &Apache::lonnet::hostname($lonhost);
17727: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17728: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17729: if ($context eq 'usercreation') {
17730: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17731: if (ref($domconfig{$context}) eq 'HASH') {
17732: $hashtocheck = $domconfig{$context}{'cancreate'};
17733: if (ref($hashtocheck) eq 'HASH') {
17734: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17735: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17736: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17737: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17738: }
17739: if ($privkey && $pubkey) {
17740: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17741: $version = $hashtocheck->{'recaptchaversion'};
17742: if ($version ne '2') {
17743: $version = 1;
17744: }
1.1075.2.14 raeburn 17745: } else {
17746: $captcha = 'original';
17747: }
17748: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17749: $captcha = 'original';
17750: }
17751: }
17752: } else {
17753: $captcha = 'captcha';
17754: }
17755: } elsif ($context eq 'login') {
17756: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17757: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17758: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17759: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17760: if ($privkey && $pubkey) {
17761: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17762: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17763: if ($version ne '2') {
17764: $version = 1;
17765: }
1.1075.2.14 raeburn 17766: } else {
17767: $captcha = 'original';
17768: }
17769: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17770: $captcha = 'original';
17771: }
1.1075.2.137 raeburn 17772: } elsif ($context eq 'passwords') {
17773: if ($dom_in_effect) {
17774: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17775: if ($passwdconf{'captcha'} eq 'recaptcha') {
17776: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17777: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17778: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17779: }
17780: if ($privkey && $pubkey) {
17781: $captcha = 'recaptcha';
17782: $version = $passwdconf{'recaptchaversion'};
17783: if ($version ne '2') {
17784: $version = 1;
17785: }
17786: } else {
17787: $captcha = 'original';
17788: }
17789: } elsif ($passwdconf{'captcha'} ne 'notused') {
17790: $captcha = 'original';
17791: }
17792: }
1.1075.2.14 raeburn 17793: }
1.1075.2.107 raeburn 17794: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17795: }
17796:
17797: sub create_captcha {
17798: my %captcha_params = &captcha_settings();
17799: my ($output,$maxtries,$tries) = ('',10,0);
17800: while ($tries < $maxtries) {
17801: $tries ++;
17802: my $captcha = Authen::Captcha->new (
17803: output_folder => $captcha_params{'output_dir'},
17804: data_folder => $captcha_params{'db_dir'},
17805: );
17806: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17807:
17808: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17809: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17810: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17811: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17812: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1075.2.158 raeburn 17813: '</span><br />'.
1.1075.2.66 raeburn 17814: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17815: last;
17816: }
17817: }
1.1075.2.158 raeburn 17818: if ($output eq '') {
17819: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17820: }
1.1075.2.14 raeburn 17821: return $output;
17822: }
17823:
17824: sub captcha_settings {
17825: my %captcha_params = (
17826: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17827: www_output_dir => "/captchaspool",
17828: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17829: numchars => '5',
17830: );
17831: return %captcha_params;
17832: }
17833:
17834: sub check_captcha {
17835: my ($captcha_chk,$captcha_error);
17836: my $code = $env{'form.code'};
17837: my $md5sum = $env{'form.crypt'};
17838: my %captcha_params = &captcha_settings();
17839: my $captcha = Authen::Captcha->new(
17840: output_folder => $captcha_params{'output_dir'},
17841: data_folder => $captcha_params{'db_dir'},
17842: );
1.1075.2.26 raeburn 17843: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17844: my %captcha_hash = (
17845: 0 => 'Code not checked (file error)',
17846: -1 => 'Failed: code expired',
17847: -2 => 'Failed: invalid code (not in database)',
17848: -3 => 'Failed: invalid code (code does not match crypt)',
17849: );
17850: if ($captcha_chk != 1) {
17851: $captcha_error = $captcha_hash{$captcha_chk}
17852: }
17853: return ($captcha_chk,$captcha_error);
17854: }
17855:
17856: sub create_recaptcha {
1.1075.2.107 raeburn 17857: my ($pubkey,$version) = @_;
17858: if ($version >= 2) {
1.1075.2.158 raeburn 17859: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17860: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17861: } else {
17862: my $use_ssl;
17863: if ($ENV{'SERVER_PORT'} == 443) {
17864: $use_ssl = 1;
17865: }
17866: my $captcha = Captcha::reCAPTCHA->new;
17867: return $captcha->get_options_setter({theme => 'white'})."\n".
17868: $captcha->get_html($pubkey,undef,$use_ssl).
17869: &mt('If the text is hard to read, [_1] will replace them.',
17870: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17871: '<br /><br />';
17872: }
1.1075.2.14 raeburn 17873: }
17874:
17875: sub check_recaptcha {
1.1075.2.107 raeburn 17876: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17877: my $captcha_chk;
1.1075.2.150 raeburn 17878: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17879: if ($version >= 2) {
17880: my $ua = LWP::UserAgent->new;
17881: $ua->timeout(10);
17882: my %info = (
17883: secret => $privkey,
17884: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17885: remoteip => $ip,
1.1075.2.107 raeburn 17886: );
17887: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17888: if ($response->is_success) {
17889: my $data = JSON::DWIW->from_json($response->decoded_content);
17890: if (ref($data) eq 'HASH') {
17891: if ($data->{'success'}) {
17892: $captcha_chk = 1;
17893: }
17894: }
17895: }
17896: } else {
17897: my $captcha = Captcha::reCAPTCHA->new;
17898: my $captcha_result =
17899: $captcha->check_answer(
17900: $privkey,
1.1075.2.150 raeburn 17901: $ip,
1.1075.2.107 raeburn 17902: $env{'form.recaptcha_challenge_field'},
17903: $env{'form.recaptcha_response_field'},
17904: );
17905: if ($captcha_result->{is_valid}) {
17906: $captcha_chk = 1;
17907: }
1.1075.2.14 raeburn 17908: }
17909: return $captcha_chk;
17910: }
17911:
1.1075.2.64 raeburn 17912: sub emailusername_info {
1.1075.2.103 raeburn 17913: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17914: my %titles = &Apache::lonlocal::texthash (
17915: lastname => 'Last Name',
17916: firstname => 'First Name',
17917: institution => 'School/college/university',
17918: location => "School's city, state/province, country",
17919: web => "School's web address",
17920: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17921: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17922: );
17923: return (\@fields,\%titles);
17924: }
17925:
1.1075.2.56 raeburn 17926: sub cleanup_html {
17927: my ($incoming) = @_;
17928: my $outgoing;
17929: if ($incoming ne '') {
17930: $outgoing = $incoming;
17931: $outgoing =~ s/;/;/g;
17932: $outgoing =~ s/\#/#/g;
17933: $outgoing =~ s/\&/&/g;
17934: $outgoing =~ s/</</g;
17935: $outgoing =~ s/>/>/g;
17936: $outgoing =~ s/\(/(/g;
17937: $outgoing =~ s/\)/)/g;
17938: $outgoing =~ s/"/"/g;
17939: $outgoing =~ s/'/'/g;
17940: $outgoing =~ s/\$/$/g;
17941: $outgoing =~ s{/}{/}g;
17942: $outgoing =~ s/=/=/g;
17943: $outgoing =~ s/\\/\/g
17944: }
17945: return $outgoing;
17946: }
17947:
1.1075.2.74 raeburn 17948: # Checks for critical messages and returns a redirect url if one exists.
17949: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 17950:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 17951: sub critical_redirect {
1.1075.2.161. .1(raebu 17952:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 17953: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17954: return ();
17955: }
1.1075.2.74 raeburn 17956: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 17957:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17958:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17959:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 17960:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 17961:21): if ($blocked) {
17962:21): my $checkrole = "cm./$cdom/$cnum";
17963:21): if ($env{'request.course.sec'} ne '') {
17964:21): $checkrole .= "/$env{'request.course.sec'}";
17965:21): }
17966:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17967:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17968:21): return;
17969:21): }
17970:21): }
17971:21): }
1.1075.2.74 raeburn 17972: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17973: $env{'user.name'});
17974: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17975: my $redirecturl;
17976: if ($what[0]) {
1.1075.2.158 raeburn 17977: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17978: $redirecturl='/adm/email?critical=display';
17979: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17980: return (1, $url);
17981: }
17982: }
17983: }
17984: return ();
17985: }
17986:
1.1075.2.64 raeburn 17987: # Use:
17988: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17989: #
17990: ##################################################
17991: # password associated functions #
17992: ##################################################
17993: sub des_keys {
17994: # Make a new key for DES encryption.
17995: # Each key has two parts which are returned separately.
17996: # Please note: Each key must be passed through the &hex function
17997: # before it is output to the web browser. The hex versions cannot
17998: # be used to decrypt.
17999: my @hexstr=('0','1','2','3','4','5','6','7',
18000: '8','9','a','b','c','d','e','f');
18001: my $lkey='';
18002: for (0..7) {
18003: $lkey.=$hexstr[rand(15)];
18004: }
18005: my $ukey='';
18006: for (0..7) {
18007: $ukey.=$hexstr[rand(15)];
18008: }
18009: return ($lkey,$ukey);
18010: }
18011:
18012: sub des_decrypt {
18013: my ($key,$cyphertext) = @_;
18014: my $keybin=pack("H16",$key);
18015: my $cypher;
18016: if ($Crypt::DES::VERSION>=2.03) {
18017: $cypher=new Crypt::DES $keybin;
18018: } else {
18019: $cypher=new DES $keybin;
18020: }
1.1075.2.106 raeburn 18021: my $plaintext='';
18022: my $cypherlength = length($cyphertext);
18023: my $numchunks = int($cypherlength/32);
18024: for (my $j=0; $j<$numchunks; $j++) {
18025: my $start = $j*32;
18026: my $cypherblock = substr($cyphertext,$start,32);
18027: my $chunk =
18028: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18029: $chunk .=
18030: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18031: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18032: $plaintext .= $chunk;
18033: }
1.1075.2.64 raeburn 18034: return $plaintext;
18035: }
18036:
1.1075.2.161. .1(raebu 18037:21): sub get_requested_shorturls {
18038:21): my ($cdom,$cnum,$navmap) = @_;
18039:21): return unless (ref($navmap));
18040:21): my ($numnew,$errors);
18041:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18042:21): if (@toshorten) {
18043:21): my (%maps,%resources,%titles);
18044:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18045:21): 'shorturls',$cdom,$cnum);
18046:21): if (keys(%resources)) {
18047:21): my %tocreate;
18048:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18049:21): my $symb = $resources{$item};
18050:21): if ($symb) {
18051:21): $tocreate{$cnum.'&'.$symb} = 1;
18052:21): }
18053:21): }
18054:21): if (keys(%tocreate)) {
18055:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18056:21): \%tocreate);
18057:21): }
18058:21): }
18059:21): }
18060:21): return ($numnew,$errors);
18061:21): }
18062:21):
18063:21): sub make_short_symbs {
18064:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18065:21): my ($numnew,@errors);
18066:21): if (ref($tocreateref) eq 'HASH') {
18067:21): my %tocreate = %{$tocreateref};
18068:21): if (keys(%tocreate)) {
18069:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18070:21): my $su = Short::URL->new(no_vowels => 1);
18071:21): my $init = '';
18072:21): my (%newunique,%addcourse,%courseonly,%failed);
18073:21): # get lock on tiny db
18074:21): my $now = time;
18075:21): if ($lockuser eq '') {
18076:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18077:21): }
18078:21): my $lockhash = {
18079:21): "lock\0$now" => $lockuser,
18080:21): };
18081:21): my $tries = 0;
18082:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18083:21): my ($code,$error);
18084:21): while (($gotlock ne 'ok') && ($tries<3)) {
18085:21): $tries ++;
18086:21): sleep 1;
18087:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18088:21): }
18089:21): if ($gotlock eq 'ok') {
18090:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18091:21): \%addcourse,\%courseonly,\%failed);
18092:21): if (keys(%failed)) {
18093:21): my $numfailed = scalar(keys(%failed));
18094:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18095:21): }
18096:21): if (keys(%newunique)) {
18097:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18098:21): if ($putres eq 'ok') {
18099:21): $numnew = scalar(keys(%newunique));
18100:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18101:21): unless ($newputres eq 'ok') {
18102:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
18103:21): }
18104:21): } else {
18105:21): push(@errors,&mt('error: could not store unique six character URLs'));
18106:21): }
18107:21): }
18108:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18109:21): unless ($dellockres eq 'ok') {
18110:21): push(@errors,&mt('error: could not release lockfile'));
18111:21): }
18112:21): } else {
18113:21): push(@errors,&mt('error: could not obtain lockfile'));
18114:21): }
18115:21): if (keys(%courseonly)) {
18116:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18117:21): if ($result ne 'ok') {
18118:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
18119:21): }
18120:21): }
18121:21): }
18122:21): }
18123:21): return ($numnew,\@errors);
18124:21): }
18125:21):
18126:21): sub shorten_symbs {
18127:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18128:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18129:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18130:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18131:21): my (%possibles,%collisions);
18132:21): foreach my $key (keys(%{$tocreate})) {
18133:21): my $num = String::CRC32::crc32($key);
18134:21): my $tiny = $su->encode($num,$init);
18135:21): if ($tiny) {
18136:21): $possibles{$tiny} = $key;
18137:21): }
18138:21): }
18139:21): if (!$init) {
18140:21): $init = 1;
18141:21): } else {
18142:21): $init ++;
18143:21): }
18144:21): if (keys(%possibles)) {
18145:21): my @posstiny = keys(%possibles);
18146:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18147:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18148:21): if (keys(%currtiny)) {
18149:21): foreach my $key (keys(%currtiny)) {
18150:21): next if ($currtiny{$key} eq '');
18151:21): if ($currtiny{$key} eq $possibles{$key}) {
18152:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18153:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18154:21): $courseonly->{$tsymb} = $key;
18155:21): }
18156:21): } else {
18157:21): $collisions{$possibles{$key}} = 1;
18158:21): }
18159:21): delete($possibles{$key});
18160:21): }
18161:21): }
18162:21): foreach my $key (keys(%possibles)) {
18163:21): $newunique->{$key} = $possibles{$key};
18164:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18165:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18166:21): $addcourse->{$tsymb} = $key;
18167:21): }
18168:21): }
18169:21): }
18170:21): if (keys(%collisions)) {
18171:21): if ($init <5) {
18172:21): if (!$init) {
18173:21): $init = 1;
18174:21): } else {
18175:21): $init ++;
18176:21): }
18177:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18178:21): $newunique,$addcourse,$courseonly,$failed);
18179:21): } else {
18180:21): foreach my $key (keys(%collisions)) {
18181:21): $failed->{$key} = 1;
18182:21): $failed->{$key} = 1;
18183:21): }
18184:21): }
18185:21): }
18186:21): return $init;
18187:21): }
18188:21):
1.1075.2.135 raeburn 18189: sub is_nonframeable {
18190: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18191: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
18192: return if (($remprotocol eq '') || ($remhost eq ''));
18193:
18194: $remprotocol = lc($remprotocol);
18195: $remhost = lc($remhost);
18196: my $remport = 80;
18197: if ($remprotocol eq 'https') {
18198: $remport = 443;
18199: }
18200: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
18201: if ($cached) {
18202: unless ($nocache) {
18203: if ($result) {
18204: return 1;
18205: } else {
18206: return 0;
18207: }
18208: }
18209: }
18210: my $uselink;
18211: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 18212: my $ua = LWP::UserAgent->new;
18213: $ua->timeout(5);
18214: my $response=$ua->request($request);
1.1075.2.135 raeburn 18215: if ($response->is_success()) {
18216: my $secpolicy = lc($response->header('content-security-policy'));
18217: my $xframeop = lc($response->header('x-frame-options'));
18218: $secpolicy =~ s/^\s+|\s+$//g;
18219: $xframeop =~ s/^\s+|\s+$//g;
18220: if (($secpolicy ne '') || ($xframeop ne '')) {
18221: my $remotehost = $remprotocol.'://'.$remhost;
18222: my ($origin,$protocol,$port);
18223: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18224: $port = $ENV{'SERVER_PORT'};
18225: } else {
18226: $port = 80;
18227: }
18228: if ($absolute eq '') {
18229: $protocol = 'http:';
18230: if ($port == 443) {
18231: $protocol = 'https:';
18232: }
18233: $origin = $protocol.'//'.lc($hostname);
18234: } else {
18235: $origin = lc($absolute);
18236: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18237: }
18238: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18239: my $framepolicy = $1;
18240: $framepolicy =~ s/^\s+|\s+$//g;
18241: my @policies = split(/\s+/,$framepolicy);
18242: if (@policies) {
18243: if (grep(/^\Q'none'\E$/,@policies)) {
18244: $uselink = 1;
18245: } else {
18246: $uselink = 1;
18247: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18248: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18249: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18250: undef($uselink);
18251: }
18252: if ($uselink) {
18253: if (grep(/^\Q'self'\E$/,@policies)) {
18254: if (($origin ne '') && ($remotehost eq $origin)) {
18255: undef($uselink);
18256: }
18257: }
18258: }
18259: if ($uselink) {
18260: my @possok;
18261: if ($ip ne '') {
18262: push(@possok,$ip);
18263: }
18264: my $hoststr = '';
18265: foreach my $part (reverse(split(/\./,$hostname))) {
18266: if ($hoststr eq '') {
18267: $hoststr = $part;
18268: } else {
18269: $hoststr = "$part.$hoststr";
18270: }
18271: if ($hoststr eq $hostname) {
18272: push(@possok,$hostname);
18273: } else {
18274: push(@possok,"*.$hoststr");
18275: }
18276: }
18277: if (@possok) {
18278: foreach my $poss (@possok) {
18279: last if (!$uselink);
18280: foreach my $policy (@policies) {
18281: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18282: undef($uselink);
18283: last;
18284: }
18285: }
18286: }
18287: }
18288: }
18289: }
18290: }
18291: } elsif ($xframeop ne '') {
18292: $uselink = 1;
18293: my @policies = split(/\s*,\s*/,$xframeop);
18294: if (@policies) {
18295: unless (grep(/^deny$/,@policies)) {
18296: if ($origin ne '') {
18297: if (grep(/^sameorigin$/,@policies)) {
18298: if ($remotehost eq $origin) {
18299: undef($uselink);
18300: }
18301: }
18302: if ($uselink) {
18303: foreach my $policy (@policies) {
18304: if ($policy =~ /^allow-from\s*(.+)$/) {
18305: my $allowfrom = $1;
18306: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18307: undef($uselink);
18308: last;
18309: }
18310: }
18311: }
18312: }
18313: }
18314: }
18315: }
18316: }
18317: }
18318: }
18319: if ($nocache) {
18320: if ($cached) {
18321: my $devalidate;
18322: if ($uselink && !$result) {
18323: $devalidate = 1;
18324: } elsif (!$uselink && $result) {
18325: $devalidate = 1;
18326: }
18327: if ($devalidate) {
18328: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18329: }
18330: }
18331: } else {
18332: if ($uselink) {
18333: $result = 1;
18334: } else {
18335: $result = 0;
18336: }
18337: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18338: }
18339: return $uselink;
18340: }
18341:
1.1075.2.161. .1(raebu 18342:21): sub page_menu {
18343:21): my ($menucolls,$menunum) = @_;
18344:21): my %menu;
18345:21): foreach my $item (split(/;/,$menucolls)) {
18346:21): my ($num,$value) = split(/\%/,$item);
18347:21): if ($num eq $menunum) {
18348:21): my @entries = split(/\&/,$value);
18349:21): foreach my $entry (@entries) {
18350:21): my ($name,$fields) = split(/=/,$entry);
18351:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
18352:21): $menu{$name} = $fields;
18353:21): } else {
18354:21): my @shown;
18355:21): if ($fields =~ /,/) {
18356:21): @shown = split(/,/,$fields);
18357:21): } else {
18358:21): @shown = ($fields);
18359:21): }
18360:21): if (@shown) {
18361:21): foreach my $field (@shown) {
18362:21): next if ($field eq '');
18363:21): $menu{$field} = 1;
18364:21): }
18365:21): }
18366:21): }
18367:21): }
18368:21): }
18369:21): }
18370:21): return %menu;
18371:21): }
18372:21):
1.112 bowersj2 18373: 1;
18374: __END__;
1.41 ng 18375:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>