Annotation of loncom/interface/loncommon.pm, revision 1.1348
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1348 ! raeburn 4: # $Id: loncommon.pm,v 1.1347 2020/09/28 00:10:28 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.1347 raeburn 5151: my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
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) =
1.1347 raeburn 5157: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 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' ||
1.1346 raeburn 5175: $activity eq 'search' || $activity eq 'reinit' ||
5176: $activity eq 'alert') &&
1.1189 raeburn 5177: ($env{'request.course.id'})) {
1.490 raeburn 5178: foreach my $key (keys(%live_courses)) {
5179: if ($key ne $env{'request.course.id'}) {
5180: delete($live_courses{$key});
5181: }
5182: }
5183: }
5184:
5185: my $otheruser = 0;
5186: my %own_courses;
5187: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5188: # Resource belongs to user other than current user.
5189: $otheruser = 1;
5190: # Gather courses for current user
5191: %own_courses =
5192: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5193: }
5194:
5195: # Gather active course roles - course coordinator, instructor,
5196: # exam proctor, ta, student, or custom role.
1.474 raeburn 5197:
5198: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5199: my ($cdom,$cnum);
5200: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5201: $cdom = $env{'course.'.$course.'.domain'};
5202: $cnum = $env{'course.'.$course.'.num'};
5203: } else {
1.490 raeburn 5204: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5205: }
5206: my $no_ownblock = 0;
5207: my $no_userblock = 0;
1.533 raeburn 5208: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5209: # Check if current user has 'evb' priv for this
5210: if (defined($own_courses{$course})) {
5211: foreach my $sec (keys(%{$own_courses{$course}})) {
5212: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5213: if ($sec ne 'none') {
5214: $checkrole .= '/'.$sec;
5215: }
5216: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5217: $no_ownblock = 1;
5218: last;
5219: }
5220: }
5221: }
5222: # if they have 'evb' priv and are currently not playing student
5223: next if (($no_ownblock) &&
5224: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5225: }
1.474 raeburn 5226: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5227: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5228: if ($sec ne 'none') {
1.482 raeburn 5229: $checkrole .= '/'.$sec;
1.474 raeburn 5230: }
1.490 raeburn 5231: if ($otheruser) {
5232: # Resource belongs to user other than current user.
5233: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5234: my (%allroles,%userroles);
5235: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5236: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5237: my ($trole,$tdom,$tnum,$tsec);
5238: if ($entry =~ /^cr/) {
5239: ($trole,$tdom,$tnum,$tsec) =
5240: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5241: } else {
5242: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5243: }
5244: my ($spec,$area,$trest);
5245: $area = '/'.$tdom.'/'.$tnum;
5246: $trest = $tnum;
5247: if ($tsec ne '') {
5248: $area .= '/'.$tsec;
5249: $trest .= '/'.$tsec;
5250: }
5251: $spec = $trole.'.'.$area;
5252: if ($trole =~ /^cr/) {
5253: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5254: $tdom,$spec,$trest,$area);
5255: } else {
5256: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5257: $tdom,$spec,$trest,$area);
5258: }
5259: }
1.1276 raeburn 5260: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5261: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5262: if ($1) {
5263: $no_userblock = 1;
5264: last;
5265: }
1.486 raeburn 5266: }
5267: }
1.490 raeburn 5268: } else {
5269: # Resource belongs to current user
5270: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5271: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5272: $no_ownblock = 1;
5273: last;
5274: }
1.474 raeburn 5275: }
5276: }
5277: # if they have the evb priv and are currently not playing student
1.482 raeburn 5278: next if (($no_ownblock) &&
1.491 albertel 5279: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5280: next if ($no_userblock);
1.474 raeburn 5281:
1.1303 raeburn 5282: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5283: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5284:
1.1062 raeburn 5285: my ($start,$end,$trigger) =
1.1347 raeburn 5286: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5287: if (($start != 0) &&
5288: (($startblock == 0) || ($startblock > $start))) {
5289: $startblock = $start;
1.1062 raeburn 5290: if ($trigger ne '') {
5291: $triggerblock = $trigger;
5292: }
1.502 raeburn 5293: }
5294: if (($end != 0) &&
5295: (($endblock == 0) || ($endblock < $end))) {
5296: $endblock = $end;
1.1062 raeburn 5297: if ($trigger ne '') {
5298: $triggerblock = $trigger;
5299: }
1.502 raeburn 5300: }
1.490 raeburn 5301: }
1.1062 raeburn 5302: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5303: }
5304:
5305: sub get_blocks {
1.1347 raeburn 5306: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5307: my $startblock = 0;
5308: my $endblock = 0;
1.1062 raeburn 5309: my $triggerblock = '';
1.490 raeburn 5310: my $course = $cdom.'_'.$cnum;
5311: $setters->{$course} = {};
5312: $setters->{$course}{'staff'} = [];
5313: $setters->{$course}{'times'} = [];
1.1062 raeburn 5314: $setters->{$course}{'triggers'} = [];
5315: my (@blockers,%triggered);
5316: my $now = time;
5317: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5318: if ($activity eq 'docs') {
1.1348 ! raeburn 5319: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5320: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5321: $blocked = 1;
5322: $nosymbcache = 1;
1.1348 ! raeburn 5323: $noenccheck = 1;
1.1347 raeburn 5324: }
1.1348 ! raeburn 5325: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5326: foreach my $block (@blockers) {
5327: if ($block =~ /^firstaccess____(.+)$/) {
5328: my $item = $1;
5329: my $type = 'map';
5330: my $timersymb = $item;
5331: if ($item eq 'course') {
5332: $type = 'course';
5333: } elsif ($item =~ /___\d+___/) {
5334: $type = 'resource';
5335: } else {
5336: $timersymb = &Apache::lonnet::symbread($item);
5337: }
5338: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5339: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5340: $triggered{$block} = {
5341: start => $start,
5342: end => $end,
5343: type => $type,
5344: };
5345: }
5346: }
5347: } else {
5348: foreach my $block (keys(%commblocks)) {
5349: if ($block =~ m/^(\d+)____(\d+)$/) {
5350: my ($start,$end) = ($1,$2);
5351: if ($start <= time && $end >= time) {
5352: if (ref($commblocks{$block}) eq 'HASH') {
5353: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5354: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5355: unless(grep(/^\Q$block\E$/,@blockers)) {
5356: push(@blockers,$block);
5357: }
5358: }
5359: }
5360: }
5361: }
5362: } elsif ($block =~ /^firstaccess____(.+)$/) {
5363: my $item = $1;
5364: my $timersymb = $item;
5365: my $type = 'map';
5366: if ($item eq 'course') {
5367: $type = 'course';
5368: } elsif ($item =~ /___\d+___/) {
5369: $type = 'resource';
5370: } else {
5371: $timersymb = &Apache::lonnet::symbread($item);
5372: }
5373: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5374: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5375: if ($start && $end) {
5376: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5377: if (ref($commblocks{$block}) eq 'HASH') {
5378: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5379: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5380: unless(grep(/^\Q$block\E$/,@blockers)) {
5381: push(@blockers,$block);
5382: $triggered{$block} = {
5383: start => $start,
5384: end => $end,
5385: type => $type,
5386: };
5387: }
5388: }
5389: }
1.1062 raeburn 5390: }
5391: }
1.490 raeburn 5392: }
1.1062 raeburn 5393: }
5394: }
5395: }
5396: foreach my $blocker (@blockers) {
5397: my ($staff_name,$staff_dom,$title,$blocks) =
5398: &parse_block_record($commblocks{$blocker});
5399: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5400: my ($start,$end,$triggertype);
5401: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5402: ($start,$end) = ($1,$2);
5403: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5404: $start = $triggered{$blocker}{'start'};
5405: $end = $triggered{$blocker}{'end'};
5406: $triggertype = $triggered{$blocker}{'type'};
5407: }
5408: if ($start) {
5409: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5410: if ($triggertype) {
5411: push(@{$$setters{$course}{'triggers'}},$triggertype);
5412: } else {
5413: push(@{$$setters{$course}{'triggers'}},0);
5414: }
5415: if ( ($startblock == 0) || ($startblock > $start) ) {
5416: $startblock = $start;
5417: if ($triggertype) {
5418: $triggerblock = $blocker;
1.474 raeburn 5419: }
5420: }
1.1062 raeburn 5421: if ( ($endblock == 0) || ($endblock < $end) ) {
5422: $endblock = $end;
5423: if ($triggertype) {
5424: $triggerblock = $blocker;
5425: }
5426: }
1.474 raeburn 5427: }
5428: }
1.1062 raeburn 5429: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5430: }
5431:
5432: sub parse_block_record {
5433: my ($record) = @_;
5434: my ($setuname,$setudom,$title,$blocks);
5435: if (ref($record) eq 'HASH') {
5436: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5437: $title = &unescape($record->{'event'});
5438: $blocks = $record->{'blocks'};
5439: } else {
5440: my @data = split(/:/,$record,3);
5441: if (scalar(@data) eq 2) {
5442: $title = $data[1];
5443: ($setuname,$setudom) = split(/@/,$data[0]);
5444: } else {
5445: ($setuname,$setudom,$title) = @data;
5446: }
5447: $blocks = { 'com' => 'on' };
5448: }
5449: return ($setuname,$setudom,$title,$blocks);
5450: }
5451:
1.854 kalberla 5452: sub blocking_status {
1.1347 raeburn 5453: my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5454: my %setters;
1.890 droeschl 5455:
1.1061 raeburn 5456: # check for active blocking
1.1062 raeburn 5457: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5458: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5459: my $blocked = 0;
5460: if ($startblock && $endblock) {
5461: $blocked = 1;
5462: }
1.890 droeschl 5463:
1.1061 raeburn 5464: # caller just wants to know whether a block is active
5465: if (!wantarray) { return $blocked; }
5466:
5467: # build a link to a popup window containing the details
5468: my $querystring = "?activity=$activity";
5469: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5470: if (($activity eq 'port') || ($activity eq 'passwd')) {
5471: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5472: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5473: } elsif ($activity eq 'docs') {
1.1347 raeburn 5474: my $showurl = &Apache::lonenc::check_encrypt($url);
5475: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5476: if ($symb) {
5477: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5478: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5479: }
1.1062 raeburn 5480: }
1.1061 raeburn 5481:
5482: my $output .= <<'END_MYBLOCK';
5483: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5484: var options = "width=" + w + ",height=" + h + ",";
5485: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5486: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5487: var newWin = window.open(url, wdwName, options);
5488: newWin.focus();
5489: }
1.890 droeschl 5490: END_MYBLOCK
1.854 kalberla 5491:
1.1061 raeburn 5492: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5493:
1.1061 raeburn 5494: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5495: my $text = &mt('Communication Blocked');
1.1217 raeburn 5496: my $class = 'LC_comblock';
1.1062 raeburn 5497: if ($activity eq 'docs') {
5498: $text = &mt('Content Access Blocked');
1.1217 raeburn 5499: $class = '';
1.1063 raeburn 5500: } elsif ($activity eq 'printout') {
5501: $text = &mt('Printing Blocked');
1.1232 raeburn 5502: } elsif ($activity eq 'passwd') {
5503: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5504: } elsif ($activity eq 'grades') {
5505: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5506: } elsif ($activity eq 'search') {
5507: $text = &mt('Search Blocked');
1.1282 raeburn 5508: } elsif ($activity eq 'alert') {
5509: $text = &mt('Checking Critical Messages Blocked');
5510: } elsif ($activity eq 'reinit') {
5511: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5512: }
1.1061 raeburn 5513: $output .= <<"END_BLOCK";
1.1217 raeburn 5514: <div class='$class'>
1.869 kalberla 5515: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5516: title='$text'>
5517: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5518: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5519: title='$text'>$text</a>
1.867 kalberla 5520: </div>
5521:
5522: END_BLOCK
1.474 raeburn 5523:
1.1061 raeburn 5524: return ($blocked, $output);
1.854 kalberla 5525: }
1.490 raeburn 5526:
1.60 matthew 5527: ###############################################
5528:
1.682 raeburn 5529: sub check_ip_acc {
1.1201 raeburn 5530: my ($acc,$clientip)=@_;
1.682 raeburn 5531: &Apache::lonxml::debug("acc is $acc");
5532: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5533: return 1;
5534: }
1.1339 raeburn 5535: my ($ip,$allowed);
5536: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5537: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5538: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5539: } else {
5540: $ip = $ENV{'REMOTE_ADDR'} || $env{'request.host'} || $clientip;
5541: }
1.682 raeburn 5542:
5543: my $name;
1.1219 raeburn 5544: my %access = (
5545: allowfrom => 1,
5546: denyfrom => 0,
5547: );
5548: my @allows;
5549: my @denies;
5550: foreach my $item (split(',',$acc)) {
5551: $item =~ s/^\s*//;
5552: $item =~ s/\s*$//;
5553: my $pattern;
5554: if ($item =~ /^\!(.+)$/) {
5555: push(@denies,$1);
5556: } else {
5557: push(@allows,$item);
5558: }
5559: }
5560: my $numdenies = scalar(@denies);
5561: my $numallows = scalar(@allows);
5562: my $count = 0;
5563: foreach my $pattern (@denies,@allows) {
5564: $count ++;
5565: my $acctype = 'allowfrom';
5566: if ($count <= $numdenies) {
5567: $acctype = 'denyfrom';
5568: }
1.682 raeburn 5569: if ($pattern =~ /\*$/) {
5570: #35.8.*
5571: $pattern=~s/\*//;
1.1219 raeburn 5572: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5573: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5574: #35.8.3.[34-56]
5575: my $low=$2;
5576: my $high=$3;
5577: $pattern=$1;
5578: if ($ip =~ /^\Q$pattern\E/) {
5579: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5580: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5581: }
5582: } elsif ($pattern =~ /^\*/) {
5583: #*.msu.edu
5584: $pattern=~s/\*//;
5585: if (!defined($name)) {
5586: use Socket;
5587: my $netaddr=inet_aton($ip);
5588: ($name)=gethostbyaddr($netaddr,AF_INET);
5589: }
1.1219 raeburn 5590: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5591: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5592: #127.0.0.1
1.1219 raeburn 5593: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5594: } else {
5595: #some.name.com
5596: if (!defined($name)) {
5597: use Socket;
5598: my $netaddr=inet_aton($ip);
5599: ($name)=gethostbyaddr($netaddr,AF_INET);
5600: }
1.1219 raeburn 5601: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5602: }
5603: if ($allowed =~ /^(0|1)$/) { last; }
5604: }
5605: if ($allowed eq '') {
5606: if ($numdenies && !$numallows) {
5607: $allowed = 1;
5608: } else {
5609: $allowed = 0;
1.682 raeburn 5610: }
5611: }
5612: return $allowed;
5613: }
5614:
5615: ###############################################
5616:
1.60 matthew 5617: =pod
5618:
1.112 bowersj2 5619: =head1 Domain Template Functions
5620:
5621: =over 4
5622:
5623: =item * &determinedomain()
1.60 matthew 5624:
5625: Inputs: $domain (usually will be undef)
5626:
1.63 www 5627: Returns: Determines which domain should be used for designs
1.60 matthew 5628:
5629: =cut
1.54 www 5630:
1.60 matthew 5631: ###############################################
1.63 www 5632: sub determinedomain {
5633: my $domain=shift;
1.531 albertel 5634: if (! $domain) {
1.60 matthew 5635: # Determine domain if we have not been given one
1.893 raeburn 5636: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5637: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5638: if ($env{'request.role.domain'}) {
5639: $domain=$env{'request.role.domain'};
1.60 matthew 5640: }
5641: }
1.63 www 5642: return $domain;
5643: }
5644: ###############################################
1.517 raeburn 5645:
1.518 albertel 5646: sub devalidate_domconfig_cache {
5647: my ($udom)=@_;
5648: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5649: }
5650:
5651: # ---------------------- Get domain configuration for a domain
5652: sub get_domainconf {
5653: my ($udom) = @_;
5654: my $cachetime=1800;
5655: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5656: if (defined($cached)) { return %{$result}; }
5657:
5658: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5659: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5660: my (%designhash,%legacy);
1.518 albertel 5661: if (keys(%domconfig) > 0) {
5662: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5663: if (keys(%{$domconfig{'login'}})) {
5664: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5665: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5666: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5667: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5668: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5669: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5670: if ($key eq 'loginvia') {
5671: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5672: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5673: $designhash{$udom.'.login.loginvia'} = $server;
5674: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5675:
5676: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5677: } else {
5678: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5679: }
1.948 raeburn 5680: }
1.1208 raeburn 5681: } elsif ($key eq 'headtag') {
5682: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5683: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5684: }
1.946 raeburn 5685: }
1.1208 raeburn 5686: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5687: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5688: }
1.946 raeburn 5689: }
5690: }
5691: }
5692: } else {
5693: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5694: $designhash{$udom.'.login.'.$key.'_'.$img} =
5695: $domconfig{'login'}{$key}{$img};
5696: }
1.699 raeburn 5697: }
5698: } else {
5699: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5700: }
1.632 raeburn 5701: }
5702: } else {
5703: $legacy{'login'} = 1;
1.518 albertel 5704: }
1.632 raeburn 5705: } else {
5706: $legacy{'login'} = 1;
1.518 albertel 5707: }
5708: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5709: if (keys(%{$domconfig{'rolecolors'}})) {
5710: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5711: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5712: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5713: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5714: }
1.518 albertel 5715: }
5716: }
1.632 raeburn 5717: } else {
5718: $legacy{'rolecolors'} = 1;
1.518 albertel 5719: }
1.632 raeburn 5720: } else {
5721: $legacy{'rolecolors'} = 1;
1.518 albertel 5722: }
1.948 raeburn 5723: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5724: if ($domconfig{'autoenroll'}{'co-owners'}) {
5725: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5726: }
5727: }
1.632 raeburn 5728: if (keys(%legacy) > 0) {
5729: my %legacyhash = &get_legacy_domconf($udom);
5730: foreach my $item (keys(%legacyhash)) {
5731: if ($item =~ /^\Q$udom\E\.login/) {
5732: if ($legacy{'login'}) {
5733: $designhash{$item} = $legacyhash{$item};
5734: }
5735: } else {
5736: if ($legacy{'rolecolors'}) {
5737: $designhash{$item} = $legacyhash{$item};
5738: }
1.518 albertel 5739: }
5740: }
5741: }
1.632 raeburn 5742: } else {
5743: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5744: }
5745: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5746: $cachetime);
5747: return %designhash;
5748: }
5749:
1.632 raeburn 5750: sub get_legacy_domconf {
5751: my ($udom) = @_;
5752: my %legacyhash;
5753: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5754: my $designfile = $designdir.'/'.$udom.'.tab';
5755: if (-e $designfile) {
1.1317 raeburn 5756: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5757: while (my $line = <$fh>) {
5758: next if ($line =~ /^\#/);
5759: chomp($line);
5760: my ($key,$val)=(split(/\=/,$line));
5761: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5762: }
5763: close($fh);
5764: }
5765: }
1.1026 raeburn 5766: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5767: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5768: }
5769: return %legacyhash;
5770: }
5771:
1.63 www 5772: =pod
5773:
1.112 bowersj2 5774: =item * &domainlogo()
1.63 www 5775:
5776: Inputs: $domain (usually will be undef)
5777:
5778: Returns: A link to a domain logo, if the domain logo exists.
5779: If the domain logo does not exist, a description of the domain.
5780:
5781: =cut
1.112 bowersj2 5782:
1.63 www 5783: ###############################################
5784: sub domainlogo {
1.517 raeburn 5785: my $domain = &determinedomain(shift);
1.518 albertel 5786: my %designhash = &get_domainconf($domain);
1.517 raeburn 5787: # See if there is a logo
5788: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5789: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5790: if ($imgsrc =~ m{^/(adm|res)/}) {
5791: if ($imgsrc =~ m{^/res/}) {
5792: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5793: &Apache::lonnet::repcopy($local_name);
5794: }
5795: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5796: }
5797: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5798: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5799: return &Apache::lonnet::domain($domain,'description');
1.59 www 5800: } else {
1.60 matthew 5801: return '';
1.59 www 5802: }
5803: }
1.63 www 5804: ##############################################
5805:
5806: =pod
5807:
1.112 bowersj2 5808: =item * &designparm()
1.63 www 5809:
5810: Inputs: $which parameter; $domain (usually will be undef)
5811:
5812: Returns: value of designparamter $which
5813:
5814: =cut
1.112 bowersj2 5815:
1.397 albertel 5816:
1.400 albertel 5817: ##############################################
1.397 albertel 5818: sub designparm {
5819: my ($which,$domain)=@_;
5820: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5821: return $env{'environment.color.'.$which};
1.96 www 5822: }
1.63 www 5823: $domain=&determinedomain($domain);
1.1016 raeburn 5824: my %domdesign;
5825: unless ($domain eq 'public') {
5826: %domdesign = &get_domainconf($domain);
5827: }
1.520 raeburn 5828: my $output;
1.517 raeburn 5829: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5830: $output = $domdesign{$domain.'.'.$which};
1.63 www 5831: } else {
1.520 raeburn 5832: $output = $defaultdesign{$which};
5833: }
5834: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5835: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5836: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5837: if ($output =~ m{^/res/}) {
5838: my $local_name = &Apache::lonnet::filelocation('',$output);
5839: &Apache::lonnet::repcopy($local_name);
5840: }
1.520 raeburn 5841: $output = &lonhttpdurl($output);
5842: }
1.63 www 5843: }
1.520 raeburn 5844: return $output;
1.63 www 5845: }
1.59 www 5846:
1.822 bisitz 5847: ##############################################
5848: =pod
5849:
1.832 bisitz 5850: =item * &authorspace()
5851:
1.1028 raeburn 5852: Inputs: $url (usually will be undef).
1.832 bisitz 5853:
1.1132 raeburn 5854: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5855: directory being viewed (or for which action is being taken).
5856: If $url is provided, and begins /priv/<domain>/<uname>
5857: the path will be that portion of the $context argument.
5858: Otherwise the path will be for the author space of the current
5859: user when the current role is author, or for that of the
5860: co-author/assistant co-author space when the current role
5861: is co-author or assistant co-author.
1.832 bisitz 5862:
5863: =cut
5864:
5865: sub authorspace {
1.1028 raeburn 5866: my ($url) = @_;
5867: if ($url ne '') {
5868: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5869: return $1;
5870: }
5871: }
1.832 bisitz 5872: my $caname = '';
1.1024 www 5873: my $cadom = '';
1.1028 raeburn 5874: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5875: ($cadom,$caname) =
1.832 bisitz 5876: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5877: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5878: $caname = $env{'user.name'};
1.1024 www 5879: $cadom = $env{'user.domain'};
1.832 bisitz 5880: }
1.1028 raeburn 5881: if (($caname ne '') && ($cadom ne '')) {
5882: return "/priv/$cadom/$caname/";
5883: }
5884: return;
1.832 bisitz 5885: }
5886:
5887: ##############################################
5888: =pod
5889:
1.822 bisitz 5890: =item * &head_subbox()
5891:
5892: Inputs: $content (contains HTML code with page functions, etc.)
5893:
5894: Returns: HTML div with $content
5895: To be included in page header
5896:
5897: =cut
5898:
5899: sub head_subbox {
5900: my ($content)=@_;
5901: my $output =
1.993 raeburn 5902: '<div class="LC_head_subbox">'
1.822 bisitz 5903: .$content
5904: .'</div>'
5905: }
5906:
5907: ##############################################
5908: =pod
5909:
5910: =item * &CSTR_pageheader()
5911:
1.1026 raeburn 5912: Input: (optional) filename from which breadcrumb trail is built.
5913: In most cases no input as needed, as $env{'request.filename'}
5914: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5915:
5916: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5917: To be included on Authoring Space pages
1.822 bisitz 5918:
5919: =cut
5920:
5921: sub CSTR_pageheader {
1.1026 raeburn 5922: my ($trailfile) = @_;
5923: if ($trailfile eq '') {
5924: $trailfile = $env{'request.filename'};
5925: }
5926:
5927: # this is for resources; directories have customtitle, and crumbs
5928: # and select recent are created in lonpubdir.pm
5929:
5930: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5931: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5932: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5933: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5934: $formaction =~ s{/+}{/}g;
1.822 bisitz 5935:
5936: my $parentpath = '';
5937: my $lastitem = '';
5938: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5939: $parentpath = $1;
5940: $lastitem = $2;
5941: } else {
5942: $lastitem = $thisdisfn;
5943: }
1.921 bisitz 5944:
1.1246 raeburn 5945: my ($crsauthor,$title);
5946: if (($env{'request.course.id'}) &&
5947: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5948: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5949: $crsauthor = 1;
5950: $title = &mt('Course Authoring Space');
5951: } else {
5952: $title = &mt('Authoring Space');
5953: }
5954:
1.1314 raeburn 5955: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5956: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5957: $target = '';
5958: $crumbtarget = '';
1.1313 raeburn 5959: }
5960:
1.921 bisitz 5961: my $output =
1.822 bisitz 5962: '<div>'
5963: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5964: .'<b>'.$title.'</b> '
1.1314 raeburn 5965: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5966: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5967:
5968: if ($lastitem) {
5969: $output .=
5970: '<span class="LC_filename">'
5971: .$lastitem
5972: .'</span>';
5973: }
1.1245 raeburn 5974:
1.1246 raeburn 5975: if ($crsauthor) {
5976: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5977: } else {
5978: $output .=
5979: '<br />'
1.1314 raeburn 5980: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5981: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5982: .'</form>'
5983: .&Apache::lonmenu::constspaceform();
5984: }
5985: $output .= '</div>';
1.921 bisitz 5986:
5987: return $output;
1.822 bisitz 5988: }
5989:
1.60 matthew 5990: ###############################################
5991: ###############################################
5992:
5993: =pod
5994:
1.112 bowersj2 5995: =back
5996:
1.549 albertel 5997: =head1 HTML Helpers
1.112 bowersj2 5998:
5999: =over 4
6000:
6001: =item * &bodytag()
1.60 matthew 6002:
6003: Returns a uniform header for LON-CAPA web pages.
6004:
6005: Inputs:
6006:
1.112 bowersj2 6007: =over 4
6008:
6009: =item * $title, A title to be displayed on the page.
6010:
6011: =item * $function, the current role (can be undef).
6012:
6013: =item * $addentries, extra parameters for the <body> tag.
6014:
6015: =item * $bodyonly, if defined, only return the <body> tag.
6016:
6017: =item * $domain, if defined, force a given domain.
6018:
6019: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6020: text interface only)
1.60 matthew 6021:
1.814 bisitz 6022: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6023: navigational links
1.317 albertel 6024:
1.338 albertel 6025: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6026:
1.460 albertel 6027: =item * $args, optional argument valid values are
6028: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6029: use_absolute -> for external resource or syllabus, this will
6030: contain https://<hostname> if server uses
6031: https (as per hosts.tab), but request is for http
6032: hostname -> hostname, from $r->hostname().
1.460 albertel 6033:
1.1096 raeburn 6034: =item * $advtoolsref, optional argument, ref to an array containing
6035: inlineremote items to be added in "Functions" menu below
6036: breadcrumbs.
6037:
1.1316 raeburn 6038: =item * $ltiscope, optional argument, will be one of: resource, map or
6039: course, if LON-CAPA is in LTI Provider context. Value is
6040: the scope of use, i.e., launch was for access to a single, a map
6041: or the entire course.
6042:
6043: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6044: context, this will contain the URL for the landing item in
6045: the course, after launch from an LTI Consumer
6046:
1.1318 raeburn 6047: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6048: context, this will contain a reference to hash of items
6049: to be included in the page header and/or inline menu.
6050:
1.112 bowersj2 6051: =back
6052:
1.60 matthew 6053: Returns: A uniform header for LON-CAPA web pages.
6054: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6055: If $bodyonly is undef or zero, an html string containing a <body> tag and
6056: other decorations will be returned.
6057:
6058: =cut
6059:
1.54 www 6060: sub bodytag {
1.831 bisitz 6061: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 6062: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 6063:
1.954 raeburn 6064: my $public;
6065: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6066: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6067: $public = 1;
6068: }
1.460 albertel 6069: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6070: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6071: my $hostname = $args->{'hostname'};
1.339 albertel 6072:
1.183 matthew 6073: $function = &get_users_function() if (!$function);
1.339 albertel 6074: my $img = &designparm($function.'.img',$domain);
6075: my $font = &designparm($function.'.font',$domain);
6076: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6077:
1.803 bisitz 6078: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6079: 'bgcolor' => $pgbg,
1.339 albertel 6080: 'text' => $font,
6081: 'alink' => &designparm($function.'.alink',$domain),
6082: 'vlink' => &designparm($function.'.vlink',$domain),
6083: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6084: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6085:
1.63 www 6086: # role and realm
1.1178 raeburn 6087: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6088: if ($realm) {
6089: $realm = '/'.$realm;
6090: }
1.378 raeburn 6091: if ($role eq 'ca') {
1.479 albertel 6092: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6093: $realm = &plainname($rname,$rdom);
1.378 raeburn 6094: }
1.55 www 6095: # realm
1.258 albertel 6096: if ($env{'request.course.id'}) {
1.378 raeburn 6097: if ($env{'request.role'} !~ /^cr/) {
6098: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6099: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6100: if ($env{'request.role.desc'}) {
6101: $role = $env{'request.role.desc'};
6102: } else {
6103: $role = &mt('Helpdesk[_1]',' '.$2);
6104: }
1.1257 raeburn 6105: } else {
6106: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6107: }
1.898 raeburn 6108: if ($env{'request.course.sec'}) {
6109: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6110: }
1.359 albertel 6111: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6112: } else {
6113: $role = &Apache::lonnet::plaintext($role);
1.54 www 6114: }
1.433 albertel 6115:
1.359 albertel 6116: if (!$realm) { $realm=' '; }
1.330 albertel 6117:
1.438 albertel 6118: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6119:
1.101 www 6120: # construct main body tag
1.359 albertel 6121: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6122: &Apache::lontexconvert::init_math_support();
1.252 albertel 6123:
1.1131 raeburn 6124: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6125:
1.1130 raeburn 6126: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6127: return $bodytag;
1.1130 raeburn 6128: }
1.359 albertel 6129:
1.954 raeburn 6130: if ($public) {
1.433 albertel 6131: undef($role);
6132: }
1.1318 raeburn 6133:
6134: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6135: if (ref($ltimenu) eq 'HASH') {
6136: unless ($ltimenu->{'role'}) {
6137: undef($role);
6138: }
6139: unless ($ltimenu->{'coursetitle'}) {
6140: $realm=' ';
6141: }
6142: }
6143: }
6144:
1.762 bisitz 6145: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6146: #
6147: # Extra info if you are the DC
6148: my $dc_info = '';
6149: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6150: $env{'course.'.$env{'request.course.id'}.
6151: '.domain'}.'/'})) {
6152: my $cid = $env{'request.course.id'};
1.917 raeburn 6153: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6154: $dc_info =~ s/\s+$//;
1.359 albertel 6155: }
6156:
1.1237 raeburn 6157: my $crstype;
6158: if ($env{'request.course.id'}) {
6159: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6160: } elsif ($args->{'crstype'}) {
6161: $crstype = $args->{'crstype'};
6162: }
6163: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6164: undef($role);
6165: } else {
1.1242 raeburn 6166: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6167: }
1.853 droeschl 6168:
1.903 droeschl 6169: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6170:
6171: # if ($env{'request.state'} eq 'construct') {
6172: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6173: # }
6174:
1.1130 raeburn 6175: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6176: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6177:
1.1318 raeburn 6178: unless ($args->{'no_primary_menu'}) {
6179: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6180:
1.1318 raeburn 6181: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6182: if ($dc_info) {
6183: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6184: }
6185: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6186: <em>$realm</em> $dc_info</div>|;
6187: return $bodytag;
6188: }
1.894 droeschl 6189:
1.1318 raeburn 6190: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6191: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6192: }
1.916 droeschl 6193:
1.1318 raeburn 6194: $bodytag .= $right;
1.852 droeschl 6195:
1.1318 raeburn 6196: if ($dc_info) {
6197: $dc_info = &dc_courseid_toggle($dc_info);
6198: }
6199: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6200: }
1.916 droeschl 6201:
1.1169 raeburn 6202: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6203: if ($args->{'no_secondary_menu'}) {
6204: return $bodytag;
6205: }
1.1169 raeburn 6206: #don't show menus for public users
1.954 raeburn 6207: if (!$public){
1.1318 raeburn 6208: unless ($args->{'no_inline_menu'}) {
6209: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6210: $args->{'no_primary_menu'});
6211: }
1.903 droeschl 6212: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6213: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6214: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6215: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6216: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6217: } elsif ($forcereg) {
6218: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6219: $args->{'group'},
1.1274 raeburn 6220: $args->{'hide_buttons'},
1.1316 raeburn 6221: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6222: } else {
6223: $bodytag .=
6224: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6225: $forcereg,$args->{'group'},
6226: $args->{'bread_crumbs'},
1.1274 raeburn 6227: $advtoolsref,'',$hostname);
1.920 raeburn 6228: }
1.903 droeschl 6229: }else{
6230: # this is to seperate menu from content when there's no secondary
6231: # menu. Especially needed for public accessible ressources.
6232: $bodytag .= '<hr style="clear:both" />';
6233: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6234: }
1.903 droeschl 6235:
1.235 raeburn 6236: return $bodytag;
1.182 matthew 6237: }
6238:
1.917 raeburn 6239: sub dc_courseid_toggle {
6240: my ($dc_info) = @_;
1.980 raeburn 6241: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6242: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6243: &mt('(More ...)').'</a></span>'.
6244: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6245: }
6246:
1.330 albertel 6247: sub make_attr_string {
6248: my ($register,$attr_ref) = @_;
6249:
6250: if ($attr_ref && !ref($attr_ref)) {
6251: die("addentries Must be a hash ref ".
6252: join(':',caller(1))." ".
6253: join(':',caller(0))." ");
6254: }
6255:
6256: if ($register) {
1.339 albertel 6257: my ($on_load,$on_unload);
6258: foreach my $key (keys(%{$attr_ref})) {
6259: if (lc($key) eq 'onload') {
6260: $on_load.=$attr_ref->{$key}.';';
6261: delete($attr_ref->{$key});
6262:
6263: } elsif (lc($key) eq 'onunload') {
6264: $on_unload.=$attr_ref->{$key}.';';
6265: delete($attr_ref->{$key});
6266: }
6267: }
1.953 droeschl 6268: $attr_ref->{'onload'} = $on_load;
6269: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6270: }
1.339 albertel 6271:
1.330 albertel 6272: my $attr_string;
1.1159 raeburn 6273: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6274: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6275: }
6276: return $attr_string;
6277: }
6278:
6279:
1.182 matthew 6280: ###############################################
1.251 albertel 6281: ###############################################
6282:
6283: =pod
6284:
6285: =item * &endbodytag()
6286:
6287: Returns a uniform footer for LON-CAPA web pages.
6288:
1.635 raeburn 6289: Inputs: 1 - optional reference to an args hash
6290: If in the hash, key for noredirectlink has a value which evaluates to true,
6291: a 'Continue' link is not displayed if the page contains an
6292: internal redirect in the <head></head> section,
6293: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6294:
6295: =cut
6296:
6297: sub endbodytag {
1.635 raeburn 6298: my ($args) = @_;
1.1080 raeburn 6299: my $endbodytag;
6300: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6301: $endbodytag='</body>';
6302: }
1.315 albertel 6303: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6304: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6305: $endbodytag=
6306: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6307: &mt('Continue').'</a>'.
6308: $endbodytag;
6309: }
1.315 albertel 6310: }
1.251 albertel 6311: return $endbodytag;
6312: }
6313:
1.352 albertel 6314: =pod
6315:
6316: =item * &standard_css()
6317:
6318: Returns a style sheet
6319:
6320: Inputs: (all optional)
6321: domain -> force to color decorate a page for a specific
6322: domain
6323: function -> force usage of a specific rolish color scheme
6324: bgcolor -> override the default page bgcolor
6325:
6326: =cut
6327:
1.343 albertel 6328: sub standard_css {
1.345 albertel 6329: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6330: $function = &get_users_function() if (!$function);
6331: my $img = &designparm($function.'.img', $domain);
6332: my $tabbg = &designparm($function.'.tabbg', $domain);
6333: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6334: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6335: #second colour for later usage
1.345 albertel 6336: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6337: my $pgbg_or_bgcolor =
6338: $bgcolor ||
1.352 albertel 6339: &designparm($function.'.pgbg', $domain);
1.382 albertel 6340: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6341: my $alink = &designparm($function.'.alink', $domain);
6342: my $vlink = &designparm($function.'.vlink', $domain);
6343: my $link = &designparm($function.'.link', $domain);
6344:
1.602 albertel 6345: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6346: my $mono = 'monospace';
1.850 bisitz 6347: my $data_table_head = $sidebg;
6348: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6349: my $data_table_dark = '#E0E0E0';
1.470 banghart 6350: my $data_table_darker = '#CCCCCC';
1.349 albertel 6351: my $data_table_highlight = '#FFFF00';
1.352 albertel 6352: my $mail_new = '#FFBB77';
6353: my $mail_new_hover = '#DD9955';
6354: my $mail_read = '#BBBB77';
6355: my $mail_read_hover = '#999944';
6356: my $mail_replied = '#AAAA88';
6357: my $mail_replied_hover = '#888855';
6358: my $mail_other = '#99BBBB';
6359: my $mail_other_hover = '#669999';
1.391 albertel 6360: my $table_header = '#DDDDDD';
1.489 raeburn 6361: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6362: my $lg_border_color = '#C8C8C8';
1.952 onken 6363: my $button_hover = '#BF2317';
1.392 albertel 6364:
1.608 albertel 6365: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6366: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6367: : '0 3px 0 4px';
1.448 albertel 6368:
1.523 albertel 6369:
1.343 albertel 6370: return <<END;
1.947 droeschl 6371:
6372: /* needed for iframe to allow 100% height in FF */
6373: body, html {
6374: margin: 0;
6375: padding: 0 0.5%;
6376: height: 99%; /* to avoid scrollbars */
6377: }
6378:
1.795 www 6379: body {
1.911 bisitz 6380: font-family: $sans;
6381: line-height:130%;
6382: font-size:0.83em;
6383: color:$font;
1.795 www 6384: }
6385:
1.959 onken 6386: a:focus,
6387: a:focus img {
1.795 www 6388: color: red;
6389: }
1.698 harmsja 6390:
1.911 bisitz 6391: form, .inline {
6392: display: inline;
1.795 www 6393: }
1.721 harmsja 6394:
1.795 www 6395: .LC_right {
1.911 bisitz 6396: text-align:right;
1.795 www 6397: }
6398:
6399: .LC_middle {
1.911 bisitz 6400: vertical-align:middle;
1.795 www 6401: }
1.721 harmsja 6402:
1.1130 raeburn 6403: .LC_floatleft {
6404: float: left;
6405: }
6406:
6407: .LC_floatright {
6408: float: right;
6409: }
6410:
1.911 bisitz 6411: .LC_400Box {
6412: width:400px;
6413: }
1.721 harmsja 6414:
1.947 droeschl 6415: .LC_iframecontainer {
6416: width: 98%;
6417: margin: 0;
6418: position: fixed;
6419: top: 8.5em;
6420: bottom: 0;
6421: }
6422:
6423: .LC_iframecontainer iframe{
6424: border: none;
6425: width: 100%;
6426: height: 100%;
6427: }
6428:
1.778 bisitz 6429: .LC_filename {
6430: font-family: $mono;
6431: white-space:pre;
1.921 bisitz 6432: font-size: 120%;
1.778 bisitz 6433: }
6434:
6435: .LC_fileicon {
6436: border: none;
6437: height: 1.3em;
6438: vertical-align: text-bottom;
6439: margin-right: 0.3em;
6440: text-decoration:none;
6441: }
6442:
1.1008 www 6443: .LC_setting {
6444: text-decoration:underline;
6445: }
6446:
1.350 albertel 6447: .LC_error {
6448: color: red;
6449: }
1.795 www 6450:
1.1097 bisitz 6451: .LC_warning {
6452: color: darkorange;
6453: }
6454:
1.457 albertel 6455: .LC_diff_removed {
1.733 bisitz 6456: color: red;
1.394 albertel 6457: }
1.532 albertel 6458:
6459: .LC_info,
1.457 albertel 6460: .LC_success,
6461: .LC_diff_added {
1.350 albertel 6462: color: green;
6463: }
1.795 www 6464:
1.802 bisitz 6465: div.LC_confirm_box {
6466: background-color: #FAFAFA;
6467: border: 1px solid $lg_border_color;
6468: margin-right: 0;
6469: padding: 5px;
6470: }
6471:
6472: div.LC_confirm_box .LC_error img,
6473: div.LC_confirm_box .LC_success img {
6474: vertical-align: middle;
6475: }
6476:
1.1242 raeburn 6477: .LC_maxwidth {
6478: max-width: 100%;
6479: height: auto;
6480: }
6481:
1.1243 raeburn 6482: .LC_textsize_mobile {
6483: \@media only screen and (max-device-width: 480px) {
6484: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6485: }
6486: }
6487:
1.440 albertel 6488: .LC_icon {
1.771 droeschl 6489: border: none;
1.790 droeschl 6490: vertical-align: middle;
1.771 droeschl 6491: }
6492:
1.543 albertel 6493: .LC_docs_spacer {
6494: width: 25px;
6495: height: 1px;
1.771 droeschl 6496: border: none;
1.543 albertel 6497: }
1.346 albertel 6498:
1.532 albertel 6499: .LC_internal_info {
1.735 bisitz 6500: color: #999999;
1.532 albertel 6501: }
6502:
1.794 www 6503: .LC_discussion {
1.1050 www 6504: background: $data_table_dark;
1.911 bisitz 6505: border: 1px solid black;
6506: margin: 2px;
1.794 www 6507: }
6508:
6509: .LC_disc_action_left {
1.1050 www 6510: background: $sidebg;
1.911 bisitz 6511: text-align: left;
1.1050 www 6512: padding: 4px;
6513: margin: 2px;
1.794 www 6514: }
6515:
6516: .LC_disc_action_right {
1.1050 www 6517: background: $sidebg;
1.911 bisitz 6518: text-align: right;
1.1050 www 6519: padding: 4px;
6520: margin: 2px;
1.794 www 6521: }
6522:
6523: .LC_disc_new_item {
1.911 bisitz 6524: background: white;
6525: border: 2px solid red;
1.1050 www 6526: margin: 4px;
6527: padding: 4px;
1.794 www 6528: }
6529:
6530: .LC_disc_old_item {
1.911 bisitz 6531: background: white;
1.1050 www 6532: margin: 4px;
6533: padding: 4px;
1.794 www 6534: }
6535:
1.458 albertel 6536: table.LC_pastsubmission {
6537: border: 1px solid black;
6538: margin: 2px;
6539: }
6540:
1.924 bisitz 6541: table#LC_menubuttons {
1.345 albertel 6542: width: 100%;
6543: background: $pgbg;
1.392 albertel 6544: border: 2px;
1.402 albertel 6545: border-collapse: separate;
1.803 bisitz 6546: padding: 0;
1.345 albertel 6547: }
1.392 albertel 6548:
1.801 tempelho 6549: table#LC_title_bar a {
6550: color: $fontmenu;
6551: }
1.836 bisitz 6552:
1.807 droeschl 6553: table#LC_title_bar {
1.819 tempelho 6554: clear: both;
1.836 bisitz 6555: display: none;
1.807 droeschl 6556: }
6557:
1.795 www 6558: table#LC_title_bar,
1.933 droeschl 6559: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6560: table#LC_title_bar.LC_with_remote {
1.359 albertel 6561: width: 100%;
1.392 albertel 6562: border-color: $pgbg;
6563: border-style: solid;
6564: border-width: $border;
1.379 albertel 6565: background: $pgbg;
1.801 tempelho 6566: color: $fontmenu;
1.392 albertel 6567: border-collapse: collapse;
1.803 bisitz 6568: padding: 0;
1.819 tempelho 6569: margin: 0;
1.359 albertel 6570: }
1.795 www 6571:
1.933 droeschl 6572: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6573: margin: 0;
6574: padding: 0;
1.933 droeschl 6575: position: relative;
6576: list-style: none;
1.913 droeschl 6577: }
1.933 droeschl 6578: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6579: display: inline;
6580: }
1.933 droeschl 6581:
6582: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6583: padding: 0;
1.933 droeschl 6584: margin: 0;
6585: float: left;
1.913 droeschl 6586: }
1.933 droeschl 6587: .LC_breadcrumb_tools_tools {
6588: padding: 0;
6589: margin: 0;
1.913 droeschl 6590: float: right;
6591: }
6592:
1.1240 raeburn 6593: .LC_placement_prog {
6594: padding-right: 20px;
6595: font-weight: bold;
6596: font-size: 90%;
6597: }
6598:
1.359 albertel 6599: table#LC_title_bar td {
6600: background: $tabbg;
6601: }
1.795 www 6602:
1.911 bisitz 6603: table#LC_menubuttons img {
1.803 bisitz 6604: border: none;
1.346 albertel 6605: }
1.795 www 6606:
1.842 droeschl 6607: .LC_breadcrumbs_component {
1.911 bisitz 6608: float: right;
6609: margin: 0 1em;
1.357 albertel 6610: }
1.842 droeschl 6611: .LC_breadcrumbs_component img {
1.911 bisitz 6612: vertical-align: middle;
1.777 tempelho 6613: }
1.795 www 6614:
1.1243 raeburn 6615: .LC_breadcrumbs_hoverable {
6616: background: $sidebg;
6617: }
6618:
1.383 albertel 6619: td.LC_table_cell_checkbox {
6620: text-align: center;
6621: }
1.795 www 6622:
6623: .LC_fontsize_small {
1.911 bisitz 6624: font-size: 70%;
1.705 tempelho 6625: }
6626:
1.844 bisitz 6627: #LC_breadcrumbs {
1.911 bisitz 6628: clear:both;
6629: background: $sidebg;
6630: border-bottom: 1px solid $lg_border_color;
6631: line-height: 2.5em;
1.933 droeschl 6632: overflow: hidden;
1.911 bisitz 6633: margin: 0;
6634: padding: 0;
1.995 raeburn 6635: text-align: left;
1.819 tempelho 6636: }
1.862 bisitz 6637:
1.1098 bisitz 6638: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6639: clear:both;
6640: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6641: border: 1px solid $sidebg;
1.1098 bisitz 6642: margin: 0 0 10px 0;
1.966 bisitz 6643: padding: 3px;
1.995 raeburn 6644: text-align: left;
1.822 bisitz 6645: }
6646:
1.795 www 6647: .LC_fontsize_medium {
1.911 bisitz 6648: font-size: 85%;
1.705 tempelho 6649: }
6650:
1.795 www 6651: .LC_fontsize_large {
1.911 bisitz 6652: font-size: 120%;
1.705 tempelho 6653: }
6654:
1.346 albertel 6655: .LC_menubuttons_inline_text {
6656: color: $font;
1.698 harmsja 6657: font-size: 90%;
1.701 harmsja 6658: padding-left:3px;
1.346 albertel 6659: }
6660:
1.934 droeschl 6661: .LC_menubuttons_inline_text img{
6662: vertical-align: middle;
6663: }
6664:
1.1051 www 6665: li.LC_menubuttons_inline_text img {
1.951 onken 6666: cursor:pointer;
1.1002 droeschl 6667: text-decoration: none;
1.951 onken 6668: }
6669:
1.526 www 6670: .LC_menubuttons_link {
6671: text-decoration: none;
6672: }
1.795 www 6673:
1.522 albertel 6674: .LC_menubuttons_category {
1.521 www 6675: color: $font;
1.526 www 6676: background: $pgbg;
1.521 www 6677: font-size: larger;
6678: font-weight: bold;
6679: }
6680:
1.346 albertel 6681: td.LC_menubuttons_text {
1.911 bisitz 6682: color: $font;
1.346 albertel 6683: }
1.706 harmsja 6684:
1.346 albertel 6685: .LC_current_location {
6686: background: $tabbg;
6687: }
1.795 www 6688:
1.1286 raeburn 6689: td.LC_zero_height {
6690: line-height: 0;
6691: cellpadding: 0;
6692: }
6693:
1.938 bisitz 6694: table.LC_data_table {
1.347 albertel 6695: border: 1px solid #000000;
1.402 albertel 6696: border-collapse: separate;
1.426 albertel 6697: border-spacing: 1px;
1.610 albertel 6698: background: $pgbg;
1.347 albertel 6699: }
1.795 www 6700:
1.422 albertel 6701: .LC_data_table_dense {
6702: font-size: small;
6703: }
1.795 www 6704:
1.507 raeburn 6705: table.LC_nested_outer {
6706: border: 1px solid #000000;
1.589 raeburn 6707: border-collapse: collapse;
1.803 bisitz 6708: border-spacing: 0;
1.507 raeburn 6709: width: 100%;
6710: }
1.795 www 6711:
1.879 raeburn 6712: table.LC_innerpickbox,
1.507 raeburn 6713: table.LC_nested {
1.803 bisitz 6714: border: none;
1.589 raeburn 6715: border-collapse: collapse;
1.803 bisitz 6716: border-spacing: 0;
1.507 raeburn 6717: width: 100%;
6718: }
1.795 www 6719:
1.911 bisitz 6720: table.LC_data_table tr th,
6721: table.LC_calendar tr th,
1.879 raeburn 6722: table.LC_prior_tries tr th,
6723: table.LC_innerpickbox tr th {
1.349 albertel 6724: font-weight: bold;
6725: background-color: $data_table_head;
1.801 tempelho 6726: color:$fontmenu;
1.701 harmsja 6727: font-size:90%;
1.347 albertel 6728: }
1.795 www 6729:
1.879 raeburn 6730: table.LC_innerpickbox tr th,
6731: table.LC_innerpickbox tr td {
6732: vertical-align: top;
6733: }
6734:
1.711 raeburn 6735: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6736: background-color: #CCCCCC;
1.711 raeburn 6737: font-weight: bold;
6738: text-align: left;
6739: }
1.795 www 6740:
1.912 bisitz 6741: table.LC_data_table tr.LC_odd_row > td {
6742: background-color: $data_table_light;
6743: padding: 2px;
6744: vertical-align: top;
6745: }
6746:
1.809 bisitz 6747: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6748: background-color: $data_table_light;
1.912 bisitz 6749: vertical-align: top;
6750: }
6751:
6752: table.LC_data_table tr.LC_even_row > td {
6753: background-color: $data_table_dark;
1.425 albertel 6754: padding: 2px;
1.900 bisitz 6755: vertical-align: top;
1.347 albertel 6756: }
1.795 www 6757:
1.809 bisitz 6758: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6759: background-color: $data_table_dark;
1.900 bisitz 6760: vertical-align: top;
1.347 albertel 6761: }
1.795 www 6762:
1.425 albertel 6763: table.LC_data_table tr.LC_data_table_highlight td {
6764: background-color: $data_table_darker;
6765: }
1.795 www 6766:
1.639 raeburn 6767: table.LC_data_table tr td.LC_leftcol_header {
6768: background-color: $data_table_head;
6769: font-weight: bold;
6770: }
1.795 www 6771:
1.451 albertel 6772: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6773: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6774: font-weight: bold;
6775: font-style: italic;
6776: text-align: center;
6777: padding: 8px;
1.347 albertel 6778: }
1.795 www 6779:
1.1114 raeburn 6780: table.LC_data_table tr.LC_empty_row td,
6781: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6782: background-color: $sidebg;
6783: }
6784:
6785: table.LC_nested tr.LC_empty_row td {
6786: background-color: #FFFFFF;
6787: }
6788:
1.890 droeschl 6789: table.LC_caption {
6790: }
6791:
1.507 raeburn 6792: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6793: padding: 4ex
6794: }
1.795 www 6795:
1.507 raeburn 6796: table.LC_nested_outer tr th {
6797: font-weight: bold;
1.801 tempelho 6798: color:$fontmenu;
1.507 raeburn 6799: background-color: $data_table_head;
1.701 harmsja 6800: font-size: small;
1.507 raeburn 6801: border-bottom: 1px solid #000000;
6802: }
1.795 www 6803:
1.507 raeburn 6804: table.LC_nested_outer tr td.LC_subheader {
6805: background-color: $data_table_head;
6806: font-weight: bold;
6807: font-size: small;
6808: border-bottom: 1px solid #000000;
6809: text-align: right;
1.451 albertel 6810: }
1.795 www 6811:
1.507 raeburn 6812: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6813: background-color: #CCCCCC;
1.451 albertel 6814: font-weight: bold;
6815: font-size: small;
1.507 raeburn 6816: text-align: center;
6817: }
1.795 www 6818:
1.589 raeburn 6819: table.LC_nested tr.LC_info_row td.LC_left_item,
6820: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6821: text-align: left;
1.451 albertel 6822: }
1.795 www 6823:
1.507 raeburn 6824: table.LC_nested td {
1.735 bisitz 6825: background-color: #FFFFFF;
1.451 albertel 6826: font-size: small;
1.507 raeburn 6827: }
1.795 www 6828:
1.507 raeburn 6829: table.LC_nested_outer tr th.LC_right_item,
6830: table.LC_nested tr.LC_info_row td.LC_right_item,
6831: table.LC_nested tr.LC_odd_row td.LC_right_item,
6832: table.LC_nested tr td.LC_right_item {
1.451 albertel 6833: text-align: right;
6834: }
6835:
1.507 raeburn 6836: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6837: background-color: #EEEEEE;
1.451 albertel 6838: }
6839:
1.473 raeburn 6840: table.LC_createuser {
6841: }
6842:
6843: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6844: font-size: small;
1.473 raeburn 6845: }
6846:
6847: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6848: background-color: #CCCCCC;
1.473 raeburn 6849: font-weight: bold;
6850: text-align: center;
6851: }
6852:
1.349 albertel 6853: table.LC_calendar {
6854: border: 1px solid #000000;
6855: border-collapse: collapse;
1.917 raeburn 6856: width: 98%;
1.349 albertel 6857: }
1.795 www 6858:
1.349 albertel 6859: table.LC_calendar_pickdate {
6860: font-size: xx-small;
6861: }
1.795 www 6862:
1.349 albertel 6863: table.LC_calendar tr td {
6864: border: 1px solid #000000;
6865: vertical-align: top;
1.917 raeburn 6866: width: 14%;
1.349 albertel 6867: }
1.795 www 6868:
1.349 albertel 6869: table.LC_calendar tr td.LC_calendar_day_empty {
6870: background-color: $data_table_dark;
6871: }
1.795 www 6872:
1.779 bisitz 6873: table.LC_calendar tr td.LC_calendar_day_current {
6874: background-color: $data_table_highlight;
1.777 tempelho 6875: }
1.795 www 6876:
1.938 bisitz 6877: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6878: background-color: $mail_new;
6879: }
1.795 www 6880:
1.938 bisitz 6881: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6882: background-color: $mail_new_hover;
6883: }
1.795 www 6884:
1.938 bisitz 6885: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6886: background-color: $mail_read;
6887: }
1.795 www 6888:
1.938 bisitz 6889: /*
6890: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6891: background-color: $mail_read_hover;
6892: }
1.938 bisitz 6893: */
1.795 www 6894:
1.938 bisitz 6895: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6896: background-color: $mail_replied;
6897: }
1.795 www 6898:
1.938 bisitz 6899: /*
6900: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6901: background-color: $mail_replied_hover;
6902: }
1.938 bisitz 6903: */
1.795 www 6904:
1.938 bisitz 6905: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6906: background-color: $mail_other;
6907: }
1.795 www 6908:
1.938 bisitz 6909: /*
6910: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6911: background-color: $mail_other_hover;
6912: }
1.938 bisitz 6913: */
1.494 raeburn 6914:
1.777 tempelho 6915: table.LC_data_table tr > td.LC_browser_file,
6916: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6917: background: #AAEE77;
1.389 albertel 6918: }
1.795 www 6919:
1.777 tempelho 6920: table.LC_data_table tr > td.LC_browser_file_locked,
6921: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6922: background: #FFAA99;
1.387 albertel 6923: }
1.795 www 6924:
1.777 tempelho 6925: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6926: background: #888888;
1.779 bisitz 6927: }
1.795 www 6928:
1.777 tempelho 6929: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6930: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6931: background: #F8F866;
1.777 tempelho 6932: }
1.795 www 6933:
1.696 bisitz 6934: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6935: background: #E0E8FF;
1.387 albertel 6936: }
1.696 bisitz 6937:
1.707 bisitz 6938: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6939: /* background: #77FF77; */
1.707 bisitz 6940: }
1.795 www 6941:
1.707 bisitz 6942: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6943: border-right: 8px solid #FFFF77;
1.707 bisitz 6944: }
1.795 www 6945:
1.707 bisitz 6946: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6947: border-right: 8px solid #FFAA77;
1.707 bisitz 6948: }
1.795 www 6949:
1.707 bisitz 6950: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6951: border-right: 8px solid #FF7777;
1.707 bisitz 6952: }
1.795 www 6953:
1.707 bisitz 6954: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6955: border-right: 8px solid #AAFF77;
1.707 bisitz 6956: }
1.795 www 6957:
1.707 bisitz 6958: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6959: border-right: 8px solid #11CC55;
1.707 bisitz 6960: }
6961:
1.388 albertel 6962: span.LC_current_location {
1.701 harmsja 6963: font-size:larger;
1.388 albertel 6964: background: $pgbg;
6965: }
1.387 albertel 6966:
1.1029 www 6967: span.LC_current_nav_location {
6968: font-weight:bold;
6969: background: $sidebg;
6970: }
6971:
1.395 albertel 6972: span.LC_parm_menu_item {
6973: font-size: larger;
6974: }
1.795 www 6975:
1.395 albertel 6976: span.LC_parm_scope_all {
6977: color: red;
6978: }
1.795 www 6979:
1.395 albertel 6980: span.LC_parm_scope_folder {
6981: color: green;
6982: }
1.795 www 6983:
1.395 albertel 6984: span.LC_parm_scope_resource {
6985: color: orange;
6986: }
1.795 www 6987:
1.395 albertel 6988: span.LC_parm_part {
6989: color: blue;
6990: }
1.795 www 6991:
1.911 bisitz 6992: span.LC_parm_folder,
6993: span.LC_parm_symb {
1.395 albertel 6994: font-size: x-small;
6995: font-family: $mono;
6996: color: #AAAAAA;
6997: }
6998:
1.977 bisitz 6999: ul.LC_parm_parmlist li {
7000: display: inline-block;
7001: padding: 0.3em 0.8em;
7002: vertical-align: top;
7003: width: 150px;
7004: border-top:1px solid $lg_border_color;
7005: }
7006:
1.795 www 7007: td.LC_parm_overview_level_menu,
7008: td.LC_parm_overview_map_menu,
7009: td.LC_parm_overview_parm_selectors,
7010: td.LC_parm_overview_restrictions {
1.396 albertel 7011: border: 1px solid black;
7012: border-collapse: collapse;
7013: }
1.795 www 7014:
1.1285 raeburn 7015: span.LC_parm_recursive,
7016: td.LC_parm_recursive {
7017: font-weight: bold;
7018: font-size: smaller;
7019: }
7020:
1.396 albertel 7021: table.LC_parm_overview_restrictions td {
7022: border-width: 1px 4px 1px 4px;
7023: border-style: solid;
7024: border-color: $pgbg;
7025: text-align: center;
7026: }
1.795 www 7027:
1.396 albertel 7028: table.LC_parm_overview_restrictions th {
7029: background: $tabbg;
7030: border-width: 1px 4px 1px 4px;
7031: border-style: solid;
7032: border-color: $pgbg;
7033: }
1.795 www 7034:
1.398 albertel 7035: table#LC_helpmenu {
1.803 bisitz 7036: border: none;
1.398 albertel 7037: height: 55px;
1.803 bisitz 7038: border-spacing: 0;
1.398 albertel 7039: }
7040:
7041: table#LC_helpmenu fieldset legend {
7042: font-size: larger;
7043: }
1.795 www 7044:
1.397 albertel 7045: table#LC_helpmenu_links {
7046: width: 100%;
7047: border: 1px solid black;
7048: background: $pgbg;
1.803 bisitz 7049: padding: 0;
1.397 albertel 7050: border-spacing: 1px;
7051: }
1.795 www 7052:
1.397 albertel 7053: table#LC_helpmenu_links tr td {
7054: padding: 1px;
7055: background: $tabbg;
1.399 albertel 7056: text-align: center;
7057: font-weight: bold;
1.397 albertel 7058: }
1.396 albertel 7059:
1.795 www 7060: table#LC_helpmenu_links a:link,
7061: table#LC_helpmenu_links a:visited,
1.397 albertel 7062: table#LC_helpmenu_links a:active {
7063: text-decoration: none;
7064: color: $font;
7065: }
1.795 www 7066:
1.397 albertel 7067: table#LC_helpmenu_links a:hover {
7068: text-decoration: underline;
7069: color: $vlink;
7070: }
1.396 albertel 7071:
1.417 albertel 7072: .LC_chrt_popup_exists {
7073: border: 1px solid #339933;
7074: margin: -1px;
7075: }
1.795 www 7076:
1.417 albertel 7077: .LC_chrt_popup_up {
7078: border: 1px solid yellow;
7079: margin: -1px;
7080: }
1.795 www 7081:
1.417 albertel 7082: .LC_chrt_popup {
7083: border: 1px solid #8888FF;
7084: background: #CCCCFF;
7085: }
1.795 www 7086:
1.421 albertel 7087: table.LC_pick_box {
7088: border-collapse: separate;
7089: background: white;
7090: border: 1px solid black;
7091: border-spacing: 1px;
7092: }
1.795 www 7093:
1.421 albertel 7094: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7095: background: $sidebg;
1.421 albertel 7096: font-weight: bold;
1.900 bisitz 7097: text-align: left;
1.740 bisitz 7098: vertical-align: top;
1.421 albertel 7099: width: 184px;
7100: padding: 8px;
7101: }
1.795 www 7102:
1.579 raeburn 7103: table.LC_pick_box td.LC_pick_box_value {
7104: text-align: left;
7105: padding: 8px;
7106: }
1.795 www 7107:
1.579 raeburn 7108: table.LC_pick_box td.LC_pick_box_select {
7109: text-align: left;
7110: padding: 8px;
7111: }
1.795 www 7112:
1.424 albertel 7113: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7114: padding: 0;
1.421 albertel 7115: height: 1px;
7116: background: black;
7117: }
1.795 www 7118:
1.421 albertel 7119: table.LC_pick_box td.LC_pick_box_submit {
7120: text-align: right;
7121: }
1.795 www 7122:
1.579 raeburn 7123: table.LC_pick_box td.LC_evenrow_value {
7124: text-align: left;
7125: padding: 8px;
7126: background-color: $data_table_light;
7127: }
1.795 www 7128:
1.579 raeburn 7129: table.LC_pick_box td.LC_oddrow_value {
7130: text-align: left;
7131: padding: 8px;
7132: background-color: $data_table_light;
7133: }
1.795 www 7134:
1.579 raeburn 7135: span.LC_helpform_receipt_cat {
7136: font-weight: bold;
7137: }
1.795 www 7138:
1.424 albertel 7139: table.LC_group_priv_box {
7140: background: white;
7141: border: 1px solid black;
7142: border-spacing: 1px;
7143: }
1.795 www 7144:
1.424 albertel 7145: table.LC_group_priv_box td.LC_pick_box_title {
7146: background: $tabbg;
7147: font-weight: bold;
7148: text-align: right;
7149: width: 184px;
7150: }
1.795 www 7151:
1.424 albertel 7152: table.LC_group_priv_box td.LC_groups_fixed {
7153: background: $data_table_light;
7154: text-align: center;
7155: }
1.795 www 7156:
1.424 albertel 7157: table.LC_group_priv_box td.LC_groups_optional {
7158: background: $data_table_dark;
7159: text-align: center;
7160: }
1.795 www 7161:
1.424 albertel 7162: table.LC_group_priv_box td.LC_groups_functionality {
7163: background: $data_table_darker;
7164: text-align: center;
7165: font-weight: bold;
7166: }
1.795 www 7167:
1.424 albertel 7168: table.LC_group_priv td {
7169: text-align: left;
1.803 bisitz 7170: padding: 0;
1.424 albertel 7171: }
7172:
7173: .LC_navbuttons {
7174: margin: 2ex 0ex 2ex 0ex;
7175: }
1.795 www 7176:
1.423 albertel 7177: .LC_topic_bar {
7178: font-weight: bold;
7179: background: $tabbg;
1.918 wenzelju 7180: margin: 1em 0em 1em 2em;
1.805 bisitz 7181: padding: 3px;
1.918 wenzelju 7182: font-size: 1.2em;
1.423 albertel 7183: }
1.795 www 7184:
1.423 albertel 7185: .LC_topic_bar span {
1.918 wenzelju 7186: left: 0.5em;
7187: position: absolute;
1.423 albertel 7188: vertical-align: middle;
1.918 wenzelju 7189: font-size: 1.2em;
1.423 albertel 7190: }
1.795 www 7191:
1.423 albertel 7192: table.LC_course_group_status {
7193: margin: 20px;
7194: }
1.795 www 7195:
1.423 albertel 7196: table.LC_status_selector td {
7197: vertical-align: top;
7198: text-align: center;
1.424 albertel 7199: padding: 4px;
7200: }
1.795 www 7201:
1.599 albertel 7202: div.LC_feedback_link {
1.616 albertel 7203: clear: both;
1.829 kalberla 7204: background: $sidebg;
1.779 bisitz 7205: width: 100%;
1.829 kalberla 7206: padding-bottom: 10px;
7207: border: 1px $tabbg solid;
1.833 kalberla 7208: height: 22px;
7209: line-height: 22px;
7210: padding-top: 5px;
7211: }
7212:
7213: div.LC_feedback_link img {
7214: height: 22px;
1.867 kalberla 7215: vertical-align:middle;
1.829 kalberla 7216: }
7217:
1.911 bisitz 7218: div.LC_feedback_link a {
1.829 kalberla 7219: text-decoration: none;
1.489 raeburn 7220: }
1.795 www 7221:
1.867 kalberla 7222: div.LC_comblock {
1.911 bisitz 7223: display:inline;
1.867 kalberla 7224: color:$font;
7225: font-size:90%;
7226: }
7227:
7228: div.LC_feedback_link div.LC_comblock {
7229: padding-left:5px;
7230: }
7231:
7232: div.LC_feedback_link div.LC_comblock a {
7233: color:$font;
7234: }
7235:
1.489 raeburn 7236: span.LC_feedback_link {
1.858 bisitz 7237: /* background: $feedback_link_bg; */
1.599 albertel 7238: font-size: larger;
7239: }
1.795 www 7240:
1.599 albertel 7241: span.LC_message_link {
1.858 bisitz 7242: /* background: $feedback_link_bg; */
1.599 albertel 7243: font-size: larger;
7244: position: absolute;
7245: right: 1em;
1.489 raeburn 7246: }
1.421 albertel 7247:
1.515 albertel 7248: table.LC_prior_tries {
1.524 albertel 7249: border: 1px solid #000000;
7250: border-collapse: separate;
7251: border-spacing: 1px;
1.515 albertel 7252: }
1.523 albertel 7253:
1.515 albertel 7254: table.LC_prior_tries td {
1.524 albertel 7255: padding: 2px;
1.515 albertel 7256: }
1.523 albertel 7257:
7258: .LC_answer_correct {
1.795 www 7259: background: lightgreen;
7260: color: darkgreen;
7261: padding: 6px;
1.523 albertel 7262: }
1.795 www 7263:
1.523 albertel 7264: .LC_answer_charged_try {
1.797 www 7265: background: #FFAAAA;
1.795 www 7266: color: darkred;
7267: padding: 6px;
1.523 albertel 7268: }
1.795 www 7269:
1.779 bisitz 7270: .LC_answer_not_charged_try,
1.523 albertel 7271: .LC_answer_no_grade,
7272: .LC_answer_late {
1.795 www 7273: background: lightyellow;
1.523 albertel 7274: color: black;
1.795 www 7275: padding: 6px;
1.523 albertel 7276: }
1.795 www 7277:
1.523 albertel 7278: .LC_answer_previous {
1.795 www 7279: background: lightblue;
7280: color: darkblue;
7281: padding: 6px;
1.523 albertel 7282: }
1.795 www 7283:
1.779 bisitz 7284: .LC_answer_no_message {
1.777 tempelho 7285: background: #FFFFFF;
7286: color: black;
1.795 www 7287: padding: 6px;
1.779 bisitz 7288: }
1.795 www 7289:
1.1334 raeburn 7290: .LC_answer_unknown,
7291: .LC_answer_warning {
1.779 bisitz 7292: background: orange;
7293: color: black;
1.795 www 7294: padding: 6px;
1.777 tempelho 7295: }
1.795 www 7296:
1.529 albertel 7297: span.LC_prior_numerical,
7298: span.LC_prior_string,
7299: span.LC_prior_custom,
7300: span.LC_prior_reaction,
7301: span.LC_prior_math {
1.925 bisitz 7302: font-family: $mono;
1.523 albertel 7303: white-space: pre;
7304: }
7305:
1.525 albertel 7306: span.LC_prior_string {
1.925 bisitz 7307: font-family: $mono;
1.525 albertel 7308: white-space: pre;
7309: }
7310:
1.523 albertel 7311: table.LC_prior_option {
7312: width: 100%;
7313: border-collapse: collapse;
7314: }
1.795 www 7315:
1.911 bisitz 7316: table.LC_prior_rank,
1.795 www 7317: table.LC_prior_match {
1.528 albertel 7318: border-collapse: collapse;
7319: }
1.795 www 7320:
1.528 albertel 7321: table.LC_prior_option tr td,
7322: table.LC_prior_rank tr td,
7323: table.LC_prior_match tr td {
1.524 albertel 7324: border: 1px solid #000000;
1.515 albertel 7325: }
7326:
1.855 bisitz 7327: .LC_nobreak {
1.544 albertel 7328: white-space: nowrap;
1.519 raeburn 7329: }
7330:
1.576 raeburn 7331: span.LC_cusr_emph {
7332: font-style: italic;
7333: }
7334:
1.633 raeburn 7335: span.LC_cusr_subheading {
7336: font-weight: normal;
7337: font-size: 85%;
7338: }
7339:
1.861 bisitz 7340: div.LC_docs_entry_move {
1.859 bisitz 7341: border: 1px solid #BBBBBB;
1.545 albertel 7342: background: #DDDDDD;
1.861 bisitz 7343: width: 22px;
1.859 bisitz 7344: padding: 1px;
7345: margin: 0;
1.545 albertel 7346: }
7347:
1.861 bisitz 7348: table.LC_data_table tr > td.LC_docs_entry_commands,
7349: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7350: font-size: x-small;
7351: }
1.795 www 7352:
1.861 bisitz 7353: .LC_docs_entry_parameter {
7354: white-space: nowrap;
7355: }
7356:
1.544 albertel 7357: .LC_docs_copy {
1.545 albertel 7358: color: #000099;
1.544 albertel 7359: }
1.795 www 7360:
1.544 albertel 7361: .LC_docs_cut {
1.545 albertel 7362: color: #550044;
1.544 albertel 7363: }
1.795 www 7364:
1.544 albertel 7365: .LC_docs_rename {
1.545 albertel 7366: color: #009900;
1.544 albertel 7367: }
1.795 www 7368:
1.544 albertel 7369: .LC_docs_remove {
1.545 albertel 7370: color: #990000;
7371: }
7372:
1.1284 raeburn 7373: .LC_docs_alias {
7374: color: #440055;
7375: }
7376:
1.1286 raeburn 7377: .LC_domprefs_email,
1.1284 raeburn 7378: .LC_docs_alias_name,
1.547 albertel 7379: .LC_docs_reinit_warn,
7380: .LC_docs_ext_edit {
7381: font-size: x-small;
7382: }
7383:
1.545 albertel 7384: table.LC_docs_adddocs td,
7385: table.LC_docs_adddocs th {
7386: border: 1px solid #BBBBBB;
7387: padding: 4px;
7388: background: #DDDDDD;
1.543 albertel 7389: }
7390:
1.584 albertel 7391: table.LC_sty_begin {
7392: background: #BBFFBB;
7393: }
1.795 www 7394:
1.584 albertel 7395: table.LC_sty_end {
7396: background: #FFBBBB;
7397: }
7398:
1.589 raeburn 7399: table.LC_double_column {
1.803 bisitz 7400: border-width: 0;
1.589 raeburn 7401: border-collapse: collapse;
7402: width: 100%;
7403: padding: 2px;
7404: }
7405:
7406: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7407: top: 2px;
1.589 raeburn 7408: left: 2px;
7409: width: 47%;
7410: vertical-align: top;
7411: }
7412:
7413: table.LC_double_column tr td.LC_right_col {
7414: top: 2px;
1.779 bisitz 7415: right: 2px;
1.589 raeburn 7416: width: 47%;
7417: vertical-align: top;
7418: }
7419:
1.591 raeburn 7420: div.LC_left_float {
7421: float: left;
7422: padding-right: 5%;
1.597 albertel 7423: padding-bottom: 4px;
1.591 raeburn 7424: }
7425:
7426: div.LC_clear_float_header {
1.597 albertel 7427: padding-bottom: 2px;
1.591 raeburn 7428: }
7429:
7430: div.LC_clear_float_footer {
1.597 albertel 7431: padding-top: 10px;
1.591 raeburn 7432: clear: both;
7433: }
7434:
1.597 albertel 7435: div.LC_grade_show_user {
1.941 bisitz 7436: /* border-left: 5px solid $sidebg; */
7437: border-top: 5px solid #000000;
7438: margin: 50px 0 0 0;
1.936 bisitz 7439: padding: 15px 0 5px 10px;
1.597 albertel 7440: }
1.795 www 7441:
1.936 bisitz 7442: div.LC_grade_show_user_odd_row {
1.941 bisitz 7443: /* border-left: 5px solid #000000; */
7444: }
7445:
7446: div.LC_grade_show_user div.LC_Box {
7447: margin-right: 50px;
1.597 albertel 7448: }
7449:
7450: div.LC_grade_submissions,
7451: div.LC_grade_message_center,
1.936 bisitz 7452: div.LC_grade_info_links {
1.597 albertel 7453: margin: 5px;
7454: width: 99%;
7455: background: #FFFFFF;
7456: }
1.795 www 7457:
1.597 albertel 7458: div.LC_grade_submissions_header,
1.936 bisitz 7459: div.LC_grade_message_center_header {
1.705 tempelho 7460: font-weight: bold;
7461: font-size: large;
1.597 albertel 7462: }
1.795 www 7463:
1.597 albertel 7464: div.LC_grade_submissions_body,
1.936 bisitz 7465: div.LC_grade_message_center_body {
1.597 albertel 7466: border: 1px solid black;
7467: width: 99%;
7468: background: #FFFFFF;
7469: }
1.795 www 7470:
1.613 albertel 7471: table.LC_scantron_action {
7472: width: 100%;
7473: }
1.795 www 7474:
1.613 albertel 7475: table.LC_scantron_action tr th {
1.698 harmsja 7476: font-weight:bold;
7477: font-style:normal;
1.613 albertel 7478: }
1.795 www 7479:
1.779 bisitz 7480: .LC_edit_problem_header,
1.614 albertel 7481: div.LC_edit_problem_footer {
1.705 tempelho 7482: font-weight: normal;
7483: font-size: medium;
1.602 albertel 7484: margin: 2px;
1.1060 bisitz 7485: background-color: $sidebg;
1.600 albertel 7486: }
1.795 www 7487:
1.600 albertel 7488: div.LC_edit_problem_header,
1.602 albertel 7489: div.LC_edit_problem_header div,
1.614 albertel 7490: div.LC_edit_problem_footer,
7491: div.LC_edit_problem_footer div,
1.602 albertel 7492: div.LC_edit_problem_editxml_header,
7493: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7494: z-index: 100;
1.600 albertel 7495: }
1.795 www 7496:
1.600 albertel 7497: div.LC_edit_problem_header_title {
1.705 tempelho 7498: font-weight: bold;
7499: font-size: larger;
1.602 albertel 7500: background: $tabbg;
7501: padding: 3px;
1.1060 bisitz 7502: margin: 0 0 5px 0;
1.602 albertel 7503: }
1.795 www 7504:
1.602 albertel 7505: table.LC_edit_problem_header_title {
7506: width: 100%;
1.600 albertel 7507: background: $tabbg;
1.602 albertel 7508: }
7509:
1.1205 golterma 7510: div.LC_edit_actionbar {
7511: background-color: $sidebg;
1.1218 droeschl 7512: margin: 0;
7513: padding: 0;
7514: line-height: 200%;
1.602 albertel 7515: }
1.795 www 7516:
1.1218 droeschl 7517: div.LC_edit_actionbar div{
7518: padding: 0;
7519: margin: 0;
7520: display: inline-block;
1.600 albertel 7521: }
1.795 www 7522:
1.1124 bisitz 7523: .LC_edit_opt {
7524: padding-left: 1em;
7525: white-space: nowrap;
7526: }
7527:
1.1152 golterma 7528: .LC_edit_problem_latexhelper{
7529: text-align: right;
7530: }
7531:
7532: #LC_edit_problem_colorful div{
7533: margin-left: 40px;
7534: }
7535:
1.1205 golterma 7536: #LC_edit_problem_codemirror div{
7537: margin-left: 0px;
7538: }
7539:
1.911 bisitz 7540: img.stift {
1.803 bisitz 7541: border-width: 0;
7542: vertical-align: middle;
1.677 riegler 7543: }
1.680 riegler 7544:
1.923 bisitz 7545: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7546: vertical-align: top;
1.777 tempelho 7547: }
1.795 www 7548:
1.716 raeburn 7549: div.LC_createcourse {
1.911 bisitz 7550: margin: 10px 10px 10px 10px;
1.716 raeburn 7551: }
7552:
1.917 raeburn 7553: .LC_dccid {
1.1130 raeburn 7554: float: right;
1.917 raeburn 7555: margin: 0.2em 0 0 0;
7556: padding: 0;
7557: font-size: 90%;
7558: display:none;
7559: }
7560:
1.897 wenzelju 7561: ol.LC_primary_menu a:hover,
1.721 harmsja 7562: ol#LC_MenuBreadcrumbs a:hover,
7563: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7564: ul#LC_secondary_menu a:hover,
1.721 harmsja 7565: .LC_FormSectionClearButton input:hover
1.795 www 7566: ul.LC_TabContent li:hover a {
1.952 onken 7567: color:$button_hover;
1.911 bisitz 7568: text-decoration:none;
1.693 droeschl 7569: }
7570:
1.779 bisitz 7571: h1 {
1.911 bisitz 7572: padding: 0;
7573: line-height:130%;
1.693 droeschl 7574: }
1.698 harmsja 7575:
1.911 bisitz 7576: h2,
7577: h3,
7578: h4,
7579: h5,
7580: h6 {
7581: margin: 5px 0 5px 0;
7582: padding: 0;
7583: line-height:130%;
1.693 droeschl 7584: }
1.795 www 7585:
7586: .LC_hcell {
1.911 bisitz 7587: padding:3px 15px 3px 15px;
7588: margin: 0;
7589: background-color:$tabbg;
7590: color:$fontmenu;
7591: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7592: }
1.795 www 7593:
1.840 bisitz 7594: .LC_Box > .LC_hcell {
1.911 bisitz 7595: margin: 0 -10px 10px -10px;
1.835 bisitz 7596: }
7597:
1.721 harmsja 7598: .LC_noBorder {
1.911 bisitz 7599: border: 0;
1.698 harmsja 7600: }
1.693 droeschl 7601:
1.721 harmsja 7602: .LC_FormSectionClearButton input {
1.911 bisitz 7603: background-color:transparent;
7604: border: none;
7605: cursor:pointer;
7606: text-decoration:underline;
1.693 droeschl 7607: }
1.763 bisitz 7608:
7609: .LC_help_open_topic {
1.911 bisitz 7610: color: #FFFFFF;
7611: background-color: #EEEEFF;
7612: margin: 1px;
7613: padding: 4px;
7614: border: 1px solid #000033;
7615: white-space: nowrap;
7616: /* vertical-align: middle; */
1.759 neumanie 7617: }
1.693 droeschl 7618:
1.911 bisitz 7619: dl,
7620: ul,
7621: div,
7622: fieldset {
7623: margin: 10px 10px 10px 0;
7624: /* overflow: hidden; */
1.693 droeschl 7625: }
1.795 www 7626:
1.1211 raeburn 7627: article.geogebraweb div {
7628: margin: 0;
7629: }
7630:
1.838 bisitz 7631: fieldset > legend {
1.911 bisitz 7632: font-weight: bold;
7633: padding: 0 5px 0 5px;
1.838 bisitz 7634: }
7635:
1.813 bisitz 7636: #LC_nav_bar {
1.911 bisitz 7637: float: left;
1.995 raeburn 7638: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7639: margin: 0 0 2px 0;
1.807 droeschl 7640: }
7641:
1.916 droeschl 7642: #LC_realm {
7643: margin: 0.2em 0 0 0;
7644: padding: 0;
7645: font-weight: bold;
7646: text-align: center;
1.995 raeburn 7647: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7648: }
7649:
1.911 bisitz 7650: #LC_nav_bar em {
7651: font-weight: bold;
7652: font-style: normal;
1.807 droeschl 7653: }
7654:
1.897 wenzelju 7655: ol.LC_primary_menu {
1.934 droeschl 7656: margin: 0;
1.1076 raeburn 7657: padding: 0;
1.807 droeschl 7658: }
7659:
1.852 droeschl 7660: ol#LC_PathBreadcrumbs {
1.911 bisitz 7661: margin: 0;
1.693 droeschl 7662: }
7663:
1.897 wenzelju 7664: ol.LC_primary_menu li {
1.1076 raeburn 7665: color: RGB(80, 80, 80);
7666: vertical-align: middle;
7667: text-align: left;
7668: list-style: none;
1.1205 golterma 7669: position: relative;
1.1076 raeburn 7670: float: left;
1.1205 golterma 7671: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7672: line-height: 1.5em;
1.1076 raeburn 7673: }
7674:
1.1205 golterma 7675: ol.LC_primary_menu li a,
7676: ol.LC_primary_menu li p {
1.1076 raeburn 7677: display: block;
7678: margin: 0;
7679: padding: 0 5px 0 10px;
7680: text-decoration: none;
7681: }
7682:
1.1205 golterma 7683: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7684: display: inline-block;
7685: width: 95%;
7686: text-align: left;
7687: }
7688:
7689: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7690: display: inline-block;
7691: width: 5%;
7692: float: right;
7693: text-align: right;
7694: font-size: 70%;
7695: }
7696:
7697: ol.LC_primary_menu ul {
1.1076 raeburn 7698: display: none;
1.1205 golterma 7699: width: 15em;
1.1076 raeburn 7700: background-color: $data_table_light;
1.1205 golterma 7701: position: absolute;
7702: top: 100%;
1.1076 raeburn 7703: }
7704:
1.1205 golterma 7705: ol.LC_primary_menu ul ul {
7706: left: 100%;
7707: top: 0;
7708: }
7709:
7710: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7711: display: block;
7712: position: absolute;
7713: margin: 0;
7714: padding: 0;
1.1078 raeburn 7715: z-index: 2;
1.1076 raeburn 7716: }
7717:
7718: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7719: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7720: font-size: 90%;
1.911 bisitz 7721: vertical-align: top;
1.1076 raeburn 7722: float: none;
1.1079 raeburn 7723: border-left: 1px solid black;
7724: border-right: 1px solid black;
1.1205 golterma 7725: /* A dark bottom border to visualize different menu options;
7726: overwritten in the create_submenu routine for the last border-bottom of the menu */
7727: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7728: }
7729:
1.1205 golterma 7730: ol.LC_primary_menu li li p:hover {
7731: color:$button_hover;
7732: text-decoration:none;
7733: background-color:$data_table_dark;
1.1076 raeburn 7734: }
7735:
7736: ol.LC_primary_menu li li a:hover {
7737: color:$button_hover;
7738: background-color:$data_table_dark;
1.693 droeschl 7739: }
7740:
1.1205 golterma 7741: /* Font-size equal to the size of the predecessors*/
7742: ol.LC_primary_menu li:hover li li {
7743: font-size: 100%;
7744: }
7745:
1.897 wenzelju 7746: ol.LC_primary_menu li img {
1.911 bisitz 7747: vertical-align: bottom;
1.934 droeschl 7748: height: 1.1em;
1.1077 raeburn 7749: margin: 0.2em 0 0 0;
1.693 droeschl 7750: }
7751:
1.897 wenzelju 7752: ol.LC_primary_menu a {
1.911 bisitz 7753: color: RGB(80, 80, 80);
7754: text-decoration: none;
1.693 droeschl 7755: }
1.795 www 7756:
1.949 droeschl 7757: ol.LC_primary_menu a.LC_new_message {
7758: font-weight:bold;
7759: color: darkred;
7760: }
7761:
1.975 raeburn 7762: ol.LC_docs_parameters {
7763: margin-left: 0;
7764: padding: 0;
7765: list-style: none;
7766: }
7767:
7768: ol.LC_docs_parameters li {
7769: margin: 0;
7770: padding-right: 20px;
7771: display: inline;
7772: }
7773:
1.976 raeburn 7774: ol.LC_docs_parameters li:before {
7775: content: "\\002022 \\0020";
7776: }
7777:
7778: li.LC_docs_parameters_title {
7779: font-weight: bold;
7780: }
7781:
7782: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7783: content: "";
7784: }
7785:
1.897 wenzelju 7786: ul#LC_secondary_menu {
1.1107 raeburn 7787: clear: right;
1.911 bisitz 7788: color: $fontmenu;
7789: background: $tabbg;
7790: list-style: none;
7791: padding: 0;
7792: margin: 0;
7793: width: 100%;
1.995 raeburn 7794: text-align: left;
1.1107 raeburn 7795: float: left;
1.808 droeschl 7796: }
7797:
1.897 wenzelju 7798: ul#LC_secondary_menu li {
1.911 bisitz 7799: font-weight: bold;
7800: line-height: 1.8em;
1.1107 raeburn 7801: border-right: 1px solid black;
7802: float: left;
7803: }
7804:
7805: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7806: background-color: $data_table_light;
7807: }
7808:
7809: ul#LC_secondary_menu li a {
1.911 bisitz 7810: padding: 0 0.8em;
1.1107 raeburn 7811: }
7812:
7813: ul#LC_secondary_menu li ul {
7814: display: none;
7815: }
7816:
7817: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7818: display: block;
7819: position: absolute;
7820: margin: 0;
7821: padding: 0;
7822: list-style:none;
7823: float: none;
7824: background-color: $data_table_light;
7825: z-index: 2;
7826: margin-left: -1px;
7827: }
7828:
7829: ul#LC_secondary_menu li ul li {
7830: font-size: 90%;
7831: vertical-align: top;
7832: border-left: 1px solid black;
1.911 bisitz 7833: border-right: 1px solid black;
1.1119 raeburn 7834: background-color: $data_table_light;
1.1107 raeburn 7835: list-style:none;
7836: float: none;
7837: }
7838:
7839: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7840: background-color: $data_table_dark;
1.807 droeschl 7841: }
7842:
1.847 tempelho 7843: ul.LC_TabContent {
1.911 bisitz 7844: display:block;
7845: background: $sidebg;
7846: border-bottom: solid 1px $lg_border_color;
7847: list-style:none;
1.1020 raeburn 7848: margin: -1px -10px 0 -10px;
1.911 bisitz 7849: padding: 0;
1.693 droeschl 7850: }
7851:
1.795 www 7852: ul.LC_TabContent li,
7853: ul.LC_TabContentBigger li {
1.911 bisitz 7854: float:left;
1.741 harmsja 7855: }
1.795 www 7856:
1.897 wenzelju 7857: ul#LC_secondary_menu li a {
1.911 bisitz 7858: color: $fontmenu;
7859: text-decoration: none;
1.693 droeschl 7860: }
1.795 www 7861:
1.721 harmsja 7862: ul.LC_TabContent {
1.952 onken 7863: min-height:20px;
1.721 harmsja 7864: }
1.795 www 7865:
7866: ul.LC_TabContent li {
1.911 bisitz 7867: vertical-align:middle;
1.959 onken 7868: padding: 0 16px 0 10px;
1.911 bisitz 7869: background-color:$tabbg;
7870: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7871: border-left: solid 1px $font;
1.721 harmsja 7872: }
1.795 www 7873:
1.847 tempelho 7874: ul.LC_TabContent .right {
1.911 bisitz 7875: float:right;
1.847 tempelho 7876: }
7877:
1.911 bisitz 7878: ul.LC_TabContent li a,
7879: ul.LC_TabContent li {
7880: color:rgb(47,47,47);
7881: text-decoration:none;
7882: font-size:95%;
7883: font-weight:bold;
1.952 onken 7884: min-height:20px;
7885: }
7886:
1.959 onken 7887: ul.LC_TabContent li a:hover,
7888: ul.LC_TabContent li a:focus {
1.952 onken 7889: color: $button_hover;
1.959 onken 7890: background:none;
7891: outline:none;
1.952 onken 7892: }
7893:
7894: ul.LC_TabContent li:hover {
7895: color: $button_hover;
7896: cursor:pointer;
1.721 harmsja 7897: }
1.795 www 7898:
1.911 bisitz 7899: ul.LC_TabContent li.active {
1.952 onken 7900: color: $font;
1.911 bisitz 7901: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7902: border-bottom:solid 1px #FFFFFF;
7903: cursor: default;
1.744 ehlerst 7904: }
1.795 www 7905:
1.959 onken 7906: ul.LC_TabContent li.active a {
7907: color:$font;
7908: background:#FFFFFF;
7909: outline: none;
7910: }
1.1047 raeburn 7911:
7912: ul.LC_TabContent li.goback {
7913: float: left;
7914: border-left: none;
7915: }
7916:
1.870 tempelho 7917: #maincoursedoc {
1.911 bisitz 7918: clear:both;
1.870 tempelho 7919: }
7920:
7921: ul.LC_TabContentBigger {
1.911 bisitz 7922: display:block;
7923: list-style:none;
7924: padding: 0;
1.870 tempelho 7925: }
7926:
1.795 www 7927: ul.LC_TabContentBigger li {
1.911 bisitz 7928: vertical-align:bottom;
7929: height: 30px;
7930: font-size:110%;
7931: font-weight:bold;
7932: color: #737373;
1.841 tempelho 7933: }
7934:
1.957 onken 7935: ul.LC_TabContentBigger li.active {
7936: position: relative;
7937: top: 1px;
7938: }
7939:
1.870 tempelho 7940: ul.LC_TabContentBigger li a {
1.911 bisitz 7941: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7942: height: 30px;
7943: line-height: 30px;
7944: text-align: center;
7945: display: block;
7946: text-decoration: none;
1.958 onken 7947: outline: none;
1.741 harmsja 7948: }
1.795 www 7949:
1.870 tempelho 7950: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7951: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7952: color:$font;
1.744 ehlerst 7953: }
1.795 www 7954:
1.870 tempelho 7955: ul.LC_TabContentBigger li b {
1.911 bisitz 7956: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7957: display: block;
7958: float: left;
7959: padding: 0 30px;
1.957 onken 7960: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7961: }
7962:
1.956 onken 7963: ul.LC_TabContentBigger li:hover b {
7964: color:$button_hover;
7965: }
7966:
1.870 tempelho 7967: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7968: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7969: color:$font;
1.957 onken 7970: border: 0;
1.741 harmsja 7971: }
1.693 droeschl 7972:
1.870 tempelho 7973:
1.862 bisitz 7974: ul.LC_CourseBreadcrumbs {
7975: background: $sidebg;
1.1020 raeburn 7976: height: 2em;
1.862 bisitz 7977: padding-left: 10px;
1.1020 raeburn 7978: margin: 0;
1.862 bisitz 7979: list-style-position: inside;
7980: }
7981:
1.911 bisitz 7982: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7983: ol#LC_PathBreadcrumbs {
1.911 bisitz 7984: padding-left: 10px;
7985: margin: 0;
1.933 droeschl 7986: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7987: }
7988:
1.911 bisitz 7989: ol#LC_MenuBreadcrumbs li,
7990: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7991: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7992: display: inline;
1.933 droeschl 7993: white-space: normal;
1.693 droeschl 7994: }
7995:
1.823 bisitz 7996: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7997: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7998: text-decoration: none;
7999: font-size:90%;
1.693 droeschl 8000: }
1.795 www 8001:
1.969 droeschl 8002: ol#LC_MenuBreadcrumbs h1 {
8003: display: inline;
8004: font-size: 90%;
8005: line-height: 2.5em;
8006: margin: 0;
8007: padding: 0;
8008: }
8009:
1.795 www 8010: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8011: text-decoration:none;
8012: font-size:100%;
8013: font-weight:bold;
1.693 droeschl 8014: }
1.795 www 8015:
1.840 bisitz 8016: .LC_Box {
1.911 bisitz 8017: border: solid 1px $lg_border_color;
8018: padding: 0 10px 10px 10px;
1.746 neumanie 8019: }
1.795 www 8020:
1.1020 raeburn 8021: .LC_DocsBox {
8022: border: solid 1px $lg_border_color;
8023: padding: 0 0 10px 10px;
8024: }
8025:
1.795 www 8026: .LC_AboutMe_Image {
1.911 bisitz 8027: float:left;
8028: margin-right:10px;
1.747 neumanie 8029: }
1.795 www 8030:
8031: .LC_Clear_AboutMe_Image {
1.911 bisitz 8032: clear:left;
1.747 neumanie 8033: }
1.795 www 8034:
1.721 harmsja 8035: dl.LC_ListStyleClean dt {
1.911 bisitz 8036: padding-right: 5px;
8037: display: table-header-group;
1.693 droeschl 8038: }
8039:
1.721 harmsja 8040: dl.LC_ListStyleClean dd {
1.911 bisitz 8041: display: table-row;
1.693 droeschl 8042: }
8043:
1.721 harmsja 8044: .LC_ListStyleClean,
8045: .LC_ListStyleSimple,
8046: .LC_ListStyleNormal,
1.795 www 8047: .LC_ListStyleSpecial {
1.911 bisitz 8048: /* display:block; */
8049: list-style-position: inside;
8050: list-style-type: none;
8051: overflow: hidden;
8052: padding: 0;
1.693 droeschl 8053: }
8054:
1.721 harmsja 8055: .LC_ListStyleSimple li,
8056: .LC_ListStyleSimple dd,
8057: .LC_ListStyleNormal li,
8058: .LC_ListStyleNormal dd,
8059: .LC_ListStyleSpecial li,
1.795 www 8060: .LC_ListStyleSpecial dd {
1.911 bisitz 8061: margin: 0;
8062: padding: 5px 5px 5px 10px;
8063: clear: both;
1.693 droeschl 8064: }
8065:
1.721 harmsja 8066: .LC_ListStyleClean li,
8067: .LC_ListStyleClean dd {
1.911 bisitz 8068: padding-top: 0;
8069: padding-bottom: 0;
1.693 droeschl 8070: }
8071:
1.721 harmsja 8072: .LC_ListStyleSimple dd,
1.795 www 8073: .LC_ListStyleSimple li {
1.911 bisitz 8074: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8075: }
8076:
1.721 harmsja 8077: .LC_ListStyleSpecial li,
8078: .LC_ListStyleSpecial dd {
1.911 bisitz 8079: list-style-type: none;
8080: background-color: RGB(220, 220, 220);
8081: margin-bottom: 4px;
1.693 droeschl 8082: }
8083:
1.721 harmsja 8084: table.LC_SimpleTable {
1.911 bisitz 8085: margin:5px;
8086: border:solid 1px $lg_border_color;
1.795 www 8087: }
1.693 droeschl 8088:
1.721 harmsja 8089: table.LC_SimpleTable tr {
1.911 bisitz 8090: padding: 0;
8091: border:solid 1px $lg_border_color;
1.693 droeschl 8092: }
1.795 www 8093:
8094: table.LC_SimpleTable thead {
1.911 bisitz 8095: background:rgb(220,220,220);
1.693 droeschl 8096: }
8097:
1.721 harmsja 8098: div.LC_columnSection {
1.911 bisitz 8099: display: block;
8100: clear: both;
8101: overflow: hidden;
8102: margin: 0;
1.693 droeschl 8103: }
8104:
1.721 harmsja 8105: div.LC_columnSection>* {
1.911 bisitz 8106: float: left;
8107: margin: 10px 20px 10px 0;
8108: overflow:hidden;
1.693 droeschl 8109: }
1.721 harmsja 8110:
1.795 www 8111: table em {
1.911 bisitz 8112: font-weight: bold;
8113: font-style: normal;
1.748 schulted 8114: }
1.795 www 8115:
1.779 bisitz 8116: table.LC_tableBrowseRes,
1.795 www 8117: table.LC_tableOfContent {
1.911 bisitz 8118: border:none;
8119: border-spacing: 1px;
8120: padding: 3px;
8121: background-color: #FFFFFF;
8122: font-size: 90%;
1.753 droeschl 8123: }
1.789 droeschl 8124:
1.911 bisitz 8125: table.LC_tableOfContent {
8126: border-collapse: collapse;
1.789 droeschl 8127: }
8128:
1.771 droeschl 8129: table.LC_tableBrowseRes a,
1.768 schulted 8130: table.LC_tableOfContent a {
1.911 bisitz 8131: background-color: transparent;
8132: text-decoration: none;
1.753 droeschl 8133: }
8134:
1.795 www 8135: table.LC_tableOfContent img {
1.911 bisitz 8136: border: none;
8137: height: 1.3em;
8138: vertical-align: text-bottom;
8139: margin-right: 0.3em;
1.753 droeschl 8140: }
1.757 schulted 8141:
1.795 www 8142: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8143: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8144: }
8145:
1.795 www 8146: a#LC_content_toolbar_everything {
1.911 bisitz 8147: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8148: }
8149:
1.795 www 8150: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8151: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8152: }
8153:
1.795 www 8154: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8155: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8156: }
8157:
1.795 www 8158: a#LC_content_toolbar_changefolder {
1.911 bisitz 8159: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8160: }
8161:
1.795 www 8162: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8163: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8164: }
8165:
1.1043 raeburn 8166: a#LC_content_toolbar_edittoplevel {
8167: background-image:url(/res/adm/pages/edittoplevel.gif);
8168: }
8169:
1.795 www 8170: ul#LC_toolbar li a:hover {
1.911 bisitz 8171: background-position: bottom center;
1.757 schulted 8172: }
8173:
1.795 www 8174: ul#LC_toolbar {
1.911 bisitz 8175: padding: 0;
8176: margin: 2px;
8177: list-style:none;
8178: position:relative;
8179: background-color:white;
1.1082 raeburn 8180: overflow: auto;
1.757 schulted 8181: }
8182:
1.795 www 8183: ul#LC_toolbar li {
1.911 bisitz 8184: border:1px solid white;
8185: padding: 0;
8186: margin: 0;
8187: float: left;
8188: display:inline;
8189: vertical-align:middle;
1.1082 raeburn 8190: white-space: nowrap;
1.911 bisitz 8191: }
1.757 schulted 8192:
1.783 amueller 8193:
1.795 www 8194: a.LC_toolbarItem {
1.911 bisitz 8195: display:block;
8196: padding: 0;
8197: margin: 0;
8198: height: 32px;
8199: width: 32px;
8200: color:white;
8201: border: none;
8202: background-repeat:no-repeat;
8203: background-color:transparent;
1.757 schulted 8204: }
8205:
1.915 droeschl 8206: ul.LC_funclist {
8207: margin: 0;
8208: padding: 0.5em 1em 0.5em 0;
8209: }
8210:
1.933 droeschl 8211: ul.LC_funclist > li:first-child {
8212: font-weight:bold;
8213: margin-left:0.8em;
8214: }
8215:
1.915 droeschl 8216: ul.LC_funclist + ul.LC_funclist {
8217: /*
8218: left border as a seperator if we have more than
8219: one list
8220: */
8221: border-left: 1px solid $sidebg;
8222: /*
8223: this hides the left border behind the border of the
8224: outer box if element is wrapped to the next 'line'
8225: */
8226: margin-left: -1px;
8227: }
8228:
1.843 bisitz 8229: ul.LC_funclist li {
1.915 droeschl 8230: display: inline;
1.782 bisitz 8231: white-space: nowrap;
1.915 droeschl 8232: margin: 0 0 0 25px;
8233: line-height: 150%;
1.782 bisitz 8234: }
8235:
1.974 wenzelju 8236: .LC_hidden {
8237: display: none;
8238: }
8239:
1.1030 www 8240: .LCmodal-overlay {
8241: position:fixed;
8242: top:0;
8243: right:0;
8244: bottom:0;
8245: left:0;
8246: height:100%;
8247: width:100%;
8248: margin:0;
8249: padding:0;
8250: background:#999;
8251: opacity:.75;
8252: filter: alpha(opacity=75);
8253: -moz-opacity: 0.75;
8254: z-index:101;
8255: }
8256:
8257: * html .LCmodal-overlay {
8258: position: absolute;
8259: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8260: }
8261:
8262: .LCmodal-window {
8263: position:fixed;
8264: top:50%;
8265: left:50%;
8266: margin:0;
8267: padding:0;
8268: z-index:102;
8269: }
8270:
8271: * html .LCmodal-window {
8272: position:absolute;
8273: }
8274:
8275: .LCclose-window {
8276: position:absolute;
8277: width:32px;
8278: height:32px;
8279: right:8px;
8280: top:8px;
8281: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8282: text-indent:-99999px;
8283: overflow:hidden;
8284: cursor:pointer;
8285: }
8286:
1.1335 raeburn 8287: pre.LC_wordwrap {
8288: white-space: pre-wrap;
8289: white-space: -moz-pre-wrap;
8290: white-space: -pre-wrap;
8291: white-space: -o-pre-wrap;
8292: word-wrap: break-word;
8293: }
8294:
1.1100 raeburn 8295: /*
1.1231 damieng 8296: styles used for response display
8297: */
8298: div.LC_radiofoil, div.LC_rankfoil {
8299: margin: .5em 0em .5em 0em;
8300: }
8301: table.LC_itemgroup {
8302: margin-top: 1em;
8303: }
8304:
8305: /*
1.1100 raeburn 8306: styles used by TTH when "Default set of options to pass to tth/m
8307: when converting TeX" in course settings has been set
8308:
8309: option passed: -t
8310:
8311: */
8312:
8313: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8314: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8315: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8316: td div.norm {line-height:normal;}
8317:
8318: /*
8319: option passed -y3
8320: */
8321:
8322: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8323: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8324: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8325:
1.1230 damieng 8326: /*
8327: sections with roles, for content only
8328: */
8329: section[class^="role-"] {
8330: padding-left: 10px;
8331: padding-right: 5px;
8332: margin-top: 8px;
8333: margin-bottom: 8px;
8334: border: 1px solid #2A4;
8335: border-radius: 5px;
8336: box-shadow: 0px 1px 1px #BBB;
8337: }
8338: section[class^="role-"]>h1 {
8339: position: relative;
8340: margin: 0px;
8341: padding-top: 10px;
8342: padding-left: 40px;
8343: }
8344: section[class^="role-"]>h1:before {
8345: position: absolute;
8346: left: -5px;
8347: top: 5px;
8348: }
8349: section.role-activity>h1:before {
8350: content:url('/adm/daxe/images/section_icons/activity.png');
8351: }
8352: section.role-advice>h1:before {
8353: content:url('/adm/daxe/images/section_icons/advice.png');
8354: }
8355: section.role-bibliography>h1:before {
8356: content:url('/adm/daxe/images/section_icons/bibliography.png');
8357: }
8358: section.role-citation>h1:before {
8359: content:url('/adm/daxe/images/section_icons/citation.png');
8360: }
8361: section.role-conclusion>h1:before {
8362: content:url('/adm/daxe/images/section_icons/conclusion.png');
8363: }
8364: section.role-definition>h1:before {
8365: content:url('/adm/daxe/images/section_icons/definition.png');
8366: }
8367: section.role-demonstration>h1:before {
8368: content:url('/adm/daxe/images/section_icons/demonstration.png');
8369: }
8370: section.role-example>h1:before {
8371: content:url('/adm/daxe/images/section_icons/example.png');
8372: }
8373: section.role-explanation>h1:before {
8374: content:url('/adm/daxe/images/section_icons/explanation.png');
8375: }
8376: section.role-introduction>h1:before {
8377: content:url('/adm/daxe/images/section_icons/introduction.png');
8378: }
8379: section.role-method>h1:before {
8380: content:url('/adm/daxe/images/section_icons/method.png');
8381: }
8382: section.role-more_information>h1:before {
8383: content:url('/adm/daxe/images/section_icons/more_information.png');
8384: }
8385: section.role-objectives>h1:before {
8386: content:url('/adm/daxe/images/section_icons/objectives.png');
8387: }
8388: section.role-prerequisites>h1:before {
8389: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8390: }
8391: section.role-remark>h1:before {
8392: content:url('/adm/daxe/images/section_icons/remark.png');
8393: }
8394: section.role-reminder>h1:before {
8395: content:url('/adm/daxe/images/section_icons/reminder.png');
8396: }
8397: section.role-summary>h1:before {
8398: content:url('/adm/daxe/images/section_icons/summary.png');
8399: }
8400: section.role-syntax>h1:before {
8401: content:url('/adm/daxe/images/section_icons/syntax.png');
8402: }
8403: section.role-warning>h1:before {
8404: content:url('/adm/daxe/images/section_icons/warning.png');
8405: }
8406:
1.1269 raeburn 8407: #LC_minitab_header {
8408: float:left;
8409: width:100%;
8410: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8411: font-size:93%;
8412: line-height:normal;
8413: margin: 0.5em 0 0.5em 0;
8414: }
8415: #LC_minitab_header ul {
8416: margin:0;
8417: padding:10px 10px 0;
8418: list-style:none;
8419: }
8420: #LC_minitab_header li {
8421: float:left;
8422: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8423: margin:0;
8424: padding:0 0 0 9px;
8425: }
8426: #LC_minitab_header a {
8427: display:block;
8428: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8429: padding:5px 15px 4px 6px;
8430: }
8431: #LC_minitab_header #LC_current_minitab {
8432: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8433: }
8434: #LC_minitab_header #LC_current_minitab a {
8435: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8436: padding-bottom:5px;
8437: }
8438:
8439:
1.343 albertel 8440: END
8441: }
8442:
1.306 albertel 8443: =pod
8444:
8445: =item * &headtag()
8446:
8447: Returns a uniform footer for LON-CAPA web pages.
8448:
1.307 albertel 8449: Inputs: $title - optional title for the head
8450: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8451: $args - optional arguments
1.319 albertel 8452: force_register - if is true call registerurl so the remote is
8453: informed
1.415 albertel 8454: redirect -> array ref of
8455: 1- seconds before redirect occurs
8456: 2- url to redirect to
8457: 3- whether the side effect should occur
1.315 albertel 8458: (side effect of setting
8459: $env{'internal.head.redirect'} to the url
8460: redirected too)
1.352 albertel 8461: domain -> force to color decorate a page for a specific
8462: domain
8463: function -> force usage of a specific rolish color scheme
8464: bgcolor -> override the default page bgcolor
1.460 albertel 8465: no_auto_mt_title
8466: -> prevent &mt()ing the title arg
1.464 albertel 8467:
1.306 albertel 8468: =cut
8469:
8470: sub headtag {
1.313 albertel 8471: my ($title,$head_extra,$args) = @_;
1.306 albertel 8472:
1.363 albertel 8473: my $function = $args->{'function'} || &get_users_function();
8474: my $domain = $args->{'domain'} || &determinedomain();
8475: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8476: my $httphost = $args->{'use_absolute'};
1.418 albertel 8477: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8478: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8479: #time(),
1.418 albertel 8480: $env{'environment.color.timestamp'},
1.363 albertel 8481: $function,$domain,$bgcolor);
8482:
1.369 www 8483: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8484:
1.308 albertel 8485: my $result =
8486: '<head>'.
1.1160 raeburn 8487: &font_settings($args);
1.319 albertel 8488:
1.1188 raeburn 8489: my $inhibitprint;
8490: if ($args->{'print_suppress'}) {
8491: $inhibitprint = &print_suppression();
8492: }
1.1064 raeburn 8493:
1.461 albertel 8494: if (!$args->{'frameset'}) {
8495: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8496: }
1.962 droeschl 8497: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8498: $result .= Apache::lonxml::display_title();
1.319 albertel 8499: }
1.436 albertel 8500: if (!$args->{'no_nav_bar'}
8501: && !$args->{'only_body'}
8502: && !$args->{'frameset'}) {
1.1154 raeburn 8503: $result .= &help_menu_js($httphost);
1.1032 www 8504: $result.=&modal_window();
1.1038 www 8505: $result.=&togglebox_script();
1.1034 www 8506: $result.=&wishlist_window();
1.1041 www 8507: $result.=&LCprogressbarUpdate_script();
1.1034 www 8508: } else {
8509: if ($args->{'add_modal'}) {
8510: $result.=&modal_window();
8511: }
8512: if ($args->{'add_wishlist'}) {
8513: $result.=&wishlist_window();
8514: }
1.1038 www 8515: if ($args->{'add_togglebox'}) {
8516: $result.=&togglebox_script();
8517: }
1.1041 www 8518: if ($args->{'add_progressbar'}) {
8519: $result.=&LCprogressbarUpdate_script();
8520: }
1.436 albertel 8521: }
1.314 albertel 8522: if (ref($args->{'redirect'})) {
1.414 albertel 8523: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8524: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8525: if (!$inhibit_continue) {
8526: $env{'internal.head.redirect'} = $url;
8527: }
1.313 albertel 8528: $result.=<<ADDMETA
8529: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8530: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8531: ADDMETA
1.1210 raeburn 8532: } else {
8533: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8534: my $requrl = $env{'request.uri'};
8535: if ($requrl eq '') {
8536: $requrl = $ENV{'REQUEST_URI'};
8537: $requrl =~ s/\?.+$//;
8538: }
8539: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8540: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8541: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8542: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8543: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8544: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8545: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8546: my $offload;
1.1210 raeburn 8547: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8548: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8549: $offload = 1;
8550: }
8551: }
8552: unless ($offload) {
8553: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8554: if ($domdefs{'offloadoth'}{$lonhost}) {
8555: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8556: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8557: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8558: $offload = 1;
8559: $dom_in_use = $env{'user.domain'};
8560: }
1.1210 raeburn 8561: }
1.1340 raeburn 8562: }
8563: }
8564: }
8565: if ($offload) {
8566: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8567: if (($newserver) && ($newserver ne $lonhost)) {
8568: my $numsec = 5;
8569: my $timeout = $numsec * 1000;
8570: my ($newurl,$locknum,%locks,$msg);
8571: if ($env{'request.role.adv'}) {
8572: ($locknum,%locks) = &Apache::lonnet::get_locks();
8573: }
8574: my $disable_submit = 0;
8575: if ($requrl =~ /$LONCAPA::assess_re/) {
8576: $disable_submit = 1;
8577: }
8578: if ($locknum) {
8579: my @lockinfo = sort(values(%locks));
8580: $msg = &mt('Once the following tasks are complete: ')."\n".
8581: join(", ",sort(values(%locks)))."\n";
8582: if (&show_course()) {
8583: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8584: } else {
8585: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8586: }
1.1340 raeburn 8587: } else {
8588: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8589: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8590: }
8591: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8592: $newurl = '/adm/switchserver?otherserver='.$newserver;
8593: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8594: $newurl .= '&role='.$env{'request.role'};
8595: }
8596: if ($env{'request.symb'}) {
8597: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8598: if ($shownsymb =~ m{^/enc/}) {
8599: my $reqdmajor = 2;
8600: my $reqdminor = 11;
8601: my $reqdsubminor = 3;
8602: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8603: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8604: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8605: if (($major eq '' && $minor eq '') ||
8606: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8607: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8608: ($reqdsubminor > $subminor))))) {
8609: undef($shownsymb);
8610: }
1.1210 raeburn 8611: }
1.1340 raeburn 8612: if ($shownsymb) {
8613: &js_escape(\$shownsymb);
8614: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8615: }
1.1340 raeburn 8616: } else {
8617: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8618: &js_escape(\$shownurl);
8619: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8620: }
1.1340 raeburn 8621: }
8622: &js_escape(\$msg);
8623: $result.=<<OFFLOAD
1.1210 raeburn 8624: <meta http-equiv="pragma" content="no-cache" />
8625: <script type="text/javascript">
1.1215 raeburn 8626: // <![CDATA[
1.1210 raeburn 8627: function LC_Offload_Now() {
8628: var dest = "$newurl";
8629: if (dest != '') {
8630: window.location.href="$newurl";
8631: }
8632: }
1.1214 raeburn 8633: \$(document).ready(function () {
8634: window.alert('$msg');
8635: if ($disable_submit) {
1.1210 raeburn 8636: \$(".LC_hwk_submit").prop("disabled", true);
8637: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8638: }
8639: setTimeout('LC_Offload_Now()', $timeout);
8640: });
1.1215 raeburn 8641: // ]]>
1.1210 raeburn 8642: </script>
8643: OFFLOAD
8644: }
8645: }
8646: }
8647: }
8648: }
1.313 albertel 8649: }
1.306 albertel 8650: if (!defined($title)) {
8651: $title = 'The LearningOnline Network with CAPA';
8652: }
1.460 albertel 8653: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8654: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8655: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8656: if (!$args->{'frameset'}) {
8657: $result .= ' /';
8658: }
8659: $result .= '>'
1.1064 raeburn 8660: .$inhibitprint
1.414 albertel 8661: .$head_extra;
1.1242 raeburn 8662: my $clientmobile;
8663: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8664: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8665: } else {
8666: $clientmobile = $env{'browser.mobile'};
8667: }
8668: if ($clientmobile) {
1.1137 raeburn 8669: $result .= '
8670: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8671: <meta name="apple-mobile-web-app-capable" content="yes" />';
8672: }
1.1278 raeburn 8673: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8674: return $result.'</head>';
1.306 albertel 8675: }
8676:
8677: =pod
8678:
1.340 albertel 8679: =item * &font_settings()
8680:
8681: Returns neccessary <meta> to set the proper encoding
8682:
1.1160 raeburn 8683: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8684:
8685: =cut
8686:
8687: sub font_settings {
1.1160 raeburn 8688: my ($args) = @_;
1.340 albertel 8689: my $headerstring='';
1.1160 raeburn 8690: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8691: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8692: $headerstring.=
8693: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8694: if (!$args->{'frameset'}) {
8695: $headerstring.= ' /';
8696: }
8697: $headerstring .= '>'."\n";
1.340 albertel 8698: }
8699: return $headerstring;
8700: }
8701:
1.341 albertel 8702: =pod
8703:
1.1064 raeburn 8704: =item * &print_suppression()
8705:
8706: In course context returns css which causes the body to be blank when media="print",
8707: if printout generation is unavailable for the current resource.
8708:
8709: This could be because:
8710:
8711: (a) printstartdate is in the future
8712:
8713: (b) printenddate is in the past
8714:
8715: (c) there is an active exam block with "printout"
8716: functionality blocked
8717:
8718: Users with pav, pfo or evb privileges are exempt.
8719:
8720: Inputs: none
8721:
8722: =cut
8723:
8724:
8725: sub print_suppression {
8726: my $noprint;
8727: if ($env{'request.course.id'}) {
8728: my $scope = $env{'request.course.id'};
8729: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8730: (&Apache::lonnet::allowed('pfo',$scope))) {
8731: return;
8732: }
8733: if ($env{'request.course.sec'} ne '') {
8734: $scope .= "/$env{'request.course.sec'}";
8735: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8736: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8737: return;
1.1064 raeburn 8738: }
8739: }
8740: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8741: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8742: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8743: if ($blocked) {
8744: my $checkrole = "cm./$cdom/$cnum";
8745: if ($env{'request.course.sec'} ne '') {
8746: $checkrole .= "/$env{'request.course.sec'}";
8747: }
8748: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8749: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8750: $noprint = 1;
8751: }
8752: }
8753: unless ($noprint) {
8754: my $symb = &Apache::lonnet::symbread();
8755: if ($symb ne '') {
8756: my $navmap = Apache::lonnavmaps::navmap->new();
8757: if (ref($navmap)) {
8758: my $res = $navmap->getBySymb($symb);
8759: if (ref($res)) {
8760: if (!$res->resprintable()) {
8761: $noprint = 1;
8762: }
8763: }
8764: }
8765: }
8766: }
8767: if ($noprint) {
8768: return <<"ENDSTYLE";
8769: <style type="text/css" media="print">
8770: body { display:none }
8771: </style>
8772: ENDSTYLE
8773: }
8774: }
8775: return;
8776: }
8777:
8778: =pod
8779:
1.341 albertel 8780: =item * &xml_begin()
8781:
8782: Returns the needed doctype and <html>
8783:
8784: Inputs: none
8785:
8786: =cut
8787:
8788: sub xml_begin {
1.1168 raeburn 8789: my ($is_frameset) = @_;
1.341 albertel 8790: my $output='';
8791:
8792: if ($env{'browser.mathml'}) {
8793: $output='<?xml version="1.0"?>'
8794: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8795: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8796:
8797: # .'<!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">] >'
8798: .'<!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">'
8799: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8800: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8801: } elsif ($is_frameset) {
8802: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8803: '<html>'."\n";
1.341 albertel 8804: } else {
1.1168 raeburn 8805: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8806: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8807: }
8808: return $output;
8809: }
1.340 albertel 8810:
8811: =pod
8812:
1.306 albertel 8813: =item * &start_page()
8814:
8815: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8816:
1.648 raeburn 8817: Inputs:
8818:
8819: =over 4
8820:
8821: $title - optional title for the page
8822:
8823: $head_extra - optional extra HTML to incude inside the <head>
8824:
8825: $args - additional optional args supported are:
8826:
8827: =over 8
8828:
8829: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8830: arg on
1.814 bisitz 8831: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8832: add_entries -> additional attributes to add to the <body>
8833: domain -> force to color decorate a page for a
1.317 albertel 8834: specific domain
1.648 raeburn 8835: function -> force usage of a specific rolish color
1.317 albertel 8836: scheme
1.648 raeburn 8837: redirect -> see &headtag()
8838: bgcolor -> override the default page bg color
8839: js_ready -> return a string ready for being used in
1.317 albertel 8840: a javascript writeln
1.648 raeburn 8841: html_encode -> return a string ready for being used in
1.320 albertel 8842: a html attribute
1.648 raeburn 8843: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8844: $forcereg arg
1.648 raeburn 8845: frameset -> if true will start with a <frameset>
1.330 albertel 8846: rather than <body>
1.648 raeburn 8847: skip_phases -> hash ref of
1.338 albertel 8848: head -> skip the <html><head> generation
8849: body -> skip all <body> generation
1.648 raeburn 8850: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8851: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8852: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8853: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8854: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8855: group -> includes the current group, if page is for a
1.1274 raeburn 8856: specific group
8857: use_absolute -> for request for external resource or syllabus, this
8858: will contain https://<hostname> if server uses
8859: https (as per hosts.tab), but request is for http
8860: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8861:
1.648 raeburn 8862: =back
1.460 albertel 8863:
1.648 raeburn 8864: =back
1.562 albertel 8865:
1.306 albertel 8866: =cut
8867:
8868: sub start_page {
1.309 albertel 8869: my ($title,$head_extra,$args) = @_;
1.318 albertel 8870: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8871:
1.315 albertel 8872: $env{'internal.start_page'}++;
1.1318 raeburn 8873: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8874:
1.338 albertel 8875: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8876: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8877: }
1.1316 raeburn 8878:
8879: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8880: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8881: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8882: $args->{'no_primary_menu'} = 1;
8883: }
8884: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8885: $args->{'no_inline_menu'} = 1;
8886: }
8887: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8888: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8889: }
8890: } else {
8891: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8892: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8893: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8894: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8895: $args->{'no_primary_menu'} = 1;
8896: }
8897: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8898: $args->{'no_inline_menu'} = 1;
8899: }
8900: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8901: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8902: }
8903: }
8904: }
1.1316 raeburn 8905: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8906: $env{'course.'.$env{'request.course.id'}.'.domain'},
8907: $env{'course.'.$env{'request.course.id'}.'.num'});
8908: }
1.338 albertel 8909:
8910: if (! exists($args->{'skip_phases'}{'body'}) ) {
8911: if ($args->{'frameset'}) {
8912: my $attr_string = &make_attr_string($args->{'force_register'},
8913: $args->{'add_entries'});
8914: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8915: } else {
8916: $result .=
8917: &bodytag($title,
8918: $args->{'function'}, $args->{'add_entries'},
8919: $args->{'only_body'}, $args->{'domain'},
8920: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8921: $args->{'bgcolor'}, $args,
1.1318 raeburn 8922: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8923: }
1.330 albertel 8924: }
1.338 albertel 8925:
1.315 albertel 8926: if ($args->{'js_ready'}) {
1.713 kaisler 8927: $result = &js_ready($result);
1.315 albertel 8928: }
1.320 albertel 8929: if ($args->{'html_encode'}) {
1.713 kaisler 8930: $result = &html_encode($result);
8931: }
8932:
1.813 bisitz 8933: # Preparation for new and consistent functionlist at top of screen
8934: # if ($args->{'functionlist'}) {
8935: # $result .= &build_functionlist();
8936: #}
8937:
1.964 droeschl 8938: # Don't add anything more if only_body wanted or in const space
8939: return $result if $args->{'only_body'}
8940: || $env{'request.state'} eq 'construct';
1.813 bisitz 8941:
8942: #Breadcrumbs
1.758 kaisler 8943: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8944: &Apache::lonhtmlcommon::clear_breadcrumbs();
8945: #if any br links exists, add them to the breadcrumbs
8946: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8947: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8948: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8949: }
8950: }
1.1096 raeburn 8951: # if @advtools array contains items add then to the breadcrumbs
8952: if (@advtools > 0) {
8953: &Apache::lonmenu::advtools_crumbs(@advtools);
8954: }
1.1272 raeburn 8955: my $menulink;
8956: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8957: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8958: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8959: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8960: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8961: (!$env{'request.role.adv'}))) {
8962: $menulink = 0;
8963: } else {
8964: undef($menulink);
8965: }
1.758 kaisler 8966: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8967: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8968: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8969: } else {
1.1272 raeburn 8970: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8971: }
1.320 albertel 8972: }
1.315 albertel 8973: return $result;
1.306 albertel 8974: }
8975:
8976: sub end_page {
1.315 albertel 8977: my ($args) = @_;
8978: $env{'internal.end_page'}++;
1.330 albertel 8979: my $result;
1.335 albertel 8980: if ($args->{'discussion'}) {
8981: my ($target,$parser);
8982: if (ref($args->{'discussion'})) {
8983: ($target,$parser) =($args->{'discussion'}{'target'},
8984: $args->{'discussion'}{'parser'});
8985: }
8986: $result .= &Apache::lonxml::xmlend($target,$parser);
8987: }
1.330 albertel 8988: if ($args->{'frameset'}) {
8989: $result .= '</frameset>';
8990: } else {
1.635 raeburn 8991: $result .= &endbodytag($args);
1.330 albertel 8992: }
1.1080 raeburn 8993: unless ($args->{'notbody'}) {
8994: $result .= "\n</html>";
8995: }
1.330 albertel 8996:
1.315 albertel 8997: if ($args->{'js_ready'}) {
1.317 albertel 8998: $result = &js_ready($result);
1.315 albertel 8999: }
1.335 albertel 9000:
1.320 albertel 9001: if ($args->{'html_encode'}) {
9002: $result = &html_encode($result);
9003: }
1.335 albertel 9004:
1.315 albertel 9005: return $result;
9006: }
9007:
1.1034 www 9008: sub wishlist_window {
9009: return(<<'ENDWISHLIST');
1.1046 raeburn 9010: <script type="text/javascript">
1.1034 www 9011: // <![CDATA[
9012: // <!-- BEGIN LON-CAPA Internal
9013: function set_wishlistlink(title, path) {
9014: if (!title) {
9015: title = document.title;
9016: title = title.replace(/^LON-CAPA /,'');
9017: }
1.1175 raeburn 9018: title = encodeURIComponent(title);
1.1203 raeburn 9019: title = title.replace("'","\\\'");
1.1034 www 9020: if (!path) {
9021: path = location.pathname;
9022: }
1.1175 raeburn 9023: path = encodeURIComponent(path);
1.1203 raeburn 9024: path = path.replace("'","\\\'");
1.1034 www 9025: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9026: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9027: }
9028: // END LON-CAPA Internal -->
9029: // ]]>
9030: </script>
9031: ENDWISHLIST
9032: }
9033:
1.1030 www 9034: sub modal_window {
9035: return(<<'ENDMODAL');
1.1046 raeburn 9036: <script type="text/javascript">
1.1030 www 9037: // <![CDATA[
9038: // <!-- BEGIN LON-CAPA Internal
9039: var modalWindow = {
9040: parent:"body",
9041: windowId:null,
9042: content:null,
9043: width:null,
9044: height:null,
9045: close:function()
9046: {
9047: $(".LCmodal-window").remove();
9048: $(".LCmodal-overlay").remove();
9049: },
9050: open:function()
9051: {
9052: var modal = "";
9053: modal += "<div class=\"LCmodal-overlay\"></div>";
9054: 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;\">";
9055: modal += this.content;
9056: modal += "</div>";
9057:
9058: $(this.parent).append(modal);
9059:
9060: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9061: $(".LCclose-window").click(function(){modalWindow.close();});
9062: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9063: }
9064: };
1.1140 raeburn 9065: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9066: {
1.1266 raeburn 9067: source = source.replace(/'/g,"'");
1.1030 www 9068: modalWindow.windowId = "myModal";
9069: modalWindow.width = width;
9070: modalWindow.height = height;
1.1196 raeburn 9071: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9072: modalWindow.open();
1.1208 raeburn 9073: };
1.1030 www 9074: // END LON-CAPA Internal -->
9075: // ]]>
9076: </script>
9077: ENDMODAL
9078: }
9079:
9080: sub modal_link {
1.1140 raeburn 9081: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9082: unless ($width) { $width=480; }
9083: unless ($height) { $height=400; }
1.1031 www 9084: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9085: unless ($transparency) { $transparency='true'; }
9086:
1.1074 raeburn 9087: my $target_attr;
9088: if (defined($target)) {
9089: $target_attr = 'target="'.$target.'"';
9090: }
9091: return <<"ENDLINK";
1.1336 raeburn 9092: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9093: ENDLINK
1.1030 www 9094: }
9095:
1.1032 www 9096: sub modal_adhoc_script {
9097: my ($funcname,$width,$height,$content)=@_;
9098: return (<<ENDADHOC);
1.1046 raeburn 9099: <script type="text/javascript">
1.1032 www 9100: // <![CDATA[
9101: var $funcname = function()
9102: {
9103: modalWindow.windowId = "myModal";
9104: modalWindow.width = $width;
9105: modalWindow.height = $height;
9106: modalWindow.content = '$content';
9107: modalWindow.open();
9108: };
9109: // ]]>
9110: </script>
9111: ENDADHOC
9112: }
9113:
1.1041 www 9114: sub modal_adhoc_inner {
9115: my ($funcname,$width,$height,$content)=@_;
9116: my $innerwidth=$width-20;
9117: $content=&js_ready(
1.1140 raeburn 9118: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9119: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9120: $content.
1.1041 www 9121: &end_scrollbox().
1.1140 raeburn 9122: &end_page()
1.1041 www 9123: );
9124: return &modal_adhoc_script($funcname,$width,$height,$content);
9125: }
9126:
9127: sub modal_adhoc_window {
9128: my ($funcname,$width,$height,$content,$linktext)=@_;
9129: return &modal_adhoc_inner($funcname,$width,$height,$content).
9130: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9131: }
9132:
9133: sub modal_adhoc_launch {
9134: my ($funcname,$width,$height,$content)=@_;
9135: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9136: <script type="text/javascript">
9137: // <![CDATA[
9138: $funcname();
9139: // ]]>
9140: </script>
9141: ENDLAUNCH
9142: }
9143:
9144: sub modal_adhoc_close {
9145: return (<<ENDCLOSE);
9146: <script type="text/javascript">
9147: // <![CDATA[
9148: modalWindow.close();
9149: // ]]>
9150: </script>
9151: ENDCLOSE
9152: }
9153:
1.1038 www 9154: sub togglebox_script {
9155: return(<<ENDTOGGLE);
9156: <script type="text/javascript">
9157: // <![CDATA[
9158: function LCtoggleDisplay(id,hidetext,showtext) {
9159: link = document.getElementById(id + "link").childNodes[0];
9160: with (document.getElementById(id).style) {
9161: if (display == "none" ) {
9162: display = "inline";
9163: link.nodeValue = hidetext;
9164: } else {
9165: display = "none";
9166: link.nodeValue = showtext;
9167: }
9168: }
9169: }
9170: // ]]>
9171: </script>
9172: ENDTOGGLE
9173: }
9174:
1.1039 www 9175: sub start_togglebox {
9176: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9177: unless ($heading) { $heading=''; } else { $heading.=' '; }
9178: unless ($showtext) { $showtext=&mt('show'); }
9179: unless ($hidetext) { $hidetext=&mt('hide'); }
9180: unless ($headerbg) { $headerbg='#FFFFFF'; }
9181: return &start_data_table().
9182: &start_data_table_header_row().
9183: '<td bgcolor="'.$headerbg.'">'.$heading.
9184: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9185: $showtext.'\')">'.$showtext.'</a>]</td>'.
9186: &end_data_table_header_row().
9187: '<tr id="'.$id.'" style="display:none""><td>';
9188: }
9189:
9190: sub end_togglebox {
9191: return '</td></tr>'.&end_data_table();
9192: }
9193:
1.1041 www 9194: sub LCprogressbar_script {
1.1302 raeburn 9195: my ($id,$number_to_do)=@_;
9196: if ($number_to_do) {
9197: return(<<ENDPROGRESS);
1.1041 www 9198: <script type="text/javascript">
9199: // <![CDATA[
1.1045 www 9200: \$('#progressbar$id').progressbar({
1.1041 www 9201: value: 0,
9202: change: function(event, ui) {
9203: var newVal = \$(this).progressbar('option', 'value');
9204: \$('.pblabel', this).text(LCprogressTxt);
9205: }
9206: });
9207: // ]]>
9208: </script>
9209: ENDPROGRESS
1.1302 raeburn 9210: } else {
9211: return(<<ENDPROGRESS);
9212: <script type="text/javascript">
9213: // <![CDATA[
9214: \$('#progressbar$id').progressbar({
9215: value: false,
9216: create: function(event, ui) {
9217: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9218: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9219: }
9220: });
9221: // ]]>
9222: </script>
9223: ENDPROGRESS
9224: }
1.1041 www 9225: }
9226:
9227: sub LCprogressbarUpdate_script {
9228: return(<<ENDPROGRESSUPDATE);
9229: <style type="text/css">
9230: .ui-progressbar { position:relative; }
1.1302 raeburn 9231: .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 9232: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9233: </style>
9234: <script type="text/javascript">
9235: // <![CDATA[
1.1045 www 9236: var LCprogressTxt='---';
9237:
1.1302 raeburn 9238: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9239: LCprogressTxt=progresstext;
1.1302 raeburn 9240: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9241: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9242: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9243: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9244: } else {
9245: \$('#progressbar'+id).progressbar('value',percent);
9246: }
1.1041 www 9247: }
9248: // ]]>
9249: </script>
9250: ENDPROGRESSUPDATE
9251: }
9252:
1.1042 www 9253: my $LClastpercent;
1.1045 www 9254: my $LCidcnt;
9255: my $LCcurrentid;
1.1042 www 9256:
1.1041 www 9257: sub LCprogressbar {
1.1302 raeburn 9258: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9259: $LClastpercent=0;
1.1045 www 9260: $LCidcnt++;
9261: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9262: my ($starting,$content);
9263: if ($number_to_do) {
9264: $starting=&mt('Starting');
9265: $content=(<<ENDPROGBAR);
9266: $preamble
1.1045 www 9267: <div id="progressbar$LCcurrentid">
1.1041 www 9268: <span class="pblabel">$starting</span>
9269: </div>
9270: ENDPROGBAR
1.1302 raeburn 9271: } else {
9272: $starting=&mt('Loading...');
9273: $LClastpercent='false';
9274: $content=(<<ENDPROGBAR);
9275: $preamble
9276: <div id="progressbar$LCcurrentid">
9277: <div class="progress-label">$starting</div>
9278: </div>
9279: ENDPROGBAR
9280: }
9281: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9282: }
9283:
9284: sub LCprogressbarUpdate {
1.1302 raeburn 9285: my ($r,$val,$text,$number_to_do)=@_;
9286: if ($number_to_do) {
9287: unless ($val) {
9288: if ($LClastpercent) {
9289: $val=$LClastpercent;
9290: } else {
9291: $val=0;
9292: }
9293: }
9294: if ($val<0) { $val=0; }
9295: if ($val>100) { $val=0; }
9296: $LClastpercent=$val;
9297: unless ($text) { $text=$val.'%'; }
9298: } else {
9299: $val = 'false';
1.1042 www 9300: }
1.1041 www 9301: $text=&js_ready($text);
1.1044 www 9302: &r_print($r,<<ENDUPDATE);
1.1041 www 9303: <script type="text/javascript">
9304: // <![CDATA[
1.1302 raeburn 9305: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9306: // ]]>
9307: </script>
9308: ENDUPDATE
1.1035 www 9309: }
9310:
1.1042 www 9311: sub LCprogressbarClose {
9312: my ($r)=@_;
9313: $LClastpercent=0;
1.1044 www 9314: &r_print($r,<<ENDCLOSE);
1.1042 www 9315: <script type="text/javascript">
9316: // <![CDATA[
1.1045 www 9317: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9318: // ]]>
9319: </script>
9320: ENDCLOSE
1.1044 www 9321: }
9322:
9323: sub r_print {
9324: my ($r,$to_print)=@_;
9325: if ($r) {
9326: $r->print($to_print);
9327: $r->rflush();
9328: } else {
9329: print($to_print);
9330: }
1.1042 www 9331: }
9332:
1.320 albertel 9333: sub html_encode {
9334: my ($result) = @_;
9335:
1.322 albertel 9336: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9337:
9338: return $result;
9339: }
1.1044 www 9340:
1.317 albertel 9341: sub js_ready {
9342: my ($result) = @_;
9343:
1.323 albertel 9344: $result =~ s/[\n\r]/ /xmsg;
9345: $result =~ s/\\/\\\\/xmsg;
9346: $result =~ s/'/\\'/xmsg;
1.372 albertel 9347: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9348:
9349: return $result;
9350: }
9351:
1.315 albertel 9352: sub validate_page {
9353: if ( exists($env{'internal.start_page'})
1.316 albertel 9354: && $env{'internal.start_page'} > 1) {
9355: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9356: $env{'internal.start_page'}.' '.
1.316 albertel 9357: $ENV{'request.filename'});
1.315 albertel 9358: }
9359: if ( exists($env{'internal.end_page'})
1.316 albertel 9360: && $env{'internal.end_page'} > 1) {
9361: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9362: $env{'internal.end_page'}.' '.
1.316 albertel 9363: $env{'request.filename'});
1.315 albertel 9364: }
9365: if ( exists($env{'internal.start_page'})
9366: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9367: &Apache::lonnet::logthis('start_page called without end_page '.
9368: $env{'request.filename'});
1.315 albertel 9369: }
9370: if ( ! exists($env{'internal.start_page'})
9371: && exists($env{'internal.end_page'})) {
1.316 albertel 9372: &Apache::lonnet::logthis('end_page called without start_page'.
9373: $env{'request.filename'});
1.315 albertel 9374: }
1.306 albertel 9375: }
1.315 albertel 9376:
1.996 www 9377:
9378: sub start_scrollbox {
1.1140 raeburn 9379: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9380: unless ($outerwidth) { $outerwidth='520px'; }
9381: unless ($width) { $width='500px'; }
9382: unless ($height) { $height='200px'; }
1.1075 raeburn 9383: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9384: if ($id ne '') {
1.1140 raeburn 9385: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9386: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9387: }
1.1075 raeburn 9388: if ($bgcolor ne '') {
9389: $tdcol = "background-color: $bgcolor;";
9390: }
1.1137 raeburn 9391: my $nicescroll_js;
9392: if ($env{'browser.mobile'}) {
1.1140 raeburn 9393: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9394: }
9395: return <<"END";
9396: $nicescroll_js
9397:
9398: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9399: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9400: END
9401: }
9402:
9403: sub end_scrollbox {
9404: return '</div></td></tr></table>';
9405: }
9406:
9407: sub nicescroll_javascript {
9408: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9409: my %options;
9410: if (ref($cursor) eq 'HASH') {
9411: %options = %{$cursor};
9412: }
9413: unless ($options{'railalign'} =~ /^left|right$/) {
9414: $options{'railalign'} = 'left';
9415: }
9416: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9417: my $function = &get_users_function();
9418: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9419: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9420: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9421: }
1.1140 raeburn 9422: }
9423: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9424: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9425: $options{'cursoropacity'}='1.0';
9426: }
1.1140 raeburn 9427: } else {
9428: $options{'cursoropacity'}='1.0';
9429: }
9430: if ($options{'cursorfixedheight'} eq 'none') {
9431: delete($options{'cursorfixedheight'});
9432: } else {
9433: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9434: }
9435: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9436: delete($options{'railoffset'});
9437: }
9438: my @niceoptions;
9439: while (my($key,$value) = each(%options)) {
9440: if ($value =~ /^\{.+\}$/) {
9441: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9442: } else {
1.1140 raeburn 9443: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9444: }
1.1140 raeburn 9445: }
9446: my $nicescroll_js = '
1.1137 raeburn 9447: $(document).ready(
1.1140 raeburn 9448: function() {
9449: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9450: }
1.1137 raeburn 9451: );
9452: ';
1.1140 raeburn 9453: if ($framecheck) {
9454: $nicescroll_js .= '
9455: function expand_div(caller) {
9456: if (top === self) {
9457: document.getElementById("'.$id.'").style.width = "auto";
9458: document.getElementById("'.$id.'").style.height = "auto";
9459: } else {
9460: try {
9461: if (parent.frames) {
9462: if (parent.frames.length > 1) {
9463: var framesrc = parent.frames[1].location.href;
9464: var currsrc = framesrc.replace(/\#.*$/,"");
9465: if ((caller == "search") || (currsrc == "'.$location.'")) {
9466: document.getElementById("'.$id.'").style.width = "auto";
9467: document.getElementById("'.$id.'").style.height = "auto";
9468: }
9469: }
9470: }
9471: } catch (e) {
9472: return;
9473: }
1.1137 raeburn 9474: }
1.1140 raeburn 9475: return;
1.996 www 9476: }
1.1140 raeburn 9477: ';
9478: }
9479: if ($needjsready) {
9480: $nicescroll_js = '
9481: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9482: } else {
9483: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9484: }
9485: return $nicescroll_js;
1.996 www 9486: }
9487:
1.318 albertel 9488: sub simple_error_page {
1.1150 bisitz 9489: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9490: my %displayargs;
1.1151 raeburn 9491: if (ref($args) eq 'HASH') {
9492: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9493: if ($args->{'only_body'}) {
9494: $displayargs{'only_body'} = 1;
9495: }
9496: if ($args->{'no_nav_bar'}) {
9497: $displayargs{'no_nav_bar'} = 1;
9498: }
1.1151 raeburn 9499: } else {
9500: $msg = &mt($msg);
9501: }
1.1150 bisitz 9502:
1.318 albertel 9503: my $page =
1.1304 raeburn 9504: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9505: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9506: &Apache::loncommon::end_page();
9507: if (ref($r)) {
9508: $r->print($page);
1.327 albertel 9509: return;
1.318 albertel 9510: }
9511: return $page;
9512: }
1.347 albertel 9513:
9514: {
1.610 albertel 9515: my @row_count;
1.961 onken 9516:
9517: sub start_data_table_count {
9518: unshift(@row_count, 0);
9519: return;
9520: }
9521:
9522: sub end_data_table_count {
9523: shift(@row_count);
9524: return;
9525: }
9526:
1.347 albertel 9527: sub start_data_table {
1.1018 raeburn 9528: my ($add_class,$id) = @_;
1.422 albertel 9529: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9530: my $table_id;
9531: if (defined($id)) {
9532: $table_id = ' id="'.$id.'"';
9533: }
1.961 onken 9534: &start_data_table_count();
1.1018 raeburn 9535: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9536: }
9537:
9538: sub end_data_table {
1.961 onken 9539: &end_data_table_count();
1.389 albertel 9540: return '</table>'."\n";;
1.347 albertel 9541: }
9542:
9543: sub start_data_table_row {
1.974 wenzelju 9544: my ($add_class, $id) = @_;
1.610 albertel 9545: $row_count[0]++;
9546: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9547: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9548: $id = (' id="'.$id.'"') unless ($id eq '');
9549: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9550: }
1.471 banghart 9551:
9552: sub continue_data_table_row {
1.974 wenzelju 9553: my ($add_class, $id) = @_;
1.610 albertel 9554: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9555: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9556: $id = (' id="'.$id.'"') unless ($id eq '');
9557: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9558: }
1.347 albertel 9559:
9560: sub end_data_table_row {
1.389 albertel 9561: return '</tr>'."\n";;
1.347 albertel 9562: }
1.367 www 9563:
1.421 albertel 9564: sub start_data_table_empty_row {
1.707 bisitz 9565: # $row_count[0]++;
1.421 albertel 9566: return '<tr class="LC_empty_row" >'."\n";;
9567: }
9568:
9569: sub end_data_table_empty_row {
9570: return '</tr>'."\n";;
9571: }
9572:
1.367 www 9573: sub start_data_table_header_row {
1.389 albertel 9574: return '<tr class="LC_header_row">'."\n";;
1.367 www 9575: }
9576:
9577: sub end_data_table_header_row {
1.389 albertel 9578: return '</tr>'."\n";;
1.367 www 9579: }
1.890 droeschl 9580:
9581: sub data_table_caption {
9582: my $caption = shift;
9583: return "<caption class=\"LC_caption\">$caption</caption>";
9584: }
1.347 albertel 9585: }
9586:
1.548 albertel 9587: =pod
9588:
9589: =item * &inhibit_menu_check($arg)
9590:
9591: Checks for a inhibitmenu state and generates output to preserve it
9592:
9593: Inputs: $arg - can be any of
9594: - undef - in which case the return value is a string
9595: to add into arguments list of a uri
9596: - 'input' - in which case the return value is a HTML
9597: <form> <input> field of type hidden to
9598: preserve the value
9599: - a url - in which case the return value is the url with
9600: the neccesary cgi args added to preserve the
9601: inhibitmenu state
9602: - a ref to a url - no return value, but the string is
9603: updated to include the neccessary cgi
9604: args to preserve the inhibitmenu state
9605:
9606: =cut
9607:
9608: sub inhibit_menu_check {
9609: my ($arg) = @_;
9610: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9611: if ($arg eq 'input') {
9612: if ($env{'form.inhibitmenu'}) {
9613: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9614: } else {
9615: return
9616: }
9617: }
9618: if ($env{'form.inhibitmenu'}) {
9619: if (ref($arg)) {
9620: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9621: } elsif ($arg eq '') {
9622: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9623: } else {
9624: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9625: }
9626: }
9627: if (!ref($arg)) {
9628: return $arg;
9629: }
9630: }
9631:
1.251 albertel 9632: ###############################################
1.182 matthew 9633:
9634: =pod
9635:
1.549 albertel 9636: =back
9637:
9638: =head1 User Information Routines
9639:
9640: =over 4
9641:
1.405 albertel 9642: =item * &get_users_function()
1.182 matthew 9643:
9644: Used by &bodytag to determine the current users primary role.
9645: Returns either 'student','coordinator','admin', or 'author'.
9646:
9647: =cut
9648:
9649: ###############################################
9650: sub get_users_function {
1.815 tempelho 9651: my $function = 'norole';
1.818 tempelho 9652: if ($env{'request.role'}=~/^(st)/) {
9653: $function='student';
9654: }
1.907 raeburn 9655: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9656: $function='coordinator';
9657: }
1.258 albertel 9658: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9659: $function='admin';
9660: }
1.826 bisitz 9661: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9662: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9663: $function='author';
9664: }
9665: return $function;
1.54 www 9666: }
1.99 www 9667:
9668: ###############################################
9669:
1.233 raeburn 9670: =pod
9671:
1.821 raeburn 9672: =item * &show_course()
9673:
9674: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9675: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9676:
9677: Inputs:
9678: None
9679:
9680: Outputs:
9681: Scalar: 1 if 'Course' to be used, 0 otherwise.
9682:
9683: =cut
9684:
9685: ###############################################
9686: sub show_course {
9687: my $course = !$env{'user.adv'};
9688: if (!$env{'user.adv'}) {
9689: foreach my $env (keys(%env)) {
9690: next if ($env !~ m/^user\.priv\./);
9691: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9692: $course = 0;
9693: last;
9694: }
9695: }
9696: }
9697: return $course;
9698: }
9699:
9700: ###############################################
9701:
9702: =pod
9703:
1.542 raeburn 9704: =item * &check_user_status()
1.274 raeburn 9705:
9706: Determines current status of supplied role for a
9707: specific user. Roles can be active, previous or future.
9708:
9709: Inputs:
9710: user's domain, user's username, course's domain,
1.375 raeburn 9711: course's number, optional section ID.
1.274 raeburn 9712:
9713: Outputs:
9714: role status: active, previous or future.
9715:
9716: =cut
9717:
9718: sub check_user_status {
1.412 raeburn 9719: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9720: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9721: my @uroles = keys(%userinfo);
1.274 raeburn 9722: my $srchstr;
9723: my $active_chk = 'none';
1.412 raeburn 9724: my $now = time;
1.274 raeburn 9725: if (@uroles > 0) {
1.908 raeburn 9726: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9727: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9728: } else {
1.412 raeburn 9729: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9730: }
9731: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9732: my $role_end = 0;
9733: my $role_start = 0;
9734: $active_chk = 'active';
1.412 raeburn 9735: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9736: $role_end = $1;
9737: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9738: $role_start = $1;
1.274 raeburn 9739: }
9740: }
9741: if ($role_start > 0) {
1.412 raeburn 9742: if ($now < $role_start) {
1.274 raeburn 9743: $active_chk = 'future';
9744: }
9745: }
9746: if ($role_end > 0) {
1.412 raeburn 9747: if ($now > $role_end) {
1.274 raeburn 9748: $active_chk = 'previous';
9749: }
9750: }
9751: }
9752: }
9753: return $active_chk;
9754: }
9755:
9756: ###############################################
9757:
9758: =pod
9759:
1.405 albertel 9760: =item * &get_sections()
1.233 raeburn 9761:
9762: Determines all the sections for a course including
9763: sections with students and sections containing other roles.
1.419 raeburn 9764: Incoming parameters:
9765:
9766: 1. domain
9767: 2. course number
9768: 3. reference to array containing roles for which sections should
9769: be gathered (optional).
9770: 4. reference to array containing status types for which sections
9771: should be gathered (optional).
9772:
9773: If the third argument is undefined, sections are gathered for any role.
9774: If the fourth argument is undefined, sections are gathered for any status.
9775: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9776:
1.374 raeburn 9777: Returns section hash (keys are section IDs, values are
9778: number of users in each section), subject to the
1.419 raeburn 9779: optional roles filter, optional status filter
1.233 raeburn 9780:
9781: =cut
9782:
9783: ###############################################
9784: sub get_sections {
1.419 raeburn 9785: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9786: if (!defined($cdom) || !defined($cnum)) {
9787: my $cid = $env{'request.course.id'};
9788:
9789: return if (!defined($cid));
9790:
9791: $cdom = $env{'course.'.$cid.'.domain'};
9792: $cnum = $env{'course.'.$cid.'.num'};
9793: }
9794:
9795: my %sectioncount;
1.419 raeburn 9796: my $now = time;
1.240 albertel 9797:
1.1118 raeburn 9798: my $check_students = 1;
9799: my $only_students = 0;
9800: if (ref($possible_roles) eq 'ARRAY') {
9801: if (grep(/^st$/,@{$possible_roles})) {
9802: if (@{$possible_roles} == 1) {
9803: $only_students = 1;
9804: }
9805: } else {
9806: $check_students = 0;
9807: }
9808: }
9809:
9810: if ($check_students) {
1.276 albertel 9811: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9812: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9813: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9814: my $start_index = &Apache::loncoursedata::CL_START();
9815: my $end_index = &Apache::loncoursedata::CL_END();
9816: my $status;
1.366 albertel 9817: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9818: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9819: $data->[$status_index],
9820: $data->[$start_index],
9821: $data->[$end_index]);
9822: if ($stu_status eq 'Active') {
9823: $status = 'active';
9824: } elsif ($end < $now) {
9825: $status = 'previous';
9826: } elsif ($start > $now) {
9827: $status = 'future';
9828: }
9829: if ($section ne '-1' && $section !~ /^\s*$/) {
9830: if ((!defined($possible_status)) || (($status ne '') &&
9831: (grep/^\Q$status\E$/,@{$possible_status}))) {
9832: $sectioncount{$section}++;
9833: }
1.240 albertel 9834: }
9835: }
9836: }
1.1118 raeburn 9837: if ($only_students) {
9838: return %sectioncount;
9839: }
1.240 albertel 9840: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9841: foreach my $user (sort(keys(%courseroles))) {
9842: if ($user !~ /^(\w{2})/) { next; }
9843: my ($role) = ($user =~ /^(\w{2})/);
9844: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9845: my ($section,$status);
1.240 albertel 9846: if ($role eq 'cr' &&
9847: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9848: $section=$1;
9849: }
9850: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9851: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9852: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9853: if ($end == -1 && $start == -1) {
9854: next; #deleted role
9855: }
9856: if (!defined($possible_status)) {
9857: $sectioncount{$section}++;
9858: } else {
9859: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9860: $status = 'active';
9861: } elsif ($end < $now) {
9862: $status = 'future';
9863: } elsif ($start > $now) {
9864: $status = 'previous';
9865: }
9866: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9867: $sectioncount{$section}++;
9868: }
9869: }
1.233 raeburn 9870: }
1.366 albertel 9871: return %sectioncount;
1.233 raeburn 9872: }
9873:
1.274 raeburn 9874: ###############################################
1.294 raeburn 9875:
9876: =pod
1.405 albertel 9877:
9878: =item * &get_course_users()
9879:
1.275 raeburn 9880: Retrieves usernames:domains for users in the specified course
9881: with specific role(s), and access status.
9882:
9883: Incoming parameters:
1.277 albertel 9884: 1. course domain
9885: 2. course number
9886: 3. access status: users must have - either active,
1.275 raeburn 9887: previous, future, or all.
1.277 albertel 9888: 4. reference to array of permissible roles
1.288 raeburn 9889: 5. reference to array of section restrictions (optional)
9890: 6. reference to results object (hash of hashes).
9891: 7. reference to optional userdata hash
1.609 raeburn 9892: 8. reference to optional statushash
1.630 raeburn 9893: 9. flag if privileged users (except those set to unhide in
9894: course settings) should be excluded
1.609 raeburn 9895: Keys of top level results hash are roles.
1.275 raeburn 9896: Keys of inner hashes are username:domain, with
9897: values set to access type.
1.288 raeburn 9898: Optional userdata hash returns an array with arguments in the
9899: same order as loncoursedata::get_classlist() for student data.
9900:
1.609 raeburn 9901: Optional statushash returns
9902:
1.288 raeburn 9903: Entries for end, start, section and status are blank because
9904: of the possibility of multiple values for non-student roles.
9905:
1.275 raeburn 9906: =cut
1.405 albertel 9907:
1.275 raeburn 9908: ###############################################
1.405 albertel 9909:
1.275 raeburn 9910: sub get_course_users {
1.630 raeburn 9911: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9912: my %idx = ();
1.419 raeburn 9913: my %seclists;
1.288 raeburn 9914:
9915: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9916: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9917: $idx{end} = &Apache::loncoursedata::CL_END();
9918: $idx{start} = &Apache::loncoursedata::CL_START();
9919: $idx{id} = &Apache::loncoursedata::CL_ID();
9920: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9921: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9922: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9923:
1.290 albertel 9924: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9925: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9926: my $now = time;
1.277 albertel 9927: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9928: my $match = 0;
1.412 raeburn 9929: my $secmatch = 0;
1.419 raeburn 9930: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9931: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9932: if ($section eq '') {
9933: $section = 'none';
9934: }
1.291 albertel 9935: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9936: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9937: $secmatch = 1;
9938: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9939: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9940: $secmatch = 1;
9941: }
9942: } else {
1.419 raeburn 9943: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9944: $secmatch = 1;
9945: }
1.290 albertel 9946: }
1.412 raeburn 9947: if (!$secmatch) {
9948: next;
9949: }
1.419 raeburn 9950: }
1.275 raeburn 9951: if (defined($$types{'active'})) {
1.288 raeburn 9952: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9953: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9954: $match = 1;
1.275 raeburn 9955: }
9956: }
9957: if (defined($$types{'previous'})) {
1.609 raeburn 9958: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9959: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9960: $match = 1;
1.275 raeburn 9961: }
9962: }
9963: if (defined($$types{'future'})) {
1.609 raeburn 9964: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9965: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9966: $match = 1;
1.275 raeburn 9967: }
9968: }
1.609 raeburn 9969: if ($match) {
9970: push(@{$seclists{$student}},$section);
9971: if (ref($userdata) eq 'HASH') {
9972: $$userdata{$student} = $$classlist{$student};
9973: }
9974: if (ref($statushash) eq 'HASH') {
9975: $statushash->{$student}{'st'}{$section} = $status;
9976: }
1.288 raeburn 9977: }
1.275 raeburn 9978: }
9979: }
1.412 raeburn 9980: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9981: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9982: my $now = time;
1.609 raeburn 9983: my %displaystatus = ( previous => 'Expired',
9984: active => 'Active',
9985: future => 'Future',
9986: );
1.1121 raeburn 9987: my (%nothide,@possdoms);
1.630 raeburn 9988: if ($hidepriv) {
9989: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9990: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9991: if ($user !~ /:/) {
9992: $nothide{join(':',split(/[\@]/,$user))}=1;
9993: } else {
9994: $nothide{$user} = 1;
9995: }
9996: }
1.1121 raeburn 9997: my @possdoms = ($cdom);
9998: if ($coursehash{'checkforpriv'}) {
9999: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10000: }
1.630 raeburn 10001: }
1.439 raeburn 10002: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10003: my $match = 0;
1.412 raeburn 10004: my $secmatch = 0;
1.439 raeburn 10005: my $status;
1.412 raeburn 10006: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10007: $user =~ s/:$//;
1.439 raeburn 10008: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10009: if ($end == -1 || $start == -1) {
10010: next;
10011: }
10012: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10013: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10014: my ($uname,$udom) = split(/:/,$user);
10015: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10016: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10017: $secmatch = 1;
10018: } elsif ($usec eq '') {
1.420 albertel 10019: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10020: $secmatch = 1;
10021: }
10022: } else {
10023: if (grep(/^\Q$usec\E$/,@{$sections})) {
10024: $secmatch = 1;
10025: }
10026: }
10027: if (!$secmatch) {
10028: next;
10029: }
1.288 raeburn 10030: }
1.419 raeburn 10031: if ($usec eq '') {
10032: $usec = 'none';
10033: }
1.275 raeburn 10034: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10035: if ($hidepriv) {
1.1121 raeburn 10036: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10037: (!$nothide{$uname.':'.$udom})) {
10038: next;
10039: }
10040: }
1.503 raeburn 10041: if ($end > 0 && $end < $now) {
1.439 raeburn 10042: $status = 'previous';
10043: } elsif ($start > $now) {
10044: $status = 'future';
10045: } else {
10046: $status = 'active';
10047: }
1.277 albertel 10048: foreach my $type (keys(%{$types})) {
1.275 raeburn 10049: if ($status eq $type) {
1.420 albertel 10050: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10051: push(@{$$users{$role}{$user}},$type);
10052: }
1.288 raeburn 10053: $match = 1;
10054: }
10055: }
1.419 raeburn 10056: if (($match) && (ref($userdata) eq 'HASH')) {
10057: if (!exists($$userdata{$uname.':'.$udom})) {
10058: &get_user_info($udom,$uname,\%idx,$userdata);
10059: }
1.420 albertel 10060: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10061: push(@{$seclists{$uname.':'.$udom}},$usec);
10062: }
1.609 raeburn 10063: if (ref($statushash) eq 'HASH') {
10064: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10065: }
1.275 raeburn 10066: }
10067: }
10068: }
10069: }
1.290 albertel 10070: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10071: if ((defined($cdom)) && (defined($cnum))) {
10072: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10073: if ( defined($csettings{'internal.courseowner'}) ) {
10074: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10075: next if ($owner eq '');
10076: my ($ownername,$ownerdom);
10077: if ($owner =~ /^([^:]+):([^:]+)$/) {
10078: $ownername = $1;
10079: $ownerdom = $2;
10080: } else {
10081: $ownername = $owner;
10082: $ownerdom = $cdom;
10083: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10084: }
10085: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10086: if (defined($userdata) &&
1.609 raeburn 10087: !exists($$userdata{$owner})) {
10088: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10089: if (!grep(/^none$/,@{$seclists{$owner}})) {
10090: push(@{$seclists{$owner}},'none');
10091: }
10092: if (ref($statushash) eq 'HASH') {
10093: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10094: }
1.290 albertel 10095: }
1.279 raeburn 10096: }
10097: }
10098: }
1.419 raeburn 10099: foreach my $user (keys(%seclists)) {
10100: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10101: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10102: }
1.275 raeburn 10103: }
10104: return;
10105: }
10106:
1.288 raeburn 10107: sub get_user_info {
10108: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10109: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10110: &plainname($uname,$udom,'lastname');
1.291 albertel 10111: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10112: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10113: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10114: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10115: return;
10116: }
1.275 raeburn 10117:
1.472 raeburn 10118: ###############################################
10119:
10120: =pod
10121:
10122: =item * &get_user_quota()
10123:
1.1134 raeburn 10124: Retrieves quota assigned for storage of user files.
10125: Default is to report quota for portfolio files.
1.472 raeburn 10126:
10127: Incoming parameters:
10128: 1. user's username
10129: 2. user's domain
1.1134 raeburn 10130: 3. quota name - portfolio, author, or course
1.1136 raeburn 10131: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10132: 4. crstype - official, unofficial, textbook, placement or community,
10133: if quota name is course
1.472 raeburn 10134:
10135: Returns:
1.1163 raeburn 10136: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10137: 2. (Optional) Type of setting: custom or default
10138: (individually assigned or default for user's
10139: institutional status).
10140: 3. (Optional) - User's institutional status (e.g., faculty, staff
10141: or student - types as defined in localenroll::inst_usertypes
10142: for user's domain, which determines default quota for user.
10143: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10144:
10145: If a value has been stored in the user's environment,
1.536 raeburn 10146: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10147: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10148:
10149: =cut
10150:
10151: ###############################################
10152:
10153:
10154: sub get_user_quota {
1.1136 raeburn 10155: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10156: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10157: if (!defined($udom)) {
10158: $udom = $env{'user.domain'};
10159: }
10160: if (!defined($uname)) {
10161: $uname = $env{'user.name'};
10162: }
10163: if (($udom eq '' || $uname eq '') ||
10164: ($udom eq 'public') && ($uname eq 'public')) {
10165: $quota = 0;
1.536 raeburn 10166: $quotatype = 'default';
10167: $defquota = 0;
1.472 raeburn 10168: } else {
1.536 raeburn 10169: my $inststatus;
1.1134 raeburn 10170: if ($quotaname eq 'course') {
10171: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10172: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10173: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10174: } else {
10175: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10176: $quota = $cenv{'internal.uploadquota'};
10177: }
1.536 raeburn 10178: } else {
1.1134 raeburn 10179: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10180: if ($quotaname eq 'author') {
10181: $quota = $env{'environment.authorquota'};
10182: } else {
10183: $quota = $env{'environment.portfolioquota'};
10184: }
10185: $inststatus = $env{'environment.inststatus'};
10186: } else {
10187: my %userenv =
10188: &Apache::lonnet::get('environment',['portfolioquota',
10189: 'authorquota','inststatus'],$udom,$uname);
10190: my ($tmp) = keys(%userenv);
10191: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10192: if ($quotaname eq 'author') {
10193: $quota = $userenv{'authorquota'};
10194: } else {
10195: $quota = $userenv{'portfolioquota'};
10196: }
10197: $inststatus = $userenv{'inststatus'};
10198: } else {
10199: undef(%userenv);
10200: }
10201: }
10202: }
10203: if ($quota eq '' || wantarray) {
10204: if ($quotaname eq 'course') {
10205: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10206: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10207: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10208: ($crstype eq 'placement')) {
1.1136 raeburn 10209: $defquota = $domdefs{$crstype.'quota'};
10210: }
10211: if ($defquota eq '') {
10212: $defquota = 500;
10213: }
1.1134 raeburn 10214: } else {
10215: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10216: }
10217: if ($quota eq '') {
10218: $quota = $defquota;
10219: $quotatype = 'default';
10220: } else {
10221: $quotatype = 'custom';
10222: }
1.472 raeburn 10223: }
10224: }
1.536 raeburn 10225: if (wantarray) {
10226: return ($quota,$quotatype,$settingstatus,$defquota);
10227: } else {
10228: return $quota;
10229: }
1.472 raeburn 10230: }
10231:
10232: ###############################################
10233:
10234: =pod
10235:
10236: =item * &default_quota()
10237:
1.536 raeburn 10238: Retrieves default quota assigned for storage of user portfolio files,
10239: given an (optional) user's institutional status.
1.472 raeburn 10240:
10241: Incoming parameters:
1.1142 raeburn 10242:
1.472 raeburn 10243: 1. domain
1.536 raeburn 10244: 2. (Optional) institutional status(es). This is a : separated list of
10245: status types (e.g., faculty, staff, student etc.)
10246: which apply to the user for whom the default is being retrieved.
10247: If the institutional status string in undefined, the domain
1.1134 raeburn 10248: default quota will be returned.
10249: 3. quota name - portfolio, author, or course
10250: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10251:
10252: Returns:
1.1142 raeburn 10253:
1.1163 raeburn 10254: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10255: 2. (Optional) institutional type which determined the value of the
10256: default quota.
1.472 raeburn 10257:
10258: If a value has been stored in the domain's configuration db,
10259: it will return that, otherwise it returns 20 (for backwards
10260: compatibility with domains which have not set up a configuration
1.1163 raeburn 10261: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10262:
1.536 raeburn 10263: If the user's status includes multiple types (e.g., staff and student),
10264: the largest default quota which applies to the user determines the
10265: default quota returned.
10266:
1.472 raeburn 10267: =cut
10268:
10269: ###############################################
10270:
10271:
10272: sub default_quota {
1.1134 raeburn 10273: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10274: my ($defquota,$settingstatus);
10275: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10276: ['quotas'],$udom);
1.1134 raeburn 10277: my $key = 'defaultquota';
10278: if ($quotaname eq 'author') {
10279: $key = 'authorquota';
10280: }
1.622 raeburn 10281: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10282: if ($inststatus ne '') {
1.765 raeburn 10283: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10284: foreach my $item (@statuses) {
1.1134 raeburn 10285: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10286: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10287: if ($defquota eq '') {
1.1134 raeburn 10288: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10289: $settingstatus = $item;
1.1134 raeburn 10290: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10291: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10292: $settingstatus = $item;
10293: }
10294: }
1.1134 raeburn 10295: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10296: if ($quotahash{'quotas'}{$item} ne '') {
10297: if ($defquota eq '') {
10298: $defquota = $quotahash{'quotas'}{$item};
10299: $settingstatus = $item;
10300: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10301: $defquota = $quotahash{'quotas'}{$item};
10302: $settingstatus = $item;
10303: }
1.536 raeburn 10304: }
10305: }
10306: }
10307: }
10308: if ($defquota eq '') {
1.1134 raeburn 10309: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10310: $defquota = $quotahash{'quotas'}{$key}{'default'};
10311: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10312: $defquota = $quotahash{'quotas'}{'default'};
10313: }
1.536 raeburn 10314: $settingstatus = 'default';
1.1139 raeburn 10315: if ($defquota eq '') {
10316: if ($quotaname eq 'author') {
10317: $defquota = 500;
10318: }
10319: }
1.536 raeburn 10320: }
10321: } else {
10322: $settingstatus = 'default';
1.1134 raeburn 10323: if ($quotaname eq 'author') {
10324: $defquota = 500;
10325: } else {
10326: $defquota = 20;
10327: }
1.536 raeburn 10328: }
10329: if (wantarray) {
10330: return ($defquota,$settingstatus);
1.472 raeburn 10331: } else {
1.536 raeburn 10332: return $defquota;
1.472 raeburn 10333: }
10334: }
10335:
1.1135 raeburn 10336: ###############################################
10337:
10338: =pod
10339:
1.1136 raeburn 10340: =item * &excess_filesize_warning()
1.1135 raeburn 10341:
10342: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10343: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10344: space to be exceeded.
1.1136 raeburn 10345:
10346: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10347: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10348:
1.1165 raeburn 10349: Inputs: 7
1.1136 raeburn 10350: 1. username or coursenum
1.1135 raeburn 10351: 2. domain
1.1136 raeburn 10352: 3. context ('author' or 'course')
1.1135 raeburn 10353: 4. filename of file for which action is being requested
10354: 5. filesize (kB) of file
10355: 6. action being taken: copy or upload.
1.1237 raeburn 10356: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10357:
10358: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10359: otherwise return null.
10360:
10361: =back
1.1135 raeburn 10362:
10363: =cut
10364:
1.1136 raeburn 10365: sub excess_filesize_warning {
1.1165 raeburn 10366: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10367: my $current_disk_usage = 0;
1.1165 raeburn 10368: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10369: if ($context eq 'author') {
10370: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10371: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10372: } else {
10373: foreach my $subdir ('docs','supplemental') {
10374: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10375: }
10376: }
1.1135 raeburn 10377: $disk_quota = int($disk_quota * 1000);
10378: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10379: return '<p class="LC_warning">'.
1.1135 raeburn 10380: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10381: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10382: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10383: $disk_quota,$current_disk_usage).
10384: '</p>';
10385: }
10386: return;
10387: }
10388:
10389: ###############################################
10390:
10391:
1.1136 raeburn 10392:
10393:
1.384 raeburn 10394: sub get_secgrprole_info {
10395: my ($cdom,$cnum,$needroles,$type) = @_;
10396: my %sections_count = &get_sections($cdom,$cnum);
10397: my @sections = (sort {$a <=> $b} keys(%sections_count));
10398: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10399: my @groups = sort(keys(%curr_groups));
10400: my $allroles = [];
10401: my $rolehash;
10402: my $accesshash = {
10403: active => 'Currently has access',
10404: future => 'Will have future access',
10405: previous => 'Previously had access',
10406: };
10407: if ($needroles) {
10408: $rolehash = {'all' => 'all'};
1.385 albertel 10409: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10410: if (&Apache::lonnet::error(%user_roles)) {
10411: undef(%user_roles);
10412: }
10413: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10414: my ($role)=split(/\:/,$item,2);
10415: if ($role eq 'cr') { next; }
10416: if ($role =~ /^cr/) {
10417: $$rolehash{$role} = (split('/',$role))[3];
10418: } else {
10419: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10420: }
10421: }
10422: foreach my $key (sort(keys(%{$rolehash}))) {
10423: push(@{$allroles},$key);
10424: }
10425: push (@{$allroles},'st');
10426: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10427: }
10428: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10429: }
10430:
1.555 raeburn 10431: sub user_picker {
1.1279 raeburn 10432: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10433: my $currdom = $dom;
1.1253 raeburn 10434: my @alldoms = &Apache::lonnet::all_domains();
10435: if (@alldoms == 1) {
10436: my %domsrch = &Apache::lonnet::get_dom('configuration',
10437: ['directorysrch'],$alldoms[0]);
10438: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10439: my $showdom = $domdesc;
10440: if ($showdom eq '') {
10441: $showdom = $dom;
10442: }
10443: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10444: if ((!$domsrch{'directorysrch'}{'available'}) &&
10445: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10446: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10447: }
10448: }
10449: }
1.555 raeburn 10450: my %curr_selected = (
10451: srchin => 'dom',
1.580 raeburn 10452: srchby => 'lastname',
1.555 raeburn 10453: );
10454: my $srchterm;
1.625 raeburn 10455: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10456: if ($srch->{'srchby'} ne '') {
10457: $curr_selected{'srchby'} = $srch->{'srchby'};
10458: }
10459: if ($srch->{'srchin'} ne '') {
10460: $curr_selected{'srchin'} = $srch->{'srchin'};
10461: }
10462: if ($srch->{'srchtype'} ne '') {
10463: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10464: }
10465: if ($srch->{'srchdomain'} ne '') {
10466: $currdom = $srch->{'srchdomain'};
10467: }
10468: $srchterm = $srch->{'srchterm'};
10469: }
1.1222 damieng 10470: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10471: 'usr' => 'Search criteria',
1.563 raeburn 10472: 'doma' => 'Domain/institution to search',
1.558 albertel 10473: 'uname' => 'username',
10474: 'lastname' => 'last name',
1.555 raeburn 10475: 'lastfirst' => 'last name, first name',
1.558 albertel 10476: 'crs' => 'in this course',
1.576 raeburn 10477: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10478: 'alc' => 'all LON-CAPA',
1.573 raeburn 10479: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10480: 'exact' => 'is',
10481: 'contains' => 'contains',
1.569 raeburn 10482: 'begins' => 'begins with',
1.1222 damieng 10483: );
10484: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10485: 'youm' => "You must include some text to search for.",
10486: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10487: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10488: 'yomc' => "You must choose a domain when using an institutional directory search.",
10489: 'ymcd' => "You must choose a domain when using a domain search.",
10490: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10491: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10492: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10493: );
1.1222 damieng 10494: &html_escape(\%html_lt);
10495: &js_escape(\%js_lt);
1.1255 raeburn 10496: my $domform;
1.1277 raeburn 10497: my $allow_blank = 1;
1.1255 raeburn 10498: if ($fixeddom) {
1.1277 raeburn 10499: $allow_blank = 0;
10500: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10501: } else {
1.1287 raeburn 10502: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10503: my ($trusted,$untrusted);
1.1287 raeburn 10504: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10505: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10506: } elsif ($context eq 'author') {
1.1288 raeburn 10507: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10508: } elsif ($context eq 'domain') {
1.1288 raeburn 10509: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10510: }
1.1288 raeburn 10511: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10512: }
1.563 raeburn 10513: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10514:
10515: my @srchins = ('crs','dom','alc','instd');
10516:
10517: foreach my $option (@srchins) {
10518: # FIXME 'alc' option unavailable until
10519: # loncreateuser::print_user_query_page()
10520: # has been completed.
10521: next if ($option eq 'alc');
1.880 raeburn 10522: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10523: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10524: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10525: if ($curr_selected{'srchin'} eq $option) {
10526: $srchinsel .= '
1.1222 damieng 10527: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10528: } else {
10529: $srchinsel .= '
1.1222 damieng 10530: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10531: }
1.555 raeburn 10532: }
1.563 raeburn 10533: $srchinsel .= "\n </select>\n";
1.555 raeburn 10534:
10535: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10536: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10537: if ($curr_selected{'srchby'} eq $option) {
10538: $srchbysel .= '
1.1222 damieng 10539: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10540: } else {
10541: $srchbysel .= '
1.1222 damieng 10542: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10543: }
10544: }
10545: $srchbysel .= "\n </select>\n";
10546:
10547: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10548: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10549: if ($curr_selected{'srchtype'} eq $option) {
10550: $srchtypesel .= '
1.1222 damieng 10551: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10552: } else {
10553: $srchtypesel .= '
1.1222 damieng 10554: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10555: }
10556: }
10557: $srchtypesel .= "\n </select>\n";
10558:
1.558 albertel 10559: my ($newuserscript,$new_user_create);
1.994 raeburn 10560: my $context_dom = $env{'request.role.domain'};
10561: if ($context eq 'requestcrs') {
10562: if ($env{'form.coursedom'} ne '') {
10563: $context_dom = $env{'form.coursedom'};
10564: }
10565: }
1.556 raeburn 10566: if ($forcenewuser) {
1.576 raeburn 10567: if (ref($srch) eq 'HASH') {
1.994 raeburn 10568: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10569: if ($cancreate) {
10570: $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>';
10571: } else {
1.799 bisitz 10572: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10573: my %usertypetext = (
10574: official => 'institutional',
10575: unofficial => 'non-institutional',
10576: );
1.799 bisitz 10577: $new_user_create = '<p class="LC_warning">'
10578: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10579: .' '
10580: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10581: ,'<a href="'.$helplink.'">','</a>')
10582: .'</p><br />';
1.627 raeburn 10583: }
1.576 raeburn 10584: }
10585: }
10586:
1.556 raeburn 10587: $newuserscript = <<"ENDSCRIPT";
10588:
1.570 raeburn 10589: function setSearch(createnew,callingForm) {
1.556 raeburn 10590: if (createnew == 1) {
1.570 raeburn 10591: for (var i=0; i<callingForm.srchby.length; i++) {
10592: if (callingForm.srchby.options[i].value == 'uname') {
10593: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10594: }
10595: }
1.570 raeburn 10596: for (var i=0; i<callingForm.srchin.length; i++) {
10597: if ( callingForm.srchin.options[i].value == 'dom') {
10598: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10599: }
10600: }
1.570 raeburn 10601: for (var i=0; i<callingForm.srchtype.length; i++) {
10602: if (callingForm.srchtype.options[i].value == 'exact') {
10603: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10604: }
10605: }
1.570 raeburn 10606: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10607: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10608: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10609: }
10610: }
10611: }
10612: }
10613: ENDSCRIPT
1.558 albertel 10614:
1.556 raeburn 10615: }
10616:
1.555 raeburn 10617: my $output = <<"END_BLOCK";
1.556 raeburn 10618: <script type="text/javascript">
1.824 bisitz 10619: // <![CDATA[
1.570 raeburn 10620: function validateEntry(callingForm) {
1.558 albertel 10621:
1.556 raeburn 10622: var checkok = 1;
1.558 albertel 10623: var srchin;
1.570 raeburn 10624: for (var i=0; i<callingForm.srchin.length; i++) {
10625: if ( callingForm.srchin[i].checked ) {
10626: srchin = callingForm.srchin[i].value;
1.558 albertel 10627: }
10628: }
10629:
1.570 raeburn 10630: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10631: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10632: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10633: var srchterm = callingForm.srchterm.value;
10634: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10635: var msg = "";
10636:
10637: if (srchterm == "") {
10638: checkok = 0;
1.1222 damieng 10639: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10640: }
10641:
1.569 raeburn 10642: if (srchtype== 'begins') {
10643: if (srchterm.length < 2) {
10644: checkok = 0;
1.1222 damieng 10645: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10646: }
10647: }
10648:
1.556 raeburn 10649: if (srchtype== 'contains') {
10650: if (srchterm.length < 3) {
10651: checkok = 0;
1.1222 damieng 10652: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10653: }
10654: }
10655: if (srchin == 'instd') {
10656: if (srchdomain == '') {
10657: checkok = 0;
1.1222 damieng 10658: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10659: }
10660: }
10661: if (srchin == 'dom') {
10662: if (srchdomain == '') {
10663: checkok = 0;
1.1222 damieng 10664: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10665: }
10666: }
10667: if (srchby == 'lastfirst') {
10668: if (srchterm.indexOf(",") == -1) {
10669: checkok = 0;
1.1222 damieng 10670: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10671: }
10672: if (srchterm.indexOf(",") == srchterm.length -1) {
10673: checkok = 0;
1.1222 damieng 10674: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10675: }
10676: }
10677: if (checkok == 0) {
1.1222 damieng 10678: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10679: return;
10680: }
10681: if (checkok == 1) {
1.570 raeburn 10682: callingForm.submit();
1.556 raeburn 10683: }
10684: }
10685:
10686: $newuserscript
10687:
1.824 bisitz 10688: // ]]>
1.556 raeburn 10689: </script>
1.558 albertel 10690:
10691: $new_user_create
10692:
1.555 raeburn 10693: END_BLOCK
1.558 albertel 10694:
1.876 raeburn 10695: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10696: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10697: $domform.
10698: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10699: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10700: $srchbysel.
10701: $srchtypesel.
10702: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10703: $srchinsel.
10704: &Apache::lonhtmlcommon::row_closure(1).
10705: &Apache::lonhtmlcommon::end_pick_box().
10706: '<br />';
1.1253 raeburn 10707: return ($output,1);
1.555 raeburn 10708: }
10709:
1.612 raeburn 10710: sub user_rule_check {
1.615 raeburn 10711: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10712: my ($response,%inst_response);
1.612 raeburn 10713: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10714: if (keys(%{$usershash}) > 1) {
10715: my (%by_username,%by_id,%userdoms);
10716: my $checkid;
10717: if (ref($checks) eq 'HASH') {
10718: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10719: $checkid = 1;
10720: }
10721: }
10722: foreach my $user (keys(%{$usershash})) {
10723: my ($uname,$udom) = split(/:/,$user);
10724: if ($checkid) {
10725: if (ref($usershash->{$user}) eq 'HASH') {
10726: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10727: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10728: $userdoms{$udom} = 1;
1.1227 raeburn 10729: if (ref($inst_results) eq 'HASH') {
10730: $inst_results->{$uname.':'.$udom} = {};
10731: }
1.1226 raeburn 10732: }
10733: }
10734: } else {
10735: $by_username{$udom}{$uname} = 1;
10736: $userdoms{$udom} = 1;
1.1227 raeburn 10737: if (ref($inst_results) eq 'HASH') {
10738: $inst_results->{$uname.':'.$udom} = {};
10739: }
1.1226 raeburn 10740: }
10741: }
10742: foreach my $udom (keys(%userdoms)) {
10743: if (!$got_rules->{$udom}) {
10744: my %domconfig = &Apache::lonnet::get_dom('configuration',
10745: ['usercreation'],$udom);
10746: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10747: foreach my $item ('username','id') {
10748: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10749: $$curr_rules{$udom}{$item} =
10750: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10751: }
10752: }
10753: }
10754: $got_rules->{$udom} = 1;
10755: }
1.612 raeburn 10756: }
1.1226 raeburn 10757: if ($checkid) {
10758: foreach my $udom (keys(%by_id)) {
10759: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10760: if ($outcome eq 'ok') {
1.1227 raeburn 10761: foreach my $id (keys(%{$by_id{$udom}})) {
10762: my $uname = $by_id{$udom}{$id};
10763: $inst_response{$uname.':'.$udom} = $outcome;
10764: }
1.1226 raeburn 10765: if (ref($results) eq 'HASH') {
10766: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10767: if (exists($inst_response{$uname.':'.$udom})) {
10768: $inst_response{$uname.':'.$udom} = $outcome;
10769: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10770: }
1.1226 raeburn 10771: }
10772: }
10773: }
1.612 raeburn 10774: }
1.615 raeburn 10775: } else {
1.1226 raeburn 10776: foreach my $udom (keys(%by_username)) {
10777: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10778: if ($outcome eq 'ok') {
1.1227 raeburn 10779: foreach my $uname (keys(%{$by_username{$udom}})) {
10780: $inst_response{$uname.':'.$udom} = $outcome;
10781: }
1.1226 raeburn 10782: if (ref($results) eq 'HASH') {
10783: foreach my $uname (keys(%{$results})) {
10784: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10785: }
10786: }
10787: }
10788: }
1.612 raeburn 10789: }
1.1226 raeburn 10790: } elsif (keys(%{$usershash}) == 1) {
10791: my $user = (keys(%{$usershash}))[0];
10792: my ($uname,$udom) = split(/:/,$user);
10793: if (($udom ne '') && ($uname ne '')) {
10794: if (ref($usershash->{$user}) eq 'HASH') {
10795: if (ref($checks) eq 'HASH') {
10796: if (defined($checks->{'username'})) {
10797: ($inst_response{$user},%{$inst_results->{$user}}) =
10798: &Apache::lonnet::get_instuser($udom,$uname);
10799: } elsif (defined($checks->{'id'})) {
10800: if ($usershash->{$user}->{'id'} ne '') {
10801: ($inst_response{$user},%{$inst_results->{$user}}) =
10802: &Apache::lonnet::get_instuser($udom,undef,
10803: $usershash->{$user}->{'id'});
10804: } else {
10805: ($inst_response{$user},%{$inst_results->{$user}}) =
10806: &Apache::lonnet::get_instuser($udom,$uname);
10807: }
1.585 raeburn 10808: }
1.1226 raeburn 10809: } else {
10810: ($inst_response{$user},%{$inst_results->{$user}}) =
10811: &Apache::lonnet::get_instuser($udom,$uname);
10812: return;
10813: }
10814: if (!$got_rules->{$udom}) {
10815: my %domconfig = &Apache::lonnet::get_dom('configuration',
10816: ['usercreation'],$udom);
10817: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10818: foreach my $item ('username','id') {
10819: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10820: $$curr_rules{$udom}{$item} =
10821: $domconfig{'usercreation'}{$item.'_rule'};
10822: }
10823: }
10824: }
10825: $got_rules->{$udom} = 1;
1.585 raeburn 10826: }
10827: }
1.1226 raeburn 10828: } else {
10829: return;
10830: }
10831: } else {
10832: return;
10833: }
10834: foreach my $user (keys(%{$usershash})) {
10835: my ($uname,$udom) = split(/:/,$user);
10836: next if (($udom eq '') || ($uname eq ''));
10837: my $id;
1.1227 raeburn 10838: if (ref($inst_results) eq 'HASH') {
10839: if (ref($inst_results->{$user}) eq 'HASH') {
10840: $id = $inst_results->{$user}->{'id'};
10841: }
10842: }
10843: if ($id eq '') {
10844: if (ref($usershash->{$user})) {
10845: $id = $usershash->{$user}->{'id'};
10846: }
1.585 raeburn 10847: }
1.612 raeburn 10848: foreach my $item (keys(%{$checks})) {
10849: if (ref($$curr_rules{$udom}) eq 'HASH') {
10850: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10851: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10852: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10853: $$curr_rules{$udom}{$item});
1.612 raeburn 10854: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10855: if ($rule_check{$rule}) {
10856: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10857: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10858: if (ref($inst_results) eq 'HASH') {
10859: if (ref($inst_results->{$user}) eq 'HASH') {
10860: if (keys(%{$inst_results->{$user}}) == 0) {
10861: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10862: } elsif ($item eq 'id') {
10863: if ($inst_results->{$user}->{'id'} eq '') {
10864: $$alerts{$item}{$udom}{$uname} = 1;
10865: }
1.615 raeburn 10866: }
1.612 raeburn 10867: }
10868: }
1.615 raeburn 10869: }
10870: last;
1.585 raeburn 10871: }
10872: }
10873: }
10874: }
10875: }
10876: }
10877: }
10878: }
1.612 raeburn 10879: return;
10880: }
10881:
10882: sub user_rule_formats {
10883: my ($domain,$domdesc,$curr_rules,$check) = @_;
10884: my %text = (
10885: 'username' => 'Usernames',
10886: 'id' => 'IDs',
10887: );
10888: my $output;
10889: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10890: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10891: if (@{$ruleorder} > 0) {
1.1102 raeburn 10892: $output = '<br />'.
10893: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10894: '<span class="LC_cusr_emph">','</span>',$domdesc).
10895: ' <ul>';
1.612 raeburn 10896: foreach my $rule (@{$ruleorder}) {
10897: if (ref($curr_rules) eq 'ARRAY') {
10898: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10899: if (ref($rules->{$rule}) eq 'HASH') {
10900: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10901: $rules->{$rule}{'desc'}.'</li>';
10902: }
10903: }
10904: }
10905: }
10906: $output .= '</ul>';
10907: }
10908: }
10909: return $output;
10910: }
10911:
10912: sub instrule_disallow_msg {
1.615 raeburn 10913: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10914: my $response;
10915: my %text = (
10916: item => 'username',
10917: items => 'usernames',
10918: match => 'matches',
10919: do => 'does',
10920: action => 'a username',
10921: one => 'one',
10922: );
10923: if ($count > 1) {
10924: $text{'item'} = 'usernames';
10925: $text{'match'} ='match';
10926: $text{'do'} = 'do';
10927: $text{'action'} = 'usernames',
10928: $text{'one'} = 'ones';
10929: }
10930: if ($checkitem eq 'id') {
10931: $text{'items'} = 'IDs';
10932: $text{'item'} = 'ID';
10933: $text{'action'} = 'an ID';
1.615 raeburn 10934: if ($count > 1) {
10935: $text{'item'} = 'IDs';
10936: $text{'action'} = 'IDs';
10937: }
1.612 raeburn 10938: }
1.674 bisitz 10939: $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 10940: if ($mode eq 'upload') {
10941: if ($checkitem eq 'username') {
10942: $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'}.");
10943: } elsif ($checkitem eq 'id') {
1.674 bisitz 10944: $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 10945: }
1.669 raeburn 10946: } elsif ($mode eq 'selfcreate') {
10947: if ($checkitem eq 'id') {
10948: $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.");
10949: }
1.615 raeburn 10950: } else {
10951: if ($checkitem eq 'username') {
10952: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10953: } elsif ($checkitem eq 'id') {
10954: $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.");
10955: }
1.612 raeburn 10956: }
10957: return $response;
1.585 raeburn 10958: }
10959:
1.624 raeburn 10960: sub personal_data_fieldtitles {
10961: my %fieldtitles = &Apache::lonlocal::texthash (
10962: id => 'Student/Employee ID',
10963: permanentemail => 'E-mail address',
10964: lastname => 'Last Name',
10965: firstname => 'First Name',
10966: middlename => 'Middle Name',
10967: generation => 'Generation',
10968: gen => 'Generation',
1.765 raeburn 10969: inststatus => 'Affiliation',
1.624 raeburn 10970: );
10971: return %fieldtitles;
10972: }
10973:
1.642 raeburn 10974: sub sorted_inst_types {
10975: my ($dom) = @_;
1.1185 raeburn 10976: my ($usertypes,$order);
10977: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10978: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10979: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10980: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10981: } else {
10982: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10983: }
1.642 raeburn 10984: my $othertitle = &mt('All users');
10985: if ($env{'request.course.id'}) {
1.668 raeburn 10986: $othertitle = &mt('Any users');
1.642 raeburn 10987: }
10988: my @types;
10989: if (ref($order) eq 'ARRAY') {
10990: @types = @{$order};
10991: }
10992: if (@types == 0) {
10993: if (ref($usertypes) eq 'HASH') {
10994: @types = sort(keys(%{$usertypes}));
10995: }
10996: }
10997: if (keys(%{$usertypes}) > 0) {
10998: $othertitle = &mt('Other users');
10999: }
11000: return ($othertitle,$usertypes,\@types);
11001: }
11002:
1.645 raeburn 11003: sub get_institutional_codes {
11004: my ($settings,$allcourses,$LC_code) = @_;
11005: # Get complete list of course sections to update
11006: my @currsections = ();
11007: my @currxlists = ();
11008: my $coursecode = $$settings{'internal.coursecode'};
11009:
11010: if ($$settings{'internal.sectionnums'} ne '') {
11011: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11012: }
11013:
11014: if ($$settings{'internal.crosslistings'} ne '') {
11015: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11016: }
11017:
11018: if (@currxlists > 0) {
11019: foreach (@currxlists) {
11020: if (m/^([^:]+):(\w*)$/) {
11021: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11022: push(@{$allcourses},$1);
1.645 raeburn 11023: $$LC_code{$1} = $2;
11024: }
11025: }
11026: }
11027: }
11028:
11029: if (@currsections > 0) {
11030: foreach (@currsections) {
11031: if (m/^(\w+):(\w*)$/) {
11032: my $sec = $coursecode.$1;
11033: my $lc_sec = $2;
11034: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 11035: push(@{$allcourses},$sec);
1.645 raeburn 11036: $$LC_code{$sec} = $lc_sec;
11037: }
11038: }
11039: }
11040: }
11041: return;
11042: }
11043:
1.971 raeburn 11044: sub get_standard_codeitems {
11045: return ('Year','Semester','Department','Number','Section');
11046: }
11047:
1.112 bowersj2 11048: =pod
11049:
1.780 raeburn 11050: =head1 Slot Helpers
11051:
11052: =over 4
11053:
11054: =item * sorted_slots()
11055:
1.1040 raeburn 11056: Sorts an array of slot names in order of an optional sort key,
11057: default sort is by slot start time (earliest first).
1.780 raeburn 11058:
11059: Inputs:
11060:
11061: =over 4
11062:
11063: slotsarr - Reference to array of unsorted slot names.
11064:
11065: slots - Reference to hash of hash, where outer hash keys are slot names.
11066:
1.1040 raeburn 11067: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11068:
1.549 albertel 11069: =back
11070:
1.780 raeburn 11071: Returns:
11072:
11073: =over 4
11074:
1.1040 raeburn 11075: sorted - An array of slot names sorted by a specified sort key
11076: (default sort key is start time of the slot).
1.780 raeburn 11077:
11078: =back
11079:
11080: =cut
11081:
11082:
11083: sub sorted_slots {
1.1040 raeburn 11084: my ($slotsarr,$slots,$sortkey) = @_;
11085: if ($sortkey eq '') {
11086: $sortkey = 'starttime';
11087: }
1.780 raeburn 11088: my @sorted;
11089: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11090: @sorted =
11091: sort {
11092: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11093: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11094: }
11095: if (ref($slots->{$a})) { return -1;}
11096: if (ref($slots->{$b})) { return 1;}
11097: return 0;
11098: } @{$slotsarr};
11099: }
11100: return @sorted;
11101: }
11102:
1.1040 raeburn 11103: =pod
11104:
11105: =item * get_future_slots()
11106:
11107: Inputs:
11108:
11109: =over 4
11110:
11111: cnum - course number
11112:
11113: cdom - course domain
11114:
11115: now - current UNIX time
11116:
11117: symb - optional symb
11118:
11119: =back
11120:
11121: Returns:
11122:
11123: =over 4
11124:
11125: sorted_reservable - ref to array of student_schedulable slots currently
11126: reservable, ordered by end date of reservation period.
11127:
11128: reservable_now - ref to hash of student_schedulable slots currently
11129: reservable.
11130:
11131: Keys in inner hash are:
11132: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11133: (b) endreserve: end date of reservation period.
11134: (c) uniqueperiod: start,end dates when slot is to be uniquely
11135: selected.
1.1040 raeburn 11136:
11137: sorted_future - ref to array of student_schedulable slots reservable in
11138: the future, ordered by start date of reservation period.
11139:
11140: future_reservable - ref to hash of student_schedulable slots reservable
11141: in the future.
11142:
11143: Keys in inner hash are:
11144: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11145: (b) startreserve: start date of reservation period.
11146: (c) uniqueperiod: start,end dates when slot is to be uniquely
11147: selected.
1.1040 raeburn 11148:
11149: =back
11150:
11151: =cut
11152:
11153: sub get_future_slots {
11154: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11155: my $map;
11156: if ($symb) {
11157: ($map) = &Apache::lonnet::decode_symb($symb);
11158: }
1.1040 raeburn 11159: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11160: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11161: foreach my $slot (keys(%slots)) {
11162: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11163: if ($symb) {
1.1229 raeburn 11164: if ($slots{$slot}->{'symb'} ne '') {
11165: my $canuse;
11166: my %oksymbs;
11167: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11168: map { $oksymbs{$_} = 1; } @slotsymbs;
11169: if ($oksymbs{$symb}) {
11170: $canuse = 1;
11171: } else {
11172: foreach my $item (@slotsymbs) {
11173: if ($item =~ /\.(page|sequence)$/) {
11174: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11175: if (($map ne '') && ($map eq $sloturl)) {
11176: $canuse = 1;
11177: last;
11178: }
11179: }
11180: }
11181: }
11182: next unless ($canuse);
11183: }
1.1040 raeburn 11184: }
11185: if (($slots{$slot}->{'starttime'} > $now) &&
11186: ($slots{$slot}->{'endtime'} > $now)) {
11187: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11188: my $userallowed = 0;
11189: if ($slots{$slot}->{'allowedsections'}) {
11190: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11191: if (!defined($env{'request.role.sec'})
11192: && grep(/^No section assigned$/,@allowed_sec)) {
11193: $userallowed=1;
11194: } else {
11195: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11196: $userallowed=1;
11197: }
11198: }
11199: unless ($userallowed) {
11200: if (defined($env{'request.course.groups'})) {
11201: my @groups = split(/:/,$env{'request.course.groups'});
11202: foreach my $group (@groups) {
11203: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11204: $userallowed=1;
11205: last;
11206: }
11207: }
11208: }
11209: }
11210: }
11211: if ($slots{$slot}->{'allowedusers'}) {
11212: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11213: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11214: if (grep(/^\Q$user\E$/,@allowed_users)) {
11215: $userallowed = 1;
11216: }
11217: }
11218: next unless($userallowed);
11219: }
11220: my $startreserve = $slots{$slot}->{'startreserve'};
11221: my $endreserve = $slots{$slot}->{'endreserve'};
11222: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11223: my $uniqueperiod;
11224: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11225: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11226: }
1.1040 raeburn 11227: if (($startreserve < $now) &&
11228: (!$endreserve || $endreserve > $now)) {
11229: my $lastres = $endreserve;
11230: if (!$lastres) {
11231: $lastres = $slots{$slot}->{'starttime'};
11232: }
11233: $reservable_now{$slot} = {
11234: symb => $symb,
1.1250 raeburn 11235: endreserve => $lastres,
11236: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11237: };
11238: } elsif (($startreserve > $now) &&
11239: (!$endreserve || $endreserve > $startreserve)) {
11240: $future_reservable{$slot} = {
11241: symb => $symb,
1.1250 raeburn 11242: startreserve => $startreserve,
11243: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11244: };
11245: }
11246: }
11247: }
11248: my @unsorted_reservable = keys(%reservable_now);
11249: if (@unsorted_reservable > 0) {
11250: @sorted_reservable =
11251: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11252: }
11253: my @unsorted_future = keys(%future_reservable);
11254: if (@unsorted_future > 0) {
11255: @sorted_future =
11256: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11257: }
11258: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11259: }
1.780 raeburn 11260:
11261: =pod
11262:
1.1057 foxr 11263: =back
11264:
1.549 albertel 11265: =head1 HTTP Helpers
11266:
11267: =over 4
11268:
1.648 raeburn 11269: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11270:
1.258 albertel 11271: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11272: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11273: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11274:
11275: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11276: $possible_names is an ref to an array of form element names. As an example:
11277: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11278: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11279:
11280: =cut
1.1 albertel 11281:
1.6 albertel 11282: sub get_unprocessed_cgi {
1.25 albertel 11283: my ($query,$possible_names)= @_;
1.26 matthew 11284: # $Apache::lonxml::debug=1;
1.356 albertel 11285: foreach my $pair (split(/&/,$query)) {
11286: my ($name, $value) = split(/=/,$pair);
1.369 www 11287: $name = &unescape($name);
1.25 albertel 11288: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11289: $value =~ tr/+/ /;
11290: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11291: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11292: }
1.16 harris41 11293: }
1.6 albertel 11294: }
11295:
1.112 bowersj2 11296: =pod
11297:
1.648 raeburn 11298: =item * &cacheheader()
1.112 bowersj2 11299:
11300: returns cache-controlling header code
11301:
11302: =cut
11303:
1.7 albertel 11304: sub cacheheader {
1.258 albertel 11305: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11306: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11307: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11308: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11309: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11310: return $output;
1.7 albertel 11311: }
11312:
1.112 bowersj2 11313: =pod
11314:
1.648 raeburn 11315: =item * &no_cache($r)
1.112 bowersj2 11316:
11317: specifies header code to not have cache
11318:
11319: =cut
11320:
1.9 albertel 11321: sub no_cache {
1.216 albertel 11322: my ($r) = @_;
11323: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11324: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11325: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11326: $r->no_cache(1);
11327: $r->header_out("Expires" => $date);
11328: $r->header_out("Pragma" => "no-cache");
1.123 www 11329: }
11330:
11331: sub content_type {
1.181 albertel 11332: my ($r,$type,$charset) = @_;
1.299 foxr 11333: if ($r) {
11334: # Note that printout.pl calls this with undef for $r.
11335: &no_cache($r);
11336: }
1.258 albertel 11337: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11338: unless ($charset) {
11339: $charset=&Apache::lonlocal::current_encoding;
11340: }
11341: if ($charset) { $type.='; charset='.$charset; }
11342: if ($r) {
11343: $r->content_type($type);
11344: } else {
11345: print("Content-type: $type\n\n");
11346: }
1.9 albertel 11347: }
1.25 albertel 11348:
1.112 bowersj2 11349: =pod
11350:
1.648 raeburn 11351: =item * &add_to_env($name,$value)
1.112 bowersj2 11352:
1.258 albertel 11353: adds $name to the %env hash with value
1.112 bowersj2 11354: $value, if $name already exists, the entry is converted to an array
11355: reference and $value is added to the array.
11356:
11357: =cut
11358:
1.25 albertel 11359: sub add_to_env {
11360: my ($name,$value)=@_;
1.258 albertel 11361: if (defined($env{$name})) {
11362: if (ref($env{$name})) {
1.25 albertel 11363: #already have multiple values
1.258 albertel 11364: push(@{ $env{$name} },$value);
1.25 albertel 11365: } else {
11366: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11367: my $first=$env{$name};
11368: undef($env{$name});
11369: push(@{ $env{$name} },$first,$value);
1.25 albertel 11370: }
11371: } else {
1.258 albertel 11372: $env{$name}=$value;
1.25 albertel 11373: }
1.31 albertel 11374: }
1.149 albertel 11375:
11376: =pod
11377:
1.648 raeburn 11378: =item * &get_env_multiple($name)
1.149 albertel 11379:
1.258 albertel 11380: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11381: values may be defined and end up as an array ref.
11382:
11383: returns an array of values
11384:
11385: =cut
11386:
11387: sub get_env_multiple {
11388: my ($name) = @_;
11389: my @values;
1.258 albertel 11390: if (defined($env{$name})) {
1.149 albertel 11391: # exists is it an array
1.258 albertel 11392: if (ref($env{$name})) {
11393: @values=@{ $env{$name} };
1.149 albertel 11394: } else {
1.258 albertel 11395: $values[0]=$env{$name};
1.149 albertel 11396: }
11397: }
11398: return(@values);
11399: }
11400:
1.1249 damieng 11401: # Looks at given dependencies, and returns something depending on the context.
11402: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11403: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11404: # For all other contexts, returns ($output, $counter, $numpathchg).
11405: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11406: # $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.
11407: # $numpathchg: integer with the number of cleaned up dependency paths.
11408: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11409: # \%mapping: hash reference clean path -> original path for all dependencies.
11410: # @param {string} actionurl - The path to the handler, indicative of the context.
11411: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11412: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11413: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11414: # @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)
11415: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11416: sub ask_for_embedded_content {
1.1249 damieng 11417: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11418: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11419: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11420: %currsubfile,%unused,$rem);
1.1071 raeburn 11421: my $counter = 0;
11422: my $numnew = 0;
1.987 raeburn 11423: my $numremref = 0;
11424: my $numinvalid = 0;
11425: my $numpathchg = 0;
11426: my $numexisting = 0;
1.1071 raeburn 11427: my $numunused = 0;
11428: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11429: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11430: my $heading = &mt('Upload embedded files');
11431: my $buttontext = &mt('Upload');
11432:
1.1249 damieng 11433: # fills these variables based on the context:
11434: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11435: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11436: if ($env{'request.course.id'}) {
1.1123 raeburn 11437: if ($actionurl eq '/adm/dependencies') {
11438: $navmap = Apache::lonnavmaps::navmap->new();
11439: }
11440: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11441: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11442: }
1.1123 raeburn 11443: if (($actionurl eq '/adm/portfolio') ||
11444: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11445: my $current_path='/';
11446: if ($env{'form.currentpath'}) {
11447: $current_path = $env{'form.currentpath'};
11448: }
11449: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11450: $udom = $cdom;
11451: $uname = $cnum;
1.984 raeburn 11452: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11453: } else {
11454: $udom = $env{'user.domain'};
11455: $uname = $env{'user.name'};
11456: $url = '/userfiles/portfolio';
11457: }
1.987 raeburn 11458: $toplevel = $url.'/';
1.984 raeburn 11459: $url .= $current_path;
11460: $getpropath = 1;
1.987 raeburn 11461: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11462: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11463: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11464: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11465: $toplevel = $url;
1.984 raeburn 11466: if ($rest ne '') {
1.987 raeburn 11467: $url .= $rest;
11468: }
11469: } elsif ($actionurl eq '/adm/coursedocs') {
11470: if (ref($args) eq 'HASH') {
1.1071 raeburn 11471: $url = $args->{'docs_url'};
11472: $toplevel = $url;
1.1084 raeburn 11473: if ($args->{'context'} eq 'paste') {
11474: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11475: ($path) =
11476: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11477: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11478: $fileloc =~ s{^/}{};
11479: }
1.1071 raeburn 11480: }
1.1084 raeburn 11481: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11482: if ($env{'request.course.id'} ne '') {
11483: if (ref($args) eq 'HASH') {
11484: $url = $args->{'docs_url'};
11485: $title = $args->{'docs_title'};
1.1126 raeburn 11486: $toplevel = $url;
11487: unless ($toplevel =~ m{^/}) {
11488: $toplevel = "/$url";
11489: }
1.1085 raeburn 11490: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11491: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11492: $path = $1;
11493: } else {
11494: ($path) =
11495: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11496: }
1.1195 raeburn 11497: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11498: $fileloc = $toplevel;
11499: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11500: my ($udom,$uname,$fname) =
11501: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11502: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11503: } else {
11504: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11505: }
1.1071 raeburn 11506: $fileloc =~ s{^/}{};
11507: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11508: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11509: }
1.987 raeburn 11510: }
1.1123 raeburn 11511: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11512: $udom = $cdom;
11513: $uname = $cnum;
11514: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11515: $toplevel = $url;
11516: $path = $url;
11517: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11518: $fileloc =~ s{^/}{};
1.987 raeburn 11519: }
1.1249 damieng 11520:
11521: # parses the dependency paths to get some info
11522: # fills $newfiles, $mapping, $subdependencies, $dependencies
11523: # $newfiles: hash URL -> 1 for new files or external URLs
11524: # (will be completed later)
11525: # $mapping:
11526: # for external URLs: external URL -> external URL
11527: # for relative paths: clean path -> original path
11528: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11529: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11530: foreach my $file (keys(%{$allfiles})) {
11531: my $embed_file;
11532: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11533: $embed_file = $1;
11534: } else {
11535: $embed_file = $file;
11536: }
1.1158 raeburn 11537: my ($absolutepath,$cleaned_file);
11538: if ($embed_file =~ m{^\w+://}) {
11539: $cleaned_file = $embed_file;
1.1147 raeburn 11540: $newfiles{$cleaned_file} = 1;
11541: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11542: } else {
1.1158 raeburn 11543: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11544: if ($embed_file =~ m{^/}) {
11545: $absolutepath = $embed_file;
11546: }
1.1147 raeburn 11547: if ($cleaned_file =~ m{/}) {
11548: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11549: $path = &check_for_traversal($path,$url,$toplevel);
11550: my $item = $fname;
11551: if ($path ne '') {
11552: $item = $path.'/'.$fname;
11553: $subdependencies{$path}{$fname} = 1;
11554: } else {
11555: $dependencies{$item} = 1;
11556: }
11557: if ($absolutepath) {
11558: $mapping{$item} = $absolutepath;
11559: } else {
11560: $mapping{$item} = $embed_file;
11561: }
11562: } else {
11563: $dependencies{$embed_file} = 1;
11564: if ($absolutepath) {
1.1147 raeburn 11565: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11566: } else {
1.1147 raeburn 11567: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11568: }
11569: }
1.984 raeburn 11570: }
11571: }
1.1249 damieng 11572:
11573: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11574: # and lists
11575: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11576: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11577: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11578: # the path had to be cleaned up
11579: # $existing: hash clean path -> 1 if the file exists
11580: # $numexisting: number of keys in $existing
11581: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11582: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11583: # dependency subdirectories that are
11584: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11585: my $dirptr = 16384;
1.984 raeburn 11586: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11587: $currsubfile{$path} = {};
1.1123 raeburn 11588: if (($actionurl eq '/adm/portfolio') ||
11589: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11590: my ($sublistref,$listerror) =
11591: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11592: if (ref($sublistref) eq 'ARRAY') {
11593: foreach my $line (@{$sublistref}) {
11594: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11595: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11596: }
1.984 raeburn 11597: }
1.987 raeburn 11598: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11599: if (opendir(my $dir,$url.'/'.$path)) {
11600: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11601: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11602: }
1.1084 raeburn 11603: } elsif (($actionurl eq '/adm/dependencies') ||
11604: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11605: ($args->{'context'} eq 'paste')) ||
11606: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11607: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11608: my $dir;
11609: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11610: $dir = $fileloc;
11611: } else {
11612: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11613: }
1.1071 raeburn 11614: if ($dir ne '') {
11615: my ($sublistref,$listerror) =
11616: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11617: if (ref($sublistref) eq 'ARRAY') {
11618: foreach my $line (@{$sublistref}) {
11619: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11620: undef,$mtime)=split(/\&/,$line,12);
11621: unless (($testdir&$dirptr) ||
11622: ($file_name =~ /^\.\.?$/)) {
11623: $currsubfile{$path}{$file_name} = [$size,$mtime];
11624: }
11625: }
11626: }
11627: }
1.984 raeburn 11628: }
11629: }
11630: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11631: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11632: my $item = $path.'/'.$file;
11633: unless ($mapping{$item} eq $item) {
11634: $pathchanges{$item} = 1;
11635: }
11636: $existing{$item} = 1;
11637: $numexisting ++;
11638: } else {
11639: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11640: }
11641: }
1.1071 raeburn 11642: if ($actionurl eq '/adm/dependencies') {
11643: foreach my $path (keys(%currsubfile)) {
11644: if (ref($currsubfile{$path}) eq 'HASH') {
11645: foreach my $file (keys(%{$currsubfile{$path}})) {
11646: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11647: next if (($rem ne '') &&
11648: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11649: (ref($navmap) &&
11650: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11651: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11652: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11653: $unused{$path.'/'.$file} = 1;
11654: }
11655: }
11656: }
11657: }
11658: }
1.984 raeburn 11659: }
1.1249 damieng 11660:
11661: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11662: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11663: my %currfile;
1.1123 raeburn 11664: if (($actionurl eq '/adm/portfolio') ||
11665: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11666: my ($dirlistref,$listerror) =
11667: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11668: if (ref($dirlistref) eq 'ARRAY') {
11669: foreach my $line (@{$dirlistref}) {
11670: my ($file_name,$rest) = split(/\&/,$line,2);
11671: $currfile{$file_name} = 1;
11672: }
1.984 raeburn 11673: }
1.987 raeburn 11674: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11675: if (opendir(my $dir,$url)) {
1.987 raeburn 11676: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11677: map {$currfile{$_} = 1;} @dir_list;
11678: }
1.1084 raeburn 11679: } elsif (($actionurl eq '/adm/dependencies') ||
11680: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11681: ($args->{'context'} eq 'paste')) ||
11682: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11683: if ($env{'request.course.id'} ne '') {
11684: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11685: if ($dir ne '') {
11686: my ($dirlistref,$listerror) =
11687: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11688: if (ref($dirlistref) eq 'ARRAY') {
11689: foreach my $line (@{$dirlistref}) {
11690: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11691: $size,undef,$mtime)=split(/\&/,$line,12);
11692: unless (($testdir&$dirptr) ||
11693: ($file_name =~ /^\.\.?$/)) {
11694: $currfile{$file_name} = [$size,$mtime];
11695: }
11696: }
11697: }
11698: }
11699: }
1.984 raeburn 11700: }
1.1249 damieng 11701: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11702: # are not in subdirectories, using $currfile
1.984 raeburn 11703: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11704: if (exists($currfile{$file})) {
1.987 raeburn 11705: unless ($mapping{$file} eq $file) {
11706: $pathchanges{$file} = 1;
11707: }
11708: $existing{$file} = 1;
11709: $numexisting ++;
11710: } else {
1.984 raeburn 11711: $newfiles{$file} = 1;
11712: }
11713: }
1.1071 raeburn 11714: foreach my $file (keys(%currfile)) {
11715: unless (($file eq $filename) ||
11716: ($file eq $filename.'.bak') ||
11717: ($dependencies{$file})) {
1.1085 raeburn 11718: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11719: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11720: next if (($rem ne '') &&
11721: (($env{"httpref.$rem".$file} ne '') ||
11722: (ref($navmap) &&
11723: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11724: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11725: ($navmap->getResourceByUrl($rem.$1)))))));
11726: }
1.1085 raeburn 11727: }
1.1071 raeburn 11728: $unused{$file} = 1;
11729: }
11730: }
1.1249 damieng 11731:
11732: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11733: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11734: ($args->{'context'} eq 'paste')) {
11735: $counter = scalar(keys(%existing));
11736: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11737: return ($output,$counter,$numpathchg,\%existing);
11738: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11739: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11740: $counter = scalar(keys(%existing));
11741: $numpathchg = scalar(keys(%pathchanges));
11742: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11743: }
1.1249 damieng 11744:
11745: # returns HTML otherwise, with dependency results and to ask for more uploads
11746:
11747: # $upload_output: missing dependencies (with upload form)
11748: # $modify_output: uploaded dependencies (in use)
11749: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11750: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11751: if ($actionurl eq '/adm/dependencies') {
11752: next if ($embed_file =~ m{^\w+://});
11753: }
1.660 raeburn 11754: $upload_output .= &start_data_table_row().
1.1123 raeburn 11755: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11756: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11757: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11758: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11759: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11760: }
1.1123 raeburn 11761: $upload_output .= '</td>';
1.1071 raeburn 11762: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11763: $upload_output.='<td align="right">'.
11764: '<span class="LC_info LC_fontsize_medium">'.
11765: &mt("URL points to web address").'</span>';
1.987 raeburn 11766: $numremref++;
1.660 raeburn 11767: } elsif ($args->{'error_on_invalid_names'}
11768: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11769: $upload_output.='<td align="right"><span class="LC_warning">'.
11770: &mt('Invalid characters').'</span>';
1.987 raeburn 11771: $numinvalid++;
1.660 raeburn 11772: } else {
1.1123 raeburn 11773: $upload_output .= '<td>'.
11774: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11775: $embed_file,\%mapping,
1.1071 raeburn 11776: $allfiles,$codebase,'upload');
11777: $counter ++;
11778: $numnew ++;
1.987 raeburn 11779: }
11780: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11781: }
11782: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11783: if ($actionurl eq '/adm/dependencies') {
11784: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11785: $modify_output .= &start_data_table_row().
11786: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11787: '<img src="'.&icon($embed_file).'" border="0" />'.
11788: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11789: '<td>'.$size.'</td>'.
11790: '<td>'.$mtime.'</td>'.
11791: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11792: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11793: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11794: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11795: &embedded_file_element('upload_embedded',$counter,
11796: $embed_file,\%mapping,
11797: $allfiles,$codebase,'modify').
11798: '</div></td>'.
11799: &end_data_table_row()."\n";
11800: $counter ++;
11801: } else {
11802: $upload_output .= &start_data_table_row().
1.1123 raeburn 11803: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11804: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11805: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11806: &Apache::loncommon::end_data_table_row()."\n";
11807: }
11808: }
11809: my $delidx = $counter;
11810: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11811: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11812: $delete_output .= &start_data_table_row().
11813: '<td><img src="'.&icon($oldfile).'" />'.
11814: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11815: '<td>'.$size.'</td>'.
11816: '<td>'.$mtime.'</td>'.
11817: '<td><label><input type="checkbox" name="del_upload_dep" '.
11818: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11819: &embedded_file_element('upload_embedded',$delidx,
11820: $oldfile,\%mapping,$allfiles,
11821: $codebase,'delete').'</td>'.
11822: &end_data_table_row()."\n";
11823: $numunused ++;
11824: $delidx ++;
1.987 raeburn 11825: }
11826: if ($upload_output) {
11827: $upload_output = &start_data_table().
11828: $upload_output.
11829: &end_data_table()."\n";
11830: }
1.1071 raeburn 11831: if ($modify_output) {
11832: $modify_output = &start_data_table().
11833: &start_data_table_header_row().
11834: '<th>'.&mt('File').'</th>'.
11835: '<th>'.&mt('Size (KB)').'</th>'.
11836: '<th>'.&mt('Modified').'</th>'.
11837: '<th>'.&mt('Upload replacement?').'</th>'.
11838: &end_data_table_header_row().
11839: $modify_output.
11840: &end_data_table()."\n";
11841: }
11842: if ($delete_output) {
11843: $delete_output = &start_data_table().
11844: &start_data_table_header_row().
11845: '<th>'.&mt('File').'</th>'.
11846: '<th>'.&mt('Size (KB)').'</th>'.
11847: '<th>'.&mt('Modified').'</th>'.
11848: '<th>'.&mt('Delete?').'</th>'.
11849: &end_data_table_header_row().
11850: $delete_output.
11851: &end_data_table()."\n";
11852: }
1.987 raeburn 11853: my $applies = 0;
11854: if ($numremref) {
11855: $applies ++;
11856: }
11857: if ($numinvalid) {
11858: $applies ++;
11859: }
11860: if ($numexisting) {
11861: $applies ++;
11862: }
1.1071 raeburn 11863: if ($counter || $numunused) {
1.987 raeburn 11864: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11865: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11866: $state.'<h3>'.$heading.'</h3>';
11867: if ($actionurl eq '/adm/dependencies') {
11868: if ($numnew) {
11869: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11870: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11871: $upload_output.'<br />'."\n";
11872: }
11873: if ($numexisting) {
11874: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11875: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11876: $modify_output.'<br />'."\n";
11877: $buttontext = &mt('Save changes');
11878: }
11879: if ($numunused) {
11880: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11881: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11882: $delete_output.'<br />'."\n";
11883: $buttontext = &mt('Save changes');
11884: }
11885: } else {
11886: $output .= $upload_output.'<br />'."\n";
11887: }
11888: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11889: $counter.'" />'."\n";
11890: if ($actionurl eq '/adm/dependencies') {
11891: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11892: $numnew.'" />'."\n";
11893: } elsif ($actionurl eq '') {
1.987 raeburn 11894: $output .= '<input type="hidden" name="phase" value="three" />';
11895: }
11896: } elsif ($applies) {
11897: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11898: if ($applies > 1) {
11899: $output .=
1.1123 raeburn 11900: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11901: if ($numremref) {
11902: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11903: }
11904: if ($numinvalid) {
11905: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11906: }
11907: if ($numexisting) {
11908: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11909: }
11910: $output .= '</ul><br />';
11911: } elsif ($numremref) {
11912: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11913: } elsif ($numinvalid) {
11914: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11915: } elsif ($numexisting) {
11916: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11917: }
11918: $output .= $upload_output.'<br />';
11919: }
11920: my ($pathchange_output,$chgcount);
1.1071 raeburn 11921: $chgcount = $counter;
1.987 raeburn 11922: if (keys(%pathchanges) > 0) {
11923: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11924: if ($counter) {
1.987 raeburn 11925: $output .= &embedded_file_element('pathchange',$chgcount,
11926: $embed_file,\%mapping,
1.1071 raeburn 11927: $allfiles,$codebase,'change');
1.987 raeburn 11928: } else {
11929: $pathchange_output .=
11930: &start_data_table_row().
11931: '<td><input type ="checkbox" name="namechange" value="'.
11932: $chgcount.'" checked="checked" /></td>'.
11933: '<td>'.$mapping{$embed_file}.'</td>'.
11934: '<td>'.$embed_file.
11935: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11936: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11937: '</td>'.&end_data_table_row();
1.660 raeburn 11938: }
1.987 raeburn 11939: $numpathchg ++;
11940: $chgcount ++;
1.660 raeburn 11941: }
11942: }
1.1127 raeburn 11943: if (($counter) || ($numunused)) {
1.987 raeburn 11944: if ($numpathchg) {
11945: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11946: $numpathchg.'" />'."\n";
11947: }
11948: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11949: ($actionurl eq '/adm/imsimport')) {
11950: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11951: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11952: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11953: } elsif ($actionurl eq '/adm/dependencies') {
11954: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11955: }
1.1123 raeburn 11956: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11957: } elsif ($numpathchg) {
11958: my %pathchange = ();
11959: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11960: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11961: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11962: }
1.987 raeburn 11963: }
1.1071 raeburn 11964: return ($output,$counter,$numpathchg);
1.987 raeburn 11965: }
11966:
1.1147 raeburn 11967: =pod
11968:
11969: =item * clean_path($name)
11970:
11971: Performs clean-up of directories, subdirectories and filename in an
11972: embedded object, referenced in an HTML file which is being uploaded
11973: to a course or portfolio, where
11974: "Upload embedded images/multimedia files if HTML file" checkbox was
11975: checked.
11976:
11977: Clean-up is similar to replacements in lonnet::clean_filename()
11978: except each / between sub-directory and next level is preserved.
11979:
11980: =cut
11981:
11982: sub clean_path {
11983: my ($embed_file) = @_;
11984: $embed_file =~s{^/+}{};
11985: my @contents;
11986: if ($embed_file =~ m{/}) {
11987: @contents = split(/\//,$embed_file);
11988: } else {
11989: @contents = ($embed_file);
11990: }
11991: my $lastidx = scalar(@contents)-1;
11992: for (my $i=0; $i<=$lastidx; $i++) {
11993: $contents[$i]=~s{\\}{/}g;
11994: $contents[$i]=~s/\s+/\_/g;
11995: $contents[$i]=~s{[^/\w\.\-]}{}g;
11996: if ($i == $lastidx) {
11997: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11998: }
11999: }
12000: if ($lastidx > 0) {
12001: return join('/',@contents);
12002: } else {
12003: return $contents[0];
12004: }
12005: }
12006:
1.987 raeburn 12007: sub embedded_file_element {
1.1071 raeburn 12008: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12009: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12010: (ref($codebase) eq 'HASH'));
12011: my $output;
1.1071 raeburn 12012: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12013: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12014: }
12015: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12016: &escape($embed_file).'" />';
12017: unless (($context eq 'upload_embedded') &&
12018: ($mapping->{$embed_file} eq $embed_file)) {
12019: $output .='
12020: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12021: }
12022: my $attrib;
12023: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12024: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12025: }
12026: $output .=
12027: "\n\t\t".
12028: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12029: $attrib.'" />';
12030: if (exists($codebase->{$mapping->{$embed_file}})) {
12031: $output .=
12032: "\n\t\t".
12033: '<input name="codebase_'.$num.'" type="hidden" value="'.
12034: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12035: }
1.987 raeburn 12036: return $output;
1.660 raeburn 12037: }
12038:
1.1071 raeburn 12039: sub get_dependency_details {
12040: my ($currfile,$currsubfile,$embed_file) = @_;
12041: my ($size,$mtime,$showsize,$showmtime);
12042: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12043: if ($embed_file =~ m{/}) {
12044: my ($path,$fname) = split(/\//,$embed_file);
12045: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12046: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12047: }
12048: } else {
12049: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12050: ($size,$mtime) = @{$currfile->{$embed_file}};
12051: }
12052: }
12053: $showsize = $size/1024.0;
12054: $showsize = sprintf("%.1f",$showsize);
12055: if ($mtime > 0) {
12056: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12057: }
12058: }
12059: return ($showsize,$showmtime);
12060: }
12061:
12062: sub ask_embedded_js {
12063: return <<"END";
12064: <script type="text/javascript"">
12065: // <![CDATA[
12066: function toggleBrowse(counter) {
12067: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12068: var fileid = document.getElementById('embedded_item_'+counter);
12069: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12070: if (chkboxid.checked == true) {
12071: uploaddivid.style.display='block';
12072: } else {
12073: uploaddivid.style.display='none';
12074: fileid.value = '';
12075: }
12076: }
12077: // ]]>
12078: </script>
12079:
12080: END
12081: }
12082:
1.661 raeburn 12083: sub upload_embedded {
12084: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12085: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12086: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12087: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12088: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12089: my $orig_uploaded_filename =
12090: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12091: foreach my $type ('orig','ref','attrib','codebase') {
12092: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12093: $env{'form.embedded_'.$type.'_'.$i} =
12094: &unescape($env{'form.embedded_'.$type.'_'.$i});
12095: }
12096: }
1.661 raeburn 12097: my ($path,$fname) =
12098: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12099: # no path, whole string is fname
12100: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12101: $fname = &Apache::lonnet::clean_filename($fname);
12102: # See if there is anything left
12103: next if ($fname eq '');
12104:
12105: # Check if file already exists as a file or directory.
12106: my ($state,$msg);
12107: if ($context eq 'portfolio') {
12108: my $port_path = $dirpath;
12109: if ($group ne '') {
12110: $port_path = "groups/$group/$port_path";
12111: }
1.987 raeburn 12112: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12113: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12114: $dir_root,$port_path,$disk_quota,
12115: $current_disk_usage,$uname,$udom);
12116: if ($state eq 'will_exceed_quota'
1.984 raeburn 12117: || $state eq 'file_locked') {
1.661 raeburn 12118: $output .= $msg;
12119: next;
12120: }
12121: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12122: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12123: if ($state eq 'exists') {
12124: $output .= $msg;
12125: next;
12126: }
12127: }
12128: # Check if extension is valid
12129: if (($fname =~ /\.(\w+)$/) &&
12130: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12131: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12132: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12133: next;
12134: } elsif (($fname =~ /\.(\w+)$/) &&
12135: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12136: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12137: next;
12138: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12139: $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 12140: next;
12141: }
12142: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12143: my $subdir = $path;
12144: $subdir =~ s{/+$}{};
1.661 raeburn 12145: if ($context eq 'portfolio') {
1.984 raeburn 12146: my $result;
12147: if ($state eq 'existingfile') {
12148: $result=
12149: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12150: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12151: } else {
1.984 raeburn 12152: $result=
12153: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12154: $dirpath.
1.1123 raeburn 12155: $env{'form.currentpath'}.$subdir);
1.984 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 {
1.987 raeburn 12163: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12164: $path.$fname.'</span>').'<br />';
1.984 raeburn 12165: }
1.661 raeburn 12166: }
1.1123 raeburn 12167: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12168: my $extendedsubdir = $dirpath.'/'.$subdir;
12169: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12170: my $result =
1.1126 raeburn 12171: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12172: if ($result !~ m|^/uploaded/|) {
12173: $output .= '<span class="LC_error">'
12174: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12175: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12176: .'</span><br />';
12177: next;
12178: } else {
12179: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12180: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12181: if ($context eq 'syllabus') {
12182: &Apache::lonnet::make_public_indefinitely($result);
12183: }
1.987 raeburn 12184: }
1.661 raeburn 12185: } else {
12186: # Save the file
12187: my $target = $env{'form.embedded_item_'.$i};
12188: my $fullpath = $dir_root.$dirpath.'/'.$path;
12189: my $dest = $fullpath.$fname;
12190: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12191: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12192: my $count;
12193: my $filepath = $dir_root;
1.1027 raeburn 12194: foreach my $subdir (@parts) {
12195: $filepath .= "/$subdir";
12196: if (!-e $filepath) {
1.661 raeburn 12197: mkdir($filepath,0770);
12198: }
12199: }
12200: my $fh;
12201: if (!open($fh,'>'.$dest)) {
12202: &Apache::lonnet::logthis('Failed to create '.$dest);
12203: $output .= '<span class="LC_error">'.
1.1071 raeburn 12204: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12205: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12206: '</span><br />';
12207: } else {
12208: if (!print $fh $env{'form.embedded_item_'.$i}) {
12209: &Apache::lonnet::logthis('Failed to write to '.$dest);
12210: $output .= '<span class="LC_error">'.
1.1071 raeburn 12211: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12212: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12213: '</span><br />';
12214: } else {
1.987 raeburn 12215: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12216: $url.'</span>').'<br />';
12217: unless ($context eq 'testbank') {
12218: $footer .= &mt('View embedded file: [_1]',
12219: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12220: }
12221: }
12222: close($fh);
12223: }
12224: }
12225: if ($env{'form.embedded_ref_'.$i}) {
12226: $pathchange{$i} = 1;
12227: }
12228: }
12229: if ($output) {
12230: $output = '<p>'.$output.'</p>';
12231: }
12232: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12233: $returnflag = 'ok';
1.1071 raeburn 12234: my $numpathchgs = scalar(keys(%pathchange));
12235: if ($numpathchgs > 0) {
1.987 raeburn 12236: if ($context eq 'portfolio') {
12237: $output .= '<p>'.&mt('or').'</p>';
12238: } elsif ($context eq 'testbank') {
1.1071 raeburn 12239: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12240: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12241: $returnflag = 'modify_orightml';
12242: }
12243: }
1.1071 raeburn 12244: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12245: }
12246:
12247: sub modify_html_form {
12248: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12249: my $end = 0;
12250: my $modifyform;
12251: if ($context eq 'upload_embedded') {
12252: return unless (ref($pathchange) eq 'HASH');
12253: if ($env{'form.number_embedded_items'}) {
12254: $end += $env{'form.number_embedded_items'};
12255: }
12256: if ($env{'form.number_pathchange_items'}) {
12257: $end += $env{'form.number_pathchange_items'};
12258: }
12259: if ($end) {
12260: for (my $i=0; $i<$end; $i++) {
12261: if ($i < $env{'form.number_embedded_items'}) {
12262: next unless($pathchange->{$i});
12263: }
12264: $modifyform .=
12265: &start_data_table_row().
12266: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12267: 'checked="checked" /></td>'.
12268: '<td>'.$env{'form.embedded_ref_'.$i}.
12269: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12270: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12271: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12272: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12273: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12274: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12275: '<td>'.$env{'form.embedded_orig_'.$i}.
12276: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12277: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12278: &end_data_table_row();
1.1071 raeburn 12279: }
1.987 raeburn 12280: }
12281: } else {
12282: $modifyform = $pathchgtable;
12283: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12284: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12285: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12286: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12287: }
12288: }
12289: if ($modifyform) {
1.1071 raeburn 12290: if ($actionurl eq '/adm/dependencies') {
12291: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12292: }
1.987 raeburn 12293: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12294: '<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".
12295: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12296: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12297: '</ol></p>'."\n".'<p>'.
12298: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12299: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12300: &start_data_table()."\n".
12301: &start_data_table_header_row().
12302: '<th>'.&mt('Change?').'</th>'.
12303: '<th>'.&mt('Current reference').'</th>'.
12304: '<th>'.&mt('Required reference').'</th>'.
12305: &end_data_table_header_row()."\n".
12306: $modifyform.
12307: &end_data_table().'<br />'."\n".$hiddenstate.
12308: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12309: '</form>'."\n";
12310: }
12311: return;
12312: }
12313:
12314: sub modify_html_refs {
1.1123 raeburn 12315: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12316: my $container;
12317: if ($context eq 'portfolio') {
12318: $container = $env{'form.container'};
12319: } elsif ($context eq 'coursedoc') {
12320: $container = $env{'form.primaryurl'};
1.1071 raeburn 12321: } elsif ($context eq 'manage_dependencies') {
12322: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12323: $container = "/$container";
1.1123 raeburn 12324: } elsif ($context eq 'syllabus') {
12325: $container = $url;
1.987 raeburn 12326: } else {
1.1027 raeburn 12327: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12328: }
12329: my (%allfiles,%codebase,$output,$content);
12330: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12331: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12332: if (wantarray) {
12333: return ('',0,0);
12334: } else {
12335: return;
12336: }
12337: }
12338: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12339: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12340: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12341: if (wantarray) {
12342: return ('',0,0);
12343: } else {
12344: return;
12345: }
12346: }
1.987 raeburn 12347: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12348: if ($content eq '-1') {
12349: if (wantarray) {
12350: return ('',0,0);
12351: } else {
12352: return;
12353: }
12354: }
1.987 raeburn 12355: } else {
1.1071 raeburn 12356: unless ($container =~ /^\Q$dir_root\E/) {
12357: if (wantarray) {
12358: return ('',0,0);
12359: } else {
12360: return;
12361: }
12362: }
1.1317 raeburn 12363: if (open(my $fh,'<',$container)) {
1.987 raeburn 12364: $content = join('', <$fh>);
12365: close($fh);
12366: } else {
1.1071 raeburn 12367: if (wantarray) {
12368: return ('',0,0);
12369: } else {
12370: return;
12371: }
1.987 raeburn 12372: }
12373: }
12374: my ($count,$codebasecount) = (0,0);
12375: my $mm = new File::MMagic;
12376: my $mime_type = $mm->checktype_contents($content);
12377: if ($mime_type eq 'text/html') {
12378: my $parse_result =
12379: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12380: \%codebase,\$content);
12381: if ($parse_result eq 'ok') {
12382: foreach my $i (@changes) {
12383: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12384: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12385: if ($allfiles{$ref}) {
12386: my $newname = $orig;
12387: my ($attrib_regexp,$codebase);
1.1006 raeburn 12388: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12389: if ($attrib_regexp =~ /:/) {
12390: $attrib_regexp =~ s/\:/|/g;
12391: }
12392: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12393: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12394: $count += $numchg;
1.1123 raeburn 12395: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12396: delete($allfiles{$ref});
1.987 raeburn 12397: }
12398: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12399: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12400: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12401: $codebasecount ++;
12402: }
12403: }
12404: }
1.1123 raeburn 12405: my $skiprewrites;
1.987 raeburn 12406: if ($count || $codebasecount) {
12407: my $saveresult;
1.1071 raeburn 12408: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12409: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12410: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12411: if ($url eq $container) {
12412: my ($fname) = ($container =~ m{/([^/]+)$});
12413: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12414: $count,'<span class="LC_filename">'.
1.1071 raeburn 12415: $fname.'</span>').'</p>';
1.987 raeburn 12416: } else {
12417: $output = '<p class="LC_error">'.
12418: &mt('Error: update failed for: [_1].',
12419: '<span class="LC_filename">'.
12420: $container.'</span>').'</p>';
12421: }
1.1123 raeburn 12422: if ($context eq 'syllabus') {
12423: unless ($saveresult eq 'ok') {
12424: $skiprewrites = 1;
12425: }
12426: }
1.987 raeburn 12427: } else {
1.1317 raeburn 12428: if (open(my $fh,'>',$container)) {
1.987 raeburn 12429: print $fh $content;
12430: close($fh);
12431: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12432: $count,'<span class="LC_filename">'.
12433: $container.'</span>').'</p>';
1.661 raeburn 12434: } else {
1.987 raeburn 12435: $output = '<p class="LC_error">'.
12436: &mt('Error: could not update [_1].',
12437: '<span class="LC_filename">'.
12438: $container.'</span>').'</p>';
1.661 raeburn 12439: }
12440: }
12441: }
1.1123 raeburn 12442: if (($context eq 'syllabus') && (!$skiprewrites)) {
12443: my ($actionurl,$state);
12444: $actionurl = "/public/$udom/$uname/syllabus";
12445: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12446: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12447: \%codebase,
12448: {'context' => 'rewrites',
12449: 'ignore_remote_references' => 1,});
12450: if (ref($mapping) eq 'HASH') {
12451: my $rewrites = 0;
12452: foreach my $key (keys(%{$mapping})) {
12453: next if ($key =~ m{^https?://});
12454: my $ref = $mapping->{$key};
12455: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12456: my $attrib;
12457: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12458: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12459: }
12460: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12461: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12462: $rewrites += $numchg;
12463: }
12464: }
12465: if ($rewrites) {
12466: my $saveresult;
12467: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12468: if ($url eq $container) {
12469: my ($fname) = ($container =~ m{/([^/]+)$});
12470: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12471: $count,'<span class="LC_filename">'.
12472: $fname.'</span>').'</p>';
12473: } else {
12474: $output .= '<p class="LC_error">'.
12475: &mt('Error: could not update links in [_1].',
12476: '<span class="LC_filename">'.
12477: $container.'</span>').'</p>';
12478:
12479: }
12480: }
12481: }
12482: }
1.987 raeburn 12483: } else {
12484: &logthis('Failed to parse '.$container.
12485: ' to modify references: '.$parse_result);
1.661 raeburn 12486: }
12487: }
1.1071 raeburn 12488: if (wantarray) {
12489: return ($output,$count,$codebasecount);
12490: } else {
12491: return $output;
12492: }
1.661 raeburn 12493: }
12494:
12495: sub check_for_existing {
12496: my ($path,$fname,$element) = @_;
12497: my ($state,$msg);
12498: if (-d $path.'/'.$fname) {
12499: $state = 'exists';
12500: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12501: } elsif (-e $path.'/'.$fname) {
12502: $state = 'exists';
12503: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12504: }
12505: if ($state eq 'exists') {
12506: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12507: }
12508: return ($state,$msg);
12509: }
12510:
12511: sub check_for_upload {
12512: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12513: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12514: my $filesize = length($env{'form.'.$element});
12515: if (!$filesize) {
12516: my $msg = '<span class="LC_error">'.
12517: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12518: '<span class="LC_filename">'.$fname.'</span>',
12519: $filesize).'<br />'.
1.1007 raeburn 12520: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12521: '</span>';
12522: return ('zero_bytes',$msg);
12523: }
12524: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12525: my $getpropath = 1;
1.1021 raeburn 12526: my ($dirlistref,$listerror) =
12527: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12528: my $found_file = 0;
12529: my $locked_file = 0;
1.991 raeburn 12530: my @lockers;
12531: my $navmap;
12532: if ($env{'request.course.id'}) {
12533: $navmap = Apache::lonnavmaps::navmap->new();
12534: }
1.1021 raeburn 12535: if (ref($dirlistref) eq 'ARRAY') {
12536: foreach my $line (@{$dirlistref}) {
12537: my ($file_name,$rest)=split(/\&/,$line,2);
12538: if ($file_name eq $fname){
12539: $file_name = $path.$file_name;
12540: if ($group ne '') {
12541: $file_name = $group.$file_name;
12542: }
12543: $found_file = 1;
12544: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12545: foreach my $lock (@lockers) {
12546: if (ref($lock) eq 'ARRAY') {
12547: my ($symb,$crsid) = @{$lock};
12548: if ($crsid eq $env{'request.course.id'}) {
12549: if (ref($navmap)) {
12550: my $res = $navmap->getBySymb($symb);
12551: foreach my $part (@{$res->parts()}) {
12552: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12553: unless (($slot_status == $res->RESERVED) ||
12554: ($slot_status == $res->RESERVED_LOCATION)) {
12555: $locked_file = 1;
12556: }
1.991 raeburn 12557: }
1.1021 raeburn 12558: } else {
12559: $locked_file = 1;
1.991 raeburn 12560: }
12561: } else {
12562: $locked_file = 1;
12563: }
12564: }
1.1021 raeburn 12565: }
12566: } else {
12567: my @info = split(/\&/,$rest);
12568: my $currsize = $info[6]/1000;
12569: if ($currsize < $filesize) {
12570: my $extra = $filesize - $currsize;
12571: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12572: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12573: &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 12574: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12575: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12576: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12577: return ('will_exceed_quota',$msg);
12578: }
1.984 raeburn 12579: }
12580: }
1.661 raeburn 12581: }
12582: }
12583: }
12584: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12585: my $msg = '<p class="LC_warning">'.
12586: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12587: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12588: return ('will_exceed_quota',$msg);
12589: } elsif ($found_file) {
12590: if ($locked_file) {
1.1179 bisitz 12591: my $msg = '<p class="LC_warning">';
1.661 raeburn 12592: $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 12593: $msg .= '</p>';
1.661 raeburn 12594: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12595: return ('file_locked',$msg);
12596: } else {
1.1179 bisitz 12597: my $msg = '<p class="LC_error">';
1.984 raeburn 12598: $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 12599: $msg .= '</p>';
1.984 raeburn 12600: return ('existingfile',$msg);
1.661 raeburn 12601: }
12602: }
12603: }
12604:
1.987 raeburn 12605: sub check_for_traversal {
12606: my ($path,$url,$toplevel) = @_;
12607: my @parts=split(/\//,$path);
12608: my $cleanpath;
12609: my $fullpath = $url;
12610: for (my $i=0;$i<@parts;$i++) {
12611: next if ($parts[$i] eq '.');
12612: if ($parts[$i] eq '..') {
12613: $fullpath =~ s{([^/]+/)$}{};
12614: } else {
12615: $fullpath .= $parts[$i].'/';
12616: }
12617: }
12618: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12619: $cleanpath = $1;
12620: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12621: my $curr_toprel = $1;
12622: my @parts = split(/\//,$curr_toprel);
12623: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12624: my @urlparts = split(/\//,$url_toprel);
12625: my $doubledots;
12626: my $startdiff = -1;
12627: for (my $i=0; $i<@urlparts; $i++) {
12628: if ($startdiff == -1) {
12629: unless ($urlparts[$i] eq $parts[$i]) {
12630: $startdiff = $i;
12631: $doubledots .= '../';
12632: }
12633: } else {
12634: $doubledots .= '../';
12635: }
12636: }
12637: if ($startdiff > -1) {
12638: $cleanpath = $doubledots;
12639: for (my $i=$startdiff; $i<@parts; $i++) {
12640: $cleanpath .= $parts[$i].'/';
12641: }
12642: }
12643: }
12644: $cleanpath =~ s{(/)$}{};
12645: return $cleanpath;
12646: }
1.31 albertel 12647:
1.1053 raeburn 12648: sub is_archive_file {
12649: my ($mimetype) = @_;
12650: if (($mimetype eq 'application/octet-stream') ||
12651: ($mimetype eq 'application/x-stuffit') ||
12652: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12653: return 1;
12654: }
12655: return;
12656: }
12657:
12658: sub decompress_form {
1.1065 raeburn 12659: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12660: my %lt = &Apache::lonlocal::texthash (
12661: this => 'This file is an archive file.',
1.1067 raeburn 12662: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12663: itsc => 'Its contents are as follows:',
1.1053 raeburn 12664: youm => 'You may wish to extract its contents.',
12665: extr => 'Extract contents',
1.1067 raeburn 12666: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12667: proa => 'Process automatically?',
1.1053 raeburn 12668: yes => 'Yes',
12669: no => 'No',
1.1067 raeburn 12670: fold => 'Title for folder containing movie',
12671: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12672: );
1.1065 raeburn 12673: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12674: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12675: my $info = &list_archive_contents($fileloc,\@paths);
12676: if (@paths) {
12677: foreach my $path (@paths) {
12678: $path =~ s{^/}{};
1.1067 raeburn 12679: if ($path =~ m{^([^/]+)/$}) {
12680: $topdir = $1;
12681: }
1.1065 raeburn 12682: if ($path =~ m{^([^/]+)/}) {
12683: $toplevel{$1} = $path;
12684: } else {
12685: $toplevel{$path} = $path;
12686: }
12687: }
12688: }
1.1067 raeburn 12689: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12690: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12691: "$topdir/media/",
12692: "$topdir/media/$topdir.mp4",
12693: "$topdir/media/FirstFrame.png",
12694: "$topdir/media/player.swf",
12695: "$topdir/media/swfobject.js",
12696: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12697: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12698: "$topdir/$topdir.mp4",
12699: "$topdir/$topdir\_config.xml",
12700: "$topdir/$topdir\_controller.swf",
12701: "$topdir/$topdir\_embed.css",
12702: "$topdir/$topdir\_First_Frame.png",
12703: "$topdir/$topdir\_player.html",
12704: "$topdir/$topdir\_Thumbnails.png",
12705: "$topdir/playerProductInstall.swf",
12706: "$topdir/scripts/",
12707: "$topdir/scripts/config_xml.js",
12708: "$topdir/scripts/handlebars.js",
12709: "$topdir/scripts/jquery-1.7.1.min.js",
12710: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12711: "$topdir/scripts/modernizr.js",
12712: "$topdir/scripts/player-min.js",
12713: "$topdir/scripts/swfobject.js",
12714: "$topdir/skins/",
12715: "$topdir/skins/configuration_express.xml",
12716: "$topdir/skins/express_show/",
12717: "$topdir/skins/express_show/player-min.css",
12718: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12719: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12720: "$topdir/$topdir.mp4",
12721: "$topdir/$topdir\_config.xml",
12722: "$topdir/$topdir\_controller.swf",
12723: "$topdir/$topdir\_embed.css",
12724: "$topdir/$topdir\_First_Frame.png",
12725: "$topdir/$topdir\_player.html",
12726: "$topdir/$topdir\_Thumbnails.png",
12727: "$topdir/playerProductInstall.swf",
12728: "$topdir/scripts/",
12729: "$topdir/scripts/config_xml.js",
12730: "$topdir/scripts/techsmith-smart-player.min.js",
12731: "$topdir/skins/",
12732: "$topdir/skins/configuration_express.xml",
12733: "$topdir/skins/express_show/",
12734: "$topdir/skins/express_show/spritesheet.min.css",
12735: "$topdir/skins/express_show/spritesheet.png",
12736: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12737: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12738: if (@diffs == 0) {
1.1164 raeburn 12739: $is_camtasia = 6;
12740: } else {
1.1197 raeburn 12741: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12742: if (@diffs == 0) {
12743: $is_camtasia = 8;
1.1197 raeburn 12744: } else {
12745: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12746: if (@diffs == 0) {
12747: $is_camtasia = 8;
12748: }
1.1164 raeburn 12749: }
1.1067 raeburn 12750: }
12751: }
12752: my $output;
12753: if ($is_camtasia) {
12754: $output = <<"ENDCAM";
12755: <script type="text/javascript" language="Javascript">
12756: // <![CDATA[
12757:
12758: function camtasiaToggle() {
12759: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12760: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12761: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12762: document.getElementById('camtasia_titles').style.display='block';
12763: } else {
12764: document.getElementById('camtasia_titles').style.display='none';
12765: }
12766: }
12767: }
12768: return;
12769: }
12770:
12771: // ]]>
12772: </script>
12773: <p>$lt{'camt'}</p>
12774: ENDCAM
1.1065 raeburn 12775: } else {
1.1067 raeburn 12776: $output = '<p>'.$lt{'this'};
12777: if ($info eq '') {
12778: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12779: } else {
12780: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12781: '<div><pre>'.$info.'</pre></div>';
12782: }
1.1065 raeburn 12783: }
1.1067 raeburn 12784: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12785: my $duplicates;
12786: my $num = 0;
12787: if (ref($dirlist) eq 'ARRAY') {
12788: foreach my $item (@{$dirlist}) {
12789: if (ref($item) eq 'ARRAY') {
12790: if (exists($toplevel{$item->[0]})) {
12791: $duplicates .=
12792: &start_data_table_row().
12793: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12794: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12795: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12796: 'value="1" />'.&mt('Yes').'</label>'.
12797: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12798: '<td>'.$item->[0].'</td>';
12799: if ($item->[2]) {
12800: $duplicates .= '<td>'.&mt('Directory').'</td>';
12801: } else {
12802: $duplicates .= '<td>'.&mt('File').'</td>';
12803: }
12804: $duplicates .= '<td>'.$item->[3].'</td>'.
12805: '<td>'.
12806: &Apache::lonlocal::locallocaltime($item->[4]).
12807: '</td>'.
12808: &end_data_table_row();
12809: $num ++;
12810: }
12811: }
12812: }
12813: }
12814: my $itemcount;
12815: if (@paths > 0) {
12816: $itemcount = scalar(@paths);
12817: } else {
12818: $itemcount = 1;
12819: }
1.1067 raeburn 12820: if ($is_camtasia) {
12821: $output .= $lt{'auto'}.'<br />'.
12822: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12823: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12824: $lt{'yes'}.'</label> <label>'.
12825: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12826: $lt{'no'}.'</label></span><br />'.
12827: '<div id="camtasia_titles" style="display:block">'.
12828: &Apache::lonhtmlcommon::start_pick_box().
12829: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12830: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12831: &Apache::lonhtmlcommon::row_closure().
12832: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12833: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12834: &Apache::lonhtmlcommon::row_closure(1).
12835: &Apache::lonhtmlcommon::end_pick_box().
12836: '</div>';
12837: }
1.1065 raeburn 12838: $output .=
12839: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12840: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12841: "\n";
1.1065 raeburn 12842: if ($duplicates ne '') {
12843: $output .= '<p><span class="LC_warning">'.
12844: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12845: &start_data_table().
12846: &start_data_table_header_row().
12847: '<th>'.&mt('Overwrite?').'</th>'.
12848: '<th>'.&mt('Name').'</th>'.
12849: '<th>'.&mt('Type').'</th>'.
12850: '<th>'.&mt('Size').'</th>'.
12851: '<th>'.&mt('Last modified').'</th>'.
12852: &end_data_table_header_row().
12853: $duplicates.
12854: &end_data_table().
12855: '</p>';
12856: }
1.1067 raeburn 12857: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12858: if (ref($hiddenelements) eq 'HASH') {
12859: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12860: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12861: }
12862: }
12863: $output .= <<"END";
1.1067 raeburn 12864: <br />
1.1053 raeburn 12865: <input type="submit" name="decompress" value="$lt{'extr'}" />
12866: </form>
12867: $noextract
12868: END
12869: return $output;
12870: }
12871:
1.1065 raeburn 12872: sub decompression_utility {
12873: my ($program) = @_;
12874: my @utilities = ('tar','gunzip','bunzip2','unzip');
12875: my $location;
12876: if (grep(/^\Q$program\E$/,@utilities)) {
12877: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12878: '/usr/sbin/') {
12879: if (-x $dir.$program) {
12880: $location = $dir.$program;
12881: last;
12882: }
12883: }
12884: }
12885: return $location;
12886: }
12887:
12888: sub list_archive_contents {
12889: my ($file,$pathsref) = @_;
12890: my (@cmd,$output);
12891: my $needsregexp;
12892: if ($file =~ /\.zip$/) {
12893: @cmd = (&decompression_utility('unzip'),"-l");
12894: $needsregexp = 1;
12895: } elsif (($file =~ m/\.tar\.gz$/) ||
12896: ($file =~ /\.tgz$/)) {
12897: @cmd = (&decompression_utility('tar'),"-ztf");
12898: } elsif ($file =~ /\.tar\.bz2$/) {
12899: @cmd = (&decompression_utility('tar'),"-jtf");
12900: } elsif ($file =~ m|\.tar$|) {
12901: @cmd = (&decompression_utility('tar'),"-tf");
12902: }
12903: if (@cmd) {
12904: undef($!);
12905: undef($@);
12906: if (open(my $fh,"-|", @cmd, $file)) {
12907: while (my $line = <$fh>) {
12908: $output .= $line;
12909: chomp($line);
12910: my $item;
12911: if ($needsregexp) {
12912: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12913: } else {
12914: $item = $line;
12915: }
12916: if ($item ne '') {
12917: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12918: push(@{$pathsref},$item);
12919: }
12920: }
12921: }
12922: close($fh);
12923: }
12924: }
12925: return $output;
12926: }
12927:
1.1053 raeburn 12928: sub decompress_uploaded_file {
12929: my ($file,$dir) = @_;
12930: &Apache::lonnet::appenv({'cgi.file' => $file});
12931: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12932: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12933: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12934: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12935: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12936: my $decompressed = $env{'cgi.decompressed'};
12937: &Apache::lonnet::delenv('cgi.file');
12938: &Apache::lonnet::delenv('cgi.dir');
12939: &Apache::lonnet::delenv('cgi.decompressed');
12940: return ($decompressed,$result);
12941: }
12942:
1.1055 raeburn 12943: sub process_decompression {
12944: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12945: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12946: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12947: &mt('Unexpected file path.').'</p>'."\n";
12948: }
12949: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12950: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12951: &mt('Unexpected course context.').'</p>'."\n";
12952: }
1.1293 raeburn 12953: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12954: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12955: &mt('Filename contained unexpected characters.').'</p>'."\n";
12956: }
1.1055 raeburn 12957: my ($dir,$error,$warning,$output);
1.1180 raeburn 12958: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12959: $error = &mt('Filename not a supported archive file type.').
12960: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12961: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12962: } else {
12963: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12964: if ($docuhome eq 'no_host') {
12965: $error = &mt('Could not determine home server for course.');
12966: } else {
12967: my @ids=&Apache::lonnet::current_machine_ids();
12968: my $currdir = "$dir_root/$destination";
12969: if (grep(/^\Q$docuhome\E$/,@ids)) {
12970: $dir = &LONCAPA::propath($docudom,$docuname).
12971: "$dir_root/$destination";
12972: } else {
12973: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12974: "$dir_root/$docudom/$docuname/$destination";
12975: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12976: $error = &mt('Archive file not found.');
12977: }
12978: }
1.1065 raeburn 12979: my (@to_overwrite,@to_skip);
12980: if ($env{'form.archive_overwrite_total'} > 0) {
12981: my $total = $env{'form.archive_overwrite_total'};
12982: for (my $i=0; $i<$total; $i++) {
12983: if ($env{'form.archive_overwrite_'.$i} == 1) {
12984: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12985: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12986: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12987: }
12988: }
12989: }
12990: my $numskip = scalar(@to_skip);
1.1292 raeburn 12991: my $numoverwrite = scalar(@to_overwrite);
12992: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12993: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12994: } elsif ($dir eq '') {
1.1055 raeburn 12995: $error = &mt('Directory containing archive file unavailable.');
12996: } elsif (!$error) {
1.1065 raeburn 12997: my ($decompressed,$display);
1.1292 raeburn 12998: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12999: my $tempdir = time.'_'.$$.int(rand(10000));
13000: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13001: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13002: ($decompressed,$display) =
13003: &decompress_uploaded_file($file,"$dir/$tempdir");
13004: foreach my $item (@to_skip) {
13005: if (($item ne '') && ($item !~ /\.\./)) {
13006: if (-f "$dir/$tempdir/$item") {
13007: unlink("$dir/$tempdir/$item");
13008: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13009: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13010: }
13011: }
13012: }
13013: foreach my $item (@to_overwrite) {
13014: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13015: if (($item ne '') && ($item !~ /\.\./)) {
13016: if (-f "$dir/$item") {
13017: unlink("$dir/$item");
13018: } elsif (-d "$dir/$item") {
1.1300 raeburn 13019: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13020: }
13021: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13022: }
1.1065 raeburn 13023: }
13024: }
1.1292 raeburn 13025: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13026: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13027: }
1.1065 raeburn 13028: }
13029: } else {
13030: ($decompressed,$display) =
13031: &decompress_uploaded_file($file,$dir);
13032: }
1.1055 raeburn 13033: if ($decompressed eq 'ok') {
1.1065 raeburn 13034: $output = '<p class="LC_info">'.
13035: &mt('Files extracted successfully from archive.').
13036: '</p>'."\n";
1.1055 raeburn 13037: my ($warning,$result,@contents);
13038: my ($newdirlistref,$newlisterror) =
13039: &Apache::lonnet::dirlist($currdir,$docudom,
13040: $docuname,1);
13041: my (%is_dir,%changes,@newitems);
13042: my $dirptr = 16384;
1.1065 raeburn 13043: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13044: foreach my $dir_line (@{$newdirlistref}) {
13045: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13046: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13047: push(@newitems,$item);
13048: if ($dirptr&$testdir) {
13049: $is_dir{$item} = 1;
13050: }
13051: $changes{$item} = 1;
13052: }
13053: }
13054: }
13055: if (keys(%changes) > 0) {
13056: foreach my $item (sort(@newitems)) {
13057: if ($changes{$item}) {
13058: push(@contents,$item);
13059: }
13060: }
13061: }
13062: if (@contents > 0) {
1.1067 raeburn 13063: my $wantform;
13064: unless ($env{'form.autoextract_camtasia'}) {
13065: $wantform = 1;
13066: }
1.1056 raeburn 13067: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13068: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13069: $currdir,\%is_dir,
13070: \%children,\%parent,
1.1056 raeburn 13071: \@contents,\%dirorder,
13072: \%titles,$wantform);
1.1055 raeburn 13073: if ($datatable ne '') {
13074: $output .= &archive_options_form('decompressed',$datatable,
13075: $count,$hiddenelem);
1.1065 raeburn 13076: my $startcount = 6;
1.1055 raeburn 13077: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13078: \%titles,\%children);
1.1055 raeburn 13079: }
1.1067 raeburn 13080: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13081: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13082: my %displayed;
13083: my $total = 1;
13084: $env{'form.archive_directory'} = [];
13085: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13086: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13087: $path =~ s{/$}{};
13088: my $item;
13089: if ($path ne '') {
13090: $item = "$path/$titles{$i}";
13091: } else {
13092: $item = $titles{$i};
13093: }
13094: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13095: if ($item eq $contents[0]) {
13096: push(@{$env{'form.archive_directory'}},$i);
13097: $env{'form.archive_'.$i} = 'display';
13098: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13099: $displayed{'folder'} = $i;
1.1164 raeburn 13100: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13101: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13102: $env{'form.archive_'.$i} = 'display';
13103: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13104: $displayed{'web'} = $i;
13105: } else {
1.1164 raeburn 13106: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13107: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13108: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13109: push(@{$env{'form.archive_directory'}},$i);
13110: }
13111: $env{'form.archive_'.$i} = 'dependency';
13112: }
13113: $total ++;
13114: }
13115: for (my $i=1; $i<$total; $i++) {
13116: next if ($i == $displayed{'web'});
13117: next if ($i == $displayed{'folder'});
13118: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13119: }
13120: $env{'form.phase'} = 'decompress_cleanup';
13121: $env{'form.archivedelete'} = 1;
13122: $env{'form.archive_count'} = $total-1;
13123: $output .=
13124: &process_extracted_files('coursedocs',$docudom,
13125: $docuname,$destination,
13126: $dir_root,$hiddenelem);
13127: }
1.1055 raeburn 13128: } else {
13129: $warning = &mt('No new items extracted from archive file.');
13130: }
13131: } else {
13132: $output = $display;
13133: $error = &mt('An error occurred during extraction from the archive file.');
13134: }
13135: }
13136: }
13137: }
13138: if ($error) {
13139: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13140: $error.'</p>'."\n";
13141: }
13142: if ($warning) {
13143: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13144: }
13145: return $output;
13146: }
13147:
13148: sub get_extracted {
1.1056 raeburn 13149: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13150: $titles,$wantform) = @_;
1.1055 raeburn 13151: my $count = 0;
13152: my $depth = 0;
13153: my $datatable;
1.1056 raeburn 13154: my @hierarchy;
1.1055 raeburn 13155: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13156: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13157: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13158: foreach my $item (@{$contents}) {
13159: $count ++;
1.1056 raeburn 13160: @{$dirorder->{$count}} = @hierarchy;
13161: $titles->{$count} = $item;
1.1055 raeburn 13162: &archive_hierarchy($depth,$count,$parent,$children);
13163: if ($wantform) {
13164: $datatable .= &archive_row($is_dir->{$item},$item,
13165: $currdir,$depth,$count);
13166: }
13167: if ($is_dir->{$item}) {
13168: $depth ++;
1.1056 raeburn 13169: push(@hierarchy,$count);
13170: $parent->{$depth} = $count;
1.1055 raeburn 13171: $datatable .=
13172: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13173: \$depth,\$count,\@hierarchy,$dirorder,
13174: $children,$parent,$titles,$wantform);
1.1055 raeburn 13175: $depth --;
1.1056 raeburn 13176: pop(@hierarchy);
1.1055 raeburn 13177: }
13178: }
13179: return ($count,$datatable);
13180: }
13181:
13182: sub recurse_extracted_archive {
1.1056 raeburn 13183: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13184: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13185: my $result='';
1.1056 raeburn 13186: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13187: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13188: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13189: return $result;
13190: }
13191: my $dirptr = 16384;
13192: my ($newdirlistref,$newlisterror) =
13193: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13194: if (ref($newdirlistref) eq 'ARRAY') {
13195: foreach my $dir_line (@{$newdirlistref}) {
13196: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13197: unless ($item =~ /^\.+$/) {
13198: $$count ++;
1.1056 raeburn 13199: @{$dirorder->{$$count}} = @{$hierarchy};
13200: $titles->{$$count} = $item;
1.1055 raeburn 13201: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13202:
1.1055 raeburn 13203: my $is_dir;
13204: if ($dirptr&$testdir) {
13205: $is_dir = 1;
13206: }
13207: if ($wantform) {
13208: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13209: }
13210: if ($is_dir) {
13211: $$depth ++;
1.1056 raeburn 13212: push(@{$hierarchy},$$count);
13213: $parent->{$$depth} = $$count;
1.1055 raeburn 13214: $result .=
13215: &recurse_extracted_archive("$currdir/$item",$docudom,
13216: $docuname,$depth,$count,
1.1056 raeburn 13217: $hierarchy,$dirorder,$children,
13218: $parent,$titles,$wantform);
1.1055 raeburn 13219: $$depth --;
1.1056 raeburn 13220: pop(@{$hierarchy});
1.1055 raeburn 13221: }
13222: }
13223: }
13224: }
13225: return $result;
13226: }
13227:
13228: sub archive_hierarchy {
13229: my ($depth,$count,$parent,$children) =@_;
13230: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13231: if (exists($parent->{$depth})) {
13232: $children->{$parent->{$depth}} .= $count.':';
13233: }
13234: }
13235: return;
13236: }
13237:
13238: sub archive_row {
13239: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13240: my ($name) = ($item =~ m{([^/]+)$});
13241: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13242: 'display' => 'Add as file',
1.1055 raeburn 13243: 'dependency' => 'Include as dependency',
13244: 'discard' => 'Discard',
13245: );
13246: if ($is_dir) {
1.1059 raeburn 13247: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13248: }
1.1056 raeburn 13249: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13250: my $offset = 0;
1.1055 raeburn 13251: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13252: $offset ++;
1.1065 raeburn 13253: if ($action ne 'display') {
13254: $offset ++;
13255: }
1.1055 raeburn 13256: $output .= '<td><span class="LC_nobreak">'.
13257: '<label><input type="radio" name="archive_'.$count.
13258: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13259: my $text = $choices{$action};
13260: if ($is_dir) {
13261: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13262: if ($action eq 'display') {
1.1059 raeburn 13263: $text = &mt('Add as folder');
1.1055 raeburn 13264: }
1.1056 raeburn 13265: } else {
13266: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13267:
13268: }
13269: $output .= ' /> '.$choices{$action}.'</label></span>';
13270: if ($action eq 'dependency') {
13271: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13272: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13273: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13274: '<option value=""></option>'."\n".
13275: '</select>'."\n".
13276: '</div>';
1.1059 raeburn 13277: } elsif ($action eq 'display') {
13278: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13279: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13280: '</div>';
1.1055 raeburn 13281: }
1.1056 raeburn 13282: $output .= '</td>';
1.1055 raeburn 13283: }
13284: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13285: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13286: for (my $i=0; $i<$depth; $i++) {
13287: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13288: }
13289: if ($is_dir) {
13290: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13291: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13292: } else {
13293: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13294: }
13295: $output .= ' '.$name.'</td>'."\n".
13296: &end_data_table_row();
13297: return $output;
13298: }
13299:
13300: sub archive_options_form {
1.1065 raeburn 13301: my ($form,$display,$count,$hiddenelem) = @_;
13302: my %lt = &Apache::lonlocal::texthash(
13303: perm => 'Permanently remove archive file?',
13304: hows => 'How should each extracted item be incorporated in the course?',
13305: cont => 'Content actions for all',
13306: addf => 'Add as folder/file',
13307: incd => 'Include as dependency for a displayed file',
13308: disc => 'Discard',
13309: no => 'No',
13310: yes => 'Yes',
13311: save => 'Save',
13312: );
13313: my $output = <<"END";
13314: <form name="$form" method="post" action="">
13315: <p><span class="LC_nobreak">$lt{'perm'}
13316: <label>
13317: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13318: </label>
13319:
13320: <label>
13321: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13322: </span>
13323: </p>
13324: <input type="hidden" name="phase" value="decompress_cleanup" />
13325: <br />$lt{'hows'}
13326: <div class="LC_columnSection">
13327: <fieldset>
13328: <legend>$lt{'cont'}</legend>
13329: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13330: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13331: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13332: </fieldset>
13333: </div>
13334: END
13335: return $output.
1.1055 raeburn 13336: &start_data_table()."\n".
1.1065 raeburn 13337: $display."\n".
1.1055 raeburn 13338: &end_data_table()."\n".
13339: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13340: $hiddenelem.
1.1065 raeburn 13341: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13342: '</form>';
13343: }
13344:
13345: sub archive_javascript {
1.1056 raeburn 13346: my ($startcount,$numitems,$titles,$children) = @_;
13347: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13348: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13349: my $scripttag = <<START;
13350: <script type="text/javascript">
13351: // <![CDATA[
13352:
13353: function checkAll(form,prefix) {
13354: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13355: for (var i=0; i < form.elements.length; i++) {
13356: var id = form.elements[i].id;
13357: if ((id != '') && (id != undefined)) {
13358: if (idstr.test(id)) {
13359: if (form.elements[i].type == 'radio') {
13360: form.elements[i].checked = true;
1.1056 raeburn 13361: var nostart = i-$startcount;
1.1059 raeburn 13362: var offset = nostart%7;
13363: var count = (nostart-offset)/7;
1.1056 raeburn 13364: dependencyCheck(form,count,offset);
1.1055 raeburn 13365: }
13366: }
13367: }
13368: }
13369: }
13370:
13371: function propagateCheck(form,count) {
13372: if (count > 0) {
1.1059 raeburn 13373: var startelement = $startcount + ((count-1) * 7);
13374: for (var j=1; j<6; j++) {
13375: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13376: var item = startelement + j;
13377: if (form.elements[item].type == 'radio') {
13378: if (form.elements[item].checked) {
13379: containerCheck(form,count,j);
13380: break;
13381: }
1.1055 raeburn 13382: }
13383: }
13384: }
13385: }
13386: }
13387:
13388: numitems = $numitems
1.1056 raeburn 13389: var titles = new Array(numitems);
13390: var parents = new Array(numitems);
1.1055 raeburn 13391: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13392: parents[i] = new Array;
1.1055 raeburn 13393: }
1.1059 raeburn 13394: var maintitle = '$maintitle';
1.1055 raeburn 13395:
13396: START
13397:
1.1056 raeburn 13398: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13399: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13400: for (my $i=0; $i<@contents; $i ++) {
13401: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13402: }
13403: }
13404:
1.1056 raeburn 13405: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13406: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13407: }
13408:
1.1055 raeburn 13409: $scripttag .= <<END;
13410:
13411: function containerCheck(form,count,offset) {
13412: if (count > 0) {
1.1056 raeburn 13413: dependencyCheck(form,count,offset);
1.1059 raeburn 13414: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13415: form.elements[item].checked = true;
13416: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13417: if (parents[count].length > 0) {
13418: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13419: containerCheck(form,parents[count][j],offset);
13420: }
13421: }
13422: }
13423: }
13424: }
13425:
13426: function dependencyCheck(form,count,offset) {
13427: if (count > 0) {
1.1059 raeburn 13428: var chosen = (offset+$startcount)+7*(count-1);
13429: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13430: var currtype = form.elements[depitem].type;
13431: if (form.elements[chosen].value == 'dependency') {
13432: document.getElementById('arc_depon_'+count).style.display='block';
13433: form.elements[depitem].options.length = 0;
13434: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13435: for (var i=1; i<=numitems; i++) {
13436: if (i == count) {
13437: continue;
13438: }
1.1059 raeburn 13439: var startelement = $startcount + (i-1) * 7;
13440: for (var j=1; j<6; j++) {
13441: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13442: var item = startelement + j;
13443: if (form.elements[item].type == 'radio') {
13444: if (form.elements[item].checked) {
13445: if (form.elements[item].value == 'display') {
13446: var n = form.elements[depitem].options.length;
13447: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13448: }
13449: }
13450: }
13451: }
13452: }
13453: }
13454: } else {
13455: document.getElementById('arc_depon_'+count).style.display='none';
13456: form.elements[depitem].options.length = 0;
13457: form.elements[depitem].options[0] = new Option('Select','',true,true);
13458: }
1.1059 raeburn 13459: titleCheck(form,count,offset);
1.1056 raeburn 13460: }
13461: }
13462:
13463: function propagateSelect(form,count,offset) {
13464: if (count > 0) {
1.1065 raeburn 13465: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13466: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13467: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13468: if (parents[count].length > 0) {
13469: for (var j=0; j<parents[count].length; j++) {
13470: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13471: }
13472: }
13473: }
13474: }
13475: }
1.1056 raeburn 13476:
13477: function containerSelect(form,count,offset,picked) {
13478: if (count > 0) {
1.1065 raeburn 13479: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13480: if (form.elements[item].type == 'radio') {
13481: if (form.elements[item].value == 'dependency') {
13482: if (form.elements[item+1].type == 'select-one') {
13483: for (var i=0; i<form.elements[item+1].options.length; i++) {
13484: if (form.elements[item+1].options[i].value == picked) {
13485: form.elements[item+1].selectedIndex = i;
13486: break;
13487: }
13488: }
13489: }
13490: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13491: if (parents[count].length > 0) {
13492: for (var j=0; j<parents[count].length; j++) {
13493: containerSelect(form,parents[count][j],offset,picked);
13494: }
13495: }
13496: }
13497: }
13498: }
13499: }
13500: }
13501:
1.1059 raeburn 13502: function titleCheck(form,count,offset) {
13503: if (count > 0) {
13504: var chosen = (offset+$startcount)+7*(count-1);
13505: var depitem = $startcount + ((count-1) * 7) + 2;
13506: var currtype = form.elements[depitem].type;
13507: if (form.elements[chosen].value == 'display') {
13508: document.getElementById('arc_title_'+count).style.display='block';
13509: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13510: document.getElementById('archive_title_'+count).value=maintitle;
13511: }
13512: } else {
13513: document.getElementById('arc_title_'+count).style.display='none';
13514: if (currtype == 'text') {
13515: document.getElementById('archive_title_'+count).value='';
13516: }
13517: }
13518: }
13519: return;
13520: }
13521:
1.1055 raeburn 13522: // ]]>
13523: </script>
13524: END
13525: return $scripttag;
13526: }
13527:
13528: sub process_extracted_files {
1.1067 raeburn 13529: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13530: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13531: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13532: my @ids=&Apache::lonnet::current_machine_ids();
13533: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13534: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13535: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13536: if (grep(/^\Q$docuhome\E$/,@ids)) {
13537: $prefix = &LONCAPA::propath($docudom,$docuname);
13538: $pathtocheck = "$dir_root/$destination";
13539: $dir = $dir_root;
13540: $ishome = 1;
13541: } else {
13542: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13543: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13544: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13545: }
13546: my $currdir = "$dir_root/$destination";
13547: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13548: if ($env{'form.folderpath'}) {
13549: my @items = split('&',$env{'form.folderpath'});
13550: $folders{'0'} = $items[-2];
1.1099 raeburn 13551: if ($env{'form.folderpath'} =~ /\:1$/) {
13552: $containers{'0'}='page';
13553: } else {
13554: $containers{'0'}='sequence';
13555: }
1.1055 raeburn 13556: }
13557: my @archdirs = &get_env_multiple('form.archive_directory');
13558: if ($numitems) {
13559: for (my $i=1; $i<=$numitems; $i++) {
13560: my $path = $env{'form.archive_content_'.$i};
13561: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13562: my $item = $1;
13563: $toplevelitems{$item} = $i;
13564: if (grep(/^\Q$i\E$/,@archdirs)) {
13565: $is_dir{$item} = 1;
13566: }
13567: }
13568: }
13569: }
1.1067 raeburn 13570: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13571: if (keys(%toplevelitems) > 0) {
13572: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13573: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13574: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13575: }
1.1066 raeburn 13576: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13577: if ($numitems) {
13578: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13579: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13580: my $path = $env{'form.archive_content_'.$i};
13581: if ($path =~ /^\Q$pathtocheck\E/) {
13582: if ($env{'form.archive_'.$i} eq 'discard') {
13583: if ($prefix ne '' && $path ne '') {
13584: if (-e $prefix.$path) {
1.1066 raeburn 13585: if ((@archdirs > 0) &&
13586: (grep(/^\Q$i\E$/,@archdirs))) {
13587: $todeletedir{$prefix.$path} = 1;
13588: } else {
13589: $todelete{$prefix.$path} = 1;
13590: }
1.1055 raeburn 13591: }
13592: }
13593: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13594: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13595: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13596: $docstitle = $env{'form.archive_title_'.$i};
13597: if ($docstitle eq '') {
13598: $docstitle = $title;
13599: }
1.1055 raeburn 13600: $outer = 0;
1.1056 raeburn 13601: if (ref($dirorder{$i}) eq 'ARRAY') {
13602: if (@{$dirorder{$i}} > 0) {
13603: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13604: if ($env{'form.archive_'.$item} eq 'display') {
13605: $outer = $item;
13606: last;
13607: }
13608: }
13609: }
13610: }
13611: my ($errtext,$fatal) =
13612: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13613: '/'.$folders{$outer}.'.'.
13614: $containers{$outer});
13615: next if ($fatal);
13616: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13617: if ($context eq 'coursedocs') {
1.1056 raeburn 13618: $mapinner{$i} = time;
1.1055 raeburn 13619: $folders{$i} = 'default_'.$mapinner{$i};
13620: $containers{$i} = 'sequence';
13621: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13622: $folders{$i}.'.'.$containers{$i};
13623: my $newidx = &LONCAPA::map::getresidx();
13624: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13625: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13626: push(@LONCAPA::map::order,$newidx);
13627: my ($outtext,$errtext) =
13628: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13629: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13630: '.'.$containers{$outer},1,1);
1.1056 raeburn 13631: $newseqid{$i} = $newidx;
1.1067 raeburn 13632: unless ($errtext) {
1.1294 raeburn 13633: $result .= '<li>'.&mt('Folder: [_1] added to course',
13634: &HTML::Entities::encode($docstitle,'<>&"')).
13635: '</li>'."\n";
1.1067 raeburn 13636: }
1.1055 raeburn 13637: }
13638: } else {
13639: if ($context eq 'coursedocs') {
13640: my $newidx=&LONCAPA::map::getresidx();
13641: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13642: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13643: $title;
1.1294 raeburn 13644: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13645: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13646: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13647: }
13648: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13649: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13650: }
13651: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13652: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13653: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13654: unless ($ishome) {
13655: my $fetch = "$newdest{$i}/$title";
13656: $fetch =~ s/^\Q$prefix$dir\E//;
13657: $prompttofetch{$fetch} = 1;
13658: }
1.1292 raeburn 13659: }
1.1067 raeburn 13660: }
1.1294 raeburn 13661: $LONCAPA::map::resources[$newidx]=
13662: $docstitle.':'.$url.':false:normal:res';
13663: push(@LONCAPA::map::order, $newidx);
13664: my ($outtext,$errtext)=
13665: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13666: $docuname.'/'.$folders{$outer}.
13667: '.'.$containers{$outer},1,1);
13668: unless ($errtext) {
13669: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13670: $result .= '<li>'.&mt('File: [_1] added to course',
13671: &HTML::Entities::encode($docstitle,'<>&"')).
13672: '</li>'."\n";
13673: }
1.1067 raeburn 13674: }
1.1294 raeburn 13675: } else {
13676: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13677: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13678: }
1.1055 raeburn 13679: }
13680: }
1.1086 raeburn 13681: }
13682: } else {
1.1294 raeburn 13683: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13684: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13685: }
13686: }
13687: for (my $i=1; $i<=$numitems; $i++) {
13688: next unless ($env{'form.archive_'.$i} eq 'dependency');
13689: my $path = $env{'form.archive_content_'.$i};
13690: if ($path =~ /^\Q$pathtocheck\E/) {
13691: my ($title) = ($path =~ m{/([^/]+)$});
13692: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13693: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13694: if (ref($dirorder{$i}) eq 'ARRAY') {
13695: my ($itemidx,$fullpath,$relpath);
13696: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13697: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13698: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13699: if ($dirorder{$i}->[$j] eq $container) {
13700: $itemidx = $j;
1.1056 raeburn 13701: }
13702: }
1.1086 raeburn 13703: }
13704: if ($itemidx eq '') {
13705: $itemidx = 0;
13706: }
13707: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13708: if ($mapinner{$referrer{$i}}) {
13709: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13710: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13711: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13712: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13713: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13714: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13715: if (!-e $fullpath) {
13716: mkdir($fullpath,0755);
1.1056 raeburn 13717: }
13718: }
1.1086 raeburn 13719: } else {
13720: last;
1.1056 raeburn 13721: }
1.1086 raeburn 13722: }
13723: }
13724: } elsif ($newdest{$referrer{$i}}) {
13725: $fullpath = $newdest{$referrer{$i}};
13726: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13727: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13728: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13729: last;
13730: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13731: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13732: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13733: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13734: if (!-e $fullpath) {
13735: mkdir($fullpath,0755);
1.1056 raeburn 13736: }
13737: }
1.1086 raeburn 13738: } else {
13739: last;
1.1056 raeburn 13740: }
1.1055 raeburn 13741: }
13742: }
1.1086 raeburn 13743: if ($fullpath ne '') {
13744: if (-e "$prefix$path") {
1.1292 raeburn 13745: unless (rename("$prefix$path","$fullpath/$title")) {
13746: $warning .= &mt('Failed to rename dependency').'<br />';
13747: }
1.1086 raeburn 13748: }
13749: if (-e "$fullpath/$title") {
13750: my $showpath;
13751: if ($relpath ne '') {
13752: $showpath = "$relpath/$title";
13753: } else {
13754: $showpath = "/$title";
13755: }
1.1294 raeburn 13756: $result .= '<li>'.&mt('[_1] included as a dependency',
13757: &HTML::Entities::encode($showpath,'<>&"')).
13758: '</li>'."\n";
1.1292 raeburn 13759: unless ($ishome) {
13760: my $fetch = "$fullpath/$title";
13761: $fetch =~ s/^\Q$prefix$dir\E//;
13762: $prompttofetch{$fetch} = 1;
13763: }
1.1086 raeburn 13764: }
13765: }
1.1055 raeburn 13766: }
1.1086 raeburn 13767: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13768: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13769: &HTML::Entities::encode($path,'<>&"'),
13770: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13771: '<br />';
1.1055 raeburn 13772: }
13773: } else {
1.1294 raeburn 13774: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13775: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13776: }
13777: }
13778: if (keys(%todelete)) {
13779: foreach my $key (keys(%todelete)) {
13780: unlink($key);
1.1066 raeburn 13781: }
13782: }
13783: if (keys(%todeletedir)) {
13784: foreach my $key (keys(%todeletedir)) {
13785: rmdir($key);
13786: }
13787: }
13788: foreach my $dir (sort(keys(%is_dir))) {
13789: if (($pathtocheck ne '') && ($dir ne '')) {
13790: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13791: }
13792: }
1.1067 raeburn 13793: if ($result ne '') {
13794: $output .= '<ul>'."\n".
13795: $result."\n".
13796: '</ul>';
13797: }
13798: unless ($ishome) {
13799: my $replicationfail;
13800: foreach my $item (keys(%prompttofetch)) {
13801: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13802: unless ($fetchresult eq 'ok') {
13803: $replicationfail .= '<li>'.$item.'</li>'."\n";
13804: }
13805: }
13806: if ($replicationfail) {
13807: $output .= '<p class="LC_error">'.
13808: &mt('Course home server failed to retrieve:').'<ul>'.
13809: $replicationfail.
13810: '</ul></p>';
13811: }
13812: }
1.1055 raeburn 13813: } else {
13814: $warning = &mt('No items found in archive.');
13815: }
13816: if ($error) {
13817: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13818: $error.'</p>'."\n";
13819: }
13820: if ($warning) {
13821: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13822: }
13823: return $output;
13824: }
13825:
1.1066 raeburn 13826: sub cleanup_empty_dirs {
13827: my ($path) = @_;
13828: if (($path ne '') && (-d $path)) {
13829: if (opendir(my $dirh,$path)) {
13830: my @dircontents = grep(!/^\./,readdir($dirh));
13831: my $numitems = 0;
13832: foreach my $item (@dircontents) {
13833: if (-d "$path/$item") {
1.1111 raeburn 13834: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13835: if (-e "$path/$item") {
13836: $numitems ++;
13837: }
13838: } else {
13839: $numitems ++;
13840: }
13841: }
13842: if ($numitems == 0) {
13843: rmdir($path);
13844: }
13845: closedir($dirh);
13846: }
13847: }
13848: return;
13849: }
13850:
1.41 ng 13851: =pod
1.45 matthew 13852:
1.1162 raeburn 13853: =item * &get_folder_hierarchy()
1.1068 raeburn 13854:
13855: Provides hierarchy of names of folders/sub-folders containing the current
13856: item,
13857:
13858: Inputs: 3
13859: - $navmap - navmaps object
13860:
13861: - $map - url for map (either the trigger itself, or map containing
13862: the resource, which is the trigger).
13863:
13864: - $showitem - 1 => show title for map itself; 0 => do not show.
13865:
13866: Outputs: 1 @pathitems - array of folder/subfolder names.
13867:
13868: =cut
13869:
13870: sub get_folder_hierarchy {
13871: my ($navmap,$map,$showitem) = @_;
13872: my @pathitems;
13873: if (ref($navmap)) {
13874: my $mapres = $navmap->getResourceByUrl($map);
13875: if (ref($mapres)) {
13876: my $pcslist = $mapres->map_hierarchy();
13877: if ($pcslist ne '') {
13878: my @pcs = split(/,/,$pcslist);
13879: foreach my $pc (@pcs) {
13880: if ($pc == 1) {
1.1129 raeburn 13881: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13882: } else {
13883: my $res = $navmap->getByMapPc($pc);
13884: if (ref($res)) {
13885: my $title = $res->compTitle();
13886: $title =~ s/\W+/_/g;
13887: if ($title ne '') {
13888: push(@pathitems,$title);
13889: }
13890: }
13891: }
13892: }
13893: }
1.1071 raeburn 13894: if ($showitem) {
13895: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13896: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13897: } else {
13898: my $maptitle = $mapres->compTitle();
13899: $maptitle =~ s/\W+/_/g;
13900: if ($maptitle ne '') {
13901: push(@pathitems,$maptitle);
13902: }
1.1068 raeburn 13903: }
13904: }
13905: }
13906: }
13907: return @pathitems;
13908: }
13909:
13910: =pod
13911:
1.1015 raeburn 13912: =item * &get_turnedin_filepath()
13913:
13914: Determines path in a user's portfolio file for storage of files uploaded
13915: to a specific essayresponse or dropbox item.
13916:
13917: Inputs: 3 required + 1 optional.
13918: $symb is symb for resource, $uname and $udom are for current user (required).
13919: $caller is optional (can be "submission", if routine is called when storing
13920: an upoaded file when "Submit Answer" button was pressed).
13921:
13922: Returns array containing $path and $multiresp.
13923: $path is path in portfolio. $multiresp is 1 if this resource contains more
13924: than one file upload item. Callers of routine should append partid as a
13925: subdirectory to $path in cases where $multiresp is 1.
13926:
13927: Called by: homework/essayresponse.pm and homework/structuretags.pm
13928:
13929: =cut
13930:
13931: sub get_turnedin_filepath {
13932: my ($symb,$uname,$udom,$caller) = @_;
13933: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13934: my $turnindir;
13935: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13936: $turnindir = $userhash{'turnindir'};
13937: my ($path,$multiresp);
13938: if ($turnindir eq '') {
13939: if ($caller eq 'submission') {
13940: $turnindir = &mt('turned in');
13941: $turnindir =~ s/\W+/_/g;
13942: my %newhash = (
13943: 'turnindir' => $turnindir,
13944: );
13945: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13946: }
13947: }
13948: if ($turnindir ne '') {
13949: $path = '/'.$turnindir.'/';
13950: my ($multipart,$turnin,@pathitems);
13951: my $navmap = Apache::lonnavmaps::navmap->new();
13952: if (defined($navmap)) {
13953: my $mapres = $navmap->getResourceByUrl($map);
13954: if (ref($mapres)) {
13955: my $pcslist = $mapres->map_hierarchy();
13956: if ($pcslist ne '') {
13957: foreach my $pc (split(/,/,$pcslist)) {
13958: my $res = $navmap->getByMapPc($pc);
13959: if (ref($res)) {
13960: my $title = $res->compTitle();
13961: $title =~ s/\W+/_/g;
13962: if ($title ne '') {
1.1149 raeburn 13963: if (($pc > 1) && (length($title) > 12)) {
13964: $title = substr($title,0,12);
13965: }
1.1015 raeburn 13966: push(@pathitems,$title);
13967: }
13968: }
13969: }
13970: }
13971: my $maptitle = $mapres->compTitle();
13972: $maptitle =~ s/\W+/_/g;
13973: if ($maptitle ne '') {
1.1149 raeburn 13974: if (length($maptitle) > 12) {
13975: $maptitle = substr($maptitle,0,12);
13976: }
1.1015 raeburn 13977: push(@pathitems,$maptitle);
13978: }
13979: unless ($env{'request.state'} eq 'construct') {
13980: my $res = $navmap->getBySymb($symb);
13981: if (ref($res)) {
13982: my $partlist = $res->parts();
13983: my $totaluploads = 0;
13984: if (ref($partlist) eq 'ARRAY') {
13985: foreach my $part (@{$partlist}) {
13986: my @types = $res->responseType($part);
13987: my @ids = $res->responseIds($part);
13988: for (my $i=0; $i < scalar(@ids); $i++) {
13989: if ($types[$i] eq 'essay') {
13990: my $partid = $part.'_'.$ids[$i];
13991: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13992: $totaluploads ++;
13993: }
13994: }
13995: }
13996: }
13997: if ($totaluploads > 1) {
13998: $multiresp = 1;
13999: }
14000: }
14001: }
14002: }
14003: } else {
14004: return;
14005: }
14006: } else {
14007: return;
14008: }
14009: my $restitle=&Apache::lonnet::gettitle($symb);
14010: $restitle =~ s/\W+/_/g;
14011: if ($restitle eq '') {
14012: $restitle = ($resurl =~ m{/[^/]+$});
14013: if ($restitle eq '') {
14014: $restitle = time;
14015: }
14016: }
1.1149 raeburn 14017: if (length($restitle) > 12) {
14018: $restitle = substr($restitle,0,12);
14019: }
1.1015 raeburn 14020: push(@pathitems,$restitle);
14021: $path .= join('/',@pathitems);
14022: }
14023: return ($path,$multiresp);
14024: }
14025:
14026: =pod
14027:
1.464 albertel 14028: =back
1.41 ng 14029:
1.112 bowersj2 14030: =head1 CSV Upload/Handling functions
1.38 albertel 14031:
1.41 ng 14032: =over 4
14033:
1.648 raeburn 14034: =item * &upfile_store($r)
1.41 ng 14035:
14036: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14037: needs $env{'form.upfile'}
1.41 ng 14038: returns $datatoken to be put into hidden field
14039:
14040: =cut
1.31 albertel 14041:
14042: sub upfile_store {
14043: my $r=shift;
1.258 albertel 14044: $env{'form.upfile'}=~s/\r/\n/gs;
14045: $env{'form.upfile'}=~s/\f/\n/gs;
14046: $env{'form.upfile'}=~s/\n+/\n/gs;
14047: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14048:
1.1299 raeburn 14049: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14050: '_enroll_'.$env{'request.course.id'}.'_'.
14051: time.'_'.$$);
14052: return if ($datatoken eq '');
14053:
1.31 albertel 14054: {
1.158 raeburn 14055: my $datafile = $r->dir_config('lonDaemons').
14056: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14057: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14058: print $fh $env{'form.upfile'};
1.158 raeburn 14059: close($fh);
14060: }
1.31 albertel 14061: }
14062: return $datatoken;
14063: }
14064:
1.56 matthew 14065: =pod
14066:
1.1290 raeburn 14067: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14068:
14069: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14070: $datatoken is the name to assign to the temporary file.
1.258 albertel 14071: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14072:
14073: =cut
1.31 albertel 14074:
14075: sub load_tmp_file {
1.1290 raeburn 14076: my ($r,$datatoken) = @_;
14077: return if ($datatoken eq '');
1.31 albertel 14078: my @studentdata=();
14079: {
1.158 raeburn 14080: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14081: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14082: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14083: @studentdata=<$fh>;
14084: close($fh);
14085: }
1.31 albertel 14086: }
1.258 albertel 14087: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14088: }
14089:
1.1290 raeburn 14090: sub valid_datatoken {
14091: my ($datatoken) = @_;
1.1325 raeburn 14092: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14093: return $datatoken;
14094: }
14095: return;
14096: }
14097:
1.56 matthew 14098: =pod
14099:
1.648 raeburn 14100: =item * &upfile_record_sep()
1.41 ng 14101:
14102: Separate uploaded file into records
14103: returns array of records,
1.258 albertel 14104: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14105:
14106: =cut
1.31 albertel 14107:
14108: sub upfile_record_sep {
1.258 albertel 14109: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14110: } else {
1.248 albertel 14111: my @records;
1.258 albertel 14112: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14113: if ($line=~/^\s*$/) { next; }
14114: push(@records,$line);
14115: }
14116: return @records;
1.31 albertel 14117: }
14118: }
14119:
1.56 matthew 14120: =pod
14121:
1.648 raeburn 14122: =item * &record_sep($record)
1.41 ng 14123:
1.258 albertel 14124: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14125:
14126: =cut
14127:
1.263 www 14128: sub takeleft {
14129: my $index=shift;
14130: return substr('0000'.$index,-4,4);
14131: }
14132:
1.31 albertel 14133: sub record_sep {
14134: my $record=shift;
14135: my %components=();
1.258 albertel 14136: if ($env{'form.upfiletype'} eq 'xml') {
14137: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14138: my $i=0;
1.356 albertel 14139: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14140: $field=~s/^(\"|\')//;
14141: $field=~s/(\"|\')$//;
1.263 www 14142: $components{&takeleft($i)}=$field;
1.31 albertel 14143: $i++;
14144: }
1.258 albertel 14145: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14146: my $i=0;
1.356 albertel 14147: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14148: $field=~s/^(\"|\')//;
14149: $field=~s/(\"|\')$//;
1.263 www 14150: $components{&takeleft($i)}=$field;
1.31 albertel 14151: $i++;
14152: }
14153: } else {
1.561 www 14154: my $separator=',';
1.480 banghart 14155: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14156: $separator=';';
1.480 banghart 14157: }
1.31 albertel 14158: my $i=0;
1.561 www 14159: # the character we are looking for to indicate the end of a quote or a record
14160: my $looking_for=$separator;
14161: # do not add the characters to the fields
14162: my $ignore=0;
14163: # we just encountered a separator (or the beginning of the record)
14164: my $just_found_separator=1;
14165: # store the field we are working on here
14166: my $field='';
14167: # work our way through all characters in record
14168: foreach my $character ($record=~/(.)/g) {
14169: if ($character eq $looking_for) {
14170: if ($character ne $separator) {
14171: # Found the end of a quote, again looking for separator
14172: $looking_for=$separator;
14173: $ignore=1;
14174: } else {
14175: # Found a separator, store away what we got
14176: $components{&takeleft($i)}=$field;
14177: $i++;
14178: $just_found_separator=1;
14179: $ignore=0;
14180: $field='';
14181: }
14182: next;
14183: }
14184: # single or double quotation marks after a separator indicate beginning of a quote
14185: # we are now looking for the end of the quote and need to ignore separators
14186: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14187: $looking_for=$character;
14188: next;
14189: }
14190: # ignore would be true after we reached the end of a quote
14191: if ($ignore) { next; }
14192: if (($just_found_separator) && ($character=~/\s/)) { next; }
14193: $field.=$character;
14194: $just_found_separator=0;
1.31 albertel 14195: }
1.561 www 14196: # catch the very last entry, since we never encountered the separator
14197: $components{&takeleft($i)}=$field;
1.31 albertel 14198: }
14199: return %components;
14200: }
14201:
1.144 matthew 14202: ######################################################
14203: ######################################################
14204:
1.56 matthew 14205: =pod
14206:
1.648 raeburn 14207: =item * &upfile_select_html()
1.41 ng 14208:
1.144 matthew 14209: Return HTML code to select a file from the users machine and specify
14210: the file type.
1.41 ng 14211:
14212: =cut
14213:
1.144 matthew 14214: ######################################################
14215: ######################################################
1.31 albertel 14216: sub upfile_select_html {
1.144 matthew 14217: my %Types = (
14218: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14219: semisv => &mt('Semicolon separated values'),
1.144 matthew 14220: space => &mt('Space separated'),
14221: tab => &mt('Tabulator separated'),
14222: # xml => &mt('HTML/XML'),
14223: );
14224: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14225: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14226: foreach my $type (sort(keys(%Types))) {
14227: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14228: }
14229: $Str .= "</select>\n";
14230: return $Str;
1.31 albertel 14231: }
14232:
1.301 albertel 14233: sub get_samples {
14234: my ($records,$toget) = @_;
14235: my @samples=({});
14236: my $got=0;
14237: foreach my $rec (@$records) {
14238: my %temp = &record_sep($rec);
14239: if (! grep(/\S/, values(%temp))) { next; }
14240: if (%temp) {
14241: $samples[$got]=\%temp;
14242: $got++;
14243: if ($got == $toget) { last; }
14244: }
14245: }
14246: return \@samples;
14247: }
14248:
1.144 matthew 14249: ######################################################
14250: ######################################################
14251:
1.56 matthew 14252: =pod
14253:
1.648 raeburn 14254: =item * &csv_print_samples($r,$records)
1.41 ng 14255:
14256: Prints a table of sample values from each column uploaded $r is an
14257: Apache Request ref, $records is an arrayref from
14258: &Apache::loncommon::upfile_record_sep
14259:
14260: =cut
14261:
1.144 matthew 14262: ######################################################
14263: ######################################################
1.31 albertel 14264: sub csv_print_samples {
14265: my ($r,$records) = @_;
1.662 bisitz 14266: my $samples = &get_samples($records,5);
1.301 albertel 14267:
1.594 raeburn 14268: $r->print(&mt('Samples').'<br />'.&start_data_table().
14269: &start_data_table_header_row());
1.356 albertel 14270: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14271: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14272: $r->print(&end_data_table_header_row());
1.301 albertel 14273: foreach my $hash (@$samples) {
1.594 raeburn 14274: $r->print(&start_data_table_row());
1.356 albertel 14275: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14276: $r->print('<td>');
1.356 albertel 14277: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14278: $r->print('</td>');
14279: }
1.594 raeburn 14280: $r->print(&end_data_table_row());
1.31 albertel 14281: }
1.594 raeburn 14282: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14283: }
14284:
1.144 matthew 14285: ######################################################
14286: ######################################################
14287:
1.56 matthew 14288: =pod
14289:
1.648 raeburn 14290: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14291:
14292: Prints a table to create associations between values and table columns.
1.144 matthew 14293:
1.41 ng 14294: $r is an Apache Request ref,
14295: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14296: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14297:
14298: =cut
14299:
1.144 matthew 14300: ######################################################
14301: ######################################################
1.31 albertel 14302: sub csv_print_select_table {
14303: my ($r,$records,$d) = @_;
1.301 albertel 14304: my $i=0;
14305: my $samples = &get_samples($records,1);
1.144 matthew 14306: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14307: &start_data_table().&start_data_table_header_row().
1.144 matthew 14308: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14309: '<th>'.&mt('Column').'</th>'.
14310: &end_data_table_header_row()."\n");
1.356 albertel 14311: foreach my $array_ref (@$d) {
14312: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14313: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14314:
1.875 bisitz 14315: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14316: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14317: $r->print('<option value="none"></option>');
1.356 albertel 14318: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14319: $r->print('<option value="'.$sample.'"'.
14320: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14321: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14322: }
1.594 raeburn 14323: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14324: $i++;
14325: }
1.594 raeburn 14326: $r->print(&end_data_table());
1.31 albertel 14327: $i--;
14328: return $i;
14329: }
1.56 matthew 14330:
1.144 matthew 14331: ######################################################
14332: ######################################################
14333:
1.56 matthew 14334: =pod
1.31 albertel 14335:
1.648 raeburn 14336: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14337:
14338: Prints a table of sample values from the upload and can make associate samples to internal names.
14339:
14340: $r is an Apache Request ref,
14341: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14342: $d is an array of 2 element arrays (internal name, displayed name)
14343:
14344: =cut
14345:
1.144 matthew 14346: ######################################################
14347: ######################################################
1.31 albertel 14348: sub csv_samples_select_table {
14349: my ($r,$records,$d) = @_;
14350: my $i=0;
1.144 matthew 14351: #
1.662 bisitz 14352: my $max_samples = 5;
14353: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14354: $r->print(&start_data_table().
14355: &start_data_table_header_row().'<th>'.
14356: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14357: &end_data_table_header_row());
1.301 albertel 14358:
14359: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14360: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14361: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14362: foreach my $option (@$d) {
14363: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14364: $r->print('<option value="'.$value.'"'.
1.253 albertel 14365: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14366: $display.'</option>');
1.31 albertel 14367: }
14368: $r->print('</select></td><td>');
1.662 bisitz 14369: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14370: if (defined($samples->[$line]{$key})) {
14371: $r->print($samples->[$line]{$key}."<br />\n");
14372: }
14373: }
1.594 raeburn 14374: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14375: $i++;
14376: }
1.594 raeburn 14377: $r->print(&end_data_table());
1.31 albertel 14378: $i--;
14379: return($i);
1.115 matthew 14380: }
14381:
1.144 matthew 14382: ######################################################
14383: ######################################################
14384:
1.115 matthew 14385: =pod
14386:
1.648 raeburn 14387: =item * &clean_excel_name($name)
1.115 matthew 14388:
14389: Returns a replacement for $name which does not contain any illegal characters.
14390:
14391: =cut
14392:
1.144 matthew 14393: ######################################################
14394: ######################################################
1.115 matthew 14395: sub clean_excel_name {
14396: my ($name) = @_;
14397: $name =~ s/[:\*\?\/\\]//g;
14398: if (length($name) > 31) {
14399: $name = substr($name,0,31);
14400: }
14401: return $name;
1.25 albertel 14402: }
1.84 albertel 14403:
1.85 albertel 14404: =pod
14405:
1.648 raeburn 14406: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14407:
14408: Returns either 1 or undef
14409:
14410: 1 if the part is to be hidden, undef if it is to be shown
14411:
14412: Arguments are:
14413:
14414: $id the id of the part to be checked
14415: $symb, optional the symb of the resource to check
14416: $udom, optional the domain of the user to check for
14417: $uname, optional the username of the user to check for
14418:
14419: =cut
1.84 albertel 14420:
14421: sub check_if_partid_hidden {
14422: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14423: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14424: $symb,$udom,$uname);
1.141 albertel 14425: my $truth=1;
14426: #if the string starts with !, then the list is the list to show not hide
14427: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14428: my @hiddenlist=split(/,/,$hiddenparts);
14429: foreach my $checkid (@hiddenlist) {
1.141 albertel 14430: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14431: }
1.141 albertel 14432: return !$truth;
1.84 albertel 14433: }
1.127 matthew 14434:
1.138 matthew 14435:
14436: ############################################################
14437: ############################################################
14438:
14439: =pod
14440:
1.157 matthew 14441: =back
14442:
1.138 matthew 14443: =head1 cgi-bin script and graphing routines
14444:
1.157 matthew 14445: =over 4
14446:
1.648 raeburn 14447: =item * &get_cgi_id()
1.138 matthew 14448:
14449: Inputs: none
14450:
14451: Returns an id which can be used to pass environment variables
14452: to various cgi-bin scripts. These environment variables will
14453: be removed from the users environment after a given time by
14454: the routine &Apache::lonnet::transfer_profile_to_env.
14455:
14456: =cut
14457:
14458: ############################################################
14459: ############################################################
1.152 albertel 14460: my $uniq=0;
1.136 matthew 14461: sub get_cgi_id {
1.154 albertel 14462: $uniq=($uniq+1)%100000;
1.280 albertel 14463: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14464: }
14465:
1.127 matthew 14466: ############################################################
14467: ############################################################
14468:
14469: =pod
14470:
1.648 raeburn 14471: =item * &DrawBarGraph()
1.127 matthew 14472:
1.138 matthew 14473: Facilitates the plotting of data in a (stacked) bar graph.
14474: Puts plot definition data into the users environment in order for
14475: graph.png to plot it. Returns an <img> tag for the plot.
14476: The bars on the plot are labeled '1','2',...,'n'.
14477:
14478: Inputs:
14479:
14480: =over 4
14481:
14482: =item $Title: string, the title of the plot
14483:
14484: =item $xlabel: string, text describing the X-axis of the plot
14485:
14486: =item $ylabel: string, text describing the Y-axis of the plot
14487:
14488: =item $Max: scalar, the maximum Y value to use in the plot
14489: If $Max is < any data point, the graph will not be rendered.
14490:
1.140 matthew 14491: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14492: they are plotted. If undefined, default values will be used.
14493:
1.178 matthew 14494: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14495:
1.138 matthew 14496: =item @Values: An array of array references. Each array reference holds data
14497: to be plotted in a stacked bar chart.
14498:
1.239 matthew 14499: =item If the final element of @Values is a hash reference the key/value
14500: pairs will be added to the graph definition.
14501:
1.138 matthew 14502: =back
14503:
14504: Returns:
14505:
14506: An <img> tag which references graph.png and the appropriate identifying
14507: information for the plot.
14508:
1.127 matthew 14509: =cut
14510:
14511: ############################################################
14512: ############################################################
1.134 matthew 14513: sub DrawBarGraph {
1.178 matthew 14514: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14515: #
14516: if (! defined($colors)) {
14517: $colors = ['#33ff00',
14518: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14519: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14520: ];
14521: }
1.228 matthew 14522: my $extra_settings = {};
14523: if (ref($Values[-1]) eq 'HASH') {
14524: $extra_settings = pop(@Values);
14525: }
1.127 matthew 14526: #
1.136 matthew 14527: my $identifier = &get_cgi_id();
14528: my $id = 'cgi.'.$identifier;
1.129 matthew 14529: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14530: return '';
14531: }
1.225 matthew 14532: #
14533: my @Labels;
14534: if (defined($labels)) {
14535: @Labels = @$labels;
14536: } else {
14537: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14538: push(@Labels,$i+1);
1.225 matthew 14539: }
14540: }
14541: #
1.129 matthew 14542: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14543: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14544: my %ValuesHash;
14545: my $NumSets=1;
14546: foreach my $array (@Values) {
14547: next if (! ref($array));
1.136 matthew 14548: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14549: join(',',@$array);
1.129 matthew 14550: }
1.127 matthew 14551: #
1.136 matthew 14552: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14553: if ($NumBars < 3) {
14554: $width = 120+$NumBars*32;
1.220 matthew 14555: $xskip = 1;
1.225 matthew 14556: $bar_width = 30;
14557: } elsif ($NumBars < 5) {
14558: $width = 120+$NumBars*20;
14559: $xskip = 1;
14560: $bar_width = 20;
1.220 matthew 14561: } elsif ($NumBars < 10) {
1.136 matthew 14562: $width = 120+$NumBars*15;
14563: $xskip = 1;
14564: $bar_width = 15;
14565: } elsif ($NumBars <= 25) {
14566: $width = 120+$NumBars*11;
14567: $xskip = 5;
14568: $bar_width = 8;
14569: } elsif ($NumBars <= 50) {
14570: $width = 120+$NumBars*8;
14571: $xskip = 5;
14572: $bar_width = 4;
14573: } else {
14574: $width = 120+$NumBars*8;
14575: $xskip = 5;
14576: $bar_width = 4;
14577: }
14578: #
1.137 matthew 14579: $Max = 1 if ($Max < 1);
14580: if ( int($Max) < $Max ) {
14581: $Max++;
14582: $Max = int($Max);
14583: }
1.127 matthew 14584: $Title = '' if (! defined($Title));
14585: $xlabel = '' if (! defined($xlabel));
14586: $ylabel = '' if (! defined($ylabel));
1.369 www 14587: $ValuesHash{$id.'.title'} = &escape($Title);
14588: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14589: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14590: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14591: $ValuesHash{$id.'.NumBars'} = $NumBars;
14592: $ValuesHash{$id.'.NumSets'} = $NumSets;
14593: $ValuesHash{$id.'.PlotType'} = 'bar';
14594: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14595: $ValuesHash{$id.'.height'} = $height;
14596: $ValuesHash{$id.'.width'} = $width;
14597: $ValuesHash{$id.'.xskip'} = $xskip;
14598: $ValuesHash{$id.'.bar_width'} = $bar_width;
14599: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14600: #
1.228 matthew 14601: # Deal with other parameters
14602: while (my ($key,$value) = each(%$extra_settings)) {
14603: $ValuesHash{$id.'.'.$key} = $value;
14604: }
14605: #
1.646 raeburn 14606: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14607: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14608: }
14609:
14610: ############################################################
14611: ############################################################
14612:
14613: =pod
14614:
1.648 raeburn 14615: =item * &DrawXYGraph()
1.137 matthew 14616:
1.138 matthew 14617: Facilitates the plotting of data in an XY graph.
14618: Puts plot definition data into the users environment in order for
14619: graph.png to plot it. Returns an <img> tag for the plot.
14620:
14621: Inputs:
14622:
14623: =over 4
14624:
14625: =item $Title: string, the title of the plot
14626:
14627: =item $xlabel: string, text describing the X-axis of the plot
14628:
14629: =item $ylabel: string, text describing the Y-axis of the plot
14630:
14631: =item $Max: scalar, the maximum Y value to use in the plot
14632: If $Max is < any data point, the graph will not be rendered.
14633:
14634: =item $colors: Array ref containing the hex color codes for the data to be
14635: plotted in. If undefined, default values will be used.
14636:
14637: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14638:
14639: =item $Ydata: Array ref containing Array refs.
1.185 www 14640: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14641:
14642: =item %Values: hash indicating or overriding any default values which are
14643: passed to graph.png.
14644: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14645:
14646: =back
14647:
14648: Returns:
14649:
14650: An <img> tag which references graph.png and the appropriate identifying
14651: information for the plot.
14652:
1.137 matthew 14653: =cut
14654:
14655: ############################################################
14656: ############################################################
14657: sub DrawXYGraph {
14658: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14659: #
14660: # Create the identifier for the graph
14661: my $identifier = &get_cgi_id();
14662: my $id = 'cgi.'.$identifier;
14663: #
14664: $Title = '' if (! defined($Title));
14665: $xlabel = '' if (! defined($xlabel));
14666: $ylabel = '' if (! defined($ylabel));
14667: my %ValuesHash =
14668: (
1.369 www 14669: $id.'.title' => &escape($Title),
14670: $id.'.xlabel' => &escape($xlabel),
14671: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14672: $id.'.y_max_value'=> $Max,
14673: $id.'.labels' => join(',',@$Xlabels),
14674: $id.'.PlotType' => 'XY',
14675: );
14676: #
14677: if (defined($colors) && ref($colors) eq 'ARRAY') {
14678: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14679: }
14680: #
14681: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14682: return '';
14683: }
14684: my $NumSets=1;
1.138 matthew 14685: foreach my $array (@{$Ydata}){
1.137 matthew 14686: next if (! ref($array));
14687: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14688: }
1.138 matthew 14689: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14690: #
14691: # Deal with other parameters
14692: while (my ($key,$value) = each(%Values)) {
14693: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14694: }
14695: #
1.646 raeburn 14696: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14697: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14698: }
14699:
14700: ############################################################
14701: ############################################################
14702:
14703: =pod
14704:
1.648 raeburn 14705: =item * &DrawXYYGraph()
1.138 matthew 14706:
14707: Facilitates the plotting of data in an XY graph with two Y axes.
14708: Puts plot definition data into the users environment in order for
14709: graph.png to plot it. Returns an <img> tag for the plot.
14710:
14711: Inputs:
14712:
14713: =over 4
14714:
14715: =item $Title: string, the title of the plot
14716:
14717: =item $xlabel: string, text describing the X-axis of the plot
14718:
14719: =item $ylabel: string, text describing the Y-axis of the plot
14720:
14721: =item $colors: Array ref containing the hex color codes for the data to be
14722: plotted in. If undefined, default values will be used.
14723:
14724: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14725:
14726: =item $Ydata1: The first data set
14727:
14728: =item $Min1: The minimum value of the left Y-axis
14729:
14730: =item $Max1: The maximum value of the left Y-axis
14731:
14732: =item $Ydata2: The second data set
14733:
14734: =item $Min2: The minimum value of the right Y-axis
14735:
14736: =item $Max2: The maximum value of the left Y-axis
14737:
14738: =item %Values: hash indicating or overriding any default values which are
14739: passed to graph.png.
14740: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14741:
14742: =back
14743:
14744: Returns:
14745:
14746: An <img> tag which references graph.png and the appropriate identifying
14747: information for the plot.
1.136 matthew 14748:
14749: =cut
14750:
14751: ############################################################
14752: ############################################################
1.137 matthew 14753: sub DrawXYYGraph {
14754: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14755: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14756: #
14757: # Create the identifier for the graph
14758: my $identifier = &get_cgi_id();
14759: my $id = 'cgi.'.$identifier;
14760: #
14761: $Title = '' if (! defined($Title));
14762: $xlabel = '' if (! defined($xlabel));
14763: $ylabel = '' if (! defined($ylabel));
14764: my %ValuesHash =
14765: (
1.369 www 14766: $id.'.title' => &escape($Title),
14767: $id.'.xlabel' => &escape($xlabel),
14768: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14769: $id.'.labels' => join(',',@$Xlabels),
14770: $id.'.PlotType' => 'XY',
14771: $id.'.NumSets' => 2,
1.137 matthew 14772: $id.'.two_axes' => 1,
14773: $id.'.y1_max_value' => $Max1,
14774: $id.'.y1_min_value' => $Min1,
14775: $id.'.y2_max_value' => $Max2,
14776: $id.'.y2_min_value' => $Min2,
1.136 matthew 14777: );
14778: #
1.137 matthew 14779: if (defined($colors) && ref($colors) eq 'ARRAY') {
14780: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14781: }
14782: #
14783: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14784: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14785: return '';
14786: }
14787: my $NumSets=1;
1.137 matthew 14788: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14789: next if (! ref($array));
14790: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14791: }
14792: #
14793: # Deal with other parameters
14794: while (my ($key,$value) = each(%Values)) {
14795: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14796: }
14797: #
1.646 raeburn 14798: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14799: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14800: }
14801:
14802: ############################################################
14803: ############################################################
14804:
14805: =pod
14806:
1.157 matthew 14807: =back
14808:
1.139 matthew 14809: =head1 Statistics helper routines?
14810:
14811: Bad place for them but what the hell.
14812:
1.157 matthew 14813: =over 4
14814:
1.648 raeburn 14815: =item * &chartlink()
1.139 matthew 14816:
14817: Returns a link to the chart for a specific student.
14818:
14819: Inputs:
14820:
14821: =over 4
14822:
14823: =item $linktext: The text of the link
14824:
14825: =item $sname: The students username
14826:
14827: =item $sdomain: The students domain
14828:
14829: =back
14830:
1.157 matthew 14831: =back
14832:
1.139 matthew 14833: =cut
14834:
14835: ############################################################
14836: ############################################################
14837: sub chartlink {
14838: my ($linktext, $sname, $sdomain) = @_;
14839: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14840: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14841: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14842: '">'.$linktext.'</a>';
1.153 matthew 14843: }
14844:
14845: #######################################################
14846: #######################################################
14847:
14848: =pod
14849:
14850: =head1 Course Environment Routines
1.157 matthew 14851:
14852: =over 4
1.153 matthew 14853:
1.648 raeburn 14854: =item * &restore_course_settings()
1.153 matthew 14855:
1.648 raeburn 14856: =item * &store_course_settings()
1.153 matthew 14857:
14858: Restores/Store indicated form parameters from the course environment.
14859: Will not overwrite existing values of the form parameters.
14860:
14861: Inputs:
14862: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14863:
14864: a hash ref describing the data to be stored. For example:
14865:
14866: %Save_Parameters = ('Status' => 'scalar',
14867: 'chartoutputmode' => 'scalar',
14868: 'chartoutputdata' => 'scalar',
14869: 'Section' => 'array',
1.373 raeburn 14870: 'Group' => 'array',
1.153 matthew 14871: 'StudentData' => 'array',
14872: 'Maps' => 'array');
14873:
14874: Returns: both routines return nothing
14875:
1.631 raeburn 14876: =back
14877:
1.153 matthew 14878: =cut
14879:
14880: #######################################################
14881: #######################################################
14882: sub store_course_settings {
1.496 albertel 14883: return &store_settings($env{'request.course.id'},@_);
14884: }
14885:
14886: sub store_settings {
1.153 matthew 14887: # save to the environment
14888: # appenv the same items, just to be safe
1.300 albertel 14889: my $udom = $env{'user.domain'};
14890: my $uname = $env{'user.name'};
1.496 albertel 14891: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14892: my %SaveHash;
14893: my %AppHash;
14894: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14895: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14896: my $envname = 'environment.'.$basename;
1.258 albertel 14897: if (exists($env{'form.'.$setting})) {
1.153 matthew 14898: # Save this value away
14899: if ($type eq 'scalar' &&
1.258 albertel 14900: (! exists($env{$envname}) ||
14901: $env{$envname} ne $env{'form.'.$setting})) {
14902: $SaveHash{$basename} = $env{'form.'.$setting};
14903: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14904: } elsif ($type eq 'array') {
14905: my $stored_form;
1.258 albertel 14906: if (ref($env{'form.'.$setting})) {
1.153 matthew 14907: $stored_form = join(',',
14908: map {
1.369 www 14909: &escape($_);
1.258 albertel 14910: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14911: } else {
14912: $stored_form =
1.369 www 14913: &escape($env{'form.'.$setting});
1.153 matthew 14914: }
14915: # Determine if the array contents are the same.
1.258 albertel 14916: if ($stored_form ne $env{$envname}) {
1.153 matthew 14917: $SaveHash{$basename} = $stored_form;
14918: $AppHash{$envname} = $stored_form;
14919: }
14920: }
14921: }
14922: }
14923: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14924: $udom,$uname);
1.153 matthew 14925: if ($put_result !~ /^(ok|delayed)/) {
14926: &Apache::lonnet::logthis('unable to save form parameters, '.
14927: 'got error:'.$put_result);
14928: }
14929: # Make sure these settings stick around in this session, too
1.646 raeburn 14930: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14931: return;
14932: }
14933:
14934: sub restore_course_settings {
1.499 albertel 14935: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14936: }
14937:
14938: sub restore_settings {
14939: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14940: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14941: next if (exists($env{'form.'.$setting}));
1.496 albertel 14942: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14943: '.'.$setting;
1.258 albertel 14944: if (exists($env{$envname})) {
1.153 matthew 14945: if ($type eq 'scalar') {
1.258 albertel 14946: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14947: } elsif ($type eq 'array') {
1.258 albertel 14948: $env{'form.'.$setting} = [
1.153 matthew 14949: map {
1.369 www 14950: &unescape($_);
1.258 albertel 14951: } split(',',$env{$envname})
1.153 matthew 14952: ];
14953: }
14954: }
14955: }
1.127 matthew 14956: }
14957:
1.618 raeburn 14958: #######################################################
14959: #######################################################
14960:
14961: =pod
14962:
14963: =head1 Domain E-mail Routines
14964:
14965: =over 4
14966:
1.648 raeburn 14967: =item * &build_recipient_list()
1.618 raeburn 14968:
1.1144 raeburn 14969: Build recipient lists for following types of e-mail:
1.766 raeburn 14970: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14971: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14972: module change checking, student/employee ID conflict checks, as
14973: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14974: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14975:
14976: Inputs:
1.619 raeburn 14977: defmail (scalar - email address of default recipient),
1.1144 raeburn 14978: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14979: requestsmail, updatesmail, or idconflictsmail).
14980:
1.619 raeburn 14981: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14982:
1.619 raeburn 14983: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14984: i.e., predates configuration by DC via domainprefs.pm
14985:
14986: $requname username of requester (if mailing type is helpdeskmail)
14987:
14988: $requdom domain of requester (if mailing type is helpdeskmail)
14989:
14990: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14991:
1.618 raeburn 14992:
1.655 raeburn 14993: Returns: comma separated list of addresses to which to send e-mail.
14994:
14995: =back
1.618 raeburn 14996:
14997: =cut
14998:
14999: ############################################################
15000: ############################################################
15001: sub build_recipient_list {
1.1297 raeburn 15002: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15003: my @recipients;
1.1270 raeburn 15004: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15005: my %domconfig =
1.1270 raeburn 15006: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15007: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15008: if (exists($domconfig{'contacts'}{$mailing})) {
15009: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15010: my @contacts = ('adminemail','supportemail');
15011: foreach my $item (@contacts) {
15012: if ($domconfig{'contacts'}{$mailing}{$item}) {
15013: my $addr = $domconfig{'contacts'}{$item};
15014: if (!grep(/^\Q$addr\E$/,@recipients)) {
15015: push(@recipients,$addr);
15016: }
1.619 raeburn 15017: }
1.1270 raeburn 15018: }
15019: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15020: if ($mailing eq 'helpdeskmail') {
15021: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15022: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15023: my @ok_bccs;
15024: foreach my $bcc (@bccs) {
15025: $bcc =~ s/^\s+//g;
15026: $bcc =~ s/\s+$//g;
15027: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15028: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15029: push(@ok_bccs,$bcc);
15030: }
15031: }
15032: }
15033: if (@ok_bccs > 0) {
15034: $allbcc = join(', ',@ok_bccs);
15035: }
15036: }
15037: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15038: }
15039: }
1.766 raeburn 15040: } elsif ($origmail ne '') {
1.1270 raeburn 15041: $lastresort = $origmail;
1.618 raeburn 15042: }
1.1297 raeburn 15043: if ($mailing eq 'helpdeskmail') {
15044: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15045: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15046: my ($inststatus,$inststatus_checked);
15047: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15048: ($env{'user.domain'} ne 'public')) {
15049: $inststatus_checked = 1;
15050: $inststatus = $env{'environment.inststatus'};
15051: }
15052: unless ($inststatus_checked) {
15053: if (($requname ne '') && ($requdom ne '')) {
15054: if (($requname =~ /^$match_username$/) &&
15055: ($requdom =~ /^$match_domain$/) &&
15056: (&Apache::lonnet::domain($requdom))) {
15057: my $requhome = &Apache::lonnet::homeserver($requname,
15058: $requdom);
15059: unless ($requhome eq 'no_host') {
15060: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15061: $inststatus = $userenv{'inststatus'};
15062: $inststatus_checked = 1;
15063: }
15064: }
15065: }
15066: }
15067: unless ($inststatus_checked) {
15068: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15069: my %srch = (srchby => 'email',
15070: srchdomain => $defdom,
15071: srchterm => $reqemail,
15072: srchtype => 'exact');
15073: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15074: foreach my $uname (keys(%srch_results)) {
15075: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15076: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15077: $inststatus_checked = 1;
15078: last;
15079: }
15080: }
15081: unless ($inststatus_checked) {
15082: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15083: if ($dirsrchres eq 'ok') {
15084: foreach my $uname (keys(%srch_results)) {
15085: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15086: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15087: $inststatus_checked = 1;
15088: last;
15089: }
15090: }
15091: }
15092: }
15093: }
15094: }
15095: if ($inststatus ne '') {
15096: foreach my $status (split(/\:/,$inststatus)) {
15097: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15098: my @contacts = ('adminemail','supportemail');
15099: foreach my $item (@contacts) {
15100: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15101: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15102: if (!grep(/^\Q$addr\E$/,@recipients)) {
15103: push(@recipients,$addr);
15104: }
15105: }
15106: }
15107: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15108: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15109: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15110: my @ok_bccs;
15111: foreach my $bcc (@bccs) {
15112: $bcc =~ s/^\s+//g;
15113: $bcc =~ s/\s+$//g;
15114: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15115: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15116: push(@ok_bccs,$bcc);
15117: }
15118: }
15119: }
15120: if (@ok_bccs > 0) {
15121: $allbcc = join(', ',@ok_bccs);
15122: }
15123: }
15124: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15125: last;
15126: }
15127: }
15128: }
15129: }
15130: }
1.619 raeburn 15131: } elsif ($origmail ne '') {
1.1270 raeburn 15132: $lastresort = $origmail;
15133: }
1.1297 raeburn 15134: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15135: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15136: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15137: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15138: my %what = (
15139: perlvar => 1,
15140: );
15141: my $primary = &Apache::lonnet::domain($defdom,'primary');
15142: if ($primary) {
15143: my $gotaddr;
15144: my ($result,$returnhash) =
15145: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15146: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15147: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15148: $lastresort = $returnhash->{'lonSupportEMail'};
15149: $gotaddr = 1;
15150: }
15151: }
15152: unless ($gotaddr) {
15153: my $uintdom = &Apache::lonnet::internet_dom($primary);
15154: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15155: unless ($uintdom eq $intdom) {
15156: my %domconfig =
15157: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15158: if (ref($domconfig{'contacts'}) eq 'HASH') {
15159: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15160: my @contacts = ('adminemail','supportemail');
15161: foreach my $item (@contacts) {
15162: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15163: my $addr = $domconfig{'contacts'}{$item};
15164: if (!grep(/^\Q$addr\E$/,@recipients)) {
15165: push(@recipients,$addr);
15166: }
15167: }
15168: }
15169: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15170: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15171: }
15172: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15173: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15174: my @ok_bccs;
15175: foreach my $bcc (@bccs) {
15176: $bcc =~ s/^\s+//g;
15177: $bcc =~ s/\s+$//g;
15178: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15179: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15180: push(@ok_bccs,$bcc);
15181: }
15182: }
15183: }
15184: if (@ok_bccs > 0) {
15185: $allbcc = join(', ',@ok_bccs);
15186: }
15187: }
15188: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15189: }
15190: }
15191: }
15192: }
15193: }
15194: }
1.618 raeburn 15195: }
1.688 raeburn 15196: if (defined($defmail)) {
15197: if ($defmail ne '') {
15198: push(@recipients,$defmail);
15199: }
1.618 raeburn 15200: }
15201: if ($otheremails) {
1.619 raeburn 15202: my @others;
15203: if ($otheremails =~ /,/) {
15204: @others = split(/,/,$otheremails);
1.618 raeburn 15205: } else {
1.619 raeburn 15206: push(@others,$otheremails);
15207: }
15208: foreach my $addr (@others) {
15209: if (!grep(/^\Q$addr\E$/,@recipients)) {
15210: push(@recipients,$addr);
15211: }
1.618 raeburn 15212: }
15213: }
1.1298 raeburn 15214: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15215: if ((!@recipients) && ($lastresort ne '')) {
15216: push(@recipients,$lastresort);
15217: }
15218: } elsif ($lastresort ne '') {
15219: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15220: push(@recipients,$lastresort);
15221: }
15222: }
1.1271 raeburn 15223: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15224: if (wantarray) {
15225: return ($recipientlist,$allbcc,$addtext);
15226: } else {
15227: return $recipientlist;
15228: }
1.618 raeburn 15229: }
15230:
1.127 matthew 15231: ############################################################
15232: ############################################################
1.154 albertel 15233:
1.655 raeburn 15234: =pod
15235:
1.1224 musolffc 15236: =over 4
15237:
1.1223 musolffc 15238: =item * &mime_email()
15239:
15240: Sends an email with a possible attachment
15241:
15242: Inputs:
15243:
15244: =over 4
15245:
15246: from - Sender's email address
15247:
1.1343 raeburn 15248: replyto - Reply-To email address
15249:
1.1223 musolffc 15250: to - Email address of recipient
15251:
15252: subject - Subject of email
15253:
15254: body - Body of email
15255:
15256: cc_string - Carbon copy email address
15257:
15258: bcc - Blind carbon copy email address
15259:
15260: attachment_path - Path of file to be attached
15261:
15262: file_name - Name of file to be attached
15263:
15264: attachment_text - The body of an attachment of type "TEXT"
15265:
15266: =back
15267:
15268: =back
15269:
15270: =cut
15271:
15272: ############################################################
15273: ############################################################
15274:
15275: sub mime_email {
1.1343 raeburn 15276: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15277: $file_name,$attachment_text) = @_;
15278:
1.1223 musolffc 15279: my $msg = MIME::Lite->new(
15280: From => $from,
15281: To => $to,
15282: Subject => $subject,
15283: Type =>'TEXT',
15284: Data => $body,
15285: );
1.1343 raeburn 15286: if ($replyto ne '') {
15287: $msg->add("Reply-To" => $replyto);
15288: }
1.1223 musolffc 15289: if ($cc_string ne '') {
15290: $msg->add("Cc" => $cc_string);
15291: }
15292: if ($bcc ne '') {
15293: $msg->add("Bcc" => $bcc);
15294: }
15295: $msg->attr("content-type" => "text/plain");
15296: $msg->attr("content-type.charset" => "UTF-8");
15297: # Attach file if given
15298: if ($attachment_path) {
15299: unless ($file_name) {
15300: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15301: }
15302: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15303: $msg->attach(Type => $type,
15304: Path => $attachment_path,
15305: Filename => $file_name
15306: );
15307: # Otherwise attach text if given
15308: } elsif ($attachment_text) {
15309: $msg->attach(Type => 'TEXT',
15310: Data => $attachment_text);
15311: }
15312: # Send it
15313: $msg->send('sendmail');
15314: }
15315:
15316: ############################################################
15317: ############################################################
15318:
15319: =pod
15320:
1.655 raeburn 15321: =head1 Course Catalog Routines
15322:
15323: =over 4
15324:
15325: =item * &gather_categories()
15326:
15327: Converts category definitions - keys of categories hash stored in
15328: coursecategories in configuration.db on the primary library server in a
15329: domain - to an array. Also generates javascript and idx hash used to
15330: generate Domain Coordinator interface for editing Course Categories.
15331:
15332: Inputs:
1.663 raeburn 15333:
1.655 raeburn 15334: categories (reference to hash of category definitions).
1.663 raeburn 15335:
1.655 raeburn 15336: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15337: categories and subcategories).
1.663 raeburn 15338:
1.655 raeburn 15339: idx (reference to hash of counters used in Domain Coordinator interface for
15340: editing Course Categories).
1.663 raeburn 15341:
1.655 raeburn 15342: jsarray (reference to array of categories used to create Javascript arrays for
15343: Domain Coordinator interface for editing Course Categories).
15344:
15345: Returns: nothing
15346:
15347: Side effects: populates cats, idx and jsarray.
15348:
15349: =cut
15350:
15351: sub gather_categories {
15352: my ($categories,$cats,$idx,$jsarray) = @_;
15353: my %counters;
15354: my $num = 0;
15355: foreach my $item (keys(%{$categories})) {
15356: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15357: if ($container eq '' && $depth == 0) {
15358: $cats->[$depth][$categories->{$item}] = $cat;
15359: } else {
15360: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15361: }
15362: my ($escitem,$tail) = split(/:/,$item,2);
15363: if ($counters{$tail} eq '') {
15364: $counters{$tail} = $num;
15365: $num ++;
15366: }
15367: if (ref($idx) eq 'HASH') {
15368: $idx->{$item} = $counters{$tail};
15369: }
15370: if (ref($jsarray) eq 'ARRAY') {
15371: push(@{$jsarray->[$counters{$tail}]},$item);
15372: }
15373: }
15374: return;
15375: }
15376:
15377: =pod
15378:
15379: =item * &extract_categories()
15380:
15381: Used to generate breadcrumb trails for course categories.
15382:
15383: Inputs:
1.663 raeburn 15384:
1.655 raeburn 15385: categories (reference to hash of category definitions).
1.663 raeburn 15386:
1.655 raeburn 15387: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15388: categories and subcategories).
1.663 raeburn 15389:
1.655 raeburn 15390: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15391:
1.655 raeburn 15392: allitems (reference to hash - key is category key
15393: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15394:
1.655 raeburn 15395: idx (reference to hash of counters used in Domain Coordinator interface for
15396: editing Course Categories).
1.663 raeburn 15397:
1.655 raeburn 15398: jsarray (reference to array of categories used to create Javascript arrays for
15399: Domain Coordinator interface for editing Course Categories).
15400:
1.665 raeburn 15401: subcats (reference to hash of arrays containing all subcategories within each
15402: category, -recursive)
15403:
1.1321 raeburn 15404: maxd (reference to hash used to hold max depth for all top-level categories).
15405:
1.655 raeburn 15406: Returns: nothing
15407:
15408: Side effects: populates trails and allitems hash references.
15409:
15410: =cut
15411:
15412: sub extract_categories {
1.1321 raeburn 15413: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15414: if (ref($categories) eq 'HASH') {
15415: &gather_categories($categories,$cats,$idx,$jsarray);
15416: if (ref($cats->[0]) eq 'ARRAY') {
15417: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15418: my $name = $cats->[0][$i];
15419: my $item = &escape($name).'::0';
15420: my $trailstr;
15421: if ($name eq 'instcode') {
15422: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15423: } elsif ($name eq 'communities') {
15424: $trailstr = &mt('Communities');
1.1239 raeburn 15425: } elsif ($name eq 'placement') {
15426: $trailstr = &mt('Placement Tests');
1.655 raeburn 15427: } else {
15428: $trailstr = $name;
15429: }
15430: if ($allitems->{$item} eq '') {
15431: push(@{$trails},$trailstr);
15432: $allitems->{$item} = scalar(@{$trails})-1;
15433: }
15434: my @parents = ($name);
15435: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15436: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15437: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15438: if (ref($subcats) eq 'HASH') {
15439: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15440: }
1.1321 raeburn 15441: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15442: }
15443: } else {
15444: if (ref($subcats) eq 'HASH') {
15445: $subcats->{$item} = [];
1.655 raeburn 15446: }
1.1321 raeburn 15447: if (ref($maxd) eq 'HASH') {
15448: $maxd->{$name} = 1;
15449: }
1.655 raeburn 15450: }
15451: }
15452: }
15453: }
15454: return;
15455: }
15456:
15457: =pod
15458:
1.1162 raeburn 15459: =item * &recurse_categories()
1.655 raeburn 15460:
15461: Recursively used to generate breadcrumb trails for course categories.
15462:
15463: Inputs:
1.663 raeburn 15464:
1.655 raeburn 15465: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15466: categories and subcategories).
1.663 raeburn 15467:
1.655 raeburn 15468: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15469:
15470: category (current course category, for which breadcrumb trail is being generated).
15471:
15472: trails (reference to array of breadcrumb trails for each category).
15473:
1.655 raeburn 15474: allitems (reference to hash - key is category key
15475: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15476:
1.655 raeburn 15477: parents (array containing containers directories for current category,
15478: back to top level).
15479:
15480: Returns: nothing
15481:
15482: Side effects: populates trails and allitems hash references
15483:
15484: =cut
15485:
15486: sub recurse_categories {
1.1321 raeburn 15487: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15488: my $shallower = $depth - 1;
15489: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15490: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15491: my $name = $cats->[$depth]{$category}[$k];
15492: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15493: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15494: if ($allitems->{$item} eq '') {
15495: push(@{$trails},$trailstr);
15496: $allitems->{$item} = scalar(@{$trails})-1;
15497: }
15498: my $deeper = $depth+1;
15499: push(@{$parents},$category);
1.665 raeburn 15500: if (ref($subcats) eq 'HASH') {
15501: my $subcat = &escape($name).':'.$category.':'.$depth;
15502: for (my $j=@{$parents}; $j>=0; $j--) {
15503: my $higher;
15504: if ($j > 0) {
15505: $higher = &escape($parents->[$j]).':'.
15506: &escape($parents->[$j-1]).':'.$j;
15507: } else {
15508: $higher = &escape($parents->[$j]).'::'.$j;
15509: }
15510: push(@{$subcats->{$higher}},$subcat);
15511: }
15512: }
15513: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15514: $subcats,$maxd);
1.655 raeburn 15515: pop(@{$parents});
15516: }
15517: } else {
15518: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15519: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15520: if ($allitems->{$item} eq '') {
15521: push(@{$trails},$trailstr);
15522: $allitems->{$item} = scalar(@{$trails})-1;
15523: }
1.1321 raeburn 15524: if (ref($maxd) eq 'HASH') {
15525: if ($depth > $maxd->{$parents->[0]}) {
15526: $maxd->{$parents->[0]} = $depth;
15527: }
15528: }
1.655 raeburn 15529: }
15530: return;
15531: }
15532:
1.663 raeburn 15533: =pod
15534:
1.1162 raeburn 15535: =item * &assign_categories_table()
1.663 raeburn 15536:
15537: Create a datatable for display of hierarchical categories in a domain,
15538: with checkboxes to allow a course to be categorized.
15539:
15540: Inputs:
15541:
15542: cathash - reference to hash of categories defined for the domain (from
15543: configuration.db)
15544:
15545: currcat - scalar with an & separated list of categories assigned to a course.
15546:
1.919 raeburn 15547: type - scalar contains course type (Course or Community).
15548:
1.1260 raeburn 15549: disabled - scalar (optional) contains disabled="disabled" if input elements are
15550: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15551:
1.663 raeburn 15552: Returns: $output (markup to be displayed)
15553:
15554: =cut
15555:
15556: sub assign_categories_table {
1.1259 raeburn 15557: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15558: my $output;
15559: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15560: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15561: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15562: $maxdepth = scalar(@cats);
15563: if (@cats > 0) {
15564: my $itemcount = 0;
15565: if (ref($cats[0]) eq 'ARRAY') {
15566: my @currcategories;
15567: if ($currcat ne '') {
15568: @currcategories = split('&',$currcat);
15569: }
1.919 raeburn 15570: my $table;
1.663 raeburn 15571: for (my $i=0; $i<@{$cats[0]}; $i++) {
15572: my $parent = $cats[0][$i];
1.919 raeburn 15573: next if ($parent eq 'instcode');
15574: if ($type eq 'Community') {
15575: next unless ($parent eq 'communities');
1.1239 raeburn 15576: } elsif ($type eq 'Placement') {
15577: next unless ($parent eq 'placement');
1.919 raeburn 15578: } else {
1.1239 raeburn 15579: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15580: }
1.663 raeburn 15581: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15582: my $item = &escape($parent).'::0';
15583: my $checked = '';
15584: if (@currcategories > 0) {
15585: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15586: $checked = ' checked="checked"';
1.663 raeburn 15587: }
15588: }
1.919 raeburn 15589: my $parent_title = $parent;
15590: if ($parent eq 'communities') {
15591: $parent_title = &mt('Communities');
1.1239 raeburn 15592: } elsif ($parent eq 'placement') {
15593: $parent_title = &mt('Placement Tests');
1.919 raeburn 15594: }
15595: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15596: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15597: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15598: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15599: my $depth = 1;
15600: push(@path,$parent);
1.1259 raeburn 15601: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15602: pop(@path);
1.919 raeburn 15603: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15604: $itemcount ++;
15605: }
1.919 raeburn 15606: if ($itemcount) {
15607: $output = &Apache::loncommon::start_data_table().
15608: $table.
15609: &Apache::loncommon::end_data_table();
15610: }
1.663 raeburn 15611: }
15612: }
15613: }
15614: return $output;
15615: }
15616:
15617: =pod
15618:
1.1162 raeburn 15619: =item * &assign_category_rows()
1.663 raeburn 15620:
15621: Create a datatable row for display of nested categories in a domain,
15622: with checkboxes to allow a course to be categorized,called recursively.
15623:
15624: Inputs:
15625:
15626: itemcount - track row number for alternating colors
15627:
15628: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15629: categories and subcategories.
15630:
15631: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15632:
15633: parent - parent of current category item
15634:
15635: path - Array containing all categories back up through the hierarchy from the
15636: current category to the top level.
15637:
15638: currcategories - reference to array of current categories assigned to the course
15639:
1.1260 raeburn 15640: disabled - scalar (optional) contains disabled="disabled" if input elements are
15641: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15642:
1.663 raeburn 15643: Returns: $output (markup to be displayed).
15644:
15645: =cut
15646:
15647: sub assign_category_rows {
1.1259 raeburn 15648: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15649: my ($text,$name,$item,$chgstr);
15650: if (ref($cats) eq 'ARRAY') {
15651: my $maxdepth = scalar(@{$cats});
15652: if (ref($cats->[$depth]) eq 'HASH') {
15653: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15654: my $numchildren = @{$cats->[$depth]{$parent}};
15655: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15656: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15657: for (my $j=0; $j<$numchildren; $j++) {
15658: $name = $cats->[$depth]{$parent}[$j];
15659: $item = &escape($name).':'.&escape($parent).':'.$depth;
15660: my $deeper = $depth+1;
15661: my $checked = '';
15662: if (ref($currcategories) eq 'ARRAY') {
15663: if (@{$currcategories} > 0) {
15664: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15665: $checked = ' checked="checked"';
1.663 raeburn 15666: }
15667: }
15668: }
1.664 raeburn 15669: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15670: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15671: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15672: '<input type="hidden" name="catname" value="'.$name.'" />'.
15673: '</td><td>';
1.663 raeburn 15674: if (ref($path) eq 'ARRAY') {
15675: push(@{$path},$name);
1.1259 raeburn 15676: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15677: pop(@{$path});
15678: }
15679: $text .= '</td></tr>';
15680: }
15681: $text .= '</table></td>';
15682: }
15683: }
15684: }
15685: return $text;
15686: }
15687:
1.1181 raeburn 15688: =pod
15689:
15690: =back
15691:
15692: =cut
15693:
1.655 raeburn 15694: ############################################################
15695: ############################################################
15696:
15697:
1.443 albertel 15698: sub commit_customrole {
1.664 raeburn 15699: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15700: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15701: ($start?', '.&mt('starting').' '.localtime($start):'').
15702: ($end?', ending '.localtime($end):'').': <b>'.
15703: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15704: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15705: '</b><br />';
15706: return $output;
15707: }
15708:
15709: sub commit_standardrole {
1.1116 raeburn 15710: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15711: my ($output,$logmsg,$linefeed);
15712: if ($context eq 'auto') {
15713: $linefeed = "\n";
15714: } else {
15715: $linefeed = "<br />\n";
15716: }
1.443 albertel 15717: if ($three eq 'st') {
1.541 raeburn 15718: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15719: $one,$two,$sec,$context,$credits);
1.541 raeburn 15720: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15721: ($result eq 'unknown_course') || ($result eq 'refused')) {
15722: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15723: } else {
1.541 raeburn 15724: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15725: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15726: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15727: if ($context eq 'auto') {
15728: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15729: } else {
15730: $output .= '<b>'.$result.'</b>'.$linefeed.
15731: &mt('Add to classlist').': <b>ok</b>';
15732: }
15733: $output .= $linefeed;
1.443 albertel 15734: }
15735: } else {
15736: $output = &mt('Assigning').' '.$three.' in '.$url.
15737: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15738: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15739: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15740: if ($context eq 'auto') {
15741: $output .= $result.$linefeed;
15742: } else {
15743: $output .= '<b>'.$result.'</b>'.$linefeed;
15744: }
1.443 albertel 15745: }
15746: return $output;
15747: }
15748:
15749: sub commit_studentrole {
1.1116 raeburn 15750: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15751: $credits) = @_;
1.626 raeburn 15752: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15753: if ($context eq 'auto') {
15754: $linefeed = "\n";
15755: } else {
15756: $linefeed = '<br />'."\n";
15757: }
1.443 albertel 15758: if (defined($one) && defined($two)) {
15759: my $cid=$one.'_'.$two;
15760: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15761: my $secchange = 0;
15762: my $expire_role_result;
15763: my $modify_section_result;
1.628 raeburn 15764: if ($oldsec ne '-1') {
15765: if ($oldsec ne $sec) {
1.443 albertel 15766: $secchange = 1;
1.628 raeburn 15767: my $now = time;
1.443 albertel 15768: my $uurl='/'.$cid;
15769: $uurl=~s/\_/\//g;
15770: if ($oldsec) {
15771: $uurl.='/'.$oldsec;
15772: }
1.626 raeburn 15773: $oldsecurl = $uurl;
1.628 raeburn 15774: $expire_role_result =
1.652 raeburn 15775: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15776: if ($env{'request.course.sec'} ne '') {
15777: if ($expire_role_result eq 'refused') {
15778: my @roles = ('st');
15779: my @statuses = ('previous');
15780: my @roledoms = ($one);
15781: my $withsec = 1;
15782: my %roleshash =
15783: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15784: \@statuses,\@roles,\@roledoms,$withsec);
15785: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15786: my ($oldstart,$oldend) =
15787: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15788: if ($oldend > 0 && $oldend <= $now) {
15789: $expire_role_result = 'ok';
15790: }
15791: }
15792: }
15793: }
1.443 albertel 15794: $result = $expire_role_result;
15795: }
15796: }
15797: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15798: $modify_section_result =
15799: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15800: undef,undef,undef,$sec,
15801: $end,$start,'','',$cid,
15802: '',$context,$credits);
1.443 albertel 15803: if ($modify_section_result =~ /^ok/) {
15804: if ($secchange == 1) {
1.628 raeburn 15805: if ($sec eq '') {
15806: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15807: } else {
15808: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15809: }
1.443 albertel 15810: } elsif ($oldsec eq '-1') {
1.628 raeburn 15811: if ($sec eq '') {
15812: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15813: } else {
15814: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15815: }
1.443 albertel 15816: } else {
1.628 raeburn 15817: if ($sec eq '') {
15818: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15819: } else {
15820: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15821: }
1.443 albertel 15822: }
15823: } else {
1.1115 raeburn 15824: if ($secchange) {
1.628 raeburn 15825: $$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;
15826: } else {
15827: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15828: }
1.443 albertel 15829: }
15830: $result = $modify_section_result;
15831: } elsif ($secchange == 1) {
1.628 raeburn 15832: if ($oldsec eq '') {
1.1103 raeburn 15833: $$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 15834: } else {
15835: $$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;
15836: }
1.626 raeburn 15837: if ($expire_role_result eq 'refused') {
15838: my $newsecurl = '/'.$cid;
15839: $newsecurl =~ s/\_/\//g;
15840: if ($sec ne '') {
15841: $newsecurl.='/'.$sec;
15842: }
15843: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15844: if ($sec eq '') {
15845: $$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;
15846: } else {
15847: $$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;
15848: }
15849: }
15850: }
1.443 albertel 15851: }
15852: } else {
1.626 raeburn 15853: $$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 15854: $result = "error: incomplete course id\n";
15855: }
15856: return $result;
15857: }
15858:
1.1108 raeburn 15859: sub show_role_extent {
15860: my ($scope,$context,$role) = @_;
15861: $scope =~ s{^/}{};
15862: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15863: push(@courseroles,'co');
15864: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15865: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15866: $scope =~ s{/}{_};
15867: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15868: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15869: my ($audom,$auname) = split(/\//,$scope);
15870: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15871: &Apache::loncommon::plainname($auname,$audom).'</span>');
15872: } else {
15873: $scope =~ s{/$}{};
15874: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15875: &Apache::lonnet::domain($scope,'description').'</span>');
15876: }
15877: }
15878:
1.443 albertel 15879: ############################################################
15880: ############################################################
15881:
1.566 albertel 15882: sub check_clone {
1.578 raeburn 15883: my ($args,$linefeed) = @_;
1.566 albertel 15884: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15885: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15886: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 15887: my $clonetitle;
15888: my @clonemsg;
1.566 albertel 15889: my $can_clone = 0;
1.944 raeburn 15890: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15891: if ($lctype ne 'community') {
15892: $lctype = 'course';
15893: }
1.566 albertel 15894: if ($clonehome eq 'no_host') {
1.944 raeburn 15895: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 15896: push(@clonemsg,({
15897: mt => 'No new community created.',
15898: args => [],
15899: },
15900: {
15901: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15902: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15903: }));
1.908 raeburn 15904: } else {
1.1344 raeburn 15905: push(@clonemsg,({
15906: mt => 'No new course created.',
15907: args => [],
15908: },
15909: {
15910: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15911: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15912: }));
15913: }
1.566 albertel 15914: } else {
15915: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 15916: $clonetitle = $clonedesc{'description'};
1.944 raeburn 15917: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15918: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 15919: push(@clonemsg,({
15920: mt => 'No new community created.',
15921: args => [],
15922: },
15923: {
15924: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
15925: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15926: }));
15927: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 15928: }
15929: }
1.1262 raeburn 15930: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15931: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15932: $can_clone = 1;
15933: } else {
1.1221 raeburn 15934: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15935: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15936: if ($clonehash{'cloners'} eq '') {
15937: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15938: if ($domdefs{'canclone'}) {
15939: unless ($domdefs{'canclone'} eq 'none') {
15940: if ($domdefs{'canclone'} eq 'domain') {
15941: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15942: $can_clone = 1;
15943: }
15944: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15945: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15946: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15947: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15948: $can_clone = 1;
15949: }
15950: }
15951: }
15952: }
1.578 raeburn 15953: } else {
1.1221 raeburn 15954: my @cloners = split(/,/,$clonehash{'cloners'});
15955: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15956: $can_clone = 1;
1.1221 raeburn 15957: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15958: $can_clone = 1;
1.1225 raeburn 15959: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15960: $can_clone = 1;
1.1221 raeburn 15961: }
15962: unless ($can_clone) {
1.1225 raeburn 15963: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15964: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15965: my (%gotdomdefaults,%gotcodedefaults);
15966: foreach my $cloner (@cloners) {
15967: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15968: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15969: my (%codedefaults,@code_order);
15970: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15971: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15972: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15973: }
15974: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15975: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15976: }
15977: } else {
15978: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15979: \%codedefaults,
15980: \@code_order);
15981: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15982: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15983: }
15984: if (@code_order > 0) {
15985: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15986: $cloner,$clonehash{'internal.coursecode'},
15987: $args->{'crscode'})) {
15988: $can_clone = 1;
15989: last;
15990: }
15991: }
15992: }
15993: }
15994: }
1.1225 raeburn 15995: }
15996: }
15997: unless ($can_clone) {
15998: my $ccrole = 'cc';
15999: if ($args->{'crstype'} eq 'Community') {
16000: $ccrole = 'co';
16001: }
16002: my %roleshash =
16003: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16004: $args->{'ccdomain'},
16005: 'userroles',['active'],[$ccrole],
16006: [$args->{'clonedomain'}]);
16007: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16008: $can_clone = 1;
16009: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16010: $args->{'ccuname'},$args->{'ccdomain'})) {
16011: $can_clone = 1;
1.1221 raeburn 16012: }
16013: }
16014: unless ($can_clone) {
16015: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16016: push(@clonemsg,({
16017: mt => 'No new community created.',
16018: args => [],
16019: },
16020: {
16021: 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]).',
16022: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16023: }));
1.942 raeburn 16024: } else {
1.1344 raeburn 16025: push(@clonemsg,({
16026: mt => 'No new course created.',
16027: args => [],
16028: },
16029: {
16030: 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]).',
16031: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16032: }));
1.1221 raeburn 16033: }
1.566 albertel 16034: }
1.578 raeburn 16035: }
1.566 albertel 16036: }
1.1344 raeburn 16037: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16038: }
16039:
1.444 albertel 16040: sub construct_course {
1.1262 raeburn 16041: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16042: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16043: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16044: my $linefeed = '<br />'."\n";
16045: if ($context eq 'auto') {
16046: $linefeed = "\n";
16047: }
1.566 albertel 16048:
16049: #
16050: # Are we cloning?
16051: #
1.1344 raeburn 16052: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16053: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16054: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16055: if (!$can_clone) {
1.1344 raeburn 16056: return (0,$outcome,$clonemsgref);
1.566 albertel 16057: }
16058: }
16059:
1.444 albertel 16060: #
16061: # Open course
16062: #
1.1239 raeburn 16063: my $showncrstype;
16064: if ($args->{'crstype'} eq 'Placement') {
16065: $showncrstype = 'placement test';
16066: } else {
16067: $showncrstype = lc($args->{'crstype'});
16068: }
1.444 albertel 16069: my %cenv=();
16070: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16071: $args->{'cdescr'},
16072: $args->{'curl'},
16073: $args->{'course_home'},
16074: $args->{'nonstandard'},
16075: $args->{'crscode'},
16076: $args->{'ccuname'}.':'.
16077: $args->{'ccdomain'},
1.882 raeburn 16078: $args->{'crstype'},
1.1344 raeburn 16079: $cnum,$context,$category,
16080: $callercontext);
1.444 albertel 16081:
16082: # Note: The testing routines depend on this being output; see
16083: # Utils::Course. This needs to at least be output as a comment
16084: # if anyone ever decides to not show this, and Utils::Course::new
16085: # will need to be suitably modified.
1.1344 raeburn 16086: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16087: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16088: } else {
16089: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16090: }
1.943 raeburn 16091: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16092: return (0,$outcome,$clonemsgref);
1.943 raeburn 16093: }
16094:
1.444 albertel 16095: #
16096: # Check if created correctly
16097: #
1.479 albertel 16098: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16099: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16100: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16101: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16102: $outcome .= &mt_user($user_lh,
16103: 'Course creation failed, unrecognized course home server.');
16104: } else {
16105: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16106: }
16107: $outcome .= $linefeed;
16108: return (0,$outcome,$clonemsgref);
1.943 raeburn 16109: }
1.541 raeburn 16110: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16111:
1.444 albertel 16112: #
1.566 albertel 16113: # Do the cloning
16114: #
1.1344 raeburn 16115: my @clonemsg;
1.566 albertel 16116: if ($can_clone && $cloneid) {
1.1344 raeburn 16117: push(@clonemsg,
16118: {
16119: mt => 'Created [_1] by cloning from [_2]',
16120: args => [$showncrstype,$clonetitle],
16121: });
1.566 albertel 16122: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16123: # Copy all files
1.1344 raeburn 16124: my @info =
16125: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16126: $args->{'dateshift'},$args->{'crscode'},
16127: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16128: $args->{'tinyurls'});
16129: if (@info) {
16130: push(@clonemsg,@info);
16131: }
1.444 albertel 16132: # Restore URL
1.566 albertel 16133: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16134: # Restore title
1.566 albertel 16135: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16136: # Restore creation date, creator and creation context.
16137: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16138: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16139: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16140: # Mark as cloned
1.566 albertel 16141: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16142: # Need to clone grading mode
16143: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16144: $cenv{'grading'}=$newenv{'grading'};
16145: # Do not clone these environment entries
16146: &Apache::lonnet::del('environment',
16147: ['default_enrollment_start_date',
16148: 'default_enrollment_end_date',
16149: 'question.email',
16150: 'policy.email',
16151: 'comment.email',
16152: 'pch.users.denied',
1.725 raeburn 16153: 'plc.users.denied',
16154: 'hidefromcat',
1.1121 raeburn 16155: 'checkforpriv',
1.1166 raeburn 16156: 'categories',
16157: 'internal.uniquecode'],
1.638 www 16158: $$crsudom,$$crsunum);
1.1170 raeburn 16159: if ($args->{'textbook'}) {
16160: $cenv{'internal.textbook'} = $args->{'textbook'};
16161: }
1.444 albertel 16162: }
1.566 albertel 16163:
1.444 albertel 16164: #
16165: # Set environment (will override cloned, if existing)
16166: #
16167: my @sections = ();
16168: my @xlists = ();
16169: if ($args->{'crstype'}) {
16170: $cenv{'type'}=$args->{'crstype'};
16171: }
16172: if ($args->{'crsid'}) {
16173: $cenv{'courseid'}=$args->{'crsid'};
16174: }
16175: if ($args->{'crscode'}) {
16176: $cenv{'internal.coursecode'}=$args->{'crscode'};
16177: }
16178: if ($args->{'crsquota'} ne '') {
16179: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16180: } else {
16181: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16182: }
16183: if ($args->{'ccuname'}) {
16184: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16185: ':'.$args->{'ccdomain'};
16186: } else {
16187: $cenv{'internal.courseowner'} = $args->{'curruser'};
16188: }
1.1116 raeburn 16189: if ($args->{'defaultcredits'}) {
16190: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16191: }
1.444 albertel 16192: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16193: if ($args->{'crssections'}) {
16194: $cenv{'internal.sectionnums'} = '';
16195: if ($args->{'crssections'} =~ m/,/) {
16196: @sections = split/,/,$args->{'crssections'};
16197: } else {
16198: $sections[0] = $args->{'crssections'};
16199: }
16200: if (@sections > 0) {
16201: foreach my $item (@sections) {
16202: my ($sec,$gp) = split/:/,$item;
16203: my $class = $args->{'crscode'}.$sec;
16204: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16205: $cenv{'internal.sectionnums'} .= $item.',';
16206: unless ($addcheck eq 'ok') {
1.1263 raeburn 16207: push(@badclasses,$class);
1.444 albertel 16208: }
16209: }
16210: $cenv{'internal.sectionnums'} =~ s/,$//;
16211: }
16212: }
16213: # do not hide course coordinator from staff listing,
16214: # even if privileged
16215: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16216: # add course coordinator's domain to domains to check for privileged users
16217: # if different to course domain
16218: if ($$crsudom ne $args->{'ccdomain'}) {
16219: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16220: }
1.444 albertel 16221: # add crosslistings
16222: if ($args->{'crsxlist'}) {
16223: $cenv{'internal.crosslistings'}='';
16224: if ($args->{'crsxlist'} =~ m/,/) {
16225: @xlists = split/,/,$args->{'crsxlist'};
16226: } else {
16227: $xlists[0] = $args->{'crsxlist'};
16228: }
16229: if (@xlists > 0) {
16230: foreach my $item (@xlists) {
16231: my ($xl,$gp) = split/:/,$item;
16232: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16233: $cenv{'internal.crosslistings'} .= $item.',';
16234: unless ($addcheck eq 'ok') {
1.1263 raeburn 16235: push(@badclasses,$xl);
1.444 albertel 16236: }
16237: }
16238: $cenv{'internal.crosslistings'} =~ s/,$//;
16239: }
16240: }
16241: if ($args->{'autoadds'}) {
16242: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16243: }
16244: if ($args->{'autodrops'}) {
16245: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16246: }
16247: # check for notification of enrollment changes
16248: my @notified = ();
16249: if ($args->{'notify_owner'}) {
16250: if ($args->{'ccuname'} ne '') {
16251: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16252: }
16253: }
16254: if ($args->{'notify_dc'}) {
16255: if ($uname ne '') {
1.630 raeburn 16256: push(@notified,$uname.':'.$udom);
1.444 albertel 16257: }
16258: }
16259: if (@notified > 0) {
16260: my $notifylist;
16261: if (@notified > 1) {
16262: $notifylist = join(',',@notified);
16263: } else {
16264: $notifylist = $notified[0];
16265: }
16266: $cenv{'internal.notifylist'} = $notifylist;
16267: }
16268: if (@badclasses > 0) {
16269: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16270: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16271: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16272: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16273: );
1.1264 raeburn 16274: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16275: &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 16276: if ($context eq 'auto') {
16277: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16278: } else {
1.566 albertel 16279: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16280: }
16281: foreach my $item (@badclasses) {
1.541 raeburn 16282: if ($context eq 'auto') {
1.1261 raeburn 16283: $outcome .= " - $item\n";
1.541 raeburn 16284: } else {
1.1261 raeburn 16285: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16286: }
1.1261 raeburn 16287: }
16288: if ($context eq 'auto') {
16289: $outcome .= $linefeed;
16290: } else {
16291: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16292: }
1.444 albertel 16293: }
16294: if ($args->{'no_end_date'}) {
16295: $args->{'endaccess'} = 0;
16296: }
16297: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16298: $cenv{'internal.autoend'}=$args->{'enrollend'};
16299: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16300: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16301: if ($args->{'showphotos'}) {
16302: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16303: }
16304: $cenv{'internal.authtype'} = $args->{'authtype'};
16305: $cenv{'internal.autharg'} = $args->{'autharg'};
16306: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16307: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16308: 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');
16309: if ($context eq 'auto') {
16310: $outcome .= $krb_msg;
16311: } else {
1.566 albertel 16312: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16313: }
16314: $outcome .= $linefeed;
1.444 albertel 16315: }
16316: }
16317: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16318: if ($args->{'setpolicy'}) {
16319: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16320: }
16321: if ($args->{'setcontent'}) {
16322: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16323: }
1.1251 raeburn 16324: if ($args->{'setcomment'}) {
16325: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16326: }
1.444 albertel 16327: }
16328: if ($args->{'reshome'}) {
16329: $cenv{'reshome'}=$args->{'reshome'}.'/';
16330: $cenv{'reshome'}=~s/\/+$/\//;
16331: }
16332: #
16333: # course has keyed access
16334: #
16335: if ($args->{'setkeys'}) {
16336: $cenv{'keyaccess'}='yes';
16337: }
16338: # if specified, key authority is not course, but user
16339: # only active if keyaccess is yes
16340: if ($args->{'keyauth'}) {
1.487 albertel 16341: my ($user,$domain) = split(':',$args->{'keyauth'});
16342: $user = &LONCAPA::clean_username($user);
16343: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16344: if ($user ne '' && $domain ne '') {
1.487 albertel 16345: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16346: }
16347: }
16348:
1.1166 raeburn 16349: #
1.1167 raeburn 16350: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16351: #
16352: if ($args->{'uniquecode'}) {
16353: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16354: if ($code) {
16355: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16356: my %crsinfo =
16357: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16358: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16359: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16360: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16361: }
1.1166 raeburn 16362: if (ref($coderef)) {
16363: $$coderef = $code;
16364: }
16365: }
16366: }
16367:
1.444 albertel 16368: if ($args->{'disresdis'}) {
16369: $cenv{'pch.roles.denied'}='st';
16370: }
16371: if ($args->{'disablechat'}) {
16372: $cenv{'plc.roles.denied'}='st';
16373: }
16374:
16375: # Record we've not yet viewed the Course Initialization Helper for this
16376: # course
16377: $cenv{'course.helper.not.run'} = 1;
16378: #
16379: # Use new Randomseed
16380: #
16381: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16382: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16383: #
16384: # The encryption code and receipt prefix for this course
16385: #
16386: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16387: $cenv{'internal.encpref'}=100+int(9*rand(99));
16388: #
16389: # By default, use standard grading
16390: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16391:
1.541 raeburn 16392: $outcome .= $linefeed.&mt('Setting environment').': '.
16393: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16394: #
16395: # Open all assignments
16396: #
16397: if ($args->{'openall'}) {
1.1341 raeburn 16398: my $opendate = time;
16399: if ($args->{'openallfrom'} =~ /^\d+$/) {
16400: $opendate = $args->{'openallfrom'};
16401: }
1.444 albertel 16402: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16403: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16404: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16405: $outcome .= &mt('All assignments open starting [_1]',
16406: &Apache::lonlocal::locallocaltime($opendate)).': '.
16407: &Apache::lonnet::cput
16408: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16409: }
16410: #
16411: # Set first page
16412: #
16413: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16414: || ($cloneid)) {
1.445 albertel 16415: use LONCAPA::map;
1.444 albertel 16416: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16417:
16418: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16419: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16420:
1.444 albertel 16421: $outcome .= ($fatal?$errtext:'read ok').' - ';
16422: my $title; my $url;
16423: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16424: $title=&mt('Syllabus');
1.444 albertel 16425: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16426: } else {
1.963 raeburn 16427: $title=&mt('Table of Contents');
1.444 albertel 16428: $url='/adm/navmaps';
16429: }
1.445 albertel 16430:
16431: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16432: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16433:
16434: if ($errtext) { $fatal=2; }
1.541 raeburn 16435: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16436: }
1.566 albertel 16437:
1.1237 raeburn 16438: #
16439: # Set params for Placement Tests
16440: #
1.1239 raeburn 16441: if ($args->{'crstype'} eq 'Placement') {
16442: my %storecontent;
16443: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16444: my %defaults = (
16445: buttonshide => { value => 'yes',
16446: type => 'string_yesno',},
16447: type => { value => 'randomizetry',
16448: type => 'string_questiontype',},
16449: maxtries => { value => 1,
16450: type => 'int_pos',},
16451: problemstatus => { value => 'no',
16452: type => 'string_problemstatus',},
16453: );
16454: foreach my $key (keys(%defaults)) {
16455: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16456: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16457: }
1.1237 raeburn 16458: &Apache::lonnet::cput
16459: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16460: }
16461:
1.1344 raeburn 16462: return (1,$outcome,\@clonemsg);
1.444 albertel 16463: }
16464:
1.1166 raeburn 16465: sub make_unique_code {
16466: my ($cdom,$cnum) = @_;
16467: # get lock on uniquecodes db
16468: my $lockhash = {
16469: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16470: ':'.$env{'user.domain'},
16471: };
16472: my $tries = 0;
16473: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16474: my ($code,$error);
16475:
16476: while (($gotlock ne 'ok') && ($tries<3)) {
16477: $tries ++;
16478: sleep 1;
16479: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16480: }
16481: if ($gotlock eq 'ok') {
16482: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16483: my $gotcode;
16484: my $attempts = 0;
16485: while ((!$gotcode) && ($attempts < 100)) {
16486: $code = &generate_code();
16487: if (!exists($currcodes{$code})) {
16488: $gotcode = 1;
16489: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16490: $error = 'nostore';
16491: }
16492: }
16493: $attempts ++;
16494: }
16495: my @del_lock = ($cnum."\0".'uniquecodes');
16496: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16497: } else {
16498: $error = 'nolock';
16499: }
16500: return ($code,$error);
16501: }
16502:
16503: sub generate_code {
16504: my $code;
16505: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16506: for (my $i=0; $i<6; $i++) {
16507: my $lettnum = int (rand 2);
16508: my $item = '';
16509: if ($lettnum) {
16510: $item = $letts[int( rand(18) )];
16511: } else {
16512: $item = 1+int( rand(8) );
16513: }
16514: $code .= $item;
16515: }
16516: return $code;
16517: }
16518:
1.444 albertel 16519: ############################################################
16520: ############################################################
16521:
1.1237 raeburn 16522: # Community, Course and Placement Test
1.378 raeburn 16523: sub course_type {
16524: my ($cid) = @_;
16525: if (!defined($cid)) {
16526: $cid = $env{'request.course.id'};
16527: }
1.404 albertel 16528: if (defined($env{'course.'.$cid.'.type'})) {
16529: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16530: } else {
16531: return 'Course';
1.377 raeburn 16532: }
16533: }
1.156 albertel 16534:
1.406 raeburn 16535: sub group_term {
16536: my $crstype = &course_type();
16537: my %names = (
16538: 'Course' => 'group',
1.865 raeburn 16539: 'Community' => 'group',
1.1237 raeburn 16540: 'Placement' => 'group',
1.406 raeburn 16541: );
16542: return $names{$crstype};
16543: }
16544:
1.902 raeburn 16545: sub course_types {
1.1310 raeburn 16546: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16547: my %typename = (
16548: official => 'Official course',
16549: unofficial => 'Unofficial course',
16550: community => 'Community',
1.1165 raeburn 16551: textbook => 'Textbook course',
1.1237 raeburn 16552: placement => 'Placement test',
1.1310 raeburn 16553: lti => 'LTI provider',
1.902 raeburn 16554: );
16555: return (\@types,\%typename);
16556: }
16557:
1.156 albertel 16558: sub icon {
16559: my ($file)=@_;
1.505 albertel 16560: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16561: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16562: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16563: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16564: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16565: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16566: $curfext.".gif") {
16567: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16568: $curfext.".gif";
16569: }
16570: }
1.249 albertel 16571: return &lonhttpdurl($iconname);
1.154 albertel 16572: }
1.84 albertel 16573:
1.575 albertel 16574: sub lonhttpdurl {
1.692 www 16575: #
16576: # Had been used for "small fry" static images on separate port 8080.
16577: # Modify here if lightweight http functionality desired again.
16578: # Currently eliminated due to increasing firewall issues.
16579: #
1.575 albertel 16580: my ($url)=@_;
1.692 www 16581: return $url;
1.215 albertel 16582: }
16583:
1.213 albertel 16584: sub connection_aborted {
16585: my ($r)=@_;
16586: $r->print(" ");$r->rflush();
16587: my $c = $r->connection;
16588: return $c->aborted();
16589: }
16590:
1.221 foxr 16591: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16592: # strings as 'strings'.
16593: sub escape_single {
1.221 foxr 16594: my ($input) = @_;
1.223 albertel 16595: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16596: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16597: return $input;
16598: }
1.223 albertel 16599:
1.222 foxr 16600: # Same as escape_single, but escape's "'s This
16601: # can be used for "strings"
16602: sub escape_double {
16603: my ($input) = @_;
16604: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16605: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16606: return $input;
16607: }
1.223 albertel 16608:
1.222 foxr 16609: # Escapes the last element of a full URL.
16610: sub escape_url {
16611: my ($url) = @_;
1.238 raeburn 16612: my @urlslices = split(/\//, $url,-1);
1.369 www 16613: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16614: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16615: }
1.462 albertel 16616:
1.820 raeburn 16617: sub compare_arrays {
16618: my ($arrayref1,$arrayref2) = @_;
16619: my (@difference,%count);
16620: @difference = ();
16621: %count = ();
16622: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16623: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16624: foreach my $element (keys(%count)) {
16625: if ($count{$element} == 1) {
16626: push(@difference,$element);
16627: }
16628: }
16629: }
16630: return @difference;
16631: }
16632:
1.1322 raeburn 16633: sub lon_status_items {
16634: my %defaults = (
16635: E => 100,
16636: W => 4,
16637: N => 1,
1.1324 raeburn 16638: U => 5,
1.1322 raeburn 16639: threshold => 200,
16640: sysmail => 2500,
16641: );
16642: my %names = (
16643: E => 'Errors',
16644: W => 'Warnings',
16645: N => 'Notices',
1.1324 raeburn 16646: U => 'Unsent',
1.1322 raeburn 16647: );
16648: return (\%defaults,\%names);
16649: }
16650:
1.817 bisitz 16651: # -------------------------------------------------------- Initialize user login
1.462 albertel 16652: sub init_user_environment {
1.463 albertel 16653: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16654: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16655:
16656: my $public=($username eq 'public' && $domain eq 'public');
16657:
1.1062 raeburn 16658: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16659: my $now=time;
16660:
16661: if ($public) {
16662: my $max_public=100;
16663: my $oldest;
16664: my $oldest_time=0;
16665: for(my $next=1;$next<=$max_public;$next++) {
16666: if (-e $lonids."/publicuser_$next.id") {
16667: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16668: if ($mtime<$oldest_time || !$oldest_time) {
16669: $oldest_time=$mtime;
16670: $oldest=$next;
16671: }
16672: } else {
16673: $cookie="publicuser_$next";
16674: last;
16675: }
16676: }
16677: if (!$cookie) { $cookie="publicuser_$oldest"; }
16678: } else {
1.1275 raeburn 16679: # See if old ID present, if so, remove if this isn't a robot,
16680: # killing any existing non-robot sessions
1.463 albertel 16681: if (!$args->{'robot'}) {
16682: opendir(DIR,$lonids);
16683: while ($filename=readdir(DIR)) {
16684: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16685: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16686: &GDBM_READER(),0640)) {
1.1295 raeburn 16687: my $linkedfile;
1.1320 raeburn 16688: if (exists($oldenv{'user.linkedenv'})) {
16689: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16690: }
1.1320 raeburn 16691: untie(%oldenv);
16692: if (unlink("$lonids/$filename")) {
16693: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16694: if (-l "$lonids/$linkedfile.id") {
16695: unlink("$lonids/$linkedfile.id");
16696: }
1.1295 raeburn 16697: }
16698: }
16699: } else {
16700: unlink($lonids.'/'.$filename);
16701: }
1.463 albertel 16702: }
1.462 albertel 16703: }
1.463 albertel 16704: closedir(DIR);
1.1204 raeburn 16705: # If there is a undeleted lockfile for the user's paste buffer remove it.
16706: my $namespace = 'nohist_courseeditor';
16707: my $lockingkey = 'paste'."\0".'locked_num';
16708: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16709: $domain,$username);
16710: if (exists($lockhash{$lockingkey})) {
16711: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16712: unless ($delresult eq 'ok') {
16713: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16714: }
16715: }
1.462 albertel 16716: }
16717: # Give them a new cookie
1.463 albertel 16718: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16719: : $now.$$.int(rand(10000)));
1.463 albertel 16720: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16721:
16722: # Initialize roles
16723:
1.1062 raeburn 16724: ($userroles,$firstaccenv,$timerintenv) =
16725: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16726: }
16727: # ------------------------------------ Check browser type and MathML capability
16728:
1.1194 raeburn 16729: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16730: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16731:
16732: # ------------------------------------------------------------- Get environment
16733:
16734: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16735: my ($tmp) = keys(%userenv);
1.1275 raeburn 16736: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16737: undef(%userenv);
16738: }
16739: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16740: $form->{'interface'}=$userenv{'interface'};
16741: }
16742: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16743:
16744: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16745: foreach my $option ('interface','localpath','localres') {
16746: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16747: }
16748: # --------------------------------------------------------- Write first profile
16749:
16750: {
16751: my %initial_env =
16752: ("user.name" => $username,
16753: "user.domain" => $domain,
16754: "user.home" => $authhost,
16755: "browser.type" => $clientbrowser,
16756: "browser.version" => $clientversion,
16757: "browser.mathml" => $clientmathml,
16758: "browser.unicode" => $clientunicode,
16759: "browser.os" => $clientos,
1.1137 raeburn 16760: "browser.mobile" => $clientmobile,
1.1141 raeburn 16761: "browser.info" => $clientinfo,
1.1194 raeburn 16762: "browser.osversion" => $clientosversion,
1.462 albertel 16763: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16764: "request.course.fn" => '',
16765: "request.course.uri" => '',
16766: "request.course.sec" => '',
16767: "request.role" => 'cm',
16768: "request.role.adv" => $env{'user.adv'},
16769: "request.host" => $ENV{'REMOTE_ADDR'},);
16770:
16771: if ($form->{'localpath'}) {
16772: $initial_env{"browser.localpath"} = $form->{'localpath'};
16773: $initial_env{"browser.localres"} = $form->{'localres'};
16774: }
16775:
16776: if ($form->{'interface'}) {
16777: $form->{'interface'}=~s/\W//gs;
16778: $initial_env{"browser.interface"} = $form->{'interface'};
16779: $env{'browser.interface'}=$form->{'interface'};
16780: }
16781:
1.1157 raeburn 16782: if ($form->{'iptoken'}) {
16783: my $lonhost = $r->dir_config('lonHostID');
16784: $initial_env{"user.noloadbalance"} = $lonhost;
16785: $env{'user.noloadbalance'} = $lonhost;
16786: }
16787:
1.1268 raeburn 16788: if ($form->{'noloadbalance'}) {
16789: my @hosts = &Apache::lonnet::current_machine_ids();
16790: my $hosthere = $form->{'noloadbalance'};
16791: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16792: $initial_env{"user.noloadbalance"} = $hosthere;
16793: $env{'user.noloadbalance'} = $hosthere;
16794: }
16795: }
16796:
1.1016 raeburn 16797: unless ($domain eq 'public') {
1.1273 raeburn 16798: my %is_adv = ( is_adv => $env{'user.adv'} );
16799: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16800:
16801: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16802: $userenv{'availabletools.'.$tool} =
16803: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16804: undef,\%userenv,\%domdef,\%is_adv);
16805: }
1.980 raeburn 16806:
1.1311 raeburn 16807: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16808: $userenv{'canrequest.'.$crstype} =
16809: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16810: 'reload','requestcourses',
16811: \%userenv,\%domdef,\%is_adv);
16812: }
1.724 raeburn 16813:
1.1273 raeburn 16814: $userenv{'canrequest.author'} =
16815: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16816: 'reload','requestauthor',
1.980 raeburn 16817: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16818: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16819: $domain,$username);
16820: my $reqstatus = $reqauthor{'author_status'};
16821: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16822: if (ref($reqauthor{'author'}) eq 'HASH') {
16823: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16824: $reqauthor{'author'}{'timestamp'};
16825: }
1.1092 raeburn 16826: }
1.1287 raeburn 16827: my ($types,$typename) = &course_types();
16828: if (ref($types) eq 'ARRAY') {
16829: my @options = ('approval','validate','autolimit');
16830: my $optregex = join('|',@options);
16831: my (%willtrust,%trustchecked);
16832: foreach my $type (@{$types}) {
16833: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16834: if ($dom_str ne '') {
16835: my $updatedstr = '';
16836: my @possdomains = split(',',$dom_str);
16837: foreach my $entry (@possdomains) {
16838: my ($extdom,$extopt) = split(':',$entry);
16839: unless ($trustchecked{$extdom}) {
16840: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16841: $trustchecked{$extdom} = 1;
16842: }
16843: if ($willtrust{$extdom}) {
16844: $updatedstr .= $entry.',';
16845: }
16846: }
16847: $updatedstr =~ s/,$//;
16848: if ($updatedstr) {
16849: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16850: } else {
16851: delete($userenv{'reqcrsotherdom.'.$type});
16852: }
16853: }
16854: }
16855: }
1.1092 raeburn 16856: }
1.462 albertel 16857: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16858:
1.462 albertel 16859: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16860: &GDBM_WRCREAT(),0640)) {
16861: &_add_to_env(\%disk_env,\%initial_env);
16862: &_add_to_env(\%disk_env,\%userenv,'environment.');
16863: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16864: if (ref($firstaccenv) eq 'HASH') {
16865: &_add_to_env(\%disk_env,$firstaccenv);
16866: }
16867: if (ref($timerintenv) eq 'HASH') {
16868: &_add_to_env(\%disk_env,$timerintenv);
16869: }
1.463 albertel 16870: if (ref($args->{'extra_env'})) {
16871: &_add_to_env(\%disk_env,$args->{'extra_env'});
16872: }
1.462 albertel 16873: untie(%disk_env);
16874: } else {
1.705 tempelho 16875: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16876: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16877: return 'error: '.$!;
16878: }
16879: }
16880: $env{'request.role'}='cm';
16881: $env{'request.role.adv'}=$env{'user.adv'};
16882: $env{'browser.type'}=$clientbrowser;
16883:
16884: return $cookie;
16885:
16886: }
16887:
16888: sub _add_to_env {
16889: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16890: if (ref($env_data) eq 'HASH') {
16891: while (my ($key,$value) = each(%$env_data)) {
16892: $idf->{$prefix.$key} = $value;
16893: $env{$prefix.$key} = $value;
16894: }
1.462 albertel 16895: }
16896: }
16897:
1.685 tempelho 16898: # --- Get the symbolic name of a problem and the url
16899: sub get_symb {
16900: my ($request,$silent) = @_;
1.726 raeburn 16901: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16902: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16903: if ($symb eq '') {
16904: if (!$silent) {
1.1071 raeburn 16905: if (ref($request)) {
16906: $request->print("Unable to handle ambiguous references:$url:.");
16907: }
1.685 tempelho 16908: return ();
16909: }
16910: }
16911: &Apache::lonenc::check_decrypt(\$symb);
16912: return ($symb);
16913: }
16914:
16915: # --------------------------------------------------------------Get annotation
16916:
16917: sub get_annotation {
16918: my ($symb,$enc) = @_;
16919:
16920: my $key = $symb;
16921: if (!$enc) {
16922: $key =
16923: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16924: }
16925: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16926: return $annotation{$key};
16927: }
16928:
16929: sub clean_symb {
1.731 raeburn 16930: my ($symb,$delete_enc) = @_;
1.685 tempelho 16931:
16932: &Apache::lonenc::check_decrypt(\$symb);
16933: my $enc = $env{'request.enc'};
1.731 raeburn 16934: if ($delete_enc) {
1.730 raeburn 16935: delete($env{'request.enc'});
16936: }
1.685 tempelho 16937:
16938: return ($symb,$enc);
16939: }
1.462 albertel 16940:
1.1181 raeburn 16941: ############################################################
16942: ############################################################
16943:
16944: =pod
16945:
16946: =head1 Routines for building display used to search for courses
16947:
16948:
16949: =over 4
16950:
16951: =item * &build_filters()
16952:
16953: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16954: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16955: and quotacheck.pl
16956:
1.1181 raeburn 16957:
16958: Inputs:
16959:
16960: filterlist - anonymous array of fields to include as potential filters
16961:
16962: crstype - course type
16963:
16964: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16965: to pop-open a course selector (will contain "extra element").
16966:
16967: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16968:
16969: filter - anonymous hash of criteria and their values
16970:
16971: action - form action
16972:
16973: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16974:
1.1182 raeburn 16975: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16976:
16977: cloneruname - username of owner of new course who wants to clone
16978:
16979: clonerudom - domain of owner of new course who wants to clone
16980:
16981: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16982:
16983: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16984:
16985: codedom - domain
16986:
16987: formname - value of form element named "form".
16988:
16989: fixeddom - domain, if fixed.
16990:
16991: prevphase - value to assign to form element named "phase" when going back to the previous screen
16992:
16993: cnameelement - name of form element in form on opener page which will receive title of selected course
16994:
16995: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16996:
16997: cdomelement - name of form element in form on opener page which will receive domain of selected course
16998:
16999: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17000:
17001: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17002:
17003: clonewarning - warning message about missing information for intended course owner when DC creates a course
17004:
1.1182 raeburn 17005:
1.1181 raeburn 17006: Returns: $output - HTML for display of search criteria, and hidden form elements.
17007:
1.1182 raeburn 17008:
1.1181 raeburn 17009: Side Effects: None
17010:
17011: =cut
17012:
17013: # ---------------------------------------------- search for courses based on last activity etc.
17014:
17015: sub build_filters {
17016: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17017: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17018: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17019: $cnameelement,$cnumelement,$cdomelement,$setroles,
17020: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17021: my ($list,$jscript);
1.1181 raeburn 17022: my $onchange = 'javascript:updateFilters(this)';
17023: my ($domainselectform,$sincefilterform,$createdfilterform,
17024: $ownerdomselectform,$persondomselectform,$instcodeform,
17025: $typeselectform,$instcodetitle);
17026: if ($formname eq '') {
17027: $formname = $caller;
17028: }
17029: foreach my $item (@{$filterlist}) {
17030: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17031: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17032: if ($item eq 'domainfilter') {
17033: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17034: } elsif ($item eq 'coursefilter') {
17035: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17036: } elsif ($item eq 'ownerfilter') {
17037: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17038: } elsif ($item eq 'ownerdomfilter') {
17039: $filter->{'ownerdomfilter'} =
17040: &LONCAPA::clean_domain($filter->{$item});
17041: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17042: 'ownerdomfilter',1);
17043: } elsif ($item eq 'personfilter') {
17044: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17045: } elsif ($item eq 'persondomfilter') {
17046: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17047: 'persondomfilter',1);
17048: } else {
17049: $filter->{$item} =~ s/\W//g;
17050: }
17051: if (!$filter->{$item}) {
17052: $filter->{$item} = '';
17053: }
17054: }
17055: if ($item eq 'domainfilter') {
17056: my $allow_blank = 1;
17057: if ($formname eq 'portform') {
17058: $allow_blank=0;
17059: } elsif ($formname eq 'studentform') {
17060: $allow_blank=0;
17061: }
17062: if ($fixeddom) {
17063: $domainselectform = '<input type="hidden" name="domainfilter"'.
17064: ' value="'.$codedom.'" />'.
17065: &Apache::lonnet::domain($codedom,'description');
17066: } else {
17067: $domainselectform = &select_dom_form($filter->{$item},
17068: 'domainfilter',
17069: $allow_blank,'',$onchange);
17070: }
17071: } else {
17072: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17073: }
17074: }
17075:
17076: # last course activity filter and selection
17077: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17078:
17079: # course created filter and selection
17080: if (exists($filter->{'createdfilter'})) {
17081: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17082: }
17083:
1.1239 raeburn 17084: my $prefix = $crstype;
17085: if ($crstype eq 'Placement') {
17086: $prefix = 'Placement Test'
17087: }
1.1181 raeburn 17088: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17089: 'cac' => "$prefix Activity",
17090: 'ccr' => "$prefix Created",
17091: 'cde' => "$prefix Title",
17092: 'cdo' => "$prefix Domain",
1.1181 raeburn 17093: 'ins' => 'Institutional Code',
17094: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17095: 'cow' => "$prefix Owner/Co-owner",
17096: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17097: 'cog' => 'Type',
17098: );
17099:
17100: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17101: my $typeval = 'Course';
17102: if ($crstype eq 'Community') {
17103: $typeval = 'Community';
1.1239 raeburn 17104: } elsif ($crstype eq 'Placement') {
17105: $typeval = 'Placement';
1.1181 raeburn 17106: }
17107: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17108: } else {
17109: $typeselectform = '<select name="type" size="1"';
17110: if ($onchange) {
17111: $typeselectform .= ' onchange="'.$onchange.'"';
17112: }
17113: $typeselectform .= '>'."\n";
1.1237 raeburn 17114: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17115: my $shown;
17116: if ($posstype eq 'Placement') {
17117: $shown = &mt('Placement Test');
17118: } else {
17119: $shown = &mt($posstype);
17120: }
1.1181 raeburn 17121: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17122: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17123: }
17124: $typeselectform.="</select>";
17125: }
17126:
17127: my ($cloneableonlyform,$cloneabletitle);
17128: if (exists($filter->{'cloneableonly'})) {
17129: my $cloneableon = '';
17130: my $cloneableoff = ' checked="checked"';
17131: if ($filter->{'cloneableonly'}) {
17132: $cloneableon = $cloneableoff;
17133: $cloneableoff = '';
17134: }
17135: $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>';
17136: if ($formname eq 'ccrs') {
1.1187 bisitz 17137: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17138: } else {
17139: $cloneabletitle = &mt('Cloneable by you');
17140: }
17141: }
17142: my $officialjs;
17143: if ($crstype eq 'Course') {
17144: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17145: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17146: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17147: if ($codedom) {
1.1181 raeburn 17148: $officialjs = 1;
17149: ($instcodeform,$jscript,$$numtitlesref) =
17150: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17151: $officialjs,$codetitlesref);
17152: if ($jscript) {
1.1182 raeburn 17153: $jscript = '<script type="text/javascript">'."\n".
17154: '// <![CDATA['."\n".
17155: $jscript."\n".
17156: '// ]]>'."\n".
17157: '</script>'."\n";
1.1181 raeburn 17158: }
17159: }
17160: if ($instcodeform eq '') {
17161: $instcodeform =
17162: '<input type="text" name="instcodefilter" size="10" value="'.
17163: $list->{'instcodefilter'}.'" />';
17164: $instcodetitle = $lt{'ins'};
17165: } else {
17166: $instcodetitle = $lt{'inc'};
17167: }
17168: if ($fixeddom) {
17169: $instcodetitle .= '<br />('.$codedom.')';
17170: }
17171: }
17172: }
17173: my $output = qq|
17174: <form method="post" name="filterpicker" action="$action">
17175: <input type="hidden" name="form" value="$formname" />
17176: |;
17177: if ($formname eq 'modifycourse') {
17178: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17179: '<input type="hidden" name="prevphase" value="'.
17180: $prevphase.'" />'."\n";
1.1198 musolffc 17181: } elsif ($formname eq 'quotacheck') {
17182: $output .= qq|
17183: <input type="hidden" name="sortby" value="" />
17184: <input type="hidden" name="sortorder" value="" />
17185: |;
17186: } else {
1.1181 raeburn 17187: my $name_input;
17188: if ($cnameelement ne '') {
17189: $name_input = '<input type="hidden" name="cnameelement" value="'.
17190: $cnameelement.'" />';
17191: }
17192: $output .= qq|
1.1182 raeburn 17193: <input type="hidden" name="cnumelement" value="$cnumelement" />
17194: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17195: $name_input
17196: $roleelement
17197: $multelement
17198: $typeelement
17199: |;
17200: if ($formname eq 'portform') {
17201: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17202: }
17203: }
17204: if ($fixeddom) {
17205: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17206: }
17207: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17208: if ($sincefilterform) {
17209: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17210: .$sincefilterform
17211: .&Apache::lonhtmlcommon::row_closure();
17212: }
17213: if ($createdfilterform) {
17214: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17215: .$createdfilterform
17216: .&Apache::lonhtmlcommon::row_closure();
17217: }
17218: if ($domainselectform) {
17219: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17220: .$domainselectform
17221: .&Apache::lonhtmlcommon::row_closure();
17222: }
17223: if ($typeselectform) {
17224: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17225: $output .= $typeselectform;
17226: } else {
17227: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17228: .$typeselectform
17229: .&Apache::lonhtmlcommon::row_closure();
17230: }
17231: }
17232: if ($instcodeform) {
17233: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17234: .$instcodeform
17235: .&Apache::lonhtmlcommon::row_closure();
17236: }
17237: if (exists($filter->{'ownerfilter'})) {
17238: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17239: '<table><tr><td>'.&mt('Username').'<br />'.
17240: '<input type="text" name="ownerfilter" size="20" value="'.
17241: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17242: $ownerdomselectform.'</td></tr></table>'.
17243: &Apache::lonhtmlcommon::row_closure();
17244: }
17245: if (exists($filter->{'personfilter'})) {
17246: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17247: '<table><tr><td>'.&mt('Username').'<br />'.
17248: '<input type="text" name="personfilter" size="20" value="'.
17249: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17250: $persondomselectform.'</td></tr></table>'.
17251: &Apache::lonhtmlcommon::row_closure();
17252: }
17253: if (exists($filter->{'coursefilter'})) {
17254: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17255: .'<input type="text" name="coursefilter" size="25" value="'
17256: .$list->{'coursefilter'}.'" />'
17257: .&Apache::lonhtmlcommon::row_closure();
17258: }
17259: if ($cloneableonlyform) {
17260: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17261: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17262: }
17263: if (exists($filter->{'descriptfilter'})) {
17264: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17265: .'<input type="text" name="descriptfilter" size="40" value="'
17266: .$list->{'descriptfilter'}.'" />'
17267: .&Apache::lonhtmlcommon::row_closure(1);
17268: }
17269: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17270: '<input type="hidden" name="updater" value="" />'."\n".
17271: '<input type="submit" name="gosearch" value="'.
17272: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17273: return $jscript.$clonewarning.$output;
17274: }
17275:
17276: =pod
17277:
17278: =item * &timebased_select_form()
17279:
1.1182 raeburn 17280: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17281: filter e.g., Course Activity, Course Created, when searching for courses
17282: or communities
17283:
17284: Inputs:
17285:
17286: item - name of form element (sincefilter or createdfilter)
17287:
17288: filter - anonymous hash of criteria and their values
17289:
17290: Returns: HTML for a select box contained a blank, then six time selections,
17291: with value set in incoming form variables currently selected.
17292:
17293: Side Effects: None
17294:
17295: =cut
17296:
17297: sub timebased_select_form {
17298: my ($item,$filter) = @_;
17299: if (ref($filter) eq 'HASH') {
17300: $filter->{$item} =~ s/[^\d-]//g;
17301: if (!$filter->{$item}) { $filter->{$item}=-1; }
17302: return &select_form(
17303: $filter->{$item},
17304: $item,
17305: { '-1' => '',
17306: '86400' => &mt('today'),
17307: '604800' => &mt('last week'),
17308: '2592000' => &mt('last month'),
17309: '7776000' => &mt('last three months'),
17310: '15552000' => &mt('last six months'),
17311: '31104000' => &mt('last year'),
17312: 'select_form_order' =>
17313: ['-1','86400','604800','2592000','7776000',
17314: '15552000','31104000']});
17315: }
17316: }
17317:
17318: =pod
17319:
17320: =item * &js_changer()
17321:
17322: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17323: when course type or domain is changed, and also to hide 'Searching ...' on
17324: page load completion for page showing search result.
1.1181 raeburn 17325:
17326: Inputs: None
17327:
1.1183 raeburn 17328: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17329:
17330: Side Effects: None
17331:
17332: =cut
17333:
17334: sub js_changer {
17335: return <<ENDJS;
17336: <script type="text/javascript">
17337: // <![CDATA[
17338: function updateFilters(caller) {
17339: if (typeof(caller) != "undefined") {
17340: document.filterpicker.updater.value = caller.name;
17341: }
17342: document.filterpicker.submit();
17343: }
1.1183 raeburn 17344:
17345: function hideSearching() {
17346: if (document.getElementById('searching')) {
17347: document.getElementById('searching').style.display = 'none';
17348: }
17349: return;
17350: }
17351:
1.1181 raeburn 17352: // ]]>
17353: </script>
17354:
17355: ENDJS
17356: }
17357:
17358: =pod
17359:
1.1182 raeburn 17360: =item * &search_courses()
17361:
17362: Process selected filters form course search form and pass to lonnet::courseiddump
17363: to retrieve a hash for which keys are courseIDs which match the selected filters.
17364:
17365: Inputs:
17366:
17367: dom - domain being searched
17368:
17369: type - course type ('Course' or 'Community' or '.' if any).
17370:
17371: filter - anonymous hash of criteria and their values
17372:
17373: numtitles - for institutional codes - number of categories
17374:
17375: cloneruname - optional username of new course owner
17376:
17377: clonerudom - optional domain of new course owner
17378:
1.1221 raeburn 17379: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17380: (used when DC is using course creation form)
17381:
17382: codetitles - reference to array of titles of components in institutional codes (official courses).
17383:
1.1221 raeburn 17384: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17385: (and so can clone automatically)
17386:
17387: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17388:
17389: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17390: courses to clone
1.1182 raeburn 17391:
17392: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17393:
17394:
17395: Side Effects: None
17396:
17397: =cut
17398:
17399:
17400: sub search_courses {
1.1221 raeburn 17401: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17402: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17403: my (%courses,%showcourses,$cloner);
17404: if (($filter->{'ownerfilter'} ne '') ||
17405: ($filter->{'ownerdomfilter'} ne '')) {
17406: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17407: $filter->{'ownerdomfilter'};
17408: }
17409: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17410: if (!$filter->{$item}) {
17411: $filter->{$item}='.';
17412: }
17413: }
17414: my $now = time;
17415: my $timefilter =
17416: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17417: my ($createdbefore,$createdafter);
17418: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17419: $createdbefore = $now;
17420: $createdafter = $now-$filter->{'createdfilter'};
17421: }
17422: my ($instcodefilter,$regexpok);
17423: if ($numtitles) {
17424: if ($env{'form.official'} eq 'on') {
17425: $instcodefilter =
17426: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17427: $regexpok = 1;
17428: } elsif ($env{'form.official'} eq 'off') {
17429: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17430: unless ($instcodefilter eq '') {
17431: $regexpok = -1;
17432: }
17433: }
17434: } else {
17435: $instcodefilter = $filter->{'instcodefilter'};
17436: }
17437: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17438: if ($type eq '') { $type = '.'; }
17439:
17440: if (($clonerudom ne '') && ($cloneruname ne '')) {
17441: $cloner = $cloneruname.':'.$clonerudom;
17442: }
17443: %courses = &Apache::lonnet::courseiddump($dom,
17444: $filter->{'descriptfilter'},
17445: $timefilter,
17446: $instcodefilter,
17447: $filter->{'combownerfilter'},
17448: $filter->{'coursefilter'},
17449: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17450: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17451: $filter->{'cloneableonly'},
17452: $createdbefore,$createdafter,undef,
1.1221 raeburn 17453: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17454: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17455: my $ccrole;
17456: if ($type eq 'Community') {
17457: $ccrole = 'co';
17458: } else {
17459: $ccrole = 'cc';
17460: }
17461: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17462: $filter->{'persondomfilter'},
17463: 'userroles',undef,
17464: [$ccrole,'in','ad','ep','ta','cr'],
17465: $dom);
17466: foreach my $role (keys(%rolehash)) {
17467: my ($cnum,$cdom,$courserole) = split(':',$role);
17468: my $cid = $cdom.'_'.$cnum;
17469: if (exists($courses{$cid})) {
17470: if (ref($courses{$cid}) eq 'HASH') {
17471: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17472: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17473: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17474: }
17475: } else {
17476: $courses{$cid}{roles} = [$courserole];
17477: }
17478: $showcourses{$cid} = $courses{$cid};
17479: }
17480: }
17481: }
17482: %courses = %showcourses;
17483: }
17484: return %courses;
17485: }
17486:
17487: =pod
17488:
1.1181 raeburn 17489: =back
17490:
1.1207 raeburn 17491: =head1 Routines for version requirements for current course.
17492:
17493: =over 4
17494:
17495: =item * &check_release_required()
17496:
17497: Compares required LON-CAPA version with version on server, and
17498: if required version is newer looks for a server with the required version.
17499:
17500: Looks first at servers in user's owen domain; if none suitable, looks at
17501: servers in course's domain are permitted to host sessions for user's domain.
17502:
17503: Inputs:
17504:
17505: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17506:
17507: $courseid - Course ID of current course
17508:
17509: $rolecode - User's current role in course (for switchserver query string).
17510:
17511: $required - LON-CAPA version needed by course (format: Major.Minor).
17512:
17513:
17514: Returns:
17515:
17516: $switchserver - query string tp append to /adm/switchserver call (if
17517: current server's LON-CAPA version is too old.
17518:
17519: $warning - Message is displayed if no suitable server could be found.
17520:
17521: =cut
17522:
17523: sub check_release_required {
17524: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17525: my ($switchserver,$warning);
17526: if ($required ne '') {
17527: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17528: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17529: if ($reqdmajor ne '' && $reqdminor ne '') {
17530: my $otherserver;
17531: if (($major eq '' && $minor eq '') ||
17532: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17533: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17534: my $switchlcrev =
17535: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17536: $userdomserver);
17537: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17538: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17539: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17540: my $cdom = $env{'course.'.$courseid.'.domain'};
17541: if ($cdom ne $env{'user.domain'}) {
17542: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17543: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17544: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17545: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17546: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17547: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17548: my $canhost =
17549: &Apache::lonnet::can_host_session($env{'user.domain'},
17550: $coursedomserver,
17551: $remoterev,
17552: $udomdefaults{'remotesessions'},
17553: $defdomdefaults{'hostedsessions'});
17554:
17555: if ($canhost) {
17556: $otherserver = $coursedomserver;
17557: } else {
17558: $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.");
17559: }
17560: } else {
17561: $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).");
17562: }
17563: } else {
17564: $otherserver = $userdomserver;
17565: }
17566: }
17567: if ($otherserver ne '') {
17568: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17569: }
17570: }
17571: }
17572: return ($switchserver,$warning);
17573: }
17574:
17575: =pod
17576:
17577: =item * &check_release_result()
17578:
17579: Inputs:
17580:
17581: $switchwarning - Warning message if no suitable server found to host session.
17582:
17583: $switchserver - query string to append to /adm/switchserver containing lonHostID
17584: and current role.
17585:
17586: Returns: HTML to display with information about requirement to switch server.
17587: Either displaying warning with link to Roles/Courses screen or
17588: display link to switchserver.
17589:
1.1181 raeburn 17590: =cut
17591:
1.1207 raeburn 17592: sub check_release_result {
17593: my ($switchwarning,$switchserver) = @_;
17594: my $output = &start_page('Selected course unavailable on this server').
17595: '<p class="LC_warning">';
17596: if ($switchwarning) {
17597: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17598: if (&show_course()) {
17599: $output .= &mt('Display courses');
17600: } else {
17601: $output .= &mt('Display roles');
17602: }
17603: $output .= '</a>';
17604: } elsif ($switchserver) {
17605: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17606: '<br />'.
17607: '<a href="/adm/switchserver?'.$switchserver.'">'.
17608: &mt('Switch Server').
17609: '</a>';
17610: }
17611: $output .= '</p>'.&end_page();
17612: return $output;
17613: }
17614:
17615: =pod
17616:
17617: =item * &needs_coursereinit()
17618:
17619: Determine if course contents stored for user's session needs to be
17620: refreshed, because content has changed since "Big Hash" last tied.
17621:
17622: Check for change is made if time last checked is more than 10 minutes ago
17623: (by default).
17624:
17625: Inputs:
17626:
17627: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17628:
17629: $interval (optional) - Time which may elapse (in s) between last check for content
17630: change in current course. (default: 600 s).
17631:
17632: Returns: an array; first element is:
17633:
17634: =over 4
17635:
17636: 'switch' - if content updates mean user's session
17637: needs to be switched to a server running a newer LON-CAPA version
17638:
17639: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17640: on current server hosting user's session
17641:
17642: '' - if no action required.
17643:
17644: =back
17645:
17646: If first item element is 'switch':
17647:
17648: second item is $switchwarning - Warning message if no suitable server found to host session.
17649:
17650: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17651: and current role.
17652:
17653: otherwise: no other elements returned.
17654:
17655: =back
17656:
17657: =cut
17658:
17659: sub needs_coursereinit {
17660: my ($loncaparev,$interval) = @_;
17661: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17662: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17663: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17664: my $now = time;
17665: if ($interval eq '') {
17666: $interval = 600;
17667: }
17668: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17669: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17670: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17671: if ($blocked) {
17672: return ();
17673: }
1.1207 raeburn 17674: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17675: if ($lastchange > $env{'request.course.tied'}) {
17676: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17677: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17678: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17679: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17680: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17681: $curr_reqd_hash{'internal.releaserequired'}});
17682: my ($switchserver,$switchwarning) =
17683: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17684: $curr_reqd_hash{'internal.releaserequired'});
17685: if ($switchwarning ne '' || $switchserver ne '') {
17686: return ('switch',$switchwarning,$switchserver);
17687: }
17688: }
17689: }
17690: return ('update');
17691: }
17692: }
17693: return ();
17694: }
1.1181 raeburn 17695:
1.1083 raeburn 17696: sub update_content_constraints {
1.1326 raeburn 17697: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17698: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17699: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17700: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17701: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17702: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17703: if ($item eq 'resourcetag') {
17704: if ($name eq 'responsetype') {
17705: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17706: }
1.1307 raeburn 17707: } elsif ($item eq 'course') {
17708: if ($name eq 'courserestype') {
17709: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17710: }
1.1083 raeburn 17711: }
17712: }
17713: my $navmap = Apache::lonnavmaps::navmap->new();
17714: if (defined($navmap)) {
1.1307 raeburn 17715: my (%allresponses,%allcrsrestypes);
17716: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17717: if ($res->is_tool()) {
17718: if ($allcrsrestypes{'exttool'}) {
17719: $allcrsrestypes{'exttool'} ++;
17720: } else {
17721: $allcrsrestypes{'exttool'} = 1;
17722: }
17723: next;
17724: }
1.1083 raeburn 17725: my %responses = $res->responseTypes();
17726: foreach my $key (keys(%responses)) {
17727: next unless(exists($checkresponsetypes{$key}));
17728: $allresponses{$key} += $responses{$key};
17729: }
17730: }
17731: foreach my $key (keys(%allresponses)) {
17732: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17733: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17734: ($reqdmajor,$reqdminor) = ($major,$minor);
17735: }
17736: }
1.1307 raeburn 17737: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17738: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17739: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17740: ($reqdmajor,$reqdminor) = ($major,$minor);
17741: }
17742: }
1.1083 raeburn 17743: undef($navmap);
17744: }
1.1326 raeburn 17745: my (@resources,@order,@resparms,@zombies);
17746: if ($keeporder) {
17747: use LONCAPA::map;
17748: @resources = @LONCAPA::map::resources;
17749: @order = @LONCAPA::map::order;
17750: @resparms = @LONCAPA::map::resparms;
17751: @zombies = @LONCAPA::map::zombies;
17752: }
1.1308 raeburn 17753: my $suppmap = 'supplemental.sequence';
17754: my ($suppcount,$supptools,$errors) = (0,0,0);
17755: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17756: $suppcount,$supptools,$errors);
1.1326 raeburn 17757: if ($keeporder) {
17758: @LONCAPA::map::resources = @resources;
17759: @LONCAPA::map::order = @order;
17760: @LONCAPA::map::resparms = @resparms;
17761: @LONCAPA::map::zombies = @zombies;
17762: }
1.1308 raeburn 17763: if ($supptools) {
17764: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17765: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17766: ($reqdmajor,$reqdminor) = ($major,$minor);
17767: }
17768: }
1.1083 raeburn 17769: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17770: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17771: }
17772: return;
17773: }
17774:
1.1110 raeburn 17775: sub allmaps_incourse {
17776: my ($cdom,$cnum,$chome,$cid) = @_;
17777: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17778: $cid = $env{'request.course.id'};
17779: $cdom = $env{'course.'.$cid.'.domain'};
17780: $cnum = $env{'course.'.$cid.'.num'};
17781: $chome = $env{'course.'.$cid.'.home'};
17782: }
17783: my %allmaps = ();
17784: my $lastchange =
17785: &Apache::lonnet::get_coursechange($cdom,$cnum);
17786: if ($lastchange > $env{'request.course.tied'}) {
17787: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17788: unless ($ferr) {
1.1326 raeburn 17789: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17790: }
17791: }
17792: my $navmap = Apache::lonnavmaps::navmap->new();
17793: if (defined($navmap)) {
17794: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17795: $allmaps{$res->src()} = 1;
17796: }
17797: }
17798: return \%allmaps;
17799: }
17800:
1.1083 raeburn 17801: sub parse_supplemental_title {
17802: my ($title) = @_;
17803:
17804: my ($foldertitle,$renametitle);
17805: if ($title =~ /&&&/) {
17806: $title = &HTML::Entites::decode($title);
17807: }
17808: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17809: $renametitle=$4;
17810: my ($time,$uname,$udom) = ($1,$2,$3);
17811: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17812: my $name = &plainname($uname,$udom);
17813: $name = &HTML::Entities::encode($name,'"<>&\'');
17814: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17815: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17816: $name.': <br />'.$foldertitle;
17817: }
17818: if (wantarray) {
17819: return ($title,$foldertitle,$renametitle);
17820: }
17821: return $title;
17822: }
17823:
1.1143 raeburn 17824: sub recurse_supplemental {
1.1308 raeburn 17825: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17826: if ($suppmap) {
17827: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17828: if ($fatal) {
17829: $errors ++;
17830: } else {
17831: if ($#LONCAPA::map::resources > 0) {
17832: foreach my $res (@LONCAPA::map::resources) {
17833: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17834: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17835: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17836: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17837: $numfiles,$numexttools,$errors);
1.1143 raeburn 17838: } else {
1.1308 raeburn 17839: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17840: $numexttools ++;
17841: }
1.1143 raeburn 17842: $numfiles ++;
17843: }
17844: }
17845: }
17846: }
17847: }
17848: }
1.1308 raeburn 17849: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17850: }
17851:
1.1101 raeburn 17852: sub symb_to_docspath {
1.1267 raeburn 17853: my ($symb,$navmapref) = @_;
17854: return unless ($symb && ref($navmapref));
1.1101 raeburn 17855: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17856: if ($resurl=~/\.(sequence|page)$/) {
17857: $mapurl=$resurl;
17858: } elsif ($resurl eq 'adm/navmaps') {
17859: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17860: }
17861: my $mapresobj;
1.1267 raeburn 17862: unless (ref($$navmapref)) {
17863: $$navmapref = Apache::lonnavmaps::navmap->new();
17864: }
17865: if (ref($$navmapref)) {
17866: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17867: }
17868: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17869: my $type=$2;
17870: my $path;
17871: if (ref($mapresobj)) {
17872: my $pcslist = $mapresobj->map_hierarchy();
17873: if ($pcslist ne '') {
17874: foreach my $pc (split(/,/,$pcslist)) {
17875: next if ($pc <= 1);
1.1267 raeburn 17876: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17877: if (ref($res)) {
17878: my $thisurl = $res->src();
17879: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17880: my $thistitle = $res->title();
17881: $path .= '&'.
17882: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17883: &escape($thistitle).
1.1101 raeburn 17884: ':'.$res->randompick().
17885: ':'.$res->randomout().
17886: ':'.$res->encrypted().
17887: ':'.$res->randomorder().
17888: ':'.$res->is_page();
17889: }
17890: }
17891: }
17892: $path =~ s/^\&//;
17893: my $maptitle = $mapresobj->title();
17894: if ($mapurl eq 'default') {
1.1129 raeburn 17895: $maptitle = 'Main Content';
1.1101 raeburn 17896: }
17897: $path .= (($path ne '')? '&' : '').
17898: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17899: &escape($maptitle).
1.1101 raeburn 17900: ':'.$mapresobj->randompick().
17901: ':'.$mapresobj->randomout().
17902: ':'.$mapresobj->encrypted().
17903: ':'.$mapresobj->randomorder().
17904: ':'.$mapresobj->is_page();
17905: } else {
17906: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17907: my $ispage = (($type eq 'page')? 1 : '');
17908: if ($mapurl eq 'default') {
1.1129 raeburn 17909: $maptitle = 'Main Content';
1.1101 raeburn 17910: }
17911: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17912: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17913: }
17914: unless ($mapurl eq 'default') {
17915: $path = 'default&'.
1.1146 raeburn 17916: &escape('Main Content').
1.1101 raeburn 17917: ':::::&'.$path;
17918: }
17919: return $path;
17920: }
17921:
1.1094 raeburn 17922: sub captcha_display {
1.1327 raeburn 17923: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17924: my ($output,$error);
1.1234 raeburn 17925: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17926: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17927: if ($captcha eq 'original') {
1.1094 raeburn 17928: $output = &create_captcha();
17929: unless ($output) {
1.1172 raeburn 17930: $error = 'captcha';
1.1094 raeburn 17931: }
17932: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17933: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17934: unless ($output) {
1.1172 raeburn 17935: $error = 'recaptcha';
1.1094 raeburn 17936: }
17937: }
1.1234 raeburn 17938: return ($output,$error,$captcha,$version);
1.1094 raeburn 17939: }
17940:
17941: sub captcha_response {
1.1327 raeburn 17942: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17943: my ($captcha_chk,$captcha_error);
1.1327 raeburn 17944: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17945: if ($captcha eq 'original') {
1.1094 raeburn 17946: ($captcha_chk,$captcha_error) = &check_captcha();
17947: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17948: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17949: } else {
17950: $captcha_chk = 1;
17951: }
17952: return ($captcha_chk,$captcha_error);
17953: }
17954:
17955: sub get_captcha_config {
1.1327 raeburn 17956: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 17957: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17958: my $hostname = &Apache::lonnet::hostname($lonhost);
17959: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17960: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17961: if ($context eq 'usercreation') {
17962: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17963: if (ref($domconfig{$context}) eq 'HASH') {
17964: $hashtocheck = $domconfig{$context}{'cancreate'};
17965: if (ref($hashtocheck) eq 'HASH') {
17966: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17967: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17968: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17969: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17970: }
17971: if ($privkey && $pubkey) {
17972: $captcha = 'recaptcha';
1.1234 raeburn 17973: $version = $hashtocheck->{'recaptchaversion'};
17974: if ($version ne '2') {
17975: $version = 1;
17976: }
1.1095 raeburn 17977: } else {
17978: $captcha = 'original';
17979: }
17980: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17981: $captcha = 'original';
17982: }
1.1094 raeburn 17983: }
1.1095 raeburn 17984: } else {
17985: $captcha = 'captcha';
17986: }
17987: } elsif ($context eq 'login') {
17988: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17989: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17990: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17991: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17992: if ($privkey && $pubkey) {
17993: $captcha = 'recaptcha';
1.1234 raeburn 17994: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17995: if ($version ne '2') {
17996: $version = 1;
17997: }
1.1095 raeburn 17998: } else {
17999: $captcha = 'original';
1.1094 raeburn 18000: }
1.1095 raeburn 18001: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18002: $captcha = 'original';
1.1094 raeburn 18003: }
1.1327 raeburn 18004: } elsif ($context eq 'passwords') {
18005: if ($dom_in_effect) {
18006: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18007: if ($passwdconf{'captcha'} eq 'recaptcha') {
18008: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18009: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18010: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18011: }
18012: if ($privkey && $pubkey) {
18013: $captcha = 'recaptcha';
18014: $version = $passwdconf{'recaptchaversion'};
18015: if ($version ne '2') {
18016: $version = 1;
18017: }
18018: } else {
18019: $captcha = 'original';
18020: }
18021: } elsif ($passwdconf{'captcha'} ne 'notused') {
18022: $captcha = 'original';
18023: }
18024: }
18025: }
1.1234 raeburn 18026: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18027: }
18028:
18029: sub create_captcha {
18030: my %captcha_params = &captcha_settings();
18031: my ($output,$maxtries,$tries) = ('',10,0);
18032: while ($tries < $maxtries) {
18033: $tries ++;
18034: my $captcha = Authen::Captcha->new (
18035: output_folder => $captcha_params{'output_dir'},
18036: data_folder => $captcha_params{'db_dir'},
18037: );
18038: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18039:
18040: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18041: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
18042: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18043: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
18044: '<br />'.
18045: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18046: last;
18047: }
18048: }
1.1323 raeburn 18049: if ($output eq '') {
18050: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18051: }
1.1094 raeburn 18052: return $output;
18053: }
18054:
18055: sub captcha_settings {
18056: my %captcha_params = (
18057: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18058: www_output_dir => "/captchaspool",
18059: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18060: numchars => '5',
18061: );
18062: return %captcha_params;
18063: }
18064:
18065: sub check_captcha {
18066: my ($captcha_chk,$captcha_error);
18067: my $code = $env{'form.code'};
18068: my $md5sum = $env{'form.crypt'};
18069: my %captcha_params = &captcha_settings();
18070: my $captcha = Authen::Captcha->new(
18071: output_folder => $captcha_params{'output_dir'},
18072: data_folder => $captcha_params{'db_dir'},
18073: );
1.1109 raeburn 18074: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18075: my %captcha_hash = (
18076: 0 => 'Code not checked (file error)',
18077: -1 => 'Failed: code expired',
18078: -2 => 'Failed: invalid code (not in database)',
18079: -3 => 'Failed: invalid code (code does not match crypt)',
18080: );
18081: if ($captcha_chk != 1) {
18082: $captcha_error = $captcha_hash{$captcha_chk}
18083: }
18084: return ($captcha_chk,$captcha_error);
18085: }
18086:
18087: sub create_recaptcha {
1.1234 raeburn 18088: my ($pubkey,$version) = @_;
18089: if ($version >= 2) {
18090: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
18091: } else {
18092: my $use_ssl;
18093: if ($ENV{'SERVER_PORT'} == 443) {
18094: $use_ssl = 1;
18095: }
18096: my $captcha = Captcha::reCAPTCHA->new;
18097: return $captcha->get_options_setter({theme => 'white'})."\n".
18098: $captcha->get_html($pubkey,undef,$use_ssl).
18099: &mt('If the text is hard to read, [_1] will replace them.',
18100: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18101: '<br /><br />';
18102: }
1.1094 raeburn 18103: }
18104:
18105: sub check_recaptcha {
1.1234 raeburn 18106: my ($privkey,$version) = @_;
1.1094 raeburn 18107: my $captcha_chk;
1.1234 raeburn 18108: if ($version >= 2) {
18109: my %info = (
18110: secret => $privkey,
18111: response => $env{'form.g-recaptcha-response'},
18112: remoteip => $ENV{'REMOTE_ADDR'},
18113: );
1.1280 raeburn 18114: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18115: $request->content(join('&',map {
18116: my $name = escape($_);
18117: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18118: ? join("&$name=", map {escape($_) } @{$info{$_}})
18119: : &escape($info{$_}) );
18120: } keys(%info)));
18121: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18122: if ($response->is_success) {
18123: my $data = JSON::DWIW->from_json($response->decoded_content);
18124: if (ref($data) eq 'HASH') {
18125: if ($data->{'success'}) {
18126: $captcha_chk = 1;
18127: }
18128: }
18129: }
18130: } else {
18131: my $captcha = Captcha::reCAPTCHA->new;
18132: my $captcha_result =
18133: $captcha->check_answer(
18134: $privkey,
18135: $ENV{'REMOTE_ADDR'},
18136: $env{'form.recaptcha_challenge_field'},
18137: $env{'form.recaptcha_response_field'},
18138: );
18139: if ($captcha_result->{is_valid}) {
18140: $captcha_chk = 1;
18141: }
1.1094 raeburn 18142: }
18143: return $captcha_chk;
18144: }
18145:
1.1174 raeburn 18146: sub emailusername_info {
1.1244 raeburn 18147: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18148: my %titles = &Apache::lonlocal::texthash (
18149: lastname => 'Last Name',
18150: firstname => 'First Name',
18151: institution => 'School/college/university',
18152: location => "School's city, state/province, country",
18153: web => "School's web address",
18154: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18155: id => 'Student/Employee ID',
1.1174 raeburn 18156: );
18157: return (\@fields,\%titles);
18158: }
18159:
1.1161 raeburn 18160: sub cleanup_html {
18161: my ($incoming) = @_;
18162: my $outgoing;
18163: if ($incoming ne '') {
18164: $outgoing = $incoming;
18165: $outgoing =~ s/;/;/g;
18166: $outgoing =~ s/\#/#/g;
18167: $outgoing =~ s/\&/&/g;
18168: $outgoing =~ s/</</g;
18169: $outgoing =~ s/>/>/g;
18170: $outgoing =~ s/\(/(/g;
18171: $outgoing =~ s/\)/)/g;
18172: $outgoing =~ s/"/"/g;
18173: $outgoing =~ s/'/'/g;
18174: $outgoing =~ s/\$/$/g;
18175: $outgoing =~ s{/}{/}g;
18176: $outgoing =~ s/=/=/g;
18177: $outgoing =~ s/\\/\/g
18178: }
18179: return $outgoing;
18180: }
18181:
1.1190 musolffc 18182: # Checks for critical messages and returns a redirect url if one exists.
18183: # $interval indicates how often to check for messages.
1.1282 raeburn 18184: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18185: sub critical_redirect {
1.1282 raeburn 18186: my ($interval,$context) = @_;
1.1190 musolffc 18187: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18188: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18189: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18190: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18191: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18192: if ($blocked) {
18193: my $checkrole = "cm./$cdom/$cnum";
18194: if ($env{'request.course.sec'} ne '') {
18195: $checkrole .= "/$env{'request.course.sec'}";
18196: }
18197: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18198: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18199: return;
18200: }
18201: }
18202: }
1.1190 musolffc 18203: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18204: $env{'user.name'});
18205: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18206: my $redirecturl;
1.1190 musolffc 18207: if ($what[0]) {
18208: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18209: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18210: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18211: return (1, $url);
1.1190 musolffc 18212: }
1.1191 raeburn 18213: }
18214: }
18215: return ();
1.1190 musolffc 18216: }
18217:
1.1174 raeburn 18218: # Use:
18219: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18220: #
18221: ##################################################
18222: # password associated functions #
18223: ##################################################
18224: sub des_keys {
18225: # Make a new key for DES encryption.
18226: # Each key has two parts which are returned separately.
18227: # Please note: Each key must be passed through the &hex function
18228: # before it is output to the web browser. The hex versions cannot
18229: # be used to decrypt.
18230: my @hexstr=('0','1','2','3','4','5','6','7',
18231: '8','9','a','b','c','d','e','f');
18232: my $lkey='';
18233: for (0..7) {
18234: $lkey.=$hexstr[rand(15)];
18235: }
18236: my $ukey='';
18237: for (0..7) {
18238: $ukey.=$hexstr[rand(15)];
18239: }
18240: return ($lkey,$ukey);
18241: }
18242:
18243: sub des_decrypt {
18244: my ($key,$cyphertext) = @_;
18245: my $keybin=pack("H16",$key);
18246: my $cypher;
18247: if ($Crypt::DES::VERSION>=2.03) {
18248: $cypher=new Crypt::DES $keybin;
18249: } else {
18250: $cypher=new DES $keybin;
18251: }
1.1233 raeburn 18252: my $plaintext='';
18253: my $cypherlength = length($cyphertext);
18254: my $numchunks = int($cypherlength/32);
18255: for (my $j=0; $j<$numchunks; $j++) {
18256: my $start = $j*32;
18257: my $cypherblock = substr($cyphertext,$start,32);
18258: my $chunk =
18259: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18260: $chunk .=
18261: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18262: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18263: $plaintext .= $chunk;
18264: }
1.1174 raeburn 18265: return $plaintext;
18266: }
18267:
1.1344 raeburn 18268: sub get_requested_shorturls {
1.1309 raeburn 18269: my ($cdom,$cnum,$navmap) = @_;
18270: return unless (ref($navmap));
1.1344 raeburn 18271: my ($numnew,$errors);
1.1309 raeburn 18272: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18273: if (@toshorten) {
18274: my (%maps,%resources,%titles);
18275: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18276: 'shorturls',$cdom,$cnum);
18277: if (keys(%resources)) {
1.1344 raeburn 18278: my %tocreate;
1.1309 raeburn 18279: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18280: my $symb = $resources{$item};
18281: if ($symb) {
18282: $tocreate{$cnum.'&'.$symb} = 1;
18283: }
18284: }
1.1344 raeburn 18285: if (keys(%tocreate)) {
18286: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18287: \%tocreate);
18288: }
1.1309 raeburn 18289: }
1.1344 raeburn 18290: }
18291: return ($numnew,$errors);
18292: }
18293:
18294: sub make_short_symbs {
18295: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18296: my ($numnew,@errors);
18297: if (ref($tocreateref) eq 'HASH') {
18298: my %tocreate = %{$tocreateref};
1.1309 raeburn 18299: if (keys(%tocreate)) {
18300: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18301: my $su = Short::URL->new(no_vowels => 1);
18302: my $init = '';
18303: my (%newunique,%addcourse,%courseonly,%failed);
18304: # get lock on tiny db
18305: my $now = time;
1.1344 raeburn 18306: if ($lockuser eq '') {
18307: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18308: }
1.1309 raeburn 18309: my $lockhash = {
1.1344 raeburn 18310: "lock\0$now" => $lockuser,
1.1309 raeburn 18311: };
18312: my $tries = 0;
18313: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18314: my ($code,$error);
18315: while (($gotlock ne 'ok') && ($tries<3)) {
18316: $tries ++;
18317: sleep 1;
1.1319 raeburn 18318: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18319: }
18320: if ($gotlock eq 'ok') {
18321: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18322: \%addcourse,\%courseonly,\%failed);
18323: if (keys(%failed)) {
18324: my $numfailed = scalar(keys(%failed));
18325: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18326: }
18327: if (keys(%newunique)) {
18328: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18329: if ($putres eq 'ok') {
18330: $numnew = scalar(keys(%newunique));
18331: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18332: unless ($newputres eq 'ok') {
18333: push(@errors,&mt('error: could not store course look-up of short URLs'));
18334: }
18335: } else {
18336: push(@errors,&mt('error: could not store unique six character URLs'));
18337: }
18338: }
18339: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18340: unless ($dellockres eq 'ok') {
18341: push(@errors,&mt('error: could not release lockfile'));
18342: }
18343: } else {
18344: push(@errors,&mt('error: could not obtain lockfile'));
18345: }
18346: if (keys(%courseonly)) {
18347: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18348: if ($result ne 'ok') {
18349: push(@errors,&mt('error: could not update course look-up of short URLs'));
18350: }
18351: }
18352: }
18353: }
18354: return ($numnew,\@errors);
18355: }
18356:
18357: sub shorten_symbs {
18358: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18359: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18360: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18361: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18362: my (%possibles,%collisions);
18363: foreach my $key (keys(%{$tocreate})) {
18364: my $num = String::CRC32::crc32($key);
18365: my $tiny = $su->encode($num,$init);
18366: if ($tiny) {
18367: $possibles{$tiny} = $key;
18368: }
18369: }
18370: if (!$init) {
18371: $init = 1;
18372: } else {
18373: $init ++;
18374: }
18375: if (keys(%possibles)) {
18376: my @posstiny = keys(%possibles);
18377: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18378: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18379: if (keys(%currtiny)) {
18380: foreach my $key (keys(%currtiny)) {
18381: next if ($currtiny{$key} eq '');
18382: if ($currtiny{$key} eq $possibles{$key}) {
18383: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18384: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18385: $courseonly->{$tsymb} = $key;
18386: }
18387: } else {
18388: $collisions{$possibles{$key}} = 1;
18389: }
18390: delete($possibles{$key});
18391: }
18392: }
18393: foreach my $key (keys(%possibles)) {
18394: $newunique->{$key} = $possibles{$key};
18395: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18396: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18397: $addcourse->{$tsymb} = $key;
18398: }
18399: }
18400: }
18401: if (keys(%collisions)) {
18402: if ($init <5) {
18403: if (!$init) {
18404: $init = 1;
18405: } else {
18406: $init ++;
18407: }
18408: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18409: $newunique,$addcourse,$courseonly,$failed);
18410: } else {
18411: foreach my $key (keys(%collisions)) {
18412: $failed->{$key} = 1;
18413: }
18414: }
18415: }
18416: return $init;
18417: }
18418:
1.1328 raeburn 18419: sub is_nonframeable {
1.1329 raeburn 18420: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18421: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18422: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18423:
18424: $remprotocol = lc($remprotocol);
18425: $remhost = lc($remhost);
18426: my $remport = 80;
18427: if ($remprotocol eq 'https') {
18428: $remport = 443;
18429: }
1.1330 raeburn 18430: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18431: if ($cached) {
18432: unless ($nocache) {
18433: if ($result) {
18434: return 1;
18435: } else {
18436: return 0;
18437: }
18438: }
18439: }
1.1328 raeburn 18440: my $uselink;
18441: my $request = new HTTP::Request('HEAD',$url);
18442: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18443: if ($response->is_success()) {
18444: my $secpolicy = lc($response->header('content-security-policy'));
18445: my $xframeop = lc($response->header('x-frame-options'));
18446: $secpolicy =~ s/^\s+|\s+$//g;
18447: $xframeop =~ s/^\s+|\s+$//g;
18448: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18449: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18450: my ($origin,$protocol,$port);
18451: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18452: $port = $ENV{'SERVER_PORT'};
18453: } else {
18454: $port = 80;
18455: }
18456: if ($absolute eq '') {
18457: $protocol = 'http:';
18458: if ($port == 443) {
18459: $protocol = 'https:';
18460: }
18461: $origin = $protocol.'//'.lc($hostname);
18462: } else {
18463: $origin = lc($absolute);
18464: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18465: }
18466: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18467: my $framepolicy = $1;
18468: $framepolicy =~ s/^\s+|\s+$//g;
18469: my @policies = split(/\s+/,$framepolicy);
18470: if (@policies) {
18471: if (grep(/^\Q'none'\E$/,@policies)) {
18472: $uselink = 1;
18473: } else {
18474: $uselink = 1;
18475: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18476: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18477: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18478: undef($uselink);
18479: }
18480: if ($uselink) {
18481: if (grep(/^\Q'self'\E$/,@policies)) {
18482: if (($origin ne '') && ($remotehost eq $origin)) {
18483: undef($uselink);
18484: }
18485: }
18486: }
18487: if ($uselink) {
18488: my @possok;
18489: if ($ip ne '') {
18490: push(@possok,$ip);
18491: }
18492: my $hoststr = '';
18493: foreach my $part (reverse(split(/\./,$hostname))) {
18494: if ($hoststr eq '') {
18495: $hoststr = $part;
18496: } else {
18497: $hoststr = "$part.$hoststr";
18498: }
18499: if ($hoststr eq $hostname) {
18500: push(@possok,$hostname);
18501: } else {
18502: push(@possok,"*.$hoststr");
18503: }
18504: }
18505: if (@possok) {
18506: foreach my $poss (@possok) {
18507: last if (!$uselink);
18508: foreach my $policy (@policies) {
18509: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18510: undef($uselink);
18511: last;
18512: }
18513: }
18514: }
18515: }
18516: }
18517: }
18518: }
18519: } elsif ($xframeop ne '') {
18520: $uselink = 1;
18521: my @policies = split(/\s*,\s*/,$xframeop);
18522: if (@policies) {
18523: unless (grep(/^deny$/,@policies)) {
18524: if ($origin ne '') {
18525: if (grep(/^sameorigin$/,@policies)) {
18526: if ($remotehost eq $origin) {
18527: undef($uselink);
18528: }
18529: }
18530: if ($uselink) {
18531: foreach my $policy (@policies) {
18532: if ($policy =~ /^allow-from\s*(.+)$/) {
18533: my $allowfrom = $1;
18534: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18535: undef($uselink);
18536: last;
18537: }
18538: }
18539: }
18540: }
18541: }
18542: }
18543: }
18544: }
18545: }
18546: }
1.1329 raeburn 18547: if ($nocache) {
18548: if ($cached) {
18549: my $devalidate;
18550: if ($uselink && !$result) {
18551: $devalidate = 1;
18552: } elsif (!$uselink && $result) {
18553: $devalidate = 1;
18554: }
18555: if ($devalidate) {
18556: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18557: }
18558: }
18559: } else {
18560: if ($uselink) {
18561: $result = 1;
18562: } else {
18563: $result = 0;
18564: }
18565: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18566: }
1.1328 raeburn 18567: return $uselink;
18568: }
18569:
1.112 bowersj2 18570: 1;
18571: __END__;
1.41 ng 18572:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>