Annotation of loncom/interface/loncommon.pm, revision 1.1380
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1380 ! raeburn 4: # $Id: loncommon.pm,v 1.1379 2022/05/27 04:35:36 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"';
1.1380 ! raeburn 1310: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
! 1311: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
! 1312: if (($env{'request.noversionuri'} eq '/adm/searchcat') &&
! 1313: ($env{'form.phase'} =~ /^(sort|run_search)$/)) {
! 1314: $target = ' target="_parent"';
! 1315: } else {
! 1316: $target = '';
! 1317: }
1.1378 raeburn 1318: }
1.1380 ! raeburn 1319: if ($text ne "") {
1.763 bisitz 1320: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1321: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1322: .$text.'</a>';
1.48 bowersj2 1323: }
1324:
1.763 bisitz 1325: # (Always) Add the graphic
1.179 matthew 1326: my $title = &mt('Online Help');
1.667 raeburn 1327: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1328: if ($imgid ne '') {
1329: $imgid = ' id="'.$imgid.'"';
1330: }
1.1314 raeburn 1331: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1332: .'<img src="'.$helpicon.'" border="0"'
1333: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1334: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1335: .' /></a>';
1336: if ($text ne "") {
1337: $template.='</span>';
1338: }
1.44 bowersj2 1339: return $template;
1340:
1.106 bowersj2 1341: }
1342:
1343: # This is a quicky function for Latex cheatsheet editing, since it
1344: # appears in at least four places
1345: sub helpLatexCheatsheet {
1.1037 www 1346: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1347: my $out;
1.106 bowersj2 1348: my $addOther = '';
1.732 raeburn 1349: if ($topic) {
1.1037 www 1350: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1351: }
1352: $out = '<span>' # Start cheatsheet
1353: .$addOther
1354: .'<span>'
1.1037 www 1355: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1356: .'</span> <span>'
1.1037 www 1357: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1358: .'</span>';
1.732 raeburn 1359: unless ($not_author) {
1.1186 kruse 1360: $out .= '<span>'
1361: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1362: .'</span> <span>'
1363: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1364: .'</span>';
1.732 raeburn 1365: }
1.763 bisitz 1366: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1367: return $out;
1.172 www 1368: }
1369:
1.430 albertel 1370: sub general_help {
1371: my $helptopic='Student_Intro';
1372: if ($env{'request.role'}=~/^(ca|au)/) {
1373: $helptopic='Authoring_Intro';
1.907 raeburn 1374: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1375: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1376: } elsif ($env{'request.role'}=~/^dc/) {
1377: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1378: }
1379: return $helptopic;
1380: }
1381:
1382: sub update_help_link {
1383: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1384: my $origurl = $ENV{'REQUEST_URI'};
1385: $origurl=~s|^/~|/priv/|;
1386: my $timestamp = time;
1387: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1388: $$datum = &escape($$datum);
1389: }
1390:
1391: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1392: my $output .= <<"ENDOUTPUT";
1393: <script type="text/javascript">
1.824 bisitz 1394: // <![CDATA[
1.430 albertel 1395: banner_link = '$banner_link';
1.824 bisitz 1396: // ]]>
1.430 albertel 1397: </script>
1398: ENDOUTPUT
1399: return $output;
1400: }
1401:
1402: # now just updates the help link and generates a blue icon
1.193 raeburn 1403: sub help_open_menu {
1.430 albertel 1404: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1405: = @_;
1.949 droeschl 1406: $stayOnPage = 1;
1.430 albertel 1407: my $output;
1408: if ($component_help) {
1409: if (!$text) {
1410: $output=&help_open_topic($component_help,undef,$stayOnPage,
1411: $width,$height);
1412: } else {
1413: my $help_text;
1414: $help_text=&unescape($topic);
1415: $output='<table><tr><td>'.
1416: &help_open_topic($component_help,$help_text,$stayOnPage,
1417: $width,$height).'</td></tr></table>';
1418: }
1419: }
1420: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1421: return $output.$banner_link;
1422: }
1423:
1424: sub top_nav_help {
1.1369 raeburn 1425: my ($text,$linkattr) = @_;
1.436 albertel 1426: $text = &mt($text);
1.949 droeschl 1427: my $stay_on_page = 1;
1428:
1.1168 raeburn 1429: my ($link,$banner_link);
1430: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1431: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1432: : "javascript:helpMenu('open')";
1433: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1434: }
1.201 raeburn 1435: my $title = &mt('Get help');
1.1168 raeburn 1436: if ($link) {
1437: return <<"END";
1.436 albertel 1438: $banner_link
1.1369 raeburn 1439: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1440: END
1.1168 raeburn 1441: } else {
1442: return ' '.$text.' ';
1443: }
1.436 albertel 1444: }
1445:
1446: sub help_menu_js {
1.1154 raeburn 1447: my ($httphost) = @_;
1.949 droeschl 1448: my $stayOnPage = 1;
1.436 albertel 1449: my $width = 620;
1450: my $height = 600;
1.430 albertel 1451: my $helptopic=&general_help();
1.1154 raeburn 1452: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1453: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1454: my $start_page =
1455: &Apache::loncommon::start_page('Help Menu', undef,
1456: {'frameset' => 1,
1457: 'js_ready' => 1,
1.1154 raeburn 1458: 'use_absolute' => $httphost,
1.331 albertel 1459: 'add_entries' => {
1.1168 raeburn 1460: 'border' => '0',
1.579 raeburn 1461: 'rows' => "110,*",},});
1.331 albertel 1462: my $end_page =
1463: &Apache::loncommon::end_page({'frameset' => 1,
1464: 'js_ready' => 1,});
1465:
1.436 albertel 1466: my $template .= <<"ENDTEMPLATE";
1467: <script type="text/javascript">
1.877 bisitz 1468: // <![CDATA[
1.253 albertel 1469: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1470: var banner_link = '';
1.243 raeburn 1471: function helpMenu(target) {
1472: var caller = this;
1473: if (target == 'open') {
1474: var newWindow = null;
1475: try {
1.262 albertel 1476: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1477: }
1478: catch(error) {
1479: writeHelp(caller);
1480: return;
1481: }
1482: if (newWindow) {
1483: caller = newWindow;
1484: }
1.193 raeburn 1485: }
1.243 raeburn 1486: writeHelp(caller);
1487: return;
1488: }
1489: function writeHelp(caller) {
1.1168 raeburn 1490: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1491: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1492: caller.document.close();
1493: caller.focus();
1.193 raeburn 1494: }
1.877 bisitz 1495: // END LON-CAPA Internal -->
1.253 albertel 1496: // ]]>
1.436 albertel 1497: </script>
1.193 raeburn 1498: ENDTEMPLATE
1499: return $template;
1500: }
1501:
1.172 www 1502: sub help_open_bug {
1503: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1504: unless ($env{'user.adv'}) { return ''; }
1.172 www 1505: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1506: $text = "" if (not defined $text);
1507: $stayOnPage=1;
1.184 albertel 1508: $width = 600 if (not defined $width);
1509: $height = 600 if (not defined $height);
1.172 www 1510:
1511: $topic=~s/\W+/\+/g;
1512: my $link='';
1513: my $template='';
1.379 albertel 1514: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1515: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1516: if (!$stayOnPage)
1517: {
1518: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1519: }
1520: else
1521: {
1522: $link = $url;
1523: }
1.1314 raeburn 1524:
1525: my $target = ' target="_top"';
1526: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1527: $target = '';
1528: }
1.1378 raeburn 1529: if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1530: $target = ' target="'.$env{'request.deeplink.target'}.'"';
1531: }
1.172 www 1532: # Add the text
1533: if ($text ne "")
1534: {
1535: $template .=
1536: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1537: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1538: }
1539:
1540: # Add the graphic
1.179 matthew 1541: my $title = &mt('Report a Bug');
1.215 albertel 1542: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1543: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1544: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1545: ENDTEMPLATE
1546: if ($text ne '') { $template.='</td></tr></table>' };
1547: return $template;
1548:
1549: }
1550:
1551: sub help_open_faq {
1552: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1553: unless ($env{'user.adv'}) { return ''; }
1.172 www 1554: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1555: $text = "" if (not defined $text);
1556: $stayOnPage=1;
1557: $width = 350 if (not defined $width);
1558: $height = 400 if (not defined $height);
1559:
1560: $topic=~s/\W+/\+/g;
1561: my $link='';
1562: my $template='';
1563: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1564: if (!$stayOnPage)
1565: {
1566: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1567: }
1568: else
1569: {
1570: $link = $url;
1571: }
1572:
1573: # Add the text
1574: if ($text ne "")
1575: {
1576: $template .=
1.173 www 1577: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1578: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1579: }
1580:
1581: # Add the graphic
1.179 matthew 1582: my $title = &mt('View the FAQ');
1.215 albertel 1583: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1584: $template .= <<"ENDTEMPLATE";
1.436 albertel 1585: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1586: ENDTEMPLATE
1587: if ($text ne '') { $template.='</td></tr></table>' };
1588: return $template;
1589:
1.44 bowersj2 1590: }
1.37 matthew 1591:
1.180 matthew 1592: ###############################################################
1593: ###############################################################
1594:
1.45 matthew 1595: =pod
1596:
1.648 raeburn 1597: =item * &change_content_javascript():
1.256 matthew 1598:
1599: This and the next function allow you to create small sections of an
1600: otherwise static HTML page that you can update on the fly with
1601: Javascript, even in Netscape 4.
1602:
1603: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1604: must be written to the HTML page once. It will prove the Javascript
1605: function "change(name, content)". Calling the change function with the
1606: name of the section
1607: you want to update, matching the name passed to C<changable_area>, and
1608: the new content you want to put in there, will put the content into
1609: that area.
1610:
1611: B<Note>: Netscape 4 only reserves enough space for the changable area
1612: to contain room for the original contents. You need to "make space"
1613: for whatever changes you wish to make, and be B<sure> to check your
1614: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1615: it's adequate for updating a one-line status display, but little more.
1616: This script will set the space to 100% width, so you only need to
1617: worry about height in Netscape 4.
1618:
1619: Modern browsers are much less limiting, and if you can commit to the
1620: user not using Netscape 4, this feature may be used freely with
1621: pretty much any HTML.
1622:
1623: =cut
1624:
1625: sub change_content_javascript {
1626: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1627: if ($env{'browser.type'} eq 'netscape' &&
1628: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1629: return (<<NETSCAPE4);
1630: function change(name, content) {
1631: doc = document.layers[name+"___escape"].layers[0].document;
1632: doc.open();
1633: doc.write(content);
1634: doc.close();
1635: }
1636: NETSCAPE4
1637: } else {
1638: # Otherwise, we need to use semi-standards-compliant code
1639: # (technically, "innerHTML" isn't standard but the equivalent
1640: # is really scary, and every useful browser supports it
1641: return (<<DOMBASED);
1642: function change(name, content) {
1643: element = document.getElementById(name);
1644: element.innerHTML = content;
1645: }
1646: DOMBASED
1647: }
1648: }
1649:
1650: =pod
1651:
1.648 raeburn 1652: =item * &changable_area($name,$origContent):
1.256 matthew 1653:
1654: This provides a "changable area" that can be modified on the fly via
1655: the Javascript code provided in C<change_content_javascript>. $name is
1656: the name you will use to reference the area later; do not repeat the
1657: same name on a given HTML page more then once. $origContent is what
1658: the area will originally contain, which can be left blank.
1659:
1660: =cut
1661:
1662: sub changable_area {
1663: my ($name, $origContent) = @_;
1664:
1.258 albertel 1665: if ($env{'browser.type'} eq 'netscape' &&
1666: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1667: # If this is netscape 4, we need to use the Layer tag
1668: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1669: } else {
1670: return "<span id='$name'>$origContent</span>";
1671: }
1672: }
1673:
1674: =pod
1675:
1.648 raeburn 1676: =item * &viewport_geometry_js
1.590 raeburn 1677:
1678: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1679:
1680: =cut
1681:
1682:
1683: sub viewport_geometry_js {
1684: return <<"GEOMETRY";
1685: var Geometry = {};
1686: function init_geometry() {
1687: if (Geometry.init) { return };
1688: Geometry.init=1;
1689: if (window.innerHeight) {
1690: Geometry.getViewportHeight = function() { return window.innerHeight; };
1691: Geometry.getViewportWidth = function() { return window.innerWidth; };
1692: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1693: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1694: }
1695: else if (document.documentElement && document.documentElement.clientHeight) {
1696: Geometry.getViewportHeight =
1697: function() { return document.documentElement.clientHeight; };
1698: Geometry.getViewportWidth =
1699: function() { return document.documentElement.clientWidth; };
1700:
1701: Geometry.getHorizontalScroll =
1702: function() { return document.documentElement.scrollLeft; };
1703: Geometry.getVerticalScroll =
1704: function() { return document.documentElement.scrollTop; };
1705: }
1706: else if (document.body.clientHeight) {
1707: Geometry.getViewportHeight =
1708: function() { return document.body.clientHeight; };
1709: Geometry.getViewportWidth =
1710: function() { return document.body.clientWidth; };
1711: Geometry.getHorizontalScroll =
1712: function() { return document.body.scrollLeft; };
1713: Geometry.getVerticalScroll =
1714: function() { return document.body.scrollTop; };
1715: }
1716: }
1717:
1718: GEOMETRY
1719: }
1720:
1721: =pod
1722:
1.648 raeburn 1723: =item * &viewport_size_js()
1.590 raeburn 1724:
1725: 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.
1726:
1727: =cut
1728:
1729: sub viewport_size_js {
1730: my $geometry = &viewport_geometry_js();
1731: return <<"DIMS";
1732:
1733: $geometry
1734:
1735: function getViewportDims(width,height) {
1736: init_geometry();
1737: width.value = Geometry.getViewportWidth();
1738: height.value = Geometry.getViewportHeight();
1739: return;
1740: }
1741:
1742: DIMS
1743: }
1744:
1745: =pod
1746:
1.648 raeburn 1747: =item * &resize_textarea_js()
1.565 albertel 1748:
1749: emits the needed javascript to resize a textarea to be as big as possible
1750:
1751: creates a function resize_textrea that takes two IDs first should be
1752: the id of the element to resize, second should be the id of a div that
1753: surrounds everything that comes after the textarea, this routine needs
1754: to be attached to the <body> for the onload and onresize events.
1755:
1.648 raeburn 1756: =back
1.565 albertel 1757:
1758: =cut
1759:
1760: sub resize_textarea_js {
1.590 raeburn 1761: my $geometry = &viewport_geometry_js();
1.565 albertel 1762: return <<"RESIZE";
1763: <script type="text/javascript">
1.824 bisitz 1764: // <![CDATA[
1.590 raeburn 1765: $geometry
1.565 albertel 1766:
1.588 albertel 1767: function getX(element) {
1768: var x = 0;
1769: while (element) {
1770: x += element.offsetLeft;
1771: element = element.offsetParent;
1772: }
1773: return x;
1774: }
1775: function getY(element) {
1776: var y = 0;
1777: while (element) {
1778: y += element.offsetTop;
1779: element = element.offsetParent;
1780: }
1781: return y;
1782: }
1783:
1784:
1.565 albertel 1785: function resize_textarea(textarea_id,bottom_id) {
1786: init_geometry();
1787: var textarea = document.getElementById(textarea_id);
1788: //alert(textarea);
1789:
1.588 albertel 1790: var textarea_top = getY(textarea);
1.565 albertel 1791: var textarea_height = textarea.offsetHeight;
1792: var bottom = document.getElementById(bottom_id);
1.588 albertel 1793: var bottom_top = getY(bottom);
1.565 albertel 1794: var bottom_height = bottom.offsetHeight;
1795: var window_height = Geometry.getViewportHeight();
1.588 albertel 1796: var fudge = 23;
1.565 albertel 1797: var new_height = window_height-fudge-textarea_top-bottom_height;
1798: if (new_height < 300) {
1799: new_height = 300;
1800: }
1801: textarea.style.height=new_height+'px';
1802: }
1.824 bisitz 1803: // ]]>
1.565 albertel 1804: </script>
1805: RESIZE
1806:
1807: }
1808:
1.1205 golterma 1809: sub colorfuleditor_js {
1.1248 raeburn 1810: my $browse_or_search;
1811: my $respath;
1812: my ($cnum,$cdom) = &crsauthor_url();
1813: if ($cnum) {
1814: $respath = "/res/$cdom/$cnum/";
1815: my %js_lt = &Apache::lonlocal::texthash(
1816: sunm => 'Sub-directory name',
1817: save => 'Save page to make this permanent',
1818: );
1819: &js_escape(\%js_lt);
1820: $browse_or_search = <<"END";
1821:
1822: function toggleChooser(form,element,titleid,only,search) {
1823: var disp = 'none';
1824: if (document.getElementById('chooser_'+element)) {
1825: var curr = document.getElementById('chooser_'+element).style.display;
1826: if (curr == 'none') {
1827: disp='inline';
1828: if (form.elements['chooser_'+element].length) {
1829: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1830: form.elements['chooser_'+element][i].checked = false;
1831: }
1832: }
1833: toggleResImport(form,element);
1834: }
1835: document.getElementById('chooser_'+element).style.display = disp;
1836: }
1837: }
1838:
1839: function toggleCrsFile(form,element,numdirs) {
1840: if (document.getElementById('chooser_'+element+'_crsres')) {
1841: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1842: if (curr == 'none') {
1843: if (numdirs) {
1844: form.elements['coursepath_'+element].selectedIndex = 0;
1845: if (numdirs > 1) {
1846: window['select1'+element+'_changed']();
1847: }
1848: }
1849: }
1850: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1851:
1852: }
1853: if (document.getElementById('chooser_'+element+'_upload')) {
1854: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1855: if (document.getElementById('uploadcrsres_'+element)) {
1856: document.getElementById('uploadcrsres_'+element).value = '';
1857: }
1858: }
1859: return;
1860: }
1861:
1862: function toggleCrsUpload(form,element,numcrsdirs) {
1863: if (document.getElementById('chooser_'+element+'_crsres')) {
1864: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1865: }
1866: if (document.getElementById('chooser_'+element+'_upload')) {
1867: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1868: if (curr == 'none') {
1869: if (numcrsdirs) {
1870: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1871: form.elements['newsubdir_'+element][0].checked = true;
1872: toggleNewsubdir(form,element);
1873: }
1874: }
1875: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1876: }
1877: return;
1878: }
1879:
1880: function toggleResImport(form,element) {
1881: var choices = new Array('crsres','upload');
1882: for (var i=0; i<choices.length; i++) {
1883: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1884: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1885: }
1886: }
1887: }
1888:
1889: function toggleNewsubdir(form,element) {
1890: var newsub = form.elements['newsubdir_'+element];
1891: if (newsub) {
1892: if (newsub.length) {
1893: for (var j=0; j<newsub.length; j++) {
1894: if (newsub[j].checked) {
1895: if (document.getElementById('newsubdirname_'+element)) {
1896: if (newsub[j].value == '1') {
1897: document.getElementById('newsubdirname_'+element).type = "text";
1898: if (document.getElementById('newsubdir_'+element)) {
1899: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1900: }
1901: } else {
1902: document.getElementById('newsubdirname_'+element).type = "hidden";
1903: document.getElementById('newsubdirname_'+element).value = "";
1904: document.getElementById('newsubdir_'+element).innerHTML = "";
1905: }
1906: }
1907: break;
1908: }
1909: }
1910: }
1911: }
1912: }
1913:
1914: function updateCrsFile(form,element) {
1915: var directory = form.elements['coursepath_'+element];
1916: var filename = form.elements['coursefile_'+element];
1917: var path = directory.options[directory.selectedIndex].value;
1918: var file = filename.options[filename.selectedIndex].value;
1919: form.elements[element].value = '$respath';
1920: if (path == '/') {
1921: form.elements[element].value += file;
1922: } else {
1923: form.elements[element].value += path+'/'+file;
1924: }
1925: unClean();
1926: if (document.getElementById('previewimg_'+element)) {
1927: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1928: var newsrc = document.getElementById('previewimg_'+element).src;
1929: }
1930: if (document.getElementById('showimg_'+element)) {
1931: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1932: }
1933: toggleChooser(form,element);
1934: return;
1935: }
1936:
1937: function uploadDone(suffix,name) {
1938: if (name) {
1939: document.forms["lonhomework"].elements[suffix].value = name;
1940: unClean();
1941: toggleChooser(document.forms["lonhomework"],suffix);
1942: }
1943: }
1944:
1945: \$(document).ready(function(){
1946:
1947: \$(document).delegate('form :submit', 'click', function( event ) {
1948: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1949: var buttonId = this.id;
1950: var suffix = buttonId.toString();
1951: suffix = suffix.replace(/^crsupload_/,'');
1952: event.preventDefault();
1953: document.lonhomework.target = 'crsupload_target_'+suffix;
1954: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1955: \$(this.form).submit();
1956: document.lonhomework.target = '';
1957: if (document.getElementById('crsuploadto_'+suffix)) {
1958: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1959: }
1960: return false;
1961: }
1962: });
1963: });
1964: END
1965: }
1.1205 golterma 1966: return <<"COLORFULEDIT"
1967: <script type="text/javascript">
1968: // <![CDATA[>
1969: function fold_box(curDepth, lastresource){
1970:
1971: // we need a list because there can be several blocks you need to fold in one tag
1972: var block = document.getElementsByName('foldblock_'+curDepth);
1973: // but there is only one folding button per tag
1974: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1975:
1976: if(block.item(0).style.display == 'none'){
1977:
1978: foldbutton.value = '@{[&mt("Hide")]}';
1979: for (i = 0; i < block.length; i++){
1980: block.item(i).style.display = '';
1981: }
1982: }else{
1983:
1984: foldbutton.value = '@{[&mt("Show")]}';
1985: for (i = 0; i < block.length; i++){
1986: // block.item(i).style.visibility = 'collapse';
1987: block.item(i).style.display = 'none';
1988: }
1989: };
1990: saveState(lastresource);
1991: }
1992:
1993: function saveState (lastresource) {
1994:
1995: var tag_list = getTagList();
1996: if(tag_list != null){
1997: var timestamp = new Date().getTime();
1998: var key = lastresource;
1999:
2000: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2001: // starting with timestamp
2002: var value = timestamp+';';
2003:
2004: // building the list of key-value pairs
2005: for(var i = 0; i < tag_list.length; i++){
2006: value += tag_list[i]+',';
2007: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2008: }
2009:
2010: // only iterate whole storage if nothing to override
2011: if(localStorage.getItem(key) == null){
2012:
2013: // prevent storage from growing large
2014: if(localStorage.length > 50){
2015: var regex_getTimestamp = /^(?:\d)+;/;
2016: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2017: var oldest_key;
2018:
2019: for(var i = 1; i < localStorage.length; i++){
2020: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2021: oldest_key = localStorage.key(i);
2022: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2023: }
2024: }
2025: localStorage.removeItem(oldest_key);
2026: }
2027: }
2028: localStorage.setItem(key,value);
2029: }
2030: }
2031:
2032: // restore folding status of blocks (on page load)
2033: function restoreState (lastresource) {
2034: if(localStorage.getItem(lastresource) != null){
2035: var key = lastresource;
2036: var value = localStorage.getItem(key);
2037: var regex_delTimestamp = /^\d+;/;
2038:
2039: value.replace(regex_delTimestamp, '');
2040:
2041: var valueArr = value.split(';');
2042: var pairs;
2043: var elements;
2044: for (var i = 0; i < valueArr.length; i++){
2045: pairs = valueArr[i].split(',');
2046: elements = document.getElementsByName(pairs[0]);
2047:
2048: for (var j = 0; j < elements.length; j++){
2049: elements[j].style.display = pairs[1];
2050: if (pairs[1] == "none"){
2051: var regex_id = /([_\\d]+)\$/;
2052: regex_id.exec(pairs[0]);
2053: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2054: }
2055: }
2056: }
2057: }
2058: }
2059:
2060: function getTagList () {
2061:
2062: var stringToSearch = document.lonhomework.innerHTML;
2063:
2064: var ret = new Array();
2065: var regex_findBlock = /(foldblock_.*?)"/g;
2066: var tag_list = stringToSearch.match(regex_findBlock);
2067:
2068: if(tag_list != null){
2069: for(var i = 0; i < tag_list.length; i++){
2070: ret.push(tag_list[i].replace(/"/, ''));
2071: }
2072: }
2073: return ret;
2074: }
2075:
2076: function saveScrollPosition (resource) {
2077: var tag_list = getTagList();
2078:
2079: // we dont always want to jump to the first block
2080: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2081: if(\$(window).scrollTop() > 170){
2082: if(tag_list != null){
2083: var result;
2084: for(var i = 0; i < tag_list.length; i++){
2085: if(isElementInViewport(tag_list[i])){
2086: result += tag_list[i]+';';
2087: }
2088: }
2089: sessionStorage.setItem('anchor_'+resource, result);
2090: }
2091: } else {
2092: // we dont need to save zero, just delete the item to leave everything tidy
2093: sessionStorage.removeItem('anchor_'+resource);
2094: }
2095: }
2096:
2097: function restoreScrollPosition(resource){
2098:
2099: var elem = sessionStorage.getItem('anchor_'+resource);
2100: if(elem != null){
2101: var tag_list = elem.split(';');
2102: var elem_list;
2103:
2104: for(var i = 0; i < tag_list.length; i++){
2105: elem_list = document.getElementsByName(tag_list[i]);
2106:
2107: if(elem_list.length > 0){
2108: elem = elem_list[0];
2109: break;
2110: }
2111: }
2112: elem.scrollIntoView();
2113: }
2114: }
2115:
2116: function isElementInViewport(el) {
2117:
2118: // change to last element instead of first
2119: var elem = document.getElementsByName(el);
2120: var rect = elem[0].getBoundingClientRect();
2121:
2122: return (
2123: rect.top >= 0 &&
2124: rect.left >= 0 &&
2125: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2126: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2127: );
2128: }
2129:
2130: function autosize(depth){
2131: var cmInst = window['cm'+depth];
2132: var fitsizeButton = document.getElementById('fitsize'+depth);
2133:
2134: // is fixed size, switching to dynamic
2135: if (sessionStorage.getItem("autosized_"+depth) == null) {
2136: cmInst.setSize("","auto");
2137: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2138: sessionStorage.setItem("autosized_"+depth, "yes");
2139:
2140: // is dynamic size, switching to fixed
2141: } else {
2142: cmInst.setSize("","300px");
2143: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2144: sessionStorage.removeItem("autosized_"+depth);
2145: }
2146: }
2147:
1.1248 raeburn 2148: $browse_or_search
1.1205 golterma 2149:
2150: // ]]>
2151: </script>
2152: COLORFULEDIT
2153: }
2154:
2155: sub xmleditor_js {
2156: return <<XMLEDIT
2157: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2158: <script type="text/javascript">
2159: // <![CDATA[>
2160:
2161: function saveScrollPosition (resource) {
2162:
2163: var scrollPos = \$(window).scrollTop();
2164: sessionStorage.setItem(resource,scrollPos);
2165: }
2166:
2167: function restoreScrollPosition(resource){
2168:
2169: var scrollPos = sessionStorage.getItem(resource);
2170: \$(window).scrollTop(scrollPos);
2171: }
2172:
2173: // unless internet explorer
2174: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2175:
2176: \$(document).ready(function() {
2177: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2178: });
2179: }
2180:
2181: // inserts text at cursor position into codemirror (xml editor only)
2182: function insertText(text){
2183: cm.focus();
2184: var curPos = cm.getCursor();
2185: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2186: }
2187: // ]]>
2188: </script>
2189: XMLEDIT
2190: }
2191:
2192: sub insert_folding_button {
2193: my $curDepth = $Apache::lonxml::curdepth;
2194: my $lastresource = $env{'request.ambiguous'};
2195:
2196: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2197: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2198: }
2199:
1.1248 raeburn 2200: sub crsauthor_url {
2201: my ($url) = @_;
2202: if ($url eq '') {
2203: $url = $ENV{'REQUEST_URI'};
2204: }
2205: my ($cnum,$cdom);
2206: if ($env{'request.course.id'}) {
2207: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2208: if ($audom ne '' && $auname ne '') {
2209: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2210: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2211: $cnum = $auname;
2212: $cdom = $audom;
2213: }
2214: }
2215: }
2216: return ($cnum,$cdom);
2217: }
2218:
2219: sub import_crsauthor_form {
1.1265 raeburn 2220: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2221: return (0) unless ($env{'request.course.id'});
2222: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2223: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2224: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2225: return (0) unless (($cnum ne '') && ($cdom ne ''));
2226: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2227: my @ids=&Apache::lonnet::current_machine_ids();
2228: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2229:
2230: if (grep(/^\Q$crshome\E$/,@ids)) {
2231: $is_home = 1;
2232: }
2233: $relpath = "/priv/$cdom/$cnum";
2234: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2235: my %lt = &Apache::lonlocal::texthash (
2236: fnam => 'Filename',
2237: dire => 'Directory',
2238: );
2239: my $numdirs = scalar(keys(%files));
2240: my (%possexts,$singledir,@singledirfiles);
2241: if ($only) {
2242: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2243: }
2244: my (%nonemptydirs,$possdirs);
2245: if ($numdirs > 1) {
2246: my @order;
2247: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2248: if (ref($files{$key}) eq 'HASH') {
2249: my $shown = $key;
2250: if ($key eq '') {
2251: $shown = '/';
2252: }
2253: my @ordered = ();
2254: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2255: next if ($file =~ /\.rights$/);
1.1248 raeburn 2256: if ($only) {
2257: my ($ext) = ($file =~ /\.([^.]+)$/);
2258: unless ($possexts{lc($ext)}) {
2259: next;
2260: }
2261: }
2262: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2263: push(@ordered,$file);
2264: }
2265: if (@ordered) {
2266: push(@order,$key);
2267: $nonemptydirs{$key} = 1;
2268: $selimport_menus{$key}->{'text'} = $shown;
2269: $selimport_menus{$key}->{'default'} = '';
2270: $selimport_menus{$key}->{'select2'}->{''} = '';
2271: $selimport_menus{$key}->{'order'} = \@ordered;
2272: }
2273: }
2274: }
2275: $possdirs = scalar(keys(%nonemptydirs));
2276: if ($possdirs > 1) {
2277: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2278: $output = $lt{'dire'}.
2279: &linked_select_forms($form,'<br />'.
2280: $lt{'fnam'},'',
2281: $firstselectname,$secondselectname,
2282: \%selimport_menus,\@order,
2283: $onchangefirst,'',$suffix).'<br />';
2284: } elsif ($possdirs == 1) {
2285: $singledir = (keys(%nonemptydirs))[0];
2286: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2287: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2288: }
2289: delete($selimport_menus{$singledir});
2290: }
2291: } elsif ($numdirs == 1) {
2292: $singledir = (keys(%files))[0];
2293: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2294: if ($only) {
2295: my ($ext) = ($file =~ /\.([^.]+)$/);
2296: unless ($possexts{lc($ext)}) {
2297: next;
2298: }
1.1315 raeburn 2299: } else {
2300: next if ($file =~ /\.rights$/);
1.1248 raeburn 2301: }
2302: push(@singledirfiles,$file);
2303: }
2304: if (@singledirfiles) {
1.1315 raeburn 2305: $possdirs = 1;
1.1248 raeburn 2306: }
2307: }
2308: if (($possdirs == 1) && (@singledirfiles)) {
2309: my $showdir = $singledir;
2310: if ($singledir eq '') {
2311: $showdir = '/';
2312: }
2313: $output = $lt{'dire'}.
2314: '<select name="'.$firstselectname.'">'.
2315: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2316: '</select><br />'.
2317: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2318: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2319: foreach my $file (@singledirfiles) {
2320: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2321: }
2322: $output .= '</select><br />'."\n";
2323: }
2324: return ($possdirs,$output);
2325: }
2326:
1.565 albertel 2327: =pod
2328:
1.256 matthew 2329: =head1 Excel and CSV file utility routines
2330:
2331: =cut
2332:
2333: ###############################################################
2334: ###############################################################
2335:
2336: =pod
2337:
1.1162 raeburn 2338: =over 4
2339:
1.648 raeburn 2340: =item * &csv_translate($text)
1.37 matthew 2341:
1.185 www 2342: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2343: format.
2344:
2345: =cut
2346:
1.180 matthew 2347: ###############################################################
2348: ###############################################################
1.37 matthew 2349: sub csv_translate {
2350: my $text = shift;
2351: $text =~ s/\"/\"\"/g;
1.209 albertel 2352: $text =~ s/\n/ /g;
1.37 matthew 2353: return $text;
2354: }
1.180 matthew 2355:
2356: ###############################################################
2357: ###############################################################
2358:
2359: =pod
2360:
1.648 raeburn 2361: =item * &define_excel_formats()
1.180 matthew 2362:
2363: Define some commonly used Excel cell formats.
2364:
2365: Currently supported formats:
2366:
2367: =over 4
2368:
2369: =item header
2370:
2371: =item bold
2372:
2373: =item h1
2374:
2375: =item h2
2376:
2377: =item h3
2378:
1.256 matthew 2379: =item h4
2380:
2381: =item i
2382:
1.180 matthew 2383: =item date
2384:
2385: =back
2386:
2387: Inputs: $workbook
2388:
2389: Returns: $format, a hash reference.
2390:
1.1057 foxr 2391:
1.180 matthew 2392: =cut
2393:
2394: ###############################################################
2395: ###############################################################
2396: sub define_excel_formats {
2397: my ($workbook) = @_;
2398: my $format;
2399: $format->{'header'} = $workbook->add_format(bold => 1,
2400: bottom => 1,
2401: align => 'center');
2402: $format->{'bold'} = $workbook->add_format(bold=>1);
2403: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2404: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2405: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2406: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2407: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2408: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2409: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2410: return $format;
2411: }
2412:
2413: ###############################################################
2414: ###############################################################
1.113 bowersj2 2415:
2416: =pod
2417:
1.648 raeburn 2418: =item * &create_workbook()
1.255 matthew 2419:
2420: Create an Excel worksheet. If it fails, output message on the
2421: request object and return undefs.
2422:
2423: Inputs: Apache request object
2424:
2425: Returns (undef) on failure,
2426: Excel worksheet object, scalar with filename, and formats
2427: from &Apache::loncommon::define_excel_formats on success
2428:
2429: =cut
2430:
2431: ###############################################################
2432: ###############################################################
2433: sub create_workbook {
2434: my ($r) = @_;
2435: #
2436: # Create the excel spreadsheet
2437: my $filename = '/prtspool/'.
1.258 albertel 2438: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2439: time.'_'.rand(1000000000).'.xls';
2440: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2441: if (! defined($workbook)) {
2442: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2443: $r->print(
2444: '<p class="LC_error">'
2445: .&mt('Problems occurred in creating the new Excel file.')
2446: .' '.&mt('This error has been logged.')
2447: .' '.&mt('Please alert your LON-CAPA administrator.')
2448: .'</p>'
2449: );
1.255 matthew 2450: return (undef);
2451: }
2452: #
1.1014 foxr 2453: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2454: #
2455: my $format = &Apache::loncommon::define_excel_formats($workbook);
2456: return ($workbook,$filename,$format);
2457: }
2458:
2459: ###############################################################
2460: ###############################################################
2461:
2462: =pod
2463:
1.648 raeburn 2464: =item * &create_text_file()
1.113 bowersj2 2465:
1.542 raeburn 2466: Create a file to write to and eventually make available to the user.
1.256 matthew 2467: If file creation fails, outputs an error message on the request object and
2468: return undefs.
1.113 bowersj2 2469:
1.256 matthew 2470: Inputs: Apache request object, and file suffix
1.113 bowersj2 2471:
1.256 matthew 2472: Returns (undef) on failure,
2473: Filehandle and filename on success.
1.113 bowersj2 2474:
2475: =cut
2476:
1.256 matthew 2477: ###############################################################
2478: ###############################################################
2479: sub create_text_file {
2480: my ($r,$suffix) = @_;
2481: if (! defined($suffix)) { $suffix = 'txt'; };
2482: my $fh;
2483: my $filename = '/prtspool/'.
1.258 albertel 2484: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2485: time.'_'.rand(1000000000).'.'.$suffix;
2486: $fh = Apache::File->new('>/home/httpd'.$filename);
2487: if (! defined($fh)) {
2488: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2489: $r->print(
2490: '<p class="LC_error">'
2491: .&mt('Problems occurred in creating the output file.')
2492: .' '.&mt('This error has been logged.')
2493: .' '.&mt('Please alert your LON-CAPA administrator.')
2494: .'</p>'
2495: );
1.113 bowersj2 2496: }
1.256 matthew 2497: return ($fh,$filename)
1.113 bowersj2 2498: }
2499:
2500:
1.256 matthew 2501: =pod
1.113 bowersj2 2502:
2503: =back
2504:
2505: =cut
1.37 matthew 2506:
2507: ###############################################################
1.33 matthew 2508: ## Home server <option> list generating code ##
2509: ###############################################################
1.35 matthew 2510:
1.169 www 2511: # ------------------------------------------
2512:
2513: sub domain_select {
1.1289 raeburn 2514: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2515: my @possdoms;
2516: if (ref($incdoms) eq 'ARRAY') {
2517: @possdoms = @{$incdoms};
2518: } else {
2519: @possdoms = &Apache::lonnet::all_domains();
2520: }
2521:
1.169 www 2522: my %domains=map {
1.514 albertel 2523: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2524: } @possdoms;
2525:
2526: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2527: foreach my $dom (@{$excdoms}) {
2528: delete($domains{$dom});
2529: }
2530: }
2531:
1.169 www 2532: if ($multiple) {
2533: $domains{''}=&mt('Any domain');
1.550 albertel 2534: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2535: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2536: } else {
1.550 albertel 2537: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2538: return &select_form($name,$value,\%domains);
1.169 www 2539: }
2540: }
2541:
1.282 albertel 2542: #-------------------------------------------
2543:
2544: =pod
2545:
1.519 raeburn 2546: =head1 Routines for form select boxes
2547:
2548: =over 4
2549:
1.648 raeburn 2550: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2551:
2552: Returns a string containing a <select> element int multiple mode
2553:
2554:
2555: Args:
2556: $name - name of the <select> element
1.506 raeburn 2557: $value - scalar or array ref of values that should already be selected
1.282 albertel 2558: $size - number of rows long the select element is
1.283 albertel 2559: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2560: (shown text should already have been &mt())
1.506 raeburn 2561: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2562:
1.282 albertel 2563: =cut
2564:
2565: #-------------------------------------------
1.169 www 2566: sub multiple_select_form {
1.284 albertel 2567: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2568: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2569: my $output='';
1.191 matthew 2570: if (! defined($size)) {
2571: $size = 4;
1.283 albertel 2572: if (scalar(keys(%$hash))<4) {
2573: $size = scalar(keys(%$hash));
1.191 matthew 2574: }
2575: }
1.734 bisitz 2576: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2577: my @order;
1.506 raeburn 2578: if (ref($order) eq 'ARRAY') {
2579: @order = @{$order};
2580: } else {
2581: @order = sort(keys(%$hash));
1.501 banghart 2582: }
2583: if (exists($$hash{'select_form_order'})) {
2584: @order = @{$$hash{'select_form_order'}};
2585: }
2586:
1.284 albertel 2587: foreach my $key (@order) {
1.356 albertel 2588: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2589: $output.='selected="selected" ' if ($selected{$key});
2590: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2591: }
2592: $output.="</select>\n";
2593: return $output;
2594: }
2595:
1.88 www 2596: #-------------------------------------------
2597:
2598: =pod
2599:
1.1254 raeburn 2600: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2601:
2602: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2603: allow a user to select options from a ref to a hash containing:
2604: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2605: a javascript onchange item, e.g., onchange="this.form.submit();".
2606: An optional arg -- $readonly -- if true will cause the select form
2607: to be disabled, e.g., for the case where an instructor has a section-
2608: specific role, and is viewing/modifying parameters.
1.970 raeburn 2609:
1.88 www 2610: See lonrights.pm for an example invocation and use.
2611:
2612: =cut
2613:
2614: #-------------------------------------------
2615: sub select_form {
1.1228 raeburn 2616: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2617: return unless (ref($hashref) eq 'HASH');
2618: if ($onchange) {
2619: $onchange = ' onchange="'.$onchange.'"';
2620: }
1.1228 raeburn 2621: my $disabled;
2622: if ($readonly) {
2623: $disabled = ' disabled="disabled"';
2624: }
2625: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2626: my @keys;
1.970 raeburn 2627: if (exists($hashref->{'select_form_order'})) {
2628: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2629: } else {
1.970 raeburn 2630: @keys=sort(keys(%{$hashref}));
1.128 albertel 2631: }
1.356 albertel 2632: foreach my $key (@keys) {
2633: $selectform.=
2634: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2635: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2636: ">".$hashref->{$key}."</option>\n";
1.88 www 2637: }
2638: $selectform.="</select>";
2639: return $selectform;
2640: }
2641:
1.475 www 2642: # For display filters
2643:
2644: sub display_filter {
1.1074 raeburn 2645: my ($context) = @_;
1.475 www 2646: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2647: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2648: my $phraseinput = 'hidden';
2649: my $includeinput = 'hidden';
2650: my ($checked,$includetypestext);
2651: if ($env{'form.displayfilter'} eq 'containing') {
2652: $phraseinput = 'text';
2653: if ($context eq 'parmslog') {
2654: $includeinput = 'checkbox';
2655: if ($env{'form.includetypes'}) {
2656: $checked = ' checked="checked"';
2657: }
2658: $includetypestext = &mt('Include parameter types');
2659: }
2660: } else {
2661: $includetypestext = ' ';
2662: }
2663: my ($additional,$secondid,$thirdid);
2664: if ($context eq 'parmslog') {
2665: $additional =
2666: '<label><input type="'.$includeinput.'" name="includetypes"'.
2667: $checked.' name="includetypes" value="1" id="includetypes" />'.
2668: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2669: '</label>';
2670: $secondid = 'includetypes';
2671: $thirdid = 'includetypestext';
2672: }
2673: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2674: '$secondid','$thirdid')";
2675: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2676: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2677: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2678: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2679: &mt('Filter: [_1]',
1.477 www 2680: &select_form($env{'form.displayfilter'},
2681: 'displayfilter',
1.970 raeburn 2682: {'currentfolder' => 'Current folder/page',
1.477 www 2683: 'containing' => 'Containing phrase',
1.1074 raeburn 2684: 'none' => 'None'},$onchange)).' '.
2685: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2686: &HTML::Entities::encode($env{'form.containingphrase'}).
2687: '" />'.$additional;
2688: }
2689:
2690: sub display_filter_js {
2691: my $includetext = &mt('Include parameter types');
2692: return <<"ENDJS";
2693:
2694: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2695: var firstType = 'hidden';
2696: if (setter.options[setter.selectedIndex].value == 'containing') {
2697: firstType = 'text';
2698: }
2699: firstObject = document.getElementById(firstid);
2700: if (typeof(firstObject) == 'object') {
2701: if (firstObject.type != firstType) {
2702: changeInputType(firstObject,firstType);
2703: }
2704: }
2705: if (context == 'parmslog') {
2706: var secondType = 'hidden';
2707: if (firstType == 'text') {
2708: secondType = 'checkbox';
2709: }
2710: secondObject = document.getElementById(secondid);
2711: if (typeof(secondObject) == 'object') {
2712: if (secondObject.type != secondType) {
2713: changeInputType(secondObject,secondType);
2714: }
2715: }
2716: var textItem = document.getElementById(thirdid);
2717: var currtext = textItem.innerHTML;
2718: var newtext;
2719: if (firstType == 'text') {
2720: newtext = '$includetext';
2721: } else {
2722: newtext = ' ';
2723: }
2724: if (currtext != newtext) {
2725: textItem.innerHTML = newtext;
2726: }
2727: }
2728: return;
2729: }
2730:
2731: function changeInputType(oldObject,newType) {
2732: var newObject = document.createElement('input');
2733: newObject.type = newType;
2734: if (oldObject.size) {
2735: newObject.size = oldObject.size;
2736: }
2737: if (oldObject.value) {
2738: newObject.value = oldObject.value;
2739: }
2740: if (oldObject.name) {
2741: newObject.name = oldObject.name;
2742: }
2743: if (oldObject.id) {
2744: newObject.id = oldObject.id;
2745: }
2746: oldObject.parentNode.replaceChild(newObject,oldObject);
2747: return;
2748: }
2749:
2750: ENDJS
1.475 www 2751: }
2752:
1.167 www 2753: sub gradeleveldescription {
2754: my $gradelevel=shift;
2755: my %gradelevels=(0 => 'Not specified',
2756: 1 => 'Grade 1',
2757: 2 => 'Grade 2',
2758: 3 => 'Grade 3',
2759: 4 => 'Grade 4',
2760: 5 => 'Grade 5',
2761: 6 => 'Grade 6',
2762: 7 => 'Grade 7',
2763: 8 => 'Grade 8',
2764: 9 => 'Grade 9',
2765: 10 => 'Grade 10',
2766: 11 => 'Grade 11',
2767: 12 => 'Grade 12',
2768: 13 => 'Grade 13',
2769: 14 => '100 Level',
2770: 15 => '200 Level',
2771: 16 => '300 Level',
2772: 17 => '400 Level',
2773: 18 => 'Graduate Level');
2774: return &mt($gradelevels{$gradelevel});
2775: }
2776:
1.163 www 2777: sub select_level_form {
2778: my ($deflevel,$name)=@_;
2779: unless ($deflevel) { $deflevel=0; }
1.167 www 2780: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2781: for (my $i=0; $i<=18; $i++) {
2782: $selectform.="<option value=\"$i\" ".
1.253 albertel 2783: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2784: ">".&gradeleveldescription($i)."</option>\n";
2785: }
2786: $selectform.="</select>";
2787: return $selectform;
1.163 www 2788: }
1.167 www 2789:
1.35 matthew 2790: #-------------------------------------------
2791:
1.45 matthew 2792: =pod
2793:
1.1256 raeburn 2794: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2795:
2796: Returns a string containing a <select name='$name' size='1'> form to
2797: allow a user to select the domain to preform an operation in.
2798: See loncreateuser.pm for an example invocation and use.
2799:
1.90 www 2800: If the $includeempty flag is set, it also includes an empty choice ("no domain
2801: selected");
2802:
1.743 raeburn 2803: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2804:
1.910 raeburn 2805: 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.
2806:
1.1121 raeburn 2807: The optional $incdoms is a reference to an array of domains which will be the only available options.
2808:
2809: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2810:
1.1256 raeburn 2811: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2812:
1.35 matthew 2813: =cut
2814:
2815: #-------------------------------------------
1.34 matthew 2816: sub select_dom_form {
1.1256 raeburn 2817: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2818: if ($onchange) {
1.874 raeburn 2819: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2820: }
1.1256 raeburn 2821: if ($disabled) {
2822: $disabled = ' disabled="disabled"';
2823: }
1.1121 raeburn 2824: my (@domains,%exclude);
1.910 raeburn 2825: if (ref($incdoms) eq 'ARRAY') {
2826: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2827: } else {
2828: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2829: }
1.90 www 2830: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2831: if (ref($excdoms) eq 'ARRAY') {
2832: map { $exclude{$_} = 1; } @{$excdoms};
2833: }
1.1256 raeburn 2834: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2835: foreach my $dom (@domains) {
1.1121 raeburn 2836: next if ($exclude{$dom});
1.356 albertel 2837: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2838: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2839: if ($showdomdesc) {
2840: if ($dom ne '') {
2841: my $domdesc = &Apache::lonnet::domain($dom,'description');
2842: if ($domdesc ne '') {
2843: $selectdomain .= ' ('.$domdesc.')';
2844: }
2845: }
2846: }
2847: $selectdomain .= "</option>\n";
1.34 matthew 2848: }
2849: $selectdomain.="</select>";
2850: return $selectdomain;
2851: }
2852:
1.35 matthew 2853: #-------------------------------------------
2854:
1.45 matthew 2855: =pod
2856:
1.648 raeburn 2857: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2858:
1.586 raeburn 2859: input: 4 arguments (two required, two optional) -
2860: $domain - domain of new user
2861: $name - name of form element
2862: $default - Value of 'default' causes a default item to be first
2863: option, and selected by default.
2864: $hide - Value of 'hide' causes hiding of the name of the server,
2865: if 1 server found, or default, if 0 found.
1.594 raeburn 2866: output: returns 2 items:
1.586 raeburn 2867: (a) form element which contains either:
2868: (i) <select name="$name">
2869: <option value="$hostid1">$hostid $servers{$hostid}</option>
2870: <option value="$hostid2">$hostid $servers{$hostid}</option>
2871: </select>
2872: form item if there are multiple library servers in $domain, or
2873: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2874: if there is only one library server in $domain.
2875:
2876: (b) number of library servers found.
2877:
2878: See loncreateuser.pm for example of use.
1.35 matthew 2879:
2880: =cut
2881:
2882: #-------------------------------------------
1.586 raeburn 2883: sub home_server_form_item {
2884: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2885: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2886: my $result;
2887: my $numlib = keys(%servers);
2888: if ($numlib > 1) {
2889: $result .= '<select name="'.$name.'" />'."\n";
2890: if ($default) {
1.804 bisitz 2891: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2892: '</option>'."\n";
2893: }
2894: foreach my $hostid (sort(keys(%servers))) {
2895: $result.= '<option value="'.$hostid.'">'.
2896: $hostid.' '.$servers{$hostid}."</option>\n";
2897: }
2898: $result .= '</select>'."\n";
2899: } elsif ($numlib == 1) {
2900: my $hostid;
2901: foreach my $item (keys(%servers)) {
2902: $hostid = $item;
2903: }
2904: $result .= '<input type="hidden" name="'.$name.'" value="'.
2905: $hostid.'" />';
2906: if (!$hide) {
2907: $result .= $hostid.' '.$servers{$hostid};
2908: }
2909: $result .= "\n";
2910: } elsif ($default) {
2911: $result .= '<input type="hidden" name="'.$name.
2912: '" value="default" />';
2913: if (!$hide) {
2914: $result .= &mt('default');
2915: }
2916: $result .= "\n";
1.33 matthew 2917: }
1.586 raeburn 2918: return ($result,$numlib);
1.33 matthew 2919: }
1.112 bowersj2 2920:
2921: =pod
2922:
1.534 albertel 2923: =back
2924:
1.112 bowersj2 2925: =cut
1.87 matthew 2926:
2927: ###############################################################
1.112 bowersj2 2928: ## Decoding User Agent ##
1.87 matthew 2929: ###############################################################
2930:
2931: =pod
2932:
1.112 bowersj2 2933: =head1 Decoding the User Agent
2934:
2935: =over 4
2936:
2937: =item * &decode_user_agent()
1.87 matthew 2938:
2939: Inputs: $r
2940:
2941: Outputs:
2942:
2943: =over 4
2944:
1.112 bowersj2 2945: =item * $httpbrowser
1.87 matthew 2946:
1.112 bowersj2 2947: =item * $clientbrowser
1.87 matthew 2948:
1.112 bowersj2 2949: =item * $clientversion
1.87 matthew 2950:
1.112 bowersj2 2951: =item * $clientmathml
1.87 matthew 2952:
1.112 bowersj2 2953: =item * $clientunicode
1.87 matthew 2954:
1.112 bowersj2 2955: =item * $clientos
1.87 matthew 2956:
1.1137 raeburn 2957: =item * $clientmobile
2958:
1.1141 raeburn 2959: =item * $clientinfo
2960:
1.1194 raeburn 2961: =item * $clientosversion
2962:
1.87 matthew 2963: =back
2964:
1.157 matthew 2965: =back
2966:
1.87 matthew 2967: =cut
2968:
2969: ###############################################################
2970: ###############################################################
2971: sub decode_user_agent {
1.247 albertel 2972: my ($r)=@_;
1.87 matthew 2973: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2974: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2975: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2976: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2977: my $clientbrowser='unknown';
2978: my $clientversion='0';
2979: my $clientmathml='';
2980: my $clientunicode='0';
1.1137 raeburn 2981: my $clientmobile=0;
1.1194 raeburn 2982: my $clientosversion='';
1.87 matthew 2983: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2984: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2985: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2986: $clientbrowser=$bname;
2987: $httpbrowser=~/$vreg/i;
2988: $clientversion=$1;
2989: $clientmathml=($clientversion>=$minv);
2990: $clientunicode=($clientversion>=$univ);
2991: }
2992: }
2993: my $clientos='unknown';
1.1141 raeburn 2994: my $clientinfo;
1.87 matthew 2995: if (($httpbrowser=~/linux/i) ||
2996: ($httpbrowser=~/unix/i) ||
2997: ($httpbrowser=~/ux/i) ||
2998: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2999: if (($httpbrowser=~/vax/i) ||
3000: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3001: if ($httpbrowser=~/next/i) { $clientos='next'; }
3002: if (($httpbrowser=~/mac/i) ||
3003: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3004: if ($httpbrowser=~/win/i) {
3005: $clientos='win';
3006: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3007: $clientosversion = $1;
3008: }
3009: }
1.87 matthew 3010: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3011: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3012: $clientmobile=lc($1);
3013: }
1.1141 raeburn 3014: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3015: $clientinfo = 'firefox-'.$1;
3016: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3017: $clientinfo = 'chromeframe-'.$1;
3018: }
1.87 matthew 3019: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3020: $clientunicode,$clientos,$clientmobile,$clientinfo,
3021: $clientosversion);
1.87 matthew 3022: }
3023:
1.32 matthew 3024: ###############################################################
3025: ## Authentication changing form generation subroutines ##
3026: ###############################################################
3027: ##
3028: ## All of the authform_xxxxxxx subroutines take their inputs in a
3029: ## hash, and have reasonable default values.
3030: ##
3031: ## formname = the name given in the <form> tag.
1.35 matthew 3032: #-------------------------------------------
3033:
1.45 matthew 3034: =pod
3035:
1.112 bowersj2 3036: =head1 Authentication Routines
3037:
3038: =over 4
3039:
1.648 raeburn 3040: =item * &authform_xxxxxx()
1.35 matthew 3041:
3042: The authform_xxxxxx subroutines provide javascript and html forms which
3043: handle some of the conveniences required for authentication forms.
3044: This is not an optimal method, but it works.
3045:
3046: =over 4
3047:
1.112 bowersj2 3048: =item * authform_header
1.35 matthew 3049:
1.112 bowersj2 3050: =item * authform_authorwarning
1.35 matthew 3051:
1.112 bowersj2 3052: =item * authform_nochange
1.35 matthew 3053:
1.112 bowersj2 3054: =item * authform_kerberos
1.35 matthew 3055:
1.112 bowersj2 3056: =item * authform_internal
1.35 matthew 3057:
1.112 bowersj2 3058: =item * authform_filesystem
1.35 matthew 3059:
1.1310 raeburn 3060: =item * authform_lti
3061:
1.35 matthew 3062: =back
3063:
1.648 raeburn 3064: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3065:
1.35 matthew 3066: =cut
3067:
3068: #-------------------------------------------
1.32 matthew 3069: sub authform_header{
3070: my %in = (
3071: formname => 'cu',
1.80 albertel 3072: kerb_def_dom => '',
1.32 matthew 3073: @_,
3074: );
3075: $in{'formname'} = 'document.' . $in{'formname'};
3076: my $result='';
1.80 albertel 3077:
3078: #---------------------------------------------- Code for upper case translation
3079: my $Javascript_toUpperCase;
3080: unless ($in{kerb_def_dom}) {
3081: $Javascript_toUpperCase =<<"END";
3082: switch (choice) {
3083: case 'krb': currentform.elements[choicearg].value =
3084: currentform.elements[choicearg].value.toUpperCase();
3085: break;
3086: default:
3087: }
3088: END
3089: } else {
3090: $Javascript_toUpperCase = "";
3091: }
3092:
1.165 raeburn 3093: my $radioval = "'nochange'";
1.591 raeburn 3094: if (defined($in{'curr_authtype'})) {
3095: if ($in{'curr_authtype'} ne '') {
3096: $radioval = "'".$in{'curr_authtype'}."arg'";
3097: }
1.174 matthew 3098: }
1.165 raeburn 3099: my $argfield = 'null';
1.591 raeburn 3100: if (defined($in{'mode'})) {
1.165 raeburn 3101: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3102: if (defined($in{'curr_autharg'})) {
3103: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3104: $argfield = "'$in{'curr_autharg'}'";
3105: }
3106: }
3107: }
3108: }
3109:
1.32 matthew 3110: $result.=<<"END";
3111: var current = new Object();
1.165 raeburn 3112: current.radiovalue = $radioval;
3113: current.argfield = $argfield;
1.32 matthew 3114:
3115: function changed_radio(choice,currentform) {
3116: var choicearg = choice + 'arg';
3117: // If a radio button in changed, we need to change the argfield
3118: if (current.radiovalue != choice) {
3119: current.radiovalue = choice;
3120: if (current.argfield != null) {
3121: currentform.elements[current.argfield].value = '';
3122: }
3123: if (choice == 'nochange') {
3124: current.argfield = null;
3125: } else {
3126: current.argfield = choicearg;
3127: switch(choice) {
3128: case 'krb':
3129: currentform.elements[current.argfield].value =
3130: "$in{'kerb_def_dom'}";
3131: break;
3132: default:
3133: break;
3134: }
3135: }
3136: }
3137: return;
3138: }
1.22 www 3139:
1.32 matthew 3140: function changed_text(choice,currentform) {
3141: var choicearg = choice + 'arg';
3142: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3143: $Javascript_toUpperCase
1.32 matthew 3144: // clear old field
3145: if ((current.argfield != choicearg) && (current.argfield != null)) {
3146: currentform.elements[current.argfield].value = '';
3147: }
3148: current.argfield = choicearg;
3149: }
3150: set_auth_radio_buttons(choice,currentform);
3151: return;
1.20 www 3152: }
1.32 matthew 3153:
3154: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3155: var numauthchoices = currentform.login.length;
3156: if (typeof numauthchoices == "undefined") {
3157: return;
3158: }
1.32 matthew 3159: var i=0;
1.986 raeburn 3160: while (i < numauthchoices) {
1.32 matthew 3161: if (currentform.login[i].value == newvalue) { break; }
3162: i++;
3163: }
1.986 raeburn 3164: if (i == numauthchoices) {
1.32 matthew 3165: return;
3166: }
3167: current.radiovalue = newvalue;
3168: currentform.login[i].checked = true;
3169: return;
3170: }
3171: END
3172: return $result;
3173: }
3174:
1.1106 raeburn 3175: sub authform_authorwarning {
1.32 matthew 3176: my $result='';
1.144 matthew 3177: $result='<i>'.
3178: &mt('As a general rule, only authors or co-authors should be '.
3179: 'filesystem authenticated '.
3180: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3181: return $result;
3182: }
3183:
1.1106 raeburn 3184: sub authform_nochange {
1.32 matthew 3185: my %in = (
3186: formname => 'document.cu',
3187: kerb_def_dom => 'MSU.EDU',
3188: @_,
3189: );
1.1106 raeburn 3190: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3191: my $result;
1.1104 raeburn 3192: if (!$authnum) {
1.1105 raeburn 3193: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3194: } else {
3195: $result = '<label>'.&mt('[_1] Do not change login data',
3196: '<input type="radio" name="login" value="nochange" '.
3197: 'checked="checked" onclick="'.
1.281 albertel 3198: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3199: '</label>';
1.586 raeburn 3200: }
1.32 matthew 3201: return $result;
3202: }
3203:
1.591 raeburn 3204: sub authform_kerberos {
1.32 matthew 3205: my %in = (
3206: formname => 'document.cu',
3207: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3208: kerb_def_auth => 'krb4',
1.32 matthew 3209: @_,
3210: );
1.586 raeburn 3211: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3212: $autharg,$jscall,$disabled);
1.1106 raeburn 3213: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3214: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3215: $check5 = ' checked="checked"';
1.80 albertel 3216: } else {
1.772 bisitz 3217: $check4 = ' checked="checked"';
1.80 albertel 3218: }
1.1259 raeburn 3219: if ($in{'readonly'}) {
3220: $disabled = ' disabled="disabled"';
3221: }
1.165 raeburn 3222: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3223: if (defined($in{'curr_authtype'})) {
3224: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3225: $krbcheck = ' checked="checked"';
1.623 raeburn 3226: if (defined($in{'mode'})) {
3227: if ($in{'mode'} eq 'modifyuser') {
3228: $krbcheck = '';
3229: }
3230: }
1.591 raeburn 3231: if (defined($in{'curr_kerb_ver'})) {
3232: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3233: $check5 = ' checked="checked"';
1.591 raeburn 3234: $check4 = '';
3235: } else {
1.772 bisitz 3236: $check4 = ' checked="checked"';
1.591 raeburn 3237: $check5 = '';
3238: }
1.586 raeburn 3239: }
1.591 raeburn 3240: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3241: $krbarg = $in{'curr_autharg'};
3242: }
1.586 raeburn 3243: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3244: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3245: $result =
3246: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3247: $in{'curr_autharg'},$krbver);
3248: } else {
3249: $result =
3250: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3251: }
3252: return $result;
3253: }
3254: }
3255: } else {
3256: if ($authnum == 1) {
1.784 bisitz 3257: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3258: }
3259: }
1.586 raeburn 3260: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3261: return;
1.587 raeburn 3262: } elsif ($authtype eq '') {
1.591 raeburn 3263: if (defined($in{'mode'})) {
1.587 raeburn 3264: if ($in{'mode'} eq 'modifycourse') {
3265: if ($authnum == 1) {
1.1259 raeburn 3266: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3267: }
3268: }
3269: }
1.586 raeburn 3270: }
3271: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3272: if ($authtype eq '') {
3273: $authtype = '<input type="radio" name="login" value="krb" '.
3274: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3275: $krbcheck.$disabled.' />';
1.586 raeburn 3276: }
3277: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3278: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3279: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3280: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3281: $in{'curr_authtype'} eq 'krb4')) {
3282: $result .= &mt
1.144 matthew 3283: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3284: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3285: '<label>'.$authtype,
1.281 albertel 3286: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3287: 'value="'.$krbarg.'" '.
1.1259 raeburn 3288: 'onchange="'.$jscall.'"'.$disabled.' />',
3289: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3290: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3291: '</label>');
1.586 raeburn 3292: } elsif ($can_assign{'krb4'}) {
3293: $result .= &mt
3294: ('[_1] Kerberos authenticated with domain [_2] '.
3295: '[_3] Version 4 [_4]',
3296: '<label>'.$authtype,
3297: '</label><input type="text" size="10" name="krbarg" '.
3298: 'value="'.$krbarg.'" '.
1.1259 raeburn 3299: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3300: '<label><input type="hidden" name="krbver" value="4" />',
3301: '</label>');
3302: } elsif ($can_assign{'krb5'}) {
3303: $result .= &mt
3304: ('[_1] Kerberos authenticated with domain [_2] '.
3305: '[_3] Version 5 [_4]',
3306: '<label>'.$authtype,
3307: '</label><input type="text" size="10" name="krbarg" '.
3308: 'value="'.$krbarg.'" '.
1.1259 raeburn 3309: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3310: '<label><input type="hidden" name="krbver" value="5" />',
3311: '</label>');
3312: }
1.32 matthew 3313: return $result;
3314: }
3315:
1.1106 raeburn 3316: sub authform_internal {
1.586 raeburn 3317: my %in = (
1.32 matthew 3318: formname => 'document.cu',
3319: kerb_def_dom => 'MSU.EDU',
3320: @_,
3321: );
1.1259 raeburn 3322: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3323: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3324: if ($in{'readonly'}) {
3325: $disabled = ' disabled="disabled"';
3326: }
1.591 raeburn 3327: if (defined($in{'curr_authtype'})) {
3328: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3329: if ($can_assign{'int'}) {
1.772 bisitz 3330: $intcheck = 'checked="checked" ';
1.623 raeburn 3331: if (defined($in{'mode'})) {
3332: if ($in{'mode'} eq 'modifyuser') {
3333: $intcheck = '';
3334: }
3335: }
1.591 raeburn 3336: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3337: $intarg = $in{'curr_autharg'};
3338: }
3339: } else {
3340: $result = &mt('Currently internally authenticated.');
3341: return $result;
1.165 raeburn 3342: }
3343: }
1.586 raeburn 3344: } else {
3345: if ($authnum == 1) {
1.784 bisitz 3346: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3347: }
3348: }
3349: if (!$can_assign{'int'}) {
3350: return;
1.587 raeburn 3351: } elsif ($authtype eq '') {
1.591 raeburn 3352: if (defined($in{'mode'})) {
1.587 raeburn 3353: if ($in{'mode'} eq 'modifycourse') {
3354: if ($authnum == 1) {
1.1259 raeburn 3355: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3356: }
3357: }
3358: }
1.165 raeburn 3359: }
1.586 raeburn 3360: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3361: if ($authtype eq '') {
3362: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3363: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3364: }
1.605 bisitz 3365: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3366: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3367: $result = &mt
1.144 matthew 3368: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3369: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3370: $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 3371: return $result;
3372: }
3373:
1.1104 raeburn 3374: sub authform_local {
1.32 matthew 3375: my %in = (
3376: formname => 'document.cu',
3377: kerb_def_dom => 'MSU.EDU',
3378: @_,
3379: );
1.1259 raeburn 3380: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3381: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3382: if ($in{'readonly'}) {
3383: $disabled = ' disabled="disabled"';
3384: }
1.591 raeburn 3385: if (defined($in{'curr_authtype'})) {
3386: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3387: if ($can_assign{'loc'}) {
1.772 bisitz 3388: $loccheck = 'checked="checked" ';
1.623 raeburn 3389: if (defined($in{'mode'})) {
3390: if ($in{'mode'} eq 'modifyuser') {
3391: $loccheck = '';
3392: }
3393: }
1.591 raeburn 3394: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3395: $locarg = $in{'curr_autharg'};
3396: }
3397: } else {
3398: $result = &mt('Currently using local (institutional) authentication.');
3399: return $result;
1.165 raeburn 3400: }
3401: }
1.586 raeburn 3402: } else {
3403: if ($authnum == 1) {
1.784 bisitz 3404: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3405: }
3406: }
3407: if (!$can_assign{'loc'}) {
3408: return;
1.587 raeburn 3409: } elsif ($authtype eq '') {
1.591 raeburn 3410: if (defined($in{'mode'})) {
1.587 raeburn 3411: if ($in{'mode'} eq 'modifycourse') {
3412: if ($authnum == 1) {
1.1259 raeburn 3413: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3414: }
3415: }
3416: }
1.165 raeburn 3417: }
1.586 raeburn 3418: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3419: if ($authtype eq '') {
3420: $authtype = '<input type="radio" name="login" value="loc" '.
3421: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3422: $jscall.'"'.$disabled.' />';
1.586 raeburn 3423: }
3424: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3425: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3426: $result = &mt('[_1] Local Authentication with argument [_2]',
3427: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3428: return $result;
3429: }
3430:
1.1106 raeburn 3431: sub authform_filesystem {
1.32 matthew 3432: my %in = (
3433: formname => 'document.cu',
3434: kerb_def_dom => 'MSU.EDU',
3435: @_,
3436: );
1.1259 raeburn 3437: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3438: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3439: if ($in{'readonly'}) {
3440: $disabled = ' disabled="disabled"';
3441: }
1.591 raeburn 3442: if (defined($in{'curr_authtype'})) {
3443: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3444: if ($can_assign{'fsys'}) {
1.772 bisitz 3445: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3446: if (defined($in{'mode'})) {
3447: if ($in{'mode'} eq 'modifyuser') {
3448: $fsyscheck = '';
3449: }
3450: }
1.586 raeburn 3451: } else {
3452: $result = &mt('Currently Filesystem Authenticated.');
3453: return $result;
1.1259 raeburn 3454: }
1.586 raeburn 3455: }
3456: } else {
3457: if ($authnum == 1) {
1.784 bisitz 3458: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3459: }
3460: }
3461: if (!$can_assign{'fsys'}) {
3462: return;
1.587 raeburn 3463: } elsif ($authtype eq '') {
1.591 raeburn 3464: if (defined($in{'mode'})) {
1.587 raeburn 3465: if ($in{'mode'} eq 'modifycourse') {
3466: if ($authnum == 1) {
1.1259 raeburn 3467: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3468: }
3469: }
3470: }
1.586 raeburn 3471: }
3472: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3473: if ($authtype eq '') {
3474: $authtype = '<input type="radio" name="login" value="fsys" '.
3475: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3476: $jscall.'"'.$disabled.' />';
1.586 raeburn 3477: }
1.1310 raeburn 3478: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3479: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3480: $result = &mt
1.144 matthew 3481: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3482: '<label>'.$authtype,'</label>'.$autharg);
3483: return $result;
3484: }
3485:
3486: sub authform_lti {
3487: my %in = (
3488: formname => 'document.cu',
3489: kerb_def_dom => 'MSU.EDU',
3490: @_,
3491: );
3492: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3493: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3494: if ($in{'readonly'}) {
3495: $disabled = ' disabled="disabled"';
3496: }
3497: if (defined($in{'curr_authtype'})) {
3498: if ($in{'curr_authtype'} eq 'lti') {
3499: if ($can_assign{'lti'}) {
3500: $lticheck = 'checked="checked" ';
3501: if (defined($in{'mode'})) {
3502: if ($in{'mode'} eq 'modifyuser') {
3503: $lticheck = '';
3504: }
3505: }
3506: } else {
3507: $result = &mt('Currently LTI Authenticated.');
3508: return $result;
3509: }
3510: }
3511: } else {
3512: if ($authnum == 1) {
3513: $authtype = '<input type="hidden" name="login" value="lti" />';
3514: }
3515: }
3516: if (!$can_assign{'lti'}) {
3517: return;
3518: } elsif ($authtype eq '') {
3519: if (defined($in{'mode'})) {
3520: if ($in{'mode'} eq 'modifycourse') {
3521: if ($authnum == 1) {
3522: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3523: }
3524: }
3525: }
3526: }
3527: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3528: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3529: $authtype = '<input type="radio" name="login" value="lti" '.
3530: $lticheck.' onchange="'.$jscall.'" onclick="'.
3531: $jscall.'"'.$disabled.' />';
3532: }
3533: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3534: if ($authtype) {
3535: $result = &mt('[_1] LTI Authenticated',
3536: '<label>'.$authtype.'</label>'.$autharg);
3537: } else {
3538: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3539: $autharg;
3540: }
1.32 matthew 3541: return $result;
3542: }
3543:
1.586 raeburn 3544: sub get_assignable_auth {
3545: my ($dom) = @_;
3546: if ($dom eq '') {
3547: $dom = $env{'request.role.domain'};
3548: }
3549: my %can_assign = (
3550: krb4 => 1,
3551: krb5 => 1,
3552: int => 1,
3553: loc => 1,
1.1310 raeburn 3554: lti => 1,
1.586 raeburn 3555: );
3556: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3557: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3558: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3559: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3560: my $context;
3561: if ($env{'request.role'} =~ /^au/) {
3562: $context = 'author';
1.1259 raeburn 3563: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3564: $context = 'domain';
3565: } elsif ($env{'request.course.id'}) {
3566: $context = 'course';
3567: }
3568: if ($context) {
3569: if (ref($authhash->{$context}) eq 'HASH') {
3570: %can_assign = %{$authhash->{$context}};
3571: }
3572: }
3573: }
3574: }
3575: my $authnum = 0;
3576: foreach my $key (keys(%can_assign)) {
3577: if ($can_assign{$key}) {
3578: $authnum ++;
3579: }
3580: }
3581: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3582: $authnum --;
3583: }
3584: return ($authnum,%can_assign);
3585: }
3586:
1.1331 raeburn 3587: sub check_passwd_rules {
3588: my ($domain,$plainpass) = @_;
3589: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3590: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3591: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3592: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3593: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3594: if ($passwdconf{'min'} > $min) {
3595: $min = $passwdconf{'min'};
3596: }
1.1331 raeburn 3597: }
3598: if ($passwdconf{'max'} =~ /^\d+$/) {
3599: $max = $passwdconf{'max'};
3600: }
3601: @chars = @{$passwdconf{'chars'}};
3602: }
3603: if (($min) && (length($plainpass) < $min)) {
3604: push(@brokerule,'min');
3605: }
3606: if (($max) && (length($plainpass) > $max)) {
3607: push(@brokerule,'max');
3608: }
3609: if (@chars) {
3610: my %rules;
3611: map { $rules{$_} = 1; } @chars;
3612: if ($rules{'uc'}) {
3613: unless ($plainpass =~ /[A-Z]/) {
3614: push(@brokerule,'uc');
3615: }
3616: }
3617: if ($rules{'lc'}) {
1.1332 raeburn 3618: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3619: push(@brokerule,'lc');
3620: }
3621: }
3622: if ($rules{'num'}) {
3623: unless ($plainpass =~ /\d/) {
3624: push(@brokerule,'num');
3625: }
3626: }
3627: if ($rules{'spec'}) {
3628: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3629: push(@brokerule,'spec');
3630: }
3631: }
3632: }
3633: if (@brokerule) {
3634: my %rulenames = &Apache::lonlocal::texthash(
3635: uc => 'At least one upper case letter',
3636: lc => 'At least one lower case letter',
3637: num => 'At least one number',
3638: spec => 'At least one non-alphanumeric',
3639: );
3640: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3641: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3642: $rulenames{'num'} .= ': 0123456789';
3643: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3644: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3645: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3646: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3647: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3648: if (grep(/^$rule$/,@brokerule)) {
3649: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3650: }
3651: }
3652: $warning .= '</ul>';
3653: }
1.1332 raeburn 3654: if (wantarray) {
3655: return @brokerule;
3656: }
1.1331 raeburn 3657: return $warning;
3658: }
3659:
1.1376 raeburn 3660: sub passwd_validation_js {
1.1377 raeburn 3661: my ($currpasswdval,$domain,$context,$id) = @_;
3662: my (%passwdconf,$alertmsg);
3663: if ($context eq 'linkprot') {
3664: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3665: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3666: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3667: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3668: }
3669: }
3670: if ($id eq 'add') {
3671: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3672: } elsif ($id =~ /^\d+$/) {
3673: my $pos = $id+1;
3674: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3675: } else {
3676: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3677: }
3678: } else {
3679: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3680: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3681: }
1.1376 raeburn 3682: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3683: $numrules = 0;
3684: $min = $Apache::lonnet::passwdmin;
3685: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3686: if ($passwdconf{'min'} =~ /^\d+$/) {
3687: if ($passwdconf{'min'} > $min) {
3688: $min = $passwdconf{'min'};
3689: }
3690: }
3691: if ($passwdconf{'max'} =~ /^\d+$/) {
3692: $max = $passwdconf{'max'};
3693: $numrules ++;
3694: }
3695: @chars = @{$passwdconf{'chars'}};
3696: if (@chars) {
3697: $numrules ++;
3698: }
3699: }
3700: if ($min > 0) {
3701: $numrules ++;
3702: }
3703: if (($min > 0) || ($max ne '') || (@chars > 0)) {
3704: if ($min) {
3705: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3706: }
3707: if ($max) {
3708: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3709: }
3710: my (@charalerts,@charrules);
3711: if (@chars) {
3712: if (grep(/^uc$/,@chars)) {
3713: push(@charalerts,&mt('contain at least one upper case letter'));
3714: push(@charrules,'uc');
3715: }
3716: if (grep(/^lc$/,@chars)) {
3717: push(@charalerts,&mt('contain at least one lower case letter'));
3718: push(@charrules,'lc');
3719: }
3720: if (grep(/^num$/,@chars)) {
3721: push(@charalerts,&mt('contain at least one number'));
3722: push(@charrules,'num');
3723: }
3724: if (grep(/^spec$/,@chars)) {
3725: push(@charalerts,&mt('contain at least one non-alphanumeric'));
3726: push(@charrules,'spec');
3727: }
3728: }
3729: $intargjs = qq| var rulesmsg = '';\n|.
3730: qq| var currpwval = $currpasswdval;\n|;
3731: if ($min) {
3732: $intargjs .= qq|
3733: if (currpwval.length < $min) {
3734: rulesmsg += ' - $alert{min}';
3735: }
3736: |;
3737: }
3738: if ($max) {
3739: $intargjs .= qq|
3740: if (currpwval.length > $max) {
3741: rulesmsg += ' - $alert{max}';
3742: }
3743: |;
3744: }
3745: if (@chars > 0) {
3746: my $charrulestr = '"'.join('","',@charrules).'"';
3747: my $charalertstr = '"'.join('","',@charalerts).'"';
3748: $intargjs .= qq| var brokerules = new Array();\n|.
3749: qq| var charrules = new Array($charrulestr);\n|.
3750: qq| var charalerts = new Array($charalertstr);\n|;
3751: my %rules;
3752: map { $rules{$_} = 1; } @chars;
3753: if ($rules{'uc'}) {
3754: $intargjs .= qq|
3755: var ucRegExp = /[A-Z]/;
3756: if (!ucRegExp.test(currpwval)) {
3757: brokerules.push('uc');
3758: }
3759: |;
3760: }
3761: if ($rules{'lc'}) {
3762: $intargjs .= qq|
3763: var lcRegExp = /[a-z]/;
3764: if (!lcRegExp.test(currpwval)) {
3765: brokerules.push('lc');
3766: }
3767: |;
3768: }
3769: if ($rules{'num'}) {
3770: $intargjs .= qq|
3771: var numRegExp = /[0-9]/;
3772: if (!numRegExp.test(currpwval)) {
3773: brokerules.push('num');
3774: }
3775: |;
3776: }
3777: if ($rules{'spec'}) {
3778: $intargjs .= q|
3779: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3780: if (!specRegExp.test(currpwval)) {
3781: brokerules.push('spec');
3782: }
3783: |;
3784: }
3785: $intargjs .= qq|
3786: if (brokerules.length > 0) {
3787: for (var i=0; i<brokerules.length; i++) {
3788: for (var j=0; j<charrules.length; j++) {
3789: if (brokerules[i] == charrules[j]) {
3790: rulesmsg += ' - '+charalerts[j]+'\\n';
3791: break;
3792: }
3793: }
3794: }
3795: }
3796: |;
3797: }
3798: $intargjs .= qq|
3799: if (rulesmsg != '') {
3800: rulesmsg = '$alertmsg'+rulesmsg;
3801: alert(rulesmsg);
3802: return false;
3803: }
3804: |;
3805: }
3806: return ($numrules,$intargjs);
3807: }
3808:
1.80 albertel 3809: ###############################################################
3810: ## Get Kerberos Defaults for Domain ##
3811: ###############################################################
3812: ##
3813: ## Returns default kerberos version and an associated argument
3814: ## as listed in file domain.tab. If not listed, provides
3815: ## appropriate default domain and kerberos version.
3816: ##
3817: #-------------------------------------------
3818:
3819: =pod
3820:
1.648 raeburn 3821: =item * &get_kerberos_defaults()
1.80 albertel 3822:
3823: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3824: version and domain. If not found, it defaults to version 4 and the
3825: domain of the server.
1.80 albertel 3826:
1.648 raeburn 3827: =over 4
3828:
1.80 albertel 3829: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3830:
1.648 raeburn 3831: =back
3832:
3833: =back
3834:
1.80 albertel 3835: =cut
3836:
3837: #-------------------------------------------
3838: sub get_kerberos_defaults {
3839: my $domain=shift;
1.641 raeburn 3840: my ($krbdef,$krbdefdom);
3841: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3842: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3843: $krbdef = $domdefaults{'auth_def'};
3844: $krbdefdom = $domdefaults{'auth_arg_def'};
3845: } else {
1.80 albertel 3846: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3847: my $krbdefdom=$1;
3848: $krbdefdom=~tr/a-z/A-Z/;
3849: $krbdef = "krb4";
3850: }
3851: return ($krbdef,$krbdefdom);
3852: }
1.112 bowersj2 3853:
1.32 matthew 3854:
1.46 matthew 3855: ###############################################################
3856: ## Thesaurus Functions ##
3857: ###############################################################
1.20 www 3858:
1.46 matthew 3859: =pod
1.20 www 3860:
1.112 bowersj2 3861: =head1 Thesaurus Functions
3862:
3863: =over 4
3864:
1.648 raeburn 3865: =item * &initialize_keywords()
1.46 matthew 3866:
3867: Initializes the package variable %Keywords if it is empty. Uses the
3868: package variable $thesaurus_db_file.
3869:
3870: =cut
3871:
3872: ###################################################
3873:
3874: sub initialize_keywords {
3875: return 1 if (scalar keys(%Keywords));
3876: # If we are here, %Keywords is empty, so fill it up
3877: # Make sure the file we need exists...
3878: if (! -e $thesaurus_db_file) {
3879: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3880: " failed because it does not exist");
3881: return 0;
3882: }
3883: # Set up the hash as a database
3884: my %thesaurus_db;
3885: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3886: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3887: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3888: $thesaurus_db_file);
3889: return 0;
3890: }
3891: # Get the average number of appearances of a word.
3892: my $avecount = $thesaurus_db{'average.count'};
3893: # Put keywords (those that appear > average) into %Keywords
3894: while (my ($word,$data)=each (%thesaurus_db)) {
3895: my ($count,undef) = split /:/,$data;
3896: $Keywords{$word}++ if ($count > $avecount);
3897: }
3898: untie %thesaurus_db;
3899: # Remove special values from %Keywords.
1.356 albertel 3900: foreach my $value ('total.count','average.count') {
3901: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3902: }
1.46 matthew 3903: return 1;
3904: }
3905:
3906: ###################################################
3907:
3908: =pod
3909:
1.648 raeburn 3910: =item * &keyword($word)
1.46 matthew 3911:
3912: Returns true if $word is a keyword. A keyword is a word that appears more
3913: than the average number of times in the thesaurus database. Calls
3914: &initialize_keywords
3915:
3916: =cut
3917:
3918: ###################################################
1.20 www 3919:
3920: sub keyword {
1.46 matthew 3921: return if (!&initialize_keywords());
3922: my $word=lc(shift());
3923: $word=~s/\W//g;
3924: return exists($Keywords{$word});
1.20 www 3925: }
1.46 matthew 3926:
3927: ###############################################################
3928:
3929: =pod
1.20 www 3930:
1.648 raeburn 3931: =item * &get_related_words()
1.46 matthew 3932:
1.160 matthew 3933: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3934: an array of words. If the keyword is not in the thesaurus, an empty array
3935: will be returned. The order of the words returned is determined by the
3936: database which holds them.
3937:
3938: Uses global $thesaurus_db_file.
3939:
1.1057 foxr 3940:
1.46 matthew 3941: =cut
3942:
3943: ###############################################################
3944: sub get_related_words {
3945: my $keyword = shift;
3946: my %thesaurus_db;
3947: if (! -e $thesaurus_db_file) {
3948: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3949: "failed because the file does not exist");
3950: return ();
3951: }
3952: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3953: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3954: return ();
3955: }
3956: my @Words=();
1.429 www 3957: my $count=0;
1.46 matthew 3958: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3959: # The first element is the number of times
3960: # the word appears. We do not need it now.
1.429 www 3961: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3962: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3963: my $threshold=$mostfrequentcount/10;
3964: foreach my $possibleword (@RelatedWords) {
3965: my ($word,$wordcount)=split(/\,/,$possibleword);
3966: if ($wordcount>$threshold) {
3967: push(@Words,$word);
3968: $count++;
3969: if ($count>10) { last; }
3970: }
1.20 www 3971: }
3972: }
1.46 matthew 3973: untie %thesaurus_db;
3974: return @Words;
1.14 harris41 3975: }
1.1090 foxr 3976: ###############################################################
3977: #
3978: # Spell checking
3979: #
3980:
3981: =pod
3982:
1.1142 raeburn 3983: =back
3984:
1.1090 foxr 3985: =head1 Spell checking
3986:
3987: =over 4
3988:
3989: =item * &check_spelling($wordlist $language)
3990:
3991: Takes a string containing words and feeds it to an external
3992: spellcheck program via a pipeline. Returns a string containing
3993: them mis-spelled words.
3994:
3995: Parameters:
3996:
3997: =over 4
3998:
3999: =item - $wordlist
4000:
4001: String that will be fed into the spellcheck program.
4002:
4003: =item - $language
4004:
4005: Language string that specifies the language for which the spell
4006: check will be performed.
4007:
4008: =back
4009:
4010: =back
4011:
4012: Note: This sub assumes that aspell is installed.
4013:
4014:
4015: =cut
4016:
1.46 matthew 4017:
1.1090 foxr 4018: sub check_spelling {
4019: my ($wordlist, $language) = @_;
1.1091 foxr 4020: my @misspellings;
4021:
4022: # Generate the speller and set the langauge.
4023: # if explicitly selected:
1.1090 foxr 4024:
1.1091 foxr 4025: my $speller = Text::Aspell->new;
1.1090 foxr 4026: if ($language) {
1.1091 foxr 4027: $speller->set_option('lang', $language);
1.1090 foxr 4028: }
4029:
1.1091 foxr 4030: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4031:
1.1091 foxr 4032: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4033:
1.1091 foxr 4034: foreach my $word (@words) {
4035: if(! $speller->check($word)) {
4036: push(@misspellings, $word);
1.1090 foxr 4037: }
4038: }
1.1091 foxr 4039: return join(' ', @misspellings);
4040:
1.1090 foxr 4041: }
4042:
1.61 www 4043: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4044: =pod
4045:
1.112 bowersj2 4046: =head1 User Name Functions
4047:
4048: =over 4
4049:
1.648 raeburn 4050: =item * &plainname($uname,$udom,$first)
1.81 albertel 4051:
1.112 bowersj2 4052: Takes a users logon name and returns it as a string in
1.226 albertel 4053: "first middle last generation" form
4054: if $first is set to 'lastname' then it returns it as
4055: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4056:
4057: =cut
1.61 www 4058:
1.295 www 4059:
1.81 albertel 4060: ###############################################################
1.61 www 4061: sub plainname {
1.226 albertel 4062: my ($uname,$udom,$first)=@_;
1.537 albertel 4063: return if (!defined($uname) || !defined($udom));
1.295 www 4064: my %names=&getnames($uname,$udom);
1.226 albertel 4065: my $name=&Apache::lonnet::format_name($names{'firstname'},
4066: $names{'middlename'},
4067: $names{'lastname'},
4068: $names{'generation'},$first);
4069: $name=~s/^\s+//;
1.62 www 4070: $name=~s/\s+$//;
4071: $name=~s/\s+/ /g;
1.353 albertel 4072: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4073: return $name;
1.61 www 4074: }
1.66 www 4075:
4076: # -------------------------------------------------------------------- Nickname
1.81 albertel 4077: =pod
4078:
1.648 raeburn 4079: =item * &nickname($uname,$udom)
1.81 albertel 4080:
4081: Gets a users name and returns it as a string as
4082:
4083: ""nickname""
1.66 www 4084:
1.81 albertel 4085: if the user has a nickname or
4086:
4087: "first middle last generation"
4088:
4089: if the user does not
4090:
4091: =cut
1.66 www 4092:
4093: sub nickname {
4094: my ($uname,$udom)=@_;
1.537 albertel 4095: return if (!defined($uname) || !defined($udom));
1.295 www 4096: my %names=&getnames($uname,$udom);
1.68 albertel 4097: my $name=$names{'nickname'};
1.66 www 4098: if ($name) {
4099: $name='"'.$name.'"';
4100: } else {
4101: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4102: $names{'lastname'}.' '.$names{'generation'};
4103: $name=~s/\s+$//;
4104: $name=~s/\s+/ /g;
4105: }
4106: return $name;
4107: }
4108:
1.295 www 4109: sub getnames {
4110: my ($uname,$udom)=@_;
1.537 albertel 4111: return if (!defined($uname) || !defined($udom));
1.433 albertel 4112: if ($udom eq 'public' && $uname eq 'public') {
4113: return ('lastname' => &mt('Public'));
4114: }
1.295 www 4115: my $id=$uname.':'.$udom;
4116: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4117: if ($cached) {
4118: return %{$names};
4119: } else {
4120: my %loadnames=&Apache::lonnet::get('environment',
4121: ['firstname','middlename','lastname','generation','nickname'],
4122: $udom,$uname);
4123: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4124: return %loadnames;
4125: }
4126: }
1.61 www 4127:
1.542 raeburn 4128: # -------------------------------------------------------------------- getemails
1.648 raeburn 4129:
1.542 raeburn 4130: =pod
4131:
1.648 raeburn 4132: =item * &getemails($uname,$udom)
1.542 raeburn 4133:
4134: Gets a user's email information and returns it as a hash with keys:
4135: notification, critnotification, permanentemail
4136:
4137: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4138: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4139:
1.648 raeburn 4140:
1.542 raeburn 4141: =cut
4142:
1.648 raeburn 4143:
1.466 albertel 4144: sub getemails {
4145: my ($uname,$udom)=@_;
4146: if ($udom eq 'public' && $uname eq 'public') {
4147: return;
4148: }
1.467 www 4149: if (!$udom) { $udom=$env{'user.domain'}; }
4150: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4151: my $id=$uname.':'.$udom;
4152: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4153: if ($cached) {
4154: return %{$names};
4155: } else {
4156: my %loadnames=&Apache::lonnet::get('environment',
4157: ['notification','critnotification',
4158: 'permanentemail'],
4159: $udom,$uname);
4160: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4161: return %loadnames;
4162: }
4163: }
4164:
1.551 albertel 4165: sub flush_email_cache {
4166: my ($uname,$udom)=@_;
4167: if (!$udom) { $udom =$env{'user.domain'}; }
4168: if (!$uname) { $uname=$env{'user.name'}; }
4169: return if ($udom eq 'public' && $uname eq 'public');
4170: my $id=$uname.':'.$udom;
4171: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4172: }
4173:
1.728 raeburn 4174: # -------------------------------------------------------------------- getlangs
4175:
4176: =pod
4177:
4178: =item * &getlangs($uname,$udom)
4179:
4180: Gets a user's language preference and returns it as a hash with key:
4181: language.
4182:
4183: =cut
4184:
4185:
4186: sub getlangs {
4187: my ($uname,$udom) = @_;
4188: if (!$udom) { $udom =$env{'user.domain'}; }
4189: if (!$uname) { $uname=$env{'user.name'}; }
4190: my $id=$uname.':'.$udom;
4191: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4192: if ($cached) {
4193: return %{$langs};
4194: } else {
4195: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4196: $udom,$uname);
4197: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4198: return %loadlangs;
4199: }
4200: }
4201:
4202: sub flush_langs_cache {
4203: my ($uname,$udom)=@_;
4204: if (!$udom) { $udom =$env{'user.domain'}; }
4205: if (!$uname) { $uname=$env{'user.name'}; }
4206: return if ($udom eq 'public' && $uname eq 'public');
4207: my $id=$uname.':'.$udom;
4208: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4209: }
4210:
1.61 www 4211: # ------------------------------------------------------------------ Screenname
1.81 albertel 4212:
4213: =pod
4214:
1.648 raeburn 4215: =item * &screenname($uname,$udom)
1.81 albertel 4216:
4217: Gets a users screenname and returns it as a string
4218:
4219: =cut
1.61 www 4220:
4221: sub screenname {
4222: my ($uname,$udom)=@_;
1.258 albertel 4223: if ($uname eq $env{'user.name'} &&
4224: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4225: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4226: return $names{'screenname'};
1.62 www 4227: }
4228:
1.212 albertel 4229:
1.802 bisitz 4230: # ------------------------------------------------------------- Confirm Wrapper
4231: =pod
4232:
1.1142 raeburn 4233: =item * &confirmwrapper($message)
1.802 bisitz 4234:
4235: Wrap messages about completion of operation in box
4236:
4237: =cut
4238:
4239: sub confirmwrapper {
4240: my ($message)=@_;
4241: if ($message) {
4242: return "\n".'<div class="LC_confirm_box">'."\n"
4243: .$message."\n"
4244: .'</div>'."\n";
4245: } else {
4246: return $message;
4247: }
4248: }
4249:
1.62 www 4250: # ------------------------------------------------------------- Message Wrapper
4251:
4252: sub messagewrapper {
1.369 www 4253: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4254: return
1.441 albertel 4255: '<a href="/adm/email?compose=individual&'.
4256: 'recname='.$username.'&recdom='.$domain.
4257: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4258: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4259: }
1.802 bisitz 4260:
1.74 www 4261: # --------------------------------------------------------------- Notes Wrapper
4262:
4263: sub noteswrapper {
4264: my ($link,$un,$do)=@_;
4265: return
1.896 amueller 4266: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4267: }
1.802 bisitz 4268:
1.62 www 4269: # ------------------------------------------------------------- Aboutme Wrapper
4270:
4271: sub aboutmewrapper {
1.1070 raeburn 4272: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4273: if (!defined($username) && !defined($domain)) {
4274: return;
4275: }
1.1096 raeburn 4276: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4277: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4278: }
4279:
4280: # ------------------------------------------------------------ Syllabus Wrapper
4281:
4282: sub syllabuswrapper {
1.707 bisitz 4283: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4284: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4285: }
1.14 harris41 4286:
1.802 bisitz 4287: # -----------------------------------------------------------------------------
4288:
1.208 matthew 4289: sub track_student_link {
1.887 raeburn 4290: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4291: my $link ="/adm/trackstudent?";
1.208 matthew 4292: my $title = 'View recent activity';
4293: if (defined($sname) && $sname !~ /^\s*$/ &&
4294: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4295: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4296: $title .= ' of this student';
1.268 albertel 4297: }
1.208 matthew 4298: if (defined($target) && $target !~ /^\s*$/) {
4299: $target = qq{target="$target"};
4300: } else {
4301: $target = '';
4302: }
1.268 albertel 4303: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4304: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4305: $title = &mt($title);
4306: $linktext = &mt($linktext);
1.448 albertel 4307: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4308: &help_open_topic('View_recent_activity');
1.208 matthew 4309: }
4310:
1.781 raeburn 4311: sub slot_reservations_link {
4312: my ($linktext,$sname,$sdom,$target) = @_;
4313: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4314: my $title = 'View slot reservation history';
4315: if (defined($sname) && $sname !~ /^\s*$/ &&
4316: defined($sdom) && $sdom !~ /^\s*$/) {
4317: $link .= "&uname=$sname&udom=$sdom";
4318: $title .= ' of this student';
4319: }
4320: if (defined($target) && $target !~ /^\s*$/) {
4321: $target = qq{target="$target"};
4322: } else {
4323: $target = '';
4324: }
4325: $title = &mt($title);
4326: $linktext = &mt($linktext);
4327: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4328: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4329:
4330: }
4331:
1.508 www 4332: # ===================================================== Display a student photo
4333:
4334:
1.509 albertel 4335: sub student_image_tag {
1.508 www 4336: my ($domain,$user)=@_;
4337: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4338: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4339: return '<img src="'.$imgsrc.'" align="right" />';
4340: } else {
4341: return '';
4342: }
4343: }
4344:
1.112 bowersj2 4345: =pod
4346:
4347: =back
4348:
4349: =head1 Access .tab File Data
4350:
4351: =over 4
4352:
1.648 raeburn 4353: =item * &languageids()
1.112 bowersj2 4354:
4355: returns list of all language ids
4356:
4357: =cut
4358:
1.14 harris41 4359: sub languageids {
1.16 harris41 4360: return sort(keys(%language));
1.14 harris41 4361: }
4362:
1.112 bowersj2 4363: =pod
4364:
1.648 raeburn 4365: =item * &languagedescription()
1.112 bowersj2 4366:
4367: returns description of a specified language id
4368:
4369: =cut
4370:
1.14 harris41 4371: sub languagedescription {
1.125 www 4372: my $code=shift;
4373: return ($supported_language{$code}?'* ':'').
4374: $language{$code}.
1.126 www 4375: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4376: }
4377:
1.1048 foxr 4378: =pod
4379:
4380: =item * &plainlanguagedescription
4381:
4382: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4383: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4384:
4385: =cut
4386:
1.145 www 4387: sub plainlanguagedescription {
4388: my $code=shift;
4389: return $language{$code};
4390: }
4391:
1.1048 foxr 4392: =pod
4393:
4394: =item * &supportedlanguagecode
4395:
4396: Returns the supported language code (e.g. sptutf maps to pt) given a language
4397: code.
4398:
4399: =cut
4400:
1.145 www 4401: sub supportedlanguagecode {
4402: my $code=shift;
4403: return $supported_language{$code};
1.97 www 4404: }
4405:
1.112 bowersj2 4406: =pod
4407:
1.1048 foxr 4408: =item * &latexlanguage()
4409:
4410: Given a language key code returns the correspondnig language to use
4411: to select the correct hyphenation on LaTeX printouts. This is undef if there
4412: is no supported hyphenation for the language code.
4413:
4414: =cut
4415:
4416: sub latexlanguage {
4417: my $code = shift;
4418: return $latex_language{$code};
4419: }
4420:
4421: =pod
4422:
4423: =item * &latexhyphenation()
4424:
4425: Same as above but what's supplied is the language as it might be stored
4426: in the metadata.
4427:
4428: =cut
4429:
4430: sub latexhyphenation {
4431: my $key = shift;
4432: return $latex_language_bykey{$key};
4433: }
4434:
4435: =pod
4436:
1.648 raeburn 4437: =item * ©rightids()
1.112 bowersj2 4438:
4439: returns list of all copyrights
4440:
4441: =cut
4442:
4443: sub copyrightids {
4444: return sort(keys(%cprtag));
4445: }
4446:
4447: =pod
4448:
1.648 raeburn 4449: =item * ©rightdescription()
1.112 bowersj2 4450:
4451: returns description of a specified copyright id
4452:
4453: =cut
4454:
4455: sub copyrightdescription {
1.166 www 4456: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4457: }
1.197 matthew 4458:
4459: =pod
4460:
1.648 raeburn 4461: =item * &source_copyrightids()
1.192 taceyjo1 4462:
4463: returns list of all source copyrights
4464:
4465: =cut
4466:
4467: sub source_copyrightids {
4468: return sort(keys(%scprtag));
4469: }
4470:
4471: =pod
4472:
1.648 raeburn 4473: =item * &source_copyrightdescription()
1.192 taceyjo1 4474:
4475: returns description of a specified source copyright id
4476:
4477: =cut
4478:
4479: sub source_copyrightdescription {
4480: return &mt($scprtag{shift(@_)});
4481: }
1.112 bowersj2 4482:
4483: =pod
4484:
1.648 raeburn 4485: =item * &filecategories()
1.112 bowersj2 4486:
4487: returns list of all file categories
4488:
4489: =cut
4490:
4491: sub filecategories {
4492: return sort(keys(%category_extensions));
4493: }
4494:
4495: =pod
4496:
1.648 raeburn 4497: =item * &filecategorytypes()
1.112 bowersj2 4498:
4499: returns list of file types belonging to a given file
4500: category
4501:
4502: =cut
4503:
4504: sub filecategorytypes {
1.356 albertel 4505: my ($cat) = @_;
1.1248 raeburn 4506: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4507: return @{$category_extensions{lc($cat)}};
4508: } else {
4509: return ();
4510: }
1.112 bowersj2 4511: }
4512:
4513: =pod
4514:
1.648 raeburn 4515: =item * &fileembstyle()
1.112 bowersj2 4516:
4517: returns embedding style for a specified file type
4518:
4519: =cut
4520:
4521: sub fileembstyle {
4522: return $fe{lc(shift(@_))};
1.169 www 4523: }
4524:
1.351 www 4525: sub filemimetype {
4526: return $fm{lc(shift(@_))};
4527: }
4528:
1.169 www 4529:
4530: sub filecategoryselect {
4531: my ($name,$value)=@_;
1.189 matthew 4532: return &select_form($value,$name,
1.970 raeburn 4533: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4534: }
4535:
4536: =pod
4537:
1.648 raeburn 4538: =item * &filedescription()
1.112 bowersj2 4539:
4540: returns description for a specified file type
4541:
4542: =cut
4543:
4544: sub filedescription {
1.188 matthew 4545: my $file_description = $fd{lc(shift())};
4546: $file_description =~ s:([\[\]]):~$1:g;
4547: return &mt($file_description);
1.112 bowersj2 4548: }
4549:
4550: =pod
4551:
1.648 raeburn 4552: =item * &filedescriptionex()
1.112 bowersj2 4553:
4554: returns description for a specified file type with
4555: extra formatting
4556:
4557: =cut
4558:
4559: sub filedescriptionex {
4560: my $ex=shift;
1.188 matthew 4561: my $file_description = $fd{lc($ex)};
4562: $file_description =~ s:([\[\]]):~$1:g;
4563: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4564: }
4565:
4566: # End of .tab access
4567: =pod
4568:
4569: =back
4570:
4571: =cut
4572:
4573: # ------------------------------------------------------------------ File Types
4574: sub fileextensions {
4575: return sort(keys(%fe));
4576: }
4577:
1.97 www 4578: # ----------------------------------------------------------- Display Languages
4579: # returns a hash with all desired display languages
4580: #
4581:
4582: sub display_languages {
4583: my %languages=();
1.695 raeburn 4584: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4585: $languages{$lang}=1;
1.97 www 4586: }
4587: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4588: if ($env{'form.displaylanguage'}) {
1.356 albertel 4589: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4590: $languages{$lang}=1;
1.97 www 4591: }
4592: }
4593: return %languages;
1.14 harris41 4594: }
4595:
1.582 albertel 4596: sub languages {
4597: my ($possible_langs) = @_;
1.695 raeburn 4598: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4599: if (!ref($possible_langs)) {
4600: if( wantarray ) {
4601: return @preferred_langs;
4602: } else {
4603: return $preferred_langs[0];
4604: }
4605: }
4606: my %possibilities = map { $_ => 1 } (@$possible_langs);
4607: my @preferred_possibilities;
4608: foreach my $preferred_lang (@preferred_langs) {
4609: if (exists($possibilities{$preferred_lang})) {
4610: push(@preferred_possibilities, $preferred_lang);
4611: }
4612: }
4613: if( wantarray ) {
4614: return @preferred_possibilities;
4615: }
4616: return $preferred_possibilities[0];
4617: }
4618:
1.742 raeburn 4619: sub user_lang {
4620: my ($touname,$toudom,$fromcid) = @_;
4621: my @userlangs;
4622: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4623: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4624: $env{'course.'.$fromcid.'.languages'}));
4625: } else {
4626: my %langhash = &getlangs($touname,$toudom);
4627: if ($langhash{'languages'} ne '') {
4628: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4629: } else {
4630: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4631: if ($domdefs{'lang_def'} ne '') {
4632: @userlangs = ($domdefs{'lang_def'});
4633: }
4634: }
4635: }
4636: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4637: my $user_lh = Apache::localize->get_handle(@languages);
4638: return $user_lh;
4639: }
4640:
4641:
1.112 bowersj2 4642: ###############################################################
4643: ## Student Answer Attempts ##
4644: ###############################################################
4645:
4646: =pod
4647:
4648: =head1 Alternate Problem Views
4649:
4650: =over 4
4651:
1.648 raeburn 4652: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4653: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4654:
4655: Return string with previous attempt on problem. Arguments:
4656:
4657: =over 4
4658:
4659: =item * $symb: Problem, including path
4660:
4661: =item * $username: username of the desired student
4662:
4663: =item * $domain: domain of the desired student
1.14 harris41 4664:
1.112 bowersj2 4665: =item * $course: Course ID
1.14 harris41 4666:
1.112 bowersj2 4667: =item * $getattempt: Leave blank for all attempts, otherwise put
4668: something
1.14 harris41 4669:
1.112 bowersj2 4670: =item * $regexp: if string matches this regexp, the string will be
4671: sent to $gradesub
1.14 harris41 4672:
1.112 bowersj2 4673: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4674:
1.1199 raeburn 4675: =item * $usec: section of the desired student
4676:
4677: =item * $identifier: counter for student (multiple students one problem) or
4678: problem (one student; whole sequence).
4679:
1.112 bowersj2 4680: =back
1.14 harris41 4681:
1.112 bowersj2 4682: The output string is a table containing all desired attempts, if any.
1.16 harris41 4683:
1.112 bowersj2 4684: =cut
1.1 albertel 4685:
4686: sub get_previous_attempt {
1.1199 raeburn 4687: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4688: my $prevattempts='';
1.43 ng 4689: no strict 'refs';
1.1 albertel 4690: if ($symb) {
1.3 albertel 4691: my (%returnhash)=
4692: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4693: if ($returnhash{'version'}) {
4694: my %lasthash=();
4695: my $version;
4696: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4697: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4698: if ($key =~ /\.rawrndseed$/) {
4699: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4700: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4701: } else {
4702: $lasthash{$key}=$returnhash{$version.':'.$key};
4703: }
1.19 harris41 4704: }
1.1 albertel 4705: }
1.596 albertel 4706: $prevattempts=&start_data_table().&start_data_table_header_row();
4707: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4708: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4709: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4710: foreach my $key (sort(keys(%lasthash))) {
4711: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4712: if ($#parts > 0) {
1.31 albertel 4713: my $data=$parts[-1];
1.989 raeburn 4714: next if ($data eq 'foilorder');
1.31 albertel 4715: pop(@parts);
1.1010 www 4716: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4717: if ($data eq 'type') {
4718: unless ($showsurv) {
4719: my $id = join(',',@parts);
4720: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4721: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4722: $lasthidden{$ign.'.'.$id} = 1;
4723: }
1.945 raeburn 4724: }
1.1199 raeburn 4725: if ($identifier ne '') {
4726: my $id = join(',',@parts);
4727: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4728: $domain,$username,$usec,undef,$course) =~ /^no/) {
4729: $hidestatus{$ign.'.'.$id} = 1;
4730: }
4731: }
4732: } elsif ($data eq 'regrader') {
4733: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4734: my $id = join(',',@parts);
4735: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4736: }
1.1010 www 4737: }
1.31 albertel 4738: } else {
1.41 ng 4739: if ($#parts == 0) {
4740: $prevattempts.='<th>'.$parts[0].'</th>';
4741: } else {
4742: $prevattempts.='<th>'.$ign.'</th>';
4743: }
1.31 albertel 4744: }
1.16 harris41 4745: }
1.596 albertel 4746: $prevattempts.=&end_data_table_header_row();
1.40 ng 4747: if ($getattempt eq '') {
1.1199 raeburn 4748: my (%solved,%resets,%probstatus);
1.1200 raeburn 4749: if (($identifier ne '') && (keys(%regraded) > 0)) {
4750: for ($version=1;$version<=$returnhash{'version'};$version++) {
4751: foreach my $id (keys(%regraded)) {
4752: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4753: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4754: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4755: push(@{$resets{$id}},$version);
1.1199 raeburn 4756: }
4757: }
4758: }
1.1200 raeburn 4759: }
4760: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4761: my (@hidden,@unsolved);
1.945 raeburn 4762: if (%typeparts) {
4763: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4764: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4765: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4766: push(@hidden,$id);
1.1199 raeburn 4767: } elsif ($identifier ne '') {
4768: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4769: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4770: ($hidestatus{$id})) {
1.1200 raeburn 4771: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4772: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4773: push(@{$solved{$id}},$version);
4774: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4775: (ref($solved{$id}) eq 'ARRAY')) {
4776: my $skip;
4777: if (ref($resets{$id}) eq 'ARRAY') {
4778: foreach my $reset (@{$resets{$id}}) {
4779: if ($reset > $solved{$id}[-1]) {
4780: $skip=1;
4781: last;
4782: }
4783: }
4784: }
4785: unless ($skip) {
4786: my ($ign,$partslist) = split(/\./,$id,2);
4787: push(@unsolved,$partslist);
4788: }
4789: }
4790: }
1.945 raeburn 4791: }
4792: }
4793: }
4794: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4795: '<td>'.&mt('Transaction [_1]',$version);
4796: if (@unsolved) {
4797: $prevattempts .= '<span class="LC_nobreak"><label>'.
4798: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4799: &mt('Hide').'</label></span>';
4800: }
4801: $prevattempts .= '</td>';
1.945 raeburn 4802: if (@hidden) {
4803: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4804: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4805: my $hide;
4806: foreach my $id (@hidden) {
4807: if ($key =~ /^\Q$id\E/) {
4808: $hide = 1;
4809: last;
4810: }
4811: }
4812: if ($hide) {
4813: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4814: if (($data eq 'award') || ($data eq 'awarddetail')) {
4815: my $value = &format_previous_attempt_value($key,
4816: $returnhash{$version.':'.$key});
1.1173 kruse 4817: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4818: } else {
4819: $prevattempts.='<td> </td>';
4820: }
4821: } else {
4822: if ($key =~ /\./) {
1.1212 raeburn 4823: my $value = $returnhash{$version.':'.$key};
4824: if ($key =~ /\.rndseed$/) {
4825: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4826: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4827: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4828: }
4829: }
4830: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4831: ' </td>';
1.945 raeburn 4832: } else {
4833: $prevattempts.='<td> </td>';
4834: }
4835: }
4836: }
4837: } else {
4838: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4839: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4840: my $value = $returnhash{$version.':'.$key};
4841: if ($key =~ /\.rndseed$/) {
4842: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4843: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4844: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4845: }
4846: }
4847: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4848: ' </td>';
1.945 raeburn 4849: }
4850: }
4851: $prevattempts.=&end_data_table_row();
1.40 ng 4852: }
1.1 albertel 4853: }
1.945 raeburn 4854: my @currhidden = keys(%lasthidden);
1.596 albertel 4855: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4856: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4857: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4858: if (%typeparts) {
4859: my $hidden;
4860: foreach my $id (@currhidden) {
4861: if ($key =~ /^\Q$id\E/) {
4862: $hidden = 1;
4863: last;
4864: }
4865: }
4866: if ($hidden) {
4867: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4868: if (($data eq 'award') || ($data eq 'awarddetail')) {
4869: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4870: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4871: $value = &$gradesub($value);
4872: }
1.1173 kruse 4873: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4874: } else {
4875: $prevattempts.='<td> </td>';
4876: }
4877: } else {
4878: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4879: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4880: $value = &$gradesub($value);
4881: }
1.1173 kruse 4882: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4883: }
4884: } else {
4885: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4886: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4887: $value = &$gradesub($value);
4888: }
1.1173 kruse 4889: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4890: }
1.16 harris41 4891: }
1.596 albertel 4892: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4893: } else {
1.1305 raeburn 4894: my $msg;
4895: if ($symb =~ /ext\.tool$/) {
4896: $msg = &mt('No grade passed back.');
4897: } else {
4898: $msg = &mt('Nothing submitted - no attempts.');
4899: }
1.596 albertel 4900: $prevattempts=
4901: &start_data_table().&start_data_table_row().
1.1305 raeburn 4902: '<td>'.$msg.'</td>'.
1.596 albertel 4903: &end_data_table_row().&end_data_table();
1.1 albertel 4904: }
4905: } else {
1.596 albertel 4906: $prevattempts=
4907: &start_data_table().&start_data_table_row().
4908: '<td>'.&mt('No data.').'</td>'.
4909: &end_data_table_row().&end_data_table();
1.1 albertel 4910: }
1.10 albertel 4911: }
4912:
1.581 albertel 4913: sub format_previous_attempt_value {
4914: my ($key,$value) = @_;
1.1011 www 4915: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4916: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4917: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4918: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4919: } elsif ($key =~ /answerstring$/) {
4920: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4921: my @answer = %answers;
4922: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4923: my @anskeys = sort(keys(%answers));
4924: if (@anskeys == 1) {
4925: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4926: if ($answer =~ m{\0}) {
4927: $answer =~ s{\0}{,}g;
1.988 raeburn 4928: }
4929: my $tag_internal_answer_name = 'INTERNAL';
4930: if ($anskeys[0] eq $tag_internal_answer_name) {
4931: $value = $answer;
4932: } else {
4933: $value = $anskeys[0].'='.$answer;
4934: }
4935: } else {
4936: foreach my $ans (@anskeys) {
4937: my $answer = $answers{$ans};
1.1001 raeburn 4938: if ($answer =~ m{\0}) {
4939: $answer =~ s{\0}{,}g;
1.988 raeburn 4940: }
4941: $value .= $ans.'='.$answer.'<br />';;
4942: }
4943: }
1.581 albertel 4944: } else {
1.1173 kruse 4945: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4946: }
4947: return $value;
4948: }
4949:
4950:
1.107 albertel 4951: sub relative_to_absolute {
4952: my ($url,$output)=@_;
4953: my $parser=HTML::TokeParser->new(\$output);
4954: my $token;
4955: my $thisdir=$url;
4956: my @rlinks=();
4957: while ($token=$parser->get_token) {
4958: if ($token->[0] eq 'S') {
4959: if ($token->[1] eq 'a') {
4960: if ($token->[2]->{'href'}) {
4961: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4962: }
4963: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4964: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4965: } elsif ($token->[1] eq 'base') {
4966: $thisdir=$token->[2]->{'href'};
4967: }
4968: }
4969: }
4970: $thisdir=~s-/[^/]*$--;
1.356 albertel 4971: foreach my $link (@rlinks) {
1.726 raeburn 4972: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4973: ($link=~/^\//) ||
4974: ($link=~/^javascript:/i) ||
4975: ($link=~/^mailto:/i) ||
4976: ($link=~/^\#/)) {
4977: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4978: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4979: }
4980: }
4981: # -------------------------------------------------- Deal with Applet codebases
4982: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4983: return $output;
4984: }
4985:
1.112 bowersj2 4986: =pod
4987:
1.648 raeburn 4988: =item * &get_student_view()
1.112 bowersj2 4989:
4990: show a snapshot of what student was looking at
4991:
4992: =cut
4993:
1.10 albertel 4994: sub get_student_view {
1.186 albertel 4995: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4996: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4997: my (%form);
1.10 albertel 4998: my @elements=('symb','courseid','domain','username');
4999: foreach my $element (@elements) {
1.186 albertel 5000: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5001: }
1.186 albertel 5002: if (defined($moreenv)) {
5003: %form=(%form,%{$moreenv});
5004: }
1.236 albertel 5005: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5006: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5007: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5008: $feedurl =~ s{^/adm/wrapper}{};
5009: }
1.650 www 5010: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5011: $userview=~s/\<body[^\>]*\>//gi;
5012: $userview=~s/\<\/body\>//gi;
5013: $userview=~s/\<html\>//gi;
5014: $userview=~s/\<\/html\>//gi;
5015: $userview=~s/\<head\>//gi;
5016: $userview=~s/\<\/head\>//gi;
5017: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5018: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5019: if (wantarray) {
5020: return ($userview,$response);
5021: } else {
5022: return $userview;
5023: }
5024: }
5025:
5026: sub get_student_view_with_retries {
5027: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5028:
5029: my $ok = 0; # True if we got a good response.
5030: my $content;
5031: my $response;
5032:
5033: # Try to get the student_view done. within the retries count:
5034:
5035: do {
5036: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5037: $ok = $response->is_success;
5038: if (!$ok) {
5039: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5040: }
5041: $retries--;
5042: } while (!$ok && ($retries > 0));
5043:
5044: if (!$ok) {
5045: $content = ''; # On error return an empty content.
5046: }
1.651 www 5047: if (wantarray) {
5048: return ($content, $response);
5049: } else {
5050: return $content;
5051: }
1.11 albertel 5052: }
5053:
1.1349 raeburn 5054: sub css_links {
5055: my ($currsymb,$level) = @_;
5056: my ($links,@symbs,%cssrefs,%httpref);
5057: if ($level eq 'map') {
5058: my $navmap = Apache::lonnavmaps::navmap->new();
5059: if (ref($navmap)) {
5060: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5061: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5062: foreach my $res (@resources) {
5063: if (ref($res) && $res->symb()) {
5064: push(@symbs,$res->symb());
5065: }
5066: }
5067: }
5068: } else {
5069: @symbs = ($currsymb);
5070: }
5071: foreach my $symb (@symbs) {
5072: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5073: if ($css_href =~ /\S/) {
5074: unless ($css_href =~ m{https?://}) {
5075: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5076: my $proburl = &Apache::lonnet::clutter($url);
5077: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5078: unless ($css_href =~ m{^/}) {
5079: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5080: }
5081: if ($css_href =~ m{^/(res|uploaded)/}) {
5082: unless (($httpref{'httpref.'.$css_href}) ||
5083: (&Apache::lonnet::is_on_map($css_href))) {
5084: my $thisurl = $proburl;
5085: if ($env{'httpref.'.$proburl}) {
5086: $thisurl = $env{'httpref.'.$proburl};
5087: }
5088: $httpref{'httpref.'.$css_href} = $thisurl;
5089: }
5090: }
5091: }
5092: $cssrefs{$css_href} = 1;
5093: }
5094: }
5095: if (keys(%httpref)) {
5096: &Apache::lonnet::appenv(\%httpref);
5097: }
5098: if (keys(%cssrefs)) {
5099: foreach my $css_href (keys(%cssrefs)) {
5100: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5101: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5102: }
5103: }
5104: return $links;
5105: }
5106:
1.112 bowersj2 5107: =pod
5108:
1.648 raeburn 5109: =item * &get_student_answers()
1.112 bowersj2 5110:
5111: show a snapshot of how student was answering problem
5112:
5113: =cut
5114:
1.11 albertel 5115: sub get_student_answers {
1.100 sakharuk 5116: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5117: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5118: my (%moreenv);
1.11 albertel 5119: my @elements=('symb','courseid','domain','username');
5120: foreach my $element (@elements) {
1.186 albertel 5121: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5122: }
1.186 albertel 5123: $moreenv{'grade_target'}='answer';
5124: %moreenv=(%form,%moreenv);
1.497 raeburn 5125: $feedurl = &Apache::lonnet::clutter($feedurl);
5126: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5127: return $userview;
1.1 albertel 5128: }
1.116 albertel 5129:
5130: =pod
5131:
5132: =item * &submlink()
5133:
1.242 albertel 5134: Inputs: $text $uname $udom $symb $target
1.116 albertel 5135:
5136: Returns: A link to grades.pm such as to see the SUBM view of a student
5137:
5138: =cut
5139:
5140: ###############################################
5141: sub submlink {
1.242 albertel 5142: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5143: if (!($uname && $udom)) {
5144: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5145: &Apache::lonnet::whichuser($symb);
1.116 albertel 5146: if (!$symb) { $symb=$cursymb; }
5147: }
1.254 matthew 5148: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5149: $symb=&escape($symb);
1.960 bisitz 5150: if ($target) { $target=" target=\"$target\""; }
5151: return
5152: '<a href="/adm/grades?command=submission'.
5153: '&symb='.$symb.
5154: '&student='.$uname.
5155: '&userdom='.$udom.'"'.
5156: $target.'>'.$text.'</a>';
1.242 albertel 5157: }
5158: ##############################################
5159:
5160: =pod
5161:
5162: =item * &pgrdlink()
5163:
5164: Inputs: $text $uname $udom $symb $target
5165:
5166: Returns: A link to grades.pm such as to see the PGRD view of a student
5167:
5168: =cut
5169:
5170: ###############################################
5171: sub pgrdlink {
5172: my $link=&submlink(@_);
5173: $link=~s/(&command=submission)/$1&showgrading=yes/;
5174: return $link;
5175: }
5176: ##############################################
5177:
5178: =pod
5179:
5180: =item * &pprmlink()
5181:
5182: Inputs: $text $uname $udom $symb $target
5183:
5184: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5185: student and a specific resource
1.242 albertel 5186:
5187: =cut
5188:
5189: ###############################################
5190: sub pprmlink {
5191: my ($text,$uname,$udom,$symb,$target)=@_;
5192: if (!($uname && $udom)) {
5193: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5194: &Apache::lonnet::whichuser($symb);
1.242 albertel 5195: if (!$symb) { $symb=$cursymb; }
5196: }
1.254 matthew 5197: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5198: $symb=&escape($symb);
1.242 albertel 5199: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5200: return '<a href="/adm/parmset?command=set&'.
5201: 'symb='.$symb.'&uname='.$uname.
5202: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5203: }
5204: ##############################################
1.37 matthew 5205:
1.112 bowersj2 5206: =pod
5207:
5208: =back
5209:
5210: =cut
5211:
1.37 matthew 5212: ###############################################
1.51 www 5213:
5214:
5215: sub timehash {
1.687 raeburn 5216: my ($thistime) = @_;
5217: my $timezone = &Apache::lonlocal::gettimezone();
5218: my $dt = DateTime->from_epoch(epoch => $thistime)
5219: ->set_time_zone($timezone);
5220: my $wday = $dt->day_of_week();
5221: if ($wday == 7) { $wday = 0; }
5222: return ( 'second' => $dt->second(),
5223: 'minute' => $dt->minute(),
5224: 'hour' => $dt->hour(),
5225: 'day' => $dt->day_of_month(),
5226: 'month' => $dt->month(),
5227: 'year' => $dt->year(),
5228: 'weekday' => $wday,
5229: 'dayyear' => $dt->day_of_year(),
5230: 'dlsav' => $dt->is_dst() );
1.51 www 5231: }
5232:
1.370 www 5233: sub utc_string {
5234: my ($date)=@_;
1.371 www 5235: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5236: }
5237:
1.51 www 5238: sub maketime {
5239: my %th=@_;
1.687 raeburn 5240: my ($epoch_time,$timezone,$dt);
5241: $timezone = &Apache::lonlocal::gettimezone();
5242: eval {
5243: $dt = DateTime->new( year => $th{'year'},
5244: month => $th{'month'},
5245: day => $th{'day'},
5246: hour => $th{'hour'},
5247: minute => $th{'minute'},
5248: second => $th{'second'},
5249: time_zone => $timezone,
5250: );
5251: };
5252: if (!$@) {
5253: $epoch_time = $dt->epoch;
5254: if ($epoch_time) {
5255: return $epoch_time;
5256: }
5257: }
1.51 www 5258: return POSIX::mktime(
5259: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5260: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5261: }
5262:
5263: #########################################
1.51 www 5264:
5265: sub findallcourses {
1.482 raeburn 5266: my ($roles,$uname,$udom) = @_;
1.355 albertel 5267: my %roles;
5268: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5269: my %courses;
1.51 www 5270: my $now=time;
1.482 raeburn 5271: if (!defined($uname)) {
5272: $uname = $env{'user.name'};
5273: }
5274: if (!defined($udom)) {
5275: $udom = $env{'user.domain'};
5276: }
5277: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5278: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5279: if (!%roles) {
5280: %roles = (
5281: cc => 1,
1.907 raeburn 5282: co => 1,
1.482 raeburn 5283: in => 1,
5284: ep => 1,
5285: ta => 1,
5286: cr => 1,
5287: st => 1,
5288: );
5289: }
5290: foreach my $entry (keys(%roleshash)) {
5291: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5292: if ($trole =~ /^cr/) {
5293: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5294: } else {
5295: next if (!exists($roles{$trole}));
5296: }
5297: if ($tend) {
5298: next if ($tend < $now);
5299: }
5300: if ($tstart) {
5301: next if ($tstart > $now);
5302: }
1.1058 raeburn 5303: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5304: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5305: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5306: if ($secpart eq '') {
5307: ($cnum,$role) = split(/_/,$cnumpart);
5308: $sec = 'none';
1.1058 raeburn 5309: $value .= $cnum.'/';
1.482 raeburn 5310: } else {
5311: $cnum = $cnumpart;
5312: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5313: $value .= $cnum.'/'.$sec;
5314: }
5315: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5316: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5317: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5318: }
5319: } else {
5320: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5321: }
1.482 raeburn 5322: }
5323: } else {
5324: foreach my $key (keys(%env)) {
1.483 albertel 5325: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5326: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5327: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5328: next if ($role eq 'ca' || $role eq 'aa');
5329: next if (%roles && !exists($roles{$role}));
5330: my ($starttime,$endtime)=split(/\./,$env{$key});
5331: my $active=1;
5332: if ($starttime) {
5333: if ($now<$starttime) { $active=0; }
5334: }
5335: if ($endtime) {
5336: if ($now>$endtime) { $active=0; }
5337: }
5338: if ($active) {
1.1058 raeburn 5339: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5340: if ($sec eq '') {
5341: $sec = 'none';
1.1058 raeburn 5342: } else {
5343: $value .= $sec;
5344: }
5345: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5346: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5347: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5348: }
5349: } else {
5350: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5351: }
1.474 raeburn 5352: }
5353: }
1.51 www 5354: }
5355: }
1.474 raeburn 5356: return %courses;
1.51 www 5357: }
1.37 matthew 5358:
1.54 www 5359: ###############################################
1.474 raeburn 5360:
5361: sub blockcheck {
1.1372 raeburn 5362: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5363: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5364: my ($has_evb,$check_ipaccess);
5365: my $dom = $env{'user.domain'};
5366: if ($env{'request.course.id'}) {
5367: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5368: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5369: my $checkrole = "cm./$cdom/$cnum";
5370: my $sec = $env{'request.course.sec'};
5371: if ($sec ne '') {
5372: $checkrole .= "/$sec";
5373: }
5374: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5375: ($env{'request.role'} !~ /^st/)) {
5376: $has_evb = 1;
5377: }
5378: unless ($has_evb) {
5379: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5380: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5381: if ($udom eq $cdom) {
5382: $check_ipaccess = 1;
5383: }
5384: }
5385: }
1.1375 raeburn 5386: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5387: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5388: my $checkrole;
5389: if ($env{'request.role.domain'} eq '') {
5390: $checkrole = "cm./$env{'user.domain'}/";
5391: } else {
5392: $checkrole = "cm./$env{'request.role.domain'}/";
5393: }
5394: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5395: $has_evb = 1;
5396: }
1.1372 raeburn 5397: }
5398: unless ($has_evb || $check_ipaccess) {
5399: my @machinedoms = &Apache::lonnet::current_machine_domains();
5400: if (($dom eq 'public') && ($activity eq 'port')) {
5401: $dom = $udom;
5402: }
5403: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5404: $check_ipaccess = 1;
5405: } else {
5406: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5407: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5408: my $prim = &Apache::lonnet::domain($dom,'primary');
5409: my $intdom = &Apache::lonnet::internet_dom($prim);
5410: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5411: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5412: $check_ipaccess = 1;
5413: }
5414: }
5415: }
5416: }
5417: if ($check_ipaccess) {
5418: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5419: unless (defined($cached)) {
5420: my %domconfig =
5421: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5422: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5423: }
5424: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5425: foreach my $id (keys(%{$ipaccessref})) {
5426: if (ref($ipaccessref->{$id}) eq 'HASH') {
5427: my $range = $ipaccessref->{$id}->{'ip'};
5428: if ($range) {
5429: if (&Apache::lonnet::ip_match($clientip,$range)) {
5430: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5431: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5432: return ('','','',$id,$dom);
5433: last;
5434: }
5435: }
5436: }
5437: }
5438: }
5439: }
5440: }
5441: }
1.1373 raeburn 5442: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5443: return ();
5444: }
1.1372 raeburn 5445: }
1.1189 raeburn 5446: if (defined($udom) && defined($uname)) {
5447: # If uname and udom are for a course, check for blocks in the course.
5448: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5449: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5450: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5451: return ($startblock,$endblock,$triggerblock);
5452: }
5453: } else {
1.490 raeburn 5454: $udom = $env{'user.domain'};
5455: $uname = $env{'user.name'};
5456: }
5457:
1.502 raeburn 5458: my $startblock = 0;
5459: my $endblock = 0;
1.1062 raeburn 5460: my $triggerblock = '';
1.1373 raeburn 5461: my %live_courses;
5462: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5463: %live_courses = &findallcourses(undef,$uname,$udom);
5464: }
1.474 raeburn 5465:
1.490 raeburn 5466: # If uname is for a user, and activity is course-specific, i.e.,
5467: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5468:
1.490 raeburn 5469: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5470: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5471: $activity eq 'search' || $activity eq 'reinit' ||
5472: $activity eq 'alert') &&
1.1189 raeburn 5473: ($env{'request.course.id'})) {
1.490 raeburn 5474: foreach my $key (keys(%live_courses)) {
5475: if ($key ne $env{'request.course.id'}) {
5476: delete($live_courses{$key});
5477: }
5478: }
5479: }
5480:
5481: my $otheruser = 0;
5482: my %own_courses;
5483: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5484: # Resource belongs to user other than current user.
5485: $otheruser = 1;
5486: # Gather courses for current user
5487: %own_courses =
5488: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5489: }
5490:
5491: # Gather active course roles - course coordinator, instructor,
5492: # exam proctor, ta, student, or custom role.
1.474 raeburn 5493:
5494: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5495: my ($cdom,$cnum);
5496: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5497: $cdom = $env{'course.'.$course.'.domain'};
5498: $cnum = $env{'course.'.$course.'.num'};
5499: } else {
1.490 raeburn 5500: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5501: }
5502: my $no_ownblock = 0;
5503: my $no_userblock = 0;
1.533 raeburn 5504: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5505: # Check if current user has 'evb' priv for this
5506: if (defined($own_courses{$course})) {
5507: foreach my $sec (keys(%{$own_courses{$course}})) {
5508: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5509: if ($sec ne 'none') {
5510: $checkrole .= '/'.$sec;
5511: }
5512: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5513: $no_ownblock = 1;
5514: last;
5515: }
5516: }
5517: }
5518: # if they have 'evb' priv and are currently not playing student
5519: next if (($no_ownblock) &&
5520: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5521: }
1.474 raeburn 5522: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5523: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5524: if ($sec ne 'none') {
1.482 raeburn 5525: $checkrole .= '/'.$sec;
1.474 raeburn 5526: }
1.490 raeburn 5527: if ($otheruser) {
5528: # Resource belongs to user other than current user.
5529: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5530: my (%allroles,%userroles);
5531: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5532: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5533: my ($trole,$tdom,$tnum,$tsec);
5534: if ($entry =~ /^cr/) {
5535: ($trole,$tdom,$tnum,$tsec) =
5536: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5537: } else {
5538: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5539: }
5540: my ($spec,$area,$trest);
5541: $area = '/'.$tdom.'/'.$tnum;
5542: $trest = $tnum;
5543: if ($tsec ne '') {
5544: $area .= '/'.$tsec;
5545: $trest .= '/'.$tsec;
5546: }
5547: $spec = $trole.'.'.$area;
5548: if ($trole =~ /^cr/) {
5549: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5550: $tdom,$spec,$trest,$area);
5551: } else {
5552: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5553: $tdom,$spec,$trest,$area);
5554: }
5555: }
1.1276 raeburn 5556: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5557: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5558: if ($1) {
5559: $no_userblock = 1;
5560: last;
5561: }
1.486 raeburn 5562: }
5563: }
1.490 raeburn 5564: } else {
5565: # Resource belongs to current user
5566: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5567: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5568: $no_ownblock = 1;
5569: last;
5570: }
1.474 raeburn 5571: }
5572: }
5573: # if they have the evb priv and are currently not playing student
1.482 raeburn 5574: next if (($no_ownblock) &&
1.491 albertel 5575: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5576: next if ($no_userblock);
1.474 raeburn 5577:
1.1303 raeburn 5578: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5579: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5580:
1.1062 raeburn 5581: my ($start,$end,$trigger) =
1.1347 raeburn 5582: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5583: if (($start != 0) &&
5584: (($startblock == 0) || ($startblock > $start))) {
5585: $startblock = $start;
1.1062 raeburn 5586: if ($trigger ne '') {
5587: $triggerblock = $trigger;
5588: }
1.502 raeburn 5589: }
5590: if (($end != 0) &&
5591: (($endblock == 0) || ($endblock < $end))) {
5592: $endblock = $end;
1.1062 raeburn 5593: if ($trigger ne '') {
5594: $triggerblock = $trigger;
5595: }
1.502 raeburn 5596: }
1.490 raeburn 5597: }
1.1062 raeburn 5598: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5599: }
5600:
5601: sub get_blocks {
1.1347 raeburn 5602: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5603: my $startblock = 0;
5604: my $endblock = 0;
1.1062 raeburn 5605: my $triggerblock = '';
1.490 raeburn 5606: my $course = $cdom.'_'.$cnum;
5607: $setters->{$course} = {};
5608: $setters->{$course}{'staff'} = [];
5609: $setters->{$course}{'times'} = [];
1.1062 raeburn 5610: $setters->{$course}{'triggers'} = [];
5611: my (@blockers,%triggered);
5612: my $now = time;
5613: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5614: if ($activity eq 'docs') {
1.1348 raeburn 5615: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5616: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5617: $blocked = 1;
5618: $nosymbcache = 1;
1.1348 raeburn 5619: $noenccheck = 1;
1.1347 raeburn 5620: }
1.1348 raeburn 5621: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5622: foreach my $block (@blockers) {
5623: if ($block =~ /^firstaccess____(.+)$/) {
5624: my $item = $1;
5625: my $type = 'map';
5626: my $timersymb = $item;
5627: if ($item eq 'course') {
5628: $type = 'course';
5629: } elsif ($item =~ /___\d+___/) {
5630: $type = 'resource';
5631: } else {
5632: $timersymb = &Apache::lonnet::symbread($item);
5633: }
5634: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5635: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5636: $triggered{$block} = {
5637: start => $start,
5638: end => $end,
5639: type => $type,
5640: };
5641: }
5642: }
5643: } else {
5644: foreach my $block (keys(%commblocks)) {
5645: if ($block =~ m/^(\d+)____(\d+)$/) {
5646: my ($start,$end) = ($1,$2);
5647: if ($start <= time && $end >= time) {
5648: if (ref($commblocks{$block}) eq 'HASH') {
5649: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5650: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5651: unless(grep(/^\Q$block\E$/,@blockers)) {
5652: push(@blockers,$block);
5653: }
5654: }
5655: }
5656: }
5657: }
5658: } elsif ($block =~ /^firstaccess____(.+)$/) {
5659: my $item = $1;
5660: my $timersymb = $item;
5661: my $type = 'map';
5662: if ($item eq 'course') {
5663: $type = 'course';
5664: } elsif ($item =~ /___\d+___/) {
5665: $type = 'resource';
5666: } else {
5667: $timersymb = &Apache::lonnet::symbread($item);
5668: }
5669: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5670: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5671: if ($start && $end) {
5672: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5673: if (ref($commblocks{$block}) eq 'HASH') {
5674: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5675: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5676: unless(grep(/^\Q$block\E$/,@blockers)) {
5677: push(@blockers,$block);
5678: $triggered{$block} = {
5679: start => $start,
5680: end => $end,
5681: type => $type,
5682: };
5683: }
5684: }
5685: }
1.1062 raeburn 5686: }
5687: }
1.490 raeburn 5688: }
1.1062 raeburn 5689: }
5690: }
5691: }
5692: foreach my $blocker (@blockers) {
5693: my ($staff_name,$staff_dom,$title,$blocks) =
5694: &parse_block_record($commblocks{$blocker});
5695: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5696: my ($start,$end,$triggertype);
5697: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5698: ($start,$end) = ($1,$2);
5699: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5700: $start = $triggered{$blocker}{'start'};
5701: $end = $triggered{$blocker}{'end'};
5702: $triggertype = $triggered{$blocker}{'type'};
5703: }
5704: if ($start) {
5705: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5706: if ($triggertype) {
5707: push(@{$$setters{$course}{'triggers'}},$triggertype);
5708: } else {
5709: push(@{$$setters{$course}{'triggers'}},0);
5710: }
5711: if ( ($startblock == 0) || ($startblock > $start) ) {
5712: $startblock = $start;
5713: if ($triggertype) {
5714: $triggerblock = $blocker;
1.474 raeburn 5715: }
5716: }
1.1062 raeburn 5717: if ( ($endblock == 0) || ($endblock < $end) ) {
5718: $endblock = $end;
5719: if ($triggertype) {
5720: $triggerblock = $blocker;
5721: }
5722: }
1.474 raeburn 5723: }
5724: }
1.1062 raeburn 5725: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5726: }
5727:
5728: sub parse_block_record {
5729: my ($record) = @_;
5730: my ($setuname,$setudom,$title,$blocks);
5731: if (ref($record) eq 'HASH') {
5732: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5733: $title = &unescape($record->{'event'});
5734: $blocks = $record->{'blocks'};
5735: } else {
5736: my @data = split(/:/,$record,3);
5737: if (scalar(@data) eq 2) {
5738: $title = $data[1];
5739: ($setuname,$setudom) = split(/@/,$data[0]);
5740: } else {
5741: ($setuname,$setudom,$title) = @data;
5742: }
5743: $blocks = { 'com' => 'on' };
5744: }
5745: return ($setuname,$setudom,$title,$blocks);
5746: }
5747:
1.854 kalberla 5748: sub blocking_status {
1.1372 raeburn 5749: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5750: my %setters;
1.890 droeschl 5751:
1.1061 raeburn 5752: # check for active blocking
1.1372 raeburn 5753: if ($clientip eq '') {
5754: $clientip = &Apache::lonnet::get_requestor_ip();
5755: }
5756: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5757: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5758: my $blocked = 0;
1.1372 raeburn 5759: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5760: $blocked = 1;
5761: }
1.890 droeschl 5762:
1.1061 raeburn 5763: # caller just wants to know whether a block is active
5764: if (!wantarray) { return $blocked; }
5765:
5766: # build a link to a popup window containing the details
5767: my $querystring = "?activity=$activity";
1.1351 raeburn 5768: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5769: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5770: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5771: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5772: } elsif ($activity eq 'docs') {
1.1347 raeburn 5773: my $showurl = &Apache::lonenc::check_encrypt($url);
5774: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5775: if ($symb) {
5776: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5777: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5778: }
1.1062 raeburn 5779: }
1.1061 raeburn 5780:
5781: my $output .= <<'END_MYBLOCK';
5782: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5783: var options = "width=" + w + ",height=" + h + ",";
5784: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5785: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5786: var newWin = window.open(url, wdwName, options);
5787: newWin.focus();
5788: }
1.890 droeschl 5789: END_MYBLOCK
1.854 kalberla 5790:
1.1061 raeburn 5791: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5792:
1.1061 raeburn 5793: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5794: my $text = &mt('Communication Blocked');
1.1217 raeburn 5795: my $class = 'LC_comblock';
1.1062 raeburn 5796: if ($activity eq 'docs') {
5797: $text = &mt('Content Access Blocked');
1.1217 raeburn 5798: $class = '';
1.1063 raeburn 5799: } elsif ($activity eq 'printout') {
5800: $text = &mt('Printing Blocked');
1.1232 raeburn 5801: } elsif ($activity eq 'passwd') {
5802: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5803: } elsif ($activity eq 'grades') {
5804: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5805: } elsif ($activity eq 'search') {
5806: $text = &mt('Search Blocked');
1.1282 raeburn 5807: } elsif ($activity eq 'alert') {
5808: $text = &mt('Checking Critical Messages Blocked');
5809: } elsif ($activity eq 'reinit') {
5810: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5811: } elsif ($activity eq 'about') {
5812: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5813: } elsif ($activity eq 'wishlist') {
5814: $text = &mt('Access to Stored Links Blocked');
5815: } elsif ($activity eq 'annotate') {
5816: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5817: }
1.1061 raeburn 5818: $output .= <<"END_BLOCK";
1.1217 raeburn 5819: <div class='$class'>
1.869 kalberla 5820: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5821: title='$text'>
5822: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5823: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5824: title='$text'>$text</a>
1.867 kalberla 5825: </div>
5826:
5827: END_BLOCK
1.474 raeburn 5828:
1.1061 raeburn 5829: return ($blocked, $output);
1.854 kalberla 5830: }
1.490 raeburn 5831:
1.60 matthew 5832: ###############################################
5833:
1.682 raeburn 5834: sub check_ip_acc {
1.1201 raeburn 5835: my ($acc,$clientip)=@_;
1.682 raeburn 5836: &Apache::lonxml::debug("acc is $acc");
5837: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5838: return 1;
5839: }
1.1339 raeburn 5840: my ($ip,$allowed);
5841: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5842: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5843: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5844: } else {
1.1350 raeburn 5845: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5846: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5847: }
1.682 raeburn 5848:
5849: my $name;
1.1219 raeburn 5850: my %access = (
5851: allowfrom => 1,
5852: denyfrom => 0,
5853: );
5854: my @allows;
5855: my @denies;
5856: foreach my $item (split(',',$acc)) {
5857: $item =~ s/^\s*//;
5858: $item =~ s/\s*$//;
5859: my $pattern;
5860: if ($item =~ /^\!(.+)$/) {
5861: push(@denies,$1);
5862: } else {
5863: push(@allows,$item);
5864: }
5865: }
5866: my $numdenies = scalar(@denies);
5867: my $numallows = scalar(@allows);
5868: my $count = 0;
5869: foreach my $pattern (@denies,@allows) {
5870: $count ++;
5871: my $acctype = 'allowfrom';
5872: if ($count <= $numdenies) {
5873: $acctype = 'denyfrom';
5874: }
1.682 raeburn 5875: if ($pattern =~ /\*$/) {
5876: #35.8.*
5877: $pattern=~s/\*//;
1.1219 raeburn 5878: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5879: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5880: #35.8.3.[34-56]
5881: my $low=$2;
5882: my $high=$3;
5883: $pattern=$1;
5884: if ($ip =~ /^\Q$pattern\E/) {
5885: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5886: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5887: }
5888: } elsif ($pattern =~ /^\*/) {
5889: #*.msu.edu
5890: $pattern=~s/\*//;
5891: if (!defined($name)) {
5892: use Socket;
5893: my $netaddr=inet_aton($ip);
5894: ($name)=gethostbyaddr($netaddr,AF_INET);
5895: }
1.1219 raeburn 5896: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5897: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5898: #127.0.0.1
1.1219 raeburn 5899: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5900: } else {
5901: #some.name.com
5902: if (!defined($name)) {
5903: use Socket;
5904: my $netaddr=inet_aton($ip);
5905: ($name)=gethostbyaddr($netaddr,AF_INET);
5906: }
1.1219 raeburn 5907: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5908: }
5909: if ($allowed =~ /^(0|1)$/) { last; }
5910: }
5911: if ($allowed eq '') {
5912: if ($numdenies && !$numallows) {
5913: $allowed = 1;
5914: } else {
5915: $allowed = 0;
1.682 raeburn 5916: }
5917: }
5918: return $allowed;
5919: }
5920:
5921: ###############################################
5922:
1.60 matthew 5923: =pod
5924:
1.112 bowersj2 5925: =head1 Domain Template Functions
5926:
5927: =over 4
5928:
5929: =item * &determinedomain()
1.60 matthew 5930:
5931: Inputs: $domain (usually will be undef)
5932:
1.63 www 5933: Returns: Determines which domain should be used for designs
1.60 matthew 5934:
5935: =cut
1.54 www 5936:
1.60 matthew 5937: ###############################################
1.63 www 5938: sub determinedomain {
5939: my $domain=shift;
1.531 albertel 5940: if (! $domain) {
1.60 matthew 5941: # Determine domain if we have not been given one
1.893 raeburn 5942: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5943: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5944: if ($env{'request.role.domain'}) {
5945: $domain=$env{'request.role.domain'};
1.60 matthew 5946: }
5947: }
1.63 www 5948: return $domain;
5949: }
5950: ###############################################
1.517 raeburn 5951:
1.518 albertel 5952: sub devalidate_domconfig_cache {
5953: my ($udom)=@_;
5954: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5955: }
5956:
5957: # ---------------------- Get domain configuration for a domain
5958: sub get_domainconf {
5959: my ($udom) = @_;
5960: my $cachetime=1800;
5961: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5962: if (defined($cached)) { return %{$result}; }
5963:
5964: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5965: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5966: my (%designhash,%legacy);
1.518 albertel 5967: if (keys(%domconfig) > 0) {
5968: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5969: if (keys(%{$domconfig{'login'}})) {
5970: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5971: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5972: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5973: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5974: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5975: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5976: if ($key eq 'loginvia') {
5977: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5978: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5979: $designhash{$udom.'.login.loginvia'} = $server;
5980: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5981:
5982: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5983: } else {
5984: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5985: }
1.948 raeburn 5986: }
1.1208 raeburn 5987: } elsif ($key eq 'headtag') {
5988: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5989: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5990: }
1.946 raeburn 5991: }
1.1208 raeburn 5992: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5993: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5994: }
1.946 raeburn 5995: }
5996: }
5997: }
1.1366 raeburn 5998: } elsif ($key eq 'saml') {
5999: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6000: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6001: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6002: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
6003: foreach my $item ('text','img','alt','url','title','notsso') {
6004: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6005: }
6006: }
6007: }
6008: }
1.946 raeburn 6009: } else {
6010: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6011: $designhash{$udom.'.login.'.$key.'_'.$img} =
6012: $domconfig{'login'}{$key}{$img};
6013: }
1.699 raeburn 6014: }
6015: } else {
6016: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6017: }
1.632 raeburn 6018: }
6019: } else {
6020: $legacy{'login'} = 1;
1.518 albertel 6021: }
1.632 raeburn 6022: } else {
6023: $legacy{'login'} = 1;
1.518 albertel 6024: }
6025: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6026: if (keys(%{$domconfig{'rolecolors'}})) {
6027: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6028: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6029: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6030: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6031: }
1.518 albertel 6032: }
6033: }
1.632 raeburn 6034: } else {
6035: $legacy{'rolecolors'} = 1;
1.518 albertel 6036: }
1.632 raeburn 6037: } else {
6038: $legacy{'rolecolors'} = 1;
1.518 albertel 6039: }
1.948 raeburn 6040: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6041: if ($domconfig{'autoenroll'}{'co-owners'}) {
6042: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6043: }
6044: }
1.632 raeburn 6045: if (keys(%legacy) > 0) {
6046: my %legacyhash = &get_legacy_domconf($udom);
6047: foreach my $item (keys(%legacyhash)) {
6048: if ($item =~ /^\Q$udom\E\.login/) {
6049: if ($legacy{'login'}) {
6050: $designhash{$item} = $legacyhash{$item};
6051: }
6052: } else {
6053: if ($legacy{'rolecolors'}) {
6054: $designhash{$item} = $legacyhash{$item};
6055: }
1.518 albertel 6056: }
6057: }
6058: }
1.632 raeburn 6059: } else {
6060: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6061: }
6062: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6063: $cachetime);
6064: return %designhash;
6065: }
6066:
1.632 raeburn 6067: sub get_legacy_domconf {
6068: my ($udom) = @_;
6069: my %legacyhash;
6070: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6071: my $designfile = $designdir.'/'.$udom.'.tab';
6072: if (-e $designfile) {
1.1317 raeburn 6073: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6074: while (my $line = <$fh>) {
6075: next if ($line =~ /^\#/);
6076: chomp($line);
6077: my ($key,$val)=(split(/\=/,$line));
6078: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6079: }
6080: close($fh);
6081: }
6082: }
1.1026 raeburn 6083: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6084: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6085: }
6086: return %legacyhash;
6087: }
6088:
1.63 www 6089: =pod
6090:
1.112 bowersj2 6091: =item * &domainlogo()
1.63 www 6092:
6093: Inputs: $domain (usually will be undef)
6094:
6095: Returns: A link to a domain logo, if the domain logo exists.
6096: If the domain logo does not exist, a description of the domain.
6097:
6098: =cut
1.112 bowersj2 6099:
1.63 www 6100: ###############################################
6101: sub domainlogo {
1.517 raeburn 6102: my $domain = &determinedomain(shift);
1.518 albertel 6103: my %designhash = &get_domainconf($domain);
1.517 raeburn 6104: # See if there is a logo
6105: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6106: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6107: if ($imgsrc =~ m{^/(adm|res)/}) {
6108: if ($imgsrc =~ m{^/res/}) {
6109: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6110: &Apache::lonnet::repcopy($local_name);
6111: }
6112: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6113: }
6114: my $alttext = $domain;
6115: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6116: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6117: }
6118: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6119: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6120: return &Apache::lonnet::domain($domain,'description');
1.59 www 6121: } else {
1.60 matthew 6122: return '';
1.59 www 6123: }
6124: }
1.63 www 6125: ##############################################
6126:
6127: =pod
6128:
1.112 bowersj2 6129: =item * &designparm()
1.63 www 6130:
6131: Inputs: $which parameter; $domain (usually will be undef)
6132:
6133: Returns: value of designparamter $which
6134:
6135: =cut
1.112 bowersj2 6136:
1.397 albertel 6137:
1.400 albertel 6138: ##############################################
1.397 albertel 6139: sub designparm {
6140: my ($which,$domain)=@_;
6141: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6142: return $env{'environment.color.'.$which};
1.96 www 6143: }
1.63 www 6144: $domain=&determinedomain($domain);
1.1016 raeburn 6145: my %domdesign;
6146: unless ($domain eq 'public') {
6147: %domdesign = &get_domainconf($domain);
6148: }
1.520 raeburn 6149: my $output;
1.517 raeburn 6150: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6151: $output = $domdesign{$domain.'.'.$which};
1.63 www 6152: } else {
1.520 raeburn 6153: $output = $defaultdesign{$which};
6154: }
6155: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6156: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6157: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6158: if ($output =~ m{^/res/}) {
6159: my $local_name = &Apache::lonnet::filelocation('',$output);
6160: &Apache::lonnet::repcopy($local_name);
6161: }
1.520 raeburn 6162: $output = &lonhttpdurl($output);
6163: }
1.63 www 6164: }
1.520 raeburn 6165: return $output;
1.63 www 6166: }
1.59 www 6167:
1.822 bisitz 6168: ##############################################
6169: =pod
6170:
1.832 bisitz 6171: =item * &authorspace()
6172:
1.1028 raeburn 6173: Inputs: $url (usually will be undef).
1.832 bisitz 6174:
1.1132 raeburn 6175: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6176: directory being viewed (or for which action is being taken).
6177: If $url is provided, and begins /priv/<domain>/<uname>
6178: the path will be that portion of the $context argument.
6179: Otherwise the path will be for the author space of the current
6180: user when the current role is author, or for that of the
6181: co-author/assistant co-author space when the current role
6182: is co-author or assistant co-author.
1.832 bisitz 6183:
6184: =cut
6185:
6186: sub authorspace {
1.1028 raeburn 6187: my ($url) = @_;
6188: if ($url ne '') {
6189: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6190: return $1;
6191: }
6192: }
1.832 bisitz 6193: my $caname = '';
1.1024 www 6194: my $cadom = '';
1.1028 raeburn 6195: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6196: ($cadom,$caname) =
1.832 bisitz 6197: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6198: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6199: $caname = $env{'user.name'};
1.1024 www 6200: $cadom = $env{'user.domain'};
1.832 bisitz 6201: }
1.1028 raeburn 6202: if (($caname ne '') && ($cadom ne '')) {
6203: return "/priv/$cadom/$caname/";
6204: }
6205: return;
1.832 bisitz 6206: }
6207:
6208: ##############################################
6209: =pod
6210:
1.822 bisitz 6211: =item * &head_subbox()
6212:
6213: Inputs: $content (contains HTML code with page functions, etc.)
6214:
6215: Returns: HTML div with $content
6216: To be included in page header
6217:
6218: =cut
6219:
6220: sub head_subbox {
6221: my ($content)=@_;
6222: my $output =
1.993 raeburn 6223: '<div class="LC_head_subbox">'
1.822 bisitz 6224: .$content
6225: .'</div>'
6226: }
6227:
6228: ##############################################
6229: =pod
6230:
6231: =item * &CSTR_pageheader()
6232:
1.1026 raeburn 6233: Input: (optional) filename from which breadcrumb trail is built.
6234: In most cases no input as needed, as $env{'request.filename'}
6235: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6236: frameset flag
6237: If page header is being requested for use in a frameset, then
6238: the second (option) argument -- frameset will be true, and
6239: the target attribute set for links should be target="_parent".
1.822 bisitz 6240:
6241: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6242: To be included on Authoring Space pages
1.822 bisitz 6243:
6244: =cut
6245:
6246: sub CSTR_pageheader {
1.1379 raeburn 6247: my ($trailfile,$frameset) = @_;
1.1026 raeburn 6248: if ($trailfile eq '') {
6249: $trailfile = $env{'request.filename'};
6250: }
6251:
6252: # this is for resources; directories have customtitle, and crumbs
6253: # and select recent are created in lonpubdir.pm
6254:
6255: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6256: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6257: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6258: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6259: $formaction =~ s{/+}{/}g;
1.822 bisitz 6260:
6261: my $parentpath = '';
6262: my $lastitem = '';
6263: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6264: $parentpath = $1;
6265: $lastitem = $2;
6266: } else {
6267: $lastitem = $thisdisfn;
6268: }
1.921 bisitz 6269:
1.1246 raeburn 6270: my ($crsauthor,$title);
6271: if (($env{'request.course.id'}) &&
6272: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6273: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6274: $crsauthor = 1;
6275: $title = &mt('Course Authoring Space');
6276: } else {
6277: $title = &mt('Authoring Space');
6278: }
6279:
1.1379 raeburn 6280: my ($target,$crumbtarget) = (' target="_top"','_top');
6281: if ($frameset) {
6282: $target = ' target="_parent"';
6283: $crumbtarget = '_parent';
6284: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6285: $target = '';
6286: $crumbtarget = '';
1.1379 raeburn 6287: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6288: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6289: $crumbtarget = $env{'request.deeplink.target'};
6290: }
1.1313 raeburn 6291:
1.921 bisitz 6292: my $output =
1.822 bisitz 6293: '<div>'
6294: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6295: .'<b>'.$title.'</b> '
1.1314 raeburn 6296: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6297: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6298:
6299: if ($lastitem) {
6300: $output .=
6301: '<span class="LC_filename">'
6302: .$lastitem
6303: .'</span>';
6304: }
1.1245 raeburn 6305:
1.1246 raeburn 6306: if ($crsauthor) {
1.1379 raeburn 6307: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6308: } else {
6309: $output .=
6310: '<br />'
1.1314 raeburn 6311: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6312: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6313: .'</form>'
1.1379 raeburn 6314: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6315: }
6316: $output .= '</div>';
1.921 bisitz 6317:
6318: return $output;
1.822 bisitz 6319: }
6320:
1.60 matthew 6321: ###############################################
6322: ###############################################
6323:
6324: =pod
6325:
1.112 bowersj2 6326: =back
6327:
1.549 albertel 6328: =head1 HTML Helpers
1.112 bowersj2 6329:
6330: =over 4
6331:
6332: =item * &bodytag()
1.60 matthew 6333:
6334: Returns a uniform header for LON-CAPA web pages.
6335:
6336: Inputs:
6337:
1.112 bowersj2 6338: =over 4
6339:
6340: =item * $title, A title to be displayed on the page.
6341:
6342: =item * $function, the current role (can be undef).
6343:
6344: =item * $addentries, extra parameters for the <body> tag.
6345:
6346: =item * $bodyonly, if defined, only return the <body> tag.
6347:
6348: =item * $domain, if defined, force a given domain.
6349:
6350: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6351: text interface only)
1.60 matthew 6352:
1.814 bisitz 6353: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6354: navigational links
1.317 albertel 6355:
1.338 albertel 6356: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6357:
1.460 albertel 6358: =item * $args, optional argument valid values are
6359: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6360: use_absolute -> for external resource or syllabus, this will
6361: contain https://<hostname> if server uses
6362: https (as per hosts.tab), but request is for http
6363: hostname -> hostname, from $r->hostname().
1.460 albertel 6364:
1.1096 raeburn 6365: =item * $advtoolsref, optional argument, ref to an array containing
6366: inlineremote items to be added in "Functions" menu below
6367: breadcrumbs.
6368:
1.1316 raeburn 6369: =item * $ltiscope, optional argument, will be one of: resource, map or
6370: course, if LON-CAPA is in LTI Provider context. Value is
6371: the scope of use, i.e., launch was for access to a single, a map
6372: or the entire course.
6373:
6374: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6375: context, this will contain the URL for the landing item in
6376: the course, after launch from an LTI Consumer
6377:
1.1318 raeburn 6378: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6379: context, this will contain a reference to hash of items
6380: to be included in the page header and/or inline menu.
6381:
1.112 bowersj2 6382: =back
6383:
1.60 matthew 6384: Returns: A uniform header for LON-CAPA web pages.
6385: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6386: If $bodyonly is undef or zero, an html string containing a <body> tag and
6387: other decorations will be returned.
6388:
6389: =cut
6390:
1.54 www 6391: sub bodytag {
1.831 bisitz 6392: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6393: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
6394: $ltimenu,$menucoll,$menuref)=@_;
1.339 albertel 6395:
1.954 raeburn 6396: my $public;
6397: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6398: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6399: $public = 1;
6400: }
1.460 albertel 6401: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6402: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6403: my $hostname = $args->{'hostname'};
1.339 albertel 6404:
1.183 matthew 6405: $function = &get_users_function() if (!$function);
1.339 albertel 6406: my $img = &designparm($function.'.img',$domain);
6407: my $font = &designparm($function.'.font',$domain);
6408: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6409:
1.803 bisitz 6410: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6411: 'bgcolor' => $pgbg,
1.339 albertel 6412: 'text' => $font,
6413: 'alink' => &designparm($function.'.alink',$domain),
6414: 'vlink' => &designparm($function.'.vlink',$domain),
6415: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6416: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6417:
1.63 www 6418: # role and realm
1.1178 raeburn 6419: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6420: if ($realm) {
6421: $realm = '/'.$realm;
6422: }
1.1357 raeburn 6423: if ($role eq 'ca') {
1.479 albertel 6424: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6425: $realm = &plainname($rname,$rdom);
1.378 raeburn 6426: }
1.55 www 6427: # realm
1.1357 raeburn 6428: my ($cid,$sec);
1.258 albertel 6429: if ($env{'request.course.id'}) {
1.1357 raeburn 6430: $cid = $env{'request.course.id'};
6431: if ($env{'request.course.sec'}) {
6432: $sec = $env{'request.course.sec'};
6433: }
6434: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6435: if (&Apache::lonnet::is_course($1,$2)) {
6436: $cid = $1.'_'.$2;
6437: $sec = $3;
6438: }
6439: }
6440: if ($cid) {
1.378 raeburn 6441: if ($env{'request.role'} !~ /^cr/) {
6442: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6443: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6444: if ($env{'request.role.desc'}) {
6445: $role = $env{'request.role.desc'};
6446: } else {
6447: $role = &mt('Helpdesk[_1]',' '.$2);
6448: }
1.1257 raeburn 6449: } else {
6450: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6451: }
1.1357 raeburn 6452: if ($sec) {
6453: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6454: }
1.1357 raeburn 6455: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6456: } else {
6457: $role = &Apache::lonnet::plaintext($role);
1.54 www 6458: }
1.433 albertel 6459:
1.359 albertel 6460: if (!$realm) { $realm=' '; }
1.330 albertel 6461:
1.438 albertel 6462: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6463:
1.101 www 6464: # construct main body tag
1.359 albertel 6465: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6466: &Apache::lontexconvert::init_math_support();
1.252 albertel 6467:
1.1131 raeburn 6468: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6469:
1.1130 raeburn 6470: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6471: return $bodytag;
1.1130 raeburn 6472: }
1.359 albertel 6473:
1.954 raeburn 6474: if ($public) {
1.433 albertel 6475: undef($role);
6476: }
1.1318 raeburn 6477:
1.1359 raeburn 6478: my $showcrstitle = 1;
1.1357 raeburn 6479: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6480: if (ref($ltimenu) eq 'HASH') {
6481: unless ($ltimenu->{'role'}) {
6482: undef($role);
6483: }
6484: unless ($ltimenu->{'coursetitle'}) {
6485: $realm=' ';
1.1359 raeburn 6486: $showcrstitle = 0;
6487: }
6488: }
6489: } elsif (($cid) && ($menucoll)) {
6490: if (ref($menuref) eq 'HASH') {
6491: unless ($menuref->{'role'}) {
6492: undef($role);
6493: }
6494: unless ($menuref->{'crs'}) {
6495: $realm=' ';
6496: $showcrstitle = 0;
1.1318 raeburn 6497: }
6498: }
6499: }
6500:
1.762 bisitz 6501: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6502: #
6503: # Extra info if you are the DC
6504: my $dc_info = '';
1.1359 raeburn 6505: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6506: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6507: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6508: $dc_info =~ s/\s+$//;
1.359 albertel 6509: }
6510:
1.1237 raeburn 6511: my $crstype;
1.1357 raeburn 6512: if ($cid) {
6513: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6514: } elsif ($args->{'crstype'}) {
6515: $crstype = $args->{'crstype'};
6516: }
6517: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6518: undef($role);
6519: } else {
1.1242 raeburn 6520: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6521: }
1.853 droeschl 6522:
1.903 droeschl 6523: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6524:
6525: # if ($env{'request.state'} eq 'construct') {
6526: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6527: # }
6528:
1.1130 raeburn 6529: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6530: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6531:
1.1318 raeburn 6532: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6533: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 ! raeburn 6534: $args->{'links_disabled'},
! 6535: $args->{'links_target'});
1.359 albertel 6536:
1.1318 raeburn 6537: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6538: if ($dc_info) {
6539: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6540: }
6541: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6542: <em>$realm</em> $dc_info</div>|;
6543: return $bodytag;
6544: }
1.894 droeschl 6545:
1.1318 raeburn 6546: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6547: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6548: }
1.916 droeschl 6549:
1.1318 raeburn 6550: $bodytag .= $right;
1.852 droeschl 6551:
1.1318 raeburn 6552: if ($dc_info) {
6553: $dc_info = &dc_courseid_toggle($dc_info);
6554: }
6555: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6556: }
1.916 droeschl 6557:
1.1169 raeburn 6558: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6559: if ($args->{'no_secondary_menu'}) {
6560: return $bodytag;
6561: }
1.1169 raeburn 6562: #don't show menus for public users
1.954 raeburn 6563: if (!$public){
1.1318 raeburn 6564: unless ($args->{'no_inline_menu'}) {
6565: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6566: $args->{'no_primary_menu'},
1.1369 raeburn 6567: $menucoll,$menuref,
1.1380 ! raeburn 6568: $args->{'links_disabled'},
! 6569: $args->{'links_target'});
1.1318 raeburn 6570: }
1.903 droeschl 6571: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6572: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6573: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6574: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6575: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6576: } elsif ($forcereg) {
6577: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6578: $args->{'group'},
1.1274 raeburn 6579: $args->{'hide_buttons'},
1.1316 raeburn 6580: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6581: } else {
6582: $bodytag .=
6583: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6584: $forcereg,$args->{'group'},
6585: $args->{'bread_crumbs'},
1.1274 raeburn 6586: $advtoolsref,'',$hostname);
1.920 raeburn 6587: }
1.903 droeschl 6588: }else{
6589: # this is to seperate menu from content when there's no secondary
6590: # menu. Especially needed for public accessible ressources.
6591: $bodytag .= '<hr style="clear:both" />';
6592: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6593: }
1.903 droeschl 6594:
1.235 raeburn 6595: return $bodytag;
1.182 matthew 6596: }
6597:
1.917 raeburn 6598: sub dc_courseid_toggle {
6599: my ($dc_info) = @_;
1.980 raeburn 6600: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6601: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6602: &mt('(More ...)').'</a></span>'.
6603: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6604: }
6605:
1.330 albertel 6606: sub make_attr_string {
6607: my ($register,$attr_ref) = @_;
6608:
6609: if ($attr_ref && !ref($attr_ref)) {
6610: die("addentries Must be a hash ref ".
6611: join(':',caller(1))." ".
6612: join(':',caller(0))." ");
6613: }
6614:
6615: if ($register) {
1.339 albertel 6616: my ($on_load,$on_unload);
6617: foreach my $key (keys(%{$attr_ref})) {
6618: if (lc($key) eq 'onload') {
6619: $on_load.=$attr_ref->{$key}.';';
6620: delete($attr_ref->{$key});
6621:
6622: } elsif (lc($key) eq 'onunload') {
6623: $on_unload.=$attr_ref->{$key}.';';
6624: delete($attr_ref->{$key});
6625: }
6626: }
1.953 droeschl 6627: $attr_ref->{'onload'} = $on_load;
6628: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6629: }
1.339 albertel 6630:
1.330 albertel 6631: my $attr_string;
1.1159 raeburn 6632: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6633: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6634: }
6635: return $attr_string;
6636: }
6637:
6638:
1.182 matthew 6639: ###############################################
1.251 albertel 6640: ###############################################
6641:
6642: =pod
6643:
6644: =item * &endbodytag()
6645:
6646: Returns a uniform footer for LON-CAPA web pages.
6647:
1.635 raeburn 6648: Inputs: 1 - optional reference to an args hash
6649: If in the hash, key for noredirectlink has a value which evaluates to true,
6650: a 'Continue' link is not displayed if the page contains an
6651: internal redirect in the <head></head> section,
6652: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6653:
6654: =cut
6655:
6656: sub endbodytag {
1.635 raeburn 6657: my ($args) = @_;
1.1080 raeburn 6658: my $endbodytag;
6659: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6660: $endbodytag='</body>';
6661: }
1.315 albertel 6662: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6663: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6664: $endbodytag=
6665: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6666: &mt('Continue').'</a>'.
6667: $endbodytag;
6668: }
1.315 albertel 6669: }
1.251 albertel 6670: return $endbodytag;
6671: }
6672:
1.352 albertel 6673: =pod
6674:
6675: =item * &standard_css()
6676:
6677: Returns a style sheet
6678:
6679: Inputs: (all optional)
6680: domain -> force to color decorate a page for a specific
6681: domain
6682: function -> force usage of a specific rolish color scheme
6683: bgcolor -> override the default page bgcolor
6684:
6685: =cut
6686:
1.343 albertel 6687: sub standard_css {
1.345 albertel 6688: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6689: $function = &get_users_function() if (!$function);
6690: my $img = &designparm($function.'.img', $domain);
6691: my $tabbg = &designparm($function.'.tabbg', $domain);
6692: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6693: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6694: #second colour for later usage
1.345 albertel 6695: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6696: my $pgbg_or_bgcolor =
6697: $bgcolor ||
1.352 albertel 6698: &designparm($function.'.pgbg', $domain);
1.382 albertel 6699: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6700: my $alink = &designparm($function.'.alink', $domain);
6701: my $vlink = &designparm($function.'.vlink', $domain);
6702: my $link = &designparm($function.'.link', $domain);
6703:
1.602 albertel 6704: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6705: my $mono = 'monospace';
1.850 bisitz 6706: my $data_table_head = $sidebg;
6707: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6708: my $data_table_dark = '#E0E0E0';
1.470 banghart 6709: my $data_table_darker = '#CCCCCC';
1.349 albertel 6710: my $data_table_highlight = '#FFFF00';
1.352 albertel 6711: my $mail_new = '#FFBB77';
6712: my $mail_new_hover = '#DD9955';
6713: my $mail_read = '#BBBB77';
6714: my $mail_read_hover = '#999944';
6715: my $mail_replied = '#AAAA88';
6716: my $mail_replied_hover = '#888855';
6717: my $mail_other = '#99BBBB';
6718: my $mail_other_hover = '#669999';
1.391 albertel 6719: my $table_header = '#DDDDDD';
1.489 raeburn 6720: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6721: my $lg_border_color = '#C8C8C8';
1.952 onken 6722: my $button_hover = '#BF2317';
1.392 albertel 6723:
1.608 albertel 6724: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6725: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6726: : '0 3px 0 4px';
1.448 albertel 6727:
1.523 albertel 6728:
1.343 albertel 6729: return <<END;
1.947 droeschl 6730:
6731: /* needed for iframe to allow 100% height in FF */
6732: body, html {
6733: margin: 0;
6734: padding: 0 0.5%;
6735: height: 99%; /* to avoid scrollbars */
6736: }
6737:
1.795 www 6738: body {
1.911 bisitz 6739: font-family: $sans;
6740: line-height:130%;
6741: font-size:0.83em;
6742: color:$font;
1.795 www 6743: }
6744:
1.959 onken 6745: a:focus,
6746: a:focus img {
1.795 www 6747: color: red;
6748: }
1.698 harmsja 6749:
1.911 bisitz 6750: form, .inline {
6751: display: inline;
1.795 www 6752: }
1.721 harmsja 6753:
1.795 www 6754: .LC_right {
1.911 bisitz 6755: text-align:right;
1.795 www 6756: }
6757:
6758: .LC_middle {
1.911 bisitz 6759: vertical-align:middle;
1.795 www 6760: }
1.721 harmsja 6761:
1.1130 raeburn 6762: .LC_floatleft {
6763: float: left;
6764: }
6765:
6766: .LC_floatright {
6767: float: right;
6768: }
6769:
1.911 bisitz 6770: .LC_400Box {
6771: width:400px;
6772: }
1.721 harmsja 6773:
1.947 droeschl 6774: .LC_iframecontainer {
6775: width: 98%;
6776: margin: 0;
6777: position: fixed;
6778: top: 8.5em;
6779: bottom: 0;
6780: }
6781:
6782: .LC_iframecontainer iframe{
6783: border: none;
6784: width: 100%;
6785: height: 100%;
6786: }
6787:
1.778 bisitz 6788: .LC_filename {
6789: font-family: $mono;
6790: white-space:pre;
1.921 bisitz 6791: font-size: 120%;
1.778 bisitz 6792: }
6793:
6794: .LC_fileicon {
6795: border: none;
6796: height: 1.3em;
6797: vertical-align: text-bottom;
6798: margin-right: 0.3em;
6799: text-decoration:none;
6800: }
6801:
1.1008 www 6802: .LC_setting {
6803: text-decoration:underline;
6804: }
6805:
1.350 albertel 6806: .LC_error {
6807: color: red;
6808: }
1.795 www 6809:
1.1097 bisitz 6810: .LC_warning {
6811: color: darkorange;
6812: }
6813:
1.457 albertel 6814: .LC_diff_removed {
1.733 bisitz 6815: color: red;
1.394 albertel 6816: }
1.532 albertel 6817:
6818: .LC_info,
1.457 albertel 6819: .LC_success,
6820: .LC_diff_added {
1.350 albertel 6821: color: green;
6822: }
1.795 www 6823:
1.802 bisitz 6824: div.LC_confirm_box {
6825: background-color: #FAFAFA;
6826: border: 1px solid $lg_border_color;
6827: margin-right: 0;
6828: padding: 5px;
6829: }
6830:
6831: div.LC_confirm_box .LC_error img,
6832: div.LC_confirm_box .LC_success img {
6833: vertical-align: middle;
6834: }
6835:
1.1242 raeburn 6836: .LC_maxwidth {
6837: max-width: 100%;
6838: height: auto;
6839: }
6840:
1.1243 raeburn 6841: .LC_textsize_mobile {
6842: \@media only screen and (max-device-width: 480px) {
6843: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6844: }
6845: }
6846:
1.440 albertel 6847: .LC_icon {
1.771 droeschl 6848: border: none;
1.790 droeschl 6849: vertical-align: middle;
1.771 droeschl 6850: }
6851:
1.543 albertel 6852: .LC_docs_spacer {
6853: width: 25px;
6854: height: 1px;
1.771 droeschl 6855: border: none;
1.543 albertel 6856: }
1.346 albertel 6857:
1.532 albertel 6858: .LC_internal_info {
1.735 bisitz 6859: color: #999999;
1.532 albertel 6860: }
6861:
1.794 www 6862: .LC_discussion {
1.1050 www 6863: background: $data_table_dark;
1.911 bisitz 6864: border: 1px solid black;
6865: margin: 2px;
1.794 www 6866: }
6867:
6868: .LC_disc_action_left {
1.1050 www 6869: background: $sidebg;
1.911 bisitz 6870: text-align: left;
1.1050 www 6871: padding: 4px;
6872: margin: 2px;
1.794 www 6873: }
6874:
6875: .LC_disc_action_right {
1.1050 www 6876: background: $sidebg;
1.911 bisitz 6877: text-align: right;
1.1050 www 6878: padding: 4px;
6879: margin: 2px;
1.794 www 6880: }
6881:
6882: .LC_disc_new_item {
1.911 bisitz 6883: background: white;
6884: border: 2px solid red;
1.1050 www 6885: margin: 4px;
6886: padding: 4px;
1.794 www 6887: }
6888:
6889: .LC_disc_old_item {
1.911 bisitz 6890: background: white;
1.1050 www 6891: margin: 4px;
6892: padding: 4px;
1.794 www 6893: }
6894:
1.458 albertel 6895: table.LC_pastsubmission {
6896: border: 1px solid black;
6897: margin: 2px;
6898: }
6899:
1.924 bisitz 6900: table#LC_menubuttons {
1.345 albertel 6901: width: 100%;
6902: background: $pgbg;
1.392 albertel 6903: border: 2px;
1.402 albertel 6904: border-collapse: separate;
1.803 bisitz 6905: padding: 0;
1.345 albertel 6906: }
1.392 albertel 6907:
1.801 tempelho 6908: table#LC_title_bar a {
6909: color: $fontmenu;
6910: }
1.836 bisitz 6911:
1.807 droeschl 6912: table#LC_title_bar {
1.819 tempelho 6913: clear: both;
1.836 bisitz 6914: display: none;
1.807 droeschl 6915: }
6916:
1.795 www 6917: table#LC_title_bar,
1.933 droeschl 6918: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6919: table#LC_title_bar.LC_with_remote {
1.359 albertel 6920: width: 100%;
1.392 albertel 6921: border-color: $pgbg;
6922: border-style: solid;
6923: border-width: $border;
1.379 albertel 6924: background: $pgbg;
1.801 tempelho 6925: color: $fontmenu;
1.392 albertel 6926: border-collapse: collapse;
1.803 bisitz 6927: padding: 0;
1.819 tempelho 6928: margin: 0;
1.359 albertel 6929: }
1.795 www 6930:
1.933 droeschl 6931: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6932: margin: 0;
6933: padding: 0;
1.933 droeschl 6934: position: relative;
6935: list-style: none;
1.913 droeschl 6936: }
1.933 droeschl 6937: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6938: display: inline;
6939: }
1.933 droeschl 6940:
6941: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6942: padding: 0;
1.933 droeschl 6943: margin: 0;
6944: float: left;
1.913 droeschl 6945: }
1.933 droeschl 6946: .LC_breadcrumb_tools_tools {
6947: padding: 0;
6948: margin: 0;
1.913 droeschl 6949: float: right;
6950: }
6951:
1.1240 raeburn 6952: .LC_placement_prog {
6953: padding-right: 20px;
6954: font-weight: bold;
6955: font-size: 90%;
6956: }
6957:
1.359 albertel 6958: table#LC_title_bar td {
6959: background: $tabbg;
6960: }
1.795 www 6961:
1.911 bisitz 6962: table#LC_menubuttons img {
1.803 bisitz 6963: border: none;
1.346 albertel 6964: }
1.795 www 6965:
1.842 droeschl 6966: .LC_breadcrumbs_component {
1.911 bisitz 6967: float: right;
6968: margin: 0 1em;
1.357 albertel 6969: }
1.842 droeschl 6970: .LC_breadcrumbs_component img {
1.911 bisitz 6971: vertical-align: middle;
1.777 tempelho 6972: }
1.795 www 6973:
1.1243 raeburn 6974: .LC_breadcrumbs_hoverable {
6975: background: $sidebg;
6976: }
6977:
1.383 albertel 6978: td.LC_table_cell_checkbox {
6979: text-align: center;
6980: }
1.795 www 6981:
6982: .LC_fontsize_small {
1.911 bisitz 6983: font-size: 70%;
1.705 tempelho 6984: }
6985:
1.844 bisitz 6986: #LC_breadcrumbs {
1.911 bisitz 6987: clear:both;
6988: background: $sidebg;
6989: border-bottom: 1px solid $lg_border_color;
6990: line-height: 2.5em;
1.933 droeschl 6991: overflow: hidden;
1.911 bisitz 6992: margin: 0;
6993: padding: 0;
1.995 raeburn 6994: text-align: left;
1.819 tempelho 6995: }
1.862 bisitz 6996:
1.1098 bisitz 6997: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6998: clear:both;
6999: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7000: border: 1px solid $sidebg;
1.1098 bisitz 7001: margin: 0 0 10px 0;
1.966 bisitz 7002: padding: 3px;
1.995 raeburn 7003: text-align: left;
1.822 bisitz 7004: }
7005:
1.795 www 7006: .LC_fontsize_medium {
1.911 bisitz 7007: font-size: 85%;
1.705 tempelho 7008: }
7009:
1.795 www 7010: .LC_fontsize_large {
1.911 bisitz 7011: font-size: 120%;
1.705 tempelho 7012: }
7013:
1.346 albertel 7014: .LC_menubuttons_inline_text {
7015: color: $font;
1.698 harmsja 7016: font-size: 90%;
1.701 harmsja 7017: padding-left:3px;
1.346 albertel 7018: }
7019:
1.934 droeschl 7020: .LC_menubuttons_inline_text img{
7021: vertical-align: middle;
7022: }
7023:
1.1051 www 7024: li.LC_menubuttons_inline_text img {
1.951 onken 7025: cursor:pointer;
1.1002 droeschl 7026: text-decoration: none;
1.951 onken 7027: }
7028:
1.526 www 7029: .LC_menubuttons_link {
7030: text-decoration: none;
7031: }
1.795 www 7032:
1.522 albertel 7033: .LC_menubuttons_category {
1.521 www 7034: color: $font;
1.526 www 7035: background: $pgbg;
1.521 www 7036: font-size: larger;
7037: font-weight: bold;
7038: }
7039:
1.346 albertel 7040: td.LC_menubuttons_text {
1.911 bisitz 7041: color: $font;
1.346 albertel 7042: }
1.706 harmsja 7043:
1.346 albertel 7044: .LC_current_location {
7045: background: $tabbg;
7046: }
1.795 www 7047:
1.1286 raeburn 7048: td.LC_zero_height {
7049: line-height: 0;
7050: cellpadding: 0;
7051: }
7052:
1.938 bisitz 7053: table.LC_data_table {
1.347 albertel 7054: border: 1px solid #000000;
1.402 albertel 7055: border-collapse: separate;
1.426 albertel 7056: border-spacing: 1px;
1.610 albertel 7057: background: $pgbg;
1.347 albertel 7058: }
1.795 www 7059:
1.422 albertel 7060: .LC_data_table_dense {
7061: font-size: small;
7062: }
1.795 www 7063:
1.507 raeburn 7064: table.LC_nested_outer {
7065: border: 1px solid #000000;
1.589 raeburn 7066: border-collapse: collapse;
1.803 bisitz 7067: border-spacing: 0;
1.507 raeburn 7068: width: 100%;
7069: }
1.795 www 7070:
1.879 raeburn 7071: table.LC_innerpickbox,
1.507 raeburn 7072: table.LC_nested {
1.803 bisitz 7073: border: none;
1.589 raeburn 7074: border-collapse: collapse;
1.803 bisitz 7075: border-spacing: 0;
1.507 raeburn 7076: width: 100%;
7077: }
1.795 www 7078:
1.911 bisitz 7079: table.LC_data_table tr th,
7080: table.LC_calendar tr th,
1.879 raeburn 7081: table.LC_prior_tries tr th,
7082: table.LC_innerpickbox tr th {
1.349 albertel 7083: font-weight: bold;
7084: background-color: $data_table_head;
1.801 tempelho 7085: color:$fontmenu;
1.701 harmsja 7086: font-size:90%;
1.347 albertel 7087: }
1.795 www 7088:
1.879 raeburn 7089: table.LC_innerpickbox tr th,
7090: table.LC_innerpickbox tr td {
7091: vertical-align: top;
7092: }
7093:
1.711 raeburn 7094: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7095: background-color: #CCCCCC;
1.711 raeburn 7096: font-weight: bold;
7097: text-align: left;
7098: }
1.795 www 7099:
1.912 bisitz 7100: table.LC_data_table tr.LC_odd_row > td {
7101: background-color: $data_table_light;
7102: padding: 2px;
7103: vertical-align: top;
7104: }
7105:
1.809 bisitz 7106: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7107: background-color: $data_table_light;
1.912 bisitz 7108: vertical-align: top;
7109: }
7110:
7111: table.LC_data_table tr.LC_even_row > td {
7112: background-color: $data_table_dark;
1.425 albertel 7113: padding: 2px;
1.900 bisitz 7114: vertical-align: top;
1.347 albertel 7115: }
1.795 www 7116:
1.809 bisitz 7117: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7118: background-color: $data_table_dark;
1.900 bisitz 7119: vertical-align: top;
1.347 albertel 7120: }
1.795 www 7121:
1.425 albertel 7122: table.LC_data_table tr.LC_data_table_highlight td {
7123: background-color: $data_table_darker;
7124: }
1.795 www 7125:
1.639 raeburn 7126: table.LC_data_table tr td.LC_leftcol_header {
7127: background-color: $data_table_head;
7128: font-weight: bold;
7129: }
1.795 www 7130:
1.451 albertel 7131: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7132: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7133: font-weight: bold;
7134: font-style: italic;
7135: text-align: center;
7136: padding: 8px;
1.347 albertel 7137: }
1.795 www 7138:
1.1114 raeburn 7139: table.LC_data_table tr.LC_empty_row td,
7140: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7141: background-color: $sidebg;
7142: }
7143:
7144: table.LC_nested tr.LC_empty_row td {
7145: background-color: #FFFFFF;
7146: }
7147:
1.890 droeschl 7148: table.LC_caption {
7149: }
7150:
1.507 raeburn 7151: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7152: padding: 4ex
7153: }
1.795 www 7154:
1.507 raeburn 7155: table.LC_nested_outer tr th {
7156: font-weight: bold;
1.801 tempelho 7157: color:$fontmenu;
1.507 raeburn 7158: background-color: $data_table_head;
1.701 harmsja 7159: font-size: small;
1.507 raeburn 7160: border-bottom: 1px solid #000000;
7161: }
1.795 www 7162:
1.507 raeburn 7163: table.LC_nested_outer tr td.LC_subheader {
7164: background-color: $data_table_head;
7165: font-weight: bold;
7166: font-size: small;
7167: border-bottom: 1px solid #000000;
7168: text-align: right;
1.451 albertel 7169: }
1.795 www 7170:
1.507 raeburn 7171: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7172: background-color: #CCCCCC;
1.451 albertel 7173: font-weight: bold;
7174: font-size: small;
1.507 raeburn 7175: text-align: center;
7176: }
1.795 www 7177:
1.589 raeburn 7178: table.LC_nested tr.LC_info_row td.LC_left_item,
7179: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7180: text-align: left;
1.451 albertel 7181: }
1.795 www 7182:
1.507 raeburn 7183: table.LC_nested td {
1.735 bisitz 7184: background-color: #FFFFFF;
1.451 albertel 7185: font-size: small;
1.507 raeburn 7186: }
1.795 www 7187:
1.507 raeburn 7188: table.LC_nested_outer tr th.LC_right_item,
7189: table.LC_nested tr.LC_info_row td.LC_right_item,
7190: table.LC_nested tr.LC_odd_row td.LC_right_item,
7191: table.LC_nested tr td.LC_right_item {
1.451 albertel 7192: text-align: right;
7193: }
7194:
1.507 raeburn 7195: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7196: background-color: #EEEEEE;
1.451 albertel 7197: }
7198:
1.473 raeburn 7199: table.LC_createuser {
7200: }
7201:
7202: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7203: font-size: small;
1.473 raeburn 7204: }
7205:
7206: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7207: background-color: #CCCCCC;
1.473 raeburn 7208: font-weight: bold;
7209: text-align: center;
7210: }
7211:
1.349 albertel 7212: table.LC_calendar {
7213: border: 1px solid #000000;
7214: border-collapse: collapse;
1.917 raeburn 7215: width: 98%;
1.349 albertel 7216: }
1.795 www 7217:
1.349 albertel 7218: table.LC_calendar_pickdate {
7219: font-size: xx-small;
7220: }
1.795 www 7221:
1.349 albertel 7222: table.LC_calendar tr td {
7223: border: 1px solid #000000;
7224: vertical-align: top;
1.917 raeburn 7225: width: 14%;
1.349 albertel 7226: }
1.795 www 7227:
1.349 albertel 7228: table.LC_calendar tr td.LC_calendar_day_empty {
7229: background-color: $data_table_dark;
7230: }
1.795 www 7231:
1.779 bisitz 7232: table.LC_calendar tr td.LC_calendar_day_current {
7233: background-color: $data_table_highlight;
1.777 tempelho 7234: }
1.795 www 7235:
1.938 bisitz 7236: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7237: background-color: $mail_new;
7238: }
1.795 www 7239:
1.938 bisitz 7240: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7241: background-color: $mail_new_hover;
7242: }
1.795 www 7243:
1.938 bisitz 7244: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7245: background-color: $mail_read;
7246: }
1.795 www 7247:
1.938 bisitz 7248: /*
7249: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7250: background-color: $mail_read_hover;
7251: }
1.938 bisitz 7252: */
1.795 www 7253:
1.938 bisitz 7254: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7255: background-color: $mail_replied;
7256: }
1.795 www 7257:
1.938 bisitz 7258: /*
7259: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7260: background-color: $mail_replied_hover;
7261: }
1.938 bisitz 7262: */
1.795 www 7263:
1.938 bisitz 7264: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7265: background-color: $mail_other;
7266: }
1.795 www 7267:
1.938 bisitz 7268: /*
7269: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7270: background-color: $mail_other_hover;
7271: }
1.938 bisitz 7272: */
1.494 raeburn 7273:
1.777 tempelho 7274: table.LC_data_table tr > td.LC_browser_file,
7275: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7276: background: #AAEE77;
1.389 albertel 7277: }
1.795 www 7278:
1.777 tempelho 7279: table.LC_data_table tr > td.LC_browser_file_locked,
7280: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7281: background: #FFAA99;
1.387 albertel 7282: }
1.795 www 7283:
1.777 tempelho 7284: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7285: background: #888888;
1.779 bisitz 7286: }
1.795 www 7287:
1.777 tempelho 7288: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7289: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7290: background: #F8F866;
1.777 tempelho 7291: }
1.795 www 7292:
1.696 bisitz 7293: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7294: background: #E0E8FF;
1.387 albertel 7295: }
1.696 bisitz 7296:
1.707 bisitz 7297: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7298: /* background: #77FF77; */
1.707 bisitz 7299: }
1.795 www 7300:
1.707 bisitz 7301: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7302: border-right: 8px solid #FFFF77;
1.707 bisitz 7303: }
1.795 www 7304:
1.707 bisitz 7305: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7306: border-right: 8px solid #FFAA77;
1.707 bisitz 7307: }
1.795 www 7308:
1.707 bisitz 7309: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7310: border-right: 8px solid #FF7777;
1.707 bisitz 7311: }
1.795 www 7312:
1.707 bisitz 7313: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7314: border-right: 8px solid #AAFF77;
1.707 bisitz 7315: }
1.795 www 7316:
1.707 bisitz 7317: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7318: border-right: 8px solid #11CC55;
1.707 bisitz 7319: }
7320:
1.388 albertel 7321: span.LC_current_location {
1.701 harmsja 7322: font-size:larger;
1.388 albertel 7323: background: $pgbg;
7324: }
1.387 albertel 7325:
1.1029 www 7326: span.LC_current_nav_location {
7327: font-weight:bold;
7328: background: $sidebg;
7329: }
7330:
1.395 albertel 7331: span.LC_parm_menu_item {
7332: font-size: larger;
7333: }
1.795 www 7334:
1.395 albertel 7335: span.LC_parm_scope_all {
7336: color: red;
7337: }
1.795 www 7338:
1.395 albertel 7339: span.LC_parm_scope_folder {
7340: color: green;
7341: }
1.795 www 7342:
1.395 albertel 7343: span.LC_parm_scope_resource {
7344: color: orange;
7345: }
1.795 www 7346:
1.395 albertel 7347: span.LC_parm_part {
7348: color: blue;
7349: }
1.795 www 7350:
1.911 bisitz 7351: span.LC_parm_folder,
7352: span.LC_parm_symb {
1.395 albertel 7353: font-size: x-small;
7354: font-family: $mono;
7355: color: #AAAAAA;
7356: }
7357:
1.977 bisitz 7358: ul.LC_parm_parmlist li {
7359: display: inline-block;
7360: padding: 0.3em 0.8em;
7361: vertical-align: top;
7362: width: 150px;
7363: border-top:1px solid $lg_border_color;
7364: }
7365:
1.795 www 7366: td.LC_parm_overview_level_menu,
7367: td.LC_parm_overview_map_menu,
7368: td.LC_parm_overview_parm_selectors,
7369: td.LC_parm_overview_restrictions {
1.396 albertel 7370: border: 1px solid black;
7371: border-collapse: collapse;
7372: }
1.795 www 7373:
1.1285 raeburn 7374: span.LC_parm_recursive,
7375: td.LC_parm_recursive {
7376: font-weight: bold;
7377: font-size: smaller;
7378: }
7379:
1.396 albertel 7380: table.LC_parm_overview_restrictions td {
7381: border-width: 1px 4px 1px 4px;
7382: border-style: solid;
7383: border-color: $pgbg;
7384: text-align: center;
7385: }
1.795 www 7386:
1.396 albertel 7387: table.LC_parm_overview_restrictions th {
7388: background: $tabbg;
7389: border-width: 1px 4px 1px 4px;
7390: border-style: solid;
7391: border-color: $pgbg;
7392: }
1.795 www 7393:
1.398 albertel 7394: table#LC_helpmenu {
1.803 bisitz 7395: border: none;
1.398 albertel 7396: height: 55px;
1.803 bisitz 7397: border-spacing: 0;
1.398 albertel 7398: }
7399:
7400: table#LC_helpmenu fieldset legend {
7401: font-size: larger;
7402: }
1.795 www 7403:
1.397 albertel 7404: table#LC_helpmenu_links {
7405: width: 100%;
7406: border: 1px solid black;
7407: background: $pgbg;
1.803 bisitz 7408: padding: 0;
1.397 albertel 7409: border-spacing: 1px;
7410: }
1.795 www 7411:
1.397 albertel 7412: table#LC_helpmenu_links tr td {
7413: padding: 1px;
7414: background: $tabbg;
1.399 albertel 7415: text-align: center;
7416: font-weight: bold;
1.397 albertel 7417: }
1.396 albertel 7418:
1.795 www 7419: table#LC_helpmenu_links a:link,
7420: table#LC_helpmenu_links a:visited,
1.397 albertel 7421: table#LC_helpmenu_links a:active {
7422: text-decoration: none;
7423: color: $font;
7424: }
1.795 www 7425:
1.397 albertel 7426: table#LC_helpmenu_links a:hover {
7427: text-decoration: underline;
7428: color: $vlink;
7429: }
1.396 albertel 7430:
1.417 albertel 7431: .LC_chrt_popup_exists {
7432: border: 1px solid #339933;
7433: margin: -1px;
7434: }
1.795 www 7435:
1.417 albertel 7436: .LC_chrt_popup_up {
7437: border: 1px solid yellow;
7438: margin: -1px;
7439: }
1.795 www 7440:
1.417 albertel 7441: .LC_chrt_popup {
7442: border: 1px solid #8888FF;
7443: background: #CCCCFF;
7444: }
1.795 www 7445:
1.421 albertel 7446: table.LC_pick_box {
7447: border-collapse: separate;
7448: background: white;
7449: border: 1px solid black;
7450: border-spacing: 1px;
7451: }
1.795 www 7452:
1.421 albertel 7453: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7454: background: $sidebg;
1.421 albertel 7455: font-weight: bold;
1.900 bisitz 7456: text-align: left;
1.740 bisitz 7457: vertical-align: top;
1.421 albertel 7458: width: 184px;
7459: padding: 8px;
7460: }
1.795 www 7461:
1.579 raeburn 7462: table.LC_pick_box td.LC_pick_box_value {
7463: text-align: left;
7464: padding: 8px;
7465: }
1.795 www 7466:
1.579 raeburn 7467: table.LC_pick_box td.LC_pick_box_select {
7468: text-align: left;
7469: padding: 8px;
7470: }
1.795 www 7471:
1.424 albertel 7472: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7473: padding: 0;
1.421 albertel 7474: height: 1px;
7475: background: black;
7476: }
1.795 www 7477:
1.421 albertel 7478: table.LC_pick_box td.LC_pick_box_submit {
7479: text-align: right;
7480: }
1.795 www 7481:
1.579 raeburn 7482: table.LC_pick_box td.LC_evenrow_value {
7483: text-align: left;
7484: padding: 8px;
7485: background-color: $data_table_light;
7486: }
1.795 www 7487:
1.579 raeburn 7488: table.LC_pick_box td.LC_oddrow_value {
7489: text-align: left;
7490: padding: 8px;
7491: background-color: $data_table_light;
7492: }
1.795 www 7493:
1.579 raeburn 7494: span.LC_helpform_receipt_cat {
7495: font-weight: bold;
7496: }
1.795 www 7497:
1.424 albertel 7498: table.LC_group_priv_box {
7499: background: white;
7500: border: 1px solid black;
7501: border-spacing: 1px;
7502: }
1.795 www 7503:
1.424 albertel 7504: table.LC_group_priv_box td.LC_pick_box_title {
7505: background: $tabbg;
7506: font-weight: bold;
7507: text-align: right;
7508: width: 184px;
7509: }
1.795 www 7510:
1.424 albertel 7511: table.LC_group_priv_box td.LC_groups_fixed {
7512: background: $data_table_light;
7513: text-align: center;
7514: }
1.795 www 7515:
1.424 albertel 7516: table.LC_group_priv_box td.LC_groups_optional {
7517: background: $data_table_dark;
7518: text-align: center;
7519: }
1.795 www 7520:
1.424 albertel 7521: table.LC_group_priv_box td.LC_groups_functionality {
7522: background: $data_table_darker;
7523: text-align: center;
7524: font-weight: bold;
7525: }
1.795 www 7526:
1.424 albertel 7527: table.LC_group_priv td {
7528: text-align: left;
1.803 bisitz 7529: padding: 0;
1.424 albertel 7530: }
7531:
7532: .LC_navbuttons {
7533: margin: 2ex 0ex 2ex 0ex;
7534: }
1.795 www 7535:
1.423 albertel 7536: .LC_topic_bar {
7537: font-weight: bold;
7538: background: $tabbg;
1.918 wenzelju 7539: margin: 1em 0em 1em 2em;
1.805 bisitz 7540: padding: 3px;
1.918 wenzelju 7541: font-size: 1.2em;
1.423 albertel 7542: }
1.795 www 7543:
1.423 albertel 7544: .LC_topic_bar span {
1.918 wenzelju 7545: left: 0.5em;
7546: position: absolute;
1.423 albertel 7547: vertical-align: middle;
1.918 wenzelju 7548: font-size: 1.2em;
1.423 albertel 7549: }
1.795 www 7550:
1.423 albertel 7551: table.LC_course_group_status {
7552: margin: 20px;
7553: }
1.795 www 7554:
1.423 albertel 7555: table.LC_status_selector td {
7556: vertical-align: top;
7557: text-align: center;
1.424 albertel 7558: padding: 4px;
7559: }
1.795 www 7560:
1.599 albertel 7561: div.LC_feedback_link {
1.616 albertel 7562: clear: both;
1.829 kalberla 7563: background: $sidebg;
1.779 bisitz 7564: width: 100%;
1.829 kalberla 7565: padding-bottom: 10px;
7566: border: 1px $tabbg solid;
1.833 kalberla 7567: height: 22px;
7568: line-height: 22px;
7569: padding-top: 5px;
7570: }
7571:
7572: div.LC_feedback_link img {
7573: height: 22px;
1.867 kalberla 7574: vertical-align:middle;
1.829 kalberla 7575: }
7576:
1.911 bisitz 7577: div.LC_feedback_link a {
1.829 kalberla 7578: text-decoration: none;
1.489 raeburn 7579: }
1.795 www 7580:
1.867 kalberla 7581: div.LC_comblock {
1.911 bisitz 7582: display:inline;
1.867 kalberla 7583: color:$font;
7584: font-size:90%;
7585: }
7586:
7587: div.LC_feedback_link div.LC_comblock {
7588: padding-left:5px;
7589: }
7590:
7591: div.LC_feedback_link div.LC_comblock a {
7592: color:$font;
7593: }
7594:
1.489 raeburn 7595: span.LC_feedback_link {
1.858 bisitz 7596: /* background: $feedback_link_bg; */
1.599 albertel 7597: font-size: larger;
7598: }
1.795 www 7599:
1.599 albertel 7600: span.LC_message_link {
1.858 bisitz 7601: /* background: $feedback_link_bg; */
1.599 albertel 7602: font-size: larger;
7603: position: absolute;
7604: right: 1em;
1.489 raeburn 7605: }
1.421 albertel 7606:
1.515 albertel 7607: table.LC_prior_tries {
1.524 albertel 7608: border: 1px solid #000000;
7609: border-collapse: separate;
7610: border-spacing: 1px;
1.515 albertel 7611: }
1.523 albertel 7612:
1.515 albertel 7613: table.LC_prior_tries td {
1.524 albertel 7614: padding: 2px;
1.515 albertel 7615: }
1.523 albertel 7616:
7617: .LC_answer_correct {
1.795 www 7618: background: lightgreen;
7619: color: darkgreen;
7620: padding: 6px;
1.523 albertel 7621: }
1.795 www 7622:
1.523 albertel 7623: .LC_answer_charged_try {
1.797 www 7624: background: #FFAAAA;
1.795 www 7625: color: darkred;
7626: padding: 6px;
1.523 albertel 7627: }
1.795 www 7628:
1.779 bisitz 7629: .LC_answer_not_charged_try,
1.523 albertel 7630: .LC_answer_no_grade,
7631: .LC_answer_late {
1.795 www 7632: background: lightyellow;
1.523 albertel 7633: color: black;
1.795 www 7634: padding: 6px;
1.523 albertel 7635: }
1.795 www 7636:
1.523 albertel 7637: .LC_answer_previous {
1.795 www 7638: background: lightblue;
7639: color: darkblue;
7640: padding: 6px;
1.523 albertel 7641: }
1.795 www 7642:
1.779 bisitz 7643: .LC_answer_no_message {
1.777 tempelho 7644: background: #FFFFFF;
7645: color: black;
1.795 www 7646: padding: 6px;
1.779 bisitz 7647: }
1.795 www 7648:
1.1334 raeburn 7649: .LC_answer_unknown,
7650: .LC_answer_warning {
1.779 bisitz 7651: background: orange;
7652: color: black;
1.795 www 7653: padding: 6px;
1.777 tempelho 7654: }
1.795 www 7655:
1.529 albertel 7656: span.LC_prior_numerical,
7657: span.LC_prior_string,
7658: span.LC_prior_custom,
7659: span.LC_prior_reaction,
7660: span.LC_prior_math {
1.925 bisitz 7661: font-family: $mono;
1.523 albertel 7662: white-space: pre;
7663: }
7664:
1.525 albertel 7665: span.LC_prior_string {
1.925 bisitz 7666: font-family: $mono;
1.525 albertel 7667: white-space: pre;
7668: }
7669:
1.523 albertel 7670: table.LC_prior_option {
7671: width: 100%;
7672: border-collapse: collapse;
7673: }
1.795 www 7674:
1.911 bisitz 7675: table.LC_prior_rank,
1.795 www 7676: table.LC_prior_match {
1.528 albertel 7677: border-collapse: collapse;
7678: }
1.795 www 7679:
1.528 albertel 7680: table.LC_prior_option tr td,
7681: table.LC_prior_rank tr td,
7682: table.LC_prior_match tr td {
1.524 albertel 7683: border: 1px solid #000000;
1.515 albertel 7684: }
7685:
1.855 bisitz 7686: .LC_nobreak {
1.544 albertel 7687: white-space: nowrap;
1.519 raeburn 7688: }
7689:
1.576 raeburn 7690: span.LC_cusr_emph {
7691: font-style: italic;
7692: }
7693:
1.633 raeburn 7694: span.LC_cusr_subheading {
7695: font-weight: normal;
7696: font-size: 85%;
7697: }
7698:
1.861 bisitz 7699: div.LC_docs_entry_move {
1.859 bisitz 7700: border: 1px solid #BBBBBB;
1.545 albertel 7701: background: #DDDDDD;
1.861 bisitz 7702: width: 22px;
1.859 bisitz 7703: padding: 1px;
7704: margin: 0;
1.545 albertel 7705: }
7706:
1.861 bisitz 7707: table.LC_data_table tr > td.LC_docs_entry_commands,
7708: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7709: font-size: x-small;
7710: }
1.795 www 7711:
1.861 bisitz 7712: .LC_docs_entry_parameter {
7713: white-space: nowrap;
7714: }
7715:
1.544 albertel 7716: .LC_docs_copy {
1.545 albertel 7717: color: #000099;
1.544 albertel 7718: }
1.795 www 7719:
1.544 albertel 7720: .LC_docs_cut {
1.545 albertel 7721: color: #550044;
1.544 albertel 7722: }
1.795 www 7723:
1.544 albertel 7724: .LC_docs_rename {
1.545 albertel 7725: color: #009900;
1.544 albertel 7726: }
1.795 www 7727:
1.544 albertel 7728: .LC_docs_remove {
1.545 albertel 7729: color: #990000;
7730: }
7731:
1.1284 raeburn 7732: .LC_docs_alias {
7733: color: #440055;
7734: }
7735:
1.1286 raeburn 7736: .LC_domprefs_email,
1.1284 raeburn 7737: .LC_docs_alias_name,
1.547 albertel 7738: .LC_docs_reinit_warn,
7739: .LC_docs_ext_edit {
7740: font-size: x-small;
7741: }
7742:
1.545 albertel 7743: table.LC_docs_adddocs td,
7744: table.LC_docs_adddocs th {
7745: border: 1px solid #BBBBBB;
7746: padding: 4px;
7747: background: #DDDDDD;
1.543 albertel 7748: }
7749:
1.584 albertel 7750: table.LC_sty_begin {
7751: background: #BBFFBB;
7752: }
1.795 www 7753:
1.584 albertel 7754: table.LC_sty_end {
7755: background: #FFBBBB;
7756: }
7757:
1.589 raeburn 7758: table.LC_double_column {
1.803 bisitz 7759: border-width: 0;
1.589 raeburn 7760: border-collapse: collapse;
7761: width: 100%;
7762: padding: 2px;
7763: }
7764:
7765: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7766: top: 2px;
1.589 raeburn 7767: left: 2px;
7768: width: 47%;
7769: vertical-align: top;
7770: }
7771:
7772: table.LC_double_column tr td.LC_right_col {
7773: top: 2px;
1.779 bisitz 7774: right: 2px;
1.589 raeburn 7775: width: 47%;
7776: vertical-align: top;
7777: }
7778:
1.591 raeburn 7779: div.LC_left_float {
7780: float: left;
7781: padding-right: 5%;
1.597 albertel 7782: padding-bottom: 4px;
1.591 raeburn 7783: }
7784:
7785: div.LC_clear_float_header {
1.597 albertel 7786: padding-bottom: 2px;
1.591 raeburn 7787: }
7788:
7789: div.LC_clear_float_footer {
1.597 albertel 7790: padding-top: 10px;
1.591 raeburn 7791: clear: both;
7792: }
7793:
1.597 albertel 7794: div.LC_grade_show_user {
1.941 bisitz 7795: /* border-left: 5px solid $sidebg; */
7796: border-top: 5px solid #000000;
7797: margin: 50px 0 0 0;
1.936 bisitz 7798: padding: 15px 0 5px 10px;
1.597 albertel 7799: }
1.795 www 7800:
1.936 bisitz 7801: div.LC_grade_show_user_odd_row {
1.941 bisitz 7802: /* border-left: 5px solid #000000; */
7803: }
7804:
7805: div.LC_grade_show_user div.LC_Box {
7806: margin-right: 50px;
1.597 albertel 7807: }
7808:
7809: div.LC_grade_submissions,
7810: div.LC_grade_message_center,
1.936 bisitz 7811: div.LC_grade_info_links {
1.597 albertel 7812: margin: 5px;
7813: width: 99%;
7814: background: #FFFFFF;
7815: }
1.795 www 7816:
1.597 albertel 7817: div.LC_grade_submissions_header,
1.936 bisitz 7818: div.LC_grade_message_center_header {
1.705 tempelho 7819: font-weight: bold;
7820: font-size: large;
1.597 albertel 7821: }
1.795 www 7822:
1.597 albertel 7823: div.LC_grade_submissions_body,
1.936 bisitz 7824: div.LC_grade_message_center_body {
1.597 albertel 7825: border: 1px solid black;
7826: width: 99%;
7827: background: #FFFFFF;
7828: }
1.795 www 7829:
1.613 albertel 7830: table.LC_scantron_action {
7831: width: 100%;
7832: }
1.795 www 7833:
1.613 albertel 7834: table.LC_scantron_action tr th {
1.698 harmsja 7835: font-weight:bold;
7836: font-style:normal;
1.613 albertel 7837: }
1.795 www 7838:
1.779 bisitz 7839: .LC_edit_problem_header,
1.614 albertel 7840: div.LC_edit_problem_footer {
1.705 tempelho 7841: font-weight: normal;
7842: font-size: medium;
1.602 albertel 7843: margin: 2px;
1.1060 bisitz 7844: background-color: $sidebg;
1.600 albertel 7845: }
1.795 www 7846:
1.600 albertel 7847: div.LC_edit_problem_header,
1.602 albertel 7848: div.LC_edit_problem_header div,
1.614 albertel 7849: div.LC_edit_problem_footer,
7850: div.LC_edit_problem_footer div,
1.602 albertel 7851: div.LC_edit_problem_editxml_header,
7852: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7853: z-index: 100;
1.600 albertel 7854: }
1.795 www 7855:
1.600 albertel 7856: div.LC_edit_problem_header_title {
1.705 tempelho 7857: font-weight: bold;
7858: font-size: larger;
1.602 albertel 7859: background: $tabbg;
7860: padding: 3px;
1.1060 bisitz 7861: margin: 0 0 5px 0;
1.602 albertel 7862: }
1.795 www 7863:
1.602 albertel 7864: table.LC_edit_problem_header_title {
7865: width: 100%;
1.600 albertel 7866: background: $tabbg;
1.602 albertel 7867: }
7868:
1.1205 golterma 7869: div.LC_edit_actionbar {
7870: background-color: $sidebg;
1.1218 droeschl 7871: margin: 0;
7872: padding: 0;
7873: line-height: 200%;
1.602 albertel 7874: }
1.795 www 7875:
1.1218 droeschl 7876: div.LC_edit_actionbar div{
7877: padding: 0;
7878: margin: 0;
7879: display: inline-block;
1.600 albertel 7880: }
1.795 www 7881:
1.1124 bisitz 7882: .LC_edit_opt {
7883: padding-left: 1em;
7884: white-space: nowrap;
7885: }
7886:
1.1152 golterma 7887: .LC_edit_problem_latexhelper{
7888: text-align: right;
7889: }
7890:
7891: #LC_edit_problem_colorful div{
7892: margin-left: 40px;
7893: }
7894:
1.1205 golterma 7895: #LC_edit_problem_codemirror div{
7896: margin-left: 0px;
7897: }
7898:
1.911 bisitz 7899: img.stift {
1.803 bisitz 7900: border-width: 0;
7901: vertical-align: middle;
1.677 riegler 7902: }
1.680 riegler 7903:
1.923 bisitz 7904: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7905: vertical-align: top;
1.777 tempelho 7906: }
1.795 www 7907:
1.716 raeburn 7908: div.LC_createcourse {
1.911 bisitz 7909: margin: 10px 10px 10px 10px;
1.716 raeburn 7910: }
7911:
1.917 raeburn 7912: .LC_dccid {
1.1130 raeburn 7913: float: right;
1.917 raeburn 7914: margin: 0.2em 0 0 0;
7915: padding: 0;
7916: font-size: 90%;
7917: display:none;
7918: }
7919:
1.897 wenzelju 7920: ol.LC_primary_menu a:hover,
1.721 harmsja 7921: ol#LC_MenuBreadcrumbs a:hover,
7922: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7923: ul#LC_secondary_menu a:hover,
1.721 harmsja 7924: .LC_FormSectionClearButton input:hover
1.795 www 7925: ul.LC_TabContent li:hover a {
1.952 onken 7926: color:$button_hover;
1.911 bisitz 7927: text-decoration:none;
1.693 droeschl 7928: }
7929:
1.779 bisitz 7930: h1 {
1.911 bisitz 7931: padding: 0;
7932: line-height:130%;
1.693 droeschl 7933: }
1.698 harmsja 7934:
1.911 bisitz 7935: h2,
7936: h3,
7937: h4,
7938: h5,
7939: h6 {
7940: margin: 5px 0 5px 0;
7941: padding: 0;
7942: line-height:130%;
1.693 droeschl 7943: }
1.795 www 7944:
7945: .LC_hcell {
1.911 bisitz 7946: padding:3px 15px 3px 15px;
7947: margin: 0;
7948: background-color:$tabbg;
7949: color:$fontmenu;
7950: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7951: }
1.795 www 7952:
1.840 bisitz 7953: .LC_Box > .LC_hcell {
1.911 bisitz 7954: margin: 0 -10px 10px -10px;
1.835 bisitz 7955: }
7956:
1.721 harmsja 7957: .LC_noBorder {
1.911 bisitz 7958: border: 0;
1.698 harmsja 7959: }
1.693 droeschl 7960:
1.721 harmsja 7961: .LC_FormSectionClearButton input {
1.911 bisitz 7962: background-color:transparent;
7963: border: none;
7964: cursor:pointer;
7965: text-decoration:underline;
1.693 droeschl 7966: }
1.763 bisitz 7967:
7968: .LC_help_open_topic {
1.911 bisitz 7969: color: #FFFFFF;
7970: background-color: #EEEEFF;
7971: margin: 1px;
7972: padding: 4px;
7973: border: 1px solid #000033;
7974: white-space: nowrap;
7975: /* vertical-align: middle; */
1.759 neumanie 7976: }
1.693 droeschl 7977:
1.911 bisitz 7978: dl,
7979: ul,
7980: div,
7981: fieldset {
7982: margin: 10px 10px 10px 0;
7983: /* overflow: hidden; */
1.693 droeschl 7984: }
1.795 www 7985:
1.1211 raeburn 7986: article.geogebraweb div {
7987: margin: 0;
7988: }
7989:
1.838 bisitz 7990: fieldset > legend {
1.911 bisitz 7991: font-weight: bold;
7992: padding: 0 5px 0 5px;
1.838 bisitz 7993: }
7994:
1.813 bisitz 7995: #LC_nav_bar {
1.911 bisitz 7996: float: left;
1.995 raeburn 7997: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7998: margin: 0 0 2px 0;
1.807 droeschl 7999: }
8000:
1.916 droeschl 8001: #LC_realm {
8002: margin: 0.2em 0 0 0;
8003: padding: 0;
8004: font-weight: bold;
8005: text-align: center;
1.995 raeburn 8006: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8007: }
8008:
1.911 bisitz 8009: #LC_nav_bar em {
8010: font-weight: bold;
8011: font-style: normal;
1.807 droeschl 8012: }
8013:
1.897 wenzelju 8014: ol.LC_primary_menu {
1.934 droeschl 8015: margin: 0;
1.1076 raeburn 8016: padding: 0;
1.807 droeschl 8017: }
8018:
1.852 droeschl 8019: ol#LC_PathBreadcrumbs {
1.911 bisitz 8020: margin: 0;
1.693 droeschl 8021: }
8022:
1.897 wenzelju 8023: ol.LC_primary_menu li {
1.1076 raeburn 8024: color: RGB(80, 80, 80);
8025: vertical-align: middle;
8026: text-align: left;
8027: list-style: none;
1.1205 golterma 8028: position: relative;
1.1076 raeburn 8029: float: left;
1.1205 golterma 8030: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8031: line-height: 1.5em;
1.1076 raeburn 8032: }
8033:
1.1205 golterma 8034: ol.LC_primary_menu li a,
8035: ol.LC_primary_menu li p {
1.1076 raeburn 8036: display: block;
8037: margin: 0;
8038: padding: 0 5px 0 10px;
8039: text-decoration: none;
8040: }
8041:
1.1205 golterma 8042: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8043: display: inline-block;
8044: width: 95%;
8045: text-align: left;
8046: }
8047:
8048: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8049: display: inline-block;
8050: width: 5%;
8051: float: right;
8052: text-align: right;
8053: font-size: 70%;
8054: }
8055:
8056: ol.LC_primary_menu ul {
1.1076 raeburn 8057: display: none;
1.1205 golterma 8058: width: 15em;
1.1076 raeburn 8059: background-color: $data_table_light;
1.1205 golterma 8060: position: absolute;
8061: top: 100%;
1.1076 raeburn 8062: }
8063:
1.1205 golterma 8064: ol.LC_primary_menu ul ul {
8065: left: 100%;
8066: top: 0;
8067: }
8068:
8069: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8070: display: block;
8071: position: absolute;
8072: margin: 0;
8073: padding: 0;
1.1078 raeburn 8074: z-index: 2;
1.1076 raeburn 8075: }
8076:
8077: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8078: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8079: font-size: 90%;
1.911 bisitz 8080: vertical-align: top;
1.1076 raeburn 8081: float: none;
1.1079 raeburn 8082: border-left: 1px solid black;
8083: border-right: 1px solid black;
1.1205 golterma 8084: /* A dark bottom border to visualize different menu options;
8085: overwritten in the create_submenu routine for the last border-bottom of the menu */
8086: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8087: }
8088:
1.1205 golterma 8089: ol.LC_primary_menu li li p:hover {
8090: color:$button_hover;
8091: text-decoration:none;
8092: background-color:$data_table_dark;
1.1076 raeburn 8093: }
8094:
8095: ol.LC_primary_menu li li a:hover {
8096: color:$button_hover;
8097: background-color:$data_table_dark;
1.693 droeschl 8098: }
8099:
1.1205 golterma 8100: /* Font-size equal to the size of the predecessors*/
8101: ol.LC_primary_menu li:hover li li {
8102: font-size: 100%;
8103: }
8104:
1.897 wenzelju 8105: ol.LC_primary_menu li img {
1.911 bisitz 8106: vertical-align: bottom;
1.934 droeschl 8107: height: 1.1em;
1.1077 raeburn 8108: margin: 0.2em 0 0 0;
1.693 droeschl 8109: }
8110:
1.897 wenzelju 8111: ol.LC_primary_menu a {
1.911 bisitz 8112: color: RGB(80, 80, 80);
8113: text-decoration: none;
1.693 droeschl 8114: }
1.795 www 8115:
1.949 droeschl 8116: ol.LC_primary_menu a.LC_new_message {
8117: font-weight:bold;
8118: color: darkred;
8119: }
8120:
1.975 raeburn 8121: ol.LC_docs_parameters {
8122: margin-left: 0;
8123: padding: 0;
8124: list-style: none;
8125: }
8126:
8127: ol.LC_docs_parameters li {
8128: margin: 0;
8129: padding-right: 20px;
8130: display: inline;
8131: }
8132:
1.976 raeburn 8133: ol.LC_docs_parameters li:before {
8134: content: "\\002022 \\0020";
8135: }
8136:
8137: li.LC_docs_parameters_title {
8138: font-weight: bold;
8139: }
8140:
8141: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8142: content: "";
8143: }
8144:
1.897 wenzelju 8145: ul#LC_secondary_menu {
1.1107 raeburn 8146: clear: right;
1.911 bisitz 8147: color: $fontmenu;
8148: background: $tabbg;
8149: list-style: none;
8150: padding: 0;
8151: margin: 0;
8152: width: 100%;
1.995 raeburn 8153: text-align: left;
1.1107 raeburn 8154: float: left;
1.808 droeschl 8155: }
8156:
1.897 wenzelju 8157: ul#LC_secondary_menu li {
1.911 bisitz 8158: font-weight: bold;
8159: line-height: 1.8em;
1.1107 raeburn 8160: border-right: 1px solid black;
8161: float: left;
8162: }
8163:
8164: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8165: background-color: $data_table_light;
8166: }
8167:
8168: ul#LC_secondary_menu li a {
1.911 bisitz 8169: padding: 0 0.8em;
1.1107 raeburn 8170: }
8171:
8172: ul#LC_secondary_menu li ul {
8173: display: none;
8174: }
8175:
8176: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8177: display: block;
8178: position: absolute;
8179: margin: 0;
8180: padding: 0;
8181: list-style:none;
8182: float: none;
8183: background-color: $data_table_light;
8184: z-index: 2;
8185: margin-left: -1px;
8186: }
8187:
8188: ul#LC_secondary_menu li ul li {
8189: font-size: 90%;
8190: vertical-align: top;
8191: border-left: 1px solid black;
1.911 bisitz 8192: border-right: 1px solid black;
1.1119 raeburn 8193: background-color: $data_table_light;
1.1107 raeburn 8194: list-style:none;
8195: float: none;
8196: }
8197:
8198: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8199: background-color: $data_table_dark;
1.807 droeschl 8200: }
8201:
1.847 tempelho 8202: ul.LC_TabContent {
1.911 bisitz 8203: display:block;
8204: background: $sidebg;
8205: border-bottom: solid 1px $lg_border_color;
8206: list-style:none;
1.1020 raeburn 8207: margin: -1px -10px 0 -10px;
1.911 bisitz 8208: padding: 0;
1.693 droeschl 8209: }
8210:
1.795 www 8211: ul.LC_TabContent li,
8212: ul.LC_TabContentBigger li {
1.911 bisitz 8213: float:left;
1.741 harmsja 8214: }
1.795 www 8215:
1.897 wenzelju 8216: ul#LC_secondary_menu li a {
1.911 bisitz 8217: color: $fontmenu;
8218: text-decoration: none;
1.693 droeschl 8219: }
1.795 www 8220:
1.721 harmsja 8221: ul.LC_TabContent {
1.952 onken 8222: min-height:20px;
1.721 harmsja 8223: }
1.795 www 8224:
8225: ul.LC_TabContent li {
1.911 bisitz 8226: vertical-align:middle;
1.959 onken 8227: padding: 0 16px 0 10px;
1.911 bisitz 8228: background-color:$tabbg;
8229: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8230: border-left: solid 1px $font;
1.721 harmsja 8231: }
1.795 www 8232:
1.847 tempelho 8233: ul.LC_TabContent .right {
1.911 bisitz 8234: float:right;
1.847 tempelho 8235: }
8236:
1.911 bisitz 8237: ul.LC_TabContent li a,
8238: ul.LC_TabContent li {
8239: color:rgb(47,47,47);
8240: text-decoration:none;
8241: font-size:95%;
8242: font-weight:bold;
1.952 onken 8243: min-height:20px;
8244: }
8245:
1.959 onken 8246: ul.LC_TabContent li a:hover,
8247: ul.LC_TabContent li a:focus {
1.952 onken 8248: color: $button_hover;
1.959 onken 8249: background:none;
8250: outline:none;
1.952 onken 8251: }
8252:
8253: ul.LC_TabContent li:hover {
8254: color: $button_hover;
8255: cursor:pointer;
1.721 harmsja 8256: }
1.795 www 8257:
1.911 bisitz 8258: ul.LC_TabContent li.active {
1.952 onken 8259: color: $font;
1.911 bisitz 8260: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8261: border-bottom:solid 1px #FFFFFF;
8262: cursor: default;
1.744 ehlerst 8263: }
1.795 www 8264:
1.959 onken 8265: ul.LC_TabContent li.active a {
8266: color:$font;
8267: background:#FFFFFF;
8268: outline: none;
8269: }
1.1047 raeburn 8270:
8271: ul.LC_TabContent li.goback {
8272: float: left;
8273: border-left: none;
8274: }
8275:
1.870 tempelho 8276: #maincoursedoc {
1.911 bisitz 8277: clear:both;
1.870 tempelho 8278: }
8279:
8280: ul.LC_TabContentBigger {
1.911 bisitz 8281: display:block;
8282: list-style:none;
8283: padding: 0;
1.870 tempelho 8284: }
8285:
1.795 www 8286: ul.LC_TabContentBigger li {
1.911 bisitz 8287: vertical-align:bottom;
8288: height: 30px;
8289: font-size:110%;
8290: font-weight:bold;
8291: color: #737373;
1.841 tempelho 8292: }
8293:
1.957 onken 8294: ul.LC_TabContentBigger li.active {
8295: position: relative;
8296: top: 1px;
8297: }
8298:
1.870 tempelho 8299: ul.LC_TabContentBigger li a {
1.911 bisitz 8300: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8301: height: 30px;
8302: line-height: 30px;
8303: text-align: center;
8304: display: block;
8305: text-decoration: none;
1.958 onken 8306: outline: none;
1.741 harmsja 8307: }
1.795 www 8308:
1.870 tempelho 8309: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8310: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8311: color:$font;
1.744 ehlerst 8312: }
1.795 www 8313:
1.870 tempelho 8314: ul.LC_TabContentBigger li b {
1.911 bisitz 8315: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8316: display: block;
8317: float: left;
8318: padding: 0 30px;
1.957 onken 8319: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8320: }
8321:
1.956 onken 8322: ul.LC_TabContentBigger li:hover b {
8323: color:$button_hover;
8324: }
8325:
1.870 tempelho 8326: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8327: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8328: color:$font;
1.957 onken 8329: border: 0;
1.741 harmsja 8330: }
1.693 droeschl 8331:
1.870 tempelho 8332:
1.862 bisitz 8333: ul.LC_CourseBreadcrumbs {
8334: background: $sidebg;
1.1020 raeburn 8335: height: 2em;
1.862 bisitz 8336: padding-left: 10px;
1.1020 raeburn 8337: margin: 0;
1.862 bisitz 8338: list-style-position: inside;
8339: }
8340:
1.911 bisitz 8341: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8342: ol#LC_PathBreadcrumbs {
1.911 bisitz 8343: padding-left: 10px;
8344: margin: 0;
1.933 droeschl 8345: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8346: }
8347:
1.911 bisitz 8348: ol#LC_MenuBreadcrumbs li,
8349: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8350: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8351: display: inline;
1.933 droeschl 8352: white-space: normal;
1.693 droeschl 8353: }
8354:
1.823 bisitz 8355: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8356: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8357: text-decoration: none;
8358: font-size:90%;
1.693 droeschl 8359: }
1.795 www 8360:
1.969 droeschl 8361: ol#LC_MenuBreadcrumbs h1 {
8362: display: inline;
8363: font-size: 90%;
8364: line-height: 2.5em;
8365: margin: 0;
8366: padding: 0;
8367: }
8368:
1.795 www 8369: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8370: text-decoration:none;
8371: font-size:100%;
8372: font-weight:bold;
1.693 droeschl 8373: }
1.795 www 8374:
1.840 bisitz 8375: .LC_Box {
1.911 bisitz 8376: border: solid 1px $lg_border_color;
8377: padding: 0 10px 10px 10px;
1.746 neumanie 8378: }
1.795 www 8379:
1.1020 raeburn 8380: .LC_DocsBox {
8381: border: solid 1px $lg_border_color;
8382: padding: 0 0 10px 10px;
8383: }
8384:
1.795 www 8385: .LC_AboutMe_Image {
1.911 bisitz 8386: float:left;
8387: margin-right:10px;
1.747 neumanie 8388: }
1.795 www 8389:
8390: .LC_Clear_AboutMe_Image {
1.911 bisitz 8391: clear:left;
1.747 neumanie 8392: }
1.795 www 8393:
1.721 harmsja 8394: dl.LC_ListStyleClean dt {
1.911 bisitz 8395: padding-right: 5px;
8396: display: table-header-group;
1.693 droeschl 8397: }
8398:
1.721 harmsja 8399: dl.LC_ListStyleClean dd {
1.911 bisitz 8400: display: table-row;
1.693 droeschl 8401: }
8402:
1.721 harmsja 8403: .LC_ListStyleClean,
8404: .LC_ListStyleSimple,
8405: .LC_ListStyleNormal,
1.795 www 8406: .LC_ListStyleSpecial {
1.911 bisitz 8407: /* display:block; */
8408: list-style-position: inside;
8409: list-style-type: none;
8410: overflow: hidden;
8411: padding: 0;
1.693 droeschl 8412: }
8413:
1.721 harmsja 8414: .LC_ListStyleSimple li,
8415: .LC_ListStyleSimple dd,
8416: .LC_ListStyleNormal li,
8417: .LC_ListStyleNormal dd,
8418: .LC_ListStyleSpecial li,
1.795 www 8419: .LC_ListStyleSpecial dd {
1.911 bisitz 8420: margin: 0;
8421: padding: 5px 5px 5px 10px;
8422: clear: both;
1.693 droeschl 8423: }
8424:
1.721 harmsja 8425: .LC_ListStyleClean li,
8426: .LC_ListStyleClean dd {
1.911 bisitz 8427: padding-top: 0;
8428: padding-bottom: 0;
1.693 droeschl 8429: }
8430:
1.721 harmsja 8431: .LC_ListStyleSimple dd,
1.795 www 8432: .LC_ListStyleSimple li {
1.911 bisitz 8433: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8434: }
8435:
1.721 harmsja 8436: .LC_ListStyleSpecial li,
8437: .LC_ListStyleSpecial dd {
1.911 bisitz 8438: list-style-type: none;
8439: background-color: RGB(220, 220, 220);
8440: margin-bottom: 4px;
1.693 droeschl 8441: }
8442:
1.721 harmsja 8443: table.LC_SimpleTable {
1.911 bisitz 8444: margin:5px;
8445: border:solid 1px $lg_border_color;
1.795 www 8446: }
1.693 droeschl 8447:
1.721 harmsja 8448: table.LC_SimpleTable tr {
1.911 bisitz 8449: padding: 0;
8450: border:solid 1px $lg_border_color;
1.693 droeschl 8451: }
1.795 www 8452:
8453: table.LC_SimpleTable thead {
1.911 bisitz 8454: background:rgb(220,220,220);
1.693 droeschl 8455: }
8456:
1.721 harmsja 8457: div.LC_columnSection {
1.911 bisitz 8458: display: block;
8459: clear: both;
8460: overflow: hidden;
8461: margin: 0;
1.693 droeschl 8462: }
8463:
1.721 harmsja 8464: div.LC_columnSection>* {
1.911 bisitz 8465: float: left;
8466: margin: 10px 20px 10px 0;
8467: overflow:hidden;
1.693 droeschl 8468: }
1.721 harmsja 8469:
1.795 www 8470: table em {
1.911 bisitz 8471: font-weight: bold;
8472: font-style: normal;
1.748 schulted 8473: }
1.795 www 8474:
1.779 bisitz 8475: table.LC_tableBrowseRes,
1.795 www 8476: table.LC_tableOfContent {
1.911 bisitz 8477: border:none;
8478: border-spacing: 1px;
8479: padding: 3px;
8480: background-color: #FFFFFF;
8481: font-size: 90%;
1.753 droeschl 8482: }
1.789 droeschl 8483:
1.911 bisitz 8484: table.LC_tableOfContent {
8485: border-collapse: collapse;
1.789 droeschl 8486: }
8487:
1.771 droeschl 8488: table.LC_tableBrowseRes a,
1.768 schulted 8489: table.LC_tableOfContent a {
1.911 bisitz 8490: background-color: transparent;
8491: text-decoration: none;
1.753 droeschl 8492: }
8493:
1.795 www 8494: table.LC_tableOfContent img {
1.911 bisitz 8495: border: none;
8496: height: 1.3em;
8497: vertical-align: text-bottom;
8498: margin-right: 0.3em;
1.753 droeschl 8499: }
1.757 schulted 8500:
1.795 www 8501: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8502: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8503: }
8504:
1.795 www 8505: a#LC_content_toolbar_everything {
1.911 bisitz 8506: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8507: }
8508:
1.795 www 8509: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8510: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8511: }
8512:
1.795 www 8513: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8514: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8515: }
8516:
1.795 www 8517: a#LC_content_toolbar_changefolder {
1.911 bisitz 8518: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8519: }
8520:
1.795 www 8521: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8522: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8523: }
8524:
1.1043 raeburn 8525: a#LC_content_toolbar_edittoplevel {
8526: background-image:url(/res/adm/pages/edittoplevel.gif);
8527: }
8528:
1.795 www 8529: ul#LC_toolbar li a:hover {
1.911 bisitz 8530: background-position: bottom center;
1.757 schulted 8531: }
8532:
1.795 www 8533: ul#LC_toolbar {
1.911 bisitz 8534: padding: 0;
8535: margin: 2px;
8536: list-style:none;
8537: position:relative;
8538: background-color:white;
1.1082 raeburn 8539: overflow: auto;
1.757 schulted 8540: }
8541:
1.795 www 8542: ul#LC_toolbar li {
1.911 bisitz 8543: border:1px solid white;
8544: padding: 0;
8545: margin: 0;
8546: float: left;
8547: display:inline;
8548: vertical-align:middle;
1.1082 raeburn 8549: white-space: nowrap;
1.911 bisitz 8550: }
1.757 schulted 8551:
1.783 amueller 8552:
1.795 www 8553: a.LC_toolbarItem {
1.911 bisitz 8554: display:block;
8555: padding: 0;
8556: margin: 0;
8557: height: 32px;
8558: width: 32px;
8559: color:white;
8560: border: none;
8561: background-repeat:no-repeat;
8562: background-color:transparent;
1.757 schulted 8563: }
8564:
1.915 droeschl 8565: ul.LC_funclist {
8566: margin: 0;
8567: padding: 0.5em 1em 0.5em 0;
8568: }
8569:
1.933 droeschl 8570: ul.LC_funclist > li:first-child {
8571: font-weight:bold;
8572: margin-left:0.8em;
8573: }
8574:
1.915 droeschl 8575: ul.LC_funclist + ul.LC_funclist {
8576: /*
8577: left border as a seperator if we have more than
8578: one list
8579: */
8580: border-left: 1px solid $sidebg;
8581: /*
8582: this hides the left border behind the border of the
8583: outer box if element is wrapped to the next 'line'
8584: */
8585: margin-left: -1px;
8586: }
8587:
1.843 bisitz 8588: ul.LC_funclist li {
1.915 droeschl 8589: display: inline;
1.782 bisitz 8590: white-space: nowrap;
1.915 droeschl 8591: margin: 0 0 0 25px;
8592: line-height: 150%;
1.782 bisitz 8593: }
8594:
1.974 wenzelju 8595: .LC_hidden {
8596: display: none;
8597: }
8598:
1.1030 www 8599: .LCmodal-overlay {
8600: position:fixed;
8601: top:0;
8602: right:0;
8603: bottom:0;
8604: left:0;
8605: height:100%;
8606: width:100%;
8607: margin:0;
8608: padding:0;
8609: background:#999;
8610: opacity:.75;
8611: filter: alpha(opacity=75);
8612: -moz-opacity: 0.75;
8613: z-index:101;
8614: }
8615:
8616: * html .LCmodal-overlay {
8617: position: absolute;
8618: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8619: }
8620:
8621: .LCmodal-window {
8622: position:fixed;
8623: top:50%;
8624: left:50%;
8625: margin:0;
8626: padding:0;
8627: z-index:102;
8628: }
8629:
8630: * html .LCmodal-window {
8631: position:absolute;
8632: }
8633:
8634: .LCclose-window {
8635: position:absolute;
8636: width:32px;
8637: height:32px;
8638: right:8px;
8639: top:8px;
8640: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8641: text-indent:-99999px;
8642: overflow:hidden;
8643: cursor:pointer;
8644: }
8645:
1.1369 raeburn 8646: .LCisDisabled {
8647: cursor: not-allowed;
8648: opacity: 0.5;
8649: }
8650:
8651: a[aria-disabled="true"] {
8652: color: currentColor;
8653: display: inline-block; /* For IE11/ MS Edge bug */
8654: pointer-events: none;
8655: text-decoration: none;
8656: }
8657:
1.1335 raeburn 8658: pre.LC_wordwrap {
8659: white-space: pre-wrap;
8660: white-space: -moz-pre-wrap;
8661: white-space: -pre-wrap;
8662: white-space: -o-pre-wrap;
8663: word-wrap: break-word;
8664: }
8665:
1.1100 raeburn 8666: /*
1.1231 damieng 8667: styles used for response display
8668: */
8669: div.LC_radiofoil, div.LC_rankfoil {
8670: margin: .5em 0em .5em 0em;
8671: }
8672: table.LC_itemgroup {
8673: margin-top: 1em;
8674: }
8675:
8676: /*
1.1100 raeburn 8677: styles used by TTH when "Default set of options to pass to tth/m
8678: when converting TeX" in course settings has been set
8679:
8680: option passed: -t
8681:
8682: */
8683:
8684: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8685: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8686: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8687: td div.norm {line-height:normal;}
8688:
8689: /*
8690: option passed -y3
8691: */
8692:
8693: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8694: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8695: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8696:
1.1230 damieng 8697: /*
8698: sections with roles, for content only
8699: */
8700: section[class^="role-"] {
8701: padding-left: 10px;
8702: padding-right: 5px;
8703: margin-top: 8px;
8704: margin-bottom: 8px;
8705: border: 1px solid #2A4;
8706: border-radius: 5px;
8707: box-shadow: 0px 1px 1px #BBB;
8708: }
8709: section[class^="role-"]>h1 {
8710: position: relative;
8711: margin: 0px;
8712: padding-top: 10px;
8713: padding-left: 40px;
8714: }
8715: section[class^="role-"]>h1:before {
8716: position: absolute;
8717: left: -5px;
8718: top: 5px;
8719: }
8720: section.role-activity>h1:before {
8721: content:url('/adm/daxe/images/section_icons/activity.png');
8722: }
8723: section.role-advice>h1:before {
8724: content:url('/adm/daxe/images/section_icons/advice.png');
8725: }
8726: section.role-bibliography>h1:before {
8727: content:url('/adm/daxe/images/section_icons/bibliography.png');
8728: }
8729: section.role-citation>h1:before {
8730: content:url('/adm/daxe/images/section_icons/citation.png');
8731: }
8732: section.role-conclusion>h1:before {
8733: content:url('/adm/daxe/images/section_icons/conclusion.png');
8734: }
8735: section.role-definition>h1:before {
8736: content:url('/adm/daxe/images/section_icons/definition.png');
8737: }
8738: section.role-demonstration>h1:before {
8739: content:url('/adm/daxe/images/section_icons/demonstration.png');
8740: }
8741: section.role-example>h1:before {
8742: content:url('/adm/daxe/images/section_icons/example.png');
8743: }
8744: section.role-explanation>h1:before {
8745: content:url('/adm/daxe/images/section_icons/explanation.png');
8746: }
8747: section.role-introduction>h1:before {
8748: content:url('/adm/daxe/images/section_icons/introduction.png');
8749: }
8750: section.role-method>h1:before {
8751: content:url('/adm/daxe/images/section_icons/method.png');
8752: }
8753: section.role-more_information>h1:before {
8754: content:url('/adm/daxe/images/section_icons/more_information.png');
8755: }
8756: section.role-objectives>h1:before {
8757: content:url('/adm/daxe/images/section_icons/objectives.png');
8758: }
8759: section.role-prerequisites>h1:before {
8760: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8761: }
8762: section.role-remark>h1:before {
8763: content:url('/adm/daxe/images/section_icons/remark.png');
8764: }
8765: section.role-reminder>h1:before {
8766: content:url('/adm/daxe/images/section_icons/reminder.png');
8767: }
8768: section.role-summary>h1:before {
8769: content:url('/adm/daxe/images/section_icons/summary.png');
8770: }
8771: section.role-syntax>h1:before {
8772: content:url('/adm/daxe/images/section_icons/syntax.png');
8773: }
8774: section.role-warning>h1:before {
8775: content:url('/adm/daxe/images/section_icons/warning.png');
8776: }
8777:
1.1269 raeburn 8778: #LC_minitab_header {
8779: float:left;
8780: width:100%;
8781: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8782: font-size:93%;
8783: line-height:normal;
8784: margin: 0.5em 0 0.5em 0;
8785: }
8786: #LC_minitab_header ul {
8787: margin:0;
8788: padding:10px 10px 0;
8789: list-style:none;
8790: }
8791: #LC_minitab_header li {
8792: float:left;
8793: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8794: margin:0;
8795: padding:0 0 0 9px;
8796: }
8797: #LC_minitab_header a {
8798: display:block;
8799: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8800: padding:5px 15px 4px 6px;
8801: }
8802: #LC_minitab_header #LC_current_minitab {
8803: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8804: }
8805: #LC_minitab_header #LC_current_minitab a {
8806: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8807: padding-bottom:5px;
8808: }
8809:
8810:
1.343 albertel 8811: END
8812: }
8813:
1.306 albertel 8814: =pod
8815:
8816: =item * &headtag()
8817:
8818: Returns a uniform footer for LON-CAPA web pages.
8819:
1.307 albertel 8820: Inputs: $title - optional title for the head
8821: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8822: $args - optional arguments
1.319 albertel 8823: force_register - if is true call registerurl so the remote is
8824: informed
1.415 albertel 8825: redirect -> array ref of
8826: 1- seconds before redirect occurs
8827: 2- url to redirect to
8828: 3- whether the side effect should occur
1.315 albertel 8829: (side effect of setting
8830: $env{'internal.head.redirect'} to the url
8831: redirected too)
1.352 albertel 8832: domain -> force to color decorate a page for a specific
8833: domain
8834: function -> force usage of a specific rolish color scheme
8835: bgcolor -> override the default page bgcolor
1.460 albertel 8836: no_auto_mt_title
8837: -> prevent &mt()ing the title arg
1.464 albertel 8838:
1.306 albertel 8839: =cut
8840:
8841: sub headtag {
1.313 albertel 8842: my ($title,$head_extra,$args) = @_;
1.306 albertel 8843:
1.363 albertel 8844: my $function = $args->{'function'} || &get_users_function();
8845: my $domain = $args->{'domain'} || &determinedomain();
8846: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8847: my $httphost = $args->{'use_absolute'};
1.418 albertel 8848: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8849: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8850: #time(),
1.418 albertel 8851: $env{'environment.color.timestamp'},
1.363 albertel 8852: $function,$domain,$bgcolor);
8853:
1.369 www 8854: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8855:
1.308 albertel 8856: my $result =
8857: '<head>'.
1.1160 raeburn 8858: &font_settings($args);
1.319 albertel 8859:
1.1188 raeburn 8860: my $inhibitprint;
8861: if ($args->{'print_suppress'}) {
8862: $inhibitprint = &print_suppression();
8863: }
1.1064 raeburn 8864:
1.461 albertel 8865: if (!$args->{'frameset'}) {
8866: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8867: }
1.962 droeschl 8868: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8869: $result .= Apache::lonxml::display_title();
1.319 albertel 8870: }
1.436 albertel 8871: if (!$args->{'no_nav_bar'}
8872: && !$args->{'only_body'}
8873: && !$args->{'frameset'}) {
1.1154 raeburn 8874: $result .= &help_menu_js($httphost);
1.1032 www 8875: $result.=&modal_window();
1.1038 www 8876: $result.=&togglebox_script();
1.1034 www 8877: $result.=&wishlist_window();
1.1041 www 8878: $result.=&LCprogressbarUpdate_script();
1.1034 www 8879: } else {
8880: if ($args->{'add_modal'}) {
8881: $result.=&modal_window();
8882: }
8883: if ($args->{'add_wishlist'}) {
8884: $result.=&wishlist_window();
8885: }
1.1038 www 8886: if ($args->{'add_togglebox'}) {
8887: $result.=&togglebox_script();
8888: }
1.1041 www 8889: if ($args->{'add_progressbar'}) {
8890: $result.=&LCprogressbarUpdate_script();
8891: }
1.436 albertel 8892: }
1.314 albertel 8893: if (ref($args->{'redirect'})) {
1.414 albertel 8894: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8895: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8896: if (!$inhibit_continue) {
8897: $env{'internal.head.redirect'} = $url;
8898: }
1.313 albertel 8899: $result.=<<ADDMETA
8900: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8901: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8902: ADDMETA
1.1210 raeburn 8903: } else {
8904: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8905: my $requrl = $env{'request.uri'};
8906: if ($requrl eq '') {
8907: $requrl = $ENV{'REQUEST_URI'};
8908: $requrl =~ s/\?.+$//;
8909: }
8910: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8911: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8912: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8913: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8914: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8915: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8916: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8917: my ($offload,$offloadoth);
1.1210 raeburn 8918: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8919: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8920: $offload = 1;
1.1353 raeburn 8921: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8922: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8923: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8924: $offloadoth = 1;
8925: $dom_in_use = $env{'user.domain'};
8926: }
8927: }
1.1340 raeburn 8928: }
8929: }
8930: unless ($offload) {
8931: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8932: if ($domdefs{'offloadoth'}{$lonhost}) {
8933: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8934: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8935: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8936: $offload = 1;
1.1352 raeburn 8937: $offloadoth = 1;
1.1340 raeburn 8938: $dom_in_use = $env{'user.domain'};
8939: }
1.1210 raeburn 8940: }
1.1340 raeburn 8941: }
8942: }
8943: }
8944: if ($offload) {
1.1358 raeburn 8945: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 8946: if (($newserver eq '') && ($offloadoth)) {
8947: my @domains = &Apache::lonnet::current_machine_domains();
8948: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8949: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8950: }
8951: }
1.1340 raeburn 8952: if (($newserver) && ($newserver ne $lonhost)) {
8953: my $numsec = 5;
8954: my $timeout = $numsec * 1000;
8955: my ($newurl,$locknum,%locks,$msg);
8956: if ($env{'request.role.adv'}) {
8957: ($locknum,%locks) = &Apache::lonnet::get_locks();
8958: }
8959: my $disable_submit = 0;
8960: if ($requrl =~ /$LONCAPA::assess_re/) {
8961: $disable_submit = 1;
8962: }
8963: if ($locknum) {
8964: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8965: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8966: join(", ",sort(values(%locks)))."\n";
8967: if (&show_course()) {
8968: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8969: } else {
8970: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8971: }
1.1340 raeburn 8972: } else {
8973: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8974: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8975: }
8976: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8977: $newurl = '/adm/switchserver?otherserver='.$newserver;
8978: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8979: $newurl .= '&role='.$env{'request.role'};
8980: }
8981: if ($env{'request.symb'}) {
8982: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8983: if ($shownsymb =~ m{^/enc/}) {
8984: my $reqdmajor = 2;
8985: my $reqdminor = 11;
8986: my $reqdsubminor = 3;
8987: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8988: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8989: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8990: if (($major eq '' && $minor eq '') ||
8991: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8992: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8993: ($reqdsubminor > $subminor))))) {
8994: undef($shownsymb);
8995: }
1.1210 raeburn 8996: }
1.1340 raeburn 8997: if ($shownsymb) {
8998: &js_escape(\$shownsymb);
8999: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9000: }
1.1340 raeburn 9001: } else {
9002: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9003: &js_escape(\$shownurl);
9004: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9005: }
1.1340 raeburn 9006: }
9007: &js_escape(\$msg);
9008: $result.=<<OFFLOAD
1.1210 raeburn 9009: <meta http-equiv="pragma" content="no-cache" />
9010: <script type="text/javascript">
1.1215 raeburn 9011: // <![CDATA[
1.1210 raeburn 9012: function LC_Offload_Now() {
9013: var dest = "$newurl";
9014: if (dest != '') {
9015: window.location.href="$newurl";
9016: }
9017: }
1.1214 raeburn 9018: \$(document).ready(function () {
9019: window.alert('$msg');
9020: if ($disable_submit) {
1.1210 raeburn 9021: \$(".LC_hwk_submit").prop("disabled", true);
9022: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9023: }
9024: setTimeout('LC_Offload_Now()', $timeout);
9025: });
1.1215 raeburn 9026: // ]]>
1.1210 raeburn 9027: </script>
9028: OFFLOAD
9029: }
9030: }
9031: }
9032: }
9033: }
1.313 albertel 9034: }
1.306 albertel 9035: if (!defined($title)) {
9036: $title = 'The LearningOnline Network with CAPA';
9037: }
1.460 albertel 9038: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9039: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9040: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9041: if (!$args->{'frameset'}) {
9042: $result .= ' /';
9043: }
9044: $result .= '>'
1.1064 raeburn 9045: .$inhibitprint
1.414 albertel 9046: .$head_extra;
1.1242 raeburn 9047: my $clientmobile;
9048: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9049: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9050: } else {
9051: $clientmobile = $env{'browser.mobile'};
9052: }
9053: if ($clientmobile) {
1.1137 raeburn 9054: $result .= '
9055: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9056: <meta name="apple-mobile-web-app-capable" content="yes" />';
9057: }
1.1278 raeburn 9058: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9059: return $result.'</head>';
1.306 albertel 9060: }
9061:
9062: =pod
9063:
1.340 albertel 9064: =item * &font_settings()
9065:
9066: Returns neccessary <meta> to set the proper encoding
9067:
1.1160 raeburn 9068: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9069:
9070: =cut
9071:
9072: sub font_settings {
1.1160 raeburn 9073: my ($args) = @_;
1.340 albertel 9074: my $headerstring='';
1.1160 raeburn 9075: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9076: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9077: $headerstring.=
9078: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9079: if (!$args->{'frameset'}) {
9080: $headerstring.= ' /';
9081: }
9082: $headerstring .= '>'."\n";
1.340 albertel 9083: }
9084: return $headerstring;
9085: }
9086:
1.341 albertel 9087: =pod
9088:
1.1064 raeburn 9089: =item * &print_suppression()
9090:
9091: In course context returns css which causes the body to be blank when media="print",
9092: if printout generation is unavailable for the current resource.
9093:
9094: This could be because:
9095:
9096: (a) printstartdate is in the future
9097:
9098: (b) printenddate is in the past
9099:
9100: (c) there is an active exam block with "printout"
9101: functionality blocked
9102:
9103: Users with pav, pfo or evb privileges are exempt.
9104:
9105: Inputs: none
9106:
9107: =cut
9108:
9109:
9110: sub print_suppression {
9111: my $noprint;
9112: if ($env{'request.course.id'}) {
9113: my $scope = $env{'request.course.id'};
9114: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9115: (&Apache::lonnet::allowed('pfo',$scope))) {
9116: return;
9117: }
9118: if ($env{'request.course.sec'} ne '') {
9119: $scope .= "/$env{'request.course.sec'}";
9120: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9121: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9122: return;
1.1064 raeburn 9123: }
9124: }
9125: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9126: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9127: my $clientip = &Apache::lonnet::get_requestor_ip();
9128: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9129: if ($blocked) {
9130: my $checkrole = "cm./$cdom/$cnum";
9131: if ($env{'request.course.sec'} ne '') {
9132: $checkrole .= "/$env{'request.course.sec'}";
9133: }
9134: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9135: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9136: $noprint = 1;
9137: }
9138: }
9139: unless ($noprint) {
9140: my $symb = &Apache::lonnet::symbread();
9141: if ($symb ne '') {
9142: my $navmap = Apache::lonnavmaps::navmap->new();
9143: if (ref($navmap)) {
9144: my $res = $navmap->getBySymb($symb);
9145: if (ref($res)) {
9146: if (!$res->resprintable()) {
9147: $noprint = 1;
9148: }
9149: }
9150: }
9151: }
9152: }
9153: if ($noprint) {
9154: return <<"ENDSTYLE";
9155: <style type="text/css" media="print">
9156: body { display:none }
9157: </style>
9158: ENDSTYLE
9159: }
9160: }
9161: return;
9162: }
9163:
9164: =pod
9165:
1.341 albertel 9166: =item * &xml_begin()
9167:
9168: Returns the needed doctype and <html>
9169:
9170: Inputs: none
9171:
9172: =cut
9173:
9174: sub xml_begin {
1.1168 raeburn 9175: my ($is_frameset) = @_;
1.341 albertel 9176: my $output='';
9177:
9178: if ($env{'browser.mathml'}) {
9179: $output='<?xml version="1.0"?>'
9180: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9181: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9182:
9183: # .'<!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">] >'
9184: .'<!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">'
9185: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9186: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9187: } elsif ($is_frameset) {
9188: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9189: '<html>'."\n";
1.341 albertel 9190: } else {
1.1168 raeburn 9191: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9192: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9193: }
9194: return $output;
9195: }
1.340 albertel 9196:
9197: =pod
9198:
1.306 albertel 9199: =item * &start_page()
9200:
9201: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9202:
1.648 raeburn 9203: Inputs:
9204:
9205: =over 4
9206:
9207: $title - optional title for the page
9208:
9209: $head_extra - optional extra HTML to incude inside the <head>
9210:
9211: $args - additional optional args supported are:
9212:
9213: =over 8
9214:
9215: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9216: arg on
1.814 bisitz 9217: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9218: add_entries -> additional attributes to add to the <body>
9219: domain -> force to color decorate a page for a
1.317 albertel 9220: specific domain
1.648 raeburn 9221: function -> force usage of a specific rolish color
1.317 albertel 9222: scheme
1.648 raeburn 9223: redirect -> see &headtag()
9224: bgcolor -> override the default page bg color
9225: js_ready -> return a string ready for being used in
1.317 albertel 9226: a javascript writeln
1.648 raeburn 9227: html_encode -> return a string ready for being used in
1.320 albertel 9228: a html attribute
1.648 raeburn 9229: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9230: $forcereg arg
1.648 raeburn 9231: frameset -> if true will start with a <frameset>
1.330 albertel 9232: rather than <body>
1.648 raeburn 9233: skip_phases -> hash ref of
1.338 albertel 9234: head -> skip the <html><head> generation
9235: body -> skip all <body> generation
1.648 raeburn 9236: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9237: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9238: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9239: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9240: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9241: group -> includes the current group, if page is for a
1.1274 raeburn 9242: specific group
9243: use_absolute -> for request for external resource or syllabus, this
9244: will contain https://<hostname> if server uses
9245: https (as per hosts.tab), but request is for http
9246: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9247: links_disabled -> Links in primary and secondary menus are disabled
9248: (Can enable them once page has loaded - see lonroles.pm
9249: for an example).
1.1380 ! raeburn 9250: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9251:
1.648 raeburn 9252: =back
1.460 albertel 9253:
1.648 raeburn 9254: =back
1.562 albertel 9255:
1.306 albertel 9256: =cut
9257:
9258: sub start_page {
1.309 albertel 9259: my ($title,$head_extra,$args) = @_;
1.318 albertel 9260: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9261:
1.315 albertel 9262: $env{'internal.start_page'}++;
1.1359 raeburn 9263: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9264:
1.338 albertel 9265: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9266: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9267: }
1.1316 raeburn 9268:
9269: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9270: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9271: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9272: $args->{'no_primary_menu'} = 1;
9273: }
9274: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9275: $args->{'no_inline_menu'} = 1;
9276: }
9277: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9278: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9279: }
9280: } else {
9281: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9282: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9283: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9284: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9285: $args->{'no_primary_menu'} = 1;
9286: }
9287: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9288: $args->{'no_inline_menu'} = 1;
9289: }
9290: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9291: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9292: }
9293: }
9294: }
1.1316 raeburn 9295: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9296: $env{'course.'.$env{'request.course.id'}.'.domain'},
9297: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9298: } elsif ($env{'request.course.id'}) {
9299: my $expiretime=600;
9300: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9301: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9302: }
9303: my ($deeplinkmenu,$menuref);
9304: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9305: if ($menucoll) {
9306: if (ref($menuref) eq 'HASH') {
9307: %menu = %{$menuref};
9308: }
9309: if ($menu{'top'} eq 'n') {
9310: $args->{'no_primary_menu'} = 1;
9311: }
9312: if ($menu{'inline'} eq 'n') {
9313: unless (&Apache::lonnet::allowed('opa')) {
9314: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9315: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9316: my $crstype = &course_type();
9317: my $now = time;
9318: my $ccrole;
9319: if ($crstype eq 'Community') {
9320: $ccrole = 'co';
9321: } else {
9322: $ccrole = 'cc';
9323: }
9324: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9325: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9326: if ((($start) && ($start<0)) ||
9327: (($end) && ($end<$now)) ||
9328: (($start) && ($now<$start))) {
9329: $args->{'no_inline_menu'} = 1;
9330: }
9331: } else {
9332: $args->{'no_inline_menu'} = 1;
9333: }
9334: }
9335: }
9336: }
1.1316 raeburn 9337: }
1.1359 raeburn 9338:
1.338 albertel 9339: if (! exists($args->{'skip_phases'}{'body'}) ) {
9340: if ($args->{'frameset'}) {
9341: my $attr_string = &make_attr_string($args->{'force_register'},
9342: $args->{'add_entries'});
9343: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9344: } else {
9345: $result .=
9346: &bodytag($title,
9347: $args->{'function'}, $args->{'add_entries'},
9348: $args->{'only_body'}, $args->{'domain'},
9349: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9350: $args->{'bgcolor'}, $args,
1.1359 raeburn 9351: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu);
1.831 bisitz 9352: }
1.330 albertel 9353: }
1.338 albertel 9354:
1.315 albertel 9355: if ($args->{'js_ready'}) {
1.713 kaisler 9356: $result = &js_ready($result);
1.315 albertel 9357: }
1.320 albertel 9358: if ($args->{'html_encode'}) {
1.713 kaisler 9359: $result = &html_encode($result);
9360: }
9361:
1.813 bisitz 9362: # Preparation for new and consistent functionlist at top of screen
9363: # if ($args->{'functionlist'}) {
9364: # $result .= &build_functionlist();
9365: #}
9366:
1.964 droeschl 9367: # Don't add anything more if only_body wanted or in const space
9368: return $result if $args->{'only_body'}
9369: || $env{'request.state'} eq 'construct';
1.813 bisitz 9370:
9371: #Breadcrumbs
1.758 kaisler 9372: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9373: &Apache::lonhtmlcommon::clear_breadcrumbs();
9374: #if any br links exists, add them to the breadcrumbs
9375: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9376: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9377: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9378: }
9379: }
1.1096 raeburn 9380: # if @advtools array contains items add then to the breadcrumbs
9381: if (@advtools > 0) {
9382: &Apache::lonmenu::advtools_crumbs(@advtools);
9383: }
1.1272 raeburn 9384: my $menulink;
9385: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9386: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9387: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9388: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9389: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9390: (!$env{'request.role.adv'}))) {
9391: $menulink = 0;
9392: } else {
9393: undef($menulink);
9394: }
1.758 kaisler 9395: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9396: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9397: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9398: } else {
1.1272 raeburn 9399: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9400: }
1.320 albertel 9401: }
1.315 albertel 9402: return $result;
1.306 albertel 9403: }
9404:
9405: sub end_page {
1.315 albertel 9406: my ($args) = @_;
9407: $env{'internal.end_page'}++;
1.330 albertel 9408: my $result;
1.335 albertel 9409: if ($args->{'discussion'}) {
9410: my ($target,$parser);
9411: if (ref($args->{'discussion'})) {
9412: ($target,$parser) =($args->{'discussion'}{'target'},
9413: $args->{'discussion'}{'parser'});
9414: }
9415: $result .= &Apache::lonxml::xmlend($target,$parser);
9416: }
1.330 albertel 9417: if ($args->{'frameset'}) {
9418: $result .= '</frameset>';
9419: } else {
1.635 raeburn 9420: $result .= &endbodytag($args);
1.330 albertel 9421: }
1.1080 raeburn 9422: unless ($args->{'notbody'}) {
9423: $result .= "\n</html>";
9424: }
1.330 albertel 9425:
1.315 albertel 9426: if ($args->{'js_ready'}) {
1.317 albertel 9427: $result = &js_ready($result);
1.315 albertel 9428: }
1.335 albertel 9429:
1.320 albertel 9430: if ($args->{'html_encode'}) {
9431: $result = &html_encode($result);
9432: }
1.335 albertel 9433:
1.315 albertel 9434: return $result;
9435: }
9436:
1.1359 raeburn 9437: sub menucoll_in_effect {
9438: my ($menucoll,$deeplinkmenu,%menu);
9439: if ($env{'request.course.id'}) {
9440: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9441: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9442: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9443: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9444: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9445: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9446: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9447: my $navmap = Apache::lonnavmaps::navmap->new();
9448: if (ref($navmap)) {
9449: $deeplink = $navmap->get_mapparam(undef,
9450: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9451: '0.deeplink');
1.1370 raeburn 9452: } else {
9453: $check_login_symb = 1;
1.1362 raeburn 9454: }
9455: } else {
1.1370 raeburn 9456: my $symb = &Apache::lonnet::symbread();
9457: if ($symb) {
9458: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9459: } else {
9460: $check_login_symb = 1;
9461: }
1.1362 raeburn 9462: }
9463: } else {
1.1370 raeburn 9464: $check_login_symb = 1;
9465: }
9466: if ($check_login_symb) {
1.1362 raeburn 9467: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9468: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9469: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9470: my $navmap = Apache::lonnavmaps::navmap->new();
9471: if (ref($navmap)) {
9472: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9473: }
9474: } else {
9475: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9476: }
9477: }
1.1359 raeburn 9478: if ($deeplink ne '') {
1.1378 raeburn 9479: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 9480: if ($display =~ /^\d+$/) {
9481: $deeplinkmenu = 1;
9482: $menucoll = $display;
9483: }
9484: }
9485: }
9486: if ($menucoll) {
9487: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9488: }
9489: }
9490: return ($menucoll,$deeplinkmenu,\%menu);
9491: }
9492:
1.1362 raeburn 9493: sub deeplink_login_symb {
9494: my ($cnum,$cdom) = @_;
9495: my $login_symb;
9496: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9497: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9498: }
9499: return $login_symb;
9500: }
9501:
9502: sub symb_from_tinyurl {
9503: my ($url,$cnum,$cdom) = @_;
9504: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9505: my $key = $1;
9506: my ($tinyurl,$login);
9507: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9508: if (defined($cached)) {
9509: $tinyurl = $result;
9510: } else {
9511: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9512: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9513: if ($currtiny{$key} ne '') {
9514: $tinyurl = $currtiny{$key};
9515: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9516: }
1.1364 raeburn 9517: }
9518: if ($tinyurl ne '') {
9519: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9520: if (wantarray) {
9521: return ($cnumreq,$symb);
9522: } elsif ($cnumreq eq $cnum) {
9523: return $symb;
1.1362 raeburn 9524: }
9525: }
9526: }
1.1364 raeburn 9527: if (wantarray) {
9528: return ();
9529: } else {
9530: return;
9531: }
1.1362 raeburn 9532: }
9533:
1.1034 www 9534: sub wishlist_window {
9535: return(<<'ENDWISHLIST');
1.1046 raeburn 9536: <script type="text/javascript">
1.1034 www 9537: // <![CDATA[
9538: // <!-- BEGIN LON-CAPA Internal
9539: function set_wishlistlink(title, path) {
9540: if (!title) {
9541: title = document.title;
9542: title = title.replace(/^LON-CAPA /,'');
9543: }
1.1175 raeburn 9544: title = encodeURIComponent(title);
1.1203 raeburn 9545: title = title.replace("'","\\\'");
1.1034 www 9546: if (!path) {
9547: path = location.pathname;
9548: }
1.1175 raeburn 9549: path = encodeURIComponent(path);
1.1203 raeburn 9550: path = path.replace("'","\\\'");
1.1034 www 9551: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9552: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9553: }
9554: // END LON-CAPA Internal -->
9555: // ]]>
9556: </script>
9557: ENDWISHLIST
9558: }
9559:
1.1030 www 9560: sub modal_window {
9561: return(<<'ENDMODAL');
1.1046 raeburn 9562: <script type="text/javascript">
1.1030 www 9563: // <![CDATA[
9564: // <!-- BEGIN LON-CAPA Internal
9565: var modalWindow = {
9566: parent:"body",
9567: windowId:null,
9568: content:null,
9569: width:null,
9570: height:null,
9571: close:function()
9572: {
9573: $(".LCmodal-window").remove();
9574: $(".LCmodal-overlay").remove();
9575: },
9576: open:function()
9577: {
9578: var modal = "";
9579: modal += "<div class=\"LCmodal-overlay\"></div>";
9580: 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;\">";
9581: modal += this.content;
9582: modal += "</div>";
9583:
9584: $(this.parent).append(modal);
9585:
9586: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9587: $(".LCclose-window").click(function(){modalWindow.close();});
9588: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9589: }
9590: };
1.1140 raeburn 9591: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9592: {
1.1266 raeburn 9593: source = source.replace(/'/g,"'");
1.1030 www 9594: modalWindow.windowId = "myModal";
9595: modalWindow.width = width;
9596: modalWindow.height = height;
1.1196 raeburn 9597: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9598: modalWindow.open();
1.1208 raeburn 9599: };
1.1030 www 9600: // END LON-CAPA Internal -->
9601: // ]]>
9602: </script>
9603: ENDMODAL
9604: }
9605:
9606: sub modal_link {
1.1140 raeburn 9607: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9608: unless ($width) { $width=480; }
9609: unless ($height) { $height=400; }
1.1031 www 9610: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9611: unless ($transparency) { $transparency='true'; }
9612:
1.1074 raeburn 9613: my $target_attr;
9614: if (defined($target)) {
9615: $target_attr = 'target="'.$target.'"';
9616: }
9617: return <<"ENDLINK";
1.1336 raeburn 9618: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9619: ENDLINK
1.1030 www 9620: }
9621:
1.1032 www 9622: sub modal_adhoc_script {
1.1365 raeburn 9623: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9624: my $mathjax;
9625: if ($possmathjax) {
9626: $mathjax = <<'ENDJAX';
9627: if (typeof MathJax == 'object') {
9628: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9629: }
9630: ENDJAX
9631: }
1.1032 www 9632: return (<<ENDADHOC);
1.1046 raeburn 9633: <script type="text/javascript">
1.1032 www 9634: // <![CDATA[
9635: var $funcname = function()
9636: {
9637: modalWindow.windowId = "myModal";
9638: modalWindow.width = $width;
9639: modalWindow.height = $height;
9640: modalWindow.content = '$content';
9641: modalWindow.open();
1.1365 raeburn 9642: $mathjax
1.1032 www 9643: };
9644: // ]]>
9645: </script>
9646: ENDADHOC
9647: }
9648:
1.1041 www 9649: sub modal_adhoc_inner {
1.1365 raeburn 9650: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9651: my $innerwidth=$width-20;
9652: $content=&js_ready(
1.1140 raeburn 9653: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9654: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9655: $content.
1.1041 www 9656: &end_scrollbox().
1.1140 raeburn 9657: &end_page()
1.1041 www 9658: );
1.1365 raeburn 9659: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9660: }
9661:
9662: sub modal_adhoc_window {
1.1365 raeburn 9663: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9664: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9665: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9666: }
9667:
9668: sub modal_adhoc_launch {
9669: my ($funcname,$width,$height,$content)=@_;
9670: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9671: <script type="text/javascript">
9672: // <![CDATA[
9673: $funcname();
9674: // ]]>
9675: </script>
9676: ENDLAUNCH
9677: }
9678:
9679: sub modal_adhoc_close {
9680: return (<<ENDCLOSE);
9681: <script type="text/javascript">
9682: // <![CDATA[
9683: modalWindow.close();
9684: // ]]>
9685: </script>
9686: ENDCLOSE
9687: }
9688:
1.1038 www 9689: sub togglebox_script {
9690: return(<<ENDTOGGLE);
9691: <script type="text/javascript">
9692: // <![CDATA[
9693: function LCtoggleDisplay(id,hidetext,showtext) {
9694: link = document.getElementById(id + "link").childNodes[0];
9695: with (document.getElementById(id).style) {
9696: if (display == "none" ) {
9697: display = "inline";
9698: link.nodeValue = hidetext;
9699: } else {
9700: display = "none";
9701: link.nodeValue = showtext;
9702: }
9703: }
9704: }
9705: // ]]>
9706: </script>
9707: ENDTOGGLE
9708: }
9709:
1.1039 www 9710: sub start_togglebox {
9711: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9712: unless ($heading) { $heading=''; } else { $heading.=' '; }
9713: unless ($showtext) { $showtext=&mt('show'); }
9714: unless ($hidetext) { $hidetext=&mt('hide'); }
9715: unless ($headerbg) { $headerbg='#FFFFFF'; }
9716: return &start_data_table().
9717: &start_data_table_header_row().
9718: '<td bgcolor="'.$headerbg.'">'.$heading.
9719: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9720: $showtext.'\')">'.$showtext.'</a>]</td>'.
9721: &end_data_table_header_row().
9722: '<tr id="'.$id.'" style="display:none""><td>';
9723: }
9724:
9725: sub end_togglebox {
9726: return '</td></tr>'.&end_data_table();
9727: }
9728:
1.1041 www 9729: sub LCprogressbar_script {
1.1302 raeburn 9730: my ($id,$number_to_do)=@_;
9731: if ($number_to_do) {
9732: return(<<ENDPROGRESS);
1.1041 www 9733: <script type="text/javascript">
9734: // <![CDATA[
1.1045 www 9735: \$('#progressbar$id').progressbar({
1.1041 www 9736: value: 0,
9737: change: function(event, ui) {
9738: var newVal = \$(this).progressbar('option', 'value');
9739: \$('.pblabel', this).text(LCprogressTxt);
9740: }
9741: });
9742: // ]]>
9743: </script>
9744: ENDPROGRESS
1.1302 raeburn 9745: } else {
9746: return(<<ENDPROGRESS);
9747: <script type="text/javascript">
9748: // <![CDATA[
9749: \$('#progressbar$id').progressbar({
9750: value: false,
9751: create: function(event, ui) {
9752: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9753: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9754: }
9755: });
9756: // ]]>
9757: </script>
9758: ENDPROGRESS
9759: }
1.1041 www 9760: }
9761:
9762: sub LCprogressbarUpdate_script {
9763: return(<<ENDPROGRESSUPDATE);
9764: <style type="text/css">
9765: .ui-progressbar { position:relative; }
1.1302 raeburn 9766: .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 9767: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9768: </style>
9769: <script type="text/javascript">
9770: // <![CDATA[
1.1045 www 9771: var LCprogressTxt='---';
9772:
1.1302 raeburn 9773: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9774: LCprogressTxt=progresstext;
1.1302 raeburn 9775: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9776: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9777: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9778: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9779: } else {
9780: \$('#progressbar'+id).progressbar('value',percent);
9781: }
1.1041 www 9782: }
9783: // ]]>
9784: </script>
9785: ENDPROGRESSUPDATE
9786: }
9787:
1.1042 www 9788: my $LClastpercent;
1.1045 www 9789: my $LCidcnt;
9790: my $LCcurrentid;
1.1042 www 9791:
1.1041 www 9792: sub LCprogressbar {
1.1302 raeburn 9793: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9794: $LClastpercent=0;
1.1045 www 9795: $LCidcnt++;
9796: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9797: my ($starting,$content);
9798: if ($number_to_do) {
9799: $starting=&mt('Starting');
9800: $content=(<<ENDPROGBAR);
9801: $preamble
1.1045 www 9802: <div id="progressbar$LCcurrentid">
1.1041 www 9803: <span class="pblabel">$starting</span>
9804: </div>
9805: ENDPROGBAR
1.1302 raeburn 9806: } else {
9807: $starting=&mt('Loading...');
9808: $LClastpercent='false';
9809: $content=(<<ENDPROGBAR);
9810: $preamble
9811: <div id="progressbar$LCcurrentid">
9812: <div class="progress-label">$starting</div>
9813: </div>
9814: ENDPROGBAR
9815: }
9816: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9817: }
9818:
9819: sub LCprogressbarUpdate {
1.1302 raeburn 9820: my ($r,$val,$text,$number_to_do)=@_;
9821: if ($number_to_do) {
9822: unless ($val) {
9823: if ($LClastpercent) {
9824: $val=$LClastpercent;
9825: } else {
9826: $val=0;
9827: }
9828: }
9829: if ($val<0) { $val=0; }
9830: if ($val>100) { $val=0; }
9831: $LClastpercent=$val;
9832: unless ($text) { $text=$val.'%'; }
9833: } else {
9834: $val = 'false';
1.1042 www 9835: }
1.1041 www 9836: $text=&js_ready($text);
1.1044 www 9837: &r_print($r,<<ENDUPDATE);
1.1041 www 9838: <script type="text/javascript">
9839: // <![CDATA[
1.1302 raeburn 9840: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9841: // ]]>
9842: </script>
9843: ENDUPDATE
1.1035 www 9844: }
9845:
1.1042 www 9846: sub LCprogressbarClose {
9847: my ($r)=@_;
9848: $LClastpercent=0;
1.1044 www 9849: &r_print($r,<<ENDCLOSE);
1.1042 www 9850: <script type="text/javascript">
9851: // <![CDATA[
1.1045 www 9852: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9853: // ]]>
9854: </script>
9855: ENDCLOSE
1.1044 www 9856: }
9857:
9858: sub r_print {
9859: my ($r,$to_print)=@_;
9860: if ($r) {
9861: $r->print($to_print);
9862: $r->rflush();
9863: } else {
9864: print($to_print);
9865: }
1.1042 www 9866: }
9867:
1.320 albertel 9868: sub html_encode {
9869: my ($result) = @_;
9870:
1.322 albertel 9871: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9872:
9873: return $result;
9874: }
1.1044 www 9875:
1.317 albertel 9876: sub js_ready {
9877: my ($result) = @_;
9878:
1.323 albertel 9879: $result =~ s/[\n\r]/ /xmsg;
9880: $result =~ s/\\/\\\\/xmsg;
9881: $result =~ s/'/\\'/xmsg;
1.372 albertel 9882: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9883:
9884: return $result;
9885: }
9886:
1.315 albertel 9887: sub validate_page {
9888: if ( exists($env{'internal.start_page'})
1.316 albertel 9889: && $env{'internal.start_page'} > 1) {
9890: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9891: $env{'internal.start_page'}.' '.
1.316 albertel 9892: $ENV{'request.filename'});
1.315 albertel 9893: }
9894: if ( exists($env{'internal.end_page'})
1.316 albertel 9895: && $env{'internal.end_page'} > 1) {
9896: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9897: $env{'internal.end_page'}.' '.
1.316 albertel 9898: $env{'request.filename'});
1.315 albertel 9899: }
9900: if ( exists($env{'internal.start_page'})
9901: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9902: &Apache::lonnet::logthis('start_page called without end_page '.
9903: $env{'request.filename'});
1.315 albertel 9904: }
9905: if ( ! exists($env{'internal.start_page'})
9906: && exists($env{'internal.end_page'})) {
1.316 albertel 9907: &Apache::lonnet::logthis('end_page called without start_page'.
9908: $env{'request.filename'});
1.315 albertel 9909: }
1.306 albertel 9910: }
1.315 albertel 9911:
1.996 www 9912:
9913: sub start_scrollbox {
1.1140 raeburn 9914: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9915: unless ($outerwidth) { $outerwidth='520px'; }
9916: unless ($width) { $width='500px'; }
9917: unless ($height) { $height='200px'; }
1.1075 raeburn 9918: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9919: if ($id ne '') {
1.1140 raeburn 9920: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9921: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9922: }
1.1075 raeburn 9923: if ($bgcolor ne '') {
9924: $tdcol = "background-color: $bgcolor;";
9925: }
1.1137 raeburn 9926: my $nicescroll_js;
9927: if ($env{'browser.mobile'}) {
1.1140 raeburn 9928: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9929: }
9930: return <<"END";
9931: $nicescroll_js
9932:
9933: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9934: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9935: END
9936: }
9937:
9938: sub end_scrollbox {
9939: return '</div></td></tr></table>';
9940: }
9941:
9942: sub nicescroll_javascript {
9943: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9944: my %options;
9945: if (ref($cursor) eq 'HASH') {
9946: %options = %{$cursor};
9947: }
9948: unless ($options{'railalign'} =~ /^left|right$/) {
9949: $options{'railalign'} = 'left';
9950: }
9951: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9952: my $function = &get_users_function();
9953: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9954: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9955: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9956: }
1.1140 raeburn 9957: }
9958: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9959: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9960: $options{'cursoropacity'}='1.0';
9961: }
1.1140 raeburn 9962: } else {
9963: $options{'cursoropacity'}='1.0';
9964: }
9965: if ($options{'cursorfixedheight'} eq 'none') {
9966: delete($options{'cursorfixedheight'});
9967: } else {
9968: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9969: }
9970: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9971: delete($options{'railoffset'});
9972: }
9973: my @niceoptions;
9974: while (my($key,$value) = each(%options)) {
9975: if ($value =~ /^\{.+\}$/) {
9976: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9977: } else {
1.1140 raeburn 9978: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9979: }
1.1140 raeburn 9980: }
9981: my $nicescroll_js = '
1.1137 raeburn 9982: $(document).ready(
1.1140 raeburn 9983: function() {
9984: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9985: }
1.1137 raeburn 9986: );
9987: ';
1.1140 raeburn 9988: if ($framecheck) {
9989: $nicescroll_js .= '
9990: function expand_div(caller) {
9991: if (top === self) {
9992: document.getElementById("'.$id.'").style.width = "auto";
9993: document.getElementById("'.$id.'").style.height = "auto";
9994: } else {
9995: try {
9996: if (parent.frames) {
9997: if (parent.frames.length > 1) {
9998: var framesrc = parent.frames[1].location.href;
9999: var currsrc = framesrc.replace(/\#.*$/,"");
10000: if ((caller == "search") || (currsrc == "'.$location.'")) {
10001: document.getElementById("'.$id.'").style.width = "auto";
10002: document.getElementById("'.$id.'").style.height = "auto";
10003: }
10004: }
10005: }
10006: } catch (e) {
10007: return;
10008: }
1.1137 raeburn 10009: }
1.1140 raeburn 10010: return;
1.996 www 10011: }
1.1140 raeburn 10012: ';
10013: }
10014: if ($needjsready) {
10015: $nicescroll_js = '
10016: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10017: } else {
10018: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10019: }
10020: return $nicescroll_js;
1.996 www 10021: }
10022:
1.318 albertel 10023: sub simple_error_page {
1.1150 bisitz 10024: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10025: my %displayargs;
1.1151 raeburn 10026: if (ref($args) eq 'HASH') {
10027: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10028: if ($args->{'only_body'}) {
10029: $displayargs{'only_body'} = 1;
10030: }
10031: if ($args->{'no_nav_bar'}) {
10032: $displayargs{'no_nav_bar'} = 1;
10033: }
1.1151 raeburn 10034: } else {
10035: $msg = &mt($msg);
10036: }
1.1150 bisitz 10037:
1.318 albertel 10038: my $page =
1.1304 raeburn 10039: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10040: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10041: &Apache::loncommon::end_page();
10042: if (ref($r)) {
10043: $r->print($page);
1.327 albertel 10044: return;
1.318 albertel 10045: }
10046: return $page;
10047: }
1.347 albertel 10048:
10049: {
1.610 albertel 10050: my @row_count;
1.961 onken 10051:
10052: sub start_data_table_count {
10053: unshift(@row_count, 0);
10054: return;
10055: }
10056:
10057: sub end_data_table_count {
10058: shift(@row_count);
10059: return;
10060: }
10061:
1.347 albertel 10062: sub start_data_table {
1.1018 raeburn 10063: my ($add_class,$id) = @_;
1.422 albertel 10064: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10065: my $table_id;
10066: if (defined($id)) {
10067: $table_id = ' id="'.$id.'"';
10068: }
1.961 onken 10069: &start_data_table_count();
1.1018 raeburn 10070: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10071: }
10072:
10073: sub end_data_table {
1.961 onken 10074: &end_data_table_count();
1.389 albertel 10075: return '</table>'."\n";;
1.347 albertel 10076: }
10077:
10078: sub start_data_table_row {
1.974 wenzelju 10079: my ($add_class, $id) = @_;
1.610 albertel 10080: $row_count[0]++;
10081: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10082: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10083: $id = (' id="'.$id.'"') unless ($id eq '');
10084: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10085: }
1.471 banghart 10086:
10087: sub continue_data_table_row {
1.974 wenzelju 10088: my ($add_class, $id) = @_;
1.610 albertel 10089: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10090: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10091: $id = (' id="'.$id.'"') unless ($id eq '');
10092: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10093: }
1.347 albertel 10094:
10095: sub end_data_table_row {
1.389 albertel 10096: return '</tr>'."\n";;
1.347 albertel 10097: }
1.367 www 10098:
1.421 albertel 10099: sub start_data_table_empty_row {
1.707 bisitz 10100: # $row_count[0]++;
1.421 albertel 10101: return '<tr class="LC_empty_row" >'."\n";;
10102: }
10103:
10104: sub end_data_table_empty_row {
10105: return '</tr>'."\n";;
10106: }
10107:
1.367 www 10108: sub start_data_table_header_row {
1.389 albertel 10109: return '<tr class="LC_header_row">'."\n";;
1.367 www 10110: }
10111:
10112: sub end_data_table_header_row {
1.389 albertel 10113: return '</tr>'."\n";;
1.367 www 10114: }
1.890 droeschl 10115:
10116: sub data_table_caption {
10117: my $caption = shift;
10118: return "<caption class=\"LC_caption\">$caption</caption>";
10119: }
1.347 albertel 10120: }
10121:
1.548 albertel 10122: =pod
10123:
10124: =item * &inhibit_menu_check($arg)
10125:
10126: Checks for a inhibitmenu state and generates output to preserve it
10127:
10128: Inputs: $arg - can be any of
10129: - undef - in which case the return value is a string
10130: to add into arguments list of a uri
10131: - 'input' - in which case the return value is a HTML
10132: <form> <input> field of type hidden to
10133: preserve the value
10134: - a url - in which case the return value is the url with
10135: the neccesary cgi args added to preserve the
10136: inhibitmenu state
10137: - a ref to a url - no return value, but the string is
10138: updated to include the neccessary cgi
10139: args to preserve the inhibitmenu state
10140:
10141: =cut
10142:
10143: sub inhibit_menu_check {
10144: my ($arg) = @_;
10145: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10146: if ($arg eq 'input') {
10147: if ($env{'form.inhibitmenu'}) {
10148: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10149: } else {
10150: return
10151: }
10152: }
10153: if ($env{'form.inhibitmenu'}) {
10154: if (ref($arg)) {
10155: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10156: } elsif ($arg eq '') {
10157: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10158: } else {
10159: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10160: }
10161: }
10162: if (!ref($arg)) {
10163: return $arg;
10164: }
10165: }
10166:
1.251 albertel 10167: ###############################################
1.182 matthew 10168:
10169: =pod
10170:
1.549 albertel 10171: =back
10172:
10173: =head1 User Information Routines
10174:
10175: =over 4
10176:
1.405 albertel 10177: =item * &get_users_function()
1.182 matthew 10178:
10179: Used by &bodytag to determine the current users primary role.
10180: Returns either 'student','coordinator','admin', or 'author'.
10181:
10182: =cut
10183:
10184: ###############################################
10185: sub get_users_function {
1.815 tempelho 10186: my $function = 'norole';
1.818 tempelho 10187: if ($env{'request.role'}=~/^(st)/) {
10188: $function='student';
10189: }
1.907 raeburn 10190: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10191: $function='coordinator';
10192: }
1.258 albertel 10193: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10194: $function='admin';
10195: }
1.826 bisitz 10196: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10197: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10198: $function='author';
10199: }
10200: return $function;
1.54 www 10201: }
1.99 www 10202:
10203: ###############################################
10204:
1.233 raeburn 10205: =pod
10206:
1.821 raeburn 10207: =item * &show_course()
10208:
10209: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10210: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10211:
10212: Inputs:
10213: None
10214:
10215: Outputs:
10216: Scalar: 1 if 'Course' to be used, 0 otherwise.
10217:
10218: =cut
10219:
10220: ###############################################
10221: sub show_course {
10222: my $course = !$env{'user.adv'};
10223: if (!$env{'user.adv'}) {
10224: foreach my $env (keys(%env)) {
10225: next if ($env !~ m/^user\.priv\./);
10226: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10227: $course = 0;
10228: last;
10229: }
10230: }
10231: }
10232: return $course;
10233: }
10234:
10235: ###############################################
10236:
10237: =pod
10238:
1.542 raeburn 10239: =item * &check_user_status()
1.274 raeburn 10240:
10241: Determines current status of supplied role for a
10242: specific user. Roles can be active, previous or future.
10243:
10244: Inputs:
10245: user's domain, user's username, course's domain,
1.375 raeburn 10246: course's number, optional section ID.
1.274 raeburn 10247:
10248: Outputs:
10249: role status: active, previous or future.
10250:
10251: =cut
10252:
10253: sub check_user_status {
1.412 raeburn 10254: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10255: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10256: my @uroles = keys(%userinfo);
1.274 raeburn 10257: my $srchstr;
10258: my $active_chk = 'none';
1.412 raeburn 10259: my $now = time;
1.274 raeburn 10260: if (@uroles > 0) {
1.908 raeburn 10261: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10262: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10263: } else {
1.412 raeburn 10264: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10265: }
10266: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10267: my $role_end = 0;
10268: my $role_start = 0;
10269: $active_chk = 'active';
1.412 raeburn 10270: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10271: $role_end = $1;
10272: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10273: $role_start = $1;
1.274 raeburn 10274: }
10275: }
10276: if ($role_start > 0) {
1.412 raeburn 10277: if ($now < $role_start) {
1.274 raeburn 10278: $active_chk = 'future';
10279: }
10280: }
10281: if ($role_end > 0) {
1.412 raeburn 10282: if ($now > $role_end) {
1.274 raeburn 10283: $active_chk = 'previous';
10284: }
10285: }
10286: }
10287: }
10288: return $active_chk;
10289: }
10290:
10291: ###############################################
10292:
10293: =pod
10294:
1.405 albertel 10295: =item * &get_sections()
1.233 raeburn 10296:
10297: Determines all the sections for a course including
10298: sections with students and sections containing other roles.
1.419 raeburn 10299: Incoming parameters:
10300:
10301: 1. domain
10302: 2. course number
10303: 3. reference to array containing roles for which sections should
10304: be gathered (optional).
10305: 4. reference to array containing status types for which sections
10306: should be gathered (optional).
10307:
10308: If the third argument is undefined, sections are gathered for any role.
10309: If the fourth argument is undefined, sections are gathered for any status.
10310: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10311:
1.374 raeburn 10312: Returns section hash (keys are section IDs, values are
10313: number of users in each section), subject to the
1.419 raeburn 10314: optional roles filter, optional status filter
1.233 raeburn 10315:
10316: =cut
10317:
10318: ###############################################
10319: sub get_sections {
1.419 raeburn 10320: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10321: if (!defined($cdom) || !defined($cnum)) {
10322: my $cid = $env{'request.course.id'};
10323:
10324: return if (!defined($cid));
10325:
10326: $cdom = $env{'course.'.$cid.'.domain'};
10327: $cnum = $env{'course.'.$cid.'.num'};
10328: }
10329:
10330: my %sectioncount;
1.419 raeburn 10331: my $now = time;
1.240 albertel 10332:
1.1118 raeburn 10333: my $check_students = 1;
10334: my $only_students = 0;
10335: if (ref($possible_roles) eq 'ARRAY') {
10336: if (grep(/^st$/,@{$possible_roles})) {
10337: if (@{$possible_roles} == 1) {
10338: $only_students = 1;
10339: }
10340: } else {
10341: $check_students = 0;
10342: }
10343: }
10344:
10345: if ($check_students) {
1.276 albertel 10346: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10347: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10348: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10349: my $start_index = &Apache::loncoursedata::CL_START();
10350: my $end_index = &Apache::loncoursedata::CL_END();
10351: my $status;
1.366 albertel 10352: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10353: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10354: $data->[$status_index],
10355: $data->[$start_index],
10356: $data->[$end_index]);
10357: if ($stu_status eq 'Active') {
10358: $status = 'active';
10359: } elsif ($end < $now) {
10360: $status = 'previous';
10361: } elsif ($start > $now) {
10362: $status = 'future';
10363: }
10364: if ($section ne '-1' && $section !~ /^\s*$/) {
10365: if ((!defined($possible_status)) || (($status ne '') &&
10366: (grep/^\Q$status\E$/,@{$possible_status}))) {
10367: $sectioncount{$section}++;
10368: }
1.240 albertel 10369: }
10370: }
10371: }
1.1118 raeburn 10372: if ($only_students) {
10373: return %sectioncount;
10374: }
1.240 albertel 10375: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10376: foreach my $user (sort(keys(%courseroles))) {
10377: if ($user !~ /^(\w{2})/) { next; }
10378: my ($role) = ($user =~ /^(\w{2})/);
10379: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10380: my ($section,$status);
1.240 albertel 10381: if ($role eq 'cr' &&
10382: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10383: $section=$1;
10384: }
10385: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10386: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10387: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10388: if ($end == -1 && $start == -1) {
10389: next; #deleted role
10390: }
10391: if (!defined($possible_status)) {
10392: $sectioncount{$section}++;
10393: } else {
10394: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10395: $status = 'active';
10396: } elsif ($end < $now) {
10397: $status = 'future';
10398: } elsif ($start > $now) {
10399: $status = 'previous';
10400: }
10401: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10402: $sectioncount{$section}++;
10403: }
10404: }
1.233 raeburn 10405: }
1.366 albertel 10406: return %sectioncount;
1.233 raeburn 10407: }
10408:
1.274 raeburn 10409: ###############################################
1.294 raeburn 10410:
10411: =pod
1.405 albertel 10412:
10413: =item * &get_course_users()
10414:
1.275 raeburn 10415: Retrieves usernames:domains for users in the specified course
10416: with specific role(s), and access status.
10417:
10418: Incoming parameters:
1.277 albertel 10419: 1. course domain
10420: 2. course number
10421: 3. access status: users must have - either active,
1.275 raeburn 10422: previous, future, or all.
1.277 albertel 10423: 4. reference to array of permissible roles
1.288 raeburn 10424: 5. reference to array of section restrictions (optional)
10425: 6. reference to results object (hash of hashes).
10426: 7. reference to optional userdata hash
1.609 raeburn 10427: 8. reference to optional statushash
1.630 raeburn 10428: 9. flag if privileged users (except those set to unhide in
10429: course settings) should be excluded
1.609 raeburn 10430: Keys of top level results hash are roles.
1.275 raeburn 10431: Keys of inner hashes are username:domain, with
10432: values set to access type.
1.288 raeburn 10433: Optional userdata hash returns an array with arguments in the
10434: same order as loncoursedata::get_classlist() for student data.
10435:
1.609 raeburn 10436: Optional statushash returns
10437:
1.288 raeburn 10438: Entries for end, start, section and status are blank because
10439: of the possibility of multiple values for non-student roles.
10440:
1.275 raeburn 10441: =cut
1.405 albertel 10442:
1.275 raeburn 10443: ###############################################
1.405 albertel 10444:
1.275 raeburn 10445: sub get_course_users {
1.630 raeburn 10446: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10447: my %idx = ();
1.419 raeburn 10448: my %seclists;
1.288 raeburn 10449:
10450: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10451: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10452: $idx{end} = &Apache::loncoursedata::CL_END();
10453: $idx{start} = &Apache::loncoursedata::CL_START();
10454: $idx{id} = &Apache::loncoursedata::CL_ID();
10455: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10456: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10457: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10458:
1.290 albertel 10459: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10460: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10461: my $now = time;
1.277 albertel 10462: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10463: my $match = 0;
1.412 raeburn 10464: my $secmatch = 0;
1.419 raeburn 10465: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10466: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10467: if ($section eq '') {
10468: $section = 'none';
10469: }
1.291 albertel 10470: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10471: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10472: $secmatch = 1;
10473: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10474: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10475: $secmatch = 1;
10476: }
10477: } else {
1.419 raeburn 10478: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10479: $secmatch = 1;
10480: }
1.290 albertel 10481: }
1.412 raeburn 10482: if (!$secmatch) {
10483: next;
10484: }
1.419 raeburn 10485: }
1.275 raeburn 10486: if (defined($$types{'active'})) {
1.288 raeburn 10487: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10488: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10489: $match = 1;
1.275 raeburn 10490: }
10491: }
10492: if (defined($$types{'previous'})) {
1.609 raeburn 10493: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10494: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10495: $match = 1;
1.275 raeburn 10496: }
10497: }
10498: if (defined($$types{'future'})) {
1.609 raeburn 10499: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10500: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10501: $match = 1;
1.275 raeburn 10502: }
10503: }
1.609 raeburn 10504: if ($match) {
10505: push(@{$seclists{$student}},$section);
10506: if (ref($userdata) eq 'HASH') {
10507: $$userdata{$student} = $$classlist{$student};
10508: }
10509: if (ref($statushash) eq 'HASH') {
10510: $statushash->{$student}{'st'}{$section} = $status;
10511: }
1.288 raeburn 10512: }
1.275 raeburn 10513: }
10514: }
1.412 raeburn 10515: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10516: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10517: my $now = time;
1.609 raeburn 10518: my %displaystatus = ( previous => 'Expired',
10519: active => 'Active',
10520: future => 'Future',
10521: );
1.1121 raeburn 10522: my (%nothide,@possdoms);
1.630 raeburn 10523: if ($hidepriv) {
10524: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10525: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10526: if ($user !~ /:/) {
10527: $nothide{join(':',split(/[\@]/,$user))}=1;
10528: } else {
10529: $nothide{$user} = 1;
10530: }
10531: }
1.1121 raeburn 10532: my @possdoms = ($cdom);
10533: if ($coursehash{'checkforpriv'}) {
10534: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10535: }
1.630 raeburn 10536: }
1.439 raeburn 10537: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10538: my $match = 0;
1.412 raeburn 10539: my $secmatch = 0;
1.439 raeburn 10540: my $status;
1.412 raeburn 10541: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10542: $user =~ s/:$//;
1.439 raeburn 10543: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10544: if ($end == -1 || $start == -1) {
10545: next;
10546: }
10547: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10548: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10549: my ($uname,$udom) = split(/:/,$user);
10550: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10551: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10552: $secmatch = 1;
10553: } elsif ($usec eq '') {
1.420 albertel 10554: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10555: $secmatch = 1;
10556: }
10557: } else {
10558: if (grep(/^\Q$usec\E$/,@{$sections})) {
10559: $secmatch = 1;
10560: }
10561: }
10562: if (!$secmatch) {
10563: next;
10564: }
1.288 raeburn 10565: }
1.419 raeburn 10566: if ($usec eq '') {
10567: $usec = 'none';
10568: }
1.275 raeburn 10569: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10570: if ($hidepriv) {
1.1121 raeburn 10571: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10572: (!$nothide{$uname.':'.$udom})) {
10573: next;
10574: }
10575: }
1.503 raeburn 10576: if ($end > 0 && $end < $now) {
1.439 raeburn 10577: $status = 'previous';
10578: } elsif ($start > $now) {
10579: $status = 'future';
10580: } else {
10581: $status = 'active';
10582: }
1.277 albertel 10583: foreach my $type (keys(%{$types})) {
1.275 raeburn 10584: if ($status eq $type) {
1.420 albertel 10585: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10586: push(@{$$users{$role}{$user}},$type);
10587: }
1.288 raeburn 10588: $match = 1;
10589: }
10590: }
1.419 raeburn 10591: if (($match) && (ref($userdata) eq 'HASH')) {
10592: if (!exists($$userdata{$uname.':'.$udom})) {
10593: &get_user_info($udom,$uname,\%idx,$userdata);
10594: }
1.420 albertel 10595: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10596: push(@{$seclists{$uname.':'.$udom}},$usec);
10597: }
1.609 raeburn 10598: if (ref($statushash) eq 'HASH') {
10599: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10600: }
1.275 raeburn 10601: }
10602: }
10603: }
10604: }
1.290 albertel 10605: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10606: if ((defined($cdom)) && (defined($cnum))) {
10607: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10608: if ( defined($csettings{'internal.courseowner'}) ) {
10609: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10610: next if ($owner eq '');
10611: my ($ownername,$ownerdom);
10612: if ($owner =~ /^([^:]+):([^:]+)$/) {
10613: $ownername = $1;
10614: $ownerdom = $2;
10615: } else {
10616: $ownername = $owner;
10617: $ownerdom = $cdom;
10618: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10619: }
10620: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10621: if (defined($userdata) &&
1.609 raeburn 10622: !exists($$userdata{$owner})) {
10623: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10624: if (!grep(/^none$/,@{$seclists{$owner}})) {
10625: push(@{$seclists{$owner}},'none');
10626: }
10627: if (ref($statushash) eq 'HASH') {
10628: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10629: }
1.290 albertel 10630: }
1.279 raeburn 10631: }
10632: }
10633: }
1.419 raeburn 10634: foreach my $user (keys(%seclists)) {
10635: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10636: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10637: }
1.275 raeburn 10638: }
10639: return;
10640: }
10641:
1.288 raeburn 10642: sub get_user_info {
10643: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10644: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10645: &plainname($uname,$udom,'lastname');
1.291 albertel 10646: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10647: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10648: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10649: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10650: return;
10651: }
1.275 raeburn 10652:
1.472 raeburn 10653: ###############################################
10654:
10655: =pod
10656:
10657: =item * &get_user_quota()
10658:
1.1134 raeburn 10659: Retrieves quota assigned for storage of user files.
10660: Default is to report quota for portfolio files.
1.472 raeburn 10661:
10662: Incoming parameters:
10663: 1. user's username
10664: 2. user's domain
1.1134 raeburn 10665: 3. quota name - portfolio, author, or course
1.1136 raeburn 10666: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10667: 4. crstype - official, unofficial, textbook, placement or community,
10668: if quota name is course
1.472 raeburn 10669:
10670: Returns:
1.1163 raeburn 10671: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10672: 2. (Optional) Type of setting: custom or default
10673: (individually assigned or default for user's
10674: institutional status).
10675: 3. (Optional) - User's institutional status (e.g., faculty, staff
10676: or student - types as defined in localenroll::inst_usertypes
10677: for user's domain, which determines default quota for user.
10678: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10679:
10680: If a value has been stored in the user's environment,
1.536 raeburn 10681: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10682: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10683:
10684: =cut
10685:
10686: ###############################################
10687:
10688:
10689: sub get_user_quota {
1.1136 raeburn 10690: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10691: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10692: if (!defined($udom)) {
10693: $udom = $env{'user.domain'};
10694: }
10695: if (!defined($uname)) {
10696: $uname = $env{'user.name'};
10697: }
10698: if (($udom eq '' || $uname eq '') ||
10699: ($udom eq 'public') && ($uname eq 'public')) {
10700: $quota = 0;
1.536 raeburn 10701: $quotatype = 'default';
10702: $defquota = 0;
1.472 raeburn 10703: } else {
1.536 raeburn 10704: my $inststatus;
1.1134 raeburn 10705: if ($quotaname eq 'course') {
10706: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10707: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10708: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10709: } else {
10710: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10711: $quota = $cenv{'internal.uploadquota'};
10712: }
1.536 raeburn 10713: } else {
1.1134 raeburn 10714: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10715: if ($quotaname eq 'author') {
10716: $quota = $env{'environment.authorquota'};
10717: } else {
10718: $quota = $env{'environment.portfolioquota'};
10719: }
10720: $inststatus = $env{'environment.inststatus'};
10721: } else {
10722: my %userenv =
10723: &Apache::lonnet::get('environment',['portfolioquota',
10724: 'authorquota','inststatus'],$udom,$uname);
10725: my ($tmp) = keys(%userenv);
10726: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10727: if ($quotaname eq 'author') {
10728: $quota = $userenv{'authorquota'};
10729: } else {
10730: $quota = $userenv{'portfolioquota'};
10731: }
10732: $inststatus = $userenv{'inststatus'};
10733: } else {
10734: undef(%userenv);
10735: }
10736: }
10737: }
10738: if ($quota eq '' || wantarray) {
10739: if ($quotaname eq 'course') {
10740: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10741: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10742: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10743: ($crstype eq 'placement')) {
1.1136 raeburn 10744: $defquota = $domdefs{$crstype.'quota'};
10745: }
10746: if ($defquota eq '') {
10747: $defquota = 500;
10748: }
1.1134 raeburn 10749: } else {
10750: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10751: }
10752: if ($quota eq '') {
10753: $quota = $defquota;
10754: $quotatype = 'default';
10755: } else {
10756: $quotatype = 'custom';
10757: }
1.472 raeburn 10758: }
10759: }
1.536 raeburn 10760: if (wantarray) {
10761: return ($quota,$quotatype,$settingstatus,$defquota);
10762: } else {
10763: return $quota;
10764: }
1.472 raeburn 10765: }
10766:
10767: ###############################################
10768:
10769: =pod
10770:
10771: =item * &default_quota()
10772:
1.536 raeburn 10773: Retrieves default quota assigned for storage of user portfolio files,
10774: given an (optional) user's institutional status.
1.472 raeburn 10775:
10776: Incoming parameters:
1.1142 raeburn 10777:
1.472 raeburn 10778: 1. domain
1.536 raeburn 10779: 2. (Optional) institutional status(es). This is a : separated list of
10780: status types (e.g., faculty, staff, student etc.)
10781: which apply to the user for whom the default is being retrieved.
10782: If the institutional status string in undefined, the domain
1.1134 raeburn 10783: default quota will be returned.
10784: 3. quota name - portfolio, author, or course
10785: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10786:
10787: Returns:
1.1142 raeburn 10788:
1.1163 raeburn 10789: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10790: 2. (Optional) institutional type which determined the value of the
10791: default quota.
1.472 raeburn 10792:
10793: If a value has been stored in the domain's configuration db,
10794: it will return that, otherwise it returns 20 (for backwards
10795: compatibility with domains which have not set up a configuration
1.1163 raeburn 10796: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10797:
1.536 raeburn 10798: If the user's status includes multiple types (e.g., staff and student),
10799: the largest default quota which applies to the user determines the
10800: default quota returned.
10801:
1.472 raeburn 10802: =cut
10803:
10804: ###############################################
10805:
10806:
10807: sub default_quota {
1.1134 raeburn 10808: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10809: my ($defquota,$settingstatus);
10810: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10811: ['quotas'],$udom);
1.1134 raeburn 10812: my $key = 'defaultquota';
10813: if ($quotaname eq 'author') {
10814: $key = 'authorquota';
10815: }
1.622 raeburn 10816: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10817: if ($inststatus ne '') {
1.765 raeburn 10818: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10819: foreach my $item (@statuses) {
1.1134 raeburn 10820: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10821: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10822: if ($defquota eq '') {
1.1134 raeburn 10823: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10824: $settingstatus = $item;
1.1134 raeburn 10825: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10826: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10827: $settingstatus = $item;
10828: }
10829: }
1.1134 raeburn 10830: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10831: if ($quotahash{'quotas'}{$item} ne '') {
10832: if ($defquota eq '') {
10833: $defquota = $quotahash{'quotas'}{$item};
10834: $settingstatus = $item;
10835: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10836: $defquota = $quotahash{'quotas'}{$item};
10837: $settingstatus = $item;
10838: }
1.536 raeburn 10839: }
10840: }
10841: }
10842: }
10843: if ($defquota eq '') {
1.1134 raeburn 10844: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10845: $defquota = $quotahash{'quotas'}{$key}{'default'};
10846: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10847: $defquota = $quotahash{'quotas'}{'default'};
10848: }
1.536 raeburn 10849: $settingstatus = 'default';
1.1139 raeburn 10850: if ($defquota eq '') {
10851: if ($quotaname eq 'author') {
10852: $defquota = 500;
10853: }
10854: }
1.536 raeburn 10855: }
10856: } else {
10857: $settingstatus = 'default';
1.1134 raeburn 10858: if ($quotaname eq 'author') {
10859: $defquota = 500;
10860: } else {
10861: $defquota = 20;
10862: }
1.536 raeburn 10863: }
10864: if (wantarray) {
10865: return ($defquota,$settingstatus);
1.472 raeburn 10866: } else {
1.536 raeburn 10867: return $defquota;
1.472 raeburn 10868: }
10869: }
10870:
1.1135 raeburn 10871: ###############################################
10872:
10873: =pod
10874:
1.1136 raeburn 10875: =item * &excess_filesize_warning()
1.1135 raeburn 10876:
10877: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10878: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10879: space to be exceeded.
1.1136 raeburn 10880:
10881: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10882: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10883:
1.1165 raeburn 10884: Inputs: 7
1.1136 raeburn 10885: 1. username or coursenum
1.1135 raeburn 10886: 2. domain
1.1136 raeburn 10887: 3. context ('author' or 'course')
1.1135 raeburn 10888: 4. filename of file for which action is being requested
10889: 5. filesize (kB) of file
10890: 6. action being taken: copy or upload.
1.1237 raeburn 10891: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10892:
10893: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10894: otherwise return null.
10895:
10896: =back
1.1135 raeburn 10897:
10898: =cut
10899:
1.1136 raeburn 10900: sub excess_filesize_warning {
1.1165 raeburn 10901: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10902: my $current_disk_usage = 0;
1.1165 raeburn 10903: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10904: if ($context eq 'author') {
10905: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10906: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10907: } else {
10908: foreach my $subdir ('docs','supplemental') {
10909: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10910: }
10911: }
1.1135 raeburn 10912: $disk_quota = int($disk_quota * 1000);
10913: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10914: return '<p class="LC_warning">'.
1.1135 raeburn 10915: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10916: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10917: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10918: $disk_quota,$current_disk_usage).
10919: '</p>';
10920: }
10921: return;
10922: }
10923:
10924: ###############################################
10925:
10926:
1.1136 raeburn 10927:
10928:
1.384 raeburn 10929: sub get_secgrprole_info {
10930: my ($cdom,$cnum,$needroles,$type) = @_;
10931: my %sections_count = &get_sections($cdom,$cnum);
10932: my @sections = (sort {$a <=> $b} keys(%sections_count));
10933: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10934: my @groups = sort(keys(%curr_groups));
10935: my $allroles = [];
10936: my $rolehash;
10937: my $accesshash = {
10938: active => 'Currently has access',
10939: future => 'Will have future access',
10940: previous => 'Previously had access',
10941: };
10942: if ($needroles) {
10943: $rolehash = {'all' => 'all'};
1.385 albertel 10944: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10945: if (&Apache::lonnet::error(%user_roles)) {
10946: undef(%user_roles);
10947: }
10948: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10949: my ($role)=split(/\:/,$item,2);
10950: if ($role eq 'cr') { next; }
10951: if ($role =~ /^cr/) {
10952: $$rolehash{$role} = (split('/',$role))[3];
10953: } else {
10954: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10955: }
10956: }
10957: foreach my $key (sort(keys(%{$rolehash}))) {
10958: push(@{$allroles},$key);
10959: }
10960: push (@{$allroles},'st');
10961: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10962: }
10963: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10964: }
10965:
1.555 raeburn 10966: sub user_picker {
1.1279 raeburn 10967: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10968: my $currdom = $dom;
1.1253 raeburn 10969: my @alldoms = &Apache::lonnet::all_domains();
10970: if (@alldoms == 1) {
10971: my %domsrch = &Apache::lonnet::get_dom('configuration',
10972: ['directorysrch'],$alldoms[0]);
10973: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10974: my $showdom = $domdesc;
10975: if ($showdom eq '') {
10976: $showdom = $dom;
10977: }
10978: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10979: if ((!$domsrch{'directorysrch'}{'available'}) &&
10980: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10981: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10982: }
10983: }
10984: }
1.555 raeburn 10985: my %curr_selected = (
10986: srchin => 'dom',
1.580 raeburn 10987: srchby => 'lastname',
1.555 raeburn 10988: );
10989: my $srchterm;
1.625 raeburn 10990: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10991: if ($srch->{'srchby'} ne '') {
10992: $curr_selected{'srchby'} = $srch->{'srchby'};
10993: }
10994: if ($srch->{'srchin'} ne '') {
10995: $curr_selected{'srchin'} = $srch->{'srchin'};
10996: }
10997: if ($srch->{'srchtype'} ne '') {
10998: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10999: }
11000: if ($srch->{'srchdomain'} ne '') {
11001: $currdom = $srch->{'srchdomain'};
11002: }
11003: $srchterm = $srch->{'srchterm'};
11004: }
1.1222 damieng 11005: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11006: 'usr' => 'Search criteria',
1.563 raeburn 11007: 'doma' => 'Domain/institution to search',
1.558 albertel 11008: 'uname' => 'username',
11009: 'lastname' => 'last name',
1.555 raeburn 11010: 'lastfirst' => 'last name, first name',
1.558 albertel 11011: 'crs' => 'in this course',
1.576 raeburn 11012: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11013: 'alc' => 'all LON-CAPA',
1.573 raeburn 11014: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11015: 'exact' => 'is',
11016: 'contains' => 'contains',
1.569 raeburn 11017: 'begins' => 'begins with',
1.1222 damieng 11018: );
11019: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11020: 'youm' => "You must include some text to search for.",
11021: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11022: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11023: 'yomc' => "You must choose a domain when using an institutional directory search.",
11024: 'ymcd' => "You must choose a domain when using a domain search.",
11025: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11026: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11027: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11028: );
1.1222 damieng 11029: &html_escape(\%html_lt);
11030: &js_escape(\%js_lt);
1.1255 raeburn 11031: my $domform;
1.1277 raeburn 11032: my $allow_blank = 1;
1.1255 raeburn 11033: if ($fixeddom) {
1.1277 raeburn 11034: $allow_blank = 0;
11035: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11036: } else {
1.1287 raeburn 11037: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11038: my ($trusted,$untrusted);
1.1287 raeburn 11039: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11040: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11041: } elsif ($context eq 'author') {
1.1288 raeburn 11042: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11043: } elsif ($context eq 'domain') {
1.1288 raeburn 11044: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11045: }
1.1288 raeburn 11046: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11047: }
1.563 raeburn 11048: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11049:
11050: my @srchins = ('crs','dom','alc','instd');
11051:
11052: foreach my $option (@srchins) {
11053: # FIXME 'alc' option unavailable until
11054: # loncreateuser::print_user_query_page()
11055: # has been completed.
11056: next if ($option eq 'alc');
1.880 raeburn 11057: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11058: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11059: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11060: if ($curr_selected{'srchin'} eq $option) {
11061: $srchinsel .= '
1.1222 damieng 11062: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11063: } else {
11064: $srchinsel .= '
1.1222 damieng 11065: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11066: }
1.555 raeburn 11067: }
1.563 raeburn 11068: $srchinsel .= "\n </select>\n";
1.555 raeburn 11069:
11070: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11071: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11072: if ($curr_selected{'srchby'} eq $option) {
11073: $srchbysel .= '
1.1222 damieng 11074: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11075: } else {
11076: $srchbysel .= '
1.1222 damieng 11077: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11078: }
11079: }
11080: $srchbysel .= "\n </select>\n";
11081:
11082: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11083: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11084: if ($curr_selected{'srchtype'} eq $option) {
11085: $srchtypesel .= '
1.1222 damieng 11086: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11087: } else {
11088: $srchtypesel .= '
1.1222 damieng 11089: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11090: }
11091: }
11092: $srchtypesel .= "\n </select>\n";
11093:
1.558 albertel 11094: my ($newuserscript,$new_user_create);
1.994 raeburn 11095: my $context_dom = $env{'request.role.domain'};
11096: if ($context eq 'requestcrs') {
11097: if ($env{'form.coursedom'} ne '') {
11098: $context_dom = $env{'form.coursedom'};
11099: }
11100: }
1.556 raeburn 11101: if ($forcenewuser) {
1.576 raeburn 11102: if (ref($srch) eq 'HASH') {
1.994 raeburn 11103: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11104: if ($cancreate) {
11105: $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>';
11106: } else {
1.799 bisitz 11107: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11108: my %usertypetext = (
11109: official => 'institutional',
11110: unofficial => 'non-institutional',
11111: );
1.799 bisitz 11112: $new_user_create = '<p class="LC_warning">'
11113: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11114: .' '
11115: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11116: ,'<a href="'.$helplink.'">','</a>')
11117: .'</p><br />';
1.627 raeburn 11118: }
1.576 raeburn 11119: }
11120: }
11121:
1.556 raeburn 11122: $newuserscript = <<"ENDSCRIPT";
11123:
1.570 raeburn 11124: function setSearch(createnew,callingForm) {
1.556 raeburn 11125: if (createnew == 1) {
1.570 raeburn 11126: for (var i=0; i<callingForm.srchby.length; i++) {
11127: if (callingForm.srchby.options[i].value == 'uname') {
11128: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11129: }
11130: }
1.570 raeburn 11131: for (var i=0; i<callingForm.srchin.length; i++) {
11132: if ( callingForm.srchin.options[i].value == 'dom') {
11133: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11134: }
11135: }
1.570 raeburn 11136: for (var i=0; i<callingForm.srchtype.length; i++) {
11137: if (callingForm.srchtype.options[i].value == 'exact') {
11138: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11139: }
11140: }
1.570 raeburn 11141: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11142: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11143: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11144: }
11145: }
11146: }
11147: }
11148: ENDSCRIPT
1.558 albertel 11149:
1.556 raeburn 11150: }
11151:
1.555 raeburn 11152: my $output = <<"END_BLOCK";
1.556 raeburn 11153: <script type="text/javascript">
1.824 bisitz 11154: // <![CDATA[
1.570 raeburn 11155: function validateEntry(callingForm) {
1.558 albertel 11156:
1.556 raeburn 11157: var checkok = 1;
1.558 albertel 11158: var srchin;
1.570 raeburn 11159: for (var i=0; i<callingForm.srchin.length; i++) {
11160: if ( callingForm.srchin[i].checked ) {
11161: srchin = callingForm.srchin[i].value;
1.558 albertel 11162: }
11163: }
11164:
1.570 raeburn 11165: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11166: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11167: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11168: var srchterm = callingForm.srchterm.value;
11169: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11170: var msg = "";
11171:
11172: if (srchterm == "") {
11173: checkok = 0;
1.1222 damieng 11174: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11175: }
11176:
1.569 raeburn 11177: if (srchtype== 'begins') {
11178: if (srchterm.length < 2) {
11179: checkok = 0;
1.1222 damieng 11180: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11181: }
11182: }
11183:
1.556 raeburn 11184: if (srchtype== 'contains') {
11185: if (srchterm.length < 3) {
11186: checkok = 0;
1.1222 damieng 11187: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11188: }
11189: }
11190: if (srchin == 'instd') {
11191: if (srchdomain == '') {
11192: checkok = 0;
1.1222 damieng 11193: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11194: }
11195: }
11196: if (srchin == 'dom') {
11197: if (srchdomain == '') {
11198: checkok = 0;
1.1222 damieng 11199: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11200: }
11201: }
11202: if (srchby == 'lastfirst') {
11203: if (srchterm.indexOf(",") == -1) {
11204: checkok = 0;
1.1222 damieng 11205: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11206: }
11207: if (srchterm.indexOf(",") == srchterm.length -1) {
11208: checkok = 0;
1.1222 damieng 11209: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11210: }
11211: }
11212: if (checkok == 0) {
1.1222 damieng 11213: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11214: return;
11215: }
11216: if (checkok == 1) {
1.570 raeburn 11217: callingForm.submit();
1.556 raeburn 11218: }
11219: }
11220:
11221: $newuserscript
11222:
1.824 bisitz 11223: // ]]>
1.556 raeburn 11224: </script>
1.558 albertel 11225:
11226: $new_user_create
11227:
1.555 raeburn 11228: END_BLOCK
1.558 albertel 11229:
1.876 raeburn 11230: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11231: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11232: $domform.
11233: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11234: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11235: $srchbysel.
11236: $srchtypesel.
11237: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11238: $srchinsel.
11239: &Apache::lonhtmlcommon::row_closure(1).
11240: &Apache::lonhtmlcommon::end_pick_box().
11241: '<br />';
1.1253 raeburn 11242: return ($output,1);
1.555 raeburn 11243: }
11244:
1.612 raeburn 11245: sub user_rule_check {
1.615 raeburn 11246: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11247: my ($response,%inst_response);
1.612 raeburn 11248: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11249: if (keys(%{$usershash}) > 1) {
11250: my (%by_username,%by_id,%userdoms);
11251: my $checkid;
11252: if (ref($checks) eq 'HASH') {
11253: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11254: $checkid = 1;
11255: }
11256: }
11257: foreach my $user (keys(%{$usershash})) {
11258: my ($uname,$udom) = split(/:/,$user);
11259: if ($checkid) {
11260: if (ref($usershash->{$user}) eq 'HASH') {
11261: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11262: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11263: $userdoms{$udom} = 1;
1.1227 raeburn 11264: if (ref($inst_results) eq 'HASH') {
11265: $inst_results->{$uname.':'.$udom} = {};
11266: }
1.1226 raeburn 11267: }
11268: }
11269: } else {
11270: $by_username{$udom}{$uname} = 1;
11271: $userdoms{$udom} = 1;
1.1227 raeburn 11272: if (ref($inst_results) eq 'HASH') {
11273: $inst_results->{$uname.':'.$udom} = {};
11274: }
1.1226 raeburn 11275: }
11276: }
11277: foreach my $udom (keys(%userdoms)) {
11278: if (!$got_rules->{$udom}) {
11279: my %domconfig = &Apache::lonnet::get_dom('configuration',
11280: ['usercreation'],$udom);
11281: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11282: foreach my $item ('username','id') {
11283: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11284: $$curr_rules{$udom}{$item} =
11285: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11286: }
11287: }
11288: }
11289: $got_rules->{$udom} = 1;
11290: }
1.612 raeburn 11291: }
1.1226 raeburn 11292: if ($checkid) {
11293: foreach my $udom (keys(%by_id)) {
11294: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11295: if ($outcome eq 'ok') {
1.1227 raeburn 11296: foreach my $id (keys(%{$by_id{$udom}})) {
11297: my $uname = $by_id{$udom}{$id};
11298: $inst_response{$uname.':'.$udom} = $outcome;
11299: }
1.1226 raeburn 11300: if (ref($results) eq 'HASH') {
11301: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11302: if (exists($inst_response{$uname.':'.$udom})) {
11303: $inst_response{$uname.':'.$udom} = $outcome;
11304: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11305: }
1.1226 raeburn 11306: }
11307: }
11308: }
1.612 raeburn 11309: }
1.615 raeburn 11310: } else {
1.1226 raeburn 11311: foreach my $udom (keys(%by_username)) {
11312: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11313: if ($outcome eq 'ok') {
1.1227 raeburn 11314: foreach my $uname (keys(%{$by_username{$udom}})) {
11315: $inst_response{$uname.':'.$udom} = $outcome;
11316: }
1.1226 raeburn 11317: if (ref($results) eq 'HASH') {
11318: foreach my $uname (keys(%{$results})) {
11319: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11320: }
11321: }
11322: }
11323: }
1.612 raeburn 11324: }
1.1226 raeburn 11325: } elsif (keys(%{$usershash}) == 1) {
11326: my $user = (keys(%{$usershash}))[0];
11327: my ($uname,$udom) = split(/:/,$user);
11328: if (($udom ne '') && ($uname ne '')) {
11329: if (ref($usershash->{$user}) eq 'HASH') {
11330: if (ref($checks) eq 'HASH') {
11331: if (defined($checks->{'username'})) {
11332: ($inst_response{$user},%{$inst_results->{$user}}) =
11333: &Apache::lonnet::get_instuser($udom,$uname);
11334: } elsif (defined($checks->{'id'})) {
11335: if ($usershash->{$user}->{'id'} ne '') {
11336: ($inst_response{$user},%{$inst_results->{$user}}) =
11337: &Apache::lonnet::get_instuser($udom,undef,
11338: $usershash->{$user}->{'id'});
11339: } else {
11340: ($inst_response{$user},%{$inst_results->{$user}}) =
11341: &Apache::lonnet::get_instuser($udom,$uname);
11342: }
1.585 raeburn 11343: }
1.1226 raeburn 11344: } else {
11345: ($inst_response{$user},%{$inst_results->{$user}}) =
11346: &Apache::lonnet::get_instuser($udom,$uname);
11347: return;
11348: }
11349: if (!$got_rules->{$udom}) {
11350: my %domconfig = &Apache::lonnet::get_dom('configuration',
11351: ['usercreation'],$udom);
11352: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11353: foreach my $item ('username','id') {
11354: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11355: $$curr_rules{$udom}{$item} =
11356: $domconfig{'usercreation'}{$item.'_rule'};
11357: }
11358: }
11359: }
11360: $got_rules->{$udom} = 1;
1.585 raeburn 11361: }
11362: }
1.1226 raeburn 11363: } else {
11364: return;
11365: }
11366: } else {
11367: return;
11368: }
11369: foreach my $user (keys(%{$usershash})) {
11370: my ($uname,$udom) = split(/:/,$user);
11371: next if (($udom eq '') || ($uname eq ''));
11372: my $id;
1.1227 raeburn 11373: if (ref($inst_results) eq 'HASH') {
11374: if (ref($inst_results->{$user}) eq 'HASH') {
11375: $id = $inst_results->{$user}->{'id'};
11376: }
11377: }
11378: if ($id eq '') {
11379: if (ref($usershash->{$user})) {
11380: $id = $usershash->{$user}->{'id'};
11381: }
1.585 raeburn 11382: }
1.612 raeburn 11383: foreach my $item (keys(%{$checks})) {
11384: if (ref($$curr_rules{$udom}) eq 'HASH') {
11385: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11386: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11387: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11388: $$curr_rules{$udom}{$item});
1.612 raeburn 11389: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11390: if ($rule_check{$rule}) {
11391: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11392: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11393: if (ref($inst_results) eq 'HASH') {
11394: if (ref($inst_results->{$user}) eq 'HASH') {
11395: if (keys(%{$inst_results->{$user}}) == 0) {
11396: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11397: } elsif ($item eq 'id') {
11398: if ($inst_results->{$user}->{'id'} eq '') {
11399: $$alerts{$item}{$udom}{$uname} = 1;
11400: }
1.615 raeburn 11401: }
1.612 raeburn 11402: }
11403: }
1.615 raeburn 11404: }
11405: last;
1.585 raeburn 11406: }
11407: }
11408: }
11409: }
11410: }
11411: }
11412: }
11413: }
1.612 raeburn 11414: return;
11415: }
11416:
11417: sub user_rule_formats {
11418: my ($domain,$domdesc,$curr_rules,$check) = @_;
11419: my %text = (
11420: 'username' => 'Usernames',
11421: 'id' => 'IDs',
11422: );
11423: my $output;
11424: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11425: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11426: if (@{$ruleorder} > 0) {
1.1102 raeburn 11427: $output = '<br />'.
11428: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11429: '<span class="LC_cusr_emph">','</span>',$domdesc).
11430: ' <ul>';
1.612 raeburn 11431: foreach my $rule (@{$ruleorder}) {
11432: if (ref($curr_rules) eq 'ARRAY') {
11433: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11434: if (ref($rules->{$rule}) eq 'HASH') {
11435: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11436: $rules->{$rule}{'desc'}.'</li>';
11437: }
11438: }
11439: }
11440: }
11441: $output .= '</ul>';
11442: }
11443: }
11444: return $output;
11445: }
11446:
11447: sub instrule_disallow_msg {
1.615 raeburn 11448: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11449: my $response;
11450: my %text = (
11451: item => 'username',
11452: items => 'usernames',
11453: match => 'matches',
11454: do => 'does',
11455: action => 'a username',
11456: one => 'one',
11457: );
11458: if ($count > 1) {
11459: $text{'item'} = 'usernames';
11460: $text{'match'} ='match';
11461: $text{'do'} = 'do';
11462: $text{'action'} = 'usernames',
11463: $text{'one'} = 'ones';
11464: }
11465: if ($checkitem eq 'id') {
11466: $text{'items'} = 'IDs';
11467: $text{'item'} = 'ID';
11468: $text{'action'} = 'an ID';
1.615 raeburn 11469: if ($count > 1) {
11470: $text{'item'} = 'IDs';
11471: $text{'action'} = 'IDs';
11472: }
1.612 raeburn 11473: }
1.674 bisitz 11474: $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 11475: if ($mode eq 'upload') {
11476: if ($checkitem eq 'username') {
11477: $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'}.");
11478: } elsif ($checkitem eq 'id') {
1.674 bisitz 11479: $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 11480: }
1.669 raeburn 11481: } elsif ($mode eq 'selfcreate') {
11482: if ($checkitem eq 'id') {
11483: $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.");
11484: }
1.615 raeburn 11485: } else {
11486: if ($checkitem eq 'username') {
11487: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11488: } elsif ($checkitem eq 'id') {
11489: $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.");
11490: }
1.612 raeburn 11491: }
11492: return $response;
1.585 raeburn 11493: }
11494:
1.624 raeburn 11495: sub personal_data_fieldtitles {
11496: my %fieldtitles = &Apache::lonlocal::texthash (
11497: id => 'Student/Employee ID',
11498: permanentemail => 'E-mail address',
11499: lastname => 'Last Name',
11500: firstname => 'First Name',
11501: middlename => 'Middle Name',
11502: generation => 'Generation',
11503: gen => 'Generation',
1.765 raeburn 11504: inststatus => 'Affiliation',
1.624 raeburn 11505: );
11506: return %fieldtitles;
11507: }
11508:
1.642 raeburn 11509: sub sorted_inst_types {
11510: my ($dom) = @_;
1.1185 raeburn 11511: my ($usertypes,$order);
11512: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11513: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11514: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11515: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11516: } else {
11517: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11518: }
1.642 raeburn 11519: my $othertitle = &mt('All users');
11520: if ($env{'request.course.id'}) {
1.668 raeburn 11521: $othertitle = &mt('Any users');
1.642 raeburn 11522: }
11523: my @types;
11524: if (ref($order) eq 'ARRAY') {
11525: @types = @{$order};
11526: }
11527: if (@types == 0) {
11528: if (ref($usertypes) eq 'HASH') {
11529: @types = sort(keys(%{$usertypes}));
11530: }
11531: }
11532: if (keys(%{$usertypes}) > 0) {
11533: $othertitle = &mt('Other users');
11534: }
11535: return ($othertitle,$usertypes,\@types);
11536: }
11537:
1.645 raeburn 11538: sub get_institutional_codes {
1.1361 raeburn 11539: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11540: # Get complete list of course sections to update
11541: my @currsections = ();
11542: my @currxlists = ();
1.1361 raeburn 11543: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11544: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11545: my $crskey = $crs.':'.$coursecode;
11546: @{$unclutteredsec{$crskey}} = ();
11547: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11548:
11549: if ($$settings{'internal.sectionnums'} ne '') {
11550: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11551: }
11552:
11553: if ($$settings{'internal.crosslistings'} ne '') {
11554: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11555: }
11556:
11557: if (@currxlists > 0) {
1.1361 raeburn 11558: foreach my $xl (@currxlists) {
11559: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11560: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11561: push(@{$allcourses},$1);
1.645 raeburn 11562: $$LC_code{$1} = $2;
11563: }
11564: }
11565: }
11566: }
1.1361 raeburn 11567:
1.645 raeburn 11568: if (@currsections > 0) {
1.1361 raeburn 11569: foreach my $sec (@currsections) {
11570: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11571: my $instsec = $1;
1.645 raeburn 11572: my $lc_sec = $2;
1.1361 raeburn 11573: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11574: push(@{$unclutteredsec{$crskey}},$instsec);
11575: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11576: }
11577: }
11578: }
11579: }
11580:
11581: if (@{$unclutteredsec{$crskey}} > 0) {
11582: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11583: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11584: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11585: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11586: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11587: push(@{$allcourses},$sec);
1.1361 raeburn 11588: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11589: }
11590: }
11591: }
11592: }
11593: return;
11594: }
11595:
1.971 raeburn 11596: sub get_standard_codeitems {
11597: return ('Year','Semester','Department','Number','Section');
11598: }
11599:
1.112 bowersj2 11600: =pod
11601:
1.780 raeburn 11602: =head1 Slot Helpers
11603:
11604: =over 4
11605:
11606: =item * sorted_slots()
11607:
1.1040 raeburn 11608: Sorts an array of slot names in order of an optional sort key,
11609: default sort is by slot start time (earliest first).
1.780 raeburn 11610:
11611: Inputs:
11612:
11613: =over 4
11614:
11615: slotsarr - Reference to array of unsorted slot names.
11616:
11617: slots - Reference to hash of hash, where outer hash keys are slot names.
11618:
1.1040 raeburn 11619: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11620:
1.549 albertel 11621: =back
11622:
1.780 raeburn 11623: Returns:
11624:
11625: =over 4
11626:
1.1040 raeburn 11627: sorted - An array of slot names sorted by a specified sort key
11628: (default sort key is start time of the slot).
1.780 raeburn 11629:
11630: =back
11631:
11632: =cut
11633:
11634:
11635: sub sorted_slots {
1.1040 raeburn 11636: my ($slotsarr,$slots,$sortkey) = @_;
11637: if ($sortkey eq '') {
11638: $sortkey = 'starttime';
11639: }
1.780 raeburn 11640: my @sorted;
11641: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11642: @sorted =
11643: sort {
11644: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11645: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11646: }
11647: if (ref($slots->{$a})) { return -1;}
11648: if (ref($slots->{$b})) { return 1;}
11649: return 0;
11650: } @{$slotsarr};
11651: }
11652: return @sorted;
11653: }
11654:
1.1040 raeburn 11655: =pod
11656:
11657: =item * get_future_slots()
11658:
11659: Inputs:
11660:
11661: =over 4
11662:
11663: cnum - course number
11664:
11665: cdom - course domain
11666:
11667: now - current UNIX time
11668:
11669: symb - optional symb
11670:
11671: =back
11672:
11673: Returns:
11674:
11675: =over 4
11676:
11677: sorted_reservable - ref to array of student_schedulable slots currently
11678: reservable, ordered by end date of reservation period.
11679:
11680: reservable_now - ref to hash of student_schedulable slots currently
11681: reservable.
11682:
11683: Keys in inner hash are:
11684: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11685: (b) endreserve: end date of reservation period.
11686: (c) uniqueperiod: start,end dates when slot is to be uniquely
11687: selected.
1.1040 raeburn 11688:
11689: sorted_future - ref to array of student_schedulable slots reservable in
11690: the future, ordered by start date of reservation period.
11691:
11692: future_reservable - ref to hash of student_schedulable slots reservable
11693: in the future.
11694:
11695: Keys in inner hash are:
11696: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11697: (b) startreserve: start date of reservation period.
11698: (c) uniqueperiod: start,end dates when slot is to be uniquely
11699: selected.
1.1040 raeburn 11700:
11701: =back
11702:
11703: =cut
11704:
11705: sub get_future_slots {
11706: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11707: my $map;
11708: if ($symb) {
11709: ($map) = &Apache::lonnet::decode_symb($symb);
11710: }
1.1040 raeburn 11711: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11712: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11713: foreach my $slot (keys(%slots)) {
11714: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11715: if ($symb) {
1.1229 raeburn 11716: if ($slots{$slot}->{'symb'} ne '') {
11717: my $canuse;
11718: my %oksymbs;
11719: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11720: map { $oksymbs{$_} = 1; } @slotsymbs;
11721: if ($oksymbs{$symb}) {
11722: $canuse = 1;
11723: } else {
11724: foreach my $item (@slotsymbs) {
11725: if ($item =~ /\.(page|sequence)$/) {
11726: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11727: if (($map ne '') && ($map eq $sloturl)) {
11728: $canuse = 1;
11729: last;
11730: }
11731: }
11732: }
11733: }
11734: next unless ($canuse);
11735: }
1.1040 raeburn 11736: }
11737: if (($slots{$slot}->{'starttime'} > $now) &&
11738: ($slots{$slot}->{'endtime'} > $now)) {
11739: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11740: my $userallowed = 0;
11741: if ($slots{$slot}->{'allowedsections'}) {
11742: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11743: if (!defined($env{'request.role.sec'})
11744: && grep(/^No section assigned$/,@allowed_sec)) {
11745: $userallowed=1;
11746: } else {
11747: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11748: $userallowed=1;
11749: }
11750: }
11751: unless ($userallowed) {
11752: if (defined($env{'request.course.groups'})) {
11753: my @groups = split(/:/,$env{'request.course.groups'});
11754: foreach my $group (@groups) {
11755: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11756: $userallowed=1;
11757: last;
11758: }
11759: }
11760: }
11761: }
11762: }
11763: if ($slots{$slot}->{'allowedusers'}) {
11764: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11765: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11766: if (grep(/^\Q$user\E$/,@allowed_users)) {
11767: $userallowed = 1;
11768: }
11769: }
11770: next unless($userallowed);
11771: }
11772: my $startreserve = $slots{$slot}->{'startreserve'};
11773: my $endreserve = $slots{$slot}->{'endreserve'};
11774: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11775: my $uniqueperiod;
11776: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11777: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11778: }
1.1040 raeburn 11779: if (($startreserve < $now) &&
11780: (!$endreserve || $endreserve > $now)) {
11781: my $lastres = $endreserve;
11782: if (!$lastres) {
11783: $lastres = $slots{$slot}->{'starttime'};
11784: }
11785: $reservable_now{$slot} = {
11786: symb => $symb,
1.1250 raeburn 11787: endreserve => $lastres,
11788: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11789: };
11790: } elsif (($startreserve > $now) &&
11791: (!$endreserve || $endreserve > $startreserve)) {
11792: $future_reservable{$slot} = {
11793: symb => $symb,
1.1250 raeburn 11794: startreserve => $startreserve,
11795: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11796: };
11797: }
11798: }
11799: }
11800: my @unsorted_reservable = keys(%reservable_now);
11801: if (@unsorted_reservable > 0) {
11802: @sorted_reservable =
11803: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11804: }
11805: my @unsorted_future = keys(%future_reservable);
11806: if (@unsorted_future > 0) {
11807: @sorted_future =
11808: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11809: }
11810: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11811: }
1.780 raeburn 11812:
11813: =pod
11814:
1.1057 foxr 11815: =back
11816:
1.549 albertel 11817: =head1 HTTP Helpers
11818:
11819: =over 4
11820:
1.648 raeburn 11821: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11822:
1.258 albertel 11823: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11824: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11825: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11826:
11827: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11828: $possible_names is an ref to an array of form element names. As an example:
11829: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11830: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11831:
11832: =cut
1.1 albertel 11833:
1.6 albertel 11834: sub get_unprocessed_cgi {
1.25 albertel 11835: my ($query,$possible_names)= @_;
1.26 matthew 11836: # $Apache::lonxml::debug=1;
1.356 albertel 11837: foreach my $pair (split(/&/,$query)) {
11838: my ($name, $value) = split(/=/,$pair);
1.369 www 11839: $name = &unescape($name);
1.25 albertel 11840: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11841: $value =~ tr/+/ /;
11842: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11843: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11844: }
1.16 harris41 11845: }
1.6 albertel 11846: }
11847:
1.112 bowersj2 11848: =pod
11849:
1.648 raeburn 11850: =item * &cacheheader()
1.112 bowersj2 11851:
11852: returns cache-controlling header code
11853:
11854: =cut
11855:
1.7 albertel 11856: sub cacheheader {
1.258 albertel 11857: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11858: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11859: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11860: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11861: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11862: return $output;
1.7 albertel 11863: }
11864:
1.112 bowersj2 11865: =pod
11866:
1.648 raeburn 11867: =item * &no_cache($r)
1.112 bowersj2 11868:
11869: specifies header code to not have cache
11870:
11871: =cut
11872:
1.9 albertel 11873: sub no_cache {
1.216 albertel 11874: my ($r) = @_;
11875: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11876: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11877: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11878: $r->no_cache(1);
11879: $r->header_out("Expires" => $date);
11880: $r->header_out("Pragma" => "no-cache");
1.123 www 11881: }
11882:
11883: sub content_type {
1.181 albertel 11884: my ($r,$type,$charset) = @_;
1.299 foxr 11885: if ($r) {
11886: # Note that printout.pl calls this with undef for $r.
11887: &no_cache($r);
11888: }
1.258 albertel 11889: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11890: unless ($charset) {
11891: $charset=&Apache::lonlocal::current_encoding;
11892: }
11893: if ($charset) { $type.='; charset='.$charset; }
11894: if ($r) {
11895: $r->content_type($type);
11896: } else {
11897: print("Content-type: $type\n\n");
11898: }
1.9 albertel 11899: }
1.25 albertel 11900:
1.112 bowersj2 11901: =pod
11902:
1.648 raeburn 11903: =item * &add_to_env($name,$value)
1.112 bowersj2 11904:
1.258 albertel 11905: adds $name to the %env hash with value
1.112 bowersj2 11906: $value, if $name already exists, the entry is converted to an array
11907: reference and $value is added to the array.
11908:
11909: =cut
11910:
1.25 albertel 11911: sub add_to_env {
11912: my ($name,$value)=@_;
1.258 albertel 11913: if (defined($env{$name})) {
11914: if (ref($env{$name})) {
1.25 albertel 11915: #already have multiple values
1.258 albertel 11916: push(@{ $env{$name} },$value);
1.25 albertel 11917: } else {
11918: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11919: my $first=$env{$name};
11920: undef($env{$name});
11921: push(@{ $env{$name} },$first,$value);
1.25 albertel 11922: }
11923: } else {
1.258 albertel 11924: $env{$name}=$value;
1.25 albertel 11925: }
1.31 albertel 11926: }
1.149 albertel 11927:
11928: =pod
11929:
1.648 raeburn 11930: =item * &get_env_multiple($name)
1.149 albertel 11931:
1.258 albertel 11932: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11933: values may be defined and end up as an array ref.
11934:
11935: returns an array of values
11936:
11937: =cut
11938:
11939: sub get_env_multiple {
11940: my ($name) = @_;
11941: my @values;
1.258 albertel 11942: if (defined($env{$name})) {
1.149 albertel 11943: # exists is it an array
1.258 albertel 11944: if (ref($env{$name})) {
11945: @values=@{ $env{$name} };
1.149 albertel 11946: } else {
1.258 albertel 11947: $values[0]=$env{$name};
1.149 albertel 11948: }
11949: }
11950: return(@values);
11951: }
11952:
1.1249 damieng 11953: # Looks at given dependencies, and returns something depending on the context.
11954: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11955: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11956: # For all other contexts, returns ($output, $counter, $numpathchg).
11957: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11958: # $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.
11959: # $numpathchg: integer with the number of cleaned up dependency paths.
11960: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11961: # \%mapping: hash reference clean path -> original path for all dependencies.
11962: # @param {string} actionurl - The path to the handler, indicative of the context.
11963: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11964: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11965: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11966: # @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)
11967: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11968: sub ask_for_embedded_content {
1.1249 damieng 11969: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11970: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11971: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11972: %currsubfile,%unused,$rem);
1.1071 raeburn 11973: my $counter = 0;
11974: my $numnew = 0;
1.987 raeburn 11975: my $numremref = 0;
11976: my $numinvalid = 0;
11977: my $numpathchg = 0;
11978: my $numexisting = 0;
1.1071 raeburn 11979: my $numunused = 0;
11980: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11981: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11982: my $heading = &mt('Upload embedded files');
11983: my $buttontext = &mt('Upload');
11984:
1.1249 damieng 11985: # fills these variables based on the context:
11986: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11987: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11988: if ($env{'request.course.id'}) {
1.1123 raeburn 11989: if ($actionurl eq '/adm/dependencies') {
11990: $navmap = Apache::lonnavmaps::navmap->new();
11991: }
11992: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11993: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11994: }
1.1123 raeburn 11995: if (($actionurl eq '/adm/portfolio') ||
11996: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11997: my $current_path='/';
11998: if ($env{'form.currentpath'}) {
11999: $current_path = $env{'form.currentpath'};
12000: }
12001: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12002: $udom = $cdom;
12003: $uname = $cnum;
1.984 raeburn 12004: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12005: } else {
12006: $udom = $env{'user.domain'};
12007: $uname = $env{'user.name'};
12008: $url = '/userfiles/portfolio';
12009: }
1.987 raeburn 12010: $toplevel = $url.'/';
1.984 raeburn 12011: $url .= $current_path;
12012: $getpropath = 1;
1.987 raeburn 12013: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12014: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12015: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12016: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12017: $toplevel = $url;
1.984 raeburn 12018: if ($rest ne '') {
1.987 raeburn 12019: $url .= $rest;
12020: }
12021: } elsif ($actionurl eq '/adm/coursedocs') {
12022: if (ref($args) eq 'HASH') {
1.1071 raeburn 12023: $url = $args->{'docs_url'};
12024: $toplevel = $url;
1.1084 raeburn 12025: if ($args->{'context'} eq 'paste') {
12026: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12027: ($path) =
12028: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12029: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12030: $fileloc =~ s{^/}{};
12031: }
1.1071 raeburn 12032: }
1.1084 raeburn 12033: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12034: if ($env{'request.course.id'} ne '') {
12035: if (ref($args) eq 'HASH') {
12036: $url = $args->{'docs_url'};
12037: $title = $args->{'docs_title'};
1.1126 raeburn 12038: $toplevel = $url;
12039: unless ($toplevel =~ m{^/}) {
12040: $toplevel = "/$url";
12041: }
1.1085 raeburn 12042: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12043: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12044: $path = $1;
12045: } else {
12046: ($path) =
12047: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12048: }
1.1195 raeburn 12049: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12050: $fileloc = $toplevel;
12051: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12052: my ($udom,$uname,$fname) =
12053: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12054: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12055: } else {
12056: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12057: }
1.1071 raeburn 12058: $fileloc =~ s{^/}{};
12059: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12060: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12061: }
1.987 raeburn 12062: }
1.1123 raeburn 12063: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12064: $udom = $cdom;
12065: $uname = $cnum;
12066: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12067: $toplevel = $url;
12068: $path = $url;
12069: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12070: $fileloc =~ s{^/}{};
1.987 raeburn 12071: }
1.1249 damieng 12072:
12073: # parses the dependency paths to get some info
12074: # fills $newfiles, $mapping, $subdependencies, $dependencies
12075: # $newfiles: hash URL -> 1 for new files or external URLs
12076: # (will be completed later)
12077: # $mapping:
12078: # for external URLs: external URL -> external URL
12079: # for relative paths: clean path -> original path
12080: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12081: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12082: foreach my $file (keys(%{$allfiles})) {
12083: my $embed_file;
12084: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12085: $embed_file = $1;
12086: } else {
12087: $embed_file = $file;
12088: }
1.1158 raeburn 12089: my ($absolutepath,$cleaned_file);
12090: if ($embed_file =~ m{^\w+://}) {
12091: $cleaned_file = $embed_file;
1.1147 raeburn 12092: $newfiles{$cleaned_file} = 1;
12093: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12094: } else {
1.1158 raeburn 12095: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12096: if ($embed_file =~ m{^/}) {
12097: $absolutepath = $embed_file;
12098: }
1.1147 raeburn 12099: if ($cleaned_file =~ m{/}) {
12100: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12101: $path = &check_for_traversal($path,$url,$toplevel);
12102: my $item = $fname;
12103: if ($path ne '') {
12104: $item = $path.'/'.$fname;
12105: $subdependencies{$path}{$fname} = 1;
12106: } else {
12107: $dependencies{$item} = 1;
12108: }
12109: if ($absolutepath) {
12110: $mapping{$item} = $absolutepath;
12111: } else {
12112: $mapping{$item} = $embed_file;
12113: }
12114: } else {
12115: $dependencies{$embed_file} = 1;
12116: if ($absolutepath) {
1.1147 raeburn 12117: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12118: } else {
1.1147 raeburn 12119: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12120: }
12121: }
1.984 raeburn 12122: }
12123: }
1.1249 damieng 12124:
12125: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12126: # and lists
12127: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12128: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12129: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12130: # the path had to be cleaned up
12131: # $existing: hash clean path -> 1 if the file exists
12132: # $numexisting: number of keys in $existing
12133: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12134: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12135: # dependency subdirectories that are
12136: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12137: my $dirptr = 16384;
1.984 raeburn 12138: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12139: $currsubfile{$path} = {};
1.1123 raeburn 12140: if (($actionurl eq '/adm/portfolio') ||
12141: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12142: my ($sublistref,$listerror) =
12143: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12144: if (ref($sublistref) eq 'ARRAY') {
12145: foreach my $line (@{$sublistref}) {
12146: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12147: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12148: }
1.984 raeburn 12149: }
1.987 raeburn 12150: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12151: if (opendir(my $dir,$url.'/'.$path)) {
12152: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12153: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12154: }
1.1084 raeburn 12155: } elsif (($actionurl eq '/adm/dependencies') ||
12156: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12157: ($args->{'context'} eq 'paste')) ||
12158: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12159: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12160: my $dir;
12161: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12162: $dir = $fileloc;
12163: } else {
12164: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12165: }
1.1071 raeburn 12166: if ($dir ne '') {
12167: my ($sublistref,$listerror) =
12168: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12169: if (ref($sublistref) eq 'ARRAY') {
12170: foreach my $line (@{$sublistref}) {
12171: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12172: undef,$mtime)=split(/\&/,$line,12);
12173: unless (($testdir&$dirptr) ||
12174: ($file_name =~ /^\.\.?$/)) {
12175: $currsubfile{$path}{$file_name} = [$size,$mtime];
12176: }
12177: }
12178: }
12179: }
1.984 raeburn 12180: }
12181: }
12182: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12183: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12184: my $item = $path.'/'.$file;
12185: unless ($mapping{$item} eq $item) {
12186: $pathchanges{$item} = 1;
12187: }
12188: $existing{$item} = 1;
12189: $numexisting ++;
12190: } else {
12191: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12192: }
12193: }
1.1071 raeburn 12194: if ($actionurl eq '/adm/dependencies') {
12195: foreach my $path (keys(%currsubfile)) {
12196: if (ref($currsubfile{$path}) eq 'HASH') {
12197: foreach my $file (keys(%{$currsubfile{$path}})) {
12198: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12199: next if (($rem ne '') &&
12200: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12201: (ref($navmap) &&
12202: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12203: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12204: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12205: $unused{$path.'/'.$file} = 1;
12206: }
12207: }
12208: }
12209: }
12210: }
1.984 raeburn 12211: }
1.1249 damieng 12212:
12213: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12214: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12215: my %currfile;
1.1123 raeburn 12216: if (($actionurl eq '/adm/portfolio') ||
12217: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12218: my ($dirlistref,$listerror) =
12219: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12220: if (ref($dirlistref) eq 'ARRAY') {
12221: foreach my $line (@{$dirlistref}) {
12222: my ($file_name,$rest) = split(/\&/,$line,2);
12223: $currfile{$file_name} = 1;
12224: }
1.984 raeburn 12225: }
1.987 raeburn 12226: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12227: if (opendir(my $dir,$url)) {
1.987 raeburn 12228: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12229: map {$currfile{$_} = 1;} @dir_list;
12230: }
1.1084 raeburn 12231: } elsif (($actionurl eq '/adm/dependencies') ||
12232: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12233: ($args->{'context'} eq 'paste')) ||
12234: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12235: if ($env{'request.course.id'} ne '') {
12236: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12237: if ($dir ne '') {
12238: my ($dirlistref,$listerror) =
12239: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12240: if (ref($dirlistref) eq 'ARRAY') {
12241: foreach my $line (@{$dirlistref}) {
12242: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12243: $size,undef,$mtime)=split(/\&/,$line,12);
12244: unless (($testdir&$dirptr) ||
12245: ($file_name =~ /^\.\.?$/)) {
12246: $currfile{$file_name} = [$size,$mtime];
12247: }
12248: }
12249: }
12250: }
12251: }
1.984 raeburn 12252: }
1.1249 damieng 12253: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12254: # are not in subdirectories, using $currfile
1.984 raeburn 12255: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12256: if (exists($currfile{$file})) {
1.987 raeburn 12257: unless ($mapping{$file} eq $file) {
12258: $pathchanges{$file} = 1;
12259: }
12260: $existing{$file} = 1;
12261: $numexisting ++;
12262: } else {
1.984 raeburn 12263: $newfiles{$file} = 1;
12264: }
12265: }
1.1071 raeburn 12266: foreach my $file (keys(%currfile)) {
12267: unless (($file eq $filename) ||
12268: ($file eq $filename.'.bak') ||
12269: ($dependencies{$file})) {
1.1085 raeburn 12270: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12271: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12272: next if (($rem ne '') &&
12273: (($env{"httpref.$rem".$file} ne '') ||
12274: (ref($navmap) &&
12275: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12276: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12277: ($navmap->getResourceByUrl($rem.$1)))))));
12278: }
1.1085 raeburn 12279: }
1.1071 raeburn 12280: $unused{$file} = 1;
12281: }
12282: }
1.1249 damieng 12283:
12284: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12285: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12286: ($args->{'context'} eq 'paste')) {
12287: $counter = scalar(keys(%existing));
12288: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12289: return ($output,$counter,$numpathchg,\%existing);
12290: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12291: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12292: $counter = scalar(keys(%existing));
12293: $numpathchg = scalar(keys(%pathchanges));
12294: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12295: }
1.1249 damieng 12296:
12297: # returns HTML otherwise, with dependency results and to ask for more uploads
12298:
12299: # $upload_output: missing dependencies (with upload form)
12300: # $modify_output: uploaded dependencies (in use)
12301: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12302: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12303: if ($actionurl eq '/adm/dependencies') {
12304: next if ($embed_file =~ m{^\w+://});
12305: }
1.660 raeburn 12306: $upload_output .= &start_data_table_row().
1.1123 raeburn 12307: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12308: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12309: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12310: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12311: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12312: }
1.1123 raeburn 12313: $upload_output .= '</td>';
1.1071 raeburn 12314: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12315: $upload_output.='<td align="right">'.
12316: '<span class="LC_info LC_fontsize_medium">'.
12317: &mt("URL points to web address").'</span>';
1.987 raeburn 12318: $numremref++;
1.660 raeburn 12319: } elsif ($args->{'error_on_invalid_names'}
12320: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12321: $upload_output.='<td align="right"><span class="LC_warning">'.
12322: &mt('Invalid characters').'</span>';
1.987 raeburn 12323: $numinvalid++;
1.660 raeburn 12324: } else {
1.1123 raeburn 12325: $upload_output .= '<td>'.
12326: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12327: $embed_file,\%mapping,
1.1071 raeburn 12328: $allfiles,$codebase,'upload');
12329: $counter ++;
12330: $numnew ++;
1.987 raeburn 12331: }
12332: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12333: }
12334: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12335: if ($actionurl eq '/adm/dependencies') {
12336: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12337: $modify_output .= &start_data_table_row().
12338: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12339: '<img src="'.&icon($embed_file).'" border="0" />'.
12340: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12341: '<td>'.$size.'</td>'.
12342: '<td>'.$mtime.'</td>'.
12343: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12344: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12345: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12346: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12347: &embedded_file_element('upload_embedded',$counter,
12348: $embed_file,\%mapping,
12349: $allfiles,$codebase,'modify').
12350: '</div></td>'.
12351: &end_data_table_row()."\n";
12352: $counter ++;
12353: } else {
12354: $upload_output .= &start_data_table_row().
1.1123 raeburn 12355: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12356: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12357: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12358: &Apache::loncommon::end_data_table_row()."\n";
12359: }
12360: }
12361: my $delidx = $counter;
12362: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12363: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12364: $delete_output .= &start_data_table_row().
12365: '<td><img src="'.&icon($oldfile).'" />'.
12366: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12367: '<td>'.$size.'</td>'.
12368: '<td>'.$mtime.'</td>'.
12369: '<td><label><input type="checkbox" name="del_upload_dep" '.
12370: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12371: &embedded_file_element('upload_embedded',$delidx,
12372: $oldfile,\%mapping,$allfiles,
12373: $codebase,'delete').'</td>'.
12374: &end_data_table_row()."\n";
12375: $numunused ++;
12376: $delidx ++;
1.987 raeburn 12377: }
12378: if ($upload_output) {
12379: $upload_output = &start_data_table().
12380: $upload_output.
12381: &end_data_table()."\n";
12382: }
1.1071 raeburn 12383: if ($modify_output) {
12384: $modify_output = &start_data_table().
12385: &start_data_table_header_row().
12386: '<th>'.&mt('File').'</th>'.
12387: '<th>'.&mt('Size (KB)').'</th>'.
12388: '<th>'.&mt('Modified').'</th>'.
12389: '<th>'.&mt('Upload replacement?').'</th>'.
12390: &end_data_table_header_row().
12391: $modify_output.
12392: &end_data_table()."\n";
12393: }
12394: if ($delete_output) {
12395: $delete_output = &start_data_table().
12396: &start_data_table_header_row().
12397: '<th>'.&mt('File').'</th>'.
12398: '<th>'.&mt('Size (KB)').'</th>'.
12399: '<th>'.&mt('Modified').'</th>'.
12400: '<th>'.&mt('Delete?').'</th>'.
12401: &end_data_table_header_row().
12402: $delete_output.
12403: &end_data_table()."\n";
12404: }
1.987 raeburn 12405: my $applies = 0;
12406: if ($numremref) {
12407: $applies ++;
12408: }
12409: if ($numinvalid) {
12410: $applies ++;
12411: }
12412: if ($numexisting) {
12413: $applies ++;
12414: }
1.1071 raeburn 12415: if ($counter || $numunused) {
1.987 raeburn 12416: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12417: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12418: $state.'<h3>'.$heading.'</h3>';
12419: if ($actionurl eq '/adm/dependencies') {
12420: if ($numnew) {
12421: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12422: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12423: $upload_output.'<br />'."\n";
12424: }
12425: if ($numexisting) {
12426: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12427: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12428: $modify_output.'<br />'."\n";
12429: $buttontext = &mt('Save changes');
12430: }
12431: if ($numunused) {
12432: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12433: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12434: $delete_output.'<br />'."\n";
12435: $buttontext = &mt('Save changes');
12436: }
12437: } else {
12438: $output .= $upload_output.'<br />'."\n";
12439: }
12440: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12441: $counter.'" />'."\n";
12442: if ($actionurl eq '/adm/dependencies') {
12443: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12444: $numnew.'" />'."\n";
12445: } elsif ($actionurl eq '') {
1.987 raeburn 12446: $output .= '<input type="hidden" name="phase" value="three" />';
12447: }
12448: } elsif ($applies) {
12449: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12450: if ($applies > 1) {
12451: $output .=
1.1123 raeburn 12452: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12453: if ($numremref) {
12454: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12455: }
12456: if ($numinvalid) {
12457: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12458: }
12459: if ($numexisting) {
12460: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12461: }
12462: $output .= '</ul><br />';
12463: } elsif ($numremref) {
12464: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12465: } elsif ($numinvalid) {
12466: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12467: } elsif ($numexisting) {
12468: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12469: }
12470: $output .= $upload_output.'<br />';
12471: }
12472: my ($pathchange_output,$chgcount);
1.1071 raeburn 12473: $chgcount = $counter;
1.987 raeburn 12474: if (keys(%pathchanges) > 0) {
12475: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12476: if ($counter) {
1.987 raeburn 12477: $output .= &embedded_file_element('pathchange',$chgcount,
12478: $embed_file,\%mapping,
1.1071 raeburn 12479: $allfiles,$codebase,'change');
1.987 raeburn 12480: } else {
12481: $pathchange_output .=
12482: &start_data_table_row().
12483: '<td><input type ="checkbox" name="namechange" value="'.
12484: $chgcount.'" checked="checked" /></td>'.
12485: '<td>'.$mapping{$embed_file}.'</td>'.
12486: '<td>'.$embed_file.
12487: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12488: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12489: '</td>'.&end_data_table_row();
1.660 raeburn 12490: }
1.987 raeburn 12491: $numpathchg ++;
12492: $chgcount ++;
1.660 raeburn 12493: }
12494: }
1.1127 raeburn 12495: if (($counter) || ($numunused)) {
1.987 raeburn 12496: if ($numpathchg) {
12497: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12498: $numpathchg.'" />'."\n";
12499: }
12500: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12501: ($actionurl eq '/adm/imsimport')) {
12502: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12503: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12504: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12505: } elsif ($actionurl eq '/adm/dependencies') {
12506: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12507: }
1.1123 raeburn 12508: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12509: } elsif ($numpathchg) {
12510: my %pathchange = ();
12511: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12512: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12513: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12514: }
1.987 raeburn 12515: }
1.1071 raeburn 12516: return ($output,$counter,$numpathchg);
1.987 raeburn 12517: }
12518:
1.1147 raeburn 12519: =pod
12520:
12521: =item * clean_path($name)
12522:
12523: Performs clean-up of directories, subdirectories and filename in an
12524: embedded object, referenced in an HTML file which is being uploaded
12525: to a course or portfolio, where
12526: "Upload embedded images/multimedia files if HTML file" checkbox was
12527: checked.
12528:
12529: Clean-up is similar to replacements in lonnet::clean_filename()
12530: except each / between sub-directory and next level is preserved.
12531:
12532: =cut
12533:
12534: sub clean_path {
12535: my ($embed_file) = @_;
12536: $embed_file =~s{^/+}{};
12537: my @contents;
12538: if ($embed_file =~ m{/}) {
12539: @contents = split(/\//,$embed_file);
12540: } else {
12541: @contents = ($embed_file);
12542: }
12543: my $lastidx = scalar(@contents)-1;
12544: for (my $i=0; $i<=$lastidx; $i++) {
12545: $contents[$i]=~s{\\}{/}g;
12546: $contents[$i]=~s/\s+/\_/g;
12547: $contents[$i]=~s{[^/\w\.\-]}{}g;
12548: if ($i == $lastidx) {
12549: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12550: }
12551: }
12552: if ($lastidx > 0) {
12553: return join('/',@contents);
12554: } else {
12555: return $contents[0];
12556: }
12557: }
12558:
1.987 raeburn 12559: sub embedded_file_element {
1.1071 raeburn 12560: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12561: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12562: (ref($codebase) eq 'HASH'));
12563: my $output;
1.1071 raeburn 12564: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12565: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12566: }
12567: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12568: &escape($embed_file).'" />';
12569: unless (($context eq 'upload_embedded') &&
12570: ($mapping->{$embed_file} eq $embed_file)) {
12571: $output .='
12572: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12573: }
12574: my $attrib;
12575: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12576: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12577: }
12578: $output .=
12579: "\n\t\t".
12580: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12581: $attrib.'" />';
12582: if (exists($codebase->{$mapping->{$embed_file}})) {
12583: $output .=
12584: "\n\t\t".
12585: '<input name="codebase_'.$num.'" type="hidden" value="'.
12586: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12587: }
1.987 raeburn 12588: return $output;
1.660 raeburn 12589: }
12590:
1.1071 raeburn 12591: sub get_dependency_details {
12592: my ($currfile,$currsubfile,$embed_file) = @_;
12593: my ($size,$mtime,$showsize,$showmtime);
12594: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12595: if ($embed_file =~ m{/}) {
12596: my ($path,$fname) = split(/\//,$embed_file);
12597: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12598: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12599: }
12600: } else {
12601: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12602: ($size,$mtime) = @{$currfile->{$embed_file}};
12603: }
12604: }
12605: $showsize = $size/1024.0;
12606: $showsize = sprintf("%.1f",$showsize);
12607: if ($mtime > 0) {
12608: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12609: }
12610: }
12611: return ($showsize,$showmtime);
12612: }
12613:
12614: sub ask_embedded_js {
12615: return <<"END";
12616: <script type="text/javascript"">
12617: // <![CDATA[
12618: function toggleBrowse(counter) {
12619: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12620: var fileid = document.getElementById('embedded_item_'+counter);
12621: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12622: if (chkboxid.checked == true) {
12623: uploaddivid.style.display='block';
12624: } else {
12625: uploaddivid.style.display='none';
12626: fileid.value = '';
12627: }
12628: }
12629: // ]]>
12630: </script>
12631:
12632: END
12633: }
12634:
1.661 raeburn 12635: sub upload_embedded {
12636: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12637: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12638: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12639: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12640: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12641: my $orig_uploaded_filename =
12642: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12643: foreach my $type ('orig','ref','attrib','codebase') {
12644: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12645: $env{'form.embedded_'.$type.'_'.$i} =
12646: &unescape($env{'form.embedded_'.$type.'_'.$i});
12647: }
12648: }
1.661 raeburn 12649: my ($path,$fname) =
12650: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12651: # no path, whole string is fname
12652: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12653: $fname = &Apache::lonnet::clean_filename($fname);
12654: # See if there is anything left
12655: next if ($fname eq '');
12656:
12657: # Check if file already exists as a file or directory.
12658: my ($state,$msg);
12659: if ($context eq 'portfolio') {
12660: my $port_path = $dirpath;
12661: if ($group ne '') {
12662: $port_path = "groups/$group/$port_path";
12663: }
1.987 raeburn 12664: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12665: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12666: $dir_root,$port_path,$disk_quota,
12667: $current_disk_usage,$uname,$udom);
12668: if ($state eq 'will_exceed_quota'
1.984 raeburn 12669: || $state eq 'file_locked') {
1.661 raeburn 12670: $output .= $msg;
12671: next;
12672: }
12673: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12674: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12675: if ($state eq 'exists') {
12676: $output .= $msg;
12677: next;
12678: }
12679: }
12680: # Check if extension is valid
12681: if (($fname =~ /\.(\w+)$/) &&
12682: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12683: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12684: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12685: next;
12686: } elsif (($fname =~ /\.(\w+)$/) &&
12687: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12688: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12689: next;
12690: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12691: $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 12692: next;
12693: }
12694: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12695: my $subdir = $path;
12696: $subdir =~ s{/+$}{};
1.661 raeburn 12697: if ($context eq 'portfolio') {
1.984 raeburn 12698: my $result;
12699: if ($state eq 'existingfile') {
12700: $result=
12701: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12702: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12703: } else {
1.984 raeburn 12704: $result=
12705: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12706: $dirpath.
1.1123 raeburn 12707: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12708: if ($result !~ m|^/uploaded/|) {
12709: $output .= '<span class="LC_error">'
12710: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12711: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12712: .'</span><br />';
12713: next;
12714: } else {
1.987 raeburn 12715: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12716: $path.$fname.'</span>').'<br />';
1.984 raeburn 12717: }
1.661 raeburn 12718: }
1.1123 raeburn 12719: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12720: my $extendedsubdir = $dirpath.'/'.$subdir;
12721: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12722: my $result =
1.1126 raeburn 12723: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12724: if ($result !~ m|^/uploaded/|) {
12725: $output .= '<span class="LC_error">'
12726: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12727: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12728: .'</span><br />';
12729: next;
12730: } else {
12731: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12732: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12733: if ($context eq 'syllabus') {
12734: &Apache::lonnet::make_public_indefinitely($result);
12735: }
1.987 raeburn 12736: }
1.661 raeburn 12737: } else {
12738: # Save the file
12739: my $target = $env{'form.embedded_item_'.$i};
12740: my $fullpath = $dir_root.$dirpath.'/'.$path;
12741: my $dest = $fullpath.$fname;
12742: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12743: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12744: my $count;
12745: my $filepath = $dir_root;
1.1027 raeburn 12746: foreach my $subdir (@parts) {
12747: $filepath .= "/$subdir";
12748: if (!-e $filepath) {
1.661 raeburn 12749: mkdir($filepath,0770);
12750: }
12751: }
12752: my $fh;
12753: if (!open($fh,'>'.$dest)) {
12754: &Apache::lonnet::logthis('Failed to create '.$dest);
12755: $output .= '<span class="LC_error">'.
1.1071 raeburn 12756: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12757: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12758: '</span><br />';
12759: } else {
12760: if (!print $fh $env{'form.embedded_item_'.$i}) {
12761: &Apache::lonnet::logthis('Failed to write to '.$dest);
12762: $output .= '<span class="LC_error">'.
1.1071 raeburn 12763: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12764: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12765: '</span><br />';
12766: } else {
1.987 raeburn 12767: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12768: $url.'</span>').'<br />';
12769: unless ($context eq 'testbank') {
12770: $footer .= &mt('View embedded file: [_1]',
12771: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12772: }
12773: }
12774: close($fh);
12775: }
12776: }
12777: if ($env{'form.embedded_ref_'.$i}) {
12778: $pathchange{$i} = 1;
12779: }
12780: }
12781: if ($output) {
12782: $output = '<p>'.$output.'</p>';
12783: }
12784: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12785: $returnflag = 'ok';
1.1071 raeburn 12786: my $numpathchgs = scalar(keys(%pathchange));
12787: if ($numpathchgs > 0) {
1.987 raeburn 12788: if ($context eq 'portfolio') {
12789: $output .= '<p>'.&mt('or').'</p>';
12790: } elsif ($context eq 'testbank') {
1.1071 raeburn 12791: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12792: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12793: $returnflag = 'modify_orightml';
12794: }
12795: }
1.1071 raeburn 12796: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12797: }
12798:
12799: sub modify_html_form {
12800: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12801: my $end = 0;
12802: my $modifyform;
12803: if ($context eq 'upload_embedded') {
12804: return unless (ref($pathchange) eq 'HASH');
12805: if ($env{'form.number_embedded_items'}) {
12806: $end += $env{'form.number_embedded_items'};
12807: }
12808: if ($env{'form.number_pathchange_items'}) {
12809: $end += $env{'form.number_pathchange_items'};
12810: }
12811: if ($end) {
12812: for (my $i=0; $i<$end; $i++) {
12813: if ($i < $env{'form.number_embedded_items'}) {
12814: next unless($pathchange->{$i});
12815: }
12816: $modifyform .=
12817: &start_data_table_row().
12818: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12819: 'checked="checked" /></td>'.
12820: '<td>'.$env{'form.embedded_ref_'.$i}.
12821: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12822: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12823: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12824: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12825: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12826: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12827: '<td>'.$env{'form.embedded_orig_'.$i}.
12828: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12829: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12830: &end_data_table_row();
1.1071 raeburn 12831: }
1.987 raeburn 12832: }
12833: } else {
12834: $modifyform = $pathchgtable;
12835: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12836: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12837: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12838: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12839: }
12840: }
12841: if ($modifyform) {
1.1071 raeburn 12842: if ($actionurl eq '/adm/dependencies') {
12843: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12844: }
1.987 raeburn 12845: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12846: '<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".
12847: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12848: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12849: '</ol></p>'."\n".'<p>'.
12850: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12851: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12852: &start_data_table()."\n".
12853: &start_data_table_header_row().
12854: '<th>'.&mt('Change?').'</th>'.
12855: '<th>'.&mt('Current reference').'</th>'.
12856: '<th>'.&mt('Required reference').'</th>'.
12857: &end_data_table_header_row()."\n".
12858: $modifyform.
12859: &end_data_table().'<br />'."\n".$hiddenstate.
12860: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12861: '</form>'."\n";
12862: }
12863: return;
12864: }
12865:
12866: sub modify_html_refs {
1.1123 raeburn 12867: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12868: my $container;
12869: if ($context eq 'portfolio') {
12870: $container = $env{'form.container'};
12871: } elsif ($context eq 'coursedoc') {
12872: $container = $env{'form.primaryurl'};
1.1071 raeburn 12873: } elsif ($context eq 'manage_dependencies') {
12874: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12875: $container = "/$container";
1.1123 raeburn 12876: } elsif ($context eq 'syllabus') {
12877: $container = $url;
1.987 raeburn 12878: } else {
1.1027 raeburn 12879: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12880: }
12881: my (%allfiles,%codebase,$output,$content);
12882: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12883: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12884: if (wantarray) {
12885: return ('',0,0);
12886: } else {
12887: return;
12888: }
12889: }
12890: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12891: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12892: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12893: if (wantarray) {
12894: return ('',0,0);
12895: } else {
12896: return;
12897: }
12898: }
1.987 raeburn 12899: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12900: if ($content eq '-1') {
12901: if (wantarray) {
12902: return ('',0,0);
12903: } else {
12904: return;
12905: }
12906: }
1.987 raeburn 12907: } else {
1.1071 raeburn 12908: unless ($container =~ /^\Q$dir_root\E/) {
12909: if (wantarray) {
12910: return ('',0,0);
12911: } else {
12912: return;
12913: }
12914: }
1.1317 raeburn 12915: if (open(my $fh,'<',$container)) {
1.987 raeburn 12916: $content = join('', <$fh>);
12917: close($fh);
12918: } else {
1.1071 raeburn 12919: if (wantarray) {
12920: return ('',0,0);
12921: } else {
12922: return;
12923: }
1.987 raeburn 12924: }
12925: }
12926: my ($count,$codebasecount) = (0,0);
12927: my $mm = new File::MMagic;
12928: my $mime_type = $mm->checktype_contents($content);
12929: if ($mime_type eq 'text/html') {
12930: my $parse_result =
12931: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12932: \%codebase,\$content);
12933: if ($parse_result eq 'ok') {
12934: foreach my $i (@changes) {
12935: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12936: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12937: if ($allfiles{$ref}) {
12938: my $newname = $orig;
12939: my ($attrib_regexp,$codebase);
1.1006 raeburn 12940: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12941: if ($attrib_regexp =~ /:/) {
12942: $attrib_regexp =~ s/\:/|/g;
12943: }
12944: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12945: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12946: $count += $numchg;
1.1123 raeburn 12947: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12948: delete($allfiles{$ref});
1.987 raeburn 12949: }
12950: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12951: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12952: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12953: $codebasecount ++;
12954: }
12955: }
12956: }
1.1123 raeburn 12957: my $skiprewrites;
1.987 raeburn 12958: if ($count || $codebasecount) {
12959: my $saveresult;
1.1071 raeburn 12960: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12961: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12962: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12963: if ($url eq $container) {
12964: my ($fname) = ($container =~ m{/([^/]+)$});
12965: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12966: $count,'<span class="LC_filename">'.
1.1071 raeburn 12967: $fname.'</span>').'</p>';
1.987 raeburn 12968: } else {
12969: $output = '<p class="LC_error">'.
12970: &mt('Error: update failed for: [_1].',
12971: '<span class="LC_filename">'.
12972: $container.'</span>').'</p>';
12973: }
1.1123 raeburn 12974: if ($context eq 'syllabus') {
12975: unless ($saveresult eq 'ok') {
12976: $skiprewrites = 1;
12977: }
12978: }
1.987 raeburn 12979: } else {
1.1317 raeburn 12980: if (open(my $fh,'>',$container)) {
1.987 raeburn 12981: print $fh $content;
12982: close($fh);
12983: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12984: $count,'<span class="LC_filename">'.
12985: $container.'</span>').'</p>';
1.661 raeburn 12986: } else {
1.987 raeburn 12987: $output = '<p class="LC_error">'.
12988: &mt('Error: could not update [_1].',
12989: '<span class="LC_filename">'.
12990: $container.'</span>').'</p>';
1.661 raeburn 12991: }
12992: }
12993: }
1.1123 raeburn 12994: if (($context eq 'syllabus') && (!$skiprewrites)) {
12995: my ($actionurl,$state);
12996: $actionurl = "/public/$udom/$uname/syllabus";
12997: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12998: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12999: \%codebase,
13000: {'context' => 'rewrites',
13001: 'ignore_remote_references' => 1,});
13002: if (ref($mapping) eq 'HASH') {
13003: my $rewrites = 0;
13004: foreach my $key (keys(%{$mapping})) {
13005: next if ($key =~ m{^https?://});
13006: my $ref = $mapping->{$key};
13007: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13008: my $attrib;
13009: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13010: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13011: }
13012: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13013: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13014: $rewrites += $numchg;
13015: }
13016: }
13017: if ($rewrites) {
13018: my $saveresult;
13019: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13020: if ($url eq $container) {
13021: my ($fname) = ($container =~ m{/([^/]+)$});
13022: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13023: $count,'<span class="LC_filename">'.
13024: $fname.'</span>').'</p>';
13025: } else {
13026: $output .= '<p class="LC_error">'.
13027: &mt('Error: could not update links in [_1].',
13028: '<span class="LC_filename">'.
13029: $container.'</span>').'</p>';
13030:
13031: }
13032: }
13033: }
13034: }
1.987 raeburn 13035: } else {
13036: &logthis('Failed to parse '.$container.
13037: ' to modify references: '.$parse_result);
1.661 raeburn 13038: }
13039: }
1.1071 raeburn 13040: if (wantarray) {
13041: return ($output,$count,$codebasecount);
13042: } else {
13043: return $output;
13044: }
1.661 raeburn 13045: }
13046:
13047: sub check_for_existing {
13048: my ($path,$fname,$element) = @_;
13049: my ($state,$msg);
13050: if (-d $path.'/'.$fname) {
13051: $state = 'exists';
13052: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13053: } elsif (-e $path.'/'.$fname) {
13054: $state = 'exists';
13055: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13056: }
13057: if ($state eq 'exists') {
13058: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13059: }
13060: return ($state,$msg);
13061: }
13062:
13063: sub check_for_upload {
13064: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13065: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13066: my $filesize = length($env{'form.'.$element});
13067: if (!$filesize) {
13068: my $msg = '<span class="LC_error">'.
13069: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13070: '<span class="LC_filename">'.$fname.'</span>',
13071: $filesize).'<br />'.
1.1007 raeburn 13072: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13073: '</span>';
13074: return ('zero_bytes',$msg);
13075: }
13076: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13077: my $getpropath = 1;
1.1021 raeburn 13078: my ($dirlistref,$listerror) =
13079: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13080: my $found_file = 0;
13081: my $locked_file = 0;
1.991 raeburn 13082: my @lockers;
13083: my $navmap;
13084: if ($env{'request.course.id'}) {
13085: $navmap = Apache::lonnavmaps::navmap->new();
13086: }
1.1021 raeburn 13087: if (ref($dirlistref) eq 'ARRAY') {
13088: foreach my $line (@{$dirlistref}) {
13089: my ($file_name,$rest)=split(/\&/,$line,2);
13090: if ($file_name eq $fname){
13091: $file_name = $path.$file_name;
13092: if ($group ne '') {
13093: $file_name = $group.$file_name;
13094: }
13095: $found_file = 1;
13096: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13097: foreach my $lock (@lockers) {
13098: if (ref($lock) eq 'ARRAY') {
13099: my ($symb,$crsid) = @{$lock};
13100: if ($crsid eq $env{'request.course.id'}) {
13101: if (ref($navmap)) {
13102: my $res = $navmap->getBySymb($symb);
13103: foreach my $part (@{$res->parts()}) {
13104: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13105: unless (($slot_status == $res->RESERVED) ||
13106: ($slot_status == $res->RESERVED_LOCATION)) {
13107: $locked_file = 1;
13108: }
1.991 raeburn 13109: }
1.1021 raeburn 13110: } else {
13111: $locked_file = 1;
1.991 raeburn 13112: }
13113: } else {
13114: $locked_file = 1;
13115: }
13116: }
1.1021 raeburn 13117: }
13118: } else {
13119: my @info = split(/\&/,$rest);
13120: my $currsize = $info[6]/1000;
13121: if ($currsize < $filesize) {
13122: my $extra = $filesize - $currsize;
13123: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13124: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13125: &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 13126: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13127: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13128: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13129: return ('will_exceed_quota',$msg);
13130: }
1.984 raeburn 13131: }
13132: }
1.661 raeburn 13133: }
13134: }
13135: }
13136: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13137: my $msg = '<p class="LC_warning">'.
13138: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13139: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13140: return ('will_exceed_quota',$msg);
13141: } elsif ($found_file) {
13142: if ($locked_file) {
1.1179 bisitz 13143: my $msg = '<p class="LC_warning">';
1.661 raeburn 13144: $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 13145: $msg .= '</p>';
1.661 raeburn 13146: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13147: return ('file_locked',$msg);
13148: } else {
1.1179 bisitz 13149: my $msg = '<p class="LC_error">';
1.984 raeburn 13150: $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 13151: $msg .= '</p>';
1.984 raeburn 13152: return ('existingfile',$msg);
1.661 raeburn 13153: }
13154: }
13155: }
13156:
1.987 raeburn 13157: sub check_for_traversal {
13158: my ($path,$url,$toplevel) = @_;
13159: my @parts=split(/\//,$path);
13160: my $cleanpath;
13161: my $fullpath = $url;
13162: for (my $i=0;$i<@parts;$i++) {
13163: next if ($parts[$i] eq '.');
13164: if ($parts[$i] eq '..') {
13165: $fullpath =~ s{([^/]+/)$}{};
13166: } else {
13167: $fullpath .= $parts[$i].'/';
13168: }
13169: }
13170: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13171: $cleanpath = $1;
13172: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13173: my $curr_toprel = $1;
13174: my @parts = split(/\//,$curr_toprel);
13175: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13176: my @urlparts = split(/\//,$url_toprel);
13177: my $doubledots;
13178: my $startdiff = -1;
13179: for (my $i=0; $i<@urlparts; $i++) {
13180: if ($startdiff == -1) {
13181: unless ($urlparts[$i] eq $parts[$i]) {
13182: $startdiff = $i;
13183: $doubledots .= '../';
13184: }
13185: } else {
13186: $doubledots .= '../';
13187: }
13188: }
13189: if ($startdiff > -1) {
13190: $cleanpath = $doubledots;
13191: for (my $i=$startdiff; $i<@parts; $i++) {
13192: $cleanpath .= $parts[$i].'/';
13193: }
13194: }
13195: }
13196: $cleanpath =~ s{(/)$}{};
13197: return $cleanpath;
13198: }
1.31 albertel 13199:
1.1053 raeburn 13200: sub is_archive_file {
13201: my ($mimetype) = @_;
13202: if (($mimetype eq 'application/octet-stream') ||
13203: ($mimetype eq 'application/x-stuffit') ||
13204: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13205: return 1;
13206: }
13207: return;
13208: }
13209:
13210: sub decompress_form {
1.1065 raeburn 13211: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13212: my %lt = &Apache::lonlocal::texthash (
13213: this => 'This file is an archive file.',
1.1067 raeburn 13214: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13215: itsc => 'Its contents are as follows:',
1.1053 raeburn 13216: youm => 'You may wish to extract its contents.',
13217: extr => 'Extract contents',
1.1067 raeburn 13218: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13219: proa => 'Process automatically?',
1.1053 raeburn 13220: yes => 'Yes',
13221: no => 'No',
1.1067 raeburn 13222: fold => 'Title for folder containing movie',
13223: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13224: );
1.1065 raeburn 13225: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13226: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13227: my $info = &list_archive_contents($fileloc,\@paths);
13228: if (@paths) {
13229: foreach my $path (@paths) {
13230: $path =~ s{^/}{};
1.1067 raeburn 13231: if ($path =~ m{^([^/]+)/$}) {
13232: $topdir = $1;
13233: }
1.1065 raeburn 13234: if ($path =~ m{^([^/]+)/}) {
13235: $toplevel{$1} = $path;
13236: } else {
13237: $toplevel{$path} = $path;
13238: }
13239: }
13240: }
1.1067 raeburn 13241: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13242: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13243: "$topdir/media/",
13244: "$topdir/media/$topdir.mp4",
13245: "$topdir/media/FirstFrame.png",
13246: "$topdir/media/player.swf",
13247: "$topdir/media/swfobject.js",
13248: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13249: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13250: "$topdir/$topdir.mp4",
13251: "$topdir/$topdir\_config.xml",
13252: "$topdir/$topdir\_controller.swf",
13253: "$topdir/$topdir\_embed.css",
13254: "$topdir/$topdir\_First_Frame.png",
13255: "$topdir/$topdir\_player.html",
13256: "$topdir/$topdir\_Thumbnails.png",
13257: "$topdir/playerProductInstall.swf",
13258: "$topdir/scripts/",
13259: "$topdir/scripts/config_xml.js",
13260: "$topdir/scripts/handlebars.js",
13261: "$topdir/scripts/jquery-1.7.1.min.js",
13262: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13263: "$topdir/scripts/modernizr.js",
13264: "$topdir/scripts/player-min.js",
13265: "$topdir/scripts/swfobject.js",
13266: "$topdir/skins/",
13267: "$topdir/skins/configuration_express.xml",
13268: "$topdir/skins/express_show/",
13269: "$topdir/skins/express_show/player-min.css",
13270: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13271: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13272: "$topdir/$topdir.mp4",
13273: "$topdir/$topdir\_config.xml",
13274: "$topdir/$topdir\_controller.swf",
13275: "$topdir/$topdir\_embed.css",
13276: "$topdir/$topdir\_First_Frame.png",
13277: "$topdir/$topdir\_player.html",
13278: "$topdir/$topdir\_Thumbnails.png",
13279: "$topdir/playerProductInstall.swf",
13280: "$topdir/scripts/",
13281: "$topdir/scripts/config_xml.js",
13282: "$topdir/scripts/techsmith-smart-player.min.js",
13283: "$topdir/skins/",
13284: "$topdir/skins/configuration_express.xml",
13285: "$topdir/skins/express_show/",
13286: "$topdir/skins/express_show/spritesheet.min.css",
13287: "$topdir/skins/express_show/spritesheet.png",
13288: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13289: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13290: if (@diffs == 0) {
1.1164 raeburn 13291: $is_camtasia = 6;
13292: } else {
1.1197 raeburn 13293: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13294: if (@diffs == 0) {
13295: $is_camtasia = 8;
1.1197 raeburn 13296: } else {
13297: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13298: if (@diffs == 0) {
13299: $is_camtasia = 8;
13300: }
1.1164 raeburn 13301: }
1.1067 raeburn 13302: }
13303: }
13304: my $output;
13305: if ($is_camtasia) {
13306: $output = <<"ENDCAM";
13307: <script type="text/javascript" language="Javascript">
13308: // <![CDATA[
13309:
13310: function camtasiaToggle() {
13311: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13312: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13313: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13314: document.getElementById('camtasia_titles').style.display='block';
13315: } else {
13316: document.getElementById('camtasia_titles').style.display='none';
13317: }
13318: }
13319: }
13320: return;
13321: }
13322:
13323: // ]]>
13324: </script>
13325: <p>$lt{'camt'}</p>
13326: ENDCAM
1.1065 raeburn 13327: } else {
1.1067 raeburn 13328: $output = '<p>'.$lt{'this'};
13329: if ($info eq '') {
13330: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13331: } else {
13332: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13333: '<div><pre>'.$info.'</pre></div>';
13334: }
1.1065 raeburn 13335: }
1.1067 raeburn 13336: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13337: my $duplicates;
13338: my $num = 0;
13339: if (ref($dirlist) eq 'ARRAY') {
13340: foreach my $item (@{$dirlist}) {
13341: if (ref($item) eq 'ARRAY') {
13342: if (exists($toplevel{$item->[0]})) {
13343: $duplicates .=
13344: &start_data_table_row().
13345: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13346: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13347: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13348: 'value="1" />'.&mt('Yes').'</label>'.
13349: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13350: '<td>'.$item->[0].'</td>';
13351: if ($item->[2]) {
13352: $duplicates .= '<td>'.&mt('Directory').'</td>';
13353: } else {
13354: $duplicates .= '<td>'.&mt('File').'</td>';
13355: }
13356: $duplicates .= '<td>'.$item->[3].'</td>'.
13357: '<td>'.
13358: &Apache::lonlocal::locallocaltime($item->[4]).
13359: '</td>'.
13360: &end_data_table_row();
13361: $num ++;
13362: }
13363: }
13364: }
13365: }
13366: my $itemcount;
13367: if (@paths > 0) {
13368: $itemcount = scalar(@paths);
13369: } else {
13370: $itemcount = 1;
13371: }
1.1067 raeburn 13372: if ($is_camtasia) {
13373: $output .= $lt{'auto'}.'<br />'.
13374: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13375: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13376: $lt{'yes'}.'</label> <label>'.
13377: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13378: $lt{'no'}.'</label></span><br />'.
13379: '<div id="camtasia_titles" style="display:block">'.
13380: &Apache::lonhtmlcommon::start_pick_box().
13381: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13382: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13383: &Apache::lonhtmlcommon::row_closure().
13384: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13385: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13386: &Apache::lonhtmlcommon::row_closure(1).
13387: &Apache::lonhtmlcommon::end_pick_box().
13388: '</div>';
13389: }
1.1065 raeburn 13390: $output .=
13391: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13392: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13393: "\n";
1.1065 raeburn 13394: if ($duplicates ne '') {
13395: $output .= '<p><span class="LC_warning">'.
13396: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13397: &start_data_table().
13398: &start_data_table_header_row().
13399: '<th>'.&mt('Overwrite?').'</th>'.
13400: '<th>'.&mt('Name').'</th>'.
13401: '<th>'.&mt('Type').'</th>'.
13402: '<th>'.&mt('Size').'</th>'.
13403: '<th>'.&mt('Last modified').'</th>'.
13404: &end_data_table_header_row().
13405: $duplicates.
13406: &end_data_table().
13407: '</p>';
13408: }
1.1067 raeburn 13409: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13410: if (ref($hiddenelements) eq 'HASH') {
13411: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13412: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13413: }
13414: }
13415: $output .= <<"END";
1.1067 raeburn 13416: <br />
1.1053 raeburn 13417: <input type="submit" name="decompress" value="$lt{'extr'}" />
13418: </form>
13419: $noextract
13420: END
13421: return $output;
13422: }
13423:
1.1065 raeburn 13424: sub decompression_utility {
13425: my ($program) = @_;
13426: my @utilities = ('tar','gunzip','bunzip2','unzip');
13427: my $location;
13428: if (grep(/^\Q$program\E$/,@utilities)) {
13429: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13430: '/usr/sbin/') {
13431: if (-x $dir.$program) {
13432: $location = $dir.$program;
13433: last;
13434: }
13435: }
13436: }
13437: return $location;
13438: }
13439:
13440: sub list_archive_contents {
13441: my ($file,$pathsref) = @_;
13442: my (@cmd,$output);
13443: my $needsregexp;
13444: if ($file =~ /\.zip$/) {
13445: @cmd = (&decompression_utility('unzip'),"-l");
13446: $needsregexp = 1;
13447: } elsif (($file =~ m/\.tar\.gz$/) ||
13448: ($file =~ /\.tgz$/)) {
13449: @cmd = (&decompression_utility('tar'),"-ztf");
13450: } elsif ($file =~ /\.tar\.bz2$/) {
13451: @cmd = (&decompression_utility('tar'),"-jtf");
13452: } elsif ($file =~ m|\.tar$|) {
13453: @cmd = (&decompression_utility('tar'),"-tf");
13454: }
13455: if (@cmd) {
13456: undef($!);
13457: undef($@);
13458: if (open(my $fh,"-|", @cmd, $file)) {
13459: while (my $line = <$fh>) {
13460: $output .= $line;
13461: chomp($line);
13462: my $item;
13463: if ($needsregexp) {
13464: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13465: } else {
13466: $item = $line;
13467: }
13468: if ($item ne '') {
13469: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13470: push(@{$pathsref},$item);
13471: }
13472: }
13473: }
13474: close($fh);
13475: }
13476: }
13477: return $output;
13478: }
13479:
1.1053 raeburn 13480: sub decompress_uploaded_file {
13481: my ($file,$dir) = @_;
13482: &Apache::lonnet::appenv({'cgi.file' => $file});
13483: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13484: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13485: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13486: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13487: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13488: my $decompressed = $env{'cgi.decompressed'};
13489: &Apache::lonnet::delenv('cgi.file');
13490: &Apache::lonnet::delenv('cgi.dir');
13491: &Apache::lonnet::delenv('cgi.decompressed');
13492: return ($decompressed,$result);
13493: }
13494:
1.1055 raeburn 13495: sub process_decompression {
13496: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13497: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13498: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13499: &mt('Unexpected file path.').'</p>'."\n";
13500: }
13501: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13502: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13503: &mt('Unexpected course context.').'</p>'."\n";
13504: }
1.1293 raeburn 13505: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13506: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13507: &mt('Filename contained unexpected characters.').'</p>'."\n";
13508: }
1.1055 raeburn 13509: my ($dir,$error,$warning,$output);
1.1180 raeburn 13510: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13511: $error = &mt('Filename not a supported archive file type.').
13512: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13513: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13514: } else {
13515: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13516: if ($docuhome eq 'no_host') {
13517: $error = &mt('Could not determine home server for course.');
13518: } else {
13519: my @ids=&Apache::lonnet::current_machine_ids();
13520: my $currdir = "$dir_root/$destination";
13521: if (grep(/^\Q$docuhome\E$/,@ids)) {
13522: $dir = &LONCAPA::propath($docudom,$docuname).
13523: "$dir_root/$destination";
13524: } else {
13525: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13526: "$dir_root/$docudom/$docuname/$destination";
13527: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13528: $error = &mt('Archive file not found.');
13529: }
13530: }
1.1065 raeburn 13531: my (@to_overwrite,@to_skip);
13532: if ($env{'form.archive_overwrite_total'} > 0) {
13533: my $total = $env{'form.archive_overwrite_total'};
13534: for (my $i=0; $i<$total; $i++) {
13535: if ($env{'form.archive_overwrite_'.$i} == 1) {
13536: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13537: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13538: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13539: }
13540: }
13541: }
13542: my $numskip = scalar(@to_skip);
1.1292 raeburn 13543: my $numoverwrite = scalar(@to_overwrite);
13544: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13545: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13546: } elsif ($dir eq '') {
1.1055 raeburn 13547: $error = &mt('Directory containing archive file unavailable.');
13548: } elsif (!$error) {
1.1065 raeburn 13549: my ($decompressed,$display);
1.1292 raeburn 13550: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13551: my $tempdir = time.'_'.$$.int(rand(10000));
13552: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13553: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13554: ($decompressed,$display) =
13555: &decompress_uploaded_file($file,"$dir/$tempdir");
13556: foreach my $item (@to_skip) {
13557: if (($item ne '') && ($item !~ /\.\./)) {
13558: if (-f "$dir/$tempdir/$item") {
13559: unlink("$dir/$tempdir/$item");
13560: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13561: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13562: }
13563: }
13564: }
13565: foreach my $item (@to_overwrite) {
13566: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13567: if (($item ne '') && ($item !~ /\.\./)) {
13568: if (-f "$dir/$item") {
13569: unlink("$dir/$item");
13570: } elsif (-d "$dir/$item") {
1.1300 raeburn 13571: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13572: }
13573: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13574: }
1.1065 raeburn 13575: }
13576: }
1.1292 raeburn 13577: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13578: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13579: }
1.1065 raeburn 13580: }
13581: } else {
13582: ($decompressed,$display) =
13583: &decompress_uploaded_file($file,$dir);
13584: }
1.1055 raeburn 13585: if ($decompressed eq 'ok') {
1.1065 raeburn 13586: $output = '<p class="LC_info">'.
13587: &mt('Files extracted successfully from archive.').
13588: '</p>'."\n";
1.1055 raeburn 13589: my ($warning,$result,@contents);
13590: my ($newdirlistref,$newlisterror) =
13591: &Apache::lonnet::dirlist($currdir,$docudom,
13592: $docuname,1);
13593: my (%is_dir,%changes,@newitems);
13594: my $dirptr = 16384;
1.1065 raeburn 13595: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13596: foreach my $dir_line (@{$newdirlistref}) {
13597: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13598: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13599: push(@newitems,$item);
13600: if ($dirptr&$testdir) {
13601: $is_dir{$item} = 1;
13602: }
13603: $changes{$item} = 1;
13604: }
13605: }
13606: }
13607: if (keys(%changes) > 0) {
13608: foreach my $item (sort(@newitems)) {
13609: if ($changes{$item}) {
13610: push(@contents,$item);
13611: }
13612: }
13613: }
13614: if (@contents > 0) {
1.1067 raeburn 13615: my $wantform;
13616: unless ($env{'form.autoextract_camtasia'}) {
13617: $wantform = 1;
13618: }
1.1056 raeburn 13619: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13620: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13621: $currdir,\%is_dir,
13622: \%children,\%parent,
1.1056 raeburn 13623: \@contents,\%dirorder,
13624: \%titles,$wantform);
1.1055 raeburn 13625: if ($datatable ne '') {
13626: $output .= &archive_options_form('decompressed',$datatable,
13627: $count,$hiddenelem);
1.1065 raeburn 13628: my $startcount = 6;
1.1055 raeburn 13629: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13630: \%titles,\%children);
1.1055 raeburn 13631: }
1.1067 raeburn 13632: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13633: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13634: my %displayed;
13635: my $total = 1;
13636: $env{'form.archive_directory'} = [];
13637: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13638: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13639: $path =~ s{/$}{};
13640: my $item;
13641: if ($path ne '') {
13642: $item = "$path/$titles{$i}";
13643: } else {
13644: $item = $titles{$i};
13645: }
13646: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13647: if ($item eq $contents[0]) {
13648: push(@{$env{'form.archive_directory'}},$i);
13649: $env{'form.archive_'.$i} = 'display';
13650: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13651: $displayed{'folder'} = $i;
1.1164 raeburn 13652: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13653: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13654: $env{'form.archive_'.$i} = 'display';
13655: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13656: $displayed{'web'} = $i;
13657: } else {
1.1164 raeburn 13658: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13659: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13660: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13661: push(@{$env{'form.archive_directory'}},$i);
13662: }
13663: $env{'form.archive_'.$i} = 'dependency';
13664: }
13665: $total ++;
13666: }
13667: for (my $i=1; $i<$total; $i++) {
13668: next if ($i == $displayed{'web'});
13669: next if ($i == $displayed{'folder'});
13670: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13671: }
13672: $env{'form.phase'} = 'decompress_cleanup';
13673: $env{'form.archivedelete'} = 1;
13674: $env{'form.archive_count'} = $total-1;
13675: $output .=
13676: &process_extracted_files('coursedocs',$docudom,
13677: $docuname,$destination,
13678: $dir_root,$hiddenelem);
13679: }
1.1055 raeburn 13680: } else {
13681: $warning = &mt('No new items extracted from archive file.');
13682: }
13683: } else {
13684: $output = $display;
13685: $error = &mt('An error occurred during extraction from the archive file.');
13686: }
13687: }
13688: }
13689: }
13690: if ($error) {
13691: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13692: $error.'</p>'."\n";
13693: }
13694: if ($warning) {
13695: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13696: }
13697: return $output;
13698: }
13699:
13700: sub get_extracted {
1.1056 raeburn 13701: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13702: $titles,$wantform) = @_;
1.1055 raeburn 13703: my $count = 0;
13704: my $depth = 0;
13705: my $datatable;
1.1056 raeburn 13706: my @hierarchy;
1.1055 raeburn 13707: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13708: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13709: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13710: foreach my $item (@{$contents}) {
13711: $count ++;
1.1056 raeburn 13712: @{$dirorder->{$count}} = @hierarchy;
13713: $titles->{$count} = $item;
1.1055 raeburn 13714: &archive_hierarchy($depth,$count,$parent,$children);
13715: if ($wantform) {
13716: $datatable .= &archive_row($is_dir->{$item},$item,
13717: $currdir,$depth,$count);
13718: }
13719: if ($is_dir->{$item}) {
13720: $depth ++;
1.1056 raeburn 13721: push(@hierarchy,$count);
13722: $parent->{$depth} = $count;
1.1055 raeburn 13723: $datatable .=
13724: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13725: \$depth,\$count,\@hierarchy,$dirorder,
13726: $children,$parent,$titles,$wantform);
1.1055 raeburn 13727: $depth --;
1.1056 raeburn 13728: pop(@hierarchy);
1.1055 raeburn 13729: }
13730: }
13731: return ($count,$datatable);
13732: }
13733:
13734: sub recurse_extracted_archive {
1.1056 raeburn 13735: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13736: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13737: my $result='';
1.1056 raeburn 13738: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13739: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13740: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13741: return $result;
13742: }
13743: my $dirptr = 16384;
13744: my ($newdirlistref,$newlisterror) =
13745: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13746: if (ref($newdirlistref) eq 'ARRAY') {
13747: foreach my $dir_line (@{$newdirlistref}) {
13748: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13749: unless ($item =~ /^\.+$/) {
13750: $$count ++;
1.1056 raeburn 13751: @{$dirorder->{$$count}} = @{$hierarchy};
13752: $titles->{$$count} = $item;
1.1055 raeburn 13753: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13754:
1.1055 raeburn 13755: my $is_dir;
13756: if ($dirptr&$testdir) {
13757: $is_dir = 1;
13758: }
13759: if ($wantform) {
13760: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13761: }
13762: if ($is_dir) {
13763: $$depth ++;
1.1056 raeburn 13764: push(@{$hierarchy},$$count);
13765: $parent->{$$depth} = $$count;
1.1055 raeburn 13766: $result .=
13767: &recurse_extracted_archive("$currdir/$item",$docudom,
13768: $docuname,$depth,$count,
1.1056 raeburn 13769: $hierarchy,$dirorder,$children,
13770: $parent,$titles,$wantform);
1.1055 raeburn 13771: $$depth --;
1.1056 raeburn 13772: pop(@{$hierarchy});
1.1055 raeburn 13773: }
13774: }
13775: }
13776: }
13777: return $result;
13778: }
13779:
13780: sub archive_hierarchy {
13781: my ($depth,$count,$parent,$children) =@_;
13782: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13783: if (exists($parent->{$depth})) {
13784: $children->{$parent->{$depth}} .= $count.':';
13785: }
13786: }
13787: return;
13788: }
13789:
13790: sub archive_row {
13791: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13792: my ($name) = ($item =~ m{([^/]+)$});
13793: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13794: 'display' => 'Add as file',
1.1055 raeburn 13795: 'dependency' => 'Include as dependency',
13796: 'discard' => 'Discard',
13797: );
13798: if ($is_dir) {
1.1059 raeburn 13799: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13800: }
1.1056 raeburn 13801: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13802: my $offset = 0;
1.1055 raeburn 13803: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13804: $offset ++;
1.1065 raeburn 13805: if ($action ne 'display') {
13806: $offset ++;
13807: }
1.1055 raeburn 13808: $output .= '<td><span class="LC_nobreak">'.
13809: '<label><input type="radio" name="archive_'.$count.
13810: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13811: my $text = $choices{$action};
13812: if ($is_dir) {
13813: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13814: if ($action eq 'display') {
1.1059 raeburn 13815: $text = &mt('Add as folder');
1.1055 raeburn 13816: }
1.1056 raeburn 13817: } else {
13818: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13819:
13820: }
13821: $output .= ' /> '.$choices{$action}.'</label></span>';
13822: if ($action eq 'dependency') {
13823: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13824: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13825: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13826: '<option value=""></option>'."\n".
13827: '</select>'."\n".
13828: '</div>';
1.1059 raeburn 13829: } elsif ($action eq 'display') {
13830: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13831: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13832: '</div>';
1.1055 raeburn 13833: }
1.1056 raeburn 13834: $output .= '</td>';
1.1055 raeburn 13835: }
13836: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13837: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13838: for (my $i=0; $i<$depth; $i++) {
13839: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13840: }
13841: if ($is_dir) {
13842: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13843: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13844: } else {
13845: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13846: }
13847: $output .= ' '.$name.'</td>'."\n".
13848: &end_data_table_row();
13849: return $output;
13850: }
13851:
13852: sub archive_options_form {
1.1065 raeburn 13853: my ($form,$display,$count,$hiddenelem) = @_;
13854: my %lt = &Apache::lonlocal::texthash(
13855: perm => 'Permanently remove archive file?',
13856: hows => 'How should each extracted item be incorporated in the course?',
13857: cont => 'Content actions for all',
13858: addf => 'Add as folder/file',
13859: incd => 'Include as dependency for a displayed file',
13860: disc => 'Discard',
13861: no => 'No',
13862: yes => 'Yes',
13863: save => 'Save',
13864: );
13865: my $output = <<"END";
13866: <form name="$form" method="post" action="">
13867: <p><span class="LC_nobreak">$lt{'perm'}
13868: <label>
13869: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13870: </label>
13871:
13872: <label>
13873: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13874: </span>
13875: </p>
13876: <input type="hidden" name="phase" value="decompress_cleanup" />
13877: <br />$lt{'hows'}
13878: <div class="LC_columnSection">
13879: <fieldset>
13880: <legend>$lt{'cont'}</legend>
13881: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13882: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13883: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13884: </fieldset>
13885: </div>
13886: END
13887: return $output.
1.1055 raeburn 13888: &start_data_table()."\n".
1.1065 raeburn 13889: $display."\n".
1.1055 raeburn 13890: &end_data_table()."\n".
13891: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13892: $hiddenelem.
1.1065 raeburn 13893: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13894: '</form>';
13895: }
13896:
13897: sub archive_javascript {
1.1056 raeburn 13898: my ($startcount,$numitems,$titles,$children) = @_;
13899: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13900: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13901: my $scripttag = <<START;
13902: <script type="text/javascript">
13903: // <![CDATA[
13904:
13905: function checkAll(form,prefix) {
13906: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13907: for (var i=0; i < form.elements.length; i++) {
13908: var id = form.elements[i].id;
13909: if ((id != '') && (id != undefined)) {
13910: if (idstr.test(id)) {
13911: if (form.elements[i].type == 'radio') {
13912: form.elements[i].checked = true;
1.1056 raeburn 13913: var nostart = i-$startcount;
1.1059 raeburn 13914: var offset = nostart%7;
13915: var count = (nostart-offset)/7;
1.1056 raeburn 13916: dependencyCheck(form,count,offset);
1.1055 raeburn 13917: }
13918: }
13919: }
13920: }
13921: }
13922:
13923: function propagateCheck(form,count) {
13924: if (count > 0) {
1.1059 raeburn 13925: var startelement = $startcount + ((count-1) * 7);
13926: for (var j=1; j<6; j++) {
13927: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13928: var item = startelement + j;
13929: if (form.elements[item].type == 'radio') {
13930: if (form.elements[item].checked) {
13931: containerCheck(form,count,j);
13932: break;
13933: }
1.1055 raeburn 13934: }
13935: }
13936: }
13937: }
13938: }
13939:
13940: numitems = $numitems
1.1056 raeburn 13941: var titles = new Array(numitems);
13942: var parents = new Array(numitems);
1.1055 raeburn 13943: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13944: parents[i] = new Array;
1.1055 raeburn 13945: }
1.1059 raeburn 13946: var maintitle = '$maintitle';
1.1055 raeburn 13947:
13948: START
13949:
1.1056 raeburn 13950: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13951: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13952: for (my $i=0; $i<@contents; $i ++) {
13953: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13954: }
13955: }
13956:
1.1056 raeburn 13957: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13958: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13959: }
13960:
1.1055 raeburn 13961: $scripttag .= <<END;
13962:
13963: function containerCheck(form,count,offset) {
13964: if (count > 0) {
1.1056 raeburn 13965: dependencyCheck(form,count,offset);
1.1059 raeburn 13966: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13967: form.elements[item].checked = true;
13968: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13969: if (parents[count].length > 0) {
13970: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13971: containerCheck(form,parents[count][j],offset);
13972: }
13973: }
13974: }
13975: }
13976: }
13977:
13978: function dependencyCheck(form,count,offset) {
13979: if (count > 0) {
1.1059 raeburn 13980: var chosen = (offset+$startcount)+7*(count-1);
13981: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13982: var currtype = form.elements[depitem].type;
13983: if (form.elements[chosen].value == 'dependency') {
13984: document.getElementById('arc_depon_'+count).style.display='block';
13985: form.elements[depitem].options.length = 0;
13986: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13987: for (var i=1; i<=numitems; i++) {
13988: if (i == count) {
13989: continue;
13990: }
1.1059 raeburn 13991: var startelement = $startcount + (i-1) * 7;
13992: for (var j=1; j<6; j++) {
13993: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13994: var item = startelement + j;
13995: if (form.elements[item].type == 'radio') {
13996: if (form.elements[item].checked) {
13997: if (form.elements[item].value == 'display') {
13998: var n = form.elements[depitem].options.length;
13999: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14000: }
14001: }
14002: }
14003: }
14004: }
14005: }
14006: } else {
14007: document.getElementById('arc_depon_'+count).style.display='none';
14008: form.elements[depitem].options.length = 0;
14009: form.elements[depitem].options[0] = new Option('Select','',true,true);
14010: }
1.1059 raeburn 14011: titleCheck(form,count,offset);
1.1056 raeburn 14012: }
14013: }
14014:
14015: function propagateSelect(form,count,offset) {
14016: if (count > 0) {
1.1065 raeburn 14017: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14018: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14019: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14020: if (parents[count].length > 0) {
14021: for (var j=0; j<parents[count].length; j++) {
14022: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14023: }
14024: }
14025: }
14026: }
14027: }
1.1056 raeburn 14028:
14029: function containerSelect(form,count,offset,picked) {
14030: if (count > 0) {
1.1065 raeburn 14031: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14032: if (form.elements[item].type == 'radio') {
14033: if (form.elements[item].value == 'dependency') {
14034: if (form.elements[item+1].type == 'select-one') {
14035: for (var i=0; i<form.elements[item+1].options.length; i++) {
14036: if (form.elements[item+1].options[i].value == picked) {
14037: form.elements[item+1].selectedIndex = i;
14038: break;
14039: }
14040: }
14041: }
14042: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14043: if (parents[count].length > 0) {
14044: for (var j=0; j<parents[count].length; j++) {
14045: containerSelect(form,parents[count][j],offset,picked);
14046: }
14047: }
14048: }
14049: }
14050: }
14051: }
14052: }
14053:
1.1059 raeburn 14054: function titleCheck(form,count,offset) {
14055: if (count > 0) {
14056: var chosen = (offset+$startcount)+7*(count-1);
14057: var depitem = $startcount + ((count-1) * 7) + 2;
14058: var currtype = form.elements[depitem].type;
14059: if (form.elements[chosen].value == 'display') {
14060: document.getElementById('arc_title_'+count).style.display='block';
14061: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14062: document.getElementById('archive_title_'+count).value=maintitle;
14063: }
14064: } else {
14065: document.getElementById('arc_title_'+count).style.display='none';
14066: if (currtype == 'text') {
14067: document.getElementById('archive_title_'+count).value='';
14068: }
14069: }
14070: }
14071: return;
14072: }
14073:
1.1055 raeburn 14074: // ]]>
14075: </script>
14076: END
14077: return $scripttag;
14078: }
14079:
14080: sub process_extracted_files {
1.1067 raeburn 14081: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14082: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14083: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14084: my @ids=&Apache::lonnet::current_machine_ids();
14085: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14086: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14087: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14088: if (grep(/^\Q$docuhome\E$/,@ids)) {
14089: $prefix = &LONCAPA::propath($docudom,$docuname);
14090: $pathtocheck = "$dir_root/$destination";
14091: $dir = $dir_root;
14092: $ishome = 1;
14093: } else {
14094: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14095: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14096: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14097: }
14098: my $currdir = "$dir_root/$destination";
14099: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14100: if ($env{'form.folderpath'}) {
14101: my @items = split('&',$env{'form.folderpath'});
14102: $folders{'0'} = $items[-2];
1.1099 raeburn 14103: if ($env{'form.folderpath'} =~ /\:1$/) {
14104: $containers{'0'}='page';
14105: } else {
14106: $containers{'0'}='sequence';
14107: }
1.1055 raeburn 14108: }
14109: my @archdirs = &get_env_multiple('form.archive_directory');
14110: if ($numitems) {
14111: for (my $i=1; $i<=$numitems; $i++) {
14112: my $path = $env{'form.archive_content_'.$i};
14113: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14114: my $item = $1;
14115: $toplevelitems{$item} = $i;
14116: if (grep(/^\Q$i\E$/,@archdirs)) {
14117: $is_dir{$item} = 1;
14118: }
14119: }
14120: }
14121: }
1.1067 raeburn 14122: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14123: if (keys(%toplevelitems) > 0) {
14124: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14125: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14126: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14127: }
1.1066 raeburn 14128: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14129: if ($numitems) {
14130: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14131: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14132: my $path = $env{'form.archive_content_'.$i};
14133: if ($path =~ /^\Q$pathtocheck\E/) {
14134: if ($env{'form.archive_'.$i} eq 'discard') {
14135: if ($prefix ne '' && $path ne '') {
14136: if (-e $prefix.$path) {
1.1066 raeburn 14137: if ((@archdirs > 0) &&
14138: (grep(/^\Q$i\E$/,@archdirs))) {
14139: $todeletedir{$prefix.$path} = 1;
14140: } else {
14141: $todelete{$prefix.$path} = 1;
14142: }
1.1055 raeburn 14143: }
14144: }
14145: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14146: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14147: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14148: $docstitle = $env{'form.archive_title_'.$i};
14149: if ($docstitle eq '') {
14150: $docstitle = $title;
14151: }
1.1055 raeburn 14152: $outer = 0;
1.1056 raeburn 14153: if (ref($dirorder{$i}) eq 'ARRAY') {
14154: if (@{$dirorder{$i}} > 0) {
14155: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14156: if ($env{'form.archive_'.$item} eq 'display') {
14157: $outer = $item;
14158: last;
14159: }
14160: }
14161: }
14162: }
14163: my ($errtext,$fatal) =
14164: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14165: '/'.$folders{$outer}.'.'.
14166: $containers{$outer});
14167: next if ($fatal);
14168: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14169: if ($context eq 'coursedocs') {
1.1056 raeburn 14170: $mapinner{$i} = time;
1.1055 raeburn 14171: $folders{$i} = 'default_'.$mapinner{$i};
14172: $containers{$i} = 'sequence';
14173: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14174: $folders{$i}.'.'.$containers{$i};
14175: my $newidx = &LONCAPA::map::getresidx();
14176: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14177: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14178: push(@LONCAPA::map::order,$newidx);
14179: my ($outtext,$errtext) =
14180: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14181: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14182: '.'.$containers{$outer},1,1);
1.1056 raeburn 14183: $newseqid{$i} = $newidx;
1.1067 raeburn 14184: unless ($errtext) {
1.1294 raeburn 14185: $result .= '<li>'.&mt('Folder: [_1] added to course',
14186: &HTML::Entities::encode($docstitle,'<>&"')).
14187: '</li>'."\n";
1.1067 raeburn 14188: }
1.1055 raeburn 14189: }
14190: } else {
14191: if ($context eq 'coursedocs') {
14192: my $newidx=&LONCAPA::map::getresidx();
14193: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14194: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14195: $title;
1.1294 raeburn 14196: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
14197: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14198: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14199: }
14200: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14201: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14202: }
14203: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14204: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14205: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14206: unless ($ishome) {
14207: my $fetch = "$newdest{$i}/$title";
14208: $fetch =~ s/^\Q$prefix$dir\E//;
14209: $prompttofetch{$fetch} = 1;
14210: }
1.1292 raeburn 14211: }
1.1067 raeburn 14212: }
1.1294 raeburn 14213: $LONCAPA::map::resources[$newidx]=
14214: $docstitle.':'.$url.':false:normal:res';
14215: push(@LONCAPA::map::order, $newidx);
14216: my ($outtext,$errtext)=
14217: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14218: $docuname.'/'.$folders{$outer}.
14219: '.'.$containers{$outer},1,1);
14220: unless ($errtext) {
14221: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14222: $result .= '<li>'.&mt('File: [_1] added to course',
14223: &HTML::Entities::encode($docstitle,'<>&"')).
14224: '</li>'."\n";
14225: }
1.1067 raeburn 14226: }
1.1294 raeburn 14227: } else {
14228: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14229: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14230: }
1.1055 raeburn 14231: }
14232: }
1.1086 raeburn 14233: }
14234: } else {
1.1294 raeburn 14235: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14236: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14237: }
14238: }
14239: for (my $i=1; $i<=$numitems; $i++) {
14240: next unless ($env{'form.archive_'.$i} eq 'dependency');
14241: my $path = $env{'form.archive_content_'.$i};
14242: if ($path =~ /^\Q$pathtocheck\E/) {
14243: my ($title) = ($path =~ m{/([^/]+)$});
14244: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14245: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14246: if (ref($dirorder{$i}) eq 'ARRAY') {
14247: my ($itemidx,$fullpath,$relpath);
14248: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14249: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14250: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14251: if ($dirorder{$i}->[$j] eq $container) {
14252: $itemidx = $j;
1.1056 raeburn 14253: }
14254: }
1.1086 raeburn 14255: }
14256: if ($itemidx eq '') {
14257: $itemidx = 0;
14258: }
14259: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14260: if ($mapinner{$referrer{$i}}) {
14261: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14262: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14263: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14264: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14265: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14266: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14267: if (!-e $fullpath) {
14268: mkdir($fullpath,0755);
1.1056 raeburn 14269: }
14270: }
1.1086 raeburn 14271: } else {
14272: last;
1.1056 raeburn 14273: }
1.1086 raeburn 14274: }
14275: }
14276: } elsif ($newdest{$referrer{$i}}) {
14277: $fullpath = $newdest{$referrer{$i}};
14278: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14279: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14280: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14281: last;
14282: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14283: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14284: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14285: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14286: if (!-e $fullpath) {
14287: mkdir($fullpath,0755);
1.1056 raeburn 14288: }
14289: }
1.1086 raeburn 14290: } else {
14291: last;
1.1056 raeburn 14292: }
1.1055 raeburn 14293: }
14294: }
1.1086 raeburn 14295: if ($fullpath ne '') {
14296: if (-e "$prefix$path") {
1.1292 raeburn 14297: unless (rename("$prefix$path","$fullpath/$title")) {
14298: $warning .= &mt('Failed to rename dependency').'<br />';
14299: }
1.1086 raeburn 14300: }
14301: if (-e "$fullpath/$title") {
14302: my $showpath;
14303: if ($relpath ne '') {
14304: $showpath = "$relpath/$title";
14305: } else {
14306: $showpath = "/$title";
14307: }
1.1294 raeburn 14308: $result .= '<li>'.&mt('[_1] included as a dependency',
14309: &HTML::Entities::encode($showpath,'<>&"')).
14310: '</li>'."\n";
1.1292 raeburn 14311: unless ($ishome) {
14312: my $fetch = "$fullpath/$title";
14313: $fetch =~ s/^\Q$prefix$dir\E//;
14314: $prompttofetch{$fetch} = 1;
14315: }
1.1086 raeburn 14316: }
14317: }
1.1055 raeburn 14318: }
1.1086 raeburn 14319: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14320: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14321: &HTML::Entities::encode($path,'<>&"'),
14322: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14323: '<br />';
1.1055 raeburn 14324: }
14325: } else {
1.1294 raeburn 14326: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14327: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14328: }
14329: }
14330: if (keys(%todelete)) {
14331: foreach my $key (keys(%todelete)) {
14332: unlink($key);
1.1066 raeburn 14333: }
14334: }
14335: if (keys(%todeletedir)) {
14336: foreach my $key (keys(%todeletedir)) {
14337: rmdir($key);
14338: }
14339: }
14340: foreach my $dir (sort(keys(%is_dir))) {
14341: if (($pathtocheck ne '') && ($dir ne '')) {
14342: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14343: }
14344: }
1.1067 raeburn 14345: if ($result ne '') {
14346: $output .= '<ul>'."\n".
14347: $result."\n".
14348: '</ul>';
14349: }
14350: unless ($ishome) {
14351: my $replicationfail;
14352: foreach my $item (keys(%prompttofetch)) {
14353: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14354: unless ($fetchresult eq 'ok') {
14355: $replicationfail .= '<li>'.$item.'</li>'."\n";
14356: }
14357: }
14358: if ($replicationfail) {
14359: $output .= '<p class="LC_error">'.
14360: &mt('Course home server failed to retrieve:').'<ul>'.
14361: $replicationfail.
14362: '</ul></p>';
14363: }
14364: }
1.1055 raeburn 14365: } else {
14366: $warning = &mt('No items found in archive.');
14367: }
14368: if ($error) {
14369: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14370: $error.'</p>'."\n";
14371: }
14372: if ($warning) {
14373: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14374: }
14375: return $output;
14376: }
14377:
1.1066 raeburn 14378: sub cleanup_empty_dirs {
14379: my ($path) = @_;
14380: if (($path ne '') && (-d $path)) {
14381: if (opendir(my $dirh,$path)) {
14382: my @dircontents = grep(!/^\./,readdir($dirh));
14383: my $numitems = 0;
14384: foreach my $item (@dircontents) {
14385: if (-d "$path/$item") {
1.1111 raeburn 14386: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14387: if (-e "$path/$item") {
14388: $numitems ++;
14389: }
14390: } else {
14391: $numitems ++;
14392: }
14393: }
14394: if ($numitems == 0) {
14395: rmdir($path);
14396: }
14397: closedir($dirh);
14398: }
14399: }
14400: return;
14401: }
14402:
1.41 ng 14403: =pod
1.45 matthew 14404:
1.1162 raeburn 14405: =item * &get_folder_hierarchy()
1.1068 raeburn 14406:
14407: Provides hierarchy of names of folders/sub-folders containing the current
14408: item,
14409:
14410: Inputs: 3
14411: - $navmap - navmaps object
14412:
14413: - $map - url for map (either the trigger itself, or map containing
14414: the resource, which is the trigger).
14415:
14416: - $showitem - 1 => show title for map itself; 0 => do not show.
14417:
14418: Outputs: 1 @pathitems - array of folder/subfolder names.
14419:
14420: =cut
14421:
14422: sub get_folder_hierarchy {
14423: my ($navmap,$map,$showitem) = @_;
14424: my @pathitems;
14425: if (ref($navmap)) {
14426: my $mapres = $navmap->getResourceByUrl($map);
14427: if (ref($mapres)) {
14428: my $pcslist = $mapres->map_hierarchy();
14429: if ($pcslist ne '') {
14430: my @pcs = split(/,/,$pcslist);
14431: foreach my $pc (@pcs) {
14432: if ($pc == 1) {
1.1129 raeburn 14433: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14434: } else {
14435: my $res = $navmap->getByMapPc($pc);
14436: if (ref($res)) {
14437: my $title = $res->compTitle();
14438: $title =~ s/\W+/_/g;
14439: if ($title ne '') {
14440: push(@pathitems,$title);
14441: }
14442: }
14443: }
14444: }
14445: }
1.1071 raeburn 14446: if ($showitem) {
14447: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14448: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14449: } else {
14450: my $maptitle = $mapres->compTitle();
14451: $maptitle =~ s/\W+/_/g;
14452: if ($maptitle ne '') {
14453: push(@pathitems,$maptitle);
14454: }
1.1068 raeburn 14455: }
14456: }
14457: }
14458: }
14459: return @pathitems;
14460: }
14461:
14462: =pod
14463:
1.1015 raeburn 14464: =item * &get_turnedin_filepath()
14465:
14466: Determines path in a user's portfolio file for storage of files uploaded
14467: to a specific essayresponse or dropbox item.
14468:
14469: Inputs: 3 required + 1 optional.
14470: $symb is symb for resource, $uname and $udom are for current user (required).
14471: $caller is optional (can be "submission", if routine is called when storing
14472: an upoaded file when "Submit Answer" button was pressed).
14473:
14474: Returns array containing $path and $multiresp.
14475: $path is path in portfolio. $multiresp is 1 if this resource contains more
14476: than one file upload item. Callers of routine should append partid as a
14477: subdirectory to $path in cases where $multiresp is 1.
14478:
14479: Called by: homework/essayresponse.pm and homework/structuretags.pm
14480:
14481: =cut
14482:
14483: sub get_turnedin_filepath {
14484: my ($symb,$uname,$udom,$caller) = @_;
14485: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14486: my $turnindir;
14487: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14488: $turnindir = $userhash{'turnindir'};
14489: my ($path,$multiresp);
14490: if ($turnindir eq '') {
14491: if ($caller eq 'submission') {
14492: $turnindir = &mt('turned in');
14493: $turnindir =~ s/\W+/_/g;
14494: my %newhash = (
14495: 'turnindir' => $turnindir,
14496: );
14497: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14498: }
14499: }
14500: if ($turnindir ne '') {
14501: $path = '/'.$turnindir.'/';
14502: my ($multipart,$turnin,@pathitems);
14503: my $navmap = Apache::lonnavmaps::navmap->new();
14504: if (defined($navmap)) {
14505: my $mapres = $navmap->getResourceByUrl($map);
14506: if (ref($mapres)) {
14507: my $pcslist = $mapres->map_hierarchy();
14508: if ($pcslist ne '') {
14509: foreach my $pc (split(/,/,$pcslist)) {
14510: my $res = $navmap->getByMapPc($pc);
14511: if (ref($res)) {
14512: my $title = $res->compTitle();
14513: $title =~ s/\W+/_/g;
14514: if ($title ne '') {
1.1149 raeburn 14515: if (($pc > 1) && (length($title) > 12)) {
14516: $title = substr($title,0,12);
14517: }
1.1015 raeburn 14518: push(@pathitems,$title);
14519: }
14520: }
14521: }
14522: }
14523: my $maptitle = $mapres->compTitle();
14524: $maptitle =~ s/\W+/_/g;
14525: if ($maptitle ne '') {
1.1149 raeburn 14526: if (length($maptitle) > 12) {
14527: $maptitle = substr($maptitle,0,12);
14528: }
1.1015 raeburn 14529: push(@pathitems,$maptitle);
14530: }
14531: unless ($env{'request.state'} eq 'construct') {
14532: my $res = $navmap->getBySymb($symb);
14533: if (ref($res)) {
14534: my $partlist = $res->parts();
14535: my $totaluploads = 0;
14536: if (ref($partlist) eq 'ARRAY') {
14537: foreach my $part (@{$partlist}) {
14538: my @types = $res->responseType($part);
14539: my @ids = $res->responseIds($part);
14540: for (my $i=0; $i < scalar(@ids); $i++) {
14541: if ($types[$i] eq 'essay') {
14542: my $partid = $part.'_'.$ids[$i];
14543: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14544: $totaluploads ++;
14545: }
14546: }
14547: }
14548: }
14549: if ($totaluploads > 1) {
14550: $multiresp = 1;
14551: }
14552: }
14553: }
14554: }
14555: } else {
14556: return;
14557: }
14558: } else {
14559: return;
14560: }
14561: my $restitle=&Apache::lonnet::gettitle($symb);
14562: $restitle =~ s/\W+/_/g;
14563: if ($restitle eq '') {
14564: $restitle = ($resurl =~ m{/[^/]+$});
14565: if ($restitle eq '') {
14566: $restitle = time;
14567: }
14568: }
1.1149 raeburn 14569: if (length($restitle) > 12) {
14570: $restitle = substr($restitle,0,12);
14571: }
1.1015 raeburn 14572: push(@pathitems,$restitle);
14573: $path .= join('/',@pathitems);
14574: }
14575: return ($path,$multiresp);
14576: }
14577:
14578: =pod
14579:
1.464 albertel 14580: =back
1.41 ng 14581:
1.112 bowersj2 14582: =head1 CSV Upload/Handling functions
1.38 albertel 14583:
1.41 ng 14584: =over 4
14585:
1.648 raeburn 14586: =item * &upfile_store($r)
1.41 ng 14587:
14588: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14589: needs $env{'form.upfile'}
1.41 ng 14590: returns $datatoken to be put into hidden field
14591:
14592: =cut
1.31 albertel 14593:
14594: sub upfile_store {
14595: my $r=shift;
1.258 albertel 14596: $env{'form.upfile'}=~s/\r/\n/gs;
14597: $env{'form.upfile'}=~s/\f/\n/gs;
14598: $env{'form.upfile'}=~s/\n+/\n/gs;
14599: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14600:
1.1299 raeburn 14601: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14602: '_enroll_'.$env{'request.course.id'}.'_'.
14603: time.'_'.$$);
14604: return if ($datatoken eq '');
14605:
1.31 albertel 14606: {
1.158 raeburn 14607: my $datafile = $r->dir_config('lonDaemons').
14608: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14609: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14610: print $fh $env{'form.upfile'};
1.158 raeburn 14611: close($fh);
14612: }
1.31 albertel 14613: }
14614: return $datatoken;
14615: }
14616:
1.56 matthew 14617: =pod
14618:
1.1290 raeburn 14619: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14620:
14621: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14622: $datatoken is the name to assign to the temporary file.
1.258 albertel 14623: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14624:
14625: =cut
1.31 albertel 14626:
14627: sub load_tmp_file {
1.1290 raeburn 14628: my ($r,$datatoken) = @_;
14629: return if ($datatoken eq '');
1.31 albertel 14630: my @studentdata=();
14631: {
1.158 raeburn 14632: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14633: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14634: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14635: @studentdata=<$fh>;
14636: close($fh);
14637: }
1.31 albertel 14638: }
1.258 albertel 14639: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14640: }
14641:
1.1290 raeburn 14642: sub valid_datatoken {
14643: my ($datatoken) = @_;
1.1325 raeburn 14644: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14645: return $datatoken;
14646: }
14647: return;
14648: }
14649:
1.56 matthew 14650: =pod
14651:
1.648 raeburn 14652: =item * &upfile_record_sep()
1.41 ng 14653:
14654: Separate uploaded file into records
14655: returns array of records,
1.258 albertel 14656: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14657:
14658: =cut
1.31 albertel 14659:
14660: sub upfile_record_sep {
1.258 albertel 14661: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14662: } else {
1.248 albertel 14663: my @records;
1.258 albertel 14664: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14665: if ($line=~/^\s*$/) { next; }
14666: push(@records,$line);
14667: }
14668: return @records;
1.31 albertel 14669: }
14670: }
14671:
1.56 matthew 14672: =pod
14673:
1.648 raeburn 14674: =item * &record_sep($record)
1.41 ng 14675:
1.258 albertel 14676: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14677:
14678: =cut
14679:
1.263 www 14680: sub takeleft {
14681: my $index=shift;
14682: return substr('0000'.$index,-4,4);
14683: }
14684:
1.31 albertel 14685: sub record_sep {
14686: my $record=shift;
14687: my %components=();
1.258 albertel 14688: if ($env{'form.upfiletype'} eq 'xml') {
14689: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14690: my $i=0;
1.356 albertel 14691: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14692: $field=~s/^(\"|\')//;
14693: $field=~s/(\"|\')$//;
1.263 www 14694: $components{&takeleft($i)}=$field;
1.31 albertel 14695: $i++;
14696: }
1.258 albertel 14697: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14698: my $i=0;
1.356 albertel 14699: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14700: $field=~s/^(\"|\')//;
14701: $field=~s/(\"|\')$//;
1.263 www 14702: $components{&takeleft($i)}=$field;
1.31 albertel 14703: $i++;
14704: }
14705: } else {
1.561 www 14706: my $separator=',';
1.480 banghart 14707: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14708: $separator=';';
1.480 banghart 14709: }
1.31 albertel 14710: my $i=0;
1.561 www 14711: # the character we are looking for to indicate the end of a quote or a record
14712: my $looking_for=$separator;
14713: # do not add the characters to the fields
14714: my $ignore=0;
14715: # we just encountered a separator (or the beginning of the record)
14716: my $just_found_separator=1;
14717: # store the field we are working on here
14718: my $field='';
14719: # work our way through all characters in record
14720: foreach my $character ($record=~/(.)/g) {
14721: if ($character eq $looking_for) {
14722: if ($character ne $separator) {
14723: # Found the end of a quote, again looking for separator
14724: $looking_for=$separator;
14725: $ignore=1;
14726: } else {
14727: # Found a separator, store away what we got
14728: $components{&takeleft($i)}=$field;
14729: $i++;
14730: $just_found_separator=1;
14731: $ignore=0;
14732: $field='';
14733: }
14734: next;
14735: }
14736: # single or double quotation marks after a separator indicate beginning of a quote
14737: # we are now looking for the end of the quote and need to ignore separators
14738: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14739: $looking_for=$character;
14740: next;
14741: }
14742: # ignore would be true after we reached the end of a quote
14743: if ($ignore) { next; }
14744: if (($just_found_separator) && ($character=~/\s/)) { next; }
14745: $field.=$character;
14746: $just_found_separator=0;
1.31 albertel 14747: }
1.561 www 14748: # catch the very last entry, since we never encountered the separator
14749: $components{&takeleft($i)}=$field;
1.31 albertel 14750: }
14751: return %components;
14752: }
14753:
1.144 matthew 14754: ######################################################
14755: ######################################################
14756:
1.56 matthew 14757: =pod
14758:
1.648 raeburn 14759: =item * &upfile_select_html()
1.41 ng 14760:
1.144 matthew 14761: Return HTML code to select a file from the users machine and specify
14762: the file type.
1.41 ng 14763:
14764: =cut
14765:
1.144 matthew 14766: ######################################################
14767: ######################################################
1.31 albertel 14768: sub upfile_select_html {
1.144 matthew 14769: my %Types = (
14770: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14771: semisv => &mt('Semicolon separated values'),
1.144 matthew 14772: space => &mt('Space separated'),
14773: tab => &mt('Tabulator separated'),
14774: # xml => &mt('HTML/XML'),
14775: );
14776: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14777: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14778: foreach my $type (sort(keys(%Types))) {
14779: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14780: }
14781: $Str .= "</select>\n";
14782: return $Str;
1.31 albertel 14783: }
14784:
1.301 albertel 14785: sub get_samples {
14786: my ($records,$toget) = @_;
14787: my @samples=({});
14788: my $got=0;
14789: foreach my $rec (@$records) {
14790: my %temp = &record_sep($rec);
14791: if (! grep(/\S/, values(%temp))) { next; }
14792: if (%temp) {
14793: $samples[$got]=\%temp;
14794: $got++;
14795: if ($got == $toget) { last; }
14796: }
14797: }
14798: return \@samples;
14799: }
14800:
1.144 matthew 14801: ######################################################
14802: ######################################################
14803:
1.56 matthew 14804: =pod
14805:
1.648 raeburn 14806: =item * &csv_print_samples($r,$records)
1.41 ng 14807:
14808: Prints a table of sample values from each column uploaded $r is an
14809: Apache Request ref, $records is an arrayref from
14810: &Apache::loncommon::upfile_record_sep
14811:
14812: =cut
14813:
1.144 matthew 14814: ######################################################
14815: ######################################################
1.31 albertel 14816: sub csv_print_samples {
14817: my ($r,$records) = @_;
1.662 bisitz 14818: my $samples = &get_samples($records,5);
1.301 albertel 14819:
1.594 raeburn 14820: $r->print(&mt('Samples').'<br />'.&start_data_table().
14821: &start_data_table_header_row());
1.356 albertel 14822: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14823: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14824: $r->print(&end_data_table_header_row());
1.301 albertel 14825: foreach my $hash (@$samples) {
1.594 raeburn 14826: $r->print(&start_data_table_row());
1.356 albertel 14827: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14828: $r->print('<td>');
1.356 albertel 14829: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14830: $r->print('</td>');
14831: }
1.594 raeburn 14832: $r->print(&end_data_table_row());
1.31 albertel 14833: }
1.594 raeburn 14834: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14835: }
14836:
1.144 matthew 14837: ######################################################
14838: ######################################################
14839:
1.56 matthew 14840: =pod
14841:
1.648 raeburn 14842: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14843:
14844: Prints a table to create associations between values and table columns.
1.144 matthew 14845:
1.41 ng 14846: $r is an Apache Request ref,
14847: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14848: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14849:
14850: =cut
14851:
1.144 matthew 14852: ######################################################
14853: ######################################################
1.31 albertel 14854: sub csv_print_select_table {
14855: my ($r,$records,$d) = @_;
1.301 albertel 14856: my $i=0;
14857: my $samples = &get_samples($records,1);
1.144 matthew 14858: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14859: &start_data_table().&start_data_table_header_row().
1.144 matthew 14860: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14861: '<th>'.&mt('Column').'</th>'.
14862: &end_data_table_header_row()."\n");
1.356 albertel 14863: foreach my $array_ref (@$d) {
14864: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14865: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14866:
1.875 bisitz 14867: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14868: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14869: $r->print('<option value="none"></option>');
1.356 albertel 14870: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14871: $r->print('<option value="'.$sample.'"'.
14872: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14873: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14874: }
1.594 raeburn 14875: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14876: $i++;
14877: }
1.594 raeburn 14878: $r->print(&end_data_table());
1.31 albertel 14879: $i--;
14880: return $i;
14881: }
1.56 matthew 14882:
1.144 matthew 14883: ######################################################
14884: ######################################################
14885:
1.56 matthew 14886: =pod
1.31 albertel 14887:
1.648 raeburn 14888: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14889:
14890: Prints a table of sample values from the upload and can make associate samples to internal names.
14891:
14892: $r is an Apache Request ref,
14893: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14894: $d is an array of 2 element arrays (internal name, displayed name)
14895:
14896: =cut
14897:
1.144 matthew 14898: ######################################################
14899: ######################################################
1.31 albertel 14900: sub csv_samples_select_table {
14901: my ($r,$records,$d) = @_;
14902: my $i=0;
1.144 matthew 14903: #
1.662 bisitz 14904: my $max_samples = 5;
14905: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14906: $r->print(&start_data_table().
14907: &start_data_table_header_row().'<th>'.
14908: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14909: &end_data_table_header_row());
1.301 albertel 14910:
14911: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14912: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14913: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14914: foreach my $option (@$d) {
14915: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14916: $r->print('<option value="'.$value.'"'.
1.253 albertel 14917: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14918: $display.'</option>');
1.31 albertel 14919: }
14920: $r->print('</select></td><td>');
1.662 bisitz 14921: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14922: if (defined($samples->[$line]{$key})) {
14923: $r->print($samples->[$line]{$key}."<br />\n");
14924: }
14925: }
1.594 raeburn 14926: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14927: $i++;
14928: }
1.594 raeburn 14929: $r->print(&end_data_table());
1.31 albertel 14930: $i--;
14931: return($i);
1.115 matthew 14932: }
14933:
1.144 matthew 14934: ######################################################
14935: ######################################################
14936:
1.115 matthew 14937: =pod
14938:
1.648 raeburn 14939: =item * &clean_excel_name($name)
1.115 matthew 14940:
14941: Returns a replacement for $name which does not contain any illegal characters.
14942:
14943: =cut
14944:
1.144 matthew 14945: ######################################################
14946: ######################################################
1.115 matthew 14947: sub clean_excel_name {
14948: my ($name) = @_;
14949: $name =~ s/[:\*\?\/\\]//g;
14950: if (length($name) > 31) {
14951: $name = substr($name,0,31);
14952: }
14953: return $name;
1.25 albertel 14954: }
1.84 albertel 14955:
1.85 albertel 14956: =pod
14957:
1.648 raeburn 14958: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14959:
14960: Returns either 1 or undef
14961:
14962: 1 if the part is to be hidden, undef if it is to be shown
14963:
14964: Arguments are:
14965:
14966: $id the id of the part to be checked
14967: $symb, optional the symb of the resource to check
14968: $udom, optional the domain of the user to check for
14969: $uname, optional the username of the user to check for
14970:
14971: =cut
1.84 albertel 14972:
14973: sub check_if_partid_hidden {
14974: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14975: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14976: $symb,$udom,$uname);
1.141 albertel 14977: my $truth=1;
14978: #if the string starts with !, then the list is the list to show not hide
14979: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14980: my @hiddenlist=split(/,/,$hiddenparts);
14981: foreach my $checkid (@hiddenlist) {
1.141 albertel 14982: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14983: }
1.141 albertel 14984: return !$truth;
1.84 albertel 14985: }
1.127 matthew 14986:
1.138 matthew 14987:
14988: ############################################################
14989: ############################################################
14990:
14991: =pod
14992:
1.157 matthew 14993: =back
14994:
1.138 matthew 14995: =head1 cgi-bin script and graphing routines
14996:
1.157 matthew 14997: =over 4
14998:
1.648 raeburn 14999: =item * &get_cgi_id()
1.138 matthew 15000:
15001: Inputs: none
15002:
15003: Returns an id which can be used to pass environment variables
15004: to various cgi-bin scripts. These environment variables will
15005: be removed from the users environment after a given time by
15006: the routine &Apache::lonnet::transfer_profile_to_env.
15007:
15008: =cut
15009:
15010: ############################################################
15011: ############################################################
1.152 albertel 15012: my $uniq=0;
1.136 matthew 15013: sub get_cgi_id {
1.154 albertel 15014: $uniq=($uniq+1)%100000;
1.280 albertel 15015: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15016: }
15017:
1.127 matthew 15018: ############################################################
15019: ############################################################
15020:
15021: =pod
15022:
1.648 raeburn 15023: =item * &DrawBarGraph()
1.127 matthew 15024:
1.138 matthew 15025: Facilitates the plotting of data in a (stacked) bar graph.
15026: Puts plot definition data into the users environment in order for
15027: graph.png to plot it. Returns an <img> tag for the plot.
15028: The bars on the plot are labeled '1','2',...,'n'.
15029:
15030: Inputs:
15031:
15032: =over 4
15033:
15034: =item $Title: string, the title of the plot
15035:
15036: =item $xlabel: string, text describing the X-axis of the plot
15037:
15038: =item $ylabel: string, text describing the Y-axis of the plot
15039:
15040: =item $Max: scalar, the maximum Y value to use in the plot
15041: If $Max is < any data point, the graph will not be rendered.
15042:
1.140 matthew 15043: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15044: they are plotted. If undefined, default values will be used.
15045:
1.178 matthew 15046: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15047:
1.138 matthew 15048: =item @Values: An array of array references. Each array reference holds data
15049: to be plotted in a stacked bar chart.
15050:
1.239 matthew 15051: =item If the final element of @Values is a hash reference the key/value
15052: pairs will be added to the graph definition.
15053:
1.138 matthew 15054: =back
15055:
15056: Returns:
15057:
15058: An <img> tag which references graph.png and the appropriate identifying
15059: information for the plot.
15060:
1.127 matthew 15061: =cut
15062:
15063: ############################################################
15064: ############################################################
1.134 matthew 15065: sub DrawBarGraph {
1.178 matthew 15066: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15067: #
15068: if (! defined($colors)) {
15069: $colors = ['#33ff00',
15070: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15071: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15072: ];
15073: }
1.228 matthew 15074: my $extra_settings = {};
15075: if (ref($Values[-1]) eq 'HASH') {
15076: $extra_settings = pop(@Values);
15077: }
1.127 matthew 15078: #
1.136 matthew 15079: my $identifier = &get_cgi_id();
15080: my $id = 'cgi.'.$identifier;
1.129 matthew 15081: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15082: return '';
15083: }
1.225 matthew 15084: #
15085: my @Labels;
15086: if (defined($labels)) {
15087: @Labels = @$labels;
15088: } else {
15089: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15090: push(@Labels,$i+1);
1.225 matthew 15091: }
15092: }
15093: #
1.129 matthew 15094: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15095: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15096: my %ValuesHash;
15097: my $NumSets=1;
15098: foreach my $array (@Values) {
15099: next if (! ref($array));
1.136 matthew 15100: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15101: join(',',@$array);
1.129 matthew 15102: }
1.127 matthew 15103: #
1.136 matthew 15104: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15105: if ($NumBars < 3) {
15106: $width = 120+$NumBars*32;
1.220 matthew 15107: $xskip = 1;
1.225 matthew 15108: $bar_width = 30;
15109: } elsif ($NumBars < 5) {
15110: $width = 120+$NumBars*20;
15111: $xskip = 1;
15112: $bar_width = 20;
1.220 matthew 15113: } elsif ($NumBars < 10) {
1.136 matthew 15114: $width = 120+$NumBars*15;
15115: $xskip = 1;
15116: $bar_width = 15;
15117: } elsif ($NumBars <= 25) {
15118: $width = 120+$NumBars*11;
15119: $xskip = 5;
15120: $bar_width = 8;
15121: } elsif ($NumBars <= 50) {
15122: $width = 120+$NumBars*8;
15123: $xskip = 5;
15124: $bar_width = 4;
15125: } else {
15126: $width = 120+$NumBars*8;
15127: $xskip = 5;
15128: $bar_width = 4;
15129: }
15130: #
1.137 matthew 15131: $Max = 1 if ($Max < 1);
15132: if ( int($Max) < $Max ) {
15133: $Max++;
15134: $Max = int($Max);
15135: }
1.127 matthew 15136: $Title = '' if (! defined($Title));
15137: $xlabel = '' if (! defined($xlabel));
15138: $ylabel = '' if (! defined($ylabel));
1.369 www 15139: $ValuesHash{$id.'.title'} = &escape($Title);
15140: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15141: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15142: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15143: $ValuesHash{$id.'.NumBars'} = $NumBars;
15144: $ValuesHash{$id.'.NumSets'} = $NumSets;
15145: $ValuesHash{$id.'.PlotType'} = 'bar';
15146: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15147: $ValuesHash{$id.'.height'} = $height;
15148: $ValuesHash{$id.'.width'} = $width;
15149: $ValuesHash{$id.'.xskip'} = $xskip;
15150: $ValuesHash{$id.'.bar_width'} = $bar_width;
15151: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15152: #
1.228 matthew 15153: # Deal with other parameters
15154: while (my ($key,$value) = each(%$extra_settings)) {
15155: $ValuesHash{$id.'.'.$key} = $value;
15156: }
15157: #
1.646 raeburn 15158: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15159: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15160: }
15161:
15162: ############################################################
15163: ############################################################
15164:
15165: =pod
15166:
1.648 raeburn 15167: =item * &DrawXYGraph()
1.137 matthew 15168:
1.138 matthew 15169: Facilitates the plotting of data in an XY graph.
15170: Puts plot definition data into the users environment in order for
15171: graph.png to plot it. Returns an <img> tag for the plot.
15172:
15173: Inputs:
15174:
15175: =over 4
15176:
15177: =item $Title: string, the title of the plot
15178:
15179: =item $xlabel: string, text describing the X-axis of the plot
15180:
15181: =item $ylabel: string, text describing the Y-axis of the plot
15182:
15183: =item $Max: scalar, the maximum Y value to use in the plot
15184: If $Max is < any data point, the graph will not be rendered.
15185:
15186: =item $colors: Array ref containing the hex color codes for the data to be
15187: plotted in. If undefined, default values will be used.
15188:
15189: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15190:
15191: =item $Ydata: Array ref containing Array refs.
1.185 www 15192: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15193:
15194: =item %Values: hash indicating or overriding any default values which are
15195: passed to graph.png.
15196: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15197:
15198: =back
15199:
15200: Returns:
15201:
15202: An <img> tag which references graph.png and the appropriate identifying
15203: information for the plot.
15204:
1.137 matthew 15205: =cut
15206:
15207: ############################################################
15208: ############################################################
15209: sub DrawXYGraph {
15210: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15211: #
15212: # Create the identifier for the graph
15213: my $identifier = &get_cgi_id();
15214: my $id = 'cgi.'.$identifier;
15215: #
15216: $Title = '' if (! defined($Title));
15217: $xlabel = '' if (! defined($xlabel));
15218: $ylabel = '' if (! defined($ylabel));
15219: my %ValuesHash =
15220: (
1.369 www 15221: $id.'.title' => &escape($Title),
15222: $id.'.xlabel' => &escape($xlabel),
15223: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15224: $id.'.y_max_value'=> $Max,
15225: $id.'.labels' => join(',',@$Xlabels),
15226: $id.'.PlotType' => 'XY',
15227: );
15228: #
15229: if (defined($colors) && ref($colors) eq 'ARRAY') {
15230: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15231: }
15232: #
15233: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15234: return '';
15235: }
15236: my $NumSets=1;
1.138 matthew 15237: foreach my $array (@{$Ydata}){
1.137 matthew 15238: next if (! ref($array));
15239: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15240: }
1.138 matthew 15241: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15242: #
15243: # Deal with other parameters
15244: while (my ($key,$value) = each(%Values)) {
15245: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15246: }
15247: #
1.646 raeburn 15248: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15249: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15250: }
15251:
15252: ############################################################
15253: ############################################################
15254:
15255: =pod
15256:
1.648 raeburn 15257: =item * &DrawXYYGraph()
1.138 matthew 15258:
15259: Facilitates the plotting of data in an XY graph with two Y axes.
15260: Puts plot definition data into the users environment in order for
15261: graph.png to plot it. Returns an <img> tag for the plot.
15262:
15263: Inputs:
15264:
15265: =over 4
15266:
15267: =item $Title: string, the title of the plot
15268:
15269: =item $xlabel: string, text describing the X-axis of the plot
15270:
15271: =item $ylabel: string, text describing the Y-axis of the plot
15272:
15273: =item $colors: Array ref containing the hex color codes for the data to be
15274: plotted in. If undefined, default values will be used.
15275:
15276: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15277:
15278: =item $Ydata1: The first data set
15279:
15280: =item $Min1: The minimum value of the left Y-axis
15281:
15282: =item $Max1: The maximum value of the left Y-axis
15283:
15284: =item $Ydata2: The second data set
15285:
15286: =item $Min2: The minimum value of the right Y-axis
15287:
15288: =item $Max2: The maximum value of the left Y-axis
15289:
15290: =item %Values: hash indicating or overriding any default values which are
15291: passed to graph.png.
15292: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15293:
15294: =back
15295:
15296: Returns:
15297:
15298: An <img> tag which references graph.png and the appropriate identifying
15299: information for the plot.
1.136 matthew 15300:
15301: =cut
15302:
15303: ############################################################
15304: ############################################################
1.137 matthew 15305: sub DrawXYYGraph {
15306: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15307: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15308: #
15309: # Create the identifier for the graph
15310: my $identifier = &get_cgi_id();
15311: my $id = 'cgi.'.$identifier;
15312: #
15313: $Title = '' if (! defined($Title));
15314: $xlabel = '' if (! defined($xlabel));
15315: $ylabel = '' if (! defined($ylabel));
15316: my %ValuesHash =
15317: (
1.369 www 15318: $id.'.title' => &escape($Title),
15319: $id.'.xlabel' => &escape($xlabel),
15320: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15321: $id.'.labels' => join(',',@$Xlabels),
15322: $id.'.PlotType' => 'XY',
15323: $id.'.NumSets' => 2,
1.137 matthew 15324: $id.'.two_axes' => 1,
15325: $id.'.y1_max_value' => $Max1,
15326: $id.'.y1_min_value' => $Min1,
15327: $id.'.y2_max_value' => $Max2,
15328: $id.'.y2_min_value' => $Min2,
1.136 matthew 15329: );
15330: #
1.137 matthew 15331: if (defined($colors) && ref($colors) eq 'ARRAY') {
15332: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15333: }
15334: #
15335: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15336: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15337: return '';
15338: }
15339: my $NumSets=1;
1.137 matthew 15340: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15341: next if (! ref($array));
15342: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15343: }
15344: #
15345: # Deal with other parameters
15346: while (my ($key,$value) = each(%Values)) {
15347: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15348: }
15349: #
1.646 raeburn 15350: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15351: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15352: }
15353:
15354: ############################################################
15355: ############################################################
15356:
15357: =pod
15358:
1.157 matthew 15359: =back
15360:
1.139 matthew 15361: =head1 Statistics helper routines?
15362:
15363: Bad place for them but what the hell.
15364:
1.157 matthew 15365: =over 4
15366:
1.648 raeburn 15367: =item * &chartlink()
1.139 matthew 15368:
15369: Returns a link to the chart for a specific student.
15370:
15371: Inputs:
15372:
15373: =over 4
15374:
15375: =item $linktext: The text of the link
15376:
15377: =item $sname: The students username
15378:
15379: =item $sdomain: The students domain
15380:
15381: =back
15382:
1.157 matthew 15383: =back
15384:
1.139 matthew 15385: =cut
15386:
15387: ############################################################
15388: ############################################################
15389: sub chartlink {
15390: my ($linktext, $sname, $sdomain) = @_;
15391: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15392: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15393: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15394: '">'.$linktext.'</a>';
1.153 matthew 15395: }
15396:
15397: #######################################################
15398: #######################################################
15399:
15400: =pod
15401:
15402: =head1 Course Environment Routines
1.157 matthew 15403:
15404: =over 4
1.153 matthew 15405:
1.648 raeburn 15406: =item * &restore_course_settings()
1.153 matthew 15407:
1.648 raeburn 15408: =item * &store_course_settings()
1.153 matthew 15409:
15410: Restores/Store indicated form parameters from the course environment.
15411: Will not overwrite existing values of the form parameters.
15412:
15413: Inputs:
15414: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15415:
15416: a hash ref describing the data to be stored. For example:
15417:
15418: %Save_Parameters = ('Status' => 'scalar',
15419: 'chartoutputmode' => 'scalar',
15420: 'chartoutputdata' => 'scalar',
15421: 'Section' => 'array',
1.373 raeburn 15422: 'Group' => 'array',
1.153 matthew 15423: 'StudentData' => 'array',
15424: 'Maps' => 'array');
15425:
15426: Returns: both routines return nothing
15427:
1.631 raeburn 15428: =back
15429:
1.153 matthew 15430: =cut
15431:
15432: #######################################################
15433: #######################################################
15434: sub store_course_settings {
1.496 albertel 15435: return &store_settings($env{'request.course.id'},@_);
15436: }
15437:
15438: sub store_settings {
1.153 matthew 15439: # save to the environment
15440: # appenv the same items, just to be safe
1.300 albertel 15441: my $udom = $env{'user.domain'};
15442: my $uname = $env{'user.name'};
1.496 albertel 15443: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15444: my %SaveHash;
15445: my %AppHash;
15446: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15447: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15448: my $envname = 'environment.'.$basename;
1.258 albertel 15449: if (exists($env{'form.'.$setting})) {
1.153 matthew 15450: # Save this value away
15451: if ($type eq 'scalar' &&
1.258 albertel 15452: (! exists($env{$envname}) ||
15453: $env{$envname} ne $env{'form.'.$setting})) {
15454: $SaveHash{$basename} = $env{'form.'.$setting};
15455: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15456: } elsif ($type eq 'array') {
15457: my $stored_form;
1.258 albertel 15458: if (ref($env{'form.'.$setting})) {
1.153 matthew 15459: $stored_form = join(',',
15460: map {
1.369 www 15461: &escape($_);
1.258 albertel 15462: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15463: } else {
15464: $stored_form =
1.369 www 15465: &escape($env{'form.'.$setting});
1.153 matthew 15466: }
15467: # Determine if the array contents are the same.
1.258 albertel 15468: if ($stored_form ne $env{$envname}) {
1.153 matthew 15469: $SaveHash{$basename} = $stored_form;
15470: $AppHash{$envname} = $stored_form;
15471: }
15472: }
15473: }
15474: }
15475: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15476: $udom,$uname);
1.153 matthew 15477: if ($put_result !~ /^(ok|delayed)/) {
15478: &Apache::lonnet::logthis('unable to save form parameters, '.
15479: 'got error:'.$put_result);
15480: }
15481: # Make sure these settings stick around in this session, too
1.646 raeburn 15482: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15483: return;
15484: }
15485:
15486: sub restore_course_settings {
1.499 albertel 15487: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15488: }
15489:
15490: sub restore_settings {
15491: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15492: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15493: next if (exists($env{'form.'.$setting}));
1.496 albertel 15494: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15495: '.'.$setting;
1.258 albertel 15496: if (exists($env{$envname})) {
1.153 matthew 15497: if ($type eq 'scalar') {
1.258 albertel 15498: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15499: } elsif ($type eq 'array') {
1.258 albertel 15500: $env{'form.'.$setting} = [
1.153 matthew 15501: map {
1.369 www 15502: &unescape($_);
1.258 albertel 15503: } split(',',$env{$envname})
1.153 matthew 15504: ];
15505: }
15506: }
15507: }
1.127 matthew 15508: }
15509:
1.618 raeburn 15510: #######################################################
15511: #######################################################
15512:
15513: =pod
15514:
15515: =head1 Domain E-mail Routines
15516:
15517: =over 4
15518:
1.648 raeburn 15519: =item * &build_recipient_list()
1.618 raeburn 15520:
1.1144 raeburn 15521: Build recipient lists for following types of e-mail:
1.766 raeburn 15522: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15523: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15524: module change checking, student/employee ID conflict checks, as
15525: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15526: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15527:
15528: Inputs:
1.619 raeburn 15529: defmail (scalar - email address of default recipient),
1.1144 raeburn 15530: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15531: requestsmail, updatesmail, or idconflictsmail).
15532:
1.619 raeburn 15533: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15534:
1.619 raeburn 15535: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15536: i.e., predates configuration by DC via domainprefs.pm
15537:
15538: $requname username of requester (if mailing type is helpdeskmail)
15539:
15540: $requdom domain of requester (if mailing type is helpdeskmail)
15541:
15542: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15543:
1.618 raeburn 15544:
1.655 raeburn 15545: Returns: comma separated list of addresses to which to send e-mail.
15546:
15547: =back
1.618 raeburn 15548:
15549: =cut
15550:
15551: ############################################################
15552: ############################################################
15553: sub build_recipient_list {
1.1297 raeburn 15554: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15555: my @recipients;
1.1270 raeburn 15556: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15557: my %domconfig =
1.1270 raeburn 15558: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15559: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15560: if (exists($domconfig{'contacts'}{$mailing})) {
15561: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15562: my @contacts = ('adminemail','supportemail');
15563: foreach my $item (@contacts) {
15564: if ($domconfig{'contacts'}{$mailing}{$item}) {
15565: my $addr = $domconfig{'contacts'}{$item};
15566: if (!grep(/^\Q$addr\E$/,@recipients)) {
15567: push(@recipients,$addr);
15568: }
1.619 raeburn 15569: }
1.1270 raeburn 15570: }
15571: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15572: if ($mailing eq 'helpdeskmail') {
15573: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15574: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15575: my @ok_bccs;
15576: foreach my $bcc (@bccs) {
15577: $bcc =~ s/^\s+//g;
15578: $bcc =~ s/\s+$//g;
15579: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15580: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15581: push(@ok_bccs,$bcc);
15582: }
15583: }
15584: }
15585: if (@ok_bccs > 0) {
15586: $allbcc = join(', ',@ok_bccs);
15587: }
15588: }
15589: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15590: }
15591: }
1.766 raeburn 15592: } elsif ($origmail ne '') {
1.1270 raeburn 15593: $lastresort = $origmail;
1.618 raeburn 15594: }
1.1297 raeburn 15595: if ($mailing eq 'helpdeskmail') {
15596: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15597: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15598: my ($inststatus,$inststatus_checked);
15599: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15600: ($env{'user.domain'} ne 'public')) {
15601: $inststatus_checked = 1;
15602: $inststatus = $env{'environment.inststatus'};
15603: }
15604: unless ($inststatus_checked) {
15605: if (($requname ne '') && ($requdom ne '')) {
15606: if (($requname =~ /^$match_username$/) &&
15607: ($requdom =~ /^$match_domain$/) &&
15608: (&Apache::lonnet::domain($requdom))) {
15609: my $requhome = &Apache::lonnet::homeserver($requname,
15610: $requdom);
15611: unless ($requhome eq 'no_host') {
15612: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15613: $inststatus = $userenv{'inststatus'};
15614: $inststatus_checked = 1;
15615: }
15616: }
15617: }
15618: }
15619: unless ($inststatus_checked) {
15620: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15621: my %srch = (srchby => 'email',
15622: srchdomain => $defdom,
15623: srchterm => $reqemail,
15624: srchtype => 'exact');
15625: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15626: foreach my $uname (keys(%srch_results)) {
15627: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15628: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15629: $inststatus_checked = 1;
15630: last;
15631: }
15632: }
15633: unless ($inststatus_checked) {
15634: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15635: if ($dirsrchres eq 'ok') {
15636: foreach my $uname (keys(%srch_results)) {
15637: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15638: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15639: $inststatus_checked = 1;
15640: last;
15641: }
15642: }
15643: }
15644: }
15645: }
15646: }
15647: if ($inststatus ne '') {
15648: foreach my $status (split(/\:/,$inststatus)) {
15649: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15650: my @contacts = ('adminemail','supportemail');
15651: foreach my $item (@contacts) {
15652: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15653: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15654: if (!grep(/^\Q$addr\E$/,@recipients)) {
15655: push(@recipients,$addr);
15656: }
15657: }
15658: }
15659: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15660: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15661: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15662: my @ok_bccs;
15663: foreach my $bcc (@bccs) {
15664: $bcc =~ s/^\s+//g;
15665: $bcc =~ s/\s+$//g;
15666: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15667: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15668: push(@ok_bccs,$bcc);
15669: }
15670: }
15671: }
15672: if (@ok_bccs > 0) {
15673: $allbcc = join(', ',@ok_bccs);
15674: }
15675: }
15676: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15677: last;
15678: }
15679: }
15680: }
15681: }
15682: }
1.619 raeburn 15683: } elsif ($origmail ne '') {
1.1270 raeburn 15684: $lastresort = $origmail;
15685: }
1.1297 raeburn 15686: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15687: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15688: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15689: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15690: my %what = (
15691: perlvar => 1,
15692: );
15693: my $primary = &Apache::lonnet::domain($defdom,'primary');
15694: if ($primary) {
15695: my $gotaddr;
15696: my ($result,$returnhash) =
15697: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15698: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15699: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15700: $lastresort = $returnhash->{'lonSupportEMail'};
15701: $gotaddr = 1;
15702: }
15703: }
15704: unless ($gotaddr) {
15705: my $uintdom = &Apache::lonnet::internet_dom($primary);
15706: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15707: unless ($uintdom eq $intdom) {
15708: my %domconfig =
15709: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15710: if (ref($domconfig{'contacts'}) eq 'HASH') {
15711: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15712: my @contacts = ('adminemail','supportemail');
15713: foreach my $item (@contacts) {
15714: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15715: my $addr = $domconfig{'contacts'}{$item};
15716: if (!grep(/^\Q$addr\E$/,@recipients)) {
15717: push(@recipients,$addr);
15718: }
15719: }
15720: }
15721: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15722: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15723: }
15724: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15725: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15726: my @ok_bccs;
15727: foreach my $bcc (@bccs) {
15728: $bcc =~ s/^\s+//g;
15729: $bcc =~ s/\s+$//g;
15730: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15731: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15732: push(@ok_bccs,$bcc);
15733: }
15734: }
15735: }
15736: if (@ok_bccs > 0) {
15737: $allbcc = join(', ',@ok_bccs);
15738: }
15739: }
15740: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15741: }
15742: }
15743: }
15744: }
15745: }
15746: }
1.618 raeburn 15747: }
1.688 raeburn 15748: if (defined($defmail)) {
15749: if ($defmail ne '') {
15750: push(@recipients,$defmail);
15751: }
1.618 raeburn 15752: }
15753: if ($otheremails) {
1.619 raeburn 15754: my @others;
15755: if ($otheremails =~ /,/) {
15756: @others = split(/,/,$otheremails);
1.618 raeburn 15757: } else {
1.619 raeburn 15758: push(@others,$otheremails);
15759: }
15760: foreach my $addr (@others) {
15761: if (!grep(/^\Q$addr\E$/,@recipients)) {
15762: push(@recipients,$addr);
15763: }
1.618 raeburn 15764: }
15765: }
1.1298 raeburn 15766: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15767: if ((!@recipients) && ($lastresort ne '')) {
15768: push(@recipients,$lastresort);
15769: }
15770: } elsif ($lastresort ne '') {
15771: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15772: push(@recipients,$lastresort);
15773: }
15774: }
1.1271 raeburn 15775: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15776: if (wantarray) {
15777: return ($recipientlist,$allbcc,$addtext);
15778: } else {
15779: return $recipientlist;
15780: }
1.618 raeburn 15781: }
15782:
1.127 matthew 15783: ############################################################
15784: ############################################################
1.154 albertel 15785:
1.655 raeburn 15786: =pod
15787:
1.1224 musolffc 15788: =over 4
15789:
1.1223 musolffc 15790: =item * &mime_email()
15791:
15792: Sends an email with a possible attachment
15793:
15794: Inputs:
15795:
15796: =over 4
15797:
15798: from - Sender's email address
15799:
1.1343 raeburn 15800: replyto - Reply-To email address
15801:
1.1223 musolffc 15802: to - Email address of recipient
15803:
15804: subject - Subject of email
15805:
15806: body - Body of email
15807:
15808: cc_string - Carbon copy email address
15809:
15810: bcc - Blind carbon copy email address
15811:
15812: attachment_path - Path of file to be attached
15813:
15814: file_name - Name of file to be attached
15815:
15816: attachment_text - The body of an attachment of type "TEXT"
15817:
15818: =back
15819:
15820: =back
15821:
15822: =cut
15823:
15824: ############################################################
15825: ############################################################
15826:
15827: sub mime_email {
1.1343 raeburn 15828: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15829: $file_name,$attachment_text) = @_;
15830:
1.1223 musolffc 15831: my $msg = MIME::Lite->new(
15832: From => $from,
15833: To => $to,
15834: Subject => $subject,
15835: Type =>'TEXT',
15836: Data => $body,
15837: );
1.1343 raeburn 15838: if ($replyto ne '') {
15839: $msg->add("Reply-To" => $replyto);
15840: }
1.1223 musolffc 15841: if ($cc_string ne '') {
15842: $msg->add("Cc" => $cc_string);
15843: }
15844: if ($bcc ne '') {
15845: $msg->add("Bcc" => $bcc);
15846: }
15847: $msg->attr("content-type" => "text/plain");
15848: $msg->attr("content-type.charset" => "UTF-8");
15849: # Attach file if given
15850: if ($attachment_path) {
15851: unless ($file_name) {
15852: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15853: }
15854: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15855: $msg->attach(Type => $type,
15856: Path => $attachment_path,
15857: Filename => $file_name
15858: );
15859: # Otherwise attach text if given
15860: } elsif ($attachment_text) {
15861: $msg->attach(Type => 'TEXT',
15862: Data => $attachment_text);
15863: }
15864: # Send it
15865: $msg->send('sendmail');
15866: }
15867:
15868: ############################################################
15869: ############################################################
15870:
15871: =pod
15872:
1.655 raeburn 15873: =head1 Course Catalog Routines
15874:
15875: =over 4
15876:
15877: =item * &gather_categories()
15878:
15879: Converts category definitions - keys of categories hash stored in
15880: coursecategories in configuration.db on the primary library server in a
15881: domain - to an array. Also generates javascript and idx hash used to
15882: generate Domain Coordinator interface for editing Course Categories.
15883:
15884: Inputs:
1.663 raeburn 15885:
1.655 raeburn 15886: categories (reference to hash of category definitions).
1.663 raeburn 15887:
1.655 raeburn 15888: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15889: categories and subcategories).
1.663 raeburn 15890:
1.655 raeburn 15891: idx (reference to hash of counters used in Domain Coordinator interface for
15892: editing Course Categories).
1.663 raeburn 15893:
1.655 raeburn 15894: jsarray (reference to array of categories used to create Javascript arrays for
15895: Domain Coordinator interface for editing Course Categories).
15896:
15897: Returns: nothing
15898:
15899: Side effects: populates cats, idx and jsarray.
15900:
15901: =cut
15902:
15903: sub gather_categories {
15904: my ($categories,$cats,$idx,$jsarray) = @_;
15905: my %counters;
15906: my $num = 0;
15907: foreach my $item (keys(%{$categories})) {
15908: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15909: if ($container eq '' && $depth == 0) {
15910: $cats->[$depth][$categories->{$item}] = $cat;
15911: } else {
15912: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15913: }
15914: my ($escitem,$tail) = split(/:/,$item,2);
15915: if ($counters{$tail} eq '') {
15916: $counters{$tail} = $num;
15917: $num ++;
15918: }
15919: if (ref($idx) eq 'HASH') {
15920: $idx->{$item} = $counters{$tail};
15921: }
15922: if (ref($jsarray) eq 'ARRAY') {
15923: push(@{$jsarray->[$counters{$tail}]},$item);
15924: }
15925: }
15926: return;
15927: }
15928:
15929: =pod
15930:
15931: =item * &extract_categories()
15932:
15933: Used to generate breadcrumb trails for course categories.
15934:
15935: Inputs:
1.663 raeburn 15936:
1.655 raeburn 15937: categories (reference to hash of category definitions).
1.663 raeburn 15938:
1.655 raeburn 15939: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15940: categories and subcategories).
1.663 raeburn 15941:
1.655 raeburn 15942: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15943:
1.655 raeburn 15944: allitems (reference to hash - key is category key
15945: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15946:
1.655 raeburn 15947: idx (reference to hash of counters used in Domain Coordinator interface for
15948: editing Course Categories).
1.663 raeburn 15949:
1.655 raeburn 15950: jsarray (reference to array of categories used to create Javascript arrays for
15951: Domain Coordinator interface for editing Course Categories).
15952:
1.665 raeburn 15953: subcats (reference to hash of arrays containing all subcategories within each
15954: category, -recursive)
15955:
1.1321 raeburn 15956: maxd (reference to hash used to hold max depth for all top-level categories).
15957:
1.655 raeburn 15958: Returns: nothing
15959:
15960: Side effects: populates trails and allitems hash references.
15961:
15962: =cut
15963:
15964: sub extract_categories {
1.1321 raeburn 15965: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15966: if (ref($categories) eq 'HASH') {
15967: &gather_categories($categories,$cats,$idx,$jsarray);
15968: if (ref($cats->[0]) eq 'ARRAY') {
15969: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15970: my $name = $cats->[0][$i];
15971: my $item = &escape($name).'::0';
15972: my $trailstr;
15973: if ($name eq 'instcode') {
15974: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15975: } elsif ($name eq 'communities') {
15976: $trailstr = &mt('Communities');
1.1239 raeburn 15977: } elsif ($name eq 'placement') {
15978: $trailstr = &mt('Placement Tests');
1.655 raeburn 15979: } else {
15980: $trailstr = $name;
15981: }
15982: if ($allitems->{$item} eq '') {
15983: push(@{$trails},$trailstr);
15984: $allitems->{$item} = scalar(@{$trails})-1;
15985: }
15986: my @parents = ($name);
15987: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15988: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15989: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15990: if (ref($subcats) eq 'HASH') {
15991: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15992: }
1.1321 raeburn 15993: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15994: }
15995: } else {
15996: if (ref($subcats) eq 'HASH') {
15997: $subcats->{$item} = [];
1.655 raeburn 15998: }
1.1321 raeburn 15999: if (ref($maxd) eq 'HASH') {
16000: $maxd->{$name} = 1;
16001: }
1.655 raeburn 16002: }
16003: }
16004: }
16005: }
16006: return;
16007: }
16008:
16009: =pod
16010:
1.1162 raeburn 16011: =item * &recurse_categories()
1.655 raeburn 16012:
16013: Recursively used to generate breadcrumb trails for course categories.
16014:
16015: Inputs:
1.663 raeburn 16016:
1.655 raeburn 16017: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16018: categories and subcategories).
1.663 raeburn 16019:
1.655 raeburn 16020: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16021:
16022: category (current course category, for which breadcrumb trail is being generated).
16023:
16024: trails (reference to array of breadcrumb trails for each category).
16025:
1.655 raeburn 16026: allitems (reference to hash - key is category key
16027: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16028:
1.655 raeburn 16029: parents (array containing containers directories for current category,
16030: back to top level).
16031:
16032: Returns: nothing
16033:
16034: Side effects: populates trails and allitems hash references
16035:
16036: =cut
16037:
16038: sub recurse_categories {
1.1321 raeburn 16039: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16040: my $shallower = $depth - 1;
16041: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16042: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16043: my $name = $cats->[$depth]{$category}[$k];
16044: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16045: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16046: if ($allitems->{$item} eq '') {
16047: push(@{$trails},$trailstr);
16048: $allitems->{$item} = scalar(@{$trails})-1;
16049: }
16050: my $deeper = $depth+1;
16051: push(@{$parents},$category);
1.665 raeburn 16052: if (ref($subcats) eq 'HASH') {
16053: my $subcat = &escape($name).':'.$category.':'.$depth;
16054: for (my $j=@{$parents}; $j>=0; $j--) {
16055: my $higher;
16056: if ($j > 0) {
16057: $higher = &escape($parents->[$j]).':'.
16058: &escape($parents->[$j-1]).':'.$j;
16059: } else {
16060: $higher = &escape($parents->[$j]).'::'.$j;
16061: }
16062: push(@{$subcats->{$higher}},$subcat);
16063: }
16064: }
16065: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16066: $subcats,$maxd);
1.655 raeburn 16067: pop(@{$parents});
16068: }
16069: } else {
16070: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16071: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16072: if ($allitems->{$item} eq '') {
16073: push(@{$trails},$trailstr);
16074: $allitems->{$item} = scalar(@{$trails})-1;
16075: }
1.1321 raeburn 16076: if (ref($maxd) eq 'HASH') {
16077: if ($depth > $maxd->{$parents->[0]}) {
16078: $maxd->{$parents->[0]} = $depth;
16079: }
16080: }
1.655 raeburn 16081: }
16082: return;
16083: }
16084:
1.663 raeburn 16085: =pod
16086:
1.1162 raeburn 16087: =item * &assign_categories_table()
1.663 raeburn 16088:
16089: Create a datatable for display of hierarchical categories in a domain,
16090: with checkboxes to allow a course to be categorized.
16091:
16092: Inputs:
16093:
16094: cathash - reference to hash of categories defined for the domain (from
16095: configuration.db)
16096:
16097: currcat - scalar with an & separated list of categories assigned to a course.
16098:
1.919 raeburn 16099: type - scalar contains course type (Course or Community).
16100:
1.1260 raeburn 16101: disabled - scalar (optional) contains disabled="disabled" if input elements are
16102: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16103:
1.663 raeburn 16104: Returns: $output (markup to be displayed)
16105:
16106: =cut
16107:
16108: sub assign_categories_table {
1.1259 raeburn 16109: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16110: my $output;
16111: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16112: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16113: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16114: $maxdepth = scalar(@cats);
16115: if (@cats > 0) {
16116: my $itemcount = 0;
16117: if (ref($cats[0]) eq 'ARRAY') {
16118: my @currcategories;
16119: if ($currcat ne '') {
16120: @currcategories = split('&',$currcat);
16121: }
1.919 raeburn 16122: my $table;
1.663 raeburn 16123: for (my $i=0; $i<@{$cats[0]}; $i++) {
16124: my $parent = $cats[0][$i];
1.919 raeburn 16125: next if ($parent eq 'instcode');
16126: if ($type eq 'Community') {
16127: next unless ($parent eq 'communities');
1.1239 raeburn 16128: } elsif ($type eq 'Placement') {
16129: next unless ($parent eq 'placement');
1.919 raeburn 16130: } else {
1.1239 raeburn 16131: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16132: }
1.663 raeburn 16133: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16134: my $item = &escape($parent).'::0';
16135: my $checked = '';
16136: if (@currcategories > 0) {
16137: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16138: $checked = ' checked="checked"';
1.663 raeburn 16139: }
16140: }
1.919 raeburn 16141: my $parent_title = $parent;
16142: if ($parent eq 'communities') {
16143: $parent_title = &mt('Communities');
1.1239 raeburn 16144: } elsif ($parent eq 'placement') {
16145: $parent_title = &mt('Placement Tests');
1.919 raeburn 16146: }
16147: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16148: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16149: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16150: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16151: my $depth = 1;
16152: push(@path,$parent);
1.1259 raeburn 16153: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16154: pop(@path);
1.919 raeburn 16155: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16156: $itemcount ++;
16157: }
1.919 raeburn 16158: if ($itemcount) {
16159: $output = &Apache::loncommon::start_data_table().
16160: $table.
16161: &Apache::loncommon::end_data_table();
16162: }
1.663 raeburn 16163: }
16164: }
16165: }
16166: return $output;
16167: }
16168:
16169: =pod
16170:
1.1162 raeburn 16171: =item * &assign_category_rows()
1.663 raeburn 16172:
16173: Create a datatable row for display of nested categories in a domain,
16174: with checkboxes to allow a course to be categorized,called recursively.
16175:
16176: Inputs:
16177:
16178: itemcount - track row number for alternating colors
16179:
16180: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16181: categories and subcategories.
16182:
16183: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16184:
16185: parent - parent of current category item
16186:
16187: path - Array containing all categories back up through the hierarchy from the
16188: current category to the top level.
16189:
16190: currcategories - reference to array of current categories assigned to the course
16191:
1.1260 raeburn 16192: disabled - scalar (optional) contains disabled="disabled" if input elements are
16193: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16194:
1.663 raeburn 16195: Returns: $output (markup to be displayed).
16196:
16197: =cut
16198:
16199: sub assign_category_rows {
1.1259 raeburn 16200: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16201: my ($text,$name,$item,$chgstr);
16202: if (ref($cats) eq 'ARRAY') {
16203: my $maxdepth = scalar(@{$cats});
16204: if (ref($cats->[$depth]) eq 'HASH') {
16205: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16206: my $numchildren = @{$cats->[$depth]{$parent}};
16207: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16208: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16209: for (my $j=0; $j<$numchildren; $j++) {
16210: $name = $cats->[$depth]{$parent}[$j];
16211: $item = &escape($name).':'.&escape($parent).':'.$depth;
16212: my $deeper = $depth+1;
16213: my $checked = '';
16214: if (ref($currcategories) eq 'ARRAY') {
16215: if (@{$currcategories} > 0) {
16216: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16217: $checked = ' checked="checked"';
1.663 raeburn 16218: }
16219: }
16220: }
1.664 raeburn 16221: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16222: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16223: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16224: '<input type="hidden" name="catname" value="'.$name.'" />'.
16225: '</td><td>';
1.663 raeburn 16226: if (ref($path) eq 'ARRAY') {
16227: push(@{$path},$name);
1.1259 raeburn 16228: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16229: pop(@{$path});
16230: }
16231: $text .= '</td></tr>';
16232: }
16233: $text .= '</table></td>';
16234: }
16235: }
16236: }
16237: return $text;
16238: }
16239:
1.1181 raeburn 16240: =pod
16241:
16242: =back
16243:
16244: =cut
16245:
1.655 raeburn 16246: ############################################################
16247: ############################################################
16248:
16249:
1.443 albertel 16250: sub commit_customrole {
1.664 raeburn 16251: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16252: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16253: ($start?', '.&mt('starting').' '.localtime($start):'').
16254: ($end?', ending '.localtime($end):'').': <b>'.
16255: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16256: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16257: '</b><br />';
16258: return $output;
16259: }
16260:
16261: sub commit_standardrole {
1.1116 raeburn 16262: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16263: my ($output,$logmsg,$linefeed);
16264: if ($context eq 'auto') {
16265: $linefeed = "\n";
16266: } else {
16267: $linefeed = "<br />\n";
16268: }
1.443 albertel 16269: if ($three eq 'st') {
1.541 raeburn 16270: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 16271: $one,$two,$sec,$context,$credits);
1.541 raeburn 16272: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16273: ($result eq 'unknown_course') || ($result eq 'refused')) {
16274: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16275: } else {
1.541 raeburn 16276: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16277: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16278: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16279: if ($context eq 'auto') {
16280: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16281: } else {
16282: $output .= '<b>'.$result.'</b>'.$linefeed.
16283: &mt('Add to classlist').': <b>ok</b>';
16284: }
16285: $output .= $linefeed;
1.443 albertel 16286: }
16287: } else {
16288: $output = &mt('Assigning').' '.$three.' in '.$url.
16289: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16290: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16291: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16292: if ($context eq 'auto') {
16293: $output .= $result.$linefeed;
16294: } else {
16295: $output .= '<b>'.$result.'</b>'.$linefeed;
16296: }
1.443 albertel 16297: }
16298: return $output;
16299: }
16300:
16301: sub commit_studentrole {
1.1116 raeburn 16302: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16303: $credits) = @_;
1.626 raeburn 16304: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16305: if ($context eq 'auto') {
16306: $linefeed = "\n";
16307: } else {
16308: $linefeed = '<br />'."\n";
16309: }
1.443 albertel 16310: if (defined($one) && defined($two)) {
16311: my $cid=$one.'_'.$two;
16312: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16313: my $secchange = 0;
16314: my $expire_role_result;
16315: my $modify_section_result;
1.628 raeburn 16316: if ($oldsec ne '-1') {
16317: if ($oldsec ne $sec) {
1.443 albertel 16318: $secchange = 1;
1.628 raeburn 16319: my $now = time;
1.443 albertel 16320: my $uurl='/'.$cid;
16321: $uurl=~s/\_/\//g;
16322: if ($oldsec) {
16323: $uurl.='/'.$oldsec;
16324: }
1.626 raeburn 16325: $oldsecurl = $uurl;
1.628 raeburn 16326: $expire_role_result =
1.652 raeburn 16327: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 16328: if ($env{'request.course.sec'} ne '') {
16329: if ($expire_role_result eq 'refused') {
16330: my @roles = ('st');
16331: my @statuses = ('previous');
16332: my @roledoms = ($one);
16333: my $withsec = 1;
16334: my %roleshash =
16335: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16336: \@statuses,\@roles,\@roledoms,$withsec);
16337: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16338: my ($oldstart,$oldend) =
16339: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16340: if ($oldend > 0 && $oldend <= $now) {
16341: $expire_role_result = 'ok';
16342: }
16343: }
16344: }
16345: }
1.443 albertel 16346: $result = $expire_role_result;
16347: }
16348: }
16349: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16350: $modify_section_result =
16351: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16352: undef,undef,undef,$sec,
16353: $end,$start,'','',$cid,
16354: '',$context,$credits);
1.443 albertel 16355: if ($modify_section_result =~ /^ok/) {
16356: if ($secchange == 1) {
1.628 raeburn 16357: if ($sec eq '') {
16358: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16359: } else {
16360: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16361: }
1.443 albertel 16362: } elsif ($oldsec eq '-1') {
1.628 raeburn 16363: if ($sec eq '') {
16364: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16365: } else {
16366: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16367: }
1.443 albertel 16368: } else {
1.628 raeburn 16369: if ($sec eq '') {
16370: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16371: } else {
16372: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16373: }
1.443 albertel 16374: }
16375: } else {
1.1115 raeburn 16376: if ($secchange) {
1.628 raeburn 16377: $$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;
16378: } else {
16379: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16380: }
1.443 albertel 16381: }
16382: $result = $modify_section_result;
16383: } elsif ($secchange == 1) {
1.628 raeburn 16384: if ($oldsec eq '') {
1.1103 raeburn 16385: $$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 16386: } else {
16387: $$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;
16388: }
1.626 raeburn 16389: if ($expire_role_result eq 'refused') {
16390: my $newsecurl = '/'.$cid;
16391: $newsecurl =~ s/\_/\//g;
16392: if ($sec ne '') {
16393: $newsecurl.='/'.$sec;
16394: }
16395: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16396: if ($sec eq '') {
16397: $$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;
16398: } else {
16399: $$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;
16400: }
16401: }
16402: }
1.443 albertel 16403: }
16404: } else {
1.626 raeburn 16405: $$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 16406: $result = "error: incomplete course id\n";
16407: }
16408: return $result;
16409: }
16410:
1.1108 raeburn 16411: sub show_role_extent {
16412: my ($scope,$context,$role) = @_;
16413: $scope =~ s{^/}{};
16414: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16415: push(@courseroles,'co');
16416: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16417: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16418: $scope =~ s{/}{_};
16419: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16420: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16421: my ($audom,$auname) = split(/\//,$scope);
16422: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16423: &Apache::loncommon::plainname($auname,$audom).'</span>');
16424: } else {
16425: $scope =~ s{/$}{};
16426: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16427: &Apache::lonnet::domain($scope,'description').'</span>');
16428: }
16429: }
16430:
1.443 albertel 16431: ############################################################
16432: ############################################################
16433:
1.566 albertel 16434: sub check_clone {
1.578 raeburn 16435: my ($args,$linefeed) = @_;
1.566 albertel 16436: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16437: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16438: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16439: my $clonetitle;
16440: my @clonemsg;
1.566 albertel 16441: my $can_clone = 0;
1.944 raeburn 16442: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16443: if ($lctype ne 'community') {
16444: $lctype = 'course';
16445: }
1.566 albertel 16446: if ($clonehome eq 'no_host') {
1.944 raeburn 16447: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16448: push(@clonemsg,({
16449: mt => 'No new community created.',
16450: args => [],
16451: },
16452: {
16453: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16454: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16455: }));
1.908 raeburn 16456: } else {
1.1344 raeburn 16457: push(@clonemsg,({
16458: mt => 'No new course created.',
16459: args => [],
16460: },
16461: {
16462: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16463: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16464: }));
16465: }
1.566 albertel 16466: } else {
16467: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16468: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16469: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16470: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16471: push(@clonemsg,({
16472: mt => 'No new community created.',
16473: args => [],
16474: },
16475: {
16476: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16477: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16478: }));
16479: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16480: }
16481: }
1.1262 raeburn 16482: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16483: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16484: $can_clone = 1;
16485: } else {
1.1221 raeburn 16486: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16487: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16488: if ($clonehash{'cloners'} eq '') {
16489: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16490: if ($domdefs{'canclone'}) {
16491: unless ($domdefs{'canclone'} eq 'none') {
16492: if ($domdefs{'canclone'} eq 'domain') {
16493: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16494: $can_clone = 1;
16495: }
16496: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16497: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16498: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16499: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16500: $can_clone = 1;
16501: }
16502: }
16503: }
16504: }
1.578 raeburn 16505: } else {
1.1221 raeburn 16506: my @cloners = split(/,/,$clonehash{'cloners'});
16507: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16508: $can_clone = 1;
1.1221 raeburn 16509: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16510: $can_clone = 1;
1.1225 raeburn 16511: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16512: $can_clone = 1;
1.1221 raeburn 16513: }
16514: unless ($can_clone) {
1.1225 raeburn 16515: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16516: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16517: my (%gotdomdefaults,%gotcodedefaults);
16518: foreach my $cloner (@cloners) {
16519: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16520: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16521: my (%codedefaults,@code_order);
16522: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16523: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16524: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16525: }
16526: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16527: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16528: }
16529: } else {
16530: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16531: \%codedefaults,
16532: \@code_order);
16533: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16534: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16535: }
16536: if (@code_order > 0) {
16537: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16538: $cloner,$clonehash{'internal.coursecode'},
16539: $args->{'crscode'})) {
16540: $can_clone = 1;
16541: last;
16542: }
16543: }
16544: }
16545: }
16546: }
1.1225 raeburn 16547: }
16548: }
16549: unless ($can_clone) {
16550: my $ccrole = 'cc';
16551: if ($args->{'crstype'} eq 'Community') {
16552: $ccrole = 'co';
16553: }
16554: my %roleshash =
16555: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16556: $args->{'ccdomain'},
16557: 'userroles',['active'],[$ccrole],
16558: [$args->{'clonedomain'}]);
16559: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16560: $can_clone = 1;
16561: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16562: $args->{'ccuname'},$args->{'ccdomain'})) {
16563: $can_clone = 1;
1.1221 raeburn 16564: }
16565: }
16566: unless ($can_clone) {
16567: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16568: push(@clonemsg,({
16569: mt => 'No new community created.',
16570: args => [],
16571: },
16572: {
16573: 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]).',
16574: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16575: }));
1.942 raeburn 16576: } else {
1.1344 raeburn 16577: push(@clonemsg,({
16578: mt => 'No new course created.',
16579: args => [],
16580: },
16581: {
16582: 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]).',
16583: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16584: }));
1.1221 raeburn 16585: }
1.566 albertel 16586: }
1.578 raeburn 16587: }
1.566 albertel 16588: }
1.1344 raeburn 16589: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16590: }
16591:
1.444 albertel 16592: sub construct_course {
1.1262 raeburn 16593: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16594: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16595: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16596: my $linefeed = '<br />'."\n";
16597: if ($context eq 'auto') {
16598: $linefeed = "\n";
16599: }
1.566 albertel 16600:
16601: #
16602: # Are we cloning?
16603: #
1.1344 raeburn 16604: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16605: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16606: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16607: if (!$can_clone) {
1.1344 raeburn 16608: return (0,$outcome,$clonemsgref);
1.566 albertel 16609: }
16610: }
16611:
1.444 albertel 16612: #
16613: # Open course
16614: #
1.1239 raeburn 16615: my $showncrstype;
16616: if ($args->{'crstype'} eq 'Placement') {
16617: $showncrstype = 'placement test';
16618: } else {
16619: $showncrstype = lc($args->{'crstype'});
16620: }
1.444 albertel 16621: my %cenv=();
16622: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16623: $args->{'cdescr'},
16624: $args->{'curl'},
16625: $args->{'course_home'},
16626: $args->{'nonstandard'},
16627: $args->{'crscode'},
16628: $args->{'ccuname'}.':'.
16629: $args->{'ccdomain'},
1.882 raeburn 16630: $args->{'crstype'},
1.1344 raeburn 16631: $cnum,$context,$category,
16632: $callercontext);
1.444 albertel 16633:
16634: # Note: The testing routines depend on this being output; see
16635: # Utils::Course. This needs to at least be output as a comment
16636: # if anyone ever decides to not show this, and Utils::Course::new
16637: # will need to be suitably modified.
1.1344 raeburn 16638: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16639: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16640: } else {
16641: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16642: }
1.943 raeburn 16643: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16644: return (0,$outcome,$clonemsgref);
1.943 raeburn 16645: }
16646:
1.444 albertel 16647: #
16648: # Check if created correctly
16649: #
1.479 albertel 16650: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16651: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16652: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16653: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16654: $outcome .= &mt_user($user_lh,
16655: 'Course creation failed, unrecognized course home server.');
16656: } else {
16657: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16658: }
16659: $outcome .= $linefeed;
16660: return (0,$outcome,$clonemsgref);
1.943 raeburn 16661: }
1.541 raeburn 16662: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16663:
1.444 albertel 16664: #
1.566 albertel 16665: # Do the cloning
16666: #
1.1344 raeburn 16667: my @clonemsg;
1.566 albertel 16668: if ($can_clone && $cloneid) {
1.1344 raeburn 16669: push(@clonemsg,
16670: {
16671: mt => 'Created [_1] by cloning from [_2]',
16672: args => [$showncrstype,$clonetitle],
16673: });
1.566 albertel 16674: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16675: # Copy all files
1.1344 raeburn 16676: my @info =
16677: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16678: $args->{'dateshift'},$args->{'crscode'},
16679: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16680: $args->{'tinyurls'});
16681: if (@info) {
16682: push(@clonemsg,@info);
16683: }
1.444 albertel 16684: # Restore URL
1.566 albertel 16685: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16686: # Restore title
1.566 albertel 16687: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16688: # Restore creation date, creator and creation context.
16689: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16690: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16691: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16692: # Mark as cloned
1.566 albertel 16693: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16694: # Need to clone grading mode
16695: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16696: $cenv{'grading'}=$newenv{'grading'};
16697: # Do not clone these environment entries
16698: &Apache::lonnet::del('environment',
16699: ['default_enrollment_start_date',
16700: 'default_enrollment_end_date',
16701: 'question.email',
16702: 'policy.email',
16703: 'comment.email',
16704: 'pch.users.denied',
1.725 raeburn 16705: 'plc.users.denied',
16706: 'hidefromcat',
1.1121 raeburn 16707: 'checkforpriv',
1.1355 raeburn 16708: 'categories'],
1.638 www 16709: $$crsudom,$$crsunum);
1.1170 raeburn 16710: if ($args->{'textbook'}) {
16711: $cenv{'internal.textbook'} = $args->{'textbook'};
16712: }
1.444 albertel 16713: }
1.566 albertel 16714:
1.444 albertel 16715: #
16716: # Set environment (will override cloned, if existing)
16717: #
16718: my @sections = ();
16719: my @xlists = ();
16720: if ($args->{'crstype'}) {
16721: $cenv{'type'}=$args->{'crstype'};
16722: }
1.1371 raeburn 16723: if ($args->{'lti'}) {
16724: $cenv{'internal.lti'}=$args->{'lti'};
16725: }
1.444 albertel 16726: if ($args->{'crsid'}) {
16727: $cenv{'courseid'}=$args->{'crsid'};
16728: }
16729: if ($args->{'crscode'}) {
16730: $cenv{'internal.coursecode'}=$args->{'crscode'};
16731: }
16732: if ($args->{'crsquota'} ne '') {
16733: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16734: } else {
16735: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16736: }
16737: if ($args->{'ccuname'}) {
16738: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16739: ':'.$args->{'ccdomain'};
16740: } else {
16741: $cenv{'internal.courseowner'} = $args->{'curruser'};
16742: }
1.1116 raeburn 16743: if ($args->{'defaultcredits'}) {
16744: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16745: }
1.444 albertel 16746: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16747: if ($args->{'crssections'}) {
16748: $cenv{'internal.sectionnums'} = '';
16749: if ($args->{'crssections'} =~ m/,/) {
16750: @sections = split/,/,$args->{'crssections'};
16751: } else {
16752: $sections[0] = $args->{'crssections'};
16753: }
16754: if (@sections > 0) {
16755: foreach my $item (@sections) {
16756: my ($sec,$gp) = split/:/,$item;
16757: my $class = $args->{'crscode'}.$sec;
16758: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16759: $cenv{'internal.sectionnums'} .= $item.',';
16760: unless ($addcheck eq 'ok') {
1.1263 raeburn 16761: push(@badclasses,$class);
1.444 albertel 16762: }
16763: }
16764: $cenv{'internal.sectionnums'} =~ s/,$//;
16765: }
16766: }
16767: # do not hide course coordinator from staff listing,
16768: # even if privileged
16769: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16770: # add course coordinator's domain to domains to check for privileged users
16771: # if different to course domain
16772: if ($$crsudom ne $args->{'ccdomain'}) {
16773: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16774: }
1.444 albertel 16775: # add crosslistings
16776: if ($args->{'crsxlist'}) {
16777: $cenv{'internal.crosslistings'}='';
16778: if ($args->{'crsxlist'} =~ m/,/) {
16779: @xlists = split/,/,$args->{'crsxlist'};
16780: } else {
16781: $xlists[0] = $args->{'crsxlist'};
16782: }
16783: if (@xlists > 0) {
16784: foreach my $item (@xlists) {
16785: my ($xl,$gp) = split/:/,$item;
16786: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16787: $cenv{'internal.crosslistings'} .= $item.',';
16788: unless ($addcheck eq 'ok') {
1.1263 raeburn 16789: push(@badclasses,$xl);
1.444 albertel 16790: }
16791: }
16792: $cenv{'internal.crosslistings'} =~ s/,$//;
16793: }
16794: }
16795: if ($args->{'autoadds'}) {
16796: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16797: }
16798: if ($args->{'autodrops'}) {
16799: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16800: }
16801: # check for notification of enrollment changes
16802: my @notified = ();
16803: if ($args->{'notify_owner'}) {
16804: if ($args->{'ccuname'} ne '') {
16805: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16806: }
16807: }
16808: if ($args->{'notify_dc'}) {
16809: if ($uname ne '') {
1.630 raeburn 16810: push(@notified,$uname.':'.$udom);
1.444 albertel 16811: }
16812: }
16813: if (@notified > 0) {
16814: my $notifylist;
16815: if (@notified > 1) {
16816: $notifylist = join(',',@notified);
16817: } else {
16818: $notifylist = $notified[0];
16819: }
16820: $cenv{'internal.notifylist'} = $notifylist;
16821: }
16822: if (@badclasses > 0) {
16823: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16824: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16825: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16826: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16827: );
1.1264 raeburn 16828: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16829: &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 16830: if ($context eq 'auto') {
16831: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16832: } else {
1.566 albertel 16833: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16834: }
16835: foreach my $item (@badclasses) {
1.541 raeburn 16836: if ($context eq 'auto') {
1.1261 raeburn 16837: $outcome .= " - $item\n";
1.541 raeburn 16838: } else {
1.1261 raeburn 16839: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16840: }
1.1261 raeburn 16841: }
16842: if ($context eq 'auto') {
16843: $outcome .= $linefeed;
16844: } else {
16845: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16846: }
1.444 albertel 16847: }
16848: if ($args->{'no_end_date'}) {
16849: $args->{'endaccess'} = 0;
16850: }
16851: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16852: $cenv{'internal.autoend'}=$args->{'enrollend'};
16853: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16854: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16855: if ($args->{'showphotos'}) {
16856: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16857: }
16858: $cenv{'internal.authtype'} = $args->{'authtype'};
16859: $cenv{'internal.autharg'} = $args->{'autharg'};
16860: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16861: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16862: 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');
16863: if ($context eq 'auto') {
16864: $outcome .= $krb_msg;
16865: } else {
1.566 albertel 16866: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16867: }
16868: $outcome .= $linefeed;
1.444 albertel 16869: }
16870: }
16871: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16872: if ($args->{'setpolicy'}) {
16873: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16874: }
16875: if ($args->{'setcontent'}) {
16876: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16877: }
1.1251 raeburn 16878: if ($args->{'setcomment'}) {
16879: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16880: }
1.444 albertel 16881: }
16882: if ($args->{'reshome'}) {
16883: $cenv{'reshome'}=$args->{'reshome'}.'/';
16884: $cenv{'reshome'}=~s/\/+$/\//;
16885: }
16886: #
16887: # course has keyed access
16888: #
16889: if ($args->{'setkeys'}) {
16890: $cenv{'keyaccess'}='yes';
16891: }
16892: # if specified, key authority is not course, but user
16893: # only active if keyaccess is yes
16894: if ($args->{'keyauth'}) {
1.487 albertel 16895: my ($user,$domain) = split(':',$args->{'keyauth'});
16896: $user = &LONCAPA::clean_username($user);
16897: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16898: if ($user ne '' && $domain ne '') {
1.487 albertel 16899: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16900: }
16901: }
16902:
1.1166 raeburn 16903: #
1.1167 raeburn 16904: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16905: #
16906: if ($args->{'uniquecode'}) {
16907: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16908: if ($code) {
16909: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16910: my %crsinfo =
16911: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16912: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16913: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16914: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16915: }
1.1166 raeburn 16916: if (ref($coderef)) {
16917: $$coderef = $code;
16918: }
16919: }
16920: }
16921:
1.444 albertel 16922: if ($args->{'disresdis'}) {
16923: $cenv{'pch.roles.denied'}='st';
16924: }
16925: if ($args->{'disablechat'}) {
16926: $cenv{'plc.roles.denied'}='st';
16927: }
16928:
16929: # Record we've not yet viewed the Course Initialization Helper for this
16930: # course
16931: $cenv{'course.helper.not.run'} = 1;
16932: #
16933: # Use new Randomseed
16934: #
16935: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16936: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16937: #
16938: # The encryption code and receipt prefix for this course
16939: #
16940: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16941: $cenv{'internal.encpref'}=100+int(9*rand(99));
16942: #
16943: # By default, use standard grading
16944: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16945:
1.541 raeburn 16946: $outcome .= $linefeed.&mt('Setting environment').': '.
16947: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16948: #
16949: # Open all assignments
16950: #
16951: if ($args->{'openall'}) {
1.1341 raeburn 16952: my $opendate = time;
16953: if ($args->{'openallfrom'} =~ /^\d+$/) {
16954: $opendate = $args->{'openallfrom'};
16955: }
1.444 albertel 16956: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16957: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16958: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16959: $outcome .= &mt('All assignments open starting [_1]',
16960: &Apache::lonlocal::locallocaltime($opendate)).': '.
16961: &Apache::lonnet::cput
16962: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16963: }
16964: #
16965: # Set first page
16966: #
16967: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16968: || ($cloneid)) {
1.445 albertel 16969: use LONCAPA::map;
1.444 albertel 16970: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16971:
16972: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16973: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16974:
1.444 albertel 16975: $outcome .= ($fatal?$errtext:'read ok').' - ';
16976: my $title; my $url;
16977: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16978: $title=&mt('Syllabus');
1.444 albertel 16979: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16980: } else {
1.963 raeburn 16981: $title=&mt('Table of Contents');
1.444 albertel 16982: $url='/adm/navmaps';
16983: }
1.445 albertel 16984:
16985: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16986: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16987:
16988: if ($errtext) { $fatal=2; }
1.541 raeburn 16989: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16990: }
1.566 albertel 16991:
1.1237 raeburn 16992: #
16993: # Set params for Placement Tests
16994: #
1.1239 raeburn 16995: if ($args->{'crstype'} eq 'Placement') {
16996: my %storecontent;
16997: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16998: my %defaults = (
16999: buttonshide => { value => 'yes',
17000: type => 'string_yesno',},
17001: type => { value => 'randomizetry',
17002: type => 'string_questiontype',},
17003: maxtries => { value => 1,
17004: type => 'int_pos',},
17005: problemstatus => { value => 'no',
17006: type => 'string_problemstatus',},
17007: );
17008: foreach my $key (keys(%defaults)) {
17009: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17010: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17011: }
1.1237 raeburn 17012: &Apache::lonnet::cput
17013: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17014: }
17015:
1.1344 raeburn 17016: return (1,$outcome,\@clonemsg);
1.444 albertel 17017: }
17018:
1.1166 raeburn 17019: sub make_unique_code {
17020: my ($cdom,$cnum) = @_;
17021: # get lock on uniquecodes db
17022: my $lockhash = {
17023: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17024: ':'.$env{'user.domain'},
17025: };
17026: my $tries = 0;
17027: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17028: my ($code,$error);
17029:
17030: while (($gotlock ne 'ok') && ($tries<3)) {
17031: $tries ++;
17032: sleep 1;
17033: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17034: }
17035: if ($gotlock eq 'ok') {
17036: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17037: my $gotcode;
17038: my $attempts = 0;
17039: while ((!$gotcode) && ($attempts < 100)) {
17040: $code = &generate_code();
17041: if (!exists($currcodes{$code})) {
17042: $gotcode = 1;
17043: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17044: $error = 'nostore';
17045: }
17046: }
17047: $attempts ++;
17048: }
17049: my @del_lock = ($cnum."\0".'uniquecodes');
17050: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17051: } else {
17052: $error = 'nolock';
17053: }
17054: return ($code,$error);
17055: }
17056:
17057: sub generate_code {
17058: my $code;
17059: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17060: for (my $i=0; $i<6; $i++) {
17061: my $lettnum = int (rand 2);
17062: my $item = '';
17063: if ($lettnum) {
17064: $item = $letts[int( rand(18) )];
17065: } else {
17066: $item = 1+int( rand(8) );
17067: }
17068: $code .= $item;
17069: }
17070: return $code;
17071: }
17072:
1.444 albertel 17073: ############################################################
17074: ############################################################
17075:
1.1237 raeburn 17076: # Community, Course and Placement Test
1.378 raeburn 17077: sub course_type {
17078: my ($cid) = @_;
17079: if (!defined($cid)) {
17080: $cid = $env{'request.course.id'};
17081: }
1.404 albertel 17082: if (defined($env{'course.'.$cid.'.type'})) {
17083: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17084: } else {
17085: return 'Course';
1.377 raeburn 17086: }
17087: }
1.156 albertel 17088:
1.406 raeburn 17089: sub group_term {
17090: my $crstype = &course_type();
17091: my %names = (
17092: 'Course' => 'group',
1.865 raeburn 17093: 'Community' => 'group',
1.1237 raeburn 17094: 'Placement' => 'group',
1.406 raeburn 17095: );
17096: return $names{$crstype};
17097: }
17098:
1.902 raeburn 17099: sub course_types {
1.1310 raeburn 17100: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17101: my %typename = (
17102: official => 'Official course',
17103: unofficial => 'Unofficial course',
17104: community => 'Community',
1.1165 raeburn 17105: textbook => 'Textbook course',
1.1237 raeburn 17106: placement => 'Placement test',
1.1310 raeburn 17107: lti => 'LTI provider',
1.902 raeburn 17108: );
17109: return (\@types,\%typename);
17110: }
17111:
1.156 albertel 17112: sub icon {
17113: my ($file)=@_;
1.505 albertel 17114: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17115: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17116: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17117: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17118: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17119: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17120: $curfext.".gif") {
17121: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17122: $curfext.".gif";
17123: }
17124: }
1.249 albertel 17125: return &lonhttpdurl($iconname);
1.154 albertel 17126: }
1.84 albertel 17127:
1.575 albertel 17128: sub lonhttpdurl {
1.692 www 17129: #
17130: # Had been used for "small fry" static images on separate port 8080.
17131: # Modify here if lightweight http functionality desired again.
17132: # Currently eliminated due to increasing firewall issues.
17133: #
1.575 albertel 17134: my ($url)=@_;
1.692 www 17135: return $url;
1.215 albertel 17136: }
17137:
1.213 albertel 17138: sub connection_aborted {
17139: my ($r)=@_;
17140: $r->print(" ");$r->rflush();
17141: my $c = $r->connection;
17142: return $c->aborted();
17143: }
17144:
1.221 foxr 17145: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17146: # strings as 'strings'.
17147: sub escape_single {
1.221 foxr 17148: my ($input) = @_;
1.223 albertel 17149: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17150: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17151: return $input;
17152: }
1.223 albertel 17153:
1.222 foxr 17154: # Same as escape_single, but escape's "'s This
17155: # can be used for "strings"
17156: sub escape_double {
17157: my ($input) = @_;
17158: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17159: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17160: return $input;
17161: }
1.223 albertel 17162:
1.222 foxr 17163: # Escapes the last element of a full URL.
17164: sub escape_url {
17165: my ($url) = @_;
1.238 raeburn 17166: my @urlslices = split(/\//, $url,-1);
1.369 www 17167: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17168: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17169: }
1.462 albertel 17170:
1.820 raeburn 17171: sub compare_arrays {
17172: my ($arrayref1,$arrayref2) = @_;
17173: my (@difference,%count);
17174: @difference = ();
17175: %count = ();
17176: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17177: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17178: foreach my $element (keys(%count)) {
17179: if ($count{$element} == 1) {
17180: push(@difference,$element);
17181: }
17182: }
17183: }
17184: return @difference;
17185: }
17186:
1.1322 raeburn 17187: sub lon_status_items {
17188: my %defaults = (
17189: E => 100,
17190: W => 4,
17191: N => 1,
1.1324 raeburn 17192: U => 5,
1.1322 raeburn 17193: threshold => 200,
17194: sysmail => 2500,
17195: );
17196: my %names = (
17197: E => 'Errors',
17198: W => 'Warnings',
17199: N => 'Notices',
1.1324 raeburn 17200: U => 'Unsent',
1.1322 raeburn 17201: );
17202: return (\%defaults,\%names);
17203: }
17204:
1.817 bisitz 17205: # -------------------------------------------------------- Initialize user login
1.462 albertel 17206: sub init_user_environment {
1.463 albertel 17207: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17208: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17209:
17210: my $public=($username eq 'public' && $domain eq 'public');
17211:
1.1062 raeburn 17212: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 17213: my $now=time;
17214:
17215: if ($public) {
17216: my $max_public=100;
17217: my $oldest;
17218: my $oldest_time=0;
17219: for(my $next=1;$next<=$max_public;$next++) {
17220: if (-e $lonids."/publicuser_$next.id") {
17221: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17222: if ($mtime<$oldest_time || !$oldest_time) {
17223: $oldest_time=$mtime;
17224: $oldest=$next;
17225: }
17226: } else {
17227: $cookie="publicuser_$next";
17228: last;
17229: }
17230: }
17231: if (!$cookie) { $cookie="publicuser_$oldest"; }
17232: } else {
1.1275 raeburn 17233: # See if old ID present, if so, remove if this isn't a robot,
17234: # killing any existing non-robot sessions
1.463 albertel 17235: if (!$args->{'robot'}) {
17236: opendir(DIR,$lonids);
17237: while ($filename=readdir(DIR)) {
17238: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17239: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17240: &GDBM_READER(),0640)) {
1.1295 raeburn 17241: my $linkedfile;
1.1320 raeburn 17242: if (exists($oldenv{'user.linkedenv'})) {
17243: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17244: }
1.1320 raeburn 17245: untie(%oldenv);
17246: if (unlink("$lonids/$filename")) {
17247: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17248: if (-l "$lonids/$linkedfile.id") {
17249: unlink("$lonids/$linkedfile.id");
17250: }
1.1295 raeburn 17251: }
17252: }
17253: } else {
17254: unlink($lonids.'/'.$filename);
17255: }
1.463 albertel 17256: }
1.462 albertel 17257: }
1.463 albertel 17258: closedir(DIR);
1.1204 raeburn 17259: # If there is a undeleted lockfile for the user's paste buffer remove it.
17260: my $namespace = 'nohist_courseeditor';
17261: my $lockingkey = 'paste'."\0".'locked_num';
17262: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17263: $domain,$username);
17264: if (exists($lockhash{$lockingkey})) {
17265: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17266: unless ($delresult eq 'ok') {
17267: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17268: }
17269: }
1.462 albertel 17270: }
17271: # Give them a new cookie
1.463 albertel 17272: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17273: : $now.$$.int(rand(10000)));
1.463 albertel 17274: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17275:
17276: # Initialize roles
17277:
1.1062 raeburn 17278: ($userroles,$firstaccenv,$timerintenv) =
17279: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17280: }
17281: # ------------------------------------ Check browser type and MathML capability
17282:
1.1194 raeburn 17283: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17284: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17285:
17286: # ------------------------------------------------------------- Get environment
17287:
17288: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17289: my ($tmp) = keys(%userenv);
1.1275 raeburn 17290: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17291: undef(%userenv);
17292: }
17293: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17294: $form->{'interface'}=$userenv{'interface'};
17295: }
17296: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17297:
17298: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17299: foreach my $option ('interface','localpath','localres') {
17300: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17301: }
17302: # --------------------------------------------------------- Write first profile
17303:
17304: {
1.1350 raeburn 17305: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17306: my %initial_env =
17307: ("user.name" => $username,
17308: "user.domain" => $domain,
17309: "user.home" => $authhost,
17310: "browser.type" => $clientbrowser,
17311: "browser.version" => $clientversion,
17312: "browser.mathml" => $clientmathml,
17313: "browser.unicode" => $clientunicode,
17314: "browser.os" => $clientos,
1.1137 raeburn 17315: "browser.mobile" => $clientmobile,
1.1141 raeburn 17316: "browser.info" => $clientinfo,
1.1194 raeburn 17317: "browser.osversion" => $clientosversion,
1.462 albertel 17318: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17319: "request.course.fn" => '',
17320: "request.course.uri" => '',
17321: "request.course.sec" => '',
17322: "request.role" => 'cm',
17323: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17324: "request.host" => $ip,);
1.462 albertel 17325:
17326: if ($form->{'localpath'}) {
17327: $initial_env{"browser.localpath"} = $form->{'localpath'};
17328: $initial_env{"browser.localres"} = $form->{'localres'};
17329: }
17330:
17331: if ($form->{'interface'}) {
17332: $form->{'interface'}=~s/\W//gs;
17333: $initial_env{"browser.interface"} = $form->{'interface'};
17334: $env{'browser.interface'}=$form->{'interface'};
17335: }
17336:
1.1157 raeburn 17337: if ($form->{'iptoken'}) {
17338: my $lonhost = $r->dir_config('lonHostID');
17339: $initial_env{"user.noloadbalance"} = $lonhost;
17340: $env{'user.noloadbalance'} = $lonhost;
17341: }
17342:
1.1268 raeburn 17343: if ($form->{'noloadbalance'}) {
17344: my @hosts = &Apache::lonnet::current_machine_ids();
17345: my $hosthere = $form->{'noloadbalance'};
17346: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17347: $initial_env{"user.noloadbalance"} = $hosthere;
17348: $env{'user.noloadbalance'} = $hosthere;
17349: }
17350: }
17351:
1.1016 raeburn 17352: unless ($domain eq 'public') {
1.1273 raeburn 17353: my %is_adv = ( is_adv => $env{'user.adv'} );
17354: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17355:
17356: foreach my $tool ('aboutme','blog','webdav','portfolio') {
17357: $userenv{'availabletools.'.$tool} =
17358: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17359: undef,\%userenv,\%domdef,\%is_adv);
17360: }
1.980 raeburn 17361:
1.1311 raeburn 17362: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17363: $userenv{'canrequest.'.$crstype} =
17364: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17365: 'reload','requestcourses',
17366: \%userenv,\%domdef,\%is_adv);
17367: }
1.724 raeburn 17368:
1.1273 raeburn 17369: $userenv{'canrequest.author'} =
17370: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17371: 'reload','requestauthor',
1.980 raeburn 17372: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17373: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17374: $domain,$username);
17375: my $reqstatus = $reqauthor{'author_status'};
17376: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17377: if (ref($reqauthor{'author'}) eq 'HASH') {
17378: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17379: $reqauthor{'author'}{'timestamp'};
17380: }
1.1092 raeburn 17381: }
1.1287 raeburn 17382: my ($types,$typename) = &course_types();
17383: if (ref($types) eq 'ARRAY') {
17384: my @options = ('approval','validate','autolimit');
17385: my $optregex = join('|',@options);
17386: my (%willtrust,%trustchecked);
17387: foreach my $type (@{$types}) {
17388: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17389: if ($dom_str ne '') {
17390: my $updatedstr = '';
17391: my @possdomains = split(',',$dom_str);
17392: foreach my $entry (@possdomains) {
17393: my ($extdom,$extopt) = split(':',$entry);
17394: unless ($trustchecked{$extdom}) {
17395: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17396: $trustchecked{$extdom} = 1;
17397: }
17398: if ($willtrust{$extdom}) {
17399: $updatedstr .= $entry.',';
17400: }
17401: }
17402: $updatedstr =~ s/,$//;
17403: if ($updatedstr) {
17404: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17405: } else {
17406: delete($userenv{'reqcrsotherdom.'.$type});
17407: }
17408: }
17409: }
17410: }
1.1092 raeburn 17411: }
1.462 albertel 17412: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17413:
1.462 albertel 17414: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17415: &GDBM_WRCREAT(),0640)) {
17416: &_add_to_env(\%disk_env,\%initial_env);
17417: &_add_to_env(\%disk_env,\%userenv,'environment.');
17418: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17419: if (ref($firstaccenv) eq 'HASH') {
17420: &_add_to_env(\%disk_env,$firstaccenv);
17421: }
17422: if (ref($timerintenv) eq 'HASH') {
17423: &_add_to_env(\%disk_env,$timerintenv);
17424: }
1.463 albertel 17425: if (ref($args->{'extra_env'})) {
17426: &_add_to_env(\%disk_env,$args->{'extra_env'});
17427: }
1.462 albertel 17428: untie(%disk_env);
17429: } else {
1.705 tempelho 17430: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17431: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17432: return 'error: '.$!;
17433: }
17434: }
17435: $env{'request.role'}='cm';
17436: $env{'request.role.adv'}=$env{'user.adv'};
17437: $env{'browser.type'}=$clientbrowser;
17438:
17439: return $cookie;
17440:
17441: }
17442:
17443: sub _add_to_env {
17444: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17445: if (ref($env_data) eq 'HASH') {
17446: while (my ($key,$value) = each(%$env_data)) {
17447: $idf->{$prefix.$key} = $value;
17448: $env{$prefix.$key} = $value;
17449: }
1.462 albertel 17450: }
17451: }
17452:
1.685 tempelho 17453: # --- Get the symbolic name of a problem and the url
17454: sub get_symb {
17455: my ($request,$silent) = @_;
1.726 raeburn 17456: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17457: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17458: if ($symb eq '') {
17459: if (!$silent) {
1.1071 raeburn 17460: if (ref($request)) {
17461: $request->print("Unable to handle ambiguous references:$url:.");
17462: }
1.685 tempelho 17463: return ();
17464: }
17465: }
17466: &Apache::lonenc::check_decrypt(\$symb);
17467: return ($symb);
17468: }
17469:
17470: # --------------------------------------------------------------Get annotation
17471:
17472: sub get_annotation {
17473: my ($symb,$enc) = @_;
17474:
17475: my $key = $symb;
17476: if (!$enc) {
17477: $key =
17478: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17479: }
17480: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17481: return $annotation{$key};
17482: }
17483:
17484: sub clean_symb {
1.731 raeburn 17485: my ($symb,$delete_enc) = @_;
1.685 tempelho 17486:
17487: &Apache::lonenc::check_decrypt(\$symb);
17488: my $enc = $env{'request.enc'};
1.731 raeburn 17489: if ($delete_enc) {
1.730 raeburn 17490: delete($env{'request.enc'});
17491: }
1.685 tempelho 17492:
17493: return ($symb,$enc);
17494: }
1.462 albertel 17495:
1.1181 raeburn 17496: ############################################################
17497: ############################################################
17498:
17499: =pod
17500:
17501: =head1 Routines for building display used to search for courses
17502:
17503:
17504: =over 4
17505:
17506: =item * &build_filters()
17507:
17508: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17509: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17510: and quotacheck.pl
17511:
1.1181 raeburn 17512:
17513: Inputs:
17514:
17515: filterlist - anonymous array of fields to include as potential filters
17516:
17517: crstype - course type
17518:
17519: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17520: to pop-open a course selector (will contain "extra element").
17521:
17522: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17523:
17524: filter - anonymous hash of criteria and their values
17525:
17526: action - form action
17527:
17528: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17529:
1.1182 raeburn 17530: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17531:
17532: cloneruname - username of owner of new course who wants to clone
17533:
17534: clonerudom - domain of owner of new course who wants to clone
17535:
17536: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17537:
17538: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17539:
17540: codedom - domain
17541:
17542: formname - value of form element named "form".
17543:
17544: fixeddom - domain, if fixed.
17545:
17546: prevphase - value to assign to form element named "phase" when going back to the previous screen
17547:
17548: cnameelement - name of form element in form on opener page which will receive title of selected course
17549:
17550: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17551:
17552: cdomelement - name of form element in form on opener page which will receive domain of selected course
17553:
17554: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17555:
17556: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17557:
17558: clonewarning - warning message about missing information for intended course owner when DC creates a course
17559:
1.1182 raeburn 17560:
1.1181 raeburn 17561: Returns: $output - HTML for display of search criteria, and hidden form elements.
17562:
1.1182 raeburn 17563:
1.1181 raeburn 17564: Side Effects: None
17565:
17566: =cut
17567:
17568: # ---------------------------------------------- search for courses based on last activity etc.
17569:
17570: sub build_filters {
17571: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17572: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17573: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17574: $cnameelement,$cnumelement,$cdomelement,$setroles,
17575: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17576: my ($list,$jscript);
1.1181 raeburn 17577: my $onchange = 'javascript:updateFilters(this)';
17578: my ($domainselectform,$sincefilterform,$createdfilterform,
17579: $ownerdomselectform,$persondomselectform,$instcodeform,
17580: $typeselectform,$instcodetitle);
17581: if ($formname eq '') {
17582: $formname = $caller;
17583: }
17584: foreach my $item (@{$filterlist}) {
17585: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17586: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17587: if ($item eq 'domainfilter') {
17588: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17589: } elsif ($item eq 'coursefilter') {
17590: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17591: } elsif ($item eq 'ownerfilter') {
17592: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17593: } elsif ($item eq 'ownerdomfilter') {
17594: $filter->{'ownerdomfilter'} =
17595: &LONCAPA::clean_domain($filter->{$item});
17596: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17597: 'ownerdomfilter',1);
17598: } elsif ($item eq 'personfilter') {
17599: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17600: } elsif ($item eq 'persondomfilter') {
17601: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17602: 'persondomfilter',1);
17603: } else {
17604: $filter->{$item} =~ s/\W//g;
17605: }
17606: if (!$filter->{$item}) {
17607: $filter->{$item} = '';
17608: }
17609: }
17610: if ($item eq 'domainfilter') {
17611: my $allow_blank = 1;
17612: if ($formname eq 'portform') {
17613: $allow_blank=0;
17614: } elsif ($formname eq 'studentform') {
17615: $allow_blank=0;
17616: }
17617: if ($fixeddom) {
17618: $domainselectform = '<input type="hidden" name="domainfilter"'.
17619: ' value="'.$codedom.'" />'.
17620: &Apache::lonnet::domain($codedom,'description');
17621: } else {
17622: $domainselectform = &select_dom_form($filter->{$item},
17623: 'domainfilter',
17624: $allow_blank,'',$onchange);
17625: }
17626: } else {
17627: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17628: }
17629: }
17630:
17631: # last course activity filter and selection
17632: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17633:
17634: # course created filter and selection
17635: if (exists($filter->{'createdfilter'})) {
17636: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17637: }
17638:
1.1239 raeburn 17639: my $prefix = $crstype;
17640: if ($crstype eq 'Placement') {
17641: $prefix = 'Placement Test'
17642: }
1.1181 raeburn 17643: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17644: 'cac' => "$prefix Activity",
17645: 'ccr' => "$prefix Created",
17646: 'cde' => "$prefix Title",
17647: 'cdo' => "$prefix Domain",
1.1181 raeburn 17648: 'ins' => 'Institutional Code',
17649: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17650: 'cow' => "$prefix Owner/Co-owner",
17651: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17652: 'cog' => 'Type',
17653: );
17654:
17655: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17656: my $typeval = 'Course';
17657: if ($crstype eq 'Community') {
17658: $typeval = 'Community';
1.1239 raeburn 17659: } elsif ($crstype eq 'Placement') {
17660: $typeval = 'Placement';
1.1181 raeburn 17661: }
17662: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17663: } else {
17664: $typeselectform = '<select name="type" size="1"';
17665: if ($onchange) {
17666: $typeselectform .= ' onchange="'.$onchange.'"';
17667: }
17668: $typeselectform .= '>'."\n";
1.1237 raeburn 17669: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17670: my $shown;
17671: if ($posstype eq 'Placement') {
17672: $shown = &mt('Placement Test');
17673: } else {
17674: $shown = &mt($posstype);
17675: }
1.1181 raeburn 17676: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17677: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17678: }
17679: $typeselectform.="</select>";
17680: }
17681:
17682: my ($cloneableonlyform,$cloneabletitle);
17683: if (exists($filter->{'cloneableonly'})) {
17684: my $cloneableon = '';
17685: my $cloneableoff = ' checked="checked"';
17686: if ($filter->{'cloneableonly'}) {
17687: $cloneableon = $cloneableoff;
17688: $cloneableoff = '';
17689: }
17690: $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>';
17691: if ($formname eq 'ccrs') {
1.1187 bisitz 17692: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17693: } else {
17694: $cloneabletitle = &mt('Cloneable by you');
17695: }
17696: }
17697: my $officialjs;
17698: if ($crstype eq 'Course') {
17699: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17700: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17701: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17702: if ($codedom) {
1.1181 raeburn 17703: $officialjs = 1;
17704: ($instcodeform,$jscript,$$numtitlesref) =
17705: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17706: $officialjs,$codetitlesref);
17707: if ($jscript) {
1.1182 raeburn 17708: $jscript = '<script type="text/javascript">'."\n".
17709: '// <![CDATA['."\n".
17710: $jscript."\n".
17711: '// ]]>'."\n".
17712: '</script>'."\n";
1.1181 raeburn 17713: }
17714: }
17715: if ($instcodeform eq '') {
17716: $instcodeform =
17717: '<input type="text" name="instcodefilter" size="10" value="'.
17718: $list->{'instcodefilter'}.'" />';
17719: $instcodetitle = $lt{'ins'};
17720: } else {
17721: $instcodetitle = $lt{'inc'};
17722: }
17723: if ($fixeddom) {
17724: $instcodetitle .= '<br />('.$codedom.')';
17725: }
17726: }
17727: }
17728: my $output = qq|
17729: <form method="post" name="filterpicker" action="$action">
17730: <input type="hidden" name="form" value="$formname" />
17731: |;
17732: if ($formname eq 'modifycourse') {
17733: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17734: '<input type="hidden" name="prevphase" value="'.
17735: $prevphase.'" />'."\n";
1.1198 musolffc 17736: } elsif ($formname eq 'quotacheck') {
17737: $output .= qq|
17738: <input type="hidden" name="sortby" value="" />
17739: <input type="hidden" name="sortorder" value="" />
17740: |;
17741: } else {
1.1181 raeburn 17742: my $name_input;
17743: if ($cnameelement ne '') {
17744: $name_input = '<input type="hidden" name="cnameelement" value="'.
17745: $cnameelement.'" />';
17746: }
17747: $output .= qq|
1.1182 raeburn 17748: <input type="hidden" name="cnumelement" value="$cnumelement" />
17749: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17750: $name_input
17751: $roleelement
17752: $multelement
17753: $typeelement
17754: |;
17755: if ($formname eq 'portform') {
17756: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17757: }
17758: }
17759: if ($fixeddom) {
17760: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17761: }
17762: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17763: if ($sincefilterform) {
17764: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17765: .$sincefilterform
17766: .&Apache::lonhtmlcommon::row_closure();
17767: }
17768: if ($createdfilterform) {
17769: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17770: .$createdfilterform
17771: .&Apache::lonhtmlcommon::row_closure();
17772: }
17773: if ($domainselectform) {
17774: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17775: .$domainselectform
17776: .&Apache::lonhtmlcommon::row_closure();
17777: }
17778: if ($typeselectform) {
17779: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17780: $output .= $typeselectform;
17781: } else {
17782: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17783: .$typeselectform
17784: .&Apache::lonhtmlcommon::row_closure();
17785: }
17786: }
17787: if ($instcodeform) {
17788: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17789: .$instcodeform
17790: .&Apache::lonhtmlcommon::row_closure();
17791: }
17792: if (exists($filter->{'ownerfilter'})) {
17793: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17794: '<table><tr><td>'.&mt('Username').'<br />'.
17795: '<input type="text" name="ownerfilter" size="20" value="'.
17796: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17797: $ownerdomselectform.'</td></tr></table>'.
17798: &Apache::lonhtmlcommon::row_closure();
17799: }
17800: if (exists($filter->{'personfilter'})) {
17801: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17802: '<table><tr><td>'.&mt('Username').'<br />'.
17803: '<input type="text" name="personfilter" size="20" value="'.
17804: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17805: $persondomselectform.'</td></tr></table>'.
17806: &Apache::lonhtmlcommon::row_closure();
17807: }
17808: if (exists($filter->{'coursefilter'})) {
17809: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17810: .'<input type="text" name="coursefilter" size="25" value="'
17811: .$list->{'coursefilter'}.'" />'
17812: .&Apache::lonhtmlcommon::row_closure();
17813: }
17814: if ($cloneableonlyform) {
17815: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17816: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17817: }
17818: if (exists($filter->{'descriptfilter'})) {
17819: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17820: .'<input type="text" name="descriptfilter" size="40" value="'
17821: .$list->{'descriptfilter'}.'" />'
17822: .&Apache::lonhtmlcommon::row_closure(1);
17823: }
17824: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17825: '<input type="hidden" name="updater" value="" />'."\n".
17826: '<input type="submit" name="gosearch" value="'.
17827: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17828: return $jscript.$clonewarning.$output;
17829: }
17830:
17831: =pod
17832:
17833: =item * &timebased_select_form()
17834:
1.1182 raeburn 17835: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17836: filter e.g., Course Activity, Course Created, when searching for courses
17837: or communities
17838:
17839: Inputs:
17840:
17841: item - name of form element (sincefilter or createdfilter)
17842:
17843: filter - anonymous hash of criteria and their values
17844:
17845: Returns: HTML for a select box contained a blank, then six time selections,
17846: with value set in incoming form variables currently selected.
17847:
17848: Side Effects: None
17849:
17850: =cut
17851:
17852: sub timebased_select_form {
17853: my ($item,$filter) = @_;
17854: if (ref($filter) eq 'HASH') {
17855: $filter->{$item} =~ s/[^\d-]//g;
17856: if (!$filter->{$item}) { $filter->{$item}=-1; }
17857: return &select_form(
17858: $filter->{$item},
17859: $item,
17860: { '-1' => '',
17861: '86400' => &mt('today'),
17862: '604800' => &mt('last week'),
17863: '2592000' => &mt('last month'),
17864: '7776000' => &mt('last three months'),
17865: '15552000' => &mt('last six months'),
17866: '31104000' => &mt('last year'),
17867: 'select_form_order' =>
17868: ['-1','86400','604800','2592000','7776000',
17869: '15552000','31104000']});
17870: }
17871: }
17872:
17873: =pod
17874:
17875: =item * &js_changer()
17876:
17877: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17878: when course type or domain is changed, and also to hide 'Searching ...' on
17879: page load completion for page showing search result.
1.1181 raeburn 17880:
17881: Inputs: None
17882:
1.1183 raeburn 17883: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17884:
17885: Side Effects: None
17886:
17887: =cut
17888:
17889: sub js_changer {
17890: return <<ENDJS;
17891: <script type="text/javascript">
17892: // <![CDATA[
17893: function updateFilters(caller) {
17894: if (typeof(caller) != "undefined") {
17895: document.filterpicker.updater.value = caller.name;
17896: }
17897: document.filterpicker.submit();
17898: }
1.1183 raeburn 17899:
17900: function hideSearching() {
17901: if (document.getElementById('searching')) {
17902: document.getElementById('searching').style.display = 'none';
17903: }
17904: return;
17905: }
17906:
1.1181 raeburn 17907: // ]]>
17908: </script>
17909:
17910: ENDJS
17911: }
17912:
17913: =pod
17914:
1.1182 raeburn 17915: =item * &search_courses()
17916:
17917: Process selected filters form course search form and pass to lonnet::courseiddump
17918: to retrieve a hash for which keys are courseIDs which match the selected filters.
17919:
17920: Inputs:
17921:
17922: dom - domain being searched
17923:
17924: type - course type ('Course' or 'Community' or '.' if any).
17925:
17926: filter - anonymous hash of criteria and their values
17927:
17928: numtitles - for institutional codes - number of categories
17929:
17930: cloneruname - optional username of new course owner
17931:
17932: clonerudom - optional domain of new course owner
17933:
1.1221 raeburn 17934: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17935: (used when DC is using course creation form)
17936:
17937: codetitles - reference to array of titles of components in institutional codes (official courses).
17938:
1.1221 raeburn 17939: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17940: (and so can clone automatically)
17941:
17942: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17943:
17944: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17945: courses to clone
1.1182 raeburn 17946:
17947: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17948:
17949:
17950: Side Effects: None
17951:
17952: =cut
17953:
17954:
17955: sub search_courses {
1.1221 raeburn 17956: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17957: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17958: my (%courses,%showcourses,$cloner);
17959: if (($filter->{'ownerfilter'} ne '') ||
17960: ($filter->{'ownerdomfilter'} ne '')) {
17961: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17962: $filter->{'ownerdomfilter'};
17963: }
17964: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17965: if (!$filter->{$item}) {
17966: $filter->{$item}='.';
17967: }
17968: }
17969: my $now = time;
17970: my $timefilter =
17971: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17972: my ($createdbefore,$createdafter);
17973: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17974: $createdbefore = $now;
17975: $createdafter = $now-$filter->{'createdfilter'};
17976: }
17977: my ($instcodefilter,$regexpok);
17978: if ($numtitles) {
17979: if ($env{'form.official'} eq 'on') {
17980: $instcodefilter =
17981: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17982: $regexpok = 1;
17983: } elsif ($env{'form.official'} eq 'off') {
17984: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17985: unless ($instcodefilter eq '') {
17986: $regexpok = -1;
17987: }
17988: }
17989: } else {
17990: $instcodefilter = $filter->{'instcodefilter'};
17991: }
17992: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17993: if ($type eq '') { $type = '.'; }
17994:
17995: if (($clonerudom ne '') && ($cloneruname ne '')) {
17996: $cloner = $cloneruname.':'.$clonerudom;
17997: }
17998: %courses = &Apache::lonnet::courseiddump($dom,
17999: $filter->{'descriptfilter'},
18000: $timefilter,
18001: $instcodefilter,
18002: $filter->{'combownerfilter'},
18003: $filter->{'coursefilter'},
18004: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18005: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18006: $filter->{'cloneableonly'},
18007: $createdbefore,$createdafter,undef,
1.1221 raeburn 18008: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18009: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18010: my $ccrole;
18011: if ($type eq 'Community') {
18012: $ccrole = 'co';
18013: } else {
18014: $ccrole = 'cc';
18015: }
18016: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18017: $filter->{'persondomfilter'},
18018: 'userroles',undef,
18019: [$ccrole,'in','ad','ep','ta','cr'],
18020: $dom);
18021: foreach my $role (keys(%rolehash)) {
18022: my ($cnum,$cdom,$courserole) = split(':',$role);
18023: my $cid = $cdom.'_'.$cnum;
18024: if (exists($courses{$cid})) {
18025: if (ref($courses{$cid}) eq 'HASH') {
18026: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18027: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18028: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18029: }
18030: } else {
18031: $courses{$cid}{roles} = [$courserole];
18032: }
18033: $showcourses{$cid} = $courses{$cid};
18034: }
18035: }
18036: }
18037: %courses = %showcourses;
18038: }
18039: return %courses;
18040: }
18041:
18042: =pod
18043:
1.1181 raeburn 18044: =back
18045:
1.1207 raeburn 18046: =head1 Routines for version requirements for current course.
18047:
18048: =over 4
18049:
18050: =item * &check_release_required()
18051:
18052: Compares required LON-CAPA version with version on server, and
18053: if required version is newer looks for a server with the required version.
18054:
18055: Looks first at servers in user's owen domain; if none suitable, looks at
18056: servers in course's domain are permitted to host sessions for user's domain.
18057:
18058: Inputs:
18059:
18060: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18061:
18062: $courseid - Course ID of current course
18063:
18064: $rolecode - User's current role in course (for switchserver query string).
18065:
18066: $required - LON-CAPA version needed by course (format: Major.Minor).
18067:
18068:
18069: Returns:
18070:
18071: $switchserver - query string tp append to /adm/switchserver call (if
18072: current server's LON-CAPA version is too old.
18073:
18074: $warning - Message is displayed if no suitable server could be found.
18075:
18076: =cut
18077:
18078: sub check_release_required {
18079: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18080: my ($switchserver,$warning);
18081: if ($required ne '') {
18082: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18083: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18084: if ($reqdmajor ne '' && $reqdminor ne '') {
18085: my $otherserver;
18086: if (($major eq '' && $minor eq '') ||
18087: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18088: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18089: my $switchlcrev =
18090: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18091: $userdomserver);
18092: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18093: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18094: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18095: my $cdom = $env{'course.'.$courseid.'.domain'};
18096: if ($cdom ne $env{'user.domain'}) {
18097: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18098: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18099: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18100: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18101: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18102: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18103: my $canhost =
18104: &Apache::lonnet::can_host_session($env{'user.domain'},
18105: $coursedomserver,
18106: $remoterev,
18107: $udomdefaults{'remotesessions'},
18108: $defdomdefaults{'hostedsessions'});
18109:
18110: if ($canhost) {
18111: $otherserver = $coursedomserver;
18112: } else {
18113: $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.");
18114: }
18115: } else {
18116: $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).");
18117: }
18118: } else {
18119: $otherserver = $userdomserver;
18120: }
18121: }
18122: if ($otherserver ne '') {
18123: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18124: }
18125: }
18126: }
18127: return ($switchserver,$warning);
18128: }
18129:
18130: =pod
18131:
18132: =item * &check_release_result()
18133:
18134: Inputs:
18135:
18136: $switchwarning - Warning message if no suitable server found to host session.
18137:
18138: $switchserver - query string to append to /adm/switchserver containing lonHostID
18139: and current role.
18140:
18141: Returns: HTML to display with information about requirement to switch server.
18142: Either displaying warning with link to Roles/Courses screen or
18143: display link to switchserver.
18144:
1.1181 raeburn 18145: =cut
18146:
1.1207 raeburn 18147: sub check_release_result {
18148: my ($switchwarning,$switchserver) = @_;
18149: my $output = &start_page('Selected course unavailable on this server').
18150: '<p class="LC_warning">';
18151: if ($switchwarning) {
18152: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18153: if (&show_course()) {
18154: $output .= &mt('Display courses');
18155: } else {
18156: $output .= &mt('Display roles');
18157: }
18158: $output .= '</a>';
18159: } elsif ($switchserver) {
18160: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18161: '<br />'.
18162: '<a href="/adm/switchserver?'.$switchserver.'">'.
18163: &mt('Switch Server').
18164: '</a>';
18165: }
18166: $output .= '</p>'.&end_page();
18167: return $output;
18168: }
18169:
18170: =pod
18171:
18172: =item * &needs_coursereinit()
18173:
18174: Determine if course contents stored for user's session needs to be
18175: refreshed, because content has changed since "Big Hash" last tied.
18176:
18177: Check for change is made if time last checked is more than 10 minutes ago
18178: (by default).
18179:
18180: Inputs:
18181:
18182: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18183:
18184: $interval (optional) - Time which may elapse (in s) between last check for content
18185: change in current course. (default: 600 s).
18186:
18187: Returns: an array; first element is:
18188:
18189: =over 4
18190:
18191: 'switch' - if content updates mean user's session
18192: needs to be switched to a server running a newer LON-CAPA version
18193:
18194: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18195: on current server hosting user's session
18196:
18197: '' - if no action required.
18198:
18199: =back
18200:
18201: If first item element is 'switch':
18202:
18203: second item is $switchwarning - Warning message if no suitable server found to host session.
18204:
18205: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18206: and current role.
18207:
18208: otherwise: no other elements returned.
18209:
18210: =back
18211:
18212: =cut
18213:
18214: sub needs_coursereinit {
18215: my ($loncaparev,$interval) = @_;
18216: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18217: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18218: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18219: my $now = time;
18220: if ($interval eq '') {
18221: $interval = 600;
18222: }
18223: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18224: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18225: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18226: if ($blocked) {
18227: return ();
18228: }
1.1207 raeburn 18229: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18230: if ($lastchange > $env{'request.course.tied'}) {
18231: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18232: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18233: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18234: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18235: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18236: $curr_reqd_hash{'internal.releaserequired'}});
18237: my ($switchserver,$switchwarning) =
18238: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18239: $curr_reqd_hash{'internal.releaserequired'});
18240: if ($switchwarning ne '' || $switchserver ne '') {
18241: return ('switch',$switchwarning,$switchserver);
18242: }
18243: }
18244: }
18245: return ('update');
18246: }
18247: }
18248: return ();
18249: }
1.1181 raeburn 18250:
1.1083 raeburn 18251: sub update_content_constraints {
1.1326 raeburn 18252: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 18253: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18254: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18255: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18256: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18257: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18258: if ($item eq 'resourcetag') {
18259: if ($name eq 'responsetype') {
18260: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18261: }
1.1307 raeburn 18262: } elsif ($item eq 'course') {
18263: if ($name eq 'courserestype') {
18264: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18265: }
1.1083 raeburn 18266: }
18267: }
18268: my $navmap = Apache::lonnavmaps::navmap->new();
18269: if (defined($navmap)) {
1.1307 raeburn 18270: my (%allresponses,%allcrsrestypes);
18271: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18272: if ($res->is_tool()) {
18273: if ($allcrsrestypes{'exttool'}) {
18274: $allcrsrestypes{'exttool'} ++;
18275: } else {
18276: $allcrsrestypes{'exttool'} = 1;
18277: }
18278: next;
18279: }
1.1083 raeburn 18280: my %responses = $res->responseTypes();
18281: foreach my $key (keys(%responses)) {
18282: next unless(exists($checkresponsetypes{$key}));
18283: $allresponses{$key} += $responses{$key};
18284: }
18285: }
18286: foreach my $key (keys(%allresponses)) {
18287: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18288: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18289: ($reqdmajor,$reqdminor) = ($major,$minor);
18290: }
18291: }
1.1307 raeburn 18292: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18293: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18294: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18295: ($reqdmajor,$reqdminor) = ($major,$minor);
18296: }
18297: }
1.1083 raeburn 18298: undef($navmap);
18299: }
1.1326 raeburn 18300: my (@resources,@order,@resparms,@zombies);
18301: if ($keeporder) {
18302: use LONCAPA::map;
18303: @resources = @LONCAPA::map::resources;
18304: @order = @LONCAPA::map::order;
18305: @resparms = @LONCAPA::map::resparms;
18306: @zombies = @LONCAPA::map::zombies;
18307: }
1.1308 raeburn 18308: my $suppmap = 'supplemental.sequence';
18309: my ($suppcount,$supptools,$errors) = (0,0,0);
18310: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
18311: $suppcount,$supptools,$errors);
1.1326 raeburn 18312: if ($keeporder) {
18313: @LONCAPA::map::resources = @resources;
18314: @LONCAPA::map::order = @order;
18315: @LONCAPA::map::resparms = @resparms;
18316: @LONCAPA::map::zombies = @zombies;
18317: }
1.1308 raeburn 18318: if ($supptools) {
18319: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18320: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18321: ($reqdmajor,$reqdminor) = ($major,$minor);
18322: }
18323: }
1.1083 raeburn 18324: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18325: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18326: }
18327: return;
18328: }
18329:
1.1110 raeburn 18330: sub allmaps_incourse {
18331: my ($cdom,$cnum,$chome,$cid) = @_;
18332: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18333: $cid = $env{'request.course.id'};
18334: $cdom = $env{'course.'.$cid.'.domain'};
18335: $cnum = $env{'course.'.$cid.'.num'};
18336: $chome = $env{'course.'.$cid.'.home'};
18337: }
18338: my %allmaps = ();
18339: my $lastchange =
18340: &Apache::lonnet::get_coursechange($cdom,$cnum);
18341: if ($lastchange > $env{'request.course.tied'}) {
18342: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18343: unless ($ferr) {
1.1326 raeburn 18344: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 18345: }
18346: }
18347: my $navmap = Apache::lonnavmaps::navmap->new();
18348: if (defined($navmap)) {
18349: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18350: $allmaps{$res->src()} = 1;
18351: }
18352: }
18353: return \%allmaps;
18354: }
18355:
1.1083 raeburn 18356: sub parse_supplemental_title {
18357: my ($title) = @_;
18358:
18359: my ($foldertitle,$renametitle);
18360: if ($title =~ /&&&/) {
18361: $title = &HTML::Entites::decode($title);
18362: }
18363: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18364: $renametitle=$4;
18365: my ($time,$uname,$udom) = ($1,$2,$3);
18366: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18367: my $name = &plainname($uname,$udom);
18368: $name = &HTML::Entities::encode($name,'"<>&\'');
18369: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
18370: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
18371: $name.': <br />'.$foldertitle;
18372: }
18373: if (wantarray) {
18374: return ($title,$foldertitle,$renametitle);
18375: }
18376: return $title;
18377: }
18378:
1.1143 raeburn 18379: sub recurse_supplemental {
1.1308 raeburn 18380: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 18381: if ($suppmap) {
18382: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18383: if ($fatal) {
18384: $errors ++;
18385: } else {
18386: if ($#LONCAPA::map::resources > 0) {
18387: foreach my $res (@LONCAPA::map::resources) {
18388: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
18389: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 18390: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 18391: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
18392: $numfiles,$numexttools,$errors);
1.1143 raeburn 18393: } else {
1.1308 raeburn 18394: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
18395: $numexttools ++;
18396: }
1.1143 raeburn 18397: $numfiles ++;
18398: }
18399: }
18400: }
18401: }
18402: }
18403: }
1.1308 raeburn 18404: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 18405: }
18406:
1.1101 raeburn 18407: sub symb_to_docspath {
1.1267 raeburn 18408: my ($symb,$navmapref) = @_;
18409: return unless ($symb && ref($navmapref));
1.1101 raeburn 18410: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18411: if ($resurl=~/\.(sequence|page)$/) {
18412: $mapurl=$resurl;
18413: } elsif ($resurl eq 'adm/navmaps') {
18414: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18415: }
18416: my $mapresobj;
1.1267 raeburn 18417: unless (ref($$navmapref)) {
18418: $$navmapref = Apache::lonnavmaps::navmap->new();
18419: }
18420: if (ref($$navmapref)) {
18421: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18422: }
18423: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18424: my $type=$2;
18425: my $path;
18426: if (ref($mapresobj)) {
18427: my $pcslist = $mapresobj->map_hierarchy();
18428: if ($pcslist ne '') {
18429: foreach my $pc (split(/,/,$pcslist)) {
18430: next if ($pc <= 1);
1.1267 raeburn 18431: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18432: if (ref($res)) {
18433: my $thisurl = $res->src();
18434: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18435: my $thistitle = $res->title();
18436: $path .= '&'.
18437: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18438: &escape($thistitle).
1.1101 raeburn 18439: ':'.$res->randompick().
18440: ':'.$res->randomout().
18441: ':'.$res->encrypted().
18442: ':'.$res->randomorder().
18443: ':'.$res->is_page();
18444: }
18445: }
18446: }
18447: $path =~ s/^\&//;
18448: my $maptitle = $mapresobj->title();
18449: if ($mapurl eq 'default') {
1.1129 raeburn 18450: $maptitle = 'Main Content';
1.1101 raeburn 18451: }
18452: $path .= (($path ne '')? '&' : '').
18453: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18454: &escape($maptitle).
1.1101 raeburn 18455: ':'.$mapresobj->randompick().
18456: ':'.$mapresobj->randomout().
18457: ':'.$mapresobj->encrypted().
18458: ':'.$mapresobj->randomorder().
18459: ':'.$mapresobj->is_page();
18460: } else {
18461: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18462: my $ispage = (($type eq 'page')? 1 : '');
18463: if ($mapurl eq 'default') {
1.1129 raeburn 18464: $maptitle = 'Main Content';
1.1101 raeburn 18465: }
18466: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18467: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18468: }
18469: unless ($mapurl eq 'default') {
18470: $path = 'default&'.
1.1146 raeburn 18471: &escape('Main Content').
1.1101 raeburn 18472: ':::::&'.$path;
18473: }
18474: return $path;
18475: }
18476:
1.1094 raeburn 18477: sub captcha_display {
1.1327 raeburn 18478: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18479: my ($output,$error);
1.1234 raeburn 18480: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18481: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18482: if ($captcha eq 'original') {
1.1094 raeburn 18483: $output = &create_captcha();
18484: unless ($output) {
1.1172 raeburn 18485: $error = 'captcha';
1.1094 raeburn 18486: }
18487: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18488: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18489: unless ($output) {
1.1172 raeburn 18490: $error = 'recaptcha';
1.1094 raeburn 18491: }
18492: }
1.1234 raeburn 18493: return ($output,$error,$captcha,$version);
1.1094 raeburn 18494: }
18495:
18496: sub captcha_response {
1.1327 raeburn 18497: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18498: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18499: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18500: if ($captcha eq 'original') {
1.1094 raeburn 18501: ($captcha_chk,$captcha_error) = &check_captcha();
18502: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18503: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18504: } else {
18505: $captcha_chk = 1;
18506: }
18507: return ($captcha_chk,$captcha_error);
18508: }
18509:
18510: sub get_captcha_config {
1.1327 raeburn 18511: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18512: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18513: my $hostname = &Apache::lonnet::hostname($lonhost);
18514: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18515: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18516: if ($context eq 'usercreation') {
18517: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18518: if (ref($domconfig{$context}) eq 'HASH') {
18519: $hashtocheck = $domconfig{$context}{'cancreate'};
18520: if (ref($hashtocheck) eq 'HASH') {
18521: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18522: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18523: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18524: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18525: }
18526: if ($privkey && $pubkey) {
18527: $captcha = 'recaptcha';
1.1234 raeburn 18528: $version = $hashtocheck->{'recaptchaversion'};
18529: if ($version ne '2') {
18530: $version = 1;
18531: }
1.1095 raeburn 18532: } else {
18533: $captcha = 'original';
18534: }
18535: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18536: $captcha = 'original';
18537: }
1.1094 raeburn 18538: }
1.1095 raeburn 18539: } else {
18540: $captcha = 'captcha';
18541: }
18542: } elsif ($context eq 'login') {
18543: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18544: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18545: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18546: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18547: if ($privkey && $pubkey) {
18548: $captcha = 'recaptcha';
1.1234 raeburn 18549: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18550: if ($version ne '2') {
18551: $version = 1;
18552: }
1.1095 raeburn 18553: } else {
18554: $captcha = 'original';
1.1094 raeburn 18555: }
1.1095 raeburn 18556: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18557: $captcha = 'original';
1.1094 raeburn 18558: }
1.1327 raeburn 18559: } elsif ($context eq 'passwords') {
18560: if ($dom_in_effect) {
18561: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18562: if ($passwdconf{'captcha'} eq 'recaptcha') {
18563: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18564: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18565: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18566: }
18567: if ($privkey && $pubkey) {
18568: $captcha = 'recaptcha';
18569: $version = $passwdconf{'recaptchaversion'};
18570: if ($version ne '2') {
18571: $version = 1;
18572: }
18573: } else {
18574: $captcha = 'original';
18575: }
18576: } elsif ($passwdconf{'captcha'} ne 'notused') {
18577: $captcha = 'original';
18578: }
18579: }
18580: }
1.1234 raeburn 18581: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18582: }
18583:
18584: sub create_captcha {
18585: my %captcha_params = &captcha_settings();
18586: my ($output,$maxtries,$tries) = ('',10,0);
18587: while ($tries < $maxtries) {
18588: $tries ++;
18589: my $captcha = Authen::Captcha->new (
18590: output_folder => $captcha_params{'output_dir'},
18591: data_folder => $captcha_params{'db_dir'},
18592: );
18593: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18594:
18595: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18596: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 18597: '<span class="LC_nobreak">'.
1.1094 raeburn 18598: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18599: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1367 raeburn 18600: '</span><br />'.
1.1176 raeburn 18601: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18602: last;
18603: }
18604: }
1.1323 raeburn 18605: if ($output eq '') {
18606: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18607: }
1.1094 raeburn 18608: return $output;
18609: }
18610:
18611: sub captcha_settings {
18612: my %captcha_params = (
18613: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18614: www_output_dir => "/captchaspool",
18615: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18616: numchars => '5',
18617: );
18618: return %captcha_params;
18619: }
18620:
18621: sub check_captcha {
18622: my ($captcha_chk,$captcha_error);
18623: my $code = $env{'form.code'};
18624: my $md5sum = $env{'form.crypt'};
18625: my %captcha_params = &captcha_settings();
18626: my $captcha = Authen::Captcha->new(
18627: output_folder => $captcha_params{'output_dir'},
18628: data_folder => $captcha_params{'db_dir'},
18629: );
1.1109 raeburn 18630: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18631: my %captcha_hash = (
18632: 0 => 'Code not checked (file error)',
18633: -1 => 'Failed: code expired',
18634: -2 => 'Failed: invalid code (not in database)',
18635: -3 => 'Failed: invalid code (code does not match crypt)',
18636: );
18637: if ($captcha_chk != 1) {
18638: $captcha_error = $captcha_hash{$captcha_chk}
18639: }
18640: return ($captcha_chk,$captcha_error);
18641: }
18642:
18643: sub create_recaptcha {
1.1234 raeburn 18644: my ($pubkey,$version) = @_;
18645: if ($version >= 2) {
1.1367 raeburn 18646: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18647: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 18648: } else {
18649: my $use_ssl;
18650: if ($ENV{'SERVER_PORT'} == 443) {
18651: $use_ssl = 1;
18652: }
18653: my $captcha = Captcha::reCAPTCHA->new;
18654: return $captcha->get_options_setter({theme => 'white'})."\n".
18655: $captcha->get_html($pubkey,undef,$use_ssl).
18656: &mt('If the text is hard to read, [_1] will replace them.',
18657: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18658: '<br /><br />';
18659: }
1.1094 raeburn 18660: }
18661:
18662: sub check_recaptcha {
1.1234 raeburn 18663: my ($privkey,$version) = @_;
1.1094 raeburn 18664: my $captcha_chk;
1.1350 raeburn 18665: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18666: if ($version >= 2) {
18667: my %info = (
18668: secret => $privkey,
18669: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18670: remoteip => $ip,
1.1234 raeburn 18671: );
1.1280 raeburn 18672: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18673: $request->content(join('&',map {
18674: my $name = escape($_);
18675: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18676: ? join("&$name=", map {escape($_) } @{$info{$_}})
18677: : &escape($info{$_}) );
18678: } keys(%info)));
18679: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18680: if ($response->is_success) {
18681: my $data = JSON::DWIW->from_json($response->decoded_content);
18682: if (ref($data) eq 'HASH') {
18683: if ($data->{'success'}) {
18684: $captcha_chk = 1;
18685: }
18686: }
18687: }
18688: } else {
18689: my $captcha = Captcha::reCAPTCHA->new;
18690: my $captcha_result =
18691: $captcha->check_answer(
18692: $privkey,
1.1350 raeburn 18693: $ip,
1.1234 raeburn 18694: $env{'form.recaptcha_challenge_field'},
18695: $env{'form.recaptcha_response_field'},
18696: );
18697: if ($captcha_result->{is_valid}) {
18698: $captcha_chk = 1;
18699: }
1.1094 raeburn 18700: }
18701: return $captcha_chk;
18702: }
18703:
1.1174 raeburn 18704: sub emailusername_info {
1.1244 raeburn 18705: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18706: my %titles = &Apache::lonlocal::texthash (
18707: lastname => 'Last Name',
18708: firstname => 'First Name',
18709: institution => 'School/college/university',
18710: location => "School's city, state/province, country",
18711: web => "School's web address",
18712: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18713: id => 'Student/Employee ID',
1.1174 raeburn 18714: );
18715: return (\@fields,\%titles);
18716: }
18717:
1.1161 raeburn 18718: sub cleanup_html {
18719: my ($incoming) = @_;
18720: my $outgoing;
18721: if ($incoming ne '') {
18722: $outgoing = $incoming;
18723: $outgoing =~ s/;/;/g;
18724: $outgoing =~ s/\#/#/g;
18725: $outgoing =~ s/\&/&/g;
18726: $outgoing =~ s/</</g;
18727: $outgoing =~ s/>/>/g;
18728: $outgoing =~ s/\(/(/g;
18729: $outgoing =~ s/\)/)/g;
18730: $outgoing =~ s/"/"/g;
18731: $outgoing =~ s/'/'/g;
18732: $outgoing =~ s/\$/$/g;
18733: $outgoing =~ s{/}{/}g;
18734: $outgoing =~ s/=/=/g;
18735: $outgoing =~ s/\\/\/g
18736: }
18737: return $outgoing;
18738: }
18739:
1.1190 musolffc 18740: # Checks for critical messages and returns a redirect url if one exists.
18741: # $interval indicates how often to check for messages.
1.1282 raeburn 18742: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18743: sub critical_redirect {
1.1282 raeburn 18744: my ($interval,$context) = @_;
1.1356 raeburn 18745: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18746: return ();
18747: }
1.1190 musolffc 18748: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18749: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18750: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18751: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 18752: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18753: if ($blocked) {
18754: my $checkrole = "cm./$cdom/$cnum";
18755: if ($env{'request.course.sec'} ne '') {
18756: $checkrole .= "/$env{'request.course.sec'}";
18757: }
18758: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18759: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18760: return;
18761: }
18762: }
18763: }
1.1190 musolffc 18764: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18765: $env{'user.name'});
18766: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18767: my $redirecturl;
1.1190 musolffc 18768: if ($what[0]) {
1.1356 raeburn 18769: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 18770: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18771: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18772: return (1, $url);
1.1190 musolffc 18773: }
1.1191 raeburn 18774: }
18775: }
18776: return ();
1.1190 musolffc 18777: }
18778:
1.1174 raeburn 18779: # Use:
18780: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18781: #
18782: ##################################################
18783: # password associated functions #
18784: ##################################################
18785: sub des_keys {
18786: # Make a new key for DES encryption.
18787: # Each key has two parts which are returned separately.
18788: # Please note: Each key must be passed through the &hex function
18789: # before it is output to the web browser. The hex versions cannot
18790: # be used to decrypt.
18791: my @hexstr=('0','1','2','3','4','5','6','7',
18792: '8','9','a','b','c','d','e','f');
18793: my $lkey='';
18794: for (0..7) {
18795: $lkey.=$hexstr[rand(15)];
18796: }
18797: my $ukey='';
18798: for (0..7) {
18799: $ukey.=$hexstr[rand(15)];
18800: }
18801: return ($lkey,$ukey);
18802: }
18803:
18804: sub des_decrypt {
18805: my ($key,$cyphertext) = @_;
18806: my $keybin=pack("H16",$key);
18807: my $cypher;
18808: if ($Crypt::DES::VERSION>=2.03) {
18809: $cypher=new Crypt::DES $keybin;
18810: } else {
18811: $cypher=new DES $keybin;
18812: }
1.1233 raeburn 18813: my $plaintext='';
18814: my $cypherlength = length($cyphertext);
18815: my $numchunks = int($cypherlength/32);
18816: for (my $j=0; $j<$numchunks; $j++) {
18817: my $start = $j*32;
18818: my $cypherblock = substr($cyphertext,$start,32);
18819: my $chunk =
18820: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18821: $chunk .=
18822: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18823: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18824: $plaintext .= $chunk;
18825: }
1.1174 raeburn 18826: return $plaintext;
18827: }
18828:
1.1344 raeburn 18829: sub get_requested_shorturls {
1.1309 raeburn 18830: my ($cdom,$cnum,$navmap) = @_;
18831: return unless (ref($navmap));
1.1344 raeburn 18832: my ($numnew,$errors);
1.1309 raeburn 18833: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18834: if (@toshorten) {
18835: my (%maps,%resources,%titles);
18836: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18837: 'shorturls',$cdom,$cnum);
18838: if (keys(%resources)) {
1.1344 raeburn 18839: my %tocreate;
1.1309 raeburn 18840: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18841: my $symb = $resources{$item};
18842: if ($symb) {
18843: $tocreate{$cnum.'&'.$symb} = 1;
18844: }
18845: }
1.1344 raeburn 18846: if (keys(%tocreate)) {
18847: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18848: \%tocreate);
18849: }
1.1309 raeburn 18850: }
1.1344 raeburn 18851: }
18852: return ($numnew,$errors);
18853: }
18854:
18855: sub make_short_symbs {
18856: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18857: my ($numnew,@errors);
18858: if (ref($tocreateref) eq 'HASH') {
18859: my %tocreate = %{$tocreateref};
1.1309 raeburn 18860: if (keys(%tocreate)) {
18861: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18862: my $su = Short::URL->new(no_vowels => 1);
18863: my $init = '';
18864: my (%newunique,%addcourse,%courseonly,%failed);
18865: # get lock on tiny db
18866: my $now = time;
1.1344 raeburn 18867: if ($lockuser eq '') {
18868: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18869: }
1.1309 raeburn 18870: my $lockhash = {
1.1344 raeburn 18871: "lock\0$now" => $lockuser,
1.1309 raeburn 18872: };
18873: my $tries = 0;
18874: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18875: my ($code,$error);
18876: while (($gotlock ne 'ok') && ($tries<3)) {
18877: $tries ++;
18878: sleep 1;
1.1319 raeburn 18879: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18880: }
18881: if ($gotlock eq 'ok') {
18882: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18883: \%addcourse,\%courseonly,\%failed);
18884: if (keys(%failed)) {
18885: my $numfailed = scalar(keys(%failed));
18886: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18887: }
18888: if (keys(%newunique)) {
18889: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18890: if ($putres eq 'ok') {
18891: $numnew = scalar(keys(%newunique));
18892: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18893: unless ($newputres eq 'ok') {
18894: push(@errors,&mt('error: could not store course look-up of short URLs'));
18895: }
18896: } else {
18897: push(@errors,&mt('error: could not store unique six character URLs'));
18898: }
18899: }
18900: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18901: unless ($dellockres eq 'ok') {
18902: push(@errors,&mt('error: could not release lockfile'));
18903: }
18904: } else {
18905: push(@errors,&mt('error: could not obtain lockfile'));
18906: }
18907: if (keys(%courseonly)) {
18908: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18909: if ($result ne 'ok') {
18910: push(@errors,&mt('error: could not update course look-up of short URLs'));
18911: }
18912: }
18913: }
18914: }
18915: return ($numnew,\@errors);
18916: }
18917:
18918: sub shorten_symbs {
18919: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18920: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18921: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18922: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18923: my (%possibles,%collisions);
18924: foreach my $key (keys(%{$tocreate})) {
18925: my $num = String::CRC32::crc32($key);
18926: my $tiny = $su->encode($num,$init);
18927: if ($tiny) {
18928: $possibles{$tiny} = $key;
18929: }
18930: }
18931: if (!$init) {
18932: $init = 1;
18933: } else {
18934: $init ++;
18935: }
18936: if (keys(%possibles)) {
18937: my @posstiny = keys(%possibles);
18938: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18939: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18940: if (keys(%currtiny)) {
18941: foreach my $key (keys(%currtiny)) {
18942: next if ($currtiny{$key} eq '');
18943: if ($currtiny{$key} eq $possibles{$key}) {
18944: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18945: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18946: $courseonly->{$tsymb} = $key;
18947: }
18948: } else {
18949: $collisions{$possibles{$key}} = 1;
18950: }
18951: delete($possibles{$key});
18952: }
18953: }
18954: foreach my $key (keys(%possibles)) {
18955: $newunique->{$key} = $possibles{$key};
18956: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18957: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18958: $addcourse->{$tsymb} = $key;
18959: }
18960: }
18961: }
18962: if (keys(%collisions)) {
18963: if ($init <5) {
18964: if (!$init) {
18965: $init = 1;
18966: } else {
18967: $init ++;
18968: }
18969: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18970: $newunique,$addcourse,$courseonly,$failed);
18971: } else {
18972: foreach my $key (keys(%collisions)) {
18973: $failed->{$key} = 1;
18974: }
18975: }
18976: }
18977: return $init;
18978: }
18979:
1.1328 raeburn 18980: sub is_nonframeable {
1.1329 raeburn 18981: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18982: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18983: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18984:
18985: $remprotocol = lc($remprotocol);
18986: $remhost = lc($remhost);
18987: my $remport = 80;
18988: if ($remprotocol eq 'https') {
18989: $remport = 443;
18990: }
1.1330 raeburn 18991: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18992: if ($cached) {
18993: unless ($nocache) {
18994: if ($result) {
18995: return 1;
18996: } else {
18997: return 0;
18998: }
18999: }
19000: }
1.1328 raeburn 19001: my $uselink;
19002: my $request = new HTTP::Request('HEAD',$url);
19003: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
19004: if ($response->is_success()) {
19005: my $secpolicy = lc($response->header('content-security-policy'));
19006: my $xframeop = lc($response->header('x-frame-options'));
19007: $secpolicy =~ s/^\s+|\s+$//g;
19008: $xframeop =~ s/^\s+|\s+$//g;
19009: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 19010: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 19011: my ($origin,$protocol,$port);
19012: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19013: $port = $ENV{'SERVER_PORT'};
19014: } else {
19015: $port = 80;
19016: }
19017: if ($absolute eq '') {
19018: $protocol = 'http:';
19019: if ($port == 443) {
19020: $protocol = 'https:';
19021: }
19022: $origin = $protocol.'//'.lc($hostname);
19023: } else {
19024: $origin = lc($absolute);
19025: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19026: }
19027: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19028: my $framepolicy = $1;
19029: $framepolicy =~ s/^\s+|\s+$//g;
19030: my @policies = split(/\s+/,$framepolicy);
19031: if (@policies) {
19032: if (grep(/^\Q'none'\E$/,@policies)) {
19033: $uselink = 1;
19034: } else {
19035: $uselink = 1;
19036: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19037: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19038: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19039: undef($uselink);
19040: }
19041: if ($uselink) {
19042: if (grep(/^\Q'self'\E$/,@policies)) {
19043: if (($origin ne '') && ($remotehost eq $origin)) {
19044: undef($uselink);
19045: }
19046: }
19047: }
19048: if ($uselink) {
19049: my @possok;
19050: if ($ip ne '') {
19051: push(@possok,$ip);
19052: }
19053: my $hoststr = '';
19054: foreach my $part (reverse(split(/\./,$hostname))) {
19055: if ($hoststr eq '') {
19056: $hoststr = $part;
19057: } else {
19058: $hoststr = "$part.$hoststr";
19059: }
19060: if ($hoststr eq $hostname) {
19061: push(@possok,$hostname);
19062: } else {
19063: push(@possok,"*.$hoststr");
19064: }
19065: }
19066: if (@possok) {
19067: foreach my $poss (@possok) {
19068: last if (!$uselink);
19069: foreach my $policy (@policies) {
19070: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19071: undef($uselink);
19072: last;
19073: }
19074: }
19075: }
19076: }
19077: }
19078: }
19079: }
19080: } elsif ($xframeop ne '') {
19081: $uselink = 1;
19082: my @policies = split(/\s*,\s*/,$xframeop);
19083: if (@policies) {
19084: unless (grep(/^deny$/,@policies)) {
19085: if ($origin ne '') {
19086: if (grep(/^sameorigin$/,@policies)) {
19087: if ($remotehost eq $origin) {
19088: undef($uselink);
19089: }
19090: }
19091: if ($uselink) {
19092: foreach my $policy (@policies) {
19093: if ($policy =~ /^allow-from\s*(.+)$/) {
19094: my $allowfrom = $1;
19095: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19096: undef($uselink);
19097: last;
19098: }
19099: }
19100: }
19101: }
19102: }
19103: }
19104: }
19105: }
19106: }
19107: }
1.1329 raeburn 19108: if ($nocache) {
19109: if ($cached) {
19110: my $devalidate;
19111: if ($uselink && !$result) {
19112: $devalidate = 1;
19113: } elsif (!$uselink && $result) {
19114: $devalidate = 1;
19115: }
19116: if ($devalidate) {
19117: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19118: }
19119: }
19120: } else {
19121: if ($uselink) {
19122: $result = 1;
19123: } else {
19124: $result = 0;
19125: }
19126: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19127: }
1.1328 raeburn 19128: return $uselink;
19129: }
19130:
1.1359 raeburn 19131: sub page_menu {
19132: my ($menucolls,$menunum) = @_;
19133: my %menu;
19134: foreach my $item (split(/;/,$menucolls)) {
19135: my ($num,$value) = split(/\%/,$item);
19136: if ($num eq $menunum) {
19137: my @entries = split(/\&/,$value);
19138: foreach my $entry (@entries) {
19139: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19140: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19141: $menu{$name} = $fields;
19142: } else {
19143: my @shown;
19144: if ($fields =~ /,/) {
19145: @shown = split(/,/,$fields);
19146: } else {
19147: @shown = ($fields);
19148: }
19149: if (@shown) {
19150: foreach my $field (@shown) {
19151: next if ($field eq '');
19152: $menu{$field} = 1;
19153: }
19154: }
19155: }
19156: }
19157: }
19158: }
19159: return %menu;
19160: }
19161:
1.112 bowersj2 19162: 1;
19163: __END__;
1.41 ng 19164:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>