Annotation of loncom/interface/loncommon.pm, revision 1.1376
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1376 ! raeburn 4: # $Id: loncommon.pm,v 1.1375 2022/01/18 21:03:15 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.1328 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1241 raeburn 77: use DateTime::Locale;
1.1220 raeburn 78: use Encode();
1.1091 foxr 79: use Text::Aspell;
1.1094 raeburn 80: use Authen::Captcha;
81: use Captcha::reCAPTCHA;
1.1234 raeburn 82: use JSON::DWIW;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.1292 raeburn 87: use File::Copy();
1.1300 raeburn 88: use File::Path();
1.1309 raeburn 89: use String::CRC32();
90: use Short::URL();
1.117 www 91:
1.517 raeburn 92: # ---------------------------------------------- Designs
93: use vars qw(%defaultdesign);
94:
1.22 www 95: my $readit;
96:
1.517 raeburn 97:
1.157 matthew 98: ##
99: ## Global Variables
100: ##
1.46 matthew 101:
1.643 foxr 102:
103: # ----------------------------------------------- SSI with retries:
104: #
105:
106: =pod
107:
1.648 raeburn 108: =head1 Server Side include with retries:
1.643 foxr 109:
110: =over 4
111:
1.648 raeburn 112: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 113:
114: Performs an ssi with some number of retries. Retries continue either
115: until the result is ok or until the retry count supplied by the
116: caller is exhausted.
117:
118: Inputs:
1.648 raeburn 119:
120: =over 4
121:
1.643 foxr 122: resource - Identifies the resource to insert.
1.648 raeburn 123:
1.643 foxr 124: retries - Count of the number of retries allowed.
1.648 raeburn 125:
1.643 foxr 126: form - Hash that identifies the rendering options.
127:
1.648 raeburn 128: =back
129:
130: Returns:
131:
132: =over 4
133:
1.643 foxr 134: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 135:
1.643 foxr 136: response - The response from the last attempt (which may or may not have been successful.
137:
1.648 raeburn 138: =back
139:
140: =back
141:
1.643 foxr 142: =cut
143:
144: sub ssi_with_retries {
145: my ($resource, $retries, %form) = @_;
146:
147:
148: my $ok = 0; # True if we got a good response.
149: my $content;
150: my $response;
151:
152: # Try to get the ssi done. within the retries count:
153:
154: do {
155: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
156: $ok = $response->is_success;
1.650 www 157: if (!$ok) {
158: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
159: }
1.643 foxr 160: $retries--;
161: } while (!$ok && ($retries > 0));
162:
163: if (!$ok) {
164: $content = ''; # On error return an empty content.
165: }
166: return ($content, $response);
167:
168: }
169:
170:
171:
1.20 www 172: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 173: my %language;
1.124 www 174: my %supported_language;
1.1088 foxr 175: my %supported_codes;
1.1048 foxr 176: my %latex_language; # For choosing hyphenation in <transl..>
177: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 178: my %cprtag;
1.192 taceyjo1 179: my %scprtag;
1.351 www 180: my %fe; my %fd; my %fm;
1.41 ng 181: my %category_extensions;
1.12 harris41 182:
1.46 matthew 183: # ---------------------------------------------- Thesaurus variables
1.144 matthew 184: #
185: # %Keywords:
186: # A hash used by &keyword to determine if a word is considered a keyword.
187: # $thesaurus_db_file
188: # Scalar containing the full path to the thesaurus database.
1.46 matthew 189:
190: my %Keywords;
191: my $thesaurus_db_file;
192:
1.144 matthew 193: #
194: # Initialize values from language.tab, copyright.tab, filetypes.tab,
195: # thesaurus.tab, and filecategories.tab.
196: #
1.18 www 197: BEGIN {
1.46 matthew 198: # Variable initialization
199: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
200: #
1.22 www 201: unless ($readit) {
1.12 harris41 202: # ------------------------------------------------------------------- languages
203: {
1.158 raeburn 204: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
205: '/language.tab';
1.1317 raeburn 206: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 207: while (my $line = <$fh>) {
208: next if ($line=~/^\#/);
209: chomp($line);
1.1088 foxr 210: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 211: $language{$key}=$val.' - '.$enc;
212: if ($sup) {
213: $supported_language{$key}=$sup;
1.1088 foxr 214: $supported_codes{$key} = $code;
1.158 raeburn 215: }
1.1048 foxr 216: if ($latex) {
217: $latex_language_bykey{$key} = $latex;
1.1088 foxr 218: $latex_language{$code} = $latex;
1.1048 foxr 219: }
1.158 raeburn 220: }
221: close($fh);
222: }
1.12 harris41 223: }
224: # ------------------------------------------------------------------ copyrights
225: {
1.158 raeburn 226: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
227: '/copyright.tab';
1.1317 raeburn 228: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 229: while (my $line = <$fh>) {
230: next if ($line=~/^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 233: $cprtag{$key}=$val;
234: }
235: close($fh);
236: }
1.12 harris41 237: }
1.351 www 238: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 239: {
240: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
241: '/source_copyright.tab';
1.1317 raeburn 242: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 247: $scprtag{$key}=$val;
248: }
249: close($fh);
250: }
251: }
1.63 www 252:
1.517 raeburn 253: # -------------------------------------------------------------- default domain designs
1.63 www 254: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 255: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 256: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 257: while (my $line = <$fh>) {
258: next if ($line =~ /^\#/);
259: chomp($line);
260: my ($key,$val)=(split(/\=/,$line));
261: if ($val) { $defaultdesign{$key}=$val; }
262: }
263: close($fh);
1.63 www 264: }
265:
1.15 harris41 266: # ------------------------------------------------------------- file categories
267: {
1.158 raeburn 268: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
269: '/filecategories.tab';
1.1317 raeburn 270: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 271: while (my $line = <$fh>) {
272: next if ($line =~ /^\#/);
273: chomp($line);
274: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 275: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 276: }
277: close($fh);
278: }
279:
1.15 harris41 280: }
1.12 harris41 281: # ------------------------------------------------------------------ file types
282: {
1.158 raeburn 283: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
284: '/filetypes.tab';
1.1317 raeburn 285: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 286: while (my $line = <$fh>) {
287: next if ($line =~ /^\#/);
288: chomp($line);
289: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 290: if ($descr ne '') {
291: $fe{$ending}=lc($emb);
292: $fd{$ending}=$descr;
1.351 www 293: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 294: }
295: }
296: close($fh);
297: }
1.12 harris41 298: }
1.22 www 299: &Apache::lonnet::logthis(
1.705 tempelho 300: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 301: $readit=1;
1.46 matthew 302: } # end of unless($readit)
1.32 matthew 303:
304: }
1.112 bowersj2 305:
1.42 matthew 306: ###############################################################
307: ## HTML and Javascript Helper Functions ##
308: ###############################################################
309:
310: =pod
311:
1.112 bowersj2 312: =head1 HTML and Javascript Functions
1.42 matthew 313:
1.112 bowersj2 314: =over 4
315:
1.648 raeburn 316: =item * &browser_and_searcher_javascript()
1.112 bowersj2 317:
318: X<browsing, javascript>X<searching, javascript>Returns a string
319: containing javascript with two functions, C<openbrowser> and
320: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
321: tags.
1.42 matthew 322:
1.648 raeburn 323: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 324:
325: inputs: formname, elementname, only, omit
326:
327: formname and elementname indicate the name of the html form and name of
328: the element that the results of the browsing selection are to be placed in.
329:
330: Specifying 'only' will restrict the browser to displaying only files
1.185 www 331: with the given extension. Can be a comma separated list.
1.42 matthew 332:
333: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 334: with the given extension. Can be a comma separated list.
1.42 matthew 335:
1.648 raeburn 336: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 337:
338: Inputs: formname, elementname
339:
340: formname and elementname specify the name of the html form and the name
341: of the element the selection from the search results will be placed in.
1.542 raeburn 342:
1.42 matthew 343: =cut
344:
345: sub browser_and_searcher_javascript {
1.199 albertel 346: my ($mode)=@_;
347: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 348: my $resurl=&escape_single(&lastresurl());
1.42 matthew 349: return <<END;
1.219 albertel 350: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 351: var editbrowser = null;
1.135 albertel 352: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 353: var url = '$resurl/?';
1.42 matthew 354: if (editbrowser == null) {
355: url += 'launch=1&';
356: }
357: url += 'catalogmode=interactive&';
1.199 albertel 358: url += 'mode=$mode&';
1.611 albertel 359: url += 'inhibitmenu=yes&';
1.42 matthew 360: url += 'form=' + formname + '&';
361: if (only != null) {
362: url += 'only=' + only + '&';
1.217 albertel 363: } else {
364: url += 'only=&';
365: }
1.42 matthew 366: if (omit != null) {
367: url += 'omit=' + omit + '&';
1.217 albertel 368: } else {
369: url += 'omit=&';
370: }
1.135 albertel 371: if (titleelement != null) {
372: url += 'titleelement=' + titleelement + '&';
1.217 albertel 373: } else {
374: url += 'titleelement=&';
375: }
1.42 matthew 376: url += 'element=' + elementname + '';
377: var title = 'Browser';
1.435 albertel 378: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 379: options += ',width=700,height=600';
380: editbrowser = open(url,title,options,'1');
381: editbrowser.focus();
382: }
383: var editsearcher;
1.135 albertel 384: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 385: var url = '/adm/searchcat?';
386: if (editsearcher == null) {
387: url += 'launch=1&';
388: }
389: url += 'catalogmode=interactive&';
1.199 albertel 390: url += 'mode=$mode&';
1.42 matthew 391: url += 'form=' + formname + '&';
1.135 albertel 392: if (titleelement != null) {
393: url += 'titleelement=' + titleelement + '&';
1.217 albertel 394: } else {
395: url += 'titleelement=&';
396: }
1.42 matthew 397: url += 'element=' + elementname + '';
398: var title = 'Search';
1.435 albertel 399: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 400: options += ',width=700,height=600';
401: editsearcher = open(url,title,options,'1');
402: editsearcher.focus();
403: }
1.219 albertel 404: // END LON-CAPA Internal -->
1.42 matthew 405: END
1.170 www 406: }
407:
408: sub lastresurl {
1.258 albertel 409: if ($env{'environment.lastresurl'}) {
410: return $env{'environment.lastresurl'}
1.170 www 411: } else {
412: return '/res';
413: }
414: }
415:
416: sub storeresurl {
417: my $resurl=&Apache::lonnet::clutter(shift);
418: unless ($resurl=~/^\/res/) { return 0; }
419: $resurl=~s/\/$//;
420: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 421: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 422: return 1;
1.42 matthew 423: }
424:
1.74 www 425: sub studentbrowser_javascript {
1.111 www 426: unless (
1.258 albertel 427: (($env{'request.course.id'}) &&
1.302 albertel 428: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
429: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
430: '/'.$env{'request.course.sec'})
431: ))
1.258 albertel 432: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 433: ) { return ''; }
1.74 www 434: return (<<'ENDSTDBRW');
1.776 bisitz 435: <script type="text/javascript" language="Javascript">
1.824 bisitz 436: // <![CDATA[
1.74 www 437: var stdeditbrowser;
1.1337 raeburn 438: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 439: var url = '/adm/pickstudent?';
440: var filter;
1.558 albertel 441: if (!ignorefilter) {
442: eval('filter=document.'+formname+'.'+uname+'.value;');
443: }
1.74 www 444: if (filter != null) {
445: if (filter != '') {
446: url += 'filter='+filter+'&';
447: }
448: }
449: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 450: '&udomelement='+udom+
451: '&clicker='+clicker;
1.111 www 452: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 453: if (courseadv == 'condition') {
454: if (document.getElementById('courseadv')) {
455: courseadv = document.getElementById('courseadv').value;
456: }
457: }
458: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 459: var title = 'Student_Browser';
1.74 www 460: var options = 'scrollbars=1,resizable=1,menubar=0';
461: options += ',width=700,height=600';
462: stdeditbrowser = open(url,title,options,'1');
463: stdeditbrowser.focus();
464: }
1.824 bisitz 465: // ]]>
1.74 www 466: </script>
467: ENDSTDBRW
468: }
1.42 matthew 469:
1.1003 www 470: sub resourcebrowser_javascript {
471: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 472: return (<<'ENDRESBRW');
1.1003 www 473: <script type="text/javascript" language="Javascript">
474: // <![CDATA[
475: var reseditbrowser;
1.1004 www 476: function openresbrowser(formname,reslink) {
1.1005 www 477: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 478: var title = 'Resource_Browser';
479: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 480: options += ',width=700,height=500';
1.1004 www 481: reseditbrowser = open(url,title,options,'1');
482: reseditbrowser.focus();
1.1003 www 483: }
484: // ]]>
485: </script>
1.1004 www 486: ENDRESBRW
1.1003 www 487: }
488:
1.74 www 489: sub selectstudent_link {
1.1337 raeburn 490: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 491: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
492: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
493: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 494: if ($env{'request.course.id'}) {
1.302 albertel 495: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
496: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
497: '/'.$env{'request.course.sec'})) {
1.111 www 498: return '';
499: }
1.999 www 500: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 501: if ($courseadv eq 'only') {
502: $callargs .= ",'',1,'$courseadv'";
503: } elsif ($courseadv eq 'none') {
504: $callargs .= ",'','','$courseadv'";
505: } elsif ($courseadv eq 'condition') {
506: $callargs .= ",'','','$courseadv'";
1.793 raeburn 507: }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openstdbrowser('.$callargs.');">'.
510: &mt('Select User').'</a></span>';
1.74 www 511: }
1.258 albertel 512: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 513: $callargs .= ",'',1";
1.793 raeburn 514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openstdbrowser('.$callargs.');">'.
516: &mt('Select User').'</a></span>';
1.111 www 517: }
518: return '';
1.91 www 519: }
520:
1.1004 www 521: sub selectresource_link {
522: my ($form,$reslink,$arg)=@_;
523:
524: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
525: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
526: unless ($env{'request.course.id'}) { return $arg; }
527: return '<span class="LC_nobreak">'.
528: '<a href="javascript:openresbrowser('.$callargs.');">'.
529: $arg.'</a></span>';
530: }
531:
532:
533:
1.653 raeburn 534: sub authorbrowser_javascript {
535: return <<"ENDAUTHORBRW";
1.776 bisitz 536: <script type="text/javascript" language="JavaScript">
1.824 bisitz 537: // <![CDATA[
1.653 raeburn 538: var stdeditbrowser;
539:
540: function openauthorbrowser(formname,udom) {
541: var url = '/adm/pickauthor?';
542: url += 'form='+formname+'&roledom='+udom;
543: var title = 'Author_Browser';
544: var options = 'scrollbars=1,resizable=1,menubar=0';
545: options += ',width=700,height=600';
546: stdeditbrowser = open(url,title,options,'1');
547: stdeditbrowser.focus();
548: }
549:
1.824 bisitz 550: // ]]>
1.653 raeburn 551: </script>
552: ENDAUTHORBRW
553: }
554:
1.91 www 555: sub coursebrowser_javascript {
1.1116 raeburn 556: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 557: $credits_element,$instcode) = @_;
1.932 raeburn 558: my $wintitle = 'Course_Browser';
1.931 raeburn 559: if ($crstype eq 'Community') {
1.932 raeburn 560: $wintitle = 'Community_Browser';
1.909 raeburn 561: }
1.876 raeburn 562: my $id_functions = &javascript_index_functions();
563: my $output = '
1.776 bisitz 564: <script type="text/javascript" language="JavaScript">
1.824 bisitz 565: // <![CDATA[
1.468 raeburn 566: var stdeditbrowser;'."\n";
1.876 raeburn 567:
568: $output .= <<"ENDSTDBRW";
1.909 raeburn 569: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 570: var url = '/adm/pickcourse?';
1.895 raeburn 571: var formid = getFormIdByName(formname);
1.876 raeburn 572: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 573: if (domainfilter != null) {
574: if (domainfilter != '') {
575: url += 'domainfilter='+domainfilter+'&';
576: }
577: }
1.91 www 578: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 579: '&cdomelement='+udom+
580: '&cnameelement='+desc;
1.468 raeburn 581: if (extra_element !=null && extra_element != '') {
1.594 raeburn 582: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 583: url += '&roleelement='+extra_element;
584: if (domainfilter == null || domainfilter == '') {
585: url += '&domainfilter='+extra_element;
586: }
1.234 raeburn 587: }
1.468 raeburn 588: else {
589: if (formname == 'portform') {
590: url += '&setroles='+extra_element;
1.800 raeburn 591: } else {
592: if (formname == 'rules') {
593: url += '&fixeddom='+extra_element;
594: }
1.468 raeburn 595: }
596: }
1.230 raeburn 597: }
1.909 raeburn 598: if (type != null && type != '') {
599: url += '&type='+type;
600: }
601: if (type_elem != null && type_elem != '') {
602: url += '&typeelement='+type_elem;
603: }
1.872 raeburn 604: if (formname == 'ccrs') {
605: var ownername = document.forms[formid].ccuname.value;
606: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 607: url += '&cloner='+ownername+':'+ownerdom;
608: if (type == 'Course') {
609: url += '&crscode='+document.forms[formid].crscode.value;
610: }
1.1221 raeburn 611: }
612: if (formname == 'requestcrs') {
613: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 614: }
1.293 raeburn 615: if (multflag !=null && multflag != '') {
616: url += '&multiple='+multflag;
617: }
1.909 raeburn 618: var title = '$wintitle';
1.91 www 619: var options = 'scrollbars=1,resizable=1,menubar=0';
620: options += ',width=700,height=600';
621: stdeditbrowser = open(url,title,options,'1');
622: stdeditbrowser.focus();
623: }
1.876 raeburn 624: $id_functions
625: ENDSTDBRW
1.1116 raeburn 626: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
627: $output .= &setsec_javascript($sec_element,$formname,$role_element,
628: $credits_element);
1.876 raeburn 629: }
630: $output .= '
631: // ]]>
632: </script>';
633: return $output;
634: }
635:
636: sub javascript_index_functions {
637: return <<"ENDJS";
638:
639: function getFormIdByName(formname) {
640: for (var i=0;i<document.forms.length;i++) {
641: if (document.forms[i].name == formname) {
642: return i;
643: }
644: }
645: return -1;
646: }
647:
648: function getIndexByName(formid,item) {
649: for (var i=0;i<document.forms[formid].elements.length;i++) {
650: if (document.forms[formid].elements[i].name == item) {
651: return i;
652: }
653: }
654: return -1;
655: }
1.468 raeburn 656:
1.876 raeburn 657: function getDomainFromSelectbox(formname,udom) {
658: var userdom;
659: var formid = getFormIdByName(formname);
660: if (formid > -1) {
661: var domid = getIndexByName(formid,udom);
662: if (domid > -1) {
663: if (document.forms[formid].elements[domid].type == 'select-one') {
664: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
665: }
666: if (document.forms[formid].elements[domid].type == 'hidden') {
667: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 668: }
669: }
670: }
1.876 raeburn 671: return userdom;
672: }
673:
674: ENDJS
1.468 raeburn 675:
1.876 raeburn 676: }
677:
1.1017 raeburn 678: sub javascript_array_indexof {
1.1018 raeburn 679: return <<ENDJS;
1.1017 raeburn 680: <script type="text/javascript" language="JavaScript">
681: // <![CDATA[
682:
683: if (!Array.prototype.indexOf) {
684: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
685: "use strict";
686: if (this === void 0 || this === null) {
687: throw new TypeError();
688: }
689: var t = Object(this);
690: var len = t.length >>> 0;
691: if (len === 0) {
692: return -1;
693: }
694: var n = 0;
695: if (arguments.length > 0) {
696: n = Number(arguments[1]);
1.1088 foxr 697: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 698: n = 0;
699: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
700: n = (n > 0 || -1) * Math.floor(Math.abs(n));
701: }
702: }
703: if (n >= len) {
704: return -1;
705: }
706: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
707: for (; k < len; k++) {
708: if (k in t && t[k] === searchElement) {
709: return k;
710: }
711: }
712: return -1;
713: }
714: }
715:
716: // ]]>
717: </script>
718:
719: ENDJS
720:
721: }
722:
1.876 raeburn 723: sub userbrowser_javascript {
724: my $id_functions = &javascript_index_functions();
725: return <<"ENDUSERBRW";
726:
1.888 raeburn 727: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 728: var url = '/adm/pickuser?';
729: var userdom = getDomainFromSelectbox(formname,udom);
730: if (userdom != null) {
731: if (userdom != '') {
732: url += 'srchdom='+userdom+'&';
733: }
734: }
735: url += 'form=' + formname + '&unameelement='+uname+
736: '&udomelement='+udom+
737: '&ulastelement='+ulast+
738: '&ufirstelement='+ufirst+
739: '&uemailelement='+uemail+
1.881 raeburn 740: '&hideudomelement='+hideudom+
741: '&coursedom='+crsdom;
1.888 raeburn 742: if ((caller != null) && (caller != undefined)) {
743: url += '&caller='+caller;
744: }
1.876 raeburn 745: var title = 'User_Browser';
746: var options = 'scrollbars=1,resizable=1,menubar=0';
747: options += ',width=700,height=600';
748: var stdeditbrowser = open(url,title,options,'1');
749: stdeditbrowser.focus();
750: }
751:
1.888 raeburn 752: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 753: var formid = getFormIdByName(formname);
754: if (formid > -1) {
1.888 raeburn 755: var unameid = getIndexByName(formid,uname);
1.876 raeburn 756: var domid = getIndexByName(formid,udom);
757: var hidedomid = getIndexByName(formid,origdom);
758: if (hidedomid > -1) {
759: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 760: var unameval = document.forms[formid].elements[unameid].value;
761: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
762: if (domid > -1) {
763: var slct = document.forms[formid].elements[domid];
764: if (slct.type == 'select-one') {
765: var i;
766: for (i=0;i<slct.length;i++) {
767: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
768: }
769: }
770: if (slct.type == 'hidden') {
771: slct.value = fixeddom;
1.876 raeburn 772: }
773: }
1.468 raeburn 774: }
775: }
776: }
1.876 raeburn 777: return;
778: }
779:
780: $id_functions
781: ENDUSERBRW
1.468 raeburn 782: }
783:
784: sub setsec_javascript {
1.1116 raeburn 785: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 786: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
787: $communityrolestr);
788: if ($role_element ne '') {
789: my @allroles = ('st','ta','ep','in','ad');
790: foreach my $crstype ('Course','Community') {
791: if ($crstype eq 'Community') {
792: foreach my $role (@allroles) {
793: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
794: }
795: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
796: } else {
797: foreach my $role (@allroles) {
798: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
799: }
800: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
801: }
802: }
803: $rolestr = '"'.join('","',@allroles).'"';
804: $courserolestr = '"'.join('","',@courserolenames).'"';
805: $communityrolestr = '"'.join('","',@communityrolenames).'"';
806: }
1.468 raeburn 807: my $setsections = qq|
808: function setSect(sectionlist) {
1.629 raeburn 809: var sectionsArray = new Array();
810: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
811: sectionsArray = sectionlist.split(",");
812: }
1.468 raeburn 813: var numSections = sectionsArray.length;
814: document.$formname.$sec_element.length = 0;
815: if (numSections == 0) {
816: document.$formname.$sec_element.multiple=false;
817: document.$formname.$sec_element.size=1;
818: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
819: } else {
820: if (numSections == 1) {
821: document.$formname.$sec_element.multiple=false;
822: document.$formname.$sec_element.size=1;
823: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
824: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
825: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
826: } else {
827: for (var i=0; i<numSections; i++) {
828: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
829: }
830: document.$formname.$sec_element.multiple=true
831: if (numSections < 3) {
832: document.$formname.$sec_element.size=numSections;
833: } else {
834: document.$formname.$sec_element.size=3;
835: }
836: document.$formname.$sec_element.options[0].selected = false
837: }
838: }
1.91 www 839: }
1.905 raeburn 840:
841: function setRole(crstype) {
1.468 raeburn 842: |;
1.905 raeburn 843: if ($role_element eq '') {
844: $setsections .= ' return;
845: }
846: ';
847: } else {
848: $setsections .= qq|
849: var elementLength = document.$formname.$role_element.length;
850: var allroles = Array($rolestr);
851: var courserolenames = Array($courserolestr);
852: var communityrolenames = Array($communityrolestr);
853: if (elementLength != undefined) {
854: if (document.$formname.$role_element.options[5].value == 'cc') {
855: if (crstype == 'Course') {
856: return;
857: } else {
858: allroles[5] = 'co';
859: for (var i=0; i<6; i++) {
860: document.$formname.$role_element.options[i].value = allroles[i];
861: document.$formname.$role_element.options[i].text = communityrolenames[i];
862: }
863: }
864: } else {
865: if (crstype == 'Community') {
866: return;
867: } else {
868: allroles[5] = 'cc';
869: for (var i=0; i<6; i++) {
870: document.$formname.$role_element.options[i].value = allroles[i];
871: document.$formname.$role_element.options[i].text = courserolenames[i];
872: }
873: }
874: }
875: }
876: return;
877: }
878: |;
879: }
1.1116 raeburn 880: if ($credits_element) {
881: $setsections .= qq|
882: function setCredits(defaultcredits) {
883: document.$formname.$credits_element.value = defaultcredits;
884: return;
885: }
886: |;
887: }
1.468 raeburn 888: return $setsections;
889: }
890:
1.91 www 891: sub selectcourse_link {
1.909 raeburn 892: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
893: $typeelement) = @_;
894: my $type = $selecttype;
1.871 raeburn 895: my $linktext = &mt('Select Course');
896: if ($selecttype eq 'Community') {
1.909 raeburn 897: $linktext = &mt('Select Community');
1.1239 raeburn 898: } elsif ($selecttype eq 'Placement') {
899: $linktext = &mt('Select Placement Test');
1.906 raeburn 900: } elsif ($selecttype eq 'Course/Community') {
901: $linktext = &mt('Select Course/Community');
1.909 raeburn 902: $type = '';
1.1019 raeburn 903: } elsif ($selecttype eq 'Select') {
904: $linktext = &mt('Select');
905: $type = '';
1.871 raeburn 906: }
1.787 bisitz 907: return '<span class="LC_nobreak">'
908: ."<a href='"
909: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
910: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 911: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 912: ."'>".$linktext.'</a>'
1.787 bisitz 913: .'</span>';
1.74 www 914: }
1.42 matthew 915:
1.653 raeburn 916: sub selectauthor_link {
917: my ($form,$udom)=@_;
918: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
919: &mt('Select Author').'</a>';
920: }
921:
1.876 raeburn 922: sub selectuser_link {
1.881 raeburn 923: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 924: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 925: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 926: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 927: ');">'.$linktext.'</a>';
1.876 raeburn 928: }
929:
1.273 raeburn 930: sub check_uncheck_jscript {
931: my $jscript = <<"ENDSCRT";
932: function checkAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
1.1093 raeburn 935: if (!field[i].disabled) {
936: field[i].checked = true;
937: }
1.273 raeburn 938: }
939: } else {
1.1093 raeburn 940: if (!field.disabled) {
941: field.checked = true;
942: }
1.273 raeburn 943: }
944: }
945:
946: function uncheckAll(field) {
947: if (field.length > 0) {
948: for (i = 0; i < field.length; i++) {
949: field[i].checked = false ;
1.543 albertel 950: }
951: } else {
1.273 raeburn 952: field.checked = false ;
953: }
954: }
955: ENDSCRT
956: return $jscript;
957: }
958:
1.656 www 959: sub select_timezone {
1.1256 raeburn 960: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
961: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 962: if ($includeempty) {
963: $output .= '<option value=""';
964: if (($selected eq '') || ($selected eq 'local')) {
965: $output .= ' selected="selected" ';
966: }
967: $output .= '> </option>';
968: }
1.657 raeburn 969: my @timezones = DateTime::TimeZone->all_names;
970: foreach my $tzone (@timezones) {
971: $output.= '<option value="'.$tzone.'"';
972: if ($tzone eq $selected) {
973: $output.=' selected="selected"';
974: }
975: $output.=">$tzone</option>\n";
1.656 www 976: }
977: $output.="</select>";
978: return $output;
979: }
1.273 raeburn 980:
1.687 raeburn 981: sub select_datelocale {
1.1256 raeburn 982: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
983: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 984: if ($includeempty) {
985: $output .= '<option value=""';
986: if ($selected eq '') {
987: $output .= ' selected="selected" ';
988: }
989: $output .= '> </option>';
990: }
1.1241 raeburn 991: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 992: my (@possibles,%locale_names);
1.1241 raeburn 993: my @locales = DateTime::Locale->ids();
994: foreach my $id (@locales) {
995: if ($id ne '') {
996: my ($en_terr,$native_terr);
997: my $loc = DateTime::Locale->load($id);
998: if (ref($loc)) {
999: $en_terr = $loc->name();
1000: $native_terr = $loc->native_name();
1.687 raeburn 1001: if (grep(/^en$/,@languages) || !@languages) {
1002: if ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: } elsif ($native_terr ne '') {
1005: $locale_names{$id} = $native_terr;
1006: }
1007: } else {
1008: if ($native_terr ne '') {
1009: $locale_names{$id} = $native_terr.' ';
1010: } elsif ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: }
1013: }
1.1220 raeburn 1014: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1015: push(@possibles,$id);
1016: }
1.687 raeburn 1017: }
1018: }
1019: foreach my $item (sort(@possibles)) {
1020: $output.= '<option value="'.$item.'"';
1021: if ($item eq $selected) {
1022: $output.=' selected="selected"';
1023: }
1024: $output.=">$item";
1025: if ($locale_names{$item} ne '') {
1.1220 raeburn 1026: $output.=' '.$locale_names{$item};
1.687 raeburn 1027: }
1028: $output.="</option>\n";
1029: }
1030: $output.="</select>";
1031: return $output;
1032: }
1033:
1.792 raeburn 1034: sub select_language {
1.1256 raeburn 1035: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1036: my %langchoices;
1037: if ($includeempty) {
1.1117 raeburn 1038: %langchoices = ('' => 'No language preference');
1.792 raeburn 1039: }
1040: foreach my $id (&languageids()) {
1041: my $code = &supportedlanguagecode($id);
1042: if ($code) {
1043: $langchoices{$code} = &plainlanguagedescription($id);
1044: }
1045: }
1.1117 raeburn 1046: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1047: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1048: }
1049:
1.42 matthew 1050: =pod
1.36 matthew 1051:
1.1088 foxr 1052:
1053: =item * &list_languages()
1054:
1055: Returns an array reference that is suitable for use in language prompters.
1056: Each array element is itself a two element array. The first element
1057: is the language code. The second element a descsriptiuon of the
1058: language itself. This is suitable for use in e.g.
1059: &Apache::edit::select_arg (once dereferenced that is).
1060:
1061: =cut
1062:
1063: sub list_languages {
1064: my @lang_choices;
1065:
1066: foreach my $id (&languageids()) {
1067: my $code = &supportedlanguagecode($id);
1068: if ($code) {
1069: my $selector = $supported_codes{$id};
1070: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1071: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1072: }
1073: }
1074: return \@lang_choices;
1075: }
1076:
1077: =pod
1078:
1.648 raeburn 1079: =item * &linked_select_forms(...)
1.36 matthew 1080:
1081: linked_select_forms returns a string containing a <script></script> block
1082: and html for two <select> menus. The select menus will be linked in that
1083: changing the value of the first menu will result in new values being placed
1084: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1085: order unless a defined order is provided.
1.36 matthew 1086:
1087: linked_select_forms takes the following ordered inputs:
1088:
1089: =over 4
1090:
1.112 bowersj2 1091: =item * $formname, the name of the <form> tag
1.36 matthew 1092:
1.112 bowersj2 1093: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1094:
1.112 bowersj2 1095: =item * $firstdefault, the default value for the first menu
1.36 matthew 1096:
1.112 bowersj2 1097: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1098:
1.112 bowersj2 1099: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1102:
1.609 raeburn 1103: =item * $menuorder, the order of values in the first menu
1104:
1.1115 raeburn 1105: =item * $onchangefirst, additional javascript call to execute for an onchange
1106: event for the first <select> tag
1107:
1108: =item * $onchangesecond, additional javascript call to execute for an onchange
1109: event for the second <select> tag
1110:
1.1245 raeburn 1111: =item * $suffix, to differentiate separate uses of select2data javascript
1112: objects in a page.
1113:
1.41 ng 1114: =back
1115:
1.36 matthew 1116: Below is an example of such a hash. Only the 'text', 'default', and
1117: 'select2' keys must appear as stated. keys(%menu) are the possible
1118: values for the first select menu. The text that coincides with the
1.41 ng 1119: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1120: and text for the second menu are given in the hash pointed to by
1121: $menu{$choice1}->{'select2'}.
1122:
1.112 bowersj2 1123: my %menu = ( A1 => { text =>"Choice A1" ,
1124: default => "B3",
1125: select2 => {
1126: B1 => "Choice B1",
1127: B2 => "Choice B2",
1128: B3 => "Choice B3",
1129: B4 => "Choice B4"
1.609 raeburn 1130: },
1131: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1132: },
1133: A2 => { text =>"Choice A2" ,
1134: default => "C2",
1135: select2 => {
1136: C1 => "Choice C1",
1137: C2 => "Choice C2",
1138: C3 => "Choice C3"
1.609 raeburn 1139: },
1140: order => ['C2','C1','C3'],
1.112 bowersj2 1141: },
1142: A3 => { text =>"Choice A3" ,
1143: default => "D6",
1144: select2 => {
1145: D1 => "Choice D1",
1146: D2 => "Choice D2",
1147: D3 => "Choice D3",
1148: D4 => "Choice D4",
1149: D5 => "Choice D5",
1150: D6 => "Choice D6",
1151: D7 => "Choice D7"
1.609 raeburn 1152: },
1153: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1154: }
1155: );
1.36 matthew 1156:
1157: =cut
1158:
1159: sub linked_select_forms {
1160: my ($formname,
1161: $middletext,
1162: $firstdefault,
1163: $firstselectname,
1164: $secondselectname,
1.609 raeburn 1165: $hashref,
1166: $menuorder,
1.1115 raeburn 1167: $onchangefirst,
1.1245 raeburn 1168: $onchangesecond,
1169: $suffix
1.36 matthew 1170: ) = @_;
1171: my $second = "document.$formname.$secondselectname";
1172: my $first = "document.$formname.$firstselectname";
1173: # output the javascript to do the changing
1174: my $result = '';
1.776 bisitz 1175: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1176: $result.="// <![CDATA[\n";
1.1245 raeburn 1177: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1178: $" = '","';
1179: my $debug = '';
1180: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1181: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1182: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1183: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1184: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1185: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1186: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1187: @s2values = @{$hashref->{$s1}->{'order'}};
1188: }
1.36 matthew 1189: $result.="\"@s2values\");\n";
1.1245 raeburn 1190: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1191: my @s2texts;
1192: foreach my $value (@s2values) {
1.1263 raeburn 1193: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1194: }
1195: $result.="\"@s2texts\");\n";
1196: }
1197: $"=' ';
1198: $result.= <<"END";
1199:
1.1245 raeburn 1200: function select1${suffix}_changed() {
1.36 matthew 1201: // Determine new choice
1.1245 raeburn 1202: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1203: // update select2
1.1245 raeburn 1204: var values = select2data${suffix}[newvalue].values;
1205: var texts = select2data${suffix}[newvalue].texts;
1206: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1207: var i;
1208: // out with the old
1.1245 raeburn 1209: $second.options.length = 0;
1210: // in with the new
1.36 matthew 1211: for (i=0;i<values.length; i++) {
1212: $second.options[i] = new Option(values[i]);
1.143 matthew 1213: $second.options[i].value = values[i];
1.36 matthew 1214: $second.options[i].text = texts[i];
1215: if (values[i] == select2def) {
1216: $second.options[i].selected = true;
1217: }
1218: }
1219: }
1.824 bisitz 1220: // ]]>
1.36 matthew 1221: </script>
1222: END
1223: # output the initial values for the selection lists
1.1245 raeburn 1224: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1225: my @order = sort(keys(%{$hashref}));
1226: if (ref($menuorder) eq 'ARRAY') {
1227: @order = @{$menuorder};
1228: }
1229: foreach my $value (@order) {
1.36 matthew 1230: $result.=" <option value=\"$value\" ";
1.253 albertel 1231: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1232: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1233: }
1234: $result .= "</select>\n";
1235: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1236: $result .= $middletext;
1.1115 raeburn 1237: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1238: if ($onchangesecond) {
1239: $result .= ' onchange="'.$onchangesecond.'"';
1240: }
1241: $result .= ">\n";
1.36 matthew 1242: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1243:
1244: my @secondorder = sort(keys(%select2));
1245: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1246: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1247: }
1248: foreach my $value (@secondorder) {
1.36 matthew 1249: $result.=" <option value=\"$value\" ";
1.253 albertel 1250: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1251: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1252: }
1253: $result .= "</select>\n";
1254: # return $debug;
1255: return $result;
1256: } # end of sub linked_select_forms {
1257:
1.45 matthew 1258: =pod
1.44 bowersj2 1259:
1.973 raeburn 1260: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1261:
1.112 bowersj2 1262: Returns a string corresponding to an HTML link to the given help
1263: $topic, where $topic corresponds to the name of a .tex file in
1264: /home/httpd/html/adm/help/tex, with underscores replaced by
1265: spaces.
1266:
1267: $text will optionally be linked to the same topic, allowing you to
1268: link text in addition to the graphic. If you do not want to link
1269: text, but wish to specify one of the later parameters, pass an
1270: empty string.
1271:
1272: $stayOnPage is a value that will be interpreted as a boolean. If true,
1273: the link will not open a new window. If false, the link will open
1274: a new window using Javascript. (Default is false.)
1275:
1276: $width and $height are optional numerical parameters that will
1277: override the width and height of the popped up window, which may
1.973 raeburn 1278: be useful for certain help topics with big pictures included.
1279:
1280: $imgid is the id of the img tag used for the help icon. This may be
1281: used in a javascript call to switch the image src. See
1282: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1283:
1284: =cut
1285:
1286: sub help_open_topic {
1.973 raeburn 1287: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1288: $text = "" if (not defined $text);
1.44 bowersj2 1289: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1290: $width = 500 if (not defined $width);
1.44 bowersj2 1291: $height = 400 if (not defined $height);
1292: my $filename = $topic;
1293: $filename =~ s/ /_/g;
1294:
1.48 bowersj2 1295: my $template = "";
1296: my $link;
1.572 banghart 1297:
1.159 www 1298: $topic=~s/\W/\_/g;
1.44 bowersj2 1299:
1.572 banghart 1300: if (!$stayOnPage) {
1.1033 www 1301: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1302: } elsif ($stayOnPage eq 'popup') {
1303: $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 1304: } else {
1.48 bowersj2 1305: $link = "/adm/help/${filename}.hlp";
1306: }
1307:
1308: # Add the text
1.1314 raeburn 1309: my $target = ' target="_top"';
1310: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1311: $target = '';
1312: }
1.755 neumanie 1313: if ($text ne "") {
1.763 bisitz 1314: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1315: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1316: .$text.'</a>';
1.48 bowersj2 1317: }
1318:
1.763 bisitz 1319: # (Always) Add the graphic
1.179 matthew 1320: my $title = &mt('Online Help');
1.667 raeburn 1321: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1322: if ($imgid ne '') {
1323: $imgid = ' id="'.$imgid.'"';
1324: }
1.1314 raeburn 1325: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1326: .'<img src="'.$helpicon.'" border="0"'
1327: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1328: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1329: .' /></a>';
1330: if ($text ne "") {
1331: $template.='</span>';
1332: }
1.44 bowersj2 1333: return $template;
1334:
1.106 bowersj2 1335: }
1336:
1337: # This is a quicky function for Latex cheatsheet editing, since it
1338: # appears in at least four places
1339: sub helpLatexCheatsheet {
1.1037 www 1340: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1341: my $out;
1.106 bowersj2 1342: my $addOther = '';
1.732 raeburn 1343: if ($topic) {
1.1037 www 1344: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1345: }
1346: $out = '<span>' # Start cheatsheet
1347: .$addOther
1348: .'<span>'
1.1037 www 1349: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1350: .'</span> <span>'
1.1037 www 1351: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1352: .'</span>';
1.732 raeburn 1353: unless ($not_author) {
1.1186 kruse 1354: $out .= '<span>'
1355: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1356: .'</span> <span>'
1357: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1358: .'</span>';
1.732 raeburn 1359: }
1.763 bisitz 1360: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1361: return $out;
1.172 www 1362: }
1363:
1.430 albertel 1364: sub general_help {
1365: my $helptopic='Student_Intro';
1366: if ($env{'request.role'}=~/^(ca|au)/) {
1367: $helptopic='Authoring_Intro';
1.907 raeburn 1368: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1369: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1370: } elsif ($env{'request.role'}=~/^dc/) {
1371: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1372: }
1373: return $helptopic;
1374: }
1375:
1376: sub update_help_link {
1377: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1378: my $origurl = $ENV{'REQUEST_URI'};
1379: $origurl=~s|^/~|/priv/|;
1380: my $timestamp = time;
1381: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1382: $$datum = &escape($$datum);
1383: }
1384:
1385: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1386: my $output .= <<"ENDOUTPUT";
1387: <script type="text/javascript">
1.824 bisitz 1388: // <![CDATA[
1.430 albertel 1389: banner_link = '$banner_link';
1.824 bisitz 1390: // ]]>
1.430 albertel 1391: </script>
1392: ENDOUTPUT
1393: return $output;
1394: }
1395:
1396: # now just updates the help link and generates a blue icon
1.193 raeburn 1397: sub help_open_menu {
1.430 albertel 1398: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1399: = @_;
1.949 droeschl 1400: $stayOnPage = 1;
1.430 albertel 1401: my $output;
1402: if ($component_help) {
1403: if (!$text) {
1404: $output=&help_open_topic($component_help,undef,$stayOnPage,
1405: $width,$height);
1406: } else {
1407: my $help_text;
1408: $help_text=&unescape($topic);
1409: $output='<table><tr><td>'.
1410: &help_open_topic($component_help,$help_text,$stayOnPage,
1411: $width,$height).'</td></tr></table>';
1412: }
1413: }
1414: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1415: return $output.$banner_link;
1416: }
1417:
1418: sub top_nav_help {
1.1369 raeburn 1419: my ($text,$linkattr) = @_;
1.436 albertel 1420: $text = &mt($text);
1.949 droeschl 1421: my $stay_on_page = 1;
1422:
1.1168 raeburn 1423: my ($link,$banner_link);
1424: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1425: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1426: : "javascript:helpMenu('open')";
1427: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1428: }
1.201 raeburn 1429: my $title = &mt('Get help');
1.1168 raeburn 1430: if ($link) {
1431: return <<"END";
1.436 albertel 1432: $banner_link
1.1369 raeburn 1433: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1434: END
1.1168 raeburn 1435: } else {
1436: return ' '.$text.' ';
1437: }
1.436 albertel 1438: }
1439:
1440: sub help_menu_js {
1.1154 raeburn 1441: my ($httphost) = @_;
1.949 droeschl 1442: my $stayOnPage = 1;
1.436 albertel 1443: my $width = 620;
1444: my $height = 600;
1.430 albertel 1445: my $helptopic=&general_help();
1.1154 raeburn 1446: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1447: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1448: my $start_page =
1449: &Apache::loncommon::start_page('Help Menu', undef,
1450: {'frameset' => 1,
1451: 'js_ready' => 1,
1.1154 raeburn 1452: 'use_absolute' => $httphost,
1.331 albertel 1453: 'add_entries' => {
1.1168 raeburn 1454: 'border' => '0',
1.579 raeburn 1455: 'rows' => "110,*",},});
1.331 albertel 1456: my $end_page =
1457: &Apache::loncommon::end_page({'frameset' => 1,
1458: 'js_ready' => 1,});
1459:
1.436 albertel 1460: my $template .= <<"ENDTEMPLATE";
1461: <script type="text/javascript">
1.877 bisitz 1462: // <![CDATA[
1.253 albertel 1463: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1464: var banner_link = '';
1.243 raeburn 1465: function helpMenu(target) {
1466: var caller = this;
1467: if (target == 'open') {
1468: var newWindow = null;
1469: try {
1.262 albertel 1470: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1471: }
1472: catch(error) {
1473: writeHelp(caller);
1474: return;
1475: }
1476: if (newWindow) {
1477: caller = newWindow;
1478: }
1.193 raeburn 1479: }
1.243 raeburn 1480: writeHelp(caller);
1481: return;
1482: }
1483: function writeHelp(caller) {
1.1168 raeburn 1484: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1485: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1486: caller.document.close();
1487: caller.focus();
1.193 raeburn 1488: }
1.877 bisitz 1489: // END LON-CAPA Internal -->
1.253 albertel 1490: // ]]>
1.436 albertel 1491: </script>
1.193 raeburn 1492: ENDTEMPLATE
1493: return $template;
1494: }
1495:
1.172 www 1496: sub help_open_bug {
1497: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1498: unless ($env{'user.adv'}) { return ''; }
1.172 www 1499: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1500: $text = "" if (not defined $text);
1501: $stayOnPage=1;
1.184 albertel 1502: $width = 600 if (not defined $width);
1503: $height = 600 if (not defined $height);
1.172 www 1504:
1505: $topic=~s/\W+/\+/g;
1506: my $link='';
1507: my $template='';
1.379 albertel 1508: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1509: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1510: if (!$stayOnPage)
1511: {
1512: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1513: }
1514: else
1515: {
1516: $link = $url;
1517: }
1.1314 raeburn 1518:
1519: my $target = ' target="_top"';
1520: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1521: $target = '';
1522: }
1.172 www 1523: # Add the text
1524: if ($text ne "")
1525: {
1526: $template .=
1527: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1528: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1529: }
1530:
1531: # Add the graphic
1.179 matthew 1532: my $title = &mt('Report a Bug');
1.215 albertel 1533: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1534: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1535: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1536: ENDTEMPLATE
1537: if ($text ne '') { $template.='</td></tr></table>' };
1538: return $template;
1539:
1540: }
1541:
1542: sub help_open_faq {
1543: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1544: unless ($env{'user.adv'}) { return ''; }
1.172 www 1545: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1546: $text = "" if (not defined $text);
1547: $stayOnPage=1;
1548: $width = 350 if (not defined $width);
1549: $height = 400 if (not defined $height);
1550:
1551: $topic=~s/\W+/\+/g;
1552: my $link='';
1553: my $template='';
1554: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1555: if (!$stayOnPage)
1556: {
1557: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1558: }
1559: else
1560: {
1561: $link = $url;
1562: }
1563:
1564: # Add the text
1565: if ($text ne "")
1566: {
1567: $template .=
1.173 www 1568: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1569: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1570: }
1571:
1572: # Add the graphic
1.179 matthew 1573: my $title = &mt('View the FAQ');
1.215 albertel 1574: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1575: $template .= <<"ENDTEMPLATE";
1.436 albertel 1576: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1577: ENDTEMPLATE
1578: if ($text ne '') { $template.='</td></tr></table>' };
1579: return $template;
1580:
1.44 bowersj2 1581: }
1.37 matthew 1582:
1.180 matthew 1583: ###############################################################
1584: ###############################################################
1585:
1.45 matthew 1586: =pod
1587:
1.648 raeburn 1588: =item * &change_content_javascript():
1.256 matthew 1589:
1590: This and the next function allow you to create small sections of an
1591: otherwise static HTML page that you can update on the fly with
1592: Javascript, even in Netscape 4.
1593:
1594: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1595: must be written to the HTML page once. It will prove the Javascript
1596: function "change(name, content)". Calling the change function with the
1597: name of the section
1598: you want to update, matching the name passed to C<changable_area>, and
1599: the new content you want to put in there, will put the content into
1600: that area.
1601:
1602: B<Note>: Netscape 4 only reserves enough space for the changable area
1603: to contain room for the original contents. You need to "make space"
1604: for whatever changes you wish to make, and be B<sure> to check your
1605: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1606: it's adequate for updating a one-line status display, but little more.
1607: This script will set the space to 100% width, so you only need to
1608: worry about height in Netscape 4.
1609:
1610: Modern browsers are much less limiting, and if you can commit to the
1611: user not using Netscape 4, this feature may be used freely with
1612: pretty much any HTML.
1613:
1614: =cut
1615:
1616: sub change_content_javascript {
1617: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1618: if ($env{'browser.type'} eq 'netscape' &&
1619: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1620: return (<<NETSCAPE4);
1621: function change(name, content) {
1622: doc = document.layers[name+"___escape"].layers[0].document;
1623: doc.open();
1624: doc.write(content);
1625: doc.close();
1626: }
1627: NETSCAPE4
1628: } else {
1629: # Otherwise, we need to use semi-standards-compliant code
1630: # (technically, "innerHTML" isn't standard but the equivalent
1631: # is really scary, and every useful browser supports it
1632: return (<<DOMBASED);
1633: function change(name, content) {
1634: element = document.getElementById(name);
1635: element.innerHTML = content;
1636: }
1637: DOMBASED
1638: }
1639: }
1640:
1641: =pod
1642:
1.648 raeburn 1643: =item * &changable_area($name,$origContent):
1.256 matthew 1644:
1645: This provides a "changable area" that can be modified on the fly via
1646: the Javascript code provided in C<change_content_javascript>. $name is
1647: the name you will use to reference the area later; do not repeat the
1648: same name on a given HTML page more then once. $origContent is what
1649: the area will originally contain, which can be left blank.
1650:
1651: =cut
1652:
1653: sub changable_area {
1654: my ($name, $origContent) = @_;
1655:
1.258 albertel 1656: if ($env{'browser.type'} eq 'netscape' &&
1657: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1658: # If this is netscape 4, we need to use the Layer tag
1659: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1660: } else {
1661: return "<span id='$name'>$origContent</span>";
1662: }
1663: }
1664:
1665: =pod
1666:
1.648 raeburn 1667: =item * &viewport_geometry_js
1.590 raeburn 1668:
1669: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1670:
1671: =cut
1672:
1673:
1674: sub viewport_geometry_js {
1675: return <<"GEOMETRY";
1676: var Geometry = {};
1677: function init_geometry() {
1678: if (Geometry.init) { return };
1679: Geometry.init=1;
1680: if (window.innerHeight) {
1681: Geometry.getViewportHeight = function() { return window.innerHeight; };
1682: Geometry.getViewportWidth = function() { return window.innerWidth; };
1683: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1684: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1685: }
1686: else if (document.documentElement && document.documentElement.clientHeight) {
1687: Geometry.getViewportHeight =
1688: function() { return document.documentElement.clientHeight; };
1689: Geometry.getViewportWidth =
1690: function() { return document.documentElement.clientWidth; };
1691:
1692: Geometry.getHorizontalScroll =
1693: function() { return document.documentElement.scrollLeft; };
1694: Geometry.getVerticalScroll =
1695: function() { return document.documentElement.scrollTop; };
1696: }
1697: else if (document.body.clientHeight) {
1698: Geometry.getViewportHeight =
1699: function() { return document.body.clientHeight; };
1700: Geometry.getViewportWidth =
1701: function() { return document.body.clientWidth; };
1702: Geometry.getHorizontalScroll =
1703: function() { return document.body.scrollLeft; };
1704: Geometry.getVerticalScroll =
1705: function() { return document.body.scrollTop; };
1706: }
1707: }
1708:
1709: GEOMETRY
1710: }
1711:
1712: =pod
1713:
1.648 raeburn 1714: =item * &viewport_size_js()
1.590 raeburn 1715:
1716: 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.
1717:
1718: =cut
1719:
1720: sub viewport_size_js {
1721: my $geometry = &viewport_geometry_js();
1722: return <<"DIMS";
1723:
1724: $geometry
1725:
1726: function getViewportDims(width,height) {
1727: init_geometry();
1728: width.value = Geometry.getViewportWidth();
1729: height.value = Geometry.getViewportHeight();
1730: return;
1731: }
1732:
1733: DIMS
1734: }
1735:
1736: =pod
1737:
1.648 raeburn 1738: =item * &resize_textarea_js()
1.565 albertel 1739:
1740: emits the needed javascript to resize a textarea to be as big as possible
1741:
1742: creates a function resize_textrea that takes two IDs first should be
1743: the id of the element to resize, second should be the id of a div that
1744: surrounds everything that comes after the textarea, this routine needs
1745: to be attached to the <body> for the onload and onresize events.
1746:
1.648 raeburn 1747: =back
1.565 albertel 1748:
1749: =cut
1750:
1751: sub resize_textarea_js {
1.590 raeburn 1752: my $geometry = &viewport_geometry_js();
1.565 albertel 1753: return <<"RESIZE";
1754: <script type="text/javascript">
1.824 bisitz 1755: // <![CDATA[
1.590 raeburn 1756: $geometry
1.565 albertel 1757:
1.588 albertel 1758: function getX(element) {
1759: var x = 0;
1760: while (element) {
1761: x += element.offsetLeft;
1762: element = element.offsetParent;
1763: }
1764: return x;
1765: }
1766: function getY(element) {
1767: var y = 0;
1768: while (element) {
1769: y += element.offsetTop;
1770: element = element.offsetParent;
1771: }
1772: return y;
1773: }
1774:
1775:
1.565 albertel 1776: function resize_textarea(textarea_id,bottom_id) {
1777: init_geometry();
1778: var textarea = document.getElementById(textarea_id);
1779: //alert(textarea);
1780:
1.588 albertel 1781: var textarea_top = getY(textarea);
1.565 albertel 1782: var textarea_height = textarea.offsetHeight;
1783: var bottom = document.getElementById(bottom_id);
1.588 albertel 1784: var bottom_top = getY(bottom);
1.565 albertel 1785: var bottom_height = bottom.offsetHeight;
1786: var window_height = Geometry.getViewportHeight();
1.588 albertel 1787: var fudge = 23;
1.565 albertel 1788: var new_height = window_height-fudge-textarea_top-bottom_height;
1789: if (new_height < 300) {
1790: new_height = 300;
1791: }
1792: textarea.style.height=new_height+'px';
1793: }
1.824 bisitz 1794: // ]]>
1.565 albertel 1795: </script>
1796: RESIZE
1797:
1798: }
1799:
1.1205 golterma 1800: sub colorfuleditor_js {
1.1248 raeburn 1801: my $browse_or_search;
1802: my $respath;
1803: my ($cnum,$cdom) = &crsauthor_url();
1804: if ($cnum) {
1805: $respath = "/res/$cdom/$cnum/";
1806: my %js_lt = &Apache::lonlocal::texthash(
1807: sunm => 'Sub-directory name',
1808: save => 'Save page to make this permanent',
1809: );
1810: &js_escape(\%js_lt);
1811: $browse_or_search = <<"END";
1812:
1813: function toggleChooser(form,element,titleid,only,search) {
1814: var disp = 'none';
1815: if (document.getElementById('chooser_'+element)) {
1816: var curr = document.getElementById('chooser_'+element).style.display;
1817: if (curr == 'none') {
1818: disp='inline';
1819: if (form.elements['chooser_'+element].length) {
1820: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1821: form.elements['chooser_'+element][i].checked = false;
1822: }
1823: }
1824: toggleResImport(form,element);
1825: }
1826: document.getElementById('chooser_'+element).style.display = disp;
1827: }
1828: }
1829:
1830: function toggleCrsFile(form,element,numdirs) {
1831: if (document.getElementById('chooser_'+element+'_crsres')) {
1832: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1833: if (curr == 'none') {
1834: if (numdirs) {
1835: form.elements['coursepath_'+element].selectedIndex = 0;
1836: if (numdirs > 1) {
1837: window['select1'+element+'_changed']();
1838: }
1839: }
1840: }
1841: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1842:
1843: }
1844: if (document.getElementById('chooser_'+element+'_upload')) {
1845: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1846: if (document.getElementById('uploadcrsres_'+element)) {
1847: document.getElementById('uploadcrsres_'+element).value = '';
1848: }
1849: }
1850: return;
1851: }
1852:
1853: function toggleCrsUpload(form,element,numcrsdirs) {
1854: if (document.getElementById('chooser_'+element+'_crsres')) {
1855: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1856: }
1857: if (document.getElementById('chooser_'+element+'_upload')) {
1858: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1859: if (curr == 'none') {
1860: if (numcrsdirs) {
1861: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1862: form.elements['newsubdir_'+element][0].checked = true;
1863: toggleNewsubdir(form,element);
1864: }
1865: }
1866: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1867: }
1868: return;
1869: }
1870:
1871: function toggleResImport(form,element) {
1872: var choices = new Array('crsres','upload');
1873: for (var i=0; i<choices.length; i++) {
1874: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1875: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1876: }
1877: }
1878: }
1879:
1880: function toggleNewsubdir(form,element) {
1881: var newsub = form.elements['newsubdir_'+element];
1882: if (newsub) {
1883: if (newsub.length) {
1884: for (var j=0; j<newsub.length; j++) {
1885: if (newsub[j].checked) {
1886: if (document.getElementById('newsubdirname_'+element)) {
1887: if (newsub[j].value == '1') {
1888: document.getElementById('newsubdirname_'+element).type = "text";
1889: if (document.getElementById('newsubdir_'+element)) {
1890: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1891: }
1892: } else {
1893: document.getElementById('newsubdirname_'+element).type = "hidden";
1894: document.getElementById('newsubdirname_'+element).value = "";
1895: document.getElementById('newsubdir_'+element).innerHTML = "";
1896: }
1897: }
1898: break;
1899: }
1900: }
1901: }
1902: }
1903: }
1904:
1905: function updateCrsFile(form,element) {
1906: var directory = form.elements['coursepath_'+element];
1907: var filename = form.elements['coursefile_'+element];
1908: var path = directory.options[directory.selectedIndex].value;
1909: var file = filename.options[filename.selectedIndex].value;
1910: form.elements[element].value = '$respath';
1911: if (path == '/') {
1912: form.elements[element].value += file;
1913: } else {
1914: form.elements[element].value += path+'/'+file;
1915: }
1916: unClean();
1917: if (document.getElementById('previewimg_'+element)) {
1918: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1919: var newsrc = document.getElementById('previewimg_'+element).src;
1920: }
1921: if (document.getElementById('showimg_'+element)) {
1922: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1923: }
1924: toggleChooser(form,element);
1925: return;
1926: }
1927:
1928: function uploadDone(suffix,name) {
1929: if (name) {
1930: document.forms["lonhomework"].elements[suffix].value = name;
1931: unClean();
1932: toggleChooser(document.forms["lonhomework"],suffix);
1933: }
1934: }
1935:
1936: \$(document).ready(function(){
1937:
1938: \$(document).delegate('form :submit', 'click', function( event ) {
1939: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1940: var buttonId = this.id;
1941: var suffix = buttonId.toString();
1942: suffix = suffix.replace(/^crsupload_/,'');
1943: event.preventDefault();
1944: document.lonhomework.target = 'crsupload_target_'+suffix;
1945: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1946: \$(this.form).submit();
1947: document.lonhomework.target = '';
1948: if (document.getElementById('crsuploadto_'+suffix)) {
1949: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1950: }
1951: return false;
1952: }
1953: });
1954: });
1955: END
1956: }
1.1205 golterma 1957: return <<"COLORFULEDIT"
1958: <script type="text/javascript">
1959: // <![CDATA[>
1960: function fold_box(curDepth, lastresource){
1961:
1962: // we need a list because there can be several blocks you need to fold in one tag
1963: var block = document.getElementsByName('foldblock_'+curDepth);
1964: // but there is only one folding button per tag
1965: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1966:
1967: if(block.item(0).style.display == 'none'){
1968:
1969: foldbutton.value = '@{[&mt("Hide")]}';
1970: for (i = 0; i < block.length; i++){
1971: block.item(i).style.display = '';
1972: }
1973: }else{
1974:
1975: foldbutton.value = '@{[&mt("Show")]}';
1976: for (i = 0; i < block.length; i++){
1977: // block.item(i).style.visibility = 'collapse';
1978: block.item(i).style.display = 'none';
1979: }
1980: };
1981: saveState(lastresource);
1982: }
1983:
1984: function saveState (lastresource) {
1985:
1986: var tag_list = getTagList();
1987: if(tag_list != null){
1988: var timestamp = new Date().getTime();
1989: var key = lastresource;
1990:
1991: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1992: // starting with timestamp
1993: var value = timestamp+';';
1994:
1995: // building the list of key-value pairs
1996: for(var i = 0; i < tag_list.length; i++){
1997: value += tag_list[i]+',';
1998: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1999: }
2000:
2001: // only iterate whole storage if nothing to override
2002: if(localStorage.getItem(key) == null){
2003:
2004: // prevent storage from growing large
2005: if(localStorage.length > 50){
2006: var regex_getTimestamp = /^(?:\d)+;/;
2007: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2008: var oldest_key;
2009:
2010: for(var i = 1; i < localStorage.length; i++){
2011: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2012: oldest_key = localStorage.key(i);
2013: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2014: }
2015: }
2016: localStorage.removeItem(oldest_key);
2017: }
2018: }
2019: localStorage.setItem(key,value);
2020: }
2021: }
2022:
2023: // restore folding status of blocks (on page load)
2024: function restoreState (lastresource) {
2025: if(localStorage.getItem(lastresource) != null){
2026: var key = lastresource;
2027: var value = localStorage.getItem(key);
2028: var regex_delTimestamp = /^\d+;/;
2029:
2030: value.replace(regex_delTimestamp, '');
2031:
2032: var valueArr = value.split(';');
2033: var pairs;
2034: var elements;
2035: for (var i = 0; i < valueArr.length; i++){
2036: pairs = valueArr[i].split(',');
2037: elements = document.getElementsByName(pairs[0]);
2038:
2039: for (var j = 0; j < elements.length; j++){
2040: elements[j].style.display = pairs[1];
2041: if (pairs[1] == "none"){
2042: var regex_id = /([_\\d]+)\$/;
2043: regex_id.exec(pairs[0]);
2044: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2045: }
2046: }
2047: }
2048: }
2049: }
2050:
2051: function getTagList () {
2052:
2053: var stringToSearch = document.lonhomework.innerHTML;
2054:
2055: var ret = new Array();
2056: var regex_findBlock = /(foldblock_.*?)"/g;
2057: var tag_list = stringToSearch.match(regex_findBlock);
2058:
2059: if(tag_list != null){
2060: for(var i = 0; i < tag_list.length; i++){
2061: ret.push(tag_list[i].replace(/"/, ''));
2062: }
2063: }
2064: return ret;
2065: }
2066:
2067: function saveScrollPosition (resource) {
2068: var tag_list = getTagList();
2069:
2070: // we dont always want to jump to the first block
2071: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2072: if(\$(window).scrollTop() > 170){
2073: if(tag_list != null){
2074: var result;
2075: for(var i = 0; i < tag_list.length; i++){
2076: if(isElementInViewport(tag_list[i])){
2077: result += tag_list[i]+';';
2078: }
2079: }
2080: sessionStorage.setItem('anchor_'+resource, result);
2081: }
2082: } else {
2083: // we dont need to save zero, just delete the item to leave everything tidy
2084: sessionStorage.removeItem('anchor_'+resource);
2085: }
2086: }
2087:
2088: function restoreScrollPosition(resource){
2089:
2090: var elem = sessionStorage.getItem('anchor_'+resource);
2091: if(elem != null){
2092: var tag_list = elem.split(';');
2093: var elem_list;
2094:
2095: for(var i = 0; i < tag_list.length; i++){
2096: elem_list = document.getElementsByName(tag_list[i]);
2097:
2098: if(elem_list.length > 0){
2099: elem = elem_list[0];
2100: break;
2101: }
2102: }
2103: elem.scrollIntoView();
2104: }
2105: }
2106:
2107: function isElementInViewport(el) {
2108:
2109: // change to last element instead of first
2110: var elem = document.getElementsByName(el);
2111: var rect = elem[0].getBoundingClientRect();
2112:
2113: return (
2114: rect.top >= 0 &&
2115: rect.left >= 0 &&
2116: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2117: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2118: );
2119: }
2120:
2121: function autosize(depth){
2122: var cmInst = window['cm'+depth];
2123: var fitsizeButton = document.getElementById('fitsize'+depth);
2124:
2125: // is fixed size, switching to dynamic
2126: if (sessionStorage.getItem("autosized_"+depth) == null) {
2127: cmInst.setSize("","auto");
2128: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2129: sessionStorage.setItem("autosized_"+depth, "yes");
2130:
2131: // is dynamic size, switching to fixed
2132: } else {
2133: cmInst.setSize("","300px");
2134: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2135: sessionStorage.removeItem("autosized_"+depth);
2136: }
2137: }
2138:
1.1248 raeburn 2139: $browse_or_search
1.1205 golterma 2140:
2141: // ]]>
2142: </script>
2143: COLORFULEDIT
2144: }
2145:
2146: sub xmleditor_js {
2147: return <<XMLEDIT
2148: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2149: <script type="text/javascript">
2150: // <![CDATA[>
2151:
2152: function saveScrollPosition (resource) {
2153:
2154: var scrollPos = \$(window).scrollTop();
2155: sessionStorage.setItem(resource,scrollPos);
2156: }
2157:
2158: function restoreScrollPosition(resource){
2159:
2160: var scrollPos = sessionStorage.getItem(resource);
2161: \$(window).scrollTop(scrollPos);
2162: }
2163:
2164: // unless internet explorer
2165: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2166:
2167: \$(document).ready(function() {
2168: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2169: });
2170: }
2171:
2172: // inserts text at cursor position into codemirror (xml editor only)
2173: function insertText(text){
2174: cm.focus();
2175: var curPos = cm.getCursor();
2176: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2177: }
2178: // ]]>
2179: </script>
2180: XMLEDIT
2181: }
2182:
2183: sub insert_folding_button {
2184: my $curDepth = $Apache::lonxml::curdepth;
2185: my $lastresource = $env{'request.ambiguous'};
2186:
2187: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2188: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2189: }
2190:
1.1248 raeburn 2191: sub crsauthor_url {
2192: my ($url) = @_;
2193: if ($url eq '') {
2194: $url = $ENV{'REQUEST_URI'};
2195: }
2196: my ($cnum,$cdom);
2197: if ($env{'request.course.id'}) {
2198: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2199: if ($audom ne '' && $auname ne '') {
2200: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2201: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2202: $cnum = $auname;
2203: $cdom = $audom;
2204: }
2205: }
2206: }
2207: return ($cnum,$cdom);
2208: }
2209:
2210: sub import_crsauthor_form {
1.1265 raeburn 2211: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2212: return (0) unless ($env{'request.course.id'});
2213: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2214: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2215: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2216: return (0) unless (($cnum ne '') && ($cdom ne ''));
2217: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2218: my @ids=&Apache::lonnet::current_machine_ids();
2219: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2220:
2221: if (grep(/^\Q$crshome\E$/,@ids)) {
2222: $is_home = 1;
2223: }
2224: $relpath = "/priv/$cdom/$cnum";
2225: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2226: my %lt = &Apache::lonlocal::texthash (
2227: fnam => 'Filename',
2228: dire => 'Directory',
2229: );
2230: my $numdirs = scalar(keys(%files));
2231: my (%possexts,$singledir,@singledirfiles);
2232: if ($only) {
2233: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2234: }
2235: my (%nonemptydirs,$possdirs);
2236: if ($numdirs > 1) {
2237: my @order;
2238: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2239: if (ref($files{$key}) eq 'HASH') {
2240: my $shown = $key;
2241: if ($key eq '') {
2242: $shown = '/';
2243: }
2244: my @ordered = ();
2245: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2246: next if ($file =~ /\.rights$/);
1.1248 raeburn 2247: if ($only) {
2248: my ($ext) = ($file =~ /\.([^.]+)$/);
2249: unless ($possexts{lc($ext)}) {
2250: next;
2251: }
2252: }
2253: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2254: push(@ordered,$file);
2255: }
2256: if (@ordered) {
2257: push(@order,$key);
2258: $nonemptydirs{$key} = 1;
2259: $selimport_menus{$key}->{'text'} = $shown;
2260: $selimport_menus{$key}->{'default'} = '';
2261: $selimport_menus{$key}->{'select2'}->{''} = '';
2262: $selimport_menus{$key}->{'order'} = \@ordered;
2263: }
2264: }
2265: }
2266: $possdirs = scalar(keys(%nonemptydirs));
2267: if ($possdirs > 1) {
2268: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2269: $output = $lt{'dire'}.
2270: &linked_select_forms($form,'<br />'.
2271: $lt{'fnam'},'',
2272: $firstselectname,$secondselectname,
2273: \%selimport_menus,\@order,
2274: $onchangefirst,'',$suffix).'<br />';
2275: } elsif ($possdirs == 1) {
2276: $singledir = (keys(%nonemptydirs))[0];
2277: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2278: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2279: }
2280: delete($selimport_menus{$singledir});
2281: }
2282: } elsif ($numdirs == 1) {
2283: $singledir = (keys(%files))[0];
2284: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2285: if ($only) {
2286: my ($ext) = ($file =~ /\.([^.]+)$/);
2287: unless ($possexts{lc($ext)}) {
2288: next;
2289: }
1.1315 raeburn 2290: } else {
2291: next if ($file =~ /\.rights$/);
1.1248 raeburn 2292: }
2293: push(@singledirfiles,$file);
2294: }
2295: if (@singledirfiles) {
1.1315 raeburn 2296: $possdirs = 1;
1.1248 raeburn 2297: }
2298: }
2299: if (($possdirs == 1) && (@singledirfiles)) {
2300: my $showdir = $singledir;
2301: if ($singledir eq '') {
2302: $showdir = '/';
2303: }
2304: $output = $lt{'dire'}.
2305: '<select name="'.$firstselectname.'">'.
2306: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2307: '</select><br />'.
2308: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2309: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2310: foreach my $file (@singledirfiles) {
2311: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2312: }
2313: $output .= '</select><br />'."\n";
2314: }
2315: return ($possdirs,$output);
2316: }
2317:
1.565 albertel 2318: =pod
2319:
1.256 matthew 2320: =head1 Excel and CSV file utility routines
2321:
2322: =cut
2323:
2324: ###############################################################
2325: ###############################################################
2326:
2327: =pod
2328:
1.1162 raeburn 2329: =over 4
2330:
1.648 raeburn 2331: =item * &csv_translate($text)
1.37 matthew 2332:
1.185 www 2333: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2334: format.
2335:
2336: =cut
2337:
1.180 matthew 2338: ###############################################################
2339: ###############################################################
1.37 matthew 2340: sub csv_translate {
2341: my $text = shift;
2342: $text =~ s/\"/\"\"/g;
1.209 albertel 2343: $text =~ s/\n/ /g;
1.37 matthew 2344: return $text;
2345: }
1.180 matthew 2346:
2347: ###############################################################
2348: ###############################################################
2349:
2350: =pod
2351:
1.648 raeburn 2352: =item * &define_excel_formats()
1.180 matthew 2353:
2354: Define some commonly used Excel cell formats.
2355:
2356: Currently supported formats:
2357:
2358: =over 4
2359:
2360: =item header
2361:
2362: =item bold
2363:
2364: =item h1
2365:
2366: =item h2
2367:
2368: =item h3
2369:
1.256 matthew 2370: =item h4
2371:
2372: =item i
2373:
1.180 matthew 2374: =item date
2375:
2376: =back
2377:
2378: Inputs: $workbook
2379:
2380: Returns: $format, a hash reference.
2381:
1.1057 foxr 2382:
1.180 matthew 2383: =cut
2384:
2385: ###############################################################
2386: ###############################################################
2387: sub define_excel_formats {
2388: my ($workbook) = @_;
2389: my $format;
2390: $format->{'header'} = $workbook->add_format(bold => 1,
2391: bottom => 1,
2392: align => 'center');
2393: $format->{'bold'} = $workbook->add_format(bold=>1);
2394: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2395: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2396: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2397: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2398: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2399: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2400: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2401: return $format;
2402: }
2403:
2404: ###############################################################
2405: ###############################################################
1.113 bowersj2 2406:
2407: =pod
2408:
1.648 raeburn 2409: =item * &create_workbook()
1.255 matthew 2410:
2411: Create an Excel worksheet. If it fails, output message on the
2412: request object and return undefs.
2413:
2414: Inputs: Apache request object
2415:
2416: Returns (undef) on failure,
2417: Excel worksheet object, scalar with filename, and formats
2418: from &Apache::loncommon::define_excel_formats on success
2419:
2420: =cut
2421:
2422: ###############################################################
2423: ###############################################################
2424: sub create_workbook {
2425: my ($r) = @_;
2426: #
2427: # Create the excel spreadsheet
2428: my $filename = '/prtspool/'.
1.258 albertel 2429: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2430: time.'_'.rand(1000000000).'.xls';
2431: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2432: if (! defined($workbook)) {
2433: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2434: $r->print(
2435: '<p class="LC_error">'
2436: .&mt('Problems occurred in creating the new Excel file.')
2437: .' '.&mt('This error has been logged.')
2438: .' '.&mt('Please alert your LON-CAPA administrator.')
2439: .'</p>'
2440: );
1.255 matthew 2441: return (undef);
2442: }
2443: #
1.1014 foxr 2444: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2445: #
2446: my $format = &Apache::loncommon::define_excel_formats($workbook);
2447: return ($workbook,$filename,$format);
2448: }
2449:
2450: ###############################################################
2451: ###############################################################
2452:
2453: =pod
2454:
1.648 raeburn 2455: =item * &create_text_file()
1.113 bowersj2 2456:
1.542 raeburn 2457: Create a file to write to and eventually make available to the user.
1.256 matthew 2458: If file creation fails, outputs an error message on the request object and
2459: return undefs.
1.113 bowersj2 2460:
1.256 matthew 2461: Inputs: Apache request object, and file suffix
1.113 bowersj2 2462:
1.256 matthew 2463: Returns (undef) on failure,
2464: Filehandle and filename on success.
1.113 bowersj2 2465:
2466: =cut
2467:
1.256 matthew 2468: ###############################################################
2469: ###############################################################
2470: sub create_text_file {
2471: my ($r,$suffix) = @_;
2472: if (! defined($suffix)) { $suffix = 'txt'; };
2473: my $fh;
2474: my $filename = '/prtspool/'.
1.258 albertel 2475: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2476: time.'_'.rand(1000000000).'.'.$suffix;
2477: $fh = Apache::File->new('>/home/httpd'.$filename);
2478: if (! defined($fh)) {
2479: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2480: $r->print(
2481: '<p class="LC_error">'
2482: .&mt('Problems occurred in creating the output file.')
2483: .' '.&mt('This error has been logged.')
2484: .' '.&mt('Please alert your LON-CAPA administrator.')
2485: .'</p>'
2486: );
1.113 bowersj2 2487: }
1.256 matthew 2488: return ($fh,$filename)
1.113 bowersj2 2489: }
2490:
2491:
1.256 matthew 2492: =pod
1.113 bowersj2 2493:
2494: =back
2495:
2496: =cut
1.37 matthew 2497:
2498: ###############################################################
1.33 matthew 2499: ## Home server <option> list generating code ##
2500: ###############################################################
1.35 matthew 2501:
1.169 www 2502: # ------------------------------------------
2503:
2504: sub domain_select {
1.1289 raeburn 2505: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2506: my @possdoms;
2507: if (ref($incdoms) eq 'ARRAY') {
2508: @possdoms = @{$incdoms};
2509: } else {
2510: @possdoms = &Apache::lonnet::all_domains();
2511: }
2512:
1.169 www 2513: my %domains=map {
1.514 albertel 2514: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2515: } @possdoms;
2516:
2517: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2518: foreach my $dom (@{$excdoms}) {
2519: delete($domains{$dom});
2520: }
2521: }
2522:
1.169 www 2523: if ($multiple) {
2524: $domains{''}=&mt('Any domain');
1.550 albertel 2525: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2526: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2527: } else {
1.550 albertel 2528: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2529: return &select_form($name,$value,\%domains);
1.169 www 2530: }
2531: }
2532:
1.282 albertel 2533: #-------------------------------------------
2534:
2535: =pod
2536:
1.519 raeburn 2537: =head1 Routines for form select boxes
2538:
2539: =over 4
2540:
1.648 raeburn 2541: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2542:
2543: Returns a string containing a <select> element int multiple mode
2544:
2545:
2546: Args:
2547: $name - name of the <select> element
1.506 raeburn 2548: $value - scalar or array ref of values that should already be selected
1.282 albertel 2549: $size - number of rows long the select element is
1.283 albertel 2550: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2551: (shown text should already have been &mt())
1.506 raeburn 2552: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2553:
1.282 albertel 2554: =cut
2555:
2556: #-------------------------------------------
1.169 www 2557: sub multiple_select_form {
1.284 albertel 2558: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2559: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2560: my $output='';
1.191 matthew 2561: if (! defined($size)) {
2562: $size = 4;
1.283 albertel 2563: if (scalar(keys(%$hash))<4) {
2564: $size = scalar(keys(%$hash));
1.191 matthew 2565: }
2566: }
1.734 bisitz 2567: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2568: my @order;
1.506 raeburn 2569: if (ref($order) eq 'ARRAY') {
2570: @order = @{$order};
2571: } else {
2572: @order = sort(keys(%$hash));
1.501 banghart 2573: }
2574: if (exists($$hash{'select_form_order'})) {
2575: @order = @{$$hash{'select_form_order'}};
2576: }
2577:
1.284 albertel 2578: foreach my $key (@order) {
1.356 albertel 2579: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2580: $output.='selected="selected" ' if ($selected{$key});
2581: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2582: }
2583: $output.="</select>\n";
2584: return $output;
2585: }
2586:
1.88 www 2587: #-------------------------------------------
2588:
2589: =pod
2590:
1.1254 raeburn 2591: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2592:
2593: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2594: allow a user to select options from a ref to a hash containing:
2595: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2596: a javascript onchange item, e.g., onchange="this.form.submit();".
2597: An optional arg -- $readonly -- if true will cause the select form
2598: to be disabled, e.g., for the case where an instructor has a section-
2599: specific role, and is viewing/modifying parameters.
1.970 raeburn 2600:
1.88 www 2601: See lonrights.pm for an example invocation and use.
2602:
2603: =cut
2604:
2605: #-------------------------------------------
2606: sub select_form {
1.1228 raeburn 2607: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2608: return unless (ref($hashref) eq 'HASH');
2609: if ($onchange) {
2610: $onchange = ' onchange="'.$onchange.'"';
2611: }
1.1228 raeburn 2612: my $disabled;
2613: if ($readonly) {
2614: $disabled = ' disabled="disabled"';
2615: }
2616: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2617: my @keys;
1.970 raeburn 2618: if (exists($hashref->{'select_form_order'})) {
2619: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2620: } else {
1.970 raeburn 2621: @keys=sort(keys(%{$hashref}));
1.128 albertel 2622: }
1.356 albertel 2623: foreach my $key (@keys) {
2624: $selectform.=
2625: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2626: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2627: ">".$hashref->{$key}."</option>\n";
1.88 www 2628: }
2629: $selectform.="</select>";
2630: return $selectform;
2631: }
2632:
1.475 www 2633: # For display filters
2634:
2635: sub display_filter {
1.1074 raeburn 2636: my ($context) = @_;
1.475 www 2637: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2638: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2639: my $phraseinput = 'hidden';
2640: my $includeinput = 'hidden';
2641: my ($checked,$includetypestext);
2642: if ($env{'form.displayfilter'} eq 'containing') {
2643: $phraseinput = 'text';
2644: if ($context eq 'parmslog') {
2645: $includeinput = 'checkbox';
2646: if ($env{'form.includetypes'}) {
2647: $checked = ' checked="checked"';
2648: }
2649: $includetypestext = &mt('Include parameter types');
2650: }
2651: } else {
2652: $includetypestext = ' ';
2653: }
2654: my ($additional,$secondid,$thirdid);
2655: if ($context eq 'parmslog') {
2656: $additional =
2657: '<label><input type="'.$includeinput.'" name="includetypes"'.
2658: $checked.' name="includetypes" value="1" id="includetypes" />'.
2659: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2660: '</label>';
2661: $secondid = 'includetypes';
2662: $thirdid = 'includetypestext';
2663: }
2664: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2665: '$secondid','$thirdid')";
2666: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2667: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2668: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2669: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2670: &mt('Filter: [_1]',
1.477 www 2671: &select_form($env{'form.displayfilter'},
2672: 'displayfilter',
1.970 raeburn 2673: {'currentfolder' => 'Current folder/page',
1.477 www 2674: 'containing' => 'Containing phrase',
1.1074 raeburn 2675: 'none' => 'None'},$onchange)).' '.
2676: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2677: &HTML::Entities::encode($env{'form.containingphrase'}).
2678: '" />'.$additional;
2679: }
2680:
2681: sub display_filter_js {
2682: my $includetext = &mt('Include parameter types');
2683: return <<"ENDJS";
2684:
2685: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2686: var firstType = 'hidden';
2687: if (setter.options[setter.selectedIndex].value == 'containing') {
2688: firstType = 'text';
2689: }
2690: firstObject = document.getElementById(firstid);
2691: if (typeof(firstObject) == 'object') {
2692: if (firstObject.type != firstType) {
2693: changeInputType(firstObject,firstType);
2694: }
2695: }
2696: if (context == 'parmslog') {
2697: var secondType = 'hidden';
2698: if (firstType == 'text') {
2699: secondType = 'checkbox';
2700: }
2701: secondObject = document.getElementById(secondid);
2702: if (typeof(secondObject) == 'object') {
2703: if (secondObject.type != secondType) {
2704: changeInputType(secondObject,secondType);
2705: }
2706: }
2707: var textItem = document.getElementById(thirdid);
2708: var currtext = textItem.innerHTML;
2709: var newtext;
2710: if (firstType == 'text') {
2711: newtext = '$includetext';
2712: } else {
2713: newtext = ' ';
2714: }
2715: if (currtext != newtext) {
2716: textItem.innerHTML = newtext;
2717: }
2718: }
2719: return;
2720: }
2721:
2722: function changeInputType(oldObject,newType) {
2723: var newObject = document.createElement('input');
2724: newObject.type = newType;
2725: if (oldObject.size) {
2726: newObject.size = oldObject.size;
2727: }
2728: if (oldObject.value) {
2729: newObject.value = oldObject.value;
2730: }
2731: if (oldObject.name) {
2732: newObject.name = oldObject.name;
2733: }
2734: if (oldObject.id) {
2735: newObject.id = oldObject.id;
2736: }
2737: oldObject.parentNode.replaceChild(newObject,oldObject);
2738: return;
2739: }
2740:
2741: ENDJS
1.475 www 2742: }
2743:
1.167 www 2744: sub gradeleveldescription {
2745: my $gradelevel=shift;
2746: my %gradelevels=(0 => 'Not specified',
2747: 1 => 'Grade 1',
2748: 2 => 'Grade 2',
2749: 3 => 'Grade 3',
2750: 4 => 'Grade 4',
2751: 5 => 'Grade 5',
2752: 6 => 'Grade 6',
2753: 7 => 'Grade 7',
2754: 8 => 'Grade 8',
2755: 9 => 'Grade 9',
2756: 10 => 'Grade 10',
2757: 11 => 'Grade 11',
2758: 12 => 'Grade 12',
2759: 13 => 'Grade 13',
2760: 14 => '100 Level',
2761: 15 => '200 Level',
2762: 16 => '300 Level',
2763: 17 => '400 Level',
2764: 18 => 'Graduate Level');
2765: return &mt($gradelevels{$gradelevel});
2766: }
2767:
1.163 www 2768: sub select_level_form {
2769: my ($deflevel,$name)=@_;
2770: unless ($deflevel) { $deflevel=0; }
1.167 www 2771: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2772: for (my $i=0; $i<=18; $i++) {
2773: $selectform.="<option value=\"$i\" ".
1.253 albertel 2774: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2775: ">".&gradeleveldescription($i)."</option>\n";
2776: }
2777: $selectform.="</select>";
2778: return $selectform;
1.163 www 2779: }
1.167 www 2780:
1.35 matthew 2781: #-------------------------------------------
2782:
1.45 matthew 2783: =pod
2784:
1.1256 raeburn 2785: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2786:
2787: Returns a string containing a <select name='$name' size='1'> form to
2788: allow a user to select the domain to preform an operation in.
2789: See loncreateuser.pm for an example invocation and use.
2790:
1.90 www 2791: If the $includeempty flag is set, it also includes an empty choice ("no domain
2792: selected");
2793:
1.743 raeburn 2794: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2795:
1.910 raeburn 2796: 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.
2797:
1.1121 raeburn 2798: The optional $incdoms is a reference to an array of domains which will be the only available options.
2799:
2800: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2801:
1.1256 raeburn 2802: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2803:
1.35 matthew 2804: =cut
2805:
2806: #-------------------------------------------
1.34 matthew 2807: sub select_dom_form {
1.1256 raeburn 2808: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2809: if ($onchange) {
1.874 raeburn 2810: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2811: }
1.1256 raeburn 2812: if ($disabled) {
2813: $disabled = ' disabled="disabled"';
2814: }
1.1121 raeburn 2815: my (@domains,%exclude);
1.910 raeburn 2816: if (ref($incdoms) eq 'ARRAY') {
2817: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2818: } else {
2819: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2820: }
1.90 www 2821: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2822: if (ref($excdoms) eq 'ARRAY') {
2823: map { $exclude{$_} = 1; } @{$excdoms};
2824: }
1.1256 raeburn 2825: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2826: foreach my $dom (@domains) {
1.1121 raeburn 2827: next if ($exclude{$dom});
1.356 albertel 2828: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2829: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2830: if ($showdomdesc) {
2831: if ($dom ne '') {
2832: my $domdesc = &Apache::lonnet::domain($dom,'description');
2833: if ($domdesc ne '') {
2834: $selectdomain .= ' ('.$domdesc.')';
2835: }
2836: }
2837: }
2838: $selectdomain .= "</option>\n";
1.34 matthew 2839: }
2840: $selectdomain.="</select>";
2841: return $selectdomain;
2842: }
2843:
1.35 matthew 2844: #-------------------------------------------
2845:
1.45 matthew 2846: =pod
2847:
1.648 raeburn 2848: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2849:
1.586 raeburn 2850: input: 4 arguments (two required, two optional) -
2851: $domain - domain of new user
2852: $name - name of form element
2853: $default - Value of 'default' causes a default item to be first
2854: option, and selected by default.
2855: $hide - Value of 'hide' causes hiding of the name of the server,
2856: if 1 server found, or default, if 0 found.
1.594 raeburn 2857: output: returns 2 items:
1.586 raeburn 2858: (a) form element which contains either:
2859: (i) <select name="$name">
2860: <option value="$hostid1">$hostid $servers{$hostid}</option>
2861: <option value="$hostid2">$hostid $servers{$hostid}</option>
2862: </select>
2863: form item if there are multiple library servers in $domain, or
2864: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2865: if there is only one library server in $domain.
2866:
2867: (b) number of library servers found.
2868:
2869: See loncreateuser.pm for example of use.
1.35 matthew 2870:
2871: =cut
2872:
2873: #-------------------------------------------
1.586 raeburn 2874: sub home_server_form_item {
2875: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2876: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2877: my $result;
2878: my $numlib = keys(%servers);
2879: if ($numlib > 1) {
2880: $result .= '<select name="'.$name.'" />'."\n";
2881: if ($default) {
1.804 bisitz 2882: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2883: '</option>'."\n";
2884: }
2885: foreach my $hostid (sort(keys(%servers))) {
2886: $result.= '<option value="'.$hostid.'">'.
2887: $hostid.' '.$servers{$hostid}."</option>\n";
2888: }
2889: $result .= '</select>'."\n";
2890: } elsif ($numlib == 1) {
2891: my $hostid;
2892: foreach my $item (keys(%servers)) {
2893: $hostid = $item;
2894: }
2895: $result .= '<input type="hidden" name="'.$name.'" value="'.
2896: $hostid.'" />';
2897: if (!$hide) {
2898: $result .= $hostid.' '.$servers{$hostid};
2899: }
2900: $result .= "\n";
2901: } elsif ($default) {
2902: $result .= '<input type="hidden" name="'.$name.
2903: '" value="default" />';
2904: if (!$hide) {
2905: $result .= &mt('default');
2906: }
2907: $result .= "\n";
1.33 matthew 2908: }
1.586 raeburn 2909: return ($result,$numlib);
1.33 matthew 2910: }
1.112 bowersj2 2911:
2912: =pod
2913:
1.534 albertel 2914: =back
2915:
1.112 bowersj2 2916: =cut
1.87 matthew 2917:
2918: ###############################################################
1.112 bowersj2 2919: ## Decoding User Agent ##
1.87 matthew 2920: ###############################################################
2921:
2922: =pod
2923:
1.112 bowersj2 2924: =head1 Decoding the User Agent
2925:
2926: =over 4
2927:
2928: =item * &decode_user_agent()
1.87 matthew 2929:
2930: Inputs: $r
2931:
2932: Outputs:
2933:
2934: =over 4
2935:
1.112 bowersj2 2936: =item * $httpbrowser
1.87 matthew 2937:
1.112 bowersj2 2938: =item * $clientbrowser
1.87 matthew 2939:
1.112 bowersj2 2940: =item * $clientversion
1.87 matthew 2941:
1.112 bowersj2 2942: =item * $clientmathml
1.87 matthew 2943:
1.112 bowersj2 2944: =item * $clientunicode
1.87 matthew 2945:
1.112 bowersj2 2946: =item * $clientos
1.87 matthew 2947:
1.1137 raeburn 2948: =item * $clientmobile
2949:
1.1141 raeburn 2950: =item * $clientinfo
2951:
1.1194 raeburn 2952: =item * $clientosversion
2953:
1.87 matthew 2954: =back
2955:
1.157 matthew 2956: =back
2957:
1.87 matthew 2958: =cut
2959:
2960: ###############################################################
2961: ###############################################################
2962: sub decode_user_agent {
1.247 albertel 2963: my ($r)=@_;
1.87 matthew 2964: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2965: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2966: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2967: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2968: my $clientbrowser='unknown';
2969: my $clientversion='0';
2970: my $clientmathml='';
2971: my $clientunicode='0';
1.1137 raeburn 2972: my $clientmobile=0;
1.1194 raeburn 2973: my $clientosversion='';
1.87 matthew 2974: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2975: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2976: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2977: $clientbrowser=$bname;
2978: $httpbrowser=~/$vreg/i;
2979: $clientversion=$1;
2980: $clientmathml=($clientversion>=$minv);
2981: $clientunicode=($clientversion>=$univ);
2982: }
2983: }
2984: my $clientos='unknown';
1.1141 raeburn 2985: my $clientinfo;
1.87 matthew 2986: if (($httpbrowser=~/linux/i) ||
2987: ($httpbrowser=~/unix/i) ||
2988: ($httpbrowser=~/ux/i) ||
2989: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2990: if (($httpbrowser=~/vax/i) ||
2991: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2992: if ($httpbrowser=~/next/i) { $clientos='next'; }
2993: if (($httpbrowser=~/mac/i) ||
2994: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2995: if ($httpbrowser=~/win/i) {
2996: $clientos='win';
2997: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2998: $clientosversion = $1;
2999: }
3000: }
1.87 matthew 3001: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3002: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3003: $clientmobile=lc($1);
3004: }
1.1141 raeburn 3005: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3006: $clientinfo = 'firefox-'.$1;
3007: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3008: $clientinfo = 'chromeframe-'.$1;
3009: }
1.87 matthew 3010: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3011: $clientunicode,$clientos,$clientmobile,$clientinfo,
3012: $clientosversion);
1.87 matthew 3013: }
3014:
1.32 matthew 3015: ###############################################################
3016: ## Authentication changing form generation subroutines ##
3017: ###############################################################
3018: ##
3019: ## All of the authform_xxxxxxx subroutines take their inputs in a
3020: ## hash, and have reasonable default values.
3021: ##
3022: ## formname = the name given in the <form> tag.
1.35 matthew 3023: #-------------------------------------------
3024:
1.45 matthew 3025: =pod
3026:
1.112 bowersj2 3027: =head1 Authentication Routines
3028:
3029: =over 4
3030:
1.648 raeburn 3031: =item * &authform_xxxxxx()
1.35 matthew 3032:
3033: The authform_xxxxxx subroutines provide javascript and html forms which
3034: handle some of the conveniences required for authentication forms.
3035: This is not an optimal method, but it works.
3036:
3037: =over 4
3038:
1.112 bowersj2 3039: =item * authform_header
1.35 matthew 3040:
1.112 bowersj2 3041: =item * authform_authorwarning
1.35 matthew 3042:
1.112 bowersj2 3043: =item * authform_nochange
1.35 matthew 3044:
1.112 bowersj2 3045: =item * authform_kerberos
1.35 matthew 3046:
1.112 bowersj2 3047: =item * authform_internal
1.35 matthew 3048:
1.112 bowersj2 3049: =item * authform_filesystem
1.35 matthew 3050:
1.1310 raeburn 3051: =item * authform_lti
3052:
1.35 matthew 3053: =back
3054:
1.648 raeburn 3055: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3056:
1.35 matthew 3057: =cut
3058:
3059: #-------------------------------------------
1.32 matthew 3060: sub authform_header{
3061: my %in = (
3062: formname => 'cu',
1.80 albertel 3063: kerb_def_dom => '',
1.32 matthew 3064: @_,
3065: );
3066: $in{'formname'} = 'document.' . $in{'formname'};
3067: my $result='';
1.80 albertel 3068:
3069: #---------------------------------------------- Code for upper case translation
3070: my $Javascript_toUpperCase;
3071: unless ($in{kerb_def_dom}) {
3072: $Javascript_toUpperCase =<<"END";
3073: switch (choice) {
3074: case 'krb': currentform.elements[choicearg].value =
3075: currentform.elements[choicearg].value.toUpperCase();
3076: break;
3077: default:
3078: }
3079: END
3080: } else {
3081: $Javascript_toUpperCase = "";
3082: }
3083:
1.165 raeburn 3084: my $radioval = "'nochange'";
1.591 raeburn 3085: if (defined($in{'curr_authtype'})) {
3086: if ($in{'curr_authtype'} ne '') {
3087: $radioval = "'".$in{'curr_authtype'}."arg'";
3088: }
1.174 matthew 3089: }
1.165 raeburn 3090: my $argfield = 'null';
1.591 raeburn 3091: if (defined($in{'mode'})) {
1.165 raeburn 3092: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3093: if (defined($in{'curr_autharg'})) {
3094: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3095: $argfield = "'$in{'curr_autharg'}'";
3096: }
3097: }
3098: }
3099: }
3100:
1.32 matthew 3101: $result.=<<"END";
3102: var current = new Object();
1.165 raeburn 3103: current.radiovalue = $radioval;
3104: current.argfield = $argfield;
1.32 matthew 3105:
3106: function changed_radio(choice,currentform) {
3107: var choicearg = choice + 'arg';
3108: // If a radio button in changed, we need to change the argfield
3109: if (current.radiovalue != choice) {
3110: current.radiovalue = choice;
3111: if (current.argfield != null) {
3112: currentform.elements[current.argfield].value = '';
3113: }
3114: if (choice == 'nochange') {
3115: current.argfield = null;
3116: } else {
3117: current.argfield = choicearg;
3118: switch(choice) {
3119: case 'krb':
3120: currentform.elements[current.argfield].value =
3121: "$in{'kerb_def_dom'}";
3122: break;
3123: default:
3124: break;
3125: }
3126: }
3127: }
3128: return;
3129: }
1.22 www 3130:
1.32 matthew 3131: function changed_text(choice,currentform) {
3132: var choicearg = choice + 'arg';
3133: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3134: $Javascript_toUpperCase
1.32 matthew 3135: // clear old field
3136: if ((current.argfield != choicearg) && (current.argfield != null)) {
3137: currentform.elements[current.argfield].value = '';
3138: }
3139: current.argfield = choicearg;
3140: }
3141: set_auth_radio_buttons(choice,currentform);
3142: return;
1.20 www 3143: }
1.32 matthew 3144:
3145: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3146: var numauthchoices = currentform.login.length;
3147: if (typeof numauthchoices == "undefined") {
3148: return;
3149: }
1.32 matthew 3150: var i=0;
1.986 raeburn 3151: while (i < numauthchoices) {
1.32 matthew 3152: if (currentform.login[i].value == newvalue) { break; }
3153: i++;
3154: }
1.986 raeburn 3155: if (i == numauthchoices) {
1.32 matthew 3156: return;
3157: }
3158: current.radiovalue = newvalue;
3159: currentform.login[i].checked = true;
3160: return;
3161: }
3162: END
3163: return $result;
3164: }
3165:
1.1106 raeburn 3166: sub authform_authorwarning {
1.32 matthew 3167: my $result='';
1.144 matthew 3168: $result='<i>'.
3169: &mt('As a general rule, only authors or co-authors should be '.
3170: 'filesystem authenticated '.
3171: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3172: return $result;
3173: }
3174:
1.1106 raeburn 3175: sub authform_nochange {
1.32 matthew 3176: my %in = (
3177: formname => 'document.cu',
3178: kerb_def_dom => 'MSU.EDU',
3179: @_,
3180: );
1.1106 raeburn 3181: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3182: my $result;
1.1104 raeburn 3183: if (!$authnum) {
1.1105 raeburn 3184: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3185: } else {
3186: $result = '<label>'.&mt('[_1] Do not change login data',
3187: '<input type="radio" name="login" value="nochange" '.
3188: 'checked="checked" onclick="'.
1.281 albertel 3189: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3190: '</label>';
1.586 raeburn 3191: }
1.32 matthew 3192: return $result;
3193: }
3194:
1.591 raeburn 3195: sub authform_kerberos {
1.32 matthew 3196: my %in = (
3197: formname => 'document.cu',
3198: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3199: kerb_def_auth => 'krb4',
1.32 matthew 3200: @_,
3201: );
1.586 raeburn 3202: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3203: $autharg,$jscall,$disabled);
1.1106 raeburn 3204: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3205: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3206: $check5 = ' checked="checked"';
1.80 albertel 3207: } else {
1.772 bisitz 3208: $check4 = ' checked="checked"';
1.80 albertel 3209: }
1.1259 raeburn 3210: if ($in{'readonly'}) {
3211: $disabled = ' disabled="disabled"';
3212: }
1.165 raeburn 3213: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3214: if (defined($in{'curr_authtype'})) {
3215: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3216: $krbcheck = ' checked="checked"';
1.623 raeburn 3217: if (defined($in{'mode'})) {
3218: if ($in{'mode'} eq 'modifyuser') {
3219: $krbcheck = '';
3220: }
3221: }
1.591 raeburn 3222: if (defined($in{'curr_kerb_ver'})) {
3223: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3224: $check5 = ' checked="checked"';
1.591 raeburn 3225: $check4 = '';
3226: } else {
1.772 bisitz 3227: $check4 = ' checked="checked"';
1.591 raeburn 3228: $check5 = '';
3229: }
1.586 raeburn 3230: }
1.591 raeburn 3231: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3232: $krbarg = $in{'curr_autharg'};
3233: }
1.586 raeburn 3234: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3235: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3236: $result =
3237: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3238: $in{'curr_autharg'},$krbver);
3239: } else {
3240: $result =
3241: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3242: }
3243: return $result;
3244: }
3245: }
3246: } else {
3247: if ($authnum == 1) {
1.784 bisitz 3248: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3249: }
3250: }
1.586 raeburn 3251: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3252: return;
1.587 raeburn 3253: } elsif ($authtype eq '') {
1.591 raeburn 3254: if (defined($in{'mode'})) {
1.587 raeburn 3255: if ($in{'mode'} eq 'modifycourse') {
3256: if ($authnum == 1) {
1.1259 raeburn 3257: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3258: }
3259: }
3260: }
1.586 raeburn 3261: }
3262: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3263: if ($authtype eq '') {
3264: $authtype = '<input type="radio" name="login" value="krb" '.
3265: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3266: $krbcheck.$disabled.' />';
1.586 raeburn 3267: }
3268: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3269: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3270: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3271: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3272: $in{'curr_authtype'} eq 'krb4')) {
3273: $result .= &mt
1.144 matthew 3274: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3275: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3276: '<label>'.$authtype,
1.281 albertel 3277: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3278: 'value="'.$krbarg.'" '.
1.1259 raeburn 3279: 'onchange="'.$jscall.'"'.$disabled.' />',
3280: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3281: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3282: '</label>');
1.586 raeburn 3283: } elsif ($can_assign{'krb4'}) {
3284: $result .= &mt
3285: ('[_1] Kerberos authenticated with domain [_2] '.
3286: '[_3] Version 4 [_4]',
3287: '<label>'.$authtype,
3288: '</label><input type="text" size="10" name="krbarg" '.
3289: 'value="'.$krbarg.'" '.
1.1259 raeburn 3290: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3291: '<label><input type="hidden" name="krbver" value="4" />',
3292: '</label>');
3293: } elsif ($can_assign{'krb5'}) {
3294: $result .= &mt
3295: ('[_1] Kerberos authenticated with domain [_2] '.
3296: '[_3] Version 5 [_4]',
3297: '<label>'.$authtype,
3298: '</label><input type="text" size="10" name="krbarg" '.
3299: 'value="'.$krbarg.'" '.
1.1259 raeburn 3300: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3301: '<label><input type="hidden" name="krbver" value="5" />',
3302: '</label>');
3303: }
1.32 matthew 3304: return $result;
3305: }
3306:
1.1106 raeburn 3307: sub authform_internal {
1.586 raeburn 3308: my %in = (
1.32 matthew 3309: formname => 'document.cu',
3310: kerb_def_dom => 'MSU.EDU',
3311: @_,
3312: );
1.1259 raeburn 3313: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3314: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3315: if ($in{'readonly'}) {
3316: $disabled = ' disabled="disabled"';
3317: }
1.591 raeburn 3318: if (defined($in{'curr_authtype'})) {
3319: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3320: if ($can_assign{'int'}) {
1.772 bisitz 3321: $intcheck = 'checked="checked" ';
1.623 raeburn 3322: if (defined($in{'mode'})) {
3323: if ($in{'mode'} eq 'modifyuser') {
3324: $intcheck = '';
3325: }
3326: }
1.591 raeburn 3327: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3328: $intarg = $in{'curr_autharg'};
3329: }
3330: } else {
3331: $result = &mt('Currently internally authenticated.');
3332: return $result;
1.165 raeburn 3333: }
3334: }
1.586 raeburn 3335: } else {
3336: if ($authnum == 1) {
1.784 bisitz 3337: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3338: }
3339: }
3340: if (!$can_assign{'int'}) {
3341: return;
1.587 raeburn 3342: } elsif ($authtype eq '') {
1.591 raeburn 3343: if (defined($in{'mode'})) {
1.587 raeburn 3344: if ($in{'mode'} eq 'modifycourse') {
3345: if ($authnum == 1) {
1.1259 raeburn 3346: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3347: }
3348: }
3349: }
1.165 raeburn 3350: }
1.586 raeburn 3351: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3352: if ($authtype eq '') {
3353: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3354: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3355: }
1.605 bisitz 3356: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3357: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3358: $result = &mt
1.144 matthew 3359: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3360: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3361: $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 3362: return $result;
3363: }
3364:
1.1104 raeburn 3365: sub authform_local {
1.32 matthew 3366: my %in = (
3367: formname => 'document.cu',
3368: kerb_def_dom => 'MSU.EDU',
3369: @_,
3370: );
1.1259 raeburn 3371: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3372: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3373: if ($in{'readonly'}) {
3374: $disabled = ' disabled="disabled"';
3375: }
1.591 raeburn 3376: if (defined($in{'curr_authtype'})) {
3377: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3378: if ($can_assign{'loc'}) {
1.772 bisitz 3379: $loccheck = 'checked="checked" ';
1.623 raeburn 3380: if (defined($in{'mode'})) {
3381: if ($in{'mode'} eq 'modifyuser') {
3382: $loccheck = '';
3383: }
3384: }
1.591 raeburn 3385: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3386: $locarg = $in{'curr_autharg'};
3387: }
3388: } else {
3389: $result = &mt('Currently using local (institutional) authentication.');
3390: return $result;
1.165 raeburn 3391: }
3392: }
1.586 raeburn 3393: } else {
3394: if ($authnum == 1) {
1.784 bisitz 3395: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3396: }
3397: }
3398: if (!$can_assign{'loc'}) {
3399: return;
1.587 raeburn 3400: } elsif ($authtype eq '') {
1.591 raeburn 3401: if (defined($in{'mode'})) {
1.587 raeburn 3402: if ($in{'mode'} eq 'modifycourse') {
3403: if ($authnum == 1) {
1.1259 raeburn 3404: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3405: }
3406: }
3407: }
1.165 raeburn 3408: }
1.586 raeburn 3409: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3410: if ($authtype eq '') {
3411: $authtype = '<input type="radio" name="login" value="loc" '.
3412: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3413: $jscall.'"'.$disabled.' />';
1.586 raeburn 3414: }
3415: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3416: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3417: $result = &mt('[_1] Local Authentication with argument [_2]',
3418: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3419: return $result;
3420: }
3421:
1.1106 raeburn 3422: sub authform_filesystem {
1.32 matthew 3423: my %in = (
3424: formname => 'document.cu',
3425: kerb_def_dom => 'MSU.EDU',
3426: @_,
3427: );
1.1259 raeburn 3428: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3429: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3430: if ($in{'readonly'}) {
3431: $disabled = ' disabled="disabled"';
3432: }
1.591 raeburn 3433: if (defined($in{'curr_authtype'})) {
3434: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3435: if ($can_assign{'fsys'}) {
1.772 bisitz 3436: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3437: if (defined($in{'mode'})) {
3438: if ($in{'mode'} eq 'modifyuser') {
3439: $fsyscheck = '';
3440: }
3441: }
1.586 raeburn 3442: } else {
3443: $result = &mt('Currently Filesystem Authenticated.');
3444: return $result;
1.1259 raeburn 3445: }
1.586 raeburn 3446: }
3447: } else {
3448: if ($authnum == 1) {
1.784 bisitz 3449: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3450: }
3451: }
3452: if (!$can_assign{'fsys'}) {
3453: return;
1.587 raeburn 3454: } elsif ($authtype eq '') {
1.591 raeburn 3455: if (defined($in{'mode'})) {
1.587 raeburn 3456: if ($in{'mode'} eq 'modifycourse') {
3457: if ($authnum == 1) {
1.1259 raeburn 3458: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3459: }
3460: }
3461: }
1.586 raeburn 3462: }
3463: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3464: if ($authtype eq '') {
3465: $authtype = '<input type="radio" name="login" value="fsys" '.
3466: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3467: $jscall.'"'.$disabled.' />';
1.586 raeburn 3468: }
1.1310 raeburn 3469: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3470: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3471: $result = &mt
1.144 matthew 3472: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3473: '<label>'.$authtype,'</label>'.$autharg);
3474: return $result;
3475: }
3476:
3477: sub authform_lti {
3478: my %in = (
3479: formname => 'document.cu',
3480: kerb_def_dom => 'MSU.EDU',
3481: @_,
3482: );
3483: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3484: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3485: if ($in{'readonly'}) {
3486: $disabled = ' disabled="disabled"';
3487: }
3488: if (defined($in{'curr_authtype'})) {
3489: if ($in{'curr_authtype'} eq 'lti') {
3490: if ($can_assign{'lti'}) {
3491: $lticheck = 'checked="checked" ';
3492: if (defined($in{'mode'})) {
3493: if ($in{'mode'} eq 'modifyuser') {
3494: $lticheck = '';
3495: }
3496: }
3497: } else {
3498: $result = &mt('Currently LTI Authenticated.');
3499: return $result;
3500: }
3501: }
3502: } else {
3503: if ($authnum == 1) {
3504: $authtype = '<input type="hidden" name="login" value="lti" />';
3505: }
3506: }
3507: if (!$can_assign{'lti'}) {
3508: return;
3509: } elsif ($authtype eq '') {
3510: if (defined($in{'mode'})) {
3511: if ($in{'mode'} eq 'modifycourse') {
3512: if ($authnum == 1) {
3513: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3514: }
3515: }
3516: }
3517: }
3518: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3519: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3520: $authtype = '<input type="radio" name="login" value="lti" '.
3521: $lticheck.' onchange="'.$jscall.'" onclick="'.
3522: $jscall.'"'.$disabled.' />';
3523: }
3524: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3525: if ($authtype) {
3526: $result = &mt('[_1] LTI Authenticated',
3527: '<label>'.$authtype.'</label>'.$autharg);
3528: } else {
3529: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3530: $autharg;
3531: }
1.32 matthew 3532: return $result;
3533: }
3534:
1.586 raeburn 3535: sub get_assignable_auth {
3536: my ($dom) = @_;
3537: if ($dom eq '') {
3538: $dom = $env{'request.role.domain'};
3539: }
3540: my %can_assign = (
3541: krb4 => 1,
3542: krb5 => 1,
3543: int => 1,
3544: loc => 1,
1.1310 raeburn 3545: lti => 1,
1.586 raeburn 3546: );
3547: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3548: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3549: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3550: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3551: my $context;
3552: if ($env{'request.role'} =~ /^au/) {
3553: $context = 'author';
1.1259 raeburn 3554: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3555: $context = 'domain';
3556: } elsif ($env{'request.course.id'}) {
3557: $context = 'course';
3558: }
3559: if ($context) {
3560: if (ref($authhash->{$context}) eq 'HASH') {
3561: %can_assign = %{$authhash->{$context}};
3562: }
3563: }
3564: }
3565: }
3566: my $authnum = 0;
3567: foreach my $key (keys(%can_assign)) {
3568: if ($can_assign{$key}) {
3569: $authnum ++;
3570: }
3571: }
3572: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3573: $authnum --;
3574: }
3575: return ($authnum,%can_assign);
3576: }
3577:
1.1331 raeburn 3578: sub check_passwd_rules {
3579: my ($domain,$plainpass) = @_;
3580: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3581: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3582: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3583: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3584: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3585: if ($passwdconf{'min'} > $min) {
3586: $min = $passwdconf{'min'};
3587: }
1.1331 raeburn 3588: }
3589: if ($passwdconf{'max'} =~ /^\d+$/) {
3590: $max = $passwdconf{'max'};
3591: }
3592: @chars = @{$passwdconf{'chars'}};
3593: }
3594: if (($min) && (length($plainpass) < $min)) {
3595: push(@brokerule,'min');
3596: }
3597: if (($max) && (length($plainpass) > $max)) {
3598: push(@brokerule,'max');
3599: }
3600: if (@chars) {
3601: my %rules;
3602: map { $rules{$_} = 1; } @chars;
3603: if ($rules{'uc'}) {
3604: unless ($plainpass =~ /[A-Z]/) {
3605: push(@brokerule,'uc');
3606: }
3607: }
3608: if ($rules{'lc'}) {
1.1332 raeburn 3609: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3610: push(@brokerule,'lc');
3611: }
3612: }
3613: if ($rules{'num'}) {
3614: unless ($plainpass =~ /\d/) {
3615: push(@brokerule,'num');
3616: }
3617: }
3618: if ($rules{'spec'}) {
3619: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3620: push(@brokerule,'spec');
3621: }
3622: }
3623: }
3624: if (@brokerule) {
3625: my %rulenames = &Apache::lonlocal::texthash(
3626: uc => 'At least one upper case letter',
3627: lc => 'At least one lower case letter',
3628: num => 'At least one number',
3629: spec => 'At least one non-alphanumeric',
3630: );
3631: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3632: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3633: $rulenames{'num'} .= ': 0123456789';
3634: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3635: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3636: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3637: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3638: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3639: if (grep(/^$rule$/,@brokerule)) {
3640: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3641: }
3642: }
3643: $warning .= '</ul>';
3644: }
1.1332 raeburn 3645: if (wantarray) {
3646: return @brokerule;
3647: }
1.1331 raeburn 3648: return $warning;
3649: }
3650:
1.1376 ! raeburn 3651: sub passwd_validation_js {
! 3652: my ($currpasswdval,$domain) = @_;
! 3653: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
! 3654: my ($min,$max,@chars,$numrules,$intargjs,%alert);
! 3655: $numrules = 0;
! 3656: $min = $Apache::lonnet::passwdmin;
! 3657: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
! 3658: if ($passwdconf{'min'} =~ /^\d+$/) {
! 3659: if ($passwdconf{'min'} > $min) {
! 3660: $min = $passwdconf{'min'};
! 3661: }
! 3662: }
! 3663: if ($passwdconf{'max'} =~ /^\d+$/) {
! 3664: $max = $passwdconf{'max'};
! 3665: $numrules ++;
! 3666: }
! 3667: @chars = @{$passwdconf{'chars'}};
! 3668: if (@chars) {
! 3669: $numrules ++;
! 3670: }
! 3671: }
! 3672: if ($min > 0) {
! 3673: $numrules ++;
! 3674: }
! 3675: if (($min > 0) || ($max ne '') || (@chars > 0)) {
! 3676: my $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
! 3677: if ($min) {
! 3678: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
! 3679: }
! 3680: if ($max) {
! 3681: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
! 3682: }
! 3683: my (@charalerts,@charrules);
! 3684: if (@chars) {
! 3685: if (grep(/^uc$/,@chars)) {
! 3686: push(@charalerts,&mt('contain at least one upper case letter'));
! 3687: push(@charrules,'uc');
! 3688: }
! 3689: if (grep(/^lc$/,@chars)) {
! 3690: push(@charalerts,&mt('contain at least one lower case letter'));
! 3691: push(@charrules,'lc');
! 3692: }
! 3693: if (grep(/^num$/,@chars)) {
! 3694: push(@charalerts,&mt('contain at least one number'));
! 3695: push(@charrules,'num');
! 3696: }
! 3697: if (grep(/^spec$/,@chars)) {
! 3698: push(@charalerts,&mt('contain at least one non-alphanumeric'));
! 3699: push(@charrules,'spec');
! 3700: }
! 3701: }
! 3702: $intargjs = qq| var rulesmsg = '';\n|.
! 3703: qq| var currpwval = $currpasswdval;\n|;
! 3704: if ($min) {
! 3705: $intargjs .= qq|
! 3706: if (currpwval.length < $min) {
! 3707: rulesmsg += ' - $alert{min}';
! 3708: }
! 3709: |;
! 3710: }
! 3711: if ($max) {
! 3712: $intargjs .= qq|
! 3713: if (currpwval.length > $max) {
! 3714: rulesmsg += ' - $alert{max}';
! 3715: }
! 3716: |;
! 3717: }
! 3718: if (@chars > 0) {
! 3719: my $charrulestr = '"'.join('","',@charrules).'"';
! 3720: my $charalertstr = '"'.join('","',@charalerts).'"';
! 3721: $intargjs .= qq| var brokerules = new Array();\n|.
! 3722: qq| var charrules = new Array($charrulestr);\n|.
! 3723: qq| var charalerts = new Array($charalertstr);\n|;
! 3724: my %rules;
! 3725: map { $rules{$_} = 1; } @chars;
! 3726: if ($rules{'uc'}) {
! 3727: $intargjs .= qq|
! 3728: var ucRegExp = /[A-Z]/;
! 3729: if (!ucRegExp.test(currpwval)) {
! 3730: brokerules.push('uc');
! 3731: }
! 3732: |;
! 3733: }
! 3734: if ($rules{'lc'}) {
! 3735: $intargjs .= qq|
! 3736: var lcRegExp = /[a-z]/;
! 3737: if (!lcRegExp.test(currpwval)) {
! 3738: brokerules.push('lc');
! 3739: }
! 3740: |;
! 3741: }
! 3742: if ($rules{'num'}) {
! 3743: $intargjs .= qq|
! 3744: var numRegExp = /[0-9]/;
! 3745: if (!numRegExp.test(currpwval)) {
! 3746: brokerules.push('num');
! 3747: }
! 3748: |;
! 3749: }
! 3750: if ($rules{'spec'}) {
! 3751: $intargjs .= q|
! 3752: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
! 3753: if (!specRegExp.test(currpwval)) {
! 3754: brokerules.push('spec');
! 3755: }
! 3756: |;
! 3757: }
! 3758: $intargjs .= qq|
! 3759: if (brokerules.length > 0) {
! 3760: for (var i=0; i<brokerules.length; i++) {
! 3761: for (var j=0; j<charrules.length; j++) {
! 3762: if (brokerules[i] == charrules[j]) {
! 3763: rulesmsg += ' - '+charalerts[j]+'\\n';
! 3764: break;
! 3765: }
! 3766: }
! 3767: }
! 3768: }
! 3769: |;
! 3770: }
! 3771: $intargjs .= qq|
! 3772: if (rulesmsg != '') {
! 3773: rulesmsg = '$alertmsg'+rulesmsg;
! 3774: alert(rulesmsg);
! 3775: return false;
! 3776: }
! 3777: |;
! 3778: }
! 3779: return ($numrules,$intargjs);
! 3780: }
! 3781:
1.80 albertel 3782: ###############################################################
3783: ## Get Kerberos Defaults for Domain ##
3784: ###############################################################
3785: ##
3786: ## Returns default kerberos version and an associated argument
3787: ## as listed in file domain.tab. If not listed, provides
3788: ## appropriate default domain and kerberos version.
3789: ##
3790: #-------------------------------------------
3791:
3792: =pod
3793:
1.648 raeburn 3794: =item * &get_kerberos_defaults()
1.80 albertel 3795:
3796: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3797: version and domain. If not found, it defaults to version 4 and the
3798: domain of the server.
1.80 albertel 3799:
1.648 raeburn 3800: =over 4
3801:
1.80 albertel 3802: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3803:
1.648 raeburn 3804: =back
3805:
3806: =back
3807:
1.80 albertel 3808: =cut
3809:
3810: #-------------------------------------------
3811: sub get_kerberos_defaults {
3812: my $domain=shift;
1.641 raeburn 3813: my ($krbdef,$krbdefdom);
3814: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3815: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3816: $krbdef = $domdefaults{'auth_def'};
3817: $krbdefdom = $domdefaults{'auth_arg_def'};
3818: } else {
1.80 albertel 3819: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3820: my $krbdefdom=$1;
3821: $krbdefdom=~tr/a-z/A-Z/;
3822: $krbdef = "krb4";
3823: }
3824: return ($krbdef,$krbdefdom);
3825: }
1.112 bowersj2 3826:
1.32 matthew 3827:
1.46 matthew 3828: ###############################################################
3829: ## Thesaurus Functions ##
3830: ###############################################################
1.20 www 3831:
1.46 matthew 3832: =pod
1.20 www 3833:
1.112 bowersj2 3834: =head1 Thesaurus Functions
3835:
3836: =over 4
3837:
1.648 raeburn 3838: =item * &initialize_keywords()
1.46 matthew 3839:
3840: Initializes the package variable %Keywords if it is empty. Uses the
3841: package variable $thesaurus_db_file.
3842:
3843: =cut
3844:
3845: ###################################################
3846:
3847: sub initialize_keywords {
3848: return 1 if (scalar keys(%Keywords));
3849: # If we are here, %Keywords is empty, so fill it up
3850: # Make sure the file we need exists...
3851: if (! -e $thesaurus_db_file) {
3852: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3853: " failed because it does not exist");
3854: return 0;
3855: }
3856: # Set up the hash as a database
3857: my %thesaurus_db;
3858: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3859: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3860: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3861: $thesaurus_db_file);
3862: return 0;
3863: }
3864: # Get the average number of appearances of a word.
3865: my $avecount = $thesaurus_db{'average.count'};
3866: # Put keywords (those that appear > average) into %Keywords
3867: while (my ($word,$data)=each (%thesaurus_db)) {
3868: my ($count,undef) = split /:/,$data;
3869: $Keywords{$word}++ if ($count > $avecount);
3870: }
3871: untie %thesaurus_db;
3872: # Remove special values from %Keywords.
1.356 albertel 3873: foreach my $value ('total.count','average.count') {
3874: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3875: }
1.46 matthew 3876: return 1;
3877: }
3878:
3879: ###################################################
3880:
3881: =pod
3882:
1.648 raeburn 3883: =item * &keyword($word)
1.46 matthew 3884:
3885: Returns true if $word is a keyword. A keyword is a word that appears more
3886: than the average number of times in the thesaurus database. Calls
3887: &initialize_keywords
3888:
3889: =cut
3890:
3891: ###################################################
1.20 www 3892:
3893: sub keyword {
1.46 matthew 3894: return if (!&initialize_keywords());
3895: my $word=lc(shift());
3896: $word=~s/\W//g;
3897: return exists($Keywords{$word});
1.20 www 3898: }
1.46 matthew 3899:
3900: ###############################################################
3901:
3902: =pod
1.20 www 3903:
1.648 raeburn 3904: =item * &get_related_words()
1.46 matthew 3905:
1.160 matthew 3906: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3907: an array of words. If the keyword is not in the thesaurus, an empty array
3908: will be returned. The order of the words returned is determined by the
3909: database which holds them.
3910:
3911: Uses global $thesaurus_db_file.
3912:
1.1057 foxr 3913:
1.46 matthew 3914: =cut
3915:
3916: ###############################################################
3917: sub get_related_words {
3918: my $keyword = shift;
3919: my %thesaurus_db;
3920: if (! -e $thesaurus_db_file) {
3921: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3922: "failed because the file does not exist");
3923: return ();
3924: }
3925: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3926: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3927: return ();
3928: }
3929: my @Words=();
1.429 www 3930: my $count=0;
1.46 matthew 3931: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3932: # The first element is the number of times
3933: # the word appears. We do not need it now.
1.429 www 3934: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3935: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3936: my $threshold=$mostfrequentcount/10;
3937: foreach my $possibleword (@RelatedWords) {
3938: my ($word,$wordcount)=split(/\,/,$possibleword);
3939: if ($wordcount>$threshold) {
3940: push(@Words,$word);
3941: $count++;
3942: if ($count>10) { last; }
3943: }
1.20 www 3944: }
3945: }
1.46 matthew 3946: untie %thesaurus_db;
3947: return @Words;
1.14 harris41 3948: }
1.1090 foxr 3949: ###############################################################
3950: #
3951: # Spell checking
3952: #
3953:
3954: =pod
3955:
1.1142 raeburn 3956: =back
3957:
1.1090 foxr 3958: =head1 Spell checking
3959:
3960: =over 4
3961:
3962: =item * &check_spelling($wordlist $language)
3963:
3964: Takes a string containing words and feeds it to an external
3965: spellcheck program via a pipeline. Returns a string containing
3966: them mis-spelled words.
3967:
3968: Parameters:
3969:
3970: =over 4
3971:
3972: =item - $wordlist
3973:
3974: String that will be fed into the spellcheck program.
3975:
3976: =item - $language
3977:
3978: Language string that specifies the language for which the spell
3979: check will be performed.
3980:
3981: =back
3982:
3983: =back
3984:
3985: Note: This sub assumes that aspell is installed.
3986:
3987:
3988: =cut
3989:
1.46 matthew 3990:
1.1090 foxr 3991: sub check_spelling {
3992: my ($wordlist, $language) = @_;
1.1091 foxr 3993: my @misspellings;
3994:
3995: # Generate the speller and set the langauge.
3996: # if explicitly selected:
1.1090 foxr 3997:
1.1091 foxr 3998: my $speller = Text::Aspell->new;
1.1090 foxr 3999: if ($language) {
1.1091 foxr 4000: $speller->set_option('lang', $language);
1.1090 foxr 4001: }
4002:
1.1091 foxr 4003: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4004:
1.1091 foxr 4005: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4006:
1.1091 foxr 4007: foreach my $word (@words) {
4008: if(! $speller->check($word)) {
4009: push(@misspellings, $word);
1.1090 foxr 4010: }
4011: }
1.1091 foxr 4012: return join(' ', @misspellings);
4013:
1.1090 foxr 4014: }
4015:
1.61 www 4016: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4017: =pod
4018:
1.112 bowersj2 4019: =head1 User Name Functions
4020:
4021: =over 4
4022:
1.648 raeburn 4023: =item * &plainname($uname,$udom,$first)
1.81 albertel 4024:
1.112 bowersj2 4025: Takes a users logon name and returns it as a string in
1.226 albertel 4026: "first middle last generation" form
4027: if $first is set to 'lastname' then it returns it as
4028: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4029:
4030: =cut
1.61 www 4031:
1.295 www 4032:
1.81 albertel 4033: ###############################################################
1.61 www 4034: sub plainname {
1.226 albertel 4035: my ($uname,$udom,$first)=@_;
1.537 albertel 4036: return if (!defined($uname) || !defined($udom));
1.295 www 4037: my %names=&getnames($uname,$udom);
1.226 albertel 4038: my $name=&Apache::lonnet::format_name($names{'firstname'},
4039: $names{'middlename'},
4040: $names{'lastname'},
4041: $names{'generation'},$first);
4042: $name=~s/^\s+//;
1.62 www 4043: $name=~s/\s+$//;
4044: $name=~s/\s+/ /g;
1.353 albertel 4045: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4046: return $name;
1.61 www 4047: }
1.66 www 4048:
4049: # -------------------------------------------------------------------- Nickname
1.81 albertel 4050: =pod
4051:
1.648 raeburn 4052: =item * &nickname($uname,$udom)
1.81 albertel 4053:
4054: Gets a users name and returns it as a string as
4055:
4056: ""nickname""
1.66 www 4057:
1.81 albertel 4058: if the user has a nickname or
4059:
4060: "first middle last generation"
4061:
4062: if the user does not
4063:
4064: =cut
1.66 www 4065:
4066: sub nickname {
4067: my ($uname,$udom)=@_;
1.537 albertel 4068: return if (!defined($uname) || !defined($udom));
1.295 www 4069: my %names=&getnames($uname,$udom);
1.68 albertel 4070: my $name=$names{'nickname'};
1.66 www 4071: if ($name) {
4072: $name='"'.$name.'"';
4073: } else {
4074: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4075: $names{'lastname'}.' '.$names{'generation'};
4076: $name=~s/\s+$//;
4077: $name=~s/\s+/ /g;
4078: }
4079: return $name;
4080: }
4081:
1.295 www 4082: sub getnames {
4083: my ($uname,$udom)=@_;
1.537 albertel 4084: return if (!defined($uname) || !defined($udom));
1.433 albertel 4085: if ($udom eq 'public' && $uname eq 'public') {
4086: return ('lastname' => &mt('Public'));
4087: }
1.295 www 4088: my $id=$uname.':'.$udom;
4089: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4090: if ($cached) {
4091: return %{$names};
4092: } else {
4093: my %loadnames=&Apache::lonnet::get('environment',
4094: ['firstname','middlename','lastname','generation','nickname'],
4095: $udom,$uname);
4096: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4097: return %loadnames;
4098: }
4099: }
1.61 www 4100:
1.542 raeburn 4101: # -------------------------------------------------------------------- getemails
1.648 raeburn 4102:
1.542 raeburn 4103: =pod
4104:
1.648 raeburn 4105: =item * &getemails($uname,$udom)
1.542 raeburn 4106:
4107: Gets a user's email information and returns it as a hash with keys:
4108: notification, critnotification, permanentemail
4109:
4110: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4111: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4112:
1.648 raeburn 4113:
1.542 raeburn 4114: =cut
4115:
1.648 raeburn 4116:
1.466 albertel 4117: sub getemails {
4118: my ($uname,$udom)=@_;
4119: if ($udom eq 'public' && $uname eq 'public') {
4120: return;
4121: }
1.467 www 4122: if (!$udom) { $udom=$env{'user.domain'}; }
4123: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4124: my $id=$uname.':'.$udom;
4125: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4126: if ($cached) {
4127: return %{$names};
4128: } else {
4129: my %loadnames=&Apache::lonnet::get('environment',
4130: ['notification','critnotification',
4131: 'permanentemail'],
4132: $udom,$uname);
4133: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4134: return %loadnames;
4135: }
4136: }
4137:
1.551 albertel 4138: sub flush_email_cache {
4139: my ($uname,$udom)=@_;
4140: if (!$udom) { $udom =$env{'user.domain'}; }
4141: if (!$uname) { $uname=$env{'user.name'}; }
4142: return if ($udom eq 'public' && $uname eq 'public');
4143: my $id=$uname.':'.$udom;
4144: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4145: }
4146:
1.728 raeburn 4147: # -------------------------------------------------------------------- getlangs
4148:
4149: =pod
4150:
4151: =item * &getlangs($uname,$udom)
4152:
4153: Gets a user's language preference and returns it as a hash with key:
4154: language.
4155:
4156: =cut
4157:
4158:
4159: sub getlangs {
4160: my ($uname,$udom) = @_;
4161: if (!$udom) { $udom =$env{'user.domain'}; }
4162: if (!$uname) { $uname=$env{'user.name'}; }
4163: my $id=$uname.':'.$udom;
4164: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4165: if ($cached) {
4166: return %{$langs};
4167: } else {
4168: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4169: $udom,$uname);
4170: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4171: return %loadlangs;
4172: }
4173: }
4174:
4175: sub flush_langs_cache {
4176: my ($uname,$udom)=@_;
4177: if (!$udom) { $udom =$env{'user.domain'}; }
4178: if (!$uname) { $uname=$env{'user.name'}; }
4179: return if ($udom eq 'public' && $uname eq 'public');
4180: my $id=$uname.':'.$udom;
4181: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4182: }
4183:
1.61 www 4184: # ------------------------------------------------------------------ Screenname
1.81 albertel 4185:
4186: =pod
4187:
1.648 raeburn 4188: =item * &screenname($uname,$udom)
1.81 albertel 4189:
4190: Gets a users screenname and returns it as a string
4191:
4192: =cut
1.61 www 4193:
4194: sub screenname {
4195: my ($uname,$udom)=@_;
1.258 albertel 4196: if ($uname eq $env{'user.name'} &&
4197: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4198: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4199: return $names{'screenname'};
1.62 www 4200: }
4201:
1.212 albertel 4202:
1.802 bisitz 4203: # ------------------------------------------------------------- Confirm Wrapper
4204: =pod
4205:
1.1142 raeburn 4206: =item * &confirmwrapper($message)
1.802 bisitz 4207:
4208: Wrap messages about completion of operation in box
4209:
4210: =cut
4211:
4212: sub confirmwrapper {
4213: my ($message)=@_;
4214: if ($message) {
4215: return "\n".'<div class="LC_confirm_box">'."\n"
4216: .$message."\n"
4217: .'</div>'."\n";
4218: } else {
4219: return $message;
4220: }
4221: }
4222:
1.62 www 4223: # ------------------------------------------------------------- Message Wrapper
4224:
4225: sub messagewrapper {
1.369 www 4226: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4227: return
1.441 albertel 4228: '<a href="/adm/email?compose=individual&'.
4229: 'recname='.$username.'&recdom='.$domain.
4230: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4231: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4232: }
1.802 bisitz 4233:
1.74 www 4234: # --------------------------------------------------------------- Notes Wrapper
4235:
4236: sub noteswrapper {
4237: my ($link,$un,$do)=@_;
4238: return
1.896 amueller 4239: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4240: }
1.802 bisitz 4241:
1.62 www 4242: # ------------------------------------------------------------- Aboutme Wrapper
4243:
4244: sub aboutmewrapper {
1.1070 raeburn 4245: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4246: if (!defined($username) && !defined($domain)) {
4247: return;
4248: }
1.1096 raeburn 4249: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4250: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4251: }
4252:
4253: # ------------------------------------------------------------ Syllabus Wrapper
4254:
4255: sub syllabuswrapper {
1.707 bisitz 4256: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4257: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4258: }
1.14 harris41 4259:
1.802 bisitz 4260: # -----------------------------------------------------------------------------
4261:
1.208 matthew 4262: sub track_student_link {
1.887 raeburn 4263: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4264: my $link ="/adm/trackstudent?";
1.208 matthew 4265: my $title = 'View recent activity';
4266: if (defined($sname) && $sname !~ /^\s*$/ &&
4267: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4268: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4269: $title .= ' of this student';
1.268 albertel 4270: }
1.208 matthew 4271: if (defined($target) && $target !~ /^\s*$/) {
4272: $target = qq{target="$target"};
4273: } else {
4274: $target = '';
4275: }
1.268 albertel 4276: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4277: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4278: $title = &mt($title);
4279: $linktext = &mt($linktext);
1.448 albertel 4280: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4281: &help_open_topic('View_recent_activity');
1.208 matthew 4282: }
4283:
1.781 raeburn 4284: sub slot_reservations_link {
4285: my ($linktext,$sname,$sdom,$target) = @_;
4286: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4287: my $title = 'View slot reservation history';
4288: if (defined($sname) && $sname !~ /^\s*$/ &&
4289: defined($sdom) && $sdom !~ /^\s*$/) {
4290: $link .= "&uname=$sname&udom=$sdom";
4291: $title .= ' of this student';
4292: }
4293: if (defined($target) && $target !~ /^\s*$/) {
4294: $target = qq{target="$target"};
4295: } else {
4296: $target = '';
4297: }
4298: $title = &mt($title);
4299: $linktext = &mt($linktext);
4300: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4301: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4302:
4303: }
4304:
1.508 www 4305: # ===================================================== Display a student photo
4306:
4307:
1.509 albertel 4308: sub student_image_tag {
1.508 www 4309: my ($domain,$user)=@_;
4310: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4311: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4312: return '<img src="'.$imgsrc.'" align="right" />';
4313: } else {
4314: return '';
4315: }
4316: }
4317:
1.112 bowersj2 4318: =pod
4319:
4320: =back
4321:
4322: =head1 Access .tab File Data
4323:
4324: =over 4
4325:
1.648 raeburn 4326: =item * &languageids()
1.112 bowersj2 4327:
4328: returns list of all language ids
4329:
4330: =cut
4331:
1.14 harris41 4332: sub languageids {
1.16 harris41 4333: return sort(keys(%language));
1.14 harris41 4334: }
4335:
1.112 bowersj2 4336: =pod
4337:
1.648 raeburn 4338: =item * &languagedescription()
1.112 bowersj2 4339:
4340: returns description of a specified language id
4341:
4342: =cut
4343:
1.14 harris41 4344: sub languagedescription {
1.125 www 4345: my $code=shift;
4346: return ($supported_language{$code}?'* ':'').
4347: $language{$code}.
1.126 www 4348: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4349: }
4350:
1.1048 foxr 4351: =pod
4352:
4353: =item * &plainlanguagedescription
4354:
4355: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4356: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4357:
4358: =cut
4359:
1.145 www 4360: sub plainlanguagedescription {
4361: my $code=shift;
4362: return $language{$code};
4363: }
4364:
1.1048 foxr 4365: =pod
4366:
4367: =item * &supportedlanguagecode
4368:
4369: Returns the supported language code (e.g. sptutf maps to pt) given a language
4370: code.
4371:
4372: =cut
4373:
1.145 www 4374: sub supportedlanguagecode {
4375: my $code=shift;
4376: return $supported_language{$code};
1.97 www 4377: }
4378:
1.112 bowersj2 4379: =pod
4380:
1.1048 foxr 4381: =item * &latexlanguage()
4382:
4383: Given a language key code returns the correspondnig language to use
4384: to select the correct hyphenation on LaTeX printouts. This is undef if there
4385: is no supported hyphenation for the language code.
4386:
4387: =cut
4388:
4389: sub latexlanguage {
4390: my $code = shift;
4391: return $latex_language{$code};
4392: }
4393:
4394: =pod
4395:
4396: =item * &latexhyphenation()
4397:
4398: Same as above but what's supplied is the language as it might be stored
4399: in the metadata.
4400:
4401: =cut
4402:
4403: sub latexhyphenation {
4404: my $key = shift;
4405: return $latex_language_bykey{$key};
4406: }
4407:
4408: =pod
4409:
1.648 raeburn 4410: =item * ©rightids()
1.112 bowersj2 4411:
4412: returns list of all copyrights
4413:
4414: =cut
4415:
4416: sub copyrightids {
4417: return sort(keys(%cprtag));
4418: }
4419:
4420: =pod
4421:
1.648 raeburn 4422: =item * ©rightdescription()
1.112 bowersj2 4423:
4424: returns description of a specified copyright id
4425:
4426: =cut
4427:
4428: sub copyrightdescription {
1.166 www 4429: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4430: }
1.197 matthew 4431:
4432: =pod
4433:
1.648 raeburn 4434: =item * &source_copyrightids()
1.192 taceyjo1 4435:
4436: returns list of all source copyrights
4437:
4438: =cut
4439:
4440: sub source_copyrightids {
4441: return sort(keys(%scprtag));
4442: }
4443:
4444: =pod
4445:
1.648 raeburn 4446: =item * &source_copyrightdescription()
1.192 taceyjo1 4447:
4448: returns description of a specified source copyright id
4449:
4450: =cut
4451:
4452: sub source_copyrightdescription {
4453: return &mt($scprtag{shift(@_)});
4454: }
1.112 bowersj2 4455:
4456: =pod
4457:
1.648 raeburn 4458: =item * &filecategories()
1.112 bowersj2 4459:
4460: returns list of all file categories
4461:
4462: =cut
4463:
4464: sub filecategories {
4465: return sort(keys(%category_extensions));
4466: }
4467:
4468: =pod
4469:
1.648 raeburn 4470: =item * &filecategorytypes()
1.112 bowersj2 4471:
4472: returns list of file types belonging to a given file
4473: category
4474:
4475: =cut
4476:
4477: sub filecategorytypes {
1.356 albertel 4478: my ($cat) = @_;
1.1248 raeburn 4479: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4480: return @{$category_extensions{lc($cat)}};
4481: } else {
4482: return ();
4483: }
1.112 bowersj2 4484: }
4485:
4486: =pod
4487:
1.648 raeburn 4488: =item * &fileembstyle()
1.112 bowersj2 4489:
4490: returns embedding style for a specified file type
4491:
4492: =cut
4493:
4494: sub fileembstyle {
4495: return $fe{lc(shift(@_))};
1.169 www 4496: }
4497:
1.351 www 4498: sub filemimetype {
4499: return $fm{lc(shift(@_))};
4500: }
4501:
1.169 www 4502:
4503: sub filecategoryselect {
4504: my ($name,$value)=@_;
1.189 matthew 4505: return &select_form($value,$name,
1.970 raeburn 4506: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4507: }
4508:
4509: =pod
4510:
1.648 raeburn 4511: =item * &filedescription()
1.112 bowersj2 4512:
4513: returns description for a specified file type
4514:
4515: =cut
4516:
4517: sub filedescription {
1.188 matthew 4518: my $file_description = $fd{lc(shift())};
4519: $file_description =~ s:([\[\]]):~$1:g;
4520: return &mt($file_description);
1.112 bowersj2 4521: }
4522:
4523: =pod
4524:
1.648 raeburn 4525: =item * &filedescriptionex()
1.112 bowersj2 4526:
4527: returns description for a specified file type with
4528: extra formatting
4529:
4530: =cut
4531:
4532: sub filedescriptionex {
4533: my $ex=shift;
1.188 matthew 4534: my $file_description = $fd{lc($ex)};
4535: $file_description =~ s:([\[\]]):~$1:g;
4536: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4537: }
4538:
4539: # End of .tab access
4540: =pod
4541:
4542: =back
4543:
4544: =cut
4545:
4546: # ------------------------------------------------------------------ File Types
4547: sub fileextensions {
4548: return sort(keys(%fe));
4549: }
4550:
1.97 www 4551: # ----------------------------------------------------------- Display Languages
4552: # returns a hash with all desired display languages
4553: #
4554:
4555: sub display_languages {
4556: my %languages=();
1.695 raeburn 4557: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4558: $languages{$lang}=1;
1.97 www 4559: }
4560: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4561: if ($env{'form.displaylanguage'}) {
1.356 albertel 4562: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4563: $languages{$lang}=1;
1.97 www 4564: }
4565: }
4566: return %languages;
1.14 harris41 4567: }
4568:
1.582 albertel 4569: sub languages {
4570: my ($possible_langs) = @_;
1.695 raeburn 4571: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4572: if (!ref($possible_langs)) {
4573: if( wantarray ) {
4574: return @preferred_langs;
4575: } else {
4576: return $preferred_langs[0];
4577: }
4578: }
4579: my %possibilities = map { $_ => 1 } (@$possible_langs);
4580: my @preferred_possibilities;
4581: foreach my $preferred_lang (@preferred_langs) {
4582: if (exists($possibilities{$preferred_lang})) {
4583: push(@preferred_possibilities, $preferred_lang);
4584: }
4585: }
4586: if( wantarray ) {
4587: return @preferred_possibilities;
4588: }
4589: return $preferred_possibilities[0];
4590: }
4591:
1.742 raeburn 4592: sub user_lang {
4593: my ($touname,$toudom,$fromcid) = @_;
4594: my @userlangs;
4595: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4596: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4597: $env{'course.'.$fromcid.'.languages'}));
4598: } else {
4599: my %langhash = &getlangs($touname,$toudom);
4600: if ($langhash{'languages'} ne '') {
4601: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4602: } else {
4603: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4604: if ($domdefs{'lang_def'} ne '') {
4605: @userlangs = ($domdefs{'lang_def'});
4606: }
4607: }
4608: }
4609: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4610: my $user_lh = Apache::localize->get_handle(@languages);
4611: return $user_lh;
4612: }
4613:
4614:
1.112 bowersj2 4615: ###############################################################
4616: ## Student Answer Attempts ##
4617: ###############################################################
4618:
4619: =pod
4620:
4621: =head1 Alternate Problem Views
4622:
4623: =over 4
4624:
1.648 raeburn 4625: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4626: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4627:
4628: Return string with previous attempt on problem. Arguments:
4629:
4630: =over 4
4631:
4632: =item * $symb: Problem, including path
4633:
4634: =item * $username: username of the desired student
4635:
4636: =item * $domain: domain of the desired student
1.14 harris41 4637:
1.112 bowersj2 4638: =item * $course: Course ID
1.14 harris41 4639:
1.112 bowersj2 4640: =item * $getattempt: Leave blank for all attempts, otherwise put
4641: something
1.14 harris41 4642:
1.112 bowersj2 4643: =item * $regexp: if string matches this regexp, the string will be
4644: sent to $gradesub
1.14 harris41 4645:
1.112 bowersj2 4646: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4647:
1.1199 raeburn 4648: =item * $usec: section of the desired student
4649:
4650: =item * $identifier: counter for student (multiple students one problem) or
4651: problem (one student; whole sequence).
4652:
1.112 bowersj2 4653: =back
1.14 harris41 4654:
1.112 bowersj2 4655: The output string is a table containing all desired attempts, if any.
1.16 harris41 4656:
1.112 bowersj2 4657: =cut
1.1 albertel 4658:
4659: sub get_previous_attempt {
1.1199 raeburn 4660: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4661: my $prevattempts='';
1.43 ng 4662: no strict 'refs';
1.1 albertel 4663: if ($symb) {
1.3 albertel 4664: my (%returnhash)=
4665: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4666: if ($returnhash{'version'}) {
4667: my %lasthash=();
4668: my $version;
4669: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4670: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4671: if ($key =~ /\.rawrndseed$/) {
4672: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4673: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4674: } else {
4675: $lasthash{$key}=$returnhash{$version.':'.$key};
4676: }
1.19 harris41 4677: }
1.1 albertel 4678: }
1.596 albertel 4679: $prevattempts=&start_data_table().&start_data_table_header_row();
4680: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4681: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4682: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4683: foreach my $key (sort(keys(%lasthash))) {
4684: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4685: if ($#parts > 0) {
1.31 albertel 4686: my $data=$parts[-1];
1.989 raeburn 4687: next if ($data eq 'foilorder');
1.31 albertel 4688: pop(@parts);
1.1010 www 4689: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4690: if ($data eq 'type') {
4691: unless ($showsurv) {
4692: my $id = join(',',@parts);
4693: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4694: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4695: $lasthidden{$ign.'.'.$id} = 1;
4696: }
1.945 raeburn 4697: }
1.1199 raeburn 4698: if ($identifier ne '') {
4699: my $id = join(',',@parts);
4700: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4701: $domain,$username,$usec,undef,$course) =~ /^no/) {
4702: $hidestatus{$ign.'.'.$id} = 1;
4703: }
4704: }
4705: } elsif ($data eq 'regrader') {
4706: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4707: my $id = join(',',@parts);
4708: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4709: }
1.1010 www 4710: }
1.31 albertel 4711: } else {
1.41 ng 4712: if ($#parts == 0) {
4713: $prevattempts.='<th>'.$parts[0].'</th>';
4714: } else {
4715: $prevattempts.='<th>'.$ign.'</th>';
4716: }
1.31 albertel 4717: }
1.16 harris41 4718: }
1.596 albertel 4719: $prevattempts.=&end_data_table_header_row();
1.40 ng 4720: if ($getattempt eq '') {
1.1199 raeburn 4721: my (%solved,%resets,%probstatus);
1.1200 raeburn 4722: if (($identifier ne '') && (keys(%regraded) > 0)) {
4723: for ($version=1;$version<=$returnhash{'version'};$version++) {
4724: foreach my $id (keys(%regraded)) {
4725: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4726: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4727: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4728: push(@{$resets{$id}},$version);
1.1199 raeburn 4729: }
4730: }
4731: }
1.1200 raeburn 4732: }
4733: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4734: my (@hidden,@unsolved);
1.945 raeburn 4735: if (%typeparts) {
4736: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4737: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4738: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4739: push(@hidden,$id);
1.1199 raeburn 4740: } elsif ($identifier ne '') {
4741: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4742: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4743: ($hidestatus{$id})) {
1.1200 raeburn 4744: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4745: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4746: push(@{$solved{$id}},$version);
4747: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4748: (ref($solved{$id}) eq 'ARRAY')) {
4749: my $skip;
4750: if (ref($resets{$id}) eq 'ARRAY') {
4751: foreach my $reset (@{$resets{$id}}) {
4752: if ($reset > $solved{$id}[-1]) {
4753: $skip=1;
4754: last;
4755: }
4756: }
4757: }
4758: unless ($skip) {
4759: my ($ign,$partslist) = split(/\./,$id,2);
4760: push(@unsolved,$partslist);
4761: }
4762: }
4763: }
1.945 raeburn 4764: }
4765: }
4766: }
4767: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4768: '<td>'.&mt('Transaction [_1]',$version);
4769: if (@unsolved) {
4770: $prevattempts .= '<span class="LC_nobreak"><label>'.
4771: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4772: &mt('Hide').'</label></span>';
4773: }
4774: $prevattempts .= '</td>';
1.945 raeburn 4775: if (@hidden) {
4776: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4777: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4778: my $hide;
4779: foreach my $id (@hidden) {
4780: if ($key =~ /^\Q$id\E/) {
4781: $hide = 1;
4782: last;
4783: }
4784: }
4785: if ($hide) {
4786: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4787: if (($data eq 'award') || ($data eq 'awarddetail')) {
4788: my $value = &format_previous_attempt_value($key,
4789: $returnhash{$version.':'.$key});
1.1173 kruse 4790: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4791: } else {
4792: $prevattempts.='<td> </td>';
4793: }
4794: } else {
4795: if ($key =~ /\./) {
1.1212 raeburn 4796: my $value = $returnhash{$version.':'.$key};
4797: if ($key =~ /\.rndseed$/) {
4798: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4799: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4800: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4801: }
4802: }
4803: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4804: ' </td>';
1.945 raeburn 4805: } else {
4806: $prevattempts.='<td> </td>';
4807: }
4808: }
4809: }
4810: } else {
4811: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4812: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4813: my $value = $returnhash{$version.':'.$key};
4814: if ($key =~ /\.rndseed$/) {
4815: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4816: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4817: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4818: }
4819: }
4820: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4821: ' </td>';
1.945 raeburn 4822: }
4823: }
4824: $prevattempts.=&end_data_table_row();
1.40 ng 4825: }
1.1 albertel 4826: }
1.945 raeburn 4827: my @currhidden = keys(%lasthidden);
1.596 albertel 4828: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4829: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4830: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4831: if (%typeparts) {
4832: my $hidden;
4833: foreach my $id (@currhidden) {
4834: if ($key =~ /^\Q$id\E/) {
4835: $hidden = 1;
4836: last;
4837: }
4838: }
4839: if ($hidden) {
4840: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4841: if (($data eq 'award') || ($data eq 'awarddetail')) {
4842: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4843: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4844: $value = &$gradesub($value);
4845: }
1.1173 kruse 4846: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4847: } else {
4848: $prevattempts.='<td> </td>';
4849: }
4850: } else {
4851: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4852: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4853: $value = &$gradesub($value);
4854: }
1.1173 kruse 4855: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4856: }
4857: } else {
4858: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4859: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4860: $value = &$gradesub($value);
4861: }
1.1173 kruse 4862: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4863: }
1.16 harris41 4864: }
1.596 albertel 4865: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4866: } else {
1.1305 raeburn 4867: my $msg;
4868: if ($symb =~ /ext\.tool$/) {
4869: $msg = &mt('No grade passed back.');
4870: } else {
4871: $msg = &mt('Nothing submitted - no attempts.');
4872: }
1.596 albertel 4873: $prevattempts=
4874: &start_data_table().&start_data_table_row().
1.1305 raeburn 4875: '<td>'.$msg.'</td>'.
1.596 albertel 4876: &end_data_table_row().&end_data_table();
1.1 albertel 4877: }
4878: } else {
1.596 albertel 4879: $prevattempts=
4880: &start_data_table().&start_data_table_row().
4881: '<td>'.&mt('No data.').'</td>'.
4882: &end_data_table_row().&end_data_table();
1.1 albertel 4883: }
1.10 albertel 4884: }
4885:
1.581 albertel 4886: sub format_previous_attempt_value {
4887: my ($key,$value) = @_;
1.1011 www 4888: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4889: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4890: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4891: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4892: } elsif ($key =~ /answerstring$/) {
4893: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4894: my @answer = %answers;
4895: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4896: my @anskeys = sort(keys(%answers));
4897: if (@anskeys == 1) {
4898: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4899: if ($answer =~ m{\0}) {
4900: $answer =~ s{\0}{,}g;
1.988 raeburn 4901: }
4902: my $tag_internal_answer_name = 'INTERNAL';
4903: if ($anskeys[0] eq $tag_internal_answer_name) {
4904: $value = $answer;
4905: } else {
4906: $value = $anskeys[0].'='.$answer;
4907: }
4908: } else {
4909: foreach my $ans (@anskeys) {
4910: my $answer = $answers{$ans};
1.1001 raeburn 4911: if ($answer =~ m{\0}) {
4912: $answer =~ s{\0}{,}g;
1.988 raeburn 4913: }
4914: $value .= $ans.'='.$answer.'<br />';;
4915: }
4916: }
1.581 albertel 4917: } else {
1.1173 kruse 4918: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4919: }
4920: return $value;
4921: }
4922:
4923:
1.107 albertel 4924: sub relative_to_absolute {
4925: my ($url,$output)=@_;
4926: my $parser=HTML::TokeParser->new(\$output);
4927: my $token;
4928: my $thisdir=$url;
4929: my @rlinks=();
4930: while ($token=$parser->get_token) {
4931: if ($token->[0] eq 'S') {
4932: if ($token->[1] eq 'a') {
4933: if ($token->[2]->{'href'}) {
4934: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4935: }
4936: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4937: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4938: } elsif ($token->[1] eq 'base') {
4939: $thisdir=$token->[2]->{'href'};
4940: }
4941: }
4942: }
4943: $thisdir=~s-/[^/]*$--;
1.356 albertel 4944: foreach my $link (@rlinks) {
1.726 raeburn 4945: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4946: ($link=~/^\//) ||
4947: ($link=~/^javascript:/i) ||
4948: ($link=~/^mailto:/i) ||
4949: ($link=~/^\#/)) {
4950: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4951: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4952: }
4953: }
4954: # -------------------------------------------------- Deal with Applet codebases
4955: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4956: return $output;
4957: }
4958:
1.112 bowersj2 4959: =pod
4960:
1.648 raeburn 4961: =item * &get_student_view()
1.112 bowersj2 4962:
4963: show a snapshot of what student was looking at
4964:
4965: =cut
4966:
1.10 albertel 4967: sub get_student_view {
1.186 albertel 4968: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4969: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4970: my (%form);
1.10 albertel 4971: my @elements=('symb','courseid','domain','username');
4972: foreach my $element (@elements) {
1.186 albertel 4973: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4974: }
1.186 albertel 4975: if (defined($moreenv)) {
4976: %form=(%form,%{$moreenv});
4977: }
1.236 albertel 4978: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4979: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4980: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4981: $feedurl =~ s{^/adm/wrapper}{};
4982: }
1.650 www 4983: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4984: $userview=~s/\<body[^\>]*\>//gi;
4985: $userview=~s/\<\/body\>//gi;
4986: $userview=~s/\<html\>//gi;
4987: $userview=~s/\<\/html\>//gi;
4988: $userview=~s/\<head\>//gi;
4989: $userview=~s/\<\/head\>//gi;
4990: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4991: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4992: if (wantarray) {
4993: return ($userview,$response);
4994: } else {
4995: return $userview;
4996: }
4997: }
4998:
4999: sub get_student_view_with_retries {
5000: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5001:
5002: my $ok = 0; # True if we got a good response.
5003: my $content;
5004: my $response;
5005:
5006: # Try to get the student_view done. within the retries count:
5007:
5008: do {
5009: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5010: $ok = $response->is_success;
5011: if (!$ok) {
5012: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5013: }
5014: $retries--;
5015: } while (!$ok && ($retries > 0));
5016:
5017: if (!$ok) {
5018: $content = ''; # On error return an empty content.
5019: }
1.651 www 5020: if (wantarray) {
5021: return ($content, $response);
5022: } else {
5023: return $content;
5024: }
1.11 albertel 5025: }
5026:
1.1349 raeburn 5027: sub css_links {
5028: my ($currsymb,$level) = @_;
5029: my ($links,@symbs,%cssrefs,%httpref);
5030: if ($level eq 'map') {
5031: my $navmap = Apache::lonnavmaps::navmap->new();
5032: if (ref($navmap)) {
5033: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5034: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5035: foreach my $res (@resources) {
5036: if (ref($res) && $res->symb()) {
5037: push(@symbs,$res->symb());
5038: }
5039: }
5040: }
5041: } else {
5042: @symbs = ($currsymb);
5043: }
5044: foreach my $symb (@symbs) {
5045: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5046: if ($css_href =~ /\S/) {
5047: unless ($css_href =~ m{https?://}) {
5048: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5049: my $proburl = &Apache::lonnet::clutter($url);
5050: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5051: unless ($css_href =~ m{^/}) {
5052: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5053: }
5054: if ($css_href =~ m{^/(res|uploaded)/}) {
5055: unless (($httpref{'httpref.'.$css_href}) ||
5056: (&Apache::lonnet::is_on_map($css_href))) {
5057: my $thisurl = $proburl;
5058: if ($env{'httpref.'.$proburl}) {
5059: $thisurl = $env{'httpref.'.$proburl};
5060: }
5061: $httpref{'httpref.'.$css_href} = $thisurl;
5062: }
5063: }
5064: }
5065: $cssrefs{$css_href} = 1;
5066: }
5067: }
5068: if (keys(%httpref)) {
5069: &Apache::lonnet::appenv(\%httpref);
5070: }
5071: if (keys(%cssrefs)) {
5072: foreach my $css_href (keys(%cssrefs)) {
5073: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5074: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5075: }
5076: }
5077: return $links;
5078: }
5079:
1.112 bowersj2 5080: =pod
5081:
1.648 raeburn 5082: =item * &get_student_answers()
1.112 bowersj2 5083:
5084: show a snapshot of how student was answering problem
5085:
5086: =cut
5087:
1.11 albertel 5088: sub get_student_answers {
1.100 sakharuk 5089: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5090: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5091: my (%moreenv);
1.11 albertel 5092: my @elements=('symb','courseid','domain','username');
5093: foreach my $element (@elements) {
1.186 albertel 5094: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5095: }
1.186 albertel 5096: $moreenv{'grade_target'}='answer';
5097: %moreenv=(%form,%moreenv);
1.497 raeburn 5098: $feedurl = &Apache::lonnet::clutter($feedurl);
5099: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5100: return $userview;
1.1 albertel 5101: }
1.116 albertel 5102:
5103: =pod
5104:
5105: =item * &submlink()
5106:
1.242 albertel 5107: Inputs: $text $uname $udom $symb $target
1.116 albertel 5108:
5109: Returns: A link to grades.pm such as to see the SUBM view of a student
5110:
5111: =cut
5112:
5113: ###############################################
5114: sub submlink {
1.242 albertel 5115: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5116: if (!($uname && $udom)) {
5117: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5118: &Apache::lonnet::whichuser($symb);
1.116 albertel 5119: if (!$symb) { $symb=$cursymb; }
5120: }
1.254 matthew 5121: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5122: $symb=&escape($symb);
1.960 bisitz 5123: if ($target) { $target=" target=\"$target\""; }
5124: return
5125: '<a href="/adm/grades?command=submission'.
5126: '&symb='.$symb.
5127: '&student='.$uname.
5128: '&userdom='.$udom.'"'.
5129: $target.'>'.$text.'</a>';
1.242 albertel 5130: }
5131: ##############################################
5132:
5133: =pod
5134:
5135: =item * &pgrdlink()
5136:
5137: Inputs: $text $uname $udom $symb $target
5138:
5139: Returns: A link to grades.pm such as to see the PGRD view of a student
5140:
5141: =cut
5142:
5143: ###############################################
5144: sub pgrdlink {
5145: my $link=&submlink(@_);
5146: $link=~s/(&command=submission)/$1&showgrading=yes/;
5147: return $link;
5148: }
5149: ##############################################
5150:
5151: =pod
5152:
5153: =item * &pprmlink()
5154:
5155: Inputs: $text $uname $udom $symb $target
5156:
5157: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5158: student and a specific resource
1.242 albertel 5159:
5160: =cut
5161:
5162: ###############################################
5163: sub pprmlink {
5164: my ($text,$uname,$udom,$symb,$target)=@_;
5165: if (!($uname && $udom)) {
5166: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5167: &Apache::lonnet::whichuser($symb);
1.242 albertel 5168: if (!$symb) { $symb=$cursymb; }
5169: }
1.254 matthew 5170: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5171: $symb=&escape($symb);
1.242 albertel 5172: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5173: return '<a href="/adm/parmset?command=set&'.
5174: 'symb='.$symb.'&uname='.$uname.
5175: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5176: }
5177: ##############################################
1.37 matthew 5178:
1.112 bowersj2 5179: =pod
5180:
5181: =back
5182:
5183: =cut
5184:
1.37 matthew 5185: ###############################################
1.51 www 5186:
5187:
5188: sub timehash {
1.687 raeburn 5189: my ($thistime) = @_;
5190: my $timezone = &Apache::lonlocal::gettimezone();
5191: my $dt = DateTime->from_epoch(epoch => $thistime)
5192: ->set_time_zone($timezone);
5193: my $wday = $dt->day_of_week();
5194: if ($wday == 7) { $wday = 0; }
5195: return ( 'second' => $dt->second(),
5196: 'minute' => $dt->minute(),
5197: 'hour' => $dt->hour(),
5198: 'day' => $dt->day_of_month(),
5199: 'month' => $dt->month(),
5200: 'year' => $dt->year(),
5201: 'weekday' => $wday,
5202: 'dayyear' => $dt->day_of_year(),
5203: 'dlsav' => $dt->is_dst() );
1.51 www 5204: }
5205:
1.370 www 5206: sub utc_string {
5207: my ($date)=@_;
1.371 www 5208: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5209: }
5210:
1.51 www 5211: sub maketime {
5212: my %th=@_;
1.687 raeburn 5213: my ($epoch_time,$timezone,$dt);
5214: $timezone = &Apache::lonlocal::gettimezone();
5215: eval {
5216: $dt = DateTime->new( year => $th{'year'},
5217: month => $th{'month'},
5218: day => $th{'day'},
5219: hour => $th{'hour'},
5220: minute => $th{'minute'},
5221: second => $th{'second'},
5222: time_zone => $timezone,
5223: );
5224: };
5225: if (!$@) {
5226: $epoch_time = $dt->epoch;
5227: if ($epoch_time) {
5228: return $epoch_time;
5229: }
5230: }
1.51 www 5231: return POSIX::mktime(
5232: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5233: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5234: }
5235:
5236: #########################################
1.51 www 5237:
5238: sub findallcourses {
1.482 raeburn 5239: my ($roles,$uname,$udom) = @_;
1.355 albertel 5240: my %roles;
5241: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5242: my %courses;
1.51 www 5243: my $now=time;
1.482 raeburn 5244: if (!defined($uname)) {
5245: $uname = $env{'user.name'};
5246: }
5247: if (!defined($udom)) {
5248: $udom = $env{'user.domain'};
5249: }
5250: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5251: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5252: if (!%roles) {
5253: %roles = (
5254: cc => 1,
1.907 raeburn 5255: co => 1,
1.482 raeburn 5256: in => 1,
5257: ep => 1,
5258: ta => 1,
5259: cr => 1,
5260: st => 1,
5261: );
5262: }
5263: foreach my $entry (keys(%roleshash)) {
5264: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5265: if ($trole =~ /^cr/) {
5266: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5267: } else {
5268: next if (!exists($roles{$trole}));
5269: }
5270: if ($tend) {
5271: next if ($tend < $now);
5272: }
5273: if ($tstart) {
5274: next if ($tstart > $now);
5275: }
1.1058 raeburn 5276: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5277: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5278: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5279: if ($secpart eq '') {
5280: ($cnum,$role) = split(/_/,$cnumpart);
5281: $sec = 'none';
1.1058 raeburn 5282: $value .= $cnum.'/';
1.482 raeburn 5283: } else {
5284: $cnum = $cnumpart;
5285: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5286: $value .= $cnum.'/'.$sec;
5287: }
5288: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5289: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5290: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5291: }
5292: } else {
5293: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5294: }
1.482 raeburn 5295: }
5296: } else {
5297: foreach my $key (keys(%env)) {
1.483 albertel 5298: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5299: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5300: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5301: next if ($role eq 'ca' || $role eq 'aa');
5302: next if (%roles && !exists($roles{$role}));
5303: my ($starttime,$endtime)=split(/\./,$env{$key});
5304: my $active=1;
5305: if ($starttime) {
5306: if ($now<$starttime) { $active=0; }
5307: }
5308: if ($endtime) {
5309: if ($now>$endtime) { $active=0; }
5310: }
5311: if ($active) {
1.1058 raeburn 5312: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5313: if ($sec eq '') {
5314: $sec = 'none';
1.1058 raeburn 5315: } else {
5316: $value .= $sec;
5317: }
5318: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5319: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5320: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5321: }
5322: } else {
5323: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5324: }
1.474 raeburn 5325: }
5326: }
1.51 www 5327: }
5328: }
1.474 raeburn 5329: return %courses;
1.51 www 5330: }
1.37 matthew 5331:
1.54 www 5332: ###############################################
1.474 raeburn 5333:
5334: sub blockcheck {
1.1372 raeburn 5335: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5336: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5337: my ($has_evb,$check_ipaccess);
5338: my $dom = $env{'user.domain'};
5339: if ($env{'request.course.id'}) {
5340: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5341: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5342: my $checkrole = "cm./$cdom/$cnum";
5343: my $sec = $env{'request.course.sec'};
5344: if ($sec ne '') {
5345: $checkrole .= "/$sec";
5346: }
5347: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5348: ($env{'request.role'} !~ /^st/)) {
5349: $has_evb = 1;
5350: }
5351: unless ($has_evb) {
5352: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5353: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5354: if ($udom eq $cdom) {
5355: $check_ipaccess = 1;
5356: }
5357: }
5358: }
1.1375 raeburn 5359: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5360: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5361: my $checkrole;
5362: if ($env{'request.role.domain'} eq '') {
5363: $checkrole = "cm./$env{'user.domain'}/";
5364: } else {
5365: $checkrole = "cm./$env{'request.role.domain'}/";
5366: }
5367: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5368: $has_evb = 1;
5369: }
1.1372 raeburn 5370: }
5371: unless ($has_evb || $check_ipaccess) {
5372: my @machinedoms = &Apache::lonnet::current_machine_domains();
5373: if (($dom eq 'public') && ($activity eq 'port')) {
5374: $dom = $udom;
5375: }
5376: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5377: $check_ipaccess = 1;
5378: } else {
5379: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5380: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5381: my $prim = &Apache::lonnet::domain($dom,'primary');
5382: my $intdom = &Apache::lonnet::internet_dom($prim);
5383: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5384: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5385: $check_ipaccess = 1;
5386: }
5387: }
5388: }
5389: }
5390: if ($check_ipaccess) {
5391: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5392: unless (defined($cached)) {
5393: my %domconfig =
5394: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5395: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5396: }
5397: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5398: foreach my $id (keys(%{$ipaccessref})) {
5399: if (ref($ipaccessref->{$id}) eq 'HASH') {
5400: my $range = $ipaccessref->{$id}->{'ip'};
5401: if ($range) {
5402: if (&Apache::lonnet::ip_match($clientip,$range)) {
5403: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5404: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5405: return ('','','',$id,$dom);
5406: last;
5407: }
5408: }
5409: }
5410: }
5411: }
5412: }
5413: }
5414: }
1.1373 raeburn 5415: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5416: return ();
5417: }
1.1372 raeburn 5418: }
1.1189 raeburn 5419: if (defined($udom) && defined($uname)) {
5420: # If uname and udom are for a course, check for blocks in the course.
5421: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5422: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5423: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5424: return ($startblock,$endblock,$triggerblock);
5425: }
5426: } else {
1.490 raeburn 5427: $udom = $env{'user.domain'};
5428: $uname = $env{'user.name'};
5429: }
5430:
1.502 raeburn 5431: my $startblock = 0;
5432: my $endblock = 0;
1.1062 raeburn 5433: my $triggerblock = '';
1.1373 raeburn 5434: my %live_courses;
5435: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5436: %live_courses = &findallcourses(undef,$uname,$udom);
5437: }
1.474 raeburn 5438:
1.490 raeburn 5439: # If uname is for a user, and activity is course-specific, i.e.,
5440: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5441:
1.490 raeburn 5442: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5443: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5444: $activity eq 'search' || $activity eq 'reinit' ||
5445: $activity eq 'alert') &&
1.1189 raeburn 5446: ($env{'request.course.id'})) {
1.490 raeburn 5447: foreach my $key (keys(%live_courses)) {
5448: if ($key ne $env{'request.course.id'}) {
5449: delete($live_courses{$key});
5450: }
5451: }
5452: }
5453:
5454: my $otheruser = 0;
5455: my %own_courses;
5456: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5457: # Resource belongs to user other than current user.
5458: $otheruser = 1;
5459: # Gather courses for current user
5460: %own_courses =
5461: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5462: }
5463:
5464: # Gather active course roles - course coordinator, instructor,
5465: # exam proctor, ta, student, or custom role.
1.474 raeburn 5466:
5467: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5468: my ($cdom,$cnum);
5469: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5470: $cdom = $env{'course.'.$course.'.domain'};
5471: $cnum = $env{'course.'.$course.'.num'};
5472: } else {
1.490 raeburn 5473: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5474: }
5475: my $no_ownblock = 0;
5476: my $no_userblock = 0;
1.533 raeburn 5477: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5478: # Check if current user has 'evb' priv for this
5479: if (defined($own_courses{$course})) {
5480: foreach my $sec (keys(%{$own_courses{$course}})) {
5481: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5482: if ($sec ne 'none') {
5483: $checkrole .= '/'.$sec;
5484: }
5485: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5486: $no_ownblock = 1;
5487: last;
5488: }
5489: }
5490: }
5491: # if they have 'evb' priv and are currently not playing student
5492: next if (($no_ownblock) &&
5493: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5494: }
1.474 raeburn 5495: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5496: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5497: if ($sec ne 'none') {
1.482 raeburn 5498: $checkrole .= '/'.$sec;
1.474 raeburn 5499: }
1.490 raeburn 5500: if ($otheruser) {
5501: # Resource belongs to user other than current user.
5502: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5503: my (%allroles,%userroles);
5504: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5505: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5506: my ($trole,$tdom,$tnum,$tsec);
5507: if ($entry =~ /^cr/) {
5508: ($trole,$tdom,$tnum,$tsec) =
5509: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5510: } else {
5511: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5512: }
5513: my ($spec,$area,$trest);
5514: $area = '/'.$tdom.'/'.$tnum;
5515: $trest = $tnum;
5516: if ($tsec ne '') {
5517: $area .= '/'.$tsec;
5518: $trest .= '/'.$tsec;
5519: }
5520: $spec = $trole.'.'.$area;
5521: if ($trole =~ /^cr/) {
5522: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5523: $tdom,$spec,$trest,$area);
5524: } else {
5525: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5526: $tdom,$spec,$trest,$area);
5527: }
5528: }
1.1276 raeburn 5529: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5530: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5531: if ($1) {
5532: $no_userblock = 1;
5533: last;
5534: }
1.486 raeburn 5535: }
5536: }
1.490 raeburn 5537: } else {
5538: # Resource belongs to current user
5539: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5540: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5541: $no_ownblock = 1;
5542: last;
5543: }
1.474 raeburn 5544: }
5545: }
5546: # if they have the evb priv and are currently not playing student
1.482 raeburn 5547: next if (($no_ownblock) &&
1.491 albertel 5548: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5549: next if ($no_userblock);
1.474 raeburn 5550:
1.1303 raeburn 5551: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5552: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5553:
1.1062 raeburn 5554: my ($start,$end,$trigger) =
1.1347 raeburn 5555: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5556: if (($start != 0) &&
5557: (($startblock == 0) || ($startblock > $start))) {
5558: $startblock = $start;
1.1062 raeburn 5559: if ($trigger ne '') {
5560: $triggerblock = $trigger;
5561: }
1.502 raeburn 5562: }
5563: if (($end != 0) &&
5564: (($endblock == 0) || ($endblock < $end))) {
5565: $endblock = $end;
1.1062 raeburn 5566: if ($trigger ne '') {
5567: $triggerblock = $trigger;
5568: }
1.502 raeburn 5569: }
1.490 raeburn 5570: }
1.1062 raeburn 5571: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5572: }
5573:
5574: sub get_blocks {
1.1347 raeburn 5575: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5576: my $startblock = 0;
5577: my $endblock = 0;
1.1062 raeburn 5578: my $triggerblock = '';
1.490 raeburn 5579: my $course = $cdom.'_'.$cnum;
5580: $setters->{$course} = {};
5581: $setters->{$course}{'staff'} = [];
5582: $setters->{$course}{'times'} = [];
1.1062 raeburn 5583: $setters->{$course}{'triggers'} = [];
5584: my (@blockers,%triggered);
5585: my $now = time;
5586: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5587: if ($activity eq 'docs') {
1.1348 raeburn 5588: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5589: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5590: $blocked = 1;
5591: $nosymbcache = 1;
1.1348 raeburn 5592: $noenccheck = 1;
1.1347 raeburn 5593: }
1.1348 raeburn 5594: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5595: foreach my $block (@blockers) {
5596: if ($block =~ /^firstaccess____(.+)$/) {
5597: my $item = $1;
5598: my $type = 'map';
5599: my $timersymb = $item;
5600: if ($item eq 'course') {
5601: $type = 'course';
5602: } elsif ($item =~ /___\d+___/) {
5603: $type = 'resource';
5604: } else {
5605: $timersymb = &Apache::lonnet::symbread($item);
5606: }
5607: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5608: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5609: $triggered{$block} = {
5610: start => $start,
5611: end => $end,
5612: type => $type,
5613: };
5614: }
5615: }
5616: } else {
5617: foreach my $block (keys(%commblocks)) {
5618: if ($block =~ m/^(\d+)____(\d+)$/) {
5619: my ($start,$end) = ($1,$2);
5620: if ($start <= time && $end >= time) {
5621: if (ref($commblocks{$block}) eq 'HASH') {
5622: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5623: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5624: unless(grep(/^\Q$block\E$/,@blockers)) {
5625: push(@blockers,$block);
5626: }
5627: }
5628: }
5629: }
5630: }
5631: } elsif ($block =~ /^firstaccess____(.+)$/) {
5632: my $item = $1;
5633: my $timersymb = $item;
5634: my $type = 'map';
5635: if ($item eq 'course') {
5636: $type = 'course';
5637: } elsif ($item =~ /___\d+___/) {
5638: $type = 'resource';
5639: } else {
5640: $timersymb = &Apache::lonnet::symbread($item);
5641: }
5642: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5643: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5644: if ($start && $end) {
5645: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5646: if (ref($commblocks{$block}) eq 'HASH') {
5647: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5648: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5649: unless(grep(/^\Q$block\E$/,@blockers)) {
5650: push(@blockers,$block);
5651: $triggered{$block} = {
5652: start => $start,
5653: end => $end,
5654: type => $type,
5655: };
5656: }
5657: }
5658: }
1.1062 raeburn 5659: }
5660: }
1.490 raeburn 5661: }
1.1062 raeburn 5662: }
5663: }
5664: }
5665: foreach my $blocker (@blockers) {
5666: my ($staff_name,$staff_dom,$title,$blocks) =
5667: &parse_block_record($commblocks{$blocker});
5668: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5669: my ($start,$end,$triggertype);
5670: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5671: ($start,$end) = ($1,$2);
5672: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5673: $start = $triggered{$blocker}{'start'};
5674: $end = $triggered{$blocker}{'end'};
5675: $triggertype = $triggered{$blocker}{'type'};
5676: }
5677: if ($start) {
5678: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5679: if ($triggertype) {
5680: push(@{$$setters{$course}{'triggers'}},$triggertype);
5681: } else {
5682: push(@{$$setters{$course}{'triggers'}},0);
5683: }
5684: if ( ($startblock == 0) || ($startblock > $start) ) {
5685: $startblock = $start;
5686: if ($triggertype) {
5687: $triggerblock = $blocker;
1.474 raeburn 5688: }
5689: }
1.1062 raeburn 5690: if ( ($endblock == 0) || ($endblock < $end) ) {
5691: $endblock = $end;
5692: if ($triggertype) {
5693: $triggerblock = $blocker;
5694: }
5695: }
1.474 raeburn 5696: }
5697: }
1.1062 raeburn 5698: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5699: }
5700:
5701: sub parse_block_record {
5702: my ($record) = @_;
5703: my ($setuname,$setudom,$title,$blocks);
5704: if (ref($record) eq 'HASH') {
5705: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5706: $title = &unescape($record->{'event'});
5707: $blocks = $record->{'blocks'};
5708: } else {
5709: my @data = split(/:/,$record,3);
5710: if (scalar(@data) eq 2) {
5711: $title = $data[1];
5712: ($setuname,$setudom) = split(/@/,$data[0]);
5713: } else {
5714: ($setuname,$setudom,$title) = @data;
5715: }
5716: $blocks = { 'com' => 'on' };
5717: }
5718: return ($setuname,$setudom,$title,$blocks);
5719: }
5720:
1.854 kalberla 5721: sub blocking_status {
1.1372 raeburn 5722: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5723: my %setters;
1.890 droeschl 5724:
1.1061 raeburn 5725: # check for active blocking
1.1372 raeburn 5726: if ($clientip eq '') {
5727: $clientip = &Apache::lonnet::get_requestor_ip();
5728: }
5729: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5730: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5731: my $blocked = 0;
1.1372 raeburn 5732: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5733: $blocked = 1;
5734: }
1.890 droeschl 5735:
1.1061 raeburn 5736: # caller just wants to know whether a block is active
5737: if (!wantarray) { return $blocked; }
5738:
5739: # build a link to a popup window containing the details
5740: my $querystring = "?activity=$activity";
1.1351 raeburn 5741: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5742: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5743: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5744: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5745: } elsif ($activity eq 'docs') {
1.1347 raeburn 5746: my $showurl = &Apache::lonenc::check_encrypt($url);
5747: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5748: if ($symb) {
5749: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5750: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5751: }
1.1062 raeburn 5752: }
1.1061 raeburn 5753:
5754: my $output .= <<'END_MYBLOCK';
5755: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5756: var options = "width=" + w + ",height=" + h + ",";
5757: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5758: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5759: var newWin = window.open(url, wdwName, options);
5760: newWin.focus();
5761: }
1.890 droeschl 5762: END_MYBLOCK
1.854 kalberla 5763:
1.1061 raeburn 5764: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5765:
1.1061 raeburn 5766: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5767: my $text = &mt('Communication Blocked');
1.1217 raeburn 5768: my $class = 'LC_comblock';
1.1062 raeburn 5769: if ($activity eq 'docs') {
5770: $text = &mt('Content Access Blocked');
1.1217 raeburn 5771: $class = '';
1.1063 raeburn 5772: } elsif ($activity eq 'printout') {
5773: $text = &mt('Printing Blocked');
1.1232 raeburn 5774: } elsif ($activity eq 'passwd') {
5775: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5776: } elsif ($activity eq 'grades') {
5777: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5778: } elsif ($activity eq 'search') {
5779: $text = &mt('Search Blocked');
1.1282 raeburn 5780: } elsif ($activity eq 'alert') {
5781: $text = &mt('Checking Critical Messages Blocked');
5782: } elsif ($activity eq 'reinit') {
5783: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5784: } elsif ($activity eq 'about') {
5785: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5786: } elsif ($activity eq 'wishlist') {
5787: $text = &mt('Access to Stored Links Blocked');
5788: } elsif ($activity eq 'annotate') {
5789: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5790: }
1.1061 raeburn 5791: $output .= <<"END_BLOCK";
1.1217 raeburn 5792: <div class='$class'>
1.869 kalberla 5793: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5794: title='$text'>
5795: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5796: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5797: title='$text'>$text</a>
1.867 kalberla 5798: </div>
5799:
5800: END_BLOCK
1.474 raeburn 5801:
1.1061 raeburn 5802: return ($blocked, $output);
1.854 kalberla 5803: }
1.490 raeburn 5804:
1.60 matthew 5805: ###############################################
5806:
1.682 raeburn 5807: sub check_ip_acc {
1.1201 raeburn 5808: my ($acc,$clientip)=@_;
1.682 raeburn 5809: &Apache::lonxml::debug("acc is $acc");
5810: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5811: return 1;
5812: }
1.1339 raeburn 5813: my ($ip,$allowed);
5814: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5815: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5816: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5817: } else {
1.1350 raeburn 5818: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5819: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5820: }
1.682 raeburn 5821:
5822: my $name;
1.1219 raeburn 5823: my %access = (
5824: allowfrom => 1,
5825: denyfrom => 0,
5826: );
5827: my @allows;
5828: my @denies;
5829: foreach my $item (split(',',$acc)) {
5830: $item =~ s/^\s*//;
5831: $item =~ s/\s*$//;
5832: my $pattern;
5833: if ($item =~ /^\!(.+)$/) {
5834: push(@denies,$1);
5835: } else {
5836: push(@allows,$item);
5837: }
5838: }
5839: my $numdenies = scalar(@denies);
5840: my $numallows = scalar(@allows);
5841: my $count = 0;
5842: foreach my $pattern (@denies,@allows) {
5843: $count ++;
5844: my $acctype = 'allowfrom';
5845: if ($count <= $numdenies) {
5846: $acctype = 'denyfrom';
5847: }
1.682 raeburn 5848: if ($pattern =~ /\*$/) {
5849: #35.8.*
5850: $pattern=~s/\*//;
1.1219 raeburn 5851: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5852: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5853: #35.8.3.[34-56]
5854: my $low=$2;
5855: my $high=$3;
5856: $pattern=$1;
5857: if ($ip =~ /^\Q$pattern\E/) {
5858: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5859: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5860: }
5861: } elsif ($pattern =~ /^\*/) {
5862: #*.msu.edu
5863: $pattern=~s/\*//;
5864: if (!defined($name)) {
5865: use Socket;
5866: my $netaddr=inet_aton($ip);
5867: ($name)=gethostbyaddr($netaddr,AF_INET);
5868: }
1.1219 raeburn 5869: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5870: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5871: #127.0.0.1
1.1219 raeburn 5872: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5873: } else {
5874: #some.name.com
5875: if (!defined($name)) {
5876: use Socket;
5877: my $netaddr=inet_aton($ip);
5878: ($name)=gethostbyaddr($netaddr,AF_INET);
5879: }
1.1219 raeburn 5880: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5881: }
5882: if ($allowed =~ /^(0|1)$/) { last; }
5883: }
5884: if ($allowed eq '') {
5885: if ($numdenies && !$numallows) {
5886: $allowed = 1;
5887: } else {
5888: $allowed = 0;
1.682 raeburn 5889: }
5890: }
5891: return $allowed;
5892: }
5893:
5894: ###############################################
5895:
1.60 matthew 5896: =pod
5897:
1.112 bowersj2 5898: =head1 Domain Template Functions
5899:
5900: =over 4
5901:
5902: =item * &determinedomain()
1.60 matthew 5903:
5904: Inputs: $domain (usually will be undef)
5905:
1.63 www 5906: Returns: Determines which domain should be used for designs
1.60 matthew 5907:
5908: =cut
1.54 www 5909:
1.60 matthew 5910: ###############################################
1.63 www 5911: sub determinedomain {
5912: my $domain=shift;
1.531 albertel 5913: if (! $domain) {
1.60 matthew 5914: # Determine domain if we have not been given one
1.893 raeburn 5915: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5916: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5917: if ($env{'request.role.domain'}) {
5918: $domain=$env{'request.role.domain'};
1.60 matthew 5919: }
5920: }
1.63 www 5921: return $domain;
5922: }
5923: ###############################################
1.517 raeburn 5924:
1.518 albertel 5925: sub devalidate_domconfig_cache {
5926: my ($udom)=@_;
5927: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5928: }
5929:
5930: # ---------------------- Get domain configuration for a domain
5931: sub get_domainconf {
5932: my ($udom) = @_;
5933: my $cachetime=1800;
5934: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5935: if (defined($cached)) { return %{$result}; }
5936:
5937: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5938: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5939: my (%designhash,%legacy);
1.518 albertel 5940: if (keys(%domconfig) > 0) {
5941: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5942: if (keys(%{$domconfig{'login'}})) {
5943: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5944: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5945: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5946: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5947: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5948: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5949: if ($key eq 'loginvia') {
5950: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5951: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5952: $designhash{$udom.'.login.loginvia'} = $server;
5953: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5954:
5955: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5956: } else {
5957: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5958: }
1.948 raeburn 5959: }
1.1208 raeburn 5960: } elsif ($key eq 'headtag') {
5961: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5962: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5963: }
1.946 raeburn 5964: }
1.1208 raeburn 5965: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5966: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5967: }
1.946 raeburn 5968: }
5969: }
5970: }
1.1366 raeburn 5971: } elsif ($key eq 'saml') {
5972: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5973: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5974: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5975: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
5976: foreach my $item ('text','img','alt','url','title','notsso') {
5977: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5978: }
5979: }
5980: }
5981: }
1.946 raeburn 5982: } else {
5983: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5984: $designhash{$udom.'.login.'.$key.'_'.$img} =
5985: $domconfig{'login'}{$key}{$img};
5986: }
1.699 raeburn 5987: }
5988: } else {
5989: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5990: }
1.632 raeburn 5991: }
5992: } else {
5993: $legacy{'login'} = 1;
1.518 albertel 5994: }
1.632 raeburn 5995: } else {
5996: $legacy{'login'} = 1;
1.518 albertel 5997: }
5998: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5999: if (keys(%{$domconfig{'rolecolors'}})) {
6000: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6001: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6002: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6003: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6004: }
1.518 albertel 6005: }
6006: }
1.632 raeburn 6007: } else {
6008: $legacy{'rolecolors'} = 1;
1.518 albertel 6009: }
1.632 raeburn 6010: } else {
6011: $legacy{'rolecolors'} = 1;
1.518 albertel 6012: }
1.948 raeburn 6013: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6014: if ($domconfig{'autoenroll'}{'co-owners'}) {
6015: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6016: }
6017: }
1.632 raeburn 6018: if (keys(%legacy) > 0) {
6019: my %legacyhash = &get_legacy_domconf($udom);
6020: foreach my $item (keys(%legacyhash)) {
6021: if ($item =~ /^\Q$udom\E\.login/) {
6022: if ($legacy{'login'}) {
6023: $designhash{$item} = $legacyhash{$item};
6024: }
6025: } else {
6026: if ($legacy{'rolecolors'}) {
6027: $designhash{$item} = $legacyhash{$item};
6028: }
1.518 albertel 6029: }
6030: }
6031: }
1.632 raeburn 6032: } else {
6033: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6034: }
6035: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6036: $cachetime);
6037: return %designhash;
6038: }
6039:
1.632 raeburn 6040: sub get_legacy_domconf {
6041: my ($udom) = @_;
6042: my %legacyhash;
6043: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6044: my $designfile = $designdir.'/'.$udom.'.tab';
6045: if (-e $designfile) {
1.1317 raeburn 6046: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6047: while (my $line = <$fh>) {
6048: next if ($line =~ /^\#/);
6049: chomp($line);
6050: my ($key,$val)=(split(/\=/,$line));
6051: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6052: }
6053: close($fh);
6054: }
6055: }
1.1026 raeburn 6056: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6057: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6058: }
6059: return %legacyhash;
6060: }
6061:
1.63 www 6062: =pod
6063:
1.112 bowersj2 6064: =item * &domainlogo()
1.63 www 6065:
6066: Inputs: $domain (usually will be undef)
6067:
6068: Returns: A link to a domain logo, if the domain logo exists.
6069: If the domain logo does not exist, a description of the domain.
6070:
6071: =cut
1.112 bowersj2 6072:
1.63 www 6073: ###############################################
6074: sub domainlogo {
1.517 raeburn 6075: my $domain = &determinedomain(shift);
1.518 albertel 6076: my %designhash = &get_domainconf($domain);
1.517 raeburn 6077: # See if there is a logo
6078: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6079: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6080: if ($imgsrc =~ m{^/(adm|res)/}) {
6081: if ($imgsrc =~ m{^/res/}) {
6082: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6083: &Apache::lonnet::repcopy($local_name);
6084: }
6085: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6086: }
6087: my $alttext = $domain;
6088: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6089: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6090: }
6091: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6092: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6093: return &Apache::lonnet::domain($domain,'description');
1.59 www 6094: } else {
1.60 matthew 6095: return '';
1.59 www 6096: }
6097: }
1.63 www 6098: ##############################################
6099:
6100: =pod
6101:
1.112 bowersj2 6102: =item * &designparm()
1.63 www 6103:
6104: Inputs: $which parameter; $domain (usually will be undef)
6105:
6106: Returns: value of designparamter $which
6107:
6108: =cut
1.112 bowersj2 6109:
1.397 albertel 6110:
1.400 albertel 6111: ##############################################
1.397 albertel 6112: sub designparm {
6113: my ($which,$domain)=@_;
6114: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6115: return $env{'environment.color.'.$which};
1.96 www 6116: }
1.63 www 6117: $domain=&determinedomain($domain);
1.1016 raeburn 6118: my %domdesign;
6119: unless ($domain eq 'public') {
6120: %domdesign = &get_domainconf($domain);
6121: }
1.520 raeburn 6122: my $output;
1.517 raeburn 6123: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6124: $output = $domdesign{$domain.'.'.$which};
1.63 www 6125: } else {
1.520 raeburn 6126: $output = $defaultdesign{$which};
6127: }
6128: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6129: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6130: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6131: if ($output =~ m{^/res/}) {
6132: my $local_name = &Apache::lonnet::filelocation('',$output);
6133: &Apache::lonnet::repcopy($local_name);
6134: }
1.520 raeburn 6135: $output = &lonhttpdurl($output);
6136: }
1.63 www 6137: }
1.520 raeburn 6138: return $output;
1.63 www 6139: }
1.59 www 6140:
1.822 bisitz 6141: ##############################################
6142: =pod
6143:
1.832 bisitz 6144: =item * &authorspace()
6145:
1.1028 raeburn 6146: Inputs: $url (usually will be undef).
1.832 bisitz 6147:
1.1132 raeburn 6148: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6149: directory being viewed (or for which action is being taken).
6150: If $url is provided, and begins /priv/<domain>/<uname>
6151: the path will be that portion of the $context argument.
6152: Otherwise the path will be for the author space of the current
6153: user when the current role is author, or for that of the
6154: co-author/assistant co-author space when the current role
6155: is co-author or assistant co-author.
1.832 bisitz 6156:
6157: =cut
6158:
6159: sub authorspace {
1.1028 raeburn 6160: my ($url) = @_;
6161: if ($url ne '') {
6162: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6163: return $1;
6164: }
6165: }
1.832 bisitz 6166: my $caname = '';
1.1024 www 6167: my $cadom = '';
1.1028 raeburn 6168: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6169: ($cadom,$caname) =
1.832 bisitz 6170: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6171: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6172: $caname = $env{'user.name'};
1.1024 www 6173: $cadom = $env{'user.domain'};
1.832 bisitz 6174: }
1.1028 raeburn 6175: if (($caname ne '') && ($cadom ne '')) {
6176: return "/priv/$cadom/$caname/";
6177: }
6178: return;
1.832 bisitz 6179: }
6180:
6181: ##############################################
6182: =pod
6183:
1.822 bisitz 6184: =item * &head_subbox()
6185:
6186: Inputs: $content (contains HTML code with page functions, etc.)
6187:
6188: Returns: HTML div with $content
6189: To be included in page header
6190:
6191: =cut
6192:
6193: sub head_subbox {
6194: my ($content)=@_;
6195: my $output =
1.993 raeburn 6196: '<div class="LC_head_subbox">'
1.822 bisitz 6197: .$content
6198: .'</div>'
6199: }
6200:
6201: ##############################################
6202: =pod
6203:
6204: =item * &CSTR_pageheader()
6205:
1.1026 raeburn 6206: Input: (optional) filename from which breadcrumb trail is built.
6207: In most cases no input as needed, as $env{'request.filename'}
6208: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 6209:
6210: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6211: To be included on Authoring Space pages
1.822 bisitz 6212:
6213: =cut
6214:
6215: sub CSTR_pageheader {
1.1026 raeburn 6216: my ($trailfile) = @_;
6217: if ($trailfile eq '') {
6218: $trailfile = $env{'request.filename'};
6219: }
6220:
6221: # this is for resources; directories have customtitle, and crumbs
6222: # and select recent are created in lonpubdir.pm
6223:
6224: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6225: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6226: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6227: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6228: $formaction =~ s{/+}{/}g;
1.822 bisitz 6229:
6230: my $parentpath = '';
6231: my $lastitem = '';
6232: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6233: $parentpath = $1;
6234: $lastitem = $2;
6235: } else {
6236: $lastitem = $thisdisfn;
6237: }
1.921 bisitz 6238:
1.1246 raeburn 6239: my ($crsauthor,$title);
6240: if (($env{'request.course.id'}) &&
6241: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6242: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6243: $crsauthor = 1;
6244: $title = &mt('Course Authoring Space');
6245: } else {
6246: $title = &mt('Authoring Space');
6247: }
6248:
1.1314 raeburn 6249: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 6250: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6251: $target = '';
6252: $crumbtarget = '';
1.1313 raeburn 6253: }
6254:
1.921 bisitz 6255: my $output =
1.822 bisitz 6256: '<div>'
6257: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6258: .'<b>'.$title.'</b> '
1.1314 raeburn 6259: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6260: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6261:
6262: if ($lastitem) {
6263: $output .=
6264: '<span class="LC_filename">'
6265: .$lastitem
6266: .'</span>';
6267: }
1.1245 raeburn 6268:
1.1246 raeburn 6269: if ($crsauthor) {
6270: $output .= '</form>'.&Apache::lonmenu::constspaceform();
6271: } else {
6272: $output .=
6273: '<br />'
1.1314 raeburn 6274: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6275: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6276: .'</form>'
6277: .&Apache::lonmenu::constspaceform();
6278: }
6279: $output .= '</div>';
1.921 bisitz 6280:
6281: return $output;
1.822 bisitz 6282: }
6283:
1.60 matthew 6284: ###############################################
6285: ###############################################
6286:
6287: =pod
6288:
1.112 bowersj2 6289: =back
6290:
1.549 albertel 6291: =head1 HTML Helpers
1.112 bowersj2 6292:
6293: =over 4
6294:
6295: =item * &bodytag()
1.60 matthew 6296:
6297: Returns a uniform header for LON-CAPA web pages.
6298:
6299: Inputs:
6300:
1.112 bowersj2 6301: =over 4
6302:
6303: =item * $title, A title to be displayed on the page.
6304:
6305: =item * $function, the current role (can be undef).
6306:
6307: =item * $addentries, extra parameters for the <body> tag.
6308:
6309: =item * $bodyonly, if defined, only return the <body> tag.
6310:
6311: =item * $domain, if defined, force a given domain.
6312:
6313: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6314: text interface only)
1.60 matthew 6315:
1.814 bisitz 6316: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6317: navigational links
1.317 albertel 6318:
1.338 albertel 6319: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6320:
1.460 albertel 6321: =item * $args, optional argument valid values are
6322: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6323: use_absolute -> for external resource or syllabus, this will
6324: contain https://<hostname> if server uses
6325: https (as per hosts.tab), but request is for http
6326: hostname -> hostname, from $r->hostname().
1.460 albertel 6327:
1.1096 raeburn 6328: =item * $advtoolsref, optional argument, ref to an array containing
6329: inlineremote items to be added in "Functions" menu below
6330: breadcrumbs.
6331:
1.1316 raeburn 6332: =item * $ltiscope, optional argument, will be one of: resource, map or
6333: course, if LON-CAPA is in LTI Provider context. Value is
6334: the scope of use, i.e., launch was for access to a single, a map
6335: or the entire course.
6336:
6337: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6338: context, this will contain the URL for the landing item in
6339: the course, after launch from an LTI Consumer
6340:
1.1318 raeburn 6341: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6342: context, this will contain a reference to hash of items
6343: to be included in the page header and/or inline menu.
6344:
1.112 bowersj2 6345: =back
6346:
1.60 matthew 6347: Returns: A uniform header for LON-CAPA web pages.
6348: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6349: If $bodyonly is undef or zero, an html string containing a <body> tag and
6350: other decorations will be returned.
6351:
6352: =cut
6353:
1.54 www 6354: sub bodytag {
1.831 bisitz 6355: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6356: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
6357: $ltimenu,$menucoll,$menuref)=@_;
1.339 albertel 6358:
1.954 raeburn 6359: my $public;
6360: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6361: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6362: $public = 1;
6363: }
1.460 albertel 6364: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6365: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6366: my $hostname = $args->{'hostname'};
1.339 albertel 6367:
1.183 matthew 6368: $function = &get_users_function() if (!$function);
1.339 albertel 6369: my $img = &designparm($function.'.img',$domain);
6370: my $font = &designparm($function.'.font',$domain);
6371: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6372:
1.803 bisitz 6373: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6374: 'bgcolor' => $pgbg,
1.339 albertel 6375: 'text' => $font,
6376: 'alink' => &designparm($function.'.alink',$domain),
6377: 'vlink' => &designparm($function.'.vlink',$domain),
6378: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6379: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6380:
1.63 www 6381: # role and realm
1.1178 raeburn 6382: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6383: if ($realm) {
6384: $realm = '/'.$realm;
6385: }
1.1357 raeburn 6386: if ($role eq 'ca') {
1.479 albertel 6387: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6388: $realm = &plainname($rname,$rdom);
1.378 raeburn 6389: }
1.55 www 6390: # realm
1.1357 raeburn 6391: my ($cid,$sec);
1.258 albertel 6392: if ($env{'request.course.id'}) {
1.1357 raeburn 6393: $cid = $env{'request.course.id'};
6394: if ($env{'request.course.sec'}) {
6395: $sec = $env{'request.course.sec'};
6396: }
6397: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6398: if (&Apache::lonnet::is_course($1,$2)) {
6399: $cid = $1.'_'.$2;
6400: $sec = $3;
6401: }
6402: }
6403: if ($cid) {
1.378 raeburn 6404: if ($env{'request.role'} !~ /^cr/) {
6405: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6406: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6407: if ($env{'request.role.desc'}) {
6408: $role = $env{'request.role.desc'};
6409: } else {
6410: $role = &mt('Helpdesk[_1]',' '.$2);
6411: }
1.1257 raeburn 6412: } else {
6413: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6414: }
1.1357 raeburn 6415: if ($sec) {
6416: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6417: }
1.1357 raeburn 6418: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6419: } else {
6420: $role = &Apache::lonnet::plaintext($role);
1.54 www 6421: }
1.433 albertel 6422:
1.359 albertel 6423: if (!$realm) { $realm=' '; }
1.330 albertel 6424:
1.438 albertel 6425: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6426:
1.101 www 6427: # construct main body tag
1.359 albertel 6428: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6429: &Apache::lontexconvert::init_math_support();
1.252 albertel 6430:
1.1131 raeburn 6431: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6432:
1.1130 raeburn 6433: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6434: return $bodytag;
1.1130 raeburn 6435: }
1.359 albertel 6436:
1.954 raeburn 6437: if ($public) {
1.433 albertel 6438: undef($role);
6439: }
1.1318 raeburn 6440:
1.1359 raeburn 6441: my $showcrstitle = 1;
1.1357 raeburn 6442: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6443: if (ref($ltimenu) eq 'HASH') {
6444: unless ($ltimenu->{'role'}) {
6445: undef($role);
6446: }
6447: unless ($ltimenu->{'coursetitle'}) {
6448: $realm=' ';
1.1359 raeburn 6449: $showcrstitle = 0;
6450: }
6451: }
6452: } elsif (($cid) && ($menucoll)) {
6453: if (ref($menuref) eq 'HASH') {
6454: unless ($menuref->{'role'}) {
6455: undef($role);
6456: }
6457: unless ($menuref->{'crs'}) {
6458: $realm=' ';
6459: $showcrstitle = 0;
1.1318 raeburn 6460: }
6461: }
6462: }
6463:
1.762 bisitz 6464: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6465: #
6466: # Extra info if you are the DC
6467: my $dc_info = '';
1.1359 raeburn 6468: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6469: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6470: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6471: $dc_info =~ s/\s+$//;
1.359 albertel 6472: }
6473:
1.1237 raeburn 6474: my $crstype;
1.1357 raeburn 6475: if ($cid) {
6476: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6477: } elsif ($args->{'crstype'}) {
6478: $crstype = $args->{'crstype'};
6479: }
6480: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6481: undef($role);
6482: } else {
1.1242 raeburn 6483: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6484: }
1.853 droeschl 6485:
1.903 droeschl 6486: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6487:
6488: # if ($env{'request.state'} eq 'construct') {
6489: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6490: # }
6491:
1.1130 raeburn 6492: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6493: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6494:
1.1318 raeburn 6495: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6496: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
6497: $args->{'links_disabled'});
1.359 albertel 6498:
1.1318 raeburn 6499: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6500: if ($dc_info) {
6501: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6502: }
6503: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6504: <em>$realm</em> $dc_info</div>|;
6505: return $bodytag;
6506: }
1.894 droeschl 6507:
1.1318 raeburn 6508: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6509: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6510: }
1.916 droeschl 6511:
1.1318 raeburn 6512: $bodytag .= $right;
1.852 droeschl 6513:
1.1318 raeburn 6514: if ($dc_info) {
6515: $dc_info = &dc_courseid_toggle($dc_info);
6516: }
6517: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6518: }
1.916 droeschl 6519:
1.1169 raeburn 6520: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6521: if ($args->{'no_secondary_menu'}) {
6522: return $bodytag;
6523: }
1.1169 raeburn 6524: #don't show menus for public users
1.954 raeburn 6525: if (!$public){
1.1318 raeburn 6526: unless ($args->{'no_inline_menu'}) {
6527: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6528: $args->{'no_primary_menu'},
1.1369 raeburn 6529: $menucoll,$menuref,
6530: $args->{'links_disabled'});
1.1318 raeburn 6531: }
1.903 droeschl 6532: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6533: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6534: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6535: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6536: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6537: } elsif ($forcereg) {
6538: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6539: $args->{'group'},
1.1274 raeburn 6540: $args->{'hide_buttons'},
1.1316 raeburn 6541: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6542: } else {
6543: $bodytag .=
6544: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6545: $forcereg,$args->{'group'},
6546: $args->{'bread_crumbs'},
1.1274 raeburn 6547: $advtoolsref,'',$hostname);
1.920 raeburn 6548: }
1.903 droeschl 6549: }else{
6550: # this is to seperate menu from content when there's no secondary
6551: # menu. Especially needed for public accessible ressources.
6552: $bodytag .= '<hr style="clear:both" />';
6553: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6554: }
1.903 droeschl 6555:
1.235 raeburn 6556: return $bodytag;
1.182 matthew 6557: }
6558:
1.917 raeburn 6559: sub dc_courseid_toggle {
6560: my ($dc_info) = @_;
1.980 raeburn 6561: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6562: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6563: &mt('(More ...)').'</a></span>'.
6564: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6565: }
6566:
1.330 albertel 6567: sub make_attr_string {
6568: my ($register,$attr_ref) = @_;
6569:
6570: if ($attr_ref && !ref($attr_ref)) {
6571: die("addentries Must be a hash ref ".
6572: join(':',caller(1))." ".
6573: join(':',caller(0))." ");
6574: }
6575:
6576: if ($register) {
1.339 albertel 6577: my ($on_load,$on_unload);
6578: foreach my $key (keys(%{$attr_ref})) {
6579: if (lc($key) eq 'onload') {
6580: $on_load.=$attr_ref->{$key}.';';
6581: delete($attr_ref->{$key});
6582:
6583: } elsif (lc($key) eq 'onunload') {
6584: $on_unload.=$attr_ref->{$key}.';';
6585: delete($attr_ref->{$key});
6586: }
6587: }
1.953 droeschl 6588: $attr_ref->{'onload'} = $on_load;
6589: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6590: }
1.339 albertel 6591:
1.330 albertel 6592: my $attr_string;
1.1159 raeburn 6593: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6594: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6595: }
6596: return $attr_string;
6597: }
6598:
6599:
1.182 matthew 6600: ###############################################
1.251 albertel 6601: ###############################################
6602:
6603: =pod
6604:
6605: =item * &endbodytag()
6606:
6607: Returns a uniform footer for LON-CAPA web pages.
6608:
1.635 raeburn 6609: Inputs: 1 - optional reference to an args hash
6610: If in the hash, key for noredirectlink has a value which evaluates to true,
6611: a 'Continue' link is not displayed if the page contains an
6612: internal redirect in the <head></head> section,
6613: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6614:
6615: =cut
6616:
6617: sub endbodytag {
1.635 raeburn 6618: my ($args) = @_;
1.1080 raeburn 6619: my $endbodytag;
6620: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6621: $endbodytag='</body>';
6622: }
1.315 albertel 6623: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6624: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6625: $endbodytag=
6626: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6627: &mt('Continue').'</a>'.
6628: $endbodytag;
6629: }
1.315 albertel 6630: }
1.251 albertel 6631: return $endbodytag;
6632: }
6633:
1.352 albertel 6634: =pod
6635:
6636: =item * &standard_css()
6637:
6638: Returns a style sheet
6639:
6640: Inputs: (all optional)
6641: domain -> force to color decorate a page for a specific
6642: domain
6643: function -> force usage of a specific rolish color scheme
6644: bgcolor -> override the default page bgcolor
6645:
6646: =cut
6647:
1.343 albertel 6648: sub standard_css {
1.345 albertel 6649: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6650: $function = &get_users_function() if (!$function);
6651: my $img = &designparm($function.'.img', $domain);
6652: my $tabbg = &designparm($function.'.tabbg', $domain);
6653: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6654: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6655: #second colour for later usage
1.345 albertel 6656: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6657: my $pgbg_or_bgcolor =
6658: $bgcolor ||
1.352 albertel 6659: &designparm($function.'.pgbg', $domain);
1.382 albertel 6660: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6661: my $alink = &designparm($function.'.alink', $domain);
6662: my $vlink = &designparm($function.'.vlink', $domain);
6663: my $link = &designparm($function.'.link', $domain);
6664:
1.602 albertel 6665: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6666: my $mono = 'monospace';
1.850 bisitz 6667: my $data_table_head = $sidebg;
6668: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6669: my $data_table_dark = '#E0E0E0';
1.470 banghart 6670: my $data_table_darker = '#CCCCCC';
1.349 albertel 6671: my $data_table_highlight = '#FFFF00';
1.352 albertel 6672: my $mail_new = '#FFBB77';
6673: my $mail_new_hover = '#DD9955';
6674: my $mail_read = '#BBBB77';
6675: my $mail_read_hover = '#999944';
6676: my $mail_replied = '#AAAA88';
6677: my $mail_replied_hover = '#888855';
6678: my $mail_other = '#99BBBB';
6679: my $mail_other_hover = '#669999';
1.391 albertel 6680: my $table_header = '#DDDDDD';
1.489 raeburn 6681: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6682: my $lg_border_color = '#C8C8C8';
1.952 onken 6683: my $button_hover = '#BF2317';
1.392 albertel 6684:
1.608 albertel 6685: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6686: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6687: : '0 3px 0 4px';
1.448 albertel 6688:
1.523 albertel 6689:
1.343 albertel 6690: return <<END;
1.947 droeschl 6691:
6692: /* needed for iframe to allow 100% height in FF */
6693: body, html {
6694: margin: 0;
6695: padding: 0 0.5%;
6696: height: 99%; /* to avoid scrollbars */
6697: }
6698:
1.795 www 6699: body {
1.911 bisitz 6700: font-family: $sans;
6701: line-height:130%;
6702: font-size:0.83em;
6703: color:$font;
1.795 www 6704: }
6705:
1.959 onken 6706: a:focus,
6707: a:focus img {
1.795 www 6708: color: red;
6709: }
1.698 harmsja 6710:
1.911 bisitz 6711: form, .inline {
6712: display: inline;
1.795 www 6713: }
1.721 harmsja 6714:
1.795 www 6715: .LC_right {
1.911 bisitz 6716: text-align:right;
1.795 www 6717: }
6718:
6719: .LC_middle {
1.911 bisitz 6720: vertical-align:middle;
1.795 www 6721: }
1.721 harmsja 6722:
1.1130 raeburn 6723: .LC_floatleft {
6724: float: left;
6725: }
6726:
6727: .LC_floatright {
6728: float: right;
6729: }
6730:
1.911 bisitz 6731: .LC_400Box {
6732: width:400px;
6733: }
1.721 harmsja 6734:
1.947 droeschl 6735: .LC_iframecontainer {
6736: width: 98%;
6737: margin: 0;
6738: position: fixed;
6739: top: 8.5em;
6740: bottom: 0;
6741: }
6742:
6743: .LC_iframecontainer iframe{
6744: border: none;
6745: width: 100%;
6746: height: 100%;
6747: }
6748:
1.778 bisitz 6749: .LC_filename {
6750: font-family: $mono;
6751: white-space:pre;
1.921 bisitz 6752: font-size: 120%;
1.778 bisitz 6753: }
6754:
6755: .LC_fileicon {
6756: border: none;
6757: height: 1.3em;
6758: vertical-align: text-bottom;
6759: margin-right: 0.3em;
6760: text-decoration:none;
6761: }
6762:
1.1008 www 6763: .LC_setting {
6764: text-decoration:underline;
6765: }
6766:
1.350 albertel 6767: .LC_error {
6768: color: red;
6769: }
1.795 www 6770:
1.1097 bisitz 6771: .LC_warning {
6772: color: darkorange;
6773: }
6774:
1.457 albertel 6775: .LC_diff_removed {
1.733 bisitz 6776: color: red;
1.394 albertel 6777: }
1.532 albertel 6778:
6779: .LC_info,
1.457 albertel 6780: .LC_success,
6781: .LC_diff_added {
1.350 albertel 6782: color: green;
6783: }
1.795 www 6784:
1.802 bisitz 6785: div.LC_confirm_box {
6786: background-color: #FAFAFA;
6787: border: 1px solid $lg_border_color;
6788: margin-right: 0;
6789: padding: 5px;
6790: }
6791:
6792: div.LC_confirm_box .LC_error img,
6793: div.LC_confirm_box .LC_success img {
6794: vertical-align: middle;
6795: }
6796:
1.1242 raeburn 6797: .LC_maxwidth {
6798: max-width: 100%;
6799: height: auto;
6800: }
6801:
1.1243 raeburn 6802: .LC_textsize_mobile {
6803: \@media only screen and (max-device-width: 480px) {
6804: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6805: }
6806: }
6807:
1.440 albertel 6808: .LC_icon {
1.771 droeschl 6809: border: none;
1.790 droeschl 6810: vertical-align: middle;
1.771 droeschl 6811: }
6812:
1.543 albertel 6813: .LC_docs_spacer {
6814: width: 25px;
6815: height: 1px;
1.771 droeschl 6816: border: none;
1.543 albertel 6817: }
1.346 albertel 6818:
1.532 albertel 6819: .LC_internal_info {
1.735 bisitz 6820: color: #999999;
1.532 albertel 6821: }
6822:
1.794 www 6823: .LC_discussion {
1.1050 www 6824: background: $data_table_dark;
1.911 bisitz 6825: border: 1px solid black;
6826: margin: 2px;
1.794 www 6827: }
6828:
6829: .LC_disc_action_left {
1.1050 www 6830: background: $sidebg;
1.911 bisitz 6831: text-align: left;
1.1050 www 6832: padding: 4px;
6833: margin: 2px;
1.794 www 6834: }
6835:
6836: .LC_disc_action_right {
1.1050 www 6837: background: $sidebg;
1.911 bisitz 6838: text-align: right;
1.1050 www 6839: padding: 4px;
6840: margin: 2px;
1.794 www 6841: }
6842:
6843: .LC_disc_new_item {
1.911 bisitz 6844: background: white;
6845: border: 2px solid red;
1.1050 www 6846: margin: 4px;
6847: padding: 4px;
1.794 www 6848: }
6849:
6850: .LC_disc_old_item {
1.911 bisitz 6851: background: white;
1.1050 www 6852: margin: 4px;
6853: padding: 4px;
1.794 www 6854: }
6855:
1.458 albertel 6856: table.LC_pastsubmission {
6857: border: 1px solid black;
6858: margin: 2px;
6859: }
6860:
1.924 bisitz 6861: table#LC_menubuttons {
1.345 albertel 6862: width: 100%;
6863: background: $pgbg;
1.392 albertel 6864: border: 2px;
1.402 albertel 6865: border-collapse: separate;
1.803 bisitz 6866: padding: 0;
1.345 albertel 6867: }
1.392 albertel 6868:
1.801 tempelho 6869: table#LC_title_bar a {
6870: color: $fontmenu;
6871: }
1.836 bisitz 6872:
1.807 droeschl 6873: table#LC_title_bar {
1.819 tempelho 6874: clear: both;
1.836 bisitz 6875: display: none;
1.807 droeschl 6876: }
6877:
1.795 www 6878: table#LC_title_bar,
1.933 droeschl 6879: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6880: table#LC_title_bar.LC_with_remote {
1.359 albertel 6881: width: 100%;
1.392 albertel 6882: border-color: $pgbg;
6883: border-style: solid;
6884: border-width: $border;
1.379 albertel 6885: background: $pgbg;
1.801 tempelho 6886: color: $fontmenu;
1.392 albertel 6887: border-collapse: collapse;
1.803 bisitz 6888: padding: 0;
1.819 tempelho 6889: margin: 0;
1.359 albertel 6890: }
1.795 www 6891:
1.933 droeschl 6892: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6893: margin: 0;
6894: padding: 0;
1.933 droeschl 6895: position: relative;
6896: list-style: none;
1.913 droeschl 6897: }
1.933 droeschl 6898: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6899: display: inline;
6900: }
1.933 droeschl 6901:
6902: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6903: padding: 0;
1.933 droeschl 6904: margin: 0;
6905: float: left;
1.913 droeschl 6906: }
1.933 droeschl 6907: .LC_breadcrumb_tools_tools {
6908: padding: 0;
6909: margin: 0;
1.913 droeschl 6910: float: right;
6911: }
6912:
1.1240 raeburn 6913: .LC_placement_prog {
6914: padding-right: 20px;
6915: font-weight: bold;
6916: font-size: 90%;
6917: }
6918:
1.359 albertel 6919: table#LC_title_bar td {
6920: background: $tabbg;
6921: }
1.795 www 6922:
1.911 bisitz 6923: table#LC_menubuttons img {
1.803 bisitz 6924: border: none;
1.346 albertel 6925: }
1.795 www 6926:
1.842 droeschl 6927: .LC_breadcrumbs_component {
1.911 bisitz 6928: float: right;
6929: margin: 0 1em;
1.357 albertel 6930: }
1.842 droeschl 6931: .LC_breadcrumbs_component img {
1.911 bisitz 6932: vertical-align: middle;
1.777 tempelho 6933: }
1.795 www 6934:
1.1243 raeburn 6935: .LC_breadcrumbs_hoverable {
6936: background: $sidebg;
6937: }
6938:
1.383 albertel 6939: td.LC_table_cell_checkbox {
6940: text-align: center;
6941: }
1.795 www 6942:
6943: .LC_fontsize_small {
1.911 bisitz 6944: font-size: 70%;
1.705 tempelho 6945: }
6946:
1.844 bisitz 6947: #LC_breadcrumbs {
1.911 bisitz 6948: clear:both;
6949: background: $sidebg;
6950: border-bottom: 1px solid $lg_border_color;
6951: line-height: 2.5em;
1.933 droeschl 6952: overflow: hidden;
1.911 bisitz 6953: margin: 0;
6954: padding: 0;
1.995 raeburn 6955: text-align: left;
1.819 tempelho 6956: }
1.862 bisitz 6957:
1.1098 bisitz 6958: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6959: clear:both;
6960: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6961: border: 1px solid $sidebg;
1.1098 bisitz 6962: margin: 0 0 10px 0;
1.966 bisitz 6963: padding: 3px;
1.995 raeburn 6964: text-align: left;
1.822 bisitz 6965: }
6966:
1.795 www 6967: .LC_fontsize_medium {
1.911 bisitz 6968: font-size: 85%;
1.705 tempelho 6969: }
6970:
1.795 www 6971: .LC_fontsize_large {
1.911 bisitz 6972: font-size: 120%;
1.705 tempelho 6973: }
6974:
1.346 albertel 6975: .LC_menubuttons_inline_text {
6976: color: $font;
1.698 harmsja 6977: font-size: 90%;
1.701 harmsja 6978: padding-left:3px;
1.346 albertel 6979: }
6980:
1.934 droeschl 6981: .LC_menubuttons_inline_text img{
6982: vertical-align: middle;
6983: }
6984:
1.1051 www 6985: li.LC_menubuttons_inline_text img {
1.951 onken 6986: cursor:pointer;
1.1002 droeschl 6987: text-decoration: none;
1.951 onken 6988: }
6989:
1.526 www 6990: .LC_menubuttons_link {
6991: text-decoration: none;
6992: }
1.795 www 6993:
1.522 albertel 6994: .LC_menubuttons_category {
1.521 www 6995: color: $font;
1.526 www 6996: background: $pgbg;
1.521 www 6997: font-size: larger;
6998: font-weight: bold;
6999: }
7000:
1.346 albertel 7001: td.LC_menubuttons_text {
1.911 bisitz 7002: color: $font;
1.346 albertel 7003: }
1.706 harmsja 7004:
1.346 albertel 7005: .LC_current_location {
7006: background: $tabbg;
7007: }
1.795 www 7008:
1.1286 raeburn 7009: td.LC_zero_height {
7010: line-height: 0;
7011: cellpadding: 0;
7012: }
7013:
1.938 bisitz 7014: table.LC_data_table {
1.347 albertel 7015: border: 1px solid #000000;
1.402 albertel 7016: border-collapse: separate;
1.426 albertel 7017: border-spacing: 1px;
1.610 albertel 7018: background: $pgbg;
1.347 albertel 7019: }
1.795 www 7020:
1.422 albertel 7021: .LC_data_table_dense {
7022: font-size: small;
7023: }
1.795 www 7024:
1.507 raeburn 7025: table.LC_nested_outer {
7026: border: 1px solid #000000;
1.589 raeburn 7027: border-collapse: collapse;
1.803 bisitz 7028: border-spacing: 0;
1.507 raeburn 7029: width: 100%;
7030: }
1.795 www 7031:
1.879 raeburn 7032: table.LC_innerpickbox,
1.507 raeburn 7033: table.LC_nested {
1.803 bisitz 7034: border: none;
1.589 raeburn 7035: border-collapse: collapse;
1.803 bisitz 7036: border-spacing: 0;
1.507 raeburn 7037: width: 100%;
7038: }
1.795 www 7039:
1.911 bisitz 7040: table.LC_data_table tr th,
7041: table.LC_calendar tr th,
1.879 raeburn 7042: table.LC_prior_tries tr th,
7043: table.LC_innerpickbox tr th {
1.349 albertel 7044: font-weight: bold;
7045: background-color: $data_table_head;
1.801 tempelho 7046: color:$fontmenu;
1.701 harmsja 7047: font-size:90%;
1.347 albertel 7048: }
1.795 www 7049:
1.879 raeburn 7050: table.LC_innerpickbox tr th,
7051: table.LC_innerpickbox tr td {
7052: vertical-align: top;
7053: }
7054:
1.711 raeburn 7055: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7056: background-color: #CCCCCC;
1.711 raeburn 7057: font-weight: bold;
7058: text-align: left;
7059: }
1.795 www 7060:
1.912 bisitz 7061: table.LC_data_table tr.LC_odd_row > td {
7062: background-color: $data_table_light;
7063: padding: 2px;
7064: vertical-align: top;
7065: }
7066:
1.809 bisitz 7067: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7068: background-color: $data_table_light;
1.912 bisitz 7069: vertical-align: top;
7070: }
7071:
7072: table.LC_data_table tr.LC_even_row > td {
7073: background-color: $data_table_dark;
1.425 albertel 7074: padding: 2px;
1.900 bisitz 7075: vertical-align: top;
1.347 albertel 7076: }
1.795 www 7077:
1.809 bisitz 7078: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7079: background-color: $data_table_dark;
1.900 bisitz 7080: vertical-align: top;
1.347 albertel 7081: }
1.795 www 7082:
1.425 albertel 7083: table.LC_data_table tr.LC_data_table_highlight td {
7084: background-color: $data_table_darker;
7085: }
1.795 www 7086:
1.639 raeburn 7087: table.LC_data_table tr td.LC_leftcol_header {
7088: background-color: $data_table_head;
7089: font-weight: bold;
7090: }
1.795 www 7091:
1.451 albertel 7092: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7093: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7094: font-weight: bold;
7095: font-style: italic;
7096: text-align: center;
7097: padding: 8px;
1.347 albertel 7098: }
1.795 www 7099:
1.1114 raeburn 7100: table.LC_data_table tr.LC_empty_row td,
7101: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7102: background-color: $sidebg;
7103: }
7104:
7105: table.LC_nested tr.LC_empty_row td {
7106: background-color: #FFFFFF;
7107: }
7108:
1.890 droeschl 7109: table.LC_caption {
7110: }
7111:
1.507 raeburn 7112: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7113: padding: 4ex
7114: }
1.795 www 7115:
1.507 raeburn 7116: table.LC_nested_outer tr th {
7117: font-weight: bold;
1.801 tempelho 7118: color:$fontmenu;
1.507 raeburn 7119: background-color: $data_table_head;
1.701 harmsja 7120: font-size: small;
1.507 raeburn 7121: border-bottom: 1px solid #000000;
7122: }
1.795 www 7123:
1.507 raeburn 7124: table.LC_nested_outer tr td.LC_subheader {
7125: background-color: $data_table_head;
7126: font-weight: bold;
7127: font-size: small;
7128: border-bottom: 1px solid #000000;
7129: text-align: right;
1.451 albertel 7130: }
1.795 www 7131:
1.507 raeburn 7132: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7133: background-color: #CCCCCC;
1.451 albertel 7134: font-weight: bold;
7135: font-size: small;
1.507 raeburn 7136: text-align: center;
7137: }
1.795 www 7138:
1.589 raeburn 7139: table.LC_nested tr.LC_info_row td.LC_left_item,
7140: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7141: text-align: left;
1.451 albertel 7142: }
1.795 www 7143:
1.507 raeburn 7144: table.LC_nested td {
1.735 bisitz 7145: background-color: #FFFFFF;
1.451 albertel 7146: font-size: small;
1.507 raeburn 7147: }
1.795 www 7148:
1.507 raeburn 7149: table.LC_nested_outer tr th.LC_right_item,
7150: table.LC_nested tr.LC_info_row td.LC_right_item,
7151: table.LC_nested tr.LC_odd_row td.LC_right_item,
7152: table.LC_nested tr td.LC_right_item {
1.451 albertel 7153: text-align: right;
7154: }
7155:
1.507 raeburn 7156: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7157: background-color: #EEEEEE;
1.451 albertel 7158: }
7159:
1.473 raeburn 7160: table.LC_createuser {
7161: }
7162:
7163: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7164: font-size: small;
1.473 raeburn 7165: }
7166:
7167: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7168: background-color: #CCCCCC;
1.473 raeburn 7169: font-weight: bold;
7170: text-align: center;
7171: }
7172:
1.349 albertel 7173: table.LC_calendar {
7174: border: 1px solid #000000;
7175: border-collapse: collapse;
1.917 raeburn 7176: width: 98%;
1.349 albertel 7177: }
1.795 www 7178:
1.349 albertel 7179: table.LC_calendar_pickdate {
7180: font-size: xx-small;
7181: }
1.795 www 7182:
1.349 albertel 7183: table.LC_calendar tr td {
7184: border: 1px solid #000000;
7185: vertical-align: top;
1.917 raeburn 7186: width: 14%;
1.349 albertel 7187: }
1.795 www 7188:
1.349 albertel 7189: table.LC_calendar tr td.LC_calendar_day_empty {
7190: background-color: $data_table_dark;
7191: }
1.795 www 7192:
1.779 bisitz 7193: table.LC_calendar tr td.LC_calendar_day_current {
7194: background-color: $data_table_highlight;
1.777 tempelho 7195: }
1.795 www 7196:
1.938 bisitz 7197: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7198: background-color: $mail_new;
7199: }
1.795 www 7200:
1.938 bisitz 7201: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7202: background-color: $mail_new_hover;
7203: }
1.795 www 7204:
1.938 bisitz 7205: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7206: background-color: $mail_read;
7207: }
1.795 www 7208:
1.938 bisitz 7209: /*
7210: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7211: background-color: $mail_read_hover;
7212: }
1.938 bisitz 7213: */
1.795 www 7214:
1.938 bisitz 7215: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7216: background-color: $mail_replied;
7217: }
1.795 www 7218:
1.938 bisitz 7219: /*
7220: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7221: background-color: $mail_replied_hover;
7222: }
1.938 bisitz 7223: */
1.795 www 7224:
1.938 bisitz 7225: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7226: background-color: $mail_other;
7227: }
1.795 www 7228:
1.938 bisitz 7229: /*
7230: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7231: background-color: $mail_other_hover;
7232: }
1.938 bisitz 7233: */
1.494 raeburn 7234:
1.777 tempelho 7235: table.LC_data_table tr > td.LC_browser_file,
7236: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7237: background: #AAEE77;
1.389 albertel 7238: }
1.795 www 7239:
1.777 tempelho 7240: table.LC_data_table tr > td.LC_browser_file_locked,
7241: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7242: background: #FFAA99;
1.387 albertel 7243: }
1.795 www 7244:
1.777 tempelho 7245: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7246: background: #888888;
1.779 bisitz 7247: }
1.795 www 7248:
1.777 tempelho 7249: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7250: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7251: background: #F8F866;
1.777 tempelho 7252: }
1.795 www 7253:
1.696 bisitz 7254: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7255: background: #E0E8FF;
1.387 albertel 7256: }
1.696 bisitz 7257:
1.707 bisitz 7258: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7259: /* background: #77FF77; */
1.707 bisitz 7260: }
1.795 www 7261:
1.707 bisitz 7262: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7263: border-right: 8px solid #FFFF77;
1.707 bisitz 7264: }
1.795 www 7265:
1.707 bisitz 7266: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7267: border-right: 8px solid #FFAA77;
1.707 bisitz 7268: }
1.795 www 7269:
1.707 bisitz 7270: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7271: border-right: 8px solid #FF7777;
1.707 bisitz 7272: }
1.795 www 7273:
1.707 bisitz 7274: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7275: border-right: 8px solid #AAFF77;
1.707 bisitz 7276: }
1.795 www 7277:
1.707 bisitz 7278: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7279: border-right: 8px solid #11CC55;
1.707 bisitz 7280: }
7281:
1.388 albertel 7282: span.LC_current_location {
1.701 harmsja 7283: font-size:larger;
1.388 albertel 7284: background: $pgbg;
7285: }
1.387 albertel 7286:
1.1029 www 7287: span.LC_current_nav_location {
7288: font-weight:bold;
7289: background: $sidebg;
7290: }
7291:
1.395 albertel 7292: span.LC_parm_menu_item {
7293: font-size: larger;
7294: }
1.795 www 7295:
1.395 albertel 7296: span.LC_parm_scope_all {
7297: color: red;
7298: }
1.795 www 7299:
1.395 albertel 7300: span.LC_parm_scope_folder {
7301: color: green;
7302: }
1.795 www 7303:
1.395 albertel 7304: span.LC_parm_scope_resource {
7305: color: orange;
7306: }
1.795 www 7307:
1.395 albertel 7308: span.LC_parm_part {
7309: color: blue;
7310: }
1.795 www 7311:
1.911 bisitz 7312: span.LC_parm_folder,
7313: span.LC_parm_symb {
1.395 albertel 7314: font-size: x-small;
7315: font-family: $mono;
7316: color: #AAAAAA;
7317: }
7318:
1.977 bisitz 7319: ul.LC_parm_parmlist li {
7320: display: inline-block;
7321: padding: 0.3em 0.8em;
7322: vertical-align: top;
7323: width: 150px;
7324: border-top:1px solid $lg_border_color;
7325: }
7326:
1.795 www 7327: td.LC_parm_overview_level_menu,
7328: td.LC_parm_overview_map_menu,
7329: td.LC_parm_overview_parm_selectors,
7330: td.LC_parm_overview_restrictions {
1.396 albertel 7331: border: 1px solid black;
7332: border-collapse: collapse;
7333: }
1.795 www 7334:
1.1285 raeburn 7335: span.LC_parm_recursive,
7336: td.LC_parm_recursive {
7337: font-weight: bold;
7338: font-size: smaller;
7339: }
7340:
1.396 albertel 7341: table.LC_parm_overview_restrictions td {
7342: border-width: 1px 4px 1px 4px;
7343: border-style: solid;
7344: border-color: $pgbg;
7345: text-align: center;
7346: }
1.795 www 7347:
1.396 albertel 7348: table.LC_parm_overview_restrictions th {
7349: background: $tabbg;
7350: border-width: 1px 4px 1px 4px;
7351: border-style: solid;
7352: border-color: $pgbg;
7353: }
1.795 www 7354:
1.398 albertel 7355: table#LC_helpmenu {
1.803 bisitz 7356: border: none;
1.398 albertel 7357: height: 55px;
1.803 bisitz 7358: border-spacing: 0;
1.398 albertel 7359: }
7360:
7361: table#LC_helpmenu fieldset legend {
7362: font-size: larger;
7363: }
1.795 www 7364:
1.397 albertel 7365: table#LC_helpmenu_links {
7366: width: 100%;
7367: border: 1px solid black;
7368: background: $pgbg;
1.803 bisitz 7369: padding: 0;
1.397 albertel 7370: border-spacing: 1px;
7371: }
1.795 www 7372:
1.397 albertel 7373: table#LC_helpmenu_links tr td {
7374: padding: 1px;
7375: background: $tabbg;
1.399 albertel 7376: text-align: center;
7377: font-weight: bold;
1.397 albertel 7378: }
1.396 albertel 7379:
1.795 www 7380: table#LC_helpmenu_links a:link,
7381: table#LC_helpmenu_links a:visited,
1.397 albertel 7382: table#LC_helpmenu_links a:active {
7383: text-decoration: none;
7384: color: $font;
7385: }
1.795 www 7386:
1.397 albertel 7387: table#LC_helpmenu_links a:hover {
7388: text-decoration: underline;
7389: color: $vlink;
7390: }
1.396 albertel 7391:
1.417 albertel 7392: .LC_chrt_popup_exists {
7393: border: 1px solid #339933;
7394: margin: -1px;
7395: }
1.795 www 7396:
1.417 albertel 7397: .LC_chrt_popup_up {
7398: border: 1px solid yellow;
7399: margin: -1px;
7400: }
1.795 www 7401:
1.417 albertel 7402: .LC_chrt_popup {
7403: border: 1px solid #8888FF;
7404: background: #CCCCFF;
7405: }
1.795 www 7406:
1.421 albertel 7407: table.LC_pick_box {
7408: border-collapse: separate;
7409: background: white;
7410: border: 1px solid black;
7411: border-spacing: 1px;
7412: }
1.795 www 7413:
1.421 albertel 7414: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7415: background: $sidebg;
1.421 albertel 7416: font-weight: bold;
1.900 bisitz 7417: text-align: left;
1.740 bisitz 7418: vertical-align: top;
1.421 albertel 7419: width: 184px;
7420: padding: 8px;
7421: }
1.795 www 7422:
1.579 raeburn 7423: table.LC_pick_box td.LC_pick_box_value {
7424: text-align: left;
7425: padding: 8px;
7426: }
1.795 www 7427:
1.579 raeburn 7428: table.LC_pick_box td.LC_pick_box_select {
7429: text-align: left;
7430: padding: 8px;
7431: }
1.795 www 7432:
1.424 albertel 7433: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7434: padding: 0;
1.421 albertel 7435: height: 1px;
7436: background: black;
7437: }
1.795 www 7438:
1.421 albertel 7439: table.LC_pick_box td.LC_pick_box_submit {
7440: text-align: right;
7441: }
1.795 www 7442:
1.579 raeburn 7443: table.LC_pick_box td.LC_evenrow_value {
7444: text-align: left;
7445: padding: 8px;
7446: background-color: $data_table_light;
7447: }
1.795 www 7448:
1.579 raeburn 7449: table.LC_pick_box td.LC_oddrow_value {
7450: text-align: left;
7451: padding: 8px;
7452: background-color: $data_table_light;
7453: }
1.795 www 7454:
1.579 raeburn 7455: span.LC_helpform_receipt_cat {
7456: font-weight: bold;
7457: }
1.795 www 7458:
1.424 albertel 7459: table.LC_group_priv_box {
7460: background: white;
7461: border: 1px solid black;
7462: border-spacing: 1px;
7463: }
1.795 www 7464:
1.424 albertel 7465: table.LC_group_priv_box td.LC_pick_box_title {
7466: background: $tabbg;
7467: font-weight: bold;
7468: text-align: right;
7469: width: 184px;
7470: }
1.795 www 7471:
1.424 albertel 7472: table.LC_group_priv_box td.LC_groups_fixed {
7473: background: $data_table_light;
7474: text-align: center;
7475: }
1.795 www 7476:
1.424 albertel 7477: table.LC_group_priv_box td.LC_groups_optional {
7478: background: $data_table_dark;
7479: text-align: center;
7480: }
1.795 www 7481:
1.424 albertel 7482: table.LC_group_priv_box td.LC_groups_functionality {
7483: background: $data_table_darker;
7484: text-align: center;
7485: font-weight: bold;
7486: }
1.795 www 7487:
1.424 albertel 7488: table.LC_group_priv td {
7489: text-align: left;
1.803 bisitz 7490: padding: 0;
1.424 albertel 7491: }
7492:
7493: .LC_navbuttons {
7494: margin: 2ex 0ex 2ex 0ex;
7495: }
1.795 www 7496:
1.423 albertel 7497: .LC_topic_bar {
7498: font-weight: bold;
7499: background: $tabbg;
1.918 wenzelju 7500: margin: 1em 0em 1em 2em;
1.805 bisitz 7501: padding: 3px;
1.918 wenzelju 7502: font-size: 1.2em;
1.423 albertel 7503: }
1.795 www 7504:
1.423 albertel 7505: .LC_topic_bar span {
1.918 wenzelju 7506: left: 0.5em;
7507: position: absolute;
1.423 albertel 7508: vertical-align: middle;
1.918 wenzelju 7509: font-size: 1.2em;
1.423 albertel 7510: }
1.795 www 7511:
1.423 albertel 7512: table.LC_course_group_status {
7513: margin: 20px;
7514: }
1.795 www 7515:
1.423 albertel 7516: table.LC_status_selector td {
7517: vertical-align: top;
7518: text-align: center;
1.424 albertel 7519: padding: 4px;
7520: }
1.795 www 7521:
1.599 albertel 7522: div.LC_feedback_link {
1.616 albertel 7523: clear: both;
1.829 kalberla 7524: background: $sidebg;
1.779 bisitz 7525: width: 100%;
1.829 kalberla 7526: padding-bottom: 10px;
7527: border: 1px $tabbg solid;
1.833 kalberla 7528: height: 22px;
7529: line-height: 22px;
7530: padding-top: 5px;
7531: }
7532:
7533: div.LC_feedback_link img {
7534: height: 22px;
1.867 kalberla 7535: vertical-align:middle;
1.829 kalberla 7536: }
7537:
1.911 bisitz 7538: div.LC_feedback_link a {
1.829 kalberla 7539: text-decoration: none;
1.489 raeburn 7540: }
1.795 www 7541:
1.867 kalberla 7542: div.LC_comblock {
1.911 bisitz 7543: display:inline;
1.867 kalberla 7544: color:$font;
7545: font-size:90%;
7546: }
7547:
7548: div.LC_feedback_link div.LC_comblock {
7549: padding-left:5px;
7550: }
7551:
7552: div.LC_feedback_link div.LC_comblock a {
7553: color:$font;
7554: }
7555:
1.489 raeburn 7556: span.LC_feedback_link {
1.858 bisitz 7557: /* background: $feedback_link_bg; */
1.599 albertel 7558: font-size: larger;
7559: }
1.795 www 7560:
1.599 albertel 7561: span.LC_message_link {
1.858 bisitz 7562: /* background: $feedback_link_bg; */
1.599 albertel 7563: font-size: larger;
7564: position: absolute;
7565: right: 1em;
1.489 raeburn 7566: }
1.421 albertel 7567:
1.515 albertel 7568: table.LC_prior_tries {
1.524 albertel 7569: border: 1px solid #000000;
7570: border-collapse: separate;
7571: border-spacing: 1px;
1.515 albertel 7572: }
1.523 albertel 7573:
1.515 albertel 7574: table.LC_prior_tries td {
1.524 albertel 7575: padding: 2px;
1.515 albertel 7576: }
1.523 albertel 7577:
7578: .LC_answer_correct {
1.795 www 7579: background: lightgreen;
7580: color: darkgreen;
7581: padding: 6px;
1.523 albertel 7582: }
1.795 www 7583:
1.523 albertel 7584: .LC_answer_charged_try {
1.797 www 7585: background: #FFAAAA;
1.795 www 7586: color: darkred;
7587: padding: 6px;
1.523 albertel 7588: }
1.795 www 7589:
1.779 bisitz 7590: .LC_answer_not_charged_try,
1.523 albertel 7591: .LC_answer_no_grade,
7592: .LC_answer_late {
1.795 www 7593: background: lightyellow;
1.523 albertel 7594: color: black;
1.795 www 7595: padding: 6px;
1.523 albertel 7596: }
1.795 www 7597:
1.523 albertel 7598: .LC_answer_previous {
1.795 www 7599: background: lightblue;
7600: color: darkblue;
7601: padding: 6px;
1.523 albertel 7602: }
1.795 www 7603:
1.779 bisitz 7604: .LC_answer_no_message {
1.777 tempelho 7605: background: #FFFFFF;
7606: color: black;
1.795 www 7607: padding: 6px;
1.779 bisitz 7608: }
1.795 www 7609:
1.1334 raeburn 7610: .LC_answer_unknown,
7611: .LC_answer_warning {
1.779 bisitz 7612: background: orange;
7613: color: black;
1.795 www 7614: padding: 6px;
1.777 tempelho 7615: }
1.795 www 7616:
1.529 albertel 7617: span.LC_prior_numerical,
7618: span.LC_prior_string,
7619: span.LC_prior_custom,
7620: span.LC_prior_reaction,
7621: span.LC_prior_math {
1.925 bisitz 7622: font-family: $mono;
1.523 albertel 7623: white-space: pre;
7624: }
7625:
1.525 albertel 7626: span.LC_prior_string {
1.925 bisitz 7627: font-family: $mono;
1.525 albertel 7628: white-space: pre;
7629: }
7630:
1.523 albertel 7631: table.LC_prior_option {
7632: width: 100%;
7633: border-collapse: collapse;
7634: }
1.795 www 7635:
1.911 bisitz 7636: table.LC_prior_rank,
1.795 www 7637: table.LC_prior_match {
1.528 albertel 7638: border-collapse: collapse;
7639: }
1.795 www 7640:
1.528 albertel 7641: table.LC_prior_option tr td,
7642: table.LC_prior_rank tr td,
7643: table.LC_prior_match tr td {
1.524 albertel 7644: border: 1px solid #000000;
1.515 albertel 7645: }
7646:
1.855 bisitz 7647: .LC_nobreak {
1.544 albertel 7648: white-space: nowrap;
1.519 raeburn 7649: }
7650:
1.576 raeburn 7651: span.LC_cusr_emph {
7652: font-style: italic;
7653: }
7654:
1.633 raeburn 7655: span.LC_cusr_subheading {
7656: font-weight: normal;
7657: font-size: 85%;
7658: }
7659:
1.861 bisitz 7660: div.LC_docs_entry_move {
1.859 bisitz 7661: border: 1px solid #BBBBBB;
1.545 albertel 7662: background: #DDDDDD;
1.861 bisitz 7663: width: 22px;
1.859 bisitz 7664: padding: 1px;
7665: margin: 0;
1.545 albertel 7666: }
7667:
1.861 bisitz 7668: table.LC_data_table tr > td.LC_docs_entry_commands,
7669: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7670: font-size: x-small;
7671: }
1.795 www 7672:
1.861 bisitz 7673: .LC_docs_entry_parameter {
7674: white-space: nowrap;
7675: }
7676:
1.544 albertel 7677: .LC_docs_copy {
1.545 albertel 7678: color: #000099;
1.544 albertel 7679: }
1.795 www 7680:
1.544 albertel 7681: .LC_docs_cut {
1.545 albertel 7682: color: #550044;
1.544 albertel 7683: }
1.795 www 7684:
1.544 albertel 7685: .LC_docs_rename {
1.545 albertel 7686: color: #009900;
1.544 albertel 7687: }
1.795 www 7688:
1.544 albertel 7689: .LC_docs_remove {
1.545 albertel 7690: color: #990000;
7691: }
7692:
1.1284 raeburn 7693: .LC_docs_alias {
7694: color: #440055;
7695: }
7696:
1.1286 raeburn 7697: .LC_domprefs_email,
1.1284 raeburn 7698: .LC_docs_alias_name,
1.547 albertel 7699: .LC_docs_reinit_warn,
7700: .LC_docs_ext_edit {
7701: font-size: x-small;
7702: }
7703:
1.545 albertel 7704: table.LC_docs_adddocs td,
7705: table.LC_docs_adddocs th {
7706: border: 1px solid #BBBBBB;
7707: padding: 4px;
7708: background: #DDDDDD;
1.543 albertel 7709: }
7710:
1.584 albertel 7711: table.LC_sty_begin {
7712: background: #BBFFBB;
7713: }
1.795 www 7714:
1.584 albertel 7715: table.LC_sty_end {
7716: background: #FFBBBB;
7717: }
7718:
1.589 raeburn 7719: table.LC_double_column {
1.803 bisitz 7720: border-width: 0;
1.589 raeburn 7721: border-collapse: collapse;
7722: width: 100%;
7723: padding: 2px;
7724: }
7725:
7726: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7727: top: 2px;
1.589 raeburn 7728: left: 2px;
7729: width: 47%;
7730: vertical-align: top;
7731: }
7732:
7733: table.LC_double_column tr td.LC_right_col {
7734: top: 2px;
1.779 bisitz 7735: right: 2px;
1.589 raeburn 7736: width: 47%;
7737: vertical-align: top;
7738: }
7739:
1.591 raeburn 7740: div.LC_left_float {
7741: float: left;
7742: padding-right: 5%;
1.597 albertel 7743: padding-bottom: 4px;
1.591 raeburn 7744: }
7745:
7746: div.LC_clear_float_header {
1.597 albertel 7747: padding-bottom: 2px;
1.591 raeburn 7748: }
7749:
7750: div.LC_clear_float_footer {
1.597 albertel 7751: padding-top: 10px;
1.591 raeburn 7752: clear: both;
7753: }
7754:
1.597 albertel 7755: div.LC_grade_show_user {
1.941 bisitz 7756: /* border-left: 5px solid $sidebg; */
7757: border-top: 5px solid #000000;
7758: margin: 50px 0 0 0;
1.936 bisitz 7759: padding: 15px 0 5px 10px;
1.597 albertel 7760: }
1.795 www 7761:
1.936 bisitz 7762: div.LC_grade_show_user_odd_row {
1.941 bisitz 7763: /* border-left: 5px solid #000000; */
7764: }
7765:
7766: div.LC_grade_show_user div.LC_Box {
7767: margin-right: 50px;
1.597 albertel 7768: }
7769:
7770: div.LC_grade_submissions,
7771: div.LC_grade_message_center,
1.936 bisitz 7772: div.LC_grade_info_links {
1.597 albertel 7773: margin: 5px;
7774: width: 99%;
7775: background: #FFFFFF;
7776: }
1.795 www 7777:
1.597 albertel 7778: div.LC_grade_submissions_header,
1.936 bisitz 7779: div.LC_grade_message_center_header {
1.705 tempelho 7780: font-weight: bold;
7781: font-size: large;
1.597 albertel 7782: }
1.795 www 7783:
1.597 albertel 7784: div.LC_grade_submissions_body,
1.936 bisitz 7785: div.LC_grade_message_center_body {
1.597 albertel 7786: border: 1px solid black;
7787: width: 99%;
7788: background: #FFFFFF;
7789: }
1.795 www 7790:
1.613 albertel 7791: table.LC_scantron_action {
7792: width: 100%;
7793: }
1.795 www 7794:
1.613 albertel 7795: table.LC_scantron_action tr th {
1.698 harmsja 7796: font-weight:bold;
7797: font-style:normal;
1.613 albertel 7798: }
1.795 www 7799:
1.779 bisitz 7800: .LC_edit_problem_header,
1.614 albertel 7801: div.LC_edit_problem_footer {
1.705 tempelho 7802: font-weight: normal;
7803: font-size: medium;
1.602 albertel 7804: margin: 2px;
1.1060 bisitz 7805: background-color: $sidebg;
1.600 albertel 7806: }
1.795 www 7807:
1.600 albertel 7808: div.LC_edit_problem_header,
1.602 albertel 7809: div.LC_edit_problem_header div,
1.614 albertel 7810: div.LC_edit_problem_footer,
7811: div.LC_edit_problem_footer div,
1.602 albertel 7812: div.LC_edit_problem_editxml_header,
7813: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7814: z-index: 100;
1.600 albertel 7815: }
1.795 www 7816:
1.600 albertel 7817: div.LC_edit_problem_header_title {
1.705 tempelho 7818: font-weight: bold;
7819: font-size: larger;
1.602 albertel 7820: background: $tabbg;
7821: padding: 3px;
1.1060 bisitz 7822: margin: 0 0 5px 0;
1.602 albertel 7823: }
1.795 www 7824:
1.602 albertel 7825: table.LC_edit_problem_header_title {
7826: width: 100%;
1.600 albertel 7827: background: $tabbg;
1.602 albertel 7828: }
7829:
1.1205 golterma 7830: div.LC_edit_actionbar {
7831: background-color: $sidebg;
1.1218 droeschl 7832: margin: 0;
7833: padding: 0;
7834: line-height: 200%;
1.602 albertel 7835: }
1.795 www 7836:
1.1218 droeschl 7837: div.LC_edit_actionbar div{
7838: padding: 0;
7839: margin: 0;
7840: display: inline-block;
1.600 albertel 7841: }
1.795 www 7842:
1.1124 bisitz 7843: .LC_edit_opt {
7844: padding-left: 1em;
7845: white-space: nowrap;
7846: }
7847:
1.1152 golterma 7848: .LC_edit_problem_latexhelper{
7849: text-align: right;
7850: }
7851:
7852: #LC_edit_problem_colorful div{
7853: margin-left: 40px;
7854: }
7855:
1.1205 golterma 7856: #LC_edit_problem_codemirror div{
7857: margin-left: 0px;
7858: }
7859:
1.911 bisitz 7860: img.stift {
1.803 bisitz 7861: border-width: 0;
7862: vertical-align: middle;
1.677 riegler 7863: }
1.680 riegler 7864:
1.923 bisitz 7865: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7866: vertical-align: top;
1.777 tempelho 7867: }
1.795 www 7868:
1.716 raeburn 7869: div.LC_createcourse {
1.911 bisitz 7870: margin: 10px 10px 10px 10px;
1.716 raeburn 7871: }
7872:
1.917 raeburn 7873: .LC_dccid {
1.1130 raeburn 7874: float: right;
1.917 raeburn 7875: margin: 0.2em 0 0 0;
7876: padding: 0;
7877: font-size: 90%;
7878: display:none;
7879: }
7880:
1.897 wenzelju 7881: ol.LC_primary_menu a:hover,
1.721 harmsja 7882: ol#LC_MenuBreadcrumbs a:hover,
7883: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7884: ul#LC_secondary_menu a:hover,
1.721 harmsja 7885: .LC_FormSectionClearButton input:hover
1.795 www 7886: ul.LC_TabContent li:hover a {
1.952 onken 7887: color:$button_hover;
1.911 bisitz 7888: text-decoration:none;
1.693 droeschl 7889: }
7890:
1.779 bisitz 7891: h1 {
1.911 bisitz 7892: padding: 0;
7893: line-height:130%;
1.693 droeschl 7894: }
1.698 harmsja 7895:
1.911 bisitz 7896: h2,
7897: h3,
7898: h4,
7899: h5,
7900: h6 {
7901: margin: 5px 0 5px 0;
7902: padding: 0;
7903: line-height:130%;
1.693 droeschl 7904: }
1.795 www 7905:
7906: .LC_hcell {
1.911 bisitz 7907: padding:3px 15px 3px 15px;
7908: margin: 0;
7909: background-color:$tabbg;
7910: color:$fontmenu;
7911: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7912: }
1.795 www 7913:
1.840 bisitz 7914: .LC_Box > .LC_hcell {
1.911 bisitz 7915: margin: 0 -10px 10px -10px;
1.835 bisitz 7916: }
7917:
1.721 harmsja 7918: .LC_noBorder {
1.911 bisitz 7919: border: 0;
1.698 harmsja 7920: }
1.693 droeschl 7921:
1.721 harmsja 7922: .LC_FormSectionClearButton input {
1.911 bisitz 7923: background-color:transparent;
7924: border: none;
7925: cursor:pointer;
7926: text-decoration:underline;
1.693 droeschl 7927: }
1.763 bisitz 7928:
7929: .LC_help_open_topic {
1.911 bisitz 7930: color: #FFFFFF;
7931: background-color: #EEEEFF;
7932: margin: 1px;
7933: padding: 4px;
7934: border: 1px solid #000033;
7935: white-space: nowrap;
7936: /* vertical-align: middle; */
1.759 neumanie 7937: }
1.693 droeschl 7938:
1.911 bisitz 7939: dl,
7940: ul,
7941: div,
7942: fieldset {
7943: margin: 10px 10px 10px 0;
7944: /* overflow: hidden; */
1.693 droeschl 7945: }
1.795 www 7946:
1.1211 raeburn 7947: article.geogebraweb div {
7948: margin: 0;
7949: }
7950:
1.838 bisitz 7951: fieldset > legend {
1.911 bisitz 7952: font-weight: bold;
7953: padding: 0 5px 0 5px;
1.838 bisitz 7954: }
7955:
1.813 bisitz 7956: #LC_nav_bar {
1.911 bisitz 7957: float: left;
1.995 raeburn 7958: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7959: margin: 0 0 2px 0;
1.807 droeschl 7960: }
7961:
1.916 droeschl 7962: #LC_realm {
7963: margin: 0.2em 0 0 0;
7964: padding: 0;
7965: font-weight: bold;
7966: text-align: center;
1.995 raeburn 7967: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7968: }
7969:
1.911 bisitz 7970: #LC_nav_bar em {
7971: font-weight: bold;
7972: font-style: normal;
1.807 droeschl 7973: }
7974:
1.897 wenzelju 7975: ol.LC_primary_menu {
1.934 droeschl 7976: margin: 0;
1.1076 raeburn 7977: padding: 0;
1.807 droeschl 7978: }
7979:
1.852 droeschl 7980: ol#LC_PathBreadcrumbs {
1.911 bisitz 7981: margin: 0;
1.693 droeschl 7982: }
7983:
1.897 wenzelju 7984: ol.LC_primary_menu li {
1.1076 raeburn 7985: color: RGB(80, 80, 80);
7986: vertical-align: middle;
7987: text-align: left;
7988: list-style: none;
1.1205 golterma 7989: position: relative;
1.1076 raeburn 7990: float: left;
1.1205 golterma 7991: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7992: line-height: 1.5em;
1.1076 raeburn 7993: }
7994:
1.1205 golterma 7995: ol.LC_primary_menu li a,
7996: ol.LC_primary_menu li p {
1.1076 raeburn 7997: display: block;
7998: margin: 0;
7999: padding: 0 5px 0 10px;
8000: text-decoration: none;
8001: }
8002:
1.1205 golterma 8003: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8004: display: inline-block;
8005: width: 95%;
8006: text-align: left;
8007: }
8008:
8009: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8010: display: inline-block;
8011: width: 5%;
8012: float: right;
8013: text-align: right;
8014: font-size: 70%;
8015: }
8016:
8017: ol.LC_primary_menu ul {
1.1076 raeburn 8018: display: none;
1.1205 golterma 8019: width: 15em;
1.1076 raeburn 8020: background-color: $data_table_light;
1.1205 golterma 8021: position: absolute;
8022: top: 100%;
1.1076 raeburn 8023: }
8024:
1.1205 golterma 8025: ol.LC_primary_menu ul ul {
8026: left: 100%;
8027: top: 0;
8028: }
8029:
8030: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8031: display: block;
8032: position: absolute;
8033: margin: 0;
8034: padding: 0;
1.1078 raeburn 8035: z-index: 2;
1.1076 raeburn 8036: }
8037:
8038: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8039: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8040: font-size: 90%;
1.911 bisitz 8041: vertical-align: top;
1.1076 raeburn 8042: float: none;
1.1079 raeburn 8043: border-left: 1px solid black;
8044: border-right: 1px solid black;
1.1205 golterma 8045: /* A dark bottom border to visualize different menu options;
8046: overwritten in the create_submenu routine for the last border-bottom of the menu */
8047: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8048: }
8049:
1.1205 golterma 8050: ol.LC_primary_menu li li p:hover {
8051: color:$button_hover;
8052: text-decoration:none;
8053: background-color:$data_table_dark;
1.1076 raeburn 8054: }
8055:
8056: ol.LC_primary_menu li li a:hover {
8057: color:$button_hover;
8058: background-color:$data_table_dark;
1.693 droeschl 8059: }
8060:
1.1205 golterma 8061: /* Font-size equal to the size of the predecessors*/
8062: ol.LC_primary_menu li:hover li li {
8063: font-size: 100%;
8064: }
8065:
1.897 wenzelju 8066: ol.LC_primary_menu li img {
1.911 bisitz 8067: vertical-align: bottom;
1.934 droeschl 8068: height: 1.1em;
1.1077 raeburn 8069: margin: 0.2em 0 0 0;
1.693 droeschl 8070: }
8071:
1.897 wenzelju 8072: ol.LC_primary_menu a {
1.911 bisitz 8073: color: RGB(80, 80, 80);
8074: text-decoration: none;
1.693 droeschl 8075: }
1.795 www 8076:
1.949 droeschl 8077: ol.LC_primary_menu a.LC_new_message {
8078: font-weight:bold;
8079: color: darkred;
8080: }
8081:
1.975 raeburn 8082: ol.LC_docs_parameters {
8083: margin-left: 0;
8084: padding: 0;
8085: list-style: none;
8086: }
8087:
8088: ol.LC_docs_parameters li {
8089: margin: 0;
8090: padding-right: 20px;
8091: display: inline;
8092: }
8093:
1.976 raeburn 8094: ol.LC_docs_parameters li:before {
8095: content: "\\002022 \\0020";
8096: }
8097:
8098: li.LC_docs_parameters_title {
8099: font-weight: bold;
8100: }
8101:
8102: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8103: content: "";
8104: }
8105:
1.897 wenzelju 8106: ul#LC_secondary_menu {
1.1107 raeburn 8107: clear: right;
1.911 bisitz 8108: color: $fontmenu;
8109: background: $tabbg;
8110: list-style: none;
8111: padding: 0;
8112: margin: 0;
8113: width: 100%;
1.995 raeburn 8114: text-align: left;
1.1107 raeburn 8115: float: left;
1.808 droeschl 8116: }
8117:
1.897 wenzelju 8118: ul#LC_secondary_menu li {
1.911 bisitz 8119: font-weight: bold;
8120: line-height: 1.8em;
1.1107 raeburn 8121: border-right: 1px solid black;
8122: float: left;
8123: }
8124:
8125: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8126: background-color: $data_table_light;
8127: }
8128:
8129: ul#LC_secondary_menu li a {
1.911 bisitz 8130: padding: 0 0.8em;
1.1107 raeburn 8131: }
8132:
8133: ul#LC_secondary_menu li ul {
8134: display: none;
8135: }
8136:
8137: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8138: display: block;
8139: position: absolute;
8140: margin: 0;
8141: padding: 0;
8142: list-style:none;
8143: float: none;
8144: background-color: $data_table_light;
8145: z-index: 2;
8146: margin-left: -1px;
8147: }
8148:
8149: ul#LC_secondary_menu li ul li {
8150: font-size: 90%;
8151: vertical-align: top;
8152: border-left: 1px solid black;
1.911 bisitz 8153: border-right: 1px solid black;
1.1119 raeburn 8154: background-color: $data_table_light;
1.1107 raeburn 8155: list-style:none;
8156: float: none;
8157: }
8158:
8159: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8160: background-color: $data_table_dark;
1.807 droeschl 8161: }
8162:
1.847 tempelho 8163: ul.LC_TabContent {
1.911 bisitz 8164: display:block;
8165: background: $sidebg;
8166: border-bottom: solid 1px $lg_border_color;
8167: list-style:none;
1.1020 raeburn 8168: margin: -1px -10px 0 -10px;
1.911 bisitz 8169: padding: 0;
1.693 droeschl 8170: }
8171:
1.795 www 8172: ul.LC_TabContent li,
8173: ul.LC_TabContentBigger li {
1.911 bisitz 8174: float:left;
1.741 harmsja 8175: }
1.795 www 8176:
1.897 wenzelju 8177: ul#LC_secondary_menu li a {
1.911 bisitz 8178: color: $fontmenu;
8179: text-decoration: none;
1.693 droeschl 8180: }
1.795 www 8181:
1.721 harmsja 8182: ul.LC_TabContent {
1.952 onken 8183: min-height:20px;
1.721 harmsja 8184: }
1.795 www 8185:
8186: ul.LC_TabContent li {
1.911 bisitz 8187: vertical-align:middle;
1.959 onken 8188: padding: 0 16px 0 10px;
1.911 bisitz 8189: background-color:$tabbg;
8190: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8191: border-left: solid 1px $font;
1.721 harmsja 8192: }
1.795 www 8193:
1.847 tempelho 8194: ul.LC_TabContent .right {
1.911 bisitz 8195: float:right;
1.847 tempelho 8196: }
8197:
1.911 bisitz 8198: ul.LC_TabContent li a,
8199: ul.LC_TabContent li {
8200: color:rgb(47,47,47);
8201: text-decoration:none;
8202: font-size:95%;
8203: font-weight:bold;
1.952 onken 8204: min-height:20px;
8205: }
8206:
1.959 onken 8207: ul.LC_TabContent li a:hover,
8208: ul.LC_TabContent li a:focus {
1.952 onken 8209: color: $button_hover;
1.959 onken 8210: background:none;
8211: outline:none;
1.952 onken 8212: }
8213:
8214: ul.LC_TabContent li:hover {
8215: color: $button_hover;
8216: cursor:pointer;
1.721 harmsja 8217: }
1.795 www 8218:
1.911 bisitz 8219: ul.LC_TabContent li.active {
1.952 onken 8220: color: $font;
1.911 bisitz 8221: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8222: border-bottom:solid 1px #FFFFFF;
8223: cursor: default;
1.744 ehlerst 8224: }
1.795 www 8225:
1.959 onken 8226: ul.LC_TabContent li.active a {
8227: color:$font;
8228: background:#FFFFFF;
8229: outline: none;
8230: }
1.1047 raeburn 8231:
8232: ul.LC_TabContent li.goback {
8233: float: left;
8234: border-left: none;
8235: }
8236:
1.870 tempelho 8237: #maincoursedoc {
1.911 bisitz 8238: clear:both;
1.870 tempelho 8239: }
8240:
8241: ul.LC_TabContentBigger {
1.911 bisitz 8242: display:block;
8243: list-style:none;
8244: padding: 0;
1.870 tempelho 8245: }
8246:
1.795 www 8247: ul.LC_TabContentBigger li {
1.911 bisitz 8248: vertical-align:bottom;
8249: height: 30px;
8250: font-size:110%;
8251: font-weight:bold;
8252: color: #737373;
1.841 tempelho 8253: }
8254:
1.957 onken 8255: ul.LC_TabContentBigger li.active {
8256: position: relative;
8257: top: 1px;
8258: }
8259:
1.870 tempelho 8260: ul.LC_TabContentBigger li a {
1.911 bisitz 8261: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8262: height: 30px;
8263: line-height: 30px;
8264: text-align: center;
8265: display: block;
8266: text-decoration: none;
1.958 onken 8267: outline: none;
1.741 harmsja 8268: }
1.795 www 8269:
1.870 tempelho 8270: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8271: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8272: color:$font;
1.744 ehlerst 8273: }
1.795 www 8274:
1.870 tempelho 8275: ul.LC_TabContentBigger li b {
1.911 bisitz 8276: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8277: display: block;
8278: float: left;
8279: padding: 0 30px;
1.957 onken 8280: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8281: }
8282:
1.956 onken 8283: ul.LC_TabContentBigger li:hover b {
8284: color:$button_hover;
8285: }
8286:
1.870 tempelho 8287: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8288: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8289: color:$font;
1.957 onken 8290: border: 0;
1.741 harmsja 8291: }
1.693 droeschl 8292:
1.870 tempelho 8293:
1.862 bisitz 8294: ul.LC_CourseBreadcrumbs {
8295: background: $sidebg;
1.1020 raeburn 8296: height: 2em;
1.862 bisitz 8297: padding-left: 10px;
1.1020 raeburn 8298: margin: 0;
1.862 bisitz 8299: list-style-position: inside;
8300: }
8301:
1.911 bisitz 8302: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8303: ol#LC_PathBreadcrumbs {
1.911 bisitz 8304: padding-left: 10px;
8305: margin: 0;
1.933 droeschl 8306: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8307: }
8308:
1.911 bisitz 8309: ol#LC_MenuBreadcrumbs li,
8310: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8311: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8312: display: inline;
1.933 droeschl 8313: white-space: normal;
1.693 droeschl 8314: }
8315:
1.823 bisitz 8316: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8317: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8318: text-decoration: none;
8319: font-size:90%;
1.693 droeschl 8320: }
1.795 www 8321:
1.969 droeschl 8322: ol#LC_MenuBreadcrumbs h1 {
8323: display: inline;
8324: font-size: 90%;
8325: line-height: 2.5em;
8326: margin: 0;
8327: padding: 0;
8328: }
8329:
1.795 www 8330: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8331: text-decoration:none;
8332: font-size:100%;
8333: font-weight:bold;
1.693 droeschl 8334: }
1.795 www 8335:
1.840 bisitz 8336: .LC_Box {
1.911 bisitz 8337: border: solid 1px $lg_border_color;
8338: padding: 0 10px 10px 10px;
1.746 neumanie 8339: }
1.795 www 8340:
1.1020 raeburn 8341: .LC_DocsBox {
8342: border: solid 1px $lg_border_color;
8343: padding: 0 0 10px 10px;
8344: }
8345:
1.795 www 8346: .LC_AboutMe_Image {
1.911 bisitz 8347: float:left;
8348: margin-right:10px;
1.747 neumanie 8349: }
1.795 www 8350:
8351: .LC_Clear_AboutMe_Image {
1.911 bisitz 8352: clear:left;
1.747 neumanie 8353: }
1.795 www 8354:
1.721 harmsja 8355: dl.LC_ListStyleClean dt {
1.911 bisitz 8356: padding-right: 5px;
8357: display: table-header-group;
1.693 droeschl 8358: }
8359:
1.721 harmsja 8360: dl.LC_ListStyleClean dd {
1.911 bisitz 8361: display: table-row;
1.693 droeschl 8362: }
8363:
1.721 harmsja 8364: .LC_ListStyleClean,
8365: .LC_ListStyleSimple,
8366: .LC_ListStyleNormal,
1.795 www 8367: .LC_ListStyleSpecial {
1.911 bisitz 8368: /* display:block; */
8369: list-style-position: inside;
8370: list-style-type: none;
8371: overflow: hidden;
8372: padding: 0;
1.693 droeschl 8373: }
8374:
1.721 harmsja 8375: .LC_ListStyleSimple li,
8376: .LC_ListStyleSimple dd,
8377: .LC_ListStyleNormal li,
8378: .LC_ListStyleNormal dd,
8379: .LC_ListStyleSpecial li,
1.795 www 8380: .LC_ListStyleSpecial dd {
1.911 bisitz 8381: margin: 0;
8382: padding: 5px 5px 5px 10px;
8383: clear: both;
1.693 droeschl 8384: }
8385:
1.721 harmsja 8386: .LC_ListStyleClean li,
8387: .LC_ListStyleClean dd {
1.911 bisitz 8388: padding-top: 0;
8389: padding-bottom: 0;
1.693 droeschl 8390: }
8391:
1.721 harmsja 8392: .LC_ListStyleSimple dd,
1.795 www 8393: .LC_ListStyleSimple li {
1.911 bisitz 8394: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8395: }
8396:
1.721 harmsja 8397: .LC_ListStyleSpecial li,
8398: .LC_ListStyleSpecial dd {
1.911 bisitz 8399: list-style-type: none;
8400: background-color: RGB(220, 220, 220);
8401: margin-bottom: 4px;
1.693 droeschl 8402: }
8403:
1.721 harmsja 8404: table.LC_SimpleTable {
1.911 bisitz 8405: margin:5px;
8406: border:solid 1px $lg_border_color;
1.795 www 8407: }
1.693 droeschl 8408:
1.721 harmsja 8409: table.LC_SimpleTable tr {
1.911 bisitz 8410: padding: 0;
8411: border:solid 1px $lg_border_color;
1.693 droeschl 8412: }
1.795 www 8413:
8414: table.LC_SimpleTable thead {
1.911 bisitz 8415: background:rgb(220,220,220);
1.693 droeschl 8416: }
8417:
1.721 harmsja 8418: div.LC_columnSection {
1.911 bisitz 8419: display: block;
8420: clear: both;
8421: overflow: hidden;
8422: margin: 0;
1.693 droeschl 8423: }
8424:
1.721 harmsja 8425: div.LC_columnSection>* {
1.911 bisitz 8426: float: left;
8427: margin: 10px 20px 10px 0;
8428: overflow:hidden;
1.693 droeschl 8429: }
1.721 harmsja 8430:
1.795 www 8431: table em {
1.911 bisitz 8432: font-weight: bold;
8433: font-style: normal;
1.748 schulted 8434: }
1.795 www 8435:
1.779 bisitz 8436: table.LC_tableBrowseRes,
1.795 www 8437: table.LC_tableOfContent {
1.911 bisitz 8438: border:none;
8439: border-spacing: 1px;
8440: padding: 3px;
8441: background-color: #FFFFFF;
8442: font-size: 90%;
1.753 droeschl 8443: }
1.789 droeschl 8444:
1.911 bisitz 8445: table.LC_tableOfContent {
8446: border-collapse: collapse;
1.789 droeschl 8447: }
8448:
1.771 droeschl 8449: table.LC_tableBrowseRes a,
1.768 schulted 8450: table.LC_tableOfContent a {
1.911 bisitz 8451: background-color: transparent;
8452: text-decoration: none;
1.753 droeschl 8453: }
8454:
1.795 www 8455: table.LC_tableOfContent img {
1.911 bisitz 8456: border: none;
8457: height: 1.3em;
8458: vertical-align: text-bottom;
8459: margin-right: 0.3em;
1.753 droeschl 8460: }
1.757 schulted 8461:
1.795 www 8462: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8463: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8464: }
8465:
1.795 www 8466: a#LC_content_toolbar_everything {
1.911 bisitz 8467: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8468: }
8469:
1.795 www 8470: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8471: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8472: }
8473:
1.795 www 8474: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8475: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8476: }
8477:
1.795 www 8478: a#LC_content_toolbar_changefolder {
1.911 bisitz 8479: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8480: }
8481:
1.795 www 8482: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8483: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8484: }
8485:
1.1043 raeburn 8486: a#LC_content_toolbar_edittoplevel {
8487: background-image:url(/res/adm/pages/edittoplevel.gif);
8488: }
8489:
1.795 www 8490: ul#LC_toolbar li a:hover {
1.911 bisitz 8491: background-position: bottom center;
1.757 schulted 8492: }
8493:
1.795 www 8494: ul#LC_toolbar {
1.911 bisitz 8495: padding: 0;
8496: margin: 2px;
8497: list-style:none;
8498: position:relative;
8499: background-color:white;
1.1082 raeburn 8500: overflow: auto;
1.757 schulted 8501: }
8502:
1.795 www 8503: ul#LC_toolbar li {
1.911 bisitz 8504: border:1px solid white;
8505: padding: 0;
8506: margin: 0;
8507: float: left;
8508: display:inline;
8509: vertical-align:middle;
1.1082 raeburn 8510: white-space: nowrap;
1.911 bisitz 8511: }
1.757 schulted 8512:
1.783 amueller 8513:
1.795 www 8514: a.LC_toolbarItem {
1.911 bisitz 8515: display:block;
8516: padding: 0;
8517: margin: 0;
8518: height: 32px;
8519: width: 32px;
8520: color:white;
8521: border: none;
8522: background-repeat:no-repeat;
8523: background-color:transparent;
1.757 schulted 8524: }
8525:
1.915 droeschl 8526: ul.LC_funclist {
8527: margin: 0;
8528: padding: 0.5em 1em 0.5em 0;
8529: }
8530:
1.933 droeschl 8531: ul.LC_funclist > li:first-child {
8532: font-weight:bold;
8533: margin-left:0.8em;
8534: }
8535:
1.915 droeschl 8536: ul.LC_funclist + ul.LC_funclist {
8537: /*
8538: left border as a seperator if we have more than
8539: one list
8540: */
8541: border-left: 1px solid $sidebg;
8542: /*
8543: this hides the left border behind the border of the
8544: outer box if element is wrapped to the next 'line'
8545: */
8546: margin-left: -1px;
8547: }
8548:
1.843 bisitz 8549: ul.LC_funclist li {
1.915 droeschl 8550: display: inline;
1.782 bisitz 8551: white-space: nowrap;
1.915 droeschl 8552: margin: 0 0 0 25px;
8553: line-height: 150%;
1.782 bisitz 8554: }
8555:
1.974 wenzelju 8556: .LC_hidden {
8557: display: none;
8558: }
8559:
1.1030 www 8560: .LCmodal-overlay {
8561: position:fixed;
8562: top:0;
8563: right:0;
8564: bottom:0;
8565: left:0;
8566: height:100%;
8567: width:100%;
8568: margin:0;
8569: padding:0;
8570: background:#999;
8571: opacity:.75;
8572: filter: alpha(opacity=75);
8573: -moz-opacity: 0.75;
8574: z-index:101;
8575: }
8576:
8577: * html .LCmodal-overlay {
8578: position: absolute;
8579: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8580: }
8581:
8582: .LCmodal-window {
8583: position:fixed;
8584: top:50%;
8585: left:50%;
8586: margin:0;
8587: padding:0;
8588: z-index:102;
8589: }
8590:
8591: * html .LCmodal-window {
8592: position:absolute;
8593: }
8594:
8595: .LCclose-window {
8596: position:absolute;
8597: width:32px;
8598: height:32px;
8599: right:8px;
8600: top:8px;
8601: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8602: text-indent:-99999px;
8603: overflow:hidden;
8604: cursor:pointer;
8605: }
8606:
1.1369 raeburn 8607: .LCisDisabled {
8608: cursor: not-allowed;
8609: opacity: 0.5;
8610: }
8611:
8612: a[aria-disabled="true"] {
8613: color: currentColor;
8614: display: inline-block; /* For IE11/ MS Edge bug */
8615: pointer-events: none;
8616: text-decoration: none;
8617: }
8618:
1.1335 raeburn 8619: pre.LC_wordwrap {
8620: white-space: pre-wrap;
8621: white-space: -moz-pre-wrap;
8622: white-space: -pre-wrap;
8623: white-space: -o-pre-wrap;
8624: word-wrap: break-word;
8625: }
8626:
1.1100 raeburn 8627: /*
1.1231 damieng 8628: styles used for response display
8629: */
8630: div.LC_radiofoil, div.LC_rankfoil {
8631: margin: .5em 0em .5em 0em;
8632: }
8633: table.LC_itemgroup {
8634: margin-top: 1em;
8635: }
8636:
8637: /*
1.1100 raeburn 8638: styles used by TTH when "Default set of options to pass to tth/m
8639: when converting TeX" in course settings has been set
8640:
8641: option passed: -t
8642:
8643: */
8644:
8645: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8646: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8647: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8648: td div.norm {line-height:normal;}
8649:
8650: /*
8651: option passed -y3
8652: */
8653:
8654: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8655: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8656: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8657:
1.1230 damieng 8658: /*
8659: sections with roles, for content only
8660: */
8661: section[class^="role-"] {
8662: padding-left: 10px;
8663: padding-right: 5px;
8664: margin-top: 8px;
8665: margin-bottom: 8px;
8666: border: 1px solid #2A4;
8667: border-radius: 5px;
8668: box-shadow: 0px 1px 1px #BBB;
8669: }
8670: section[class^="role-"]>h1 {
8671: position: relative;
8672: margin: 0px;
8673: padding-top: 10px;
8674: padding-left: 40px;
8675: }
8676: section[class^="role-"]>h1:before {
8677: position: absolute;
8678: left: -5px;
8679: top: 5px;
8680: }
8681: section.role-activity>h1:before {
8682: content:url('/adm/daxe/images/section_icons/activity.png');
8683: }
8684: section.role-advice>h1:before {
8685: content:url('/adm/daxe/images/section_icons/advice.png');
8686: }
8687: section.role-bibliography>h1:before {
8688: content:url('/adm/daxe/images/section_icons/bibliography.png');
8689: }
8690: section.role-citation>h1:before {
8691: content:url('/adm/daxe/images/section_icons/citation.png');
8692: }
8693: section.role-conclusion>h1:before {
8694: content:url('/adm/daxe/images/section_icons/conclusion.png');
8695: }
8696: section.role-definition>h1:before {
8697: content:url('/adm/daxe/images/section_icons/definition.png');
8698: }
8699: section.role-demonstration>h1:before {
8700: content:url('/adm/daxe/images/section_icons/demonstration.png');
8701: }
8702: section.role-example>h1:before {
8703: content:url('/adm/daxe/images/section_icons/example.png');
8704: }
8705: section.role-explanation>h1:before {
8706: content:url('/adm/daxe/images/section_icons/explanation.png');
8707: }
8708: section.role-introduction>h1:before {
8709: content:url('/adm/daxe/images/section_icons/introduction.png');
8710: }
8711: section.role-method>h1:before {
8712: content:url('/adm/daxe/images/section_icons/method.png');
8713: }
8714: section.role-more_information>h1:before {
8715: content:url('/adm/daxe/images/section_icons/more_information.png');
8716: }
8717: section.role-objectives>h1:before {
8718: content:url('/adm/daxe/images/section_icons/objectives.png');
8719: }
8720: section.role-prerequisites>h1:before {
8721: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8722: }
8723: section.role-remark>h1:before {
8724: content:url('/adm/daxe/images/section_icons/remark.png');
8725: }
8726: section.role-reminder>h1:before {
8727: content:url('/adm/daxe/images/section_icons/reminder.png');
8728: }
8729: section.role-summary>h1:before {
8730: content:url('/adm/daxe/images/section_icons/summary.png');
8731: }
8732: section.role-syntax>h1:before {
8733: content:url('/adm/daxe/images/section_icons/syntax.png');
8734: }
8735: section.role-warning>h1:before {
8736: content:url('/adm/daxe/images/section_icons/warning.png');
8737: }
8738:
1.1269 raeburn 8739: #LC_minitab_header {
8740: float:left;
8741: width:100%;
8742: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8743: font-size:93%;
8744: line-height:normal;
8745: margin: 0.5em 0 0.5em 0;
8746: }
8747: #LC_minitab_header ul {
8748: margin:0;
8749: padding:10px 10px 0;
8750: list-style:none;
8751: }
8752: #LC_minitab_header li {
8753: float:left;
8754: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8755: margin:0;
8756: padding:0 0 0 9px;
8757: }
8758: #LC_minitab_header a {
8759: display:block;
8760: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8761: padding:5px 15px 4px 6px;
8762: }
8763: #LC_minitab_header #LC_current_minitab {
8764: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8765: }
8766: #LC_minitab_header #LC_current_minitab a {
8767: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8768: padding-bottom:5px;
8769: }
8770:
8771:
1.343 albertel 8772: END
8773: }
8774:
1.306 albertel 8775: =pod
8776:
8777: =item * &headtag()
8778:
8779: Returns a uniform footer for LON-CAPA web pages.
8780:
1.307 albertel 8781: Inputs: $title - optional title for the head
8782: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8783: $args - optional arguments
1.319 albertel 8784: force_register - if is true call registerurl so the remote is
8785: informed
1.415 albertel 8786: redirect -> array ref of
8787: 1- seconds before redirect occurs
8788: 2- url to redirect to
8789: 3- whether the side effect should occur
1.315 albertel 8790: (side effect of setting
8791: $env{'internal.head.redirect'} to the url
8792: redirected too)
1.352 albertel 8793: domain -> force to color decorate a page for a specific
8794: domain
8795: function -> force usage of a specific rolish color scheme
8796: bgcolor -> override the default page bgcolor
1.460 albertel 8797: no_auto_mt_title
8798: -> prevent &mt()ing the title arg
1.464 albertel 8799:
1.306 albertel 8800: =cut
8801:
8802: sub headtag {
1.313 albertel 8803: my ($title,$head_extra,$args) = @_;
1.306 albertel 8804:
1.363 albertel 8805: my $function = $args->{'function'} || &get_users_function();
8806: my $domain = $args->{'domain'} || &determinedomain();
8807: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8808: my $httphost = $args->{'use_absolute'};
1.418 albertel 8809: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8810: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8811: #time(),
1.418 albertel 8812: $env{'environment.color.timestamp'},
1.363 albertel 8813: $function,$domain,$bgcolor);
8814:
1.369 www 8815: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8816:
1.308 albertel 8817: my $result =
8818: '<head>'.
1.1160 raeburn 8819: &font_settings($args);
1.319 albertel 8820:
1.1188 raeburn 8821: my $inhibitprint;
8822: if ($args->{'print_suppress'}) {
8823: $inhibitprint = &print_suppression();
8824: }
1.1064 raeburn 8825:
1.461 albertel 8826: if (!$args->{'frameset'}) {
8827: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8828: }
1.962 droeschl 8829: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8830: $result .= Apache::lonxml::display_title();
1.319 albertel 8831: }
1.436 albertel 8832: if (!$args->{'no_nav_bar'}
8833: && !$args->{'only_body'}
8834: && !$args->{'frameset'}) {
1.1154 raeburn 8835: $result .= &help_menu_js($httphost);
1.1032 www 8836: $result.=&modal_window();
1.1038 www 8837: $result.=&togglebox_script();
1.1034 www 8838: $result.=&wishlist_window();
1.1041 www 8839: $result.=&LCprogressbarUpdate_script();
1.1034 www 8840: } else {
8841: if ($args->{'add_modal'}) {
8842: $result.=&modal_window();
8843: }
8844: if ($args->{'add_wishlist'}) {
8845: $result.=&wishlist_window();
8846: }
1.1038 www 8847: if ($args->{'add_togglebox'}) {
8848: $result.=&togglebox_script();
8849: }
1.1041 www 8850: if ($args->{'add_progressbar'}) {
8851: $result.=&LCprogressbarUpdate_script();
8852: }
1.436 albertel 8853: }
1.314 albertel 8854: if (ref($args->{'redirect'})) {
1.414 albertel 8855: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8856: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8857: if (!$inhibit_continue) {
8858: $env{'internal.head.redirect'} = $url;
8859: }
1.313 albertel 8860: $result.=<<ADDMETA
8861: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8862: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8863: ADDMETA
1.1210 raeburn 8864: } else {
8865: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8866: my $requrl = $env{'request.uri'};
8867: if ($requrl eq '') {
8868: $requrl = $ENV{'REQUEST_URI'};
8869: $requrl =~ s/\?.+$//;
8870: }
8871: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8872: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8873: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8874: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8875: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8876: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8877: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8878: my ($offload,$offloadoth);
1.1210 raeburn 8879: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8880: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8881: $offload = 1;
1.1353 raeburn 8882: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8883: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8884: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8885: $offloadoth = 1;
8886: $dom_in_use = $env{'user.domain'};
8887: }
8888: }
1.1340 raeburn 8889: }
8890: }
8891: unless ($offload) {
8892: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8893: if ($domdefs{'offloadoth'}{$lonhost}) {
8894: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8895: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8896: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8897: $offload = 1;
1.1352 raeburn 8898: $offloadoth = 1;
1.1340 raeburn 8899: $dom_in_use = $env{'user.domain'};
8900: }
1.1210 raeburn 8901: }
1.1340 raeburn 8902: }
8903: }
8904: }
8905: if ($offload) {
1.1358 raeburn 8906: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 8907: if (($newserver eq '') && ($offloadoth)) {
8908: my @domains = &Apache::lonnet::current_machine_domains();
8909: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8910: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8911: }
8912: }
1.1340 raeburn 8913: if (($newserver) && ($newserver ne $lonhost)) {
8914: my $numsec = 5;
8915: my $timeout = $numsec * 1000;
8916: my ($newurl,$locknum,%locks,$msg);
8917: if ($env{'request.role.adv'}) {
8918: ($locknum,%locks) = &Apache::lonnet::get_locks();
8919: }
8920: my $disable_submit = 0;
8921: if ($requrl =~ /$LONCAPA::assess_re/) {
8922: $disable_submit = 1;
8923: }
8924: if ($locknum) {
8925: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8926: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8927: join(", ",sort(values(%locks)))."\n";
8928: if (&show_course()) {
8929: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8930: } else {
8931: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8932: }
1.1340 raeburn 8933: } else {
8934: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8935: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8936: }
8937: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8938: $newurl = '/adm/switchserver?otherserver='.$newserver;
8939: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8940: $newurl .= '&role='.$env{'request.role'};
8941: }
8942: if ($env{'request.symb'}) {
8943: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8944: if ($shownsymb =~ m{^/enc/}) {
8945: my $reqdmajor = 2;
8946: my $reqdminor = 11;
8947: my $reqdsubminor = 3;
8948: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8949: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8950: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8951: if (($major eq '' && $minor eq '') ||
8952: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8953: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8954: ($reqdsubminor > $subminor))))) {
8955: undef($shownsymb);
8956: }
1.1210 raeburn 8957: }
1.1340 raeburn 8958: if ($shownsymb) {
8959: &js_escape(\$shownsymb);
8960: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8961: }
1.1340 raeburn 8962: } else {
8963: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8964: &js_escape(\$shownurl);
8965: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8966: }
1.1340 raeburn 8967: }
8968: &js_escape(\$msg);
8969: $result.=<<OFFLOAD
1.1210 raeburn 8970: <meta http-equiv="pragma" content="no-cache" />
8971: <script type="text/javascript">
1.1215 raeburn 8972: // <![CDATA[
1.1210 raeburn 8973: function LC_Offload_Now() {
8974: var dest = "$newurl";
8975: if (dest != '') {
8976: window.location.href="$newurl";
8977: }
8978: }
1.1214 raeburn 8979: \$(document).ready(function () {
8980: window.alert('$msg');
8981: if ($disable_submit) {
1.1210 raeburn 8982: \$(".LC_hwk_submit").prop("disabled", true);
8983: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8984: }
8985: setTimeout('LC_Offload_Now()', $timeout);
8986: });
1.1215 raeburn 8987: // ]]>
1.1210 raeburn 8988: </script>
8989: OFFLOAD
8990: }
8991: }
8992: }
8993: }
8994: }
1.313 albertel 8995: }
1.306 albertel 8996: if (!defined($title)) {
8997: $title = 'The LearningOnline Network with CAPA';
8998: }
1.460 albertel 8999: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9000: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9001: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9002: if (!$args->{'frameset'}) {
9003: $result .= ' /';
9004: }
9005: $result .= '>'
1.1064 raeburn 9006: .$inhibitprint
1.414 albertel 9007: .$head_extra;
1.1242 raeburn 9008: my $clientmobile;
9009: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9010: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9011: } else {
9012: $clientmobile = $env{'browser.mobile'};
9013: }
9014: if ($clientmobile) {
1.1137 raeburn 9015: $result .= '
9016: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9017: <meta name="apple-mobile-web-app-capable" content="yes" />';
9018: }
1.1278 raeburn 9019: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9020: return $result.'</head>';
1.306 albertel 9021: }
9022:
9023: =pod
9024:
1.340 albertel 9025: =item * &font_settings()
9026:
9027: Returns neccessary <meta> to set the proper encoding
9028:
1.1160 raeburn 9029: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9030:
9031: =cut
9032:
9033: sub font_settings {
1.1160 raeburn 9034: my ($args) = @_;
1.340 albertel 9035: my $headerstring='';
1.1160 raeburn 9036: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9037: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9038: $headerstring.=
9039: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9040: if (!$args->{'frameset'}) {
9041: $headerstring.= ' /';
9042: }
9043: $headerstring .= '>'."\n";
1.340 albertel 9044: }
9045: return $headerstring;
9046: }
9047:
1.341 albertel 9048: =pod
9049:
1.1064 raeburn 9050: =item * &print_suppression()
9051:
9052: In course context returns css which causes the body to be blank when media="print",
9053: if printout generation is unavailable for the current resource.
9054:
9055: This could be because:
9056:
9057: (a) printstartdate is in the future
9058:
9059: (b) printenddate is in the past
9060:
9061: (c) there is an active exam block with "printout"
9062: functionality blocked
9063:
9064: Users with pav, pfo or evb privileges are exempt.
9065:
9066: Inputs: none
9067:
9068: =cut
9069:
9070:
9071: sub print_suppression {
9072: my $noprint;
9073: if ($env{'request.course.id'}) {
9074: my $scope = $env{'request.course.id'};
9075: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9076: (&Apache::lonnet::allowed('pfo',$scope))) {
9077: return;
9078: }
9079: if ($env{'request.course.sec'} ne '') {
9080: $scope .= "/$env{'request.course.sec'}";
9081: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9082: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9083: return;
1.1064 raeburn 9084: }
9085: }
9086: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9087: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9088: my $clientip = &Apache::lonnet::get_requestor_ip();
9089: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9090: if ($blocked) {
9091: my $checkrole = "cm./$cdom/$cnum";
9092: if ($env{'request.course.sec'} ne '') {
9093: $checkrole .= "/$env{'request.course.sec'}";
9094: }
9095: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9096: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9097: $noprint = 1;
9098: }
9099: }
9100: unless ($noprint) {
9101: my $symb = &Apache::lonnet::symbread();
9102: if ($symb ne '') {
9103: my $navmap = Apache::lonnavmaps::navmap->new();
9104: if (ref($navmap)) {
9105: my $res = $navmap->getBySymb($symb);
9106: if (ref($res)) {
9107: if (!$res->resprintable()) {
9108: $noprint = 1;
9109: }
9110: }
9111: }
9112: }
9113: }
9114: if ($noprint) {
9115: return <<"ENDSTYLE";
9116: <style type="text/css" media="print">
9117: body { display:none }
9118: </style>
9119: ENDSTYLE
9120: }
9121: }
9122: return;
9123: }
9124:
9125: =pod
9126:
1.341 albertel 9127: =item * &xml_begin()
9128:
9129: Returns the needed doctype and <html>
9130:
9131: Inputs: none
9132:
9133: =cut
9134:
9135: sub xml_begin {
1.1168 raeburn 9136: my ($is_frameset) = @_;
1.341 albertel 9137: my $output='';
9138:
9139: if ($env{'browser.mathml'}) {
9140: $output='<?xml version="1.0"?>'
9141: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9142: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9143:
9144: # .'<!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">] >'
9145: .'<!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">'
9146: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9147: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9148: } elsif ($is_frameset) {
9149: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9150: '<html>'."\n";
1.341 albertel 9151: } else {
1.1168 raeburn 9152: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9153: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9154: }
9155: return $output;
9156: }
1.340 albertel 9157:
9158: =pod
9159:
1.306 albertel 9160: =item * &start_page()
9161:
9162: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9163:
1.648 raeburn 9164: Inputs:
9165:
9166: =over 4
9167:
9168: $title - optional title for the page
9169:
9170: $head_extra - optional extra HTML to incude inside the <head>
9171:
9172: $args - additional optional args supported are:
9173:
9174: =over 8
9175:
9176: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9177: arg on
1.814 bisitz 9178: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9179: add_entries -> additional attributes to add to the <body>
9180: domain -> force to color decorate a page for a
1.317 albertel 9181: specific domain
1.648 raeburn 9182: function -> force usage of a specific rolish color
1.317 albertel 9183: scheme
1.648 raeburn 9184: redirect -> see &headtag()
9185: bgcolor -> override the default page bg color
9186: js_ready -> return a string ready for being used in
1.317 albertel 9187: a javascript writeln
1.648 raeburn 9188: html_encode -> return a string ready for being used in
1.320 albertel 9189: a html attribute
1.648 raeburn 9190: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9191: $forcereg arg
1.648 raeburn 9192: frameset -> if true will start with a <frameset>
1.330 albertel 9193: rather than <body>
1.648 raeburn 9194: skip_phases -> hash ref of
1.338 albertel 9195: head -> skip the <html><head> generation
9196: body -> skip all <body> generation
1.648 raeburn 9197: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9198: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9199: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9200: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9201: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9202: group -> includes the current group, if page is for a
1.1274 raeburn 9203: specific group
9204: use_absolute -> for request for external resource or syllabus, this
9205: will contain https://<hostname> if server uses
9206: https (as per hosts.tab), but request is for http
9207: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9208: links_disabled -> Links in primary and secondary menus are disabled
9209: (Can enable them once page has loaded - see lonroles.pm
9210: for an example).
1.361 albertel 9211:
1.648 raeburn 9212: =back
1.460 albertel 9213:
1.648 raeburn 9214: =back
1.562 albertel 9215:
1.306 albertel 9216: =cut
9217:
9218: sub start_page {
1.309 albertel 9219: my ($title,$head_extra,$args) = @_;
1.318 albertel 9220: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9221:
1.315 albertel 9222: $env{'internal.start_page'}++;
1.1359 raeburn 9223: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9224:
1.338 albertel 9225: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9226: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9227: }
1.1316 raeburn 9228:
9229: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9230: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9231: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9232: $args->{'no_primary_menu'} = 1;
9233: }
9234: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9235: $args->{'no_inline_menu'} = 1;
9236: }
9237: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9238: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9239: }
9240: } else {
9241: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9242: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9243: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9244: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9245: $args->{'no_primary_menu'} = 1;
9246: }
9247: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9248: $args->{'no_inline_menu'} = 1;
9249: }
9250: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9251: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9252: }
9253: }
9254: }
1.1316 raeburn 9255: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9256: $env{'course.'.$env{'request.course.id'}.'.domain'},
9257: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9258: } elsif ($env{'request.course.id'}) {
9259: my $expiretime=600;
9260: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9261: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9262: }
9263: my ($deeplinkmenu,$menuref);
9264: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9265: if ($menucoll) {
9266: if (ref($menuref) eq 'HASH') {
9267: %menu = %{$menuref};
9268: }
9269: if ($menu{'top'} eq 'n') {
9270: $args->{'no_primary_menu'} = 1;
9271: }
9272: if ($menu{'inline'} eq 'n') {
9273: unless (&Apache::lonnet::allowed('opa')) {
9274: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9275: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9276: my $crstype = &course_type();
9277: my $now = time;
9278: my $ccrole;
9279: if ($crstype eq 'Community') {
9280: $ccrole = 'co';
9281: } else {
9282: $ccrole = 'cc';
9283: }
9284: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9285: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9286: if ((($start) && ($start<0)) ||
9287: (($end) && ($end<$now)) ||
9288: (($start) && ($now<$start))) {
9289: $args->{'no_inline_menu'} = 1;
9290: }
9291: } else {
9292: $args->{'no_inline_menu'} = 1;
9293: }
9294: }
9295: }
9296: }
1.1316 raeburn 9297: }
1.1359 raeburn 9298:
1.338 albertel 9299: if (! exists($args->{'skip_phases'}{'body'}) ) {
9300: if ($args->{'frameset'}) {
9301: my $attr_string = &make_attr_string($args->{'force_register'},
9302: $args->{'add_entries'});
9303: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9304: } else {
9305: $result .=
9306: &bodytag($title,
9307: $args->{'function'}, $args->{'add_entries'},
9308: $args->{'only_body'}, $args->{'domain'},
9309: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9310: $args->{'bgcolor'}, $args,
1.1359 raeburn 9311: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu);
1.831 bisitz 9312: }
1.330 albertel 9313: }
1.338 albertel 9314:
1.315 albertel 9315: if ($args->{'js_ready'}) {
1.713 kaisler 9316: $result = &js_ready($result);
1.315 albertel 9317: }
1.320 albertel 9318: if ($args->{'html_encode'}) {
1.713 kaisler 9319: $result = &html_encode($result);
9320: }
9321:
1.813 bisitz 9322: # Preparation for new and consistent functionlist at top of screen
9323: # if ($args->{'functionlist'}) {
9324: # $result .= &build_functionlist();
9325: #}
9326:
1.964 droeschl 9327: # Don't add anything more if only_body wanted or in const space
9328: return $result if $args->{'only_body'}
9329: || $env{'request.state'} eq 'construct';
1.813 bisitz 9330:
9331: #Breadcrumbs
1.758 kaisler 9332: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9333: &Apache::lonhtmlcommon::clear_breadcrumbs();
9334: #if any br links exists, add them to the breadcrumbs
9335: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9336: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9337: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9338: }
9339: }
1.1096 raeburn 9340: # if @advtools array contains items add then to the breadcrumbs
9341: if (@advtools > 0) {
9342: &Apache::lonmenu::advtools_crumbs(@advtools);
9343: }
1.1272 raeburn 9344: my $menulink;
9345: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9346: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9347: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9348: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9349: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9350: (!$env{'request.role.adv'}))) {
9351: $menulink = 0;
9352: } else {
9353: undef($menulink);
9354: }
1.758 kaisler 9355: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9356: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9357: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9358: } else {
1.1272 raeburn 9359: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9360: }
1.320 albertel 9361: }
1.315 albertel 9362: return $result;
1.306 albertel 9363: }
9364:
9365: sub end_page {
1.315 albertel 9366: my ($args) = @_;
9367: $env{'internal.end_page'}++;
1.330 albertel 9368: my $result;
1.335 albertel 9369: if ($args->{'discussion'}) {
9370: my ($target,$parser);
9371: if (ref($args->{'discussion'})) {
9372: ($target,$parser) =($args->{'discussion'}{'target'},
9373: $args->{'discussion'}{'parser'});
9374: }
9375: $result .= &Apache::lonxml::xmlend($target,$parser);
9376: }
1.330 albertel 9377: if ($args->{'frameset'}) {
9378: $result .= '</frameset>';
9379: } else {
1.635 raeburn 9380: $result .= &endbodytag($args);
1.330 albertel 9381: }
1.1080 raeburn 9382: unless ($args->{'notbody'}) {
9383: $result .= "\n</html>";
9384: }
1.330 albertel 9385:
1.315 albertel 9386: if ($args->{'js_ready'}) {
1.317 albertel 9387: $result = &js_ready($result);
1.315 albertel 9388: }
1.335 albertel 9389:
1.320 albertel 9390: if ($args->{'html_encode'}) {
9391: $result = &html_encode($result);
9392: }
1.335 albertel 9393:
1.315 albertel 9394: return $result;
9395: }
9396:
1.1359 raeburn 9397: sub menucoll_in_effect {
9398: my ($menucoll,$deeplinkmenu,%menu);
9399: if ($env{'request.course.id'}) {
9400: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9401: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9402: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9403: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9404: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9405: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9406: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9407: my $navmap = Apache::lonnavmaps::navmap->new();
9408: if (ref($navmap)) {
9409: $deeplink = $navmap->get_mapparam(undef,
9410: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9411: '0.deeplink');
1.1370 raeburn 9412: } else {
9413: $check_login_symb = 1;
1.1362 raeburn 9414: }
9415: } else {
1.1370 raeburn 9416: my $symb = &Apache::lonnet::symbread();
9417: if ($symb) {
9418: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9419: } else {
9420: $check_login_symb = 1;
9421: }
1.1362 raeburn 9422: }
9423: } else {
1.1370 raeburn 9424: $check_login_symb = 1;
9425: }
9426: if ($check_login_symb) {
1.1362 raeburn 9427: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9428: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9429: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9430: my $navmap = Apache::lonnavmaps::navmap->new();
9431: if (ref($navmap)) {
9432: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9433: }
9434: } else {
9435: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9436: }
9437: }
1.1359 raeburn 9438: if ($deeplink ne '') {
1.1363 raeburn 9439: my ($state,$others,$listed,$scope,$protect,$display) = split(/,/,$deeplink);
1.1359 raeburn 9440: if ($display =~ /^\d+$/) {
9441: $deeplinkmenu = 1;
9442: $menucoll = $display;
9443: }
9444: }
9445: }
9446: if ($menucoll) {
9447: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9448: }
9449: }
9450: return ($menucoll,$deeplinkmenu,\%menu);
9451: }
9452:
1.1362 raeburn 9453: sub deeplink_login_symb {
9454: my ($cnum,$cdom) = @_;
9455: my $login_symb;
9456: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9457: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9458: }
9459: return $login_symb;
9460: }
9461:
9462: sub symb_from_tinyurl {
9463: my ($url,$cnum,$cdom) = @_;
9464: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9465: my $key = $1;
9466: my ($tinyurl,$login);
9467: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9468: if (defined($cached)) {
9469: $tinyurl = $result;
9470: } else {
9471: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9472: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9473: if ($currtiny{$key} ne '') {
9474: $tinyurl = $currtiny{$key};
9475: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9476: }
1.1364 raeburn 9477: }
9478: if ($tinyurl ne '') {
9479: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9480: if (wantarray) {
9481: return ($cnumreq,$symb);
9482: } elsif ($cnumreq eq $cnum) {
9483: return $symb;
1.1362 raeburn 9484: }
9485: }
9486: }
1.1364 raeburn 9487: if (wantarray) {
9488: return ();
9489: } else {
9490: return;
9491: }
1.1362 raeburn 9492: }
9493:
1.1034 www 9494: sub wishlist_window {
9495: return(<<'ENDWISHLIST');
1.1046 raeburn 9496: <script type="text/javascript">
1.1034 www 9497: // <![CDATA[
9498: // <!-- BEGIN LON-CAPA Internal
9499: function set_wishlistlink(title, path) {
9500: if (!title) {
9501: title = document.title;
9502: title = title.replace(/^LON-CAPA /,'');
9503: }
1.1175 raeburn 9504: title = encodeURIComponent(title);
1.1203 raeburn 9505: title = title.replace("'","\\\'");
1.1034 www 9506: if (!path) {
9507: path = location.pathname;
9508: }
1.1175 raeburn 9509: path = encodeURIComponent(path);
1.1203 raeburn 9510: path = path.replace("'","\\\'");
1.1034 www 9511: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9512: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9513: }
9514: // END LON-CAPA Internal -->
9515: // ]]>
9516: </script>
9517: ENDWISHLIST
9518: }
9519:
1.1030 www 9520: sub modal_window {
9521: return(<<'ENDMODAL');
1.1046 raeburn 9522: <script type="text/javascript">
1.1030 www 9523: // <![CDATA[
9524: // <!-- BEGIN LON-CAPA Internal
9525: var modalWindow = {
9526: parent:"body",
9527: windowId:null,
9528: content:null,
9529: width:null,
9530: height:null,
9531: close:function()
9532: {
9533: $(".LCmodal-window").remove();
9534: $(".LCmodal-overlay").remove();
9535: },
9536: open:function()
9537: {
9538: var modal = "";
9539: modal += "<div class=\"LCmodal-overlay\"></div>";
9540: 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;\">";
9541: modal += this.content;
9542: modal += "</div>";
9543:
9544: $(this.parent).append(modal);
9545:
9546: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9547: $(".LCclose-window").click(function(){modalWindow.close();});
9548: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9549: }
9550: };
1.1140 raeburn 9551: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9552: {
1.1266 raeburn 9553: source = source.replace(/'/g,"'");
1.1030 www 9554: modalWindow.windowId = "myModal";
9555: modalWindow.width = width;
9556: modalWindow.height = height;
1.1196 raeburn 9557: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9558: modalWindow.open();
1.1208 raeburn 9559: };
1.1030 www 9560: // END LON-CAPA Internal -->
9561: // ]]>
9562: </script>
9563: ENDMODAL
9564: }
9565:
9566: sub modal_link {
1.1140 raeburn 9567: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9568: unless ($width) { $width=480; }
9569: unless ($height) { $height=400; }
1.1031 www 9570: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9571: unless ($transparency) { $transparency='true'; }
9572:
1.1074 raeburn 9573: my $target_attr;
9574: if (defined($target)) {
9575: $target_attr = 'target="'.$target.'"';
9576: }
9577: return <<"ENDLINK";
1.1336 raeburn 9578: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9579: ENDLINK
1.1030 www 9580: }
9581:
1.1032 www 9582: sub modal_adhoc_script {
1.1365 raeburn 9583: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9584: my $mathjax;
9585: if ($possmathjax) {
9586: $mathjax = <<'ENDJAX';
9587: if (typeof MathJax == 'object') {
9588: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9589: }
9590: ENDJAX
9591: }
1.1032 www 9592: return (<<ENDADHOC);
1.1046 raeburn 9593: <script type="text/javascript">
1.1032 www 9594: // <![CDATA[
9595: var $funcname = function()
9596: {
9597: modalWindow.windowId = "myModal";
9598: modalWindow.width = $width;
9599: modalWindow.height = $height;
9600: modalWindow.content = '$content';
9601: modalWindow.open();
1.1365 raeburn 9602: $mathjax
1.1032 www 9603: };
9604: // ]]>
9605: </script>
9606: ENDADHOC
9607: }
9608:
1.1041 www 9609: sub modal_adhoc_inner {
1.1365 raeburn 9610: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9611: my $innerwidth=$width-20;
9612: $content=&js_ready(
1.1140 raeburn 9613: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9614: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9615: $content.
1.1041 www 9616: &end_scrollbox().
1.1140 raeburn 9617: &end_page()
1.1041 www 9618: );
1.1365 raeburn 9619: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9620: }
9621:
9622: sub modal_adhoc_window {
1.1365 raeburn 9623: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9624: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9625: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9626: }
9627:
9628: sub modal_adhoc_launch {
9629: my ($funcname,$width,$height,$content)=@_;
9630: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9631: <script type="text/javascript">
9632: // <![CDATA[
9633: $funcname();
9634: // ]]>
9635: </script>
9636: ENDLAUNCH
9637: }
9638:
9639: sub modal_adhoc_close {
9640: return (<<ENDCLOSE);
9641: <script type="text/javascript">
9642: // <![CDATA[
9643: modalWindow.close();
9644: // ]]>
9645: </script>
9646: ENDCLOSE
9647: }
9648:
1.1038 www 9649: sub togglebox_script {
9650: return(<<ENDTOGGLE);
9651: <script type="text/javascript">
9652: // <![CDATA[
9653: function LCtoggleDisplay(id,hidetext,showtext) {
9654: link = document.getElementById(id + "link").childNodes[0];
9655: with (document.getElementById(id).style) {
9656: if (display == "none" ) {
9657: display = "inline";
9658: link.nodeValue = hidetext;
9659: } else {
9660: display = "none";
9661: link.nodeValue = showtext;
9662: }
9663: }
9664: }
9665: // ]]>
9666: </script>
9667: ENDTOGGLE
9668: }
9669:
1.1039 www 9670: sub start_togglebox {
9671: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9672: unless ($heading) { $heading=''; } else { $heading.=' '; }
9673: unless ($showtext) { $showtext=&mt('show'); }
9674: unless ($hidetext) { $hidetext=&mt('hide'); }
9675: unless ($headerbg) { $headerbg='#FFFFFF'; }
9676: return &start_data_table().
9677: &start_data_table_header_row().
9678: '<td bgcolor="'.$headerbg.'">'.$heading.
9679: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9680: $showtext.'\')">'.$showtext.'</a>]</td>'.
9681: &end_data_table_header_row().
9682: '<tr id="'.$id.'" style="display:none""><td>';
9683: }
9684:
9685: sub end_togglebox {
9686: return '</td></tr>'.&end_data_table();
9687: }
9688:
1.1041 www 9689: sub LCprogressbar_script {
1.1302 raeburn 9690: my ($id,$number_to_do)=@_;
9691: if ($number_to_do) {
9692: return(<<ENDPROGRESS);
1.1041 www 9693: <script type="text/javascript">
9694: // <![CDATA[
1.1045 www 9695: \$('#progressbar$id').progressbar({
1.1041 www 9696: value: 0,
9697: change: function(event, ui) {
9698: var newVal = \$(this).progressbar('option', 'value');
9699: \$('.pblabel', this).text(LCprogressTxt);
9700: }
9701: });
9702: // ]]>
9703: </script>
9704: ENDPROGRESS
1.1302 raeburn 9705: } else {
9706: return(<<ENDPROGRESS);
9707: <script type="text/javascript">
9708: // <![CDATA[
9709: \$('#progressbar$id').progressbar({
9710: value: false,
9711: create: function(event, ui) {
9712: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9713: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9714: }
9715: });
9716: // ]]>
9717: </script>
9718: ENDPROGRESS
9719: }
1.1041 www 9720: }
9721:
9722: sub LCprogressbarUpdate_script {
9723: return(<<ENDPROGRESSUPDATE);
9724: <style type="text/css">
9725: .ui-progressbar { position:relative; }
1.1302 raeburn 9726: .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 9727: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9728: </style>
9729: <script type="text/javascript">
9730: // <![CDATA[
1.1045 www 9731: var LCprogressTxt='---';
9732:
1.1302 raeburn 9733: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9734: LCprogressTxt=progresstext;
1.1302 raeburn 9735: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9736: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9737: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9738: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9739: } else {
9740: \$('#progressbar'+id).progressbar('value',percent);
9741: }
1.1041 www 9742: }
9743: // ]]>
9744: </script>
9745: ENDPROGRESSUPDATE
9746: }
9747:
1.1042 www 9748: my $LClastpercent;
1.1045 www 9749: my $LCidcnt;
9750: my $LCcurrentid;
1.1042 www 9751:
1.1041 www 9752: sub LCprogressbar {
1.1302 raeburn 9753: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9754: $LClastpercent=0;
1.1045 www 9755: $LCidcnt++;
9756: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9757: my ($starting,$content);
9758: if ($number_to_do) {
9759: $starting=&mt('Starting');
9760: $content=(<<ENDPROGBAR);
9761: $preamble
1.1045 www 9762: <div id="progressbar$LCcurrentid">
1.1041 www 9763: <span class="pblabel">$starting</span>
9764: </div>
9765: ENDPROGBAR
1.1302 raeburn 9766: } else {
9767: $starting=&mt('Loading...');
9768: $LClastpercent='false';
9769: $content=(<<ENDPROGBAR);
9770: $preamble
9771: <div id="progressbar$LCcurrentid">
9772: <div class="progress-label">$starting</div>
9773: </div>
9774: ENDPROGBAR
9775: }
9776: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9777: }
9778:
9779: sub LCprogressbarUpdate {
1.1302 raeburn 9780: my ($r,$val,$text,$number_to_do)=@_;
9781: if ($number_to_do) {
9782: unless ($val) {
9783: if ($LClastpercent) {
9784: $val=$LClastpercent;
9785: } else {
9786: $val=0;
9787: }
9788: }
9789: if ($val<0) { $val=0; }
9790: if ($val>100) { $val=0; }
9791: $LClastpercent=$val;
9792: unless ($text) { $text=$val.'%'; }
9793: } else {
9794: $val = 'false';
1.1042 www 9795: }
1.1041 www 9796: $text=&js_ready($text);
1.1044 www 9797: &r_print($r,<<ENDUPDATE);
1.1041 www 9798: <script type="text/javascript">
9799: // <![CDATA[
1.1302 raeburn 9800: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9801: // ]]>
9802: </script>
9803: ENDUPDATE
1.1035 www 9804: }
9805:
1.1042 www 9806: sub LCprogressbarClose {
9807: my ($r)=@_;
9808: $LClastpercent=0;
1.1044 www 9809: &r_print($r,<<ENDCLOSE);
1.1042 www 9810: <script type="text/javascript">
9811: // <![CDATA[
1.1045 www 9812: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9813: // ]]>
9814: </script>
9815: ENDCLOSE
1.1044 www 9816: }
9817:
9818: sub r_print {
9819: my ($r,$to_print)=@_;
9820: if ($r) {
9821: $r->print($to_print);
9822: $r->rflush();
9823: } else {
9824: print($to_print);
9825: }
1.1042 www 9826: }
9827:
1.320 albertel 9828: sub html_encode {
9829: my ($result) = @_;
9830:
1.322 albertel 9831: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9832:
9833: return $result;
9834: }
1.1044 www 9835:
1.317 albertel 9836: sub js_ready {
9837: my ($result) = @_;
9838:
1.323 albertel 9839: $result =~ s/[\n\r]/ /xmsg;
9840: $result =~ s/\\/\\\\/xmsg;
9841: $result =~ s/'/\\'/xmsg;
1.372 albertel 9842: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9843:
9844: return $result;
9845: }
9846:
1.315 albertel 9847: sub validate_page {
9848: if ( exists($env{'internal.start_page'})
1.316 albertel 9849: && $env{'internal.start_page'} > 1) {
9850: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9851: $env{'internal.start_page'}.' '.
1.316 albertel 9852: $ENV{'request.filename'});
1.315 albertel 9853: }
9854: if ( exists($env{'internal.end_page'})
1.316 albertel 9855: && $env{'internal.end_page'} > 1) {
9856: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9857: $env{'internal.end_page'}.' '.
1.316 albertel 9858: $env{'request.filename'});
1.315 albertel 9859: }
9860: if ( exists($env{'internal.start_page'})
9861: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9862: &Apache::lonnet::logthis('start_page called without end_page '.
9863: $env{'request.filename'});
1.315 albertel 9864: }
9865: if ( ! exists($env{'internal.start_page'})
9866: && exists($env{'internal.end_page'})) {
1.316 albertel 9867: &Apache::lonnet::logthis('end_page called without start_page'.
9868: $env{'request.filename'});
1.315 albertel 9869: }
1.306 albertel 9870: }
1.315 albertel 9871:
1.996 www 9872:
9873: sub start_scrollbox {
1.1140 raeburn 9874: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9875: unless ($outerwidth) { $outerwidth='520px'; }
9876: unless ($width) { $width='500px'; }
9877: unless ($height) { $height='200px'; }
1.1075 raeburn 9878: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9879: if ($id ne '') {
1.1140 raeburn 9880: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9881: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9882: }
1.1075 raeburn 9883: if ($bgcolor ne '') {
9884: $tdcol = "background-color: $bgcolor;";
9885: }
1.1137 raeburn 9886: my $nicescroll_js;
9887: if ($env{'browser.mobile'}) {
1.1140 raeburn 9888: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9889: }
9890: return <<"END";
9891: $nicescroll_js
9892:
9893: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9894: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9895: END
9896: }
9897:
9898: sub end_scrollbox {
9899: return '</div></td></tr></table>';
9900: }
9901:
9902: sub nicescroll_javascript {
9903: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9904: my %options;
9905: if (ref($cursor) eq 'HASH') {
9906: %options = %{$cursor};
9907: }
9908: unless ($options{'railalign'} =~ /^left|right$/) {
9909: $options{'railalign'} = 'left';
9910: }
9911: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9912: my $function = &get_users_function();
9913: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9914: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9915: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9916: }
1.1140 raeburn 9917: }
9918: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9919: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9920: $options{'cursoropacity'}='1.0';
9921: }
1.1140 raeburn 9922: } else {
9923: $options{'cursoropacity'}='1.0';
9924: }
9925: if ($options{'cursorfixedheight'} eq 'none') {
9926: delete($options{'cursorfixedheight'});
9927: } else {
9928: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9929: }
9930: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9931: delete($options{'railoffset'});
9932: }
9933: my @niceoptions;
9934: while (my($key,$value) = each(%options)) {
9935: if ($value =~ /^\{.+\}$/) {
9936: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9937: } else {
1.1140 raeburn 9938: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9939: }
1.1140 raeburn 9940: }
9941: my $nicescroll_js = '
1.1137 raeburn 9942: $(document).ready(
1.1140 raeburn 9943: function() {
9944: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9945: }
1.1137 raeburn 9946: );
9947: ';
1.1140 raeburn 9948: if ($framecheck) {
9949: $nicescroll_js .= '
9950: function expand_div(caller) {
9951: if (top === self) {
9952: document.getElementById("'.$id.'").style.width = "auto";
9953: document.getElementById("'.$id.'").style.height = "auto";
9954: } else {
9955: try {
9956: if (parent.frames) {
9957: if (parent.frames.length > 1) {
9958: var framesrc = parent.frames[1].location.href;
9959: var currsrc = framesrc.replace(/\#.*$/,"");
9960: if ((caller == "search") || (currsrc == "'.$location.'")) {
9961: document.getElementById("'.$id.'").style.width = "auto";
9962: document.getElementById("'.$id.'").style.height = "auto";
9963: }
9964: }
9965: }
9966: } catch (e) {
9967: return;
9968: }
1.1137 raeburn 9969: }
1.1140 raeburn 9970: return;
1.996 www 9971: }
1.1140 raeburn 9972: ';
9973: }
9974: if ($needjsready) {
9975: $nicescroll_js = '
9976: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9977: } else {
9978: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9979: }
9980: return $nicescroll_js;
1.996 www 9981: }
9982:
1.318 albertel 9983: sub simple_error_page {
1.1150 bisitz 9984: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9985: my %displayargs;
1.1151 raeburn 9986: if (ref($args) eq 'HASH') {
9987: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9988: if ($args->{'only_body'}) {
9989: $displayargs{'only_body'} = 1;
9990: }
9991: if ($args->{'no_nav_bar'}) {
9992: $displayargs{'no_nav_bar'} = 1;
9993: }
1.1151 raeburn 9994: } else {
9995: $msg = &mt($msg);
9996: }
1.1150 bisitz 9997:
1.318 albertel 9998: my $page =
1.1304 raeburn 9999: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10000: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10001: &Apache::loncommon::end_page();
10002: if (ref($r)) {
10003: $r->print($page);
1.327 albertel 10004: return;
1.318 albertel 10005: }
10006: return $page;
10007: }
1.347 albertel 10008:
10009: {
1.610 albertel 10010: my @row_count;
1.961 onken 10011:
10012: sub start_data_table_count {
10013: unshift(@row_count, 0);
10014: return;
10015: }
10016:
10017: sub end_data_table_count {
10018: shift(@row_count);
10019: return;
10020: }
10021:
1.347 albertel 10022: sub start_data_table {
1.1018 raeburn 10023: my ($add_class,$id) = @_;
1.422 albertel 10024: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10025: my $table_id;
10026: if (defined($id)) {
10027: $table_id = ' id="'.$id.'"';
10028: }
1.961 onken 10029: &start_data_table_count();
1.1018 raeburn 10030: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10031: }
10032:
10033: sub end_data_table {
1.961 onken 10034: &end_data_table_count();
1.389 albertel 10035: return '</table>'."\n";;
1.347 albertel 10036: }
10037:
10038: sub start_data_table_row {
1.974 wenzelju 10039: my ($add_class, $id) = @_;
1.610 albertel 10040: $row_count[0]++;
10041: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10042: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10043: $id = (' id="'.$id.'"') unless ($id eq '');
10044: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10045: }
1.471 banghart 10046:
10047: sub continue_data_table_row {
1.974 wenzelju 10048: my ($add_class, $id) = @_;
1.610 albertel 10049: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10050: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10051: $id = (' id="'.$id.'"') unless ($id eq '');
10052: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10053: }
1.347 albertel 10054:
10055: sub end_data_table_row {
1.389 albertel 10056: return '</tr>'."\n";;
1.347 albertel 10057: }
1.367 www 10058:
1.421 albertel 10059: sub start_data_table_empty_row {
1.707 bisitz 10060: # $row_count[0]++;
1.421 albertel 10061: return '<tr class="LC_empty_row" >'."\n";;
10062: }
10063:
10064: sub end_data_table_empty_row {
10065: return '</tr>'."\n";;
10066: }
10067:
1.367 www 10068: sub start_data_table_header_row {
1.389 albertel 10069: return '<tr class="LC_header_row">'."\n";;
1.367 www 10070: }
10071:
10072: sub end_data_table_header_row {
1.389 albertel 10073: return '</tr>'."\n";;
1.367 www 10074: }
1.890 droeschl 10075:
10076: sub data_table_caption {
10077: my $caption = shift;
10078: return "<caption class=\"LC_caption\">$caption</caption>";
10079: }
1.347 albertel 10080: }
10081:
1.548 albertel 10082: =pod
10083:
10084: =item * &inhibit_menu_check($arg)
10085:
10086: Checks for a inhibitmenu state and generates output to preserve it
10087:
10088: Inputs: $arg - can be any of
10089: - undef - in which case the return value is a string
10090: to add into arguments list of a uri
10091: - 'input' - in which case the return value is a HTML
10092: <form> <input> field of type hidden to
10093: preserve the value
10094: - a url - in which case the return value is the url with
10095: the neccesary cgi args added to preserve the
10096: inhibitmenu state
10097: - a ref to a url - no return value, but the string is
10098: updated to include the neccessary cgi
10099: args to preserve the inhibitmenu state
10100:
10101: =cut
10102:
10103: sub inhibit_menu_check {
10104: my ($arg) = @_;
10105: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10106: if ($arg eq 'input') {
10107: if ($env{'form.inhibitmenu'}) {
10108: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10109: } else {
10110: return
10111: }
10112: }
10113: if ($env{'form.inhibitmenu'}) {
10114: if (ref($arg)) {
10115: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10116: } elsif ($arg eq '') {
10117: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10118: } else {
10119: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10120: }
10121: }
10122: if (!ref($arg)) {
10123: return $arg;
10124: }
10125: }
10126:
1.251 albertel 10127: ###############################################
1.182 matthew 10128:
10129: =pod
10130:
1.549 albertel 10131: =back
10132:
10133: =head1 User Information Routines
10134:
10135: =over 4
10136:
1.405 albertel 10137: =item * &get_users_function()
1.182 matthew 10138:
10139: Used by &bodytag to determine the current users primary role.
10140: Returns either 'student','coordinator','admin', or 'author'.
10141:
10142: =cut
10143:
10144: ###############################################
10145: sub get_users_function {
1.815 tempelho 10146: my $function = 'norole';
1.818 tempelho 10147: if ($env{'request.role'}=~/^(st)/) {
10148: $function='student';
10149: }
1.907 raeburn 10150: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10151: $function='coordinator';
10152: }
1.258 albertel 10153: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10154: $function='admin';
10155: }
1.826 bisitz 10156: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10157: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10158: $function='author';
10159: }
10160: return $function;
1.54 www 10161: }
1.99 www 10162:
10163: ###############################################
10164:
1.233 raeburn 10165: =pod
10166:
1.821 raeburn 10167: =item * &show_course()
10168:
10169: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10170: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10171:
10172: Inputs:
10173: None
10174:
10175: Outputs:
10176: Scalar: 1 if 'Course' to be used, 0 otherwise.
10177:
10178: =cut
10179:
10180: ###############################################
10181: sub show_course {
10182: my $course = !$env{'user.adv'};
10183: if (!$env{'user.adv'}) {
10184: foreach my $env (keys(%env)) {
10185: next if ($env !~ m/^user\.priv\./);
10186: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10187: $course = 0;
10188: last;
10189: }
10190: }
10191: }
10192: return $course;
10193: }
10194:
10195: ###############################################
10196:
10197: =pod
10198:
1.542 raeburn 10199: =item * &check_user_status()
1.274 raeburn 10200:
10201: Determines current status of supplied role for a
10202: specific user. Roles can be active, previous or future.
10203:
10204: Inputs:
10205: user's domain, user's username, course's domain,
1.375 raeburn 10206: course's number, optional section ID.
1.274 raeburn 10207:
10208: Outputs:
10209: role status: active, previous or future.
10210:
10211: =cut
10212:
10213: sub check_user_status {
1.412 raeburn 10214: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10215: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10216: my @uroles = keys(%userinfo);
1.274 raeburn 10217: my $srchstr;
10218: my $active_chk = 'none';
1.412 raeburn 10219: my $now = time;
1.274 raeburn 10220: if (@uroles > 0) {
1.908 raeburn 10221: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10222: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10223: } else {
1.412 raeburn 10224: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10225: }
10226: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10227: my $role_end = 0;
10228: my $role_start = 0;
10229: $active_chk = 'active';
1.412 raeburn 10230: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10231: $role_end = $1;
10232: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10233: $role_start = $1;
1.274 raeburn 10234: }
10235: }
10236: if ($role_start > 0) {
1.412 raeburn 10237: if ($now < $role_start) {
1.274 raeburn 10238: $active_chk = 'future';
10239: }
10240: }
10241: if ($role_end > 0) {
1.412 raeburn 10242: if ($now > $role_end) {
1.274 raeburn 10243: $active_chk = 'previous';
10244: }
10245: }
10246: }
10247: }
10248: return $active_chk;
10249: }
10250:
10251: ###############################################
10252:
10253: =pod
10254:
1.405 albertel 10255: =item * &get_sections()
1.233 raeburn 10256:
10257: Determines all the sections for a course including
10258: sections with students and sections containing other roles.
1.419 raeburn 10259: Incoming parameters:
10260:
10261: 1. domain
10262: 2. course number
10263: 3. reference to array containing roles for which sections should
10264: be gathered (optional).
10265: 4. reference to array containing status types for which sections
10266: should be gathered (optional).
10267:
10268: If the third argument is undefined, sections are gathered for any role.
10269: If the fourth argument is undefined, sections are gathered for any status.
10270: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10271:
1.374 raeburn 10272: Returns section hash (keys are section IDs, values are
10273: number of users in each section), subject to the
1.419 raeburn 10274: optional roles filter, optional status filter
1.233 raeburn 10275:
10276: =cut
10277:
10278: ###############################################
10279: sub get_sections {
1.419 raeburn 10280: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10281: if (!defined($cdom) || !defined($cnum)) {
10282: my $cid = $env{'request.course.id'};
10283:
10284: return if (!defined($cid));
10285:
10286: $cdom = $env{'course.'.$cid.'.domain'};
10287: $cnum = $env{'course.'.$cid.'.num'};
10288: }
10289:
10290: my %sectioncount;
1.419 raeburn 10291: my $now = time;
1.240 albertel 10292:
1.1118 raeburn 10293: my $check_students = 1;
10294: my $only_students = 0;
10295: if (ref($possible_roles) eq 'ARRAY') {
10296: if (grep(/^st$/,@{$possible_roles})) {
10297: if (@{$possible_roles} == 1) {
10298: $only_students = 1;
10299: }
10300: } else {
10301: $check_students = 0;
10302: }
10303: }
10304:
10305: if ($check_students) {
1.276 albertel 10306: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10307: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10308: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10309: my $start_index = &Apache::loncoursedata::CL_START();
10310: my $end_index = &Apache::loncoursedata::CL_END();
10311: my $status;
1.366 albertel 10312: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10313: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10314: $data->[$status_index],
10315: $data->[$start_index],
10316: $data->[$end_index]);
10317: if ($stu_status eq 'Active') {
10318: $status = 'active';
10319: } elsif ($end < $now) {
10320: $status = 'previous';
10321: } elsif ($start > $now) {
10322: $status = 'future';
10323: }
10324: if ($section ne '-1' && $section !~ /^\s*$/) {
10325: if ((!defined($possible_status)) || (($status ne '') &&
10326: (grep/^\Q$status\E$/,@{$possible_status}))) {
10327: $sectioncount{$section}++;
10328: }
1.240 albertel 10329: }
10330: }
10331: }
1.1118 raeburn 10332: if ($only_students) {
10333: return %sectioncount;
10334: }
1.240 albertel 10335: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10336: foreach my $user (sort(keys(%courseroles))) {
10337: if ($user !~ /^(\w{2})/) { next; }
10338: my ($role) = ($user =~ /^(\w{2})/);
10339: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10340: my ($section,$status);
1.240 albertel 10341: if ($role eq 'cr' &&
10342: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10343: $section=$1;
10344: }
10345: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10346: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10347: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10348: if ($end == -1 && $start == -1) {
10349: next; #deleted role
10350: }
10351: if (!defined($possible_status)) {
10352: $sectioncount{$section}++;
10353: } else {
10354: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10355: $status = 'active';
10356: } elsif ($end < $now) {
10357: $status = 'future';
10358: } elsif ($start > $now) {
10359: $status = 'previous';
10360: }
10361: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10362: $sectioncount{$section}++;
10363: }
10364: }
1.233 raeburn 10365: }
1.366 albertel 10366: return %sectioncount;
1.233 raeburn 10367: }
10368:
1.274 raeburn 10369: ###############################################
1.294 raeburn 10370:
10371: =pod
1.405 albertel 10372:
10373: =item * &get_course_users()
10374:
1.275 raeburn 10375: Retrieves usernames:domains for users in the specified course
10376: with specific role(s), and access status.
10377:
10378: Incoming parameters:
1.277 albertel 10379: 1. course domain
10380: 2. course number
10381: 3. access status: users must have - either active,
1.275 raeburn 10382: previous, future, or all.
1.277 albertel 10383: 4. reference to array of permissible roles
1.288 raeburn 10384: 5. reference to array of section restrictions (optional)
10385: 6. reference to results object (hash of hashes).
10386: 7. reference to optional userdata hash
1.609 raeburn 10387: 8. reference to optional statushash
1.630 raeburn 10388: 9. flag if privileged users (except those set to unhide in
10389: course settings) should be excluded
1.609 raeburn 10390: Keys of top level results hash are roles.
1.275 raeburn 10391: Keys of inner hashes are username:domain, with
10392: values set to access type.
1.288 raeburn 10393: Optional userdata hash returns an array with arguments in the
10394: same order as loncoursedata::get_classlist() for student data.
10395:
1.609 raeburn 10396: Optional statushash returns
10397:
1.288 raeburn 10398: Entries for end, start, section and status are blank because
10399: of the possibility of multiple values for non-student roles.
10400:
1.275 raeburn 10401: =cut
1.405 albertel 10402:
1.275 raeburn 10403: ###############################################
1.405 albertel 10404:
1.275 raeburn 10405: sub get_course_users {
1.630 raeburn 10406: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10407: my %idx = ();
1.419 raeburn 10408: my %seclists;
1.288 raeburn 10409:
10410: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10411: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10412: $idx{end} = &Apache::loncoursedata::CL_END();
10413: $idx{start} = &Apache::loncoursedata::CL_START();
10414: $idx{id} = &Apache::loncoursedata::CL_ID();
10415: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10416: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10417: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10418:
1.290 albertel 10419: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10420: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10421: my $now = time;
1.277 albertel 10422: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10423: my $match = 0;
1.412 raeburn 10424: my $secmatch = 0;
1.419 raeburn 10425: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10426: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10427: if ($section eq '') {
10428: $section = 'none';
10429: }
1.291 albertel 10430: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10431: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10432: $secmatch = 1;
10433: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10434: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10435: $secmatch = 1;
10436: }
10437: } else {
1.419 raeburn 10438: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10439: $secmatch = 1;
10440: }
1.290 albertel 10441: }
1.412 raeburn 10442: if (!$secmatch) {
10443: next;
10444: }
1.419 raeburn 10445: }
1.275 raeburn 10446: if (defined($$types{'active'})) {
1.288 raeburn 10447: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10448: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10449: $match = 1;
1.275 raeburn 10450: }
10451: }
10452: if (defined($$types{'previous'})) {
1.609 raeburn 10453: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10454: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10455: $match = 1;
1.275 raeburn 10456: }
10457: }
10458: if (defined($$types{'future'})) {
1.609 raeburn 10459: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10460: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10461: $match = 1;
1.275 raeburn 10462: }
10463: }
1.609 raeburn 10464: if ($match) {
10465: push(@{$seclists{$student}},$section);
10466: if (ref($userdata) eq 'HASH') {
10467: $$userdata{$student} = $$classlist{$student};
10468: }
10469: if (ref($statushash) eq 'HASH') {
10470: $statushash->{$student}{'st'}{$section} = $status;
10471: }
1.288 raeburn 10472: }
1.275 raeburn 10473: }
10474: }
1.412 raeburn 10475: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10476: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10477: my $now = time;
1.609 raeburn 10478: my %displaystatus = ( previous => 'Expired',
10479: active => 'Active',
10480: future => 'Future',
10481: );
1.1121 raeburn 10482: my (%nothide,@possdoms);
1.630 raeburn 10483: if ($hidepriv) {
10484: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10485: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10486: if ($user !~ /:/) {
10487: $nothide{join(':',split(/[\@]/,$user))}=1;
10488: } else {
10489: $nothide{$user} = 1;
10490: }
10491: }
1.1121 raeburn 10492: my @possdoms = ($cdom);
10493: if ($coursehash{'checkforpriv'}) {
10494: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10495: }
1.630 raeburn 10496: }
1.439 raeburn 10497: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10498: my $match = 0;
1.412 raeburn 10499: my $secmatch = 0;
1.439 raeburn 10500: my $status;
1.412 raeburn 10501: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10502: $user =~ s/:$//;
1.439 raeburn 10503: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10504: if ($end == -1 || $start == -1) {
10505: next;
10506: }
10507: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10508: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10509: my ($uname,$udom) = split(/:/,$user);
10510: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10511: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10512: $secmatch = 1;
10513: } elsif ($usec eq '') {
1.420 albertel 10514: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10515: $secmatch = 1;
10516: }
10517: } else {
10518: if (grep(/^\Q$usec\E$/,@{$sections})) {
10519: $secmatch = 1;
10520: }
10521: }
10522: if (!$secmatch) {
10523: next;
10524: }
1.288 raeburn 10525: }
1.419 raeburn 10526: if ($usec eq '') {
10527: $usec = 'none';
10528: }
1.275 raeburn 10529: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10530: if ($hidepriv) {
1.1121 raeburn 10531: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10532: (!$nothide{$uname.':'.$udom})) {
10533: next;
10534: }
10535: }
1.503 raeburn 10536: if ($end > 0 && $end < $now) {
1.439 raeburn 10537: $status = 'previous';
10538: } elsif ($start > $now) {
10539: $status = 'future';
10540: } else {
10541: $status = 'active';
10542: }
1.277 albertel 10543: foreach my $type (keys(%{$types})) {
1.275 raeburn 10544: if ($status eq $type) {
1.420 albertel 10545: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10546: push(@{$$users{$role}{$user}},$type);
10547: }
1.288 raeburn 10548: $match = 1;
10549: }
10550: }
1.419 raeburn 10551: if (($match) && (ref($userdata) eq 'HASH')) {
10552: if (!exists($$userdata{$uname.':'.$udom})) {
10553: &get_user_info($udom,$uname,\%idx,$userdata);
10554: }
1.420 albertel 10555: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10556: push(@{$seclists{$uname.':'.$udom}},$usec);
10557: }
1.609 raeburn 10558: if (ref($statushash) eq 'HASH') {
10559: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10560: }
1.275 raeburn 10561: }
10562: }
10563: }
10564: }
1.290 albertel 10565: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10566: if ((defined($cdom)) && (defined($cnum))) {
10567: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10568: if ( defined($csettings{'internal.courseowner'}) ) {
10569: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10570: next if ($owner eq '');
10571: my ($ownername,$ownerdom);
10572: if ($owner =~ /^([^:]+):([^:]+)$/) {
10573: $ownername = $1;
10574: $ownerdom = $2;
10575: } else {
10576: $ownername = $owner;
10577: $ownerdom = $cdom;
10578: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10579: }
10580: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10581: if (defined($userdata) &&
1.609 raeburn 10582: !exists($$userdata{$owner})) {
10583: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10584: if (!grep(/^none$/,@{$seclists{$owner}})) {
10585: push(@{$seclists{$owner}},'none');
10586: }
10587: if (ref($statushash) eq 'HASH') {
10588: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10589: }
1.290 albertel 10590: }
1.279 raeburn 10591: }
10592: }
10593: }
1.419 raeburn 10594: foreach my $user (keys(%seclists)) {
10595: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10596: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10597: }
1.275 raeburn 10598: }
10599: return;
10600: }
10601:
1.288 raeburn 10602: sub get_user_info {
10603: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10604: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10605: &plainname($uname,$udom,'lastname');
1.291 albertel 10606: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10607: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10608: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10609: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10610: return;
10611: }
1.275 raeburn 10612:
1.472 raeburn 10613: ###############################################
10614:
10615: =pod
10616:
10617: =item * &get_user_quota()
10618:
1.1134 raeburn 10619: Retrieves quota assigned for storage of user files.
10620: Default is to report quota for portfolio files.
1.472 raeburn 10621:
10622: Incoming parameters:
10623: 1. user's username
10624: 2. user's domain
1.1134 raeburn 10625: 3. quota name - portfolio, author, or course
1.1136 raeburn 10626: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10627: 4. crstype - official, unofficial, textbook, placement or community,
10628: if quota name is course
1.472 raeburn 10629:
10630: Returns:
1.1163 raeburn 10631: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10632: 2. (Optional) Type of setting: custom or default
10633: (individually assigned or default for user's
10634: institutional status).
10635: 3. (Optional) - User's institutional status (e.g., faculty, staff
10636: or student - types as defined in localenroll::inst_usertypes
10637: for user's domain, which determines default quota for user.
10638: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10639:
10640: If a value has been stored in the user's environment,
1.536 raeburn 10641: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10642: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10643:
10644: =cut
10645:
10646: ###############################################
10647:
10648:
10649: sub get_user_quota {
1.1136 raeburn 10650: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10651: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10652: if (!defined($udom)) {
10653: $udom = $env{'user.domain'};
10654: }
10655: if (!defined($uname)) {
10656: $uname = $env{'user.name'};
10657: }
10658: if (($udom eq '' || $uname eq '') ||
10659: ($udom eq 'public') && ($uname eq 'public')) {
10660: $quota = 0;
1.536 raeburn 10661: $quotatype = 'default';
10662: $defquota = 0;
1.472 raeburn 10663: } else {
1.536 raeburn 10664: my $inststatus;
1.1134 raeburn 10665: if ($quotaname eq 'course') {
10666: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10667: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10668: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10669: } else {
10670: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10671: $quota = $cenv{'internal.uploadquota'};
10672: }
1.536 raeburn 10673: } else {
1.1134 raeburn 10674: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10675: if ($quotaname eq 'author') {
10676: $quota = $env{'environment.authorquota'};
10677: } else {
10678: $quota = $env{'environment.portfolioquota'};
10679: }
10680: $inststatus = $env{'environment.inststatus'};
10681: } else {
10682: my %userenv =
10683: &Apache::lonnet::get('environment',['portfolioquota',
10684: 'authorquota','inststatus'],$udom,$uname);
10685: my ($tmp) = keys(%userenv);
10686: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10687: if ($quotaname eq 'author') {
10688: $quota = $userenv{'authorquota'};
10689: } else {
10690: $quota = $userenv{'portfolioquota'};
10691: }
10692: $inststatus = $userenv{'inststatus'};
10693: } else {
10694: undef(%userenv);
10695: }
10696: }
10697: }
10698: if ($quota eq '' || wantarray) {
10699: if ($quotaname eq 'course') {
10700: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10701: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10702: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10703: ($crstype eq 'placement')) {
1.1136 raeburn 10704: $defquota = $domdefs{$crstype.'quota'};
10705: }
10706: if ($defquota eq '') {
10707: $defquota = 500;
10708: }
1.1134 raeburn 10709: } else {
10710: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10711: }
10712: if ($quota eq '') {
10713: $quota = $defquota;
10714: $quotatype = 'default';
10715: } else {
10716: $quotatype = 'custom';
10717: }
1.472 raeburn 10718: }
10719: }
1.536 raeburn 10720: if (wantarray) {
10721: return ($quota,$quotatype,$settingstatus,$defquota);
10722: } else {
10723: return $quota;
10724: }
1.472 raeburn 10725: }
10726:
10727: ###############################################
10728:
10729: =pod
10730:
10731: =item * &default_quota()
10732:
1.536 raeburn 10733: Retrieves default quota assigned for storage of user portfolio files,
10734: given an (optional) user's institutional status.
1.472 raeburn 10735:
10736: Incoming parameters:
1.1142 raeburn 10737:
1.472 raeburn 10738: 1. domain
1.536 raeburn 10739: 2. (Optional) institutional status(es). This is a : separated list of
10740: status types (e.g., faculty, staff, student etc.)
10741: which apply to the user for whom the default is being retrieved.
10742: If the institutional status string in undefined, the domain
1.1134 raeburn 10743: default quota will be returned.
10744: 3. quota name - portfolio, author, or course
10745: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10746:
10747: Returns:
1.1142 raeburn 10748:
1.1163 raeburn 10749: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10750: 2. (Optional) institutional type which determined the value of the
10751: default quota.
1.472 raeburn 10752:
10753: If a value has been stored in the domain's configuration db,
10754: it will return that, otherwise it returns 20 (for backwards
10755: compatibility with domains which have not set up a configuration
1.1163 raeburn 10756: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10757:
1.536 raeburn 10758: If the user's status includes multiple types (e.g., staff and student),
10759: the largest default quota which applies to the user determines the
10760: default quota returned.
10761:
1.472 raeburn 10762: =cut
10763:
10764: ###############################################
10765:
10766:
10767: sub default_quota {
1.1134 raeburn 10768: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10769: my ($defquota,$settingstatus);
10770: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10771: ['quotas'],$udom);
1.1134 raeburn 10772: my $key = 'defaultquota';
10773: if ($quotaname eq 'author') {
10774: $key = 'authorquota';
10775: }
1.622 raeburn 10776: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10777: if ($inststatus ne '') {
1.765 raeburn 10778: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10779: foreach my $item (@statuses) {
1.1134 raeburn 10780: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10781: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10782: if ($defquota eq '') {
1.1134 raeburn 10783: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10784: $settingstatus = $item;
1.1134 raeburn 10785: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10786: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10787: $settingstatus = $item;
10788: }
10789: }
1.1134 raeburn 10790: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10791: if ($quotahash{'quotas'}{$item} ne '') {
10792: if ($defquota eq '') {
10793: $defquota = $quotahash{'quotas'}{$item};
10794: $settingstatus = $item;
10795: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10796: $defquota = $quotahash{'quotas'}{$item};
10797: $settingstatus = $item;
10798: }
1.536 raeburn 10799: }
10800: }
10801: }
10802: }
10803: if ($defquota eq '') {
1.1134 raeburn 10804: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10805: $defquota = $quotahash{'quotas'}{$key}{'default'};
10806: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10807: $defquota = $quotahash{'quotas'}{'default'};
10808: }
1.536 raeburn 10809: $settingstatus = 'default';
1.1139 raeburn 10810: if ($defquota eq '') {
10811: if ($quotaname eq 'author') {
10812: $defquota = 500;
10813: }
10814: }
1.536 raeburn 10815: }
10816: } else {
10817: $settingstatus = 'default';
1.1134 raeburn 10818: if ($quotaname eq 'author') {
10819: $defquota = 500;
10820: } else {
10821: $defquota = 20;
10822: }
1.536 raeburn 10823: }
10824: if (wantarray) {
10825: return ($defquota,$settingstatus);
1.472 raeburn 10826: } else {
1.536 raeburn 10827: return $defquota;
1.472 raeburn 10828: }
10829: }
10830:
1.1135 raeburn 10831: ###############################################
10832:
10833: =pod
10834:
1.1136 raeburn 10835: =item * &excess_filesize_warning()
1.1135 raeburn 10836:
10837: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10838: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10839: space to be exceeded.
1.1136 raeburn 10840:
10841: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10842: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10843:
1.1165 raeburn 10844: Inputs: 7
1.1136 raeburn 10845: 1. username or coursenum
1.1135 raeburn 10846: 2. domain
1.1136 raeburn 10847: 3. context ('author' or 'course')
1.1135 raeburn 10848: 4. filename of file for which action is being requested
10849: 5. filesize (kB) of file
10850: 6. action being taken: copy or upload.
1.1237 raeburn 10851: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10852:
10853: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10854: otherwise return null.
10855:
10856: =back
1.1135 raeburn 10857:
10858: =cut
10859:
1.1136 raeburn 10860: sub excess_filesize_warning {
1.1165 raeburn 10861: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10862: my $current_disk_usage = 0;
1.1165 raeburn 10863: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10864: if ($context eq 'author') {
10865: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10866: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10867: } else {
10868: foreach my $subdir ('docs','supplemental') {
10869: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10870: }
10871: }
1.1135 raeburn 10872: $disk_quota = int($disk_quota * 1000);
10873: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10874: return '<p class="LC_warning">'.
1.1135 raeburn 10875: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10876: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10877: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10878: $disk_quota,$current_disk_usage).
10879: '</p>';
10880: }
10881: return;
10882: }
10883:
10884: ###############################################
10885:
10886:
1.1136 raeburn 10887:
10888:
1.384 raeburn 10889: sub get_secgrprole_info {
10890: my ($cdom,$cnum,$needroles,$type) = @_;
10891: my %sections_count = &get_sections($cdom,$cnum);
10892: my @sections = (sort {$a <=> $b} keys(%sections_count));
10893: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10894: my @groups = sort(keys(%curr_groups));
10895: my $allroles = [];
10896: my $rolehash;
10897: my $accesshash = {
10898: active => 'Currently has access',
10899: future => 'Will have future access',
10900: previous => 'Previously had access',
10901: };
10902: if ($needroles) {
10903: $rolehash = {'all' => 'all'};
1.385 albertel 10904: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10905: if (&Apache::lonnet::error(%user_roles)) {
10906: undef(%user_roles);
10907: }
10908: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10909: my ($role)=split(/\:/,$item,2);
10910: if ($role eq 'cr') { next; }
10911: if ($role =~ /^cr/) {
10912: $$rolehash{$role} = (split('/',$role))[3];
10913: } else {
10914: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10915: }
10916: }
10917: foreach my $key (sort(keys(%{$rolehash}))) {
10918: push(@{$allroles},$key);
10919: }
10920: push (@{$allroles},'st');
10921: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10922: }
10923: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10924: }
10925:
1.555 raeburn 10926: sub user_picker {
1.1279 raeburn 10927: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10928: my $currdom = $dom;
1.1253 raeburn 10929: my @alldoms = &Apache::lonnet::all_domains();
10930: if (@alldoms == 1) {
10931: my %domsrch = &Apache::lonnet::get_dom('configuration',
10932: ['directorysrch'],$alldoms[0]);
10933: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10934: my $showdom = $domdesc;
10935: if ($showdom eq '') {
10936: $showdom = $dom;
10937: }
10938: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10939: if ((!$domsrch{'directorysrch'}{'available'}) &&
10940: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10941: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10942: }
10943: }
10944: }
1.555 raeburn 10945: my %curr_selected = (
10946: srchin => 'dom',
1.580 raeburn 10947: srchby => 'lastname',
1.555 raeburn 10948: );
10949: my $srchterm;
1.625 raeburn 10950: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10951: if ($srch->{'srchby'} ne '') {
10952: $curr_selected{'srchby'} = $srch->{'srchby'};
10953: }
10954: if ($srch->{'srchin'} ne '') {
10955: $curr_selected{'srchin'} = $srch->{'srchin'};
10956: }
10957: if ($srch->{'srchtype'} ne '') {
10958: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10959: }
10960: if ($srch->{'srchdomain'} ne '') {
10961: $currdom = $srch->{'srchdomain'};
10962: }
10963: $srchterm = $srch->{'srchterm'};
10964: }
1.1222 damieng 10965: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10966: 'usr' => 'Search criteria',
1.563 raeburn 10967: 'doma' => 'Domain/institution to search',
1.558 albertel 10968: 'uname' => 'username',
10969: 'lastname' => 'last name',
1.555 raeburn 10970: 'lastfirst' => 'last name, first name',
1.558 albertel 10971: 'crs' => 'in this course',
1.576 raeburn 10972: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10973: 'alc' => 'all LON-CAPA',
1.573 raeburn 10974: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10975: 'exact' => 'is',
10976: 'contains' => 'contains',
1.569 raeburn 10977: 'begins' => 'begins with',
1.1222 damieng 10978: );
10979: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10980: 'youm' => "You must include some text to search for.",
10981: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10982: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10983: 'yomc' => "You must choose a domain when using an institutional directory search.",
10984: 'ymcd' => "You must choose a domain when using a domain search.",
10985: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10986: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10987: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10988: );
1.1222 damieng 10989: &html_escape(\%html_lt);
10990: &js_escape(\%js_lt);
1.1255 raeburn 10991: my $domform;
1.1277 raeburn 10992: my $allow_blank = 1;
1.1255 raeburn 10993: if ($fixeddom) {
1.1277 raeburn 10994: $allow_blank = 0;
10995: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10996: } else {
1.1287 raeburn 10997: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10998: my ($trusted,$untrusted);
1.1287 raeburn 10999: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11000: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11001: } elsif ($context eq 'author') {
1.1288 raeburn 11002: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11003: } elsif ($context eq 'domain') {
1.1288 raeburn 11004: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11005: }
1.1288 raeburn 11006: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11007: }
1.563 raeburn 11008: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11009:
11010: my @srchins = ('crs','dom','alc','instd');
11011:
11012: foreach my $option (@srchins) {
11013: # FIXME 'alc' option unavailable until
11014: # loncreateuser::print_user_query_page()
11015: # has been completed.
11016: next if ($option eq 'alc');
1.880 raeburn 11017: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11018: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11019: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11020: if ($curr_selected{'srchin'} eq $option) {
11021: $srchinsel .= '
1.1222 damieng 11022: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11023: } else {
11024: $srchinsel .= '
1.1222 damieng 11025: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11026: }
1.555 raeburn 11027: }
1.563 raeburn 11028: $srchinsel .= "\n </select>\n";
1.555 raeburn 11029:
11030: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11031: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11032: if ($curr_selected{'srchby'} eq $option) {
11033: $srchbysel .= '
1.1222 damieng 11034: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11035: } else {
11036: $srchbysel .= '
1.1222 damieng 11037: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11038: }
11039: }
11040: $srchbysel .= "\n </select>\n";
11041:
11042: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11043: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11044: if ($curr_selected{'srchtype'} eq $option) {
11045: $srchtypesel .= '
1.1222 damieng 11046: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11047: } else {
11048: $srchtypesel .= '
1.1222 damieng 11049: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11050: }
11051: }
11052: $srchtypesel .= "\n </select>\n";
11053:
1.558 albertel 11054: my ($newuserscript,$new_user_create);
1.994 raeburn 11055: my $context_dom = $env{'request.role.domain'};
11056: if ($context eq 'requestcrs') {
11057: if ($env{'form.coursedom'} ne '') {
11058: $context_dom = $env{'form.coursedom'};
11059: }
11060: }
1.556 raeburn 11061: if ($forcenewuser) {
1.576 raeburn 11062: if (ref($srch) eq 'HASH') {
1.994 raeburn 11063: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11064: if ($cancreate) {
11065: $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>';
11066: } else {
1.799 bisitz 11067: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11068: my %usertypetext = (
11069: official => 'institutional',
11070: unofficial => 'non-institutional',
11071: );
1.799 bisitz 11072: $new_user_create = '<p class="LC_warning">'
11073: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11074: .' '
11075: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11076: ,'<a href="'.$helplink.'">','</a>')
11077: .'</p><br />';
1.627 raeburn 11078: }
1.576 raeburn 11079: }
11080: }
11081:
1.556 raeburn 11082: $newuserscript = <<"ENDSCRIPT";
11083:
1.570 raeburn 11084: function setSearch(createnew,callingForm) {
1.556 raeburn 11085: if (createnew == 1) {
1.570 raeburn 11086: for (var i=0; i<callingForm.srchby.length; i++) {
11087: if (callingForm.srchby.options[i].value == 'uname') {
11088: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11089: }
11090: }
1.570 raeburn 11091: for (var i=0; i<callingForm.srchin.length; i++) {
11092: if ( callingForm.srchin.options[i].value == 'dom') {
11093: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11094: }
11095: }
1.570 raeburn 11096: for (var i=0; i<callingForm.srchtype.length; i++) {
11097: if (callingForm.srchtype.options[i].value == 'exact') {
11098: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11099: }
11100: }
1.570 raeburn 11101: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11102: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11103: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11104: }
11105: }
11106: }
11107: }
11108: ENDSCRIPT
1.558 albertel 11109:
1.556 raeburn 11110: }
11111:
1.555 raeburn 11112: my $output = <<"END_BLOCK";
1.556 raeburn 11113: <script type="text/javascript">
1.824 bisitz 11114: // <![CDATA[
1.570 raeburn 11115: function validateEntry(callingForm) {
1.558 albertel 11116:
1.556 raeburn 11117: var checkok = 1;
1.558 albertel 11118: var srchin;
1.570 raeburn 11119: for (var i=0; i<callingForm.srchin.length; i++) {
11120: if ( callingForm.srchin[i].checked ) {
11121: srchin = callingForm.srchin[i].value;
1.558 albertel 11122: }
11123: }
11124:
1.570 raeburn 11125: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11126: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11127: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11128: var srchterm = callingForm.srchterm.value;
11129: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11130: var msg = "";
11131:
11132: if (srchterm == "") {
11133: checkok = 0;
1.1222 damieng 11134: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11135: }
11136:
1.569 raeburn 11137: if (srchtype== 'begins') {
11138: if (srchterm.length < 2) {
11139: checkok = 0;
1.1222 damieng 11140: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11141: }
11142: }
11143:
1.556 raeburn 11144: if (srchtype== 'contains') {
11145: if (srchterm.length < 3) {
11146: checkok = 0;
1.1222 damieng 11147: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11148: }
11149: }
11150: if (srchin == 'instd') {
11151: if (srchdomain == '') {
11152: checkok = 0;
1.1222 damieng 11153: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11154: }
11155: }
11156: if (srchin == 'dom') {
11157: if (srchdomain == '') {
11158: checkok = 0;
1.1222 damieng 11159: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11160: }
11161: }
11162: if (srchby == 'lastfirst') {
11163: if (srchterm.indexOf(",") == -1) {
11164: checkok = 0;
1.1222 damieng 11165: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11166: }
11167: if (srchterm.indexOf(",") == srchterm.length -1) {
11168: checkok = 0;
1.1222 damieng 11169: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11170: }
11171: }
11172: if (checkok == 0) {
1.1222 damieng 11173: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11174: return;
11175: }
11176: if (checkok == 1) {
1.570 raeburn 11177: callingForm.submit();
1.556 raeburn 11178: }
11179: }
11180:
11181: $newuserscript
11182:
1.824 bisitz 11183: // ]]>
1.556 raeburn 11184: </script>
1.558 albertel 11185:
11186: $new_user_create
11187:
1.555 raeburn 11188: END_BLOCK
1.558 albertel 11189:
1.876 raeburn 11190: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11191: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11192: $domform.
11193: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11194: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11195: $srchbysel.
11196: $srchtypesel.
11197: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11198: $srchinsel.
11199: &Apache::lonhtmlcommon::row_closure(1).
11200: &Apache::lonhtmlcommon::end_pick_box().
11201: '<br />';
1.1253 raeburn 11202: return ($output,1);
1.555 raeburn 11203: }
11204:
1.612 raeburn 11205: sub user_rule_check {
1.615 raeburn 11206: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11207: my ($response,%inst_response);
1.612 raeburn 11208: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11209: if (keys(%{$usershash}) > 1) {
11210: my (%by_username,%by_id,%userdoms);
11211: my $checkid;
11212: if (ref($checks) eq 'HASH') {
11213: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11214: $checkid = 1;
11215: }
11216: }
11217: foreach my $user (keys(%{$usershash})) {
11218: my ($uname,$udom) = split(/:/,$user);
11219: if ($checkid) {
11220: if (ref($usershash->{$user}) eq 'HASH') {
11221: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11222: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11223: $userdoms{$udom} = 1;
1.1227 raeburn 11224: if (ref($inst_results) eq 'HASH') {
11225: $inst_results->{$uname.':'.$udom} = {};
11226: }
1.1226 raeburn 11227: }
11228: }
11229: } else {
11230: $by_username{$udom}{$uname} = 1;
11231: $userdoms{$udom} = 1;
1.1227 raeburn 11232: if (ref($inst_results) eq 'HASH') {
11233: $inst_results->{$uname.':'.$udom} = {};
11234: }
1.1226 raeburn 11235: }
11236: }
11237: foreach my $udom (keys(%userdoms)) {
11238: if (!$got_rules->{$udom}) {
11239: my %domconfig = &Apache::lonnet::get_dom('configuration',
11240: ['usercreation'],$udom);
11241: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11242: foreach my $item ('username','id') {
11243: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11244: $$curr_rules{$udom}{$item} =
11245: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11246: }
11247: }
11248: }
11249: $got_rules->{$udom} = 1;
11250: }
1.612 raeburn 11251: }
1.1226 raeburn 11252: if ($checkid) {
11253: foreach my $udom (keys(%by_id)) {
11254: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11255: if ($outcome eq 'ok') {
1.1227 raeburn 11256: foreach my $id (keys(%{$by_id{$udom}})) {
11257: my $uname = $by_id{$udom}{$id};
11258: $inst_response{$uname.':'.$udom} = $outcome;
11259: }
1.1226 raeburn 11260: if (ref($results) eq 'HASH') {
11261: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11262: if (exists($inst_response{$uname.':'.$udom})) {
11263: $inst_response{$uname.':'.$udom} = $outcome;
11264: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11265: }
1.1226 raeburn 11266: }
11267: }
11268: }
1.612 raeburn 11269: }
1.615 raeburn 11270: } else {
1.1226 raeburn 11271: foreach my $udom (keys(%by_username)) {
11272: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11273: if ($outcome eq 'ok') {
1.1227 raeburn 11274: foreach my $uname (keys(%{$by_username{$udom}})) {
11275: $inst_response{$uname.':'.$udom} = $outcome;
11276: }
1.1226 raeburn 11277: if (ref($results) eq 'HASH') {
11278: foreach my $uname (keys(%{$results})) {
11279: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11280: }
11281: }
11282: }
11283: }
1.612 raeburn 11284: }
1.1226 raeburn 11285: } elsif (keys(%{$usershash}) == 1) {
11286: my $user = (keys(%{$usershash}))[0];
11287: my ($uname,$udom) = split(/:/,$user);
11288: if (($udom ne '') && ($uname ne '')) {
11289: if (ref($usershash->{$user}) eq 'HASH') {
11290: if (ref($checks) eq 'HASH') {
11291: if (defined($checks->{'username'})) {
11292: ($inst_response{$user},%{$inst_results->{$user}}) =
11293: &Apache::lonnet::get_instuser($udom,$uname);
11294: } elsif (defined($checks->{'id'})) {
11295: if ($usershash->{$user}->{'id'} ne '') {
11296: ($inst_response{$user},%{$inst_results->{$user}}) =
11297: &Apache::lonnet::get_instuser($udom,undef,
11298: $usershash->{$user}->{'id'});
11299: } else {
11300: ($inst_response{$user},%{$inst_results->{$user}}) =
11301: &Apache::lonnet::get_instuser($udom,$uname);
11302: }
1.585 raeburn 11303: }
1.1226 raeburn 11304: } else {
11305: ($inst_response{$user},%{$inst_results->{$user}}) =
11306: &Apache::lonnet::get_instuser($udom,$uname);
11307: return;
11308: }
11309: if (!$got_rules->{$udom}) {
11310: my %domconfig = &Apache::lonnet::get_dom('configuration',
11311: ['usercreation'],$udom);
11312: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11313: foreach my $item ('username','id') {
11314: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11315: $$curr_rules{$udom}{$item} =
11316: $domconfig{'usercreation'}{$item.'_rule'};
11317: }
11318: }
11319: }
11320: $got_rules->{$udom} = 1;
1.585 raeburn 11321: }
11322: }
1.1226 raeburn 11323: } else {
11324: return;
11325: }
11326: } else {
11327: return;
11328: }
11329: foreach my $user (keys(%{$usershash})) {
11330: my ($uname,$udom) = split(/:/,$user);
11331: next if (($udom eq '') || ($uname eq ''));
11332: my $id;
1.1227 raeburn 11333: if (ref($inst_results) eq 'HASH') {
11334: if (ref($inst_results->{$user}) eq 'HASH') {
11335: $id = $inst_results->{$user}->{'id'};
11336: }
11337: }
11338: if ($id eq '') {
11339: if (ref($usershash->{$user})) {
11340: $id = $usershash->{$user}->{'id'};
11341: }
1.585 raeburn 11342: }
1.612 raeburn 11343: foreach my $item (keys(%{$checks})) {
11344: if (ref($$curr_rules{$udom}) eq 'HASH') {
11345: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11346: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11347: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11348: $$curr_rules{$udom}{$item});
1.612 raeburn 11349: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11350: if ($rule_check{$rule}) {
11351: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11352: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11353: if (ref($inst_results) eq 'HASH') {
11354: if (ref($inst_results->{$user}) eq 'HASH') {
11355: if (keys(%{$inst_results->{$user}}) == 0) {
11356: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11357: } elsif ($item eq 'id') {
11358: if ($inst_results->{$user}->{'id'} eq '') {
11359: $$alerts{$item}{$udom}{$uname} = 1;
11360: }
1.615 raeburn 11361: }
1.612 raeburn 11362: }
11363: }
1.615 raeburn 11364: }
11365: last;
1.585 raeburn 11366: }
11367: }
11368: }
11369: }
11370: }
11371: }
11372: }
11373: }
1.612 raeburn 11374: return;
11375: }
11376:
11377: sub user_rule_formats {
11378: my ($domain,$domdesc,$curr_rules,$check) = @_;
11379: my %text = (
11380: 'username' => 'Usernames',
11381: 'id' => 'IDs',
11382: );
11383: my $output;
11384: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11385: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11386: if (@{$ruleorder} > 0) {
1.1102 raeburn 11387: $output = '<br />'.
11388: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11389: '<span class="LC_cusr_emph">','</span>',$domdesc).
11390: ' <ul>';
1.612 raeburn 11391: foreach my $rule (@{$ruleorder}) {
11392: if (ref($curr_rules) eq 'ARRAY') {
11393: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11394: if (ref($rules->{$rule}) eq 'HASH') {
11395: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11396: $rules->{$rule}{'desc'}.'</li>';
11397: }
11398: }
11399: }
11400: }
11401: $output .= '</ul>';
11402: }
11403: }
11404: return $output;
11405: }
11406:
11407: sub instrule_disallow_msg {
1.615 raeburn 11408: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11409: my $response;
11410: my %text = (
11411: item => 'username',
11412: items => 'usernames',
11413: match => 'matches',
11414: do => 'does',
11415: action => 'a username',
11416: one => 'one',
11417: );
11418: if ($count > 1) {
11419: $text{'item'} = 'usernames';
11420: $text{'match'} ='match';
11421: $text{'do'} = 'do';
11422: $text{'action'} = 'usernames',
11423: $text{'one'} = 'ones';
11424: }
11425: if ($checkitem eq 'id') {
11426: $text{'items'} = 'IDs';
11427: $text{'item'} = 'ID';
11428: $text{'action'} = 'an ID';
1.615 raeburn 11429: if ($count > 1) {
11430: $text{'item'} = 'IDs';
11431: $text{'action'} = 'IDs';
11432: }
1.612 raeburn 11433: }
1.674 bisitz 11434: $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 11435: if ($mode eq 'upload') {
11436: if ($checkitem eq 'username') {
11437: $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'}.");
11438: } elsif ($checkitem eq 'id') {
1.674 bisitz 11439: $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 11440: }
1.669 raeburn 11441: } elsif ($mode eq 'selfcreate') {
11442: if ($checkitem eq 'id') {
11443: $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.");
11444: }
1.615 raeburn 11445: } else {
11446: if ($checkitem eq 'username') {
11447: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11448: } elsif ($checkitem eq 'id') {
11449: $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.");
11450: }
1.612 raeburn 11451: }
11452: return $response;
1.585 raeburn 11453: }
11454:
1.624 raeburn 11455: sub personal_data_fieldtitles {
11456: my %fieldtitles = &Apache::lonlocal::texthash (
11457: id => 'Student/Employee ID',
11458: permanentemail => 'E-mail address',
11459: lastname => 'Last Name',
11460: firstname => 'First Name',
11461: middlename => 'Middle Name',
11462: generation => 'Generation',
11463: gen => 'Generation',
1.765 raeburn 11464: inststatus => 'Affiliation',
1.624 raeburn 11465: );
11466: return %fieldtitles;
11467: }
11468:
1.642 raeburn 11469: sub sorted_inst_types {
11470: my ($dom) = @_;
1.1185 raeburn 11471: my ($usertypes,$order);
11472: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11473: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11474: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11475: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11476: } else {
11477: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11478: }
1.642 raeburn 11479: my $othertitle = &mt('All users');
11480: if ($env{'request.course.id'}) {
1.668 raeburn 11481: $othertitle = &mt('Any users');
1.642 raeburn 11482: }
11483: my @types;
11484: if (ref($order) eq 'ARRAY') {
11485: @types = @{$order};
11486: }
11487: if (@types == 0) {
11488: if (ref($usertypes) eq 'HASH') {
11489: @types = sort(keys(%{$usertypes}));
11490: }
11491: }
11492: if (keys(%{$usertypes}) > 0) {
11493: $othertitle = &mt('Other users');
11494: }
11495: return ($othertitle,$usertypes,\@types);
11496: }
11497:
1.645 raeburn 11498: sub get_institutional_codes {
1.1361 raeburn 11499: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11500: # Get complete list of course sections to update
11501: my @currsections = ();
11502: my @currxlists = ();
1.1361 raeburn 11503: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11504: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11505: my $crskey = $crs.':'.$coursecode;
11506: @{$unclutteredsec{$crskey}} = ();
11507: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11508:
11509: if ($$settings{'internal.sectionnums'} ne '') {
11510: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11511: }
11512:
11513: if ($$settings{'internal.crosslistings'} ne '') {
11514: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11515: }
11516:
11517: if (@currxlists > 0) {
1.1361 raeburn 11518: foreach my $xl (@currxlists) {
11519: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11520: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11521: push(@{$allcourses},$1);
1.645 raeburn 11522: $$LC_code{$1} = $2;
11523: }
11524: }
11525: }
11526: }
1.1361 raeburn 11527:
1.645 raeburn 11528: if (@currsections > 0) {
1.1361 raeburn 11529: foreach my $sec (@currsections) {
11530: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11531: my $instsec = $1;
1.645 raeburn 11532: my $lc_sec = $2;
1.1361 raeburn 11533: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11534: push(@{$unclutteredsec{$crskey}},$instsec);
11535: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11536: }
11537: }
11538: }
11539: }
11540:
11541: if (@{$unclutteredsec{$crskey}} > 0) {
11542: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11543: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11544: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11545: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11546: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11547: push(@{$allcourses},$sec);
1.1361 raeburn 11548: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11549: }
11550: }
11551: }
11552: }
11553: return;
11554: }
11555:
1.971 raeburn 11556: sub get_standard_codeitems {
11557: return ('Year','Semester','Department','Number','Section');
11558: }
11559:
1.112 bowersj2 11560: =pod
11561:
1.780 raeburn 11562: =head1 Slot Helpers
11563:
11564: =over 4
11565:
11566: =item * sorted_slots()
11567:
1.1040 raeburn 11568: Sorts an array of slot names in order of an optional sort key,
11569: default sort is by slot start time (earliest first).
1.780 raeburn 11570:
11571: Inputs:
11572:
11573: =over 4
11574:
11575: slotsarr - Reference to array of unsorted slot names.
11576:
11577: slots - Reference to hash of hash, where outer hash keys are slot names.
11578:
1.1040 raeburn 11579: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11580:
1.549 albertel 11581: =back
11582:
1.780 raeburn 11583: Returns:
11584:
11585: =over 4
11586:
1.1040 raeburn 11587: sorted - An array of slot names sorted by a specified sort key
11588: (default sort key is start time of the slot).
1.780 raeburn 11589:
11590: =back
11591:
11592: =cut
11593:
11594:
11595: sub sorted_slots {
1.1040 raeburn 11596: my ($slotsarr,$slots,$sortkey) = @_;
11597: if ($sortkey eq '') {
11598: $sortkey = 'starttime';
11599: }
1.780 raeburn 11600: my @sorted;
11601: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11602: @sorted =
11603: sort {
11604: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11605: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11606: }
11607: if (ref($slots->{$a})) { return -1;}
11608: if (ref($slots->{$b})) { return 1;}
11609: return 0;
11610: } @{$slotsarr};
11611: }
11612: return @sorted;
11613: }
11614:
1.1040 raeburn 11615: =pod
11616:
11617: =item * get_future_slots()
11618:
11619: Inputs:
11620:
11621: =over 4
11622:
11623: cnum - course number
11624:
11625: cdom - course domain
11626:
11627: now - current UNIX time
11628:
11629: symb - optional symb
11630:
11631: =back
11632:
11633: Returns:
11634:
11635: =over 4
11636:
11637: sorted_reservable - ref to array of student_schedulable slots currently
11638: reservable, ordered by end date of reservation period.
11639:
11640: reservable_now - ref to hash of student_schedulable slots currently
11641: reservable.
11642:
11643: Keys in inner hash are:
11644: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11645: (b) endreserve: end date of reservation period.
11646: (c) uniqueperiod: start,end dates when slot is to be uniquely
11647: selected.
1.1040 raeburn 11648:
11649: sorted_future - ref to array of student_schedulable slots reservable in
11650: the future, ordered by start date of reservation period.
11651:
11652: future_reservable - ref to hash of student_schedulable slots reservable
11653: in the future.
11654:
11655: Keys in inner hash are:
11656: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11657: (b) startreserve: start date of reservation period.
11658: (c) uniqueperiod: start,end dates when slot is to be uniquely
11659: selected.
1.1040 raeburn 11660:
11661: =back
11662:
11663: =cut
11664:
11665: sub get_future_slots {
11666: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11667: my $map;
11668: if ($symb) {
11669: ($map) = &Apache::lonnet::decode_symb($symb);
11670: }
1.1040 raeburn 11671: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11672: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11673: foreach my $slot (keys(%slots)) {
11674: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11675: if ($symb) {
1.1229 raeburn 11676: if ($slots{$slot}->{'symb'} ne '') {
11677: my $canuse;
11678: my %oksymbs;
11679: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11680: map { $oksymbs{$_} = 1; } @slotsymbs;
11681: if ($oksymbs{$symb}) {
11682: $canuse = 1;
11683: } else {
11684: foreach my $item (@slotsymbs) {
11685: if ($item =~ /\.(page|sequence)$/) {
11686: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11687: if (($map ne '') && ($map eq $sloturl)) {
11688: $canuse = 1;
11689: last;
11690: }
11691: }
11692: }
11693: }
11694: next unless ($canuse);
11695: }
1.1040 raeburn 11696: }
11697: if (($slots{$slot}->{'starttime'} > $now) &&
11698: ($slots{$slot}->{'endtime'} > $now)) {
11699: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11700: my $userallowed = 0;
11701: if ($slots{$slot}->{'allowedsections'}) {
11702: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11703: if (!defined($env{'request.role.sec'})
11704: && grep(/^No section assigned$/,@allowed_sec)) {
11705: $userallowed=1;
11706: } else {
11707: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11708: $userallowed=1;
11709: }
11710: }
11711: unless ($userallowed) {
11712: if (defined($env{'request.course.groups'})) {
11713: my @groups = split(/:/,$env{'request.course.groups'});
11714: foreach my $group (@groups) {
11715: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11716: $userallowed=1;
11717: last;
11718: }
11719: }
11720: }
11721: }
11722: }
11723: if ($slots{$slot}->{'allowedusers'}) {
11724: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11725: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11726: if (grep(/^\Q$user\E$/,@allowed_users)) {
11727: $userallowed = 1;
11728: }
11729: }
11730: next unless($userallowed);
11731: }
11732: my $startreserve = $slots{$slot}->{'startreserve'};
11733: my $endreserve = $slots{$slot}->{'endreserve'};
11734: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11735: my $uniqueperiod;
11736: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11737: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11738: }
1.1040 raeburn 11739: if (($startreserve < $now) &&
11740: (!$endreserve || $endreserve > $now)) {
11741: my $lastres = $endreserve;
11742: if (!$lastres) {
11743: $lastres = $slots{$slot}->{'starttime'};
11744: }
11745: $reservable_now{$slot} = {
11746: symb => $symb,
1.1250 raeburn 11747: endreserve => $lastres,
11748: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11749: };
11750: } elsif (($startreserve > $now) &&
11751: (!$endreserve || $endreserve > $startreserve)) {
11752: $future_reservable{$slot} = {
11753: symb => $symb,
1.1250 raeburn 11754: startreserve => $startreserve,
11755: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11756: };
11757: }
11758: }
11759: }
11760: my @unsorted_reservable = keys(%reservable_now);
11761: if (@unsorted_reservable > 0) {
11762: @sorted_reservable =
11763: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11764: }
11765: my @unsorted_future = keys(%future_reservable);
11766: if (@unsorted_future > 0) {
11767: @sorted_future =
11768: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11769: }
11770: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11771: }
1.780 raeburn 11772:
11773: =pod
11774:
1.1057 foxr 11775: =back
11776:
1.549 albertel 11777: =head1 HTTP Helpers
11778:
11779: =over 4
11780:
1.648 raeburn 11781: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11782:
1.258 albertel 11783: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11784: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11785: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11786:
11787: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11788: $possible_names is an ref to an array of form element names. As an example:
11789: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11790: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11791:
11792: =cut
1.1 albertel 11793:
1.6 albertel 11794: sub get_unprocessed_cgi {
1.25 albertel 11795: my ($query,$possible_names)= @_;
1.26 matthew 11796: # $Apache::lonxml::debug=1;
1.356 albertel 11797: foreach my $pair (split(/&/,$query)) {
11798: my ($name, $value) = split(/=/,$pair);
1.369 www 11799: $name = &unescape($name);
1.25 albertel 11800: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11801: $value =~ tr/+/ /;
11802: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11803: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11804: }
1.16 harris41 11805: }
1.6 albertel 11806: }
11807:
1.112 bowersj2 11808: =pod
11809:
1.648 raeburn 11810: =item * &cacheheader()
1.112 bowersj2 11811:
11812: returns cache-controlling header code
11813:
11814: =cut
11815:
1.7 albertel 11816: sub cacheheader {
1.258 albertel 11817: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11818: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11819: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11820: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11821: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11822: return $output;
1.7 albertel 11823: }
11824:
1.112 bowersj2 11825: =pod
11826:
1.648 raeburn 11827: =item * &no_cache($r)
1.112 bowersj2 11828:
11829: specifies header code to not have cache
11830:
11831: =cut
11832:
1.9 albertel 11833: sub no_cache {
1.216 albertel 11834: my ($r) = @_;
11835: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11836: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11837: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11838: $r->no_cache(1);
11839: $r->header_out("Expires" => $date);
11840: $r->header_out("Pragma" => "no-cache");
1.123 www 11841: }
11842:
11843: sub content_type {
1.181 albertel 11844: my ($r,$type,$charset) = @_;
1.299 foxr 11845: if ($r) {
11846: # Note that printout.pl calls this with undef for $r.
11847: &no_cache($r);
11848: }
1.258 albertel 11849: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11850: unless ($charset) {
11851: $charset=&Apache::lonlocal::current_encoding;
11852: }
11853: if ($charset) { $type.='; charset='.$charset; }
11854: if ($r) {
11855: $r->content_type($type);
11856: } else {
11857: print("Content-type: $type\n\n");
11858: }
1.9 albertel 11859: }
1.25 albertel 11860:
1.112 bowersj2 11861: =pod
11862:
1.648 raeburn 11863: =item * &add_to_env($name,$value)
1.112 bowersj2 11864:
1.258 albertel 11865: adds $name to the %env hash with value
1.112 bowersj2 11866: $value, if $name already exists, the entry is converted to an array
11867: reference and $value is added to the array.
11868:
11869: =cut
11870:
1.25 albertel 11871: sub add_to_env {
11872: my ($name,$value)=@_;
1.258 albertel 11873: if (defined($env{$name})) {
11874: if (ref($env{$name})) {
1.25 albertel 11875: #already have multiple values
1.258 albertel 11876: push(@{ $env{$name} },$value);
1.25 albertel 11877: } else {
11878: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11879: my $first=$env{$name};
11880: undef($env{$name});
11881: push(@{ $env{$name} },$first,$value);
1.25 albertel 11882: }
11883: } else {
1.258 albertel 11884: $env{$name}=$value;
1.25 albertel 11885: }
1.31 albertel 11886: }
1.149 albertel 11887:
11888: =pod
11889:
1.648 raeburn 11890: =item * &get_env_multiple($name)
1.149 albertel 11891:
1.258 albertel 11892: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11893: values may be defined and end up as an array ref.
11894:
11895: returns an array of values
11896:
11897: =cut
11898:
11899: sub get_env_multiple {
11900: my ($name) = @_;
11901: my @values;
1.258 albertel 11902: if (defined($env{$name})) {
1.149 albertel 11903: # exists is it an array
1.258 albertel 11904: if (ref($env{$name})) {
11905: @values=@{ $env{$name} };
1.149 albertel 11906: } else {
1.258 albertel 11907: $values[0]=$env{$name};
1.149 albertel 11908: }
11909: }
11910: return(@values);
11911: }
11912:
1.1249 damieng 11913: # Looks at given dependencies, and returns something depending on the context.
11914: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11915: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11916: # For all other contexts, returns ($output, $counter, $numpathchg).
11917: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11918: # $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
11919: # $numpathchg: integer with the number of cleaned up dependency paths.
11920: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11921: # \%mapping: hash reference clean path -> original path for all dependencies.
11922: # @param {string} actionurl - The path to the handler, indicative of the context.
11923: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11924: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11925: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11926: # @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
11927: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11928: sub ask_for_embedded_content {
1.1249 damieng 11929: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11930: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11931: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11932: %currsubfile,%unused,$rem);
1.1071 raeburn 11933: my $counter = 0;
11934: my $numnew = 0;
1.987 raeburn 11935: my $numremref = 0;
11936: my $numinvalid = 0;
11937: my $numpathchg = 0;
11938: my $numexisting = 0;
1.1071 raeburn 11939: my $numunused = 0;
11940: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11941: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11942: my $heading = &mt('Upload embedded files');
11943: my $buttontext = &mt('Upload');
11944:
1.1249 damieng 11945: # fills these variables based on the context:
11946: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11947: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11948: if ($env{'request.course.id'}) {
1.1123 raeburn 11949: if ($actionurl eq '/adm/dependencies') {
11950: $navmap = Apache::lonnavmaps::navmap->new();
11951: }
11952: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11953: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11954: }
1.1123 raeburn 11955: if (($actionurl eq '/adm/portfolio') ||
11956: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11957: my $current_path='/';
11958: if ($env{'form.currentpath'}) {
11959: $current_path = $env{'form.currentpath'};
11960: }
11961: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11962: $udom = $cdom;
11963: $uname = $cnum;
1.984 raeburn 11964: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11965: } else {
11966: $udom = $env{'user.domain'};
11967: $uname = $env{'user.name'};
11968: $url = '/userfiles/portfolio';
11969: }
1.987 raeburn 11970: $toplevel = $url.'/';
1.984 raeburn 11971: $url .= $current_path;
11972: $getpropath = 1;
1.987 raeburn 11973: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11974: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11975: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11976: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11977: $toplevel = $url;
1.984 raeburn 11978: if ($rest ne '') {
1.987 raeburn 11979: $url .= $rest;
11980: }
11981: } elsif ($actionurl eq '/adm/coursedocs') {
11982: if (ref($args) eq 'HASH') {
1.1071 raeburn 11983: $url = $args->{'docs_url'};
11984: $toplevel = $url;
1.1084 raeburn 11985: if ($args->{'context'} eq 'paste') {
11986: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11987: ($path) =
11988: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11989: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11990: $fileloc =~ s{^/}{};
11991: }
1.1071 raeburn 11992: }
1.1084 raeburn 11993: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11994: if ($env{'request.course.id'} ne '') {
11995: if (ref($args) eq 'HASH') {
11996: $url = $args->{'docs_url'};
11997: $title = $args->{'docs_title'};
1.1126 raeburn 11998: $toplevel = $url;
11999: unless ($toplevel =~ m{^/}) {
12000: $toplevel = "/$url";
12001: }
1.1085 raeburn 12002: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12003: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12004: $path = $1;
12005: } else {
12006: ($path) =
12007: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12008: }
1.1195 raeburn 12009: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12010: $fileloc = $toplevel;
12011: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12012: my ($udom,$uname,$fname) =
12013: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12014: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12015: } else {
12016: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12017: }
1.1071 raeburn 12018: $fileloc =~ s{^/}{};
12019: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12020: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12021: }
1.987 raeburn 12022: }
1.1123 raeburn 12023: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12024: $udom = $cdom;
12025: $uname = $cnum;
12026: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12027: $toplevel = $url;
12028: $path = $url;
12029: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12030: $fileloc =~ s{^/}{};
1.987 raeburn 12031: }
1.1249 damieng 12032:
12033: # parses the dependency paths to get some info
12034: # fills $newfiles, $mapping, $subdependencies, $dependencies
12035: # $newfiles: hash URL -> 1 for new files or external URLs
12036: # (will be completed later)
12037: # $mapping:
12038: # for external URLs: external URL -> external URL
12039: # for relative paths: clean path -> original path
12040: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12041: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12042: foreach my $file (keys(%{$allfiles})) {
12043: my $embed_file;
12044: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12045: $embed_file = $1;
12046: } else {
12047: $embed_file = $file;
12048: }
1.1158 raeburn 12049: my ($absolutepath,$cleaned_file);
12050: if ($embed_file =~ m{^\w+://}) {
12051: $cleaned_file = $embed_file;
1.1147 raeburn 12052: $newfiles{$cleaned_file} = 1;
12053: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12054: } else {
1.1158 raeburn 12055: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12056: if ($embed_file =~ m{^/}) {
12057: $absolutepath = $embed_file;
12058: }
1.1147 raeburn 12059: if ($cleaned_file =~ m{/}) {
12060: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12061: $path = &check_for_traversal($path,$url,$toplevel);
12062: my $item = $fname;
12063: if ($path ne '') {
12064: $item = $path.'/'.$fname;
12065: $subdependencies{$path}{$fname} = 1;
12066: } else {
12067: $dependencies{$item} = 1;
12068: }
12069: if ($absolutepath) {
12070: $mapping{$item} = $absolutepath;
12071: } else {
12072: $mapping{$item} = $embed_file;
12073: }
12074: } else {
12075: $dependencies{$embed_file} = 1;
12076: if ($absolutepath) {
1.1147 raeburn 12077: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12078: } else {
1.1147 raeburn 12079: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12080: }
12081: }
1.984 raeburn 12082: }
12083: }
1.1249 damieng 12084:
12085: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12086: # and lists
12087: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12088: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12089: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12090: # the path had to be cleaned up
12091: # $existing: hash clean path -> 1 if the file exists
12092: # $numexisting: number of keys in $existing
12093: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12094: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12095: # dependency subdirectories that are
12096: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12097: my $dirptr = 16384;
1.984 raeburn 12098: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12099: $currsubfile{$path} = {};
1.1123 raeburn 12100: if (($actionurl eq '/adm/portfolio') ||
12101: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12102: my ($sublistref,$listerror) =
12103: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12104: if (ref($sublistref) eq 'ARRAY') {
12105: foreach my $line (@{$sublistref}) {
12106: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12107: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12108: }
1.984 raeburn 12109: }
1.987 raeburn 12110: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12111: if (opendir(my $dir,$url.'/'.$path)) {
12112: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12113: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12114: }
1.1084 raeburn 12115: } elsif (($actionurl eq '/adm/dependencies') ||
12116: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12117: ($args->{'context'} eq 'paste')) ||
12118: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12119: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12120: my $dir;
12121: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12122: $dir = $fileloc;
12123: } else {
12124: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12125: }
1.1071 raeburn 12126: if ($dir ne '') {
12127: my ($sublistref,$listerror) =
12128: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12129: if (ref($sublistref) eq 'ARRAY') {
12130: foreach my $line (@{$sublistref}) {
12131: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12132: undef,$mtime)=split(/\&/,$line,12);
12133: unless (($testdir&$dirptr) ||
12134: ($file_name =~ /^\.\.?$/)) {
12135: $currsubfile{$path}{$file_name} = [$size,$mtime];
12136: }
12137: }
12138: }
12139: }
1.984 raeburn 12140: }
12141: }
12142: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12143: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12144: my $item = $path.'/'.$file;
12145: unless ($mapping{$item} eq $item) {
12146: $pathchanges{$item} = 1;
12147: }
12148: $existing{$item} = 1;
12149: $numexisting ++;
12150: } else {
12151: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12152: }
12153: }
1.1071 raeburn 12154: if ($actionurl eq '/adm/dependencies') {
12155: foreach my $path (keys(%currsubfile)) {
12156: if (ref($currsubfile{$path}) eq 'HASH') {
12157: foreach my $file (keys(%{$currsubfile{$path}})) {
12158: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12159: next if (($rem ne '') &&
12160: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12161: (ref($navmap) &&
12162: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12163: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12164: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12165: $unused{$path.'/'.$file} = 1;
12166: }
12167: }
12168: }
12169: }
12170: }
1.984 raeburn 12171: }
1.1249 damieng 12172:
12173: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12174: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12175: my %currfile;
1.1123 raeburn 12176: if (($actionurl eq '/adm/portfolio') ||
12177: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12178: my ($dirlistref,$listerror) =
12179: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12180: if (ref($dirlistref) eq 'ARRAY') {
12181: foreach my $line (@{$dirlistref}) {
12182: my ($file_name,$rest) = split(/\&/,$line,2);
12183: $currfile{$file_name} = 1;
12184: }
1.984 raeburn 12185: }
1.987 raeburn 12186: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12187: if (opendir(my $dir,$url)) {
1.987 raeburn 12188: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12189: map {$currfile{$_} = 1;} @dir_list;
12190: }
1.1084 raeburn 12191: } elsif (($actionurl eq '/adm/dependencies') ||
12192: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12193: ($args->{'context'} eq 'paste')) ||
12194: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12195: if ($env{'request.course.id'} ne '') {
12196: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12197: if ($dir ne '') {
12198: my ($dirlistref,$listerror) =
12199: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12200: if (ref($dirlistref) eq 'ARRAY') {
12201: foreach my $line (@{$dirlistref}) {
12202: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12203: $size,undef,$mtime)=split(/\&/,$line,12);
12204: unless (($testdir&$dirptr) ||
12205: ($file_name =~ /^\.\.?$/)) {
12206: $currfile{$file_name} = [$size,$mtime];
12207: }
12208: }
12209: }
12210: }
12211: }
1.984 raeburn 12212: }
1.1249 damieng 12213: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12214: # are not in subdirectories, using $currfile
1.984 raeburn 12215: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12216: if (exists($currfile{$file})) {
1.987 raeburn 12217: unless ($mapping{$file} eq $file) {
12218: $pathchanges{$file} = 1;
12219: }
12220: $existing{$file} = 1;
12221: $numexisting ++;
12222: } else {
1.984 raeburn 12223: $newfiles{$file} = 1;
12224: }
12225: }
1.1071 raeburn 12226: foreach my $file (keys(%currfile)) {
12227: unless (($file eq $filename) ||
12228: ($file eq $filename.'.bak') ||
12229: ($dependencies{$file})) {
1.1085 raeburn 12230: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12231: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12232: next if (($rem ne '') &&
12233: (($env{"httpref.$rem".$file} ne '') ||
12234: (ref($navmap) &&
12235: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12236: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12237: ($navmap->getResourceByUrl($rem.$1)))))));
12238: }
1.1085 raeburn 12239: }
1.1071 raeburn 12240: $unused{$file} = 1;
12241: }
12242: }
1.1249 damieng 12243:
12244: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12245: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12246: ($args->{'context'} eq 'paste')) {
12247: $counter = scalar(keys(%existing));
12248: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12249: return ($output,$counter,$numpathchg,\%existing);
12250: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12251: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12252: $counter = scalar(keys(%existing));
12253: $numpathchg = scalar(keys(%pathchanges));
12254: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12255: }
1.1249 damieng 12256:
12257: # returns HTML otherwise, with dependency results and to ask for more uploads
12258:
12259: # $upload_output: missing dependencies (with upload form)
12260: # $modify_output: uploaded dependencies (in use)
12261: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12262: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12263: if ($actionurl eq '/adm/dependencies') {
12264: next if ($embed_file =~ m{^\w+://});
12265: }
1.660 raeburn 12266: $upload_output .= &start_data_table_row().
1.1123 raeburn 12267: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12268: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12269: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12270: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12271: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12272: }
1.1123 raeburn 12273: $upload_output .= '</td>';
1.1071 raeburn 12274: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12275: $upload_output.='<td align="right">'.
12276: '<span class="LC_info LC_fontsize_medium">'.
12277: &mt("URL points to web address").'</span>';
1.987 raeburn 12278: $numremref++;
1.660 raeburn 12279: } elsif ($args->{'error_on_invalid_names'}
12280: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12281: $upload_output.='<td align="right"><span class="LC_warning">'.
12282: &mt('Invalid characters').'</span>';
1.987 raeburn 12283: $numinvalid++;
1.660 raeburn 12284: } else {
1.1123 raeburn 12285: $upload_output .= '<td>'.
12286: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12287: $embed_file,\%mapping,
1.1071 raeburn 12288: $allfiles,$codebase,'upload');
12289: $counter ++;
12290: $numnew ++;
1.987 raeburn 12291: }
12292: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12293: }
12294: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12295: if ($actionurl eq '/adm/dependencies') {
12296: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12297: $modify_output .= &start_data_table_row().
12298: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12299: '<img src="'.&icon($embed_file).'" border="0" />'.
12300: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12301: '<td>'.$size.'</td>'.
12302: '<td>'.$mtime.'</td>'.
12303: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12304: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12305: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12306: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12307: &embedded_file_element('upload_embedded',$counter,
12308: $embed_file,\%mapping,
12309: $allfiles,$codebase,'modify').
12310: '</div></td>'.
12311: &end_data_table_row()."\n";
12312: $counter ++;
12313: } else {
12314: $upload_output .= &start_data_table_row().
1.1123 raeburn 12315: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12316: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12317: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12318: &Apache::loncommon::end_data_table_row()."\n";
12319: }
12320: }
12321: my $delidx = $counter;
12322: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12323: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12324: $delete_output .= &start_data_table_row().
12325: '<td><img src="'.&icon($oldfile).'" />'.
12326: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12327: '<td>'.$size.'</td>'.
12328: '<td>'.$mtime.'</td>'.
12329: '<td><label><input type="checkbox" name="del_upload_dep" '.
12330: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12331: &embedded_file_element('upload_embedded',$delidx,
12332: $oldfile,\%mapping,$allfiles,
12333: $codebase,'delete').'</td>'.
12334: &end_data_table_row()."\n";
12335: $numunused ++;
12336: $delidx ++;
1.987 raeburn 12337: }
12338: if ($upload_output) {
12339: $upload_output = &start_data_table().
12340: $upload_output.
12341: &end_data_table()."\n";
12342: }
1.1071 raeburn 12343: if ($modify_output) {
12344: $modify_output = &start_data_table().
12345: &start_data_table_header_row().
12346: '<th>'.&mt('File').'</th>'.
12347: '<th>'.&mt('Size (KB)').'</th>'.
12348: '<th>'.&mt('Modified').'</th>'.
12349: '<th>'.&mt('Upload replacement?').'</th>'.
12350: &end_data_table_header_row().
12351: $modify_output.
12352: &end_data_table()."\n";
12353: }
12354: if ($delete_output) {
12355: $delete_output = &start_data_table().
12356: &start_data_table_header_row().
12357: '<th>'.&mt('File').'</th>'.
12358: '<th>'.&mt('Size (KB)').'</th>'.
12359: '<th>'.&mt('Modified').'</th>'.
12360: '<th>'.&mt('Delete?').'</th>'.
12361: &end_data_table_header_row().
12362: $delete_output.
12363: &end_data_table()."\n";
12364: }
1.987 raeburn 12365: my $applies = 0;
12366: if ($numremref) {
12367: $applies ++;
12368: }
12369: if ($numinvalid) {
12370: $applies ++;
12371: }
12372: if ($numexisting) {
12373: $applies ++;
12374: }
1.1071 raeburn 12375: if ($counter || $numunused) {
1.987 raeburn 12376: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12377: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12378: $state.'<h3>'.$heading.'</h3>';
12379: if ($actionurl eq '/adm/dependencies') {
12380: if ($numnew) {
12381: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12382: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12383: $upload_output.'<br />'."\n";
12384: }
12385: if ($numexisting) {
12386: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12387: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12388: $modify_output.'<br />'."\n";
12389: $buttontext = &mt('Save changes');
12390: }
12391: if ($numunused) {
12392: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12393: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12394: $delete_output.'<br />'."\n";
12395: $buttontext = &mt('Save changes');
12396: }
12397: } else {
12398: $output .= $upload_output.'<br />'."\n";
12399: }
12400: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12401: $counter.'" />'."\n";
12402: if ($actionurl eq '/adm/dependencies') {
12403: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12404: $numnew.'" />'."\n";
12405: } elsif ($actionurl eq '') {
1.987 raeburn 12406: $output .= '<input type="hidden" name="phase" value="three" />';
12407: }
12408: } elsif ($applies) {
12409: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12410: if ($applies > 1) {
12411: $output .=
1.1123 raeburn 12412: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12413: if ($numremref) {
12414: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12415: }
12416: if ($numinvalid) {
12417: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12418: }
12419: if ($numexisting) {
12420: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12421: }
12422: $output .= '</ul><br />';
12423: } elsif ($numremref) {
12424: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12425: } elsif ($numinvalid) {
12426: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12427: } elsif ($numexisting) {
12428: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12429: }
12430: $output .= $upload_output.'<br />';
12431: }
12432: my ($pathchange_output,$chgcount);
1.1071 raeburn 12433: $chgcount = $counter;
1.987 raeburn 12434: if (keys(%pathchanges) > 0) {
12435: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12436: if ($counter) {
1.987 raeburn 12437: $output .= &embedded_file_element('pathchange',$chgcount,
12438: $embed_file,\%mapping,
1.1071 raeburn 12439: $allfiles,$codebase,'change');
1.987 raeburn 12440: } else {
12441: $pathchange_output .=
12442: &start_data_table_row().
12443: '<td><input type ="checkbox" name="namechange" value="'.
12444: $chgcount.'" checked="checked" /></td>'.
12445: '<td>'.$mapping{$embed_file}.'</td>'.
12446: '<td>'.$embed_file.
12447: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12448: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12449: '</td>'.&end_data_table_row();
1.660 raeburn 12450: }
1.987 raeburn 12451: $numpathchg ++;
12452: $chgcount ++;
1.660 raeburn 12453: }
12454: }
1.1127 raeburn 12455: if (($counter) || ($numunused)) {
1.987 raeburn 12456: if ($numpathchg) {
12457: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12458: $numpathchg.'" />'."\n";
12459: }
12460: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12461: ($actionurl eq '/adm/imsimport')) {
12462: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12463: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12464: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12465: } elsif ($actionurl eq '/adm/dependencies') {
12466: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12467: }
1.1123 raeburn 12468: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12469: } elsif ($numpathchg) {
12470: my %pathchange = ();
12471: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12472: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12473: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12474: }
1.987 raeburn 12475: }
1.1071 raeburn 12476: return ($output,$counter,$numpathchg);
1.987 raeburn 12477: }
12478:
1.1147 raeburn 12479: =pod
12480:
12481: =item * clean_path($name)
12482:
12483: Performs clean-up of directories, subdirectories and filename in an
12484: embedded object, referenced in an HTML file which is being uploaded
12485: to a course or portfolio, where
12486: "Upload embedded images/multimedia files if HTML file" checkbox was
12487: checked.
12488:
12489: Clean-up is similar to replacements in lonnet::clean_filename()
12490: except each / between sub-directory and next level is preserved.
12491:
12492: =cut
12493:
12494: sub clean_path {
12495: my ($embed_file) = @_;
12496: $embed_file =~s{^/+}{};
12497: my @contents;
12498: if ($embed_file =~ m{/}) {
12499: @contents = split(/\//,$embed_file);
12500: } else {
12501: @contents = ($embed_file);
12502: }
12503: my $lastidx = scalar(@contents)-1;
12504: for (my $i=0; $i<=$lastidx; $i++) {
12505: $contents[$i]=~s{\\}{/}g;
12506: $contents[$i]=~s/\s+/\_/g;
12507: $contents[$i]=~s{[^/\w\.\-]}{}g;
12508: if ($i == $lastidx) {
12509: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12510: }
12511: }
12512: if ($lastidx > 0) {
12513: return join('/',@contents);
12514: } else {
12515: return $contents[0];
12516: }
12517: }
12518:
1.987 raeburn 12519: sub embedded_file_element {
1.1071 raeburn 12520: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12521: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12522: (ref($codebase) eq 'HASH'));
12523: my $output;
1.1071 raeburn 12524: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12525: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12526: }
12527: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12528: &escape($embed_file).'" />';
12529: unless (($context eq 'upload_embedded') &&
12530: ($mapping->{$embed_file} eq $embed_file)) {
12531: $output .='
12532: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12533: }
12534: my $attrib;
12535: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12536: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12537: }
12538: $output .=
12539: "\n\t\t".
12540: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12541: $attrib.'" />';
12542: if (exists($codebase->{$mapping->{$embed_file}})) {
12543: $output .=
12544: "\n\t\t".
12545: '<input name="codebase_'.$num.'" type="hidden" value="'.
12546: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12547: }
1.987 raeburn 12548: return $output;
1.660 raeburn 12549: }
12550:
1.1071 raeburn 12551: sub get_dependency_details {
12552: my ($currfile,$currsubfile,$embed_file) = @_;
12553: my ($size,$mtime,$showsize,$showmtime);
12554: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12555: if ($embed_file =~ m{/}) {
12556: my ($path,$fname) = split(/\//,$embed_file);
12557: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12558: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12559: }
12560: } else {
12561: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12562: ($size,$mtime) = @{$currfile->{$embed_file}};
12563: }
12564: }
12565: $showsize = $size/1024.0;
12566: $showsize = sprintf("%.1f",$showsize);
12567: if ($mtime > 0) {
12568: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12569: }
12570: }
12571: return ($showsize,$showmtime);
12572: }
12573:
12574: sub ask_embedded_js {
12575: return <<"END";
12576: <script type="text/javascript"">
12577: // <![CDATA[
12578: function toggleBrowse(counter) {
12579: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12580: var fileid = document.getElementById('embedded_item_'+counter);
12581: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12582: if (chkboxid.checked == true) {
12583: uploaddivid.style.display='block';
12584: } else {
12585: uploaddivid.style.display='none';
12586: fileid.value = '';
12587: }
12588: }
12589: // ]]>
12590: </script>
12591:
12592: END
12593: }
12594:
1.661 raeburn 12595: sub upload_embedded {
12596: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12597: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12598: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12599: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12600: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12601: my $orig_uploaded_filename =
12602: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12603: foreach my $type ('orig','ref','attrib','codebase') {
12604: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12605: $env{'form.embedded_'.$type.'_'.$i} =
12606: &unescape($env{'form.embedded_'.$type.'_'.$i});
12607: }
12608: }
1.661 raeburn 12609: my ($path,$fname) =
12610: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12611: # no path, whole string is fname
12612: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12613: $fname = &Apache::lonnet::clean_filename($fname);
12614: # See if there is anything left
12615: next if ($fname eq '');
12616:
12617: # Check if file already exists as a file or directory.
12618: my ($state,$msg);
12619: if ($context eq 'portfolio') {
12620: my $port_path = $dirpath;
12621: if ($group ne '') {
12622: $port_path = "groups/$group/$port_path";
12623: }
1.987 raeburn 12624: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12625: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12626: $dir_root,$port_path,$disk_quota,
12627: $current_disk_usage,$uname,$udom);
12628: if ($state eq 'will_exceed_quota'
1.984 raeburn 12629: || $state eq 'file_locked') {
1.661 raeburn 12630: $output .= $msg;
12631: next;
12632: }
12633: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12634: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12635: if ($state eq 'exists') {
12636: $output .= $msg;
12637: next;
12638: }
12639: }
12640: # Check if extension is valid
12641: if (($fname =~ /\.(\w+)$/) &&
12642: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12643: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12644: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12645: next;
12646: } elsif (($fname =~ /\.(\w+)$/) &&
12647: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12648: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12649: next;
12650: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12651: $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 12652: next;
12653: }
12654: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12655: my $subdir = $path;
12656: $subdir =~ s{/+$}{};
1.661 raeburn 12657: if ($context eq 'portfolio') {
1.984 raeburn 12658: my $result;
12659: if ($state eq 'existingfile') {
12660: $result=
12661: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12662: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12663: } else {
1.984 raeburn 12664: $result=
12665: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12666: $dirpath.
1.1123 raeburn 12667: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12668: if ($result !~ m|^/uploaded/|) {
12669: $output .= '<span class="LC_error">'
12670: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12671: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12672: .'</span><br />';
12673: next;
12674: } else {
1.987 raeburn 12675: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12676: $path.$fname.'</span>').'<br />';
1.984 raeburn 12677: }
1.661 raeburn 12678: }
1.1123 raeburn 12679: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12680: my $extendedsubdir = $dirpath.'/'.$subdir;
12681: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12682: my $result =
1.1126 raeburn 12683: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12684: if ($result !~ m|^/uploaded/|) {
12685: $output .= '<span class="LC_error">'
12686: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12687: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12688: .'</span><br />';
12689: next;
12690: } else {
12691: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12692: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12693: if ($context eq 'syllabus') {
12694: &Apache::lonnet::make_public_indefinitely($result);
12695: }
1.987 raeburn 12696: }
1.661 raeburn 12697: } else {
12698: # Save the file
12699: my $target = $env{'form.embedded_item_'.$i};
12700: my $fullpath = $dir_root.$dirpath.'/'.$path;
12701: my $dest = $fullpath.$fname;
12702: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12703: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12704: my $count;
12705: my $filepath = $dir_root;
1.1027 raeburn 12706: foreach my $subdir (@parts) {
12707: $filepath .= "/$subdir";
12708: if (!-e $filepath) {
1.661 raeburn 12709: mkdir($filepath,0770);
12710: }
12711: }
12712: my $fh;
12713: if (!open($fh,'>'.$dest)) {
12714: &Apache::lonnet::logthis('Failed to create '.$dest);
12715: $output .= '<span class="LC_error">'.
1.1071 raeburn 12716: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12717: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12718: '</span><br />';
12719: } else {
12720: if (!print $fh $env{'form.embedded_item_'.$i}) {
12721: &Apache::lonnet::logthis('Failed to write to '.$dest);
12722: $output .= '<span class="LC_error">'.
1.1071 raeburn 12723: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12724: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12725: '</span><br />';
12726: } else {
1.987 raeburn 12727: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12728: $url.'</span>').'<br />';
12729: unless ($context eq 'testbank') {
12730: $footer .= &mt('View embedded file: [_1]',
12731: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12732: }
12733: }
12734: close($fh);
12735: }
12736: }
12737: if ($env{'form.embedded_ref_'.$i}) {
12738: $pathchange{$i} = 1;
12739: }
12740: }
12741: if ($output) {
12742: $output = '<p>'.$output.'</p>';
12743: }
12744: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12745: $returnflag = 'ok';
1.1071 raeburn 12746: my $numpathchgs = scalar(keys(%pathchange));
12747: if ($numpathchgs > 0) {
1.987 raeburn 12748: if ($context eq 'portfolio') {
12749: $output .= '<p>'.&mt('or').'</p>';
12750: } elsif ($context eq 'testbank') {
1.1071 raeburn 12751: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12752: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12753: $returnflag = 'modify_orightml';
12754: }
12755: }
1.1071 raeburn 12756: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12757: }
12758:
12759: sub modify_html_form {
12760: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12761: my $end = 0;
12762: my $modifyform;
12763: if ($context eq 'upload_embedded') {
12764: return unless (ref($pathchange) eq 'HASH');
12765: if ($env{'form.number_embedded_items'}) {
12766: $end += $env{'form.number_embedded_items'};
12767: }
12768: if ($env{'form.number_pathchange_items'}) {
12769: $end += $env{'form.number_pathchange_items'};
12770: }
12771: if ($end) {
12772: for (my $i=0; $i<$end; $i++) {
12773: if ($i < $env{'form.number_embedded_items'}) {
12774: next unless($pathchange->{$i});
12775: }
12776: $modifyform .=
12777: &start_data_table_row().
12778: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12779: 'checked="checked" /></td>'.
12780: '<td>'.$env{'form.embedded_ref_'.$i}.
12781: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12782: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12783: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12784: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12785: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12786: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12787: '<td>'.$env{'form.embedded_orig_'.$i}.
12788: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12789: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12790: &end_data_table_row();
1.1071 raeburn 12791: }
1.987 raeburn 12792: }
12793: } else {
12794: $modifyform = $pathchgtable;
12795: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12796: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12797: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12798: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12799: }
12800: }
12801: if ($modifyform) {
1.1071 raeburn 12802: if ($actionurl eq '/adm/dependencies') {
12803: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12804: }
1.987 raeburn 12805: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12806: '<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".
12807: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12808: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12809: '</ol></p>'."\n".'<p>'.
12810: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12811: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12812: &start_data_table()."\n".
12813: &start_data_table_header_row().
12814: '<th>'.&mt('Change?').'</th>'.
12815: '<th>'.&mt('Current reference').'</th>'.
12816: '<th>'.&mt('Required reference').'</th>'.
12817: &end_data_table_header_row()."\n".
12818: $modifyform.
12819: &end_data_table().'<br />'."\n".$hiddenstate.
12820: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12821: '</form>'."\n";
12822: }
12823: return;
12824: }
12825:
12826: sub modify_html_refs {
1.1123 raeburn 12827: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12828: my $container;
12829: if ($context eq 'portfolio') {
12830: $container = $env{'form.container'};
12831: } elsif ($context eq 'coursedoc') {
12832: $container = $env{'form.primaryurl'};
1.1071 raeburn 12833: } elsif ($context eq 'manage_dependencies') {
12834: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12835: $container = "/$container";
1.1123 raeburn 12836: } elsif ($context eq 'syllabus') {
12837: $container = $url;
1.987 raeburn 12838: } else {
1.1027 raeburn 12839: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12840: }
12841: my (%allfiles,%codebase,$output,$content);
12842: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12843: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12844: if (wantarray) {
12845: return ('',0,0);
12846: } else {
12847: return;
12848: }
12849: }
12850: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12851: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12852: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12853: if (wantarray) {
12854: return ('',0,0);
12855: } else {
12856: return;
12857: }
12858: }
1.987 raeburn 12859: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12860: if ($content eq '-1') {
12861: if (wantarray) {
12862: return ('',0,0);
12863: } else {
12864: return;
12865: }
12866: }
1.987 raeburn 12867: } else {
1.1071 raeburn 12868: unless ($container =~ /^\Q$dir_root\E/) {
12869: if (wantarray) {
12870: return ('',0,0);
12871: } else {
12872: return;
12873: }
12874: }
1.1317 raeburn 12875: if (open(my $fh,'<',$container)) {
1.987 raeburn 12876: $content = join('', <$fh>);
12877: close($fh);
12878: } else {
1.1071 raeburn 12879: if (wantarray) {
12880: return ('',0,0);
12881: } else {
12882: return;
12883: }
1.987 raeburn 12884: }
12885: }
12886: my ($count,$codebasecount) = (0,0);
12887: my $mm = new File::MMagic;
12888: my $mime_type = $mm->checktype_contents($content);
12889: if ($mime_type eq 'text/html') {
12890: my $parse_result =
12891: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12892: \%codebase,\$content);
12893: if ($parse_result eq 'ok') {
12894: foreach my $i (@changes) {
12895: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12896: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12897: if ($allfiles{$ref}) {
12898: my $newname = $orig;
12899: my ($attrib_regexp,$codebase);
1.1006 raeburn 12900: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12901: if ($attrib_regexp =~ /:/) {
12902: $attrib_regexp =~ s/\:/|/g;
12903: }
12904: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12905: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12906: $count += $numchg;
1.1123 raeburn 12907: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12908: delete($allfiles{$ref});
1.987 raeburn 12909: }
12910: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12911: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12912: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12913: $codebasecount ++;
12914: }
12915: }
12916: }
1.1123 raeburn 12917: my $skiprewrites;
1.987 raeburn 12918: if ($count || $codebasecount) {
12919: my $saveresult;
1.1071 raeburn 12920: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12921: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12922: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12923: if ($url eq $container) {
12924: my ($fname) = ($container =~ m{/([^/]+)$});
12925: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12926: $count,'<span class="LC_filename">'.
1.1071 raeburn 12927: $fname.'</span>').'</p>';
1.987 raeburn 12928: } else {
12929: $output = '<p class="LC_error">'.
12930: &mt('Error: update failed for: [_1].',
12931: '<span class="LC_filename">'.
12932: $container.'</span>').'</p>';
12933: }
1.1123 raeburn 12934: if ($context eq 'syllabus') {
12935: unless ($saveresult eq 'ok') {
12936: $skiprewrites = 1;
12937: }
12938: }
1.987 raeburn 12939: } else {
1.1317 raeburn 12940: if (open(my $fh,'>',$container)) {
1.987 raeburn 12941: print $fh $content;
12942: close($fh);
12943: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12944: $count,'<span class="LC_filename">'.
12945: $container.'</span>').'</p>';
1.661 raeburn 12946: } else {
1.987 raeburn 12947: $output = '<p class="LC_error">'.
12948: &mt('Error: could not update [_1].',
12949: '<span class="LC_filename">'.
12950: $container.'</span>').'</p>';
1.661 raeburn 12951: }
12952: }
12953: }
1.1123 raeburn 12954: if (($context eq 'syllabus') && (!$skiprewrites)) {
12955: my ($actionurl,$state);
12956: $actionurl = "/public/$udom/$uname/syllabus";
12957: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12958: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12959: \%codebase,
12960: {'context' => 'rewrites',
12961: 'ignore_remote_references' => 1,});
12962: if (ref($mapping) eq 'HASH') {
12963: my $rewrites = 0;
12964: foreach my $key (keys(%{$mapping})) {
12965: next if ($key =~ m{^https?://});
12966: my $ref = $mapping->{$key};
12967: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12968: my $attrib;
12969: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12970: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12971: }
12972: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12973: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12974: $rewrites += $numchg;
12975: }
12976: }
12977: if ($rewrites) {
12978: my $saveresult;
12979: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12980: if ($url eq $container) {
12981: my ($fname) = ($container =~ m{/([^/]+)$});
12982: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12983: $count,'<span class="LC_filename">'.
12984: $fname.'</span>').'</p>';
12985: } else {
12986: $output .= '<p class="LC_error">'.
12987: &mt('Error: could not update links in [_1].',
12988: '<span class="LC_filename">'.
12989: $container.'</span>').'</p>';
12990:
12991: }
12992: }
12993: }
12994: }
1.987 raeburn 12995: } else {
12996: &logthis('Failed to parse '.$container.
12997: ' to modify references: '.$parse_result);
1.661 raeburn 12998: }
12999: }
1.1071 raeburn 13000: if (wantarray) {
13001: return ($output,$count,$codebasecount);
13002: } else {
13003: return $output;
13004: }
1.661 raeburn 13005: }
13006:
13007: sub check_for_existing {
13008: my ($path,$fname,$element) = @_;
13009: my ($state,$msg);
13010: if (-d $path.'/'.$fname) {
13011: $state = 'exists';
13012: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13013: } elsif (-e $path.'/'.$fname) {
13014: $state = 'exists';
13015: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13016: }
13017: if ($state eq 'exists') {
13018: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13019: }
13020: return ($state,$msg);
13021: }
13022:
13023: sub check_for_upload {
13024: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13025: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13026: my $filesize = length($env{'form.'.$element});
13027: if (!$filesize) {
13028: my $msg = '<span class="LC_error">'.
13029: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13030: '<span class="LC_filename">'.$fname.'</span>',
13031: $filesize).'<br />'.
1.1007 raeburn 13032: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13033: '</span>';
13034: return ('zero_bytes',$msg);
13035: }
13036: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13037: my $getpropath = 1;
1.1021 raeburn 13038: my ($dirlistref,$listerror) =
13039: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13040: my $found_file = 0;
13041: my $locked_file = 0;
1.991 raeburn 13042: my @lockers;
13043: my $navmap;
13044: if ($env{'request.course.id'}) {
13045: $navmap = Apache::lonnavmaps::navmap->new();
13046: }
1.1021 raeburn 13047: if (ref($dirlistref) eq 'ARRAY') {
13048: foreach my $line (@{$dirlistref}) {
13049: my ($file_name,$rest)=split(/\&/,$line,2);
13050: if ($file_name eq $fname){
13051: $file_name = $path.$file_name;
13052: if ($group ne '') {
13053: $file_name = $group.$file_name;
13054: }
13055: $found_file = 1;
13056: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13057: foreach my $lock (@lockers) {
13058: if (ref($lock) eq 'ARRAY') {
13059: my ($symb,$crsid) = @{$lock};
13060: if ($crsid eq $env{'request.course.id'}) {
13061: if (ref($navmap)) {
13062: my $res = $navmap->getBySymb($symb);
13063: foreach my $part (@{$res->parts()}) {
13064: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13065: unless (($slot_status == $res->RESERVED) ||
13066: ($slot_status == $res->RESERVED_LOCATION)) {
13067: $locked_file = 1;
13068: }
1.991 raeburn 13069: }
1.1021 raeburn 13070: } else {
13071: $locked_file = 1;
1.991 raeburn 13072: }
13073: } else {
13074: $locked_file = 1;
13075: }
13076: }
1.1021 raeburn 13077: }
13078: } else {
13079: my @info = split(/\&/,$rest);
13080: my $currsize = $info[6]/1000;
13081: if ($currsize < $filesize) {
13082: my $extra = $filesize - $currsize;
13083: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13084: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13085: &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.1179 bisitz 13086: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13087: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13088: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13089: return ('will_exceed_quota',$msg);
13090: }
1.984 raeburn 13091: }
13092: }
1.661 raeburn 13093: }
13094: }
13095: }
13096: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13097: my $msg = '<p class="LC_warning">'.
13098: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13099: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13100: return ('will_exceed_quota',$msg);
13101: } elsif ($found_file) {
13102: if ($locked_file) {
1.1179 bisitz 13103: my $msg = '<p class="LC_warning">';
1.661 raeburn 13104: $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.1179 bisitz 13105: $msg .= '</p>';
1.661 raeburn 13106: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13107: return ('file_locked',$msg);
13108: } else {
1.1179 bisitz 13109: my $msg = '<p class="LC_error">';
1.984 raeburn 13110: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1179 bisitz 13111: $msg .= '</p>';
1.984 raeburn 13112: return ('existingfile',$msg);
1.661 raeburn 13113: }
13114: }
13115: }
13116:
1.987 raeburn 13117: sub check_for_traversal {
13118: my ($path,$url,$toplevel) = @_;
13119: my @parts=split(/\//,$path);
13120: my $cleanpath;
13121: my $fullpath = $url;
13122: for (my $i=0;$i<@parts;$i++) {
13123: next if ($parts[$i] eq '.');
13124: if ($parts[$i] eq '..') {
13125: $fullpath =~ s{([^/]+/)$}{};
13126: } else {
13127: $fullpath .= $parts[$i].'/';
13128: }
13129: }
13130: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13131: $cleanpath = $1;
13132: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13133: my $curr_toprel = $1;
13134: my @parts = split(/\//,$curr_toprel);
13135: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13136: my @urlparts = split(/\//,$url_toprel);
13137: my $doubledots;
13138: my $startdiff = -1;
13139: for (my $i=0; $i<@urlparts; $i++) {
13140: if ($startdiff == -1) {
13141: unless ($urlparts[$i] eq $parts[$i]) {
13142: $startdiff = $i;
13143: $doubledots .= '../';
13144: }
13145: } else {
13146: $doubledots .= '../';
13147: }
13148: }
13149: if ($startdiff > -1) {
13150: $cleanpath = $doubledots;
13151: for (my $i=$startdiff; $i<@parts; $i++) {
13152: $cleanpath .= $parts[$i].'/';
13153: }
13154: }
13155: }
13156: $cleanpath =~ s{(/)$}{};
13157: return $cleanpath;
13158: }
1.31 albertel 13159:
1.1053 raeburn 13160: sub is_archive_file {
13161: my ($mimetype) = @_;
13162: if (($mimetype eq 'application/octet-stream') ||
13163: ($mimetype eq 'application/x-stuffit') ||
13164: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13165: return 1;
13166: }
13167: return;
13168: }
13169:
13170: sub decompress_form {
1.1065 raeburn 13171: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13172: my %lt = &Apache::lonlocal::texthash (
13173: this => 'This file is an archive file.',
1.1067 raeburn 13174: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13175: itsc => 'Its contents are as follows:',
1.1053 raeburn 13176: youm => 'You may wish to extract its contents.',
13177: extr => 'Extract contents',
1.1067 raeburn 13178: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13179: proa => 'Process automatically?',
1.1053 raeburn 13180: yes => 'Yes',
13181: no => 'No',
1.1067 raeburn 13182: fold => 'Title for folder containing movie',
13183: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13184: );
1.1065 raeburn 13185: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13186: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13187: my $info = &list_archive_contents($fileloc,\@paths);
13188: if (@paths) {
13189: foreach my $path (@paths) {
13190: $path =~ s{^/}{};
1.1067 raeburn 13191: if ($path =~ m{^([^/]+)/$}) {
13192: $topdir = $1;
13193: }
1.1065 raeburn 13194: if ($path =~ m{^([^/]+)/}) {
13195: $toplevel{$1} = $path;
13196: } else {
13197: $toplevel{$path} = $path;
13198: }
13199: }
13200: }
1.1067 raeburn 13201: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13202: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13203: "$topdir/media/",
13204: "$topdir/media/$topdir.mp4",
13205: "$topdir/media/FirstFrame.png",
13206: "$topdir/media/player.swf",
13207: "$topdir/media/swfobject.js",
13208: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13209: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13210: "$topdir/$topdir.mp4",
13211: "$topdir/$topdir\_config.xml",
13212: "$topdir/$topdir\_controller.swf",
13213: "$topdir/$topdir\_embed.css",
13214: "$topdir/$topdir\_First_Frame.png",
13215: "$topdir/$topdir\_player.html",
13216: "$topdir/$topdir\_Thumbnails.png",
13217: "$topdir/playerProductInstall.swf",
13218: "$topdir/scripts/",
13219: "$topdir/scripts/config_xml.js",
13220: "$topdir/scripts/handlebars.js",
13221: "$topdir/scripts/jquery-1.7.1.min.js",
13222: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13223: "$topdir/scripts/modernizr.js",
13224: "$topdir/scripts/player-min.js",
13225: "$topdir/scripts/swfobject.js",
13226: "$topdir/skins/",
13227: "$topdir/skins/configuration_express.xml",
13228: "$topdir/skins/express_show/",
13229: "$topdir/skins/express_show/player-min.css",
13230: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13231: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13232: "$topdir/$topdir.mp4",
13233: "$topdir/$topdir\_config.xml",
13234: "$topdir/$topdir\_controller.swf",
13235: "$topdir/$topdir\_embed.css",
13236: "$topdir/$topdir\_First_Frame.png",
13237: "$topdir/$topdir\_player.html",
13238: "$topdir/$topdir\_Thumbnails.png",
13239: "$topdir/playerProductInstall.swf",
13240: "$topdir/scripts/",
13241: "$topdir/scripts/config_xml.js",
13242: "$topdir/scripts/techsmith-smart-player.min.js",
13243: "$topdir/skins/",
13244: "$topdir/skins/configuration_express.xml",
13245: "$topdir/skins/express_show/",
13246: "$topdir/skins/express_show/spritesheet.min.css",
13247: "$topdir/skins/express_show/spritesheet.png",
13248: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13249: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13250: if (@diffs == 0) {
1.1164 raeburn 13251: $is_camtasia = 6;
13252: } else {
1.1197 raeburn 13253: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13254: if (@diffs == 0) {
13255: $is_camtasia = 8;
1.1197 raeburn 13256: } else {
13257: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13258: if (@diffs == 0) {
13259: $is_camtasia = 8;
13260: }
1.1164 raeburn 13261: }
1.1067 raeburn 13262: }
13263: }
13264: my $output;
13265: if ($is_camtasia) {
13266: $output = <<"ENDCAM";
13267: <script type="text/javascript" language="Javascript">
13268: // <![CDATA[
13269:
13270: function camtasiaToggle() {
13271: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13272: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13273: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13274: document.getElementById('camtasia_titles').style.display='block';
13275: } else {
13276: document.getElementById('camtasia_titles').style.display='none';
13277: }
13278: }
13279: }
13280: return;
13281: }
13282:
13283: // ]]>
13284: </script>
13285: <p>$lt{'camt'}</p>
13286: ENDCAM
1.1065 raeburn 13287: } else {
1.1067 raeburn 13288: $output = '<p>'.$lt{'this'};
13289: if ($info eq '') {
13290: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13291: } else {
13292: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13293: '<div><pre>'.$info.'</pre></div>';
13294: }
1.1065 raeburn 13295: }
1.1067 raeburn 13296: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13297: my $duplicates;
13298: my $num = 0;
13299: if (ref($dirlist) eq 'ARRAY') {
13300: foreach my $item (@{$dirlist}) {
13301: if (ref($item) eq 'ARRAY') {
13302: if (exists($toplevel{$item->[0]})) {
13303: $duplicates .=
13304: &start_data_table_row().
13305: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13306: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13307: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13308: 'value="1" />'.&mt('Yes').'</label>'.
13309: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13310: '<td>'.$item->[0].'</td>';
13311: if ($item->[2]) {
13312: $duplicates .= '<td>'.&mt('Directory').'</td>';
13313: } else {
13314: $duplicates .= '<td>'.&mt('File').'</td>';
13315: }
13316: $duplicates .= '<td>'.$item->[3].'</td>'.
13317: '<td>'.
13318: &Apache::lonlocal::locallocaltime($item->[4]).
13319: '</td>'.
13320: &end_data_table_row();
13321: $num ++;
13322: }
13323: }
13324: }
13325: }
13326: my $itemcount;
13327: if (@paths > 0) {
13328: $itemcount = scalar(@paths);
13329: } else {
13330: $itemcount = 1;
13331: }
1.1067 raeburn 13332: if ($is_camtasia) {
13333: $output .= $lt{'auto'}.'<br />'.
13334: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13335: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13336: $lt{'yes'}.'</label> <label>'.
13337: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13338: $lt{'no'}.'</label></span><br />'.
13339: '<div id="camtasia_titles" style="display:block">'.
13340: &Apache::lonhtmlcommon::start_pick_box().
13341: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13342: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13343: &Apache::lonhtmlcommon::row_closure().
13344: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13345: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13346: &Apache::lonhtmlcommon::row_closure(1).
13347: &Apache::lonhtmlcommon::end_pick_box().
13348: '</div>';
13349: }
1.1065 raeburn 13350: $output .=
13351: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13352: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13353: "\n";
1.1065 raeburn 13354: if ($duplicates ne '') {
13355: $output .= '<p><span class="LC_warning">'.
13356: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13357: &start_data_table().
13358: &start_data_table_header_row().
13359: '<th>'.&mt('Overwrite?').'</th>'.
13360: '<th>'.&mt('Name').'</th>'.
13361: '<th>'.&mt('Type').'</th>'.
13362: '<th>'.&mt('Size').'</th>'.
13363: '<th>'.&mt('Last modified').'</th>'.
13364: &end_data_table_header_row().
13365: $duplicates.
13366: &end_data_table().
13367: '</p>';
13368: }
1.1067 raeburn 13369: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13370: if (ref($hiddenelements) eq 'HASH') {
13371: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13372: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13373: }
13374: }
13375: $output .= <<"END";
1.1067 raeburn 13376: <br />
1.1053 raeburn 13377: <input type="submit" name="decompress" value="$lt{'extr'}" />
13378: </form>
13379: $noextract
13380: END
13381: return $output;
13382: }
13383:
1.1065 raeburn 13384: sub decompression_utility {
13385: my ($program) = @_;
13386: my @utilities = ('tar','gunzip','bunzip2','unzip');
13387: my $location;
13388: if (grep(/^\Q$program\E$/,@utilities)) {
13389: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13390: '/usr/sbin/') {
13391: if (-x $dir.$program) {
13392: $location = $dir.$program;
13393: last;
13394: }
13395: }
13396: }
13397: return $location;
13398: }
13399:
13400: sub list_archive_contents {
13401: my ($file,$pathsref) = @_;
13402: my (@cmd,$output);
13403: my $needsregexp;
13404: if ($file =~ /\.zip$/) {
13405: @cmd = (&decompression_utility('unzip'),"-l");
13406: $needsregexp = 1;
13407: } elsif (($file =~ m/\.tar\.gz$/) ||
13408: ($file =~ /\.tgz$/)) {
13409: @cmd = (&decompression_utility('tar'),"-ztf");
13410: } elsif ($file =~ /\.tar\.bz2$/) {
13411: @cmd = (&decompression_utility('tar'),"-jtf");
13412: } elsif ($file =~ m|\.tar$|) {
13413: @cmd = (&decompression_utility('tar'),"-tf");
13414: }
13415: if (@cmd) {
13416: undef($!);
13417: undef($@);
13418: if (open(my $fh,"-|", @cmd, $file)) {
13419: while (my $line = <$fh>) {
13420: $output .= $line;
13421: chomp($line);
13422: my $item;
13423: if ($needsregexp) {
13424: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13425: } else {
13426: $item = $line;
13427: }
13428: if ($item ne '') {
13429: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13430: push(@{$pathsref},$item);
13431: }
13432: }
13433: }
13434: close($fh);
13435: }
13436: }
13437: return $output;
13438: }
13439:
1.1053 raeburn 13440: sub decompress_uploaded_file {
13441: my ($file,$dir) = @_;
13442: &Apache::lonnet::appenv({'cgi.file' => $file});
13443: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13444: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13445: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13446: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13447: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13448: my $decompressed = $env{'cgi.decompressed'};
13449: &Apache::lonnet::delenv('cgi.file');
13450: &Apache::lonnet::delenv('cgi.dir');
13451: &Apache::lonnet::delenv('cgi.decompressed');
13452: return ($decompressed,$result);
13453: }
13454:
1.1055 raeburn 13455: sub process_decompression {
13456: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13457: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13458: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13459: &mt('Unexpected file path.').'</p>'."\n";
13460: }
13461: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13462: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13463: &mt('Unexpected course context.').'</p>'."\n";
13464: }
1.1293 raeburn 13465: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13466: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13467: &mt('Filename contained unexpected characters.').'</p>'."\n";
13468: }
1.1055 raeburn 13469: my ($dir,$error,$warning,$output);
1.1180 raeburn 13470: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13471: $error = &mt('Filename not a supported archive file type.').
13472: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13473: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13474: } else {
13475: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13476: if ($docuhome eq 'no_host') {
13477: $error = &mt('Could not determine home server for course.');
13478: } else {
13479: my @ids=&Apache::lonnet::current_machine_ids();
13480: my $currdir = "$dir_root/$destination";
13481: if (grep(/^\Q$docuhome\E$/,@ids)) {
13482: $dir = &LONCAPA::propath($docudom,$docuname).
13483: "$dir_root/$destination";
13484: } else {
13485: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13486: "$dir_root/$docudom/$docuname/$destination";
13487: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13488: $error = &mt('Archive file not found.');
13489: }
13490: }
1.1065 raeburn 13491: my (@to_overwrite,@to_skip);
13492: if ($env{'form.archive_overwrite_total'} > 0) {
13493: my $total = $env{'form.archive_overwrite_total'};
13494: for (my $i=0; $i<$total; $i++) {
13495: if ($env{'form.archive_overwrite_'.$i} == 1) {
13496: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13497: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13498: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13499: }
13500: }
13501: }
13502: my $numskip = scalar(@to_skip);
1.1292 raeburn 13503: my $numoverwrite = scalar(@to_overwrite);
13504: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13505: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13506: } elsif ($dir eq '') {
1.1055 raeburn 13507: $error = &mt('Directory containing archive file unavailable.');
13508: } elsif (!$error) {
1.1065 raeburn 13509: my ($decompressed,$display);
1.1292 raeburn 13510: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13511: my $tempdir = time.'_'.$$.int(rand(10000));
13512: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13513: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13514: ($decompressed,$display) =
13515: &decompress_uploaded_file($file,"$dir/$tempdir");
13516: foreach my $item (@to_skip) {
13517: if (($item ne '') && ($item !~ /\.\./)) {
13518: if (-f "$dir/$tempdir/$item") {
13519: unlink("$dir/$tempdir/$item");
13520: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13521: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13522: }
13523: }
13524: }
13525: foreach my $item (@to_overwrite) {
13526: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13527: if (($item ne '') && ($item !~ /\.\./)) {
13528: if (-f "$dir/$item") {
13529: unlink("$dir/$item");
13530: } elsif (-d "$dir/$item") {
1.1300 raeburn 13531: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13532: }
13533: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13534: }
1.1065 raeburn 13535: }
13536: }
1.1292 raeburn 13537: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13538: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13539: }
1.1065 raeburn 13540: }
13541: } else {
13542: ($decompressed,$display) =
13543: &decompress_uploaded_file($file,$dir);
13544: }
1.1055 raeburn 13545: if ($decompressed eq 'ok') {
1.1065 raeburn 13546: $output = '<p class="LC_info">'.
13547: &mt('Files extracted successfully from archive.').
13548: '</p>'."\n";
1.1055 raeburn 13549: my ($warning,$result,@contents);
13550: my ($newdirlistref,$newlisterror) =
13551: &Apache::lonnet::dirlist($currdir,$docudom,
13552: $docuname,1);
13553: my (%is_dir,%changes,@newitems);
13554: my $dirptr = 16384;
1.1065 raeburn 13555: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13556: foreach my $dir_line (@{$newdirlistref}) {
13557: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13558: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13559: push(@newitems,$item);
13560: if ($dirptr&$testdir) {
13561: $is_dir{$item} = 1;
13562: }
13563: $changes{$item} = 1;
13564: }
13565: }
13566: }
13567: if (keys(%changes) > 0) {
13568: foreach my $item (sort(@newitems)) {
13569: if ($changes{$item}) {
13570: push(@contents,$item);
13571: }
13572: }
13573: }
13574: if (@contents > 0) {
1.1067 raeburn 13575: my $wantform;
13576: unless ($env{'form.autoextract_camtasia'}) {
13577: $wantform = 1;
13578: }
1.1056 raeburn 13579: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13580: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13581: $currdir,\%is_dir,
13582: \%children,\%parent,
1.1056 raeburn 13583: \@contents,\%dirorder,
13584: \%titles,$wantform);
1.1055 raeburn 13585: if ($datatable ne '') {
13586: $output .= &archive_options_form('decompressed',$datatable,
13587: $count,$hiddenelem);
1.1065 raeburn 13588: my $startcount = 6;
1.1055 raeburn 13589: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13590: \%titles,\%children);
1.1055 raeburn 13591: }
1.1067 raeburn 13592: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13593: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13594: my %displayed;
13595: my $total = 1;
13596: $env{'form.archive_directory'} = [];
13597: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13598: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13599: $path =~ s{/$}{};
13600: my $item;
13601: if ($path ne '') {
13602: $item = "$path/$titles{$i}";
13603: } else {
13604: $item = $titles{$i};
13605: }
13606: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13607: if ($item eq $contents[0]) {
13608: push(@{$env{'form.archive_directory'}},$i);
13609: $env{'form.archive_'.$i} = 'display';
13610: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13611: $displayed{'folder'} = $i;
1.1164 raeburn 13612: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13613: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13614: $env{'form.archive_'.$i} = 'display';
13615: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13616: $displayed{'web'} = $i;
13617: } else {
1.1164 raeburn 13618: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13619: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13620: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13621: push(@{$env{'form.archive_directory'}},$i);
13622: }
13623: $env{'form.archive_'.$i} = 'dependency';
13624: }
13625: $total ++;
13626: }
13627: for (my $i=1; $i<$total; $i++) {
13628: next if ($i == $displayed{'web'});
13629: next if ($i == $displayed{'folder'});
13630: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13631: }
13632: $env{'form.phase'} = 'decompress_cleanup';
13633: $env{'form.archivedelete'} = 1;
13634: $env{'form.archive_count'} = $total-1;
13635: $output .=
13636: &process_extracted_files('coursedocs',$docudom,
13637: $docuname,$destination,
13638: $dir_root,$hiddenelem);
13639: }
1.1055 raeburn 13640: } else {
13641: $warning = &mt('No new items extracted from archive file.');
13642: }
13643: } else {
13644: $output = $display;
13645: $error = &mt('An error occurred during extraction from the archive file.');
13646: }
13647: }
13648: }
13649: }
13650: if ($error) {
13651: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13652: $error.'</p>'."\n";
13653: }
13654: if ($warning) {
13655: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13656: }
13657: return $output;
13658: }
13659:
13660: sub get_extracted {
1.1056 raeburn 13661: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13662: $titles,$wantform) = @_;
1.1055 raeburn 13663: my $count = 0;
13664: my $depth = 0;
13665: my $datatable;
1.1056 raeburn 13666: my @hierarchy;
1.1055 raeburn 13667: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13668: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13669: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13670: foreach my $item (@{$contents}) {
13671: $count ++;
1.1056 raeburn 13672: @{$dirorder->{$count}} = @hierarchy;
13673: $titles->{$count} = $item;
1.1055 raeburn 13674: &archive_hierarchy($depth,$count,$parent,$children);
13675: if ($wantform) {
13676: $datatable .= &archive_row($is_dir->{$item},$item,
13677: $currdir,$depth,$count);
13678: }
13679: if ($is_dir->{$item}) {
13680: $depth ++;
1.1056 raeburn 13681: push(@hierarchy,$count);
13682: $parent->{$depth} = $count;
1.1055 raeburn 13683: $datatable .=
13684: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13685: \$depth,\$count,\@hierarchy,$dirorder,
13686: $children,$parent,$titles,$wantform);
1.1055 raeburn 13687: $depth --;
1.1056 raeburn 13688: pop(@hierarchy);
1.1055 raeburn 13689: }
13690: }
13691: return ($count,$datatable);
13692: }
13693:
13694: sub recurse_extracted_archive {
1.1056 raeburn 13695: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13696: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13697: my $result='';
1.1056 raeburn 13698: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13699: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13700: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13701: return $result;
13702: }
13703: my $dirptr = 16384;
13704: my ($newdirlistref,$newlisterror) =
13705: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13706: if (ref($newdirlistref) eq 'ARRAY') {
13707: foreach my $dir_line (@{$newdirlistref}) {
13708: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13709: unless ($item =~ /^\.+$/) {
13710: $$count ++;
1.1056 raeburn 13711: @{$dirorder->{$$count}} = @{$hierarchy};
13712: $titles->{$$count} = $item;
1.1055 raeburn 13713: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13714:
1.1055 raeburn 13715: my $is_dir;
13716: if ($dirptr&$testdir) {
13717: $is_dir = 1;
13718: }
13719: if ($wantform) {
13720: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13721: }
13722: if ($is_dir) {
13723: $$depth ++;
1.1056 raeburn 13724: push(@{$hierarchy},$$count);
13725: $parent->{$$depth} = $$count;
1.1055 raeburn 13726: $result .=
13727: &recurse_extracted_archive("$currdir/$item",$docudom,
13728: $docuname,$depth,$count,
1.1056 raeburn 13729: $hierarchy,$dirorder,$children,
13730: $parent,$titles,$wantform);
1.1055 raeburn 13731: $$depth --;
1.1056 raeburn 13732: pop(@{$hierarchy});
1.1055 raeburn 13733: }
13734: }
13735: }
13736: }
13737: return $result;
13738: }
13739:
13740: sub archive_hierarchy {
13741: my ($depth,$count,$parent,$children) =@_;
13742: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13743: if (exists($parent->{$depth})) {
13744: $children->{$parent->{$depth}} .= $count.':';
13745: }
13746: }
13747: return;
13748: }
13749:
13750: sub archive_row {
13751: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13752: my ($name) = ($item =~ m{([^/]+)$});
13753: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13754: 'display' => 'Add as file',
1.1055 raeburn 13755: 'dependency' => 'Include as dependency',
13756: 'discard' => 'Discard',
13757: );
13758: if ($is_dir) {
1.1059 raeburn 13759: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13760: }
1.1056 raeburn 13761: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13762: my $offset = 0;
1.1055 raeburn 13763: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13764: $offset ++;
1.1065 raeburn 13765: if ($action ne 'display') {
13766: $offset ++;
13767: }
1.1055 raeburn 13768: $output .= '<td><span class="LC_nobreak">'.
13769: '<label><input type="radio" name="archive_'.$count.
13770: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13771: my $text = $choices{$action};
13772: if ($is_dir) {
13773: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13774: if ($action eq 'display') {
1.1059 raeburn 13775: $text = &mt('Add as folder');
1.1055 raeburn 13776: }
1.1056 raeburn 13777: } else {
13778: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13779:
13780: }
13781: $output .= ' /> '.$choices{$action}.'</label></span>';
13782: if ($action eq 'dependency') {
13783: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13784: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13785: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13786: '<option value=""></option>'."\n".
13787: '</select>'."\n".
13788: '</div>';
1.1059 raeburn 13789: } elsif ($action eq 'display') {
13790: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13791: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13792: '</div>';
1.1055 raeburn 13793: }
1.1056 raeburn 13794: $output .= '</td>';
1.1055 raeburn 13795: }
13796: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13797: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13798: for (my $i=0; $i<$depth; $i++) {
13799: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13800: }
13801: if ($is_dir) {
13802: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13803: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13804: } else {
13805: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13806: }
13807: $output .= ' '.$name.'</td>'."\n".
13808: &end_data_table_row();
13809: return $output;
13810: }
13811:
13812: sub archive_options_form {
1.1065 raeburn 13813: my ($form,$display,$count,$hiddenelem) = @_;
13814: my %lt = &Apache::lonlocal::texthash(
13815: perm => 'Permanently remove archive file?',
13816: hows => 'How should each extracted item be incorporated in the course?',
13817: cont => 'Content actions for all',
13818: addf => 'Add as folder/file',
13819: incd => 'Include as dependency for a displayed file',
13820: disc => 'Discard',
13821: no => 'No',
13822: yes => 'Yes',
13823: save => 'Save',
13824: );
13825: my $output = <<"END";
13826: <form name="$form" method="post" action="">
13827: <p><span class="LC_nobreak">$lt{'perm'}
13828: <label>
13829: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13830: </label>
13831:
13832: <label>
13833: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13834: </span>
13835: </p>
13836: <input type="hidden" name="phase" value="decompress_cleanup" />
13837: <br />$lt{'hows'}
13838: <div class="LC_columnSection">
13839: <fieldset>
13840: <legend>$lt{'cont'}</legend>
13841: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13842: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13843: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13844: </fieldset>
13845: </div>
13846: END
13847: return $output.
1.1055 raeburn 13848: &start_data_table()."\n".
1.1065 raeburn 13849: $display."\n".
1.1055 raeburn 13850: &end_data_table()."\n".
13851: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13852: $hiddenelem.
1.1065 raeburn 13853: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13854: '</form>';
13855: }
13856:
13857: sub archive_javascript {
1.1056 raeburn 13858: my ($startcount,$numitems,$titles,$children) = @_;
13859: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13860: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13861: my $scripttag = <<START;
13862: <script type="text/javascript">
13863: // <![CDATA[
13864:
13865: function checkAll(form,prefix) {
13866: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13867: for (var i=0; i < form.elements.length; i++) {
13868: var id = form.elements[i].id;
13869: if ((id != '') && (id != undefined)) {
13870: if (idstr.test(id)) {
13871: if (form.elements[i].type == 'radio') {
13872: form.elements[i].checked = true;
1.1056 raeburn 13873: var nostart = i-$startcount;
1.1059 raeburn 13874: var offset = nostart%7;
13875: var count = (nostart-offset)/7;
1.1056 raeburn 13876: dependencyCheck(form,count,offset);
1.1055 raeburn 13877: }
13878: }
13879: }
13880: }
13881: }
13882:
13883: function propagateCheck(form,count) {
13884: if (count > 0) {
1.1059 raeburn 13885: var startelement = $startcount + ((count-1) * 7);
13886: for (var j=1; j<6; j++) {
13887: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13888: var item = startelement + j;
13889: if (form.elements[item].type == 'radio') {
13890: if (form.elements[item].checked) {
13891: containerCheck(form,count,j);
13892: break;
13893: }
1.1055 raeburn 13894: }
13895: }
13896: }
13897: }
13898: }
13899:
13900: numitems = $numitems
1.1056 raeburn 13901: var titles = new Array(numitems);
13902: var parents = new Array(numitems);
1.1055 raeburn 13903: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13904: parents[i] = new Array;
1.1055 raeburn 13905: }
1.1059 raeburn 13906: var maintitle = '$maintitle';
1.1055 raeburn 13907:
13908: START
13909:
1.1056 raeburn 13910: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13911: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13912: for (my $i=0; $i<@contents; $i ++) {
13913: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13914: }
13915: }
13916:
1.1056 raeburn 13917: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13918: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13919: }
13920:
1.1055 raeburn 13921: $scripttag .= <<END;
13922:
13923: function containerCheck(form,count,offset) {
13924: if (count > 0) {
1.1056 raeburn 13925: dependencyCheck(form,count,offset);
1.1059 raeburn 13926: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13927: form.elements[item].checked = true;
13928: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13929: if (parents[count].length > 0) {
13930: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13931: containerCheck(form,parents[count][j],offset);
13932: }
13933: }
13934: }
13935: }
13936: }
13937:
13938: function dependencyCheck(form,count,offset) {
13939: if (count > 0) {
1.1059 raeburn 13940: var chosen = (offset+$startcount)+7*(count-1);
13941: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13942: var currtype = form.elements[depitem].type;
13943: if (form.elements[chosen].value == 'dependency') {
13944: document.getElementById('arc_depon_'+count).style.display='block';
13945: form.elements[depitem].options.length = 0;
13946: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13947: for (var i=1; i<=numitems; i++) {
13948: if (i == count) {
13949: continue;
13950: }
1.1059 raeburn 13951: var startelement = $startcount + (i-1) * 7;
13952: for (var j=1; j<6; j++) {
13953: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13954: var item = startelement + j;
13955: if (form.elements[item].type == 'radio') {
13956: if (form.elements[item].checked) {
13957: if (form.elements[item].value == 'display') {
13958: var n = form.elements[depitem].options.length;
13959: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13960: }
13961: }
13962: }
13963: }
13964: }
13965: }
13966: } else {
13967: document.getElementById('arc_depon_'+count).style.display='none';
13968: form.elements[depitem].options.length = 0;
13969: form.elements[depitem].options[0] = new Option('Select','',true,true);
13970: }
1.1059 raeburn 13971: titleCheck(form,count,offset);
1.1056 raeburn 13972: }
13973: }
13974:
13975: function propagateSelect(form,count,offset) {
13976: if (count > 0) {
1.1065 raeburn 13977: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13978: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13979: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13980: if (parents[count].length > 0) {
13981: for (var j=0; j<parents[count].length; j++) {
13982: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13983: }
13984: }
13985: }
13986: }
13987: }
1.1056 raeburn 13988:
13989: function containerSelect(form,count,offset,picked) {
13990: if (count > 0) {
1.1065 raeburn 13991: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13992: if (form.elements[item].type == 'radio') {
13993: if (form.elements[item].value == 'dependency') {
13994: if (form.elements[item+1].type == 'select-one') {
13995: for (var i=0; i<form.elements[item+1].options.length; i++) {
13996: if (form.elements[item+1].options[i].value == picked) {
13997: form.elements[item+1].selectedIndex = i;
13998: break;
13999: }
14000: }
14001: }
14002: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14003: if (parents[count].length > 0) {
14004: for (var j=0; j<parents[count].length; j++) {
14005: containerSelect(form,parents[count][j],offset,picked);
14006: }
14007: }
14008: }
14009: }
14010: }
14011: }
14012: }
14013:
1.1059 raeburn 14014: function titleCheck(form,count,offset) {
14015: if (count > 0) {
14016: var chosen = (offset+$startcount)+7*(count-1);
14017: var depitem = $startcount + ((count-1) * 7) + 2;
14018: var currtype = form.elements[depitem].type;
14019: if (form.elements[chosen].value == 'display') {
14020: document.getElementById('arc_title_'+count).style.display='block';
14021: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14022: document.getElementById('archive_title_'+count).value=maintitle;
14023: }
14024: } else {
14025: document.getElementById('arc_title_'+count).style.display='none';
14026: if (currtype == 'text') {
14027: document.getElementById('archive_title_'+count).value='';
14028: }
14029: }
14030: }
14031: return;
14032: }
14033:
1.1055 raeburn 14034: // ]]>
14035: </script>
14036: END
14037: return $scripttag;
14038: }
14039:
14040: sub process_extracted_files {
1.1067 raeburn 14041: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14042: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14043: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14044: my @ids=&Apache::lonnet::current_machine_ids();
14045: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14046: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14047: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14048: if (grep(/^\Q$docuhome\E$/,@ids)) {
14049: $prefix = &LONCAPA::propath($docudom,$docuname);
14050: $pathtocheck = "$dir_root/$destination";
14051: $dir = $dir_root;
14052: $ishome = 1;
14053: } else {
14054: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14055: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14056: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14057: }
14058: my $currdir = "$dir_root/$destination";
14059: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14060: if ($env{'form.folderpath'}) {
14061: my @items = split('&',$env{'form.folderpath'});
14062: $folders{'0'} = $items[-2];
1.1099 raeburn 14063: if ($env{'form.folderpath'} =~ /\:1$/) {
14064: $containers{'0'}='page';
14065: } else {
14066: $containers{'0'}='sequence';
14067: }
1.1055 raeburn 14068: }
14069: my @archdirs = &get_env_multiple('form.archive_directory');
14070: if ($numitems) {
14071: for (my $i=1; $i<=$numitems; $i++) {
14072: my $path = $env{'form.archive_content_'.$i};
14073: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14074: my $item = $1;
14075: $toplevelitems{$item} = $i;
14076: if (grep(/^\Q$i\E$/,@archdirs)) {
14077: $is_dir{$item} = 1;
14078: }
14079: }
14080: }
14081: }
1.1067 raeburn 14082: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14083: if (keys(%toplevelitems) > 0) {
14084: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14085: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14086: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14087: }
1.1066 raeburn 14088: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14089: if ($numitems) {
14090: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14091: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14092: my $path = $env{'form.archive_content_'.$i};
14093: if ($path =~ /^\Q$pathtocheck\E/) {
14094: if ($env{'form.archive_'.$i} eq 'discard') {
14095: if ($prefix ne '' && $path ne '') {
14096: if (-e $prefix.$path) {
1.1066 raeburn 14097: if ((@archdirs > 0) &&
14098: (grep(/^\Q$i\E$/,@archdirs))) {
14099: $todeletedir{$prefix.$path} = 1;
14100: } else {
14101: $todelete{$prefix.$path} = 1;
14102: }
1.1055 raeburn 14103: }
14104: }
14105: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14106: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14107: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14108: $docstitle = $env{'form.archive_title_'.$i};
14109: if ($docstitle eq '') {
14110: $docstitle = $title;
14111: }
1.1055 raeburn 14112: $outer = 0;
1.1056 raeburn 14113: if (ref($dirorder{$i}) eq 'ARRAY') {
14114: if (@{$dirorder{$i}} > 0) {
14115: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14116: if ($env{'form.archive_'.$item} eq 'display') {
14117: $outer = $item;
14118: last;
14119: }
14120: }
14121: }
14122: }
14123: my ($errtext,$fatal) =
14124: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14125: '/'.$folders{$outer}.'.'.
14126: $containers{$outer});
14127: next if ($fatal);
14128: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14129: if ($context eq 'coursedocs') {
1.1056 raeburn 14130: $mapinner{$i} = time;
1.1055 raeburn 14131: $folders{$i} = 'default_'.$mapinner{$i};
14132: $containers{$i} = 'sequence';
14133: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14134: $folders{$i}.'.'.$containers{$i};
14135: my $newidx = &LONCAPA::map::getresidx();
14136: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14137: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14138: push(@LONCAPA::map::order,$newidx);
14139: my ($outtext,$errtext) =
14140: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14141: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14142: '.'.$containers{$outer},1,1);
1.1056 raeburn 14143: $newseqid{$i} = $newidx;
1.1067 raeburn 14144: unless ($errtext) {
1.1294 raeburn 14145: $result .= '<li>'.&mt('Folder: [_1] added to course',
14146: &HTML::Entities::encode($docstitle,'<>&"')).
14147: '</li>'."\n";
1.1067 raeburn 14148: }
1.1055 raeburn 14149: }
14150: } else {
14151: if ($context eq 'coursedocs') {
14152: my $newidx=&LONCAPA::map::getresidx();
14153: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14154: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14155: $title;
1.1294 raeburn 14156: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
14157: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14158: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14159: }
14160: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14161: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14162: }
14163: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14164: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14165: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14166: unless ($ishome) {
14167: my $fetch = "$newdest{$i}/$title";
14168: $fetch =~ s/^\Q$prefix$dir\E//;
14169: $prompttofetch{$fetch} = 1;
14170: }
1.1292 raeburn 14171: }
1.1067 raeburn 14172: }
1.1294 raeburn 14173: $LONCAPA::map::resources[$newidx]=
14174: $docstitle.':'.$url.':false:normal:res';
14175: push(@LONCAPA::map::order, $newidx);
14176: my ($outtext,$errtext)=
14177: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14178: $docuname.'/'.$folders{$outer}.
14179: '.'.$containers{$outer},1,1);
14180: unless ($errtext) {
14181: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14182: $result .= '<li>'.&mt('File: [_1] added to course',
14183: &HTML::Entities::encode($docstitle,'<>&"')).
14184: '</li>'."\n";
14185: }
1.1067 raeburn 14186: }
1.1294 raeburn 14187: } else {
14188: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14189: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14190: }
1.1055 raeburn 14191: }
14192: }
1.1086 raeburn 14193: }
14194: } else {
1.1294 raeburn 14195: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14196: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14197: }
14198: }
14199: for (my $i=1; $i<=$numitems; $i++) {
14200: next unless ($env{'form.archive_'.$i} eq 'dependency');
14201: my $path = $env{'form.archive_content_'.$i};
14202: if ($path =~ /^\Q$pathtocheck\E/) {
14203: my ($title) = ($path =~ m{/([^/]+)$});
14204: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14205: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14206: if (ref($dirorder{$i}) eq 'ARRAY') {
14207: my ($itemidx,$fullpath,$relpath);
14208: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14209: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14210: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14211: if ($dirorder{$i}->[$j] eq $container) {
14212: $itemidx = $j;
1.1056 raeburn 14213: }
14214: }
1.1086 raeburn 14215: }
14216: if ($itemidx eq '') {
14217: $itemidx = 0;
14218: }
14219: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14220: if ($mapinner{$referrer{$i}}) {
14221: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14222: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14223: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14224: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14225: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14226: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14227: if (!-e $fullpath) {
14228: mkdir($fullpath,0755);
1.1056 raeburn 14229: }
14230: }
1.1086 raeburn 14231: } else {
14232: last;
1.1056 raeburn 14233: }
1.1086 raeburn 14234: }
14235: }
14236: } elsif ($newdest{$referrer{$i}}) {
14237: $fullpath = $newdest{$referrer{$i}};
14238: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14239: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14240: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14241: last;
14242: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14243: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14244: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14245: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14246: if (!-e $fullpath) {
14247: mkdir($fullpath,0755);
1.1056 raeburn 14248: }
14249: }
1.1086 raeburn 14250: } else {
14251: last;
1.1056 raeburn 14252: }
1.1055 raeburn 14253: }
14254: }
1.1086 raeburn 14255: if ($fullpath ne '') {
14256: if (-e "$prefix$path") {
1.1292 raeburn 14257: unless (rename("$prefix$path","$fullpath/$title")) {
14258: $warning .= &mt('Failed to rename dependency').'<br />';
14259: }
1.1086 raeburn 14260: }
14261: if (-e "$fullpath/$title") {
14262: my $showpath;
14263: if ($relpath ne '') {
14264: $showpath = "$relpath/$title";
14265: } else {
14266: $showpath = "/$title";
14267: }
1.1294 raeburn 14268: $result .= '<li>'.&mt('[_1] included as a dependency',
14269: &HTML::Entities::encode($showpath,'<>&"')).
14270: '</li>'."\n";
1.1292 raeburn 14271: unless ($ishome) {
14272: my $fetch = "$fullpath/$title";
14273: $fetch =~ s/^\Q$prefix$dir\E//;
14274: $prompttofetch{$fetch} = 1;
14275: }
1.1086 raeburn 14276: }
14277: }
1.1055 raeburn 14278: }
1.1086 raeburn 14279: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14280: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14281: &HTML::Entities::encode($path,'<>&"'),
14282: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14283: '<br />';
1.1055 raeburn 14284: }
14285: } else {
1.1294 raeburn 14286: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14287: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14288: }
14289: }
14290: if (keys(%todelete)) {
14291: foreach my $key (keys(%todelete)) {
14292: unlink($key);
1.1066 raeburn 14293: }
14294: }
14295: if (keys(%todeletedir)) {
14296: foreach my $key (keys(%todeletedir)) {
14297: rmdir($key);
14298: }
14299: }
14300: foreach my $dir (sort(keys(%is_dir))) {
14301: if (($pathtocheck ne '') && ($dir ne '')) {
14302: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14303: }
14304: }
1.1067 raeburn 14305: if ($result ne '') {
14306: $output .= '<ul>'."\n".
14307: $result."\n".
14308: '</ul>';
14309: }
14310: unless ($ishome) {
14311: my $replicationfail;
14312: foreach my $item (keys(%prompttofetch)) {
14313: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14314: unless ($fetchresult eq 'ok') {
14315: $replicationfail .= '<li>'.$item.'</li>'."\n";
14316: }
14317: }
14318: if ($replicationfail) {
14319: $output .= '<p class="LC_error">'.
14320: &mt('Course home server failed to retrieve:').'<ul>'.
14321: $replicationfail.
14322: '</ul></p>';
14323: }
14324: }
1.1055 raeburn 14325: } else {
14326: $warning = &mt('No items found in archive.');
14327: }
14328: if ($error) {
14329: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14330: $error.'</p>'."\n";
14331: }
14332: if ($warning) {
14333: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14334: }
14335: return $output;
14336: }
14337:
1.1066 raeburn 14338: sub cleanup_empty_dirs {
14339: my ($path) = @_;
14340: if (($path ne '') && (-d $path)) {
14341: if (opendir(my $dirh,$path)) {
14342: my @dircontents = grep(!/^\./,readdir($dirh));
14343: my $numitems = 0;
14344: foreach my $item (@dircontents) {
14345: if (-d "$path/$item") {
1.1111 raeburn 14346: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14347: if (-e "$path/$item") {
14348: $numitems ++;
14349: }
14350: } else {
14351: $numitems ++;
14352: }
14353: }
14354: if ($numitems == 0) {
14355: rmdir($path);
14356: }
14357: closedir($dirh);
14358: }
14359: }
14360: return;
14361: }
14362:
1.41 ng 14363: =pod
1.45 matthew 14364:
1.1162 raeburn 14365: =item * &get_folder_hierarchy()
1.1068 raeburn 14366:
14367: Provides hierarchy of names of folders/sub-folders containing the current
14368: item,
14369:
14370: Inputs: 3
14371: - $navmap - navmaps object
14372:
14373: - $map - url for map (either the trigger itself, or map containing
14374: the resource, which is the trigger).
14375:
14376: - $showitem - 1 => show title for map itself; 0 => do not show.
14377:
14378: Outputs: 1 @pathitems - array of folder/subfolder names.
14379:
14380: =cut
14381:
14382: sub get_folder_hierarchy {
14383: my ($navmap,$map,$showitem) = @_;
14384: my @pathitems;
14385: if (ref($navmap)) {
14386: my $mapres = $navmap->getResourceByUrl($map);
14387: if (ref($mapres)) {
14388: my $pcslist = $mapres->map_hierarchy();
14389: if ($pcslist ne '') {
14390: my @pcs = split(/,/,$pcslist);
14391: foreach my $pc (@pcs) {
14392: if ($pc == 1) {
1.1129 raeburn 14393: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14394: } else {
14395: my $res = $navmap->getByMapPc($pc);
14396: if (ref($res)) {
14397: my $title = $res->compTitle();
14398: $title =~ s/\W+/_/g;
14399: if ($title ne '') {
14400: push(@pathitems,$title);
14401: }
14402: }
14403: }
14404: }
14405: }
1.1071 raeburn 14406: if ($showitem) {
14407: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14408: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14409: } else {
14410: my $maptitle = $mapres->compTitle();
14411: $maptitle =~ s/\W+/_/g;
14412: if ($maptitle ne '') {
14413: push(@pathitems,$maptitle);
14414: }
1.1068 raeburn 14415: }
14416: }
14417: }
14418: }
14419: return @pathitems;
14420: }
14421:
14422: =pod
14423:
1.1015 raeburn 14424: =item * &get_turnedin_filepath()
14425:
14426: Determines path in a user's portfolio file for storage of files uploaded
14427: to a specific essayresponse or dropbox item.
14428:
14429: Inputs: 3 required + 1 optional.
14430: $symb is symb for resource, $uname and $udom are for current user (required).
14431: $caller is optional (can be "submission", if routine is called when storing
14432: an upoaded file when "Submit Answer" button was pressed).
14433:
14434: Returns array containing $path and $multiresp.
14435: $path is path in portfolio. $multiresp is 1 if this resource contains more
14436: than one file upload item. Callers of routine should append partid as a
14437: subdirectory to $path in cases where $multiresp is 1.
14438:
14439: Called by: homework/essayresponse.pm and homework/structuretags.pm
14440:
14441: =cut
14442:
14443: sub get_turnedin_filepath {
14444: my ($symb,$uname,$udom,$caller) = @_;
14445: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14446: my $turnindir;
14447: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14448: $turnindir = $userhash{'turnindir'};
14449: my ($path,$multiresp);
14450: if ($turnindir eq '') {
14451: if ($caller eq 'submission') {
14452: $turnindir = &mt('turned in');
14453: $turnindir =~ s/\W+/_/g;
14454: my %newhash = (
14455: 'turnindir' => $turnindir,
14456: );
14457: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14458: }
14459: }
14460: if ($turnindir ne '') {
14461: $path = '/'.$turnindir.'/';
14462: my ($multipart,$turnin,@pathitems);
14463: my $navmap = Apache::lonnavmaps::navmap->new();
14464: if (defined($navmap)) {
14465: my $mapres = $navmap->getResourceByUrl($map);
14466: if (ref($mapres)) {
14467: my $pcslist = $mapres->map_hierarchy();
14468: if ($pcslist ne '') {
14469: foreach my $pc (split(/,/,$pcslist)) {
14470: my $res = $navmap->getByMapPc($pc);
14471: if (ref($res)) {
14472: my $title = $res->compTitle();
14473: $title =~ s/\W+/_/g;
14474: if ($title ne '') {
1.1149 raeburn 14475: if (($pc > 1) && (length($title) > 12)) {
14476: $title = substr($title,0,12);
14477: }
1.1015 raeburn 14478: push(@pathitems,$title);
14479: }
14480: }
14481: }
14482: }
14483: my $maptitle = $mapres->compTitle();
14484: $maptitle =~ s/\W+/_/g;
14485: if ($maptitle ne '') {
1.1149 raeburn 14486: if (length($maptitle) > 12) {
14487: $maptitle = substr($maptitle,0,12);
14488: }
1.1015 raeburn 14489: push(@pathitems,$maptitle);
14490: }
14491: unless ($env{'request.state'} eq 'construct') {
14492: my $res = $navmap->getBySymb($symb);
14493: if (ref($res)) {
14494: my $partlist = $res->parts();
14495: my $totaluploads = 0;
14496: if (ref($partlist) eq 'ARRAY') {
14497: foreach my $part (@{$partlist}) {
14498: my @types = $res->responseType($part);
14499: my @ids = $res->responseIds($part);
14500: for (my $i=0; $i < scalar(@ids); $i++) {
14501: if ($types[$i] eq 'essay') {
14502: my $partid = $part.'_'.$ids[$i];
14503: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14504: $totaluploads ++;
14505: }
14506: }
14507: }
14508: }
14509: if ($totaluploads > 1) {
14510: $multiresp = 1;
14511: }
14512: }
14513: }
14514: }
14515: } else {
14516: return;
14517: }
14518: } else {
14519: return;
14520: }
14521: my $restitle=&Apache::lonnet::gettitle($symb);
14522: $restitle =~ s/\W+/_/g;
14523: if ($restitle eq '') {
14524: $restitle = ($resurl =~ m{/[^/]+$});
14525: if ($restitle eq '') {
14526: $restitle = time;
14527: }
14528: }
1.1149 raeburn 14529: if (length($restitle) > 12) {
14530: $restitle = substr($restitle,0,12);
14531: }
1.1015 raeburn 14532: push(@pathitems,$restitle);
14533: $path .= join('/',@pathitems);
14534: }
14535: return ($path,$multiresp);
14536: }
14537:
14538: =pod
14539:
1.464 albertel 14540: =back
1.41 ng 14541:
1.112 bowersj2 14542: =head1 CSV Upload/Handling functions
1.38 albertel 14543:
1.41 ng 14544: =over 4
14545:
1.648 raeburn 14546: =item * &upfile_store($r)
1.41 ng 14547:
14548: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14549: needs $env{'form.upfile'}
1.41 ng 14550: returns $datatoken to be put into hidden field
14551:
14552: =cut
1.31 albertel 14553:
14554: sub upfile_store {
14555: my $r=shift;
1.258 albertel 14556: $env{'form.upfile'}=~s/\r/\n/gs;
14557: $env{'form.upfile'}=~s/\f/\n/gs;
14558: $env{'form.upfile'}=~s/\n+/\n/gs;
14559: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14560:
1.1299 raeburn 14561: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14562: '_enroll_'.$env{'request.course.id'}.'_'.
14563: time.'_'.$$);
14564: return if ($datatoken eq '');
14565:
1.31 albertel 14566: {
1.158 raeburn 14567: my $datafile = $r->dir_config('lonDaemons').
14568: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14569: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14570: print $fh $env{'form.upfile'};
1.158 raeburn 14571: close($fh);
14572: }
1.31 albertel 14573: }
14574: return $datatoken;
14575: }
14576:
1.56 matthew 14577: =pod
14578:
1.1290 raeburn 14579: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14580:
14581: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14582: $datatoken is the name to assign to the temporary file.
1.258 albertel 14583: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14584:
14585: =cut
1.31 albertel 14586:
14587: sub load_tmp_file {
1.1290 raeburn 14588: my ($r,$datatoken) = @_;
14589: return if ($datatoken eq '');
1.31 albertel 14590: my @studentdata=();
14591: {
1.158 raeburn 14592: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14593: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14594: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14595: @studentdata=<$fh>;
14596: close($fh);
14597: }
1.31 albertel 14598: }
1.258 albertel 14599: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14600: }
14601:
1.1290 raeburn 14602: sub valid_datatoken {
14603: my ($datatoken) = @_;
1.1325 raeburn 14604: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14605: return $datatoken;
14606: }
14607: return;
14608: }
14609:
1.56 matthew 14610: =pod
14611:
1.648 raeburn 14612: =item * &upfile_record_sep()
1.41 ng 14613:
14614: Separate uploaded file into records
14615: returns array of records,
1.258 albertel 14616: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14617:
14618: =cut
1.31 albertel 14619:
14620: sub upfile_record_sep {
1.258 albertel 14621: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14622: } else {
1.248 albertel 14623: my @records;
1.258 albertel 14624: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14625: if ($line=~/^\s*$/) { next; }
14626: push(@records,$line);
14627: }
14628: return @records;
1.31 albertel 14629: }
14630: }
14631:
1.56 matthew 14632: =pod
14633:
1.648 raeburn 14634: =item * &record_sep($record)
1.41 ng 14635:
1.258 albertel 14636: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14637:
14638: =cut
14639:
1.263 www 14640: sub takeleft {
14641: my $index=shift;
14642: return substr('0000'.$index,-4,4);
14643: }
14644:
1.31 albertel 14645: sub record_sep {
14646: my $record=shift;
14647: my %components=();
1.258 albertel 14648: if ($env{'form.upfiletype'} eq 'xml') {
14649: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14650: my $i=0;
1.356 albertel 14651: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14652: $field=~s/^(\"|\')//;
14653: $field=~s/(\"|\')$//;
1.263 www 14654: $components{&takeleft($i)}=$field;
1.31 albertel 14655: $i++;
14656: }
1.258 albertel 14657: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14658: my $i=0;
1.356 albertel 14659: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14660: $field=~s/^(\"|\')//;
14661: $field=~s/(\"|\')$//;
1.263 www 14662: $components{&takeleft($i)}=$field;
1.31 albertel 14663: $i++;
14664: }
14665: } else {
1.561 www 14666: my $separator=',';
1.480 banghart 14667: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14668: $separator=';';
1.480 banghart 14669: }
1.31 albertel 14670: my $i=0;
1.561 www 14671: # the character we are looking for to indicate the end of a quote or a record
14672: my $looking_for=$separator;
14673: # do not add the characters to the fields
14674: my $ignore=0;
14675: # we just encountered a separator (or the beginning of the record)
14676: my $just_found_separator=1;
14677: # store the field we are working on here
14678: my $field='';
14679: # work our way through all characters in record
14680: foreach my $character ($record=~/(.)/g) {
14681: if ($character eq $looking_for) {
14682: if ($character ne $separator) {
14683: # Found the end of a quote, again looking for separator
14684: $looking_for=$separator;
14685: $ignore=1;
14686: } else {
14687: # Found a separator, store away what we got
14688: $components{&takeleft($i)}=$field;
14689: $i++;
14690: $just_found_separator=1;
14691: $ignore=0;
14692: $field='';
14693: }
14694: next;
14695: }
14696: # single or double quotation marks after a separator indicate beginning of a quote
14697: # we are now looking for the end of the quote and need to ignore separators
14698: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14699: $looking_for=$character;
14700: next;
14701: }
14702: # ignore would be true after we reached the end of a quote
14703: if ($ignore) { next; }
14704: if (($just_found_separator) && ($character=~/\s/)) { next; }
14705: $field.=$character;
14706: $just_found_separator=0;
1.31 albertel 14707: }
1.561 www 14708: # catch the very last entry, since we never encountered the separator
14709: $components{&takeleft($i)}=$field;
1.31 albertel 14710: }
14711: return %components;
14712: }
14713:
1.144 matthew 14714: ######################################################
14715: ######################################################
14716:
1.56 matthew 14717: =pod
14718:
1.648 raeburn 14719: =item * &upfile_select_html()
1.41 ng 14720:
1.144 matthew 14721: Return HTML code to select a file from the users machine and specify
14722: the file type.
1.41 ng 14723:
14724: =cut
14725:
1.144 matthew 14726: ######################################################
14727: ######################################################
1.31 albertel 14728: sub upfile_select_html {
1.144 matthew 14729: my %Types = (
14730: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14731: semisv => &mt('Semicolon separated values'),
1.144 matthew 14732: space => &mt('Space separated'),
14733: tab => &mt('Tabulator separated'),
14734: # xml => &mt('HTML/XML'),
14735: );
14736: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14737: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14738: foreach my $type (sort(keys(%Types))) {
14739: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14740: }
14741: $Str .= "</select>\n";
14742: return $Str;
1.31 albertel 14743: }
14744:
1.301 albertel 14745: sub get_samples {
14746: my ($records,$toget) = @_;
14747: my @samples=({});
14748: my $got=0;
14749: foreach my $rec (@$records) {
14750: my %temp = &record_sep($rec);
14751: if (! grep(/\S/, values(%temp))) { next; }
14752: if (%temp) {
14753: $samples[$got]=\%temp;
14754: $got++;
14755: if ($got == $toget) { last; }
14756: }
14757: }
14758: return \@samples;
14759: }
14760:
1.144 matthew 14761: ######################################################
14762: ######################################################
14763:
1.56 matthew 14764: =pod
14765:
1.648 raeburn 14766: =item * &csv_print_samples($r,$records)
1.41 ng 14767:
14768: Prints a table of sample values from each column uploaded $r is an
14769: Apache Request ref, $records is an arrayref from
14770: &Apache::loncommon::upfile_record_sep
14771:
14772: =cut
14773:
1.144 matthew 14774: ######################################################
14775: ######################################################
1.31 albertel 14776: sub csv_print_samples {
14777: my ($r,$records) = @_;
1.662 bisitz 14778: my $samples = &get_samples($records,5);
1.301 albertel 14779:
1.594 raeburn 14780: $r->print(&mt('Samples').'<br />'.&start_data_table().
14781: &start_data_table_header_row());
1.356 albertel 14782: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14783: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14784: $r->print(&end_data_table_header_row());
1.301 albertel 14785: foreach my $hash (@$samples) {
1.594 raeburn 14786: $r->print(&start_data_table_row());
1.356 albertel 14787: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14788: $r->print('<td>');
1.356 albertel 14789: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14790: $r->print('</td>');
14791: }
1.594 raeburn 14792: $r->print(&end_data_table_row());
1.31 albertel 14793: }
1.594 raeburn 14794: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14795: }
14796:
1.144 matthew 14797: ######################################################
14798: ######################################################
14799:
1.56 matthew 14800: =pod
14801:
1.648 raeburn 14802: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14803:
14804: Prints a table to create associations between values and table columns.
1.144 matthew 14805:
1.41 ng 14806: $r is an Apache Request ref,
14807: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14808: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14809:
14810: =cut
14811:
1.144 matthew 14812: ######################################################
14813: ######################################################
1.31 albertel 14814: sub csv_print_select_table {
14815: my ($r,$records,$d) = @_;
1.301 albertel 14816: my $i=0;
14817: my $samples = &get_samples($records,1);
1.144 matthew 14818: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14819: &start_data_table().&start_data_table_header_row().
1.144 matthew 14820: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14821: '<th>'.&mt('Column').'</th>'.
14822: &end_data_table_header_row()."\n");
1.356 albertel 14823: foreach my $array_ref (@$d) {
14824: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14825: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14826:
1.875 bisitz 14827: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14828: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14829: $r->print('<option value="none"></option>');
1.356 albertel 14830: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14831: $r->print('<option value="'.$sample.'"'.
14832: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14833: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14834: }
1.594 raeburn 14835: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14836: $i++;
14837: }
1.594 raeburn 14838: $r->print(&end_data_table());
1.31 albertel 14839: $i--;
14840: return $i;
14841: }
1.56 matthew 14842:
1.144 matthew 14843: ######################################################
14844: ######################################################
14845:
1.56 matthew 14846: =pod
1.31 albertel 14847:
1.648 raeburn 14848: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14849:
14850: Prints a table of sample values from the upload and can make associate samples to internal names.
14851:
14852: $r is an Apache Request ref,
14853: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14854: $d is an array of 2 element arrays (internal name, displayed name)
14855:
14856: =cut
14857:
1.144 matthew 14858: ######################################################
14859: ######################################################
1.31 albertel 14860: sub csv_samples_select_table {
14861: my ($r,$records,$d) = @_;
14862: my $i=0;
1.144 matthew 14863: #
1.662 bisitz 14864: my $max_samples = 5;
14865: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14866: $r->print(&start_data_table().
14867: &start_data_table_header_row().'<th>'.
14868: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14869: &end_data_table_header_row());
1.301 albertel 14870:
14871: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14872: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14873: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14874: foreach my $option (@$d) {
14875: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14876: $r->print('<option value="'.$value.'"'.
1.253 albertel 14877: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14878: $display.'</option>');
1.31 albertel 14879: }
14880: $r->print('</select></td><td>');
1.662 bisitz 14881: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14882: if (defined($samples->[$line]{$key})) {
14883: $r->print($samples->[$line]{$key}."<br />\n");
14884: }
14885: }
1.594 raeburn 14886: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14887: $i++;
14888: }
1.594 raeburn 14889: $r->print(&end_data_table());
1.31 albertel 14890: $i--;
14891: return($i);
1.115 matthew 14892: }
14893:
1.144 matthew 14894: ######################################################
14895: ######################################################
14896:
1.115 matthew 14897: =pod
14898:
1.648 raeburn 14899: =item * &clean_excel_name($name)
1.115 matthew 14900:
14901: Returns a replacement for $name which does not contain any illegal characters.
14902:
14903: =cut
14904:
1.144 matthew 14905: ######################################################
14906: ######################################################
1.115 matthew 14907: sub clean_excel_name {
14908: my ($name) = @_;
14909: $name =~ s/[:\*\?\/\\]//g;
14910: if (length($name) > 31) {
14911: $name = substr($name,0,31);
14912: }
14913: return $name;
1.25 albertel 14914: }
1.84 albertel 14915:
1.85 albertel 14916: =pod
14917:
1.648 raeburn 14918: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14919:
14920: Returns either 1 or undef
14921:
14922: 1 if the part is to be hidden, undef if it is to be shown
14923:
14924: Arguments are:
14925:
14926: $id the id of the part to be checked
14927: $symb, optional the symb of the resource to check
14928: $udom, optional the domain of the user to check for
14929: $uname, optional the username of the user to check for
14930:
14931: =cut
1.84 albertel 14932:
14933: sub check_if_partid_hidden {
14934: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14935: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14936: $symb,$udom,$uname);
1.141 albertel 14937: my $truth=1;
14938: #if the string starts with !, then the list is the list to show not hide
14939: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14940: my @hiddenlist=split(/,/,$hiddenparts);
14941: foreach my $checkid (@hiddenlist) {
1.141 albertel 14942: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14943: }
1.141 albertel 14944: return !$truth;
1.84 albertel 14945: }
1.127 matthew 14946:
1.138 matthew 14947:
14948: ############################################################
14949: ############################################################
14950:
14951: =pod
14952:
1.157 matthew 14953: =back
14954:
1.138 matthew 14955: =head1 cgi-bin script and graphing routines
14956:
1.157 matthew 14957: =over 4
14958:
1.648 raeburn 14959: =item * &get_cgi_id()
1.138 matthew 14960:
14961: Inputs: none
14962:
14963: Returns an id which can be used to pass environment variables
14964: to various cgi-bin scripts. These environment variables will
14965: be removed from the users environment after a given time by
14966: the routine &Apache::lonnet::transfer_profile_to_env.
14967:
14968: =cut
14969:
14970: ############################################################
14971: ############################################################
1.152 albertel 14972: my $uniq=0;
1.136 matthew 14973: sub get_cgi_id {
1.154 albertel 14974: $uniq=($uniq+1)%100000;
1.280 albertel 14975: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14976: }
14977:
1.127 matthew 14978: ############################################################
14979: ############################################################
14980:
14981: =pod
14982:
1.648 raeburn 14983: =item * &DrawBarGraph()
1.127 matthew 14984:
1.138 matthew 14985: Facilitates the plotting of data in a (stacked) bar graph.
14986: Puts plot definition data into the users environment in order for
14987: graph.png to plot it. Returns an <img> tag for the plot.
14988: The bars on the plot are labeled '1','2',...,'n'.
14989:
14990: Inputs:
14991:
14992: =over 4
14993:
14994: =item $Title: string, the title of the plot
14995:
14996: =item $xlabel: string, text describing the X-axis of the plot
14997:
14998: =item $ylabel: string, text describing the Y-axis of the plot
14999:
15000: =item $Max: scalar, the maximum Y value to use in the plot
15001: If $Max is < any data point, the graph will not be rendered.
15002:
1.140 matthew 15003: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15004: they are plotted. If undefined, default values will be used.
15005:
1.178 matthew 15006: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15007:
1.138 matthew 15008: =item @Values: An array of array references. Each array reference holds data
15009: to be plotted in a stacked bar chart.
15010:
1.239 matthew 15011: =item If the final element of @Values is a hash reference the key/value
15012: pairs will be added to the graph definition.
15013:
1.138 matthew 15014: =back
15015:
15016: Returns:
15017:
15018: An <img> tag which references graph.png and the appropriate identifying
15019: information for the plot.
15020:
1.127 matthew 15021: =cut
15022:
15023: ############################################################
15024: ############################################################
1.134 matthew 15025: sub DrawBarGraph {
1.178 matthew 15026: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15027: #
15028: if (! defined($colors)) {
15029: $colors = ['#33ff00',
15030: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15031: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15032: ];
15033: }
1.228 matthew 15034: my $extra_settings = {};
15035: if (ref($Values[-1]) eq 'HASH') {
15036: $extra_settings = pop(@Values);
15037: }
1.127 matthew 15038: #
1.136 matthew 15039: my $identifier = &get_cgi_id();
15040: my $id = 'cgi.'.$identifier;
1.129 matthew 15041: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15042: return '';
15043: }
1.225 matthew 15044: #
15045: my @Labels;
15046: if (defined($labels)) {
15047: @Labels = @$labels;
15048: } else {
15049: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15050: push(@Labels,$i+1);
1.225 matthew 15051: }
15052: }
15053: #
1.129 matthew 15054: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15055: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15056: my %ValuesHash;
15057: my $NumSets=1;
15058: foreach my $array (@Values) {
15059: next if (! ref($array));
1.136 matthew 15060: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15061: join(',',@$array);
1.129 matthew 15062: }
1.127 matthew 15063: #
1.136 matthew 15064: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15065: if ($NumBars < 3) {
15066: $width = 120+$NumBars*32;
1.220 matthew 15067: $xskip = 1;
1.225 matthew 15068: $bar_width = 30;
15069: } elsif ($NumBars < 5) {
15070: $width = 120+$NumBars*20;
15071: $xskip = 1;
15072: $bar_width = 20;
1.220 matthew 15073: } elsif ($NumBars < 10) {
1.136 matthew 15074: $width = 120+$NumBars*15;
15075: $xskip = 1;
15076: $bar_width = 15;
15077: } elsif ($NumBars <= 25) {
15078: $width = 120+$NumBars*11;
15079: $xskip = 5;
15080: $bar_width = 8;
15081: } elsif ($NumBars <= 50) {
15082: $width = 120+$NumBars*8;
15083: $xskip = 5;
15084: $bar_width = 4;
15085: } else {
15086: $width = 120+$NumBars*8;
15087: $xskip = 5;
15088: $bar_width = 4;
15089: }
15090: #
1.137 matthew 15091: $Max = 1 if ($Max < 1);
15092: if ( int($Max) < $Max ) {
15093: $Max++;
15094: $Max = int($Max);
15095: }
1.127 matthew 15096: $Title = '' if (! defined($Title));
15097: $xlabel = '' if (! defined($xlabel));
15098: $ylabel = '' if (! defined($ylabel));
1.369 www 15099: $ValuesHash{$id.'.title'} = &escape($Title);
15100: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15101: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15102: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15103: $ValuesHash{$id.'.NumBars'} = $NumBars;
15104: $ValuesHash{$id.'.NumSets'} = $NumSets;
15105: $ValuesHash{$id.'.PlotType'} = 'bar';
15106: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15107: $ValuesHash{$id.'.height'} = $height;
15108: $ValuesHash{$id.'.width'} = $width;
15109: $ValuesHash{$id.'.xskip'} = $xskip;
15110: $ValuesHash{$id.'.bar_width'} = $bar_width;
15111: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15112: #
1.228 matthew 15113: # Deal with other parameters
15114: while (my ($key,$value) = each(%$extra_settings)) {
15115: $ValuesHash{$id.'.'.$key} = $value;
15116: }
15117: #
1.646 raeburn 15118: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15119: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15120: }
15121:
15122: ############################################################
15123: ############################################################
15124:
15125: =pod
15126:
1.648 raeburn 15127: =item * &DrawXYGraph()
1.137 matthew 15128:
1.138 matthew 15129: Facilitates the plotting of data in an XY graph.
15130: Puts plot definition data into the users environment in order for
15131: graph.png to plot it. Returns an <img> tag for the plot.
15132:
15133: Inputs:
15134:
15135: =over 4
15136:
15137: =item $Title: string, the title of the plot
15138:
15139: =item $xlabel: string, text describing the X-axis of the plot
15140:
15141: =item $ylabel: string, text describing the Y-axis of the plot
15142:
15143: =item $Max: scalar, the maximum Y value to use in the plot
15144: If $Max is < any data point, the graph will not be rendered.
15145:
15146: =item $colors: Array ref containing the hex color codes for the data to be
15147: plotted in. If undefined, default values will be used.
15148:
15149: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15150:
15151: =item $Ydata: Array ref containing Array refs.
1.185 www 15152: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15153:
15154: =item %Values: hash indicating or overriding any default values which are
15155: passed to graph.png.
15156: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15157:
15158: =back
15159:
15160: Returns:
15161:
15162: An <img> tag which references graph.png and the appropriate identifying
15163: information for the plot.
15164:
1.137 matthew 15165: =cut
15166:
15167: ############################################################
15168: ############################################################
15169: sub DrawXYGraph {
15170: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15171: #
15172: # Create the identifier for the graph
15173: my $identifier = &get_cgi_id();
15174: my $id = 'cgi.'.$identifier;
15175: #
15176: $Title = '' if (! defined($Title));
15177: $xlabel = '' if (! defined($xlabel));
15178: $ylabel = '' if (! defined($ylabel));
15179: my %ValuesHash =
15180: (
1.369 www 15181: $id.'.title' => &escape($Title),
15182: $id.'.xlabel' => &escape($xlabel),
15183: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15184: $id.'.y_max_value'=> $Max,
15185: $id.'.labels' => join(',',@$Xlabels),
15186: $id.'.PlotType' => 'XY',
15187: );
15188: #
15189: if (defined($colors) && ref($colors) eq 'ARRAY') {
15190: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15191: }
15192: #
15193: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15194: return '';
15195: }
15196: my $NumSets=1;
1.138 matthew 15197: foreach my $array (@{$Ydata}){
1.137 matthew 15198: next if (! ref($array));
15199: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15200: }
1.138 matthew 15201: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15202: #
15203: # Deal with other parameters
15204: while (my ($key,$value) = each(%Values)) {
15205: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15206: }
15207: #
1.646 raeburn 15208: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15209: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15210: }
15211:
15212: ############################################################
15213: ############################################################
15214:
15215: =pod
15216:
1.648 raeburn 15217: =item * &DrawXYYGraph()
1.138 matthew 15218:
15219: Facilitates the plotting of data in an XY graph with two Y axes.
15220: Puts plot definition data into the users environment in order for
15221: graph.png to plot it. Returns an <img> tag for the plot.
15222:
15223: Inputs:
15224:
15225: =over 4
15226:
15227: =item $Title: string, the title of the plot
15228:
15229: =item $xlabel: string, text describing the X-axis of the plot
15230:
15231: =item $ylabel: string, text describing the Y-axis of the plot
15232:
15233: =item $colors: Array ref containing the hex color codes for the data to be
15234: plotted in. If undefined, default values will be used.
15235:
15236: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15237:
15238: =item $Ydata1: The first data set
15239:
15240: =item $Min1: The minimum value of the left Y-axis
15241:
15242: =item $Max1: The maximum value of the left Y-axis
15243:
15244: =item $Ydata2: The second data set
15245:
15246: =item $Min2: The minimum value of the right Y-axis
15247:
15248: =item $Max2: The maximum value of the left Y-axis
15249:
15250: =item %Values: hash indicating or overriding any default values which are
15251: passed to graph.png.
15252: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15253:
15254: =back
15255:
15256: Returns:
15257:
15258: An <img> tag which references graph.png and the appropriate identifying
15259: information for the plot.
1.136 matthew 15260:
15261: =cut
15262:
15263: ############################################################
15264: ############################################################
1.137 matthew 15265: sub DrawXYYGraph {
15266: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15267: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15268: #
15269: # Create the identifier for the graph
15270: my $identifier = &get_cgi_id();
15271: my $id = 'cgi.'.$identifier;
15272: #
15273: $Title = '' if (! defined($Title));
15274: $xlabel = '' if (! defined($xlabel));
15275: $ylabel = '' if (! defined($ylabel));
15276: my %ValuesHash =
15277: (
1.369 www 15278: $id.'.title' => &escape($Title),
15279: $id.'.xlabel' => &escape($xlabel),
15280: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15281: $id.'.labels' => join(',',@$Xlabels),
15282: $id.'.PlotType' => 'XY',
15283: $id.'.NumSets' => 2,
1.137 matthew 15284: $id.'.two_axes' => 1,
15285: $id.'.y1_max_value' => $Max1,
15286: $id.'.y1_min_value' => $Min1,
15287: $id.'.y2_max_value' => $Max2,
15288: $id.'.y2_min_value' => $Min2,
1.136 matthew 15289: );
15290: #
1.137 matthew 15291: if (defined($colors) && ref($colors) eq 'ARRAY') {
15292: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15293: }
15294: #
15295: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15296: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15297: return '';
15298: }
15299: my $NumSets=1;
1.137 matthew 15300: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15301: next if (! ref($array));
15302: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15303: }
15304: #
15305: # Deal with other parameters
15306: while (my ($key,$value) = each(%Values)) {
15307: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15308: }
15309: #
1.646 raeburn 15310: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15311: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15312: }
15313:
15314: ############################################################
15315: ############################################################
15316:
15317: =pod
15318:
1.157 matthew 15319: =back
15320:
1.139 matthew 15321: =head1 Statistics helper routines?
15322:
15323: Bad place for them but what the hell.
15324:
1.157 matthew 15325: =over 4
15326:
1.648 raeburn 15327: =item * &chartlink()
1.139 matthew 15328:
15329: Returns a link to the chart for a specific student.
15330:
15331: Inputs:
15332:
15333: =over 4
15334:
15335: =item $linktext: The text of the link
15336:
15337: =item $sname: The students username
15338:
15339: =item $sdomain: The students domain
15340:
15341: =back
15342:
1.157 matthew 15343: =back
15344:
1.139 matthew 15345: =cut
15346:
15347: ############################################################
15348: ############################################################
15349: sub chartlink {
15350: my ($linktext, $sname, $sdomain) = @_;
15351: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15352: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15353: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15354: '">'.$linktext.'</a>';
1.153 matthew 15355: }
15356:
15357: #######################################################
15358: #######################################################
15359:
15360: =pod
15361:
15362: =head1 Course Environment Routines
1.157 matthew 15363:
15364: =over 4
1.153 matthew 15365:
1.648 raeburn 15366: =item * &restore_course_settings()
1.153 matthew 15367:
1.648 raeburn 15368: =item * &store_course_settings()
1.153 matthew 15369:
15370: Restores/Store indicated form parameters from the course environment.
15371: Will not overwrite existing values of the form parameters.
15372:
15373: Inputs:
15374: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15375:
15376: a hash ref describing the data to be stored. For example:
15377:
15378: %Save_Parameters = ('Status' => 'scalar',
15379: 'chartoutputmode' => 'scalar',
15380: 'chartoutputdata' => 'scalar',
15381: 'Section' => 'array',
1.373 raeburn 15382: 'Group' => 'array',
1.153 matthew 15383: 'StudentData' => 'array',
15384: 'Maps' => 'array');
15385:
15386: Returns: both routines return nothing
15387:
1.631 raeburn 15388: =back
15389:
1.153 matthew 15390: =cut
15391:
15392: #######################################################
15393: #######################################################
15394: sub store_course_settings {
1.496 albertel 15395: return &store_settings($env{'request.course.id'},@_);
15396: }
15397:
15398: sub store_settings {
1.153 matthew 15399: # save to the environment
15400: # appenv the same items, just to be safe
1.300 albertel 15401: my $udom = $env{'user.domain'};
15402: my $uname = $env{'user.name'};
1.496 albertel 15403: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15404: my %SaveHash;
15405: my %AppHash;
15406: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15407: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15408: my $envname = 'environment.'.$basename;
1.258 albertel 15409: if (exists($env{'form.'.$setting})) {
1.153 matthew 15410: # Save this value away
15411: if ($type eq 'scalar' &&
1.258 albertel 15412: (! exists($env{$envname}) ||
15413: $env{$envname} ne $env{'form.'.$setting})) {
15414: $SaveHash{$basename} = $env{'form.'.$setting};
15415: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15416: } elsif ($type eq 'array') {
15417: my $stored_form;
1.258 albertel 15418: if (ref($env{'form.'.$setting})) {
1.153 matthew 15419: $stored_form = join(',',
15420: map {
1.369 www 15421: &escape($_);
1.258 albertel 15422: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15423: } else {
15424: $stored_form =
1.369 www 15425: &escape($env{'form.'.$setting});
1.153 matthew 15426: }
15427: # Determine if the array contents are the same.
1.258 albertel 15428: if ($stored_form ne $env{$envname}) {
1.153 matthew 15429: $SaveHash{$basename} = $stored_form;
15430: $AppHash{$envname} = $stored_form;
15431: }
15432: }
15433: }
15434: }
15435: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15436: $udom,$uname);
1.153 matthew 15437: if ($put_result !~ /^(ok|delayed)/) {
15438: &Apache::lonnet::logthis('unable to save form parameters, '.
15439: 'got error:'.$put_result);
15440: }
15441: # Make sure these settings stick around in this session, too
1.646 raeburn 15442: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15443: return;
15444: }
15445:
15446: sub restore_course_settings {
1.499 albertel 15447: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15448: }
15449:
15450: sub restore_settings {
15451: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15452: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15453: next if (exists($env{'form.'.$setting}));
1.496 albertel 15454: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15455: '.'.$setting;
1.258 albertel 15456: if (exists($env{$envname})) {
1.153 matthew 15457: if ($type eq 'scalar') {
1.258 albertel 15458: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15459: } elsif ($type eq 'array') {
1.258 albertel 15460: $env{'form.'.$setting} = [
1.153 matthew 15461: map {
1.369 www 15462: &unescape($_);
1.258 albertel 15463: } split(',',$env{$envname})
1.153 matthew 15464: ];
15465: }
15466: }
15467: }
1.127 matthew 15468: }
15469:
1.618 raeburn 15470: #######################################################
15471: #######################################################
15472:
15473: =pod
15474:
15475: =head1 Domain E-mail Routines
15476:
15477: =over 4
15478:
1.648 raeburn 15479: =item * &build_recipient_list()
1.618 raeburn 15480:
1.1144 raeburn 15481: Build recipient lists for following types of e-mail:
1.766 raeburn 15482: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15483: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15484: module change checking, student/employee ID conflict checks, as
15485: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15486: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15487:
15488: Inputs:
1.619 raeburn 15489: defmail (scalar - email address of default recipient),
1.1144 raeburn 15490: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15491: requestsmail, updatesmail, or idconflictsmail).
15492:
1.619 raeburn 15493: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15494:
1.619 raeburn 15495: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15496: i.e., predates configuration by DC via domainprefs.pm
15497:
15498: $requname username of requester (if mailing type is helpdeskmail)
15499:
15500: $requdom domain of requester (if mailing type is helpdeskmail)
15501:
15502: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15503:
1.618 raeburn 15504:
1.655 raeburn 15505: Returns: comma separated list of addresses to which to send e-mail.
15506:
15507: =back
1.618 raeburn 15508:
15509: =cut
15510:
15511: ############################################################
15512: ############################################################
15513: sub build_recipient_list {
1.1297 raeburn 15514: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15515: my @recipients;
1.1270 raeburn 15516: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15517: my %domconfig =
1.1270 raeburn 15518: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15519: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15520: if (exists($domconfig{'contacts'}{$mailing})) {
15521: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15522: my @contacts = ('adminemail','supportemail');
15523: foreach my $item (@contacts) {
15524: if ($domconfig{'contacts'}{$mailing}{$item}) {
15525: my $addr = $domconfig{'contacts'}{$item};
15526: if (!grep(/^\Q$addr\E$/,@recipients)) {
15527: push(@recipients,$addr);
15528: }
1.619 raeburn 15529: }
1.1270 raeburn 15530: }
15531: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15532: if ($mailing eq 'helpdeskmail') {
15533: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15534: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15535: my @ok_bccs;
15536: foreach my $bcc (@bccs) {
15537: $bcc =~ s/^\s+//g;
15538: $bcc =~ s/\s+$//g;
15539: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15540: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15541: push(@ok_bccs,$bcc);
15542: }
15543: }
15544: }
15545: if (@ok_bccs > 0) {
15546: $allbcc = join(', ',@ok_bccs);
15547: }
15548: }
15549: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15550: }
15551: }
1.766 raeburn 15552: } elsif ($origmail ne '') {
1.1270 raeburn 15553: $lastresort = $origmail;
1.618 raeburn 15554: }
1.1297 raeburn 15555: if ($mailing eq 'helpdeskmail') {
15556: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15557: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15558: my ($inststatus,$inststatus_checked);
15559: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15560: ($env{'user.domain'} ne 'public')) {
15561: $inststatus_checked = 1;
15562: $inststatus = $env{'environment.inststatus'};
15563: }
15564: unless ($inststatus_checked) {
15565: if (($requname ne '') && ($requdom ne '')) {
15566: if (($requname =~ /^$match_username$/) &&
15567: ($requdom =~ /^$match_domain$/) &&
15568: (&Apache::lonnet::domain($requdom))) {
15569: my $requhome = &Apache::lonnet::homeserver($requname,
15570: $requdom);
15571: unless ($requhome eq 'no_host') {
15572: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15573: $inststatus = $userenv{'inststatus'};
15574: $inststatus_checked = 1;
15575: }
15576: }
15577: }
15578: }
15579: unless ($inststatus_checked) {
15580: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15581: my %srch = (srchby => 'email',
15582: srchdomain => $defdom,
15583: srchterm => $reqemail,
15584: srchtype => 'exact');
15585: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15586: foreach my $uname (keys(%srch_results)) {
15587: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15588: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15589: $inststatus_checked = 1;
15590: last;
15591: }
15592: }
15593: unless ($inststatus_checked) {
15594: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15595: if ($dirsrchres eq 'ok') {
15596: foreach my $uname (keys(%srch_results)) {
15597: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15598: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15599: $inststatus_checked = 1;
15600: last;
15601: }
15602: }
15603: }
15604: }
15605: }
15606: }
15607: if ($inststatus ne '') {
15608: foreach my $status (split(/\:/,$inststatus)) {
15609: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15610: my @contacts = ('adminemail','supportemail');
15611: foreach my $item (@contacts) {
15612: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15613: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15614: if (!grep(/^\Q$addr\E$/,@recipients)) {
15615: push(@recipients,$addr);
15616: }
15617: }
15618: }
15619: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15620: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15621: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15622: my @ok_bccs;
15623: foreach my $bcc (@bccs) {
15624: $bcc =~ s/^\s+//g;
15625: $bcc =~ s/\s+$//g;
15626: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15627: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15628: push(@ok_bccs,$bcc);
15629: }
15630: }
15631: }
15632: if (@ok_bccs > 0) {
15633: $allbcc = join(', ',@ok_bccs);
15634: }
15635: }
15636: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15637: last;
15638: }
15639: }
15640: }
15641: }
15642: }
1.619 raeburn 15643: } elsif ($origmail ne '') {
1.1270 raeburn 15644: $lastresort = $origmail;
15645: }
1.1297 raeburn 15646: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15647: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15648: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15649: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15650: my %what = (
15651: perlvar => 1,
15652: );
15653: my $primary = &Apache::lonnet::domain($defdom,'primary');
15654: if ($primary) {
15655: my $gotaddr;
15656: my ($result,$returnhash) =
15657: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15658: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15659: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15660: $lastresort = $returnhash->{'lonSupportEMail'};
15661: $gotaddr = 1;
15662: }
15663: }
15664: unless ($gotaddr) {
15665: my $uintdom = &Apache::lonnet::internet_dom($primary);
15666: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15667: unless ($uintdom eq $intdom) {
15668: my %domconfig =
15669: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15670: if (ref($domconfig{'contacts'}) eq 'HASH') {
15671: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15672: my @contacts = ('adminemail','supportemail');
15673: foreach my $item (@contacts) {
15674: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15675: my $addr = $domconfig{'contacts'}{$item};
15676: if (!grep(/^\Q$addr\E$/,@recipients)) {
15677: push(@recipients,$addr);
15678: }
15679: }
15680: }
15681: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15682: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15683: }
15684: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15685: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15686: my @ok_bccs;
15687: foreach my $bcc (@bccs) {
15688: $bcc =~ s/^\s+//g;
15689: $bcc =~ s/\s+$//g;
15690: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15691: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15692: push(@ok_bccs,$bcc);
15693: }
15694: }
15695: }
15696: if (@ok_bccs > 0) {
15697: $allbcc = join(', ',@ok_bccs);
15698: }
15699: }
15700: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15701: }
15702: }
15703: }
15704: }
15705: }
15706: }
1.618 raeburn 15707: }
1.688 raeburn 15708: if (defined($defmail)) {
15709: if ($defmail ne '') {
15710: push(@recipients,$defmail);
15711: }
1.618 raeburn 15712: }
15713: if ($otheremails) {
1.619 raeburn 15714: my @others;
15715: if ($otheremails =~ /,/) {
15716: @others = split(/,/,$otheremails);
1.618 raeburn 15717: } else {
1.619 raeburn 15718: push(@others,$otheremails);
15719: }
15720: foreach my $addr (@others) {
15721: if (!grep(/^\Q$addr\E$/,@recipients)) {
15722: push(@recipients,$addr);
15723: }
1.618 raeburn 15724: }
15725: }
1.1298 raeburn 15726: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15727: if ((!@recipients) && ($lastresort ne '')) {
15728: push(@recipients,$lastresort);
15729: }
15730: } elsif ($lastresort ne '') {
15731: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15732: push(@recipients,$lastresort);
15733: }
15734: }
1.1271 raeburn 15735: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15736: if (wantarray) {
15737: return ($recipientlist,$allbcc,$addtext);
15738: } else {
15739: return $recipientlist;
15740: }
1.618 raeburn 15741: }
15742:
1.127 matthew 15743: ############################################################
15744: ############################################################
1.154 albertel 15745:
1.655 raeburn 15746: =pod
15747:
1.1224 musolffc 15748: =over 4
15749:
1.1223 musolffc 15750: =item * &mime_email()
15751:
15752: Sends an email with a possible attachment
15753:
15754: Inputs:
15755:
15756: =over 4
15757:
15758: from - Sender's email address
15759:
1.1343 raeburn 15760: replyto - Reply-To email address
15761:
1.1223 musolffc 15762: to - Email address of recipient
15763:
15764: subject - Subject of email
15765:
15766: body - Body of email
15767:
15768: cc_string - Carbon copy email address
15769:
15770: bcc - Blind carbon copy email address
15771:
15772: attachment_path - Path of file to be attached
15773:
15774: file_name - Name of file to be attached
15775:
15776: attachment_text - The body of an attachment of type "TEXT"
15777:
15778: =back
15779:
15780: =back
15781:
15782: =cut
15783:
15784: ############################################################
15785: ############################################################
15786:
15787: sub mime_email {
1.1343 raeburn 15788: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15789: $file_name,$attachment_text) = @_;
15790:
1.1223 musolffc 15791: my $msg = MIME::Lite->new(
15792: From => $from,
15793: To => $to,
15794: Subject => $subject,
15795: Type =>'TEXT',
15796: Data => $body,
15797: );
1.1343 raeburn 15798: if ($replyto ne '') {
15799: $msg->add("Reply-To" => $replyto);
15800: }
1.1223 musolffc 15801: if ($cc_string ne '') {
15802: $msg->add("Cc" => $cc_string);
15803: }
15804: if ($bcc ne '') {
15805: $msg->add("Bcc" => $bcc);
15806: }
15807: $msg->attr("content-type" => "text/plain");
15808: $msg->attr("content-type.charset" => "UTF-8");
15809: # Attach file if given
15810: if ($attachment_path) {
15811: unless ($file_name) {
15812: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15813: }
15814: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15815: $msg->attach(Type => $type,
15816: Path => $attachment_path,
15817: Filename => $file_name
15818: );
15819: # Otherwise attach text if given
15820: } elsif ($attachment_text) {
15821: $msg->attach(Type => 'TEXT',
15822: Data => $attachment_text);
15823: }
15824: # Send it
15825: $msg->send('sendmail');
15826: }
15827:
15828: ############################################################
15829: ############################################################
15830:
15831: =pod
15832:
1.655 raeburn 15833: =head1 Course Catalog Routines
15834:
15835: =over 4
15836:
15837: =item * &gather_categories()
15838:
15839: Converts category definitions - keys of categories hash stored in
15840: coursecategories in configuration.db on the primary library server in a
15841: domain - to an array. Also generates javascript and idx hash used to
15842: generate Domain Coordinator interface for editing Course Categories.
15843:
15844: Inputs:
1.663 raeburn 15845:
1.655 raeburn 15846: categories (reference to hash of category definitions).
1.663 raeburn 15847:
1.655 raeburn 15848: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15849: categories and subcategories).
1.663 raeburn 15850:
1.655 raeburn 15851: idx (reference to hash of counters used in Domain Coordinator interface for
15852: editing Course Categories).
1.663 raeburn 15853:
1.655 raeburn 15854: jsarray (reference to array of categories used to create Javascript arrays for
15855: Domain Coordinator interface for editing Course Categories).
15856:
15857: Returns: nothing
15858:
15859: Side effects: populates cats, idx and jsarray.
15860:
15861: =cut
15862:
15863: sub gather_categories {
15864: my ($categories,$cats,$idx,$jsarray) = @_;
15865: my %counters;
15866: my $num = 0;
15867: foreach my $item (keys(%{$categories})) {
15868: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15869: if ($container eq '' && $depth == 0) {
15870: $cats->[$depth][$categories->{$item}] = $cat;
15871: } else {
15872: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15873: }
15874: my ($escitem,$tail) = split(/:/,$item,2);
15875: if ($counters{$tail} eq '') {
15876: $counters{$tail} = $num;
15877: $num ++;
15878: }
15879: if (ref($idx) eq 'HASH') {
15880: $idx->{$item} = $counters{$tail};
15881: }
15882: if (ref($jsarray) eq 'ARRAY') {
15883: push(@{$jsarray->[$counters{$tail}]},$item);
15884: }
15885: }
15886: return;
15887: }
15888:
15889: =pod
15890:
15891: =item * &extract_categories()
15892:
15893: Used to generate breadcrumb trails for course categories.
15894:
15895: Inputs:
1.663 raeburn 15896:
1.655 raeburn 15897: categories (reference to hash of category definitions).
1.663 raeburn 15898:
1.655 raeburn 15899: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15900: categories and subcategories).
1.663 raeburn 15901:
1.655 raeburn 15902: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15903:
1.655 raeburn 15904: allitems (reference to hash - key is category key
15905: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15906:
1.655 raeburn 15907: idx (reference to hash of counters used in Domain Coordinator interface for
15908: editing Course Categories).
1.663 raeburn 15909:
1.655 raeburn 15910: jsarray (reference to array of categories used to create Javascript arrays for
15911: Domain Coordinator interface for editing Course Categories).
15912:
1.665 raeburn 15913: subcats (reference to hash of arrays containing all subcategories within each
15914: category, -recursive)
15915:
1.1321 raeburn 15916: maxd (reference to hash used to hold max depth for all top-level categories).
15917:
1.655 raeburn 15918: Returns: nothing
15919:
15920: Side effects: populates trails and allitems hash references.
15921:
15922: =cut
15923:
15924: sub extract_categories {
1.1321 raeburn 15925: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15926: if (ref($categories) eq 'HASH') {
15927: &gather_categories($categories,$cats,$idx,$jsarray);
15928: if (ref($cats->[0]) eq 'ARRAY') {
15929: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15930: my $name = $cats->[0][$i];
15931: my $item = &escape($name).'::0';
15932: my $trailstr;
15933: if ($name eq 'instcode') {
15934: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15935: } elsif ($name eq 'communities') {
15936: $trailstr = &mt('Communities');
1.1239 raeburn 15937: } elsif ($name eq 'placement') {
15938: $trailstr = &mt('Placement Tests');
1.655 raeburn 15939: } else {
15940: $trailstr = $name;
15941: }
15942: if ($allitems->{$item} eq '') {
15943: push(@{$trails},$trailstr);
15944: $allitems->{$item} = scalar(@{$trails})-1;
15945: }
15946: my @parents = ($name);
15947: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15948: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15949: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15950: if (ref($subcats) eq 'HASH') {
15951: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15952: }
1.1321 raeburn 15953: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15954: }
15955: } else {
15956: if (ref($subcats) eq 'HASH') {
15957: $subcats->{$item} = [];
1.655 raeburn 15958: }
1.1321 raeburn 15959: if (ref($maxd) eq 'HASH') {
15960: $maxd->{$name} = 1;
15961: }
1.655 raeburn 15962: }
15963: }
15964: }
15965: }
15966: return;
15967: }
15968:
15969: =pod
15970:
1.1162 raeburn 15971: =item * &recurse_categories()
1.655 raeburn 15972:
15973: Recursively used to generate breadcrumb trails for course categories.
15974:
15975: Inputs:
1.663 raeburn 15976:
1.655 raeburn 15977: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15978: categories and subcategories).
1.663 raeburn 15979:
1.655 raeburn 15980: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15981:
15982: category (current course category, for which breadcrumb trail is being generated).
15983:
15984: trails (reference to array of breadcrumb trails for each category).
15985:
1.655 raeburn 15986: allitems (reference to hash - key is category key
15987: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15988:
1.655 raeburn 15989: parents (array containing containers directories for current category,
15990: back to top level).
15991:
15992: Returns: nothing
15993:
15994: Side effects: populates trails and allitems hash references
15995:
15996: =cut
15997:
15998: sub recurse_categories {
1.1321 raeburn 15999: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16000: my $shallower = $depth - 1;
16001: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16002: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16003: my $name = $cats->[$depth]{$category}[$k];
16004: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16005: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16006: if ($allitems->{$item} eq '') {
16007: push(@{$trails},$trailstr);
16008: $allitems->{$item} = scalar(@{$trails})-1;
16009: }
16010: my $deeper = $depth+1;
16011: push(@{$parents},$category);
1.665 raeburn 16012: if (ref($subcats) eq 'HASH') {
16013: my $subcat = &escape($name).':'.$category.':'.$depth;
16014: for (my $j=@{$parents}; $j>=0; $j--) {
16015: my $higher;
16016: if ($j > 0) {
16017: $higher = &escape($parents->[$j]).':'.
16018: &escape($parents->[$j-1]).':'.$j;
16019: } else {
16020: $higher = &escape($parents->[$j]).'::'.$j;
16021: }
16022: push(@{$subcats->{$higher}},$subcat);
16023: }
16024: }
16025: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16026: $subcats,$maxd);
1.655 raeburn 16027: pop(@{$parents});
16028: }
16029: } else {
16030: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16031: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16032: if ($allitems->{$item} eq '') {
16033: push(@{$trails},$trailstr);
16034: $allitems->{$item} = scalar(@{$trails})-1;
16035: }
1.1321 raeburn 16036: if (ref($maxd) eq 'HASH') {
16037: if ($depth > $maxd->{$parents->[0]}) {
16038: $maxd->{$parents->[0]} = $depth;
16039: }
16040: }
1.655 raeburn 16041: }
16042: return;
16043: }
16044:
1.663 raeburn 16045: =pod
16046:
1.1162 raeburn 16047: =item * &assign_categories_table()
1.663 raeburn 16048:
16049: Create a datatable for display of hierarchical categories in a domain,
16050: with checkboxes to allow a course to be categorized.
16051:
16052: Inputs:
16053:
16054: cathash - reference to hash of categories defined for the domain (from
16055: configuration.db)
16056:
16057: currcat - scalar with an & separated list of categories assigned to a course.
16058:
1.919 raeburn 16059: type - scalar contains course type (Course or Community).
16060:
1.1260 raeburn 16061: disabled - scalar (optional) contains disabled="disabled" if input elements are
16062: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16063:
1.663 raeburn 16064: Returns: $output (markup to be displayed)
16065:
16066: =cut
16067:
16068: sub assign_categories_table {
1.1259 raeburn 16069: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16070: my $output;
16071: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16072: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16073: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16074: $maxdepth = scalar(@cats);
16075: if (@cats > 0) {
16076: my $itemcount = 0;
16077: if (ref($cats[0]) eq 'ARRAY') {
16078: my @currcategories;
16079: if ($currcat ne '') {
16080: @currcategories = split('&',$currcat);
16081: }
1.919 raeburn 16082: my $table;
1.663 raeburn 16083: for (my $i=0; $i<@{$cats[0]}; $i++) {
16084: my $parent = $cats[0][$i];
1.919 raeburn 16085: next if ($parent eq 'instcode');
16086: if ($type eq 'Community') {
16087: next unless ($parent eq 'communities');
1.1239 raeburn 16088: } elsif ($type eq 'Placement') {
16089: next unless ($parent eq 'placement');
1.919 raeburn 16090: } else {
1.1239 raeburn 16091: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16092: }
1.663 raeburn 16093: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16094: my $item = &escape($parent).'::0';
16095: my $checked = '';
16096: if (@currcategories > 0) {
16097: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16098: $checked = ' checked="checked"';
1.663 raeburn 16099: }
16100: }
1.919 raeburn 16101: my $parent_title = $parent;
16102: if ($parent eq 'communities') {
16103: $parent_title = &mt('Communities');
1.1239 raeburn 16104: } elsif ($parent eq 'placement') {
16105: $parent_title = &mt('Placement Tests');
1.919 raeburn 16106: }
16107: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16108: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16109: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16110: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16111: my $depth = 1;
16112: push(@path,$parent);
1.1259 raeburn 16113: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16114: pop(@path);
1.919 raeburn 16115: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16116: $itemcount ++;
16117: }
1.919 raeburn 16118: if ($itemcount) {
16119: $output = &Apache::loncommon::start_data_table().
16120: $table.
16121: &Apache::loncommon::end_data_table();
16122: }
1.663 raeburn 16123: }
16124: }
16125: }
16126: return $output;
16127: }
16128:
16129: =pod
16130:
1.1162 raeburn 16131: =item * &assign_category_rows()
1.663 raeburn 16132:
16133: Create a datatable row for display of nested categories in a domain,
16134: with checkboxes to allow a course to be categorized,called recursively.
16135:
16136: Inputs:
16137:
16138: itemcount - track row number for alternating colors
16139:
16140: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16141: categories and subcategories.
16142:
16143: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16144:
16145: parent - parent of current category item
16146:
16147: path - Array containing all categories back up through the hierarchy from the
16148: current category to the top level.
16149:
16150: currcategories - reference to array of current categories assigned to the course
16151:
1.1260 raeburn 16152: disabled - scalar (optional) contains disabled="disabled" if input elements are
16153: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16154:
1.663 raeburn 16155: Returns: $output (markup to be displayed).
16156:
16157: =cut
16158:
16159: sub assign_category_rows {
1.1259 raeburn 16160: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16161: my ($text,$name,$item,$chgstr);
16162: if (ref($cats) eq 'ARRAY') {
16163: my $maxdepth = scalar(@{$cats});
16164: if (ref($cats->[$depth]) eq 'HASH') {
16165: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16166: my $numchildren = @{$cats->[$depth]{$parent}};
16167: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16168: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16169: for (my $j=0; $j<$numchildren; $j++) {
16170: $name = $cats->[$depth]{$parent}[$j];
16171: $item = &escape($name).':'.&escape($parent).':'.$depth;
16172: my $deeper = $depth+1;
16173: my $checked = '';
16174: if (ref($currcategories) eq 'ARRAY') {
16175: if (@{$currcategories} > 0) {
16176: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16177: $checked = ' checked="checked"';
1.663 raeburn 16178: }
16179: }
16180: }
1.664 raeburn 16181: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16182: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16183: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16184: '<input type="hidden" name="catname" value="'.$name.'" />'.
16185: '</td><td>';
1.663 raeburn 16186: if (ref($path) eq 'ARRAY') {
16187: push(@{$path},$name);
1.1259 raeburn 16188: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16189: pop(@{$path});
16190: }
16191: $text .= '</td></tr>';
16192: }
16193: $text .= '</table></td>';
16194: }
16195: }
16196: }
16197: return $text;
16198: }
16199:
1.1181 raeburn 16200: =pod
16201:
16202: =back
16203:
16204: =cut
16205:
1.655 raeburn 16206: ############################################################
16207: ############################################################
16208:
16209:
1.443 albertel 16210: sub commit_customrole {
1.664 raeburn 16211: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16212: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16213: ($start?', '.&mt('starting').' '.localtime($start):'').
16214: ($end?', ending '.localtime($end):'').': <b>'.
16215: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16216: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16217: '</b><br />';
16218: return $output;
16219: }
16220:
16221: sub commit_standardrole {
1.1116 raeburn 16222: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16223: my ($output,$logmsg,$linefeed);
16224: if ($context eq 'auto') {
16225: $linefeed = "\n";
16226: } else {
16227: $linefeed = "<br />\n";
16228: }
1.443 albertel 16229: if ($three eq 'st') {
1.541 raeburn 16230: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 16231: $one,$two,$sec,$context,$credits);
1.541 raeburn 16232: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16233: ($result eq 'unknown_course') || ($result eq 'refused')) {
16234: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16235: } else {
1.541 raeburn 16236: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16237: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16238: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16239: if ($context eq 'auto') {
16240: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16241: } else {
16242: $output .= '<b>'.$result.'</b>'.$linefeed.
16243: &mt('Add to classlist').': <b>ok</b>';
16244: }
16245: $output .= $linefeed;
1.443 albertel 16246: }
16247: } else {
16248: $output = &mt('Assigning').' '.$three.' in '.$url.
16249: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16250: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16251: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16252: if ($context eq 'auto') {
16253: $output .= $result.$linefeed;
16254: } else {
16255: $output .= '<b>'.$result.'</b>'.$linefeed;
16256: }
1.443 albertel 16257: }
16258: return $output;
16259: }
16260:
16261: sub commit_studentrole {
1.1116 raeburn 16262: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16263: $credits) = @_;
1.626 raeburn 16264: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16265: if ($context eq 'auto') {
16266: $linefeed = "\n";
16267: } else {
16268: $linefeed = '<br />'."\n";
16269: }
1.443 albertel 16270: if (defined($one) && defined($two)) {
16271: my $cid=$one.'_'.$two;
16272: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16273: my $secchange = 0;
16274: my $expire_role_result;
16275: my $modify_section_result;
1.628 raeburn 16276: if ($oldsec ne '-1') {
16277: if ($oldsec ne $sec) {
1.443 albertel 16278: $secchange = 1;
1.628 raeburn 16279: my $now = time;
1.443 albertel 16280: my $uurl='/'.$cid;
16281: $uurl=~s/\_/\//g;
16282: if ($oldsec) {
16283: $uurl.='/'.$oldsec;
16284: }
1.626 raeburn 16285: $oldsecurl = $uurl;
1.628 raeburn 16286: $expire_role_result =
1.652 raeburn 16287: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 16288: if ($env{'request.course.sec'} ne '') {
16289: if ($expire_role_result eq 'refused') {
16290: my @roles = ('st');
16291: my @statuses = ('previous');
16292: my @roledoms = ($one);
16293: my $withsec = 1;
16294: my %roleshash =
16295: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16296: \@statuses,\@roles,\@roledoms,$withsec);
16297: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16298: my ($oldstart,$oldend) =
16299: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16300: if ($oldend > 0 && $oldend <= $now) {
16301: $expire_role_result = 'ok';
16302: }
16303: }
16304: }
16305: }
1.443 albertel 16306: $result = $expire_role_result;
16307: }
16308: }
16309: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16310: $modify_section_result =
16311: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16312: undef,undef,undef,$sec,
16313: $end,$start,'','',$cid,
16314: '',$context,$credits);
1.443 albertel 16315: if ($modify_section_result =~ /^ok/) {
16316: if ($secchange == 1) {
1.628 raeburn 16317: if ($sec eq '') {
16318: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16319: } else {
16320: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16321: }
1.443 albertel 16322: } elsif ($oldsec eq '-1') {
1.628 raeburn 16323: if ($sec eq '') {
16324: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16325: } else {
16326: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16327: }
1.443 albertel 16328: } else {
1.628 raeburn 16329: if ($sec eq '') {
16330: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16331: } else {
16332: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16333: }
1.443 albertel 16334: }
16335: } else {
1.1115 raeburn 16336: if ($secchange) {
1.628 raeburn 16337: $$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;
16338: } else {
16339: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16340: }
1.443 albertel 16341: }
16342: $result = $modify_section_result;
16343: } elsif ($secchange == 1) {
1.628 raeburn 16344: if ($oldsec eq '') {
1.1103 raeburn 16345: $$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 16346: } else {
16347: $$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;
16348: }
1.626 raeburn 16349: if ($expire_role_result eq 'refused') {
16350: my $newsecurl = '/'.$cid;
16351: $newsecurl =~ s/\_/\//g;
16352: if ($sec ne '') {
16353: $newsecurl.='/'.$sec;
16354: }
16355: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16356: if ($sec eq '') {
16357: $$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;
16358: } else {
16359: $$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;
16360: }
16361: }
16362: }
1.443 albertel 16363: }
16364: } else {
1.626 raeburn 16365: $$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 16366: $result = "error: incomplete course id\n";
16367: }
16368: return $result;
16369: }
16370:
1.1108 raeburn 16371: sub show_role_extent {
16372: my ($scope,$context,$role) = @_;
16373: $scope =~ s{^/}{};
16374: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16375: push(@courseroles,'co');
16376: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16377: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16378: $scope =~ s{/}{_};
16379: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16380: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16381: my ($audom,$auname) = split(/\//,$scope);
16382: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16383: &Apache::loncommon::plainname($auname,$audom).'</span>');
16384: } else {
16385: $scope =~ s{/$}{};
16386: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16387: &Apache::lonnet::domain($scope,'description').'</span>');
16388: }
16389: }
16390:
1.443 albertel 16391: ############################################################
16392: ############################################################
16393:
1.566 albertel 16394: sub check_clone {
1.578 raeburn 16395: my ($args,$linefeed) = @_;
1.566 albertel 16396: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16397: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16398: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16399: my $clonetitle;
16400: my @clonemsg;
1.566 albertel 16401: my $can_clone = 0;
1.944 raeburn 16402: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16403: if ($lctype ne 'community') {
16404: $lctype = 'course';
16405: }
1.566 albertel 16406: if ($clonehome eq 'no_host') {
1.944 raeburn 16407: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16408: push(@clonemsg,({
16409: mt => 'No new community created.',
16410: args => [],
16411: },
16412: {
16413: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16414: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16415: }));
1.908 raeburn 16416: } else {
1.1344 raeburn 16417: push(@clonemsg,({
16418: mt => 'No new course created.',
16419: args => [],
16420: },
16421: {
16422: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16423: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16424: }));
16425: }
1.566 albertel 16426: } else {
16427: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16428: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16429: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16430: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16431: push(@clonemsg,({
16432: mt => 'No new community created.',
16433: args => [],
16434: },
16435: {
16436: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16437: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16438: }));
16439: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16440: }
16441: }
1.1262 raeburn 16442: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16443: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16444: $can_clone = 1;
16445: } else {
1.1221 raeburn 16446: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16447: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16448: if ($clonehash{'cloners'} eq '') {
16449: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16450: if ($domdefs{'canclone'}) {
16451: unless ($domdefs{'canclone'} eq 'none') {
16452: if ($domdefs{'canclone'} eq 'domain') {
16453: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16454: $can_clone = 1;
16455: }
16456: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16457: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16458: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16459: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16460: $can_clone = 1;
16461: }
16462: }
16463: }
16464: }
1.578 raeburn 16465: } else {
1.1221 raeburn 16466: my @cloners = split(/,/,$clonehash{'cloners'});
16467: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16468: $can_clone = 1;
1.1221 raeburn 16469: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16470: $can_clone = 1;
1.1225 raeburn 16471: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16472: $can_clone = 1;
1.1221 raeburn 16473: }
16474: unless ($can_clone) {
1.1225 raeburn 16475: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16476: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16477: my (%gotdomdefaults,%gotcodedefaults);
16478: foreach my $cloner (@cloners) {
16479: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16480: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16481: my (%codedefaults,@code_order);
16482: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16483: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16484: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16485: }
16486: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16487: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16488: }
16489: } else {
16490: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16491: \%codedefaults,
16492: \@code_order);
16493: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16494: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16495: }
16496: if (@code_order > 0) {
16497: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16498: $cloner,$clonehash{'internal.coursecode'},
16499: $args->{'crscode'})) {
16500: $can_clone = 1;
16501: last;
16502: }
16503: }
16504: }
16505: }
16506: }
1.1225 raeburn 16507: }
16508: }
16509: unless ($can_clone) {
16510: my $ccrole = 'cc';
16511: if ($args->{'crstype'} eq 'Community') {
16512: $ccrole = 'co';
16513: }
16514: my %roleshash =
16515: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16516: $args->{'ccdomain'},
16517: 'userroles',['active'],[$ccrole],
16518: [$args->{'clonedomain'}]);
16519: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16520: $can_clone = 1;
16521: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16522: $args->{'ccuname'},$args->{'ccdomain'})) {
16523: $can_clone = 1;
1.1221 raeburn 16524: }
16525: }
16526: unless ($can_clone) {
16527: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16528: push(@clonemsg,({
16529: mt => 'No new community created.',
16530: args => [],
16531: },
16532: {
16533: 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]).',
16534: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16535: }));
1.942 raeburn 16536: } else {
1.1344 raeburn 16537: push(@clonemsg,({
16538: mt => 'No new course created.',
16539: args => [],
16540: },
16541: {
16542: 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]).',
16543: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16544: }));
1.1221 raeburn 16545: }
1.566 albertel 16546: }
1.578 raeburn 16547: }
1.566 albertel 16548: }
1.1344 raeburn 16549: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16550: }
16551:
1.444 albertel 16552: sub construct_course {
1.1262 raeburn 16553: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16554: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16555: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16556: my $linefeed = '<br />'."\n";
16557: if ($context eq 'auto') {
16558: $linefeed = "\n";
16559: }
1.566 albertel 16560:
16561: #
16562: # Are we cloning?
16563: #
1.1344 raeburn 16564: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16565: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16566: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16567: if (!$can_clone) {
1.1344 raeburn 16568: return (0,$outcome,$clonemsgref);
1.566 albertel 16569: }
16570: }
16571:
1.444 albertel 16572: #
16573: # Open course
16574: #
1.1239 raeburn 16575: my $showncrstype;
16576: if ($args->{'crstype'} eq 'Placement') {
16577: $showncrstype = 'placement test';
16578: } else {
16579: $showncrstype = lc($args->{'crstype'});
16580: }
1.444 albertel 16581: my %cenv=();
16582: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16583: $args->{'cdescr'},
16584: $args->{'curl'},
16585: $args->{'course_home'},
16586: $args->{'nonstandard'},
16587: $args->{'crscode'},
16588: $args->{'ccuname'}.':'.
16589: $args->{'ccdomain'},
1.882 raeburn 16590: $args->{'crstype'},
1.1344 raeburn 16591: $cnum,$context,$category,
16592: $callercontext);
1.444 albertel 16593:
16594: # Note: The testing routines depend on this being output; see
16595: # Utils::Course. This needs to at least be output as a comment
16596: # if anyone ever decides to not show this, and Utils::Course::new
16597: # will need to be suitably modified.
1.1344 raeburn 16598: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16599: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16600: } else {
16601: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16602: }
1.943 raeburn 16603: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16604: return (0,$outcome,$clonemsgref);
1.943 raeburn 16605: }
16606:
1.444 albertel 16607: #
16608: # Check if created correctly
16609: #
1.479 albertel 16610: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16611: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16612: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16613: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16614: $outcome .= &mt_user($user_lh,
16615: 'Course creation failed, unrecognized course home server.');
16616: } else {
16617: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16618: }
16619: $outcome .= $linefeed;
16620: return (0,$outcome,$clonemsgref);
1.943 raeburn 16621: }
1.541 raeburn 16622: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16623:
1.444 albertel 16624: #
1.566 albertel 16625: # Do the cloning
16626: #
1.1344 raeburn 16627: my @clonemsg;
1.566 albertel 16628: if ($can_clone && $cloneid) {
1.1344 raeburn 16629: push(@clonemsg,
16630: {
16631: mt => 'Created [_1] by cloning from [_2]',
16632: args => [$showncrstype,$clonetitle],
16633: });
1.566 albertel 16634: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16635: # Copy all files
1.1344 raeburn 16636: my @info =
16637: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16638: $args->{'dateshift'},$args->{'crscode'},
16639: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16640: $args->{'tinyurls'});
16641: if (@info) {
16642: push(@clonemsg,@info);
16643: }
1.444 albertel 16644: # Restore URL
1.566 albertel 16645: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16646: # Restore title
1.566 albertel 16647: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16648: # Restore creation date, creator and creation context.
16649: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16650: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16651: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16652: # Mark as cloned
1.566 albertel 16653: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16654: # Need to clone grading mode
16655: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16656: $cenv{'grading'}=$newenv{'grading'};
16657: # Do not clone these environment entries
16658: &Apache::lonnet::del('environment',
16659: ['default_enrollment_start_date',
16660: 'default_enrollment_end_date',
16661: 'question.email',
16662: 'policy.email',
16663: 'comment.email',
16664: 'pch.users.denied',
1.725 raeburn 16665: 'plc.users.denied',
16666: 'hidefromcat',
1.1121 raeburn 16667: 'checkforpriv',
1.1355 raeburn 16668: 'categories'],
1.638 www 16669: $$crsudom,$$crsunum);
1.1170 raeburn 16670: if ($args->{'textbook'}) {
16671: $cenv{'internal.textbook'} = $args->{'textbook'};
16672: }
1.444 albertel 16673: }
1.566 albertel 16674:
1.444 albertel 16675: #
16676: # Set environment (will override cloned, if existing)
16677: #
16678: my @sections = ();
16679: my @xlists = ();
16680: if ($args->{'crstype'}) {
16681: $cenv{'type'}=$args->{'crstype'};
16682: }
1.1371 raeburn 16683: if ($args->{'lti'}) {
16684: $cenv{'internal.lti'}=$args->{'lti'};
16685: }
1.444 albertel 16686: if ($args->{'crsid'}) {
16687: $cenv{'courseid'}=$args->{'crsid'};
16688: }
16689: if ($args->{'crscode'}) {
16690: $cenv{'internal.coursecode'}=$args->{'crscode'};
16691: }
16692: if ($args->{'crsquota'} ne '') {
16693: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16694: } else {
16695: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16696: }
16697: if ($args->{'ccuname'}) {
16698: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16699: ':'.$args->{'ccdomain'};
16700: } else {
16701: $cenv{'internal.courseowner'} = $args->{'curruser'};
16702: }
1.1116 raeburn 16703: if ($args->{'defaultcredits'}) {
16704: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16705: }
1.444 albertel 16706: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16707: if ($args->{'crssections'}) {
16708: $cenv{'internal.sectionnums'} = '';
16709: if ($args->{'crssections'} =~ m/,/) {
16710: @sections = split/,/,$args->{'crssections'};
16711: } else {
16712: $sections[0] = $args->{'crssections'};
16713: }
16714: if (@sections > 0) {
16715: foreach my $item (@sections) {
16716: my ($sec,$gp) = split/:/,$item;
16717: my $class = $args->{'crscode'}.$sec;
16718: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16719: $cenv{'internal.sectionnums'} .= $item.',';
16720: unless ($addcheck eq 'ok') {
1.1263 raeburn 16721: push(@badclasses,$class);
1.444 albertel 16722: }
16723: }
16724: $cenv{'internal.sectionnums'} =~ s/,$//;
16725: }
16726: }
16727: # do not hide course coordinator from staff listing,
16728: # even if privileged
16729: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16730: # add course coordinator's domain to domains to check for privileged users
16731: # if different to course domain
16732: if ($$crsudom ne $args->{'ccdomain'}) {
16733: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16734: }
1.444 albertel 16735: # add crosslistings
16736: if ($args->{'crsxlist'}) {
16737: $cenv{'internal.crosslistings'}='';
16738: if ($args->{'crsxlist'} =~ m/,/) {
16739: @xlists = split/,/,$args->{'crsxlist'};
16740: } else {
16741: $xlists[0] = $args->{'crsxlist'};
16742: }
16743: if (@xlists > 0) {
16744: foreach my $item (@xlists) {
16745: my ($xl,$gp) = split/:/,$item;
16746: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16747: $cenv{'internal.crosslistings'} .= $item.',';
16748: unless ($addcheck eq 'ok') {
1.1263 raeburn 16749: push(@badclasses,$xl);
1.444 albertel 16750: }
16751: }
16752: $cenv{'internal.crosslistings'} =~ s/,$//;
16753: }
16754: }
16755: if ($args->{'autoadds'}) {
16756: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16757: }
16758: if ($args->{'autodrops'}) {
16759: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16760: }
16761: # check for notification of enrollment changes
16762: my @notified = ();
16763: if ($args->{'notify_owner'}) {
16764: if ($args->{'ccuname'} ne '') {
16765: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16766: }
16767: }
16768: if ($args->{'notify_dc'}) {
16769: if ($uname ne '') {
1.630 raeburn 16770: push(@notified,$uname.':'.$udom);
1.444 albertel 16771: }
16772: }
16773: if (@notified > 0) {
16774: my $notifylist;
16775: if (@notified > 1) {
16776: $notifylist = join(',',@notified);
16777: } else {
16778: $notifylist = $notified[0];
16779: }
16780: $cenv{'internal.notifylist'} = $notifylist;
16781: }
16782: if (@badclasses > 0) {
16783: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16784: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16785: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16786: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16787: );
1.1264 raeburn 16788: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16789: &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 16790: if ($context eq 'auto') {
16791: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16792: } else {
1.566 albertel 16793: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16794: }
16795: foreach my $item (@badclasses) {
1.541 raeburn 16796: if ($context eq 'auto') {
1.1261 raeburn 16797: $outcome .= " - $item\n";
1.541 raeburn 16798: } else {
1.1261 raeburn 16799: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16800: }
1.1261 raeburn 16801: }
16802: if ($context eq 'auto') {
16803: $outcome .= $linefeed;
16804: } else {
16805: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16806: }
1.444 albertel 16807: }
16808: if ($args->{'no_end_date'}) {
16809: $args->{'endaccess'} = 0;
16810: }
16811: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16812: $cenv{'internal.autoend'}=$args->{'enrollend'};
16813: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16814: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16815: if ($args->{'showphotos'}) {
16816: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16817: }
16818: $cenv{'internal.authtype'} = $args->{'authtype'};
16819: $cenv{'internal.autharg'} = $args->{'autharg'};
16820: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16821: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16822: 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');
16823: if ($context eq 'auto') {
16824: $outcome .= $krb_msg;
16825: } else {
1.566 albertel 16826: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16827: }
16828: $outcome .= $linefeed;
1.444 albertel 16829: }
16830: }
16831: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16832: if ($args->{'setpolicy'}) {
16833: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16834: }
16835: if ($args->{'setcontent'}) {
16836: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16837: }
1.1251 raeburn 16838: if ($args->{'setcomment'}) {
16839: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16840: }
1.444 albertel 16841: }
16842: if ($args->{'reshome'}) {
16843: $cenv{'reshome'}=$args->{'reshome'}.'/';
16844: $cenv{'reshome'}=~s/\/+$/\//;
16845: }
16846: #
16847: # course has keyed access
16848: #
16849: if ($args->{'setkeys'}) {
16850: $cenv{'keyaccess'}='yes';
16851: }
16852: # if specified, key authority is not course, but user
16853: # only active if keyaccess is yes
16854: if ($args->{'keyauth'}) {
1.487 albertel 16855: my ($user,$domain) = split(':',$args->{'keyauth'});
16856: $user = &LONCAPA::clean_username($user);
16857: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16858: if ($user ne '' && $domain ne '') {
1.487 albertel 16859: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16860: }
16861: }
16862:
1.1166 raeburn 16863: #
1.1167 raeburn 16864: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16865: #
16866: if ($args->{'uniquecode'}) {
16867: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16868: if ($code) {
16869: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16870: my %crsinfo =
16871: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16872: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16873: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16874: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16875: }
1.1166 raeburn 16876: if (ref($coderef)) {
16877: $$coderef = $code;
16878: }
16879: }
16880: }
16881:
1.444 albertel 16882: if ($args->{'disresdis'}) {
16883: $cenv{'pch.roles.denied'}='st';
16884: }
16885: if ($args->{'disablechat'}) {
16886: $cenv{'plc.roles.denied'}='st';
16887: }
16888:
16889: # Record we've not yet viewed the Course Initialization Helper for this
16890: # course
16891: $cenv{'course.helper.not.run'} = 1;
16892: #
16893: # Use new Randomseed
16894: #
16895: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16896: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16897: #
16898: # The encryption code and receipt prefix for this course
16899: #
16900: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16901: $cenv{'internal.encpref'}=100+int(9*rand(99));
16902: #
16903: # By default, use standard grading
16904: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16905:
1.541 raeburn 16906: $outcome .= $linefeed.&mt('Setting environment').': '.
16907: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16908: #
16909: # Open all assignments
16910: #
16911: if ($args->{'openall'}) {
1.1341 raeburn 16912: my $opendate = time;
16913: if ($args->{'openallfrom'} =~ /^\d+$/) {
16914: $opendate = $args->{'openallfrom'};
16915: }
1.444 albertel 16916: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16917: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16918: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16919: $outcome .= &mt('All assignments open starting [_1]',
16920: &Apache::lonlocal::locallocaltime($opendate)).': '.
16921: &Apache::lonnet::cput
16922: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16923: }
16924: #
16925: # Set first page
16926: #
16927: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16928: || ($cloneid)) {
1.445 albertel 16929: use LONCAPA::map;
1.444 albertel 16930: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16931:
16932: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16933: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16934:
1.444 albertel 16935: $outcome .= ($fatal?$errtext:'read ok').' - ';
16936: my $title; my $url;
16937: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16938: $title=&mt('Syllabus');
1.444 albertel 16939: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16940: } else {
1.963 raeburn 16941: $title=&mt('Table of Contents');
1.444 albertel 16942: $url='/adm/navmaps';
16943: }
1.445 albertel 16944:
16945: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16946: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16947:
16948: if ($errtext) { $fatal=2; }
1.541 raeburn 16949: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16950: }
1.566 albertel 16951:
1.1237 raeburn 16952: #
16953: # Set params for Placement Tests
16954: #
1.1239 raeburn 16955: if ($args->{'crstype'} eq 'Placement') {
16956: my %storecontent;
16957: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16958: my %defaults = (
16959: buttonshide => { value => 'yes',
16960: type => 'string_yesno',},
16961: type => { value => 'randomizetry',
16962: type => 'string_questiontype',},
16963: maxtries => { value => 1,
16964: type => 'int_pos',},
16965: problemstatus => { value => 'no',
16966: type => 'string_problemstatus',},
16967: );
16968: foreach my $key (keys(%defaults)) {
16969: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16970: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16971: }
1.1237 raeburn 16972: &Apache::lonnet::cput
16973: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16974: }
16975:
1.1344 raeburn 16976: return (1,$outcome,\@clonemsg);
1.444 albertel 16977: }
16978:
1.1166 raeburn 16979: sub make_unique_code {
16980: my ($cdom,$cnum) = @_;
16981: # get lock on uniquecodes db
16982: my $lockhash = {
16983: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16984: ':'.$env{'user.domain'},
16985: };
16986: my $tries = 0;
16987: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16988: my ($code,$error);
16989:
16990: while (($gotlock ne 'ok') && ($tries<3)) {
16991: $tries ++;
16992: sleep 1;
16993: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16994: }
16995: if ($gotlock eq 'ok') {
16996: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16997: my $gotcode;
16998: my $attempts = 0;
16999: while ((!$gotcode) && ($attempts < 100)) {
17000: $code = &generate_code();
17001: if (!exists($currcodes{$code})) {
17002: $gotcode = 1;
17003: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17004: $error = 'nostore';
17005: }
17006: }
17007: $attempts ++;
17008: }
17009: my @del_lock = ($cnum."\0".'uniquecodes');
17010: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17011: } else {
17012: $error = 'nolock';
17013: }
17014: return ($code,$error);
17015: }
17016:
17017: sub generate_code {
17018: my $code;
17019: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17020: for (my $i=0; $i<6; $i++) {
17021: my $lettnum = int (rand 2);
17022: my $item = '';
17023: if ($lettnum) {
17024: $item = $letts[int( rand(18) )];
17025: } else {
17026: $item = 1+int( rand(8) );
17027: }
17028: $code .= $item;
17029: }
17030: return $code;
17031: }
17032:
1.444 albertel 17033: ############################################################
17034: ############################################################
17035:
1.1237 raeburn 17036: # Community, Course and Placement Test
1.378 raeburn 17037: sub course_type {
17038: my ($cid) = @_;
17039: if (!defined($cid)) {
17040: $cid = $env{'request.course.id'};
17041: }
1.404 albertel 17042: if (defined($env{'course.'.$cid.'.type'})) {
17043: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17044: } else {
17045: return 'Course';
1.377 raeburn 17046: }
17047: }
1.156 albertel 17048:
1.406 raeburn 17049: sub group_term {
17050: my $crstype = &course_type();
17051: my %names = (
17052: 'Course' => 'group',
1.865 raeburn 17053: 'Community' => 'group',
1.1237 raeburn 17054: 'Placement' => 'group',
1.406 raeburn 17055: );
17056: return $names{$crstype};
17057: }
17058:
1.902 raeburn 17059: sub course_types {
1.1310 raeburn 17060: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17061: my %typename = (
17062: official => 'Official course',
17063: unofficial => 'Unofficial course',
17064: community => 'Community',
1.1165 raeburn 17065: textbook => 'Textbook course',
1.1237 raeburn 17066: placement => 'Placement test',
1.1310 raeburn 17067: lti => 'LTI provider',
1.902 raeburn 17068: );
17069: return (\@types,\%typename);
17070: }
17071:
1.156 albertel 17072: sub icon {
17073: my ($file)=@_;
1.505 albertel 17074: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17075: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17076: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17077: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17078: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17079: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17080: $curfext.".gif") {
17081: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17082: $curfext.".gif";
17083: }
17084: }
1.249 albertel 17085: return &lonhttpdurl($iconname);
1.154 albertel 17086: }
1.84 albertel 17087:
1.575 albertel 17088: sub lonhttpdurl {
1.692 www 17089: #
17090: # Had been used for "small fry" static images on separate port 8080.
17091: # Modify here if lightweight http functionality desired again.
17092: # Currently eliminated due to increasing firewall issues.
17093: #
1.575 albertel 17094: my ($url)=@_;
1.692 www 17095: return $url;
1.215 albertel 17096: }
17097:
1.213 albertel 17098: sub connection_aborted {
17099: my ($r)=@_;
17100: $r->print(" ");$r->rflush();
17101: my $c = $r->connection;
17102: return $c->aborted();
17103: }
17104:
1.221 foxr 17105: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17106: # strings as 'strings'.
17107: sub escape_single {
1.221 foxr 17108: my ($input) = @_;
1.223 albertel 17109: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17110: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17111: return $input;
17112: }
1.223 albertel 17113:
1.222 foxr 17114: # Same as escape_single, but escape's "'s This
17115: # can be used for "strings"
17116: sub escape_double {
17117: my ($input) = @_;
17118: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17119: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17120: return $input;
17121: }
1.223 albertel 17122:
1.222 foxr 17123: # Escapes the last element of a full URL.
17124: sub escape_url {
17125: my ($url) = @_;
1.238 raeburn 17126: my @urlslices = split(/\//, $url,-1);
1.369 www 17127: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17128: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17129: }
1.462 albertel 17130:
1.820 raeburn 17131: sub compare_arrays {
17132: my ($arrayref1,$arrayref2) = @_;
17133: my (@difference,%count);
17134: @difference = ();
17135: %count = ();
17136: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17137: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17138: foreach my $element (keys(%count)) {
17139: if ($count{$element} == 1) {
17140: push(@difference,$element);
17141: }
17142: }
17143: }
17144: return @difference;
17145: }
17146:
1.1322 raeburn 17147: sub lon_status_items {
17148: my %defaults = (
17149: E => 100,
17150: W => 4,
17151: N => 1,
1.1324 raeburn 17152: U => 5,
1.1322 raeburn 17153: threshold => 200,
17154: sysmail => 2500,
17155: );
17156: my %names = (
17157: E => 'Errors',
17158: W => 'Warnings',
17159: N => 'Notices',
1.1324 raeburn 17160: U => 'Unsent',
1.1322 raeburn 17161: );
17162: return (\%defaults,\%names);
17163: }
17164:
1.817 bisitz 17165: # -------------------------------------------------------- Initialize user login
1.462 albertel 17166: sub init_user_environment {
1.463 albertel 17167: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17168: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17169:
17170: my $public=($username eq 'public' && $domain eq 'public');
17171:
1.1062 raeburn 17172: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 17173: my $now=time;
17174:
17175: if ($public) {
17176: my $max_public=100;
17177: my $oldest;
17178: my $oldest_time=0;
17179: for(my $next=1;$next<=$max_public;$next++) {
17180: if (-e $lonids."/publicuser_$next.id") {
17181: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17182: if ($mtime<$oldest_time || !$oldest_time) {
17183: $oldest_time=$mtime;
17184: $oldest=$next;
17185: }
17186: } else {
17187: $cookie="publicuser_$next";
17188: last;
17189: }
17190: }
17191: if (!$cookie) { $cookie="publicuser_$oldest"; }
17192: } else {
1.1275 raeburn 17193: # See if old ID present, if so, remove if this isn't a robot,
17194: # killing any existing non-robot sessions
1.463 albertel 17195: if (!$args->{'robot'}) {
17196: opendir(DIR,$lonids);
17197: while ($filename=readdir(DIR)) {
17198: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17199: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17200: &GDBM_READER(),0640)) {
1.1295 raeburn 17201: my $linkedfile;
1.1320 raeburn 17202: if (exists($oldenv{'user.linkedenv'})) {
17203: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17204: }
1.1320 raeburn 17205: untie(%oldenv);
17206: if (unlink("$lonids/$filename")) {
17207: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17208: if (-l "$lonids/$linkedfile.id") {
17209: unlink("$lonids/$linkedfile.id");
17210: }
1.1295 raeburn 17211: }
17212: }
17213: } else {
17214: unlink($lonids.'/'.$filename);
17215: }
1.463 albertel 17216: }
1.462 albertel 17217: }
1.463 albertel 17218: closedir(DIR);
1.1204 raeburn 17219: # If there is a undeleted lockfile for the user's paste buffer remove it.
17220: my $namespace = 'nohist_courseeditor';
17221: my $lockingkey = 'paste'."\0".'locked_num';
17222: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17223: $domain,$username);
17224: if (exists($lockhash{$lockingkey})) {
17225: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17226: unless ($delresult eq 'ok') {
17227: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17228: }
17229: }
1.462 albertel 17230: }
17231: # Give them a new cookie
1.463 albertel 17232: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17233: : $now.$$.int(rand(10000)));
1.463 albertel 17234: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17235:
17236: # Initialize roles
17237:
1.1062 raeburn 17238: ($userroles,$firstaccenv,$timerintenv) =
17239: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17240: }
17241: # ------------------------------------ Check browser type and MathML capability
17242:
1.1194 raeburn 17243: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17244: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17245:
17246: # ------------------------------------------------------------- Get environment
17247:
17248: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17249: my ($tmp) = keys(%userenv);
1.1275 raeburn 17250: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17251: undef(%userenv);
17252: }
17253: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17254: $form->{'interface'}=$userenv{'interface'};
17255: }
17256: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17257:
17258: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17259: foreach my $option ('interface','localpath','localres') {
17260: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17261: }
17262: # --------------------------------------------------------- Write first profile
17263:
17264: {
1.1350 raeburn 17265: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17266: my %initial_env =
17267: ("user.name" => $username,
17268: "user.domain" => $domain,
17269: "user.home" => $authhost,
17270: "browser.type" => $clientbrowser,
17271: "browser.version" => $clientversion,
17272: "browser.mathml" => $clientmathml,
17273: "browser.unicode" => $clientunicode,
17274: "browser.os" => $clientos,
1.1137 raeburn 17275: "browser.mobile" => $clientmobile,
1.1141 raeburn 17276: "browser.info" => $clientinfo,
1.1194 raeburn 17277: "browser.osversion" => $clientosversion,
1.462 albertel 17278: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17279: "request.course.fn" => '',
17280: "request.course.uri" => '',
17281: "request.course.sec" => '',
17282: "request.role" => 'cm',
17283: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17284: "request.host" => $ip,);
1.462 albertel 17285:
17286: if ($form->{'localpath'}) {
17287: $initial_env{"browser.localpath"} = $form->{'localpath'};
17288: $initial_env{"browser.localres"} = $form->{'localres'};
17289: }
17290:
17291: if ($form->{'interface'}) {
17292: $form->{'interface'}=~s/\W//gs;
17293: $initial_env{"browser.interface"} = $form->{'interface'};
17294: $env{'browser.interface'}=$form->{'interface'};
17295: }
17296:
1.1157 raeburn 17297: if ($form->{'iptoken'}) {
17298: my $lonhost = $r->dir_config('lonHostID');
17299: $initial_env{"user.noloadbalance"} = $lonhost;
17300: $env{'user.noloadbalance'} = $lonhost;
17301: }
17302:
1.1268 raeburn 17303: if ($form->{'noloadbalance'}) {
17304: my @hosts = &Apache::lonnet::current_machine_ids();
17305: my $hosthere = $form->{'noloadbalance'};
17306: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17307: $initial_env{"user.noloadbalance"} = $hosthere;
17308: $env{'user.noloadbalance'} = $hosthere;
17309: }
17310: }
17311:
1.1016 raeburn 17312: unless ($domain eq 'public') {
1.1273 raeburn 17313: my %is_adv = ( is_adv => $env{'user.adv'} );
17314: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17315:
17316: foreach my $tool ('aboutme','blog','webdav','portfolio') {
17317: $userenv{'availabletools.'.$tool} =
17318: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17319: undef,\%userenv,\%domdef,\%is_adv);
17320: }
1.980 raeburn 17321:
1.1311 raeburn 17322: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17323: $userenv{'canrequest.'.$crstype} =
17324: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17325: 'reload','requestcourses',
17326: \%userenv,\%domdef,\%is_adv);
17327: }
1.724 raeburn 17328:
1.1273 raeburn 17329: $userenv{'canrequest.author'} =
17330: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17331: 'reload','requestauthor',
1.980 raeburn 17332: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17333: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17334: $domain,$username);
17335: my $reqstatus = $reqauthor{'author_status'};
17336: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17337: if (ref($reqauthor{'author'}) eq 'HASH') {
17338: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17339: $reqauthor{'author'}{'timestamp'};
17340: }
1.1092 raeburn 17341: }
1.1287 raeburn 17342: my ($types,$typename) = &course_types();
17343: if (ref($types) eq 'ARRAY') {
17344: my @options = ('approval','validate','autolimit');
17345: my $optregex = join('|',@options);
17346: my (%willtrust,%trustchecked);
17347: foreach my $type (@{$types}) {
17348: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17349: if ($dom_str ne '') {
17350: my $updatedstr = '';
17351: my @possdomains = split(',',$dom_str);
17352: foreach my $entry (@possdomains) {
17353: my ($extdom,$extopt) = split(':',$entry);
17354: unless ($trustchecked{$extdom}) {
17355: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17356: $trustchecked{$extdom} = 1;
17357: }
17358: if ($willtrust{$extdom}) {
17359: $updatedstr .= $entry.',';
17360: }
17361: }
17362: $updatedstr =~ s/,$//;
17363: if ($updatedstr) {
17364: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17365: } else {
17366: delete($userenv{'reqcrsotherdom.'.$type});
17367: }
17368: }
17369: }
17370: }
1.1092 raeburn 17371: }
1.462 albertel 17372: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17373:
1.462 albertel 17374: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17375: &GDBM_WRCREAT(),0640)) {
17376: &_add_to_env(\%disk_env,\%initial_env);
17377: &_add_to_env(\%disk_env,\%userenv,'environment.');
17378: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17379: if (ref($firstaccenv) eq 'HASH') {
17380: &_add_to_env(\%disk_env,$firstaccenv);
17381: }
17382: if (ref($timerintenv) eq 'HASH') {
17383: &_add_to_env(\%disk_env,$timerintenv);
17384: }
1.463 albertel 17385: if (ref($args->{'extra_env'})) {
17386: &_add_to_env(\%disk_env,$args->{'extra_env'});
17387: }
1.462 albertel 17388: untie(%disk_env);
17389: } else {
1.705 tempelho 17390: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17391: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17392: return 'error: '.$!;
17393: }
17394: }
17395: $env{'request.role'}='cm';
17396: $env{'request.role.adv'}=$env{'user.adv'};
17397: $env{'browser.type'}=$clientbrowser;
17398:
17399: return $cookie;
17400:
17401: }
17402:
17403: sub _add_to_env {
17404: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17405: if (ref($env_data) eq 'HASH') {
17406: while (my ($key,$value) = each(%$env_data)) {
17407: $idf->{$prefix.$key} = $value;
17408: $env{$prefix.$key} = $value;
17409: }
1.462 albertel 17410: }
17411: }
17412:
1.685 tempelho 17413: # --- Get the symbolic name of a problem and the url
17414: sub get_symb {
17415: my ($request,$silent) = @_;
1.726 raeburn 17416: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17417: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17418: if ($symb eq '') {
17419: if (!$silent) {
1.1071 raeburn 17420: if (ref($request)) {
17421: $request->print("Unable to handle ambiguous references:$url:.");
17422: }
1.685 tempelho 17423: return ();
17424: }
17425: }
17426: &Apache::lonenc::check_decrypt(\$symb);
17427: return ($symb);
17428: }
17429:
17430: # --------------------------------------------------------------Get annotation
17431:
17432: sub get_annotation {
17433: my ($symb,$enc) = @_;
17434:
17435: my $key = $symb;
17436: if (!$enc) {
17437: $key =
17438: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17439: }
17440: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17441: return $annotation{$key};
17442: }
17443:
17444: sub clean_symb {
1.731 raeburn 17445: my ($symb,$delete_enc) = @_;
1.685 tempelho 17446:
17447: &Apache::lonenc::check_decrypt(\$symb);
17448: my $enc = $env{'request.enc'};
1.731 raeburn 17449: if ($delete_enc) {
1.730 raeburn 17450: delete($env{'request.enc'});
17451: }
1.685 tempelho 17452:
17453: return ($symb,$enc);
17454: }
1.462 albertel 17455:
1.1181 raeburn 17456: ############################################################
17457: ############################################################
17458:
17459: =pod
17460:
17461: =head1 Routines for building display used to search for courses
17462:
17463:
17464: =over 4
17465:
17466: =item * &build_filters()
17467:
17468: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17469: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17470: and quotacheck.pl
17471:
1.1181 raeburn 17472:
17473: Inputs:
17474:
17475: filterlist - anonymous array of fields to include as potential filters
17476:
17477: crstype - course type
17478:
17479: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17480: to pop-open a course selector (will contain "extra element").
17481:
17482: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17483:
17484: filter - anonymous hash of criteria and their values
17485:
17486: action - form action
17487:
17488: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17489:
1.1182 raeburn 17490: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17491:
17492: cloneruname - username of owner of new course who wants to clone
17493:
17494: clonerudom - domain of owner of new course who wants to clone
17495:
17496: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17497:
17498: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17499:
17500: codedom - domain
17501:
17502: formname - value of form element named "form".
17503:
17504: fixeddom - domain, if fixed.
17505:
17506: prevphase - value to assign to form element named "phase" when going back to the previous screen
17507:
17508: cnameelement - name of form element in form on opener page which will receive title of selected course
17509:
17510: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17511:
17512: cdomelement - name of form element in form on opener page which will receive domain of selected course
17513:
17514: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17515:
17516: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17517:
17518: clonewarning - warning message about missing information for intended course owner when DC creates a course
17519:
1.1182 raeburn 17520:
1.1181 raeburn 17521: Returns: $output - HTML for display of search criteria, and hidden form elements.
17522:
1.1182 raeburn 17523:
1.1181 raeburn 17524: Side Effects: None
17525:
17526: =cut
17527:
17528: # ---------------------------------------------- search for courses based on last activity etc.
17529:
17530: sub build_filters {
17531: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17532: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17533: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17534: $cnameelement,$cnumelement,$cdomelement,$setroles,
17535: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17536: my ($list,$jscript);
1.1181 raeburn 17537: my $onchange = 'javascript:updateFilters(this)';
17538: my ($domainselectform,$sincefilterform,$createdfilterform,
17539: $ownerdomselectform,$persondomselectform,$instcodeform,
17540: $typeselectform,$instcodetitle);
17541: if ($formname eq '') {
17542: $formname = $caller;
17543: }
17544: foreach my $item (@{$filterlist}) {
17545: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17546: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17547: if ($item eq 'domainfilter') {
17548: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17549: } elsif ($item eq 'coursefilter') {
17550: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17551: } elsif ($item eq 'ownerfilter') {
17552: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17553: } elsif ($item eq 'ownerdomfilter') {
17554: $filter->{'ownerdomfilter'} =
17555: &LONCAPA::clean_domain($filter->{$item});
17556: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17557: 'ownerdomfilter',1);
17558: } elsif ($item eq 'personfilter') {
17559: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17560: } elsif ($item eq 'persondomfilter') {
17561: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17562: 'persondomfilter',1);
17563: } else {
17564: $filter->{$item} =~ s/\W//g;
17565: }
17566: if (!$filter->{$item}) {
17567: $filter->{$item} = '';
17568: }
17569: }
17570: if ($item eq 'domainfilter') {
17571: my $allow_blank = 1;
17572: if ($formname eq 'portform') {
17573: $allow_blank=0;
17574: } elsif ($formname eq 'studentform') {
17575: $allow_blank=0;
17576: }
17577: if ($fixeddom) {
17578: $domainselectform = '<input type="hidden" name="domainfilter"'.
17579: ' value="'.$codedom.'" />'.
17580: &Apache::lonnet::domain($codedom,'description');
17581: } else {
17582: $domainselectform = &select_dom_form($filter->{$item},
17583: 'domainfilter',
17584: $allow_blank,'',$onchange);
17585: }
17586: } else {
17587: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17588: }
17589: }
17590:
17591: # last course activity filter and selection
17592: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17593:
17594: # course created filter and selection
17595: if (exists($filter->{'createdfilter'})) {
17596: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17597: }
17598:
1.1239 raeburn 17599: my $prefix = $crstype;
17600: if ($crstype eq 'Placement') {
17601: $prefix = 'Placement Test'
17602: }
1.1181 raeburn 17603: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17604: 'cac' => "$prefix Activity",
17605: 'ccr' => "$prefix Created",
17606: 'cde' => "$prefix Title",
17607: 'cdo' => "$prefix Domain",
1.1181 raeburn 17608: 'ins' => 'Institutional Code',
17609: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17610: 'cow' => "$prefix Owner/Co-owner",
17611: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17612: 'cog' => 'Type',
17613: );
17614:
17615: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17616: my $typeval = 'Course';
17617: if ($crstype eq 'Community') {
17618: $typeval = 'Community';
1.1239 raeburn 17619: } elsif ($crstype eq 'Placement') {
17620: $typeval = 'Placement';
1.1181 raeburn 17621: }
17622: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17623: } else {
17624: $typeselectform = '<select name="type" size="1"';
17625: if ($onchange) {
17626: $typeselectform .= ' onchange="'.$onchange.'"';
17627: }
17628: $typeselectform .= '>'."\n";
1.1237 raeburn 17629: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17630: my $shown;
17631: if ($posstype eq 'Placement') {
17632: $shown = &mt('Placement Test');
17633: } else {
17634: $shown = &mt($posstype);
17635: }
1.1181 raeburn 17636: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17637: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17638: }
17639: $typeselectform.="</select>";
17640: }
17641:
17642: my ($cloneableonlyform,$cloneabletitle);
17643: if (exists($filter->{'cloneableonly'})) {
17644: my $cloneableon = '';
17645: my $cloneableoff = ' checked="checked"';
17646: if ($filter->{'cloneableonly'}) {
17647: $cloneableon = $cloneableoff;
17648: $cloneableoff = '';
17649: }
17650: $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>';
17651: if ($formname eq 'ccrs') {
1.1187 bisitz 17652: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17653: } else {
17654: $cloneabletitle = &mt('Cloneable by you');
17655: }
17656: }
17657: my $officialjs;
17658: if ($crstype eq 'Course') {
17659: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17660: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17661: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17662: if ($codedom) {
1.1181 raeburn 17663: $officialjs = 1;
17664: ($instcodeform,$jscript,$$numtitlesref) =
17665: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17666: $officialjs,$codetitlesref);
17667: if ($jscript) {
1.1182 raeburn 17668: $jscript = '<script type="text/javascript">'."\n".
17669: '// <![CDATA['."\n".
17670: $jscript."\n".
17671: '// ]]>'."\n".
17672: '</script>'."\n";
1.1181 raeburn 17673: }
17674: }
17675: if ($instcodeform eq '') {
17676: $instcodeform =
17677: '<input type="text" name="instcodefilter" size="10" value="'.
17678: $list->{'instcodefilter'}.'" />';
17679: $instcodetitle = $lt{'ins'};
17680: } else {
17681: $instcodetitle = $lt{'inc'};
17682: }
17683: if ($fixeddom) {
17684: $instcodetitle .= '<br />('.$codedom.')';
17685: }
17686: }
17687: }
17688: my $output = qq|
17689: <form method="post" name="filterpicker" action="$action">
17690: <input type="hidden" name="form" value="$formname" />
17691: |;
17692: if ($formname eq 'modifycourse') {
17693: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17694: '<input type="hidden" name="prevphase" value="'.
17695: $prevphase.'" />'."\n";
1.1198 musolffc 17696: } elsif ($formname eq 'quotacheck') {
17697: $output .= qq|
17698: <input type="hidden" name="sortby" value="" />
17699: <input type="hidden" name="sortorder" value="" />
17700: |;
17701: } else {
1.1181 raeburn 17702: my $name_input;
17703: if ($cnameelement ne '') {
17704: $name_input = '<input type="hidden" name="cnameelement" value="'.
17705: $cnameelement.'" />';
17706: }
17707: $output .= qq|
1.1182 raeburn 17708: <input type="hidden" name="cnumelement" value="$cnumelement" />
17709: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17710: $name_input
17711: $roleelement
17712: $multelement
17713: $typeelement
17714: |;
17715: if ($formname eq 'portform') {
17716: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17717: }
17718: }
17719: if ($fixeddom) {
17720: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17721: }
17722: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17723: if ($sincefilterform) {
17724: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17725: .$sincefilterform
17726: .&Apache::lonhtmlcommon::row_closure();
17727: }
17728: if ($createdfilterform) {
17729: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17730: .$createdfilterform
17731: .&Apache::lonhtmlcommon::row_closure();
17732: }
17733: if ($domainselectform) {
17734: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17735: .$domainselectform
17736: .&Apache::lonhtmlcommon::row_closure();
17737: }
17738: if ($typeselectform) {
17739: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17740: $output .= $typeselectform;
17741: } else {
17742: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17743: .$typeselectform
17744: .&Apache::lonhtmlcommon::row_closure();
17745: }
17746: }
17747: if ($instcodeform) {
17748: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17749: .$instcodeform
17750: .&Apache::lonhtmlcommon::row_closure();
17751: }
17752: if (exists($filter->{'ownerfilter'})) {
17753: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17754: '<table><tr><td>'.&mt('Username').'<br />'.
17755: '<input type="text" name="ownerfilter" size="20" value="'.
17756: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17757: $ownerdomselectform.'</td></tr></table>'.
17758: &Apache::lonhtmlcommon::row_closure();
17759: }
17760: if (exists($filter->{'personfilter'})) {
17761: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17762: '<table><tr><td>'.&mt('Username').'<br />'.
17763: '<input type="text" name="personfilter" size="20" value="'.
17764: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17765: $persondomselectform.'</td></tr></table>'.
17766: &Apache::lonhtmlcommon::row_closure();
17767: }
17768: if (exists($filter->{'coursefilter'})) {
17769: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17770: .'<input type="text" name="coursefilter" size="25" value="'
17771: .$list->{'coursefilter'}.'" />'
17772: .&Apache::lonhtmlcommon::row_closure();
17773: }
17774: if ($cloneableonlyform) {
17775: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17776: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17777: }
17778: if (exists($filter->{'descriptfilter'})) {
17779: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17780: .'<input type="text" name="descriptfilter" size="40" value="'
17781: .$list->{'descriptfilter'}.'" />'
17782: .&Apache::lonhtmlcommon::row_closure(1);
17783: }
17784: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17785: '<input type="hidden" name="updater" value="" />'."\n".
17786: '<input type="submit" name="gosearch" value="'.
17787: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17788: return $jscript.$clonewarning.$output;
17789: }
17790:
17791: =pod
17792:
17793: =item * &timebased_select_form()
17794:
1.1182 raeburn 17795: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17796: filter e.g., Course Activity, Course Created, when searching for courses
17797: or communities
17798:
17799: Inputs:
17800:
17801: item - name of form element (sincefilter or createdfilter)
17802:
17803: filter - anonymous hash of criteria and their values
17804:
17805: Returns: HTML for a select box contained a blank, then six time selections,
17806: with value set in incoming form variables currently selected.
17807:
17808: Side Effects: None
17809:
17810: =cut
17811:
17812: sub timebased_select_form {
17813: my ($item,$filter) = @_;
17814: if (ref($filter) eq 'HASH') {
17815: $filter->{$item} =~ s/[^\d-]//g;
17816: if (!$filter->{$item}) { $filter->{$item}=-1; }
17817: return &select_form(
17818: $filter->{$item},
17819: $item,
17820: { '-1' => '',
17821: '86400' => &mt('today'),
17822: '604800' => &mt('last week'),
17823: '2592000' => &mt('last month'),
17824: '7776000' => &mt('last three months'),
17825: '15552000' => &mt('last six months'),
17826: '31104000' => &mt('last year'),
17827: 'select_form_order' =>
17828: ['-1','86400','604800','2592000','7776000',
17829: '15552000','31104000']});
17830: }
17831: }
17832:
17833: =pod
17834:
17835: =item * &js_changer()
17836:
17837: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17838: when course type or domain is changed, and also to hide 'Searching ...' on
17839: page load completion for page showing search result.
1.1181 raeburn 17840:
17841: Inputs: None
17842:
1.1183 raeburn 17843: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17844:
17845: Side Effects: None
17846:
17847: =cut
17848:
17849: sub js_changer {
17850: return <<ENDJS;
17851: <script type="text/javascript">
17852: // <![CDATA[
17853: function updateFilters(caller) {
17854: if (typeof(caller) != "undefined") {
17855: document.filterpicker.updater.value = caller.name;
17856: }
17857: document.filterpicker.submit();
17858: }
1.1183 raeburn 17859:
17860: function hideSearching() {
17861: if (document.getElementById('searching')) {
17862: document.getElementById('searching').style.display = 'none';
17863: }
17864: return;
17865: }
17866:
1.1181 raeburn 17867: // ]]>
17868: </script>
17869:
17870: ENDJS
17871: }
17872:
17873: =pod
17874:
1.1182 raeburn 17875: =item * &search_courses()
17876:
17877: Process selected filters form course search form and pass to lonnet::courseiddump
17878: to retrieve a hash for which keys are courseIDs which match the selected filters.
17879:
17880: Inputs:
17881:
17882: dom - domain being searched
17883:
17884: type - course type ('Course' or 'Community' or '.' if any).
17885:
17886: filter - anonymous hash of criteria and their values
17887:
17888: numtitles - for institutional codes - number of categories
17889:
17890: cloneruname - optional username of new course owner
17891:
17892: clonerudom - optional domain of new course owner
17893:
1.1221 raeburn 17894: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17895: (used when DC is using course creation form)
17896:
17897: codetitles - reference to array of titles of components in institutional codes (official courses).
17898:
1.1221 raeburn 17899: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17900: (and so can clone automatically)
17901:
17902: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17903:
17904: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17905: courses to clone
1.1182 raeburn 17906:
17907: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17908:
17909:
17910: Side Effects: None
17911:
17912: =cut
17913:
17914:
17915: sub search_courses {
1.1221 raeburn 17916: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17917: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17918: my (%courses,%showcourses,$cloner);
17919: if (($filter->{'ownerfilter'} ne '') ||
17920: ($filter->{'ownerdomfilter'} ne '')) {
17921: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17922: $filter->{'ownerdomfilter'};
17923: }
17924: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17925: if (!$filter->{$item}) {
17926: $filter->{$item}='.';
17927: }
17928: }
17929: my $now = time;
17930: my $timefilter =
17931: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17932: my ($createdbefore,$createdafter);
17933: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17934: $createdbefore = $now;
17935: $createdafter = $now-$filter->{'createdfilter'};
17936: }
17937: my ($instcodefilter,$regexpok);
17938: if ($numtitles) {
17939: if ($env{'form.official'} eq 'on') {
17940: $instcodefilter =
17941: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17942: $regexpok = 1;
17943: } elsif ($env{'form.official'} eq 'off') {
17944: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17945: unless ($instcodefilter eq '') {
17946: $regexpok = -1;
17947: }
17948: }
17949: } else {
17950: $instcodefilter = $filter->{'instcodefilter'};
17951: }
17952: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17953: if ($type eq '') { $type = '.'; }
17954:
17955: if (($clonerudom ne '') && ($cloneruname ne '')) {
17956: $cloner = $cloneruname.':'.$clonerudom;
17957: }
17958: %courses = &Apache::lonnet::courseiddump($dom,
17959: $filter->{'descriptfilter'},
17960: $timefilter,
17961: $instcodefilter,
17962: $filter->{'combownerfilter'},
17963: $filter->{'coursefilter'},
17964: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17965: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17966: $filter->{'cloneableonly'},
17967: $createdbefore,$createdafter,undef,
1.1221 raeburn 17968: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17969: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17970: my $ccrole;
17971: if ($type eq 'Community') {
17972: $ccrole = 'co';
17973: } else {
17974: $ccrole = 'cc';
17975: }
17976: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17977: $filter->{'persondomfilter'},
17978: 'userroles',undef,
17979: [$ccrole,'in','ad','ep','ta','cr'],
17980: $dom);
17981: foreach my $role (keys(%rolehash)) {
17982: my ($cnum,$cdom,$courserole) = split(':',$role);
17983: my $cid = $cdom.'_'.$cnum;
17984: if (exists($courses{$cid})) {
17985: if (ref($courses{$cid}) eq 'HASH') {
17986: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17987: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17988: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17989: }
17990: } else {
17991: $courses{$cid}{roles} = [$courserole];
17992: }
17993: $showcourses{$cid} = $courses{$cid};
17994: }
17995: }
17996: }
17997: %courses = %showcourses;
17998: }
17999: return %courses;
18000: }
18001:
18002: =pod
18003:
1.1181 raeburn 18004: =back
18005:
1.1207 raeburn 18006: =head1 Routines for version requirements for current course.
18007:
18008: =over 4
18009:
18010: =item * &check_release_required()
18011:
18012: Compares required LON-CAPA version with version on server, and
18013: if required version is newer looks for a server with the required version.
18014:
18015: Looks first at servers in user's owen domain; if none suitable, looks at
18016: servers in course's domain are permitted to host sessions for user's domain.
18017:
18018: Inputs:
18019:
18020: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18021:
18022: $courseid - Course ID of current course
18023:
18024: $rolecode - User's current role in course (for switchserver query string).
18025:
18026: $required - LON-CAPA version needed by course (format: Major.Minor).
18027:
18028:
18029: Returns:
18030:
18031: $switchserver - query string tp append to /adm/switchserver call (if
18032: current server's LON-CAPA version is too old.
18033:
18034: $warning - Message is displayed if no suitable server could be found.
18035:
18036: =cut
18037:
18038: sub check_release_required {
18039: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18040: my ($switchserver,$warning);
18041: if ($required ne '') {
18042: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18043: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18044: if ($reqdmajor ne '' && $reqdminor ne '') {
18045: my $otherserver;
18046: if (($major eq '' && $minor eq '') ||
18047: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18048: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18049: my $switchlcrev =
18050: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18051: $userdomserver);
18052: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18053: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18054: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18055: my $cdom = $env{'course.'.$courseid.'.domain'};
18056: if ($cdom ne $env{'user.domain'}) {
18057: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18058: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18059: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18060: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18061: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18062: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18063: my $canhost =
18064: &Apache::lonnet::can_host_session($env{'user.domain'},
18065: $coursedomserver,
18066: $remoterev,
18067: $udomdefaults{'remotesessions'},
18068: $defdomdefaults{'hostedsessions'});
18069:
18070: if ($canhost) {
18071: $otherserver = $coursedomserver;
18072: } else {
18073: $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.");
18074: }
18075: } else {
18076: $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).");
18077: }
18078: } else {
18079: $otherserver = $userdomserver;
18080: }
18081: }
18082: if ($otherserver ne '') {
18083: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18084: }
18085: }
18086: }
18087: return ($switchserver,$warning);
18088: }
18089:
18090: =pod
18091:
18092: =item * &check_release_result()
18093:
18094: Inputs:
18095:
18096: $switchwarning - Warning message if no suitable server found to host session.
18097:
18098: $switchserver - query string to append to /adm/switchserver containing lonHostID
18099: and current role.
18100:
18101: Returns: HTML to display with information about requirement to switch server.
18102: Either displaying warning with link to Roles/Courses screen or
18103: display link to switchserver.
18104:
1.1181 raeburn 18105: =cut
18106:
1.1207 raeburn 18107: sub check_release_result {
18108: my ($switchwarning,$switchserver) = @_;
18109: my $output = &start_page('Selected course unavailable on this server').
18110: '<p class="LC_warning">';
18111: if ($switchwarning) {
18112: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18113: if (&show_course()) {
18114: $output .= &mt('Display courses');
18115: } else {
18116: $output .= &mt('Display roles');
18117: }
18118: $output .= '</a>';
18119: } elsif ($switchserver) {
18120: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18121: '<br />'.
18122: '<a href="/adm/switchserver?'.$switchserver.'">'.
18123: &mt('Switch Server').
18124: '</a>';
18125: }
18126: $output .= '</p>'.&end_page();
18127: return $output;
18128: }
18129:
18130: =pod
18131:
18132: =item * &needs_coursereinit()
18133:
18134: Determine if course contents stored for user's session needs to be
18135: refreshed, because content has changed since "Big Hash" last tied.
18136:
18137: Check for change is made if time last checked is more than 10 minutes ago
18138: (by default).
18139:
18140: Inputs:
18141:
18142: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18143:
18144: $interval (optional) - Time which may elapse (in s) between last check for content
18145: change in current course. (default: 600 s).
18146:
18147: Returns: an array; first element is:
18148:
18149: =over 4
18150:
18151: 'switch' - if content updates mean user's session
18152: needs to be switched to a server running a newer LON-CAPA version
18153:
18154: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18155: on current server hosting user's session
18156:
18157: '' - if no action required.
18158:
18159: =back
18160:
18161: If first item element is 'switch':
18162:
18163: second item is $switchwarning - Warning message if no suitable server found to host session.
18164:
18165: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18166: and current role.
18167:
18168: otherwise: no other elements returned.
18169:
18170: =back
18171:
18172: =cut
18173:
18174: sub needs_coursereinit {
18175: my ($loncaparev,$interval) = @_;
18176: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18177: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18178: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18179: my $now = time;
18180: if ($interval eq '') {
18181: $interval = 600;
18182: }
18183: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18184: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18185: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18186: if ($blocked) {
18187: return ();
18188: }
1.1207 raeburn 18189: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18190: if ($lastchange > $env{'request.course.tied'}) {
18191: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18192: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18193: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18194: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18195: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18196: $curr_reqd_hash{'internal.releaserequired'}});
18197: my ($switchserver,$switchwarning) =
18198: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18199: $curr_reqd_hash{'internal.releaserequired'});
18200: if ($switchwarning ne '' || $switchserver ne '') {
18201: return ('switch',$switchwarning,$switchserver);
18202: }
18203: }
18204: }
18205: return ('update');
18206: }
18207: }
18208: return ();
18209: }
1.1181 raeburn 18210:
1.1083 raeburn 18211: sub update_content_constraints {
1.1326 raeburn 18212: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 18213: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18214: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18215: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18216: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18217: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18218: if ($item eq 'resourcetag') {
18219: if ($name eq 'responsetype') {
18220: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18221: }
1.1307 raeburn 18222: } elsif ($item eq 'course') {
18223: if ($name eq 'courserestype') {
18224: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18225: }
1.1083 raeburn 18226: }
18227: }
18228: my $navmap = Apache::lonnavmaps::navmap->new();
18229: if (defined($navmap)) {
1.1307 raeburn 18230: my (%allresponses,%allcrsrestypes);
18231: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18232: if ($res->is_tool()) {
18233: if ($allcrsrestypes{'exttool'}) {
18234: $allcrsrestypes{'exttool'} ++;
18235: } else {
18236: $allcrsrestypes{'exttool'} = 1;
18237: }
18238: next;
18239: }
1.1083 raeburn 18240: my %responses = $res->responseTypes();
18241: foreach my $key (keys(%responses)) {
18242: next unless(exists($checkresponsetypes{$key}));
18243: $allresponses{$key} += $responses{$key};
18244: }
18245: }
18246: foreach my $key (keys(%allresponses)) {
18247: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18248: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18249: ($reqdmajor,$reqdminor) = ($major,$minor);
18250: }
18251: }
1.1307 raeburn 18252: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18253: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18254: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18255: ($reqdmajor,$reqdminor) = ($major,$minor);
18256: }
18257: }
1.1083 raeburn 18258: undef($navmap);
18259: }
1.1326 raeburn 18260: my (@resources,@order,@resparms,@zombies);
18261: if ($keeporder) {
18262: use LONCAPA::map;
18263: @resources = @LONCAPA::map::resources;
18264: @order = @LONCAPA::map::order;
18265: @resparms = @LONCAPA::map::resparms;
18266: @zombies = @LONCAPA::map::zombies;
18267: }
1.1308 raeburn 18268: my $suppmap = 'supplemental.sequence';
18269: my ($suppcount,$supptools,$errors) = (0,0,0);
18270: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
18271: $suppcount,$supptools,$errors);
1.1326 raeburn 18272: if ($keeporder) {
18273: @LONCAPA::map::resources = @resources;
18274: @LONCAPA::map::order = @order;
18275: @LONCAPA::map::resparms = @resparms;
18276: @LONCAPA::map::zombies = @zombies;
18277: }
1.1308 raeburn 18278: if ($supptools) {
18279: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18280: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18281: ($reqdmajor,$reqdminor) = ($major,$minor);
18282: }
18283: }
1.1083 raeburn 18284: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18285: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18286: }
18287: return;
18288: }
18289:
1.1110 raeburn 18290: sub allmaps_incourse {
18291: my ($cdom,$cnum,$chome,$cid) = @_;
18292: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18293: $cid = $env{'request.course.id'};
18294: $cdom = $env{'course.'.$cid.'.domain'};
18295: $cnum = $env{'course.'.$cid.'.num'};
18296: $chome = $env{'course.'.$cid.'.home'};
18297: }
18298: my %allmaps = ();
18299: my $lastchange =
18300: &Apache::lonnet::get_coursechange($cdom,$cnum);
18301: if ($lastchange > $env{'request.course.tied'}) {
18302: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18303: unless ($ferr) {
1.1326 raeburn 18304: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 18305: }
18306: }
18307: my $navmap = Apache::lonnavmaps::navmap->new();
18308: if (defined($navmap)) {
18309: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18310: $allmaps{$res->src()} = 1;
18311: }
18312: }
18313: return \%allmaps;
18314: }
18315:
1.1083 raeburn 18316: sub parse_supplemental_title {
18317: my ($title) = @_;
18318:
18319: my ($foldertitle,$renametitle);
18320: if ($title =~ /&&&/) {
18321: $title = &HTML::Entites::decode($title);
18322: }
18323: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18324: $renametitle=$4;
18325: my ($time,$uname,$udom) = ($1,$2,$3);
18326: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18327: my $name = &plainname($uname,$udom);
18328: $name = &HTML::Entities::encode($name,'"<>&\'');
18329: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
18330: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
18331: $name.': <br />'.$foldertitle;
18332: }
18333: if (wantarray) {
18334: return ($title,$foldertitle,$renametitle);
18335: }
18336: return $title;
18337: }
18338:
1.1143 raeburn 18339: sub recurse_supplemental {
1.1308 raeburn 18340: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 18341: if ($suppmap) {
18342: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18343: if ($fatal) {
18344: $errors ++;
18345: } else {
18346: if ($#LONCAPA::map::resources > 0) {
18347: foreach my $res (@LONCAPA::map::resources) {
18348: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
18349: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 18350: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 18351: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
18352: $numfiles,$numexttools,$errors);
1.1143 raeburn 18353: } else {
1.1308 raeburn 18354: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
18355: $numexttools ++;
18356: }
1.1143 raeburn 18357: $numfiles ++;
18358: }
18359: }
18360: }
18361: }
18362: }
18363: }
1.1308 raeburn 18364: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 18365: }
18366:
1.1101 raeburn 18367: sub symb_to_docspath {
1.1267 raeburn 18368: my ($symb,$navmapref) = @_;
18369: return unless ($symb && ref($navmapref));
1.1101 raeburn 18370: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18371: if ($resurl=~/\.(sequence|page)$/) {
18372: $mapurl=$resurl;
18373: } elsif ($resurl eq 'adm/navmaps') {
18374: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18375: }
18376: my $mapresobj;
1.1267 raeburn 18377: unless (ref($$navmapref)) {
18378: $$navmapref = Apache::lonnavmaps::navmap->new();
18379: }
18380: if (ref($$navmapref)) {
18381: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18382: }
18383: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18384: my $type=$2;
18385: my $path;
18386: if (ref($mapresobj)) {
18387: my $pcslist = $mapresobj->map_hierarchy();
18388: if ($pcslist ne '') {
18389: foreach my $pc (split(/,/,$pcslist)) {
18390: next if ($pc <= 1);
1.1267 raeburn 18391: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18392: if (ref($res)) {
18393: my $thisurl = $res->src();
18394: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18395: my $thistitle = $res->title();
18396: $path .= '&'.
18397: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18398: &escape($thistitle).
1.1101 raeburn 18399: ':'.$res->randompick().
18400: ':'.$res->randomout().
18401: ':'.$res->encrypted().
18402: ':'.$res->randomorder().
18403: ':'.$res->is_page();
18404: }
18405: }
18406: }
18407: $path =~ s/^\&//;
18408: my $maptitle = $mapresobj->title();
18409: if ($mapurl eq 'default') {
1.1129 raeburn 18410: $maptitle = 'Main Content';
1.1101 raeburn 18411: }
18412: $path .= (($path ne '')? '&' : '').
18413: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18414: &escape($maptitle).
1.1101 raeburn 18415: ':'.$mapresobj->randompick().
18416: ':'.$mapresobj->randomout().
18417: ':'.$mapresobj->encrypted().
18418: ':'.$mapresobj->randomorder().
18419: ':'.$mapresobj->is_page();
18420: } else {
18421: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18422: my $ispage = (($type eq 'page')? 1 : '');
18423: if ($mapurl eq 'default') {
1.1129 raeburn 18424: $maptitle = 'Main Content';
1.1101 raeburn 18425: }
18426: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18427: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18428: }
18429: unless ($mapurl eq 'default') {
18430: $path = 'default&'.
1.1146 raeburn 18431: &escape('Main Content').
1.1101 raeburn 18432: ':::::&'.$path;
18433: }
18434: return $path;
18435: }
18436:
1.1094 raeburn 18437: sub captcha_display {
1.1327 raeburn 18438: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18439: my ($output,$error);
1.1234 raeburn 18440: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18441: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18442: if ($captcha eq 'original') {
1.1094 raeburn 18443: $output = &create_captcha();
18444: unless ($output) {
1.1172 raeburn 18445: $error = 'captcha';
1.1094 raeburn 18446: }
18447: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18448: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18449: unless ($output) {
1.1172 raeburn 18450: $error = 'recaptcha';
1.1094 raeburn 18451: }
18452: }
1.1234 raeburn 18453: return ($output,$error,$captcha,$version);
1.1094 raeburn 18454: }
18455:
18456: sub captcha_response {
1.1327 raeburn 18457: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18458: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18459: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18460: if ($captcha eq 'original') {
1.1094 raeburn 18461: ($captcha_chk,$captcha_error) = &check_captcha();
18462: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18463: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18464: } else {
18465: $captcha_chk = 1;
18466: }
18467: return ($captcha_chk,$captcha_error);
18468: }
18469:
18470: sub get_captcha_config {
1.1327 raeburn 18471: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18472: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18473: my $hostname = &Apache::lonnet::hostname($lonhost);
18474: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18475: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18476: if ($context eq 'usercreation') {
18477: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18478: if (ref($domconfig{$context}) eq 'HASH') {
18479: $hashtocheck = $domconfig{$context}{'cancreate'};
18480: if (ref($hashtocheck) eq 'HASH') {
18481: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18482: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18483: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18484: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18485: }
18486: if ($privkey && $pubkey) {
18487: $captcha = 'recaptcha';
1.1234 raeburn 18488: $version = $hashtocheck->{'recaptchaversion'};
18489: if ($version ne '2') {
18490: $version = 1;
18491: }
1.1095 raeburn 18492: } else {
18493: $captcha = 'original';
18494: }
18495: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18496: $captcha = 'original';
18497: }
1.1094 raeburn 18498: }
1.1095 raeburn 18499: } else {
18500: $captcha = 'captcha';
18501: }
18502: } elsif ($context eq 'login') {
18503: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18504: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18505: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18506: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18507: if ($privkey && $pubkey) {
18508: $captcha = 'recaptcha';
1.1234 raeburn 18509: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18510: if ($version ne '2') {
18511: $version = 1;
18512: }
1.1095 raeburn 18513: } else {
18514: $captcha = 'original';
1.1094 raeburn 18515: }
1.1095 raeburn 18516: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18517: $captcha = 'original';
1.1094 raeburn 18518: }
1.1327 raeburn 18519: } elsif ($context eq 'passwords') {
18520: if ($dom_in_effect) {
18521: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18522: if ($passwdconf{'captcha'} eq 'recaptcha') {
18523: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18524: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18525: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18526: }
18527: if ($privkey && $pubkey) {
18528: $captcha = 'recaptcha';
18529: $version = $passwdconf{'recaptchaversion'};
18530: if ($version ne '2') {
18531: $version = 1;
18532: }
18533: } else {
18534: $captcha = 'original';
18535: }
18536: } elsif ($passwdconf{'captcha'} ne 'notused') {
18537: $captcha = 'original';
18538: }
18539: }
18540: }
1.1234 raeburn 18541: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18542: }
18543:
18544: sub create_captcha {
18545: my %captcha_params = &captcha_settings();
18546: my ($output,$maxtries,$tries) = ('',10,0);
18547: while ($tries < $maxtries) {
18548: $tries ++;
18549: my $captcha = Authen::Captcha->new (
18550: output_folder => $captcha_params{'output_dir'},
18551: data_folder => $captcha_params{'db_dir'},
18552: );
18553: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18554:
18555: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18556: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 18557: '<span class="LC_nobreak">'.
1.1094 raeburn 18558: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18559: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1367 raeburn 18560: '</span><br />'.
1.1176 raeburn 18561: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18562: last;
18563: }
18564: }
1.1323 raeburn 18565: if ($output eq '') {
18566: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18567: }
1.1094 raeburn 18568: return $output;
18569: }
18570:
18571: sub captcha_settings {
18572: my %captcha_params = (
18573: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18574: www_output_dir => "/captchaspool",
18575: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18576: numchars => '5',
18577: );
18578: return %captcha_params;
18579: }
18580:
18581: sub check_captcha {
18582: my ($captcha_chk,$captcha_error);
18583: my $code = $env{'form.code'};
18584: my $md5sum = $env{'form.crypt'};
18585: my %captcha_params = &captcha_settings();
18586: my $captcha = Authen::Captcha->new(
18587: output_folder => $captcha_params{'output_dir'},
18588: data_folder => $captcha_params{'db_dir'},
18589: );
1.1109 raeburn 18590: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18591: my %captcha_hash = (
18592: 0 => 'Code not checked (file error)',
18593: -1 => 'Failed: code expired',
18594: -2 => 'Failed: invalid code (not in database)',
18595: -3 => 'Failed: invalid code (code does not match crypt)',
18596: );
18597: if ($captcha_chk != 1) {
18598: $captcha_error = $captcha_hash{$captcha_chk}
18599: }
18600: return ($captcha_chk,$captcha_error);
18601: }
18602:
18603: sub create_recaptcha {
1.1234 raeburn 18604: my ($pubkey,$version) = @_;
18605: if ($version >= 2) {
1.1367 raeburn 18606: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18607: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 18608: } else {
18609: my $use_ssl;
18610: if ($ENV{'SERVER_PORT'} == 443) {
18611: $use_ssl = 1;
18612: }
18613: my $captcha = Captcha::reCAPTCHA->new;
18614: return $captcha->get_options_setter({theme => 'white'})."\n".
18615: $captcha->get_html($pubkey,undef,$use_ssl).
18616: &mt('If the text is hard to read, [_1] will replace them.',
18617: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18618: '<br /><br />';
18619: }
1.1094 raeburn 18620: }
18621:
18622: sub check_recaptcha {
1.1234 raeburn 18623: my ($privkey,$version) = @_;
1.1094 raeburn 18624: my $captcha_chk;
1.1350 raeburn 18625: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18626: if ($version >= 2) {
18627: my %info = (
18628: secret => $privkey,
18629: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18630: remoteip => $ip,
1.1234 raeburn 18631: );
1.1280 raeburn 18632: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18633: $request->content(join('&',map {
18634: my $name = escape($_);
18635: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18636: ? join("&$name=", map {escape($_) } @{$info{$_}})
18637: : &escape($info{$_}) );
18638: } keys(%info)));
18639: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18640: if ($response->is_success) {
18641: my $data = JSON::DWIW->from_json($response->decoded_content);
18642: if (ref($data) eq 'HASH') {
18643: if ($data->{'success'}) {
18644: $captcha_chk = 1;
18645: }
18646: }
18647: }
18648: } else {
18649: my $captcha = Captcha::reCAPTCHA->new;
18650: my $captcha_result =
18651: $captcha->check_answer(
18652: $privkey,
1.1350 raeburn 18653: $ip,
1.1234 raeburn 18654: $env{'form.recaptcha_challenge_field'},
18655: $env{'form.recaptcha_response_field'},
18656: );
18657: if ($captcha_result->{is_valid}) {
18658: $captcha_chk = 1;
18659: }
1.1094 raeburn 18660: }
18661: return $captcha_chk;
18662: }
18663:
1.1174 raeburn 18664: sub emailusername_info {
1.1244 raeburn 18665: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18666: my %titles = &Apache::lonlocal::texthash (
18667: lastname => 'Last Name',
18668: firstname => 'First Name',
18669: institution => 'School/college/university',
18670: location => "School's city, state/province, country",
18671: web => "School's web address",
18672: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18673: id => 'Student/Employee ID',
1.1174 raeburn 18674: );
18675: return (\@fields,\%titles);
18676: }
18677:
1.1161 raeburn 18678: sub cleanup_html {
18679: my ($incoming) = @_;
18680: my $outgoing;
18681: if ($incoming ne '') {
18682: $outgoing = $incoming;
18683: $outgoing =~ s/;/;/g;
18684: $outgoing =~ s/\#/#/g;
18685: $outgoing =~ s/\&/&/g;
18686: $outgoing =~ s/</</g;
18687: $outgoing =~ s/>/>/g;
18688: $outgoing =~ s/\(/(/g;
18689: $outgoing =~ s/\)/)/g;
18690: $outgoing =~ s/"/"/g;
18691: $outgoing =~ s/'/'/g;
18692: $outgoing =~ s/\$/$/g;
18693: $outgoing =~ s{/}{/}g;
18694: $outgoing =~ s/=/=/g;
18695: $outgoing =~ s/\\/\/g
18696: }
18697: return $outgoing;
18698: }
18699:
1.1190 musolffc 18700: # Checks for critical messages and returns a redirect url if one exists.
18701: # $interval indicates how often to check for messages.
1.1282 raeburn 18702: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18703: sub critical_redirect {
1.1282 raeburn 18704: my ($interval,$context) = @_;
1.1356 raeburn 18705: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18706: return ();
18707: }
1.1190 musolffc 18708: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18709: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18710: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18711: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 18712: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18713: if ($blocked) {
18714: my $checkrole = "cm./$cdom/$cnum";
18715: if ($env{'request.course.sec'} ne '') {
18716: $checkrole .= "/$env{'request.course.sec'}";
18717: }
18718: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18719: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18720: return;
18721: }
18722: }
18723: }
1.1190 musolffc 18724: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18725: $env{'user.name'});
18726: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18727: my $redirecturl;
1.1190 musolffc 18728: if ($what[0]) {
1.1356 raeburn 18729: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 18730: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18731: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18732: return (1, $url);
1.1190 musolffc 18733: }
1.1191 raeburn 18734: }
18735: }
18736: return ();
1.1190 musolffc 18737: }
18738:
1.1174 raeburn 18739: # Use:
18740: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18741: #
18742: ##################################################
18743: # password associated functions #
18744: ##################################################
18745: sub des_keys {
18746: # Make a new key for DES encryption.
18747: # Each key has two parts which are returned separately.
18748: # Please note: Each key must be passed through the &hex function
18749: # before it is output to the web browser. The hex versions cannot
18750: # be used to decrypt.
18751: my @hexstr=('0','1','2','3','4','5','6','7',
18752: '8','9','a','b','c','d','e','f');
18753: my $lkey='';
18754: for (0..7) {
18755: $lkey.=$hexstr[rand(15)];
18756: }
18757: my $ukey='';
18758: for (0..7) {
18759: $ukey.=$hexstr[rand(15)];
18760: }
18761: return ($lkey,$ukey);
18762: }
18763:
18764: sub des_decrypt {
18765: my ($key,$cyphertext) = @_;
18766: my $keybin=pack("H16",$key);
18767: my $cypher;
18768: if ($Crypt::DES::VERSION>=2.03) {
18769: $cypher=new Crypt::DES $keybin;
18770: } else {
18771: $cypher=new DES $keybin;
18772: }
1.1233 raeburn 18773: my $plaintext='';
18774: my $cypherlength = length($cyphertext);
18775: my $numchunks = int($cypherlength/32);
18776: for (my $j=0; $j<$numchunks; $j++) {
18777: my $start = $j*32;
18778: my $cypherblock = substr($cyphertext,$start,32);
18779: my $chunk =
18780: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18781: $chunk .=
18782: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18783: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18784: $plaintext .= $chunk;
18785: }
1.1174 raeburn 18786: return $plaintext;
18787: }
18788:
1.1344 raeburn 18789: sub get_requested_shorturls {
1.1309 raeburn 18790: my ($cdom,$cnum,$navmap) = @_;
18791: return unless (ref($navmap));
1.1344 raeburn 18792: my ($numnew,$errors);
1.1309 raeburn 18793: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18794: if (@toshorten) {
18795: my (%maps,%resources,%titles);
18796: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18797: 'shorturls',$cdom,$cnum);
18798: if (keys(%resources)) {
1.1344 raeburn 18799: my %tocreate;
1.1309 raeburn 18800: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18801: my $symb = $resources{$item};
18802: if ($symb) {
18803: $tocreate{$cnum.'&'.$symb} = 1;
18804: }
18805: }
1.1344 raeburn 18806: if (keys(%tocreate)) {
18807: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18808: \%tocreate);
18809: }
1.1309 raeburn 18810: }
1.1344 raeburn 18811: }
18812: return ($numnew,$errors);
18813: }
18814:
18815: sub make_short_symbs {
18816: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18817: my ($numnew,@errors);
18818: if (ref($tocreateref) eq 'HASH') {
18819: my %tocreate = %{$tocreateref};
1.1309 raeburn 18820: if (keys(%tocreate)) {
18821: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18822: my $su = Short::URL->new(no_vowels => 1);
18823: my $init = '';
18824: my (%newunique,%addcourse,%courseonly,%failed);
18825: # get lock on tiny db
18826: my $now = time;
1.1344 raeburn 18827: if ($lockuser eq '') {
18828: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18829: }
1.1309 raeburn 18830: my $lockhash = {
1.1344 raeburn 18831: "lock\0$now" => $lockuser,
1.1309 raeburn 18832: };
18833: my $tries = 0;
18834: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18835: my ($code,$error);
18836: while (($gotlock ne 'ok') && ($tries<3)) {
18837: $tries ++;
18838: sleep 1;
1.1319 raeburn 18839: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18840: }
18841: if ($gotlock eq 'ok') {
18842: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18843: \%addcourse,\%courseonly,\%failed);
18844: if (keys(%failed)) {
18845: my $numfailed = scalar(keys(%failed));
18846: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18847: }
18848: if (keys(%newunique)) {
18849: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18850: if ($putres eq 'ok') {
18851: $numnew = scalar(keys(%newunique));
18852: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18853: unless ($newputres eq 'ok') {
18854: push(@errors,&mt('error: could not store course look-up of short URLs'));
18855: }
18856: } else {
18857: push(@errors,&mt('error: could not store unique six character URLs'));
18858: }
18859: }
18860: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18861: unless ($dellockres eq 'ok') {
18862: push(@errors,&mt('error: could not release lockfile'));
18863: }
18864: } else {
18865: push(@errors,&mt('error: could not obtain lockfile'));
18866: }
18867: if (keys(%courseonly)) {
18868: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18869: if ($result ne 'ok') {
18870: push(@errors,&mt('error: could not update course look-up of short URLs'));
18871: }
18872: }
18873: }
18874: }
18875: return ($numnew,\@errors);
18876: }
18877:
18878: sub shorten_symbs {
18879: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18880: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18881: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18882: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18883: my (%possibles,%collisions);
18884: foreach my $key (keys(%{$tocreate})) {
18885: my $num = String::CRC32::crc32($key);
18886: my $tiny = $su->encode($num,$init);
18887: if ($tiny) {
18888: $possibles{$tiny} = $key;
18889: }
18890: }
18891: if (!$init) {
18892: $init = 1;
18893: } else {
18894: $init ++;
18895: }
18896: if (keys(%possibles)) {
18897: my @posstiny = keys(%possibles);
18898: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18899: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18900: if (keys(%currtiny)) {
18901: foreach my $key (keys(%currtiny)) {
18902: next if ($currtiny{$key} eq '');
18903: if ($currtiny{$key} eq $possibles{$key}) {
18904: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18905: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18906: $courseonly->{$tsymb} = $key;
18907: }
18908: } else {
18909: $collisions{$possibles{$key}} = 1;
18910: }
18911: delete($possibles{$key});
18912: }
18913: }
18914: foreach my $key (keys(%possibles)) {
18915: $newunique->{$key} = $possibles{$key};
18916: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18917: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18918: $addcourse->{$tsymb} = $key;
18919: }
18920: }
18921: }
18922: if (keys(%collisions)) {
18923: if ($init <5) {
18924: if (!$init) {
18925: $init = 1;
18926: } else {
18927: $init ++;
18928: }
18929: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18930: $newunique,$addcourse,$courseonly,$failed);
18931: } else {
18932: foreach my $key (keys(%collisions)) {
18933: $failed->{$key} = 1;
18934: }
18935: }
18936: }
18937: return $init;
18938: }
18939:
1.1328 raeburn 18940: sub is_nonframeable {
1.1329 raeburn 18941: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18942: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18943: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18944:
18945: $remprotocol = lc($remprotocol);
18946: $remhost = lc($remhost);
18947: my $remport = 80;
18948: if ($remprotocol eq 'https') {
18949: $remport = 443;
18950: }
1.1330 raeburn 18951: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18952: if ($cached) {
18953: unless ($nocache) {
18954: if ($result) {
18955: return 1;
18956: } else {
18957: return 0;
18958: }
18959: }
18960: }
1.1328 raeburn 18961: my $uselink;
18962: my $request = new HTTP::Request('HEAD',$url);
18963: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18964: if ($response->is_success()) {
18965: my $secpolicy = lc($response->header('content-security-policy'));
18966: my $xframeop = lc($response->header('x-frame-options'));
18967: $secpolicy =~ s/^\s+|\s+$//g;
18968: $xframeop =~ s/^\s+|\s+$//g;
18969: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18970: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18971: my ($origin,$protocol,$port);
18972: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18973: $port = $ENV{'SERVER_PORT'};
18974: } else {
18975: $port = 80;
18976: }
18977: if ($absolute eq '') {
18978: $protocol = 'http:';
18979: if ($port == 443) {
18980: $protocol = 'https:';
18981: }
18982: $origin = $protocol.'//'.lc($hostname);
18983: } else {
18984: $origin = lc($absolute);
18985: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18986: }
18987: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18988: my $framepolicy = $1;
18989: $framepolicy =~ s/^\s+|\s+$//g;
18990: my @policies = split(/\s+/,$framepolicy);
18991: if (@policies) {
18992: if (grep(/^\Q'none'\E$/,@policies)) {
18993: $uselink = 1;
18994: } else {
18995: $uselink = 1;
18996: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18997: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18998: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18999: undef($uselink);
19000: }
19001: if ($uselink) {
19002: if (grep(/^\Q'self'\E$/,@policies)) {
19003: if (($origin ne '') && ($remotehost eq $origin)) {
19004: undef($uselink);
19005: }
19006: }
19007: }
19008: if ($uselink) {
19009: my @possok;
19010: if ($ip ne '') {
19011: push(@possok,$ip);
19012: }
19013: my $hoststr = '';
19014: foreach my $part (reverse(split(/\./,$hostname))) {
19015: if ($hoststr eq '') {
19016: $hoststr = $part;
19017: } else {
19018: $hoststr = "$part.$hoststr";
19019: }
19020: if ($hoststr eq $hostname) {
19021: push(@possok,$hostname);
19022: } else {
19023: push(@possok,"*.$hoststr");
19024: }
19025: }
19026: if (@possok) {
19027: foreach my $poss (@possok) {
19028: last if (!$uselink);
19029: foreach my $policy (@policies) {
19030: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19031: undef($uselink);
19032: last;
19033: }
19034: }
19035: }
19036: }
19037: }
19038: }
19039: }
19040: } elsif ($xframeop ne '') {
19041: $uselink = 1;
19042: my @policies = split(/\s*,\s*/,$xframeop);
19043: if (@policies) {
19044: unless (grep(/^deny$/,@policies)) {
19045: if ($origin ne '') {
19046: if (grep(/^sameorigin$/,@policies)) {
19047: if ($remotehost eq $origin) {
19048: undef($uselink);
19049: }
19050: }
19051: if ($uselink) {
19052: foreach my $policy (@policies) {
19053: if ($policy =~ /^allow-from\s*(.+)$/) {
19054: my $allowfrom = $1;
19055: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19056: undef($uselink);
19057: last;
19058: }
19059: }
19060: }
19061: }
19062: }
19063: }
19064: }
19065: }
19066: }
19067: }
1.1329 raeburn 19068: if ($nocache) {
19069: if ($cached) {
19070: my $devalidate;
19071: if ($uselink && !$result) {
19072: $devalidate = 1;
19073: } elsif (!$uselink && $result) {
19074: $devalidate = 1;
19075: }
19076: if ($devalidate) {
19077: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19078: }
19079: }
19080: } else {
19081: if ($uselink) {
19082: $result = 1;
19083: } else {
19084: $result = 0;
19085: }
19086: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19087: }
1.1328 raeburn 19088: return $uselink;
19089: }
19090:
1.1359 raeburn 19091: sub page_menu {
19092: my ($menucolls,$menunum) = @_;
19093: my %menu;
19094: foreach my $item (split(/;/,$menucolls)) {
19095: my ($num,$value) = split(/\%/,$item);
19096: if ($num eq $menunum) {
19097: my @entries = split(/\&/,$value);
19098: foreach my $entry (@entries) {
19099: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19100: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19101: $menu{$name} = $fields;
19102: } else {
19103: my @shown;
19104: if ($fields =~ /,/) {
19105: @shown = split(/,/,$fields);
19106: } else {
19107: @shown = ($fields);
19108: }
19109: if (@shown) {
19110: foreach my $field (@shown) {
19111: next if ($field eq '');
19112: $menu{$field} = 1;
19113: }
19114: }
19115: }
19116: }
19117: }
19118: }
19119: return %menu;
19120: }
19121:
1.112 bowersj2 19122: 1;
19123: __END__;
1.41 ng 19124:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>