Annotation of loncom/interface/loncommon.pm, revision 1.1341
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1341 ! raeburn 4: # $Id: loncommon.pm,v 1.1340 2020/03/15 23:04: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 {
1419: my ($text) = @_;
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.1159 raeburn 1433: <a href="$link" title="$title">$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.80 albertel 3651: ###############################################################
3652: ## Get Kerberos Defaults for Domain ##
3653: ###############################################################
3654: ##
3655: ## Returns default kerberos version and an associated argument
3656: ## as listed in file domain.tab. If not listed, provides
3657: ## appropriate default domain and kerberos version.
3658: ##
3659: #-------------------------------------------
3660:
3661: =pod
3662:
1.648 raeburn 3663: =item * &get_kerberos_defaults()
1.80 albertel 3664:
3665: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3666: version and domain. If not found, it defaults to version 4 and the
3667: domain of the server.
1.80 albertel 3668:
1.648 raeburn 3669: =over 4
3670:
1.80 albertel 3671: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3672:
1.648 raeburn 3673: =back
3674:
3675: =back
3676:
1.80 albertel 3677: =cut
3678:
3679: #-------------------------------------------
3680: sub get_kerberos_defaults {
3681: my $domain=shift;
1.641 raeburn 3682: my ($krbdef,$krbdefdom);
3683: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3684: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3685: $krbdef = $domdefaults{'auth_def'};
3686: $krbdefdom = $domdefaults{'auth_arg_def'};
3687: } else {
1.80 albertel 3688: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3689: my $krbdefdom=$1;
3690: $krbdefdom=~tr/a-z/A-Z/;
3691: $krbdef = "krb4";
3692: }
3693: return ($krbdef,$krbdefdom);
3694: }
1.112 bowersj2 3695:
1.32 matthew 3696:
1.46 matthew 3697: ###############################################################
3698: ## Thesaurus Functions ##
3699: ###############################################################
1.20 www 3700:
1.46 matthew 3701: =pod
1.20 www 3702:
1.112 bowersj2 3703: =head1 Thesaurus Functions
3704:
3705: =over 4
3706:
1.648 raeburn 3707: =item * &initialize_keywords()
1.46 matthew 3708:
3709: Initializes the package variable %Keywords if it is empty. Uses the
3710: package variable $thesaurus_db_file.
3711:
3712: =cut
3713:
3714: ###################################################
3715:
3716: sub initialize_keywords {
3717: return 1 if (scalar keys(%Keywords));
3718: # If we are here, %Keywords is empty, so fill it up
3719: # Make sure the file we need exists...
3720: if (! -e $thesaurus_db_file) {
3721: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3722: " failed because it does not exist");
3723: return 0;
3724: }
3725: # Set up the hash as a database
3726: my %thesaurus_db;
3727: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3728: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3729: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3730: $thesaurus_db_file);
3731: return 0;
3732: }
3733: # Get the average number of appearances of a word.
3734: my $avecount = $thesaurus_db{'average.count'};
3735: # Put keywords (those that appear > average) into %Keywords
3736: while (my ($word,$data)=each (%thesaurus_db)) {
3737: my ($count,undef) = split /:/,$data;
3738: $Keywords{$word}++ if ($count > $avecount);
3739: }
3740: untie %thesaurus_db;
3741: # Remove special values from %Keywords.
1.356 albertel 3742: foreach my $value ('total.count','average.count') {
3743: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3744: }
1.46 matthew 3745: return 1;
3746: }
3747:
3748: ###################################################
3749:
3750: =pod
3751:
1.648 raeburn 3752: =item * &keyword($word)
1.46 matthew 3753:
3754: Returns true if $word is a keyword. A keyword is a word that appears more
3755: than the average number of times in the thesaurus database. Calls
3756: &initialize_keywords
3757:
3758: =cut
3759:
3760: ###################################################
1.20 www 3761:
3762: sub keyword {
1.46 matthew 3763: return if (!&initialize_keywords());
3764: my $word=lc(shift());
3765: $word=~s/\W//g;
3766: return exists($Keywords{$word});
1.20 www 3767: }
1.46 matthew 3768:
3769: ###############################################################
3770:
3771: =pod
1.20 www 3772:
1.648 raeburn 3773: =item * &get_related_words()
1.46 matthew 3774:
1.160 matthew 3775: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3776: an array of words. If the keyword is not in the thesaurus, an empty array
3777: will be returned. The order of the words returned is determined by the
3778: database which holds them.
3779:
3780: Uses global $thesaurus_db_file.
3781:
1.1057 foxr 3782:
1.46 matthew 3783: =cut
3784:
3785: ###############################################################
3786: sub get_related_words {
3787: my $keyword = shift;
3788: my %thesaurus_db;
3789: if (! -e $thesaurus_db_file) {
3790: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3791: "failed because the file does not exist");
3792: return ();
3793: }
3794: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3795: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3796: return ();
3797: }
3798: my @Words=();
1.429 www 3799: my $count=0;
1.46 matthew 3800: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3801: # The first element is the number of times
3802: # the word appears. We do not need it now.
1.429 www 3803: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3804: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3805: my $threshold=$mostfrequentcount/10;
3806: foreach my $possibleword (@RelatedWords) {
3807: my ($word,$wordcount)=split(/\,/,$possibleword);
3808: if ($wordcount>$threshold) {
3809: push(@Words,$word);
3810: $count++;
3811: if ($count>10) { last; }
3812: }
1.20 www 3813: }
3814: }
1.46 matthew 3815: untie %thesaurus_db;
3816: return @Words;
1.14 harris41 3817: }
1.1090 foxr 3818: ###############################################################
3819: #
3820: # Spell checking
3821: #
3822:
3823: =pod
3824:
1.1142 raeburn 3825: =back
3826:
1.1090 foxr 3827: =head1 Spell checking
3828:
3829: =over 4
3830:
3831: =item * &check_spelling($wordlist $language)
3832:
3833: Takes a string containing words and feeds it to an external
3834: spellcheck program via a pipeline. Returns a string containing
3835: them mis-spelled words.
3836:
3837: Parameters:
3838:
3839: =over 4
3840:
3841: =item - $wordlist
3842:
3843: String that will be fed into the spellcheck program.
3844:
3845: =item - $language
3846:
3847: Language string that specifies the language for which the spell
3848: check will be performed.
3849:
3850: =back
3851:
3852: =back
3853:
3854: Note: This sub assumes that aspell is installed.
3855:
3856:
3857: =cut
3858:
1.46 matthew 3859:
1.1090 foxr 3860: sub check_spelling {
3861: my ($wordlist, $language) = @_;
1.1091 foxr 3862: my @misspellings;
3863:
3864: # Generate the speller and set the langauge.
3865: # if explicitly selected:
1.1090 foxr 3866:
1.1091 foxr 3867: my $speller = Text::Aspell->new;
1.1090 foxr 3868: if ($language) {
1.1091 foxr 3869: $speller->set_option('lang', $language);
1.1090 foxr 3870: }
3871:
1.1091 foxr 3872: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3873:
1.1091 foxr 3874: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3875:
1.1091 foxr 3876: foreach my $word (@words) {
3877: if(! $speller->check($word)) {
3878: push(@misspellings, $word);
1.1090 foxr 3879: }
3880: }
1.1091 foxr 3881: return join(' ', @misspellings);
3882:
1.1090 foxr 3883: }
3884:
1.61 www 3885: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3886: =pod
3887:
1.112 bowersj2 3888: =head1 User Name Functions
3889:
3890: =over 4
3891:
1.648 raeburn 3892: =item * &plainname($uname,$udom,$first)
1.81 albertel 3893:
1.112 bowersj2 3894: Takes a users logon name and returns it as a string in
1.226 albertel 3895: "first middle last generation" form
3896: if $first is set to 'lastname' then it returns it as
3897: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3898:
3899: =cut
1.61 www 3900:
1.295 www 3901:
1.81 albertel 3902: ###############################################################
1.61 www 3903: sub plainname {
1.226 albertel 3904: my ($uname,$udom,$first)=@_;
1.537 albertel 3905: return if (!defined($uname) || !defined($udom));
1.295 www 3906: my %names=&getnames($uname,$udom);
1.226 albertel 3907: my $name=&Apache::lonnet::format_name($names{'firstname'},
3908: $names{'middlename'},
3909: $names{'lastname'},
3910: $names{'generation'},$first);
3911: $name=~s/^\s+//;
1.62 www 3912: $name=~s/\s+$//;
3913: $name=~s/\s+/ /g;
1.353 albertel 3914: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3915: return $name;
1.61 www 3916: }
1.66 www 3917:
3918: # -------------------------------------------------------------------- Nickname
1.81 albertel 3919: =pod
3920:
1.648 raeburn 3921: =item * &nickname($uname,$udom)
1.81 albertel 3922:
3923: Gets a users name and returns it as a string as
3924:
3925: ""nickname""
1.66 www 3926:
1.81 albertel 3927: if the user has a nickname or
3928:
3929: "first middle last generation"
3930:
3931: if the user does not
3932:
3933: =cut
1.66 www 3934:
3935: sub nickname {
3936: my ($uname,$udom)=@_;
1.537 albertel 3937: return if (!defined($uname) || !defined($udom));
1.295 www 3938: my %names=&getnames($uname,$udom);
1.68 albertel 3939: my $name=$names{'nickname'};
1.66 www 3940: if ($name) {
3941: $name='"'.$name.'"';
3942: } else {
3943: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3944: $names{'lastname'}.' '.$names{'generation'};
3945: $name=~s/\s+$//;
3946: $name=~s/\s+/ /g;
3947: }
3948: return $name;
3949: }
3950:
1.295 www 3951: sub getnames {
3952: my ($uname,$udom)=@_;
1.537 albertel 3953: return if (!defined($uname) || !defined($udom));
1.433 albertel 3954: if ($udom eq 'public' && $uname eq 'public') {
3955: return ('lastname' => &mt('Public'));
3956: }
1.295 www 3957: my $id=$uname.':'.$udom;
3958: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3959: if ($cached) {
3960: return %{$names};
3961: } else {
3962: my %loadnames=&Apache::lonnet::get('environment',
3963: ['firstname','middlename','lastname','generation','nickname'],
3964: $udom,$uname);
3965: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3966: return %loadnames;
3967: }
3968: }
1.61 www 3969:
1.542 raeburn 3970: # -------------------------------------------------------------------- getemails
1.648 raeburn 3971:
1.542 raeburn 3972: =pod
3973:
1.648 raeburn 3974: =item * &getemails($uname,$udom)
1.542 raeburn 3975:
3976: Gets a user's email information and returns it as a hash with keys:
3977: notification, critnotification, permanentemail
3978:
3979: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3980: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3981:
1.648 raeburn 3982:
1.542 raeburn 3983: =cut
3984:
1.648 raeburn 3985:
1.466 albertel 3986: sub getemails {
3987: my ($uname,$udom)=@_;
3988: if ($udom eq 'public' && $uname eq 'public') {
3989: return;
3990: }
1.467 www 3991: if (!$udom) { $udom=$env{'user.domain'}; }
3992: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3993: my $id=$uname.':'.$udom;
3994: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3995: if ($cached) {
3996: return %{$names};
3997: } else {
3998: my %loadnames=&Apache::lonnet::get('environment',
3999: ['notification','critnotification',
4000: 'permanentemail'],
4001: $udom,$uname);
4002: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4003: return %loadnames;
4004: }
4005: }
4006:
1.551 albertel 4007: sub flush_email_cache {
4008: my ($uname,$udom)=@_;
4009: if (!$udom) { $udom =$env{'user.domain'}; }
4010: if (!$uname) { $uname=$env{'user.name'}; }
4011: return if ($udom eq 'public' && $uname eq 'public');
4012: my $id=$uname.':'.$udom;
4013: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4014: }
4015:
1.728 raeburn 4016: # -------------------------------------------------------------------- getlangs
4017:
4018: =pod
4019:
4020: =item * &getlangs($uname,$udom)
4021:
4022: Gets a user's language preference and returns it as a hash with key:
4023: language.
4024:
4025: =cut
4026:
4027:
4028: sub getlangs {
4029: my ($uname,$udom) = @_;
4030: if (!$udom) { $udom =$env{'user.domain'}; }
4031: if (!$uname) { $uname=$env{'user.name'}; }
4032: my $id=$uname.':'.$udom;
4033: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4034: if ($cached) {
4035: return %{$langs};
4036: } else {
4037: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4038: $udom,$uname);
4039: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4040: return %loadlangs;
4041: }
4042: }
4043:
4044: sub flush_langs_cache {
4045: my ($uname,$udom)=@_;
4046: if (!$udom) { $udom =$env{'user.domain'}; }
4047: if (!$uname) { $uname=$env{'user.name'}; }
4048: return if ($udom eq 'public' && $uname eq 'public');
4049: my $id=$uname.':'.$udom;
4050: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4051: }
4052:
1.61 www 4053: # ------------------------------------------------------------------ Screenname
1.81 albertel 4054:
4055: =pod
4056:
1.648 raeburn 4057: =item * &screenname($uname,$udom)
1.81 albertel 4058:
4059: Gets a users screenname and returns it as a string
4060:
4061: =cut
1.61 www 4062:
4063: sub screenname {
4064: my ($uname,$udom)=@_;
1.258 albertel 4065: if ($uname eq $env{'user.name'} &&
4066: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4067: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4068: return $names{'screenname'};
1.62 www 4069: }
4070:
1.212 albertel 4071:
1.802 bisitz 4072: # ------------------------------------------------------------- Confirm Wrapper
4073: =pod
4074:
1.1142 raeburn 4075: =item * &confirmwrapper($message)
1.802 bisitz 4076:
4077: Wrap messages about completion of operation in box
4078:
4079: =cut
4080:
4081: sub confirmwrapper {
4082: my ($message)=@_;
4083: if ($message) {
4084: return "\n".'<div class="LC_confirm_box">'."\n"
4085: .$message."\n"
4086: .'</div>'."\n";
4087: } else {
4088: return $message;
4089: }
4090: }
4091:
1.62 www 4092: # ------------------------------------------------------------- Message Wrapper
4093:
4094: sub messagewrapper {
1.369 www 4095: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4096: return
1.441 albertel 4097: '<a href="/adm/email?compose=individual&'.
4098: 'recname='.$username.'&recdom='.$domain.
4099: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4100: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4101: }
1.802 bisitz 4102:
1.74 www 4103: # --------------------------------------------------------------- Notes Wrapper
4104:
4105: sub noteswrapper {
4106: my ($link,$un,$do)=@_;
4107: return
1.896 amueller 4108: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4109: }
1.802 bisitz 4110:
1.62 www 4111: # ------------------------------------------------------------- Aboutme Wrapper
4112:
4113: sub aboutmewrapper {
1.1070 raeburn 4114: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4115: if (!defined($username) && !defined($domain)) {
4116: return;
4117: }
1.1096 raeburn 4118: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4119: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4120: }
4121:
4122: # ------------------------------------------------------------ Syllabus Wrapper
4123:
4124: sub syllabuswrapper {
1.707 bisitz 4125: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4126: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4127: }
1.14 harris41 4128:
1.802 bisitz 4129: # -----------------------------------------------------------------------------
4130:
1.208 matthew 4131: sub track_student_link {
1.887 raeburn 4132: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4133: my $link ="/adm/trackstudent?";
1.208 matthew 4134: my $title = 'View recent activity';
4135: if (defined($sname) && $sname !~ /^\s*$/ &&
4136: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4137: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4138: $title .= ' of this student';
1.268 albertel 4139: }
1.208 matthew 4140: if (defined($target) && $target !~ /^\s*$/) {
4141: $target = qq{target="$target"};
4142: } else {
4143: $target = '';
4144: }
1.268 albertel 4145: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4146: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4147: $title = &mt($title);
4148: $linktext = &mt($linktext);
1.448 albertel 4149: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4150: &help_open_topic('View_recent_activity');
1.208 matthew 4151: }
4152:
1.781 raeburn 4153: sub slot_reservations_link {
4154: my ($linktext,$sname,$sdom,$target) = @_;
4155: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4156: my $title = 'View slot reservation history';
4157: if (defined($sname) && $sname !~ /^\s*$/ &&
4158: defined($sdom) && $sdom !~ /^\s*$/) {
4159: $link .= "&uname=$sname&udom=$sdom";
4160: $title .= ' of this student';
4161: }
4162: if (defined($target) && $target !~ /^\s*$/) {
4163: $target = qq{target="$target"};
4164: } else {
4165: $target = '';
4166: }
4167: $title = &mt($title);
4168: $linktext = &mt($linktext);
4169: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4170: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4171:
4172: }
4173:
1.508 www 4174: # ===================================================== Display a student photo
4175:
4176:
1.509 albertel 4177: sub student_image_tag {
1.508 www 4178: my ($domain,$user)=@_;
4179: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4180: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4181: return '<img src="'.$imgsrc.'" align="right" />';
4182: } else {
4183: return '';
4184: }
4185: }
4186:
1.112 bowersj2 4187: =pod
4188:
4189: =back
4190:
4191: =head1 Access .tab File Data
4192:
4193: =over 4
4194:
1.648 raeburn 4195: =item * &languageids()
1.112 bowersj2 4196:
4197: returns list of all language ids
4198:
4199: =cut
4200:
1.14 harris41 4201: sub languageids {
1.16 harris41 4202: return sort(keys(%language));
1.14 harris41 4203: }
4204:
1.112 bowersj2 4205: =pod
4206:
1.648 raeburn 4207: =item * &languagedescription()
1.112 bowersj2 4208:
4209: returns description of a specified language id
4210:
4211: =cut
4212:
1.14 harris41 4213: sub languagedescription {
1.125 www 4214: my $code=shift;
4215: return ($supported_language{$code}?'* ':'').
4216: $language{$code}.
1.126 www 4217: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4218: }
4219:
1.1048 foxr 4220: =pod
4221:
4222: =item * &plainlanguagedescription
4223:
4224: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4225: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4226:
4227: =cut
4228:
1.145 www 4229: sub plainlanguagedescription {
4230: my $code=shift;
4231: return $language{$code};
4232: }
4233:
1.1048 foxr 4234: =pod
4235:
4236: =item * &supportedlanguagecode
4237:
4238: Returns the supported language code (e.g. sptutf maps to pt) given a language
4239: code.
4240:
4241: =cut
4242:
1.145 www 4243: sub supportedlanguagecode {
4244: my $code=shift;
4245: return $supported_language{$code};
1.97 www 4246: }
4247:
1.112 bowersj2 4248: =pod
4249:
1.1048 foxr 4250: =item * &latexlanguage()
4251:
4252: Given a language key code returns the correspondnig language to use
4253: to select the correct hyphenation on LaTeX printouts. This is undef if there
4254: is no supported hyphenation for the language code.
4255:
4256: =cut
4257:
4258: sub latexlanguage {
4259: my $code = shift;
4260: return $latex_language{$code};
4261: }
4262:
4263: =pod
4264:
4265: =item * &latexhyphenation()
4266:
4267: Same as above but what's supplied is the language as it might be stored
4268: in the metadata.
4269:
4270: =cut
4271:
4272: sub latexhyphenation {
4273: my $key = shift;
4274: return $latex_language_bykey{$key};
4275: }
4276:
4277: =pod
4278:
1.648 raeburn 4279: =item * ©rightids()
1.112 bowersj2 4280:
4281: returns list of all copyrights
4282:
4283: =cut
4284:
4285: sub copyrightids {
4286: return sort(keys(%cprtag));
4287: }
4288:
4289: =pod
4290:
1.648 raeburn 4291: =item * ©rightdescription()
1.112 bowersj2 4292:
4293: returns description of a specified copyright id
4294:
4295: =cut
4296:
4297: sub copyrightdescription {
1.166 www 4298: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4299: }
1.197 matthew 4300:
4301: =pod
4302:
1.648 raeburn 4303: =item * &source_copyrightids()
1.192 taceyjo1 4304:
4305: returns list of all source copyrights
4306:
4307: =cut
4308:
4309: sub source_copyrightids {
4310: return sort(keys(%scprtag));
4311: }
4312:
4313: =pod
4314:
1.648 raeburn 4315: =item * &source_copyrightdescription()
1.192 taceyjo1 4316:
4317: returns description of a specified source copyright id
4318:
4319: =cut
4320:
4321: sub source_copyrightdescription {
4322: return &mt($scprtag{shift(@_)});
4323: }
1.112 bowersj2 4324:
4325: =pod
4326:
1.648 raeburn 4327: =item * &filecategories()
1.112 bowersj2 4328:
4329: returns list of all file categories
4330:
4331: =cut
4332:
4333: sub filecategories {
4334: return sort(keys(%category_extensions));
4335: }
4336:
4337: =pod
4338:
1.648 raeburn 4339: =item * &filecategorytypes()
1.112 bowersj2 4340:
4341: returns list of file types belonging to a given file
4342: category
4343:
4344: =cut
4345:
4346: sub filecategorytypes {
1.356 albertel 4347: my ($cat) = @_;
1.1248 raeburn 4348: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4349: return @{$category_extensions{lc($cat)}};
4350: } else {
4351: return ();
4352: }
1.112 bowersj2 4353: }
4354:
4355: =pod
4356:
1.648 raeburn 4357: =item * &fileembstyle()
1.112 bowersj2 4358:
4359: returns embedding style for a specified file type
4360:
4361: =cut
4362:
4363: sub fileembstyle {
4364: return $fe{lc(shift(@_))};
1.169 www 4365: }
4366:
1.351 www 4367: sub filemimetype {
4368: return $fm{lc(shift(@_))};
4369: }
4370:
1.169 www 4371:
4372: sub filecategoryselect {
4373: my ($name,$value)=@_;
1.189 matthew 4374: return &select_form($value,$name,
1.970 raeburn 4375: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4376: }
4377:
4378: =pod
4379:
1.648 raeburn 4380: =item * &filedescription()
1.112 bowersj2 4381:
4382: returns description for a specified file type
4383:
4384: =cut
4385:
4386: sub filedescription {
1.188 matthew 4387: my $file_description = $fd{lc(shift())};
4388: $file_description =~ s:([\[\]]):~$1:g;
4389: return &mt($file_description);
1.112 bowersj2 4390: }
4391:
4392: =pod
4393:
1.648 raeburn 4394: =item * &filedescriptionex()
1.112 bowersj2 4395:
4396: returns description for a specified file type with
4397: extra formatting
4398:
4399: =cut
4400:
4401: sub filedescriptionex {
4402: my $ex=shift;
1.188 matthew 4403: my $file_description = $fd{lc($ex)};
4404: $file_description =~ s:([\[\]]):~$1:g;
4405: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4406: }
4407:
4408: # End of .tab access
4409: =pod
4410:
4411: =back
4412:
4413: =cut
4414:
4415: # ------------------------------------------------------------------ File Types
4416: sub fileextensions {
4417: return sort(keys(%fe));
4418: }
4419:
1.97 www 4420: # ----------------------------------------------------------- Display Languages
4421: # returns a hash with all desired display languages
4422: #
4423:
4424: sub display_languages {
4425: my %languages=();
1.695 raeburn 4426: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4427: $languages{$lang}=1;
1.97 www 4428: }
4429: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4430: if ($env{'form.displaylanguage'}) {
1.356 albertel 4431: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4432: $languages{$lang}=1;
1.97 www 4433: }
4434: }
4435: return %languages;
1.14 harris41 4436: }
4437:
1.582 albertel 4438: sub languages {
4439: my ($possible_langs) = @_;
1.695 raeburn 4440: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4441: if (!ref($possible_langs)) {
4442: if( wantarray ) {
4443: return @preferred_langs;
4444: } else {
4445: return $preferred_langs[0];
4446: }
4447: }
4448: my %possibilities = map { $_ => 1 } (@$possible_langs);
4449: my @preferred_possibilities;
4450: foreach my $preferred_lang (@preferred_langs) {
4451: if (exists($possibilities{$preferred_lang})) {
4452: push(@preferred_possibilities, $preferred_lang);
4453: }
4454: }
4455: if( wantarray ) {
4456: return @preferred_possibilities;
4457: }
4458: return $preferred_possibilities[0];
4459: }
4460:
1.742 raeburn 4461: sub user_lang {
4462: my ($touname,$toudom,$fromcid) = @_;
4463: my @userlangs;
4464: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4465: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4466: $env{'course.'.$fromcid.'.languages'}));
4467: } else {
4468: my %langhash = &getlangs($touname,$toudom);
4469: if ($langhash{'languages'} ne '') {
4470: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4471: } else {
4472: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4473: if ($domdefs{'lang_def'} ne '') {
4474: @userlangs = ($domdefs{'lang_def'});
4475: }
4476: }
4477: }
4478: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4479: my $user_lh = Apache::localize->get_handle(@languages);
4480: return $user_lh;
4481: }
4482:
4483:
1.112 bowersj2 4484: ###############################################################
4485: ## Student Answer Attempts ##
4486: ###############################################################
4487:
4488: =pod
4489:
4490: =head1 Alternate Problem Views
4491:
4492: =over 4
4493:
1.648 raeburn 4494: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4495: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4496:
4497: Return string with previous attempt on problem. Arguments:
4498:
4499: =over 4
4500:
4501: =item * $symb: Problem, including path
4502:
4503: =item * $username: username of the desired student
4504:
4505: =item * $domain: domain of the desired student
1.14 harris41 4506:
1.112 bowersj2 4507: =item * $course: Course ID
1.14 harris41 4508:
1.112 bowersj2 4509: =item * $getattempt: Leave blank for all attempts, otherwise put
4510: something
1.14 harris41 4511:
1.112 bowersj2 4512: =item * $regexp: if string matches this regexp, the string will be
4513: sent to $gradesub
1.14 harris41 4514:
1.112 bowersj2 4515: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4516:
1.1199 raeburn 4517: =item * $usec: section of the desired student
4518:
4519: =item * $identifier: counter for student (multiple students one problem) or
4520: problem (one student; whole sequence).
4521:
1.112 bowersj2 4522: =back
1.14 harris41 4523:
1.112 bowersj2 4524: The output string is a table containing all desired attempts, if any.
1.16 harris41 4525:
1.112 bowersj2 4526: =cut
1.1 albertel 4527:
4528: sub get_previous_attempt {
1.1199 raeburn 4529: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4530: my $prevattempts='';
1.43 ng 4531: no strict 'refs';
1.1 albertel 4532: if ($symb) {
1.3 albertel 4533: my (%returnhash)=
4534: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4535: if ($returnhash{'version'}) {
4536: my %lasthash=();
4537: my $version;
4538: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4539: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4540: if ($key =~ /\.rawrndseed$/) {
4541: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4542: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4543: } else {
4544: $lasthash{$key}=$returnhash{$version.':'.$key};
4545: }
1.19 harris41 4546: }
1.1 albertel 4547: }
1.596 albertel 4548: $prevattempts=&start_data_table().&start_data_table_header_row();
4549: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4550: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4551: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4552: foreach my $key (sort(keys(%lasthash))) {
4553: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4554: if ($#parts > 0) {
1.31 albertel 4555: my $data=$parts[-1];
1.989 raeburn 4556: next if ($data eq 'foilorder');
1.31 albertel 4557: pop(@parts);
1.1010 www 4558: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4559: if ($data eq 'type') {
4560: unless ($showsurv) {
4561: my $id = join(',',@parts);
4562: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4563: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4564: $lasthidden{$ign.'.'.$id} = 1;
4565: }
1.945 raeburn 4566: }
1.1199 raeburn 4567: if ($identifier ne '') {
4568: my $id = join(',',@parts);
4569: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4570: $domain,$username,$usec,undef,$course) =~ /^no/) {
4571: $hidestatus{$ign.'.'.$id} = 1;
4572: }
4573: }
4574: } elsif ($data eq 'regrader') {
4575: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4576: my $id = join(',',@parts);
4577: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4578: }
1.1010 www 4579: }
1.31 albertel 4580: } else {
1.41 ng 4581: if ($#parts == 0) {
4582: $prevattempts.='<th>'.$parts[0].'</th>';
4583: } else {
4584: $prevattempts.='<th>'.$ign.'</th>';
4585: }
1.31 albertel 4586: }
1.16 harris41 4587: }
1.596 albertel 4588: $prevattempts.=&end_data_table_header_row();
1.40 ng 4589: if ($getattempt eq '') {
1.1199 raeburn 4590: my (%solved,%resets,%probstatus);
1.1200 raeburn 4591: if (($identifier ne '') && (keys(%regraded) > 0)) {
4592: for ($version=1;$version<=$returnhash{'version'};$version++) {
4593: foreach my $id (keys(%regraded)) {
4594: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4595: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4596: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4597: push(@{$resets{$id}},$version);
1.1199 raeburn 4598: }
4599: }
4600: }
1.1200 raeburn 4601: }
4602: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4603: my (@hidden,@unsolved);
1.945 raeburn 4604: if (%typeparts) {
4605: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4606: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4607: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4608: push(@hidden,$id);
1.1199 raeburn 4609: } elsif ($identifier ne '') {
4610: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4611: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4612: ($hidestatus{$id})) {
1.1200 raeburn 4613: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4614: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4615: push(@{$solved{$id}},$version);
4616: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4617: (ref($solved{$id}) eq 'ARRAY')) {
4618: my $skip;
4619: if (ref($resets{$id}) eq 'ARRAY') {
4620: foreach my $reset (@{$resets{$id}}) {
4621: if ($reset > $solved{$id}[-1]) {
4622: $skip=1;
4623: last;
4624: }
4625: }
4626: }
4627: unless ($skip) {
4628: my ($ign,$partslist) = split(/\./,$id,2);
4629: push(@unsolved,$partslist);
4630: }
4631: }
4632: }
1.945 raeburn 4633: }
4634: }
4635: }
4636: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4637: '<td>'.&mt('Transaction [_1]',$version);
4638: if (@unsolved) {
4639: $prevattempts .= '<span class="LC_nobreak"><label>'.
4640: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4641: &mt('Hide').'</label></span>';
4642: }
4643: $prevattempts .= '</td>';
1.945 raeburn 4644: if (@hidden) {
4645: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4646: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4647: my $hide;
4648: foreach my $id (@hidden) {
4649: if ($key =~ /^\Q$id\E/) {
4650: $hide = 1;
4651: last;
4652: }
4653: }
4654: if ($hide) {
4655: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4656: if (($data eq 'award') || ($data eq 'awarddetail')) {
4657: my $value = &format_previous_attempt_value($key,
4658: $returnhash{$version.':'.$key});
1.1173 kruse 4659: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4660: } else {
4661: $prevattempts.='<td> </td>';
4662: }
4663: } else {
4664: if ($key =~ /\./) {
1.1212 raeburn 4665: my $value = $returnhash{$version.':'.$key};
4666: if ($key =~ /\.rndseed$/) {
4667: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4668: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4669: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4670: }
4671: }
4672: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4673: ' </td>';
1.945 raeburn 4674: } else {
4675: $prevattempts.='<td> </td>';
4676: }
4677: }
4678: }
4679: } else {
4680: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4681: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4682: my $value = $returnhash{$version.':'.$key};
4683: if ($key =~ /\.rndseed$/) {
4684: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4685: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4686: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4687: }
4688: }
4689: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4690: ' </td>';
1.945 raeburn 4691: }
4692: }
4693: $prevattempts.=&end_data_table_row();
1.40 ng 4694: }
1.1 albertel 4695: }
1.945 raeburn 4696: my @currhidden = keys(%lasthidden);
1.596 albertel 4697: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4698: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4699: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4700: if (%typeparts) {
4701: my $hidden;
4702: foreach my $id (@currhidden) {
4703: if ($key =~ /^\Q$id\E/) {
4704: $hidden = 1;
4705: last;
4706: }
4707: }
4708: if ($hidden) {
4709: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4710: if (($data eq 'award') || ($data eq 'awarddetail')) {
4711: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4712: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4713: $value = &$gradesub($value);
4714: }
1.1173 kruse 4715: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4716: } else {
4717: $prevattempts.='<td> </td>';
4718: }
4719: } else {
4720: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4721: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4722: $value = &$gradesub($value);
4723: }
1.1173 kruse 4724: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4725: }
4726: } else {
4727: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4728: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4729: $value = &$gradesub($value);
4730: }
1.1173 kruse 4731: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4732: }
1.16 harris41 4733: }
1.596 albertel 4734: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4735: } else {
1.1305 raeburn 4736: my $msg;
4737: if ($symb =~ /ext\.tool$/) {
4738: $msg = &mt('No grade passed back.');
4739: } else {
4740: $msg = &mt('Nothing submitted - no attempts.');
4741: }
1.596 albertel 4742: $prevattempts=
4743: &start_data_table().&start_data_table_row().
1.1305 raeburn 4744: '<td>'.$msg.'</td>'.
1.596 albertel 4745: &end_data_table_row().&end_data_table();
1.1 albertel 4746: }
4747: } else {
1.596 albertel 4748: $prevattempts=
4749: &start_data_table().&start_data_table_row().
4750: '<td>'.&mt('No data.').'</td>'.
4751: &end_data_table_row().&end_data_table();
1.1 albertel 4752: }
1.10 albertel 4753: }
4754:
1.581 albertel 4755: sub format_previous_attempt_value {
4756: my ($key,$value) = @_;
1.1011 www 4757: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4758: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4759: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4760: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4761: } elsif ($key =~ /answerstring$/) {
4762: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4763: my @answer = %answers;
4764: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4765: my @anskeys = sort(keys(%answers));
4766: if (@anskeys == 1) {
4767: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4768: if ($answer =~ m{\0}) {
4769: $answer =~ s{\0}{,}g;
1.988 raeburn 4770: }
4771: my $tag_internal_answer_name = 'INTERNAL';
4772: if ($anskeys[0] eq $tag_internal_answer_name) {
4773: $value = $answer;
4774: } else {
4775: $value = $anskeys[0].'='.$answer;
4776: }
4777: } else {
4778: foreach my $ans (@anskeys) {
4779: my $answer = $answers{$ans};
1.1001 raeburn 4780: if ($answer =~ m{\0}) {
4781: $answer =~ s{\0}{,}g;
1.988 raeburn 4782: }
4783: $value .= $ans.'='.$answer.'<br />';;
4784: }
4785: }
1.581 albertel 4786: } else {
1.1173 kruse 4787: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4788: }
4789: return $value;
4790: }
4791:
4792:
1.107 albertel 4793: sub relative_to_absolute {
4794: my ($url,$output)=@_;
4795: my $parser=HTML::TokeParser->new(\$output);
4796: my $token;
4797: my $thisdir=$url;
4798: my @rlinks=();
4799: while ($token=$parser->get_token) {
4800: if ($token->[0] eq 'S') {
4801: if ($token->[1] eq 'a') {
4802: if ($token->[2]->{'href'}) {
4803: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4804: }
4805: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4806: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4807: } elsif ($token->[1] eq 'base') {
4808: $thisdir=$token->[2]->{'href'};
4809: }
4810: }
4811: }
4812: $thisdir=~s-/[^/]*$--;
1.356 albertel 4813: foreach my $link (@rlinks) {
1.726 raeburn 4814: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4815: ($link=~/^\//) ||
4816: ($link=~/^javascript:/i) ||
4817: ($link=~/^mailto:/i) ||
4818: ($link=~/^\#/)) {
4819: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4820: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4821: }
4822: }
4823: # -------------------------------------------------- Deal with Applet codebases
4824: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4825: return $output;
4826: }
4827:
1.112 bowersj2 4828: =pod
4829:
1.648 raeburn 4830: =item * &get_student_view()
1.112 bowersj2 4831:
4832: show a snapshot of what student was looking at
4833:
4834: =cut
4835:
1.10 albertel 4836: sub get_student_view {
1.186 albertel 4837: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4838: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4839: my (%form);
1.10 albertel 4840: my @elements=('symb','courseid','domain','username');
4841: foreach my $element (@elements) {
1.186 albertel 4842: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4843: }
1.186 albertel 4844: if (defined($moreenv)) {
4845: %form=(%form,%{$moreenv});
4846: }
1.236 albertel 4847: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4848: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4849: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4850: $feedurl =~ s{^/adm/wrapper}{};
4851: }
1.650 www 4852: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4853: $userview=~s/\<body[^\>]*\>//gi;
4854: $userview=~s/\<\/body\>//gi;
4855: $userview=~s/\<html\>//gi;
4856: $userview=~s/\<\/html\>//gi;
4857: $userview=~s/\<head\>//gi;
4858: $userview=~s/\<\/head\>//gi;
4859: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4860: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4861: if (wantarray) {
4862: return ($userview,$response);
4863: } else {
4864: return $userview;
4865: }
4866: }
4867:
4868: sub get_student_view_with_retries {
4869: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4870:
4871: my $ok = 0; # True if we got a good response.
4872: my $content;
4873: my $response;
4874:
4875: # Try to get the student_view done. within the retries count:
4876:
4877: do {
4878: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4879: $ok = $response->is_success;
4880: if (!$ok) {
4881: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4882: }
4883: $retries--;
4884: } while (!$ok && ($retries > 0));
4885:
4886: if (!$ok) {
4887: $content = ''; # On error return an empty content.
4888: }
1.651 www 4889: if (wantarray) {
4890: return ($content, $response);
4891: } else {
4892: return $content;
4893: }
1.11 albertel 4894: }
4895:
1.112 bowersj2 4896: =pod
4897:
1.648 raeburn 4898: =item * &get_student_answers()
1.112 bowersj2 4899:
4900: show a snapshot of how student was answering problem
4901:
4902: =cut
4903:
1.11 albertel 4904: sub get_student_answers {
1.100 sakharuk 4905: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4906: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4907: my (%moreenv);
1.11 albertel 4908: my @elements=('symb','courseid','domain','username');
4909: foreach my $element (@elements) {
1.186 albertel 4910: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4911: }
1.186 albertel 4912: $moreenv{'grade_target'}='answer';
4913: %moreenv=(%form,%moreenv);
1.497 raeburn 4914: $feedurl = &Apache::lonnet::clutter($feedurl);
4915: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4916: return $userview;
1.1 albertel 4917: }
1.116 albertel 4918:
4919: =pod
4920:
4921: =item * &submlink()
4922:
1.242 albertel 4923: Inputs: $text $uname $udom $symb $target
1.116 albertel 4924:
4925: Returns: A link to grades.pm such as to see the SUBM view of a student
4926:
4927: =cut
4928:
4929: ###############################################
4930: sub submlink {
1.242 albertel 4931: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4932: if (!($uname && $udom)) {
4933: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4934: &Apache::lonnet::whichuser($symb);
1.116 albertel 4935: if (!$symb) { $symb=$cursymb; }
4936: }
1.254 matthew 4937: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4938: $symb=&escape($symb);
1.960 bisitz 4939: if ($target) { $target=" target=\"$target\""; }
4940: return
4941: '<a href="/adm/grades?command=submission'.
4942: '&symb='.$symb.
4943: '&student='.$uname.
4944: '&userdom='.$udom.'"'.
4945: $target.'>'.$text.'</a>';
1.242 albertel 4946: }
4947: ##############################################
4948:
4949: =pod
4950:
4951: =item * &pgrdlink()
4952:
4953: Inputs: $text $uname $udom $symb $target
4954:
4955: Returns: A link to grades.pm such as to see the PGRD view of a student
4956:
4957: =cut
4958:
4959: ###############################################
4960: sub pgrdlink {
4961: my $link=&submlink(@_);
4962: $link=~s/(&command=submission)/$1&showgrading=yes/;
4963: return $link;
4964: }
4965: ##############################################
4966:
4967: =pod
4968:
4969: =item * &pprmlink()
4970:
4971: Inputs: $text $uname $udom $symb $target
4972:
4973: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4974: student and a specific resource
1.242 albertel 4975:
4976: =cut
4977:
4978: ###############################################
4979: sub pprmlink {
4980: my ($text,$uname,$udom,$symb,$target)=@_;
4981: if (!($uname && $udom)) {
4982: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4983: &Apache::lonnet::whichuser($symb);
1.242 albertel 4984: if (!$symb) { $symb=$cursymb; }
4985: }
1.254 matthew 4986: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4987: $symb=&escape($symb);
1.242 albertel 4988: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4989: return '<a href="/adm/parmset?command=set&'.
4990: 'symb='.$symb.'&uname='.$uname.
4991: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4992: }
4993: ##############################################
1.37 matthew 4994:
1.112 bowersj2 4995: =pod
4996:
4997: =back
4998:
4999: =cut
5000:
1.37 matthew 5001: ###############################################
1.51 www 5002:
5003:
5004: sub timehash {
1.687 raeburn 5005: my ($thistime) = @_;
5006: my $timezone = &Apache::lonlocal::gettimezone();
5007: my $dt = DateTime->from_epoch(epoch => $thistime)
5008: ->set_time_zone($timezone);
5009: my $wday = $dt->day_of_week();
5010: if ($wday == 7) { $wday = 0; }
5011: return ( 'second' => $dt->second(),
5012: 'minute' => $dt->minute(),
5013: 'hour' => $dt->hour(),
5014: 'day' => $dt->day_of_month(),
5015: 'month' => $dt->month(),
5016: 'year' => $dt->year(),
5017: 'weekday' => $wday,
5018: 'dayyear' => $dt->day_of_year(),
5019: 'dlsav' => $dt->is_dst() );
1.51 www 5020: }
5021:
1.370 www 5022: sub utc_string {
5023: my ($date)=@_;
1.371 www 5024: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5025: }
5026:
1.51 www 5027: sub maketime {
5028: my %th=@_;
1.687 raeburn 5029: my ($epoch_time,$timezone,$dt);
5030: $timezone = &Apache::lonlocal::gettimezone();
5031: eval {
5032: $dt = DateTime->new( year => $th{'year'},
5033: month => $th{'month'},
5034: day => $th{'day'},
5035: hour => $th{'hour'},
5036: minute => $th{'minute'},
5037: second => $th{'second'},
5038: time_zone => $timezone,
5039: );
5040: };
5041: if (!$@) {
5042: $epoch_time = $dt->epoch;
5043: if ($epoch_time) {
5044: return $epoch_time;
5045: }
5046: }
1.51 www 5047: return POSIX::mktime(
5048: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5049: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5050: }
5051:
5052: #########################################
1.51 www 5053:
5054: sub findallcourses {
1.482 raeburn 5055: my ($roles,$uname,$udom) = @_;
1.355 albertel 5056: my %roles;
5057: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5058: my %courses;
1.51 www 5059: my $now=time;
1.482 raeburn 5060: if (!defined($uname)) {
5061: $uname = $env{'user.name'};
5062: }
5063: if (!defined($udom)) {
5064: $udom = $env{'user.domain'};
5065: }
5066: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5067: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5068: if (!%roles) {
5069: %roles = (
5070: cc => 1,
1.907 raeburn 5071: co => 1,
1.482 raeburn 5072: in => 1,
5073: ep => 1,
5074: ta => 1,
5075: cr => 1,
5076: st => 1,
5077: );
5078: }
5079: foreach my $entry (keys(%roleshash)) {
5080: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5081: if ($trole =~ /^cr/) {
5082: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5083: } else {
5084: next if (!exists($roles{$trole}));
5085: }
5086: if ($tend) {
5087: next if ($tend < $now);
5088: }
5089: if ($tstart) {
5090: next if ($tstart > $now);
5091: }
1.1058 raeburn 5092: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5093: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5094: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5095: if ($secpart eq '') {
5096: ($cnum,$role) = split(/_/,$cnumpart);
5097: $sec = 'none';
1.1058 raeburn 5098: $value .= $cnum.'/';
1.482 raeburn 5099: } else {
5100: $cnum = $cnumpart;
5101: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5102: $value .= $cnum.'/'.$sec;
5103: }
5104: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5105: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5106: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5107: }
5108: } else {
5109: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5110: }
1.482 raeburn 5111: }
5112: } else {
5113: foreach my $key (keys(%env)) {
1.483 albertel 5114: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5115: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5116: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5117: next if ($role eq 'ca' || $role eq 'aa');
5118: next if (%roles && !exists($roles{$role}));
5119: my ($starttime,$endtime)=split(/\./,$env{$key});
5120: my $active=1;
5121: if ($starttime) {
5122: if ($now<$starttime) { $active=0; }
5123: }
5124: if ($endtime) {
5125: if ($now>$endtime) { $active=0; }
5126: }
5127: if ($active) {
1.1058 raeburn 5128: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5129: if ($sec eq '') {
5130: $sec = 'none';
1.1058 raeburn 5131: } else {
5132: $value .= $sec;
5133: }
5134: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5135: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5136: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5137: }
5138: } else {
5139: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5140: }
1.474 raeburn 5141: }
5142: }
1.51 www 5143: }
5144: }
1.474 raeburn 5145: return %courses;
1.51 www 5146: }
1.37 matthew 5147:
1.54 www 5148: ###############################################
1.474 raeburn 5149:
5150: sub blockcheck {
1.1189 raeburn 5151: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5152:
1.1189 raeburn 5153: if (defined($udom) && defined($uname)) {
5154: # If uname and udom are for a course, check for blocks in the course.
5155: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5156: my ($startblock,$endblock,$triggerblock) =
5157: &get_blocks($setters,$activity,$udom,$uname,$url);
5158: return ($startblock,$endblock,$triggerblock);
5159: }
5160: } else {
1.490 raeburn 5161: $udom = $env{'user.domain'};
5162: $uname = $env{'user.name'};
5163: }
5164:
1.502 raeburn 5165: my $startblock = 0;
5166: my $endblock = 0;
1.1062 raeburn 5167: my $triggerblock = '';
1.482 raeburn 5168: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5169:
1.490 raeburn 5170: # If uname is for a user, and activity is course-specific, i.e.,
5171: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5172:
1.490 raeburn 5173: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5174: $activity eq 'groups' || $activity eq 'printout' ||
5175: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5176: ($env{'request.course.id'})) {
1.490 raeburn 5177: foreach my $key (keys(%live_courses)) {
5178: if ($key ne $env{'request.course.id'}) {
5179: delete($live_courses{$key});
5180: }
5181: }
5182: }
5183:
5184: my $otheruser = 0;
5185: my %own_courses;
5186: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5187: # Resource belongs to user other than current user.
5188: $otheruser = 1;
5189: # Gather courses for current user
5190: %own_courses =
5191: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5192: }
5193:
5194: # Gather active course roles - course coordinator, instructor,
5195: # exam proctor, ta, student, or custom role.
1.474 raeburn 5196:
5197: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5198: my ($cdom,$cnum);
5199: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5200: $cdom = $env{'course.'.$course.'.domain'};
5201: $cnum = $env{'course.'.$course.'.num'};
5202: } else {
1.490 raeburn 5203: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5204: }
5205: my $no_ownblock = 0;
5206: my $no_userblock = 0;
1.533 raeburn 5207: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5208: # Check if current user has 'evb' priv for this
5209: if (defined($own_courses{$course})) {
5210: foreach my $sec (keys(%{$own_courses{$course}})) {
5211: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5212: if ($sec ne 'none') {
5213: $checkrole .= '/'.$sec;
5214: }
5215: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5216: $no_ownblock = 1;
5217: last;
5218: }
5219: }
5220: }
5221: # if they have 'evb' priv and are currently not playing student
5222: next if (($no_ownblock) &&
5223: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5224: }
1.474 raeburn 5225: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5226: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5227: if ($sec ne 'none') {
1.482 raeburn 5228: $checkrole .= '/'.$sec;
1.474 raeburn 5229: }
1.490 raeburn 5230: if ($otheruser) {
5231: # Resource belongs to user other than current user.
5232: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5233: my (%allroles,%userroles);
5234: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5235: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5236: my ($trole,$tdom,$tnum,$tsec);
5237: if ($entry =~ /^cr/) {
5238: ($trole,$tdom,$tnum,$tsec) =
5239: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5240: } else {
5241: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5242: }
5243: my ($spec,$area,$trest);
5244: $area = '/'.$tdom.'/'.$tnum;
5245: $trest = $tnum;
5246: if ($tsec ne '') {
5247: $area .= '/'.$tsec;
5248: $trest .= '/'.$tsec;
5249: }
5250: $spec = $trole.'.'.$area;
5251: if ($trole =~ /^cr/) {
5252: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5253: $tdom,$spec,$trest,$area);
5254: } else {
5255: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5256: $tdom,$spec,$trest,$area);
5257: }
5258: }
1.1276 raeburn 5259: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5260: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5261: if ($1) {
5262: $no_userblock = 1;
5263: last;
5264: }
1.486 raeburn 5265: }
5266: }
1.490 raeburn 5267: } else {
5268: # Resource belongs to current user
5269: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5270: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5271: $no_ownblock = 1;
5272: last;
5273: }
1.474 raeburn 5274: }
5275: }
5276: # if they have the evb priv and are currently not playing student
1.482 raeburn 5277: next if (($no_ownblock) &&
1.491 albertel 5278: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5279: next if ($no_userblock);
1.474 raeburn 5280:
1.1303 raeburn 5281: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5282: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5283:
1.1062 raeburn 5284: my ($start,$end,$trigger) =
5285: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5286: if (($start != 0) &&
5287: (($startblock == 0) || ($startblock > $start))) {
5288: $startblock = $start;
1.1062 raeburn 5289: if ($trigger ne '') {
5290: $triggerblock = $trigger;
5291: }
1.502 raeburn 5292: }
5293: if (($end != 0) &&
5294: (($endblock == 0) || ($endblock < $end))) {
5295: $endblock = $end;
1.1062 raeburn 5296: if ($trigger ne '') {
5297: $triggerblock = $trigger;
5298: }
1.502 raeburn 5299: }
1.490 raeburn 5300: }
1.1062 raeburn 5301: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5302: }
5303:
5304: sub get_blocks {
1.1062 raeburn 5305: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5306: my $startblock = 0;
5307: my $endblock = 0;
1.1062 raeburn 5308: my $triggerblock = '';
1.490 raeburn 5309: my $course = $cdom.'_'.$cnum;
5310: $setters->{$course} = {};
5311: $setters->{$course}{'staff'} = [];
5312: $setters->{$course}{'times'} = [];
1.1062 raeburn 5313: $setters->{$course}{'triggers'} = [];
5314: my (@blockers,%triggered);
5315: my $now = time;
5316: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5317: if ($activity eq 'docs') {
5318: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5319: foreach my $block (@blockers) {
5320: if ($block =~ /^firstaccess____(.+)$/) {
5321: my $item = $1;
5322: my $type = 'map';
5323: my $timersymb = $item;
5324: if ($item eq 'course') {
5325: $type = 'course';
5326: } elsif ($item =~ /___\d+___/) {
5327: $type = 'resource';
5328: } else {
5329: $timersymb = &Apache::lonnet::symbread($item);
5330: }
5331: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5332: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5333: $triggered{$block} = {
5334: start => $start,
5335: end => $end,
5336: type => $type,
5337: };
5338: }
5339: }
5340: } else {
5341: foreach my $block (keys(%commblocks)) {
5342: if ($block =~ m/^(\d+)____(\d+)$/) {
5343: my ($start,$end) = ($1,$2);
5344: if ($start <= time && $end >= time) {
5345: if (ref($commblocks{$block}) eq 'HASH') {
5346: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5347: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5348: unless(grep(/^\Q$block\E$/,@blockers)) {
5349: push(@blockers,$block);
5350: }
5351: }
5352: }
5353: }
5354: }
5355: } elsif ($block =~ /^firstaccess____(.+)$/) {
5356: my $item = $1;
5357: my $timersymb = $item;
5358: my $type = 'map';
5359: if ($item eq 'course') {
5360: $type = 'course';
5361: } elsif ($item =~ /___\d+___/) {
5362: $type = 'resource';
5363: } else {
5364: $timersymb = &Apache::lonnet::symbread($item);
5365: }
5366: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5367: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5368: if ($start && $end) {
5369: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5370: if (ref($commblocks{$block}) eq 'HASH') {
5371: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5372: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5373: unless(grep(/^\Q$block\E$/,@blockers)) {
5374: push(@blockers,$block);
5375: $triggered{$block} = {
5376: start => $start,
5377: end => $end,
5378: type => $type,
5379: };
5380: }
5381: }
5382: }
1.1062 raeburn 5383: }
5384: }
1.490 raeburn 5385: }
1.1062 raeburn 5386: }
5387: }
5388: }
5389: foreach my $blocker (@blockers) {
5390: my ($staff_name,$staff_dom,$title,$blocks) =
5391: &parse_block_record($commblocks{$blocker});
5392: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5393: my ($start,$end,$triggertype);
5394: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5395: ($start,$end) = ($1,$2);
5396: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5397: $start = $triggered{$blocker}{'start'};
5398: $end = $triggered{$blocker}{'end'};
5399: $triggertype = $triggered{$blocker}{'type'};
5400: }
5401: if ($start) {
5402: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5403: if ($triggertype) {
5404: push(@{$$setters{$course}{'triggers'}},$triggertype);
5405: } else {
5406: push(@{$$setters{$course}{'triggers'}},0);
5407: }
5408: if ( ($startblock == 0) || ($startblock > $start) ) {
5409: $startblock = $start;
5410: if ($triggertype) {
5411: $triggerblock = $blocker;
1.474 raeburn 5412: }
5413: }
1.1062 raeburn 5414: if ( ($endblock == 0) || ($endblock < $end) ) {
5415: $endblock = $end;
5416: if ($triggertype) {
5417: $triggerblock = $blocker;
5418: }
5419: }
1.474 raeburn 5420: }
5421: }
1.1062 raeburn 5422: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5423: }
5424:
5425: sub parse_block_record {
5426: my ($record) = @_;
5427: my ($setuname,$setudom,$title,$blocks);
5428: if (ref($record) eq 'HASH') {
5429: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5430: $title = &unescape($record->{'event'});
5431: $blocks = $record->{'blocks'};
5432: } else {
5433: my @data = split(/:/,$record,3);
5434: if (scalar(@data) eq 2) {
5435: $title = $data[1];
5436: ($setuname,$setudom) = split(/@/,$data[0]);
5437: } else {
5438: ($setuname,$setudom,$title) = @data;
5439: }
5440: $blocks = { 'com' => 'on' };
5441: }
5442: return ($setuname,$setudom,$title,$blocks);
5443: }
5444:
1.854 kalberla 5445: sub blocking_status {
1.1189 raeburn 5446: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5447: my %setters;
1.890 droeschl 5448:
1.1061 raeburn 5449: # check for active blocking
1.1062 raeburn 5450: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5451: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5452: my $blocked = 0;
5453: if ($startblock && $endblock) {
5454: $blocked = 1;
5455: }
1.890 droeschl 5456:
1.1061 raeburn 5457: # caller just wants to know whether a block is active
5458: if (!wantarray) { return $blocked; }
5459:
5460: # build a link to a popup window containing the details
5461: my $querystring = "?activity=$activity";
5462: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5463: if (($activity eq 'port') || ($activity eq 'passwd')) {
5464: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5465: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5466: } elsif ($activity eq 'docs') {
5467: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5468: }
1.1061 raeburn 5469:
5470: my $output .= <<'END_MYBLOCK';
5471: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5472: var options = "width=" + w + ",height=" + h + ",";
5473: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5474: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5475: var newWin = window.open(url, wdwName, options);
5476: newWin.focus();
5477: }
1.890 droeschl 5478: END_MYBLOCK
1.854 kalberla 5479:
1.1061 raeburn 5480: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5481:
1.1061 raeburn 5482: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5483: my $text = &mt('Communication Blocked');
1.1217 raeburn 5484: my $class = 'LC_comblock';
1.1062 raeburn 5485: if ($activity eq 'docs') {
5486: $text = &mt('Content Access Blocked');
1.1217 raeburn 5487: $class = '';
1.1063 raeburn 5488: } elsif ($activity eq 'printout') {
5489: $text = &mt('Printing Blocked');
1.1232 raeburn 5490: } elsif ($activity eq 'passwd') {
5491: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5492: } elsif ($activity eq 'alert') {
5493: $text = &mt('Checking Critical Messages Blocked');
5494: } elsif ($activity eq 'reinit') {
5495: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5496: }
1.1061 raeburn 5497: $output .= <<"END_BLOCK";
1.1217 raeburn 5498: <div class='$class'>
1.869 kalberla 5499: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5500: title='$text'>
5501: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5502: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5503: title='$text'>$text</a>
1.867 kalberla 5504: </div>
5505:
5506: END_BLOCK
1.474 raeburn 5507:
1.1061 raeburn 5508: return ($blocked, $output);
1.854 kalberla 5509: }
1.490 raeburn 5510:
1.60 matthew 5511: ###############################################
5512:
1.682 raeburn 5513: sub check_ip_acc {
1.1201 raeburn 5514: my ($acc,$clientip)=@_;
1.682 raeburn 5515: &Apache::lonxml::debug("acc is $acc");
5516: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5517: return 1;
5518: }
1.1339 raeburn 5519: my ($ip,$allowed);
5520: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5521: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5522: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5523: } else {
5524: $ip = $ENV{'REMOTE_ADDR'} || $env{'request.host'} || $clientip;
5525: }
1.682 raeburn 5526:
5527: my $name;
1.1219 raeburn 5528: my %access = (
5529: allowfrom => 1,
5530: denyfrom => 0,
5531: );
5532: my @allows;
5533: my @denies;
5534: foreach my $item (split(',',$acc)) {
5535: $item =~ s/^\s*//;
5536: $item =~ s/\s*$//;
5537: my $pattern;
5538: if ($item =~ /^\!(.+)$/) {
5539: push(@denies,$1);
5540: } else {
5541: push(@allows,$item);
5542: }
5543: }
5544: my $numdenies = scalar(@denies);
5545: my $numallows = scalar(@allows);
5546: my $count = 0;
5547: foreach my $pattern (@denies,@allows) {
5548: $count ++;
5549: my $acctype = 'allowfrom';
5550: if ($count <= $numdenies) {
5551: $acctype = 'denyfrom';
5552: }
1.682 raeburn 5553: if ($pattern =~ /\*$/) {
5554: #35.8.*
5555: $pattern=~s/\*//;
1.1219 raeburn 5556: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5557: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5558: #35.8.3.[34-56]
5559: my $low=$2;
5560: my $high=$3;
5561: $pattern=$1;
5562: if ($ip =~ /^\Q$pattern\E/) {
5563: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5564: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5565: }
5566: } elsif ($pattern =~ /^\*/) {
5567: #*.msu.edu
5568: $pattern=~s/\*//;
5569: if (!defined($name)) {
5570: use Socket;
5571: my $netaddr=inet_aton($ip);
5572: ($name)=gethostbyaddr($netaddr,AF_INET);
5573: }
1.1219 raeburn 5574: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5575: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5576: #127.0.0.1
1.1219 raeburn 5577: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5578: } else {
5579: #some.name.com
5580: if (!defined($name)) {
5581: use Socket;
5582: my $netaddr=inet_aton($ip);
5583: ($name)=gethostbyaddr($netaddr,AF_INET);
5584: }
1.1219 raeburn 5585: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5586: }
5587: if ($allowed =~ /^(0|1)$/) { last; }
5588: }
5589: if ($allowed eq '') {
5590: if ($numdenies && !$numallows) {
5591: $allowed = 1;
5592: } else {
5593: $allowed = 0;
1.682 raeburn 5594: }
5595: }
5596: return $allowed;
5597: }
5598:
5599: ###############################################
5600:
1.60 matthew 5601: =pod
5602:
1.112 bowersj2 5603: =head1 Domain Template Functions
5604:
5605: =over 4
5606:
5607: =item * &determinedomain()
1.60 matthew 5608:
5609: Inputs: $domain (usually will be undef)
5610:
1.63 www 5611: Returns: Determines which domain should be used for designs
1.60 matthew 5612:
5613: =cut
1.54 www 5614:
1.60 matthew 5615: ###############################################
1.63 www 5616: sub determinedomain {
5617: my $domain=shift;
1.531 albertel 5618: if (! $domain) {
1.60 matthew 5619: # Determine domain if we have not been given one
1.893 raeburn 5620: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5621: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5622: if ($env{'request.role.domain'}) {
5623: $domain=$env{'request.role.domain'};
1.60 matthew 5624: }
5625: }
1.63 www 5626: return $domain;
5627: }
5628: ###############################################
1.517 raeburn 5629:
1.518 albertel 5630: sub devalidate_domconfig_cache {
5631: my ($udom)=@_;
5632: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5633: }
5634:
5635: # ---------------------- Get domain configuration for a domain
5636: sub get_domainconf {
5637: my ($udom) = @_;
5638: my $cachetime=1800;
5639: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5640: if (defined($cached)) { return %{$result}; }
5641:
5642: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5643: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5644: my (%designhash,%legacy);
1.518 albertel 5645: if (keys(%domconfig) > 0) {
5646: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5647: if (keys(%{$domconfig{'login'}})) {
5648: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5649: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5650: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5651: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5652: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5653: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5654: if ($key eq 'loginvia') {
5655: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5656: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5657: $designhash{$udom.'.login.loginvia'} = $server;
5658: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5659:
5660: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5661: } else {
5662: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5663: }
1.948 raeburn 5664: }
1.1208 raeburn 5665: } elsif ($key eq 'headtag') {
5666: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5667: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5668: }
1.946 raeburn 5669: }
1.1208 raeburn 5670: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5671: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5672: }
1.946 raeburn 5673: }
5674: }
5675: }
5676: } else {
5677: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5678: $designhash{$udom.'.login.'.$key.'_'.$img} =
5679: $domconfig{'login'}{$key}{$img};
5680: }
1.699 raeburn 5681: }
5682: } else {
5683: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5684: }
1.632 raeburn 5685: }
5686: } else {
5687: $legacy{'login'} = 1;
1.518 albertel 5688: }
1.632 raeburn 5689: } else {
5690: $legacy{'login'} = 1;
1.518 albertel 5691: }
5692: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5693: if (keys(%{$domconfig{'rolecolors'}})) {
5694: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5695: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5696: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5697: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5698: }
1.518 albertel 5699: }
5700: }
1.632 raeburn 5701: } else {
5702: $legacy{'rolecolors'} = 1;
1.518 albertel 5703: }
1.632 raeburn 5704: } else {
5705: $legacy{'rolecolors'} = 1;
1.518 albertel 5706: }
1.948 raeburn 5707: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5708: if ($domconfig{'autoenroll'}{'co-owners'}) {
5709: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5710: }
5711: }
1.632 raeburn 5712: if (keys(%legacy) > 0) {
5713: my %legacyhash = &get_legacy_domconf($udom);
5714: foreach my $item (keys(%legacyhash)) {
5715: if ($item =~ /^\Q$udom\E\.login/) {
5716: if ($legacy{'login'}) {
5717: $designhash{$item} = $legacyhash{$item};
5718: }
5719: } else {
5720: if ($legacy{'rolecolors'}) {
5721: $designhash{$item} = $legacyhash{$item};
5722: }
1.518 albertel 5723: }
5724: }
5725: }
1.632 raeburn 5726: } else {
5727: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5728: }
5729: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5730: $cachetime);
5731: return %designhash;
5732: }
5733:
1.632 raeburn 5734: sub get_legacy_domconf {
5735: my ($udom) = @_;
5736: my %legacyhash;
5737: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5738: my $designfile = $designdir.'/'.$udom.'.tab';
5739: if (-e $designfile) {
1.1317 raeburn 5740: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5741: while (my $line = <$fh>) {
5742: next if ($line =~ /^\#/);
5743: chomp($line);
5744: my ($key,$val)=(split(/\=/,$line));
5745: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5746: }
5747: close($fh);
5748: }
5749: }
1.1026 raeburn 5750: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5751: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5752: }
5753: return %legacyhash;
5754: }
5755:
1.63 www 5756: =pod
5757:
1.112 bowersj2 5758: =item * &domainlogo()
1.63 www 5759:
5760: Inputs: $domain (usually will be undef)
5761:
5762: Returns: A link to a domain logo, if the domain logo exists.
5763: If the domain logo does not exist, a description of the domain.
5764:
5765: =cut
1.112 bowersj2 5766:
1.63 www 5767: ###############################################
5768: sub domainlogo {
1.517 raeburn 5769: my $domain = &determinedomain(shift);
1.518 albertel 5770: my %designhash = &get_domainconf($domain);
1.517 raeburn 5771: # See if there is a logo
5772: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5773: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5774: if ($imgsrc =~ m{^/(adm|res)/}) {
5775: if ($imgsrc =~ m{^/res/}) {
5776: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5777: &Apache::lonnet::repcopy($local_name);
5778: }
5779: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5780: }
5781: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5782: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5783: return &Apache::lonnet::domain($domain,'description');
1.59 www 5784: } else {
1.60 matthew 5785: return '';
1.59 www 5786: }
5787: }
1.63 www 5788: ##############################################
5789:
5790: =pod
5791:
1.112 bowersj2 5792: =item * &designparm()
1.63 www 5793:
5794: Inputs: $which parameter; $domain (usually will be undef)
5795:
5796: Returns: value of designparamter $which
5797:
5798: =cut
1.112 bowersj2 5799:
1.397 albertel 5800:
1.400 albertel 5801: ##############################################
1.397 albertel 5802: sub designparm {
5803: my ($which,$domain)=@_;
5804: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5805: return $env{'environment.color.'.$which};
1.96 www 5806: }
1.63 www 5807: $domain=&determinedomain($domain);
1.1016 raeburn 5808: my %domdesign;
5809: unless ($domain eq 'public') {
5810: %domdesign = &get_domainconf($domain);
5811: }
1.520 raeburn 5812: my $output;
1.517 raeburn 5813: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5814: $output = $domdesign{$domain.'.'.$which};
1.63 www 5815: } else {
1.520 raeburn 5816: $output = $defaultdesign{$which};
5817: }
5818: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5819: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5820: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5821: if ($output =~ m{^/res/}) {
5822: my $local_name = &Apache::lonnet::filelocation('',$output);
5823: &Apache::lonnet::repcopy($local_name);
5824: }
1.520 raeburn 5825: $output = &lonhttpdurl($output);
5826: }
1.63 www 5827: }
1.520 raeburn 5828: return $output;
1.63 www 5829: }
1.59 www 5830:
1.822 bisitz 5831: ##############################################
5832: =pod
5833:
1.832 bisitz 5834: =item * &authorspace()
5835:
1.1028 raeburn 5836: Inputs: $url (usually will be undef).
1.832 bisitz 5837:
1.1132 raeburn 5838: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5839: directory being viewed (or for which action is being taken).
5840: If $url is provided, and begins /priv/<domain>/<uname>
5841: the path will be that portion of the $context argument.
5842: Otherwise the path will be for the author space of the current
5843: user when the current role is author, or for that of the
5844: co-author/assistant co-author space when the current role
5845: is co-author or assistant co-author.
1.832 bisitz 5846:
5847: =cut
5848:
5849: sub authorspace {
1.1028 raeburn 5850: my ($url) = @_;
5851: if ($url ne '') {
5852: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5853: return $1;
5854: }
5855: }
1.832 bisitz 5856: my $caname = '';
1.1024 www 5857: my $cadom = '';
1.1028 raeburn 5858: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5859: ($cadom,$caname) =
1.832 bisitz 5860: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5861: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5862: $caname = $env{'user.name'};
1.1024 www 5863: $cadom = $env{'user.domain'};
1.832 bisitz 5864: }
1.1028 raeburn 5865: if (($caname ne '') && ($cadom ne '')) {
5866: return "/priv/$cadom/$caname/";
5867: }
5868: return;
1.832 bisitz 5869: }
5870:
5871: ##############################################
5872: =pod
5873:
1.822 bisitz 5874: =item * &head_subbox()
5875:
5876: Inputs: $content (contains HTML code with page functions, etc.)
5877:
5878: Returns: HTML div with $content
5879: To be included in page header
5880:
5881: =cut
5882:
5883: sub head_subbox {
5884: my ($content)=@_;
5885: my $output =
1.993 raeburn 5886: '<div class="LC_head_subbox">'
1.822 bisitz 5887: .$content
5888: .'</div>'
5889: }
5890:
5891: ##############################################
5892: =pod
5893:
5894: =item * &CSTR_pageheader()
5895:
1.1026 raeburn 5896: Input: (optional) filename from which breadcrumb trail is built.
5897: In most cases no input as needed, as $env{'request.filename'}
5898: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5899:
5900: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5901: To be included on Authoring Space pages
1.822 bisitz 5902:
5903: =cut
5904:
5905: sub CSTR_pageheader {
1.1026 raeburn 5906: my ($trailfile) = @_;
5907: if ($trailfile eq '') {
5908: $trailfile = $env{'request.filename'};
5909: }
5910:
5911: # this is for resources; directories have customtitle, and crumbs
5912: # and select recent are created in lonpubdir.pm
5913:
5914: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5915: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5916: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5917: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5918: $formaction =~ s{/+}{/}g;
1.822 bisitz 5919:
5920: my $parentpath = '';
5921: my $lastitem = '';
5922: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5923: $parentpath = $1;
5924: $lastitem = $2;
5925: } else {
5926: $lastitem = $thisdisfn;
5927: }
1.921 bisitz 5928:
1.1246 raeburn 5929: my ($crsauthor,$title);
5930: if (($env{'request.course.id'}) &&
5931: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5932: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5933: $crsauthor = 1;
5934: $title = &mt('Course Authoring Space');
5935: } else {
5936: $title = &mt('Authoring Space');
5937: }
5938:
1.1314 raeburn 5939: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5940: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5941: $target = '';
5942: $crumbtarget = '';
1.1313 raeburn 5943: }
5944:
1.921 bisitz 5945: my $output =
1.822 bisitz 5946: '<div>'
5947: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5948: .'<b>'.$title.'</b> '
1.1314 raeburn 5949: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5950: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5951:
5952: if ($lastitem) {
5953: $output .=
5954: '<span class="LC_filename">'
5955: .$lastitem
5956: .'</span>';
5957: }
1.1245 raeburn 5958:
1.1246 raeburn 5959: if ($crsauthor) {
5960: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5961: } else {
5962: $output .=
5963: '<br />'
1.1314 raeburn 5964: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5965: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5966: .'</form>'
5967: .&Apache::lonmenu::constspaceform();
5968: }
5969: $output .= '</div>';
1.921 bisitz 5970:
5971: return $output;
1.822 bisitz 5972: }
5973:
1.60 matthew 5974: ###############################################
5975: ###############################################
5976:
5977: =pod
5978:
1.112 bowersj2 5979: =back
5980:
1.549 albertel 5981: =head1 HTML Helpers
1.112 bowersj2 5982:
5983: =over 4
5984:
5985: =item * &bodytag()
1.60 matthew 5986:
5987: Returns a uniform header for LON-CAPA web pages.
5988:
5989: Inputs:
5990:
1.112 bowersj2 5991: =over 4
5992:
5993: =item * $title, A title to be displayed on the page.
5994:
5995: =item * $function, the current role (can be undef).
5996:
5997: =item * $addentries, extra parameters for the <body> tag.
5998:
5999: =item * $bodyonly, if defined, only return the <body> tag.
6000:
6001: =item * $domain, if defined, force a given domain.
6002:
6003: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6004: text interface only)
1.60 matthew 6005:
1.814 bisitz 6006: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6007: navigational links
1.317 albertel 6008:
1.338 albertel 6009: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6010:
1.460 albertel 6011: =item * $args, optional argument valid values are
6012: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6013: use_absolute -> for external resource or syllabus, this will
6014: contain https://<hostname> if server uses
6015: https (as per hosts.tab), but request is for http
6016: hostname -> hostname, from $r->hostname().
1.460 albertel 6017:
1.1096 raeburn 6018: =item * $advtoolsref, optional argument, ref to an array containing
6019: inlineremote items to be added in "Functions" menu below
6020: breadcrumbs.
6021:
1.1316 raeburn 6022: =item * $ltiscope, optional argument, will be one of: resource, map or
6023: course, if LON-CAPA is in LTI Provider context. Value is
6024: the scope of use, i.e., launch was for access to a single, a map
6025: or the entire course.
6026:
6027: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6028: context, this will contain the URL for the landing item in
6029: the course, after launch from an LTI Consumer
6030:
1.1318 raeburn 6031: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6032: context, this will contain a reference to hash of items
6033: to be included in the page header and/or inline menu.
6034:
1.112 bowersj2 6035: =back
6036:
1.60 matthew 6037: Returns: A uniform header for LON-CAPA web pages.
6038: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6039: If $bodyonly is undef or zero, an html string containing a <body> tag and
6040: other decorations will be returned.
6041:
6042: =cut
6043:
1.54 www 6044: sub bodytag {
1.831 bisitz 6045: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 6046: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 6047:
1.954 raeburn 6048: my $public;
6049: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6050: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6051: $public = 1;
6052: }
1.460 albertel 6053: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6054: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6055: my $hostname = $args->{'hostname'};
1.339 albertel 6056:
1.183 matthew 6057: $function = &get_users_function() if (!$function);
1.339 albertel 6058: my $img = &designparm($function.'.img',$domain);
6059: my $font = &designparm($function.'.font',$domain);
6060: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6061:
1.803 bisitz 6062: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6063: 'bgcolor' => $pgbg,
1.339 albertel 6064: 'text' => $font,
6065: 'alink' => &designparm($function.'.alink',$domain),
6066: 'vlink' => &designparm($function.'.vlink',$domain),
6067: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6068: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6069:
1.63 www 6070: # role and realm
1.1178 raeburn 6071: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6072: if ($realm) {
6073: $realm = '/'.$realm;
6074: }
1.378 raeburn 6075: if ($role eq 'ca') {
1.479 albertel 6076: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6077: $realm = &plainname($rname,$rdom);
1.378 raeburn 6078: }
1.55 www 6079: # realm
1.258 albertel 6080: if ($env{'request.course.id'}) {
1.378 raeburn 6081: if ($env{'request.role'} !~ /^cr/) {
6082: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6083: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6084: if ($env{'request.role.desc'}) {
6085: $role = $env{'request.role.desc'};
6086: } else {
6087: $role = &mt('Helpdesk[_1]',' '.$2);
6088: }
1.1257 raeburn 6089: } else {
6090: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6091: }
1.898 raeburn 6092: if ($env{'request.course.sec'}) {
6093: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6094: }
1.359 albertel 6095: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6096: } else {
6097: $role = &Apache::lonnet::plaintext($role);
1.54 www 6098: }
1.433 albertel 6099:
1.359 albertel 6100: if (!$realm) { $realm=' '; }
1.330 albertel 6101:
1.438 albertel 6102: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6103:
1.101 www 6104: # construct main body tag
1.359 albertel 6105: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6106: &Apache::lontexconvert::init_math_support();
1.252 albertel 6107:
1.1131 raeburn 6108: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6109:
1.1130 raeburn 6110: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6111: return $bodytag;
1.1130 raeburn 6112: }
1.359 albertel 6113:
1.954 raeburn 6114: if ($public) {
1.433 albertel 6115: undef($role);
6116: }
1.1318 raeburn 6117:
6118: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6119: if (ref($ltimenu) eq 'HASH') {
6120: unless ($ltimenu->{'role'}) {
6121: undef($role);
6122: }
6123: unless ($ltimenu->{'coursetitle'}) {
6124: $realm=' ';
6125: }
6126: }
6127: }
6128:
1.762 bisitz 6129: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6130: #
6131: # Extra info if you are the DC
6132: my $dc_info = '';
6133: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6134: $env{'course.'.$env{'request.course.id'}.
6135: '.domain'}.'/'})) {
6136: my $cid = $env{'request.course.id'};
1.917 raeburn 6137: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6138: $dc_info =~ s/\s+$//;
1.359 albertel 6139: }
6140:
1.1237 raeburn 6141: my $crstype;
6142: if ($env{'request.course.id'}) {
6143: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6144: } elsif ($args->{'crstype'}) {
6145: $crstype = $args->{'crstype'};
6146: }
6147: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6148: undef($role);
6149: } else {
1.1242 raeburn 6150: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6151: }
1.853 droeschl 6152:
1.903 droeschl 6153: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6154:
6155: # if ($env{'request.state'} eq 'construct') {
6156: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6157: # }
6158:
1.1130 raeburn 6159: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6160: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6161:
1.1318 raeburn 6162: unless ($args->{'no_primary_menu'}) {
6163: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6164:
1.1318 raeburn 6165: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6166: if ($dc_info) {
6167: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6168: }
6169: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6170: <em>$realm</em> $dc_info</div>|;
6171: return $bodytag;
6172: }
1.894 droeschl 6173:
1.1318 raeburn 6174: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6175: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6176: }
1.916 droeschl 6177:
1.1318 raeburn 6178: $bodytag .= $right;
1.852 droeschl 6179:
1.1318 raeburn 6180: if ($dc_info) {
6181: $dc_info = &dc_courseid_toggle($dc_info);
6182: }
6183: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6184: }
1.916 droeschl 6185:
1.1169 raeburn 6186: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6187: if ($args->{'no_secondary_menu'}) {
6188: return $bodytag;
6189: }
1.1169 raeburn 6190: #don't show menus for public users
1.954 raeburn 6191: if (!$public){
1.1318 raeburn 6192: unless ($args->{'no_inline_menu'}) {
6193: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6194: $args->{'no_primary_menu'});
6195: }
1.903 droeschl 6196: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6197: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6198: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6199: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6200: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6201: } elsif ($forcereg) {
6202: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6203: $args->{'group'},
1.1274 raeburn 6204: $args->{'hide_buttons'},
1.1316 raeburn 6205: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6206: } else {
6207: $bodytag .=
6208: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6209: $forcereg,$args->{'group'},
6210: $args->{'bread_crumbs'},
1.1274 raeburn 6211: $advtoolsref,'',$hostname);
1.920 raeburn 6212: }
1.903 droeschl 6213: }else{
6214: # this is to seperate menu from content when there's no secondary
6215: # menu. Especially needed for public accessible ressources.
6216: $bodytag .= '<hr style="clear:both" />';
6217: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6218: }
1.903 droeschl 6219:
1.235 raeburn 6220: return $bodytag;
1.182 matthew 6221: }
6222:
1.917 raeburn 6223: sub dc_courseid_toggle {
6224: my ($dc_info) = @_;
1.980 raeburn 6225: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6226: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6227: &mt('(More ...)').'</a></span>'.
6228: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6229: }
6230:
1.330 albertel 6231: sub make_attr_string {
6232: my ($register,$attr_ref) = @_;
6233:
6234: if ($attr_ref && !ref($attr_ref)) {
6235: die("addentries Must be a hash ref ".
6236: join(':',caller(1))." ".
6237: join(':',caller(0))." ");
6238: }
6239:
6240: if ($register) {
1.339 albertel 6241: my ($on_load,$on_unload);
6242: foreach my $key (keys(%{$attr_ref})) {
6243: if (lc($key) eq 'onload') {
6244: $on_load.=$attr_ref->{$key}.';';
6245: delete($attr_ref->{$key});
6246:
6247: } elsif (lc($key) eq 'onunload') {
6248: $on_unload.=$attr_ref->{$key}.';';
6249: delete($attr_ref->{$key});
6250: }
6251: }
1.953 droeschl 6252: $attr_ref->{'onload'} = $on_load;
6253: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6254: }
1.339 albertel 6255:
1.330 albertel 6256: my $attr_string;
1.1159 raeburn 6257: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6258: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6259: }
6260: return $attr_string;
6261: }
6262:
6263:
1.182 matthew 6264: ###############################################
1.251 albertel 6265: ###############################################
6266:
6267: =pod
6268:
6269: =item * &endbodytag()
6270:
6271: Returns a uniform footer for LON-CAPA web pages.
6272:
1.635 raeburn 6273: Inputs: 1 - optional reference to an args hash
6274: If in the hash, key for noredirectlink has a value which evaluates to true,
6275: a 'Continue' link is not displayed if the page contains an
6276: internal redirect in the <head></head> section,
6277: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6278:
6279: =cut
6280:
6281: sub endbodytag {
1.635 raeburn 6282: my ($args) = @_;
1.1080 raeburn 6283: my $endbodytag;
6284: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6285: $endbodytag='</body>';
6286: }
1.315 albertel 6287: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6288: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6289: $endbodytag=
6290: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6291: &mt('Continue').'</a>'.
6292: $endbodytag;
6293: }
1.315 albertel 6294: }
1.251 albertel 6295: return $endbodytag;
6296: }
6297:
1.352 albertel 6298: =pod
6299:
6300: =item * &standard_css()
6301:
6302: Returns a style sheet
6303:
6304: Inputs: (all optional)
6305: domain -> force to color decorate a page for a specific
6306: domain
6307: function -> force usage of a specific rolish color scheme
6308: bgcolor -> override the default page bgcolor
6309:
6310: =cut
6311:
1.343 albertel 6312: sub standard_css {
1.345 albertel 6313: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6314: $function = &get_users_function() if (!$function);
6315: my $img = &designparm($function.'.img', $domain);
6316: my $tabbg = &designparm($function.'.tabbg', $domain);
6317: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6318: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6319: #second colour for later usage
1.345 albertel 6320: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6321: my $pgbg_or_bgcolor =
6322: $bgcolor ||
1.352 albertel 6323: &designparm($function.'.pgbg', $domain);
1.382 albertel 6324: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6325: my $alink = &designparm($function.'.alink', $domain);
6326: my $vlink = &designparm($function.'.vlink', $domain);
6327: my $link = &designparm($function.'.link', $domain);
6328:
1.602 albertel 6329: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6330: my $mono = 'monospace';
1.850 bisitz 6331: my $data_table_head = $sidebg;
6332: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6333: my $data_table_dark = '#E0E0E0';
1.470 banghart 6334: my $data_table_darker = '#CCCCCC';
1.349 albertel 6335: my $data_table_highlight = '#FFFF00';
1.352 albertel 6336: my $mail_new = '#FFBB77';
6337: my $mail_new_hover = '#DD9955';
6338: my $mail_read = '#BBBB77';
6339: my $mail_read_hover = '#999944';
6340: my $mail_replied = '#AAAA88';
6341: my $mail_replied_hover = '#888855';
6342: my $mail_other = '#99BBBB';
6343: my $mail_other_hover = '#669999';
1.391 albertel 6344: my $table_header = '#DDDDDD';
1.489 raeburn 6345: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6346: my $lg_border_color = '#C8C8C8';
1.952 onken 6347: my $button_hover = '#BF2317';
1.392 albertel 6348:
1.608 albertel 6349: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6350: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6351: : '0 3px 0 4px';
1.448 albertel 6352:
1.523 albertel 6353:
1.343 albertel 6354: return <<END;
1.947 droeschl 6355:
6356: /* needed for iframe to allow 100% height in FF */
6357: body, html {
6358: margin: 0;
6359: padding: 0 0.5%;
6360: height: 99%; /* to avoid scrollbars */
6361: }
6362:
1.795 www 6363: body {
1.911 bisitz 6364: font-family: $sans;
6365: line-height:130%;
6366: font-size:0.83em;
6367: color:$font;
1.795 www 6368: }
6369:
1.959 onken 6370: a:focus,
6371: a:focus img {
1.795 www 6372: color: red;
6373: }
1.698 harmsja 6374:
1.911 bisitz 6375: form, .inline {
6376: display: inline;
1.795 www 6377: }
1.721 harmsja 6378:
1.795 www 6379: .LC_right {
1.911 bisitz 6380: text-align:right;
1.795 www 6381: }
6382:
6383: .LC_middle {
1.911 bisitz 6384: vertical-align:middle;
1.795 www 6385: }
1.721 harmsja 6386:
1.1130 raeburn 6387: .LC_floatleft {
6388: float: left;
6389: }
6390:
6391: .LC_floatright {
6392: float: right;
6393: }
6394:
1.911 bisitz 6395: .LC_400Box {
6396: width:400px;
6397: }
1.721 harmsja 6398:
1.947 droeschl 6399: .LC_iframecontainer {
6400: width: 98%;
6401: margin: 0;
6402: position: fixed;
6403: top: 8.5em;
6404: bottom: 0;
6405: }
6406:
6407: .LC_iframecontainer iframe{
6408: border: none;
6409: width: 100%;
6410: height: 100%;
6411: }
6412:
1.778 bisitz 6413: .LC_filename {
6414: font-family: $mono;
6415: white-space:pre;
1.921 bisitz 6416: font-size: 120%;
1.778 bisitz 6417: }
6418:
6419: .LC_fileicon {
6420: border: none;
6421: height: 1.3em;
6422: vertical-align: text-bottom;
6423: margin-right: 0.3em;
6424: text-decoration:none;
6425: }
6426:
1.1008 www 6427: .LC_setting {
6428: text-decoration:underline;
6429: }
6430:
1.350 albertel 6431: .LC_error {
6432: color: red;
6433: }
1.795 www 6434:
1.1097 bisitz 6435: .LC_warning {
6436: color: darkorange;
6437: }
6438:
1.457 albertel 6439: .LC_diff_removed {
1.733 bisitz 6440: color: red;
1.394 albertel 6441: }
1.532 albertel 6442:
6443: .LC_info,
1.457 albertel 6444: .LC_success,
6445: .LC_diff_added {
1.350 albertel 6446: color: green;
6447: }
1.795 www 6448:
1.802 bisitz 6449: div.LC_confirm_box {
6450: background-color: #FAFAFA;
6451: border: 1px solid $lg_border_color;
6452: margin-right: 0;
6453: padding: 5px;
6454: }
6455:
6456: div.LC_confirm_box .LC_error img,
6457: div.LC_confirm_box .LC_success img {
6458: vertical-align: middle;
6459: }
6460:
1.1242 raeburn 6461: .LC_maxwidth {
6462: max-width: 100%;
6463: height: auto;
6464: }
6465:
1.1243 raeburn 6466: .LC_textsize_mobile {
6467: \@media only screen and (max-device-width: 480px) {
6468: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6469: }
6470: }
6471:
1.440 albertel 6472: .LC_icon {
1.771 droeschl 6473: border: none;
1.790 droeschl 6474: vertical-align: middle;
1.771 droeschl 6475: }
6476:
1.543 albertel 6477: .LC_docs_spacer {
6478: width: 25px;
6479: height: 1px;
1.771 droeschl 6480: border: none;
1.543 albertel 6481: }
1.346 albertel 6482:
1.532 albertel 6483: .LC_internal_info {
1.735 bisitz 6484: color: #999999;
1.532 albertel 6485: }
6486:
1.794 www 6487: .LC_discussion {
1.1050 www 6488: background: $data_table_dark;
1.911 bisitz 6489: border: 1px solid black;
6490: margin: 2px;
1.794 www 6491: }
6492:
6493: .LC_disc_action_left {
1.1050 www 6494: background: $sidebg;
1.911 bisitz 6495: text-align: left;
1.1050 www 6496: padding: 4px;
6497: margin: 2px;
1.794 www 6498: }
6499:
6500: .LC_disc_action_right {
1.1050 www 6501: background: $sidebg;
1.911 bisitz 6502: text-align: right;
1.1050 www 6503: padding: 4px;
6504: margin: 2px;
1.794 www 6505: }
6506:
6507: .LC_disc_new_item {
1.911 bisitz 6508: background: white;
6509: border: 2px solid red;
1.1050 www 6510: margin: 4px;
6511: padding: 4px;
1.794 www 6512: }
6513:
6514: .LC_disc_old_item {
1.911 bisitz 6515: background: white;
1.1050 www 6516: margin: 4px;
6517: padding: 4px;
1.794 www 6518: }
6519:
1.458 albertel 6520: table.LC_pastsubmission {
6521: border: 1px solid black;
6522: margin: 2px;
6523: }
6524:
1.924 bisitz 6525: table#LC_menubuttons {
1.345 albertel 6526: width: 100%;
6527: background: $pgbg;
1.392 albertel 6528: border: 2px;
1.402 albertel 6529: border-collapse: separate;
1.803 bisitz 6530: padding: 0;
1.345 albertel 6531: }
1.392 albertel 6532:
1.801 tempelho 6533: table#LC_title_bar a {
6534: color: $fontmenu;
6535: }
1.836 bisitz 6536:
1.807 droeschl 6537: table#LC_title_bar {
1.819 tempelho 6538: clear: both;
1.836 bisitz 6539: display: none;
1.807 droeschl 6540: }
6541:
1.795 www 6542: table#LC_title_bar,
1.933 droeschl 6543: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6544: table#LC_title_bar.LC_with_remote {
1.359 albertel 6545: width: 100%;
1.392 albertel 6546: border-color: $pgbg;
6547: border-style: solid;
6548: border-width: $border;
1.379 albertel 6549: background: $pgbg;
1.801 tempelho 6550: color: $fontmenu;
1.392 albertel 6551: border-collapse: collapse;
1.803 bisitz 6552: padding: 0;
1.819 tempelho 6553: margin: 0;
1.359 albertel 6554: }
1.795 www 6555:
1.933 droeschl 6556: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6557: margin: 0;
6558: padding: 0;
1.933 droeschl 6559: position: relative;
6560: list-style: none;
1.913 droeschl 6561: }
1.933 droeschl 6562: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6563: display: inline;
6564: }
1.933 droeschl 6565:
6566: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6567: padding: 0;
1.933 droeschl 6568: margin: 0;
6569: float: left;
1.913 droeschl 6570: }
1.933 droeschl 6571: .LC_breadcrumb_tools_tools {
6572: padding: 0;
6573: margin: 0;
1.913 droeschl 6574: float: right;
6575: }
6576:
1.1240 raeburn 6577: .LC_placement_prog {
6578: padding-right: 20px;
6579: font-weight: bold;
6580: font-size: 90%;
6581: }
6582:
1.359 albertel 6583: table#LC_title_bar td {
6584: background: $tabbg;
6585: }
1.795 www 6586:
1.911 bisitz 6587: table#LC_menubuttons img {
1.803 bisitz 6588: border: none;
1.346 albertel 6589: }
1.795 www 6590:
1.842 droeschl 6591: .LC_breadcrumbs_component {
1.911 bisitz 6592: float: right;
6593: margin: 0 1em;
1.357 albertel 6594: }
1.842 droeschl 6595: .LC_breadcrumbs_component img {
1.911 bisitz 6596: vertical-align: middle;
1.777 tempelho 6597: }
1.795 www 6598:
1.1243 raeburn 6599: .LC_breadcrumbs_hoverable {
6600: background: $sidebg;
6601: }
6602:
1.383 albertel 6603: td.LC_table_cell_checkbox {
6604: text-align: center;
6605: }
1.795 www 6606:
6607: .LC_fontsize_small {
1.911 bisitz 6608: font-size: 70%;
1.705 tempelho 6609: }
6610:
1.844 bisitz 6611: #LC_breadcrumbs {
1.911 bisitz 6612: clear:both;
6613: background: $sidebg;
6614: border-bottom: 1px solid $lg_border_color;
6615: line-height: 2.5em;
1.933 droeschl 6616: overflow: hidden;
1.911 bisitz 6617: margin: 0;
6618: padding: 0;
1.995 raeburn 6619: text-align: left;
1.819 tempelho 6620: }
1.862 bisitz 6621:
1.1098 bisitz 6622: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6623: clear:both;
6624: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6625: border: 1px solid $sidebg;
1.1098 bisitz 6626: margin: 0 0 10px 0;
1.966 bisitz 6627: padding: 3px;
1.995 raeburn 6628: text-align: left;
1.822 bisitz 6629: }
6630:
1.795 www 6631: .LC_fontsize_medium {
1.911 bisitz 6632: font-size: 85%;
1.705 tempelho 6633: }
6634:
1.795 www 6635: .LC_fontsize_large {
1.911 bisitz 6636: font-size: 120%;
1.705 tempelho 6637: }
6638:
1.346 albertel 6639: .LC_menubuttons_inline_text {
6640: color: $font;
1.698 harmsja 6641: font-size: 90%;
1.701 harmsja 6642: padding-left:3px;
1.346 albertel 6643: }
6644:
1.934 droeschl 6645: .LC_menubuttons_inline_text img{
6646: vertical-align: middle;
6647: }
6648:
1.1051 www 6649: li.LC_menubuttons_inline_text img {
1.951 onken 6650: cursor:pointer;
1.1002 droeschl 6651: text-decoration: none;
1.951 onken 6652: }
6653:
1.526 www 6654: .LC_menubuttons_link {
6655: text-decoration: none;
6656: }
1.795 www 6657:
1.522 albertel 6658: .LC_menubuttons_category {
1.521 www 6659: color: $font;
1.526 www 6660: background: $pgbg;
1.521 www 6661: font-size: larger;
6662: font-weight: bold;
6663: }
6664:
1.346 albertel 6665: td.LC_menubuttons_text {
1.911 bisitz 6666: color: $font;
1.346 albertel 6667: }
1.706 harmsja 6668:
1.346 albertel 6669: .LC_current_location {
6670: background: $tabbg;
6671: }
1.795 www 6672:
1.1286 raeburn 6673: td.LC_zero_height {
6674: line-height: 0;
6675: cellpadding: 0;
6676: }
6677:
1.938 bisitz 6678: table.LC_data_table {
1.347 albertel 6679: border: 1px solid #000000;
1.402 albertel 6680: border-collapse: separate;
1.426 albertel 6681: border-spacing: 1px;
1.610 albertel 6682: background: $pgbg;
1.347 albertel 6683: }
1.795 www 6684:
1.422 albertel 6685: .LC_data_table_dense {
6686: font-size: small;
6687: }
1.795 www 6688:
1.507 raeburn 6689: table.LC_nested_outer {
6690: border: 1px solid #000000;
1.589 raeburn 6691: border-collapse: collapse;
1.803 bisitz 6692: border-spacing: 0;
1.507 raeburn 6693: width: 100%;
6694: }
1.795 www 6695:
1.879 raeburn 6696: table.LC_innerpickbox,
1.507 raeburn 6697: table.LC_nested {
1.803 bisitz 6698: border: none;
1.589 raeburn 6699: border-collapse: collapse;
1.803 bisitz 6700: border-spacing: 0;
1.507 raeburn 6701: width: 100%;
6702: }
1.795 www 6703:
1.911 bisitz 6704: table.LC_data_table tr th,
6705: table.LC_calendar tr th,
1.879 raeburn 6706: table.LC_prior_tries tr th,
6707: table.LC_innerpickbox tr th {
1.349 albertel 6708: font-weight: bold;
6709: background-color: $data_table_head;
1.801 tempelho 6710: color:$fontmenu;
1.701 harmsja 6711: font-size:90%;
1.347 albertel 6712: }
1.795 www 6713:
1.879 raeburn 6714: table.LC_innerpickbox tr th,
6715: table.LC_innerpickbox tr td {
6716: vertical-align: top;
6717: }
6718:
1.711 raeburn 6719: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6720: background-color: #CCCCCC;
1.711 raeburn 6721: font-weight: bold;
6722: text-align: left;
6723: }
1.795 www 6724:
1.912 bisitz 6725: table.LC_data_table tr.LC_odd_row > td {
6726: background-color: $data_table_light;
6727: padding: 2px;
6728: vertical-align: top;
6729: }
6730:
1.809 bisitz 6731: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6732: background-color: $data_table_light;
1.912 bisitz 6733: vertical-align: top;
6734: }
6735:
6736: table.LC_data_table tr.LC_even_row > td {
6737: background-color: $data_table_dark;
1.425 albertel 6738: padding: 2px;
1.900 bisitz 6739: vertical-align: top;
1.347 albertel 6740: }
1.795 www 6741:
1.809 bisitz 6742: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6743: background-color: $data_table_dark;
1.900 bisitz 6744: vertical-align: top;
1.347 albertel 6745: }
1.795 www 6746:
1.425 albertel 6747: table.LC_data_table tr.LC_data_table_highlight td {
6748: background-color: $data_table_darker;
6749: }
1.795 www 6750:
1.639 raeburn 6751: table.LC_data_table tr td.LC_leftcol_header {
6752: background-color: $data_table_head;
6753: font-weight: bold;
6754: }
1.795 www 6755:
1.451 albertel 6756: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6757: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6758: font-weight: bold;
6759: font-style: italic;
6760: text-align: center;
6761: padding: 8px;
1.347 albertel 6762: }
1.795 www 6763:
1.1114 raeburn 6764: table.LC_data_table tr.LC_empty_row td,
6765: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6766: background-color: $sidebg;
6767: }
6768:
6769: table.LC_nested tr.LC_empty_row td {
6770: background-color: #FFFFFF;
6771: }
6772:
1.890 droeschl 6773: table.LC_caption {
6774: }
6775:
1.507 raeburn 6776: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6777: padding: 4ex
6778: }
1.795 www 6779:
1.507 raeburn 6780: table.LC_nested_outer tr th {
6781: font-weight: bold;
1.801 tempelho 6782: color:$fontmenu;
1.507 raeburn 6783: background-color: $data_table_head;
1.701 harmsja 6784: font-size: small;
1.507 raeburn 6785: border-bottom: 1px solid #000000;
6786: }
1.795 www 6787:
1.507 raeburn 6788: table.LC_nested_outer tr td.LC_subheader {
6789: background-color: $data_table_head;
6790: font-weight: bold;
6791: font-size: small;
6792: border-bottom: 1px solid #000000;
6793: text-align: right;
1.451 albertel 6794: }
1.795 www 6795:
1.507 raeburn 6796: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6797: background-color: #CCCCCC;
1.451 albertel 6798: font-weight: bold;
6799: font-size: small;
1.507 raeburn 6800: text-align: center;
6801: }
1.795 www 6802:
1.589 raeburn 6803: table.LC_nested tr.LC_info_row td.LC_left_item,
6804: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6805: text-align: left;
1.451 albertel 6806: }
1.795 www 6807:
1.507 raeburn 6808: table.LC_nested td {
1.735 bisitz 6809: background-color: #FFFFFF;
1.451 albertel 6810: font-size: small;
1.507 raeburn 6811: }
1.795 www 6812:
1.507 raeburn 6813: table.LC_nested_outer tr th.LC_right_item,
6814: table.LC_nested tr.LC_info_row td.LC_right_item,
6815: table.LC_nested tr.LC_odd_row td.LC_right_item,
6816: table.LC_nested tr td.LC_right_item {
1.451 albertel 6817: text-align: right;
6818: }
6819:
1.507 raeburn 6820: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6821: background-color: #EEEEEE;
1.451 albertel 6822: }
6823:
1.473 raeburn 6824: table.LC_createuser {
6825: }
6826:
6827: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6828: font-size: small;
1.473 raeburn 6829: }
6830:
6831: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6832: background-color: #CCCCCC;
1.473 raeburn 6833: font-weight: bold;
6834: text-align: center;
6835: }
6836:
1.349 albertel 6837: table.LC_calendar {
6838: border: 1px solid #000000;
6839: border-collapse: collapse;
1.917 raeburn 6840: width: 98%;
1.349 albertel 6841: }
1.795 www 6842:
1.349 albertel 6843: table.LC_calendar_pickdate {
6844: font-size: xx-small;
6845: }
1.795 www 6846:
1.349 albertel 6847: table.LC_calendar tr td {
6848: border: 1px solid #000000;
6849: vertical-align: top;
1.917 raeburn 6850: width: 14%;
1.349 albertel 6851: }
1.795 www 6852:
1.349 albertel 6853: table.LC_calendar tr td.LC_calendar_day_empty {
6854: background-color: $data_table_dark;
6855: }
1.795 www 6856:
1.779 bisitz 6857: table.LC_calendar tr td.LC_calendar_day_current {
6858: background-color: $data_table_highlight;
1.777 tempelho 6859: }
1.795 www 6860:
1.938 bisitz 6861: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6862: background-color: $mail_new;
6863: }
1.795 www 6864:
1.938 bisitz 6865: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6866: background-color: $mail_new_hover;
6867: }
1.795 www 6868:
1.938 bisitz 6869: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6870: background-color: $mail_read;
6871: }
1.795 www 6872:
1.938 bisitz 6873: /*
6874: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6875: background-color: $mail_read_hover;
6876: }
1.938 bisitz 6877: */
1.795 www 6878:
1.938 bisitz 6879: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6880: background-color: $mail_replied;
6881: }
1.795 www 6882:
1.938 bisitz 6883: /*
6884: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6885: background-color: $mail_replied_hover;
6886: }
1.938 bisitz 6887: */
1.795 www 6888:
1.938 bisitz 6889: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6890: background-color: $mail_other;
6891: }
1.795 www 6892:
1.938 bisitz 6893: /*
6894: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6895: background-color: $mail_other_hover;
6896: }
1.938 bisitz 6897: */
1.494 raeburn 6898:
1.777 tempelho 6899: table.LC_data_table tr > td.LC_browser_file,
6900: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6901: background: #AAEE77;
1.389 albertel 6902: }
1.795 www 6903:
1.777 tempelho 6904: table.LC_data_table tr > td.LC_browser_file_locked,
6905: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6906: background: #FFAA99;
1.387 albertel 6907: }
1.795 www 6908:
1.777 tempelho 6909: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6910: background: #888888;
1.779 bisitz 6911: }
1.795 www 6912:
1.777 tempelho 6913: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6914: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6915: background: #F8F866;
1.777 tempelho 6916: }
1.795 www 6917:
1.696 bisitz 6918: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6919: background: #E0E8FF;
1.387 albertel 6920: }
1.696 bisitz 6921:
1.707 bisitz 6922: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6923: /* background: #77FF77; */
1.707 bisitz 6924: }
1.795 www 6925:
1.707 bisitz 6926: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6927: border-right: 8px solid #FFFF77;
1.707 bisitz 6928: }
1.795 www 6929:
1.707 bisitz 6930: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6931: border-right: 8px solid #FFAA77;
1.707 bisitz 6932: }
1.795 www 6933:
1.707 bisitz 6934: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6935: border-right: 8px solid #FF7777;
1.707 bisitz 6936: }
1.795 www 6937:
1.707 bisitz 6938: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6939: border-right: 8px solid #AAFF77;
1.707 bisitz 6940: }
1.795 www 6941:
1.707 bisitz 6942: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6943: border-right: 8px solid #11CC55;
1.707 bisitz 6944: }
6945:
1.388 albertel 6946: span.LC_current_location {
1.701 harmsja 6947: font-size:larger;
1.388 albertel 6948: background: $pgbg;
6949: }
1.387 albertel 6950:
1.1029 www 6951: span.LC_current_nav_location {
6952: font-weight:bold;
6953: background: $sidebg;
6954: }
6955:
1.395 albertel 6956: span.LC_parm_menu_item {
6957: font-size: larger;
6958: }
1.795 www 6959:
1.395 albertel 6960: span.LC_parm_scope_all {
6961: color: red;
6962: }
1.795 www 6963:
1.395 albertel 6964: span.LC_parm_scope_folder {
6965: color: green;
6966: }
1.795 www 6967:
1.395 albertel 6968: span.LC_parm_scope_resource {
6969: color: orange;
6970: }
1.795 www 6971:
1.395 albertel 6972: span.LC_parm_part {
6973: color: blue;
6974: }
1.795 www 6975:
1.911 bisitz 6976: span.LC_parm_folder,
6977: span.LC_parm_symb {
1.395 albertel 6978: font-size: x-small;
6979: font-family: $mono;
6980: color: #AAAAAA;
6981: }
6982:
1.977 bisitz 6983: ul.LC_parm_parmlist li {
6984: display: inline-block;
6985: padding: 0.3em 0.8em;
6986: vertical-align: top;
6987: width: 150px;
6988: border-top:1px solid $lg_border_color;
6989: }
6990:
1.795 www 6991: td.LC_parm_overview_level_menu,
6992: td.LC_parm_overview_map_menu,
6993: td.LC_parm_overview_parm_selectors,
6994: td.LC_parm_overview_restrictions {
1.396 albertel 6995: border: 1px solid black;
6996: border-collapse: collapse;
6997: }
1.795 www 6998:
1.1285 raeburn 6999: span.LC_parm_recursive,
7000: td.LC_parm_recursive {
7001: font-weight: bold;
7002: font-size: smaller;
7003: }
7004:
1.396 albertel 7005: table.LC_parm_overview_restrictions td {
7006: border-width: 1px 4px 1px 4px;
7007: border-style: solid;
7008: border-color: $pgbg;
7009: text-align: center;
7010: }
1.795 www 7011:
1.396 albertel 7012: table.LC_parm_overview_restrictions th {
7013: background: $tabbg;
7014: border-width: 1px 4px 1px 4px;
7015: border-style: solid;
7016: border-color: $pgbg;
7017: }
1.795 www 7018:
1.398 albertel 7019: table#LC_helpmenu {
1.803 bisitz 7020: border: none;
1.398 albertel 7021: height: 55px;
1.803 bisitz 7022: border-spacing: 0;
1.398 albertel 7023: }
7024:
7025: table#LC_helpmenu fieldset legend {
7026: font-size: larger;
7027: }
1.795 www 7028:
1.397 albertel 7029: table#LC_helpmenu_links {
7030: width: 100%;
7031: border: 1px solid black;
7032: background: $pgbg;
1.803 bisitz 7033: padding: 0;
1.397 albertel 7034: border-spacing: 1px;
7035: }
1.795 www 7036:
1.397 albertel 7037: table#LC_helpmenu_links tr td {
7038: padding: 1px;
7039: background: $tabbg;
1.399 albertel 7040: text-align: center;
7041: font-weight: bold;
1.397 albertel 7042: }
1.396 albertel 7043:
1.795 www 7044: table#LC_helpmenu_links a:link,
7045: table#LC_helpmenu_links a:visited,
1.397 albertel 7046: table#LC_helpmenu_links a:active {
7047: text-decoration: none;
7048: color: $font;
7049: }
1.795 www 7050:
1.397 albertel 7051: table#LC_helpmenu_links a:hover {
7052: text-decoration: underline;
7053: color: $vlink;
7054: }
1.396 albertel 7055:
1.417 albertel 7056: .LC_chrt_popup_exists {
7057: border: 1px solid #339933;
7058: margin: -1px;
7059: }
1.795 www 7060:
1.417 albertel 7061: .LC_chrt_popup_up {
7062: border: 1px solid yellow;
7063: margin: -1px;
7064: }
1.795 www 7065:
1.417 albertel 7066: .LC_chrt_popup {
7067: border: 1px solid #8888FF;
7068: background: #CCCCFF;
7069: }
1.795 www 7070:
1.421 albertel 7071: table.LC_pick_box {
7072: border-collapse: separate;
7073: background: white;
7074: border: 1px solid black;
7075: border-spacing: 1px;
7076: }
1.795 www 7077:
1.421 albertel 7078: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7079: background: $sidebg;
1.421 albertel 7080: font-weight: bold;
1.900 bisitz 7081: text-align: left;
1.740 bisitz 7082: vertical-align: top;
1.421 albertel 7083: width: 184px;
7084: padding: 8px;
7085: }
1.795 www 7086:
1.579 raeburn 7087: table.LC_pick_box td.LC_pick_box_value {
7088: text-align: left;
7089: padding: 8px;
7090: }
1.795 www 7091:
1.579 raeburn 7092: table.LC_pick_box td.LC_pick_box_select {
7093: text-align: left;
7094: padding: 8px;
7095: }
1.795 www 7096:
1.424 albertel 7097: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7098: padding: 0;
1.421 albertel 7099: height: 1px;
7100: background: black;
7101: }
1.795 www 7102:
1.421 albertel 7103: table.LC_pick_box td.LC_pick_box_submit {
7104: text-align: right;
7105: }
1.795 www 7106:
1.579 raeburn 7107: table.LC_pick_box td.LC_evenrow_value {
7108: text-align: left;
7109: padding: 8px;
7110: background-color: $data_table_light;
7111: }
1.795 www 7112:
1.579 raeburn 7113: table.LC_pick_box td.LC_oddrow_value {
7114: text-align: left;
7115: padding: 8px;
7116: background-color: $data_table_light;
7117: }
1.795 www 7118:
1.579 raeburn 7119: span.LC_helpform_receipt_cat {
7120: font-weight: bold;
7121: }
1.795 www 7122:
1.424 albertel 7123: table.LC_group_priv_box {
7124: background: white;
7125: border: 1px solid black;
7126: border-spacing: 1px;
7127: }
1.795 www 7128:
1.424 albertel 7129: table.LC_group_priv_box td.LC_pick_box_title {
7130: background: $tabbg;
7131: font-weight: bold;
7132: text-align: right;
7133: width: 184px;
7134: }
1.795 www 7135:
1.424 albertel 7136: table.LC_group_priv_box td.LC_groups_fixed {
7137: background: $data_table_light;
7138: text-align: center;
7139: }
1.795 www 7140:
1.424 albertel 7141: table.LC_group_priv_box td.LC_groups_optional {
7142: background: $data_table_dark;
7143: text-align: center;
7144: }
1.795 www 7145:
1.424 albertel 7146: table.LC_group_priv_box td.LC_groups_functionality {
7147: background: $data_table_darker;
7148: text-align: center;
7149: font-weight: bold;
7150: }
1.795 www 7151:
1.424 albertel 7152: table.LC_group_priv td {
7153: text-align: left;
1.803 bisitz 7154: padding: 0;
1.424 albertel 7155: }
7156:
7157: .LC_navbuttons {
7158: margin: 2ex 0ex 2ex 0ex;
7159: }
1.795 www 7160:
1.423 albertel 7161: .LC_topic_bar {
7162: font-weight: bold;
7163: background: $tabbg;
1.918 wenzelju 7164: margin: 1em 0em 1em 2em;
1.805 bisitz 7165: padding: 3px;
1.918 wenzelju 7166: font-size: 1.2em;
1.423 albertel 7167: }
1.795 www 7168:
1.423 albertel 7169: .LC_topic_bar span {
1.918 wenzelju 7170: left: 0.5em;
7171: position: absolute;
1.423 albertel 7172: vertical-align: middle;
1.918 wenzelju 7173: font-size: 1.2em;
1.423 albertel 7174: }
1.795 www 7175:
1.423 albertel 7176: table.LC_course_group_status {
7177: margin: 20px;
7178: }
1.795 www 7179:
1.423 albertel 7180: table.LC_status_selector td {
7181: vertical-align: top;
7182: text-align: center;
1.424 albertel 7183: padding: 4px;
7184: }
1.795 www 7185:
1.599 albertel 7186: div.LC_feedback_link {
1.616 albertel 7187: clear: both;
1.829 kalberla 7188: background: $sidebg;
1.779 bisitz 7189: width: 100%;
1.829 kalberla 7190: padding-bottom: 10px;
7191: border: 1px $tabbg solid;
1.833 kalberla 7192: height: 22px;
7193: line-height: 22px;
7194: padding-top: 5px;
7195: }
7196:
7197: div.LC_feedback_link img {
7198: height: 22px;
1.867 kalberla 7199: vertical-align:middle;
1.829 kalberla 7200: }
7201:
1.911 bisitz 7202: div.LC_feedback_link a {
1.829 kalberla 7203: text-decoration: none;
1.489 raeburn 7204: }
1.795 www 7205:
1.867 kalberla 7206: div.LC_comblock {
1.911 bisitz 7207: display:inline;
1.867 kalberla 7208: color:$font;
7209: font-size:90%;
7210: }
7211:
7212: div.LC_feedback_link div.LC_comblock {
7213: padding-left:5px;
7214: }
7215:
7216: div.LC_feedback_link div.LC_comblock a {
7217: color:$font;
7218: }
7219:
1.489 raeburn 7220: span.LC_feedback_link {
1.858 bisitz 7221: /* background: $feedback_link_bg; */
1.599 albertel 7222: font-size: larger;
7223: }
1.795 www 7224:
1.599 albertel 7225: span.LC_message_link {
1.858 bisitz 7226: /* background: $feedback_link_bg; */
1.599 albertel 7227: font-size: larger;
7228: position: absolute;
7229: right: 1em;
1.489 raeburn 7230: }
1.421 albertel 7231:
1.515 albertel 7232: table.LC_prior_tries {
1.524 albertel 7233: border: 1px solid #000000;
7234: border-collapse: separate;
7235: border-spacing: 1px;
1.515 albertel 7236: }
1.523 albertel 7237:
1.515 albertel 7238: table.LC_prior_tries td {
1.524 albertel 7239: padding: 2px;
1.515 albertel 7240: }
1.523 albertel 7241:
7242: .LC_answer_correct {
1.795 www 7243: background: lightgreen;
7244: color: darkgreen;
7245: padding: 6px;
1.523 albertel 7246: }
1.795 www 7247:
1.523 albertel 7248: .LC_answer_charged_try {
1.797 www 7249: background: #FFAAAA;
1.795 www 7250: color: darkred;
7251: padding: 6px;
1.523 albertel 7252: }
1.795 www 7253:
1.779 bisitz 7254: .LC_answer_not_charged_try,
1.523 albertel 7255: .LC_answer_no_grade,
7256: .LC_answer_late {
1.795 www 7257: background: lightyellow;
1.523 albertel 7258: color: black;
1.795 www 7259: padding: 6px;
1.523 albertel 7260: }
1.795 www 7261:
1.523 albertel 7262: .LC_answer_previous {
1.795 www 7263: background: lightblue;
7264: color: darkblue;
7265: padding: 6px;
1.523 albertel 7266: }
1.795 www 7267:
1.779 bisitz 7268: .LC_answer_no_message {
1.777 tempelho 7269: background: #FFFFFF;
7270: color: black;
1.795 www 7271: padding: 6px;
1.779 bisitz 7272: }
1.795 www 7273:
1.1334 raeburn 7274: .LC_answer_unknown,
7275: .LC_answer_warning {
1.779 bisitz 7276: background: orange;
7277: color: black;
1.795 www 7278: padding: 6px;
1.777 tempelho 7279: }
1.795 www 7280:
1.529 albertel 7281: span.LC_prior_numerical,
7282: span.LC_prior_string,
7283: span.LC_prior_custom,
7284: span.LC_prior_reaction,
7285: span.LC_prior_math {
1.925 bisitz 7286: font-family: $mono;
1.523 albertel 7287: white-space: pre;
7288: }
7289:
1.525 albertel 7290: span.LC_prior_string {
1.925 bisitz 7291: font-family: $mono;
1.525 albertel 7292: white-space: pre;
7293: }
7294:
1.523 albertel 7295: table.LC_prior_option {
7296: width: 100%;
7297: border-collapse: collapse;
7298: }
1.795 www 7299:
1.911 bisitz 7300: table.LC_prior_rank,
1.795 www 7301: table.LC_prior_match {
1.528 albertel 7302: border-collapse: collapse;
7303: }
1.795 www 7304:
1.528 albertel 7305: table.LC_prior_option tr td,
7306: table.LC_prior_rank tr td,
7307: table.LC_prior_match tr td {
1.524 albertel 7308: border: 1px solid #000000;
1.515 albertel 7309: }
7310:
1.855 bisitz 7311: .LC_nobreak {
1.544 albertel 7312: white-space: nowrap;
1.519 raeburn 7313: }
7314:
1.576 raeburn 7315: span.LC_cusr_emph {
7316: font-style: italic;
7317: }
7318:
1.633 raeburn 7319: span.LC_cusr_subheading {
7320: font-weight: normal;
7321: font-size: 85%;
7322: }
7323:
1.861 bisitz 7324: div.LC_docs_entry_move {
1.859 bisitz 7325: border: 1px solid #BBBBBB;
1.545 albertel 7326: background: #DDDDDD;
1.861 bisitz 7327: width: 22px;
1.859 bisitz 7328: padding: 1px;
7329: margin: 0;
1.545 albertel 7330: }
7331:
1.861 bisitz 7332: table.LC_data_table tr > td.LC_docs_entry_commands,
7333: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7334: font-size: x-small;
7335: }
1.795 www 7336:
1.861 bisitz 7337: .LC_docs_entry_parameter {
7338: white-space: nowrap;
7339: }
7340:
1.544 albertel 7341: .LC_docs_copy {
1.545 albertel 7342: color: #000099;
1.544 albertel 7343: }
1.795 www 7344:
1.544 albertel 7345: .LC_docs_cut {
1.545 albertel 7346: color: #550044;
1.544 albertel 7347: }
1.795 www 7348:
1.544 albertel 7349: .LC_docs_rename {
1.545 albertel 7350: color: #009900;
1.544 albertel 7351: }
1.795 www 7352:
1.544 albertel 7353: .LC_docs_remove {
1.545 albertel 7354: color: #990000;
7355: }
7356:
1.1284 raeburn 7357: .LC_docs_alias {
7358: color: #440055;
7359: }
7360:
1.1286 raeburn 7361: .LC_domprefs_email,
1.1284 raeburn 7362: .LC_docs_alias_name,
1.547 albertel 7363: .LC_docs_reinit_warn,
7364: .LC_docs_ext_edit {
7365: font-size: x-small;
7366: }
7367:
1.545 albertel 7368: table.LC_docs_adddocs td,
7369: table.LC_docs_adddocs th {
7370: border: 1px solid #BBBBBB;
7371: padding: 4px;
7372: background: #DDDDDD;
1.543 albertel 7373: }
7374:
1.584 albertel 7375: table.LC_sty_begin {
7376: background: #BBFFBB;
7377: }
1.795 www 7378:
1.584 albertel 7379: table.LC_sty_end {
7380: background: #FFBBBB;
7381: }
7382:
1.589 raeburn 7383: table.LC_double_column {
1.803 bisitz 7384: border-width: 0;
1.589 raeburn 7385: border-collapse: collapse;
7386: width: 100%;
7387: padding: 2px;
7388: }
7389:
7390: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7391: top: 2px;
1.589 raeburn 7392: left: 2px;
7393: width: 47%;
7394: vertical-align: top;
7395: }
7396:
7397: table.LC_double_column tr td.LC_right_col {
7398: top: 2px;
1.779 bisitz 7399: right: 2px;
1.589 raeburn 7400: width: 47%;
7401: vertical-align: top;
7402: }
7403:
1.591 raeburn 7404: div.LC_left_float {
7405: float: left;
7406: padding-right: 5%;
1.597 albertel 7407: padding-bottom: 4px;
1.591 raeburn 7408: }
7409:
7410: div.LC_clear_float_header {
1.597 albertel 7411: padding-bottom: 2px;
1.591 raeburn 7412: }
7413:
7414: div.LC_clear_float_footer {
1.597 albertel 7415: padding-top: 10px;
1.591 raeburn 7416: clear: both;
7417: }
7418:
1.597 albertel 7419: div.LC_grade_show_user {
1.941 bisitz 7420: /* border-left: 5px solid $sidebg; */
7421: border-top: 5px solid #000000;
7422: margin: 50px 0 0 0;
1.936 bisitz 7423: padding: 15px 0 5px 10px;
1.597 albertel 7424: }
1.795 www 7425:
1.936 bisitz 7426: div.LC_grade_show_user_odd_row {
1.941 bisitz 7427: /* border-left: 5px solid #000000; */
7428: }
7429:
7430: div.LC_grade_show_user div.LC_Box {
7431: margin-right: 50px;
1.597 albertel 7432: }
7433:
7434: div.LC_grade_submissions,
7435: div.LC_grade_message_center,
1.936 bisitz 7436: div.LC_grade_info_links {
1.597 albertel 7437: margin: 5px;
7438: width: 99%;
7439: background: #FFFFFF;
7440: }
1.795 www 7441:
1.597 albertel 7442: div.LC_grade_submissions_header,
1.936 bisitz 7443: div.LC_grade_message_center_header {
1.705 tempelho 7444: font-weight: bold;
7445: font-size: large;
1.597 albertel 7446: }
1.795 www 7447:
1.597 albertel 7448: div.LC_grade_submissions_body,
1.936 bisitz 7449: div.LC_grade_message_center_body {
1.597 albertel 7450: border: 1px solid black;
7451: width: 99%;
7452: background: #FFFFFF;
7453: }
1.795 www 7454:
1.613 albertel 7455: table.LC_scantron_action {
7456: width: 100%;
7457: }
1.795 www 7458:
1.613 albertel 7459: table.LC_scantron_action tr th {
1.698 harmsja 7460: font-weight:bold;
7461: font-style:normal;
1.613 albertel 7462: }
1.795 www 7463:
1.779 bisitz 7464: .LC_edit_problem_header,
1.614 albertel 7465: div.LC_edit_problem_footer {
1.705 tempelho 7466: font-weight: normal;
7467: font-size: medium;
1.602 albertel 7468: margin: 2px;
1.1060 bisitz 7469: background-color: $sidebg;
1.600 albertel 7470: }
1.795 www 7471:
1.600 albertel 7472: div.LC_edit_problem_header,
1.602 albertel 7473: div.LC_edit_problem_header div,
1.614 albertel 7474: div.LC_edit_problem_footer,
7475: div.LC_edit_problem_footer div,
1.602 albertel 7476: div.LC_edit_problem_editxml_header,
7477: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7478: z-index: 100;
1.600 albertel 7479: }
1.795 www 7480:
1.600 albertel 7481: div.LC_edit_problem_header_title {
1.705 tempelho 7482: font-weight: bold;
7483: font-size: larger;
1.602 albertel 7484: background: $tabbg;
7485: padding: 3px;
1.1060 bisitz 7486: margin: 0 0 5px 0;
1.602 albertel 7487: }
1.795 www 7488:
1.602 albertel 7489: table.LC_edit_problem_header_title {
7490: width: 100%;
1.600 albertel 7491: background: $tabbg;
1.602 albertel 7492: }
7493:
1.1205 golterma 7494: div.LC_edit_actionbar {
7495: background-color: $sidebg;
1.1218 droeschl 7496: margin: 0;
7497: padding: 0;
7498: line-height: 200%;
1.602 albertel 7499: }
1.795 www 7500:
1.1218 droeschl 7501: div.LC_edit_actionbar div{
7502: padding: 0;
7503: margin: 0;
7504: display: inline-block;
1.600 albertel 7505: }
1.795 www 7506:
1.1124 bisitz 7507: .LC_edit_opt {
7508: padding-left: 1em;
7509: white-space: nowrap;
7510: }
7511:
1.1152 golterma 7512: .LC_edit_problem_latexhelper{
7513: text-align: right;
7514: }
7515:
7516: #LC_edit_problem_colorful div{
7517: margin-left: 40px;
7518: }
7519:
1.1205 golterma 7520: #LC_edit_problem_codemirror div{
7521: margin-left: 0px;
7522: }
7523:
1.911 bisitz 7524: img.stift {
1.803 bisitz 7525: border-width: 0;
7526: vertical-align: middle;
1.677 riegler 7527: }
1.680 riegler 7528:
1.923 bisitz 7529: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7530: vertical-align: top;
1.777 tempelho 7531: }
1.795 www 7532:
1.716 raeburn 7533: div.LC_createcourse {
1.911 bisitz 7534: margin: 10px 10px 10px 10px;
1.716 raeburn 7535: }
7536:
1.917 raeburn 7537: .LC_dccid {
1.1130 raeburn 7538: float: right;
1.917 raeburn 7539: margin: 0.2em 0 0 0;
7540: padding: 0;
7541: font-size: 90%;
7542: display:none;
7543: }
7544:
1.897 wenzelju 7545: ol.LC_primary_menu a:hover,
1.721 harmsja 7546: ol#LC_MenuBreadcrumbs a:hover,
7547: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7548: ul#LC_secondary_menu a:hover,
1.721 harmsja 7549: .LC_FormSectionClearButton input:hover
1.795 www 7550: ul.LC_TabContent li:hover a {
1.952 onken 7551: color:$button_hover;
1.911 bisitz 7552: text-decoration:none;
1.693 droeschl 7553: }
7554:
1.779 bisitz 7555: h1 {
1.911 bisitz 7556: padding: 0;
7557: line-height:130%;
1.693 droeschl 7558: }
1.698 harmsja 7559:
1.911 bisitz 7560: h2,
7561: h3,
7562: h4,
7563: h5,
7564: h6 {
7565: margin: 5px 0 5px 0;
7566: padding: 0;
7567: line-height:130%;
1.693 droeschl 7568: }
1.795 www 7569:
7570: .LC_hcell {
1.911 bisitz 7571: padding:3px 15px 3px 15px;
7572: margin: 0;
7573: background-color:$tabbg;
7574: color:$fontmenu;
7575: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7576: }
1.795 www 7577:
1.840 bisitz 7578: .LC_Box > .LC_hcell {
1.911 bisitz 7579: margin: 0 -10px 10px -10px;
1.835 bisitz 7580: }
7581:
1.721 harmsja 7582: .LC_noBorder {
1.911 bisitz 7583: border: 0;
1.698 harmsja 7584: }
1.693 droeschl 7585:
1.721 harmsja 7586: .LC_FormSectionClearButton input {
1.911 bisitz 7587: background-color:transparent;
7588: border: none;
7589: cursor:pointer;
7590: text-decoration:underline;
1.693 droeschl 7591: }
1.763 bisitz 7592:
7593: .LC_help_open_topic {
1.911 bisitz 7594: color: #FFFFFF;
7595: background-color: #EEEEFF;
7596: margin: 1px;
7597: padding: 4px;
7598: border: 1px solid #000033;
7599: white-space: nowrap;
7600: /* vertical-align: middle; */
1.759 neumanie 7601: }
1.693 droeschl 7602:
1.911 bisitz 7603: dl,
7604: ul,
7605: div,
7606: fieldset {
7607: margin: 10px 10px 10px 0;
7608: /* overflow: hidden; */
1.693 droeschl 7609: }
1.795 www 7610:
1.1211 raeburn 7611: article.geogebraweb div {
7612: margin: 0;
7613: }
7614:
1.838 bisitz 7615: fieldset > legend {
1.911 bisitz 7616: font-weight: bold;
7617: padding: 0 5px 0 5px;
1.838 bisitz 7618: }
7619:
1.813 bisitz 7620: #LC_nav_bar {
1.911 bisitz 7621: float: left;
1.995 raeburn 7622: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7623: margin: 0 0 2px 0;
1.807 droeschl 7624: }
7625:
1.916 droeschl 7626: #LC_realm {
7627: margin: 0.2em 0 0 0;
7628: padding: 0;
7629: font-weight: bold;
7630: text-align: center;
1.995 raeburn 7631: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7632: }
7633:
1.911 bisitz 7634: #LC_nav_bar em {
7635: font-weight: bold;
7636: font-style: normal;
1.807 droeschl 7637: }
7638:
1.897 wenzelju 7639: ol.LC_primary_menu {
1.934 droeschl 7640: margin: 0;
1.1076 raeburn 7641: padding: 0;
1.807 droeschl 7642: }
7643:
1.852 droeschl 7644: ol#LC_PathBreadcrumbs {
1.911 bisitz 7645: margin: 0;
1.693 droeschl 7646: }
7647:
1.897 wenzelju 7648: ol.LC_primary_menu li {
1.1076 raeburn 7649: color: RGB(80, 80, 80);
7650: vertical-align: middle;
7651: text-align: left;
7652: list-style: none;
1.1205 golterma 7653: position: relative;
1.1076 raeburn 7654: float: left;
1.1205 golterma 7655: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7656: line-height: 1.5em;
1.1076 raeburn 7657: }
7658:
1.1205 golterma 7659: ol.LC_primary_menu li a,
7660: ol.LC_primary_menu li p {
1.1076 raeburn 7661: display: block;
7662: margin: 0;
7663: padding: 0 5px 0 10px;
7664: text-decoration: none;
7665: }
7666:
1.1205 golterma 7667: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7668: display: inline-block;
7669: width: 95%;
7670: text-align: left;
7671: }
7672:
7673: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7674: display: inline-block;
7675: width: 5%;
7676: float: right;
7677: text-align: right;
7678: font-size: 70%;
7679: }
7680:
7681: ol.LC_primary_menu ul {
1.1076 raeburn 7682: display: none;
1.1205 golterma 7683: width: 15em;
1.1076 raeburn 7684: background-color: $data_table_light;
1.1205 golterma 7685: position: absolute;
7686: top: 100%;
1.1076 raeburn 7687: }
7688:
1.1205 golterma 7689: ol.LC_primary_menu ul ul {
7690: left: 100%;
7691: top: 0;
7692: }
7693:
7694: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7695: display: block;
7696: position: absolute;
7697: margin: 0;
7698: padding: 0;
1.1078 raeburn 7699: z-index: 2;
1.1076 raeburn 7700: }
7701:
7702: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7703: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7704: font-size: 90%;
1.911 bisitz 7705: vertical-align: top;
1.1076 raeburn 7706: float: none;
1.1079 raeburn 7707: border-left: 1px solid black;
7708: border-right: 1px solid black;
1.1205 golterma 7709: /* A dark bottom border to visualize different menu options;
7710: overwritten in the create_submenu routine for the last border-bottom of the menu */
7711: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7712: }
7713:
1.1205 golterma 7714: ol.LC_primary_menu li li p:hover {
7715: color:$button_hover;
7716: text-decoration:none;
7717: background-color:$data_table_dark;
1.1076 raeburn 7718: }
7719:
7720: ol.LC_primary_menu li li a:hover {
7721: color:$button_hover;
7722: background-color:$data_table_dark;
1.693 droeschl 7723: }
7724:
1.1205 golterma 7725: /* Font-size equal to the size of the predecessors*/
7726: ol.LC_primary_menu li:hover li li {
7727: font-size: 100%;
7728: }
7729:
1.897 wenzelju 7730: ol.LC_primary_menu li img {
1.911 bisitz 7731: vertical-align: bottom;
1.934 droeschl 7732: height: 1.1em;
1.1077 raeburn 7733: margin: 0.2em 0 0 0;
1.693 droeschl 7734: }
7735:
1.897 wenzelju 7736: ol.LC_primary_menu a {
1.911 bisitz 7737: color: RGB(80, 80, 80);
7738: text-decoration: none;
1.693 droeschl 7739: }
1.795 www 7740:
1.949 droeschl 7741: ol.LC_primary_menu a.LC_new_message {
7742: font-weight:bold;
7743: color: darkred;
7744: }
7745:
1.975 raeburn 7746: ol.LC_docs_parameters {
7747: margin-left: 0;
7748: padding: 0;
7749: list-style: none;
7750: }
7751:
7752: ol.LC_docs_parameters li {
7753: margin: 0;
7754: padding-right: 20px;
7755: display: inline;
7756: }
7757:
1.976 raeburn 7758: ol.LC_docs_parameters li:before {
7759: content: "\\002022 \\0020";
7760: }
7761:
7762: li.LC_docs_parameters_title {
7763: font-weight: bold;
7764: }
7765:
7766: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7767: content: "";
7768: }
7769:
1.897 wenzelju 7770: ul#LC_secondary_menu {
1.1107 raeburn 7771: clear: right;
1.911 bisitz 7772: color: $fontmenu;
7773: background: $tabbg;
7774: list-style: none;
7775: padding: 0;
7776: margin: 0;
7777: width: 100%;
1.995 raeburn 7778: text-align: left;
1.1107 raeburn 7779: float: left;
1.808 droeschl 7780: }
7781:
1.897 wenzelju 7782: ul#LC_secondary_menu li {
1.911 bisitz 7783: font-weight: bold;
7784: line-height: 1.8em;
1.1107 raeburn 7785: border-right: 1px solid black;
7786: float: left;
7787: }
7788:
7789: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7790: background-color: $data_table_light;
7791: }
7792:
7793: ul#LC_secondary_menu li a {
1.911 bisitz 7794: padding: 0 0.8em;
1.1107 raeburn 7795: }
7796:
7797: ul#LC_secondary_menu li ul {
7798: display: none;
7799: }
7800:
7801: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7802: display: block;
7803: position: absolute;
7804: margin: 0;
7805: padding: 0;
7806: list-style:none;
7807: float: none;
7808: background-color: $data_table_light;
7809: z-index: 2;
7810: margin-left: -1px;
7811: }
7812:
7813: ul#LC_secondary_menu li ul li {
7814: font-size: 90%;
7815: vertical-align: top;
7816: border-left: 1px solid black;
1.911 bisitz 7817: border-right: 1px solid black;
1.1119 raeburn 7818: background-color: $data_table_light;
1.1107 raeburn 7819: list-style:none;
7820: float: none;
7821: }
7822:
7823: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7824: background-color: $data_table_dark;
1.807 droeschl 7825: }
7826:
1.847 tempelho 7827: ul.LC_TabContent {
1.911 bisitz 7828: display:block;
7829: background: $sidebg;
7830: border-bottom: solid 1px $lg_border_color;
7831: list-style:none;
1.1020 raeburn 7832: margin: -1px -10px 0 -10px;
1.911 bisitz 7833: padding: 0;
1.693 droeschl 7834: }
7835:
1.795 www 7836: ul.LC_TabContent li,
7837: ul.LC_TabContentBigger li {
1.911 bisitz 7838: float:left;
1.741 harmsja 7839: }
1.795 www 7840:
1.897 wenzelju 7841: ul#LC_secondary_menu li a {
1.911 bisitz 7842: color: $fontmenu;
7843: text-decoration: none;
1.693 droeschl 7844: }
1.795 www 7845:
1.721 harmsja 7846: ul.LC_TabContent {
1.952 onken 7847: min-height:20px;
1.721 harmsja 7848: }
1.795 www 7849:
7850: ul.LC_TabContent li {
1.911 bisitz 7851: vertical-align:middle;
1.959 onken 7852: padding: 0 16px 0 10px;
1.911 bisitz 7853: background-color:$tabbg;
7854: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7855: border-left: solid 1px $font;
1.721 harmsja 7856: }
1.795 www 7857:
1.847 tempelho 7858: ul.LC_TabContent .right {
1.911 bisitz 7859: float:right;
1.847 tempelho 7860: }
7861:
1.911 bisitz 7862: ul.LC_TabContent li a,
7863: ul.LC_TabContent li {
7864: color:rgb(47,47,47);
7865: text-decoration:none;
7866: font-size:95%;
7867: font-weight:bold;
1.952 onken 7868: min-height:20px;
7869: }
7870:
1.959 onken 7871: ul.LC_TabContent li a:hover,
7872: ul.LC_TabContent li a:focus {
1.952 onken 7873: color: $button_hover;
1.959 onken 7874: background:none;
7875: outline:none;
1.952 onken 7876: }
7877:
7878: ul.LC_TabContent li:hover {
7879: color: $button_hover;
7880: cursor:pointer;
1.721 harmsja 7881: }
1.795 www 7882:
1.911 bisitz 7883: ul.LC_TabContent li.active {
1.952 onken 7884: color: $font;
1.911 bisitz 7885: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7886: border-bottom:solid 1px #FFFFFF;
7887: cursor: default;
1.744 ehlerst 7888: }
1.795 www 7889:
1.959 onken 7890: ul.LC_TabContent li.active a {
7891: color:$font;
7892: background:#FFFFFF;
7893: outline: none;
7894: }
1.1047 raeburn 7895:
7896: ul.LC_TabContent li.goback {
7897: float: left;
7898: border-left: none;
7899: }
7900:
1.870 tempelho 7901: #maincoursedoc {
1.911 bisitz 7902: clear:both;
1.870 tempelho 7903: }
7904:
7905: ul.LC_TabContentBigger {
1.911 bisitz 7906: display:block;
7907: list-style:none;
7908: padding: 0;
1.870 tempelho 7909: }
7910:
1.795 www 7911: ul.LC_TabContentBigger li {
1.911 bisitz 7912: vertical-align:bottom;
7913: height: 30px;
7914: font-size:110%;
7915: font-weight:bold;
7916: color: #737373;
1.841 tempelho 7917: }
7918:
1.957 onken 7919: ul.LC_TabContentBigger li.active {
7920: position: relative;
7921: top: 1px;
7922: }
7923:
1.870 tempelho 7924: ul.LC_TabContentBigger li a {
1.911 bisitz 7925: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7926: height: 30px;
7927: line-height: 30px;
7928: text-align: center;
7929: display: block;
7930: text-decoration: none;
1.958 onken 7931: outline: none;
1.741 harmsja 7932: }
1.795 www 7933:
1.870 tempelho 7934: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7935: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7936: color:$font;
1.744 ehlerst 7937: }
1.795 www 7938:
1.870 tempelho 7939: ul.LC_TabContentBigger li b {
1.911 bisitz 7940: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7941: display: block;
7942: float: left;
7943: padding: 0 30px;
1.957 onken 7944: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7945: }
7946:
1.956 onken 7947: ul.LC_TabContentBigger li:hover b {
7948: color:$button_hover;
7949: }
7950:
1.870 tempelho 7951: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7952: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7953: color:$font;
1.957 onken 7954: border: 0;
1.741 harmsja 7955: }
1.693 droeschl 7956:
1.870 tempelho 7957:
1.862 bisitz 7958: ul.LC_CourseBreadcrumbs {
7959: background: $sidebg;
1.1020 raeburn 7960: height: 2em;
1.862 bisitz 7961: padding-left: 10px;
1.1020 raeburn 7962: margin: 0;
1.862 bisitz 7963: list-style-position: inside;
7964: }
7965:
1.911 bisitz 7966: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7967: ol#LC_PathBreadcrumbs {
1.911 bisitz 7968: padding-left: 10px;
7969: margin: 0;
1.933 droeschl 7970: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7971: }
7972:
1.911 bisitz 7973: ol#LC_MenuBreadcrumbs li,
7974: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7975: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7976: display: inline;
1.933 droeschl 7977: white-space: normal;
1.693 droeschl 7978: }
7979:
1.823 bisitz 7980: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7981: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7982: text-decoration: none;
7983: font-size:90%;
1.693 droeschl 7984: }
1.795 www 7985:
1.969 droeschl 7986: ol#LC_MenuBreadcrumbs h1 {
7987: display: inline;
7988: font-size: 90%;
7989: line-height: 2.5em;
7990: margin: 0;
7991: padding: 0;
7992: }
7993:
1.795 www 7994: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7995: text-decoration:none;
7996: font-size:100%;
7997: font-weight:bold;
1.693 droeschl 7998: }
1.795 www 7999:
1.840 bisitz 8000: .LC_Box {
1.911 bisitz 8001: border: solid 1px $lg_border_color;
8002: padding: 0 10px 10px 10px;
1.746 neumanie 8003: }
1.795 www 8004:
1.1020 raeburn 8005: .LC_DocsBox {
8006: border: solid 1px $lg_border_color;
8007: padding: 0 0 10px 10px;
8008: }
8009:
1.795 www 8010: .LC_AboutMe_Image {
1.911 bisitz 8011: float:left;
8012: margin-right:10px;
1.747 neumanie 8013: }
1.795 www 8014:
8015: .LC_Clear_AboutMe_Image {
1.911 bisitz 8016: clear:left;
1.747 neumanie 8017: }
1.795 www 8018:
1.721 harmsja 8019: dl.LC_ListStyleClean dt {
1.911 bisitz 8020: padding-right: 5px;
8021: display: table-header-group;
1.693 droeschl 8022: }
8023:
1.721 harmsja 8024: dl.LC_ListStyleClean dd {
1.911 bisitz 8025: display: table-row;
1.693 droeschl 8026: }
8027:
1.721 harmsja 8028: .LC_ListStyleClean,
8029: .LC_ListStyleSimple,
8030: .LC_ListStyleNormal,
1.795 www 8031: .LC_ListStyleSpecial {
1.911 bisitz 8032: /* display:block; */
8033: list-style-position: inside;
8034: list-style-type: none;
8035: overflow: hidden;
8036: padding: 0;
1.693 droeschl 8037: }
8038:
1.721 harmsja 8039: .LC_ListStyleSimple li,
8040: .LC_ListStyleSimple dd,
8041: .LC_ListStyleNormal li,
8042: .LC_ListStyleNormal dd,
8043: .LC_ListStyleSpecial li,
1.795 www 8044: .LC_ListStyleSpecial dd {
1.911 bisitz 8045: margin: 0;
8046: padding: 5px 5px 5px 10px;
8047: clear: both;
1.693 droeschl 8048: }
8049:
1.721 harmsja 8050: .LC_ListStyleClean li,
8051: .LC_ListStyleClean dd {
1.911 bisitz 8052: padding-top: 0;
8053: padding-bottom: 0;
1.693 droeschl 8054: }
8055:
1.721 harmsja 8056: .LC_ListStyleSimple dd,
1.795 www 8057: .LC_ListStyleSimple li {
1.911 bisitz 8058: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8059: }
8060:
1.721 harmsja 8061: .LC_ListStyleSpecial li,
8062: .LC_ListStyleSpecial dd {
1.911 bisitz 8063: list-style-type: none;
8064: background-color: RGB(220, 220, 220);
8065: margin-bottom: 4px;
1.693 droeschl 8066: }
8067:
1.721 harmsja 8068: table.LC_SimpleTable {
1.911 bisitz 8069: margin:5px;
8070: border:solid 1px $lg_border_color;
1.795 www 8071: }
1.693 droeschl 8072:
1.721 harmsja 8073: table.LC_SimpleTable tr {
1.911 bisitz 8074: padding: 0;
8075: border:solid 1px $lg_border_color;
1.693 droeschl 8076: }
1.795 www 8077:
8078: table.LC_SimpleTable thead {
1.911 bisitz 8079: background:rgb(220,220,220);
1.693 droeschl 8080: }
8081:
1.721 harmsja 8082: div.LC_columnSection {
1.911 bisitz 8083: display: block;
8084: clear: both;
8085: overflow: hidden;
8086: margin: 0;
1.693 droeschl 8087: }
8088:
1.721 harmsja 8089: div.LC_columnSection>* {
1.911 bisitz 8090: float: left;
8091: margin: 10px 20px 10px 0;
8092: overflow:hidden;
1.693 droeschl 8093: }
1.721 harmsja 8094:
1.795 www 8095: table em {
1.911 bisitz 8096: font-weight: bold;
8097: font-style: normal;
1.748 schulted 8098: }
1.795 www 8099:
1.779 bisitz 8100: table.LC_tableBrowseRes,
1.795 www 8101: table.LC_tableOfContent {
1.911 bisitz 8102: border:none;
8103: border-spacing: 1px;
8104: padding: 3px;
8105: background-color: #FFFFFF;
8106: font-size: 90%;
1.753 droeschl 8107: }
1.789 droeschl 8108:
1.911 bisitz 8109: table.LC_tableOfContent {
8110: border-collapse: collapse;
1.789 droeschl 8111: }
8112:
1.771 droeschl 8113: table.LC_tableBrowseRes a,
1.768 schulted 8114: table.LC_tableOfContent a {
1.911 bisitz 8115: background-color: transparent;
8116: text-decoration: none;
1.753 droeschl 8117: }
8118:
1.795 www 8119: table.LC_tableOfContent img {
1.911 bisitz 8120: border: none;
8121: height: 1.3em;
8122: vertical-align: text-bottom;
8123: margin-right: 0.3em;
1.753 droeschl 8124: }
1.757 schulted 8125:
1.795 www 8126: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8127: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8128: }
8129:
1.795 www 8130: a#LC_content_toolbar_everything {
1.911 bisitz 8131: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8132: }
8133:
1.795 www 8134: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8135: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8136: }
8137:
1.795 www 8138: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8139: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8140: }
8141:
1.795 www 8142: a#LC_content_toolbar_changefolder {
1.911 bisitz 8143: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8144: }
8145:
1.795 www 8146: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8147: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8148: }
8149:
1.1043 raeburn 8150: a#LC_content_toolbar_edittoplevel {
8151: background-image:url(/res/adm/pages/edittoplevel.gif);
8152: }
8153:
1.795 www 8154: ul#LC_toolbar li a:hover {
1.911 bisitz 8155: background-position: bottom center;
1.757 schulted 8156: }
8157:
1.795 www 8158: ul#LC_toolbar {
1.911 bisitz 8159: padding: 0;
8160: margin: 2px;
8161: list-style:none;
8162: position:relative;
8163: background-color:white;
1.1082 raeburn 8164: overflow: auto;
1.757 schulted 8165: }
8166:
1.795 www 8167: ul#LC_toolbar li {
1.911 bisitz 8168: border:1px solid white;
8169: padding: 0;
8170: margin: 0;
8171: float: left;
8172: display:inline;
8173: vertical-align:middle;
1.1082 raeburn 8174: white-space: nowrap;
1.911 bisitz 8175: }
1.757 schulted 8176:
1.783 amueller 8177:
1.795 www 8178: a.LC_toolbarItem {
1.911 bisitz 8179: display:block;
8180: padding: 0;
8181: margin: 0;
8182: height: 32px;
8183: width: 32px;
8184: color:white;
8185: border: none;
8186: background-repeat:no-repeat;
8187: background-color:transparent;
1.757 schulted 8188: }
8189:
1.915 droeschl 8190: ul.LC_funclist {
8191: margin: 0;
8192: padding: 0.5em 1em 0.5em 0;
8193: }
8194:
1.933 droeschl 8195: ul.LC_funclist > li:first-child {
8196: font-weight:bold;
8197: margin-left:0.8em;
8198: }
8199:
1.915 droeschl 8200: ul.LC_funclist + ul.LC_funclist {
8201: /*
8202: left border as a seperator if we have more than
8203: one list
8204: */
8205: border-left: 1px solid $sidebg;
8206: /*
8207: this hides the left border behind the border of the
8208: outer box if element is wrapped to the next 'line'
8209: */
8210: margin-left: -1px;
8211: }
8212:
1.843 bisitz 8213: ul.LC_funclist li {
1.915 droeschl 8214: display: inline;
1.782 bisitz 8215: white-space: nowrap;
1.915 droeschl 8216: margin: 0 0 0 25px;
8217: line-height: 150%;
1.782 bisitz 8218: }
8219:
1.974 wenzelju 8220: .LC_hidden {
8221: display: none;
8222: }
8223:
1.1030 www 8224: .LCmodal-overlay {
8225: position:fixed;
8226: top:0;
8227: right:0;
8228: bottom:0;
8229: left:0;
8230: height:100%;
8231: width:100%;
8232: margin:0;
8233: padding:0;
8234: background:#999;
8235: opacity:.75;
8236: filter: alpha(opacity=75);
8237: -moz-opacity: 0.75;
8238: z-index:101;
8239: }
8240:
8241: * html .LCmodal-overlay {
8242: position: absolute;
8243: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8244: }
8245:
8246: .LCmodal-window {
8247: position:fixed;
8248: top:50%;
8249: left:50%;
8250: margin:0;
8251: padding:0;
8252: z-index:102;
8253: }
8254:
8255: * html .LCmodal-window {
8256: position:absolute;
8257: }
8258:
8259: .LCclose-window {
8260: position:absolute;
8261: width:32px;
8262: height:32px;
8263: right:8px;
8264: top:8px;
8265: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8266: text-indent:-99999px;
8267: overflow:hidden;
8268: cursor:pointer;
8269: }
8270:
1.1335 raeburn 8271: pre.LC_wordwrap {
8272: white-space: pre-wrap;
8273: white-space: -moz-pre-wrap;
8274: white-space: -pre-wrap;
8275: white-space: -o-pre-wrap;
8276: word-wrap: break-word;
8277: }
8278:
1.1100 raeburn 8279: /*
1.1231 damieng 8280: styles used for response display
8281: */
8282: div.LC_radiofoil, div.LC_rankfoil {
8283: margin: .5em 0em .5em 0em;
8284: }
8285: table.LC_itemgroup {
8286: margin-top: 1em;
8287: }
8288:
8289: /*
1.1100 raeburn 8290: styles used by TTH when "Default set of options to pass to tth/m
8291: when converting TeX" in course settings has been set
8292:
8293: option passed: -t
8294:
8295: */
8296:
8297: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8298: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8299: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8300: td div.norm {line-height:normal;}
8301:
8302: /*
8303: option passed -y3
8304: */
8305:
8306: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8307: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8308: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8309:
1.1230 damieng 8310: /*
8311: sections with roles, for content only
8312: */
8313: section[class^="role-"] {
8314: padding-left: 10px;
8315: padding-right: 5px;
8316: margin-top: 8px;
8317: margin-bottom: 8px;
8318: border: 1px solid #2A4;
8319: border-radius: 5px;
8320: box-shadow: 0px 1px 1px #BBB;
8321: }
8322: section[class^="role-"]>h1 {
8323: position: relative;
8324: margin: 0px;
8325: padding-top: 10px;
8326: padding-left: 40px;
8327: }
8328: section[class^="role-"]>h1:before {
8329: position: absolute;
8330: left: -5px;
8331: top: 5px;
8332: }
8333: section.role-activity>h1:before {
8334: content:url('/adm/daxe/images/section_icons/activity.png');
8335: }
8336: section.role-advice>h1:before {
8337: content:url('/adm/daxe/images/section_icons/advice.png');
8338: }
8339: section.role-bibliography>h1:before {
8340: content:url('/adm/daxe/images/section_icons/bibliography.png');
8341: }
8342: section.role-citation>h1:before {
8343: content:url('/adm/daxe/images/section_icons/citation.png');
8344: }
8345: section.role-conclusion>h1:before {
8346: content:url('/adm/daxe/images/section_icons/conclusion.png');
8347: }
8348: section.role-definition>h1:before {
8349: content:url('/adm/daxe/images/section_icons/definition.png');
8350: }
8351: section.role-demonstration>h1:before {
8352: content:url('/adm/daxe/images/section_icons/demonstration.png');
8353: }
8354: section.role-example>h1:before {
8355: content:url('/adm/daxe/images/section_icons/example.png');
8356: }
8357: section.role-explanation>h1:before {
8358: content:url('/adm/daxe/images/section_icons/explanation.png');
8359: }
8360: section.role-introduction>h1:before {
8361: content:url('/adm/daxe/images/section_icons/introduction.png');
8362: }
8363: section.role-method>h1:before {
8364: content:url('/adm/daxe/images/section_icons/method.png');
8365: }
8366: section.role-more_information>h1:before {
8367: content:url('/adm/daxe/images/section_icons/more_information.png');
8368: }
8369: section.role-objectives>h1:before {
8370: content:url('/adm/daxe/images/section_icons/objectives.png');
8371: }
8372: section.role-prerequisites>h1:before {
8373: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8374: }
8375: section.role-remark>h1:before {
8376: content:url('/adm/daxe/images/section_icons/remark.png');
8377: }
8378: section.role-reminder>h1:before {
8379: content:url('/adm/daxe/images/section_icons/reminder.png');
8380: }
8381: section.role-summary>h1:before {
8382: content:url('/adm/daxe/images/section_icons/summary.png');
8383: }
8384: section.role-syntax>h1:before {
8385: content:url('/adm/daxe/images/section_icons/syntax.png');
8386: }
8387: section.role-warning>h1:before {
8388: content:url('/adm/daxe/images/section_icons/warning.png');
8389: }
8390:
1.1269 raeburn 8391: #LC_minitab_header {
8392: float:left;
8393: width:100%;
8394: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8395: font-size:93%;
8396: line-height:normal;
8397: margin: 0.5em 0 0.5em 0;
8398: }
8399: #LC_minitab_header ul {
8400: margin:0;
8401: padding:10px 10px 0;
8402: list-style:none;
8403: }
8404: #LC_minitab_header li {
8405: float:left;
8406: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8407: margin:0;
8408: padding:0 0 0 9px;
8409: }
8410: #LC_minitab_header a {
8411: display:block;
8412: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8413: padding:5px 15px 4px 6px;
8414: }
8415: #LC_minitab_header #LC_current_minitab {
8416: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8417: }
8418: #LC_minitab_header #LC_current_minitab a {
8419: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8420: padding-bottom:5px;
8421: }
8422:
8423:
1.343 albertel 8424: END
8425: }
8426:
1.306 albertel 8427: =pod
8428:
8429: =item * &headtag()
8430:
8431: Returns a uniform footer for LON-CAPA web pages.
8432:
1.307 albertel 8433: Inputs: $title - optional title for the head
8434: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8435: $args - optional arguments
1.319 albertel 8436: force_register - if is true call registerurl so the remote is
8437: informed
1.415 albertel 8438: redirect -> array ref of
8439: 1- seconds before redirect occurs
8440: 2- url to redirect to
8441: 3- whether the side effect should occur
1.315 albertel 8442: (side effect of setting
8443: $env{'internal.head.redirect'} to the url
8444: redirected too)
1.352 albertel 8445: domain -> force to color decorate a page for a specific
8446: domain
8447: function -> force usage of a specific rolish color scheme
8448: bgcolor -> override the default page bgcolor
1.460 albertel 8449: no_auto_mt_title
8450: -> prevent &mt()ing the title arg
1.464 albertel 8451:
1.306 albertel 8452: =cut
8453:
8454: sub headtag {
1.313 albertel 8455: my ($title,$head_extra,$args) = @_;
1.306 albertel 8456:
1.363 albertel 8457: my $function = $args->{'function'} || &get_users_function();
8458: my $domain = $args->{'domain'} || &determinedomain();
8459: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8460: my $httphost = $args->{'use_absolute'};
1.418 albertel 8461: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8462: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8463: #time(),
1.418 albertel 8464: $env{'environment.color.timestamp'},
1.363 albertel 8465: $function,$domain,$bgcolor);
8466:
1.369 www 8467: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8468:
1.308 albertel 8469: my $result =
8470: '<head>'.
1.1160 raeburn 8471: &font_settings($args);
1.319 albertel 8472:
1.1188 raeburn 8473: my $inhibitprint;
8474: if ($args->{'print_suppress'}) {
8475: $inhibitprint = &print_suppression();
8476: }
1.1064 raeburn 8477:
1.461 albertel 8478: if (!$args->{'frameset'}) {
8479: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8480: }
1.962 droeschl 8481: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8482: $result .= Apache::lonxml::display_title();
1.319 albertel 8483: }
1.436 albertel 8484: if (!$args->{'no_nav_bar'}
8485: && !$args->{'only_body'}
8486: && !$args->{'frameset'}) {
1.1154 raeburn 8487: $result .= &help_menu_js($httphost);
1.1032 www 8488: $result.=&modal_window();
1.1038 www 8489: $result.=&togglebox_script();
1.1034 www 8490: $result.=&wishlist_window();
1.1041 www 8491: $result.=&LCprogressbarUpdate_script();
1.1034 www 8492: } else {
8493: if ($args->{'add_modal'}) {
8494: $result.=&modal_window();
8495: }
8496: if ($args->{'add_wishlist'}) {
8497: $result.=&wishlist_window();
8498: }
1.1038 www 8499: if ($args->{'add_togglebox'}) {
8500: $result.=&togglebox_script();
8501: }
1.1041 www 8502: if ($args->{'add_progressbar'}) {
8503: $result.=&LCprogressbarUpdate_script();
8504: }
1.436 albertel 8505: }
1.314 albertel 8506: if (ref($args->{'redirect'})) {
1.414 albertel 8507: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8508: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8509: if (!$inhibit_continue) {
8510: $env{'internal.head.redirect'} = $url;
8511: }
1.313 albertel 8512: $result.=<<ADDMETA
8513: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8514: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8515: ADDMETA
1.1210 raeburn 8516: } else {
8517: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8518: my $requrl = $env{'request.uri'};
8519: if ($requrl eq '') {
8520: $requrl = $ENV{'REQUEST_URI'};
8521: $requrl =~ s/\?.+$//;
8522: }
8523: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8524: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8525: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8526: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8527: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8528: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8529: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8530: my $offload;
1.1210 raeburn 8531: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8532: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8533: $offload = 1;
8534: }
8535: }
8536: unless ($offload) {
8537: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8538: if ($domdefs{'offloadoth'}{$lonhost}) {
8539: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8540: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8541: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8542: $offload = 1;
8543: $dom_in_use = $env{'user.domain'};
8544: }
1.1210 raeburn 8545: }
1.1340 raeburn 8546: }
8547: }
8548: }
8549: if ($offload) {
8550: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8551: if (($newserver) && ($newserver ne $lonhost)) {
8552: my $numsec = 5;
8553: my $timeout = $numsec * 1000;
8554: my ($newurl,$locknum,%locks,$msg);
8555: if ($env{'request.role.adv'}) {
8556: ($locknum,%locks) = &Apache::lonnet::get_locks();
8557: }
8558: my $disable_submit = 0;
8559: if ($requrl =~ /$LONCAPA::assess_re/) {
8560: $disable_submit = 1;
8561: }
8562: if ($locknum) {
8563: my @lockinfo = sort(values(%locks));
8564: $msg = &mt('Once the following tasks are complete: ')."\n".
8565: join(", ",sort(values(%locks)))."\n";
8566: if (&show_course()) {
8567: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8568: } else {
8569: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8570: }
1.1340 raeburn 8571: } else {
8572: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8573: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8574: }
8575: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8576: $newurl = '/adm/switchserver?otherserver='.$newserver;
8577: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8578: $newurl .= '&role='.$env{'request.role'};
8579: }
8580: if ($env{'request.symb'}) {
8581: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8582: if ($shownsymb =~ m{^/enc/}) {
8583: my $reqdmajor = 2;
8584: my $reqdminor = 11;
8585: my $reqdsubminor = 3;
8586: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8587: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8588: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8589: if (($major eq '' && $minor eq '') ||
8590: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8591: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8592: ($reqdsubminor > $subminor))))) {
8593: undef($shownsymb);
8594: }
1.1210 raeburn 8595: }
1.1340 raeburn 8596: if ($shownsymb) {
8597: &js_escape(\$shownsymb);
8598: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8599: }
1.1340 raeburn 8600: } else {
8601: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8602: &js_escape(\$shownurl);
8603: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8604: }
1.1340 raeburn 8605: }
8606: &js_escape(\$msg);
8607: $result.=<<OFFLOAD
1.1210 raeburn 8608: <meta http-equiv="pragma" content="no-cache" />
8609: <script type="text/javascript">
1.1215 raeburn 8610: // <![CDATA[
1.1210 raeburn 8611: function LC_Offload_Now() {
8612: var dest = "$newurl";
8613: if (dest != '') {
8614: window.location.href="$newurl";
8615: }
8616: }
1.1214 raeburn 8617: \$(document).ready(function () {
8618: window.alert('$msg');
8619: if ($disable_submit) {
1.1210 raeburn 8620: \$(".LC_hwk_submit").prop("disabled", true);
8621: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8622: }
8623: setTimeout('LC_Offload_Now()', $timeout);
8624: });
1.1215 raeburn 8625: // ]]>
1.1210 raeburn 8626: </script>
8627: OFFLOAD
8628: }
8629: }
8630: }
8631: }
8632: }
1.313 albertel 8633: }
1.306 albertel 8634: if (!defined($title)) {
8635: $title = 'The LearningOnline Network with CAPA';
8636: }
1.460 albertel 8637: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8638: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8639: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8640: if (!$args->{'frameset'}) {
8641: $result .= ' /';
8642: }
8643: $result .= '>'
1.1064 raeburn 8644: .$inhibitprint
1.414 albertel 8645: .$head_extra;
1.1242 raeburn 8646: my $clientmobile;
8647: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8648: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8649: } else {
8650: $clientmobile = $env{'browser.mobile'};
8651: }
8652: if ($clientmobile) {
1.1137 raeburn 8653: $result .= '
8654: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8655: <meta name="apple-mobile-web-app-capable" content="yes" />';
8656: }
1.1278 raeburn 8657: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8658: return $result.'</head>';
1.306 albertel 8659: }
8660:
8661: =pod
8662:
1.340 albertel 8663: =item * &font_settings()
8664:
8665: Returns neccessary <meta> to set the proper encoding
8666:
1.1160 raeburn 8667: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8668:
8669: =cut
8670:
8671: sub font_settings {
1.1160 raeburn 8672: my ($args) = @_;
1.340 albertel 8673: my $headerstring='';
1.1160 raeburn 8674: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8675: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8676: $headerstring.=
8677: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8678: if (!$args->{'frameset'}) {
8679: $headerstring.= ' /';
8680: }
8681: $headerstring .= '>'."\n";
1.340 albertel 8682: }
8683: return $headerstring;
8684: }
8685:
1.341 albertel 8686: =pod
8687:
1.1064 raeburn 8688: =item * &print_suppression()
8689:
8690: In course context returns css which causes the body to be blank when media="print",
8691: if printout generation is unavailable for the current resource.
8692:
8693: This could be because:
8694:
8695: (a) printstartdate is in the future
8696:
8697: (b) printenddate is in the past
8698:
8699: (c) there is an active exam block with "printout"
8700: functionality blocked
8701:
8702: Users with pav, pfo or evb privileges are exempt.
8703:
8704: Inputs: none
8705:
8706: =cut
8707:
8708:
8709: sub print_suppression {
8710: my $noprint;
8711: if ($env{'request.course.id'}) {
8712: my $scope = $env{'request.course.id'};
8713: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8714: (&Apache::lonnet::allowed('pfo',$scope))) {
8715: return;
8716: }
8717: if ($env{'request.course.sec'} ne '') {
8718: $scope .= "/$env{'request.course.sec'}";
8719: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8720: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8721: return;
1.1064 raeburn 8722: }
8723: }
8724: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8725: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8726: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8727: if ($blocked) {
8728: my $checkrole = "cm./$cdom/$cnum";
8729: if ($env{'request.course.sec'} ne '') {
8730: $checkrole .= "/$env{'request.course.sec'}";
8731: }
8732: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8733: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8734: $noprint = 1;
8735: }
8736: }
8737: unless ($noprint) {
8738: my $symb = &Apache::lonnet::symbread();
8739: if ($symb ne '') {
8740: my $navmap = Apache::lonnavmaps::navmap->new();
8741: if (ref($navmap)) {
8742: my $res = $navmap->getBySymb($symb);
8743: if (ref($res)) {
8744: if (!$res->resprintable()) {
8745: $noprint = 1;
8746: }
8747: }
8748: }
8749: }
8750: }
8751: if ($noprint) {
8752: return <<"ENDSTYLE";
8753: <style type="text/css" media="print">
8754: body { display:none }
8755: </style>
8756: ENDSTYLE
8757: }
8758: }
8759: return;
8760: }
8761:
8762: =pod
8763:
1.341 albertel 8764: =item * &xml_begin()
8765:
8766: Returns the needed doctype and <html>
8767:
8768: Inputs: none
8769:
8770: =cut
8771:
8772: sub xml_begin {
1.1168 raeburn 8773: my ($is_frameset) = @_;
1.341 albertel 8774: my $output='';
8775:
8776: if ($env{'browser.mathml'}) {
8777: $output='<?xml version="1.0"?>'
8778: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8779: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8780:
8781: # .'<!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">] >'
8782: .'<!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">'
8783: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8784: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8785: } elsif ($is_frameset) {
8786: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8787: '<html>'."\n";
1.341 albertel 8788: } else {
1.1168 raeburn 8789: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8790: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8791: }
8792: return $output;
8793: }
1.340 albertel 8794:
8795: =pod
8796:
1.306 albertel 8797: =item * &start_page()
8798:
8799: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8800:
1.648 raeburn 8801: Inputs:
8802:
8803: =over 4
8804:
8805: $title - optional title for the page
8806:
8807: $head_extra - optional extra HTML to incude inside the <head>
8808:
8809: $args - additional optional args supported are:
8810:
8811: =over 8
8812:
8813: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8814: arg on
1.814 bisitz 8815: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8816: add_entries -> additional attributes to add to the <body>
8817: domain -> force to color decorate a page for a
1.317 albertel 8818: specific domain
1.648 raeburn 8819: function -> force usage of a specific rolish color
1.317 albertel 8820: scheme
1.648 raeburn 8821: redirect -> see &headtag()
8822: bgcolor -> override the default page bg color
8823: js_ready -> return a string ready for being used in
1.317 albertel 8824: a javascript writeln
1.648 raeburn 8825: html_encode -> return a string ready for being used in
1.320 albertel 8826: a html attribute
1.648 raeburn 8827: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8828: $forcereg arg
1.648 raeburn 8829: frameset -> if true will start with a <frameset>
1.330 albertel 8830: rather than <body>
1.648 raeburn 8831: skip_phases -> hash ref of
1.338 albertel 8832: head -> skip the <html><head> generation
8833: body -> skip all <body> generation
1.648 raeburn 8834: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8835: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8836: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8837: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8838: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8839: group -> includes the current group, if page is for a
1.1274 raeburn 8840: specific group
8841: use_absolute -> for request for external resource or syllabus, this
8842: will contain https://<hostname> if server uses
8843: https (as per hosts.tab), but request is for http
8844: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8845:
1.648 raeburn 8846: =back
1.460 albertel 8847:
1.648 raeburn 8848: =back
1.562 albertel 8849:
1.306 albertel 8850: =cut
8851:
8852: sub start_page {
1.309 albertel 8853: my ($title,$head_extra,$args) = @_;
1.318 albertel 8854: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8855:
1.315 albertel 8856: $env{'internal.start_page'}++;
1.1318 raeburn 8857: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8858:
1.338 albertel 8859: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8860: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8861: }
1.1316 raeburn 8862:
8863: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8864: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8865: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8866: $args->{'no_primary_menu'} = 1;
8867: }
8868: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8869: $args->{'no_inline_menu'} = 1;
8870: }
8871: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8872: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8873: }
8874: } else {
8875: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8876: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8877: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8878: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8879: $args->{'no_primary_menu'} = 1;
8880: }
8881: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8882: $args->{'no_inline_menu'} = 1;
8883: }
8884: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8885: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8886: }
8887: }
8888: }
1.1316 raeburn 8889: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8890: $env{'course.'.$env{'request.course.id'}.'.domain'},
8891: $env{'course.'.$env{'request.course.id'}.'.num'});
8892: }
1.338 albertel 8893:
8894: if (! exists($args->{'skip_phases'}{'body'}) ) {
8895: if ($args->{'frameset'}) {
8896: my $attr_string = &make_attr_string($args->{'force_register'},
8897: $args->{'add_entries'});
8898: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8899: } else {
8900: $result .=
8901: &bodytag($title,
8902: $args->{'function'}, $args->{'add_entries'},
8903: $args->{'only_body'}, $args->{'domain'},
8904: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8905: $args->{'bgcolor'}, $args,
1.1318 raeburn 8906: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8907: }
1.330 albertel 8908: }
1.338 albertel 8909:
1.315 albertel 8910: if ($args->{'js_ready'}) {
1.713 kaisler 8911: $result = &js_ready($result);
1.315 albertel 8912: }
1.320 albertel 8913: if ($args->{'html_encode'}) {
1.713 kaisler 8914: $result = &html_encode($result);
8915: }
8916:
1.813 bisitz 8917: # Preparation for new and consistent functionlist at top of screen
8918: # if ($args->{'functionlist'}) {
8919: # $result .= &build_functionlist();
8920: #}
8921:
1.964 droeschl 8922: # Don't add anything more if only_body wanted or in const space
8923: return $result if $args->{'only_body'}
8924: || $env{'request.state'} eq 'construct';
1.813 bisitz 8925:
8926: #Breadcrumbs
1.758 kaisler 8927: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8928: &Apache::lonhtmlcommon::clear_breadcrumbs();
8929: #if any br links exists, add them to the breadcrumbs
8930: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8931: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8932: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8933: }
8934: }
1.1096 raeburn 8935: # if @advtools array contains items add then to the breadcrumbs
8936: if (@advtools > 0) {
8937: &Apache::lonmenu::advtools_crumbs(@advtools);
8938: }
1.1272 raeburn 8939: my $menulink;
8940: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8941: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8942: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8943: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8944: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8945: (!$env{'request.role.adv'}))) {
8946: $menulink = 0;
8947: } else {
8948: undef($menulink);
8949: }
1.758 kaisler 8950: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8951: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8952: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8953: } else {
1.1272 raeburn 8954: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8955: }
1.320 albertel 8956: }
1.315 albertel 8957: return $result;
1.306 albertel 8958: }
8959:
8960: sub end_page {
1.315 albertel 8961: my ($args) = @_;
8962: $env{'internal.end_page'}++;
1.330 albertel 8963: my $result;
1.335 albertel 8964: if ($args->{'discussion'}) {
8965: my ($target,$parser);
8966: if (ref($args->{'discussion'})) {
8967: ($target,$parser) =($args->{'discussion'}{'target'},
8968: $args->{'discussion'}{'parser'});
8969: }
8970: $result .= &Apache::lonxml::xmlend($target,$parser);
8971: }
1.330 albertel 8972: if ($args->{'frameset'}) {
8973: $result .= '</frameset>';
8974: } else {
1.635 raeburn 8975: $result .= &endbodytag($args);
1.330 albertel 8976: }
1.1080 raeburn 8977: unless ($args->{'notbody'}) {
8978: $result .= "\n</html>";
8979: }
1.330 albertel 8980:
1.315 albertel 8981: if ($args->{'js_ready'}) {
1.317 albertel 8982: $result = &js_ready($result);
1.315 albertel 8983: }
1.335 albertel 8984:
1.320 albertel 8985: if ($args->{'html_encode'}) {
8986: $result = &html_encode($result);
8987: }
1.335 albertel 8988:
1.315 albertel 8989: return $result;
8990: }
8991:
1.1034 www 8992: sub wishlist_window {
8993: return(<<'ENDWISHLIST');
1.1046 raeburn 8994: <script type="text/javascript">
1.1034 www 8995: // <![CDATA[
8996: // <!-- BEGIN LON-CAPA Internal
8997: function set_wishlistlink(title, path) {
8998: if (!title) {
8999: title = document.title;
9000: title = title.replace(/^LON-CAPA /,'');
9001: }
1.1175 raeburn 9002: title = encodeURIComponent(title);
1.1203 raeburn 9003: title = title.replace("'","\\\'");
1.1034 www 9004: if (!path) {
9005: path = location.pathname;
9006: }
1.1175 raeburn 9007: path = encodeURIComponent(path);
1.1203 raeburn 9008: path = path.replace("'","\\\'");
1.1034 www 9009: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9010: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9011: }
9012: // END LON-CAPA Internal -->
9013: // ]]>
9014: </script>
9015: ENDWISHLIST
9016: }
9017:
1.1030 www 9018: sub modal_window {
9019: return(<<'ENDMODAL');
1.1046 raeburn 9020: <script type="text/javascript">
1.1030 www 9021: // <![CDATA[
9022: // <!-- BEGIN LON-CAPA Internal
9023: var modalWindow = {
9024: parent:"body",
9025: windowId:null,
9026: content:null,
9027: width:null,
9028: height:null,
9029: close:function()
9030: {
9031: $(".LCmodal-window").remove();
9032: $(".LCmodal-overlay").remove();
9033: },
9034: open:function()
9035: {
9036: var modal = "";
9037: modal += "<div class=\"LCmodal-overlay\"></div>";
9038: 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;\">";
9039: modal += this.content;
9040: modal += "</div>";
9041:
9042: $(this.parent).append(modal);
9043:
9044: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9045: $(".LCclose-window").click(function(){modalWindow.close();});
9046: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9047: }
9048: };
1.1140 raeburn 9049: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9050: {
1.1266 raeburn 9051: source = source.replace(/'/g,"'");
1.1030 www 9052: modalWindow.windowId = "myModal";
9053: modalWindow.width = width;
9054: modalWindow.height = height;
1.1196 raeburn 9055: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9056: modalWindow.open();
1.1208 raeburn 9057: };
1.1030 www 9058: // END LON-CAPA Internal -->
9059: // ]]>
9060: </script>
9061: ENDMODAL
9062: }
9063:
9064: sub modal_link {
1.1140 raeburn 9065: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9066: unless ($width) { $width=480; }
9067: unless ($height) { $height=400; }
1.1031 www 9068: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9069: unless ($transparency) { $transparency='true'; }
9070:
1.1074 raeburn 9071: my $target_attr;
9072: if (defined($target)) {
9073: $target_attr = 'target="'.$target.'"';
9074: }
9075: return <<"ENDLINK";
1.1336 raeburn 9076: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9077: ENDLINK
1.1030 www 9078: }
9079:
1.1032 www 9080: sub modal_adhoc_script {
9081: my ($funcname,$width,$height,$content)=@_;
9082: return (<<ENDADHOC);
1.1046 raeburn 9083: <script type="text/javascript">
1.1032 www 9084: // <![CDATA[
9085: var $funcname = function()
9086: {
9087: modalWindow.windowId = "myModal";
9088: modalWindow.width = $width;
9089: modalWindow.height = $height;
9090: modalWindow.content = '$content';
9091: modalWindow.open();
9092: };
9093: // ]]>
9094: </script>
9095: ENDADHOC
9096: }
9097:
1.1041 www 9098: sub modal_adhoc_inner {
9099: my ($funcname,$width,$height,$content)=@_;
9100: my $innerwidth=$width-20;
9101: $content=&js_ready(
1.1140 raeburn 9102: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9103: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9104: $content.
1.1041 www 9105: &end_scrollbox().
1.1140 raeburn 9106: &end_page()
1.1041 www 9107: );
9108: return &modal_adhoc_script($funcname,$width,$height,$content);
9109: }
9110:
9111: sub modal_adhoc_window {
9112: my ($funcname,$width,$height,$content,$linktext)=@_;
9113: return &modal_adhoc_inner($funcname,$width,$height,$content).
9114: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9115: }
9116:
9117: sub modal_adhoc_launch {
9118: my ($funcname,$width,$height,$content)=@_;
9119: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9120: <script type="text/javascript">
9121: // <![CDATA[
9122: $funcname();
9123: // ]]>
9124: </script>
9125: ENDLAUNCH
9126: }
9127:
9128: sub modal_adhoc_close {
9129: return (<<ENDCLOSE);
9130: <script type="text/javascript">
9131: // <![CDATA[
9132: modalWindow.close();
9133: // ]]>
9134: </script>
9135: ENDCLOSE
9136: }
9137:
1.1038 www 9138: sub togglebox_script {
9139: return(<<ENDTOGGLE);
9140: <script type="text/javascript">
9141: // <![CDATA[
9142: function LCtoggleDisplay(id,hidetext,showtext) {
9143: link = document.getElementById(id + "link").childNodes[0];
9144: with (document.getElementById(id).style) {
9145: if (display == "none" ) {
9146: display = "inline";
9147: link.nodeValue = hidetext;
9148: } else {
9149: display = "none";
9150: link.nodeValue = showtext;
9151: }
9152: }
9153: }
9154: // ]]>
9155: </script>
9156: ENDTOGGLE
9157: }
9158:
1.1039 www 9159: sub start_togglebox {
9160: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9161: unless ($heading) { $heading=''; } else { $heading.=' '; }
9162: unless ($showtext) { $showtext=&mt('show'); }
9163: unless ($hidetext) { $hidetext=&mt('hide'); }
9164: unless ($headerbg) { $headerbg='#FFFFFF'; }
9165: return &start_data_table().
9166: &start_data_table_header_row().
9167: '<td bgcolor="'.$headerbg.'">'.$heading.
9168: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9169: $showtext.'\')">'.$showtext.'</a>]</td>'.
9170: &end_data_table_header_row().
9171: '<tr id="'.$id.'" style="display:none""><td>';
9172: }
9173:
9174: sub end_togglebox {
9175: return '</td></tr>'.&end_data_table();
9176: }
9177:
1.1041 www 9178: sub LCprogressbar_script {
1.1302 raeburn 9179: my ($id,$number_to_do)=@_;
9180: if ($number_to_do) {
9181: return(<<ENDPROGRESS);
1.1041 www 9182: <script type="text/javascript">
9183: // <![CDATA[
1.1045 www 9184: \$('#progressbar$id').progressbar({
1.1041 www 9185: value: 0,
9186: change: function(event, ui) {
9187: var newVal = \$(this).progressbar('option', 'value');
9188: \$('.pblabel', this).text(LCprogressTxt);
9189: }
9190: });
9191: // ]]>
9192: </script>
9193: ENDPROGRESS
1.1302 raeburn 9194: } else {
9195: return(<<ENDPROGRESS);
9196: <script type="text/javascript">
9197: // <![CDATA[
9198: \$('#progressbar$id').progressbar({
9199: value: false,
9200: create: function(event, ui) {
9201: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9202: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9203: }
9204: });
9205: // ]]>
9206: </script>
9207: ENDPROGRESS
9208: }
1.1041 www 9209: }
9210:
9211: sub LCprogressbarUpdate_script {
9212: return(<<ENDPROGRESSUPDATE);
9213: <style type="text/css">
9214: .ui-progressbar { position:relative; }
1.1302 raeburn 9215: .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 9216: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9217: </style>
9218: <script type="text/javascript">
9219: // <![CDATA[
1.1045 www 9220: var LCprogressTxt='---';
9221:
1.1302 raeburn 9222: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9223: LCprogressTxt=progresstext;
1.1302 raeburn 9224: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9225: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9226: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9227: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9228: } else {
9229: \$('#progressbar'+id).progressbar('value',percent);
9230: }
1.1041 www 9231: }
9232: // ]]>
9233: </script>
9234: ENDPROGRESSUPDATE
9235: }
9236:
1.1042 www 9237: my $LClastpercent;
1.1045 www 9238: my $LCidcnt;
9239: my $LCcurrentid;
1.1042 www 9240:
1.1041 www 9241: sub LCprogressbar {
1.1302 raeburn 9242: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9243: $LClastpercent=0;
1.1045 www 9244: $LCidcnt++;
9245: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9246: my ($starting,$content);
9247: if ($number_to_do) {
9248: $starting=&mt('Starting');
9249: $content=(<<ENDPROGBAR);
9250: $preamble
1.1045 www 9251: <div id="progressbar$LCcurrentid">
1.1041 www 9252: <span class="pblabel">$starting</span>
9253: </div>
9254: ENDPROGBAR
1.1302 raeburn 9255: } else {
9256: $starting=&mt('Loading...');
9257: $LClastpercent='false';
9258: $content=(<<ENDPROGBAR);
9259: $preamble
9260: <div id="progressbar$LCcurrentid">
9261: <div class="progress-label">$starting</div>
9262: </div>
9263: ENDPROGBAR
9264: }
9265: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9266: }
9267:
9268: sub LCprogressbarUpdate {
1.1302 raeburn 9269: my ($r,$val,$text,$number_to_do)=@_;
9270: if ($number_to_do) {
9271: unless ($val) {
9272: if ($LClastpercent) {
9273: $val=$LClastpercent;
9274: } else {
9275: $val=0;
9276: }
9277: }
9278: if ($val<0) { $val=0; }
9279: if ($val>100) { $val=0; }
9280: $LClastpercent=$val;
9281: unless ($text) { $text=$val.'%'; }
9282: } else {
9283: $val = 'false';
1.1042 www 9284: }
1.1041 www 9285: $text=&js_ready($text);
1.1044 www 9286: &r_print($r,<<ENDUPDATE);
1.1041 www 9287: <script type="text/javascript">
9288: // <![CDATA[
1.1302 raeburn 9289: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9290: // ]]>
9291: </script>
9292: ENDUPDATE
1.1035 www 9293: }
9294:
1.1042 www 9295: sub LCprogressbarClose {
9296: my ($r)=@_;
9297: $LClastpercent=0;
1.1044 www 9298: &r_print($r,<<ENDCLOSE);
1.1042 www 9299: <script type="text/javascript">
9300: // <![CDATA[
1.1045 www 9301: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9302: // ]]>
9303: </script>
9304: ENDCLOSE
1.1044 www 9305: }
9306:
9307: sub r_print {
9308: my ($r,$to_print)=@_;
9309: if ($r) {
9310: $r->print($to_print);
9311: $r->rflush();
9312: } else {
9313: print($to_print);
9314: }
1.1042 www 9315: }
9316:
1.320 albertel 9317: sub html_encode {
9318: my ($result) = @_;
9319:
1.322 albertel 9320: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9321:
9322: return $result;
9323: }
1.1044 www 9324:
1.317 albertel 9325: sub js_ready {
9326: my ($result) = @_;
9327:
1.323 albertel 9328: $result =~ s/[\n\r]/ /xmsg;
9329: $result =~ s/\\/\\\\/xmsg;
9330: $result =~ s/'/\\'/xmsg;
1.372 albertel 9331: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9332:
9333: return $result;
9334: }
9335:
1.315 albertel 9336: sub validate_page {
9337: if ( exists($env{'internal.start_page'})
1.316 albertel 9338: && $env{'internal.start_page'} > 1) {
9339: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9340: $env{'internal.start_page'}.' '.
1.316 albertel 9341: $ENV{'request.filename'});
1.315 albertel 9342: }
9343: if ( exists($env{'internal.end_page'})
1.316 albertel 9344: && $env{'internal.end_page'} > 1) {
9345: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9346: $env{'internal.end_page'}.' '.
1.316 albertel 9347: $env{'request.filename'});
1.315 albertel 9348: }
9349: if ( exists($env{'internal.start_page'})
9350: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9351: &Apache::lonnet::logthis('start_page called without end_page '.
9352: $env{'request.filename'});
1.315 albertel 9353: }
9354: if ( ! exists($env{'internal.start_page'})
9355: && exists($env{'internal.end_page'})) {
1.316 albertel 9356: &Apache::lonnet::logthis('end_page called without start_page'.
9357: $env{'request.filename'});
1.315 albertel 9358: }
1.306 albertel 9359: }
1.315 albertel 9360:
1.996 www 9361:
9362: sub start_scrollbox {
1.1140 raeburn 9363: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9364: unless ($outerwidth) { $outerwidth='520px'; }
9365: unless ($width) { $width='500px'; }
9366: unless ($height) { $height='200px'; }
1.1075 raeburn 9367: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9368: if ($id ne '') {
1.1140 raeburn 9369: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9370: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9371: }
1.1075 raeburn 9372: if ($bgcolor ne '') {
9373: $tdcol = "background-color: $bgcolor;";
9374: }
1.1137 raeburn 9375: my $nicescroll_js;
9376: if ($env{'browser.mobile'}) {
1.1140 raeburn 9377: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9378: }
9379: return <<"END";
9380: $nicescroll_js
9381:
9382: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9383: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9384: END
9385: }
9386:
9387: sub end_scrollbox {
9388: return '</div></td></tr></table>';
9389: }
9390:
9391: sub nicescroll_javascript {
9392: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9393: my %options;
9394: if (ref($cursor) eq 'HASH') {
9395: %options = %{$cursor};
9396: }
9397: unless ($options{'railalign'} =~ /^left|right$/) {
9398: $options{'railalign'} = 'left';
9399: }
9400: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9401: my $function = &get_users_function();
9402: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9403: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9404: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9405: }
1.1140 raeburn 9406: }
9407: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9408: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9409: $options{'cursoropacity'}='1.0';
9410: }
1.1140 raeburn 9411: } else {
9412: $options{'cursoropacity'}='1.0';
9413: }
9414: if ($options{'cursorfixedheight'} eq 'none') {
9415: delete($options{'cursorfixedheight'});
9416: } else {
9417: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9418: }
9419: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9420: delete($options{'railoffset'});
9421: }
9422: my @niceoptions;
9423: while (my($key,$value) = each(%options)) {
9424: if ($value =~ /^\{.+\}$/) {
9425: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9426: } else {
1.1140 raeburn 9427: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9428: }
1.1140 raeburn 9429: }
9430: my $nicescroll_js = '
1.1137 raeburn 9431: $(document).ready(
1.1140 raeburn 9432: function() {
9433: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9434: }
1.1137 raeburn 9435: );
9436: ';
1.1140 raeburn 9437: if ($framecheck) {
9438: $nicescroll_js .= '
9439: function expand_div(caller) {
9440: if (top === self) {
9441: document.getElementById("'.$id.'").style.width = "auto";
9442: document.getElementById("'.$id.'").style.height = "auto";
9443: } else {
9444: try {
9445: if (parent.frames) {
9446: if (parent.frames.length > 1) {
9447: var framesrc = parent.frames[1].location.href;
9448: var currsrc = framesrc.replace(/\#.*$/,"");
9449: if ((caller == "search") || (currsrc == "'.$location.'")) {
9450: document.getElementById("'.$id.'").style.width = "auto";
9451: document.getElementById("'.$id.'").style.height = "auto";
9452: }
9453: }
9454: }
9455: } catch (e) {
9456: return;
9457: }
1.1137 raeburn 9458: }
1.1140 raeburn 9459: return;
1.996 www 9460: }
1.1140 raeburn 9461: ';
9462: }
9463: if ($needjsready) {
9464: $nicescroll_js = '
9465: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9466: } else {
9467: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9468: }
9469: return $nicescroll_js;
1.996 www 9470: }
9471:
1.318 albertel 9472: sub simple_error_page {
1.1150 bisitz 9473: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9474: my %displayargs;
1.1151 raeburn 9475: if (ref($args) eq 'HASH') {
9476: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9477: if ($args->{'only_body'}) {
9478: $displayargs{'only_body'} = 1;
9479: }
9480: if ($args->{'no_nav_bar'}) {
9481: $displayargs{'no_nav_bar'} = 1;
9482: }
1.1151 raeburn 9483: } else {
9484: $msg = &mt($msg);
9485: }
1.1150 bisitz 9486:
1.318 albertel 9487: my $page =
1.1304 raeburn 9488: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9489: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9490: &Apache::loncommon::end_page();
9491: if (ref($r)) {
9492: $r->print($page);
1.327 albertel 9493: return;
1.318 albertel 9494: }
9495: return $page;
9496: }
1.347 albertel 9497:
9498: {
1.610 albertel 9499: my @row_count;
1.961 onken 9500:
9501: sub start_data_table_count {
9502: unshift(@row_count, 0);
9503: return;
9504: }
9505:
9506: sub end_data_table_count {
9507: shift(@row_count);
9508: return;
9509: }
9510:
1.347 albertel 9511: sub start_data_table {
1.1018 raeburn 9512: my ($add_class,$id) = @_;
1.422 albertel 9513: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9514: my $table_id;
9515: if (defined($id)) {
9516: $table_id = ' id="'.$id.'"';
9517: }
1.961 onken 9518: &start_data_table_count();
1.1018 raeburn 9519: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9520: }
9521:
9522: sub end_data_table {
1.961 onken 9523: &end_data_table_count();
1.389 albertel 9524: return '</table>'."\n";;
1.347 albertel 9525: }
9526:
9527: sub start_data_table_row {
1.974 wenzelju 9528: my ($add_class, $id) = @_;
1.610 albertel 9529: $row_count[0]++;
9530: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9531: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9532: $id = (' id="'.$id.'"') unless ($id eq '');
9533: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9534: }
1.471 banghart 9535:
9536: sub continue_data_table_row {
1.974 wenzelju 9537: my ($add_class, $id) = @_;
1.610 albertel 9538: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9539: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9540: $id = (' id="'.$id.'"') unless ($id eq '');
9541: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9542: }
1.347 albertel 9543:
9544: sub end_data_table_row {
1.389 albertel 9545: return '</tr>'."\n";;
1.347 albertel 9546: }
1.367 www 9547:
1.421 albertel 9548: sub start_data_table_empty_row {
1.707 bisitz 9549: # $row_count[0]++;
1.421 albertel 9550: return '<tr class="LC_empty_row" >'."\n";;
9551: }
9552:
9553: sub end_data_table_empty_row {
9554: return '</tr>'."\n";;
9555: }
9556:
1.367 www 9557: sub start_data_table_header_row {
1.389 albertel 9558: return '<tr class="LC_header_row">'."\n";;
1.367 www 9559: }
9560:
9561: sub end_data_table_header_row {
1.389 albertel 9562: return '</tr>'."\n";;
1.367 www 9563: }
1.890 droeschl 9564:
9565: sub data_table_caption {
9566: my $caption = shift;
9567: return "<caption class=\"LC_caption\">$caption</caption>";
9568: }
1.347 albertel 9569: }
9570:
1.548 albertel 9571: =pod
9572:
9573: =item * &inhibit_menu_check($arg)
9574:
9575: Checks for a inhibitmenu state and generates output to preserve it
9576:
9577: Inputs: $arg - can be any of
9578: - undef - in which case the return value is a string
9579: to add into arguments list of a uri
9580: - 'input' - in which case the return value is a HTML
9581: <form> <input> field of type hidden to
9582: preserve the value
9583: - a url - in which case the return value is the url with
9584: the neccesary cgi args added to preserve the
9585: inhibitmenu state
9586: - a ref to a url - no return value, but the string is
9587: updated to include the neccessary cgi
9588: args to preserve the inhibitmenu state
9589:
9590: =cut
9591:
9592: sub inhibit_menu_check {
9593: my ($arg) = @_;
9594: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9595: if ($arg eq 'input') {
9596: if ($env{'form.inhibitmenu'}) {
9597: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9598: } else {
9599: return
9600: }
9601: }
9602: if ($env{'form.inhibitmenu'}) {
9603: if (ref($arg)) {
9604: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9605: } elsif ($arg eq '') {
9606: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9607: } else {
9608: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9609: }
9610: }
9611: if (!ref($arg)) {
9612: return $arg;
9613: }
9614: }
9615:
1.251 albertel 9616: ###############################################
1.182 matthew 9617:
9618: =pod
9619:
1.549 albertel 9620: =back
9621:
9622: =head1 User Information Routines
9623:
9624: =over 4
9625:
1.405 albertel 9626: =item * &get_users_function()
1.182 matthew 9627:
9628: Used by &bodytag to determine the current users primary role.
9629: Returns either 'student','coordinator','admin', or 'author'.
9630:
9631: =cut
9632:
9633: ###############################################
9634: sub get_users_function {
1.815 tempelho 9635: my $function = 'norole';
1.818 tempelho 9636: if ($env{'request.role'}=~/^(st)/) {
9637: $function='student';
9638: }
1.907 raeburn 9639: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9640: $function='coordinator';
9641: }
1.258 albertel 9642: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9643: $function='admin';
9644: }
1.826 bisitz 9645: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9646: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9647: $function='author';
9648: }
9649: return $function;
1.54 www 9650: }
1.99 www 9651:
9652: ###############################################
9653:
1.233 raeburn 9654: =pod
9655:
1.821 raeburn 9656: =item * &show_course()
9657:
9658: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9659: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9660:
9661: Inputs:
9662: None
9663:
9664: Outputs:
9665: Scalar: 1 if 'Course' to be used, 0 otherwise.
9666:
9667: =cut
9668:
9669: ###############################################
9670: sub show_course {
9671: my $course = !$env{'user.adv'};
9672: if (!$env{'user.adv'}) {
9673: foreach my $env (keys(%env)) {
9674: next if ($env !~ m/^user\.priv\./);
9675: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9676: $course = 0;
9677: last;
9678: }
9679: }
9680: }
9681: return $course;
9682: }
9683:
9684: ###############################################
9685:
9686: =pod
9687:
1.542 raeburn 9688: =item * &check_user_status()
1.274 raeburn 9689:
9690: Determines current status of supplied role for a
9691: specific user. Roles can be active, previous or future.
9692:
9693: Inputs:
9694: user's domain, user's username, course's domain,
1.375 raeburn 9695: course's number, optional section ID.
1.274 raeburn 9696:
9697: Outputs:
9698: role status: active, previous or future.
9699:
9700: =cut
9701:
9702: sub check_user_status {
1.412 raeburn 9703: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9704: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9705: my @uroles = keys(%userinfo);
1.274 raeburn 9706: my $srchstr;
9707: my $active_chk = 'none';
1.412 raeburn 9708: my $now = time;
1.274 raeburn 9709: if (@uroles > 0) {
1.908 raeburn 9710: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9711: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9712: } else {
1.412 raeburn 9713: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9714: }
9715: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9716: my $role_end = 0;
9717: my $role_start = 0;
9718: $active_chk = 'active';
1.412 raeburn 9719: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9720: $role_end = $1;
9721: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9722: $role_start = $1;
1.274 raeburn 9723: }
9724: }
9725: if ($role_start > 0) {
1.412 raeburn 9726: if ($now < $role_start) {
1.274 raeburn 9727: $active_chk = 'future';
9728: }
9729: }
9730: if ($role_end > 0) {
1.412 raeburn 9731: if ($now > $role_end) {
1.274 raeburn 9732: $active_chk = 'previous';
9733: }
9734: }
9735: }
9736: }
9737: return $active_chk;
9738: }
9739:
9740: ###############################################
9741:
9742: =pod
9743:
1.405 albertel 9744: =item * &get_sections()
1.233 raeburn 9745:
9746: Determines all the sections for a course including
9747: sections with students and sections containing other roles.
1.419 raeburn 9748: Incoming parameters:
9749:
9750: 1. domain
9751: 2. course number
9752: 3. reference to array containing roles for which sections should
9753: be gathered (optional).
9754: 4. reference to array containing status types for which sections
9755: should be gathered (optional).
9756:
9757: If the third argument is undefined, sections are gathered for any role.
9758: If the fourth argument is undefined, sections are gathered for any status.
9759: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9760:
1.374 raeburn 9761: Returns section hash (keys are section IDs, values are
9762: number of users in each section), subject to the
1.419 raeburn 9763: optional roles filter, optional status filter
1.233 raeburn 9764:
9765: =cut
9766:
9767: ###############################################
9768: sub get_sections {
1.419 raeburn 9769: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9770: if (!defined($cdom) || !defined($cnum)) {
9771: my $cid = $env{'request.course.id'};
9772:
9773: return if (!defined($cid));
9774:
9775: $cdom = $env{'course.'.$cid.'.domain'};
9776: $cnum = $env{'course.'.$cid.'.num'};
9777: }
9778:
9779: my %sectioncount;
1.419 raeburn 9780: my $now = time;
1.240 albertel 9781:
1.1118 raeburn 9782: my $check_students = 1;
9783: my $only_students = 0;
9784: if (ref($possible_roles) eq 'ARRAY') {
9785: if (grep(/^st$/,@{$possible_roles})) {
9786: if (@{$possible_roles} == 1) {
9787: $only_students = 1;
9788: }
9789: } else {
9790: $check_students = 0;
9791: }
9792: }
9793:
9794: if ($check_students) {
1.276 albertel 9795: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9796: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9797: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9798: my $start_index = &Apache::loncoursedata::CL_START();
9799: my $end_index = &Apache::loncoursedata::CL_END();
9800: my $status;
1.366 albertel 9801: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9802: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9803: $data->[$status_index],
9804: $data->[$start_index],
9805: $data->[$end_index]);
9806: if ($stu_status eq 'Active') {
9807: $status = 'active';
9808: } elsif ($end < $now) {
9809: $status = 'previous';
9810: } elsif ($start > $now) {
9811: $status = 'future';
9812: }
9813: if ($section ne '-1' && $section !~ /^\s*$/) {
9814: if ((!defined($possible_status)) || (($status ne '') &&
9815: (grep/^\Q$status\E$/,@{$possible_status}))) {
9816: $sectioncount{$section}++;
9817: }
1.240 albertel 9818: }
9819: }
9820: }
1.1118 raeburn 9821: if ($only_students) {
9822: return %sectioncount;
9823: }
1.240 albertel 9824: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9825: foreach my $user (sort(keys(%courseroles))) {
9826: if ($user !~ /^(\w{2})/) { next; }
9827: my ($role) = ($user =~ /^(\w{2})/);
9828: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9829: my ($section,$status);
1.240 albertel 9830: if ($role eq 'cr' &&
9831: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9832: $section=$1;
9833: }
9834: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9835: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9836: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9837: if ($end == -1 && $start == -1) {
9838: next; #deleted role
9839: }
9840: if (!defined($possible_status)) {
9841: $sectioncount{$section}++;
9842: } else {
9843: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9844: $status = 'active';
9845: } elsif ($end < $now) {
9846: $status = 'future';
9847: } elsif ($start > $now) {
9848: $status = 'previous';
9849: }
9850: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9851: $sectioncount{$section}++;
9852: }
9853: }
1.233 raeburn 9854: }
1.366 albertel 9855: return %sectioncount;
1.233 raeburn 9856: }
9857:
1.274 raeburn 9858: ###############################################
1.294 raeburn 9859:
9860: =pod
1.405 albertel 9861:
9862: =item * &get_course_users()
9863:
1.275 raeburn 9864: Retrieves usernames:domains for users in the specified course
9865: with specific role(s), and access status.
9866:
9867: Incoming parameters:
1.277 albertel 9868: 1. course domain
9869: 2. course number
9870: 3. access status: users must have - either active,
1.275 raeburn 9871: previous, future, or all.
1.277 albertel 9872: 4. reference to array of permissible roles
1.288 raeburn 9873: 5. reference to array of section restrictions (optional)
9874: 6. reference to results object (hash of hashes).
9875: 7. reference to optional userdata hash
1.609 raeburn 9876: 8. reference to optional statushash
1.630 raeburn 9877: 9. flag if privileged users (except those set to unhide in
9878: course settings) should be excluded
1.609 raeburn 9879: Keys of top level results hash are roles.
1.275 raeburn 9880: Keys of inner hashes are username:domain, with
9881: values set to access type.
1.288 raeburn 9882: Optional userdata hash returns an array with arguments in the
9883: same order as loncoursedata::get_classlist() for student data.
9884:
1.609 raeburn 9885: Optional statushash returns
9886:
1.288 raeburn 9887: Entries for end, start, section and status are blank because
9888: of the possibility of multiple values for non-student roles.
9889:
1.275 raeburn 9890: =cut
1.405 albertel 9891:
1.275 raeburn 9892: ###############################################
1.405 albertel 9893:
1.275 raeburn 9894: sub get_course_users {
1.630 raeburn 9895: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9896: my %idx = ();
1.419 raeburn 9897: my %seclists;
1.288 raeburn 9898:
9899: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9900: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9901: $idx{end} = &Apache::loncoursedata::CL_END();
9902: $idx{start} = &Apache::loncoursedata::CL_START();
9903: $idx{id} = &Apache::loncoursedata::CL_ID();
9904: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9905: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9906: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9907:
1.290 albertel 9908: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9909: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9910: my $now = time;
1.277 albertel 9911: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9912: my $match = 0;
1.412 raeburn 9913: my $secmatch = 0;
1.419 raeburn 9914: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9915: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9916: if ($section eq '') {
9917: $section = 'none';
9918: }
1.291 albertel 9919: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9920: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9921: $secmatch = 1;
9922: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9923: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9924: $secmatch = 1;
9925: }
9926: } else {
1.419 raeburn 9927: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9928: $secmatch = 1;
9929: }
1.290 albertel 9930: }
1.412 raeburn 9931: if (!$secmatch) {
9932: next;
9933: }
1.419 raeburn 9934: }
1.275 raeburn 9935: if (defined($$types{'active'})) {
1.288 raeburn 9936: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9937: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9938: $match = 1;
1.275 raeburn 9939: }
9940: }
9941: if (defined($$types{'previous'})) {
1.609 raeburn 9942: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9943: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9944: $match = 1;
1.275 raeburn 9945: }
9946: }
9947: if (defined($$types{'future'})) {
1.609 raeburn 9948: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9949: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9950: $match = 1;
1.275 raeburn 9951: }
9952: }
1.609 raeburn 9953: if ($match) {
9954: push(@{$seclists{$student}},$section);
9955: if (ref($userdata) eq 'HASH') {
9956: $$userdata{$student} = $$classlist{$student};
9957: }
9958: if (ref($statushash) eq 'HASH') {
9959: $statushash->{$student}{'st'}{$section} = $status;
9960: }
1.288 raeburn 9961: }
1.275 raeburn 9962: }
9963: }
1.412 raeburn 9964: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9965: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9966: my $now = time;
1.609 raeburn 9967: my %displaystatus = ( previous => 'Expired',
9968: active => 'Active',
9969: future => 'Future',
9970: );
1.1121 raeburn 9971: my (%nothide,@possdoms);
1.630 raeburn 9972: if ($hidepriv) {
9973: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9974: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9975: if ($user !~ /:/) {
9976: $nothide{join(':',split(/[\@]/,$user))}=1;
9977: } else {
9978: $nothide{$user} = 1;
9979: }
9980: }
1.1121 raeburn 9981: my @possdoms = ($cdom);
9982: if ($coursehash{'checkforpriv'}) {
9983: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9984: }
1.630 raeburn 9985: }
1.439 raeburn 9986: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9987: my $match = 0;
1.412 raeburn 9988: my $secmatch = 0;
1.439 raeburn 9989: my $status;
1.412 raeburn 9990: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9991: $user =~ s/:$//;
1.439 raeburn 9992: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9993: if ($end == -1 || $start == -1) {
9994: next;
9995: }
9996: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9997: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9998: my ($uname,$udom) = split(/:/,$user);
9999: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10000: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10001: $secmatch = 1;
10002: } elsif ($usec eq '') {
1.420 albertel 10003: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10004: $secmatch = 1;
10005: }
10006: } else {
10007: if (grep(/^\Q$usec\E$/,@{$sections})) {
10008: $secmatch = 1;
10009: }
10010: }
10011: if (!$secmatch) {
10012: next;
10013: }
1.288 raeburn 10014: }
1.419 raeburn 10015: if ($usec eq '') {
10016: $usec = 'none';
10017: }
1.275 raeburn 10018: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10019: if ($hidepriv) {
1.1121 raeburn 10020: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10021: (!$nothide{$uname.':'.$udom})) {
10022: next;
10023: }
10024: }
1.503 raeburn 10025: if ($end > 0 && $end < $now) {
1.439 raeburn 10026: $status = 'previous';
10027: } elsif ($start > $now) {
10028: $status = 'future';
10029: } else {
10030: $status = 'active';
10031: }
1.277 albertel 10032: foreach my $type (keys(%{$types})) {
1.275 raeburn 10033: if ($status eq $type) {
1.420 albertel 10034: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10035: push(@{$$users{$role}{$user}},$type);
10036: }
1.288 raeburn 10037: $match = 1;
10038: }
10039: }
1.419 raeburn 10040: if (($match) && (ref($userdata) eq 'HASH')) {
10041: if (!exists($$userdata{$uname.':'.$udom})) {
10042: &get_user_info($udom,$uname,\%idx,$userdata);
10043: }
1.420 albertel 10044: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10045: push(@{$seclists{$uname.':'.$udom}},$usec);
10046: }
1.609 raeburn 10047: if (ref($statushash) eq 'HASH') {
10048: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10049: }
1.275 raeburn 10050: }
10051: }
10052: }
10053: }
1.290 albertel 10054: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10055: if ((defined($cdom)) && (defined($cnum))) {
10056: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10057: if ( defined($csettings{'internal.courseowner'}) ) {
10058: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10059: next if ($owner eq '');
10060: my ($ownername,$ownerdom);
10061: if ($owner =~ /^([^:]+):([^:]+)$/) {
10062: $ownername = $1;
10063: $ownerdom = $2;
10064: } else {
10065: $ownername = $owner;
10066: $ownerdom = $cdom;
10067: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10068: }
10069: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10070: if (defined($userdata) &&
1.609 raeburn 10071: !exists($$userdata{$owner})) {
10072: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10073: if (!grep(/^none$/,@{$seclists{$owner}})) {
10074: push(@{$seclists{$owner}},'none');
10075: }
10076: if (ref($statushash) eq 'HASH') {
10077: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10078: }
1.290 albertel 10079: }
1.279 raeburn 10080: }
10081: }
10082: }
1.419 raeburn 10083: foreach my $user (keys(%seclists)) {
10084: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10085: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10086: }
1.275 raeburn 10087: }
10088: return;
10089: }
10090:
1.288 raeburn 10091: sub get_user_info {
10092: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10093: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10094: &plainname($uname,$udom,'lastname');
1.291 albertel 10095: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10096: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10097: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10098: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10099: return;
10100: }
1.275 raeburn 10101:
1.472 raeburn 10102: ###############################################
10103:
10104: =pod
10105:
10106: =item * &get_user_quota()
10107:
1.1134 raeburn 10108: Retrieves quota assigned for storage of user files.
10109: Default is to report quota for portfolio files.
1.472 raeburn 10110:
10111: Incoming parameters:
10112: 1. user's username
10113: 2. user's domain
1.1134 raeburn 10114: 3. quota name - portfolio, author, or course
1.1136 raeburn 10115: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10116: 4. crstype - official, unofficial, textbook, placement or community,
10117: if quota name is course
1.472 raeburn 10118:
10119: Returns:
1.1163 raeburn 10120: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10121: 2. (Optional) Type of setting: custom or default
10122: (individually assigned or default for user's
10123: institutional status).
10124: 3. (Optional) - User's institutional status (e.g., faculty, staff
10125: or student - types as defined in localenroll::inst_usertypes
10126: for user's domain, which determines default quota for user.
10127: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10128:
10129: If a value has been stored in the user's environment,
1.536 raeburn 10130: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10131: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10132:
10133: =cut
10134:
10135: ###############################################
10136:
10137:
10138: sub get_user_quota {
1.1136 raeburn 10139: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10140: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10141: if (!defined($udom)) {
10142: $udom = $env{'user.domain'};
10143: }
10144: if (!defined($uname)) {
10145: $uname = $env{'user.name'};
10146: }
10147: if (($udom eq '' || $uname eq '') ||
10148: ($udom eq 'public') && ($uname eq 'public')) {
10149: $quota = 0;
1.536 raeburn 10150: $quotatype = 'default';
10151: $defquota = 0;
1.472 raeburn 10152: } else {
1.536 raeburn 10153: my $inststatus;
1.1134 raeburn 10154: if ($quotaname eq 'course') {
10155: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10156: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10157: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10158: } else {
10159: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10160: $quota = $cenv{'internal.uploadquota'};
10161: }
1.536 raeburn 10162: } else {
1.1134 raeburn 10163: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10164: if ($quotaname eq 'author') {
10165: $quota = $env{'environment.authorquota'};
10166: } else {
10167: $quota = $env{'environment.portfolioquota'};
10168: }
10169: $inststatus = $env{'environment.inststatus'};
10170: } else {
10171: my %userenv =
10172: &Apache::lonnet::get('environment',['portfolioquota',
10173: 'authorquota','inststatus'],$udom,$uname);
10174: my ($tmp) = keys(%userenv);
10175: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10176: if ($quotaname eq 'author') {
10177: $quota = $userenv{'authorquota'};
10178: } else {
10179: $quota = $userenv{'portfolioquota'};
10180: }
10181: $inststatus = $userenv{'inststatus'};
10182: } else {
10183: undef(%userenv);
10184: }
10185: }
10186: }
10187: if ($quota eq '' || wantarray) {
10188: if ($quotaname eq 'course') {
10189: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10190: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10191: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10192: ($crstype eq 'placement')) {
1.1136 raeburn 10193: $defquota = $domdefs{$crstype.'quota'};
10194: }
10195: if ($defquota eq '') {
10196: $defquota = 500;
10197: }
1.1134 raeburn 10198: } else {
10199: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10200: }
10201: if ($quota eq '') {
10202: $quota = $defquota;
10203: $quotatype = 'default';
10204: } else {
10205: $quotatype = 'custom';
10206: }
1.472 raeburn 10207: }
10208: }
1.536 raeburn 10209: if (wantarray) {
10210: return ($quota,$quotatype,$settingstatus,$defquota);
10211: } else {
10212: return $quota;
10213: }
1.472 raeburn 10214: }
10215:
10216: ###############################################
10217:
10218: =pod
10219:
10220: =item * &default_quota()
10221:
1.536 raeburn 10222: Retrieves default quota assigned for storage of user portfolio files,
10223: given an (optional) user's institutional status.
1.472 raeburn 10224:
10225: Incoming parameters:
1.1142 raeburn 10226:
1.472 raeburn 10227: 1. domain
1.536 raeburn 10228: 2. (Optional) institutional status(es). This is a : separated list of
10229: status types (e.g., faculty, staff, student etc.)
10230: which apply to the user for whom the default is being retrieved.
10231: If the institutional status string in undefined, the domain
1.1134 raeburn 10232: default quota will be returned.
10233: 3. quota name - portfolio, author, or course
10234: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10235:
10236: Returns:
1.1142 raeburn 10237:
1.1163 raeburn 10238: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10239: 2. (Optional) institutional type which determined the value of the
10240: default quota.
1.472 raeburn 10241:
10242: If a value has been stored in the domain's configuration db,
10243: it will return that, otherwise it returns 20 (for backwards
10244: compatibility with domains which have not set up a configuration
1.1163 raeburn 10245: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10246:
1.536 raeburn 10247: If the user's status includes multiple types (e.g., staff and student),
10248: the largest default quota which applies to the user determines the
10249: default quota returned.
10250:
1.472 raeburn 10251: =cut
10252:
10253: ###############################################
10254:
10255:
10256: sub default_quota {
1.1134 raeburn 10257: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10258: my ($defquota,$settingstatus);
10259: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10260: ['quotas'],$udom);
1.1134 raeburn 10261: my $key = 'defaultquota';
10262: if ($quotaname eq 'author') {
10263: $key = 'authorquota';
10264: }
1.622 raeburn 10265: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10266: if ($inststatus ne '') {
1.765 raeburn 10267: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10268: foreach my $item (@statuses) {
1.1134 raeburn 10269: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10270: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10271: if ($defquota eq '') {
1.1134 raeburn 10272: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10273: $settingstatus = $item;
1.1134 raeburn 10274: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10275: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10276: $settingstatus = $item;
10277: }
10278: }
1.1134 raeburn 10279: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10280: if ($quotahash{'quotas'}{$item} ne '') {
10281: if ($defquota eq '') {
10282: $defquota = $quotahash{'quotas'}{$item};
10283: $settingstatus = $item;
10284: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10285: $defquota = $quotahash{'quotas'}{$item};
10286: $settingstatus = $item;
10287: }
1.536 raeburn 10288: }
10289: }
10290: }
10291: }
10292: if ($defquota eq '') {
1.1134 raeburn 10293: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10294: $defquota = $quotahash{'quotas'}{$key}{'default'};
10295: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10296: $defquota = $quotahash{'quotas'}{'default'};
10297: }
1.536 raeburn 10298: $settingstatus = 'default';
1.1139 raeburn 10299: if ($defquota eq '') {
10300: if ($quotaname eq 'author') {
10301: $defquota = 500;
10302: }
10303: }
1.536 raeburn 10304: }
10305: } else {
10306: $settingstatus = 'default';
1.1134 raeburn 10307: if ($quotaname eq 'author') {
10308: $defquota = 500;
10309: } else {
10310: $defquota = 20;
10311: }
1.536 raeburn 10312: }
10313: if (wantarray) {
10314: return ($defquota,$settingstatus);
1.472 raeburn 10315: } else {
1.536 raeburn 10316: return $defquota;
1.472 raeburn 10317: }
10318: }
10319:
1.1135 raeburn 10320: ###############################################
10321:
10322: =pod
10323:
1.1136 raeburn 10324: =item * &excess_filesize_warning()
1.1135 raeburn 10325:
10326: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10327: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10328: space to be exceeded.
1.1136 raeburn 10329:
10330: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10331: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10332:
1.1165 raeburn 10333: Inputs: 7
1.1136 raeburn 10334: 1. username or coursenum
1.1135 raeburn 10335: 2. domain
1.1136 raeburn 10336: 3. context ('author' or 'course')
1.1135 raeburn 10337: 4. filename of file for which action is being requested
10338: 5. filesize (kB) of file
10339: 6. action being taken: copy or upload.
1.1237 raeburn 10340: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10341:
10342: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10343: otherwise return null.
10344:
10345: =back
1.1135 raeburn 10346:
10347: =cut
10348:
1.1136 raeburn 10349: sub excess_filesize_warning {
1.1165 raeburn 10350: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10351: my $current_disk_usage = 0;
1.1165 raeburn 10352: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10353: if ($context eq 'author') {
10354: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10355: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10356: } else {
10357: foreach my $subdir ('docs','supplemental') {
10358: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10359: }
10360: }
1.1135 raeburn 10361: $disk_quota = int($disk_quota * 1000);
10362: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10363: return '<p class="LC_warning">'.
1.1135 raeburn 10364: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10365: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10366: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10367: $disk_quota,$current_disk_usage).
10368: '</p>';
10369: }
10370: return;
10371: }
10372:
10373: ###############################################
10374:
10375:
1.1136 raeburn 10376:
10377:
1.384 raeburn 10378: sub get_secgrprole_info {
10379: my ($cdom,$cnum,$needroles,$type) = @_;
10380: my %sections_count = &get_sections($cdom,$cnum);
10381: my @sections = (sort {$a <=> $b} keys(%sections_count));
10382: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10383: my @groups = sort(keys(%curr_groups));
10384: my $allroles = [];
10385: my $rolehash;
10386: my $accesshash = {
10387: active => 'Currently has access',
10388: future => 'Will have future access',
10389: previous => 'Previously had access',
10390: };
10391: if ($needroles) {
10392: $rolehash = {'all' => 'all'};
1.385 albertel 10393: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10394: if (&Apache::lonnet::error(%user_roles)) {
10395: undef(%user_roles);
10396: }
10397: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10398: my ($role)=split(/\:/,$item,2);
10399: if ($role eq 'cr') { next; }
10400: if ($role =~ /^cr/) {
10401: $$rolehash{$role} = (split('/',$role))[3];
10402: } else {
10403: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10404: }
10405: }
10406: foreach my $key (sort(keys(%{$rolehash}))) {
10407: push(@{$allroles},$key);
10408: }
10409: push (@{$allroles},'st');
10410: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10411: }
10412: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10413: }
10414:
1.555 raeburn 10415: sub user_picker {
1.1279 raeburn 10416: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10417: my $currdom = $dom;
1.1253 raeburn 10418: my @alldoms = &Apache::lonnet::all_domains();
10419: if (@alldoms == 1) {
10420: my %domsrch = &Apache::lonnet::get_dom('configuration',
10421: ['directorysrch'],$alldoms[0]);
10422: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10423: my $showdom = $domdesc;
10424: if ($showdom eq '') {
10425: $showdom = $dom;
10426: }
10427: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10428: if ((!$domsrch{'directorysrch'}{'available'}) &&
10429: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10430: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10431: }
10432: }
10433: }
1.555 raeburn 10434: my %curr_selected = (
10435: srchin => 'dom',
1.580 raeburn 10436: srchby => 'lastname',
1.555 raeburn 10437: );
10438: my $srchterm;
1.625 raeburn 10439: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10440: if ($srch->{'srchby'} ne '') {
10441: $curr_selected{'srchby'} = $srch->{'srchby'};
10442: }
10443: if ($srch->{'srchin'} ne '') {
10444: $curr_selected{'srchin'} = $srch->{'srchin'};
10445: }
10446: if ($srch->{'srchtype'} ne '') {
10447: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10448: }
10449: if ($srch->{'srchdomain'} ne '') {
10450: $currdom = $srch->{'srchdomain'};
10451: }
10452: $srchterm = $srch->{'srchterm'};
10453: }
1.1222 damieng 10454: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10455: 'usr' => 'Search criteria',
1.563 raeburn 10456: 'doma' => 'Domain/institution to search',
1.558 albertel 10457: 'uname' => 'username',
10458: 'lastname' => 'last name',
1.555 raeburn 10459: 'lastfirst' => 'last name, first name',
1.558 albertel 10460: 'crs' => 'in this course',
1.576 raeburn 10461: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10462: 'alc' => 'all LON-CAPA',
1.573 raeburn 10463: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10464: 'exact' => 'is',
10465: 'contains' => 'contains',
1.569 raeburn 10466: 'begins' => 'begins with',
1.1222 damieng 10467: );
10468: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10469: 'youm' => "You must include some text to search for.",
10470: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10471: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10472: 'yomc' => "You must choose a domain when using an institutional directory search.",
10473: 'ymcd' => "You must choose a domain when using a domain search.",
10474: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10475: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10476: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10477: );
1.1222 damieng 10478: &html_escape(\%html_lt);
10479: &js_escape(\%js_lt);
1.1255 raeburn 10480: my $domform;
1.1277 raeburn 10481: my $allow_blank = 1;
1.1255 raeburn 10482: if ($fixeddom) {
1.1277 raeburn 10483: $allow_blank = 0;
10484: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10485: } else {
1.1287 raeburn 10486: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10487: my ($trusted,$untrusted);
1.1287 raeburn 10488: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10489: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10490: } elsif ($context eq 'author') {
1.1288 raeburn 10491: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10492: } elsif ($context eq 'domain') {
1.1288 raeburn 10493: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10494: }
1.1288 raeburn 10495: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10496: }
1.563 raeburn 10497: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10498:
10499: my @srchins = ('crs','dom','alc','instd');
10500:
10501: foreach my $option (@srchins) {
10502: # FIXME 'alc' option unavailable until
10503: # loncreateuser::print_user_query_page()
10504: # has been completed.
10505: next if ($option eq 'alc');
1.880 raeburn 10506: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10507: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10508: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10509: if ($curr_selected{'srchin'} eq $option) {
10510: $srchinsel .= '
1.1222 damieng 10511: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10512: } else {
10513: $srchinsel .= '
1.1222 damieng 10514: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10515: }
1.555 raeburn 10516: }
1.563 raeburn 10517: $srchinsel .= "\n </select>\n";
1.555 raeburn 10518:
10519: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10520: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10521: if ($curr_selected{'srchby'} eq $option) {
10522: $srchbysel .= '
1.1222 damieng 10523: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10524: } else {
10525: $srchbysel .= '
1.1222 damieng 10526: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10527: }
10528: }
10529: $srchbysel .= "\n </select>\n";
10530:
10531: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10532: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10533: if ($curr_selected{'srchtype'} eq $option) {
10534: $srchtypesel .= '
1.1222 damieng 10535: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10536: } else {
10537: $srchtypesel .= '
1.1222 damieng 10538: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10539: }
10540: }
10541: $srchtypesel .= "\n </select>\n";
10542:
1.558 albertel 10543: my ($newuserscript,$new_user_create);
1.994 raeburn 10544: my $context_dom = $env{'request.role.domain'};
10545: if ($context eq 'requestcrs') {
10546: if ($env{'form.coursedom'} ne '') {
10547: $context_dom = $env{'form.coursedom'};
10548: }
10549: }
1.556 raeburn 10550: if ($forcenewuser) {
1.576 raeburn 10551: if (ref($srch) eq 'HASH') {
1.994 raeburn 10552: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10553: if ($cancreate) {
10554: $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>';
10555: } else {
1.799 bisitz 10556: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10557: my %usertypetext = (
10558: official => 'institutional',
10559: unofficial => 'non-institutional',
10560: );
1.799 bisitz 10561: $new_user_create = '<p class="LC_warning">'
10562: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10563: .' '
10564: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10565: ,'<a href="'.$helplink.'">','</a>')
10566: .'</p><br />';
1.627 raeburn 10567: }
1.576 raeburn 10568: }
10569: }
10570:
1.556 raeburn 10571: $newuserscript = <<"ENDSCRIPT";
10572:
1.570 raeburn 10573: function setSearch(createnew,callingForm) {
1.556 raeburn 10574: if (createnew == 1) {
1.570 raeburn 10575: for (var i=0; i<callingForm.srchby.length; i++) {
10576: if (callingForm.srchby.options[i].value == 'uname') {
10577: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10578: }
10579: }
1.570 raeburn 10580: for (var i=0; i<callingForm.srchin.length; i++) {
10581: if ( callingForm.srchin.options[i].value == 'dom') {
10582: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10583: }
10584: }
1.570 raeburn 10585: for (var i=0; i<callingForm.srchtype.length; i++) {
10586: if (callingForm.srchtype.options[i].value == 'exact') {
10587: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10588: }
10589: }
1.570 raeburn 10590: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10591: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10592: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10593: }
10594: }
10595: }
10596: }
10597: ENDSCRIPT
1.558 albertel 10598:
1.556 raeburn 10599: }
10600:
1.555 raeburn 10601: my $output = <<"END_BLOCK";
1.556 raeburn 10602: <script type="text/javascript">
1.824 bisitz 10603: // <![CDATA[
1.570 raeburn 10604: function validateEntry(callingForm) {
1.558 albertel 10605:
1.556 raeburn 10606: var checkok = 1;
1.558 albertel 10607: var srchin;
1.570 raeburn 10608: for (var i=0; i<callingForm.srchin.length; i++) {
10609: if ( callingForm.srchin[i].checked ) {
10610: srchin = callingForm.srchin[i].value;
1.558 albertel 10611: }
10612: }
10613:
1.570 raeburn 10614: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10615: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10616: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10617: var srchterm = callingForm.srchterm.value;
10618: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10619: var msg = "";
10620:
10621: if (srchterm == "") {
10622: checkok = 0;
1.1222 damieng 10623: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10624: }
10625:
1.569 raeburn 10626: if (srchtype== 'begins') {
10627: if (srchterm.length < 2) {
10628: checkok = 0;
1.1222 damieng 10629: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10630: }
10631: }
10632:
1.556 raeburn 10633: if (srchtype== 'contains') {
10634: if (srchterm.length < 3) {
10635: checkok = 0;
1.1222 damieng 10636: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10637: }
10638: }
10639: if (srchin == 'instd') {
10640: if (srchdomain == '') {
10641: checkok = 0;
1.1222 damieng 10642: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10643: }
10644: }
10645: if (srchin == 'dom') {
10646: if (srchdomain == '') {
10647: checkok = 0;
1.1222 damieng 10648: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10649: }
10650: }
10651: if (srchby == 'lastfirst') {
10652: if (srchterm.indexOf(",") == -1) {
10653: checkok = 0;
1.1222 damieng 10654: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10655: }
10656: if (srchterm.indexOf(",") == srchterm.length -1) {
10657: checkok = 0;
1.1222 damieng 10658: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10659: }
10660: }
10661: if (checkok == 0) {
1.1222 damieng 10662: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10663: return;
10664: }
10665: if (checkok == 1) {
1.570 raeburn 10666: callingForm.submit();
1.556 raeburn 10667: }
10668: }
10669:
10670: $newuserscript
10671:
1.824 bisitz 10672: // ]]>
1.556 raeburn 10673: </script>
1.558 albertel 10674:
10675: $new_user_create
10676:
1.555 raeburn 10677: END_BLOCK
1.558 albertel 10678:
1.876 raeburn 10679: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10680: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10681: $domform.
10682: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10683: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10684: $srchbysel.
10685: $srchtypesel.
10686: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10687: $srchinsel.
10688: &Apache::lonhtmlcommon::row_closure(1).
10689: &Apache::lonhtmlcommon::end_pick_box().
10690: '<br />';
1.1253 raeburn 10691: return ($output,1);
1.555 raeburn 10692: }
10693:
1.612 raeburn 10694: sub user_rule_check {
1.615 raeburn 10695: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10696: my ($response,%inst_response);
1.612 raeburn 10697: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10698: if (keys(%{$usershash}) > 1) {
10699: my (%by_username,%by_id,%userdoms);
10700: my $checkid;
10701: if (ref($checks) eq 'HASH') {
10702: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10703: $checkid = 1;
10704: }
10705: }
10706: foreach my $user (keys(%{$usershash})) {
10707: my ($uname,$udom) = split(/:/,$user);
10708: if ($checkid) {
10709: if (ref($usershash->{$user}) eq 'HASH') {
10710: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10711: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10712: $userdoms{$udom} = 1;
1.1227 raeburn 10713: if (ref($inst_results) eq 'HASH') {
10714: $inst_results->{$uname.':'.$udom} = {};
10715: }
1.1226 raeburn 10716: }
10717: }
10718: } else {
10719: $by_username{$udom}{$uname} = 1;
10720: $userdoms{$udom} = 1;
1.1227 raeburn 10721: if (ref($inst_results) eq 'HASH') {
10722: $inst_results->{$uname.':'.$udom} = {};
10723: }
1.1226 raeburn 10724: }
10725: }
10726: foreach my $udom (keys(%userdoms)) {
10727: if (!$got_rules->{$udom}) {
10728: my %domconfig = &Apache::lonnet::get_dom('configuration',
10729: ['usercreation'],$udom);
10730: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10731: foreach my $item ('username','id') {
10732: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10733: $$curr_rules{$udom}{$item} =
10734: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10735: }
10736: }
10737: }
10738: $got_rules->{$udom} = 1;
10739: }
1.612 raeburn 10740: }
1.1226 raeburn 10741: if ($checkid) {
10742: foreach my $udom (keys(%by_id)) {
10743: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10744: if ($outcome eq 'ok') {
1.1227 raeburn 10745: foreach my $id (keys(%{$by_id{$udom}})) {
10746: my $uname = $by_id{$udom}{$id};
10747: $inst_response{$uname.':'.$udom} = $outcome;
10748: }
1.1226 raeburn 10749: if (ref($results) eq 'HASH') {
10750: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10751: if (exists($inst_response{$uname.':'.$udom})) {
10752: $inst_response{$uname.':'.$udom} = $outcome;
10753: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10754: }
1.1226 raeburn 10755: }
10756: }
10757: }
1.612 raeburn 10758: }
1.615 raeburn 10759: } else {
1.1226 raeburn 10760: foreach my $udom (keys(%by_username)) {
10761: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10762: if ($outcome eq 'ok') {
1.1227 raeburn 10763: foreach my $uname (keys(%{$by_username{$udom}})) {
10764: $inst_response{$uname.':'.$udom} = $outcome;
10765: }
1.1226 raeburn 10766: if (ref($results) eq 'HASH') {
10767: foreach my $uname (keys(%{$results})) {
10768: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10769: }
10770: }
10771: }
10772: }
1.612 raeburn 10773: }
1.1226 raeburn 10774: } elsif (keys(%{$usershash}) == 1) {
10775: my $user = (keys(%{$usershash}))[0];
10776: my ($uname,$udom) = split(/:/,$user);
10777: if (($udom ne '') && ($uname ne '')) {
10778: if (ref($usershash->{$user}) eq 'HASH') {
10779: if (ref($checks) eq 'HASH') {
10780: if (defined($checks->{'username'})) {
10781: ($inst_response{$user},%{$inst_results->{$user}}) =
10782: &Apache::lonnet::get_instuser($udom,$uname);
10783: } elsif (defined($checks->{'id'})) {
10784: if ($usershash->{$user}->{'id'} ne '') {
10785: ($inst_response{$user},%{$inst_results->{$user}}) =
10786: &Apache::lonnet::get_instuser($udom,undef,
10787: $usershash->{$user}->{'id'});
10788: } else {
10789: ($inst_response{$user},%{$inst_results->{$user}}) =
10790: &Apache::lonnet::get_instuser($udom,$uname);
10791: }
1.585 raeburn 10792: }
1.1226 raeburn 10793: } else {
10794: ($inst_response{$user},%{$inst_results->{$user}}) =
10795: &Apache::lonnet::get_instuser($udom,$uname);
10796: return;
10797: }
10798: if (!$got_rules->{$udom}) {
10799: my %domconfig = &Apache::lonnet::get_dom('configuration',
10800: ['usercreation'],$udom);
10801: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10802: foreach my $item ('username','id') {
10803: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10804: $$curr_rules{$udom}{$item} =
10805: $domconfig{'usercreation'}{$item.'_rule'};
10806: }
10807: }
10808: }
10809: $got_rules->{$udom} = 1;
1.585 raeburn 10810: }
10811: }
1.1226 raeburn 10812: } else {
10813: return;
10814: }
10815: } else {
10816: return;
10817: }
10818: foreach my $user (keys(%{$usershash})) {
10819: my ($uname,$udom) = split(/:/,$user);
10820: next if (($udom eq '') || ($uname eq ''));
10821: my $id;
1.1227 raeburn 10822: if (ref($inst_results) eq 'HASH') {
10823: if (ref($inst_results->{$user}) eq 'HASH') {
10824: $id = $inst_results->{$user}->{'id'};
10825: }
10826: }
10827: if ($id eq '') {
10828: if (ref($usershash->{$user})) {
10829: $id = $usershash->{$user}->{'id'};
10830: }
1.585 raeburn 10831: }
1.612 raeburn 10832: foreach my $item (keys(%{$checks})) {
10833: if (ref($$curr_rules{$udom}) eq 'HASH') {
10834: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10835: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10836: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10837: $$curr_rules{$udom}{$item});
1.612 raeburn 10838: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10839: if ($rule_check{$rule}) {
10840: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10841: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10842: if (ref($inst_results) eq 'HASH') {
10843: if (ref($inst_results->{$user}) eq 'HASH') {
10844: if (keys(%{$inst_results->{$user}}) == 0) {
10845: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10846: } elsif ($item eq 'id') {
10847: if ($inst_results->{$user}->{'id'} eq '') {
10848: $$alerts{$item}{$udom}{$uname} = 1;
10849: }
1.615 raeburn 10850: }
1.612 raeburn 10851: }
10852: }
1.615 raeburn 10853: }
10854: last;
1.585 raeburn 10855: }
10856: }
10857: }
10858: }
10859: }
10860: }
10861: }
10862: }
1.612 raeburn 10863: return;
10864: }
10865:
10866: sub user_rule_formats {
10867: my ($domain,$domdesc,$curr_rules,$check) = @_;
10868: my %text = (
10869: 'username' => 'Usernames',
10870: 'id' => 'IDs',
10871: );
10872: my $output;
10873: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10874: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10875: if (@{$ruleorder} > 0) {
1.1102 raeburn 10876: $output = '<br />'.
10877: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10878: '<span class="LC_cusr_emph">','</span>',$domdesc).
10879: ' <ul>';
1.612 raeburn 10880: foreach my $rule (@{$ruleorder}) {
10881: if (ref($curr_rules) eq 'ARRAY') {
10882: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10883: if (ref($rules->{$rule}) eq 'HASH') {
10884: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10885: $rules->{$rule}{'desc'}.'</li>';
10886: }
10887: }
10888: }
10889: }
10890: $output .= '</ul>';
10891: }
10892: }
10893: return $output;
10894: }
10895:
10896: sub instrule_disallow_msg {
1.615 raeburn 10897: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10898: my $response;
10899: my %text = (
10900: item => 'username',
10901: items => 'usernames',
10902: match => 'matches',
10903: do => 'does',
10904: action => 'a username',
10905: one => 'one',
10906: );
10907: if ($count > 1) {
10908: $text{'item'} = 'usernames';
10909: $text{'match'} ='match';
10910: $text{'do'} = 'do';
10911: $text{'action'} = 'usernames',
10912: $text{'one'} = 'ones';
10913: }
10914: if ($checkitem eq 'id') {
10915: $text{'items'} = 'IDs';
10916: $text{'item'} = 'ID';
10917: $text{'action'} = 'an ID';
1.615 raeburn 10918: if ($count > 1) {
10919: $text{'item'} = 'IDs';
10920: $text{'action'} = 'IDs';
10921: }
1.612 raeburn 10922: }
1.674 bisitz 10923: $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 10924: if ($mode eq 'upload') {
10925: if ($checkitem eq 'username') {
10926: $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'}.");
10927: } elsif ($checkitem eq 'id') {
1.674 bisitz 10928: $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 10929: }
1.669 raeburn 10930: } elsif ($mode eq 'selfcreate') {
10931: if ($checkitem eq 'id') {
10932: $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.");
10933: }
1.615 raeburn 10934: } else {
10935: if ($checkitem eq 'username') {
10936: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10937: } elsif ($checkitem eq 'id') {
10938: $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.");
10939: }
1.612 raeburn 10940: }
10941: return $response;
1.585 raeburn 10942: }
10943:
1.624 raeburn 10944: sub personal_data_fieldtitles {
10945: my %fieldtitles = &Apache::lonlocal::texthash (
10946: id => 'Student/Employee ID',
10947: permanentemail => 'E-mail address',
10948: lastname => 'Last Name',
10949: firstname => 'First Name',
10950: middlename => 'Middle Name',
10951: generation => 'Generation',
10952: gen => 'Generation',
1.765 raeburn 10953: inststatus => 'Affiliation',
1.624 raeburn 10954: );
10955: return %fieldtitles;
10956: }
10957:
1.642 raeburn 10958: sub sorted_inst_types {
10959: my ($dom) = @_;
1.1185 raeburn 10960: my ($usertypes,$order);
10961: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10962: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10963: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10964: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10965: } else {
10966: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10967: }
1.642 raeburn 10968: my $othertitle = &mt('All users');
10969: if ($env{'request.course.id'}) {
1.668 raeburn 10970: $othertitle = &mt('Any users');
1.642 raeburn 10971: }
10972: my @types;
10973: if (ref($order) eq 'ARRAY') {
10974: @types = @{$order};
10975: }
10976: if (@types == 0) {
10977: if (ref($usertypes) eq 'HASH') {
10978: @types = sort(keys(%{$usertypes}));
10979: }
10980: }
10981: if (keys(%{$usertypes}) > 0) {
10982: $othertitle = &mt('Other users');
10983: }
10984: return ($othertitle,$usertypes,\@types);
10985: }
10986:
1.645 raeburn 10987: sub get_institutional_codes {
10988: my ($settings,$allcourses,$LC_code) = @_;
10989: # Get complete list of course sections to update
10990: my @currsections = ();
10991: my @currxlists = ();
10992: my $coursecode = $$settings{'internal.coursecode'};
10993:
10994: if ($$settings{'internal.sectionnums'} ne '') {
10995: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10996: }
10997:
10998: if ($$settings{'internal.crosslistings'} ne '') {
10999: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11000: }
11001:
11002: if (@currxlists > 0) {
11003: foreach (@currxlists) {
11004: if (m/^([^:]+):(\w*)$/) {
11005: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11006: push(@{$allcourses},$1);
1.645 raeburn 11007: $$LC_code{$1} = $2;
11008: }
11009: }
11010: }
11011: }
11012:
11013: if (@currsections > 0) {
11014: foreach (@currsections) {
11015: if (m/^(\w+):(\w*)$/) {
11016: my $sec = $coursecode.$1;
11017: my $lc_sec = $2;
11018: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 11019: push(@{$allcourses},$sec);
1.645 raeburn 11020: $$LC_code{$sec} = $lc_sec;
11021: }
11022: }
11023: }
11024: }
11025: return;
11026: }
11027:
1.971 raeburn 11028: sub get_standard_codeitems {
11029: return ('Year','Semester','Department','Number','Section');
11030: }
11031:
1.112 bowersj2 11032: =pod
11033:
1.780 raeburn 11034: =head1 Slot Helpers
11035:
11036: =over 4
11037:
11038: =item * sorted_slots()
11039:
1.1040 raeburn 11040: Sorts an array of slot names in order of an optional sort key,
11041: default sort is by slot start time (earliest first).
1.780 raeburn 11042:
11043: Inputs:
11044:
11045: =over 4
11046:
11047: slotsarr - Reference to array of unsorted slot names.
11048:
11049: slots - Reference to hash of hash, where outer hash keys are slot names.
11050:
1.1040 raeburn 11051: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11052:
1.549 albertel 11053: =back
11054:
1.780 raeburn 11055: Returns:
11056:
11057: =over 4
11058:
1.1040 raeburn 11059: sorted - An array of slot names sorted by a specified sort key
11060: (default sort key is start time of the slot).
1.780 raeburn 11061:
11062: =back
11063:
11064: =cut
11065:
11066:
11067: sub sorted_slots {
1.1040 raeburn 11068: my ($slotsarr,$slots,$sortkey) = @_;
11069: if ($sortkey eq '') {
11070: $sortkey = 'starttime';
11071: }
1.780 raeburn 11072: my @sorted;
11073: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11074: @sorted =
11075: sort {
11076: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11077: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11078: }
11079: if (ref($slots->{$a})) { return -1;}
11080: if (ref($slots->{$b})) { return 1;}
11081: return 0;
11082: } @{$slotsarr};
11083: }
11084: return @sorted;
11085: }
11086:
1.1040 raeburn 11087: =pod
11088:
11089: =item * get_future_slots()
11090:
11091: Inputs:
11092:
11093: =over 4
11094:
11095: cnum - course number
11096:
11097: cdom - course domain
11098:
11099: now - current UNIX time
11100:
11101: symb - optional symb
11102:
11103: =back
11104:
11105: Returns:
11106:
11107: =over 4
11108:
11109: sorted_reservable - ref to array of student_schedulable slots currently
11110: reservable, ordered by end date of reservation period.
11111:
11112: reservable_now - ref to hash of student_schedulable slots currently
11113: reservable.
11114:
11115: Keys in inner hash are:
11116: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11117: (b) endreserve: end date of reservation period.
11118: (c) uniqueperiod: start,end dates when slot is to be uniquely
11119: selected.
1.1040 raeburn 11120:
11121: sorted_future - ref to array of student_schedulable slots reservable in
11122: the future, ordered by start date of reservation period.
11123:
11124: future_reservable - ref to hash of student_schedulable slots reservable
11125: in the future.
11126:
11127: Keys in inner hash are:
11128: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11129: (b) startreserve: start date of reservation period.
11130: (c) uniqueperiod: start,end dates when slot is to be uniquely
11131: selected.
1.1040 raeburn 11132:
11133: =back
11134:
11135: =cut
11136:
11137: sub get_future_slots {
11138: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11139: my $map;
11140: if ($symb) {
11141: ($map) = &Apache::lonnet::decode_symb($symb);
11142: }
1.1040 raeburn 11143: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11144: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11145: foreach my $slot (keys(%slots)) {
11146: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11147: if ($symb) {
1.1229 raeburn 11148: if ($slots{$slot}->{'symb'} ne '') {
11149: my $canuse;
11150: my %oksymbs;
11151: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11152: map { $oksymbs{$_} = 1; } @slotsymbs;
11153: if ($oksymbs{$symb}) {
11154: $canuse = 1;
11155: } else {
11156: foreach my $item (@slotsymbs) {
11157: if ($item =~ /\.(page|sequence)$/) {
11158: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11159: if (($map ne '') && ($map eq $sloturl)) {
11160: $canuse = 1;
11161: last;
11162: }
11163: }
11164: }
11165: }
11166: next unless ($canuse);
11167: }
1.1040 raeburn 11168: }
11169: if (($slots{$slot}->{'starttime'} > $now) &&
11170: ($slots{$slot}->{'endtime'} > $now)) {
11171: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11172: my $userallowed = 0;
11173: if ($slots{$slot}->{'allowedsections'}) {
11174: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11175: if (!defined($env{'request.role.sec'})
11176: && grep(/^No section assigned$/,@allowed_sec)) {
11177: $userallowed=1;
11178: } else {
11179: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11180: $userallowed=1;
11181: }
11182: }
11183: unless ($userallowed) {
11184: if (defined($env{'request.course.groups'})) {
11185: my @groups = split(/:/,$env{'request.course.groups'});
11186: foreach my $group (@groups) {
11187: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11188: $userallowed=1;
11189: last;
11190: }
11191: }
11192: }
11193: }
11194: }
11195: if ($slots{$slot}->{'allowedusers'}) {
11196: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11197: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11198: if (grep(/^\Q$user\E$/,@allowed_users)) {
11199: $userallowed = 1;
11200: }
11201: }
11202: next unless($userallowed);
11203: }
11204: my $startreserve = $slots{$slot}->{'startreserve'};
11205: my $endreserve = $slots{$slot}->{'endreserve'};
11206: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11207: my $uniqueperiod;
11208: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11209: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11210: }
1.1040 raeburn 11211: if (($startreserve < $now) &&
11212: (!$endreserve || $endreserve > $now)) {
11213: my $lastres = $endreserve;
11214: if (!$lastres) {
11215: $lastres = $slots{$slot}->{'starttime'};
11216: }
11217: $reservable_now{$slot} = {
11218: symb => $symb,
1.1250 raeburn 11219: endreserve => $lastres,
11220: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11221: };
11222: } elsif (($startreserve > $now) &&
11223: (!$endreserve || $endreserve > $startreserve)) {
11224: $future_reservable{$slot} = {
11225: symb => $symb,
1.1250 raeburn 11226: startreserve => $startreserve,
11227: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11228: };
11229: }
11230: }
11231: }
11232: my @unsorted_reservable = keys(%reservable_now);
11233: if (@unsorted_reservable > 0) {
11234: @sorted_reservable =
11235: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11236: }
11237: my @unsorted_future = keys(%future_reservable);
11238: if (@unsorted_future > 0) {
11239: @sorted_future =
11240: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11241: }
11242: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11243: }
1.780 raeburn 11244:
11245: =pod
11246:
1.1057 foxr 11247: =back
11248:
1.549 albertel 11249: =head1 HTTP Helpers
11250:
11251: =over 4
11252:
1.648 raeburn 11253: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11254:
1.258 albertel 11255: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11256: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11257: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11258:
11259: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11260: $possible_names is an ref to an array of form element names. As an example:
11261: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11262: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11263:
11264: =cut
1.1 albertel 11265:
1.6 albertel 11266: sub get_unprocessed_cgi {
1.25 albertel 11267: my ($query,$possible_names)= @_;
1.26 matthew 11268: # $Apache::lonxml::debug=1;
1.356 albertel 11269: foreach my $pair (split(/&/,$query)) {
11270: my ($name, $value) = split(/=/,$pair);
1.369 www 11271: $name = &unescape($name);
1.25 albertel 11272: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11273: $value =~ tr/+/ /;
11274: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11275: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11276: }
1.16 harris41 11277: }
1.6 albertel 11278: }
11279:
1.112 bowersj2 11280: =pod
11281:
1.648 raeburn 11282: =item * &cacheheader()
1.112 bowersj2 11283:
11284: returns cache-controlling header code
11285:
11286: =cut
11287:
1.7 albertel 11288: sub cacheheader {
1.258 albertel 11289: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11290: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11291: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11292: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11293: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11294: return $output;
1.7 albertel 11295: }
11296:
1.112 bowersj2 11297: =pod
11298:
1.648 raeburn 11299: =item * &no_cache($r)
1.112 bowersj2 11300:
11301: specifies header code to not have cache
11302:
11303: =cut
11304:
1.9 albertel 11305: sub no_cache {
1.216 albertel 11306: my ($r) = @_;
11307: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11308: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11309: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11310: $r->no_cache(1);
11311: $r->header_out("Expires" => $date);
11312: $r->header_out("Pragma" => "no-cache");
1.123 www 11313: }
11314:
11315: sub content_type {
1.181 albertel 11316: my ($r,$type,$charset) = @_;
1.299 foxr 11317: if ($r) {
11318: # Note that printout.pl calls this with undef for $r.
11319: &no_cache($r);
11320: }
1.258 albertel 11321: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11322: unless ($charset) {
11323: $charset=&Apache::lonlocal::current_encoding;
11324: }
11325: if ($charset) { $type.='; charset='.$charset; }
11326: if ($r) {
11327: $r->content_type($type);
11328: } else {
11329: print("Content-type: $type\n\n");
11330: }
1.9 albertel 11331: }
1.25 albertel 11332:
1.112 bowersj2 11333: =pod
11334:
1.648 raeburn 11335: =item * &add_to_env($name,$value)
1.112 bowersj2 11336:
1.258 albertel 11337: adds $name to the %env hash with value
1.112 bowersj2 11338: $value, if $name already exists, the entry is converted to an array
11339: reference and $value is added to the array.
11340:
11341: =cut
11342:
1.25 albertel 11343: sub add_to_env {
11344: my ($name,$value)=@_;
1.258 albertel 11345: if (defined($env{$name})) {
11346: if (ref($env{$name})) {
1.25 albertel 11347: #already have multiple values
1.258 albertel 11348: push(@{ $env{$name} },$value);
1.25 albertel 11349: } else {
11350: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11351: my $first=$env{$name};
11352: undef($env{$name});
11353: push(@{ $env{$name} },$first,$value);
1.25 albertel 11354: }
11355: } else {
1.258 albertel 11356: $env{$name}=$value;
1.25 albertel 11357: }
1.31 albertel 11358: }
1.149 albertel 11359:
11360: =pod
11361:
1.648 raeburn 11362: =item * &get_env_multiple($name)
1.149 albertel 11363:
1.258 albertel 11364: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11365: values may be defined and end up as an array ref.
11366:
11367: returns an array of values
11368:
11369: =cut
11370:
11371: sub get_env_multiple {
11372: my ($name) = @_;
11373: my @values;
1.258 albertel 11374: if (defined($env{$name})) {
1.149 albertel 11375: # exists is it an array
1.258 albertel 11376: if (ref($env{$name})) {
11377: @values=@{ $env{$name} };
1.149 albertel 11378: } else {
1.258 albertel 11379: $values[0]=$env{$name};
1.149 albertel 11380: }
11381: }
11382: return(@values);
11383: }
11384:
1.1249 damieng 11385: # Looks at given dependencies, and returns something depending on the context.
11386: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11387: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11388: # For all other contexts, returns ($output, $counter, $numpathchg).
11389: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11390: # $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.
11391: # $numpathchg: integer with the number of cleaned up dependency paths.
11392: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11393: # \%mapping: hash reference clean path -> original path for all dependencies.
11394: # @param {string} actionurl - The path to the handler, indicative of the context.
11395: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11396: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11397: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11398: # @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)
11399: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11400: sub ask_for_embedded_content {
1.1249 damieng 11401: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11402: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11403: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11404: %currsubfile,%unused,$rem);
1.1071 raeburn 11405: my $counter = 0;
11406: my $numnew = 0;
1.987 raeburn 11407: my $numremref = 0;
11408: my $numinvalid = 0;
11409: my $numpathchg = 0;
11410: my $numexisting = 0;
1.1071 raeburn 11411: my $numunused = 0;
11412: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11413: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11414: my $heading = &mt('Upload embedded files');
11415: my $buttontext = &mt('Upload');
11416:
1.1249 damieng 11417: # fills these variables based on the context:
11418: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11419: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11420: if ($env{'request.course.id'}) {
1.1123 raeburn 11421: if ($actionurl eq '/adm/dependencies') {
11422: $navmap = Apache::lonnavmaps::navmap->new();
11423: }
11424: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11425: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11426: }
1.1123 raeburn 11427: if (($actionurl eq '/adm/portfolio') ||
11428: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11429: my $current_path='/';
11430: if ($env{'form.currentpath'}) {
11431: $current_path = $env{'form.currentpath'};
11432: }
11433: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11434: $udom = $cdom;
11435: $uname = $cnum;
1.984 raeburn 11436: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11437: } else {
11438: $udom = $env{'user.domain'};
11439: $uname = $env{'user.name'};
11440: $url = '/userfiles/portfolio';
11441: }
1.987 raeburn 11442: $toplevel = $url.'/';
1.984 raeburn 11443: $url .= $current_path;
11444: $getpropath = 1;
1.987 raeburn 11445: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11446: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11447: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11448: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11449: $toplevel = $url;
1.984 raeburn 11450: if ($rest ne '') {
1.987 raeburn 11451: $url .= $rest;
11452: }
11453: } elsif ($actionurl eq '/adm/coursedocs') {
11454: if (ref($args) eq 'HASH') {
1.1071 raeburn 11455: $url = $args->{'docs_url'};
11456: $toplevel = $url;
1.1084 raeburn 11457: if ($args->{'context'} eq 'paste') {
11458: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11459: ($path) =
11460: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11461: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11462: $fileloc =~ s{^/}{};
11463: }
1.1071 raeburn 11464: }
1.1084 raeburn 11465: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11466: if ($env{'request.course.id'} ne '') {
11467: if (ref($args) eq 'HASH') {
11468: $url = $args->{'docs_url'};
11469: $title = $args->{'docs_title'};
1.1126 raeburn 11470: $toplevel = $url;
11471: unless ($toplevel =~ m{^/}) {
11472: $toplevel = "/$url";
11473: }
1.1085 raeburn 11474: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11475: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11476: $path = $1;
11477: } else {
11478: ($path) =
11479: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11480: }
1.1195 raeburn 11481: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11482: $fileloc = $toplevel;
11483: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11484: my ($udom,$uname,$fname) =
11485: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11486: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11487: } else {
11488: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11489: }
1.1071 raeburn 11490: $fileloc =~ s{^/}{};
11491: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11492: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11493: }
1.987 raeburn 11494: }
1.1123 raeburn 11495: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11496: $udom = $cdom;
11497: $uname = $cnum;
11498: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11499: $toplevel = $url;
11500: $path = $url;
11501: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11502: $fileloc =~ s{^/}{};
1.987 raeburn 11503: }
1.1249 damieng 11504:
11505: # parses the dependency paths to get some info
11506: # fills $newfiles, $mapping, $subdependencies, $dependencies
11507: # $newfiles: hash URL -> 1 for new files or external URLs
11508: # (will be completed later)
11509: # $mapping:
11510: # for external URLs: external URL -> external URL
11511: # for relative paths: clean path -> original path
11512: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11513: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11514: foreach my $file (keys(%{$allfiles})) {
11515: my $embed_file;
11516: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11517: $embed_file = $1;
11518: } else {
11519: $embed_file = $file;
11520: }
1.1158 raeburn 11521: my ($absolutepath,$cleaned_file);
11522: if ($embed_file =~ m{^\w+://}) {
11523: $cleaned_file = $embed_file;
1.1147 raeburn 11524: $newfiles{$cleaned_file} = 1;
11525: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11526: } else {
1.1158 raeburn 11527: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11528: if ($embed_file =~ m{^/}) {
11529: $absolutepath = $embed_file;
11530: }
1.1147 raeburn 11531: if ($cleaned_file =~ m{/}) {
11532: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11533: $path = &check_for_traversal($path,$url,$toplevel);
11534: my $item = $fname;
11535: if ($path ne '') {
11536: $item = $path.'/'.$fname;
11537: $subdependencies{$path}{$fname} = 1;
11538: } else {
11539: $dependencies{$item} = 1;
11540: }
11541: if ($absolutepath) {
11542: $mapping{$item} = $absolutepath;
11543: } else {
11544: $mapping{$item} = $embed_file;
11545: }
11546: } else {
11547: $dependencies{$embed_file} = 1;
11548: if ($absolutepath) {
1.1147 raeburn 11549: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11550: } else {
1.1147 raeburn 11551: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11552: }
11553: }
1.984 raeburn 11554: }
11555: }
1.1249 damieng 11556:
11557: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11558: # and lists
11559: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11560: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11561: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11562: # the path had to be cleaned up
11563: # $existing: hash clean path -> 1 if the file exists
11564: # $numexisting: number of keys in $existing
11565: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11566: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11567: # dependency subdirectories that are
11568: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11569: my $dirptr = 16384;
1.984 raeburn 11570: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11571: $currsubfile{$path} = {};
1.1123 raeburn 11572: if (($actionurl eq '/adm/portfolio') ||
11573: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11574: my ($sublistref,$listerror) =
11575: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11576: if (ref($sublistref) eq 'ARRAY') {
11577: foreach my $line (@{$sublistref}) {
11578: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11579: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11580: }
1.984 raeburn 11581: }
1.987 raeburn 11582: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11583: if (opendir(my $dir,$url.'/'.$path)) {
11584: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11585: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11586: }
1.1084 raeburn 11587: } elsif (($actionurl eq '/adm/dependencies') ||
11588: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11589: ($args->{'context'} eq 'paste')) ||
11590: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11591: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11592: my $dir;
11593: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11594: $dir = $fileloc;
11595: } else {
11596: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11597: }
1.1071 raeburn 11598: if ($dir ne '') {
11599: my ($sublistref,$listerror) =
11600: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11601: if (ref($sublistref) eq 'ARRAY') {
11602: foreach my $line (@{$sublistref}) {
11603: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11604: undef,$mtime)=split(/\&/,$line,12);
11605: unless (($testdir&$dirptr) ||
11606: ($file_name =~ /^\.\.?$/)) {
11607: $currsubfile{$path}{$file_name} = [$size,$mtime];
11608: }
11609: }
11610: }
11611: }
1.984 raeburn 11612: }
11613: }
11614: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11615: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11616: my $item = $path.'/'.$file;
11617: unless ($mapping{$item} eq $item) {
11618: $pathchanges{$item} = 1;
11619: }
11620: $existing{$item} = 1;
11621: $numexisting ++;
11622: } else {
11623: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11624: }
11625: }
1.1071 raeburn 11626: if ($actionurl eq '/adm/dependencies') {
11627: foreach my $path (keys(%currsubfile)) {
11628: if (ref($currsubfile{$path}) eq 'HASH') {
11629: foreach my $file (keys(%{$currsubfile{$path}})) {
11630: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11631: next if (($rem ne '') &&
11632: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11633: (ref($navmap) &&
11634: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11635: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11636: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11637: $unused{$path.'/'.$file} = 1;
11638: }
11639: }
11640: }
11641: }
11642: }
1.984 raeburn 11643: }
1.1249 damieng 11644:
11645: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11646: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11647: my %currfile;
1.1123 raeburn 11648: if (($actionurl eq '/adm/portfolio') ||
11649: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11650: my ($dirlistref,$listerror) =
11651: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11652: if (ref($dirlistref) eq 'ARRAY') {
11653: foreach my $line (@{$dirlistref}) {
11654: my ($file_name,$rest) = split(/\&/,$line,2);
11655: $currfile{$file_name} = 1;
11656: }
1.984 raeburn 11657: }
1.987 raeburn 11658: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11659: if (opendir(my $dir,$url)) {
1.987 raeburn 11660: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11661: map {$currfile{$_} = 1;} @dir_list;
11662: }
1.1084 raeburn 11663: } elsif (($actionurl eq '/adm/dependencies') ||
11664: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11665: ($args->{'context'} eq 'paste')) ||
11666: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11667: if ($env{'request.course.id'} ne '') {
11668: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11669: if ($dir ne '') {
11670: my ($dirlistref,$listerror) =
11671: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11672: if (ref($dirlistref) eq 'ARRAY') {
11673: foreach my $line (@{$dirlistref}) {
11674: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11675: $size,undef,$mtime)=split(/\&/,$line,12);
11676: unless (($testdir&$dirptr) ||
11677: ($file_name =~ /^\.\.?$/)) {
11678: $currfile{$file_name} = [$size,$mtime];
11679: }
11680: }
11681: }
11682: }
11683: }
1.984 raeburn 11684: }
1.1249 damieng 11685: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11686: # are not in subdirectories, using $currfile
1.984 raeburn 11687: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11688: if (exists($currfile{$file})) {
1.987 raeburn 11689: unless ($mapping{$file} eq $file) {
11690: $pathchanges{$file} = 1;
11691: }
11692: $existing{$file} = 1;
11693: $numexisting ++;
11694: } else {
1.984 raeburn 11695: $newfiles{$file} = 1;
11696: }
11697: }
1.1071 raeburn 11698: foreach my $file (keys(%currfile)) {
11699: unless (($file eq $filename) ||
11700: ($file eq $filename.'.bak') ||
11701: ($dependencies{$file})) {
1.1085 raeburn 11702: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11703: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11704: next if (($rem ne '') &&
11705: (($env{"httpref.$rem".$file} ne '') ||
11706: (ref($navmap) &&
11707: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11708: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11709: ($navmap->getResourceByUrl($rem.$1)))))));
11710: }
1.1085 raeburn 11711: }
1.1071 raeburn 11712: $unused{$file} = 1;
11713: }
11714: }
1.1249 damieng 11715:
11716: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11717: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11718: ($args->{'context'} eq 'paste')) {
11719: $counter = scalar(keys(%existing));
11720: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11721: return ($output,$counter,$numpathchg,\%existing);
11722: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11723: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11724: $counter = scalar(keys(%existing));
11725: $numpathchg = scalar(keys(%pathchanges));
11726: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11727: }
1.1249 damieng 11728:
11729: # returns HTML otherwise, with dependency results and to ask for more uploads
11730:
11731: # $upload_output: missing dependencies (with upload form)
11732: # $modify_output: uploaded dependencies (in use)
11733: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11734: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11735: if ($actionurl eq '/adm/dependencies') {
11736: next if ($embed_file =~ m{^\w+://});
11737: }
1.660 raeburn 11738: $upload_output .= &start_data_table_row().
1.1123 raeburn 11739: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11740: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11741: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11742: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11743: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11744: }
1.1123 raeburn 11745: $upload_output .= '</td>';
1.1071 raeburn 11746: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11747: $upload_output.='<td align="right">'.
11748: '<span class="LC_info LC_fontsize_medium">'.
11749: &mt("URL points to web address").'</span>';
1.987 raeburn 11750: $numremref++;
1.660 raeburn 11751: } elsif ($args->{'error_on_invalid_names'}
11752: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11753: $upload_output.='<td align="right"><span class="LC_warning">'.
11754: &mt('Invalid characters').'</span>';
1.987 raeburn 11755: $numinvalid++;
1.660 raeburn 11756: } else {
1.1123 raeburn 11757: $upload_output .= '<td>'.
11758: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11759: $embed_file,\%mapping,
1.1071 raeburn 11760: $allfiles,$codebase,'upload');
11761: $counter ++;
11762: $numnew ++;
1.987 raeburn 11763: }
11764: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11765: }
11766: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11767: if ($actionurl eq '/adm/dependencies') {
11768: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11769: $modify_output .= &start_data_table_row().
11770: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11771: '<img src="'.&icon($embed_file).'" border="0" />'.
11772: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11773: '<td>'.$size.'</td>'.
11774: '<td>'.$mtime.'</td>'.
11775: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11776: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11777: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11778: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11779: &embedded_file_element('upload_embedded',$counter,
11780: $embed_file,\%mapping,
11781: $allfiles,$codebase,'modify').
11782: '</div></td>'.
11783: &end_data_table_row()."\n";
11784: $counter ++;
11785: } else {
11786: $upload_output .= &start_data_table_row().
1.1123 raeburn 11787: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11788: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11789: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11790: &Apache::loncommon::end_data_table_row()."\n";
11791: }
11792: }
11793: my $delidx = $counter;
11794: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11795: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11796: $delete_output .= &start_data_table_row().
11797: '<td><img src="'.&icon($oldfile).'" />'.
11798: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11799: '<td>'.$size.'</td>'.
11800: '<td>'.$mtime.'</td>'.
11801: '<td><label><input type="checkbox" name="del_upload_dep" '.
11802: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11803: &embedded_file_element('upload_embedded',$delidx,
11804: $oldfile,\%mapping,$allfiles,
11805: $codebase,'delete').'</td>'.
11806: &end_data_table_row()."\n";
11807: $numunused ++;
11808: $delidx ++;
1.987 raeburn 11809: }
11810: if ($upload_output) {
11811: $upload_output = &start_data_table().
11812: $upload_output.
11813: &end_data_table()."\n";
11814: }
1.1071 raeburn 11815: if ($modify_output) {
11816: $modify_output = &start_data_table().
11817: &start_data_table_header_row().
11818: '<th>'.&mt('File').'</th>'.
11819: '<th>'.&mt('Size (KB)').'</th>'.
11820: '<th>'.&mt('Modified').'</th>'.
11821: '<th>'.&mt('Upload replacement?').'</th>'.
11822: &end_data_table_header_row().
11823: $modify_output.
11824: &end_data_table()."\n";
11825: }
11826: if ($delete_output) {
11827: $delete_output = &start_data_table().
11828: &start_data_table_header_row().
11829: '<th>'.&mt('File').'</th>'.
11830: '<th>'.&mt('Size (KB)').'</th>'.
11831: '<th>'.&mt('Modified').'</th>'.
11832: '<th>'.&mt('Delete?').'</th>'.
11833: &end_data_table_header_row().
11834: $delete_output.
11835: &end_data_table()."\n";
11836: }
1.987 raeburn 11837: my $applies = 0;
11838: if ($numremref) {
11839: $applies ++;
11840: }
11841: if ($numinvalid) {
11842: $applies ++;
11843: }
11844: if ($numexisting) {
11845: $applies ++;
11846: }
1.1071 raeburn 11847: if ($counter || $numunused) {
1.987 raeburn 11848: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11849: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11850: $state.'<h3>'.$heading.'</h3>';
11851: if ($actionurl eq '/adm/dependencies') {
11852: if ($numnew) {
11853: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11854: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11855: $upload_output.'<br />'."\n";
11856: }
11857: if ($numexisting) {
11858: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11859: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11860: $modify_output.'<br />'."\n";
11861: $buttontext = &mt('Save changes');
11862: }
11863: if ($numunused) {
11864: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11865: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11866: $delete_output.'<br />'."\n";
11867: $buttontext = &mt('Save changes');
11868: }
11869: } else {
11870: $output .= $upload_output.'<br />'."\n";
11871: }
11872: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11873: $counter.'" />'."\n";
11874: if ($actionurl eq '/adm/dependencies') {
11875: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11876: $numnew.'" />'."\n";
11877: } elsif ($actionurl eq '') {
1.987 raeburn 11878: $output .= '<input type="hidden" name="phase" value="three" />';
11879: }
11880: } elsif ($applies) {
11881: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11882: if ($applies > 1) {
11883: $output .=
1.1123 raeburn 11884: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11885: if ($numremref) {
11886: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11887: }
11888: if ($numinvalid) {
11889: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11890: }
11891: if ($numexisting) {
11892: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11893: }
11894: $output .= '</ul><br />';
11895: } elsif ($numremref) {
11896: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11897: } elsif ($numinvalid) {
11898: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11899: } elsif ($numexisting) {
11900: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11901: }
11902: $output .= $upload_output.'<br />';
11903: }
11904: my ($pathchange_output,$chgcount);
1.1071 raeburn 11905: $chgcount = $counter;
1.987 raeburn 11906: if (keys(%pathchanges) > 0) {
11907: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11908: if ($counter) {
1.987 raeburn 11909: $output .= &embedded_file_element('pathchange',$chgcount,
11910: $embed_file,\%mapping,
1.1071 raeburn 11911: $allfiles,$codebase,'change');
1.987 raeburn 11912: } else {
11913: $pathchange_output .=
11914: &start_data_table_row().
11915: '<td><input type ="checkbox" name="namechange" value="'.
11916: $chgcount.'" checked="checked" /></td>'.
11917: '<td>'.$mapping{$embed_file}.'</td>'.
11918: '<td>'.$embed_file.
11919: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11920: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11921: '</td>'.&end_data_table_row();
1.660 raeburn 11922: }
1.987 raeburn 11923: $numpathchg ++;
11924: $chgcount ++;
1.660 raeburn 11925: }
11926: }
1.1127 raeburn 11927: if (($counter) || ($numunused)) {
1.987 raeburn 11928: if ($numpathchg) {
11929: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11930: $numpathchg.'" />'."\n";
11931: }
11932: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11933: ($actionurl eq '/adm/imsimport')) {
11934: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11935: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11936: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11937: } elsif ($actionurl eq '/adm/dependencies') {
11938: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11939: }
1.1123 raeburn 11940: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11941: } elsif ($numpathchg) {
11942: my %pathchange = ();
11943: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11944: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11945: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11946: }
1.987 raeburn 11947: }
1.1071 raeburn 11948: return ($output,$counter,$numpathchg);
1.987 raeburn 11949: }
11950:
1.1147 raeburn 11951: =pod
11952:
11953: =item * clean_path($name)
11954:
11955: Performs clean-up of directories, subdirectories and filename in an
11956: embedded object, referenced in an HTML file which is being uploaded
11957: to a course or portfolio, where
11958: "Upload embedded images/multimedia files if HTML file" checkbox was
11959: checked.
11960:
11961: Clean-up is similar to replacements in lonnet::clean_filename()
11962: except each / between sub-directory and next level is preserved.
11963:
11964: =cut
11965:
11966: sub clean_path {
11967: my ($embed_file) = @_;
11968: $embed_file =~s{^/+}{};
11969: my @contents;
11970: if ($embed_file =~ m{/}) {
11971: @contents = split(/\//,$embed_file);
11972: } else {
11973: @contents = ($embed_file);
11974: }
11975: my $lastidx = scalar(@contents)-1;
11976: for (my $i=0; $i<=$lastidx; $i++) {
11977: $contents[$i]=~s{\\}{/}g;
11978: $contents[$i]=~s/\s+/\_/g;
11979: $contents[$i]=~s{[^/\w\.\-]}{}g;
11980: if ($i == $lastidx) {
11981: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11982: }
11983: }
11984: if ($lastidx > 0) {
11985: return join('/',@contents);
11986: } else {
11987: return $contents[0];
11988: }
11989: }
11990:
1.987 raeburn 11991: sub embedded_file_element {
1.1071 raeburn 11992: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11993: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11994: (ref($codebase) eq 'HASH'));
11995: my $output;
1.1071 raeburn 11996: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11997: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11998: }
11999: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12000: &escape($embed_file).'" />';
12001: unless (($context eq 'upload_embedded') &&
12002: ($mapping->{$embed_file} eq $embed_file)) {
12003: $output .='
12004: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12005: }
12006: my $attrib;
12007: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12008: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12009: }
12010: $output .=
12011: "\n\t\t".
12012: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12013: $attrib.'" />';
12014: if (exists($codebase->{$mapping->{$embed_file}})) {
12015: $output .=
12016: "\n\t\t".
12017: '<input name="codebase_'.$num.'" type="hidden" value="'.
12018: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12019: }
1.987 raeburn 12020: return $output;
1.660 raeburn 12021: }
12022:
1.1071 raeburn 12023: sub get_dependency_details {
12024: my ($currfile,$currsubfile,$embed_file) = @_;
12025: my ($size,$mtime,$showsize,$showmtime);
12026: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12027: if ($embed_file =~ m{/}) {
12028: my ($path,$fname) = split(/\//,$embed_file);
12029: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12030: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12031: }
12032: } else {
12033: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12034: ($size,$mtime) = @{$currfile->{$embed_file}};
12035: }
12036: }
12037: $showsize = $size/1024.0;
12038: $showsize = sprintf("%.1f",$showsize);
12039: if ($mtime > 0) {
12040: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12041: }
12042: }
12043: return ($showsize,$showmtime);
12044: }
12045:
12046: sub ask_embedded_js {
12047: return <<"END";
12048: <script type="text/javascript"">
12049: // <![CDATA[
12050: function toggleBrowse(counter) {
12051: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12052: var fileid = document.getElementById('embedded_item_'+counter);
12053: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12054: if (chkboxid.checked == true) {
12055: uploaddivid.style.display='block';
12056: } else {
12057: uploaddivid.style.display='none';
12058: fileid.value = '';
12059: }
12060: }
12061: // ]]>
12062: </script>
12063:
12064: END
12065: }
12066:
1.661 raeburn 12067: sub upload_embedded {
12068: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12069: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12070: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12071: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12072: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12073: my $orig_uploaded_filename =
12074: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12075: foreach my $type ('orig','ref','attrib','codebase') {
12076: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12077: $env{'form.embedded_'.$type.'_'.$i} =
12078: &unescape($env{'form.embedded_'.$type.'_'.$i});
12079: }
12080: }
1.661 raeburn 12081: my ($path,$fname) =
12082: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12083: # no path, whole string is fname
12084: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12085: $fname = &Apache::lonnet::clean_filename($fname);
12086: # See if there is anything left
12087: next if ($fname eq '');
12088:
12089: # Check if file already exists as a file or directory.
12090: my ($state,$msg);
12091: if ($context eq 'portfolio') {
12092: my $port_path = $dirpath;
12093: if ($group ne '') {
12094: $port_path = "groups/$group/$port_path";
12095: }
1.987 raeburn 12096: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12097: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12098: $dir_root,$port_path,$disk_quota,
12099: $current_disk_usage,$uname,$udom);
12100: if ($state eq 'will_exceed_quota'
1.984 raeburn 12101: || $state eq 'file_locked') {
1.661 raeburn 12102: $output .= $msg;
12103: next;
12104: }
12105: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12106: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12107: if ($state eq 'exists') {
12108: $output .= $msg;
12109: next;
12110: }
12111: }
12112: # Check if extension is valid
12113: if (($fname =~ /\.(\w+)$/) &&
12114: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12115: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12116: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12117: next;
12118: } elsif (($fname =~ /\.(\w+)$/) &&
12119: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12120: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12121: next;
12122: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12123: $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 12124: next;
12125: }
12126: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12127: my $subdir = $path;
12128: $subdir =~ s{/+$}{};
1.661 raeburn 12129: if ($context eq 'portfolio') {
1.984 raeburn 12130: my $result;
12131: if ($state eq 'existingfile') {
12132: $result=
12133: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12134: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12135: } else {
1.984 raeburn 12136: $result=
12137: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12138: $dirpath.
1.1123 raeburn 12139: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12140: if ($result !~ m|^/uploaded/|) {
12141: $output .= '<span class="LC_error">'
12142: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12143: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12144: .'</span><br />';
12145: next;
12146: } else {
1.987 raeburn 12147: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12148: $path.$fname.'</span>').'<br />';
1.984 raeburn 12149: }
1.661 raeburn 12150: }
1.1123 raeburn 12151: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12152: my $extendedsubdir = $dirpath.'/'.$subdir;
12153: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12154: my $result =
1.1126 raeburn 12155: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12156: if ($result !~ m|^/uploaded/|) {
12157: $output .= '<span class="LC_error">'
12158: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12159: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12160: .'</span><br />';
12161: next;
12162: } else {
12163: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12164: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12165: if ($context eq 'syllabus') {
12166: &Apache::lonnet::make_public_indefinitely($result);
12167: }
1.987 raeburn 12168: }
1.661 raeburn 12169: } else {
12170: # Save the file
12171: my $target = $env{'form.embedded_item_'.$i};
12172: my $fullpath = $dir_root.$dirpath.'/'.$path;
12173: my $dest = $fullpath.$fname;
12174: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12175: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12176: my $count;
12177: my $filepath = $dir_root;
1.1027 raeburn 12178: foreach my $subdir (@parts) {
12179: $filepath .= "/$subdir";
12180: if (!-e $filepath) {
1.661 raeburn 12181: mkdir($filepath,0770);
12182: }
12183: }
12184: my $fh;
12185: if (!open($fh,'>'.$dest)) {
12186: &Apache::lonnet::logthis('Failed to create '.$dest);
12187: $output .= '<span class="LC_error">'.
1.1071 raeburn 12188: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12189: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12190: '</span><br />';
12191: } else {
12192: if (!print $fh $env{'form.embedded_item_'.$i}) {
12193: &Apache::lonnet::logthis('Failed to write to '.$dest);
12194: $output .= '<span class="LC_error">'.
1.1071 raeburn 12195: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12196: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12197: '</span><br />';
12198: } else {
1.987 raeburn 12199: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12200: $url.'</span>').'<br />';
12201: unless ($context eq 'testbank') {
12202: $footer .= &mt('View embedded file: [_1]',
12203: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12204: }
12205: }
12206: close($fh);
12207: }
12208: }
12209: if ($env{'form.embedded_ref_'.$i}) {
12210: $pathchange{$i} = 1;
12211: }
12212: }
12213: if ($output) {
12214: $output = '<p>'.$output.'</p>';
12215: }
12216: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12217: $returnflag = 'ok';
1.1071 raeburn 12218: my $numpathchgs = scalar(keys(%pathchange));
12219: if ($numpathchgs > 0) {
1.987 raeburn 12220: if ($context eq 'portfolio') {
12221: $output .= '<p>'.&mt('or').'</p>';
12222: } elsif ($context eq 'testbank') {
1.1071 raeburn 12223: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12224: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12225: $returnflag = 'modify_orightml';
12226: }
12227: }
1.1071 raeburn 12228: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12229: }
12230:
12231: sub modify_html_form {
12232: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12233: my $end = 0;
12234: my $modifyform;
12235: if ($context eq 'upload_embedded') {
12236: return unless (ref($pathchange) eq 'HASH');
12237: if ($env{'form.number_embedded_items'}) {
12238: $end += $env{'form.number_embedded_items'};
12239: }
12240: if ($env{'form.number_pathchange_items'}) {
12241: $end += $env{'form.number_pathchange_items'};
12242: }
12243: if ($end) {
12244: for (my $i=0; $i<$end; $i++) {
12245: if ($i < $env{'form.number_embedded_items'}) {
12246: next unless($pathchange->{$i});
12247: }
12248: $modifyform .=
12249: &start_data_table_row().
12250: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12251: 'checked="checked" /></td>'.
12252: '<td>'.$env{'form.embedded_ref_'.$i}.
12253: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12254: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12255: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12256: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12257: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12258: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12259: '<td>'.$env{'form.embedded_orig_'.$i}.
12260: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12261: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12262: &end_data_table_row();
1.1071 raeburn 12263: }
1.987 raeburn 12264: }
12265: } else {
12266: $modifyform = $pathchgtable;
12267: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12268: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12269: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12270: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12271: }
12272: }
12273: if ($modifyform) {
1.1071 raeburn 12274: if ($actionurl eq '/adm/dependencies') {
12275: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12276: }
1.987 raeburn 12277: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12278: '<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".
12279: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12280: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12281: '</ol></p>'."\n".'<p>'.
12282: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12283: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12284: &start_data_table()."\n".
12285: &start_data_table_header_row().
12286: '<th>'.&mt('Change?').'</th>'.
12287: '<th>'.&mt('Current reference').'</th>'.
12288: '<th>'.&mt('Required reference').'</th>'.
12289: &end_data_table_header_row()."\n".
12290: $modifyform.
12291: &end_data_table().'<br />'."\n".$hiddenstate.
12292: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12293: '</form>'."\n";
12294: }
12295: return;
12296: }
12297:
12298: sub modify_html_refs {
1.1123 raeburn 12299: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12300: my $container;
12301: if ($context eq 'portfolio') {
12302: $container = $env{'form.container'};
12303: } elsif ($context eq 'coursedoc') {
12304: $container = $env{'form.primaryurl'};
1.1071 raeburn 12305: } elsif ($context eq 'manage_dependencies') {
12306: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12307: $container = "/$container";
1.1123 raeburn 12308: } elsif ($context eq 'syllabus') {
12309: $container = $url;
1.987 raeburn 12310: } else {
1.1027 raeburn 12311: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12312: }
12313: my (%allfiles,%codebase,$output,$content);
12314: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12315: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12316: if (wantarray) {
12317: return ('',0,0);
12318: } else {
12319: return;
12320: }
12321: }
12322: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12323: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12324: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12325: if (wantarray) {
12326: return ('',0,0);
12327: } else {
12328: return;
12329: }
12330: }
1.987 raeburn 12331: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12332: if ($content eq '-1') {
12333: if (wantarray) {
12334: return ('',0,0);
12335: } else {
12336: return;
12337: }
12338: }
1.987 raeburn 12339: } else {
1.1071 raeburn 12340: unless ($container =~ /^\Q$dir_root\E/) {
12341: if (wantarray) {
12342: return ('',0,0);
12343: } else {
12344: return;
12345: }
12346: }
1.1317 raeburn 12347: if (open(my $fh,'<',$container)) {
1.987 raeburn 12348: $content = join('', <$fh>);
12349: close($fh);
12350: } else {
1.1071 raeburn 12351: if (wantarray) {
12352: return ('',0,0);
12353: } else {
12354: return;
12355: }
1.987 raeburn 12356: }
12357: }
12358: my ($count,$codebasecount) = (0,0);
12359: my $mm = new File::MMagic;
12360: my $mime_type = $mm->checktype_contents($content);
12361: if ($mime_type eq 'text/html') {
12362: my $parse_result =
12363: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12364: \%codebase,\$content);
12365: if ($parse_result eq 'ok') {
12366: foreach my $i (@changes) {
12367: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12368: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12369: if ($allfiles{$ref}) {
12370: my $newname = $orig;
12371: my ($attrib_regexp,$codebase);
1.1006 raeburn 12372: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12373: if ($attrib_regexp =~ /:/) {
12374: $attrib_regexp =~ s/\:/|/g;
12375: }
12376: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12377: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12378: $count += $numchg;
1.1123 raeburn 12379: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12380: delete($allfiles{$ref});
1.987 raeburn 12381: }
12382: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12383: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12384: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12385: $codebasecount ++;
12386: }
12387: }
12388: }
1.1123 raeburn 12389: my $skiprewrites;
1.987 raeburn 12390: if ($count || $codebasecount) {
12391: my $saveresult;
1.1071 raeburn 12392: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12393: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12394: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12395: if ($url eq $container) {
12396: my ($fname) = ($container =~ m{/([^/]+)$});
12397: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12398: $count,'<span class="LC_filename">'.
1.1071 raeburn 12399: $fname.'</span>').'</p>';
1.987 raeburn 12400: } else {
12401: $output = '<p class="LC_error">'.
12402: &mt('Error: update failed for: [_1].',
12403: '<span class="LC_filename">'.
12404: $container.'</span>').'</p>';
12405: }
1.1123 raeburn 12406: if ($context eq 'syllabus') {
12407: unless ($saveresult eq 'ok') {
12408: $skiprewrites = 1;
12409: }
12410: }
1.987 raeburn 12411: } else {
1.1317 raeburn 12412: if (open(my $fh,'>',$container)) {
1.987 raeburn 12413: print $fh $content;
12414: close($fh);
12415: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12416: $count,'<span class="LC_filename">'.
12417: $container.'</span>').'</p>';
1.661 raeburn 12418: } else {
1.987 raeburn 12419: $output = '<p class="LC_error">'.
12420: &mt('Error: could not update [_1].',
12421: '<span class="LC_filename">'.
12422: $container.'</span>').'</p>';
1.661 raeburn 12423: }
12424: }
12425: }
1.1123 raeburn 12426: if (($context eq 'syllabus') && (!$skiprewrites)) {
12427: my ($actionurl,$state);
12428: $actionurl = "/public/$udom/$uname/syllabus";
12429: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12430: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12431: \%codebase,
12432: {'context' => 'rewrites',
12433: 'ignore_remote_references' => 1,});
12434: if (ref($mapping) eq 'HASH') {
12435: my $rewrites = 0;
12436: foreach my $key (keys(%{$mapping})) {
12437: next if ($key =~ m{^https?://});
12438: my $ref = $mapping->{$key};
12439: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12440: my $attrib;
12441: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12442: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12443: }
12444: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12445: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12446: $rewrites += $numchg;
12447: }
12448: }
12449: if ($rewrites) {
12450: my $saveresult;
12451: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12452: if ($url eq $container) {
12453: my ($fname) = ($container =~ m{/([^/]+)$});
12454: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12455: $count,'<span class="LC_filename">'.
12456: $fname.'</span>').'</p>';
12457: } else {
12458: $output .= '<p class="LC_error">'.
12459: &mt('Error: could not update links in [_1].',
12460: '<span class="LC_filename">'.
12461: $container.'</span>').'</p>';
12462:
12463: }
12464: }
12465: }
12466: }
1.987 raeburn 12467: } else {
12468: &logthis('Failed to parse '.$container.
12469: ' to modify references: '.$parse_result);
1.661 raeburn 12470: }
12471: }
1.1071 raeburn 12472: if (wantarray) {
12473: return ($output,$count,$codebasecount);
12474: } else {
12475: return $output;
12476: }
1.661 raeburn 12477: }
12478:
12479: sub check_for_existing {
12480: my ($path,$fname,$element) = @_;
12481: my ($state,$msg);
12482: if (-d $path.'/'.$fname) {
12483: $state = 'exists';
12484: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12485: } elsif (-e $path.'/'.$fname) {
12486: $state = 'exists';
12487: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12488: }
12489: if ($state eq 'exists') {
12490: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12491: }
12492: return ($state,$msg);
12493: }
12494:
12495: sub check_for_upload {
12496: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12497: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12498: my $filesize = length($env{'form.'.$element});
12499: if (!$filesize) {
12500: my $msg = '<span class="LC_error">'.
12501: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12502: '<span class="LC_filename">'.$fname.'</span>',
12503: $filesize).'<br />'.
1.1007 raeburn 12504: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12505: '</span>';
12506: return ('zero_bytes',$msg);
12507: }
12508: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12509: my $getpropath = 1;
1.1021 raeburn 12510: my ($dirlistref,$listerror) =
12511: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12512: my $found_file = 0;
12513: my $locked_file = 0;
1.991 raeburn 12514: my @lockers;
12515: my $navmap;
12516: if ($env{'request.course.id'}) {
12517: $navmap = Apache::lonnavmaps::navmap->new();
12518: }
1.1021 raeburn 12519: if (ref($dirlistref) eq 'ARRAY') {
12520: foreach my $line (@{$dirlistref}) {
12521: my ($file_name,$rest)=split(/\&/,$line,2);
12522: if ($file_name eq $fname){
12523: $file_name = $path.$file_name;
12524: if ($group ne '') {
12525: $file_name = $group.$file_name;
12526: }
12527: $found_file = 1;
12528: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12529: foreach my $lock (@lockers) {
12530: if (ref($lock) eq 'ARRAY') {
12531: my ($symb,$crsid) = @{$lock};
12532: if ($crsid eq $env{'request.course.id'}) {
12533: if (ref($navmap)) {
12534: my $res = $navmap->getBySymb($symb);
12535: foreach my $part (@{$res->parts()}) {
12536: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12537: unless (($slot_status == $res->RESERVED) ||
12538: ($slot_status == $res->RESERVED_LOCATION)) {
12539: $locked_file = 1;
12540: }
1.991 raeburn 12541: }
1.1021 raeburn 12542: } else {
12543: $locked_file = 1;
1.991 raeburn 12544: }
12545: } else {
12546: $locked_file = 1;
12547: }
12548: }
1.1021 raeburn 12549: }
12550: } else {
12551: my @info = split(/\&/,$rest);
12552: my $currsize = $info[6]/1000;
12553: if ($currsize < $filesize) {
12554: my $extra = $filesize - $currsize;
12555: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12556: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12557: &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 12558: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12559: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12560: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12561: return ('will_exceed_quota',$msg);
12562: }
1.984 raeburn 12563: }
12564: }
1.661 raeburn 12565: }
12566: }
12567: }
12568: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12569: my $msg = '<p class="LC_warning">'.
12570: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12571: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12572: return ('will_exceed_quota',$msg);
12573: } elsif ($found_file) {
12574: if ($locked_file) {
1.1179 bisitz 12575: my $msg = '<p class="LC_warning">';
1.661 raeburn 12576: $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 12577: $msg .= '</p>';
1.661 raeburn 12578: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12579: return ('file_locked',$msg);
12580: } else {
1.1179 bisitz 12581: my $msg = '<p class="LC_error">';
1.984 raeburn 12582: $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 12583: $msg .= '</p>';
1.984 raeburn 12584: return ('existingfile',$msg);
1.661 raeburn 12585: }
12586: }
12587: }
12588:
1.987 raeburn 12589: sub check_for_traversal {
12590: my ($path,$url,$toplevel) = @_;
12591: my @parts=split(/\//,$path);
12592: my $cleanpath;
12593: my $fullpath = $url;
12594: for (my $i=0;$i<@parts;$i++) {
12595: next if ($parts[$i] eq '.');
12596: if ($parts[$i] eq '..') {
12597: $fullpath =~ s{([^/]+/)$}{};
12598: } else {
12599: $fullpath .= $parts[$i].'/';
12600: }
12601: }
12602: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12603: $cleanpath = $1;
12604: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12605: my $curr_toprel = $1;
12606: my @parts = split(/\//,$curr_toprel);
12607: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12608: my @urlparts = split(/\//,$url_toprel);
12609: my $doubledots;
12610: my $startdiff = -1;
12611: for (my $i=0; $i<@urlparts; $i++) {
12612: if ($startdiff == -1) {
12613: unless ($urlparts[$i] eq $parts[$i]) {
12614: $startdiff = $i;
12615: $doubledots .= '../';
12616: }
12617: } else {
12618: $doubledots .= '../';
12619: }
12620: }
12621: if ($startdiff > -1) {
12622: $cleanpath = $doubledots;
12623: for (my $i=$startdiff; $i<@parts; $i++) {
12624: $cleanpath .= $parts[$i].'/';
12625: }
12626: }
12627: }
12628: $cleanpath =~ s{(/)$}{};
12629: return $cleanpath;
12630: }
1.31 albertel 12631:
1.1053 raeburn 12632: sub is_archive_file {
12633: my ($mimetype) = @_;
12634: if (($mimetype eq 'application/octet-stream') ||
12635: ($mimetype eq 'application/x-stuffit') ||
12636: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12637: return 1;
12638: }
12639: return;
12640: }
12641:
12642: sub decompress_form {
1.1065 raeburn 12643: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12644: my %lt = &Apache::lonlocal::texthash (
12645: this => 'This file is an archive file.',
1.1067 raeburn 12646: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12647: itsc => 'Its contents are as follows:',
1.1053 raeburn 12648: youm => 'You may wish to extract its contents.',
12649: extr => 'Extract contents',
1.1067 raeburn 12650: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12651: proa => 'Process automatically?',
1.1053 raeburn 12652: yes => 'Yes',
12653: no => 'No',
1.1067 raeburn 12654: fold => 'Title for folder containing movie',
12655: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12656: );
1.1065 raeburn 12657: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12658: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12659: my $info = &list_archive_contents($fileloc,\@paths);
12660: if (@paths) {
12661: foreach my $path (@paths) {
12662: $path =~ s{^/}{};
1.1067 raeburn 12663: if ($path =~ m{^([^/]+)/$}) {
12664: $topdir = $1;
12665: }
1.1065 raeburn 12666: if ($path =~ m{^([^/]+)/}) {
12667: $toplevel{$1} = $path;
12668: } else {
12669: $toplevel{$path} = $path;
12670: }
12671: }
12672: }
1.1067 raeburn 12673: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12674: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12675: "$topdir/media/",
12676: "$topdir/media/$topdir.mp4",
12677: "$topdir/media/FirstFrame.png",
12678: "$topdir/media/player.swf",
12679: "$topdir/media/swfobject.js",
12680: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12681: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12682: "$topdir/$topdir.mp4",
12683: "$topdir/$topdir\_config.xml",
12684: "$topdir/$topdir\_controller.swf",
12685: "$topdir/$topdir\_embed.css",
12686: "$topdir/$topdir\_First_Frame.png",
12687: "$topdir/$topdir\_player.html",
12688: "$topdir/$topdir\_Thumbnails.png",
12689: "$topdir/playerProductInstall.swf",
12690: "$topdir/scripts/",
12691: "$topdir/scripts/config_xml.js",
12692: "$topdir/scripts/handlebars.js",
12693: "$topdir/scripts/jquery-1.7.1.min.js",
12694: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12695: "$topdir/scripts/modernizr.js",
12696: "$topdir/scripts/player-min.js",
12697: "$topdir/scripts/swfobject.js",
12698: "$topdir/skins/",
12699: "$topdir/skins/configuration_express.xml",
12700: "$topdir/skins/express_show/",
12701: "$topdir/skins/express_show/player-min.css",
12702: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12703: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12704: "$topdir/$topdir.mp4",
12705: "$topdir/$topdir\_config.xml",
12706: "$topdir/$topdir\_controller.swf",
12707: "$topdir/$topdir\_embed.css",
12708: "$topdir/$topdir\_First_Frame.png",
12709: "$topdir/$topdir\_player.html",
12710: "$topdir/$topdir\_Thumbnails.png",
12711: "$topdir/playerProductInstall.swf",
12712: "$topdir/scripts/",
12713: "$topdir/scripts/config_xml.js",
12714: "$topdir/scripts/techsmith-smart-player.min.js",
12715: "$topdir/skins/",
12716: "$topdir/skins/configuration_express.xml",
12717: "$topdir/skins/express_show/",
12718: "$topdir/skins/express_show/spritesheet.min.css",
12719: "$topdir/skins/express_show/spritesheet.png",
12720: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12721: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12722: if (@diffs == 0) {
1.1164 raeburn 12723: $is_camtasia = 6;
12724: } else {
1.1197 raeburn 12725: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12726: if (@diffs == 0) {
12727: $is_camtasia = 8;
1.1197 raeburn 12728: } else {
12729: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12730: if (@diffs == 0) {
12731: $is_camtasia = 8;
12732: }
1.1164 raeburn 12733: }
1.1067 raeburn 12734: }
12735: }
12736: my $output;
12737: if ($is_camtasia) {
12738: $output = <<"ENDCAM";
12739: <script type="text/javascript" language="Javascript">
12740: // <![CDATA[
12741:
12742: function camtasiaToggle() {
12743: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12744: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12745: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12746: document.getElementById('camtasia_titles').style.display='block';
12747: } else {
12748: document.getElementById('camtasia_titles').style.display='none';
12749: }
12750: }
12751: }
12752: return;
12753: }
12754:
12755: // ]]>
12756: </script>
12757: <p>$lt{'camt'}</p>
12758: ENDCAM
1.1065 raeburn 12759: } else {
1.1067 raeburn 12760: $output = '<p>'.$lt{'this'};
12761: if ($info eq '') {
12762: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12763: } else {
12764: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12765: '<div><pre>'.$info.'</pre></div>';
12766: }
1.1065 raeburn 12767: }
1.1067 raeburn 12768: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12769: my $duplicates;
12770: my $num = 0;
12771: if (ref($dirlist) eq 'ARRAY') {
12772: foreach my $item (@{$dirlist}) {
12773: if (ref($item) eq 'ARRAY') {
12774: if (exists($toplevel{$item->[0]})) {
12775: $duplicates .=
12776: &start_data_table_row().
12777: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12778: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12779: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12780: 'value="1" />'.&mt('Yes').'</label>'.
12781: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12782: '<td>'.$item->[0].'</td>';
12783: if ($item->[2]) {
12784: $duplicates .= '<td>'.&mt('Directory').'</td>';
12785: } else {
12786: $duplicates .= '<td>'.&mt('File').'</td>';
12787: }
12788: $duplicates .= '<td>'.$item->[3].'</td>'.
12789: '<td>'.
12790: &Apache::lonlocal::locallocaltime($item->[4]).
12791: '</td>'.
12792: &end_data_table_row();
12793: $num ++;
12794: }
12795: }
12796: }
12797: }
12798: my $itemcount;
12799: if (@paths > 0) {
12800: $itemcount = scalar(@paths);
12801: } else {
12802: $itemcount = 1;
12803: }
1.1067 raeburn 12804: if ($is_camtasia) {
12805: $output .= $lt{'auto'}.'<br />'.
12806: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12807: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12808: $lt{'yes'}.'</label> <label>'.
12809: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12810: $lt{'no'}.'</label></span><br />'.
12811: '<div id="camtasia_titles" style="display:block">'.
12812: &Apache::lonhtmlcommon::start_pick_box().
12813: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12814: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12815: &Apache::lonhtmlcommon::row_closure().
12816: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12817: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12818: &Apache::lonhtmlcommon::row_closure(1).
12819: &Apache::lonhtmlcommon::end_pick_box().
12820: '</div>';
12821: }
1.1065 raeburn 12822: $output .=
12823: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12824: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12825: "\n";
1.1065 raeburn 12826: if ($duplicates ne '') {
12827: $output .= '<p><span class="LC_warning">'.
12828: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12829: &start_data_table().
12830: &start_data_table_header_row().
12831: '<th>'.&mt('Overwrite?').'</th>'.
12832: '<th>'.&mt('Name').'</th>'.
12833: '<th>'.&mt('Type').'</th>'.
12834: '<th>'.&mt('Size').'</th>'.
12835: '<th>'.&mt('Last modified').'</th>'.
12836: &end_data_table_header_row().
12837: $duplicates.
12838: &end_data_table().
12839: '</p>';
12840: }
1.1067 raeburn 12841: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12842: if (ref($hiddenelements) eq 'HASH') {
12843: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12844: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12845: }
12846: }
12847: $output .= <<"END";
1.1067 raeburn 12848: <br />
1.1053 raeburn 12849: <input type="submit" name="decompress" value="$lt{'extr'}" />
12850: </form>
12851: $noextract
12852: END
12853: return $output;
12854: }
12855:
1.1065 raeburn 12856: sub decompression_utility {
12857: my ($program) = @_;
12858: my @utilities = ('tar','gunzip','bunzip2','unzip');
12859: my $location;
12860: if (grep(/^\Q$program\E$/,@utilities)) {
12861: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12862: '/usr/sbin/') {
12863: if (-x $dir.$program) {
12864: $location = $dir.$program;
12865: last;
12866: }
12867: }
12868: }
12869: return $location;
12870: }
12871:
12872: sub list_archive_contents {
12873: my ($file,$pathsref) = @_;
12874: my (@cmd,$output);
12875: my $needsregexp;
12876: if ($file =~ /\.zip$/) {
12877: @cmd = (&decompression_utility('unzip'),"-l");
12878: $needsregexp = 1;
12879: } elsif (($file =~ m/\.tar\.gz$/) ||
12880: ($file =~ /\.tgz$/)) {
12881: @cmd = (&decompression_utility('tar'),"-ztf");
12882: } elsif ($file =~ /\.tar\.bz2$/) {
12883: @cmd = (&decompression_utility('tar'),"-jtf");
12884: } elsif ($file =~ m|\.tar$|) {
12885: @cmd = (&decompression_utility('tar'),"-tf");
12886: }
12887: if (@cmd) {
12888: undef($!);
12889: undef($@);
12890: if (open(my $fh,"-|", @cmd, $file)) {
12891: while (my $line = <$fh>) {
12892: $output .= $line;
12893: chomp($line);
12894: my $item;
12895: if ($needsregexp) {
12896: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12897: } else {
12898: $item = $line;
12899: }
12900: if ($item ne '') {
12901: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12902: push(@{$pathsref},$item);
12903: }
12904: }
12905: }
12906: close($fh);
12907: }
12908: }
12909: return $output;
12910: }
12911:
1.1053 raeburn 12912: sub decompress_uploaded_file {
12913: my ($file,$dir) = @_;
12914: &Apache::lonnet::appenv({'cgi.file' => $file});
12915: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12916: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12917: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12918: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12919: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12920: my $decompressed = $env{'cgi.decompressed'};
12921: &Apache::lonnet::delenv('cgi.file');
12922: &Apache::lonnet::delenv('cgi.dir');
12923: &Apache::lonnet::delenv('cgi.decompressed');
12924: return ($decompressed,$result);
12925: }
12926:
1.1055 raeburn 12927: sub process_decompression {
12928: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12929: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12930: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12931: &mt('Unexpected file path.').'</p>'."\n";
12932: }
12933: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12934: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12935: &mt('Unexpected course context.').'</p>'."\n";
12936: }
1.1293 raeburn 12937: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12938: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12939: &mt('Filename contained unexpected characters.').'</p>'."\n";
12940: }
1.1055 raeburn 12941: my ($dir,$error,$warning,$output);
1.1180 raeburn 12942: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12943: $error = &mt('Filename not a supported archive file type.').
12944: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12945: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12946: } else {
12947: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12948: if ($docuhome eq 'no_host') {
12949: $error = &mt('Could not determine home server for course.');
12950: } else {
12951: my @ids=&Apache::lonnet::current_machine_ids();
12952: my $currdir = "$dir_root/$destination";
12953: if (grep(/^\Q$docuhome\E$/,@ids)) {
12954: $dir = &LONCAPA::propath($docudom,$docuname).
12955: "$dir_root/$destination";
12956: } else {
12957: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12958: "$dir_root/$docudom/$docuname/$destination";
12959: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12960: $error = &mt('Archive file not found.');
12961: }
12962: }
1.1065 raeburn 12963: my (@to_overwrite,@to_skip);
12964: if ($env{'form.archive_overwrite_total'} > 0) {
12965: my $total = $env{'form.archive_overwrite_total'};
12966: for (my $i=0; $i<$total; $i++) {
12967: if ($env{'form.archive_overwrite_'.$i} == 1) {
12968: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12969: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12970: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12971: }
12972: }
12973: }
12974: my $numskip = scalar(@to_skip);
1.1292 raeburn 12975: my $numoverwrite = scalar(@to_overwrite);
12976: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12977: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12978: } elsif ($dir eq '') {
1.1055 raeburn 12979: $error = &mt('Directory containing archive file unavailable.');
12980: } elsif (!$error) {
1.1065 raeburn 12981: my ($decompressed,$display);
1.1292 raeburn 12982: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12983: my $tempdir = time.'_'.$$.int(rand(10000));
12984: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12985: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12986: ($decompressed,$display) =
12987: &decompress_uploaded_file($file,"$dir/$tempdir");
12988: foreach my $item (@to_skip) {
12989: if (($item ne '') && ($item !~ /\.\./)) {
12990: if (-f "$dir/$tempdir/$item") {
12991: unlink("$dir/$tempdir/$item");
12992: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12993: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12994: }
12995: }
12996: }
12997: foreach my $item (@to_overwrite) {
12998: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12999: if (($item ne '') && ($item !~ /\.\./)) {
13000: if (-f "$dir/$item") {
13001: unlink("$dir/$item");
13002: } elsif (-d "$dir/$item") {
1.1300 raeburn 13003: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13004: }
13005: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13006: }
1.1065 raeburn 13007: }
13008: }
1.1292 raeburn 13009: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13010: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13011: }
1.1065 raeburn 13012: }
13013: } else {
13014: ($decompressed,$display) =
13015: &decompress_uploaded_file($file,$dir);
13016: }
1.1055 raeburn 13017: if ($decompressed eq 'ok') {
1.1065 raeburn 13018: $output = '<p class="LC_info">'.
13019: &mt('Files extracted successfully from archive.').
13020: '</p>'."\n";
1.1055 raeburn 13021: my ($warning,$result,@contents);
13022: my ($newdirlistref,$newlisterror) =
13023: &Apache::lonnet::dirlist($currdir,$docudom,
13024: $docuname,1);
13025: my (%is_dir,%changes,@newitems);
13026: my $dirptr = 16384;
1.1065 raeburn 13027: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13028: foreach my $dir_line (@{$newdirlistref}) {
13029: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13030: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13031: push(@newitems,$item);
13032: if ($dirptr&$testdir) {
13033: $is_dir{$item} = 1;
13034: }
13035: $changes{$item} = 1;
13036: }
13037: }
13038: }
13039: if (keys(%changes) > 0) {
13040: foreach my $item (sort(@newitems)) {
13041: if ($changes{$item}) {
13042: push(@contents,$item);
13043: }
13044: }
13045: }
13046: if (@contents > 0) {
1.1067 raeburn 13047: my $wantform;
13048: unless ($env{'form.autoextract_camtasia'}) {
13049: $wantform = 1;
13050: }
1.1056 raeburn 13051: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13052: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13053: $currdir,\%is_dir,
13054: \%children,\%parent,
1.1056 raeburn 13055: \@contents,\%dirorder,
13056: \%titles,$wantform);
1.1055 raeburn 13057: if ($datatable ne '') {
13058: $output .= &archive_options_form('decompressed',$datatable,
13059: $count,$hiddenelem);
1.1065 raeburn 13060: my $startcount = 6;
1.1055 raeburn 13061: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13062: \%titles,\%children);
1.1055 raeburn 13063: }
1.1067 raeburn 13064: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13065: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13066: my %displayed;
13067: my $total = 1;
13068: $env{'form.archive_directory'} = [];
13069: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13070: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13071: $path =~ s{/$}{};
13072: my $item;
13073: if ($path ne '') {
13074: $item = "$path/$titles{$i}";
13075: } else {
13076: $item = $titles{$i};
13077: }
13078: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13079: if ($item eq $contents[0]) {
13080: push(@{$env{'form.archive_directory'}},$i);
13081: $env{'form.archive_'.$i} = 'display';
13082: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13083: $displayed{'folder'} = $i;
1.1164 raeburn 13084: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13085: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13086: $env{'form.archive_'.$i} = 'display';
13087: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13088: $displayed{'web'} = $i;
13089: } else {
1.1164 raeburn 13090: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13091: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13092: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13093: push(@{$env{'form.archive_directory'}},$i);
13094: }
13095: $env{'form.archive_'.$i} = 'dependency';
13096: }
13097: $total ++;
13098: }
13099: for (my $i=1; $i<$total; $i++) {
13100: next if ($i == $displayed{'web'});
13101: next if ($i == $displayed{'folder'});
13102: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13103: }
13104: $env{'form.phase'} = 'decompress_cleanup';
13105: $env{'form.archivedelete'} = 1;
13106: $env{'form.archive_count'} = $total-1;
13107: $output .=
13108: &process_extracted_files('coursedocs',$docudom,
13109: $docuname,$destination,
13110: $dir_root,$hiddenelem);
13111: }
1.1055 raeburn 13112: } else {
13113: $warning = &mt('No new items extracted from archive file.');
13114: }
13115: } else {
13116: $output = $display;
13117: $error = &mt('An error occurred during extraction from the archive file.');
13118: }
13119: }
13120: }
13121: }
13122: if ($error) {
13123: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13124: $error.'</p>'."\n";
13125: }
13126: if ($warning) {
13127: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13128: }
13129: return $output;
13130: }
13131:
13132: sub get_extracted {
1.1056 raeburn 13133: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13134: $titles,$wantform) = @_;
1.1055 raeburn 13135: my $count = 0;
13136: my $depth = 0;
13137: my $datatable;
1.1056 raeburn 13138: my @hierarchy;
1.1055 raeburn 13139: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13140: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13141: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13142: foreach my $item (@{$contents}) {
13143: $count ++;
1.1056 raeburn 13144: @{$dirorder->{$count}} = @hierarchy;
13145: $titles->{$count} = $item;
1.1055 raeburn 13146: &archive_hierarchy($depth,$count,$parent,$children);
13147: if ($wantform) {
13148: $datatable .= &archive_row($is_dir->{$item},$item,
13149: $currdir,$depth,$count);
13150: }
13151: if ($is_dir->{$item}) {
13152: $depth ++;
1.1056 raeburn 13153: push(@hierarchy,$count);
13154: $parent->{$depth} = $count;
1.1055 raeburn 13155: $datatable .=
13156: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13157: \$depth,\$count,\@hierarchy,$dirorder,
13158: $children,$parent,$titles,$wantform);
1.1055 raeburn 13159: $depth --;
1.1056 raeburn 13160: pop(@hierarchy);
1.1055 raeburn 13161: }
13162: }
13163: return ($count,$datatable);
13164: }
13165:
13166: sub recurse_extracted_archive {
1.1056 raeburn 13167: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13168: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13169: my $result='';
1.1056 raeburn 13170: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13171: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13172: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13173: return $result;
13174: }
13175: my $dirptr = 16384;
13176: my ($newdirlistref,$newlisterror) =
13177: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13178: if (ref($newdirlistref) eq 'ARRAY') {
13179: foreach my $dir_line (@{$newdirlistref}) {
13180: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13181: unless ($item =~ /^\.+$/) {
13182: $$count ++;
1.1056 raeburn 13183: @{$dirorder->{$$count}} = @{$hierarchy};
13184: $titles->{$$count} = $item;
1.1055 raeburn 13185: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13186:
1.1055 raeburn 13187: my $is_dir;
13188: if ($dirptr&$testdir) {
13189: $is_dir = 1;
13190: }
13191: if ($wantform) {
13192: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13193: }
13194: if ($is_dir) {
13195: $$depth ++;
1.1056 raeburn 13196: push(@{$hierarchy},$$count);
13197: $parent->{$$depth} = $$count;
1.1055 raeburn 13198: $result .=
13199: &recurse_extracted_archive("$currdir/$item",$docudom,
13200: $docuname,$depth,$count,
1.1056 raeburn 13201: $hierarchy,$dirorder,$children,
13202: $parent,$titles,$wantform);
1.1055 raeburn 13203: $$depth --;
1.1056 raeburn 13204: pop(@{$hierarchy});
1.1055 raeburn 13205: }
13206: }
13207: }
13208: }
13209: return $result;
13210: }
13211:
13212: sub archive_hierarchy {
13213: my ($depth,$count,$parent,$children) =@_;
13214: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13215: if (exists($parent->{$depth})) {
13216: $children->{$parent->{$depth}} .= $count.':';
13217: }
13218: }
13219: return;
13220: }
13221:
13222: sub archive_row {
13223: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13224: my ($name) = ($item =~ m{([^/]+)$});
13225: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13226: 'display' => 'Add as file',
1.1055 raeburn 13227: 'dependency' => 'Include as dependency',
13228: 'discard' => 'Discard',
13229: );
13230: if ($is_dir) {
1.1059 raeburn 13231: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13232: }
1.1056 raeburn 13233: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13234: my $offset = 0;
1.1055 raeburn 13235: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13236: $offset ++;
1.1065 raeburn 13237: if ($action ne 'display') {
13238: $offset ++;
13239: }
1.1055 raeburn 13240: $output .= '<td><span class="LC_nobreak">'.
13241: '<label><input type="radio" name="archive_'.$count.
13242: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13243: my $text = $choices{$action};
13244: if ($is_dir) {
13245: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13246: if ($action eq 'display') {
1.1059 raeburn 13247: $text = &mt('Add as folder');
1.1055 raeburn 13248: }
1.1056 raeburn 13249: } else {
13250: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13251:
13252: }
13253: $output .= ' /> '.$choices{$action}.'</label></span>';
13254: if ($action eq 'dependency') {
13255: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13256: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13257: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13258: '<option value=""></option>'."\n".
13259: '</select>'."\n".
13260: '</div>';
1.1059 raeburn 13261: } elsif ($action eq 'display') {
13262: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13263: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13264: '</div>';
1.1055 raeburn 13265: }
1.1056 raeburn 13266: $output .= '</td>';
1.1055 raeburn 13267: }
13268: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13269: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13270: for (my $i=0; $i<$depth; $i++) {
13271: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13272: }
13273: if ($is_dir) {
13274: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13275: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13276: } else {
13277: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13278: }
13279: $output .= ' '.$name.'</td>'."\n".
13280: &end_data_table_row();
13281: return $output;
13282: }
13283:
13284: sub archive_options_form {
1.1065 raeburn 13285: my ($form,$display,$count,$hiddenelem) = @_;
13286: my %lt = &Apache::lonlocal::texthash(
13287: perm => 'Permanently remove archive file?',
13288: hows => 'How should each extracted item be incorporated in the course?',
13289: cont => 'Content actions for all',
13290: addf => 'Add as folder/file',
13291: incd => 'Include as dependency for a displayed file',
13292: disc => 'Discard',
13293: no => 'No',
13294: yes => 'Yes',
13295: save => 'Save',
13296: );
13297: my $output = <<"END";
13298: <form name="$form" method="post" action="">
13299: <p><span class="LC_nobreak">$lt{'perm'}
13300: <label>
13301: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13302: </label>
13303:
13304: <label>
13305: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13306: </span>
13307: </p>
13308: <input type="hidden" name="phase" value="decompress_cleanup" />
13309: <br />$lt{'hows'}
13310: <div class="LC_columnSection">
13311: <fieldset>
13312: <legend>$lt{'cont'}</legend>
13313: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13314: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13315: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13316: </fieldset>
13317: </div>
13318: END
13319: return $output.
1.1055 raeburn 13320: &start_data_table()."\n".
1.1065 raeburn 13321: $display."\n".
1.1055 raeburn 13322: &end_data_table()."\n".
13323: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13324: $hiddenelem.
1.1065 raeburn 13325: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13326: '</form>';
13327: }
13328:
13329: sub archive_javascript {
1.1056 raeburn 13330: my ($startcount,$numitems,$titles,$children) = @_;
13331: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13332: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13333: my $scripttag = <<START;
13334: <script type="text/javascript">
13335: // <![CDATA[
13336:
13337: function checkAll(form,prefix) {
13338: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13339: for (var i=0; i < form.elements.length; i++) {
13340: var id = form.elements[i].id;
13341: if ((id != '') && (id != undefined)) {
13342: if (idstr.test(id)) {
13343: if (form.elements[i].type == 'radio') {
13344: form.elements[i].checked = true;
1.1056 raeburn 13345: var nostart = i-$startcount;
1.1059 raeburn 13346: var offset = nostart%7;
13347: var count = (nostart-offset)/7;
1.1056 raeburn 13348: dependencyCheck(form,count,offset);
1.1055 raeburn 13349: }
13350: }
13351: }
13352: }
13353: }
13354:
13355: function propagateCheck(form,count) {
13356: if (count > 0) {
1.1059 raeburn 13357: var startelement = $startcount + ((count-1) * 7);
13358: for (var j=1; j<6; j++) {
13359: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13360: var item = startelement + j;
13361: if (form.elements[item].type == 'radio') {
13362: if (form.elements[item].checked) {
13363: containerCheck(form,count,j);
13364: break;
13365: }
1.1055 raeburn 13366: }
13367: }
13368: }
13369: }
13370: }
13371:
13372: numitems = $numitems
1.1056 raeburn 13373: var titles = new Array(numitems);
13374: var parents = new Array(numitems);
1.1055 raeburn 13375: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13376: parents[i] = new Array;
1.1055 raeburn 13377: }
1.1059 raeburn 13378: var maintitle = '$maintitle';
1.1055 raeburn 13379:
13380: START
13381:
1.1056 raeburn 13382: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13383: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13384: for (my $i=0; $i<@contents; $i ++) {
13385: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13386: }
13387: }
13388:
1.1056 raeburn 13389: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13390: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13391: }
13392:
1.1055 raeburn 13393: $scripttag .= <<END;
13394:
13395: function containerCheck(form,count,offset) {
13396: if (count > 0) {
1.1056 raeburn 13397: dependencyCheck(form,count,offset);
1.1059 raeburn 13398: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13399: form.elements[item].checked = true;
13400: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13401: if (parents[count].length > 0) {
13402: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13403: containerCheck(form,parents[count][j],offset);
13404: }
13405: }
13406: }
13407: }
13408: }
13409:
13410: function dependencyCheck(form,count,offset) {
13411: if (count > 0) {
1.1059 raeburn 13412: var chosen = (offset+$startcount)+7*(count-1);
13413: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13414: var currtype = form.elements[depitem].type;
13415: if (form.elements[chosen].value == 'dependency') {
13416: document.getElementById('arc_depon_'+count).style.display='block';
13417: form.elements[depitem].options.length = 0;
13418: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13419: for (var i=1; i<=numitems; i++) {
13420: if (i == count) {
13421: continue;
13422: }
1.1059 raeburn 13423: var startelement = $startcount + (i-1) * 7;
13424: for (var j=1; j<6; j++) {
13425: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13426: var item = startelement + j;
13427: if (form.elements[item].type == 'radio') {
13428: if (form.elements[item].checked) {
13429: if (form.elements[item].value == 'display') {
13430: var n = form.elements[depitem].options.length;
13431: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13432: }
13433: }
13434: }
13435: }
13436: }
13437: }
13438: } else {
13439: document.getElementById('arc_depon_'+count).style.display='none';
13440: form.elements[depitem].options.length = 0;
13441: form.elements[depitem].options[0] = new Option('Select','',true,true);
13442: }
1.1059 raeburn 13443: titleCheck(form,count,offset);
1.1056 raeburn 13444: }
13445: }
13446:
13447: function propagateSelect(form,count,offset) {
13448: if (count > 0) {
1.1065 raeburn 13449: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13450: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13451: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13452: if (parents[count].length > 0) {
13453: for (var j=0; j<parents[count].length; j++) {
13454: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13455: }
13456: }
13457: }
13458: }
13459: }
1.1056 raeburn 13460:
13461: function containerSelect(form,count,offset,picked) {
13462: if (count > 0) {
1.1065 raeburn 13463: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13464: if (form.elements[item].type == 'radio') {
13465: if (form.elements[item].value == 'dependency') {
13466: if (form.elements[item+1].type == 'select-one') {
13467: for (var i=0; i<form.elements[item+1].options.length; i++) {
13468: if (form.elements[item+1].options[i].value == picked) {
13469: form.elements[item+1].selectedIndex = i;
13470: break;
13471: }
13472: }
13473: }
13474: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13475: if (parents[count].length > 0) {
13476: for (var j=0; j<parents[count].length; j++) {
13477: containerSelect(form,parents[count][j],offset,picked);
13478: }
13479: }
13480: }
13481: }
13482: }
13483: }
13484: }
13485:
1.1059 raeburn 13486: function titleCheck(form,count,offset) {
13487: if (count > 0) {
13488: var chosen = (offset+$startcount)+7*(count-1);
13489: var depitem = $startcount + ((count-1) * 7) + 2;
13490: var currtype = form.elements[depitem].type;
13491: if (form.elements[chosen].value == 'display') {
13492: document.getElementById('arc_title_'+count).style.display='block';
13493: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13494: document.getElementById('archive_title_'+count).value=maintitle;
13495: }
13496: } else {
13497: document.getElementById('arc_title_'+count).style.display='none';
13498: if (currtype == 'text') {
13499: document.getElementById('archive_title_'+count).value='';
13500: }
13501: }
13502: }
13503: return;
13504: }
13505:
1.1055 raeburn 13506: // ]]>
13507: </script>
13508: END
13509: return $scripttag;
13510: }
13511:
13512: sub process_extracted_files {
1.1067 raeburn 13513: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13514: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13515: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13516: my @ids=&Apache::lonnet::current_machine_ids();
13517: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13518: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13519: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13520: if (grep(/^\Q$docuhome\E$/,@ids)) {
13521: $prefix = &LONCAPA::propath($docudom,$docuname);
13522: $pathtocheck = "$dir_root/$destination";
13523: $dir = $dir_root;
13524: $ishome = 1;
13525: } else {
13526: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13527: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13528: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13529: }
13530: my $currdir = "$dir_root/$destination";
13531: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13532: if ($env{'form.folderpath'}) {
13533: my @items = split('&',$env{'form.folderpath'});
13534: $folders{'0'} = $items[-2];
1.1099 raeburn 13535: if ($env{'form.folderpath'} =~ /\:1$/) {
13536: $containers{'0'}='page';
13537: } else {
13538: $containers{'0'}='sequence';
13539: }
1.1055 raeburn 13540: }
13541: my @archdirs = &get_env_multiple('form.archive_directory');
13542: if ($numitems) {
13543: for (my $i=1; $i<=$numitems; $i++) {
13544: my $path = $env{'form.archive_content_'.$i};
13545: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13546: my $item = $1;
13547: $toplevelitems{$item} = $i;
13548: if (grep(/^\Q$i\E$/,@archdirs)) {
13549: $is_dir{$item} = 1;
13550: }
13551: }
13552: }
13553: }
1.1067 raeburn 13554: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13555: if (keys(%toplevelitems) > 0) {
13556: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13557: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13558: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13559: }
1.1066 raeburn 13560: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13561: if ($numitems) {
13562: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13563: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13564: my $path = $env{'form.archive_content_'.$i};
13565: if ($path =~ /^\Q$pathtocheck\E/) {
13566: if ($env{'form.archive_'.$i} eq 'discard') {
13567: if ($prefix ne '' && $path ne '') {
13568: if (-e $prefix.$path) {
1.1066 raeburn 13569: if ((@archdirs > 0) &&
13570: (grep(/^\Q$i\E$/,@archdirs))) {
13571: $todeletedir{$prefix.$path} = 1;
13572: } else {
13573: $todelete{$prefix.$path} = 1;
13574: }
1.1055 raeburn 13575: }
13576: }
13577: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13578: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13579: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13580: $docstitle = $env{'form.archive_title_'.$i};
13581: if ($docstitle eq '') {
13582: $docstitle = $title;
13583: }
1.1055 raeburn 13584: $outer = 0;
1.1056 raeburn 13585: if (ref($dirorder{$i}) eq 'ARRAY') {
13586: if (@{$dirorder{$i}} > 0) {
13587: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13588: if ($env{'form.archive_'.$item} eq 'display') {
13589: $outer = $item;
13590: last;
13591: }
13592: }
13593: }
13594: }
13595: my ($errtext,$fatal) =
13596: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13597: '/'.$folders{$outer}.'.'.
13598: $containers{$outer});
13599: next if ($fatal);
13600: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13601: if ($context eq 'coursedocs') {
1.1056 raeburn 13602: $mapinner{$i} = time;
1.1055 raeburn 13603: $folders{$i} = 'default_'.$mapinner{$i};
13604: $containers{$i} = 'sequence';
13605: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13606: $folders{$i}.'.'.$containers{$i};
13607: my $newidx = &LONCAPA::map::getresidx();
13608: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13609: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13610: push(@LONCAPA::map::order,$newidx);
13611: my ($outtext,$errtext) =
13612: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13613: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13614: '.'.$containers{$outer},1,1);
1.1056 raeburn 13615: $newseqid{$i} = $newidx;
1.1067 raeburn 13616: unless ($errtext) {
1.1294 raeburn 13617: $result .= '<li>'.&mt('Folder: [_1] added to course',
13618: &HTML::Entities::encode($docstitle,'<>&"')).
13619: '</li>'."\n";
1.1067 raeburn 13620: }
1.1055 raeburn 13621: }
13622: } else {
13623: if ($context eq 'coursedocs') {
13624: my $newidx=&LONCAPA::map::getresidx();
13625: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13626: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13627: $title;
1.1294 raeburn 13628: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13629: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13630: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13631: }
13632: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13633: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13634: }
13635: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13636: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13637: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13638: unless ($ishome) {
13639: my $fetch = "$newdest{$i}/$title";
13640: $fetch =~ s/^\Q$prefix$dir\E//;
13641: $prompttofetch{$fetch} = 1;
13642: }
1.1292 raeburn 13643: }
1.1067 raeburn 13644: }
1.1294 raeburn 13645: $LONCAPA::map::resources[$newidx]=
13646: $docstitle.':'.$url.':false:normal:res';
13647: push(@LONCAPA::map::order, $newidx);
13648: my ($outtext,$errtext)=
13649: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13650: $docuname.'/'.$folders{$outer}.
13651: '.'.$containers{$outer},1,1);
13652: unless ($errtext) {
13653: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13654: $result .= '<li>'.&mt('File: [_1] added to course',
13655: &HTML::Entities::encode($docstitle,'<>&"')).
13656: '</li>'."\n";
13657: }
1.1067 raeburn 13658: }
1.1294 raeburn 13659: } else {
13660: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13661: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13662: }
1.1055 raeburn 13663: }
13664: }
1.1086 raeburn 13665: }
13666: } else {
1.1294 raeburn 13667: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13668: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13669: }
13670: }
13671: for (my $i=1; $i<=$numitems; $i++) {
13672: next unless ($env{'form.archive_'.$i} eq 'dependency');
13673: my $path = $env{'form.archive_content_'.$i};
13674: if ($path =~ /^\Q$pathtocheck\E/) {
13675: my ($title) = ($path =~ m{/([^/]+)$});
13676: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13677: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13678: if (ref($dirorder{$i}) eq 'ARRAY') {
13679: my ($itemidx,$fullpath,$relpath);
13680: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13681: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13682: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13683: if ($dirorder{$i}->[$j] eq $container) {
13684: $itemidx = $j;
1.1056 raeburn 13685: }
13686: }
1.1086 raeburn 13687: }
13688: if ($itemidx eq '') {
13689: $itemidx = 0;
13690: }
13691: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13692: if ($mapinner{$referrer{$i}}) {
13693: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13694: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13695: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13696: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13697: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13698: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13699: if (!-e $fullpath) {
13700: mkdir($fullpath,0755);
1.1056 raeburn 13701: }
13702: }
1.1086 raeburn 13703: } else {
13704: last;
1.1056 raeburn 13705: }
1.1086 raeburn 13706: }
13707: }
13708: } elsif ($newdest{$referrer{$i}}) {
13709: $fullpath = $newdest{$referrer{$i}};
13710: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13711: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13712: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13713: last;
13714: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13715: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13716: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13717: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13718: if (!-e $fullpath) {
13719: mkdir($fullpath,0755);
1.1056 raeburn 13720: }
13721: }
1.1086 raeburn 13722: } else {
13723: last;
1.1056 raeburn 13724: }
1.1055 raeburn 13725: }
13726: }
1.1086 raeburn 13727: if ($fullpath ne '') {
13728: if (-e "$prefix$path") {
1.1292 raeburn 13729: unless (rename("$prefix$path","$fullpath/$title")) {
13730: $warning .= &mt('Failed to rename dependency').'<br />';
13731: }
1.1086 raeburn 13732: }
13733: if (-e "$fullpath/$title") {
13734: my $showpath;
13735: if ($relpath ne '') {
13736: $showpath = "$relpath/$title";
13737: } else {
13738: $showpath = "/$title";
13739: }
1.1294 raeburn 13740: $result .= '<li>'.&mt('[_1] included as a dependency',
13741: &HTML::Entities::encode($showpath,'<>&"')).
13742: '</li>'."\n";
1.1292 raeburn 13743: unless ($ishome) {
13744: my $fetch = "$fullpath/$title";
13745: $fetch =~ s/^\Q$prefix$dir\E//;
13746: $prompttofetch{$fetch} = 1;
13747: }
1.1086 raeburn 13748: }
13749: }
1.1055 raeburn 13750: }
1.1086 raeburn 13751: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13752: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13753: &HTML::Entities::encode($path,'<>&"'),
13754: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13755: '<br />';
1.1055 raeburn 13756: }
13757: } else {
1.1294 raeburn 13758: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13759: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13760: }
13761: }
13762: if (keys(%todelete)) {
13763: foreach my $key (keys(%todelete)) {
13764: unlink($key);
1.1066 raeburn 13765: }
13766: }
13767: if (keys(%todeletedir)) {
13768: foreach my $key (keys(%todeletedir)) {
13769: rmdir($key);
13770: }
13771: }
13772: foreach my $dir (sort(keys(%is_dir))) {
13773: if (($pathtocheck ne '') && ($dir ne '')) {
13774: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13775: }
13776: }
1.1067 raeburn 13777: if ($result ne '') {
13778: $output .= '<ul>'."\n".
13779: $result."\n".
13780: '</ul>';
13781: }
13782: unless ($ishome) {
13783: my $replicationfail;
13784: foreach my $item (keys(%prompttofetch)) {
13785: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13786: unless ($fetchresult eq 'ok') {
13787: $replicationfail .= '<li>'.$item.'</li>'."\n";
13788: }
13789: }
13790: if ($replicationfail) {
13791: $output .= '<p class="LC_error">'.
13792: &mt('Course home server failed to retrieve:').'<ul>'.
13793: $replicationfail.
13794: '</ul></p>';
13795: }
13796: }
1.1055 raeburn 13797: } else {
13798: $warning = &mt('No items found in archive.');
13799: }
13800: if ($error) {
13801: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13802: $error.'</p>'."\n";
13803: }
13804: if ($warning) {
13805: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13806: }
13807: return $output;
13808: }
13809:
1.1066 raeburn 13810: sub cleanup_empty_dirs {
13811: my ($path) = @_;
13812: if (($path ne '') && (-d $path)) {
13813: if (opendir(my $dirh,$path)) {
13814: my @dircontents = grep(!/^\./,readdir($dirh));
13815: my $numitems = 0;
13816: foreach my $item (@dircontents) {
13817: if (-d "$path/$item") {
1.1111 raeburn 13818: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13819: if (-e "$path/$item") {
13820: $numitems ++;
13821: }
13822: } else {
13823: $numitems ++;
13824: }
13825: }
13826: if ($numitems == 0) {
13827: rmdir($path);
13828: }
13829: closedir($dirh);
13830: }
13831: }
13832: return;
13833: }
13834:
1.41 ng 13835: =pod
1.45 matthew 13836:
1.1162 raeburn 13837: =item * &get_folder_hierarchy()
1.1068 raeburn 13838:
13839: Provides hierarchy of names of folders/sub-folders containing the current
13840: item,
13841:
13842: Inputs: 3
13843: - $navmap - navmaps object
13844:
13845: - $map - url for map (either the trigger itself, or map containing
13846: the resource, which is the trigger).
13847:
13848: - $showitem - 1 => show title for map itself; 0 => do not show.
13849:
13850: Outputs: 1 @pathitems - array of folder/subfolder names.
13851:
13852: =cut
13853:
13854: sub get_folder_hierarchy {
13855: my ($navmap,$map,$showitem) = @_;
13856: my @pathitems;
13857: if (ref($navmap)) {
13858: my $mapres = $navmap->getResourceByUrl($map);
13859: if (ref($mapres)) {
13860: my $pcslist = $mapres->map_hierarchy();
13861: if ($pcslist ne '') {
13862: my @pcs = split(/,/,$pcslist);
13863: foreach my $pc (@pcs) {
13864: if ($pc == 1) {
1.1129 raeburn 13865: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13866: } else {
13867: my $res = $navmap->getByMapPc($pc);
13868: if (ref($res)) {
13869: my $title = $res->compTitle();
13870: $title =~ s/\W+/_/g;
13871: if ($title ne '') {
13872: push(@pathitems,$title);
13873: }
13874: }
13875: }
13876: }
13877: }
1.1071 raeburn 13878: if ($showitem) {
13879: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13880: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13881: } else {
13882: my $maptitle = $mapres->compTitle();
13883: $maptitle =~ s/\W+/_/g;
13884: if ($maptitle ne '') {
13885: push(@pathitems,$maptitle);
13886: }
1.1068 raeburn 13887: }
13888: }
13889: }
13890: }
13891: return @pathitems;
13892: }
13893:
13894: =pod
13895:
1.1015 raeburn 13896: =item * &get_turnedin_filepath()
13897:
13898: Determines path in a user's portfolio file for storage of files uploaded
13899: to a specific essayresponse or dropbox item.
13900:
13901: Inputs: 3 required + 1 optional.
13902: $symb is symb for resource, $uname and $udom are for current user (required).
13903: $caller is optional (can be "submission", if routine is called when storing
13904: an upoaded file when "Submit Answer" button was pressed).
13905:
13906: Returns array containing $path and $multiresp.
13907: $path is path in portfolio. $multiresp is 1 if this resource contains more
13908: than one file upload item. Callers of routine should append partid as a
13909: subdirectory to $path in cases where $multiresp is 1.
13910:
13911: Called by: homework/essayresponse.pm and homework/structuretags.pm
13912:
13913: =cut
13914:
13915: sub get_turnedin_filepath {
13916: my ($symb,$uname,$udom,$caller) = @_;
13917: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13918: my $turnindir;
13919: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13920: $turnindir = $userhash{'turnindir'};
13921: my ($path,$multiresp);
13922: if ($turnindir eq '') {
13923: if ($caller eq 'submission') {
13924: $turnindir = &mt('turned in');
13925: $turnindir =~ s/\W+/_/g;
13926: my %newhash = (
13927: 'turnindir' => $turnindir,
13928: );
13929: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13930: }
13931: }
13932: if ($turnindir ne '') {
13933: $path = '/'.$turnindir.'/';
13934: my ($multipart,$turnin,@pathitems);
13935: my $navmap = Apache::lonnavmaps::navmap->new();
13936: if (defined($navmap)) {
13937: my $mapres = $navmap->getResourceByUrl($map);
13938: if (ref($mapres)) {
13939: my $pcslist = $mapres->map_hierarchy();
13940: if ($pcslist ne '') {
13941: foreach my $pc (split(/,/,$pcslist)) {
13942: my $res = $navmap->getByMapPc($pc);
13943: if (ref($res)) {
13944: my $title = $res->compTitle();
13945: $title =~ s/\W+/_/g;
13946: if ($title ne '') {
1.1149 raeburn 13947: if (($pc > 1) && (length($title) > 12)) {
13948: $title = substr($title,0,12);
13949: }
1.1015 raeburn 13950: push(@pathitems,$title);
13951: }
13952: }
13953: }
13954: }
13955: my $maptitle = $mapres->compTitle();
13956: $maptitle =~ s/\W+/_/g;
13957: if ($maptitle ne '') {
1.1149 raeburn 13958: if (length($maptitle) > 12) {
13959: $maptitle = substr($maptitle,0,12);
13960: }
1.1015 raeburn 13961: push(@pathitems,$maptitle);
13962: }
13963: unless ($env{'request.state'} eq 'construct') {
13964: my $res = $navmap->getBySymb($symb);
13965: if (ref($res)) {
13966: my $partlist = $res->parts();
13967: my $totaluploads = 0;
13968: if (ref($partlist) eq 'ARRAY') {
13969: foreach my $part (@{$partlist}) {
13970: my @types = $res->responseType($part);
13971: my @ids = $res->responseIds($part);
13972: for (my $i=0; $i < scalar(@ids); $i++) {
13973: if ($types[$i] eq 'essay') {
13974: my $partid = $part.'_'.$ids[$i];
13975: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13976: $totaluploads ++;
13977: }
13978: }
13979: }
13980: }
13981: if ($totaluploads > 1) {
13982: $multiresp = 1;
13983: }
13984: }
13985: }
13986: }
13987: } else {
13988: return;
13989: }
13990: } else {
13991: return;
13992: }
13993: my $restitle=&Apache::lonnet::gettitle($symb);
13994: $restitle =~ s/\W+/_/g;
13995: if ($restitle eq '') {
13996: $restitle = ($resurl =~ m{/[^/]+$});
13997: if ($restitle eq '') {
13998: $restitle = time;
13999: }
14000: }
1.1149 raeburn 14001: if (length($restitle) > 12) {
14002: $restitle = substr($restitle,0,12);
14003: }
1.1015 raeburn 14004: push(@pathitems,$restitle);
14005: $path .= join('/',@pathitems);
14006: }
14007: return ($path,$multiresp);
14008: }
14009:
14010: =pod
14011:
1.464 albertel 14012: =back
1.41 ng 14013:
1.112 bowersj2 14014: =head1 CSV Upload/Handling functions
1.38 albertel 14015:
1.41 ng 14016: =over 4
14017:
1.648 raeburn 14018: =item * &upfile_store($r)
1.41 ng 14019:
14020: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14021: needs $env{'form.upfile'}
1.41 ng 14022: returns $datatoken to be put into hidden field
14023:
14024: =cut
1.31 albertel 14025:
14026: sub upfile_store {
14027: my $r=shift;
1.258 albertel 14028: $env{'form.upfile'}=~s/\r/\n/gs;
14029: $env{'form.upfile'}=~s/\f/\n/gs;
14030: $env{'form.upfile'}=~s/\n+/\n/gs;
14031: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14032:
1.1299 raeburn 14033: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14034: '_enroll_'.$env{'request.course.id'}.'_'.
14035: time.'_'.$$);
14036: return if ($datatoken eq '');
14037:
1.31 albertel 14038: {
1.158 raeburn 14039: my $datafile = $r->dir_config('lonDaemons').
14040: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14041: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14042: print $fh $env{'form.upfile'};
1.158 raeburn 14043: close($fh);
14044: }
1.31 albertel 14045: }
14046: return $datatoken;
14047: }
14048:
1.56 matthew 14049: =pod
14050:
1.1290 raeburn 14051: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14052:
14053: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14054: $datatoken is the name to assign to the temporary file.
1.258 albertel 14055: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14056:
14057: =cut
1.31 albertel 14058:
14059: sub load_tmp_file {
1.1290 raeburn 14060: my ($r,$datatoken) = @_;
14061: return if ($datatoken eq '');
1.31 albertel 14062: my @studentdata=();
14063: {
1.158 raeburn 14064: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14065: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14066: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14067: @studentdata=<$fh>;
14068: close($fh);
14069: }
1.31 albertel 14070: }
1.258 albertel 14071: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14072: }
14073:
1.1290 raeburn 14074: sub valid_datatoken {
14075: my ($datatoken) = @_;
1.1325 raeburn 14076: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14077: return $datatoken;
14078: }
14079: return;
14080: }
14081:
1.56 matthew 14082: =pod
14083:
1.648 raeburn 14084: =item * &upfile_record_sep()
1.41 ng 14085:
14086: Separate uploaded file into records
14087: returns array of records,
1.258 albertel 14088: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14089:
14090: =cut
1.31 albertel 14091:
14092: sub upfile_record_sep {
1.258 albertel 14093: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14094: } else {
1.248 albertel 14095: my @records;
1.258 albertel 14096: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14097: if ($line=~/^\s*$/) { next; }
14098: push(@records,$line);
14099: }
14100: return @records;
1.31 albertel 14101: }
14102: }
14103:
1.56 matthew 14104: =pod
14105:
1.648 raeburn 14106: =item * &record_sep($record)
1.41 ng 14107:
1.258 albertel 14108: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14109:
14110: =cut
14111:
1.263 www 14112: sub takeleft {
14113: my $index=shift;
14114: return substr('0000'.$index,-4,4);
14115: }
14116:
1.31 albertel 14117: sub record_sep {
14118: my $record=shift;
14119: my %components=();
1.258 albertel 14120: if ($env{'form.upfiletype'} eq 'xml') {
14121: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14122: my $i=0;
1.356 albertel 14123: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14124: $field=~s/^(\"|\')//;
14125: $field=~s/(\"|\')$//;
1.263 www 14126: $components{&takeleft($i)}=$field;
1.31 albertel 14127: $i++;
14128: }
1.258 albertel 14129: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14130: my $i=0;
1.356 albertel 14131: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14132: $field=~s/^(\"|\')//;
14133: $field=~s/(\"|\')$//;
1.263 www 14134: $components{&takeleft($i)}=$field;
1.31 albertel 14135: $i++;
14136: }
14137: } else {
1.561 www 14138: my $separator=',';
1.480 banghart 14139: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14140: $separator=';';
1.480 banghart 14141: }
1.31 albertel 14142: my $i=0;
1.561 www 14143: # the character we are looking for to indicate the end of a quote or a record
14144: my $looking_for=$separator;
14145: # do not add the characters to the fields
14146: my $ignore=0;
14147: # we just encountered a separator (or the beginning of the record)
14148: my $just_found_separator=1;
14149: # store the field we are working on here
14150: my $field='';
14151: # work our way through all characters in record
14152: foreach my $character ($record=~/(.)/g) {
14153: if ($character eq $looking_for) {
14154: if ($character ne $separator) {
14155: # Found the end of a quote, again looking for separator
14156: $looking_for=$separator;
14157: $ignore=1;
14158: } else {
14159: # Found a separator, store away what we got
14160: $components{&takeleft($i)}=$field;
14161: $i++;
14162: $just_found_separator=1;
14163: $ignore=0;
14164: $field='';
14165: }
14166: next;
14167: }
14168: # single or double quotation marks after a separator indicate beginning of a quote
14169: # we are now looking for the end of the quote and need to ignore separators
14170: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14171: $looking_for=$character;
14172: next;
14173: }
14174: # ignore would be true after we reached the end of a quote
14175: if ($ignore) { next; }
14176: if (($just_found_separator) && ($character=~/\s/)) { next; }
14177: $field.=$character;
14178: $just_found_separator=0;
1.31 albertel 14179: }
1.561 www 14180: # catch the very last entry, since we never encountered the separator
14181: $components{&takeleft($i)}=$field;
1.31 albertel 14182: }
14183: return %components;
14184: }
14185:
1.144 matthew 14186: ######################################################
14187: ######################################################
14188:
1.56 matthew 14189: =pod
14190:
1.648 raeburn 14191: =item * &upfile_select_html()
1.41 ng 14192:
1.144 matthew 14193: Return HTML code to select a file from the users machine and specify
14194: the file type.
1.41 ng 14195:
14196: =cut
14197:
1.144 matthew 14198: ######################################################
14199: ######################################################
1.31 albertel 14200: sub upfile_select_html {
1.144 matthew 14201: my %Types = (
14202: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14203: semisv => &mt('Semicolon separated values'),
1.144 matthew 14204: space => &mt('Space separated'),
14205: tab => &mt('Tabulator separated'),
14206: # xml => &mt('HTML/XML'),
14207: );
14208: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14209: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14210: foreach my $type (sort(keys(%Types))) {
14211: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14212: }
14213: $Str .= "</select>\n";
14214: return $Str;
1.31 albertel 14215: }
14216:
1.301 albertel 14217: sub get_samples {
14218: my ($records,$toget) = @_;
14219: my @samples=({});
14220: my $got=0;
14221: foreach my $rec (@$records) {
14222: my %temp = &record_sep($rec);
14223: if (! grep(/\S/, values(%temp))) { next; }
14224: if (%temp) {
14225: $samples[$got]=\%temp;
14226: $got++;
14227: if ($got == $toget) { last; }
14228: }
14229: }
14230: return \@samples;
14231: }
14232:
1.144 matthew 14233: ######################################################
14234: ######################################################
14235:
1.56 matthew 14236: =pod
14237:
1.648 raeburn 14238: =item * &csv_print_samples($r,$records)
1.41 ng 14239:
14240: Prints a table of sample values from each column uploaded $r is an
14241: Apache Request ref, $records is an arrayref from
14242: &Apache::loncommon::upfile_record_sep
14243:
14244: =cut
14245:
1.144 matthew 14246: ######################################################
14247: ######################################################
1.31 albertel 14248: sub csv_print_samples {
14249: my ($r,$records) = @_;
1.662 bisitz 14250: my $samples = &get_samples($records,5);
1.301 albertel 14251:
1.594 raeburn 14252: $r->print(&mt('Samples').'<br />'.&start_data_table().
14253: &start_data_table_header_row());
1.356 albertel 14254: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14255: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14256: $r->print(&end_data_table_header_row());
1.301 albertel 14257: foreach my $hash (@$samples) {
1.594 raeburn 14258: $r->print(&start_data_table_row());
1.356 albertel 14259: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14260: $r->print('<td>');
1.356 albertel 14261: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14262: $r->print('</td>');
14263: }
1.594 raeburn 14264: $r->print(&end_data_table_row());
1.31 albertel 14265: }
1.594 raeburn 14266: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14267: }
14268:
1.144 matthew 14269: ######################################################
14270: ######################################################
14271:
1.56 matthew 14272: =pod
14273:
1.648 raeburn 14274: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14275:
14276: Prints a table to create associations between values and table columns.
1.144 matthew 14277:
1.41 ng 14278: $r is an Apache Request ref,
14279: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14280: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14281:
14282: =cut
14283:
1.144 matthew 14284: ######################################################
14285: ######################################################
1.31 albertel 14286: sub csv_print_select_table {
14287: my ($r,$records,$d) = @_;
1.301 albertel 14288: my $i=0;
14289: my $samples = &get_samples($records,1);
1.144 matthew 14290: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14291: &start_data_table().&start_data_table_header_row().
1.144 matthew 14292: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14293: '<th>'.&mt('Column').'</th>'.
14294: &end_data_table_header_row()."\n");
1.356 albertel 14295: foreach my $array_ref (@$d) {
14296: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14297: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14298:
1.875 bisitz 14299: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14300: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14301: $r->print('<option value="none"></option>');
1.356 albertel 14302: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14303: $r->print('<option value="'.$sample.'"'.
14304: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14305: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14306: }
1.594 raeburn 14307: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14308: $i++;
14309: }
1.594 raeburn 14310: $r->print(&end_data_table());
1.31 albertel 14311: $i--;
14312: return $i;
14313: }
1.56 matthew 14314:
1.144 matthew 14315: ######################################################
14316: ######################################################
14317:
1.56 matthew 14318: =pod
1.31 albertel 14319:
1.648 raeburn 14320: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14321:
14322: Prints a table of sample values from the upload and can make associate samples to internal names.
14323:
14324: $r is an Apache Request ref,
14325: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14326: $d is an array of 2 element arrays (internal name, displayed name)
14327:
14328: =cut
14329:
1.144 matthew 14330: ######################################################
14331: ######################################################
1.31 albertel 14332: sub csv_samples_select_table {
14333: my ($r,$records,$d) = @_;
14334: my $i=0;
1.144 matthew 14335: #
1.662 bisitz 14336: my $max_samples = 5;
14337: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14338: $r->print(&start_data_table().
14339: &start_data_table_header_row().'<th>'.
14340: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14341: &end_data_table_header_row());
1.301 albertel 14342:
14343: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14344: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14345: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14346: foreach my $option (@$d) {
14347: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14348: $r->print('<option value="'.$value.'"'.
1.253 albertel 14349: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14350: $display.'</option>');
1.31 albertel 14351: }
14352: $r->print('</select></td><td>');
1.662 bisitz 14353: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14354: if (defined($samples->[$line]{$key})) {
14355: $r->print($samples->[$line]{$key}."<br />\n");
14356: }
14357: }
1.594 raeburn 14358: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14359: $i++;
14360: }
1.594 raeburn 14361: $r->print(&end_data_table());
1.31 albertel 14362: $i--;
14363: return($i);
1.115 matthew 14364: }
14365:
1.144 matthew 14366: ######################################################
14367: ######################################################
14368:
1.115 matthew 14369: =pod
14370:
1.648 raeburn 14371: =item * &clean_excel_name($name)
1.115 matthew 14372:
14373: Returns a replacement for $name which does not contain any illegal characters.
14374:
14375: =cut
14376:
1.144 matthew 14377: ######################################################
14378: ######################################################
1.115 matthew 14379: sub clean_excel_name {
14380: my ($name) = @_;
14381: $name =~ s/[:\*\?\/\\]//g;
14382: if (length($name) > 31) {
14383: $name = substr($name,0,31);
14384: }
14385: return $name;
1.25 albertel 14386: }
1.84 albertel 14387:
1.85 albertel 14388: =pod
14389:
1.648 raeburn 14390: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14391:
14392: Returns either 1 or undef
14393:
14394: 1 if the part is to be hidden, undef if it is to be shown
14395:
14396: Arguments are:
14397:
14398: $id the id of the part to be checked
14399: $symb, optional the symb of the resource to check
14400: $udom, optional the domain of the user to check for
14401: $uname, optional the username of the user to check for
14402:
14403: =cut
1.84 albertel 14404:
14405: sub check_if_partid_hidden {
14406: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14407: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14408: $symb,$udom,$uname);
1.141 albertel 14409: my $truth=1;
14410: #if the string starts with !, then the list is the list to show not hide
14411: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14412: my @hiddenlist=split(/,/,$hiddenparts);
14413: foreach my $checkid (@hiddenlist) {
1.141 albertel 14414: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14415: }
1.141 albertel 14416: return !$truth;
1.84 albertel 14417: }
1.127 matthew 14418:
1.138 matthew 14419:
14420: ############################################################
14421: ############################################################
14422:
14423: =pod
14424:
1.157 matthew 14425: =back
14426:
1.138 matthew 14427: =head1 cgi-bin script and graphing routines
14428:
1.157 matthew 14429: =over 4
14430:
1.648 raeburn 14431: =item * &get_cgi_id()
1.138 matthew 14432:
14433: Inputs: none
14434:
14435: Returns an id which can be used to pass environment variables
14436: to various cgi-bin scripts. These environment variables will
14437: be removed from the users environment after a given time by
14438: the routine &Apache::lonnet::transfer_profile_to_env.
14439:
14440: =cut
14441:
14442: ############################################################
14443: ############################################################
1.152 albertel 14444: my $uniq=0;
1.136 matthew 14445: sub get_cgi_id {
1.154 albertel 14446: $uniq=($uniq+1)%100000;
1.280 albertel 14447: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14448: }
14449:
1.127 matthew 14450: ############################################################
14451: ############################################################
14452:
14453: =pod
14454:
1.648 raeburn 14455: =item * &DrawBarGraph()
1.127 matthew 14456:
1.138 matthew 14457: Facilitates the plotting of data in a (stacked) bar graph.
14458: Puts plot definition data into the users environment in order for
14459: graph.png to plot it. Returns an <img> tag for the plot.
14460: The bars on the plot are labeled '1','2',...,'n'.
14461:
14462: Inputs:
14463:
14464: =over 4
14465:
14466: =item $Title: string, the title of the plot
14467:
14468: =item $xlabel: string, text describing the X-axis of the plot
14469:
14470: =item $ylabel: string, text describing the Y-axis of the plot
14471:
14472: =item $Max: scalar, the maximum Y value to use in the plot
14473: If $Max is < any data point, the graph will not be rendered.
14474:
1.140 matthew 14475: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14476: they are plotted. If undefined, default values will be used.
14477:
1.178 matthew 14478: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14479:
1.138 matthew 14480: =item @Values: An array of array references. Each array reference holds data
14481: to be plotted in a stacked bar chart.
14482:
1.239 matthew 14483: =item If the final element of @Values is a hash reference the key/value
14484: pairs will be added to the graph definition.
14485:
1.138 matthew 14486: =back
14487:
14488: Returns:
14489:
14490: An <img> tag which references graph.png and the appropriate identifying
14491: information for the plot.
14492:
1.127 matthew 14493: =cut
14494:
14495: ############################################################
14496: ############################################################
1.134 matthew 14497: sub DrawBarGraph {
1.178 matthew 14498: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14499: #
14500: if (! defined($colors)) {
14501: $colors = ['#33ff00',
14502: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14503: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14504: ];
14505: }
1.228 matthew 14506: my $extra_settings = {};
14507: if (ref($Values[-1]) eq 'HASH') {
14508: $extra_settings = pop(@Values);
14509: }
1.127 matthew 14510: #
1.136 matthew 14511: my $identifier = &get_cgi_id();
14512: my $id = 'cgi.'.$identifier;
1.129 matthew 14513: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14514: return '';
14515: }
1.225 matthew 14516: #
14517: my @Labels;
14518: if (defined($labels)) {
14519: @Labels = @$labels;
14520: } else {
14521: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14522: push(@Labels,$i+1);
1.225 matthew 14523: }
14524: }
14525: #
1.129 matthew 14526: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14527: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14528: my %ValuesHash;
14529: my $NumSets=1;
14530: foreach my $array (@Values) {
14531: next if (! ref($array));
1.136 matthew 14532: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14533: join(',',@$array);
1.129 matthew 14534: }
1.127 matthew 14535: #
1.136 matthew 14536: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14537: if ($NumBars < 3) {
14538: $width = 120+$NumBars*32;
1.220 matthew 14539: $xskip = 1;
1.225 matthew 14540: $bar_width = 30;
14541: } elsif ($NumBars < 5) {
14542: $width = 120+$NumBars*20;
14543: $xskip = 1;
14544: $bar_width = 20;
1.220 matthew 14545: } elsif ($NumBars < 10) {
1.136 matthew 14546: $width = 120+$NumBars*15;
14547: $xskip = 1;
14548: $bar_width = 15;
14549: } elsif ($NumBars <= 25) {
14550: $width = 120+$NumBars*11;
14551: $xskip = 5;
14552: $bar_width = 8;
14553: } elsif ($NumBars <= 50) {
14554: $width = 120+$NumBars*8;
14555: $xskip = 5;
14556: $bar_width = 4;
14557: } else {
14558: $width = 120+$NumBars*8;
14559: $xskip = 5;
14560: $bar_width = 4;
14561: }
14562: #
1.137 matthew 14563: $Max = 1 if ($Max < 1);
14564: if ( int($Max) < $Max ) {
14565: $Max++;
14566: $Max = int($Max);
14567: }
1.127 matthew 14568: $Title = '' if (! defined($Title));
14569: $xlabel = '' if (! defined($xlabel));
14570: $ylabel = '' if (! defined($ylabel));
1.369 www 14571: $ValuesHash{$id.'.title'} = &escape($Title);
14572: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14573: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14574: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14575: $ValuesHash{$id.'.NumBars'} = $NumBars;
14576: $ValuesHash{$id.'.NumSets'} = $NumSets;
14577: $ValuesHash{$id.'.PlotType'} = 'bar';
14578: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14579: $ValuesHash{$id.'.height'} = $height;
14580: $ValuesHash{$id.'.width'} = $width;
14581: $ValuesHash{$id.'.xskip'} = $xskip;
14582: $ValuesHash{$id.'.bar_width'} = $bar_width;
14583: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14584: #
1.228 matthew 14585: # Deal with other parameters
14586: while (my ($key,$value) = each(%$extra_settings)) {
14587: $ValuesHash{$id.'.'.$key} = $value;
14588: }
14589: #
1.646 raeburn 14590: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14591: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14592: }
14593:
14594: ############################################################
14595: ############################################################
14596:
14597: =pod
14598:
1.648 raeburn 14599: =item * &DrawXYGraph()
1.137 matthew 14600:
1.138 matthew 14601: Facilitates the plotting of data in an XY graph.
14602: Puts plot definition data into the users environment in order for
14603: graph.png to plot it. Returns an <img> tag for the plot.
14604:
14605: Inputs:
14606:
14607: =over 4
14608:
14609: =item $Title: string, the title of the plot
14610:
14611: =item $xlabel: string, text describing the X-axis of the plot
14612:
14613: =item $ylabel: string, text describing the Y-axis of the plot
14614:
14615: =item $Max: scalar, the maximum Y value to use in the plot
14616: If $Max is < any data point, the graph will not be rendered.
14617:
14618: =item $colors: Array ref containing the hex color codes for the data to be
14619: plotted in. If undefined, default values will be used.
14620:
14621: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14622:
14623: =item $Ydata: Array ref containing Array refs.
1.185 www 14624: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14625:
14626: =item %Values: hash indicating or overriding any default values which are
14627: passed to graph.png.
14628: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14629:
14630: =back
14631:
14632: Returns:
14633:
14634: An <img> tag which references graph.png and the appropriate identifying
14635: information for the plot.
14636:
1.137 matthew 14637: =cut
14638:
14639: ############################################################
14640: ############################################################
14641: sub DrawXYGraph {
14642: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14643: #
14644: # Create the identifier for the graph
14645: my $identifier = &get_cgi_id();
14646: my $id = 'cgi.'.$identifier;
14647: #
14648: $Title = '' if (! defined($Title));
14649: $xlabel = '' if (! defined($xlabel));
14650: $ylabel = '' if (! defined($ylabel));
14651: my %ValuesHash =
14652: (
1.369 www 14653: $id.'.title' => &escape($Title),
14654: $id.'.xlabel' => &escape($xlabel),
14655: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14656: $id.'.y_max_value'=> $Max,
14657: $id.'.labels' => join(',',@$Xlabels),
14658: $id.'.PlotType' => 'XY',
14659: );
14660: #
14661: if (defined($colors) && ref($colors) eq 'ARRAY') {
14662: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14663: }
14664: #
14665: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14666: return '';
14667: }
14668: my $NumSets=1;
1.138 matthew 14669: foreach my $array (@{$Ydata}){
1.137 matthew 14670: next if (! ref($array));
14671: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14672: }
1.138 matthew 14673: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14674: #
14675: # Deal with other parameters
14676: while (my ($key,$value) = each(%Values)) {
14677: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14678: }
14679: #
1.646 raeburn 14680: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14681: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14682: }
14683:
14684: ############################################################
14685: ############################################################
14686:
14687: =pod
14688:
1.648 raeburn 14689: =item * &DrawXYYGraph()
1.138 matthew 14690:
14691: Facilitates the plotting of data in an XY graph with two Y axes.
14692: Puts plot definition data into the users environment in order for
14693: graph.png to plot it. Returns an <img> tag for the plot.
14694:
14695: Inputs:
14696:
14697: =over 4
14698:
14699: =item $Title: string, the title of the plot
14700:
14701: =item $xlabel: string, text describing the X-axis of the plot
14702:
14703: =item $ylabel: string, text describing the Y-axis of the plot
14704:
14705: =item $colors: Array ref containing the hex color codes for the data to be
14706: plotted in. If undefined, default values will be used.
14707:
14708: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14709:
14710: =item $Ydata1: The first data set
14711:
14712: =item $Min1: The minimum value of the left Y-axis
14713:
14714: =item $Max1: The maximum value of the left Y-axis
14715:
14716: =item $Ydata2: The second data set
14717:
14718: =item $Min2: The minimum value of the right Y-axis
14719:
14720: =item $Max2: The maximum value of the left Y-axis
14721:
14722: =item %Values: hash indicating or overriding any default values which are
14723: passed to graph.png.
14724: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14725:
14726: =back
14727:
14728: Returns:
14729:
14730: An <img> tag which references graph.png and the appropriate identifying
14731: information for the plot.
1.136 matthew 14732:
14733: =cut
14734:
14735: ############################################################
14736: ############################################################
1.137 matthew 14737: sub DrawXYYGraph {
14738: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14739: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14740: #
14741: # Create the identifier for the graph
14742: my $identifier = &get_cgi_id();
14743: my $id = 'cgi.'.$identifier;
14744: #
14745: $Title = '' if (! defined($Title));
14746: $xlabel = '' if (! defined($xlabel));
14747: $ylabel = '' if (! defined($ylabel));
14748: my %ValuesHash =
14749: (
1.369 www 14750: $id.'.title' => &escape($Title),
14751: $id.'.xlabel' => &escape($xlabel),
14752: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14753: $id.'.labels' => join(',',@$Xlabels),
14754: $id.'.PlotType' => 'XY',
14755: $id.'.NumSets' => 2,
1.137 matthew 14756: $id.'.two_axes' => 1,
14757: $id.'.y1_max_value' => $Max1,
14758: $id.'.y1_min_value' => $Min1,
14759: $id.'.y2_max_value' => $Max2,
14760: $id.'.y2_min_value' => $Min2,
1.136 matthew 14761: );
14762: #
1.137 matthew 14763: if (defined($colors) && ref($colors) eq 'ARRAY') {
14764: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14765: }
14766: #
14767: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14768: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14769: return '';
14770: }
14771: my $NumSets=1;
1.137 matthew 14772: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14773: next if (! ref($array));
14774: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14775: }
14776: #
14777: # Deal with other parameters
14778: while (my ($key,$value) = each(%Values)) {
14779: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14780: }
14781: #
1.646 raeburn 14782: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14783: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14784: }
14785:
14786: ############################################################
14787: ############################################################
14788:
14789: =pod
14790:
1.157 matthew 14791: =back
14792:
1.139 matthew 14793: =head1 Statistics helper routines?
14794:
14795: Bad place for them but what the hell.
14796:
1.157 matthew 14797: =over 4
14798:
1.648 raeburn 14799: =item * &chartlink()
1.139 matthew 14800:
14801: Returns a link to the chart for a specific student.
14802:
14803: Inputs:
14804:
14805: =over 4
14806:
14807: =item $linktext: The text of the link
14808:
14809: =item $sname: The students username
14810:
14811: =item $sdomain: The students domain
14812:
14813: =back
14814:
1.157 matthew 14815: =back
14816:
1.139 matthew 14817: =cut
14818:
14819: ############################################################
14820: ############################################################
14821: sub chartlink {
14822: my ($linktext, $sname, $sdomain) = @_;
14823: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14824: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14825: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14826: '">'.$linktext.'</a>';
1.153 matthew 14827: }
14828:
14829: #######################################################
14830: #######################################################
14831:
14832: =pod
14833:
14834: =head1 Course Environment Routines
1.157 matthew 14835:
14836: =over 4
1.153 matthew 14837:
1.648 raeburn 14838: =item * &restore_course_settings()
1.153 matthew 14839:
1.648 raeburn 14840: =item * &store_course_settings()
1.153 matthew 14841:
14842: Restores/Store indicated form parameters from the course environment.
14843: Will not overwrite existing values of the form parameters.
14844:
14845: Inputs:
14846: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14847:
14848: a hash ref describing the data to be stored. For example:
14849:
14850: %Save_Parameters = ('Status' => 'scalar',
14851: 'chartoutputmode' => 'scalar',
14852: 'chartoutputdata' => 'scalar',
14853: 'Section' => 'array',
1.373 raeburn 14854: 'Group' => 'array',
1.153 matthew 14855: 'StudentData' => 'array',
14856: 'Maps' => 'array');
14857:
14858: Returns: both routines return nothing
14859:
1.631 raeburn 14860: =back
14861:
1.153 matthew 14862: =cut
14863:
14864: #######################################################
14865: #######################################################
14866: sub store_course_settings {
1.496 albertel 14867: return &store_settings($env{'request.course.id'},@_);
14868: }
14869:
14870: sub store_settings {
1.153 matthew 14871: # save to the environment
14872: # appenv the same items, just to be safe
1.300 albertel 14873: my $udom = $env{'user.domain'};
14874: my $uname = $env{'user.name'};
1.496 albertel 14875: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14876: my %SaveHash;
14877: my %AppHash;
14878: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14879: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14880: my $envname = 'environment.'.$basename;
1.258 albertel 14881: if (exists($env{'form.'.$setting})) {
1.153 matthew 14882: # Save this value away
14883: if ($type eq 'scalar' &&
1.258 albertel 14884: (! exists($env{$envname}) ||
14885: $env{$envname} ne $env{'form.'.$setting})) {
14886: $SaveHash{$basename} = $env{'form.'.$setting};
14887: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14888: } elsif ($type eq 'array') {
14889: my $stored_form;
1.258 albertel 14890: if (ref($env{'form.'.$setting})) {
1.153 matthew 14891: $stored_form = join(',',
14892: map {
1.369 www 14893: &escape($_);
1.258 albertel 14894: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14895: } else {
14896: $stored_form =
1.369 www 14897: &escape($env{'form.'.$setting});
1.153 matthew 14898: }
14899: # Determine if the array contents are the same.
1.258 albertel 14900: if ($stored_form ne $env{$envname}) {
1.153 matthew 14901: $SaveHash{$basename} = $stored_form;
14902: $AppHash{$envname} = $stored_form;
14903: }
14904: }
14905: }
14906: }
14907: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14908: $udom,$uname);
1.153 matthew 14909: if ($put_result !~ /^(ok|delayed)/) {
14910: &Apache::lonnet::logthis('unable to save form parameters, '.
14911: 'got error:'.$put_result);
14912: }
14913: # Make sure these settings stick around in this session, too
1.646 raeburn 14914: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14915: return;
14916: }
14917:
14918: sub restore_course_settings {
1.499 albertel 14919: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14920: }
14921:
14922: sub restore_settings {
14923: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14924: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14925: next if (exists($env{'form.'.$setting}));
1.496 albertel 14926: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14927: '.'.$setting;
1.258 albertel 14928: if (exists($env{$envname})) {
1.153 matthew 14929: if ($type eq 'scalar') {
1.258 albertel 14930: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14931: } elsif ($type eq 'array') {
1.258 albertel 14932: $env{'form.'.$setting} = [
1.153 matthew 14933: map {
1.369 www 14934: &unescape($_);
1.258 albertel 14935: } split(',',$env{$envname})
1.153 matthew 14936: ];
14937: }
14938: }
14939: }
1.127 matthew 14940: }
14941:
1.618 raeburn 14942: #######################################################
14943: #######################################################
14944:
14945: =pod
14946:
14947: =head1 Domain E-mail Routines
14948:
14949: =over 4
14950:
1.648 raeburn 14951: =item * &build_recipient_list()
1.618 raeburn 14952:
1.1144 raeburn 14953: Build recipient lists for following types of e-mail:
1.766 raeburn 14954: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14955: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14956: module change checking, student/employee ID conflict checks, as
14957: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14958: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14959:
14960: Inputs:
1.619 raeburn 14961: defmail (scalar - email address of default recipient),
1.1144 raeburn 14962: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14963: requestsmail, updatesmail, or idconflictsmail).
14964:
1.619 raeburn 14965: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14966:
1.619 raeburn 14967: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14968: i.e., predates configuration by DC via domainprefs.pm
14969:
14970: $requname username of requester (if mailing type is helpdeskmail)
14971:
14972: $requdom domain of requester (if mailing type is helpdeskmail)
14973:
14974: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14975:
1.618 raeburn 14976:
1.655 raeburn 14977: Returns: comma separated list of addresses to which to send e-mail.
14978:
14979: =back
1.618 raeburn 14980:
14981: =cut
14982:
14983: ############################################################
14984: ############################################################
14985: sub build_recipient_list {
1.1297 raeburn 14986: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14987: my @recipients;
1.1270 raeburn 14988: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14989: my %domconfig =
1.1270 raeburn 14990: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14991: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14992: if (exists($domconfig{'contacts'}{$mailing})) {
14993: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14994: my @contacts = ('adminemail','supportemail');
14995: foreach my $item (@contacts) {
14996: if ($domconfig{'contacts'}{$mailing}{$item}) {
14997: my $addr = $domconfig{'contacts'}{$item};
14998: if (!grep(/^\Q$addr\E$/,@recipients)) {
14999: push(@recipients,$addr);
15000: }
1.619 raeburn 15001: }
1.1270 raeburn 15002: }
15003: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15004: if ($mailing eq 'helpdeskmail') {
15005: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15006: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15007: my @ok_bccs;
15008: foreach my $bcc (@bccs) {
15009: $bcc =~ s/^\s+//g;
15010: $bcc =~ s/\s+$//g;
15011: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15012: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15013: push(@ok_bccs,$bcc);
15014: }
15015: }
15016: }
15017: if (@ok_bccs > 0) {
15018: $allbcc = join(', ',@ok_bccs);
15019: }
15020: }
15021: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15022: }
15023: }
1.766 raeburn 15024: } elsif ($origmail ne '') {
1.1270 raeburn 15025: $lastresort = $origmail;
1.618 raeburn 15026: }
1.1297 raeburn 15027: if ($mailing eq 'helpdeskmail') {
15028: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15029: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15030: my ($inststatus,$inststatus_checked);
15031: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15032: ($env{'user.domain'} ne 'public')) {
15033: $inststatus_checked = 1;
15034: $inststatus = $env{'environment.inststatus'};
15035: }
15036: unless ($inststatus_checked) {
15037: if (($requname ne '') && ($requdom ne '')) {
15038: if (($requname =~ /^$match_username$/) &&
15039: ($requdom =~ /^$match_domain$/) &&
15040: (&Apache::lonnet::domain($requdom))) {
15041: my $requhome = &Apache::lonnet::homeserver($requname,
15042: $requdom);
15043: unless ($requhome eq 'no_host') {
15044: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15045: $inststatus = $userenv{'inststatus'};
15046: $inststatus_checked = 1;
15047: }
15048: }
15049: }
15050: }
15051: unless ($inststatus_checked) {
15052: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15053: my %srch = (srchby => 'email',
15054: srchdomain => $defdom,
15055: srchterm => $reqemail,
15056: srchtype => 'exact');
15057: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15058: foreach my $uname (keys(%srch_results)) {
15059: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15060: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15061: $inststatus_checked = 1;
15062: last;
15063: }
15064: }
15065: unless ($inststatus_checked) {
15066: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15067: if ($dirsrchres eq 'ok') {
15068: foreach my $uname (keys(%srch_results)) {
15069: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15070: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15071: $inststatus_checked = 1;
15072: last;
15073: }
15074: }
15075: }
15076: }
15077: }
15078: }
15079: if ($inststatus ne '') {
15080: foreach my $status (split(/\:/,$inststatus)) {
15081: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15082: my @contacts = ('adminemail','supportemail');
15083: foreach my $item (@contacts) {
15084: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15085: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15086: if (!grep(/^\Q$addr\E$/,@recipients)) {
15087: push(@recipients,$addr);
15088: }
15089: }
15090: }
15091: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15092: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15093: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15094: my @ok_bccs;
15095: foreach my $bcc (@bccs) {
15096: $bcc =~ s/^\s+//g;
15097: $bcc =~ s/\s+$//g;
15098: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15099: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15100: push(@ok_bccs,$bcc);
15101: }
15102: }
15103: }
15104: if (@ok_bccs > 0) {
15105: $allbcc = join(', ',@ok_bccs);
15106: }
15107: }
15108: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15109: last;
15110: }
15111: }
15112: }
15113: }
15114: }
1.619 raeburn 15115: } elsif ($origmail ne '') {
1.1270 raeburn 15116: $lastresort = $origmail;
15117: }
1.1297 raeburn 15118: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15119: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15120: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15121: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15122: my %what = (
15123: perlvar => 1,
15124: );
15125: my $primary = &Apache::lonnet::domain($defdom,'primary');
15126: if ($primary) {
15127: my $gotaddr;
15128: my ($result,$returnhash) =
15129: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15130: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15131: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15132: $lastresort = $returnhash->{'lonSupportEMail'};
15133: $gotaddr = 1;
15134: }
15135: }
15136: unless ($gotaddr) {
15137: my $uintdom = &Apache::lonnet::internet_dom($primary);
15138: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15139: unless ($uintdom eq $intdom) {
15140: my %domconfig =
15141: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15142: if (ref($domconfig{'contacts'}) eq 'HASH') {
15143: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15144: my @contacts = ('adminemail','supportemail');
15145: foreach my $item (@contacts) {
15146: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15147: my $addr = $domconfig{'contacts'}{$item};
15148: if (!grep(/^\Q$addr\E$/,@recipients)) {
15149: push(@recipients,$addr);
15150: }
15151: }
15152: }
15153: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15154: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15155: }
15156: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15157: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15158: my @ok_bccs;
15159: foreach my $bcc (@bccs) {
15160: $bcc =~ s/^\s+//g;
15161: $bcc =~ s/\s+$//g;
15162: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15163: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15164: push(@ok_bccs,$bcc);
15165: }
15166: }
15167: }
15168: if (@ok_bccs > 0) {
15169: $allbcc = join(', ',@ok_bccs);
15170: }
15171: }
15172: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15173: }
15174: }
15175: }
15176: }
15177: }
15178: }
1.618 raeburn 15179: }
1.688 raeburn 15180: if (defined($defmail)) {
15181: if ($defmail ne '') {
15182: push(@recipients,$defmail);
15183: }
1.618 raeburn 15184: }
15185: if ($otheremails) {
1.619 raeburn 15186: my @others;
15187: if ($otheremails =~ /,/) {
15188: @others = split(/,/,$otheremails);
1.618 raeburn 15189: } else {
1.619 raeburn 15190: push(@others,$otheremails);
15191: }
15192: foreach my $addr (@others) {
15193: if (!grep(/^\Q$addr\E$/,@recipients)) {
15194: push(@recipients,$addr);
15195: }
1.618 raeburn 15196: }
15197: }
1.1298 raeburn 15198: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15199: if ((!@recipients) && ($lastresort ne '')) {
15200: push(@recipients,$lastresort);
15201: }
15202: } elsif ($lastresort ne '') {
15203: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15204: push(@recipients,$lastresort);
15205: }
15206: }
1.1271 raeburn 15207: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15208: if (wantarray) {
15209: return ($recipientlist,$allbcc,$addtext);
15210: } else {
15211: return $recipientlist;
15212: }
1.618 raeburn 15213: }
15214:
1.127 matthew 15215: ############################################################
15216: ############################################################
1.154 albertel 15217:
1.655 raeburn 15218: =pod
15219:
1.1224 musolffc 15220: =over 4
15221:
1.1223 musolffc 15222: =item * &mime_email()
15223:
15224: Sends an email with a possible attachment
15225:
15226: Inputs:
15227:
15228: =over 4
15229:
15230: from - Sender's email address
15231:
15232: to - Email address of recipient
15233:
15234: subject - Subject of email
15235:
15236: body - Body of email
15237:
15238: cc_string - Carbon copy email address
15239:
15240: bcc - Blind carbon copy email address
15241:
15242: type - File type of attachment
15243:
15244: attachment_path - Path of file to be attached
15245:
15246: file_name - Name of file to be attached
15247:
15248: attachment_text - The body of an attachment of type "TEXT"
15249:
15250: =back
15251:
15252: =back
15253:
15254: =cut
15255:
15256: ############################################################
15257: ############################################################
15258:
15259: sub mime_email {
15260: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15261: $file_name, $attachment_text) = @_;
15262: my $msg = MIME::Lite->new(
15263: From => $from,
15264: To => $to,
15265: Subject => $subject,
15266: Type =>'TEXT',
15267: Data => $body,
15268: );
15269: if ($cc_string ne '') {
15270: $msg->add("Cc" => $cc_string);
15271: }
15272: if ($bcc ne '') {
15273: $msg->add("Bcc" => $bcc);
15274: }
15275: $msg->attr("content-type" => "text/plain");
15276: $msg->attr("content-type.charset" => "UTF-8");
15277: # Attach file if given
15278: if ($attachment_path) {
15279: unless ($file_name) {
15280: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15281: }
15282: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15283: $msg->attach(Type => $type,
15284: Path => $attachment_path,
15285: Filename => $file_name
15286: );
15287: # Otherwise attach text if given
15288: } elsif ($attachment_text) {
15289: $msg->attach(Type => 'TEXT',
15290: Data => $attachment_text);
15291: }
15292: # Send it
15293: $msg->send('sendmail');
15294: }
15295:
15296: ############################################################
15297: ############################################################
15298:
15299: =pod
15300:
1.655 raeburn 15301: =head1 Course Catalog Routines
15302:
15303: =over 4
15304:
15305: =item * &gather_categories()
15306:
15307: Converts category definitions - keys of categories hash stored in
15308: coursecategories in configuration.db on the primary library server in a
15309: domain - to an array. Also generates javascript and idx hash used to
15310: generate Domain Coordinator interface for editing Course Categories.
15311:
15312: Inputs:
1.663 raeburn 15313:
1.655 raeburn 15314: categories (reference to hash of category definitions).
1.663 raeburn 15315:
1.655 raeburn 15316: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15317: categories and subcategories).
1.663 raeburn 15318:
1.655 raeburn 15319: idx (reference to hash of counters used in Domain Coordinator interface for
15320: editing Course Categories).
1.663 raeburn 15321:
1.655 raeburn 15322: jsarray (reference to array of categories used to create Javascript arrays for
15323: Domain Coordinator interface for editing Course Categories).
15324:
15325: Returns: nothing
15326:
15327: Side effects: populates cats, idx and jsarray.
15328:
15329: =cut
15330:
15331: sub gather_categories {
15332: my ($categories,$cats,$idx,$jsarray) = @_;
15333: my %counters;
15334: my $num = 0;
15335: foreach my $item (keys(%{$categories})) {
15336: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15337: if ($container eq '' && $depth == 0) {
15338: $cats->[$depth][$categories->{$item}] = $cat;
15339: } else {
15340: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15341: }
15342: my ($escitem,$tail) = split(/:/,$item,2);
15343: if ($counters{$tail} eq '') {
15344: $counters{$tail} = $num;
15345: $num ++;
15346: }
15347: if (ref($idx) eq 'HASH') {
15348: $idx->{$item} = $counters{$tail};
15349: }
15350: if (ref($jsarray) eq 'ARRAY') {
15351: push(@{$jsarray->[$counters{$tail}]},$item);
15352: }
15353: }
15354: return;
15355: }
15356:
15357: =pod
15358:
15359: =item * &extract_categories()
15360:
15361: Used to generate breadcrumb trails for course categories.
15362:
15363: Inputs:
1.663 raeburn 15364:
1.655 raeburn 15365: categories (reference to hash of category definitions).
1.663 raeburn 15366:
1.655 raeburn 15367: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15368: categories and subcategories).
1.663 raeburn 15369:
1.655 raeburn 15370: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15371:
1.655 raeburn 15372: allitems (reference to hash - key is category key
15373: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15374:
1.655 raeburn 15375: idx (reference to hash of counters used in Domain Coordinator interface for
15376: editing Course Categories).
1.663 raeburn 15377:
1.655 raeburn 15378: jsarray (reference to array of categories used to create Javascript arrays for
15379: Domain Coordinator interface for editing Course Categories).
15380:
1.665 raeburn 15381: subcats (reference to hash of arrays containing all subcategories within each
15382: category, -recursive)
15383:
1.1321 raeburn 15384: maxd (reference to hash used to hold max depth for all top-level categories).
15385:
1.655 raeburn 15386: Returns: nothing
15387:
15388: Side effects: populates trails and allitems hash references.
15389:
15390: =cut
15391:
15392: sub extract_categories {
1.1321 raeburn 15393: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15394: if (ref($categories) eq 'HASH') {
15395: &gather_categories($categories,$cats,$idx,$jsarray);
15396: if (ref($cats->[0]) eq 'ARRAY') {
15397: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15398: my $name = $cats->[0][$i];
15399: my $item = &escape($name).'::0';
15400: my $trailstr;
15401: if ($name eq 'instcode') {
15402: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15403: } elsif ($name eq 'communities') {
15404: $trailstr = &mt('Communities');
1.1239 raeburn 15405: } elsif ($name eq 'placement') {
15406: $trailstr = &mt('Placement Tests');
1.655 raeburn 15407: } else {
15408: $trailstr = $name;
15409: }
15410: if ($allitems->{$item} eq '') {
15411: push(@{$trails},$trailstr);
15412: $allitems->{$item} = scalar(@{$trails})-1;
15413: }
15414: my @parents = ($name);
15415: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15416: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15417: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15418: if (ref($subcats) eq 'HASH') {
15419: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15420: }
1.1321 raeburn 15421: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15422: }
15423: } else {
15424: if (ref($subcats) eq 'HASH') {
15425: $subcats->{$item} = [];
1.655 raeburn 15426: }
1.1321 raeburn 15427: if (ref($maxd) eq 'HASH') {
15428: $maxd->{$name} = 1;
15429: }
1.655 raeburn 15430: }
15431: }
15432: }
15433: }
15434: return;
15435: }
15436:
15437: =pod
15438:
1.1162 raeburn 15439: =item * &recurse_categories()
1.655 raeburn 15440:
15441: Recursively used to generate breadcrumb trails for course categories.
15442:
15443: Inputs:
1.663 raeburn 15444:
1.655 raeburn 15445: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15446: categories and subcategories).
1.663 raeburn 15447:
1.655 raeburn 15448: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15449:
15450: category (current course category, for which breadcrumb trail is being generated).
15451:
15452: trails (reference to array of breadcrumb trails for each category).
15453:
1.655 raeburn 15454: allitems (reference to hash - key is category key
15455: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15456:
1.655 raeburn 15457: parents (array containing containers directories for current category,
15458: back to top level).
15459:
15460: Returns: nothing
15461:
15462: Side effects: populates trails and allitems hash references
15463:
15464: =cut
15465:
15466: sub recurse_categories {
1.1321 raeburn 15467: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15468: my $shallower = $depth - 1;
15469: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15470: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15471: my $name = $cats->[$depth]{$category}[$k];
15472: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15473: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15474: if ($allitems->{$item} eq '') {
15475: push(@{$trails},$trailstr);
15476: $allitems->{$item} = scalar(@{$trails})-1;
15477: }
15478: my $deeper = $depth+1;
15479: push(@{$parents},$category);
1.665 raeburn 15480: if (ref($subcats) eq 'HASH') {
15481: my $subcat = &escape($name).':'.$category.':'.$depth;
15482: for (my $j=@{$parents}; $j>=0; $j--) {
15483: my $higher;
15484: if ($j > 0) {
15485: $higher = &escape($parents->[$j]).':'.
15486: &escape($parents->[$j-1]).':'.$j;
15487: } else {
15488: $higher = &escape($parents->[$j]).'::'.$j;
15489: }
15490: push(@{$subcats->{$higher}},$subcat);
15491: }
15492: }
15493: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15494: $subcats,$maxd);
1.655 raeburn 15495: pop(@{$parents});
15496: }
15497: } else {
15498: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15499: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15500: if ($allitems->{$item} eq '') {
15501: push(@{$trails},$trailstr);
15502: $allitems->{$item} = scalar(@{$trails})-1;
15503: }
1.1321 raeburn 15504: if (ref($maxd) eq 'HASH') {
15505: if ($depth > $maxd->{$parents->[0]}) {
15506: $maxd->{$parents->[0]} = $depth;
15507: }
15508: }
1.655 raeburn 15509: }
15510: return;
15511: }
15512:
1.663 raeburn 15513: =pod
15514:
1.1162 raeburn 15515: =item * &assign_categories_table()
1.663 raeburn 15516:
15517: Create a datatable for display of hierarchical categories in a domain,
15518: with checkboxes to allow a course to be categorized.
15519:
15520: Inputs:
15521:
15522: cathash - reference to hash of categories defined for the domain (from
15523: configuration.db)
15524:
15525: currcat - scalar with an & separated list of categories assigned to a course.
15526:
1.919 raeburn 15527: type - scalar contains course type (Course or Community).
15528:
1.1260 raeburn 15529: disabled - scalar (optional) contains disabled="disabled" if input elements are
15530: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15531:
1.663 raeburn 15532: Returns: $output (markup to be displayed)
15533:
15534: =cut
15535:
15536: sub assign_categories_table {
1.1259 raeburn 15537: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15538: my $output;
15539: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15540: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15541: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15542: $maxdepth = scalar(@cats);
15543: if (@cats > 0) {
15544: my $itemcount = 0;
15545: if (ref($cats[0]) eq 'ARRAY') {
15546: my @currcategories;
15547: if ($currcat ne '') {
15548: @currcategories = split('&',$currcat);
15549: }
1.919 raeburn 15550: my $table;
1.663 raeburn 15551: for (my $i=0; $i<@{$cats[0]}; $i++) {
15552: my $parent = $cats[0][$i];
1.919 raeburn 15553: next if ($parent eq 'instcode');
15554: if ($type eq 'Community') {
15555: next unless ($parent eq 'communities');
1.1239 raeburn 15556: } elsif ($type eq 'Placement') {
15557: next unless ($parent eq 'placement');
1.919 raeburn 15558: } else {
1.1239 raeburn 15559: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15560: }
1.663 raeburn 15561: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15562: my $item = &escape($parent).'::0';
15563: my $checked = '';
15564: if (@currcategories > 0) {
15565: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15566: $checked = ' checked="checked"';
1.663 raeburn 15567: }
15568: }
1.919 raeburn 15569: my $parent_title = $parent;
15570: if ($parent eq 'communities') {
15571: $parent_title = &mt('Communities');
1.1239 raeburn 15572: } elsif ($parent eq 'placement') {
15573: $parent_title = &mt('Placement Tests');
1.919 raeburn 15574: }
15575: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15576: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15577: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15578: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15579: my $depth = 1;
15580: push(@path,$parent);
1.1259 raeburn 15581: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15582: pop(@path);
1.919 raeburn 15583: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15584: $itemcount ++;
15585: }
1.919 raeburn 15586: if ($itemcount) {
15587: $output = &Apache::loncommon::start_data_table().
15588: $table.
15589: &Apache::loncommon::end_data_table();
15590: }
1.663 raeburn 15591: }
15592: }
15593: }
15594: return $output;
15595: }
15596:
15597: =pod
15598:
1.1162 raeburn 15599: =item * &assign_category_rows()
1.663 raeburn 15600:
15601: Create a datatable row for display of nested categories in a domain,
15602: with checkboxes to allow a course to be categorized,called recursively.
15603:
15604: Inputs:
15605:
15606: itemcount - track row number for alternating colors
15607:
15608: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15609: categories and subcategories.
15610:
15611: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15612:
15613: parent - parent of current category item
15614:
15615: path - Array containing all categories back up through the hierarchy from the
15616: current category to the top level.
15617:
15618: currcategories - reference to array of current categories assigned to the course
15619:
1.1260 raeburn 15620: disabled - scalar (optional) contains disabled="disabled" if input elements are
15621: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15622:
1.663 raeburn 15623: Returns: $output (markup to be displayed).
15624:
15625: =cut
15626:
15627: sub assign_category_rows {
1.1259 raeburn 15628: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15629: my ($text,$name,$item,$chgstr);
15630: if (ref($cats) eq 'ARRAY') {
15631: my $maxdepth = scalar(@{$cats});
15632: if (ref($cats->[$depth]) eq 'HASH') {
15633: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15634: my $numchildren = @{$cats->[$depth]{$parent}};
15635: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15636: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15637: for (my $j=0; $j<$numchildren; $j++) {
15638: $name = $cats->[$depth]{$parent}[$j];
15639: $item = &escape($name).':'.&escape($parent).':'.$depth;
15640: my $deeper = $depth+1;
15641: my $checked = '';
15642: if (ref($currcategories) eq 'ARRAY') {
15643: if (@{$currcategories} > 0) {
15644: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15645: $checked = ' checked="checked"';
1.663 raeburn 15646: }
15647: }
15648: }
1.664 raeburn 15649: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15650: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15651: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15652: '<input type="hidden" name="catname" value="'.$name.'" />'.
15653: '</td><td>';
1.663 raeburn 15654: if (ref($path) eq 'ARRAY') {
15655: push(@{$path},$name);
1.1259 raeburn 15656: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15657: pop(@{$path});
15658: }
15659: $text .= '</td></tr>';
15660: }
15661: $text .= '</table></td>';
15662: }
15663: }
15664: }
15665: return $text;
15666: }
15667:
1.1181 raeburn 15668: =pod
15669:
15670: =back
15671:
15672: =cut
15673:
1.655 raeburn 15674: ############################################################
15675: ############################################################
15676:
15677:
1.443 albertel 15678: sub commit_customrole {
1.664 raeburn 15679: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15680: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15681: ($start?', '.&mt('starting').' '.localtime($start):'').
15682: ($end?', ending '.localtime($end):'').': <b>'.
15683: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15684: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15685: '</b><br />';
15686: return $output;
15687: }
15688:
15689: sub commit_standardrole {
1.1116 raeburn 15690: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15691: my ($output,$logmsg,$linefeed);
15692: if ($context eq 'auto') {
15693: $linefeed = "\n";
15694: } else {
15695: $linefeed = "<br />\n";
15696: }
1.443 albertel 15697: if ($three eq 'st') {
1.541 raeburn 15698: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15699: $one,$two,$sec,$context,$credits);
1.541 raeburn 15700: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15701: ($result eq 'unknown_course') || ($result eq 'refused')) {
15702: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15703: } else {
1.541 raeburn 15704: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15705: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15706: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15707: if ($context eq 'auto') {
15708: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15709: } else {
15710: $output .= '<b>'.$result.'</b>'.$linefeed.
15711: &mt('Add to classlist').': <b>ok</b>';
15712: }
15713: $output .= $linefeed;
1.443 albertel 15714: }
15715: } else {
15716: $output = &mt('Assigning').' '.$three.' in '.$url.
15717: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15718: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15719: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15720: if ($context eq 'auto') {
15721: $output .= $result.$linefeed;
15722: } else {
15723: $output .= '<b>'.$result.'</b>'.$linefeed;
15724: }
1.443 albertel 15725: }
15726: return $output;
15727: }
15728:
15729: sub commit_studentrole {
1.1116 raeburn 15730: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15731: $credits) = @_;
1.626 raeburn 15732: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15733: if ($context eq 'auto') {
15734: $linefeed = "\n";
15735: } else {
15736: $linefeed = '<br />'."\n";
15737: }
1.443 albertel 15738: if (defined($one) && defined($two)) {
15739: my $cid=$one.'_'.$two;
15740: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15741: my $secchange = 0;
15742: my $expire_role_result;
15743: my $modify_section_result;
1.628 raeburn 15744: if ($oldsec ne '-1') {
15745: if ($oldsec ne $sec) {
1.443 albertel 15746: $secchange = 1;
1.628 raeburn 15747: my $now = time;
1.443 albertel 15748: my $uurl='/'.$cid;
15749: $uurl=~s/\_/\//g;
15750: if ($oldsec) {
15751: $uurl.='/'.$oldsec;
15752: }
1.626 raeburn 15753: $oldsecurl = $uurl;
1.628 raeburn 15754: $expire_role_result =
1.652 raeburn 15755: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15756: if ($env{'request.course.sec'} ne '') {
15757: if ($expire_role_result eq 'refused') {
15758: my @roles = ('st');
15759: my @statuses = ('previous');
15760: my @roledoms = ($one);
15761: my $withsec = 1;
15762: my %roleshash =
15763: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15764: \@statuses,\@roles,\@roledoms,$withsec);
15765: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15766: my ($oldstart,$oldend) =
15767: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15768: if ($oldend > 0 && $oldend <= $now) {
15769: $expire_role_result = 'ok';
15770: }
15771: }
15772: }
15773: }
1.443 albertel 15774: $result = $expire_role_result;
15775: }
15776: }
15777: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15778: $modify_section_result =
15779: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15780: undef,undef,undef,$sec,
15781: $end,$start,'','',$cid,
15782: '',$context,$credits);
1.443 albertel 15783: if ($modify_section_result =~ /^ok/) {
15784: if ($secchange == 1) {
1.628 raeburn 15785: if ($sec eq '') {
15786: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15787: } else {
15788: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15789: }
1.443 albertel 15790: } elsif ($oldsec eq '-1') {
1.628 raeburn 15791: if ($sec eq '') {
15792: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15793: } else {
15794: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15795: }
1.443 albertel 15796: } else {
1.628 raeburn 15797: if ($sec eq '') {
15798: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15799: } else {
15800: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15801: }
1.443 albertel 15802: }
15803: } else {
1.1115 raeburn 15804: if ($secchange) {
1.628 raeburn 15805: $$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;
15806: } else {
15807: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15808: }
1.443 albertel 15809: }
15810: $result = $modify_section_result;
15811: } elsif ($secchange == 1) {
1.628 raeburn 15812: if ($oldsec eq '') {
1.1103 raeburn 15813: $$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 15814: } else {
15815: $$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;
15816: }
1.626 raeburn 15817: if ($expire_role_result eq 'refused') {
15818: my $newsecurl = '/'.$cid;
15819: $newsecurl =~ s/\_/\//g;
15820: if ($sec ne '') {
15821: $newsecurl.='/'.$sec;
15822: }
15823: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15824: if ($sec eq '') {
15825: $$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;
15826: } else {
15827: $$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;
15828: }
15829: }
15830: }
1.443 albertel 15831: }
15832: } else {
1.626 raeburn 15833: $$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 15834: $result = "error: incomplete course id\n";
15835: }
15836: return $result;
15837: }
15838:
1.1108 raeburn 15839: sub show_role_extent {
15840: my ($scope,$context,$role) = @_;
15841: $scope =~ s{^/}{};
15842: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15843: push(@courseroles,'co');
15844: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15845: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15846: $scope =~ s{/}{_};
15847: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15848: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15849: my ($audom,$auname) = split(/\//,$scope);
15850: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15851: &Apache::loncommon::plainname($auname,$audom).'</span>');
15852: } else {
15853: $scope =~ s{/$}{};
15854: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15855: &Apache::lonnet::domain($scope,'description').'</span>');
15856: }
15857: }
15858:
1.443 albertel 15859: ############################################################
15860: ############################################################
15861:
1.566 albertel 15862: sub check_clone {
1.578 raeburn 15863: my ($args,$linefeed) = @_;
1.566 albertel 15864: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15865: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15866: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15867: my $clonemsg;
15868: my $can_clone = 0;
1.944 raeburn 15869: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15870: if ($lctype ne 'community') {
15871: $lctype = 'course';
15872: }
1.566 albertel 15873: if ($clonehome eq 'no_host') {
1.944 raeburn 15874: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15875: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15876: } else {
15877: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15878: }
1.566 albertel 15879: } else {
15880: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15881: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15882: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15883: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
1.908 raeburn 15884: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15885: }
15886: }
1.1262 raeburn 15887: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15888: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15889: $can_clone = 1;
15890: } else {
1.1221 raeburn 15891: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15892: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15893: if ($clonehash{'cloners'} eq '') {
15894: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15895: if ($domdefs{'canclone'}) {
15896: unless ($domdefs{'canclone'} eq 'none') {
15897: if ($domdefs{'canclone'} eq 'domain') {
15898: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15899: $can_clone = 1;
15900: }
15901: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15902: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15903: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15904: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15905: $can_clone = 1;
15906: }
15907: }
15908: }
15909: }
1.578 raeburn 15910: } else {
1.1221 raeburn 15911: my @cloners = split(/,/,$clonehash{'cloners'});
15912: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15913: $can_clone = 1;
1.1221 raeburn 15914: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15915: $can_clone = 1;
1.1225 raeburn 15916: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15917: $can_clone = 1;
1.1221 raeburn 15918: }
15919: unless ($can_clone) {
1.1225 raeburn 15920: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15921: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15922: my (%gotdomdefaults,%gotcodedefaults);
15923: foreach my $cloner (@cloners) {
15924: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15925: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15926: my (%codedefaults,@code_order);
15927: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15928: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15929: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15930: }
15931: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15932: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15933: }
15934: } else {
15935: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15936: \%codedefaults,
15937: \@code_order);
15938: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15939: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15940: }
15941: if (@code_order > 0) {
15942: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15943: $cloner,$clonehash{'internal.coursecode'},
15944: $args->{'crscode'})) {
15945: $can_clone = 1;
15946: last;
15947: }
15948: }
15949: }
15950: }
15951: }
1.1225 raeburn 15952: }
15953: }
15954: unless ($can_clone) {
15955: my $ccrole = 'cc';
15956: if ($args->{'crstype'} eq 'Community') {
15957: $ccrole = 'co';
15958: }
15959: my %roleshash =
15960: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15961: $args->{'ccdomain'},
15962: 'userroles',['active'],[$ccrole],
15963: [$args->{'clonedomain'}]);
15964: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15965: $can_clone = 1;
15966: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15967: $args->{'ccuname'},$args->{'ccdomain'})) {
15968: $can_clone = 1;
1.1221 raeburn 15969: }
15970: }
15971: unless ($can_clone) {
15972: if ($args->{'crstype'} eq 'Community') {
15973: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.942 raeburn 15974: } else {
1.1221 raeburn 15975: $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
15976: }
1.566 albertel 15977: }
1.578 raeburn 15978: }
1.566 albertel 15979: }
15980: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15981: }
15982:
1.444 albertel 15983: sub construct_course {
1.1262 raeburn 15984: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15985: $cnum,$category,$coderef) = @_;
1.444 albertel 15986: my $outcome;
1.541 raeburn 15987: my $linefeed = '<br />'."\n";
15988: if ($context eq 'auto') {
15989: $linefeed = "\n";
15990: }
1.566 albertel 15991:
15992: #
15993: # Are we cloning?
15994: #
15995: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15996: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15997: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15998: if ($context ne 'auto') {
1.578 raeburn 15999: if ($clonemsg ne '') {
16000: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
16001: }
1.566 albertel 16002: }
16003: $outcome .= $clonemsg.$linefeed;
16004:
16005: if (!$can_clone) {
16006: return (0,$outcome);
16007: }
16008: }
16009:
1.444 albertel 16010: #
16011: # Open course
16012: #
1.1239 raeburn 16013: my $showncrstype;
16014: if ($args->{'crstype'} eq 'Placement') {
16015: $showncrstype = 'placement test';
16016: } else {
16017: $showncrstype = lc($args->{'crstype'});
16018: }
1.444 albertel 16019: my %cenv=();
16020: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16021: $args->{'cdescr'},
16022: $args->{'curl'},
16023: $args->{'course_home'},
16024: $args->{'nonstandard'},
16025: $args->{'crscode'},
16026: $args->{'ccuname'}.':'.
16027: $args->{'ccdomain'},
1.882 raeburn 16028: $args->{'crstype'},
1.885 raeburn 16029: $cnum,$context,$category);
1.444 albertel 16030:
16031: # Note: The testing routines depend on this being output; see
16032: # Utils::Course. This needs to at least be output as a comment
16033: # if anyone ever decides to not show this, and Utils::Course::new
16034: # will need to be suitably modified.
1.1239 raeburn 16035: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 16036: if ($$courseid =~ /^error:/) {
16037: return (0,$outcome);
16038: }
16039:
1.444 albertel 16040: #
16041: # Check if created correctly
16042: #
1.479 albertel 16043: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16044: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16045: if ($crsuhome eq 'no_host') {
16046: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
16047: return (0,$outcome);
16048: }
1.541 raeburn 16049: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16050:
1.444 albertel 16051: #
1.566 albertel 16052: # Do the cloning
16053: #
16054: if ($can_clone && $cloneid) {
1.1239 raeburn 16055: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 16056: if ($context ne 'auto') {
16057: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
16058: }
16059: $outcome .= $clonemsg.$linefeed;
16060: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16061: # Copy all files
1.637 www 16062: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 16063: # Restore URL
1.566 albertel 16064: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16065: # Restore title
1.566 albertel 16066: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16067: # Restore creation date, creator and creation context.
16068: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16069: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16070: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16071: # Mark as cloned
1.566 albertel 16072: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16073: # Need to clone grading mode
16074: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16075: $cenv{'grading'}=$newenv{'grading'};
16076: # Do not clone these environment entries
16077: &Apache::lonnet::del('environment',
16078: ['default_enrollment_start_date',
16079: 'default_enrollment_end_date',
16080: 'question.email',
16081: 'policy.email',
16082: 'comment.email',
16083: 'pch.users.denied',
1.725 raeburn 16084: 'plc.users.denied',
16085: 'hidefromcat',
1.1121 raeburn 16086: 'checkforpriv',
1.1166 raeburn 16087: 'categories',
16088: 'internal.uniquecode'],
1.638 www 16089: $$crsudom,$$crsunum);
1.1170 raeburn 16090: if ($args->{'textbook'}) {
16091: $cenv{'internal.textbook'} = $args->{'textbook'};
16092: }
1.444 albertel 16093: }
1.566 albertel 16094:
1.444 albertel 16095: #
16096: # Set environment (will override cloned, if existing)
16097: #
16098: my @sections = ();
16099: my @xlists = ();
16100: if ($args->{'crstype'}) {
16101: $cenv{'type'}=$args->{'crstype'};
16102: }
16103: if ($args->{'crsid'}) {
16104: $cenv{'courseid'}=$args->{'crsid'};
16105: }
16106: if ($args->{'crscode'}) {
16107: $cenv{'internal.coursecode'}=$args->{'crscode'};
16108: }
16109: if ($args->{'crsquota'} ne '') {
16110: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16111: } else {
16112: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16113: }
16114: if ($args->{'ccuname'}) {
16115: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16116: ':'.$args->{'ccdomain'};
16117: } else {
16118: $cenv{'internal.courseowner'} = $args->{'curruser'};
16119: }
1.1116 raeburn 16120: if ($args->{'defaultcredits'}) {
16121: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16122: }
1.444 albertel 16123: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16124: if ($args->{'crssections'}) {
16125: $cenv{'internal.sectionnums'} = '';
16126: if ($args->{'crssections'} =~ m/,/) {
16127: @sections = split/,/,$args->{'crssections'};
16128: } else {
16129: $sections[0] = $args->{'crssections'};
16130: }
16131: if (@sections > 0) {
16132: foreach my $item (@sections) {
16133: my ($sec,$gp) = split/:/,$item;
16134: my $class = $args->{'crscode'}.$sec;
16135: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16136: $cenv{'internal.sectionnums'} .= $item.',';
16137: unless ($addcheck eq 'ok') {
1.1263 raeburn 16138: push(@badclasses,$class);
1.444 albertel 16139: }
16140: }
16141: $cenv{'internal.sectionnums'} =~ s/,$//;
16142: }
16143: }
16144: # do not hide course coordinator from staff listing,
16145: # even if privileged
16146: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16147: # add course coordinator's domain to domains to check for privileged users
16148: # if different to course domain
16149: if ($$crsudom ne $args->{'ccdomain'}) {
16150: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16151: }
1.444 albertel 16152: # add crosslistings
16153: if ($args->{'crsxlist'}) {
16154: $cenv{'internal.crosslistings'}='';
16155: if ($args->{'crsxlist'} =~ m/,/) {
16156: @xlists = split/,/,$args->{'crsxlist'};
16157: } else {
16158: $xlists[0] = $args->{'crsxlist'};
16159: }
16160: if (@xlists > 0) {
16161: foreach my $item (@xlists) {
16162: my ($xl,$gp) = split/:/,$item;
16163: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16164: $cenv{'internal.crosslistings'} .= $item.',';
16165: unless ($addcheck eq 'ok') {
1.1263 raeburn 16166: push(@badclasses,$xl);
1.444 albertel 16167: }
16168: }
16169: $cenv{'internal.crosslistings'} =~ s/,$//;
16170: }
16171: }
16172: if ($args->{'autoadds'}) {
16173: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16174: }
16175: if ($args->{'autodrops'}) {
16176: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16177: }
16178: # check for notification of enrollment changes
16179: my @notified = ();
16180: if ($args->{'notify_owner'}) {
16181: if ($args->{'ccuname'} ne '') {
16182: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16183: }
16184: }
16185: if ($args->{'notify_dc'}) {
16186: if ($uname ne '') {
1.630 raeburn 16187: push(@notified,$uname.':'.$udom);
1.444 albertel 16188: }
16189: }
16190: if (@notified > 0) {
16191: my $notifylist;
16192: if (@notified > 1) {
16193: $notifylist = join(',',@notified);
16194: } else {
16195: $notifylist = $notified[0];
16196: }
16197: $cenv{'internal.notifylist'} = $notifylist;
16198: }
16199: if (@badclasses > 0) {
16200: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16201: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16202: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16203: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16204: );
1.1264 raeburn 16205: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16206: &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 16207: if ($context eq 'auto') {
16208: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16209: } else {
1.566 albertel 16210: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16211: }
16212: foreach my $item (@badclasses) {
1.541 raeburn 16213: if ($context eq 'auto') {
1.1261 raeburn 16214: $outcome .= " - $item\n";
1.541 raeburn 16215: } else {
1.1261 raeburn 16216: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16217: }
1.1261 raeburn 16218: }
16219: if ($context eq 'auto') {
16220: $outcome .= $linefeed;
16221: } else {
16222: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16223: }
1.444 albertel 16224: }
16225: if ($args->{'no_end_date'}) {
16226: $args->{'endaccess'} = 0;
16227: }
16228: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16229: $cenv{'internal.autoend'}=$args->{'enrollend'};
16230: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16231: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16232: if ($args->{'showphotos'}) {
16233: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16234: }
16235: $cenv{'internal.authtype'} = $args->{'authtype'};
16236: $cenv{'internal.autharg'} = $args->{'autharg'};
16237: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16238: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16239: 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');
16240: if ($context eq 'auto') {
16241: $outcome .= $krb_msg;
16242: } else {
1.566 albertel 16243: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16244: }
16245: $outcome .= $linefeed;
1.444 albertel 16246: }
16247: }
16248: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16249: if ($args->{'setpolicy'}) {
16250: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16251: }
16252: if ($args->{'setcontent'}) {
16253: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16254: }
1.1251 raeburn 16255: if ($args->{'setcomment'}) {
16256: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16257: }
1.444 albertel 16258: }
16259: if ($args->{'reshome'}) {
16260: $cenv{'reshome'}=$args->{'reshome'}.'/';
16261: $cenv{'reshome'}=~s/\/+$/\//;
16262: }
16263: #
16264: # course has keyed access
16265: #
16266: if ($args->{'setkeys'}) {
16267: $cenv{'keyaccess'}='yes';
16268: }
16269: # if specified, key authority is not course, but user
16270: # only active if keyaccess is yes
16271: if ($args->{'keyauth'}) {
1.487 albertel 16272: my ($user,$domain) = split(':',$args->{'keyauth'});
16273: $user = &LONCAPA::clean_username($user);
16274: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16275: if ($user ne '' && $domain ne '') {
1.487 albertel 16276: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16277: }
16278: }
16279:
1.1166 raeburn 16280: #
1.1167 raeburn 16281: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16282: #
16283: if ($args->{'uniquecode'}) {
16284: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16285: if ($code) {
16286: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16287: my %crsinfo =
16288: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16289: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16290: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16291: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16292: }
1.1166 raeburn 16293: if (ref($coderef)) {
16294: $$coderef = $code;
16295: }
16296: }
16297: }
16298:
1.444 albertel 16299: if ($args->{'disresdis'}) {
16300: $cenv{'pch.roles.denied'}='st';
16301: }
16302: if ($args->{'disablechat'}) {
16303: $cenv{'plc.roles.denied'}='st';
16304: }
16305:
16306: # Record we've not yet viewed the Course Initialization Helper for this
16307: # course
16308: $cenv{'course.helper.not.run'} = 1;
16309: #
16310: # Use new Randomseed
16311: #
16312: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16313: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16314: #
16315: # The encryption code and receipt prefix for this course
16316: #
16317: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16318: $cenv{'internal.encpref'}=100+int(9*rand(99));
16319: #
16320: # By default, use standard grading
16321: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16322:
1.541 raeburn 16323: $outcome .= $linefeed.&mt('Setting environment').': '.
16324: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16325: #
16326: # Open all assignments
16327: #
16328: if ($args->{'openall'}) {
1.1341 ! raeburn 16329: my $opendate = time;
! 16330: if ($args->{'openallfrom'} =~ /^\d+$/) {
! 16331: $opendate = $args->{'openallfrom'};
! 16332: }
1.444 albertel 16333: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 ! raeburn 16334: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16335: $storeunder.'.type' => 'date_start');
1.1341 ! raeburn 16336: $outcome .= &mt('All assignments open starting [_1]',
! 16337: &Apache::lonlocal::locallocaltime($opendate)).': '.
! 16338: &Apache::lonnet::cput
! 16339: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16340: }
16341: #
16342: # Set first page
16343: #
16344: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16345: || ($cloneid)) {
1.445 albertel 16346: use LONCAPA::map;
1.444 albertel 16347: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16348:
16349: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16350: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16351:
1.444 albertel 16352: $outcome .= ($fatal?$errtext:'read ok').' - ';
16353: my $title; my $url;
16354: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16355: $title=&mt('Syllabus');
1.444 albertel 16356: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16357: } else {
1.963 raeburn 16358: $title=&mt('Table of Contents');
1.444 albertel 16359: $url='/adm/navmaps';
16360: }
1.445 albertel 16361:
16362: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16363: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16364:
16365: if ($errtext) { $fatal=2; }
1.541 raeburn 16366: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16367: }
1.566 albertel 16368:
1.1237 raeburn 16369: #
16370: # Set params for Placement Tests
16371: #
1.1239 raeburn 16372: if ($args->{'crstype'} eq 'Placement') {
16373: my %storecontent;
16374: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16375: my %defaults = (
16376: buttonshide => { value => 'yes',
16377: type => 'string_yesno',},
16378: type => { value => 'randomizetry',
16379: type => 'string_questiontype',},
16380: maxtries => { value => 1,
16381: type => 'int_pos',},
16382: problemstatus => { value => 'no',
16383: type => 'string_problemstatus',},
16384: );
16385: foreach my $key (keys(%defaults)) {
16386: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16387: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16388: }
1.1237 raeburn 16389: &Apache::lonnet::cput
16390: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16391: }
16392:
1.566 albertel 16393: return (1,$outcome);
1.444 albertel 16394: }
16395:
1.1166 raeburn 16396: sub make_unique_code {
16397: my ($cdom,$cnum) = @_;
16398: # get lock on uniquecodes db
16399: my $lockhash = {
16400: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16401: ':'.$env{'user.domain'},
16402: };
16403: my $tries = 0;
16404: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16405: my ($code,$error);
16406:
16407: while (($gotlock ne 'ok') && ($tries<3)) {
16408: $tries ++;
16409: sleep 1;
16410: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16411: }
16412: if ($gotlock eq 'ok') {
16413: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16414: my $gotcode;
16415: my $attempts = 0;
16416: while ((!$gotcode) && ($attempts < 100)) {
16417: $code = &generate_code();
16418: if (!exists($currcodes{$code})) {
16419: $gotcode = 1;
16420: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16421: $error = 'nostore';
16422: }
16423: }
16424: $attempts ++;
16425: }
16426: my @del_lock = ($cnum."\0".'uniquecodes');
16427: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16428: } else {
16429: $error = 'nolock';
16430: }
16431: return ($code,$error);
16432: }
16433:
16434: sub generate_code {
16435: my $code;
16436: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16437: for (my $i=0; $i<6; $i++) {
16438: my $lettnum = int (rand 2);
16439: my $item = '';
16440: if ($lettnum) {
16441: $item = $letts[int( rand(18) )];
16442: } else {
16443: $item = 1+int( rand(8) );
16444: }
16445: $code .= $item;
16446: }
16447: return $code;
16448: }
16449:
1.444 albertel 16450: ############################################################
16451: ############################################################
16452:
1.1237 raeburn 16453: # Community, Course and Placement Test
1.378 raeburn 16454: sub course_type {
16455: my ($cid) = @_;
16456: if (!defined($cid)) {
16457: $cid = $env{'request.course.id'};
16458: }
1.404 albertel 16459: if (defined($env{'course.'.$cid.'.type'})) {
16460: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16461: } else {
16462: return 'Course';
1.377 raeburn 16463: }
16464: }
1.156 albertel 16465:
1.406 raeburn 16466: sub group_term {
16467: my $crstype = &course_type();
16468: my %names = (
16469: 'Course' => 'group',
1.865 raeburn 16470: 'Community' => 'group',
1.1237 raeburn 16471: 'Placement' => 'group',
1.406 raeburn 16472: );
16473: return $names{$crstype};
16474: }
16475:
1.902 raeburn 16476: sub course_types {
1.1310 raeburn 16477: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16478: my %typename = (
16479: official => 'Official course',
16480: unofficial => 'Unofficial course',
16481: community => 'Community',
1.1165 raeburn 16482: textbook => 'Textbook course',
1.1237 raeburn 16483: placement => 'Placement test',
1.1310 raeburn 16484: lti => 'LTI provider',
1.902 raeburn 16485: );
16486: return (\@types,\%typename);
16487: }
16488:
1.156 albertel 16489: sub icon {
16490: my ($file)=@_;
1.505 albertel 16491: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16492: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16493: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16494: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16495: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16496: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16497: $curfext.".gif") {
16498: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16499: $curfext.".gif";
16500: }
16501: }
1.249 albertel 16502: return &lonhttpdurl($iconname);
1.154 albertel 16503: }
1.84 albertel 16504:
1.575 albertel 16505: sub lonhttpdurl {
1.692 www 16506: #
16507: # Had been used for "small fry" static images on separate port 8080.
16508: # Modify here if lightweight http functionality desired again.
16509: # Currently eliminated due to increasing firewall issues.
16510: #
1.575 albertel 16511: my ($url)=@_;
1.692 www 16512: return $url;
1.215 albertel 16513: }
16514:
1.213 albertel 16515: sub connection_aborted {
16516: my ($r)=@_;
16517: $r->print(" ");$r->rflush();
16518: my $c = $r->connection;
16519: return $c->aborted();
16520: }
16521:
1.221 foxr 16522: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16523: # strings as 'strings'.
16524: sub escape_single {
1.221 foxr 16525: my ($input) = @_;
1.223 albertel 16526: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16527: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16528: return $input;
16529: }
1.223 albertel 16530:
1.222 foxr 16531: # Same as escape_single, but escape's "'s This
16532: # can be used for "strings"
16533: sub escape_double {
16534: my ($input) = @_;
16535: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16536: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16537: return $input;
16538: }
1.223 albertel 16539:
1.222 foxr 16540: # Escapes the last element of a full URL.
16541: sub escape_url {
16542: my ($url) = @_;
1.238 raeburn 16543: my @urlslices = split(/\//, $url,-1);
1.369 www 16544: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16545: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16546: }
1.462 albertel 16547:
1.820 raeburn 16548: sub compare_arrays {
16549: my ($arrayref1,$arrayref2) = @_;
16550: my (@difference,%count);
16551: @difference = ();
16552: %count = ();
16553: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16554: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16555: foreach my $element (keys(%count)) {
16556: if ($count{$element} == 1) {
16557: push(@difference,$element);
16558: }
16559: }
16560: }
16561: return @difference;
16562: }
16563:
1.1322 raeburn 16564: sub lon_status_items {
16565: my %defaults = (
16566: E => 100,
16567: W => 4,
16568: N => 1,
1.1324 raeburn 16569: U => 5,
1.1322 raeburn 16570: threshold => 200,
16571: sysmail => 2500,
16572: );
16573: my %names = (
16574: E => 'Errors',
16575: W => 'Warnings',
16576: N => 'Notices',
1.1324 raeburn 16577: U => 'Unsent',
1.1322 raeburn 16578: );
16579: return (\%defaults,\%names);
16580: }
16581:
1.817 bisitz 16582: # -------------------------------------------------------- Initialize user login
1.462 albertel 16583: sub init_user_environment {
1.463 albertel 16584: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16585: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16586:
16587: my $public=($username eq 'public' && $domain eq 'public');
16588:
1.1062 raeburn 16589: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16590: my $now=time;
16591:
16592: if ($public) {
16593: my $max_public=100;
16594: my $oldest;
16595: my $oldest_time=0;
16596: for(my $next=1;$next<=$max_public;$next++) {
16597: if (-e $lonids."/publicuser_$next.id") {
16598: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16599: if ($mtime<$oldest_time || !$oldest_time) {
16600: $oldest_time=$mtime;
16601: $oldest=$next;
16602: }
16603: } else {
16604: $cookie="publicuser_$next";
16605: last;
16606: }
16607: }
16608: if (!$cookie) { $cookie="publicuser_$oldest"; }
16609: } else {
1.1275 raeburn 16610: # See if old ID present, if so, remove if this isn't a robot,
16611: # killing any existing non-robot sessions
1.463 albertel 16612: if (!$args->{'robot'}) {
16613: opendir(DIR,$lonids);
16614: while ($filename=readdir(DIR)) {
16615: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16616: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16617: &GDBM_READER(),0640)) {
1.1295 raeburn 16618: my $linkedfile;
1.1320 raeburn 16619: if (exists($oldenv{'user.linkedenv'})) {
16620: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16621: }
1.1320 raeburn 16622: untie(%oldenv);
16623: if (unlink("$lonids/$filename")) {
16624: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16625: if (-l "$lonids/$linkedfile.id") {
16626: unlink("$lonids/$linkedfile.id");
16627: }
1.1295 raeburn 16628: }
16629: }
16630: } else {
16631: unlink($lonids.'/'.$filename);
16632: }
1.463 albertel 16633: }
1.462 albertel 16634: }
1.463 albertel 16635: closedir(DIR);
1.1204 raeburn 16636: # If there is a undeleted lockfile for the user's paste buffer remove it.
16637: my $namespace = 'nohist_courseeditor';
16638: my $lockingkey = 'paste'."\0".'locked_num';
16639: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16640: $domain,$username);
16641: if (exists($lockhash{$lockingkey})) {
16642: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16643: unless ($delresult eq 'ok') {
16644: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16645: }
16646: }
1.462 albertel 16647: }
16648: # Give them a new cookie
1.463 albertel 16649: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16650: : $now.$$.int(rand(10000)));
1.463 albertel 16651: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16652:
16653: # Initialize roles
16654:
1.1062 raeburn 16655: ($userroles,$firstaccenv,$timerintenv) =
16656: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16657: }
16658: # ------------------------------------ Check browser type and MathML capability
16659:
1.1194 raeburn 16660: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16661: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16662:
16663: # ------------------------------------------------------------- Get environment
16664:
16665: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16666: my ($tmp) = keys(%userenv);
1.1275 raeburn 16667: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16668: undef(%userenv);
16669: }
16670: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16671: $form->{'interface'}=$userenv{'interface'};
16672: }
16673: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16674:
16675: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16676: foreach my $option ('interface','localpath','localres') {
16677: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16678: }
16679: # --------------------------------------------------------- Write first profile
16680:
16681: {
16682: my %initial_env =
16683: ("user.name" => $username,
16684: "user.domain" => $domain,
16685: "user.home" => $authhost,
16686: "browser.type" => $clientbrowser,
16687: "browser.version" => $clientversion,
16688: "browser.mathml" => $clientmathml,
16689: "browser.unicode" => $clientunicode,
16690: "browser.os" => $clientos,
1.1137 raeburn 16691: "browser.mobile" => $clientmobile,
1.1141 raeburn 16692: "browser.info" => $clientinfo,
1.1194 raeburn 16693: "browser.osversion" => $clientosversion,
1.462 albertel 16694: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16695: "request.course.fn" => '',
16696: "request.course.uri" => '',
16697: "request.course.sec" => '',
16698: "request.role" => 'cm',
16699: "request.role.adv" => $env{'user.adv'},
16700: "request.host" => $ENV{'REMOTE_ADDR'},);
16701:
16702: if ($form->{'localpath'}) {
16703: $initial_env{"browser.localpath"} = $form->{'localpath'};
16704: $initial_env{"browser.localres"} = $form->{'localres'};
16705: }
16706:
16707: if ($form->{'interface'}) {
16708: $form->{'interface'}=~s/\W//gs;
16709: $initial_env{"browser.interface"} = $form->{'interface'};
16710: $env{'browser.interface'}=$form->{'interface'};
16711: }
16712:
1.1157 raeburn 16713: if ($form->{'iptoken'}) {
16714: my $lonhost = $r->dir_config('lonHostID');
16715: $initial_env{"user.noloadbalance"} = $lonhost;
16716: $env{'user.noloadbalance'} = $lonhost;
16717: }
16718:
1.1268 raeburn 16719: if ($form->{'noloadbalance'}) {
16720: my @hosts = &Apache::lonnet::current_machine_ids();
16721: my $hosthere = $form->{'noloadbalance'};
16722: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16723: $initial_env{"user.noloadbalance"} = $hosthere;
16724: $env{'user.noloadbalance'} = $hosthere;
16725: }
16726: }
16727:
1.1016 raeburn 16728: unless ($domain eq 'public') {
1.1273 raeburn 16729: my %is_adv = ( is_adv => $env{'user.adv'} );
16730: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16731:
16732: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16733: $userenv{'availabletools.'.$tool} =
16734: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16735: undef,\%userenv,\%domdef,\%is_adv);
16736: }
1.980 raeburn 16737:
1.1311 raeburn 16738: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16739: $userenv{'canrequest.'.$crstype} =
16740: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16741: 'reload','requestcourses',
16742: \%userenv,\%domdef,\%is_adv);
16743: }
1.724 raeburn 16744:
1.1273 raeburn 16745: $userenv{'canrequest.author'} =
16746: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16747: 'reload','requestauthor',
1.980 raeburn 16748: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16749: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16750: $domain,$username);
16751: my $reqstatus = $reqauthor{'author_status'};
16752: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16753: if (ref($reqauthor{'author'}) eq 'HASH') {
16754: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16755: $reqauthor{'author'}{'timestamp'};
16756: }
1.1092 raeburn 16757: }
1.1287 raeburn 16758: my ($types,$typename) = &course_types();
16759: if (ref($types) eq 'ARRAY') {
16760: my @options = ('approval','validate','autolimit');
16761: my $optregex = join('|',@options);
16762: my (%willtrust,%trustchecked);
16763: foreach my $type (@{$types}) {
16764: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16765: if ($dom_str ne '') {
16766: my $updatedstr = '';
16767: my @possdomains = split(',',$dom_str);
16768: foreach my $entry (@possdomains) {
16769: my ($extdom,$extopt) = split(':',$entry);
16770: unless ($trustchecked{$extdom}) {
16771: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16772: $trustchecked{$extdom} = 1;
16773: }
16774: if ($willtrust{$extdom}) {
16775: $updatedstr .= $entry.',';
16776: }
16777: }
16778: $updatedstr =~ s/,$//;
16779: if ($updatedstr) {
16780: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16781: } else {
16782: delete($userenv{'reqcrsotherdom.'.$type});
16783: }
16784: }
16785: }
16786: }
1.1092 raeburn 16787: }
1.462 albertel 16788: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16789:
1.462 albertel 16790: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16791: &GDBM_WRCREAT(),0640)) {
16792: &_add_to_env(\%disk_env,\%initial_env);
16793: &_add_to_env(\%disk_env,\%userenv,'environment.');
16794: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16795: if (ref($firstaccenv) eq 'HASH') {
16796: &_add_to_env(\%disk_env,$firstaccenv);
16797: }
16798: if (ref($timerintenv) eq 'HASH') {
16799: &_add_to_env(\%disk_env,$timerintenv);
16800: }
1.463 albertel 16801: if (ref($args->{'extra_env'})) {
16802: &_add_to_env(\%disk_env,$args->{'extra_env'});
16803: }
1.462 albertel 16804: untie(%disk_env);
16805: } else {
1.705 tempelho 16806: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16807: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16808: return 'error: '.$!;
16809: }
16810: }
16811: $env{'request.role'}='cm';
16812: $env{'request.role.adv'}=$env{'user.adv'};
16813: $env{'browser.type'}=$clientbrowser;
16814:
16815: return $cookie;
16816:
16817: }
16818:
16819: sub _add_to_env {
16820: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16821: if (ref($env_data) eq 'HASH') {
16822: while (my ($key,$value) = each(%$env_data)) {
16823: $idf->{$prefix.$key} = $value;
16824: $env{$prefix.$key} = $value;
16825: }
1.462 albertel 16826: }
16827: }
16828:
1.685 tempelho 16829: # --- Get the symbolic name of a problem and the url
16830: sub get_symb {
16831: my ($request,$silent) = @_;
1.726 raeburn 16832: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16833: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16834: if ($symb eq '') {
16835: if (!$silent) {
1.1071 raeburn 16836: if (ref($request)) {
16837: $request->print("Unable to handle ambiguous references:$url:.");
16838: }
1.685 tempelho 16839: return ();
16840: }
16841: }
16842: &Apache::lonenc::check_decrypt(\$symb);
16843: return ($symb);
16844: }
16845:
16846: # --------------------------------------------------------------Get annotation
16847:
16848: sub get_annotation {
16849: my ($symb,$enc) = @_;
16850:
16851: my $key = $symb;
16852: if (!$enc) {
16853: $key =
16854: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16855: }
16856: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16857: return $annotation{$key};
16858: }
16859:
16860: sub clean_symb {
1.731 raeburn 16861: my ($symb,$delete_enc) = @_;
1.685 tempelho 16862:
16863: &Apache::lonenc::check_decrypt(\$symb);
16864: my $enc = $env{'request.enc'};
1.731 raeburn 16865: if ($delete_enc) {
1.730 raeburn 16866: delete($env{'request.enc'});
16867: }
1.685 tempelho 16868:
16869: return ($symb,$enc);
16870: }
1.462 albertel 16871:
1.1181 raeburn 16872: ############################################################
16873: ############################################################
16874:
16875: =pod
16876:
16877: =head1 Routines for building display used to search for courses
16878:
16879:
16880: =over 4
16881:
16882: =item * &build_filters()
16883:
16884: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16885: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16886: and quotacheck.pl
16887:
1.1181 raeburn 16888:
16889: Inputs:
16890:
16891: filterlist - anonymous array of fields to include as potential filters
16892:
16893: crstype - course type
16894:
16895: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16896: to pop-open a course selector (will contain "extra element").
16897:
16898: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16899:
16900: filter - anonymous hash of criteria and their values
16901:
16902: action - form action
16903:
16904: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16905:
1.1182 raeburn 16906: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16907:
16908: cloneruname - username of owner of new course who wants to clone
16909:
16910: clonerudom - domain of owner of new course who wants to clone
16911:
16912: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16913:
16914: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16915:
16916: codedom - domain
16917:
16918: formname - value of form element named "form".
16919:
16920: fixeddom - domain, if fixed.
16921:
16922: prevphase - value to assign to form element named "phase" when going back to the previous screen
16923:
16924: cnameelement - name of form element in form on opener page which will receive title of selected course
16925:
16926: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16927:
16928: cdomelement - name of form element in form on opener page which will receive domain of selected course
16929:
16930: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16931:
16932: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16933:
16934: clonewarning - warning message about missing information for intended course owner when DC creates a course
16935:
1.1182 raeburn 16936:
1.1181 raeburn 16937: Returns: $output - HTML for display of search criteria, and hidden form elements.
16938:
1.1182 raeburn 16939:
1.1181 raeburn 16940: Side Effects: None
16941:
16942: =cut
16943:
16944: # ---------------------------------------------- search for courses based on last activity etc.
16945:
16946: sub build_filters {
16947: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16948: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16949: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16950: $cnameelement,$cnumelement,$cdomelement,$setroles,
16951: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16952: my ($list,$jscript);
1.1181 raeburn 16953: my $onchange = 'javascript:updateFilters(this)';
16954: my ($domainselectform,$sincefilterform,$createdfilterform,
16955: $ownerdomselectform,$persondomselectform,$instcodeform,
16956: $typeselectform,$instcodetitle);
16957: if ($formname eq '') {
16958: $formname = $caller;
16959: }
16960: foreach my $item (@{$filterlist}) {
16961: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16962: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16963: if ($item eq 'domainfilter') {
16964: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16965: } elsif ($item eq 'coursefilter') {
16966: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16967: } elsif ($item eq 'ownerfilter') {
16968: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16969: } elsif ($item eq 'ownerdomfilter') {
16970: $filter->{'ownerdomfilter'} =
16971: &LONCAPA::clean_domain($filter->{$item});
16972: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16973: 'ownerdomfilter',1);
16974: } elsif ($item eq 'personfilter') {
16975: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16976: } elsif ($item eq 'persondomfilter') {
16977: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16978: 'persondomfilter',1);
16979: } else {
16980: $filter->{$item} =~ s/\W//g;
16981: }
16982: if (!$filter->{$item}) {
16983: $filter->{$item} = '';
16984: }
16985: }
16986: if ($item eq 'domainfilter') {
16987: my $allow_blank = 1;
16988: if ($formname eq 'portform') {
16989: $allow_blank=0;
16990: } elsif ($formname eq 'studentform') {
16991: $allow_blank=0;
16992: }
16993: if ($fixeddom) {
16994: $domainselectform = '<input type="hidden" name="domainfilter"'.
16995: ' value="'.$codedom.'" />'.
16996: &Apache::lonnet::domain($codedom,'description');
16997: } else {
16998: $domainselectform = &select_dom_form($filter->{$item},
16999: 'domainfilter',
17000: $allow_blank,'',$onchange);
17001: }
17002: } else {
17003: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17004: }
17005: }
17006:
17007: # last course activity filter and selection
17008: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17009:
17010: # course created filter and selection
17011: if (exists($filter->{'createdfilter'})) {
17012: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17013: }
17014:
1.1239 raeburn 17015: my $prefix = $crstype;
17016: if ($crstype eq 'Placement') {
17017: $prefix = 'Placement Test'
17018: }
1.1181 raeburn 17019: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17020: 'cac' => "$prefix Activity",
17021: 'ccr' => "$prefix Created",
17022: 'cde' => "$prefix Title",
17023: 'cdo' => "$prefix Domain",
1.1181 raeburn 17024: 'ins' => 'Institutional Code',
17025: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17026: 'cow' => "$prefix Owner/Co-owner",
17027: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17028: 'cog' => 'Type',
17029: );
17030:
17031: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17032: my $typeval = 'Course';
17033: if ($crstype eq 'Community') {
17034: $typeval = 'Community';
1.1239 raeburn 17035: } elsif ($crstype eq 'Placement') {
17036: $typeval = 'Placement';
1.1181 raeburn 17037: }
17038: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17039: } else {
17040: $typeselectform = '<select name="type" size="1"';
17041: if ($onchange) {
17042: $typeselectform .= ' onchange="'.$onchange.'"';
17043: }
17044: $typeselectform .= '>'."\n";
1.1237 raeburn 17045: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17046: my $shown;
17047: if ($posstype eq 'Placement') {
17048: $shown = &mt('Placement Test');
17049: } else {
17050: $shown = &mt($posstype);
17051: }
1.1181 raeburn 17052: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17053: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17054: }
17055: $typeselectform.="</select>";
17056: }
17057:
17058: my ($cloneableonlyform,$cloneabletitle);
17059: if (exists($filter->{'cloneableonly'})) {
17060: my $cloneableon = '';
17061: my $cloneableoff = ' checked="checked"';
17062: if ($filter->{'cloneableonly'}) {
17063: $cloneableon = $cloneableoff;
17064: $cloneableoff = '';
17065: }
17066: $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>';
17067: if ($formname eq 'ccrs') {
1.1187 bisitz 17068: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17069: } else {
17070: $cloneabletitle = &mt('Cloneable by you');
17071: }
17072: }
17073: my $officialjs;
17074: if ($crstype eq 'Course') {
17075: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17076: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17077: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17078: if ($codedom) {
1.1181 raeburn 17079: $officialjs = 1;
17080: ($instcodeform,$jscript,$$numtitlesref) =
17081: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17082: $officialjs,$codetitlesref);
17083: if ($jscript) {
1.1182 raeburn 17084: $jscript = '<script type="text/javascript">'."\n".
17085: '// <![CDATA['."\n".
17086: $jscript."\n".
17087: '// ]]>'."\n".
17088: '</script>'."\n";
1.1181 raeburn 17089: }
17090: }
17091: if ($instcodeform eq '') {
17092: $instcodeform =
17093: '<input type="text" name="instcodefilter" size="10" value="'.
17094: $list->{'instcodefilter'}.'" />';
17095: $instcodetitle = $lt{'ins'};
17096: } else {
17097: $instcodetitle = $lt{'inc'};
17098: }
17099: if ($fixeddom) {
17100: $instcodetitle .= '<br />('.$codedom.')';
17101: }
17102: }
17103: }
17104: my $output = qq|
17105: <form method="post" name="filterpicker" action="$action">
17106: <input type="hidden" name="form" value="$formname" />
17107: |;
17108: if ($formname eq 'modifycourse') {
17109: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17110: '<input type="hidden" name="prevphase" value="'.
17111: $prevphase.'" />'."\n";
1.1198 musolffc 17112: } elsif ($formname eq 'quotacheck') {
17113: $output .= qq|
17114: <input type="hidden" name="sortby" value="" />
17115: <input type="hidden" name="sortorder" value="" />
17116: |;
17117: } else {
1.1181 raeburn 17118: my $name_input;
17119: if ($cnameelement ne '') {
17120: $name_input = '<input type="hidden" name="cnameelement" value="'.
17121: $cnameelement.'" />';
17122: }
17123: $output .= qq|
1.1182 raeburn 17124: <input type="hidden" name="cnumelement" value="$cnumelement" />
17125: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17126: $name_input
17127: $roleelement
17128: $multelement
17129: $typeelement
17130: |;
17131: if ($formname eq 'portform') {
17132: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17133: }
17134: }
17135: if ($fixeddom) {
17136: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17137: }
17138: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17139: if ($sincefilterform) {
17140: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17141: .$sincefilterform
17142: .&Apache::lonhtmlcommon::row_closure();
17143: }
17144: if ($createdfilterform) {
17145: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17146: .$createdfilterform
17147: .&Apache::lonhtmlcommon::row_closure();
17148: }
17149: if ($domainselectform) {
17150: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17151: .$domainselectform
17152: .&Apache::lonhtmlcommon::row_closure();
17153: }
17154: if ($typeselectform) {
17155: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17156: $output .= $typeselectform;
17157: } else {
17158: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17159: .$typeselectform
17160: .&Apache::lonhtmlcommon::row_closure();
17161: }
17162: }
17163: if ($instcodeform) {
17164: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17165: .$instcodeform
17166: .&Apache::lonhtmlcommon::row_closure();
17167: }
17168: if (exists($filter->{'ownerfilter'})) {
17169: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17170: '<table><tr><td>'.&mt('Username').'<br />'.
17171: '<input type="text" name="ownerfilter" size="20" value="'.
17172: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17173: $ownerdomselectform.'</td></tr></table>'.
17174: &Apache::lonhtmlcommon::row_closure();
17175: }
17176: if (exists($filter->{'personfilter'})) {
17177: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17178: '<table><tr><td>'.&mt('Username').'<br />'.
17179: '<input type="text" name="personfilter" size="20" value="'.
17180: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17181: $persondomselectform.'</td></tr></table>'.
17182: &Apache::lonhtmlcommon::row_closure();
17183: }
17184: if (exists($filter->{'coursefilter'})) {
17185: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17186: .'<input type="text" name="coursefilter" size="25" value="'
17187: .$list->{'coursefilter'}.'" />'
17188: .&Apache::lonhtmlcommon::row_closure();
17189: }
17190: if ($cloneableonlyform) {
17191: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17192: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17193: }
17194: if (exists($filter->{'descriptfilter'})) {
17195: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17196: .'<input type="text" name="descriptfilter" size="40" value="'
17197: .$list->{'descriptfilter'}.'" />'
17198: .&Apache::lonhtmlcommon::row_closure(1);
17199: }
17200: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17201: '<input type="hidden" name="updater" value="" />'."\n".
17202: '<input type="submit" name="gosearch" value="'.
17203: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17204: return $jscript.$clonewarning.$output;
17205: }
17206:
17207: =pod
17208:
17209: =item * &timebased_select_form()
17210:
1.1182 raeburn 17211: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17212: filter e.g., Course Activity, Course Created, when searching for courses
17213: or communities
17214:
17215: Inputs:
17216:
17217: item - name of form element (sincefilter or createdfilter)
17218:
17219: filter - anonymous hash of criteria and their values
17220:
17221: Returns: HTML for a select box contained a blank, then six time selections,
17222: with value set in incoming form variables currently selected.
17223:
17224: Side Effects: None
17225:
17226: =cut
17227:
17228: sub timebased_select_form {
17229: my ($item,$filter) = @_;
17230: if (ref($filter) eq 'HASH') {
17231: $filter->{$item} =~ s/[^\d-]//g;
17232: if (!$filter->{$item}) { $filter->{$item}=-1; }
17233: return &select_form(
17234: $filter->{$item},
17235: $item,
17236: { '-1' => '',
17237: '86400' => &mt('today'),
17238: '604800' => &mt('last week'),
17239: '2592000' => &mt('last month'),
17240: '7776000' => &mt('last three months'),
17241: '15552000' => &mt('last six months'),
17242: '31104000' => &mt('last year'),
17243: 'select_form_order' =>
17244: ['-1','86400','604800','2592000','7776000',
17245: '15552000','31104000']});
17246: }
17247: }
17248:
17249: =pod
17250:
17251: =item * &js_changer()
17252:
17253: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17254: when course type or domain is changed, and also to hide 'Searching ...' on
17255: page load completion for page showing search result.
1.1181 raeburn 17256:
17257: Inputs: None
17258:
1.1183 raeburn 17259: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17260:
17261: Side Effects: None
17262:
17263: =cut
17264:
17265: sub js_changer {
17266: return <<ENDJS;
17267: <script type="text/javascript">
17268: // <![CDATA[
17269: function updateFilters(caller) {
17270: if (typeof(caller) != "undefined") {
17271: document.filterpicker.updater.value = caller.name;
17272: }
17273: document.filterpicker.submit();
17274: }
1.1183 raeburn 17275:
17276: function hideSearching() {
17277: if (document.getElementById('searching')) {
17278: document.getElementById('searching').style.display = 'none';
17279: }
17280: return;
17281: }
17282:
1.1181 raeburn 17283: // ]]>
17284: </script>
17285:
17286: ENDJS
17287: }
17288:
17289: =pod
17290:
1.1182 raeburn 17291: =item * &search_courses()
17292:
17293: Process selected filters form course search form and pass to lonnet::courseiddump
17294: to retrieve a hash for which keys are courseIDs which match the selected filters.
17295:
17296: Inputs:
17297:
17298: dom - domain being searched
17299:
17300: type - course type ('Course' or 'Community' or '.' if any).
17301:
17302: filter - anonymous hash of criteria and their values
17303:
17304: numtitles - for institutional codes - number of categories
17305:
17306: cloneruname - optional username of new course owner
17307:
17308: clonerudom - optional domain of new course owner
17309:
1.1221 raeburn 17310: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17311: (used when DC is using course creation form)
17312:
17313: codetitles - reference to array of titles of components in institutional codes (official courses).
17314:
1.1221 raeburn 17315: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17316: (and so can clone automatically)
17317:
17318: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17319:
17320: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17321: courses to clone
1.1182 raeburn 17322:
17323: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17324:
17325:
17326: Side Effects: None
17327:
17328: =cut
17329:
17330:
17331: sub search_courses {
1.1221 raeburn 17332: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17333: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17334: my (%courses,%showcourses,$cloner);
17335: if (($filter->{'ownerfilter'} ne '') ||
17336: ($filter->{'ownerdomfilter'} ne '')) {
17337: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17338: $filter->{'ownerdomfilter'};
17339: }
17340: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17341: if (!$filter->{$item}) {
17342: $filter->{$item}='.';
17343: }
17344: }
17345: my $now = time;
17346: my $timefilter =
17347: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17348: my ($createdbefore,$createdafter);
17349: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17350: $createdbefore = $now;
17351: $createdafter = $now-$filter->{'createdfilter'};
17352: }
17353: my ($instcodefilter,$regexpok);
17354: if ($numtitles) {
17355: if ($env{'form.official'} eq 'on') {
17356: $instcodefilter =
17357: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17358: $regexpok = 1;
17359: } elsif ($env{'form.official'} eq 'off') {
17360: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17361: unless ($instcodefilter eq '') {
17362: $regexpok = -1;
17363: }
17364: }
17365: } else {
17366: $instcodefilter = $filter->{'instcodefilter'};
17367: }
17368: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17369: if ($type eq '') { $type = '.'; }
17370:
17371: if (($clonerudom ne '') && ($cloneruname ne '')) {
17372: $cloner = $cloneruname.':'.$clonerudom;
17373: }
17374: %courses = &Apache::lonnet::courseiddump($dom,
17375: $filter->{'descriptfilter'},
17376: $timefilter,
17377: $instcodefilter,
17378: $filter->{'combownerfilter'},
17379: $filter->{'coursefilter'},
17380: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17381: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17382: $filter->{'cloneableonly'},
17383: $createdbefore,$createdafter,undef,
1.1221 raeburn 17384: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17385: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17386: my $ccrole;
17387: if ($type eq 'Community') {
17388: $ccrole = 'co';
17389: } else {
17390: $ccrole = 'cc';
17391: }
17392: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17393: $filter->{'persondomfilter'},
17394: 'userroles',undef,
17395: [$ccrole,'in','ad','ep','ta','cr'],
17396: $dom);
17397: foreach my $role (keys(%rolehash)) {
17398: my ($cnum,$cdom,$courserole) = split(':',$role);
17399: my $cid = $cdom.'_'.$cnum;
17400: if (exists($courses{$cid})) {
17401: if (ref($courses{$cid}) eq 'HASH') {
17402: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17403: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17404: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17405: }
17406: } else {
17407: $courses{$cid}{roles} = [$courserole];
17408: }
17409: $showcourses{$cid} = $courses{$cid};
17410: }
17411: }
17412: }
17413: %courses = %showcourses;
17414: }
17415: return %courses;
17416: }
17417:
17418: =pod
17419:
1.1181 raeburn 17420: =back
17421:
1.1207 raeburn 17422: =head1 Routines for version requirements for current course.
17423:
17424: =over 4
17425:
17426: =item * &check_release_required()
17427:
17428: Compares required LON-CAPA version with version on server, and
17429: if required version is newer looks for a server with the required version.
17430:
17431: Looks first at servers in user's owen domain; if none suitable, looks at
17432: servers in course's domain are permitted to host sessions for user's domain.
17433:
17434: Inputs:
17435:
17436: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17437:
17438: $courseid - Course ID of current course
17439:
17440: $rolecode - User's current role in course (for switchserver query string).
17441:
17442: $required - LON-CAPA version needed by course (format: Major.Minor).
17443:
17444:
17445: Returns:
17446:
17447: $switchserver - query string tp append to /adm/switchserver call (if
17448: current server's LON-CAPA version is too old.
17449:
17450: $warning - Message is displayed if no suitable server could be found.
17451:
17452: =cut
17453:
17454: sub check_release_required {
17455: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17456: my ($switchserver,$warning);
17457: if ($required ne '') {
17458: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17459: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17460: if ($reqdmajor ne '' && $reqdminor ne '') {
17461: my $otherserver;
17462: if (($major eq '' && $minor eq '') ||
17463: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17464: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17465: my $switchlcrev =
17466: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17467: $userdomserver);
17468: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17469: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17470: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17471: my $cdom = $env{'course.'.$courseid.'.domain'};
17472: if ($cdom ne $env{'user.domain'}) {
17473: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17474: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17475: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17476: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17477: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17478: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17479: my $canhost =
17480: &Apache::lonnet::can_host_session($env{'user.domain'},
17481: $coursedomserver,
17482: $remoterev,
17483: $udomdefaults{'remotesessions'},
17484: $defdomdefaults{'hostedsessions'});
17485:
17486: if ($canhost) {
17487: $otherserver = $coursedomserver;
17488: } else {
17489: $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.");
17490: }
17491: } else {
17492: $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).");
17493: }
17494: } else {
17495: $otherserver = $userdomserver;
17496: }
17497: }
17498: if ($otherserver ne '') {
17499: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17500: }
17501: }
17502: }
17503: return ($switchserver,$warning);
17504: }
17505:
17506: =pod
17507:
17508: =item * &check_release_result()
17509:
17510: Inputs:
17511:
17512: $switchwarning - Warning message if no suitable server found to host session.
17513:
17514: $switchserver - query string to append to /adm/switchserver containing lonHostID
17515: and current role.
17516:
17517: Returns: HTML to display with information about requirement to switch server.
17518: Either displaying warning with link to Roles/Courses screen or
17519: display link to switchserver.
17520:
1.1181 raeburn 17521: =cut
17522:
1.1207 raeburn 17523: sub check_release_result {
17524: my ($switchwarning,$switchserver) = @_;
17525: my $output = &start_page('Selected course unavailable on this server').
17526: '<p class="LC_warning">';
17527: if ($switchwarning) {
17528: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17529: if (&show_course()) {
17530: $output .= &mt('Display courses');
17531: } else {
17532: $output .= &mt('Display roles');
17533: }
17534: $output .= '</a>';
17535: } elsif ($switchserver) {
17536: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17537: '<br />'.
17538: '<a href="/adm/switchserver?'.$switchserver.'">'.
17539: &mt('Switch Server').
17540: '</a>';
17541: }
17542: $output .= '</p>'.&end_page();
17543: return $output;
17544: }
17545:
17546: =pod
17547:
17548: =item * &needs_coursereinit()
17549:
17550: Determine if course contents stored for user's session needs to be
17551: refreshed, because content has changed since "Big Hash" last tied.
17552:
17553: Check for change is made if time last checked is more than 10 minutes ago
17554: (by default).
17555:
17556: Inputs:
17557:
17558: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17559:
17560: $interval (optional) - Time which may elapse (in s) between last check for content
17561: change in current course. (default: 600 s).
17562:
17563: Returns: an array; first element is:
17564:
17565: =over 4
17566:
17567: 'switch' - if content updates mean user's session
17568: needs to be switched to a server running a newer LON-CAPA version
17569:
17570: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17571: on current server hosting user's session
17572:
17573: '' - if no action required.
17574:
17575: =back
17576:
17577: If first item element is 'switch':
17578:
17579: second item is $switchwarning - Warning message if no suitable server found to host session.
17580:
17581: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17582: and current role.
17583:
17584: otherwise: no other elements returned.
17585:
17586: =back
17587:
17588: =cut
17589:
17590: sub needs_coursereinit {
17591: my ($loncaparev,$interval) = @_;
17592: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17593: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17594: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17595: my $now = time;
17596: if ($interval eq '') {
17597: $interval = 600;
17598: }
17599: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17600: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17601: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17602: if ($blocked) {
17603: return ();
17604: }
1.1207 raeburn 17605: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17606: if ($lastchange > $env{'request.course.tied'}) {
17607: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17608: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17609: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17610: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17611: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17612: $curr_reqd_hash{'internal.releaserequired'}});
17613: my ($switchserver,$switchwarning) =
17614: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17615: $curr_reqd_hash{'internal.releaserequired'});
17616: if ($switchwarning ne '' || $switchserver ne '') {
17617: return ('switch',$switchwarning,$switchserver);
17618: }
17619: }
17620: }
17621: return ('update');
17622: }
17623: }
17624: return ();
17625: }
1.1181 raeburn 17626:
1.1083 raeburn 17627: sub update_content_constraints {
1.1326 raeburn 17628: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17629: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17630: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17631: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17632: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17633: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17634: if ($item eq 'resourcetag') {
17635: if ($name eq 'responsetype') {
17636: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17637: }
1.1307 raeburn 17638: } elsif ($item eq 'course') {
17639: if ($name eq 'courserestype') {
17640: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17641: }
1.1083 raeburn 17642: }
17643: }
17644: my $navmap = Apache::lonnavmaps::navmap->new();
17645: if (defined($navmap)) {
1.1307 raeburn 17646: my (%allresponses,%allcrsrestypes);
17647: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17648: if ($res->is_tool()) {
17649: if ($allcrsrestypes{'exttool'}) {
17650: $allcrsrestypes{'exttool'} ++;
17651: } else {
17652: $allcrsrestypes{'exttool'} = 1;
17653: }
17654: next;
17655: }
1.1083 raeburn 17656: my %responses = $res->responseTypes();
17657: foreach my $key (keys(%responses)) {
17658: next unless(exists($checkresponsetypes{$key}));
17659: $allresponses{$key} += $responses{$key};
17660: }
17661: }
17662: foreach my $key (keys(%allresponses)) {
17663: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17664: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17665: ($reqdmajor,$reqdminor) = ($major,$minor);
17666: }
17667: }
1.1307 raeburn 17668: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17669: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17670: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17671: ($reqdmajor,$reqdminor) = ($major,$minor);
17672: }
17673: }
1.1083 raeburn 17674: undef($navmap);
17675: }
1.1326 raeburn 17676: my (@resources,@order,@resparms,@zombies);
17677: if ($keeporder) {
17678: use LONCAPA::map;
17679: @resources = @LONCAPA::map::resources;
17680: @order = @LONCAPA::map::order;
17681: @resparms = @LONCAPA::map::resparms;
17682: @zombies = @LONCAPA::map::zombies;
17683: }
1.1308 raeburn 17684: my $suppmap = 'supplemental.sequence';
17685: my ($suppcount,$supptools,$errors) = (0,0,0);
17686: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17687: $suppcount,$supptools,$errors);
1.1326 raeburn 17688: if ($keeporder) {
17689: @LONCAPA::map::resources = @resources;
17690: @LONCAPA::map::order = @order;
17691: @LONCAPA::map::resparms = @resparms;
17692: @LONCAPA::map::zombies = @zombies;
17693: }
1.1308 raeburn 17694: if ($supptools) {
17695: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17696: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17697: ($reqdmajor,$reqdminor) = ($major,$minor);
17698: }
17699: }
1.1083 raeburn 17700: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17701: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17702: }
17703: return;
17704: }
17705:
1.1110 raeburn 17706: sub allmaps_incourse {
17707: my ($cdom,$cnum,$chome,$cid) = @_;
17708: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17709: $cid = $env{'request.course.id'};
17710: $cdom = $env{'course.'.$cid.'.domain'};
17711: $cnum = $env{'course.'.$cid.'.num'};
17712: $chome = $env{'course.'.$cid.'.home'};
17713: }
17714: my %allmaps = ();
17715: my $lastchange =
17716: &Apache::lonnet::get_coursechange($cdom,$cnum);
17717: if ($lastchange > $env{'request.course.tied'}) {
17718: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17719: unless ($ferr) {
1.1326 raeburn 17720: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17721: }
17722: }
17723: my $navmap = Apache::lonnavmaps::navmap->new();
17724: if (defined($navmap)) {
17725: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17726: $allmaps{$res->src()} = 1;
17727: }
17728: }
17729: return \%allmaps;
17730: }
17731:
1.1083 raeburn 17732: sub parse_supplemental_title {
17733: my ($title) = @_;
17734:
17735: my ($foldertitle,$renametitle);
17736: if ($title =~ /&&&/) {
17737: $title = &HTML::Entites::decode($title);
17738: }
17739: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17740: $renametitle=$4;
17741: my ($time,$uname,$udom) = ($1,$2,$3);
17742: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17743: my $name = &plainname($uname,$udom);
17744: $name = &HTML::Entities::encode($name,'"<>&\'');
17745: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17746: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17747: $name.': <br />'.$foldertitle;
17748: }
17749: if (wantarray) {
17750: return ($title,$foldertitle,$renametitle);
17751: }
17752: return $title;
17753: }
17754:
1.1143 raeburn 17755: sub recurse_supplemental {
1.1308 raeburn 17756: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17757: if ($suppmap) {
17758: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17759: if ($fatal) {
17760: $errors ++;
17761: } else {
17762: if ($#LONCAPA::map::resources > 0) {
17763: foreach my $res (@LONCAPA::map::resources) {
17764: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17765: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17766: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17767: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17768: $numfiles,$numexttools,$errors);
1.1143 raeburn 17769: } else {
1.1308 raeburn 17770: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17771: $numexttools ++;
17772: }
1.1143 raeburn 17773: $numfiles ++;
17774: }
17775: }
17776: }
17777: }
17778: }
17779: }
1.1308 raeburn 17780: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17781: }
17782:
1.1101 raeburn 17783: sub symb_to_docspath {
1.1267 raeburn 17784: my ($symb,$navmapref) = @_;
17785: return unless ($symb && ref($navmapref));
1.1101 raeburn 17786: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17787: if ($resurl=~/\.(sequence|page)$/) {
17788: $mapurl=$resurl;
17789: } elsif ($resurl eq 'adm/navmaps') {
17790: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17791: }
17792: my $mapresobj;
1.1267 raeburn 17793: unless (ref($$navmapref)) {
17794: $$navmapref = Apache::lonnavmaps::navmap->new();
17795: }
17796: if (ref($$navmapref)) {
17797: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17798: }
17799: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17800: my $type=$2;
17801: my $path;
17802: if (ref($mapresobj)) {
17803: my $pcslist = $mapresobj->map_hierarchy();
17804: if ($pcslist ne '') {
17805: foreach my $pc (split(/,/,$pcslist)) {
17806: next if ($pc <= 1);
1.1267 raeburn 17807: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17808: if (ref($res)) {
17809: my $thisurl = $res->src();
17810: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17811: my $thistitle = $res->title();
17812: $path .= '&'.
17813: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17814: &escape($thistitle).
1.1101 raeburn 17815: ':'.$res->randompick().
17816: ':'.$res->randomout().
17817: ':'.$res->encrypted().
17818: ':'.$res->randomorder().
17819: ':'.$res->is_page();
17820: }
17821: }
17822: }
17823: $path =~ s/^\&//;
17824: my $maptitle = $mapresobj->title();
17825: if ($mapurl eq 'default') {
1.1129 raeburn 17826: $maptitle = 'Main Content';
1.1101 raeburn 17827: }
17828: $path .= (($path ne '')? '&' : '').
17829: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17830: &escape($maptitle).
1.1101 raeburn 17831: ':'.$mapresobj->randompick().
17832: ':'.$mapresobj->randomout().
17833: ':'.$mapresobj->encrypted().
17834: ':'.$mapresobj->randomorder().
17835: ':'.$mapresobj->is_page();
17836: } else {
17837: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17838: my $ispage = (($type eq 'page')? 1 : '');
17839: if ($mapurl eq 'default') {
1.1129 raeburn 17840: $maptitle = 'Main Content';
1.1101 raeburn 17841: }
17842: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17843: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17844: }
17845: unless ($mapurl eq 'default') {
17846: $path = 'default&'.
1.1146 raeburn 17847: &escape('Main Content').
1.1101 raeburn 17848: ':::::&'.$path;
17849: }
17850: return $path;
17851: }
17852:
1.1094 raeburn 17853: sub captcha_display {
1.1327 raeburn 17854: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17855: my ($output,$error);
1.1234 raeburn 17856: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17857: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17858: if ($captcha eq 'original') {
1.1094 raeburn 17859: $output = &create_captcha();
17860: unless ($output) {
1.1172 raeburn 17861: $error = 'captcha';
1.1094 raeburn 17862: }
17863: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17864: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17865: unless ($output) {
1.1172 raeburn 17866: $error = 'recaptcha';
1.1094 raeburn 17867: }
17868: }
1.1234 raeburn 17869: return ($output,$error,$captcha,$version);
1.1094 raeburn 17870: }
17871:
17872: sub captcha_response {
1.1327 raeburn 17873: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17874: my ($captcha_chk,$captcha_error);
1.1327 raeburn 17875: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17876: if ($captcha eq 'original') {
1.1094 raeburn 17877: ($captcha_chk,$captcha_error) = &check_captcha();
17878: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17879: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17880: } else {
17881: $captcha_chk = 1;
17882: }
17883: return ($captcha_chk,$captcha_error);
17884: }
17885:
17886: sub get_captcha_config {
1.1327 raeburn 17887: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 17888: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17889: my $hostname = &Apache::lonnet::hostname($lonhost);
17890: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17891: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17892: if ($context eq 'usercreation') {
17893: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17894: if (ref($domconfig{$context}) eq 'HASH') {
17895: $hashtocheck = $domconfig{$context}{'cancreate'};
17896: if (ref($hashtocheck) eq 'HASH') {
17897: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17898: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17899: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17900: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17901: }
17902: if ($privkey && $pubkey) {
17903: $captcha = 'recaptcha';
1.1234 raeburn 17904: $version = $hashtocheck->{'recaptchaversion'};
17905: if ($version ne '2') {
17906: $version = 1;
17907: }
1.1095 raeburn 17908: } else {
17909: $captcha = 'original';
17910: }
17911: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17912: $captcha = 'original';
17913: }
1.1094 raeburn 17914: }
1.1095 raeburn 17915: } else {
17916: $captcha = 'captcha';
17917: }
17918: } elsif ($context eq 'login') {
17919: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17920: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17921: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17922: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17923: if ($privkey && $pubkey) {
17924: $captcha = 'recaptcha';
1.1234 raeburn 17925: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17926: if ($version ne '2') {
17927: $version = 1;
17928: }
1.1095 raeburn 17929: } else {
17930: $captcha = 'original';
1.1094 raeburn 17931: }
1.1095 raeburn 17932: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17933: $captcha = 'original';
1.1094 raeburn 17934: }
1.1327 raeburn 17935: } elsif ($context eq 'passwords') {
17936: if ($dom_in_effect) {
17937: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17938: if ($passwdconf{'captcha'} eq 'recaptcha') {
17939: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17940: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17941: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17942: }
17943: if ($privkey && $pubkey) {
17944: $captcha = 'recaptcha';
17945: $version = $passwdconf{'recaptchaversion'};
17946: if ($version ne '2') {
17947: $version = 1;
17948: }
17949: } else {
17950: $captcha = 'original';
17951: }
17952: } elsif ($passwdconf{'captcha'} ne 'notused') {
17953: $captcha = 'original';
17954: }
17955: }
17956: }
1.1234 raeburn 17957: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17958: }
17959:
17960: sub create_captcha {
17961: my %captcha_params = &captcha_settings();
17962: my ($output,$maxtries,$tries) = ('',10,0);
17963: while ($tries < $maxtries) {
17964: $tries ++;
17965: my $captcha = Authen::Captcha->new (
17966: output_folder => $captcha_params{'output_dir'},
17967: data_folder => $captcha_params{'db_dir'},
17968: );
17969: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17970:
17971: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17972: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17973: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17974: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17975: '<br />'.
17976: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17977: last;
17978: }
17979: }
1.1323 raeburn 17980: if ($output eq '') {
17981: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17982: }
1.1094 raeburn 17983: return $output;
17984: }
17985:
17986: sub captcha_settings {
17987: my %captcha_params = (
17988: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17989: www_output_dir => "/captchaspool",
17990: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17991: numchars => '5',
17992: );
17993: return %captcha_params;
17994: }
17995:
17996: sub check_captcha {
17997: my ($captcha_chk,$captcha_error);
17998: my $code = $env{'form.code'};
17999: my $md5sum = $env{'form.crypt'};
18000: my %captcha_params = &captcha_settings();
18001: my $captcha = Authen::Captcha->new(
18002: output_folder => $captcha_params{'output_dir'},
18003: data_folder => $captcha_params{'db_dir'},
18004: );
1.1109 raeburn 18005: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18006: my %captcha_hash = (
18007: 0 => 'Code not checked (file error)',
18008: -1 => 'Failed: code expired',
18009: -2 => 'Failed: invalid code (not in database)',
18010: -3 => 'Failed: invalid code (code does not match crypt)',
18011: );
18012: if ($captcha_chk != 1) {
18013: $captcha_error = $captcha_hash{$captcha_chk}
18014: }
18015: return ($captcha_chk,$captcha_error);
18016: }
18017:
18018: sub create_recaptcha {
1.1234 raeburn 18019: my ($pubkey,$version) = @_;
18020: if ($version >= 2) {
18021: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
18022: } else {
18023: my $use_ssl;
18024: if ($ENV{'SERVER_PORT'} == 443) {
18025: $use_ssl = 1;
18026: }
18027: my $captcha = Captcha::reCAPTCHA->new;
18028: return $captcha->get_options_setter({theme => 'white'})."\n".
18029: $captcha->get_html($pubkey,undef,$use_ssl).
18030: &mt('If the text is hard to read, [_1] will replace them.',
18031: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18032: '<br /><br />';
18033: }
1.1094 raeburn 18034: }
18035:
18036: sub check_recaptcha {
1.1234 raeburn 18037: my ($privkey,$version) = @_;
1.1094 raeburn 18038: my $captcha_chk;
1.1234 raeburn 18039: if ($version >= 2) {
18040: my %info = (
18041: secret => $privkey,
18042: response => $env{'form.g-recaptcha-response'},
18043: remoteip => $ENV{'REMOTE_ADDR'},
18044: );
1.1280 raeburn 18045: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18046: $request->content(join('&',map {
18047: my $name = escape($_);
18048: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18049: ? join("&$name=", map {escape($_) } @{$info{$_}})
18050: : &escape($info{$_}) );
18051: } keys(%info)));
18052: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18053: if ($response->is_success) {
18054: my $data = JSON::DWIW->from_json($response->decoded_content);
18055: if (ref($data) eq 'HASH') {
18056: if ($data->{'success'}) {
18057: $captcha_chk = 1;
18058: }
18059: }
18060: }
18061: } else {
18062: my $captcha = Captcha::reCAPTCHA->new;
18063: my $captcha_result =
18064: $captcha->check_answer(
18065: $privkey,
18066: $ENV{'REMOTE_ADDR'},
18067: $env{'form.recaptcha_challenge_field'},
18068: $env{'form.recaptcha_response_field'},
18069: );
18070: if ($captcha_result->{is_valid}) {
18071: $captcha_chk = 1;
18072: }
1.1094 raeburn 18073: }
18074: return $captcha_chk;
18075: }
18076:
1.1174 raeburn 18077: sub emailusername_info {
1.1244 raeburn 18078: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18079: my %titles = &Apache::lonlocal::texthash (
18080: lastname => 'Last Name',
18081: firstname => 'First Name',
18082: institution => 'School/college/university',
18083: location => "School's city, state/province, country",
18084: web => "School's web address",
18085: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18086: id => 'Student/Employee ID',
1.1174 raeburn 18087: );
18088: return (\@fields,\%titles);
18089: }
18090:
1.1161 raeburn 18091: sub cleanup_html {
18092: my ($incoming) = @_;
18093: my $outgoing;
18094: if ($incoming ne '') {
18095: $outgoing = $incoming;
18096: $outgoing =~ s/;/;/g;
18097: $outgoing =~ s/\#/#/g;
18098: $outgoing =~ s/\&/&/g;
18099: $outgoing =~ s/</</g;
18100: $outgoing =~ s/>/>/g;
18101: $outgoing =~ s/\(/(/g;
18102: $outgoing =~ s/\)/)/g;
18103: $outgoing =~ s/"/"/g;
18104: $outgoing =~ s/'/'/g;
18105: $outgoing =~ s/\$/$/g;
18106: $outgoing =~ s{/}{/}g;
18107: $outgoing =~ s/=/=/g;
18108: $outgoing =~ s/\\/\/g
18109: }
18110: return $outgoing;
18111: }
18112:
1.1190 musolffc 18113: # Checks for critical messages and returns a redirect url if one exists.
18114: # $interval indicates how often to check for messages.
1.1282 raeburn 18115: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18116: sub critical_redirect {
1.1282 raeburn 18117: my ($interval,$context) = @_;
1.1190 musolffc 18118: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18119: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18120: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18121: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18122: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18123: if ($blocked) {
18124: my $checkrole = "cm./$cdom/$cnum";
18125: if ($env{'request.course.sec'} ne '') {
18126: $checkrole .= "/$env{'request.course.sec'}";
18127: }
18128: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18129: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18130: return;
18131: }
18132: }
18133: }
1.1190 musolffc 18134: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18135: $env{'user.name'});
18136: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18137: my $redirecturl;
1.1190 musolffc 18138: if ($what[0]) {
18139: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18140: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18141: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18142: return (1, $url);
1.1190 musolffc 18143: }
1.1191 raeburn 18144: }
18145: }
18146: return ();
1.1190 musolffc 18147: }
18148:
1.1174 raeburn 18149: # Use:
18150: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18151: #
18152: ##################################################
18153: # password associated functions #
18154: ##################################################
18155: sub des_keys {
18156: # Make a new key for DES encryption.
18157: # Each key has two parts which are returned separately.
18158: # Please note: Each key must be passed through the &hex function
18159: # before it is output to the web browser. The hex versions cannot
18160: # be used to decrypt.
18161: my @hexstr=('0','1','2','3','4','5','6','7',
18162: '8','9','a','b','c','d','e','f');
18163: my $lkey='';
18164: for (0..7) {
18165: $lkey.=$hexstr[rand(15)];
18166: }
18167: my $ukey='';
18168: for (0..7) {
18169: $ukey.=$hexstr[rand(15)];
18170: }
18171: return ($lkey,$ukey);
18172: }
18173:
18174: sub des_decrypt {
18175: my ($key,$cyphertext) = @_;
18176: my $keybin=pack("H16",$key);
18177: my $cypher;
18178: if ($Crypt::DES::VERSION>=2.03) {
18179: $cypher=new Crypt::DES $keybin;
18180: } else {
18181: $cypher=new DES $keybin;
18182: }
1.1233 raeburn 18183: my $plaintext='';
18184: my $cypherlength = length($cyphertext);
18185: my $numchunks = int($cypherlength/32);
18186: for (my $j=0; $j<$numchunks; $j++) {
18187: my $start = $j*32;
18188: my $cypherblock = substr($cyphertext,$start,32);
18189: my $chunk =
18190: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18191: $chunk .=
18192: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18193: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18194: $plaintext .= $chunk;
18195: }
1.1174 raeburn 18196: return $plaintext;
18197: }
18198:
1.1309 raeburn 18199: sub make_short_symbs {
18200: my ($cdom,$cnum,$navmap) = @_;
18201: return unless (ref($navmap));
18202: my ($numnew,@errors);
18203: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18204: if (@toshorten) {
18205: my (%maps,%resources,%titles);
18206: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18207: 'shorturls',$cdom,$cnum);
18208: my %tocreate;
18209: if (keys(%resources)) {
18210: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18211: my $symb = $resources{$item};
18212: if ($symb) {
18213: $tocreate{$cnum.'&'.$symb} = 1;
18214: }
18215: }
18216: }
18217: if (keys(%tocreate)) {
18218: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18219: my $su = Short::URL->new(no_vowels => 1);
18220: my $init = '';
18221: my (%newunique,%addcourse,%courseonly,%failed);
18222: # get lock on tiny db
18223: my $now = time;
18224: my $lockhash = {
18225: "lock\0$now" => $env{'user.name'}.
18226: ':'.$env{'user.domain'},
18227: };
18228: my $tries = 0;
18229: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18230: my ($code,$error);
18231: while (($gotlock ne 'ok') && ($tries<3)) {
18232: $tries ++;
18233: sleep 1;
1.1319 raeburn 18234: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18235: }
18236: if ($gotlock eq 'ok') {
18237: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18238: \%addcourse,\%courseonly,\%failed);
18239: if (keys(%failed)) {
18240: my $numfailed = scalar(keys(%failed));
18241: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18242: }
18243: if (keys(%newunique)) {
18244: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18245: if ($putres eq 'ok') {
18246: $numnew = scalar(keys(%newunique));
18247: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18248: unless ($newputres eq 'ok') {
18249: push(@errors,&mt('error: could not store course look-up of short URLs'));
18250: }
18251: } else {
18252: push(@errors,&mt('error: could not store unique six character URLs'));
18253: }
18254: }
18255: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18256: unless ($dellockres eq 'ok') {
18257: push(@errors,&mt('error: could not release lockfile'));
18258: }
18259: } else {
18260: push(@errors,&mt('error: could not obtain lockfile'));
18261: }
18262: if (keys(%courseonly)) {
18263: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18264: if ($result ne 'ok') {
18265: push(@errors,&mt('error: could not update course look-up of short URLs'));
18266: }
18267: }
18268: }
18269: }
18270: return ($numnew,\@errors);
18271: }
18272:
18273: sub shorten_symbs {
18274: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18275: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18276: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18277: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18278: my (%possibles,%collisions);
18279: foreach my $key (keys(%{$tocreate})) {
18280: my $num = String::CRC32::crc32($key);
18281: my $tiny = $su->encode($num,$init);
18282: if ($tiny) {
18283: $possibles{$tiny} = $key;
18284: }
18285: }
18286: if (!$init) {
18287: $init = 1;
18288: } else {
18289: $init ++;
18290: }
18291: if (keys(%possibles)) {
18292: my @posstiny = keys(%possibles);
18293: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18294: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18295: if (keys(%currtiny)) {
18296: foreach my $key (keys(%currtiny)) {
18297: next if ($currtiny{$key} eq '');
18298: if ($currtiny{$key} eq $possibles{$key}) {
18299: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18300: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18301: $courseonly->{$tsymb} = $key;
18302: }
18303: } else {
18304: $collisions{$possibles{$key}} = 1;
18305: }
18306: delete($possibles{$key});
18307: }
18308: }
18309: foreach my $key (keys(%possibles)) {
18310: $newunique->{$key} = $possibles{$key};
18311: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18312: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18313: $addcourse->{$tsymb} = $key;
18314: }
18315: }
18316: }
18317: if (keys(%collisions)) {
18318: if ($init <5) {
18319: if (!$init) {
18320: $init = 1;
18321: } else {
18322: $init ++;
18323: }
18324: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18325: $newunique,$addcourse,$courseonly,$failed);
18326: } else {
18327: foreach my $key (keys(%collisions)) {
18328: $failed->{$key} = 1;
18329: }
18330: }
18331: }
18332: return $init;
18333: }
18334:
1.1328 raeburn 18335: sub is_nonframeable {
1.1329 raeburn 18336: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18337: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18338: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18339:
18340: $remprotocol = lc($remprotocol);
18341: $remhost = lc($remhost);
18342: my $remport = 80;
18343: if ($remprotocol eq 'https') {
18344: $remport = 443;
18345: }
1.1330 raeburn 18346: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18347: if ($cached) {
18348: unless ($nocache) {
18349: if ($result) {
18350: return 1;
18351: } else {
18352: return 0;
18353: }
18354: }
18355: }
1.1328 raeburn 18356: my $uselink;
18357: my $request = new HTTP::Request('HEAD',$url);
18358: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18359: if ($response->is_success()) {
18360: my $secpolicy = lc($response->header('content-security-policy'));
18361: my $xframeop = lc($response->header('x-frame-options'));
18362: $secpolicy =~ s/^\s+|\s+$//g;
18363: $xframeop =~ s/^\s+|\s+$//g;
18364: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18365: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18366: my ($origin,$protocol,$port);
18367: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18368: $port = $ENV{'SERVER_PORT'};
18369: } else {
18370: $port = 80;
18371: }
18372: if ($absolute eq '') {
18373: $protocol = 'http:';
18374: if ($port == 443) {
18375: $protocol = 'https:';
18376: }
18377: $origin = $protocol.'//'.lc($hostname);
18378: } else {
18379: $origin = lc($absolute);
18380: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18381: }
18382: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18383: my $framepolicy = $1;
18384: $framepolicy =~ s/^\s+|\s+$//g;
18385: my @policies = split(/\s+/,$framepolicy);
18386: if (@policies) {
18387: if (grep(/^\Q'none'\E$/,@policies)) {
18388: $uselink = 1;
18389: } else {
18390: $uselink = 1;
18391: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18392: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18393: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18394: undef($uselink);
18395: }
18396: if ($uselink) {
18397: if (grep(/^\Q'self'\E$/,@policies)) {
18398: if (($origin ne '') && ($remotehost eq $origin)) {
18399: undef($uselink);
18400: }
18401: }
18402: }
18403: if ($uselink) {
18404: my @possok;
18405: if ($ip ne '') {
18406: push(@possok,$ip);
18407: }
18408: my $hoststr = '';
18409: foreach my $part (reverse(split(/\./,$hostname))) {
18410: if ($hoststr eq '') {
18411: $hoststr = $part;
18412: } else {
18413: $hoststr = "$part.$hoststr";
18414: }
18415: if ($hoststr eq $hostname) {
18416: push(@possok,$hostname);
18417: } else {
18418: push(@possok,"*.$hoststr");
18419: }
18420: }
18421: if (@possok) {
18422: foreach my $poss (@possok) {
18423: last if (!$uselink);
18424: foreach my $policy (@policies) {
18425: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18426: undef($uselink);
18427: last;
18428: }
18429: }
18430: }
18431: }
18432: }
18433: }
18434: }
18435: } elsif ($xframeop ne '') {
18436: $uselink = 1;
18437: my @policies = split(/\s*,\s*/,$xframeop);
18438: if (@policies) {
18439: unless (grep(/^deny$/,@policies)) {
18440: if ($origin ne '') {
18441: if (grep(/^sameorigin$/,@policies)) {
18442: if ($remotehost eq $origin) {
18443: undef($uselink);
18444: }
18445: }
18446: if ($uselink) {
18447: foreach my $policy (@policies) {
18448: if ($policy =~ /^allow-from\s*(.+)$/) {
18449: my $allowfrom = $1;
18450: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18451: undef($uselink);
18452: last;
18453: }
18454: }
18455: }
18456: }
18457: }
18458: }
18459: }
18460: }
18461: }
18462: }
1.1329 raeburn 18463: if ($nocache) {
18464: if ($cached) {
18465: my $devalidate;
18466: if ($uselink && !$result) {
18467: $devalidate = 1;
18468: } elsif (!$uselink && $result) {
18469: $devalidate = 1;
18470: }
18471: if ($devalidate) {
18472: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18473: }
18474: }
18475: } else {
18476: if ($uselink) {
18477: $result = 1;
18478: } else {
18479: $result = 0;
18480: }
18481: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18482: }
1.1328 raeburn 18483: return $uselink;
18484: }
18485:
1.112 bowersj2 18486: 1;
18487: __END__;
1.41 ng 18488:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>