Annotation of loncom/interface/loncommon.pm, revision 1.1374
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1374 ! raeburn 4: # $Id: loncommon.pm,v 1.1373 2021/12/24 00:48:30 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.1328 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1241 raeburn 77: use DateTime::Locale;
1.1220 raeburn 78: use Encode();
1.1091 foxr 79: use Text::Aspell;
1.1094 raeburn 80: use Authen::Captcha;
81: use Captcha::reCAPTCHA;
1.1234 raeburn 82: use JSON::DWIW;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.1292 raeburn 87: use File::Copy();
1.1300 raeburn 88: use File::Path();
1.1309 raeburn 89: use String::CRC32();
90: use Short::URL();
1.117 www 91:
1.517 raeburn 92: # ---------------------------------------------- Designs
93: use vars qw(%defaultdesign);
94:
1.22 www 95: my $readit;
96:
1.517 raeburn 97:
1.157 matthew 98: ##
99: ## Global Variables
100: ##
1.46 matthew 101:
1.643 foxr 102:
103: # ----------------------------------------------- SSI with retries:
104: #
105:
106: =pod
107:
1.648 raeburn 108: =head1 Server Side include with retries:
1.643 foxr 109:
110: =over 4
111:
1.648 raeburn 112: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 113:
114: Performs an ssi with some number of retries. Retries continue either
115: until the result is ok or until the retry count supplied by the
116: caller is exhausted.
117:
118: Inputs:
1.648 raeburn 119:
120: =over 4
121:
1.643 foxr 122: resource - Identifies the resource to insert.
1.648 raeburn 123:
1.643 foxr 124: retries - Count of the number of retries allowed.
1.648 raeburn 125:
1.643 foxr 126: form - Hash that identifies the rendering options.
127:
1.648 raeburn 128: =back
129:
130: Returns:
131:
132: =over 4
133:
1.643 foxr 134: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 135:
1.643 foxr 136: response - The response from the last attempt (which may or may not have been successful.
137:
1.648 raeburn 138: =back
139:
140: =back
141:
1.643 foxr 142: =cut
143:
144: sub ssi_with_retries {
145: my ($resource, $retries, %form) = @_;
146:
147:
148: my $ok = 0; # True if we got a good response.
149: my $content;
150: my $response;
151:
152: # Try to get the ssi done. within the retries count:
153:
154: do {
155: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
156: $ok = $response->is_success;
1.650 www 157: if (!$ok) {
158: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
159: }
1.643 foxr 160: $retries--;
161: } while (!$ok && ($retries > 0));
162:
163: if (!$ok) {
164: $content = ''; # On error return an empty content.
165: }
166: return ($content, $response);
167:
168: }
169:
170:
171:
1.20 www 172: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 173: my %language;
1.124 www 174: my %supported_language;
1.1088 foxr 175: my %supported_codes;
1.1048 foxr 176: my %latex_language; # For choosing hyphenation in <transl..>
177: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 178: my %cprtag;
1.192 taceyjo1 179: my %scprtag;
1.351 www 180: my %fe; my %fd; my %fm;
1.41 ng 181: my %category_extensions;
1.12 harris41 182:
1.46 matthew 183: # ---------------------------------------------- Thesaurus variables
1.144 matthew 184: #
185: # %Keywords:
186: # A hash used by &keyword to determine if a word is considered a keyword.
187: # $thesaurus_db_file
188: # Scalar containing the full path to the thesaurus database.
1.46 matthew 189:
190: my %Keywords;
191: my $thesaurus_db_file;
192:
1.144 matthew 193: #
194: # Initialize values from language.tab, copyright.tab, filetypes.tab,
195: # thesaurus.tab, and filecategories.tab.
196: #
1.18 www 197: BEGIN {
1.46 matthew 198: # Variable initialization
199: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
200: #
1.22 www 201: unless ($readit) {
1.12 harris41 202: # ------------------------------------------------------------------- languages
203: {
1.158 raeburn 204: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
205: '/language.tab';
1.1317 raeburn 206: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 207: while (my $line = <$fh>) {
208: next if ($line=~/^\#/);
209: chomp($line);
1.1088 foxr 210: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 211: $language{$key}=$val.' - '.$enc;
212: if ($sup) {
213: $supported_language{$key}=$sup;
1.1088 foxr 214: $supported_codes{$key} = $code;
1.158 raeburn 215: }
1.1048 foxr 216: if ($latex) {
217: $latex_language_bykey{$key} = $latex;
1.1088 foxr 218: $latex_language{$code} = $latex;
1.1048 foxr 219: }
1.158 raeburn 220: }
221: close($fh);
222: }
1.12 harris41 223: }
224: # ------------------------------------------------------------------ copyrights
225: {
1.158 raeburn 226: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
227: '/copyright.tab';
1.1317 raeburn 228: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 229: while (my $line = <$fh>) {
230: next if ($line=~/^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 233: $cprtag{$key}=$val;
234: }
235: close($fh);
236: }
1.12 harris41 237: }
1.351 www 238: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 239: {
240: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
241: '/source_copyright.tab';
1.1317 raeburn 242: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 247: $scprtag{$key}=$val;
248: }
249: close($fh);
250: }
251: }
1.63 www 252:
1.517 raeburn 253: # -------------------------------------------------------------- default domain designs
1.63 www 254: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 255: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 256: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 257: while (my $line = <$fh>) {
258: next if ($line =~ /^\#/);
259: chomp($line);
260: my ($key,$val)=(split(/\=/,$line));
261: if ($val) { $defaultdesign{$key}=$val; }
262: }
263: close($fh);
1.63 www 264: }
265:
1.15 harris41 266: # ------------------------------------------------------------- file categories
267: {
1.158 raeburn 268: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
269: '/filecategories.tab';
1.1317 raeburn 270: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 271: while (my $line = <$fh>) {
272: next if ($line =~ /^\#/);
273: chomp($line);
274: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 275: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 276: }
277: close($fh);
278: }
279:
1.15 harris41 280: }
1.12 harris41 281: # ------------------------------------------------------------------ file types
282: {
1.158 raeburn 283: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
284: '/filetypes.tab';
1.1317 raeburn 285: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 286: while (my $line = <$fh>) {
287: next if ($line =~ /^\#/);
288: chomp($line);
289: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 290: if ($descr ne '') {
291: $fe{$ending}=lc($emb);
292: $fd{$ending}=$descr;
1.351 www 293: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 294: }
295: }
296: close($fh);
297: }
1.12 harris41 298: }
1.22 www 299: &Apache::lonnet::logthis(
1.705 tempelho 300: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 301: $readit=1;
1.46 matthew 302: } # end of unless($readit)
1.32 matthew 303:
304: }
1.112 bowersj2 305:
1.42 matthew 306: ###############################################################
307: ## HTML and Javascript Helper Functions ##
308: ###############################################################
309:
310: =pod
311:
1.112 bowersj2 312: =head1 HTML and Javascript Functions
1.42 matthew 313:
1.112 bowersj2 314: =over 4
315:
1.648 raeburn 316: =item * &browser_and_searcher_javascript()
1.112 bowersj2 317:
318: X<browsing, javascript>X<searching, javascript>Returns a string
319: containing javascript with two functions, C<openbrowser> and
320: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
321: tags.
1.42 matthew 322:
1.648 raeburn 323: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 324:
325: inputs: formname, elementname, only, omit
326:
327: formname and elementname indicate the name of the html form and name of
328: the element that the results of the browsing selection are to be placed in.
329:
330: Specifying 'only' will restrict the browser to displaying only files
1.185 www 331: with the given extension. Can be a comma separated list.
1.42 matthew 332:
333: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 334: with the given extension. Can be a comma separated list.
1.42 matthew 335:
1.648 raeburn 336: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 337:
338: Inputs: formname, elementname
339:
340: formname and elementname specify the name of the html form and the name
341: of the element the selection from the search results will be placed in.
1.542 raeburn 342:
1.42 matthew 343: =cut
344:
345: sub browser_and_searcher_javascript {
1.199 albertel 346: my ($mode)=@_;
347: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 348: my $resurl=&escape_single(&lastresurl());
1.42 matthew 349: return <<END;
1.219 albertel 350: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 351: var editbrowser = null;
1.135 albertel 352: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 353: var url = '$resurl/?';
1.42 matthew 354: if (editbrowser == null) {
355: url += 'launch=1&';
356: }
357: url += 'catalogmode=interactive&';
1.199 albertel 358: url += 'mode=$mode&';
1.611 albertel 359: url += 'inhibitmenu=yes&';
1.42 matthew 360: url += 'form=' + formname + '&';
361: if (only != null) {
362: url += 'only=' + only + '&';
1.217 albertel 363: } else {
364: url += 'only=&';
365: }
1.42 matthew 366: if (omit != null) {
367: url += 'omit=' + omit + '&';
1.217 albertel 368: } else {
369: url += 'omit=&';
370: }
1.135 albertel 371: if (titleelement != null) {
372: url += 'titleelement=' + titleelement + '&';
1.217 albertel 373: } else {
374: url += 'titleelement=&';
375: }
1.42 matthew 376: url += 'element=' + elementname + '';
377: var title = 'Browser';
1.435 albertel 378: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 379: options += ',width=700,height=600';
380: editbrowser = open(url,title,options,'1');
381: editbrowser.focus();
382: }
383: var editsearcher;
1.135 albertel 384: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 385: var url = '/adm/searchcat?';
386: if (editsearcher == null) {
387: url += 'launch=1&';
388: }
389: url += 'catalogmode=interactive&';
1.199 albertel 390: url += 'mode=$mode&';
1.42 matthew 391: url += 'form=' + formname + '&';
1.135 albertel 392: if (titleelement != null) {
393: url += 'titleelement=' + titleelement + '&';
1.217 albertel 394: } else {
395: url += 'titleelement=&';
396: }
1.42 matthew 397: url += 'element=' + elementname + '';
398: var title = 'Search';
1.435 albertel 399: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 400: options += ',width=700,height=600';
401: editsearcher = open(url,title,options,'1');
402: editsearcher.focus();
403: }
1.219 albertel 404: // END LON-CAPA Internal -->
1.42 matthew 405: END
1.170 www 406: }
407:
408: sub lastresurl {
1.258 albertel 409: if ($env{'environment.lastresurl'}) {
410: return $env{'environment.lastresurl'}
1.170 www 411: } else {
412: return '/res';
413: }
414: }
415:
416: sub storeresurl {
417: my $resurl=&Apache::lonnet::clutter(shift);
418: unless ($resurl=~/^\/res/) { return 0; }
419: $resurl=~s/\/$//;
420: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 421: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 422: return 1;
1.42 matthew 423: }
424:
1.74 www 425: sub studentbrowser_javascript {
1.111 www 426: unless (
1.258 albertel 427: (($env{'request.course.id'}) &&
1.302 albertel 428: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
429: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
430: '/'.$env{'request.course.sec'})
431: ))
1.258 albertel 432: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 433: ) { return ''; }
1.74 www 434: return (<<'ENDSTDBRW');
1.776 bisitz 435: <script type="text/javascript" language="Javascript">
1.824 bisitz 436: // <![CDATA[
1.74 www 437: var stdeditbrowser;
1.1337 raeburn 438: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 439: var url = '/adm/pickstudent?';
440: var filter;
1.558 albertel 441: if (!ignorefilter) {
442: eval('filter=document.'+formname+'.'+uname+'.value;');
443: }
1.74 www 444: if (filter != null) {
445: if (filter != '') {
446: url += 'filter='+filter+'&';
447: }
448: }
449: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 450: '&udomelement='+udom+
451: '&clicker='+clicker;
1.111 www 452: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 453: if (courseadv == 'condition') {
454: if (document.getElementById('courseadv')) {
455: courseadv = document.getElementById('courseadv').value;
456: }
457: }
458: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 459: var title = 'Student_Browser';
1.74 www 460: var options = 'scrollbars=1,resizable=1,menubar=0';
461: options += ',width=700,height=600';
462: stdeditbrowser = open(url,title,options,'1');
463: stdeditbrowser.focus();
464: }
1.824 bisitz 465: // ]]>
1.74 www 466: </script>
467: ENDSTDBRW
468: }
1.42 matthew 469:
1.1003 www 470: sub resourcebrowser_javascript {
471: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 472: return (<<'ENDRESBRW');
1.1003 www 473: <script type="text/javascript" language="Javascript">
474: // <![CDATA[
475: var reseditbrowser;
1.1004 www 476: function openresbrowser(formname,reslink) {
1.1005 www 477: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 478: var title = 'Resource_Browser';
479: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 480: options += ',width=700,height=500';
1.1004 www 481: reseditbrowser = open(url,title,options,'1');
482: reseditbrowser.focus();
1.1003 www 483: }
484: // ]]>
485: </script>
1.1004 www 486: ENDRESBRW
1.1003 www 487: }
488:
1.74 www 489: sub selectstudent_link {
1.1337 raeburn 490: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 491: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
492: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
493: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 494: if ($env{'request.course.id'}) {
1.302 albertel 495: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
496: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
497: '/'.$env{'request.course.sec'})) {
1.111 www 498: return '';
499: }
1.999 www 500: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 501: if ($courseadv eq 'only') {
502: $callargs .= ",'',1,'$courseadv'";
503: } elsif ($courseadv eq 'none') {
504: $callargs .= ",'','','$courseadv'";
505: } elsif ($courseadv eq 'condition') {
506: $callargs .= ",'','','$courseadv'";
1.793 raeburn 507: }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openstdbrowser('.$callargs.');">'.
510: &mt('Select User').'</a></span>';
1.74 www 511: }
1.258 albertel 512: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 513: $callargs .= ",'',1";
1.793 raeburn 514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openstdbrowser('.$callargs.');">'.
516: &mt('Select User').'</a></span>';
1.111 www 517: }
518: return '';
1.91 www 519: }
520:
1.1004 www 521: sub selectresource_link {
522: my ($form,$reslink,$arg)=@_;
523:
524: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
525: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
526: unless ($env{'request.course.id'}) { return $arg; }
527: return '<span class="LC_nobreak">'.
528: '<a href="javascript:openresbrowser('.$callargs.');">'.
529: $arg.'</a></span>';
530: }
531:
532:
533:
1.653 raeburn 534: sub authorbrowser_javascript {
535: return <<"ENDAUTHORBRW";
1.776 bisitz 536: <script type="text/javascript" language="JavaScript">
1.824 bisitz 537: // <![CDATA[
1.653 raeburn 538: var stdeditbrowser;
539:
540: function openauthorbrowser(formname,udom) {
541: var url = '/adm/pickauthor?';
542: url += 'form='+formname+'&roledom='+udom;
543: var title = 'Author_Browser';
544: var options = 'scrollbars=1,resizable=1,menubar=0';
545: options += ',width=700,height=600';
546: stdeditbrowser = open(url,title,options,'1');
547: stdeditbrowser.focus();
548: }
549:
1.824 bisitz 550: // ]]>
1.653 raeburn 551: </script>
552: ENDAUTHORBRW
553: }
554:
1.91 www 555: sub coursebrowser_javascript {
1.1116 raeburn 556: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 557: $credits_element,$instcode) = @_;
1.932 raeburn 558: my $wintitle = 'Course_Browser';
1.931 raeburn 559: if ($crstype eq 'Community') {
1.932 raeburn 560: $wintitle = 'Community_Browser';
1.909 raeburn 561: }
1.876 raeburn 562: my $id_functions = &javascript_index_functions();
563: my $output = '
1.776 bisitz 564: <script type="text/javascript" language="JavaScript">
1.824 bisitz 565: // <![CDATA[
1.468 raeburn 566: var stdeditbrowser;'."\n";
1.876 raeburn 567:
568: $output .= <<"ENDSTDBRW";
1.909 raeburn 569: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 570: var url = '/adm/pickcourse?';
1.895 raeburn 571: var formid = getFormIdByName(formname);
1.876 raeburn 572: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 573: if (domainfilter != null) {
574: if (domainfilter != '') {
575: url += 'domainfilter='+domainfilter+'&';
576: }
577: }
1.91 www 578: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 579: '&cdomelement='+udom+
580: '&cnameelement='+desc;
1.468 raeburn 581: if (extra_element !=null && extra_element != '') {
1.594 raeburn 582: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 583: url += '&roleelement='+extra_element;
584: if (domainfilter == null || domainfilter == '') {
585: url += '&domainfilter='+extra_element;
586: }
1.234 raeburn 587: }
1.468 raeburn 588: else {
589: if (formname == 'portform') {
590: url += '&setroles='+extra_element;
1.800 raeburn 591: } else {
592: if (formname == 'rules') {
593: url += '&fixeddom='+extra_element;
594: }
1.468 raeburn 595: }
596: }
1.230 raeburn 597: }
1.909 raeburn 598: if (type != null && type != '') {
599: url += '&type='+type;
600: }
601: if (type_elem != null && type_elem != '') {
602: url += '&typeelement='+type_elem;
603: }
1.872 raeburn 604: if (formname == 'ccrs') {
605: var ownername = document.forms[formid].ccuname.value;
606: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 607: url += '&cloner='+ownername+':'+ownerdom;
608: if (type == 'Course') {
609: url += '&crscode='+document.forms[formid].crscode.value;
610: }
1.1221 raeburn 611: }
612: if (formname == 'requestcrs') {
613: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 614: }
1.293 raeburn 615: if (multflag !=null && multflag != '') {
616: url += '&multiple='+multflag;
617: }
1.909 raeburn 618: var title = '$wintitle';
1.91 www 619: var options = 'scrollbars=1,resizable=1,menubar=0';
620: options += ',width=700,height=600';
621: stdeditbrowser = open(url,title,options,'1');
622: stdeditbrowser.focus();
623: }
1.876 raeburn 624: $id_functions
625: ENDSTDBRW
1.1116 raeburn 626: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
627: $output .= &setsec_javascript($sec_element,$formname,$role_element,
628: $credits_element);
1.876 raeburn 629: }
630: $output .= '
631: // ]]>
632: </script>';
633: return $output;
634: }
635:
636: sub javascript_index_functions {
637: return <<"ENDJS";
638:
639: function getFormIdByName(formname) {
640: for (var i=0;i<document.forms.length;i++) {
641: if (document.forms[i].name == formname) {
642: return i;
643: }
644: }
645: return -1;
646: }
647:
648: function getIndexByName(formid,item) {
649: for (var i=0;i<document.forms[formid].elements.length;i++) {
650: if (document.forms[formid].elements[i].name == item) {
651: return i;
652: }
653: }
654: return -1;
655: }
1.468 raeburn 656:
1.876 raeburn 657: function getDomainFromSelectbox(formname,udom) {
658: var userdom;
659: var formid = getFormIdByName(formname);
660: if (formid > -1) {
661: var domid = getIndexByName(formid,udom);
662: if (domid > -1) {
663: if (document.forms[formid].elements[domid].type == 'select-one') {
664: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
665: }
666: if (document.forms[formid].elements[domid].type == 'hidden') {
667: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 668: }
669: }
670: }
1.876 raeburn 671: return userdom;
672: }
673:
674: ENDJS
1.468 raeburn 675:
1.876 raeburn 676: }
677:
1.1017 raeburn 678: sub javascript_array_indexof {
1.1018 raeburn 679: return <<ENDJS;
1.1017 raeburn 680: <script type="text/javascript" language="JavaScript">
681: // <![CDATA[
682:
683: if (!Array.prototype.indexOf) {
684: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
685: "use strict";
686: if (this === void 0 || this === null) {
687: throw new TypeError();
688: }
689: var t = Object(this);
690: var len = t.length >>> 0;
691: if (len === 0) {
692: return -1;
693: }
694: var n = 0;
695: if (arguments.length > 0) {
696: n = Number(arguments[1]);
1.1088 foxr 697: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 698: n = 0;
699: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
700: n = (n > 0 || -1) * Math.floor(Math.abs(n));
701: }
702: }
703: if (n >= len) {
704: return -1;
705: }
706: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
707: for (; k < len; k++) {
708: if (k in t && t[k] === searchElement) {
709: return k;
710: }
711: }
712: return -1;
713: }
714: }
715:
716: // ]]>
717: </script>
718:
719: ENDJS
720:
721: }
722:
1.876 raeburn 723: sub userbrowser_javascript {
724: my $id_functions = &javascript_index_functions();
725: return <<"ENDUSERBRW";
726:
1.888 raeburn 727: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 728: var url = '/adm/pickuser?';
729: var userdom = getDomainFromSelectbox(formname,udom);
730: if (userdom != null) {
731: if (userdom != '') {
732: url += 'srchdom='+userdom+'&';
733: }
734: }
735: url += 'form=' + formname + '&unameelement='+uname+
736: '&udomelement='+udom+
737: '&ulastelement='+ulast+
738: '&ufirstelement='+ufirst+
739: '&uemailelement='+uemail+
1.881 raeburn 740: '&hideudomelement='+hideudom+
741: '&coursedom='+crsdom;
1.888 raeburn 742: if ((caller != null) && (caller != undefined)) {
743: url += '&caller='+caller;
744: }
1.876 raeburn 745: var title = 'User_Browser';
746: var options = 'scrollbars=1,resizable=1,menubar=0';
747: options += ',width=700,height=600';
748: var stdeditbrowser = open(url,title,options,'1');
749: stdeditbrowser.focus();
750: }
751:
1.888 raeburn 752: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 753: var formid = getFormIdByName(formname);
754: if (formid > -1) {
1.888 raeburn 755: var unameid = getIndexByName(formid,uname);
1.876 raeburn 756: var domid = getIndexByName(formid,udom);
757: var hidedomid = getIndexByName(formid,origdom);
758: if (hidedomid > -1) {
759: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 760: var unameval = document.forms[formid].elements[unameid].value;
761: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
762: if (domid > -1) {
763: var slct = document.forms[formid].elements[domid];
764: if (slct.type == 'select-one') {
765: var i;
766: for (i=0;i<slct.length;i++) {
767: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
768: }
769: }
770: if (slct.type == 'hidden') {
771: slct.value = fixeddom;
1.876 raeburn 772: }
773: }
1.468 raeburn 774: }
775: }
776: }
1.876 raeburn 777: return;
778: }
779:
780: $id_functions
781: ENDUSERBRW
1.468 raeburn 782: }
783:
784: sub setsec_javascript {
1.1116 raeburn 785: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 786: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
787: $communityrolestr);
788: if ($role_element ne '') {
789: my @allroles = ('st','ta','ep','in','ad');
790: foreach my $crstype ('Course','Community') {
791: if ($crstype eq 'Community') {
792: foreach my $role (@allroles) {
793: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
794: }
795: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
796: } else {
797: foreach my $role (@allroles) {
798: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
799: }
800: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
801: }
802: }
803: $rolestr = '"'.join('","',@allroles).'"';
804: $courserolestr = '"'.join('","',@courserolenames).'"';
805: $communityrolestr = '"'.join('","',@communityrolenames).'"';
806: }
1.468 raeburn 807: my $setsections = qq|
808: function setSect(sectionlist) {
1.629 raeburn 809: var sectionsArray = new Array();
810: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
811: sectionsArray = sectionlist.split(",");
812: }
1.468 raeburn 813: var numSections = sectionsArray.length;
814: document.$formname.$sec_element.length = 0;
815: if (numSections == 0) {
816: document.$formname.$sec_element.multiple=false;
817: document.$formname.$sec_element.size=1;
818: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
819: } else {
820: if (numSections == 1) {
821: document.$formname.$sec_element.multiple=false;
822: document.$formname.$sec_element.size=1;
823: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
824: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
825: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
826: } else {
827: for (var i=0; i<numSections; i++) {
828: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
829: }
830: document.$formname.$sec_element.multiple=true
831: if (numSections < 3) {
832: document.$formname.$sec_element.size=numSections;
833: } else {
834: document.$formname.$sec_element.size=3;
835: }
836: document.$formname.$sec_element.options[0].selected = false
837: }
838: }
1.91 www 839: }
1.905 raeburn 840:
841: function setRole(crstype) {
1.468 raeburn 842: |;
1.905 raeburn 843: if ($role_element eq '') {
844: $setsections .= ' return;
845: }
846: ';
847: } else {
848: $setsections .= qq|
849: var elementLength = document.$formname.$role_element.length;
850: var allroles = Array($rolestr);
851: var courserolenames = Array($courserolestr);
852: var communityrolenames = Array($communityrolestr);
853: if (elementLength != undefined) {
854: if (document.$formname.$role_element.options[5].value == 'cc') {
855: if (crstype == 'Course') {
856: return;
857: } else {
858: allroles[5] = 'co';
859: for (var i=0; i<6; i++) {
860: document.$formname.$role_element.options[i].value = allroles[i];
861: document.$formname.$role_element.options[i].text = communityrolenames[i];
862: }
863: }
864: } else {
865: if (crstype == 'Community') {
866: return;
867: } else {
868: allroles[5] = 'cc';
869: for (var i=0; i<6; i++) {
870: document.$formname.$role_element.options[i].value = allroles[i];
871: document.$formname.$role_element.options[i].text = courserolenames[i];
872: }
873: }
874: }
875: }
876: return;
877: }
878: |;
879: }
1.1116 raeburn 880: if ($credits_element) {
881: $setsections .= qq|
882: function setCredits(defaultcredits) {
883: document.$formname.$credits_element.value = defaultcredits;
884: return;
885: }
886: |;
887: }
1.468 raeburn 888: return $setsections;
889: }
890:
1.91 www 891: sub selectcourse_link {
1.909 raeburn 892: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
893: $typeelement) = @_;
894: my $type = $selecttype;
1.871 raeburn 895: my $linktext = &mt('Select Course');
896: if ($selecttype eq 'Community') {
1.909 raeburn 897: $linktext = &mt('Select Community');
1.1239 raeburn 898: } elsif ($selecttype eq 'Placement') {
899: $linktext = &mt('Select Placement Test');
1.906 raeburn 900: } elsif ($selecttype eq 'Course/Community') {
901: $linktext = &mt('Select Course/Community');
1.909 raeburn 902: $type = '';
1.1019 raeburn 903: } elsif ($selecttype eq 'Select') {
904: $linktext = &mt('Select');
905: $type = '';
1.871 raeburn 906: }
1.787 bisitz 907: return '<span class="LC_nobreak">'
908: ."<a href='"
909: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
910: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 911: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 912: ."'>".$linktext.'</a>'
1.787 bisitz 913: .'</span>';
1.74 www 914: }
1.42 matthew 915:
1.653 raeburn 916: sub selectauthor_link {
917: my ($form,$udom)=@_;
918: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
919: &mt('Select Author').'</a>';
920: }
921:
1.876 raeburn 922: sub selectuser_link {
1.881 raeburn 923: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 924: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 925: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 926: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 927: ');">'.$linktext.'</a>';
1.876 raeburn 928: }
929:
1.273 raeburn 930: sub check_uncheck_jscript {
931: my $jscript = <<"ENDSCRT";
932: function checkAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
1.1093 raeburn 935: if (!field[i].disabled) {
936: field[i].checked = true;
937: }
1.273 raeburn 938: }
939: } else {
1.1093 raeburn 940: if (!field.disabled) {
941: field.checked = true;
942: }
1.273 raeburn 943: }
944: }
945:
946: function uncheckAll(field) {
947: if (field.length > 0) {
948: for (i = 0; i < field.length; i++) {
949: field[i].checked = false ;
1.543 albertel 950: }
951: } else {
1.273 raeburn 952: field.checked = false ;
953: }
954: }
955: ENDSCRT
956: return $jscript;
957: }
958:
1.656 www 959: sub select_timezone {
1.1256 raeburn 960: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
961: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 962: if ($includeempty) {
963: $output .= '<option value=""';
964: if (($selected eq '') || ($selected eq 'local')) {
965: $output .= ' selected="selected" ';
966: }
967: $output .= '> </option>';
968: }
1.657 raeburn 969: my @timezones = DateTime::TimeZone->all_names;
970: foreach my $tzone (@timezones) {
971: $output.= '<option value="'.$tzone.'"';
972: if ($tzone eq $selected) {
973: $output.=' selected="selected"';
974: }
975: $output.=">$tzone</option>\n";
1.656 www 976: }
977: $output.="</select>";
978: return $output;
979: }
1.273 raeburn 980:
1.687 raeburn 981: sub select_datelocale {
1.1256 raeburn 982: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
983: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 984: if ($includeempty) {
985: $output .= '<option value=""';
986: if ($selected eq '') {
987: $output .= ' selected="selected" ';
988: }
989: $output .= '> </option>';
990: }
1.1241 raeburn 991: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 992: my (@possibles,%locale_names);
1.1241 raeburn 993: my @locales = DateTime::Locale->ids();
994: foreach my $id (@locales) {
995: if ($id ne '') {
996: my ($en_terr,$native_terr);
997: my $loc = DateTime::Locale->load($id);
998: if (ref($loc)) {
999: $en_terr = $loc->name();
1000: $native_terr = $loc->native_name();
1.687 raeburn 1001: if (grep(/^en$/,@languages) || !@languages) {
1002: if ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: } elsif ($native_terr ne '') {
1005: $locale_names{$id} = $native_terr;
1006: }
1007: } else {
1008: if ($native_terr ne '') {
1009: $locale_names{$id} = $native_terr.' ';
1010: } elsif ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: }
1013: }
1.1220 raeburn 1014: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1015: push(@possibles,$id);
1016: }
1.687 raeburn 1017: }
1018: }
1019: foreach my $item (sort(@possibles)) {
1020: $output.= '<option value="'.$item.'"';
1021: if ($item eq $selected) {
1022: $output.=' selected="selected"';
1023: }
1024: $output.=">$item";
1025: if ($locale_names{$item} ne '') {
1.1220 raeburn 1026: $output.=' '.$locale_names{$item};
1.687 raeburn 1027: }
1028: $output.="</option>\n";
1029: }
1030: $output.="</select>";
1031: return $output;
1032: }
1033:
1.792 raeburn 1034: sub select_language {
1.1256 raeburn 1035: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1036: my %langchoices;
1037: if ($includeempty) {
1.1117 raeburn 1038: %langchoices = ('' => 'No language preference');
1.792 raeburn 1039: }
1040: foreach my $id (&languageids()) {
1041: my $code = &supportedlanguagecode($id);
1042: if ($code) {
1043: $langchoices{$code} = &plainlanguagedescription($id);
1044: }
1045: }
1.1117 raeburn 1046: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1047: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1048: }
1049:
1.42 matthew 1050: =pod
1.36 matthew 1051:
1.1088 foxr 1052:
1053: =item * &list_languages()
1054:
1055: Returns an array reference that is suitable for use in language prompters.
1056: Each array element is itself a two element array. The first element
1057: is the language code. The second element a descsriptiuon of the
1058: language itself. This is suitable for use in e.g.
1059: &Apache::edit::select_arg (once dereferenced that is).
1060:
1061: =cut
1062:
1063: sub list_languages {
1064: my @lang_choices;
1065:
1066: foreach my $id (&languageids()) {
1067: my $code = &supportedlanguagecode($id);
1068: if ($code) {
1069: my $selector = $supported_codes{$id};
1070: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1071: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1072: }
1073: }
1074: return \@lang_choices;
1075: }
1076:
1077: =pod
1078:
1.648 raeburn 1079: =item * &linked_select_forms(...)
1.36 matthew 1080:
1081: linked_select_forms returns a string containing a <script></script> block
1082: and html for two <select> menus. The select menus will be linked in that
1083: changing the value of the first menu will result in new values being placed
1084: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1085: order unless a defined order is provided.
1.36 matthew 1086:
1087: linked_select_forms takes the following ordered inputs:
1088:
1089: =over 4
1090:
1.112 bowersj2 1091: =item * $formname, the name of the <form> tag
1.36 matthew 1092:
1.112 bowersj2 1093: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1094:
1.112 bowersj2 1095: =item * $firstdefault, the default value for the first menu
1.36 matthew 1096:
1.112 bowersj2 1097: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1098:
1.112 bowersj2 1099: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1102:
1.609 raeburn 1103: =item * $menuorder, the order of values in the first menu
1104:
1.1115 raeburn 1105: =item * $onchangefirst, additional javascript call to execute for an onchange
1106: event for the first <select> tag
1107:
1108: =item * $onchangesecond, additional javascript call to execute for an onchange
1109: event for the second <select> tag
1110:
1.1245 raeburn 1111: =item * $suffix, to differentiate separate uses of select2data javascript
1112: objects in a page.
1113:
1.41 ng 1114: =back
1115:
1.36 matthew 1116: Below is an example of such a hash. Only the 'text', 'default', and
1117: 'select2' keys must appear as stated. keys(%menu) are the possible
1118: values for the first select menu. The text that coincides with the
1.41 ng 1119: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1120: and text for the second menu are given in the hash pointed to by
1121: $menu{$choice1}->{'select2'}.
1122:
1.112 bowersj2 1123: my %menu = ( A1 => { text =>"Choice A1" ,
1124: default => "B3",
1125: select2 => {
1126: B1 => "Choice B1",
1127: B2 => "Choice B2",
1128: B3 => "Choice B3",
1129: B4 => "Choice B4"
1.609 raeburn 1130: },
1131: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1132: },
1133: A2 => { text =>"Choice A2" ,
1134: default => "C2",
1135: select2 => {
1136: C1 => "Choice C1",
1137: C2 => "Choice C2",
1138: C3 => "Choice C3"
1.609 raeburn 1139: },
1140: order => ['C2','C1','C3'],
1.112 bowersj2 1141: },
1142: A3 => { text =>"Choice A3" ,
1143: default => "D6",
1144: select2 => {
1145: D1 => "Choice D1",
1146: D2 => "Choice D2",
1147: D3 => "Choice D3",
1148: D4 => "Choice D4",
1149: D5 => "Choice D5",
1150: D6 => "Choice D6",
1151: D7 => "Choice D7"
1.609 raeburn 1152: },
1153: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1154: }
1155: );
1.36 matthew 1156:
1157: =cut
1158:
1159: sub linked_select_forms {
1160: my ($formname,
1161: $middletext,
1162: $firstdefault,
1163: $firstselectname,
1164: $secondselectname,
1.609 raeburn 1165: $hashref,
1166: $menuorder,
1.1115 raeburn 1167: $onchangefirst,
1.1245 raeburn 1168: $onchangesecond,
1169: $suffix
1.36 matthew 1170: ) = @_;
1171: my $second = "document.$formname.$secondselectname";
1172: my $first = "document.$formname.$firstselectname";
1173: # output the javascript to do the changing
1174: my $result = '';
1.776 bisitz 1175: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1176: $result.="// <![CDATA[\n";
1.1245 raeburn 1177: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1178: $" = '","';
1179: my $debug = '';
1180: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1181: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1182: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1183: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1184: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1185: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1186: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1187: @s2values = @{$hashref->{$s1}->{'order'}};
1188: }
1.36 matthew 1189: $result.="\"@s2values\");\n";
1.1245 raeburn 1190: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1191: my @s2texts;
1192: foreach my $value (@s2values) {
1.1263 raeburn 1193: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1194: }
1195: $result.="\"@s2texts\");\n";
1196: }
1197: $"=' ';
1198: $result.= <<"END";
1199:
1.1245 raeburn 1200: function select1${suffix}_changed() {
1.36 matthew 1201: // Determine new choice
1.1245 raeburn 1202: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1203: // update select2
1.1245 raeburn 1204: var values = select2data${suffix}[newvalue].values;
1205: var texts = select2data${suffix}[newvalue].texts;
1206: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1207: var i;
1208: // out with the old
1.1245 raeburn 1209: $second.options.length = 0;
1210: // in with the new
1.36 matthew 1211: for (i=0;i<values.length; i++) {
1212: $second.options[i] = new Option(values[i]);
1.143 matthew 1213: $second.options[i].value = values[i];
1.36 matthew 1214: $second.options[i].text = texts[i];
1215: if (values[i] == select2def) {
1216: $second.options[i].selected = true;
1217: }
1218: }
1219: }
1.824 bisitz 1220: // ]]>
1.36 matthew 1221: </script>
1222: END
1223: # output the initial values for the selection lists
1.1245 raeburn 1224: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1225: my @order = sort(keys(%{$hashref}));
1226: if (ref($menuorder) eq 'ARRAY') {
1227: @order = @{$menuorder};
1228: }
1229: foreach my $value (@order) {
1.36 matthew 1230: $result.=" <option value=\"$value\" ";
1.253 albertel 1231: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1232: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1233: }
1234: $result .= "</select>\n";
1235: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1236: $result .= $middletext;
1.1115 raeburn 1237: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1238: if ($onchangesecond) {
1239: $result .= ' onchange="'.$onchangesecond.'"';
1240: }
1241: $result .= ">\n";
1.36 matthew 1242: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1243:
1244: my @secondorder = sort(keys(%select2));
1245: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1246: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1247: }
1248: foreach my $value (@secondorder) {
1.36 matthew 1249: $result.=" <option value=\"$value\" ";
1.253 albertel 1250: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1251: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1252: }
1253: $result .= "</select>\n";
1254: # return $debug;
1255: return $result;
1256: } # end of sub linked_select_forms {
1257:
1.45 matthew 1258: =pod
1.44 bowersj2 1259:
1.973 raeburn 1260: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1261:
1.112 bowersj2 1262: Returns a string corresponding to an HTML link to the given help
1263: $topic, where $topic corresponds to the name of a .tex file in
1264: /home/httpd/html/adm/help/tex, with underscores replaced by
1265: spaces.
1266:
1267: $text will optionally be linked to the same topic, allowing you to
1268: link text in addition to the graphic. If you do not want to link
1269: text, but wish to specify one of the later parameters, pass an
1270: empty string.
1271:
1272: $stayOnPage is a value that will be interpreted as a boolean. If true,
1273: the link will not open a new window. If false, the link will open
1274: a new window using Javascript. (Default is false.)
1275:
1276: $width and $height are optional numerical parameters that will
1277: override the width and height of the popped up window, which may
1.973 raeburn 1278: be useful for certain help topics with big pictures included.
1279:
1280: $imgid is the id of the img tag used for the help icon. This may be
1281: used in a javascript call to switch the image src. See
1282: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1283:
1284: =cut
1285:
1286: sub help_open_topic {
1.973 raeburn 1287: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1288: $text = "" if (not defined $text);
1.44 bowersj2 1289: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1290: $width = 500 if (not defined $width);
1.44 bowersj2 1291: $height = 400 if (not defined $height);
1292: my $filename = $topic;
1293: $filename =~ s/ /_/g;
1294:
1.48 bowersj2 1295: my $template = "";
1296: my $link;
1.572 banghart 1297:
1.159 www 1298: $topic=~s/\W/\_/g;
1.44 bowersj2 1299:
1.572 banghart 1300: if (!$stayOnPage) {
1.1033 www 1301: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1302: } elsif ($stayOnPage eq 'popup') {
1303: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1304: } else {
1.48 bowersj2 1305: $link = "/adm/help/${filename}.hlp";
1306: }
1307:
1308: # Add the text
1.1314 raeburn 1309: my $target = ' target="_top"';
1310: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1311: $target = '';
1312: }
1.755 neumanie 1313: if ($text ne "") {
1.763 bisitz 1314: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1315: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1316: .$text.'</a>';
1.48 bowersj2 1317: }
1318:
1.763 bisitz 1319: # (Always) Add the graphic
1.179 matthew 1320: my $title = &mt('Online Help');
1.667 raeburn 1321: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1322: if ($imgid ne '') {
1323: $imgid = ' id="'.$imgid.'"';
1324: }
1.1314 raeburn 1325: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1326: .'<img src="'.$helpicon.'" border="0"'
1327: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1328: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1329: .' /></a>';
1330: if ($text ne "") {
1331: $template.='</span>';
1332: }
1.44 bowersj2 1333: return $template;
1334:
1.106 bowersj2 1335: }
1336:
1337: # This is a quicky function for Latex cheatsheet editing, since it
1338: # appears in at least four places
1339: sub helpLatexCheatsheet {
1.1037 www 1340: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1341: my $out;
1.106 bowersj2 1342: my $addOther = '';
1.732 raeburn 1343: if ($topic) {
1.1037 www 1344: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1345: }
1346: $out = '<span>' # Start cheatsheet
1347: .$addOther
1348: .'<span>'
1.1037 www 1349: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1350: .'</span> <span>'
1.1037 www 1351: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1352: .'</span>';
1.732 raeburn 1353: unless ($not_author) {
1.1186 kruse 1354: $out .= '<span>'
1355: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1356: .'</span> <span>'
1357: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1358: .'</span>';
1.732 raeburn 1359: }
1.763 bisitz 1360: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1361: return $out;
1.172 www 1362: }
1363:
1.430 albertel 1364: sub general_help {
1365: my $helptopic='Student_Intro';
1366: if ($env{'request.role'}=~/^(ca|au)/) {
1367: $helptopic='Authoring_Intro';
1.907 raeburn 1368: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1369: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1370: } elsif ($env{'request.role'}=~/^dc/) {
1371: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1372: }
1373: return $helptopic;
1374: }
1375:
1376: sub update_help_link {
1377: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1378: my $origurl = $ENV{'REQUEST_URI'};
1379: $origurl=~s|^/~|/priv/|;
1380: my $timestamp = time;
1381: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1382: $$datum = &escape($$datum);
1383: }
1384:
1385: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1386: my $output .= <<"ENDOUTPUT";
1387: <script type="text/javascript">
1.824 bisitz 1388: // <![CDATA[
1.430 albertel 1389: banner_link = '$banner_link';
1.824 bisitz 1390: // ]]>
1.430 albertel 1391: </script>
1392: ENDOUTPUT
1393: return $output;
1394: }
1395:
1396: # now just updates the help link and generates a blue icon
1.193 raeburn 1397: sub help_open_menu {
1.430 albertel 1398: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1399: = @_;
1.949 droeschl 1400: $stayOnPage = 1;
1.430 albertel 1401: my $output;
1402: if ($component_help) {
1403: if (!$text) {
1404: $output=&help_open_topic($component_help,undef,$stayOnPage,
1405: $width,$height);
1406: } else {
1407: my $help_text;
1408: $help_text=&unescape($topic);
1409: $output='<table><tr><td>'.
1410: &help_open_topic($component_help,$help_text,$stayOnPage,
1411: $width,$height).'</td></tr></table>';
1412: }
1413: }
1414: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1415: return $output.$banner_link;
1416: }
1417:
1418: sub top_nav_help {
1.1369 raeburn 1419: my ($text,$linkattr) = @_;
1.436 albertel 1420: $text = &mt($text);
1.949 droeschl 1421: my $stay_on_page = 1;
1422:
1.1168 raeburn 1423: my ($link,$banner_link);
1424: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1425: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1426: : "javascript:helpMenu('open')";
1427: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1428: }
1.201 raeburn 1429: my $title = &mt('Get help');
1.1168 raeburn 1430: if ($link) {
1431: return <<"END";
1.436 albertel 1432: $banner_link
1.1369 raeburn 1433: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1434: END
1.1168 raeburn 1435: } else {
1436: return ' '.$text.' ';
1437: }
1.436 albertel 1438: }
1439:
1440: sub help_menu_js {
1.1154 raeburn 1441: my ($httphost) = @_;
1.949 droeschl 1442: my $stayOnPage = 1;
1.436 albertel 1443: my $width = 620;
1444: my $height = 600;
1.430 albertel 1445: my $helptopic=&general_help();
1.1154 raeburn 1446: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1447: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1448: my $start_page =
1449: &Apache::loncommon::start_page('Help Menu', undef,
1450: {'frameset' => 1,
1451: 'js_ready' => 1,
1.1154 raeburn 1452: 'use_absolute' => $httphost,
1.331 albertel 1453: 'add_entries' => {
1.1168 raeburn 1454: 'border' => '0',
1.579 raeburn 1455: 'rows' => "110,*",},});
1.331 albertel 1456: my $end_page =
1457: &Apache::loncommon::end_page({'frameset' => 1,
1458: 'js_ready' => 1,});
1459:
1.436 albertel 1460: my $template .= <<"ENDTEMPLATE";
1461: <script type="text/javascript">
1.877 bisitz 1462: // <![CDATA[
1.253 albertel 1463: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1464: var banner_link = '';
1.243 raeburn 1465: function helpMenu(target) {
1466: var caller = this;
1467: if (target == 'open') {
1468: var newWindow = null;
1469: try {
1.262 albertel 1470: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1471: }
1472: catch(error) {
1473: writeHelp(caller);
1474: return;
1475: }
1476: if (newWindow) {
1477: caller = newWindow;
1478: }
1.193 raeburn 1479: }
1.243 raeburn 1480: writeHelp(caller);
1481: return;
1482: }
1483: function writeHelp(caller) {
1.1168 raeburn 1484: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1485: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1486: caller.document.close();
1487: caller.focus();
1.193 raeburn 1488: }
1.877 bisitz 1489: // END LON-CAPA Internal -->
1.253 albertel 1490: // ]]>
1.436 albertel 1491: </script>
1.193 raeburn 1492: ENDTEMPLATE
1493: return $template;
1494: }
1495:
1.172 www 1496: sub help_open_bug {
1497: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1498: unless ($env{'user.adv'}) { return ''; }
1.172 www 1499: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1500: $text = "" if (not defined $text);
1501: $stayOnPage=1;
1.184 albertel 1502: $width = 600 if (not defined $width);
1503: $height = 600 if (not defined $height);
1.172 www 1504:
1505: $topic=~s/\W+/\+/g;
1506: my $link='';
1507: my $template='';
1.379 albertel 1508: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1509: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1510: if (!$stayOnPage)
1511: {
1512: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1513: }
1514: else
1515: {
1516: $link = $url;
1517: }
1.1314 raeburn 1518:
1519: my $target = ' target="_top"';
1520: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1521: $target = '';
1522: }
1.172 www 1523: # Add the text
1524: if ($text ne "")
1525: {
1526: $template .=
1527: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1528: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1529: }
1530:
1531: # Add the graphic
1.179 matthew 1532: my $title = &mt('Report a Bug');
1.215 albertel 1533: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1534: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1535: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1536: ENDTEMPLATE
1537: if ($text ne '') { $template.='</td></tr></table>' };
1538: return $template;
1539:
1540: }
1541:
1542: sub help_open_faq {
1543: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1544: unless ($env{'user.adv'}) { return ''; }
1.172 www 1545: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1546: $text = "" if (not defined $text);
1547: $stayOnPage=1;
1548: $width = 350 if (not defined $width);
1549: $height = 400 if (not defined $height);
1550:
1551: $topic=~s/\W+/\+/g;
1552: my $link='';
1553: my $template='';
1554: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1555: if (!$stayOnPage)
1556: {
1557: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1558: }
1559: else
1560: {
1561: $link = $url;
1562: }
1563:
1564: # Add the text
1565: if ($text ne "")
1566: {
1567: $template .=
1.173 www 1568: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1569: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1570: }
1571:
1572: # Add the graphic
1.179 matthew 1573: my $title = &mt('View the FAQ');
1.215 albertel 1574: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1575: $template .= <<"ENDTEMPLATE";
1.436 albertel 1576: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1577: ENDTEMPLATE
1578: if ($text ne '') { $template.='</td></tr></table>' };
1579: return $template;
1580:
1.44 bowersj2 1581: }
1.37 matthew 1582:
1.180 matthew 1583: ###############################################################
1584: ###############################################################
1585:
1.45 matthew 1586: =pod
1587:
1.648 raeburn 1588: =item * &change_content_javascript():
1.256 matthew 1589:
1590: This and the next function allow you to create small sections of an
1591: otherwise static HTML page that you can update on the fly with
1592: Javascript, even in Netscape 4.
1593:
1594: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1595: must be written to the HTML page once. It will prove the Javascript
1596: function "change(name, content)". Calling the change function with the
1597: name of the section
1598: you want to update, matching the name passed to C<changable_area>, and
1599: the new content you want to put in there, will put the content into
1600: that area.
1601:
1602: B<Note>: Netscape 4 only reserves enough space for the changable area
1603: to contain room for the original contents. You need to "make space"
1604: for whatever changes you wish to make, and be B<sure> to check your
1605: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1606: it's adequate for updating a one-line status display, but little more.
1607: This script will set the space to 100% width, so you only need to
1608: worry about height in Netscape 4.
1609:
1610: Modern browsers are much less limiting, and if you can commit to the
1611: user not using Netscape 4, this feature may be used freely with
1612: pretty much any HTML.
1613:
1614: =cut
1615:
1616: sub change_content_javascript {
1617: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1618: if ($env{'browser.type'} eq 'netscape' &&
1619: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1620: return (<<NETSCAPE4);
1621: function change(name, content) {
1622: doc = document.layers[name+"___escape"].layers[0].document;
1623: doc.open();
1624: doc.write(content);
1625: doc.close();
1626: }
1627: NETSCAPE4
1628: } else {
1629: # Otherwise, we need to use semi-standards-compliant code
1630: # (technically, "innerHTML" isn't standard but the equivalent
1631: # is really scary, and every useful browser supports it
1632: return (<<DOMBASED);
1633: function change(name, content) {
1634: element = document.getElementById(name);
1635: element.innerHTML = content;
1636: }
1637: DOMBASED
1638: }
1639: }
1640:
1641: =pod
1642:
1.648 raeburn 1643: =item * &changable_area($name,$origContent):
1.256 matthew 1644:
1645: This provides a "changable area" that can be modified on the fly via
1646: the Javascript code provided in C<change_content_javascript>. $name is
1647: the name you will use to reference the area later; do not repeat the
1648: same name on a given HTML page more then once. $origContent is what
1649: the area will originally contain, which can be left blank.
1650:
1651: =cut
1652:
1653: sub changable_area {
1654: my ($name, $origContent) = @_;
1655:
1.258 albertel 1656: if ($env{'browser.type'} eq 'netscape' &&
1657: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1658: # If this is netscape 4, we need to use the Layer tag
1659: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1660: } else {
1661: return "<span id='$name'>$origContent</span>";
1662: }
1663: }
1664:
1665: =pod
1666:
1.648 raeburn 1667: =item * &viewport_geometry_js
1.590 raeburn 1668:
1669: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1670:
1671: =cut
1672:
1673:
1674: sub viewport_geometry_js {
1675: return <<"GEOMETRY";
1676: var Geometry = {};
1677: function init_geometry() {
1678: if (Geometry.init) { return };
1679: Geometry.init=1;
1680: if (window.innerHeight) {
1681: Geometry.getViewportHeight = function() { return window.innerHeight; };
1682: Geometry.getViewportWidth = function() { return window.innerWidth; };
1683: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1684: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1685: }
1686: else if (document.documentElement && document.documentElement.clientHeight) {
1687: Geometry.getViewportHeight =
1688: function() { return document.documentElement.clientHeight; };
1689: Geometry.getViewportWidth =
1690: function() { return document.documentElement.clientWidth; };
1691:
1692: Geometry.getHorizontalScroll =
1693: function() { return document.documentElement.scrollLeft; };
1694: Geometry.getVerticalScroll =
1695: function() { return document.documentElement.scrollTop; };
1696: }
1697: else if (document.body.clientHeight) {
1698: Geometry.getViewportHeight =
1699: function() { return document.body.clientHeight; };
1700: Geometry.getViewportWidth =
1701: function() { return document.body.clientWidth; };
1702: Geometry.getHorizontalScroll =
1703: function() { return document.body.scrollLeft; };
1704: Geometry.getVerticalScroll =
1705: function() { return document.body.scrollTop; };
1706: }
1707: }
1708:
1709: GEOMETRY
1710: }
1711:
1712: =pod
1713:
1.648 raeburn 1714: =item * &viewport_size_js()
1.590 raeburn 1715:
1716: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1717:
1718: =cut
1719:
1720: sub viewport_size_js {
1721: my $geometry = &viewport_geometry_js();
1722: return <<"DIMS";
1723:
1724: $geometry
1725:
1726: function getViewportDims(width,height) {
1727: init_geometry();
1728: width.value = Geometry.getViewportWidth();
1729: height.value = Geometry.getViewportHeight();
1730: return;
1731: }
1732:
1733: DIMS
1734: }
1735:
1736: =pod
1737:
1.648 raeburn 1738: =item * &resize_textarea_js()
1.565 albertel 1739:
1740: emits the needed javascript to resize a textarea to be as big as possible
1741:
1742: creates a function resize_textrea that takes two IDs first should be
1743: the id of the element to resize, second should be the id of a div that
1744: surrounds everything that comes after the textarea, this routine needs
1745: to be attached to the <body> for the onload and onresize events.
1746:
1.648 raeburn 1747: =back
1.565 albertel 1748:
1749: =cut
1750:
1751: sub resize_textarea_js {
1.590 raeburn 1752: my $geometry = &viewport_geometry_js();
1.565 albertel 1753: return <<"RESIZE";
1754: <script type="text/javascript">
1.824 bisitz 1755: // <![CDATA[
1.590 raeburn 1756: $geometry
1.565 albertel 1757:
1.588 albertel 1758: function getX(element) {
1759: var x = 0;
1760: while (element) {
1761: x += element.offsetLeft;
1762: element = element.offsetParent;
1763: }
1764: return x;
1765: }
1766: function getY(element) {
1767: var y = 0;
1768: while (element) {
1769: y += element.offsetTop;
1770: element = element.offsetParent;
1771: }
1772: return y;
1773: }
1774:
1775:
1.565 albertel 1776: function resize_textarea(textarea_id,bottom_id) {
1777: init_geometry();
1778: var textarea = document.getElementById(textarea_id);
1779: //alert(textarea);
1780:
1.588 albertel 1781: var textarea_top = getY(textarea);
1.565 albertel 1782: var textarea_height = textarea.offsetHeight;
1783: var bottom = document.getElementById(bottom_id);
1.588 albertel 1784: var bottom_top = getY(bottom);
1.565 albertel 1785: var bottom_height = bottom.offsetHeight;
1786: var window_height = Geometry.getViewportHeight();
1.588 albertel 1787: var fudge = 23;
1.565 albertel 1788: var new_height = window_height-fudge-textarea_top-bottom_height;
1789: if (new_height < 300) {
1790: new_height = 300;
1791: }
1792: textarea.style.height=new_height+'px';
1793: }
1.824 bisitz 1794: // ]]>
1.565 albertel 1795: </script>
1796: RESIZE
1797:
1798: }
1799:
1.1205 golterma 1800: sub colorfuleditor_js {
1.1248 raeburn 1801: my $browse_or_search;
1802: my $respath;
1803: my ($cnum,$cdom) = &crsauthor_url();
1804: if ($cnum) {
1805: $respath = "/res/$cdom/$cnum/";
1806: my %js_lt = &Apache::lonlocal::texthash(
1807: sunm => 'Sub-directory name',
1808: save => 'Save page to make this permanent',
1809: );
1810: &js_escape(\%js_lt);
1811: $browse_or_search = <<"END";
1812:
1813: function toggleChooser(form,element,titleid,only,search) {
1814: var disp = 'none';
1815: if (document.getElementById('chooser_'+element)) {
1816: var curr = document.getElementById('chooser_'+element).style.display;
1817: if (curr == 'none') {
1818: disp='inline';
1819: if (form.elements['chooser_'+element].length) {
1820: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1821: form.elements['chooser_'+element][i].checked = false;
1822: }
1823: }
1824: toggleResImport(form,element);
1825: }
1826: document.getElementById('chooser_'+element).style.display = disp;
1827: }
1828: }
1829:
1830: function toggleCrsFile(form,element,numdirs) {
1831: if (document.getElementById('chooser_'+element+'_crsres')) {
1832: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1833: if (curr == 'none') {
1834: if (numdirs) {
1835: form.elements['coursepath_'+element].selectedIndex = 0;
1836: if (numdirs > 1) {
1837: window['select1'+element+'_changed']();
1838: }
1839: }
1840: }
1841: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1842:
1843: }
1844: if (document.getElementById('chooser_'+element+'_upload')) {
1845: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1846: if (document.getElementById('uploadcrsres_'+element)) {
1847: document.getElementById('uploadcrsres_'+element).value = '';
1848: }
1849: }
1850: return;
1851: }
1852:
1853: function toggleCrsUpload(form,element,numcrsdirs) {
1854: if (document.getElementById('chooser_'+element+'_crsres')) {
1855: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1856: }
1857: if (document.getElementById('chooser_'+element+'_upload')) {
1858: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1859: if (curr == 'none') {
1860: if (numcrsdirs) {
1861: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1862: form.elements['newsubdir_'+element][0].checked = true;
1863: toggleNewsubdir(form,element);
1864: }
1865: }
1866: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1867: }
1868: return;
1869: }
1870:
1871: function toggleResImport(form,element) {
1872: var choices = new Array('crsres','upload');
1873: for (var i=0; i<choices.length; i++) {
1874: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1875: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1876: }
1877: }
1878: }
1879:
1880: function toggleNewsubdir(form,element) {
1881: var newsub = form.elements['newsubdir_'+element];
1882: if (newsub) {
1883: if (newsub.length) {
1884: for (var j=0; j<newsub.length; j++) {
1885: if (newsub[j].checked) {
1886: if (document.getElementById('newsubdirname_'+element)) {
1887: if (newsub[j].value == '1') {
1888: document.getElementById('newsubdirname_'+element).type = "text";
1889: if (document.getElementById('newsubdir_'+element)) {
1890: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1891: }
1892: } else {
1893: document.getElementById('newsubdirname_'+element).type = "hidden";
1894: document.getElementById('newsubdirname_'+element).value = "";
1895: document.getElementById('newsubdir_'+element).innerHTML = "";
1896: }
1897: }
1898: break;
1899: }
1900: }
1901: }
1902: }
1903: }
1904:
1905: function updateCrsFile(form,element) {
1906: var directory = form.elements['coursepath_'+element];
1907: var filename = form.elements['coursefile_'+element];
1908: var path = directory.options[directory.selectedIndex].value;
1909: var file = filename.options[filename.selectedIndex].value;
1910: form.elements[element].value = '$respath';
1911: if (path == '/') {
1912: form.elements[element].value += file;
1913: } else {
1914: form.elements[element].value += path+'/'+file;
1915: }
1916: unClean();
1917: if (document.getElementById('previewimg_'+element)) {
1918: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1919: var newsrc = document.getElementById('previewimg_'+element).src;
1920: }
1921: if (document.getElementById('showimg_'+element)) {
1922: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1923: }
1924: toggleChooser(form,element);
1925: return;
1926: }
1927:
1928: function uploadDone(suffix,name) {
1929: if (name) {
1930: document.forms["lonhomework"].elements[suffix].value = name;
1931: unClean();
1932: toggleChooser(document.forms["lonhomework"],suffix);
1933: }
1934: }
1935:
1936: \$(document).ready(function(){
1937:
1938: \$(document).delegate('form :submit', 'click', function( event ) {
1939: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1940: var buttonId = this.id;
1941: var suffix = buttonId.toString();
1942: suffix = suffix.replace(/^crsupload_/,'');
1943: event.preventDefault();
1944: document.lonhomework.target = 'crsupload_target_'+suffix;
1945: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1946: \$(this.form).submit();
1947: document.lonhomework.target = '';
1948: if (document.getElementById('crsuploadto_'+suffix)) {
1949: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1950: }
1951: return false;
1952: }
1953: });
1954: });
1955: END
1956: }
1.1205 golterma 1957: return <<"COLORFULEDIT"
1958: <script type="text/javascript">
1959: // <![CDATA[>
1960: function fold_box(curDepth, lastresource){
1961:
1962: // we need a list because there can be several blocks you need to fold in one tag
1963: var block = document.getElementsByName('foldblock_'+curDepth);
1964: // but there is only one folding button per tag
1965: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1966:
1967: if(block.item(0).style.display == 'none'){
1968:
1969: foldbutton.value = '@{[&mt("Hide")]}';
1970: for (i = 0; i < block.length; i++){
1971: block.item(i).style.display = '';
1972: }
1973: }else{
1974:
1975: foldbutton.value = '@{[&mt("Show")]}';
1976: for (i = 0; i < block.length; i++){
1977: // block.item(i).style.visibility = 'collapse';
1978: block.item(i).style.display = 'none';
1979: }
1980: };
1981: saveState(lastresource);
1982: }
1983:
1984: function saveState (lastresource) {
1985:
1986: var tag_list = getTagList();
1987: if(tag_list != null){
1988: var timestamp = new Date().getTime();
1989: var key = lastresource;
1990:
1991: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1992: // starting with timestamp
1993: var value = timestamp+';';
1994:
1995: // building the list of key-value pairs
1996: for(var i = 0; i < tag_list.length; i++){
1997: value += tag_list[i]+',';
1998: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1999: }
2000:
2001: // only iterate whole storage if nothing to override
2002: if(localStorage.getItem(key) == null){
2003:
2004: // prevent storage from growing large
2005: if(localStorage.length > 50){
2006: var regex_getTimestamp = /^(?:\d)+;/;
2007: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2008: var oldest_key;
2009:
2010: for(var i = 1; i < localStorage.length; i++){
2011: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2012: oldest_key = localStorage.key(i);
2013: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2014: }
2015: }
2016: localStorage.removeItem(oldest_key);
2017: }
2018: }
2019: localStorage.setItem(key,value);
2020: }
2021: }
2022:
2023: // restore folding status of blocks (on page load)
2024: function restoreState (lastresource) {
2025: if(localStorage.getItem(lastresource) != null){
2026: var key = lastresource;
2027: var value = localStorage.getItem(key);
2028: var regex_delTimestamp = /^\d+;/;
2029:
2030: value.replace(regex_delTimestamp, '');
2031:
2032: var valueArr = value.split(';');
2033: var pairs;
2034: var elements;
2035: for (var i = 0; i < valueArr.length; i++){
2036: pairs = valueArr[i].split(',');
2037: elements = document.getElementsByName(pairs[0]);
2038:
2039: for (var j = 0; j < elements.length; j++){
2040: elements[j].style.display = pairs[1];
2041: if (pairs[1] == "none"){
2042: var regex_id = /([_\\d]+)\$/;
2043: regex_id.exec(pairs[0]);
2044: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2045: }
2046: }
2047: }
2048: }
2049: }
2050:
2051: function getTagList () {
2052:
2053: var stringToSearch = document.lonhomework.innerHTML;
2054:
2055: var ret = new Array();
2056: var regex_findBlock = /(foldblock_.*?)"/g;
2057: var tag_list = stringToSearch.match(regex_findBlock);
2058:
2059: if(tag_list != null){
2060: for(var i = 0; i < tag_list.length; i++){
2061: ret.push(tag_list[i].replace(/"/, ''));
2062: }
2063: }
2064: return ret;
2065: }
2066:
2067: function saveScrollPosition (resource) {
2068: var tag_list = getTagList();
2069:
2070: // we dont always want to jump to the first block
2071: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2072: if(\$(window).scrollTop() > 170){
2073: if(tag_list != null){
2074: var result;
2075: for(var i = 0; i < tag_list.length; i++){
2076: if(isElementInViewport(tag_list[i])){
2077: result += tag_list[i]+';';
2078: }
2079: }
2080: sessionStorage.setItem('anchor_'+resource, result);
2081: }
2082: } else {
2083: // we dont need to save zero, just delete the item to leave everything tidy
2084: sessionStorage.removeItem('anchor_'+resource);
2085: }
2086: }
2087:
2088: function restoreScrollPosition(resource){
2089:
2090: var elem = sessionStorage.getItem('anchor_'+resource);
2091: if(elem != null){
2092: var tag_list = elem.split(';');
2093: var elem_list;
2094:
2095: for(var i = 0; i < tag_list.length; i++){
2096: elem_list = document.getElementsByName(tag_list[i]);
2097:
2098: if(elem_list.length > 0){
2099: elem = elem_list[0];
2100: break;
2101: }
2102: }
2103: elem.scrollIntoView();
2104: }
2105: }
2106:
2107: function isElementInViewport(el) {
2108:
2109: // change to last element instead of first
2110: var elem = document.getElementsByName(el);
2111: var rect = elem[0].getBoundingClientRect();
2112:
2113: return (
2114: rect.top >= 0 &&
2115: rect.left >= 0 &&
2116: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2117: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2118: );
2119: }
2120:
2121: function autosize(depth){
2122: var cmInst = window['cm'+depth];
2123: var fitsizeButton = document.getElementById('fitsize'+depth);
2124:
2125: // is fixed size, switching to dynamic
2126: if (sessionStorage.getItem("autosized_"+depth) == null) {
2127: cmInst.setSize("","auto");
2128: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2129: sessionStorage.setItem("autosized_"+depth, "yes");
2130:
2131: // is dynamic size, switching to fixed
2132: } else {
2133: cmInst.setSize("","300px");
2134: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2135: sessionStorage.removeItem("autosized_"+depth);
2136: }
2137: }
2138:
1.1248 raeburn 2139: $browse_or_search
1.1205 golterma 2140:
2141: // ]]>
2142: </script>
2143: COLORFULEDIT
2144: }
2145:
2146: sub xmleditor_js {
2147: return <<XMLEDIT
2148: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2149: <script type="text/javascript">
2150: // <![CDATA[>
2151:
2152: function saveScrollPosition (resource) {
2153:
2154: var scrollPos = \$(window).scrollTop();
2155: sessionStorage.setItem(resource,scrollPos);
2156: }
2157:
2158: function restoreScrollPosition(resource){
2159:
2160: var scrollPos = sessionStorage.getItem(resource);
2161: \$(window).scrollTop(scrollPos);
2162: }
2163:
2164: // unless internet explorer
2165: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2166:
2167: \$(document).ready(function() {
2168: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2169: });
2170: }
2171:
2172: // inserts text at cursor position into codemirror (xml editor only)
2173: function insertText(text){
2174: cm.focus();
2175: var curPos = cm.getCursor();
2176: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2177: }
2178: // ]]>
2179: </script>
2180: XMLEDIT
2181: }
2182:
2183: sub insert_folding_button {
2184: my $curDepth = $Apache::lonxml::curdepth;
2185: my $lastresource = $env{'request.ambiguous'};
2186:
2187: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2188: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2189: }
2190:
1.1248 raeburn 2191: sub crsauthor_url {
2192: my ($url) = @_;
2193: if ($url eq '') {
2194: $url = $ENV{'REQUEST_URI'};
2195: }
2196: my ($cnum,$cdom);
2197: if ($env{'request.course.id'}) {
2198: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2199: if ($audom ne '' && $auname ne '') {
2200: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2201: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2202: $cnum = $auname;
2203: $cdom = $audom;
2204: }
2205: }
2206: }
2207: return ($cnum,$cdom);
2208: }
2209:
2210: sub import_crsauthor_form {
1.1265 raeburn 2211: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2212: return (0) unless ($env{'request.course.id'});
2213: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2214: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2215: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2216: return (0) unless (($cnum ne '') && ($cdom ne ''));
2217: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2218: my @ids=&Apache::lonnet::current_machine_ids();
2219: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2220:
2221: if (grep(/^\Q$crshome\E$/,@ids)) {
2222: $is_home = 1;
2223: }
2224: $relpath = "/priv/$cdom/$cnum";
2225: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2226: my %lt = &Apache::lonlocal::texthash (
2227: fnam => 'Filename',
2228: dire => 'Directory',
2229: );
2230: my $numdirs = scalar(keys(%files));
2231: my (%possexts,$singledir,@singledirfiles);
2232: if ($only) {
2233: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2234: }
2235: my (%nonemptydirs,$possdirs);
2236: if ($numdirs > 1) {
2237: my @order;
2238: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2239: if (ref($files{$key}) eq 'HASH') {
2240: my $shown = $key;
2241: if ($key eq '') {
2242: $shown = '/';
2243: }
2244: my @ordered = ();
2245: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2246: next if ($file =~ /\.rights$/);
1.1248 raeburn 2247: if ($only) {
2248: my ($ext) = ($file =~ /\.([^.]+)$/);
2249: unless ($possexts{lc($ext)}) {
2250: next;
2251: }
2252: }
2253: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2254: push(@ordered,$file);
2255: }
2256: if (@ordered) {
2257: push(@order,$key);
2258: $nonemptydirs{$key} = 1;
2259: $selimport_menus{$key}->{'text'} = $shown;
2260: $selimport_menus{$key}->{'default'} = '';
2261: $selimport_menus{$key}->{'select2'}->{''} = '';
2262: $selimport_menus{$key}->{'order'} = \@ordered;
2263: }
2264: }
2265: }
2266: $possdirs = scalar(keys(%nonemptydirs));
2267: if ($possdirs > 1) {
2268: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2269: $output = $lt{'dire'}.
2270: &linked_select_forms($form,'<br />'.
2271: $lt{'fnam'},'',
2272: $firstselectname,$secondselectname,
2273: \%selimport_menus,\@order,
2274: $onchangefirst,'',$suffix).'<br />';
2275: } elsif ($possdirs == 1) {
2276: $singledir = (keys(%nonemptydirs))[0];
2277: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2278: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2279: }
2280: delete($selimport_menus{$singledir});
2281: }
2282: } elsif ($numdirs == 1) {
2283: $singledir = (keys(%files))[0];
2284: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2285: if ($only) {
2286: my ($ext) = ($file =~ /\.([^.]+)$/);
2287: unless ($possexts{lc($ext)}) {
2288: next;
2289: }
1.1315 raeburn 2290: } else {
2291: next if ($file =~ /\.rights$/);
1.1248 raeburn 2292: }
2293: push(@singledirfiles,$file);
2294: }
2295: if (@singledirfiles) {
1.1315 raeburn 2296: $possdirs = 1;
1.1248 raeburn 2297: }
2298: }
2299: if (($possdirs == 1) && (@singledirfiles)) {
2300: my $showdir = $singledir;
2301: if ($singledir eq '') {
2302: $showdir = '/';
2303: }
2304: $output = $lt{'dire'}.
2305: '<select name="'.$firstselectname.'">'.
2306: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2307: '</select><br />'.
2308: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2309: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2310: foreach my $file (@singledirfiles) {
2311: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2312: }
2313: $output .= '</select><br />'."\n";
2314: }
2315: return ($possdirs,$output);
2316: }
2317:
1.565 albertel 2318: =pod
2319:
1.256 matthew 2320: =head1 Excel and CSV file utility routines
2321:
2322: =cut
2323:
2324: ###############################################################
2325: ###############################################################
2326:
2327: =pod
2328:
1.1162 raeburn 2329: =over 4
2330:
1.648 raeburn 2331: =item * &csv_translate($text)
1.37 matthew 2332:
1.185 www 2333: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2334: format.
2335:
2336: =cut
2337:
1.180 matthew 2338: ###############################################################
2339: ###############################################################
1.37 matthew 2340: sub csv_translate {
2341: my $text = shift;
2342: $text =~ s/\"/\"\"/g;
1.209 albertel 2343: $text =~ s/\n/ /g;
1.37 matthew 2344: return $text;
2345: }
1.180 matthew 2346:
2347: ###############################################################
2348: ###############################################################
2349:
2350: =pod
2351:
1.648 raeburn 2352: =item * &define_excel_formats()
1.180 matthew 2353:
2354: Define some commonly used Excel cell formats.
2355:
2356: Currently supported formats:
2357:
2358: =over 4
2359:
2360: =item header
2361:
2362: =item bold
2363:
2364: =item h1
2365:
2366: =item h2
2367:
2368: =item h3
2369:
1.256 matthew 2370: =item h4
2371:
2372: =item i
2373:
1.180 matthew 2374: =item date
2375:
2376: =back
2377:
2378: Inputs: $workbook
2379:
2380: Returns: $format, a hash reference.
2381:
1.1057 foxr 2382:
1.180 matthew 2383: =cut
2384:
2385: ###############################################################
2386: ###############################################################
2387: sub define_excel_formats {
2388: my ($workbook) = @_;
2389: my $format;
2390: $format->{'header'} = $workbook->add_format(bold => 1,
2391: bottom => 1,
2392: align => 'center');
2393: $format->{'bold'} = $workbook->add_format(bold=>1);
2394: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2395: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2396: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2397: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2398: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2399: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2400: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2401: return $format;
2402: }
2403:
2404: ###############################################################
2405: ###############################################################
1.113 bowersj2 2406:
2407: =pod
2408:
1.648 raeburn 2409: =item * &create_workbook()
1.255 matthew 2410:
2411: Create an Excel worksheet. If it fails, output message on the
2412: request object and return undefs.
2413:
2414: Inputs: Apache request object
2415:
2416: Returns (undef) on failure,
2417: Excel worksheet object, scalar with filename, and formats
2418: from &Apache::loncommon::define_excel_formats on success
2419:
2420: =cut
2421:
2422: ###############################################################
2423: ###############################################################
2424: sub create_workbook {
2425: my ($r) = @_;
2426: #
2427: # Create the excel spreadsheet
2428: my $filename = '/prtspool/'.
1.258 albertel 2429: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2430: time.'_'.rand(1000000000).'.xls';
2431: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2432: if (! defined($workbook)) {
2433: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2434: $r->print(
2435: '<p class="LC_error">'
2436: .&mt('Problems occurred in creating the new Excel file.')
2437: .' '.&mt('This error has been logged.')
2438: .' '.&mt('Please alert your LON-CAPA administrator.')
2439: .'</p>'
2440: );
1.255 matthew 2441: return (undef);
2442: }
2443: #
1.1014 foxr 2444: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2445: #
2446: my $format = &Apache::loncommon::define_excel_formats($workbook);
2447: return ($workbook,$filename,$format);
2448: }
2449:
2450: ###############################################################
2451: ###############################################################
2452:
2453: =pod
2454:
1.648 raeburn 2455: =item * &create_text_file()
1.113 bowersj2 2456:
1.542 raeburn 2457: Create a file to write to and eventually make available to the user.
1.256 matthew 2458: If file creation fails, outputs an error message on the request object and
2459: return undefs.
1.113 bowersj2 2460:
1.256 matthew 2461: Inputs: Apache request object, and file suffix
1.113 bowersj2 2462:
1.256 matthew 2463: Returns (undef) on failure,
2464: Filehandle and filename on success.
1.113 bowersj2 2465:
2466: =cut
2467:
1.256 matthew 2468: ###############################################################
2469: ###############################################################
2470: sub create_text_file {
2471: my ($r,$suffix) = @_;
2472: if (! defined($suffix)) { $suffix = 'txt'; };
2473: my $fh;
2474: my $filename = '/prtspool/'.
1.258 albertel 2475: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2476: time.'_'.rand(1000000000).'.'.$suffix;
2477: $fh = Apache::File->new('>/home/httpd'.$filename);
2478: if (! defined($fh)) {
2479: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2480: $r->print(
2481: '<p class="LC_error">'
2482: .&mt('Problems occurred in creating the output file.')
2483: .' '.&mt('This error has been logged.')
2484: .' '.&mt('Please alert your LON-CAPA administrator.')
2485: .'</p>'
2486: );
1.113 bowersj2 2487: }
1.256 matthew 2488: return ($fh,$filename)
1.113 bowersj2 2489: }
2490:
2491:
1.256 matthew 2492: =pod
1.113 bowersj2 2493:
2494: =back
2495:
2496: =cut
1.37 matthew 2497:
2498: ###############################################################
1.33 matthew 2499: ## Home server <option> list generating code ##
2500: ###############################################################
1.35 matthew 2501:
1.169 www 2502: # ------------------------------------------
2503:
2504: sub domain_select {
1.1289 raeburn 2505: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2506: my @possdoms;
2507: if (ref($incdoms) eq 'ARRAY') {
2508: @possdoms = @{$incdoms};
2509: } else {
2510: @possdoms = &Apache::lonnet::all_domains();
2511: }
2512:
1.169 www 2513: my %domains=map {
1.514 albertel 2514: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2515: } @possdoms;
2516:
2517: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2518: foreach my $dom (@{$excdoms}) {
2519: delete($domains{$dom});
2520: }
2521: }
2522:
1.169 www 2523: if ($multiple) {
2524: $domains{''}=&mt('Any domain');
1.550 albertel 2525: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2526: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2527: } else {
1.550 albertel 2528: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2529: return &select_form($name,$value,\%domains);
1.169 www 2530: }
2531: }
2532:
1.282 albertel 2533: #-------------------------------------------
2534:
2535: =pod
2536:
1.519 raeburn 2537: =head1 Routines for form select boxes
2538:
2539: =over 4
2540:
1.648 raeburn 2541: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2542:
2543: Returns a string containing a <select> element int multiple mode
2544:
2545:
2546: Args:
2547: $name - name of the <select> element
1.506 raeburn 2548: $value - scalar or array ref of values that should already be selected
1.282 albertel 2549: $size - number of rows long the select element is
1.283 albertel 2550: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2551: (shown text should already have been &mt())
1.506 raeburn 2552: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2553:
1.282 albertel 2554: =cut
2555:
2556: #-------------------------------------------
1.169 www 2557: sub multiple_select_form {
1.284 albertel 2558: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2559: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2560: my $output='';
1.191 matthew 2561: if (! defined($size)) {
2562: $size = 4;
1.283 albertel 2563: if (scalar(keys(%$hash))<4) {
2564: $size = scalar(keys(%$hash));
1.191 matthew 2565: }
2566: }
1.734 bisitz 2567: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2568: my @order;
1.506 raeburn 2569: if (ref($order) eq 'ARRAY') {
2570: @order = @{$order};
2571: } else {
2572: @order = sort(keys(%$hash));
1.501 banghart 2573: }
2574: if (exists($$hash{'select_form_order'})) {
2575: @order = @{$$hash{'select_form_order'}};
2576: }
2577:
1.284 albertel 2578: foreach my $key (@order) {
1.356 albertel 2579: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2580: $output.='selected="selected" ' if ($selected{$key});
2581: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2582: }
2583: $output.="</select>\n";
2584: return $output;
2585: }
2586:
1.88 www 2587: #-------------------------------------------
2588:
2589: =pod
2590:
1.1254 raeburn 2591: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2592:
2593: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2594: allow a user to select options from a ref to a hash containing:
2595: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2596: a javascript onchange item, e.g., onchange="this.form.submit();".
2597: An optional arg -- $readonly -- if true will cause the select form
2598: to be disabled, e.g., for the case where an instructor has a section-
2599: specific role, and is viewing/modifying parameters.
1.970 raeburn 2600:
1.88 www 2601: See lonrights.pm for an example invocation and use.
2602:
2603: =cut
2604:
2605: #-------------------------------------------
2606: sub select_form {
1.1228 raeburn 2607: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2608: return unless (ref($hashref) eq 'HASH');
2609: if ($onchange) {
2610: $onchange = ' onchange="'.$onchange.'"';
2611: }
1.1228 raeburn 2612: my $disabled;
2613: if ($readonly) {
2614: $disabled = ' disabled="disabled"';
2615: }
2616: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2617: my @keys;
1.970 raeburn 2618: if (exists($hashref->{'select_form_order'})) {
2619: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2620: } else {
1.970 raeburn 2621: @keys=sort(keys(%{$hashref}));
1.128 albertel 2622: }
1.356 albertel 2623: foreach my $key (@keys) {
2624: $selectform.=
2625: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2626: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2627: ">".$hashref->{$key}."</option>\n";
1.88 www 2628: }
2629: $selectform.="</select>";
2630: return $selectform;
2631: }
2632:
1.475 www 2633: # For display filters
2634:
2635: sub display_filter {
1.1074 raeburn 2636: my ($context) = @_;
1.475 www 2637: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2638: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2639: my $phraseinput = 'hidden';
2640: my $includeinput = 'hidden';
2641: my ($checked,$includetypestext);
2642: if ($env{'form.displayfilter'} eq 'containing') {
2643: $phraseinput = 'text';
2644: if ($context eq 'parmslog') {
2645: $includeinput = 'checkbox';
2646: if ($env{'form.includetypes'}) {
2647: $checked = ' checked="checked"';
2648: }
2649: $includetypestext = &mt('Include parameter types');
2650: }
2651: } else {
2652: $includetypestext = ' ';
2653: }
2654: my ($additional,$secondid,$thirdid);
2655: if ($context eq 'parmslog') {
2656: $additional =
2657: '<label><input type="'.$includeinput.'" name="includetypes"'.
2658: $checked.' name="includetypes" value="1" id="includetypes" />'.
2659: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2660: '</label>';
2661: $secondid = 'includetypes';
2662: $thirdid = 'includetypestext';
2663: }
2664: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2665: '$secondid','$thirdid')";
2666: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2667: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2668: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2669: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2670: &mt('Filter: [_1]',
1.477 www 2671: &select_form($env{'form.displayfilter'},
2672: 'displayfilter',
1.970 raeburn 2673: {'currentfolder' => 'Current folder/page',
1.477 www 2674: 'containing' => 'Containing phrase',
1.1074 raeburn 2675: 'none' => 'None'},$onchange)).' '.
2676: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2677: &HTML::Entities::encode($env{'form.containingphrase'}).
2678: '" />'.$additional;
2679: }
2680:
2681: sub display_filter_js {
2682: my $includetext = &mt('Include parameter types');
2683: return <<"ENDJS";
2684:
2685: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2686: var firstType = 'hidden';
2687: if (setter.options[setter.selectedIndex].value == 'containing') {
2688: firstType = 'text';
2689: }
2690: firstObject = document.getElementById(firstid);
2691: if (typeof(firstObject) == 'object') {
2692: if (firstObject.type != firstType) {
2693: changeInputType(firstObject,firstType);
2694: }
2695: }
2696: if (context == 'parmslog') {
2697: var secondType = 'hidden';
2698: if (firstType == 'text') {
2699: secondType = 'checkbox';
2700: }
2701: secondObject = document.getElementById(secondid);
2702: if (typeof(secondObject) == 'object') {
2703: if (secondObject.type != secondType) {
2704: changeInputType(secondObject,secondType);
2705: }
2706: }
2707: var textItem = document.getElementById(thirdid);
2708: var currtext = textItem.innerHTML;
2709: var newtext;
2710: if (firstType == 'text') {
2711: newtext = '$includetext';
2712: } else {
2713: newtext = ' ';
2714: }
2715: if (currtext != newtext) {
2716: textItem.innerHTML = newtext;
2717: }
2718: }
2719: return;
2720: }
2721:
2722: function changeInputType(oldObject,newType) {
2723: var newObject = document.createElement('input');
2724: newObject.type = newType;
2725: if (oldObject.size) {
2726: newObject.size = oldObject.size;
2727: }
2728: if (oldObject.value) {
2729: newObject.value = oldObject.value;
2730: }
2731: if (oldObject.name) {
2732: newObject.name = oldObject.name;
2733: }
2734: if (oldObject.id) {
2735: newObject.id = oldObject.id;
2736: }
2737: oldObject.parentNode.replaceChild(newObject,oldObject);
2738: return;
2739: }
2740:
2741: ENDJS
1.475 www 2742: }
2743:
1.167 www 2744: sub gradeleveldescription {
2745: my $gradelevel=shift;
2746: my %gradelevels=(0 => 'Not specified',
2747: 1 => 'Grade 1',
2748: 2 => 'Grade 2',
2749: 3 => 'Grade 3',
2750: 4 => 'Grade 4',
2751: 5 => 'Grade 5',
2752: 6 => 'Grade 6',
2753: 7 => 'Grade 7',
2754: 8 => 'Grade 8',
2755: 9 => 'Grade 9',
2756: 10 => 'Grade 10',
2757: 11 => 'Grade 11',
2758: 12 => 'Grade 12',
2759: 13 => 'Grade 13',
2760: 14 => '100 Level',
2761: 15 => '200 Level',
2762: 16 => '300 Level',
2763: 17 => '400 Level',
2764: 18 => 'Graduate Level');
2765: return &mt($gradelevels{$gradelevel});
2766: }
2767:
1.163 www 2768: sub select_level_form {
2769: my ($deflevel,$name)=@_;
2770: unless ($deflevel) { $deflevel=0; }
1.167 www 2771: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2772: for (my $i=0; $i<=18; $i++) {
2773: $selectform.="<option value=\"$i\" ".
1.253 albertel 2774: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2775: ">".&gradeleveldescription($i)."</option>\n";
2776: }
2777: $selectform.="</select>";
2778: return $selectform;
1.163 www 2779: }
1.167 www 2780:
1.35 matthew 2781: #-------------------------------------------
2782:
1.45 matthew 2783: =pod
2784:
1.1256 raeburn 2785: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2786:
2787: Returns a string containing a <select name='$name' size='1'> form to
2788: allow a user to select the domain to preform an operation in.
2789: See loncreateuser.pm for an example invocation and use.
2790:
1.90 www 2791: If the $includeempty flag is set, it also includes an empty choice ("no domain
2792: selected");
2793:
1.743 raeburn 2794: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2795:
1.910 raeburn 2796: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2797:
1.1121 raeburn 2798: The optional $incdoms is a reference to an array of domains which will be the only available options.
2799:
2800: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2801:
1.1256 raeburn 2802: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2803:
1.35 matthew 2804: =cut
2805:
2806: #-------------------------------------------
1.34 matthew 2807: sub select_dom_form {
1.1256 raeburn 2808: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2809: if ($onchange) {
1.874 raeburn 2810: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2811: }
1.1256 raeburn 2812: if ($disabled) {
2813: $disabled = ' disabled="disabled"';
2814: }
1.1121 raeburn 2815: my (@domains,%exclude);
1.910 raeburn 2816: if (ref($incdoms) eq 'ARRAY') {
2817: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2818: } else {
2819: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2820: }
1.90 www 2821: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2822: if (ref($excdoms) eq 'ARRAY') {
2823: map { $exclude{$_} = 1; } @{$excdoms};
2824: }
1.1256 raeburn 2825: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2826: foreach my $dom (@domains) {
1.1121 raeburn 2827: next if ($exclude{$dom});
1.356 albertel 2828: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2829: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2830: if ($showdomdesc) {
2831: if ($dom ne '') {
2832: my $domdesc = &Apache::lonnet::domain($dom,'description');
2833: if ($domdesc ne '') {
2834: $selectdomain .= ' ('.$domdesc.')';
2835: }
2836: }
2837: }
2838: $selectdomain .= "</option>\n";
1.34 matthew 2839: }
2840: $selectdomain.="</select>";
2841: return $selectdomain;
2842: }
2843:
1.35 matthew 2844: #-------------------------------------------
2845:
1.45 matthew 2846: =pod
2847:
1.648 raeburn 2848: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2849:
1.586 raeburn 2850: input: 4 arguments (two required, two optional) -
2851: $domain - domain of new user
2852: $name - name of form element
2853: $default - Value of 'default' causes a default item to be first
2854: option, and selected by default.
2855: $hide - Value of 'hide' causes hiding of the name of the server,
2856: if 1 server found, or default, if 0 found.
1.594 raeburn 2857: output: returns 2 items:
1.586 raeburn 2858: (a) form element which contains either:
2859: (i) <select name="$name">
2860: <option value="$hostid1">$hostid $servers{$hostid}</option>
2861: <option value="$hostid2">$hostid $servers{$hostid}</option>
2862: </select>
2863: form item if there are multiple library servers in $domain, or
2864: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2865: if there is only one library server in $domain.
2866:
2867: (b) number of library servers found.
2868:
2869: See loncreateuser.pm for example of use.
1.35 matthew 2870:
2871: =cut
2872:
2873: #-------------------------------------------
1.586 raeburn 2874: sub home_server_form_item {
2875: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2876: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2877: my $result;
2878: my $numlib = keys(%servers);
2879: if ($numlib > 1) {
2880: $result .= '<select name="'.$name.'" />'."\n";
2881: if ($default) {
1.804 bisitz 2882: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2883: '</option>'."\n";
2884: }
2885: foreach my $hostid (sort(keys(%servers))) {
2886: $result.= '<option value="'.$hostid.'">'.
2887: $hostid.' '.$servers{$hostid}."</option>\n";
2888: }
2889: $result .= '</select>'."\n";
2890: } elsif ($numlib == 1) {
2891: my $hostid;
2892: foreach my $item (keys(%servers)) {
2893: $hostid = $item;
2894: }
2895: $result .= '<input type="hidden" name="'.$name.'" value="'.
2896: $hostid.'" />';
2897: if (!$hide) {
2898: $result .= $hostid.' '.$servers{$hostid};
2899: }
2900: $result .= "\n";
2901: } elsif ($default) {
2902: $result .= '<input type="hidden" name="'.$name.
2903: '" value="default" />';
2904: if (!$hide) {
2905: $result .= &mt('default');
2906: }
2907: $result .= "\n";
1.33 matthew 2908: }
1.586 raeburn 2909: return ($result,$numlib);
1.33 matthew 2910: }
1.112 bowersj2 2911:
2912: =pod
2913:
1.534 albertel 2914: =back
2915:
1.112 bowersj2 2916: =cut
1.87 matthew 2917:
2918: ###############################################################
1.112 bowersj2 2919: ## Decoding User Agent ##
1.87 matthew 2920: ###############################################################
2921:
2922: =pod
2923:
1.112 bowersj2 2924: =head1 Decoding the User Agent
2925:
2926: =over 4
2927:
2928: =item * &decode_user_agent()
1.87 matthew 2929:
2930: Inputs: $r
2931:
2932: Outputs:
2933:
2934: =over 4
2935:
1.112 bowersj2 2936: =item * $httpbrowser
1.87 matthew 2937:
1.112 bowersj2 2938: =item * $clientbrowser
1.87 matthew 2939:
1.112 bowersj2 2940: =item * $clientversion
1.87 matthew 2941:
1.112 bowersj2 2942: =item * $clientmathml
1.87 matthew 2943:
1.112 bowersj2 2944: =item * $clientunicode
1.87 matthew 2945:
1.112 bowersj2 2946: =item * $clientos
1.87 matthew 2947:
1.1137 raeburn 2948: =item * $clientmobile
2949:
1.1141 raeburn 2950: =item * $clientinfo
2951:
1.1194 raeburn 2952: =item * $clientosversion
2953:
1.87 matthew 2954: =back
2955:
1.157 matthew 2956: =back
2957:
1.87 matthew 2958: =cut
2959:
2960: ###############################################################
2961: ###############################################################
2962: sub decode_user_agent {
1.247 albertel 2963: my ($r)=@_;
1.87 matthew 2964: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2965: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2966: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2967: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2968: my $clientbrowser='unknown';
2969: my $clientversion='0';
2970: my $clientmathml='';
2971: my $clientunicode='0';
1.1137 raeburn 2972: my $clientmobile=0;
1.1194 raeburn 2973: my $clientosversion='';
1.87 matthew 2974: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2975: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2976: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2977: $clientbrowser=$bname;
2978: $httpbrowser=~/$vreg/i;
2979: $clientversion=$1;
2980: $clientmathml=($clientversion>=$minv);
2981: $clientunicode=($clientversion>=$univ);
2982: }
2983: }
2984: my $clientos='unknown';
1.1141 raeburn 2985: my $clientinfo;
1.87 matthew 2986: if (($httpbrowser=~/linux/i) ||
2987: ($httpbrowser=~/unix/i) ||
2988: ($httpbrowser=~/ux/i) ||
2989: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2990: if (($httpbrowser=~/vax/i) ||
2991: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2992: if ($httpbrowser=~/next/i) { $clientos='next'; }
2993: if (($httpbrowser=~/mac/i) ||
2994: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2995: if ($httpbrowser=~/win/i) {
2996: $clientos='win';
2997: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2998: $clientosversion = $1;
2999: }
3000: }
1.87 matthew 3001: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3002: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3003: $clientmobile=lc($1);
3004: }
1.1141 raeburn 3005: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3006: $clientinfo = 'firefox-'.$1;
3007: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3008: $clientinfo = 'chromeframe-'.$1;
3009: }
1.87 matthew 3010: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3011: $clientunicode,$clientos,$clientmobile,$clientinfo,
3012: $clientosversion);
1.87 matthew 3013: }
3014:
1.32 matthew 3015: ###############################################################
3016: ## Authentication changing form generation subroutines ##
3017: ###############################################################
3018: ##
3019: ## All of the authform_xxxxxxx subroutines take their inputs in a
3020: ## hash, and have reasonable default values.
3021: ##
3022: ## formname = the name given in the <form> tag.
1.35 matthew 3023: #-------------------------------------------
3024:
1.45 matthew 3025: =pod
3026:
1.112 bowersj2 3027: =head1 Authentication Routines
3028:
3029: =over 4
3030:
1.648 raeburn 3031: =item * &authform_xxxxxx()
1.35 matthew 3032:
3033: The authform_xxxxxx subroutines provide javascript and html forms which
3034: handle some of the conveniences required for authentication forms.
3035: This is not an optimal method, but it works.
3036:
3037: =over 4
3038:
1.112 bowersj2 3039: =item * authform_header
1.35 matthew 3040:
1.112 bowersj2 3041: =item * authform_authorwarning
1.35 matthew 3042:
1.112 bowersj2 3043: =item * authform_nochange
1.35 matthew 3044:
1.112 bowersj2 3045: =item * authform_kerberos
1.35 matthew 3046:
1.112 bowersj2 3047: =item * authform_internal
1.35 matthew 3048:
1.112 bowersj2 3049: =item * authform_filesystem
1.35 matthew 3050:
1.1310 raeburn 3051: =item * authform_lti
3052:
1.35 matthew 3053: =back
3054:
1.648 raeburn 3055: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3056:
1.35 matthew 3057: =cut
3058:
3059: #-------------------------------------------
1.32 matthew 3060: sub authform_header{
3061: my %in = (
3062: formname => 'cu',
1.80 albertel 3063: kerb_def_dom => '',
1.32 matthew 3064: @_,
3065: );
3066: $in{'formname'} = 'document.' . $in{'formname'};
3067: my $result='';
1.80 albertel 3068:
3069: #---------------------------------------------- Code for upper case translation
3070: my $Javascript_toUpperCase;
3071: unless ($in{kerb_def_dom}) {
3072: $Javascript_toUpperCase =<<"END";
3073: switch (choice) {
3074: case 'krb': currentform.elements[choicearg].value =
3075: currentform.elements[choicearg].value.toUpperCase();
3076: break;
3077: default:
3078: }
3079: END
3080: } else {
3081: $Javascript_toUpperCase = "";
3082: }
3083:
1.165 raeburn 3084: my $radioval = "'nochange'";
1.591 raeburn 3085: if (defined($in{'curr_authtype'})) {
3086: if ($in{'curr_authtype'} ne '') {
3087: $radioval = "'".$in{'curr_authtype'}."arg'";
3088: }
1.174 matthew 3089: }
1.165 raeburn 3090: my $argfield = 'null';
1.591 raeburn 3091: if (defined($in{'mode'})) {
1.165 raeburn 3092: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3093: if (defined($in{'curr_autharg'})) {
3094: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3095: $argfield = "'$in{'curr_autharg'}'";
3096: }
3097: }
3098: }
3099: }
3100:
1.32 matthew 3101: $result.=<<"END";
3102: var current = new Object();
1.165 raeburn 3103: current.radiovalue = $radioval;
3104: current.argfield = $argfield;
1.32 matthew 3105:
3106: function changed_radio(choice,currentform) {
3107: var choicearg = choice + 'arg';
3108: // If a radio button in changed, we need to change the argfield
3109: if (current.radiovalue != choice) {
3110: current.radiovalue = choice;
3111: if (current.argfield != null) {
3112: currentform.elements[current.argfield].value = '';
3113: }
3114: if (choice == 'nochange') {
3115: current.argfield = null;
3116: } else {
3117: current.argfield = choicearg;
3118: switch(choice) {
3119: case 'krb':
3120: currentform.elements[current.argfield].value =
3121: "$in{'kerb_def_dom'}";
3122: break;
3123: default:
3124: break;
3125: }
3126: }
3127: }
3128: return;
3129: }
1.22 www 3130:
1.32 matthew 3131: function changed_text(choice,currentform) {
3132: var choicearg = choice + 'arg';
3133: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3134: $Javascript_toUpperCase
1.32 matthew 3135: // clear old field
3136: if ((current.argfield != choicearg) && (current.argfield != null)) {
3137: currentform.elements[current.argfield].value = '';
3138: }
3139: current.argfield = choicearg;
3140: }
3141: set_auth_radio_buttons(choice,currentform);
3142: return;
1.20 www 3143: }
1.32 matthew 3144:
3145: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3146: var numauthchoices = currentform.login.length;
3147: if (typeof numauthchoices == "undefined") {
3148: return;
3149: }
1.32 matthew 3150: var i=0;
1.986 raeburn 3151: while (i < numauthchoices) {
1.32 matthew 3152: if (currentform.login[i].value == newvalue) { break; }
3153: i++;
3154: }
1.986 raeburn 3155: if (i == numauthchoices) {
1.32 matthew 3156: return;
3157: }
3158: current.radiovalue = newvalue;
3159: currentform.login[i].checked = true;
3160: return;
3161: }
3162: END
3163: return $result;
3164: }
3165:
1.1106 raeburn 3166: sub authform_authorwarning {
1.32 matthew 3167: my $result='';
1.144 matthew 3168: $result='<i>'.
3169: &mt('As a general rule, only authors or co-authors should be '.
3170: 'filesystem authenticated '.
3171: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3172: return $result;
3173: }
3174:
1.1106 raeburn 3175: sub authform_nochange {
1.32 matthew 3176: my %in = (
3177: formname => 'document.cu',
3178: kerb_def_dom => 'MSU.EDU',
3179: @_,
3180: );
1.1106 raeburn 3181: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3182: my $result;
1.1104 raeburn 3183: if (!$authnum) {
1.1105 raeburn 3184: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3185: } else {
3186: $result = '<label>'.&mt('[_1] Do not change login data',
3187: '<input type="radio" name="login" value="nochange" '.
3188: 'checked="checked" onclick="'.
1.281 albertel 3189: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3190: '</label>';
1.586 raeburn 3191: }
1.32 matthew 3192: return $result;
3193: }
3194:
1.591 raeburn 3195: sub authform_kerberos {
1.32 matthew 3196: my %in = (
3197: formname => 'document.cu',
3198: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3199: kerb_def_auth => 'krb4',
1.32 matthew 3200: @_,
3201: );
1.586 raeburn 3202: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3203: $autharg,$jscall,$disabled);
1.1106 raeburn 3204: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3205: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3206: $check5 = ' checked="checked"';
1.80 albertel 3207: } else {
1.772 bisitz 3208: $check4 = ' checked="checked"';
1.80 albertel 3209: }
1.1259 raeburn 3210: if ($in{'readonly'}) {
3211: $disabled = ' disabled="disabled"';
3212: }
1.165 raeburn 3213: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3214: if (defined($in{'curr_authtype'})) {
3215: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3216: $krbcheck = ' checked="checked"';
1.623 raeburn 3217: if (defined($in{'mode'})) {
3218: if ($in{'mode'} eq 'modifyuser') {
3219: $krbcheck = '';
3220: }
3221: }
1.591 raeburn 3222: if (defined($in{'curr_kerb_ver'})) {
3223: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3224: $check5 = ' checked="checked"';
1.591 raeburn 3225: $check4 = '';
3226: } else {
1.772 bisitz 3227: $check4 = ' checked="checked"';
1.591 raeburn 3228: $check5 = '';
3229: }
1.586 raeburn 3230: }
1.591 raeburn 3231: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3232: $krbarg = $in{'curr_autharg'};
3233: }
1.586 raeburn 3234: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3235: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3236: $result =
3237: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3238: $in{'curr_autharg'},$krbver);
3239: } else {
3240: $result =
3241: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3242: }
3243: return $result;
3244: }
3245: }
3246: } else {
3247: if ($authnum == 1) {
1.784 bisitz 3248: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3249: }
3250: }
1.586 raeburn 3251: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3252: return;
1.587 raeburn 3253: } elsif ($authtype eq '') {
1.591 raeburn 3254: if (defined($in{'mode'})) {
1.587 raeburn 3255: if ($in{'mode'} eq 'modifycourse') {
3256: if ($authnum == 1) {
1.1259 raeburn 3257: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3258: }
3259: }
3260: }
1.586 raeburn 3261: }
3262: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3263: if ($authtype eq '') {
3264: $authtype = '<input type="radio" name="login" value="krb" '.
3265: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3266: $krbcheck.$disabled.' />';
1.586 raeburn 3267: }
3268: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3269: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3270: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3271: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3272: $in{'curr_authtype'} eq 'krb4')) {
3273: $result .= &mt
1.144 matthew 3274: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3275: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3276: '<label>'.$authtype,
1.281 albertel 3277: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3278: 'value="'.$krbarg.'" '.
1.1259 raeburn 3279: 'onchange="'.$jscall.'"'.$disabled.' />',
3280: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3281: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3282: '</label>');
1.586 raeburn 3283: } elsif ($can_assign{'krb4'}) {
3284: $result .= &mt
3285: ('[_1] Kerberos authenticated with domain [_2] '.
3286: '[_3] Version 4 [_4]',
3287: '<label>'.$authtype,
3288: '</label><input type="text" size="10" name="krbarg" '.
3289: 'value="'.$krbarg.'" '.
1.1259 raeburn 3290: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3291: '<label><input type="hidden" name="krbver" value="4" />',
3292: '</label>');
3293: } elsif ($can_assign{'krb5'}) {
3294: $result .= &mt
3295: ('[_1] Kerberos authenticated with domain [_2] '.
3296: '[_3] Version 5 [_4]',
3297: '<label>'.$authtype,
3298: '</label><input type="text" size="10" name="krbarg" '.
3299: 'value="'.$krbarg.'" '.
1.1259 raeburn 3300: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3301: '<label><input type="hidden" name="krbver" value="5" />',
3302: '</label>');
3303: }
1.32 matthew 3304: return $result;
3305: }
3306:
1.1106 raeburn 3307: sub authform_internal {
1.586 raeburn 3308: my %in = (
1.32 matthew 3309: formname => 'document.cu',
3310: kerb_def_dom => 'MSU.EDU',
3311: @_,
3312: );
1.1259 raeburn 3313: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3314: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3315: if ($in{'readonly'}) {
3316: $disabled = ' disabled="disabled"';
3317: }
1.591 raeburn 3318: if (defined($in{'curr_authtype'})) {
3319: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3320: if ($can_assign{'int'}) {
1.772 bisitz 3321: $intcheck = 'checked="checked" ';
1.623 raeburn 3322: if (defined($in{'mode'})) {
3323: if ($in{'mode'} eq 'modifyuser') {
3324: $intcheck = '';
3325: }
3326: }
1.591 raeburn 3327: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3328: $intarg = $in{'curr_autharg'};
3329: }
3330: } else {
3331: $result = &mt('Currently internally authenticated.');
3332: return $result;
1.165 raeburn 3333: }
3334: }
1.586 raeburn 3335: } else {
3336: if ($authnum == 1) {
1.784 bisitz 3337: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3338: }
3339: }
3340: if (!$can_assign{'int'}) {
3341: return;
1.587 raeburn 3342: } elsif ($authtype eq '') {
1.591 raeburn 3343: if (defined($in{'mode'})) {
1.587 raeburn 3344: if ($in{'mode'} eq 'modifycourse') {
3345: if ($authnum == 1) {
1.1259 raeburn 3346: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3347: }
3348: }
3349: }
1.165 raeburn 3350: }
1.586 raeburn 3351: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3352: if ($authtype eq '') {
3353: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3354: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3355: }
1.605 bisitz 3356: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3357: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3358: $result = &mt
1.144 matthew 3359: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3360: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3361: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3362: return $result;
3363: }
3364:
1.1104 raeburn 3365: sub authform_local {
1.32 matthew 3366: my %in = (
3367: formname => 'document.cu',
3368: kerb_def_dom => 'MSU.EDU',
3369: @_,
3370: );
1.1259 raeburn 3371: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3372: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3373: if ($in{'readonly'}) {
3374: $disabled = ' disabled="disabled"';
3375: }
1.591 raeburn 3376: if (defined($in{'curr_authtype'})) {
3377: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3378: if ($can_assign{'loc'}) {
1.772 bisitz 3379: $loccheck = 'checked="checked" ';
1.623 raeburn 3380: if (defined($in{'mode'})) {
3381: if ($in{'mode'} eq 'modifyuser') {
3382: $loccheck = '';
3383: }
3384: }
1.591 raeburn 3385: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3386: $locarg = $in{'curr_autharg'};
3387: }
3388: } else {
3389: $result = &mt('Currently using local (institutional) authentication.');
3390: return $result;
1.165 raeburn 3391: }
3392: }
1.586 raeburn 3393: } else {
3394: if ($authnum == 1) {
1.784 bisitz 3395: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3396: }
3397: }
3398: if (!$can_assign{'loc'}) {
3399: return;
1.587 raeburn 3400: } elsif ($authtype eq '') {
1.591 raeburn 3401: if (defined($in{'mode'})) {
1.587 raeburn 3402: if ($in{'mode'} eq 'modifycourse') {
3403: if ($authnum == 1) {
1.1259 raeburn 3404: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3405: }
3406: }
3407: }
1.165 raeburn 3408: }
1.586 raeburn 3409: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3410: if ($authtype eq '') {
3411: $authtype = '<input type="radio" name="login" value="loc" '.
3412: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3413: $jscall.'"'.$disabled.' />';
1.586 raeburn 3414: }
3415: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3416: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3417: $result = &mt('[_1] Local Authentication with argument [_2]',
3418: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3419: return $result;
3420: }
3421:
1.1106 raeburn 3422: sub authform_filesystem {
1.32 matthew 3423: my %in = (
3424: formname => 'document.cu',
3425: kerb_def_dom => 'MSU.EDU',
3426: @_,
3427: );
1.1259 raeburn 3428: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3429: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3430: if ($in{'readonly'}) {
3431: $disabled = ' disabled="disabled"';
3432: }
1.591 raeburn 3433: if (defined($in{'curr_authtype'})) {
3434: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3435: if ($can_assign{'fsys'}) {
1.772 bisitz 3436: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3437: if (defined($in{'mode'})) {
3438: if ($in{'mode'} eq 'modifyuser') {
3439: $fsyscheck = '';
3440: }
3441: }
1.586 raeburn 3442: } else {
3443: $result = &mt('Currently Filesystem Authenticated.');
3444: return $result;
1.1259 raeburn 3445: }
1.586 raeburn 3446: }
3447: } else {
3448: if ($authnum == 1) {
1.784 bisitz 3449: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3450: }
3451: }
3452: if (!$can_assign{'fsys'}) {
3453: return;
1.587 raeburn 3454: } elsif ($authtype eq '') {
1.591 raeburn 3455: if (defined($in{'mode'})) {
1.587 raeburn 3456: if ($in{'mode'} eq 'modifycourse') {
3457: if ($authnum == 1) {
1.1259 raeburn 3458: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3459: }
3460: }
3461: }
1.586 raeburn 3462: }
3463: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3464: if ($authtype eq '') {
3465: $authtype = '<input type="radio" name="login" value="fsys" '.
3466: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3467: $jscall.'"'.$disabled.' />';
1.586 raeburn 3468: }
1.1310 raeburn 3469: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3470: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3471: $result = &mt
1.144 matthew 3472: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3473: '<label>'.$authtype,'</label>'.$autharg);
3474: return $result;
3475: }
3476:
3477: sub authform_lti {
3478: my %in = (
3479: formname => 'document.cu',
3480: kerb_def_dom => 'MSU.EDU',
3481: @_,
3482: );
3483: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3484: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3485: if ($in{'readonly'}) {
3486: $disabled = ' disabled="disabled"';
3487: }
3488: if (defined($in{'curr_authtype'})) {
3489: if ($in{'curr_authtype'} eq 'lti') {
3490: if ($can_assign{'lti'}) {
3491: $lticheck = 'checked="checked" ';
3492: if (defined($in{'mode'})) {
3493: if ($in{'mode'} eq 'modifyuser') {
3494: $lticheck = '';
3495: }
3496: }
3497: } else {
3498: $result = &mt('Currently LTI Authenticated.');
3499: return $result;
3500: }
3501: }
3502: } else {
3503: if ($authnum == 1) {
3504: $authtype = '<input type="hidden" name="login" value="lti" />';
3505: }
3506: }
3507: if (!$can_assign{'lti'}) {
3508: return;
3509: } elsif ($authtype eq '') {
3510: if (defined($in{'mode'})) {
3511: if ($in{'mode'} eq 'modifycourse') {
3512: if ($authnum == 1) {
3513: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3514: }
3515: }
3516: }
3517: }
3518: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3519: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3520: $authtype = '<input type="radio" name="login" value="lti" '.
3521: $lticheck.' onchange="'.$jscall.'" onclick="'.
3522: $jscall.'"'.$disabled.' />';
3523: }
3524: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3525: if ($authtype) {
3526: $result = &mt('[_1] LTI Authenticated',
3527: '<label>'.$authtype.'</label>'.$autharg);
3528: } else {
3529: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3530: $autharg;
3531: }
1.32 matthew 3532: return $result;
3533: }
3534:
1.586 raeburn 3535: sub get_assignable_auth {
3536: my ($dom) = @_;
3537: if ($dom eq '') {
3538: $dom = $env{'request.role.domain'};
3539: }
3540: my %can_assign = (
3541: krb4 => 1,
3542: krb5 => 1,
3543: int => 1,
3544: loc => 1,
1.1310 raeburn 3545: lti => 1,
1.586 raeburn 3546: );
3547: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3548: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3549: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3550: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3551: my $context;
3552: if ($env{'request.role'} =~ /^au/) {
3553: $context = 'author';
1.1259 raeburn 3554: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3555: $context = 'domain';
3556: } elsif ($env{'request.course.id'}) {
3557: $context = 'course';
3558: }
3559: if ($context) {
3560: if (ref($authhash->{$context}) eq 'HASH') {
3561: %can_assign = %{$authhash->{$context}};
3562: }
3563: }
3564: }
3565: }
3566: my $authnum = 0;
3567: foreach my $key (keys(%can_assign)) {
3568: if ($can_assign{$key}) {
3569: $authnum ++;
3570: }
3571: }
3572: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3573: $authnum --;
3574: }
3575: return ($authnum,%can_assign);
3576: }
3577:
1.1331 raeburn 3578: sub check_passwd_rules {
3579: my ($domain,$plainpass) = @_;
3580: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3581: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3582: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3583: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3584: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3585: if ($passwdconf{'min'} > $min) {
3586: $min = $passwdconf{'min'};
3587: }
1.1331 raeburn 3588: }
3589: if ($passwdconf{'max'} =~ /^\d+$/) {
3590: $max = $passwdconf{'max'};
3591: }
3592: @chars = @{$passwdconf{'chars'}};
3593: }
3594: if (($min) && (length($plainpass) < $min)) {
3595: push(@brokerule,'min');
3596: }
3597: if (($max) && (length($plainpass) > $max)) {
3598: push(@brokerule,'max');
3599: }
3600: if (@chars) {
3601: my %rules;
3602: map { $rules{$_} = 1; } @chars;
3603: if ($rules{'uc'}) {
3604: unless ($plainpass =~ /[A-Z]/) {
3605: push(@brokerule,'uc');
3606: }
3607: }
3608: if ($rules{'lc'}) {
1.1332 raeburn 3609: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3610: push(@brokerule,'lc');
3611: }
3612: }
3613: if ($rules{'num'}) {
3614: unless ($plainpass =~ /\d/) {
3615: push(@brokerule,'num');
3616: }
3617: }
3618: if ($rules{'spec'}) {
3619: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3620: push(@brokerule,'spec');
3621: }
3622: }
3623: }
3624: if (@brokerule) {
3625: my %rulenames = &Apache::lonlocal::texthash(
3626: uc => 'At least one upper case letter',
3627: lc => 'At least one lower case letter',
3628: num => 'At least one number',
3629: spec => 'At least one non-alphanumeric',
3630: );
3631: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3632: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3633: $rulenames{'num'} .= ': 0123456789';
3634: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3635: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3636: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3637: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3638: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3639: if (grep(/^$rule$/,@brokerule)) {
3640: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3641: }
3642: }
3643: $warning .= '</ul>';
3644: }
1.1332 raeburn 3645: if (wantarray) {
3646: return @brokerule;
3647: }
1.1331 raeburn 3648: return $warning;
3649: }
3650:
1.80 albertel 3651: ###############################################################
3652: ## Get Kerberos Defaults for Domain ##
3653: ###############################################################
3654: ##
3655: ## Returns default kerberos version and an associated argument
3656: ## as listed in file domain.tab. If not listed, provides
3657: ## appropriate default domain and kerberos version.
3658: ##
3659: #-------------------------------------------
3660:
3661: =pod
3662:
1.648 raeburn 3663: =item * &get_kerberos_defaults()
1.80 albertel 3664:
3665: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3666: version and domain. If not found, it defaults to version 4 and the
3667: domain of the server.
1.80 albertel 3668:
1.648 raeburn 3669: =over 4
3670:
1.80 albertel 3671: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3672:
1.648 raeburn 3673: =back
3674:
3675: =back
3676:
1.80 albertel 3677: =cut
3678:
3679: #-------------------------------------------
3680: sub get_kerberos_defaults {
3681: my $domain=shift;
1.641 raeburn 3682: my ($krbdef,$krbdefdom);
3683: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3684: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3685: $krbdef = $domdefaults{'auth_def'};
3686: $krbdefdom = $domdefaults{'auth_arg_def'};
3687: } else {
1.80 albertel 3688: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3689: my $krbdefdom=$1;
3690: $krbdefdom=~tr/a-z/A-Z/;
3691: $krbdef = "krb4";
3692: }
3693: return ($krbdef,$krbdefdom);
3694: }
1.112 bowersj2 3695:
1.32 matthew 3696:
1.46 matthew 3697: ###############################################################
3698: ## Thesaurus Functions ##
3699: ###############################################################
1.20 www 3700:
1.46 matthew 3701: =pod
1.20 www 3702:
1.112 bowersj2 3703: =head1 Thesaurus Functions
3704:
3705: =over 4
3706:
1.648 raeburn 3707: =item * &initialize_keywords()
1.46 matthew 3708:
3709: Initializes the package variable %Keywords if it is empty. Uses the
3710: package variable $thesaurus_db_file.
3711:
3712: =cut
3713:
3714: ###################################################
3715:
3716: sub initialize_keywords {
3717: return 1 if (scalar keys(%Keywords));
3718: # If we are here, %Keywords is empty, so fill it up
3719: # Make sure the file we need exists...
3720: if (! -e $thesaurus_db_file) {
3721: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3722: " failed because it does not exist");
3723: return 0;
3724: }
3725: # Set up the hash as a database
3726: my %thesaurus_db;
3727: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3728: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3729: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3730: $thesaurus_db_file);
3731: return 0;
3732: }
3733: # Get the average number of appearances of a word.
3734: my $avecount = $thesaurus_db{'average.count'};
3735: # Put keywords (those that appear > average) into %Keywords
3736: while (my ($word,$data)=each (%thesaurus_db)) {
3737: my ($count,undef) = split /:/,$data;
3738: $Keywords{$word}++ if ($count > $avecount);
3739: }
3740: untie %thesaurus_db;
3741: # Remove special values from %Keywords.
1.356 albertel 3742: foreach my $value ('total.count','average.count') {
3743: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3744: }
1.46 matthew 3745: return 1;
3746: }
3747:
3748: ###################################################
3749:
3750: =pod
3751:
1.648 raeburn 3752: =item * &keyword($word)
1.46 matthew 3753:
3754: Returns true if $word is a keyword. A keyword is a word that appears more
3755: than the average number of times in the thesaurus database. Calls
3756: &initialize_keywords
3757:
3758: =cut
3759:
3760: ###################################################
1.20 www 3761:
3762: sub keyword {
1.46 matthew 3763: return if (!&initialize_keywords());
3764: my $word=lc(shift());
3765: $word=~s/\W//g;
3766: return exists($Keywords{$word});
1.20 www 3767: }
1.46 matthew 3768:
3769: ###############################################################
3770:
3771: =pod
1.20 www 3772:
1.648 raeburn 3773: =item * &get_related_words()
1.46 matthew 3774:
1.160 matthew 3775: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3776: an array of words. If the keyword is not in the thesaurus, an empty array
3777: will be returned. The order of the words returned is determined by the
3778: database which holds them.
3779:
3780: Uses global $thesaurus_db_file.
3781:
1.1057 foxr 3782:
1.46 matthew 3783: =cut
3784:
3785: ###############################################################
3786: sub get_related_words {
3787: my $keyword = shift;
3788: my %thesaurus_db;
3789: if (! -e $thesaurus_db_file) {
3790: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3791: "failed because the file does not exist");
3792: return ();
3793: }
3794: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3795: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3796: return ();
3797: }
3798: my @Words=();
1.429 www 3799: my $count=0;
1.46 matthew 3800: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3801: # The first element is the number of times
3802: # the word appears. We do not need it now.
1.429 www 3803: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3804: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3805: my $threshold=$mostfrequentcount/10;
3806: foreach my $possibleword (@RelatedWords) {
3807: my ($word,$wordcount)=split(/\,/,$possibleword);
3808: if ($wordcount>$threshold) {
3809: push(@Words,$word);
3810: $count++;
3811: if ($count>10) { last; }
3812: }
1.20 www 3813: }
3814: }
1.46 matthew 3815: untie %thesaurus_db;
3816: return @Words;
1.14 harris41 3817: }
1.1090 foxr 3818: ###############################################################
3819: #
3820: # Spell checking
3821: #
3822:
3823: =pod
3824:
1.1142 raeburn 3825: =back
3826:
1.1090 foxr 3827: =head1 Spell checking
3828:
3829: =over 4
3830:
3831: =item * &check_spelling($wordlist $language)
3832:
3833: Takes a string containing words and feeds it to an external
3834: spellcheck program via a pipeline. Returns a string containing
3835: them mis-spelled words.
3836:
3837: Parameters:
3838:
3839: =over 4
3840:
3841: =item - $wordlist
3842:
3843: String that will be fed into the spellcheck program.
3844:
3845: =item - $language
3846:
3847: Language string that specifies the language for which the spell
3848: check will be performed.
3849:
3850: =back
3851:
3852: =back
3853:
3854: Note: This sub assumes that aspell is installed.
3855:
3856:
3857: =cut
3858:
1.46 matthew 3859:
1.1090 foxr 3860: sub check_spelling {
3861: my ($wordlist, $language) = @_;
1.1091 foxr 3862: my @misspellings;
3863:
3864: # Generate the speller and set the langauge.
3865: # if explicitly selected:
1.1090 foxr 3866:
1.1091 foxr 3867: my $speller = Text::Aspell->new;
1.1090 foxr 3868: if ($language) {
1.1091 foxr 3869: $speller->set_option('lang', $language);
1.1090 foxr 3870: }
3871:
1.1091 foxr 3872: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3873:
1.1091 foxr 3874: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3875:
1.1091 foxr 3876: foreach my $word (@words) {
3877: if(! $speller->check($word)) {
3878: push(@misspellings, $word);
1.1090 foxr 3879: }
3880: }
1.1091 foxr 3881: return join(' ', @misspellings);
3882:
1.1090 foxr 3883: }
3884:
1.61 www 3885: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3886: =pod
3887:
1.112 bowersj2 3888: =head1 User Name Functions
3889:
3890: =over 4
3891:
1.648 raeburn 3892: =item * &plainname($uname,$udom,$first)
1.81 albertel 3893:
1.112 bowersj2 3894: Takes a users logon name and returns it as a string in
1.226 albertel 3895: "first middle last generation" form
3896: if $first is set to 'lastname' then it returns it as
3897: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3898:
3899: =cut
1.61 www 3900:
1.295 www 3901:
1.81 albertel 3902: ###############################################################
1.61 www 3903: sub plainname {
1.226 albertel 3904: my ($uname,$udom,$first)=@_;
1.537 albertel 3905: return if (!defined($uname) || !defined($udom));
1.295 www 3906: my %names=&getnames($uname,$udom);
1.226 albertel 3907: my $name=&Apache::lonnet::format_name($names{'firstname'},
3908: $names{'middlename'},
3909: $names{'lastname'},
3910: $names{'generation'},$first);
3911: $name=~s/^\s+//;
1.62 www 3912: $name=~s/\s+$//;
3913: $name=~s/\s+/ /g;
1.353 albertel 3914: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3915: return $name;
1.61 www 3916: }
1.66 www 3917:
3918: # -------------------------------------------------------------------- Nickname
1.81 albertel 3919: =pod
3920:
1.648 raeburn 3921: =item * &nickname($uname,$udom)
1.81 albertel 3922:
3923: Gets a users name and returns it as a string as
3924:
3925: ""nickname""
1.66 www 3926:
1.81 albertel 3927: if the user has a nickname or
3928:
3929: "first middle last generation"
3930:
3931: if the user does not
3932:
3933: =cut
1.66 www 3934:
3935: sub nickname {
3936: my ($uname,$udom)=@_;
1.537 albertel 3937: return if (!defined($uname) || !defined($udom));
1.295 www 3938: my %names=&getnames($uname,$udom);
1.68 albertel 3939: my $name=$names{'nickname'};
1.66 www 3940: if ($name) {
3941: $name='"'.$name.'"';
3942: } else {
3943: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3944: $names{'lastname'}.' '.$names{'generation'};
3945: $name=~s/\s+$//;
3946: $name=~s/\s+/ /g;
3947: }
3948: return $name;
3949: }
3950:
1.295 www 3951: sub getnames {
3952: my ($uname,$udom)=@_;
1.537 albertel 3953: return if (!defined($uname) || !defined($udom));
1.433 albertel 3954: if ($udom eq 'public' && $uname eq 'public') {
3955: return ('lastname' => &mt('Public'));
3956: }
1.295 www 3957: my $id=$uname.':'.$udom;
3958: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3959: if ($cached) {
3960: return %{$names};
3961: } else {
3962: my %loadnames=&Apache::lonnet::get('environment',
3963: ['firstname','middlename','lastname','generation','nickname'],
3964: $udom,$uname);
3965: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3966: return %loadnames;
3967: }
3968: }
1.61 www 3969:
1.542 raeburn 3970: # -------------------------------------------------------------------- getemails
1.648 raeburn 3971:
1.542 raeburn 3972: =pod
3973:
1.648 raeburn 3974: =item * &getemails($uname,$udom)
1.542 raeburn 3975:
3976: Gets a user's email information and returns it as a hash with keys:
3977: notification, critnotification, permanentemail
3978:
3979: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3980: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3981:
1.648 raeburn 3982:
1.542 raeburn 3983: =cut
3984:
1.648 raeburn 3985:
1.466 albertel 3986: sub getemails {
3987: my ($uname,$udom)=@_;
3988: if ($udom eq 'public' && $uname eq 'public') {
3989: return;
3990: }
1.467 www 3991: if (!$udom) { $udom=$env{'user.domain'}; }
3992: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3993: my $id=$uname.':'.$udom;
3994: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3995: if ($cached) {
3996: return %{$names};
3997: } else {
3998: my %loadnames=&Apache::lonnet::get('environment',
3999: ['notification','critnotification',
4000: 'permanentemail'],
4001: $udom,$uname);
4002: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4003: return %loadnames;
4004: }
4005: }
4006:
1.551 albertel 4007: sub flush_email_cache {
4008: my ($uname,$udom)=@_;
4009: if (!$udom) { $udom =$env{'user.domain'}; }
4010: if (!$uname) { $uname=$env{'user.name'}; }
4011: return if ($udom eq 'public' && $uname eq 'public');
4012: my $id=$uname.':'.$udom;
4013: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4014: }
4015:
1.728 raeburn 4016: # -------------------------------------------------------------------- getlangs
4017:
4018: =pod
4019:
4020: =item * &getlangs($uname,$udom)
4021:
4022: Gets a user's language preference and returns it as a hash with key:
4023: language.
4024:
4025: =cut
4026:
4027:
4028: sub getlangs {
4029: my ($uname,$udom) = @_;
4030: if (!$udom) { $udom =$env{'user.domain'}; }
4031: if (!$uname) { $uname=$env{'user.name'}; }
4032: my $id=$uname.':'.$udom;
4033: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4034: if ($cached) {
4035: return %{$langs};
4036: } else {
4037: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4038: $udom,$uname);
4039: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4040: return %loadlangs;
4041: }
4042: }
4043:
4044: sub flush_langs_cache {
4045: my ($uname,$udom)=@_;
4046: if (!$udom) { $udom =$env{'user.domain'}; }
4047: if (!$uname) { $uname=$env{'user.name'}; }
4048: return if ($udom eq 'public' && $uname eq 'public');
4049: my $id=$uname.':'.$udom;
4050: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4051: }
4052:
1.61 www 4053: # ------------------------------------------------------------------ Screenname
1.81 albertel 4054:
4055: =pod
4056:
1.648 raeburn 4057: =item * &screenname($uname,$udom)
1.81 albertel 4058:
4059: Gets a users screenname and returns it as a string
4060:
4061: =cut
1.61 www 4062:
4063: sub screenname {
4064: my ($uname,$udom)=@_;
1.258 albertel 4065: if ($uname eq $env{'user.name'} &&
4066: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4067: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4068: return $names{'screenname'};
1.62 www 4069: }
4070:
1.212 albertel 4071:
1.802 bisitz 4072: # ------------------------------------------------------------- Confirm Wrapper
4073: =pod
4074:
1.1142 raeburn 4075: =item * &confirmwrapper($message)
1.802 bisitz 4076:
4077: Wrap messages about completion of operation in box
4078:
4079: =cut
4080:
4081: sub confirmwrapper {
4082: my ($message)=@_;
4083: if ($message) {
4084: return "\n".'<div class="LC_confirm_box">'."\n"
4085: .$message."\n"
4086: .'</div>'."\n";
4087: } else {
4088: return $message;
4089: }
4090: }
4091:
1.62 www 4092: # ------------------------------------------------------------- Message Wrapper
4093:
4094: sub messagewrapper {
1.369 www 4095: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4096: return
1.441 albertel 4097: '<a href="/adm/email?compose=individual&'.
4098: 'recname='.$username.'&recdom='.$domain.
4099: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4100: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4101: }
1.802 bisitz 4102:
1.74 www 4103: # --------------------------------------------------------------- Notes Wrapper
4104:
4105: sub noteswrapper {
4106: my ($link,$un,$do)=@_;
4107: return
1.896 amueller 4108: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4109: }
1.802 bisitz 4110:
1.62 www 4111: # ------------------------------------------------------------- Aboutme Wrapper
4112:
4113: sub aboutmewrapper {
1.1070 raeburn 4114: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4115: if (!defined($username) && !defined($domain)) {
4116: return;
4117: }
1.1096 raeburn 4118: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4119: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4120: }
4121:
4122: # ------------------------------------------------------------ Syllabus Wrapper
4123:
4124: sub syllabuswrapper {
1.707 bisitz 4125: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4126: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4127: }
1.14 harris41 4128:
1.802 bisitz 4129: # -----------------------------------------------------------------------------
4130:
1.208 matthew 4131: sub track_student_link {
1.887 raeburn 4132: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4133: my $link ="/adm/trackstudent?";
1.208 matthew 4134: my $title = 'View recent activity';
4135: if (defined($sname) && $sname !~ /^\s*$/ &&
4136: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4137: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4138: $title .= ' of this student';
1.268 albertel 4139: }
1.208 matthew 4140: if (defined($target) && $target !~ /^\s*$/) {
4141: $target = qq{target="$target"};
4142: } else {
4143: $target = '';
4144: }
1.268 albertel 4145: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4146: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4147: $title = &mt($title);
4148: $linktext = &mt($linktext);
1.448 albertel 4149: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4150: &help_open_topic('View_recent_activity');
1.208 matthew 4151: }
4152:
1.781 raeburn 4153: sub slot_reservations_link {
4154: my ($linktext,$sname,$sdom,$target) = @_;
4155: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4156: my $title = 'View slot reservation history';
4157: if (defined($sname) && $sname !~ /^\s*$/ &&
4158: defined($sdom) && $sdom !~ /^\s*$/) {
4159: $link .= "&uname=$sname&udom=$sdom";
4160: $title .= ' of this student';
4161: }
4162: if (defined($target) && $target !~ /^\s*$/) {
4163: $target = qq{target="$target"};
4164: } else {
4165: $target = '';
4166: }
4167: $title = &mt($title);
4168: $linktext = &mt($linktext);
4169: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4170: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4171:
4172: }
4173:
1.508 www 4174: # ===================================================== Display a student photo
4175:
4176:
1.509 albertel 4177: sub student_image_tag {
1.508 www 4178: my ($domain,$user)=@_;
4179: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4180: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4181: return '<img src="'.$imgsrc.'" align="right" />';
4182: } else {
4183: return '';
4184: }
4185: }
4186:
1.112 bowersj2 4187: =pod
4188:
4189: =back
4190:
4191: =head1 Access .tab File Data
4192:
4193: =over 4
4194:
1.648 raeburn 4195: =item * &languageids()
1.112 bowersj2 4196:
4197: returns list of all language ids
4198:
4199: =cut
4200:
1.14 harris41 4201: sub languageids {
1.16 harris41 4202: return sort(keys(%language));
1.14 harris41 4203: }
4204:
1.112 bowersj2 4205: =pod
4206:
1.648 raeburn 4207: =item * &languagedescription()
1.112 bowersj2 4208:
4209: returns description of a specified language id
4210:
4211: =cut
4212:
1.14 harris41 4213: sub languagedescription {
1.125 www 4214: my $code=shift;
4215: return ($supported_language{$code}?'* ':'').
4216: $language{$code}.
1.126 www 4217: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4218: }
4219:
1.1048 foxr 4220: =pod
4221:
4222: =item * &plainlanguagedescription
4223:
4224: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4225: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4226:
4227: =cut
4228:
1.145 www 4229: sub plainlanguagedescription {
4230: my $code=shift;
4231: return $language{$code};
4232: }
4233:
1.1048 foxr 4234: =pod
4235:
4236: =item * &supportedlanguagecode
4237:
4238: Returns the supported language code (e.g. sptutf maps to pt) given a language
4239: code.
4240:
4241: =cut
4242:
1.145 www 4243: sub supportedlanguagecode {
4244: my $code=shift;
4245: return $supported_language{$code};
1.97 www 4246: }
4247:
1.112 bowersj2 4248: =pod
4249:
1.1048 foxr 4250: =item * &latexlanguage()
4251:
4252: Given a language key code returns the correspondnig language to use
4253: to select the correct hyphenation on LaTeX printouts. This is undef if there
4254: is no supported hyphenation for the language code.
4255:
4256: =cut
4257:
4258: sub latexlanguage {
4259: my $code = shift;
4260: return $latex_language{$code};
4261: }
4262:
4263: =pod
4264:
4265: =item * &latexhyphenation()
4266:
4267: Same as above but what's supplied is the language as it might be stored
4268: in the metadata.
4269:
4270: =cut
4271:
4272: sub latexhyphenation {
4273: my $key = shift;
4274: return $latex_language_bykey{$key};
4275: }
4276:
4277: =pod
4278:
1.648 raeburn 4279: =item * ©rightids()
1.112 bowersj2 4280:
4281: returns list of all copyrights
4282:
4283: =cut
4284:
4285: sub copyrightids {
4286: return sort(keys(%cprtag));
4287: }
4288:
4289: =pod
4290:
1.648 raeburn 4291: =item * ©rightdescription()
1.112 bowersj2 4292:
4293: returns description of a specified copyright id
4294:
4295: =cut
4296:
4297: sub copyrightdescription {
1.166 www 4298: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4299: }
1.197 matthew 4300:
4301: =pod
4302:
1.648 raeburn 4303: =item * &source_copyrightids()
1.192 taceyjo1 4304:
4305: returns list of all source copyrights
4306:
4307: =cut
4308:
4309: sub source_copyrightids {
4310: return sort(keys(%scprtag));
4311: }
4312:
4313: =pod
4314:
1.648 raeburn 4315: =item * &source_copyrightdescription()
1.192 taceyjo1 4316:
4317: returns description of a specified source copyright id
4318:
4319: =cut
4320:
4321: sub source_copyrightdescription {
4322: return &mt($scprtag{shift(@_)});
4323: }
1.112 bowersj2 4324:
4325: =pod
4326:
1.648 raeburn 4327: =item * &filecategories()
1.112 bowersj2 4328:
4329: returns list of all file categories
4330:
4331: =cut
4332:
4333: sub filecategories {
4334: return sort(keys(%category_extensions));
4335: }
4336:
4337: =pod
4338:
1.648 raeburn 4339: =item * &filecategorytypes()
1.112 bowersj2 4340:
4341: returns list of file types belonging to a given file
4342: category
4343:
4344: =cut
4345:
4346: sub filecategorytypes {
1.356 albertel 4347: my ($cat) = @_;
1.1248 raeburn 4348: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4349: return @{$category_extensions{lc($cat)}};
4350: } else {
4351: return ();
4352: }
1.112 bowersj2 4353: }
4354:
4355: =pod
4356:
1.648 raeburn 4357: =item * &fileembstyle()
1.112 bowersj2 4358:
4359: returns embedding style for a specified file type
4360:
4361: =cut
4362:
4363: sub fileembstyle {
4364: return $fe{lc(shift(@_))};
1.169 www 4365: }
4366:
1.351 www 4367: sub filemimetype {
4368: return $fm{lc(shift(@_))};
4369: }
4370:
1.169 www 4371:
4372: sub filecategoryselect {
4373: my ($name,$value)=@_;
1.189 matthew 4374: return &select_form($value,$name,
1.970 raeburn 4375: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4376: }
4377:
4378: =pod
4379:
1.648 raeburn 4380: =item * &filedescription()
1.112 bowersj2 4381:
4382: returns description for a specified file type
4383:
4384: =cut
4385:
4386: sub filedescription {
1.188 matthew 4387: my $file_description = $fd{lc(shift())};
4388: $file_description =~ s:([\[\]]):~$1:g;
4389: return &mt($file_description);
1.112 bowersj2 4390: }
4391:
4392: =pod
4393:
1.648 raeburn 4394: =item * &filedescriptionex()
1.112 bowersj2 4395:
4396: returns description for a specified file type with
4397: extra formatting
4398:
4399: =cut
4400:
4401: sub filedescriptionex {
4402: my $ex=shift;
1.188 matthew 4403: my $file_description = $fd{lc($ex)};
4404: $file_description =~ s:([\[\]]):~$1:g;
4405: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4406: }
4407:
4408: # End of .tab access
4409: =pod
4410:
4411: =back
4412:
4413: =cut
4414:
4415: # ------------------------------------------------------------------ File Types
4416: sub fileextensions {
4417: return sort(keys(%fe));
4418: }
4419:
1.97 www 4420: # ----------------------------------------------------------- Display Languages
4421: # returns a hash with all desired display languages
4422: #
4423:
4424: sub display_languages {
4425: my %languages=();
1.695 raeburn 4426: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4427: $languages{$lang}=1;
1.97 www 4428: }
4429: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4430: if ($env{'form.displaylanguage'}) {
1.356 albertel 4431: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4432: $languages{$lang}=1;
1.97 www 4433: }
4434: }
4435: return %languages;
1.14 harris41 4436: }
4437:
1.582 albertel 4438: sub languages {
4439: my ($possible_langs) = @_;
1.695 raeburn 4440: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4441: if (!ref($possible_langs)) {
4442: if( wantarray ) {
4443: return @preferred_langs;
4444: } else {
4445: return $preferred_langs[0];
4446: }
4447: }
4448: my %possibilities = map { $_ => 1 } (@$possible_langs);
4449: my @preferred_possibilities;
4450: foreach my $preferred_lang (@preferred_langs) {
4451: if (exists($possibilities{$preferred_lang})) {
4452: push(@preferred_possibilities, $preferred_lang);
4453: }
4454: }
4455: if( wantarray ) {
4456: return @preferred_possibilities;
4457: }
4458: return $preferred_possibilities[0];
4459: }
4460:
1.742 raeburn 4461: sub user_lang {
4462: my ($touname,$toudom,$fromcid) = @_;
4463: my @userlangs;
4464: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4465: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4466: $env{'course.'.$fromcid.'.languages'}));
4467: } else {
4468: my %langhash = &getlangs($touname,$toudom);
4469: if ($langhash{'languages'} ne '') {
4470: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4471: } else {
4472: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4473: if ($domdefs{'lang_def'} ne '') {
4474: @userlangs = ($domdefs{'lang_def'});
4475: }
4476: }
4477: }
4478: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4479: my $user_lh = Apache::localize->get_handle(@languages);
4480: return $user_lh;
4481: }
4482:
4483:
1.112 bowersj2 4484: ###############################################################
4485: ## Student Answer Attempts ##
4486: ###############################################################
4487:
4488: =pod
4489:
4490: =head1 Alternate Problem Views
4491:
4492: =over 4
4493:
1.648 raeburn 4494: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4495: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4496:
4497: Return string with previous attempt on problem. Arguments:
4498:
4499: =over 4
4500:
4501: =item * $symb: Problem, including path
4502:
4503: =item * $username: username of the desired student
4504:
4505: =item * $domain: domain of the desired student
1.14 harris41 4506:
1.112 bowersj2 4507: =item * $course: Course ID
1.14 harris41 4508:
1.112 bowersj2 4509: =item * $getattempt: Leave blank for all attempts, otherwise put
4510: something
1.14 harris41 4511:
1.112 bowersj2 4512: =item * $regexp: if string matches this regexp, the string will be
4513: sent to $gradesub
1.14 harris41 4514:
1.112 bowersj2 4515: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4516:
1.1199 raeburn 4517: =item * $usec: section of the desired student
4518:
4519: =item * $identifier: counter for student (multiple students one problem) or
4520: problem (one student; whole sequence).
4521:
1.112 bowersj2 4522: =back
1.14 harris41 4523:
1.112 bowersj2 4524: The output string is a table containing all desired attempts, if any.
1.16 harris41 4525:
1.112 bowersj2 4526: =cut
1.1 albertel 4527:
4528: sub get_previous_attempt {
1.1199 raeburn 4529: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4530: my $prevattempts='';
1.43 ng 4531: no strict 'refs';
1.1 albertel 4532: if ($symb) {
1.3 albertel 4533: my (%returnhash)=
4534: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4535: if ($returnhash{'version'}) {
4536: my %lasthash=();
4537: my $version;
4538: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4539: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4540: if ($key =~ /\.rawrndseed$/) {
4541: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4542: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4543: } else {
4544: $lasthash{$key}=$returnhash{$version.':'.$key};
4545: }
1.19 harris41 4546: }
1.1 albertel 4547: }
1.596 albertel 4548: $prevattempts=&start_data_table().&start_data_table_header_row();
4549: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4550: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4551: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4552: foreach my $key (sort(keys(%lasthash))) {
4553: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4554: if ($#parts > 0) {
1.31 albertel 4555: my $data=$parts[-1];
1.989 raeburn 4556: next if ($data eq 'foilorder');
1.31 albertel 4557: pop(@parts);
1.1010 www 4558: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4559: if ($data eq 'type') {
4560: unless ($showsurv) {
4561: my $id = join(',',@parts);
4562: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4563: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4564: $lasthidden{$ign.'.'.$id} = 1;
4565: }
1.945 raeburn 4566: }
1.1199 raeburn 4567: if ($identifier ne '') {
4568: my $id = join(',',@parts);
4569: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4570: $domain,$username,$usec,undef,$course) =~ /^no/) {
4571: $hidestatus{$ign.'.'.$id} = 1;
4572: }
4573: }
4574: } elsif ($data eq 'regrader') {
4575: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4576: my $id = join(',',@parts);
4577: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4578: }
1.1010 www 4579: }
1.31 albertel 4580: } else {
1.41 ng 4581: if ($#parts == 0) {
4582: $prevattempts.='<th>'.$parts[0].'</th>';
4583: } else {
4584: $prevattempts.='<th>'.$ign.'</th>';
4585: }
1.31 albertel 4586: }
1.16 harris41 4587: }
1.596 albertel 4588: $prevattempts.=&end_data_table_header_row();
1.40 ng 4589: if ($getattempt eq '') {
1.1199 raeburn 4590: my (%solved,%resets,%probstatus);
1.1200 raeburn 4591: if (($identifier ne '') && (keys(%regraded) > 0)) {
4592: for ($version=1;$version<=$returnhash{'version'};$version++) {
4593: foreach my $id (keys(%regraded)) {
4594: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4595: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4596: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4597: push(@{$resets{$id}},$version);
1.1199 raeburn 4598: }
4599: }
4600: }
1.1200 raeburn 4601: }
4602: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4603: my (@hidden,@unsolved);
1.945 raeburn 4604: if (%typeparts) {
4605: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4606: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4607: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4608: push(@hidden,$id);
1.1199 raeburn 4609: } elsif ($identifier ne '') {
4610: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4611: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4612: ($hidestatus{$id})) {
1.1200 raeburn 4613: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4614: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4615: push(@{$solved{$id}},$version);
4616: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4617: (ref($solved{$id}) eq 'ARRAY')) {
4618: my $skip;
4619: if (ref($resets{$id}) eq 'ARRAY') {
4620: foreach my $reset (@{$resets{$id}}) {
4621: if ($reset > $solved{$id}[-1]) {
4622: $skip=1;
4623: last;
4624: }
4625: }
4626: }
4627: unless ($skip) {
4628: my ($ign,$partslist) = split(/\./,$id,2);
4629: push(@unsolved,$partslist);
4630: }
4631: }
4632: }
1.945 raeburn 4633: }
4634: }
4635: }
4636: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4637: '<td>'.&mt('Transaction [_1]',$version);
4638: if (@unsolved) {
4639: $prevattempts .= '<span class="LC_nobreak"><label>'.
4640: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4641: &mt('Hide').'</label></span>';
4642: }
4643: $prevattempts .= '</td>';
1.945 raeburn 4644: if (@hidden) {
4645: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4646: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4647: my $hide;
4648: foreach my $id (@hidden) {
4649: if ($key =~ /^\Q$id\E/) {
4650: $hide = 1;
4651: last;
4652: }
4653: }
4654: if ($hide) {
4655: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4656: if (($data eq 'award') || ($data eq 'awarddetail')) {
4657: my $value = &format_previous_attempt_value($key,
4658: $returnhash{$version.':'.$key});
1.1173 kruse 4659: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4660: } else {
4661: $prevattempts.='<td> </td>';
4662: }
4663: } else {
4664: if ($key =~ /\./) {
1.1212 raeburn 4665: my $value = $returnhash{$version.':'.$key};
4666: if ($key =~ /\.rndseed$/) {
4667: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4668: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4669: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4670: }
4671: }
4672: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4673: ' </td>';
1.945 raeburn 4674: } else {
4675: $prevattempts.='<td> </td>';
4676: }
4677: }
4678: }
4679: } else {
4680: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4681: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4682: my $value = $returnhash{$version.':'.$key};
4683: if ($key =~ /\.rndseed$/) {
4684: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4685: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4686: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4687: }
4688: }
4689: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4690: ' </td>';
1.945 raeburn 4691: }
4692: }
4693: $prevattempts.=&end_data_table_row();
1.40 ng 4694: }
1.1 albertel 4695: }
1.945 raeburn 4696: my @currhidden = keys(%lasthidden);
1.596 albertel 4697: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4698: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4699: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4700: if (%typeparts) {
4701: my $hidden;
4702: foreach my $id (@currhidden) {
4703: if ($key =~ /^\Q$id\E/) {
4704: $hidden = 1;
4705: last;
4706: }
4707: }
4708: if ($hidden) {
4709: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4710: if (($data eq 'award') || ($data eq 'awarddetail')) {
4711: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4712: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4713: $value = &$gradesub($value);
4714: }
1.1173 kruse 4715: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4716: } else {
4717: $prevattempts.='<td> </td>';
4718: }
4719: } else {
4720: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4721: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4722: $value = &$gradesub($value);
4723: }
1.1173 kruse 4724: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4725: }
4726: } else {
4727: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4728: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4729: $value = &$gradesub($value);
4730: }
1.1173 kruse 4731: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4732: }
1.16 harris41 4733: }
1.596 albertel 4734: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4735: } else {
1.1305 raeburn 4736: my $msg;
4737: if ($symb =~ /ext\.tool$/) {
4738: $msg = &mt('No grade passed back.');
4739: } else {
4740: $msg = &mt('Nothing submitted - no attempts.');
4741: }
1.596 albertel 4742: $prevattempts=
4743: &start_data_table().&start_data_table_row().
1.1305 raeburn 4744: '<td>'.$msg.'</td>'.
1.596 albertel 4745: &end_data_table_row().&end_data_table();
1.1 albertel 4746: }
4747: } else {
1.596 albertel 4748: $prevattempts=
4749: &start_data_table().&start_data_table_row().
4750: '<td>'.&mt('No data.').'</td>'.
4751: &end_data_table_row().&end_data_table();
1.1 albertel 4752: }
1.10 albertel 4753: }
4754:
1.581 albertel 4755: sub format_previous_attempt_value {
4756: my ($key,$value) = @_;
1.1011 www 4757: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4758: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4759: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4760: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4761: } elsif ($key =~ /answerstring$/) {
4762: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4763: my @answer = %answers;
4764: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4765: my @anskeys = sort(keys(%answers));
4766: if (@anskeys == 1) {
4767: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4768: if ($answer =~ m{\0}) {
4769: $answer =~ s{\0}{,}g;
1.988 raeburn 4770: }
4771: my $tag_internal_answer_name = 'INTERNAL';
4772: if ($anskeys[0] eq $tag_internal_answer_name) {
4773: $value = $answer;
4774: } else {
4775: $value = $anskeys[0].'='.$answer;
4776: }
4777: } else {
4778: foreach my $ans (@anskeys) {
4779: my $answer = $answers{$ans};
1.1001 raeburn 4780: if ($answer =~ m{\0}) {
4781: $answer =~ s{\0}{,}g;
1.988 raeburn 4782: }
4783: $value .= $ans.'='.$answer.'<br />';;
4784: }
4785: }
1.581 albertel 4786: } else {
1.1173 kruse 4787: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4788: }
4789: return $value;
4790: }
4791:
4792:
1.107 albertel 4793: sub relative_to_absolute {
4794: my ($url,$output)=@_;
4795: my $parser=HTML::TokeParser->new(\$output);
4796: my $token;
4797: my $thisdir=$url;
4798: my @rlinks=();
4799: while ($token=$parser->get_token) {
4800: if ($token->[0] eq 'S') {
4801: if ($token->[1] eq 'a') {
4802: if ($token->[2]->{'href'}) {
4803: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4804: }
4805: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4806: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4807: } elsif ($token->[1] eq 'base') {
4808: $thisdir=$token->[2]->{'href'};
4809: }
4810: }
4811: }
4812: $thisdir=~s-/[^/]*$--;
1.356 albertel 4813: foreach my $link (@rlinks) {
1.726 raeburn 4814: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4815: ($link=~/^\//) ||
4816: ($link=~/^javascript:/i) ||
4817: ($link=~/^mailto:/i) ||
4818: ($link=~/^\#/)) {
4819: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4820: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4821: }
4822: }
4823: # -------------------------------------------------- Deal with Applet codebases
4824: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4825: return $output;
4826: }
4827:
1.112 bowersj2 4828: =pod
4829:
1.648 raeburn 4830: =item * &get_student_view()
1.112 bowersj2 4831:
4832: show a snapshot of what student was looking at
4833:
4834: =cut
4835:
1.10 albertel 4836: sub get_student_view {
1.186 albertel 4837: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4838: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4839: my (%form);
1.10 albertel 4840: my @elements=('symb','courseid','domain','username');
4841: foreach my $element (@elements) {
1.186 albertel 4842: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4843: }
1.186 albertel 4844: if (defined($moreenv)) {
4845: %form=(%form,%{$moreenv});
4846: }
1.236 albertel 4847: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4848: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4849: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4850: $feedurl =~ s{^/adm/wrapper}{};
4851: }
1.650 www 4852: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4853: $userview=~s/\<body[^\>]*\>//gi;
4854: $userview=~s/\<\/body\>//gi;
4855: $userview=~s/\<html\>//gi;
4856: $userview=~s/\<\/html\>//gi;
4857: $userview=~s/\<head\>//gi;
4858: $userview=~s/\<\/head\>//gi;
4859: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4860: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4861: if (wantarray) {
4862: return ($userview,$response);
4863: } else {
4864: return $userview;
4865: }
4866: }
4867:
4868: sub get_student_view_with_retries {
4869: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4870:
4871: my $ok = 0; # True if we got a good response.
4872: my $content;
4873: my $response;
4874:
4875: # Try to get the student_view done. within the retries count:
4876:
4877: do {
4878: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4879: $ok = $response->is_success;
4880: if (!$ok) {
4881: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4882: }
4883: $retries--;
4884: } while (!$ok && ($retries > 0));
4885:
4886: if (!$ok) {
4887: $content = ''; # On error return an empty content.
4888: }
1.651 www 4889: if (wantarray) {
4890: return ($content, $response);
4891: } else {
4892: return $content;
4893: }
1.11 albertel 4894: }
4895:
1.1349 raeburn 4896: sub css_links {
4897: my ($currsymb,$level) = @_;
4898: my ($links,@symbs,%cssrefs,%httpref);
4899: if ($level eq 'map') {
4900: my $navmap = Apache::lonnavmaps::navmap->new();
4901: if (ref($navmap)) {
4902: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4903: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4904: foreach my $res (@resources) {
4905: if (ref($res) && $res->symb()) {
4906: push(@symbs,$res->symb());
4907: }
4908: }
4909: }
4910: } else {
4911: @symbs = ($currsymb);
4912: }
4913: foreach my $symb (@symbs) {
4914: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4915: if ($css_href =~ /\S/) {
4916: unless ($css_href =~ m{https?://}) {
4917: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4918: my $proburl = &Apache::lonnet::clutter($url);
4919: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4920: unless ($css_href =~ m{^/}) {
4921: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4922: }
4923: if ($css_href =~ m{^/(res|uploaded)/}) {
4924: unless (($httpref{'httpref.'.$css_href}) ||
4925: (&Apache::lonnet::is_on_map($css_href))) {
4926: my $thisurl = $proburl;
4927: if ($env{'httpref.'.$proburl}) {
4928: $thisurl = $env{'httpref.'.$proburl};
4929: }
4930: $httpref{'httpref.'.$css_href} = $thisurl;
4931: }
4932: }
4933: }
4934: $cssrefs{$css_href} = 1;
4935: }
4936: }
4937: if (keys(%httpref)) {
4938: &Apache::lonnet::appenv(\%httpref);
4939: }
4940: if (keys(%cssrefs)) {
4941: foreach my $css_href (keys(%cssrefs)) {
4942: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4943: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4944: }
4945: }
4946: return $links;
4947: }
4948:
1.112 bowersj2 4949: =pod
4950:
1.648 raeburn 4951: =item * &get_student_answers()
1.112 bowersj2 4952:
4953: show a snapshot of how student was answering problem
4954:
4955: =cut
4956:
1.11 albertel 4957: sub get_student_answers {
1.100 sakharuk 4958: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4959: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4960: my (%moreenv);
1.11 albertel 4961: my @elements=('symb','courseid','domain','username');
4962: foreach my $element (@elements) {
1.186 albertel 4963: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4964: }
1.186 albertel 4965: $moreenv{'grade_target'}='answer';
4966: %moreenv=(%form,%moreenv);
1.497 raeburn 4967: $feedurl = &Apache::lonnet::clutter($feedurl);
4968: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4969: return $userview;
1.1 albertel 4970: }
1.116 albertel 4971:
4972: =pod
4973:
4974: =item * &submlink()
4975:
1.242 albertel 4976: Inputs: $text $uname $udom $symb $target
1.116 albertel 4977:
4978: Returns: A link to grades.pm such as to see the SUBM view of a student
4979:
4980: =cut
4981:
4982: ###############################################
4983: sub submlink {
1.242 albertel 4984: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4985: if (!($uname && $udom)) {
4986: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4987: &Apache::lonnet::whichuser($symb);
1.116 albertel 4988: if (!$symb) { $symb=$cursymb; }
4989: }
1.254 matthew 4990: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4991: $symb=&escape($symb);
1.960 bisitz 4992: if ($target) { $target=" target=\"$target\""; }
4993: return
4994: '<a href="/adm/grades?command=submission'.
4995: '&symb='.$symb.
4996: '&student='.$uname.
4997: '&userdom='.$udom.'"'.
4998: $target.'>'.$text.'</a>';
1.242 albertel 4999: }
5000: ##############################################
5001:
5002: =pod
5003:
5004: =item * &pgrdlink()
5005:
5006: Inputs: $text $uname $udom $symb $target
5007:
5008: Returns: A link to grades.pm such as to see the PGRD view of a student
5009:
5010: =cut
5011:
5012: ###############################################
5013: sub pgrdlink {
5014: my $link=&submlink(@_);
5015: $link=~s/(&command=submission)/$1&showgrading=yes/;
5016: return $link;
5017: }
5018: ##############################################
5019:
5020: =pod
5021:
5022: =item * &pprmlink()
5023:
5024: Inputs: $text $uname $udom $symb $target
5025:
5026: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5027: student and a specific resource
1.242 albertel 5028:
5029: =cut
5030:
5031: ###############################################
5032: sub pprmlink {
5033: my ($text,$uname,$udom,$symb,$target)=@_;
5034: if (!($uname && $udom)) {
5035: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5036: &Apache::lonnet::whichuser($symb);
1.242 albertel 5037: if (!$symb) { $symb=$cursymb; }
5038: }
1.254 matthew 5039: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5040: $symb=&escape($symb);
1.242 albertel 5041: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5042: return '<a href="/adm/parmset?command=set&'.
5043: 'symb='.$symb.'&uname='.$uname.
5044: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5045: }
5046: ##############################################
1.37 matthew 5047:
1.112 bowersj2 5048: =pod
5049:
5050: =back
5051:
5052: =cut
5053:
1.37 matthew 5054: ###############################################
1.51 www 5055:
5056:
5057: sub timehash {
1.687 raeburn 5058: my ($thistime) = @_;
5059: my $timezone = &Apache::lonlocal::gettimezone();
5060: my $dt = DateTime->from_epoch(epoch => $thistime)
5061: ->set_time_zone($timezone);
5062: my $wday = $dt->day_of_week();
5063: if ($wday == 7) { $wday = 0; }
5064: return ( 'second' => $dt->second(),
5065: 'minute' => $dt->minute(),
5066: 'hour' => $dt->hour(),
5067: 'day' => $dt->day_of_month(),
5068: 'month' => $dt->month(),
5069: 'year' => $dt->year(),
5070: 'weekday' => $wday,
5071: 'dayyear' => $dt->day_of_year(),
5072: 'dlsav' => $dt->is_dst() );
1.51 www 5073: }
5074:
1.370 www 5075: sub utc_string {
5076: my ($date)=@_;
1.371 www 5077: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5078: }
5079:
1.51 www 5080: sub maketime {
5081: my %th=@_;
1.687 raeburn 5082: my ($epoch_time,$timezone,$dt);
5083: $timezone = &Apache::lonlocal::gettimezone();
5084: eval {
5085: $dt = DateTime->new( year => $th{'year'},
5086: month => $th{'month'},
5087: day => $th{'day'},
5088: hour => $th{'hour'},
5089: minute => $th{'minute'},
5090: second => $th{'second'},
5091: time_zone => $timezone,
5092: );
5093: };
5094: if (!$@) {
5095: $epoch_time = $dt->epoch;
5096: if ($epoch_time) {
5097: return $epoch_time;
5098: }
5099: }
1.51 www 5100: return POSIX::mktime(
5101: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5102: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5103: }
5104:
5105: #########################################
1.51 www 5106:
5107: sub findallcourses {
1.482 raeburn 5108: my ($roles,$uname,$udom) = @_;
1.355 albertel 5109: my %roles;
5110: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5111: my %courses;
1.51 www 5112: my $now=time;
1.482 raeburn 5113: if (!defined($uname)) {
5114: $uname = $env{'user.name'};
5115: }
5116: if (!defined($udom)) {
5117: $udom = $env{'user.domain'};
5118: }
5119: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5120: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5121: if (!%roles) {
5122: %roles = (
5123: cc => 1,
1.907 raeburn 5124: co => 1,
1.482 raeburn 5125: in => 1,
5126: ep => 1,
5127: ta => 1,
5128: cr => 1,
5129: st => 1,
5130: );
5131: }
5132: foreach my $entry (keys(%roleshash)) {
5133: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5134: if ($trole =~ /^cr/) {
5135: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5136: } else {
5137: next if (!exists($roles{$trole}));
5138: }
5139: if ($tend) {
5140: next if ($tend < $now);
5141: }
5142: if ($tstart) {
5143: next if ($tstart > $now);
5144: }
1.1058 raeburn 5145: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5146: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5147: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5148: if ($secpart eq '') {
5149: ($cnum,$role) = split(/_/,$cnumpart);
5150: $sec = 'none';
1.1058 raeburn 5151: $value .= $cnum.'/';
1.482 raeburn 5152: } else {
5153: $cnum = $cnumpart;
5154: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5155: $value .= $cnum.'/'.$sec;
5156: }
5157: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5158: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5159: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5160: }
5161: } else {
5162: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5163: }
1.482 raeburn 5164: }
5165: } else {
5166: foreach my $key (keys(%env)) {
1.483 albertel 5167: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5168: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5169: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5170: next if ($role eq 'ca' || $role eq 'aa');
5171: next if (%roles && !exists($roles{$role}));
5172: my ($starttime,$endtime)=split(/\./,$env{$key});
5173: my $active=1;
5174: if ($starttime) {
5175: if ($now<$starttime) { $active=0; }
5176: }
5177: if ($endtime) {
5178: if ($now>$endtime) { $active=0; }
5179: }
5180: if ($active) {
1.1058 raeburn 5181: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5182: if ($sec eq '') {
5183: $sec = 'none';
1.1058 raeburn 5184: } else {
5185: $value .= $sec;
5186: }
5187: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5188: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5189: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5190: }
5191: } else {
5192: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5193: }
1.474 raeburn 5194: }
5195: }
1.51 www 5196: }
5197: }
1.474 raeburn 5198: return %courses;
1.51 www 5199: }
1.37 matthew 5200:
1.54 www 5201: ###############################################
1.474 raeburn 5202:
5203: sub blockcheck {
1.1372 raeburn 5204: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5205: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5206: my ($has_evb,$check_ipaccess);
5207: my $dom = $env{'user.domain'};
5208: if ($env{'request.course.id'}) {
5209: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5210: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5211: my $checkrole = "cm./$cdom/$cnum";
5212: my $sec = $env{'request.course.sec'};
5213: if ($sec ne '') {
5214: $checkrole .= "/$sec";
5215: }
5216: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5217: ($env{'request.role'} !~ /^st/)) {
5218: $has_evb = 1;
5219: }
5220: unless ($has_evb) {
5221: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5222: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5223: if ($udom eq $cdom) {
5224: $check_ipaccess = 1;
5225: }
5226: }
5227: }
5228: }
5229: unless ($has_evb || $check_ipaccess) {
5230: my @machinedoms = &Apache::lonnet::current_machine_domains();
5231: if (($dom eq 'public') && ($activity eq 'port')) {
5232: $dom = $udom;
5233: }
5234: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5235: $check_ipaccess = 1;
5236: } else {
5237: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5238: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5239: my $prim = &Apache::lonnet::domain($dom,'primary');
5240: my $intdom = &Apache::lonnet::internet_dom($prim);
5241: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5242: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5243: $check_ipaccess = 1;
5244: }
5245: }
5246: }
5247: }
5248: if ($check_ipaccess) {
5249: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5250: unless (defined($cached)) {
5251: my %domconfig =
5252: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5253: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5254: }
5255: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5256: foreach my $id (keys(%{$ipaccessref})) {
5257: if (ref($ipaccessref->{$id}) eq 'HASH') {
5258: my $range = $ipaccessref->{$id}->{'ip'};
5259: if ($range) {
5260: if (&Apache::lonnet::ip_match($clientip,$range)) {
5261: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5262: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5263: return ('','','',$id,$dom);
5264: last;
5265: }
5266: }
5267: }
5268: }
5269: }
5270: }
5271: }
5272: }
1.1373 raeburn 5273: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5274: return ();
5275: }
1.1372 raeburn 5276: }
1.1189 raeburn 5277: if (defined($udom) && defined($uname)) {
5278: # If uname and udom are for a course, check for blocks in the course.
5279: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5280: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5281: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5282: return ($startblock,$endblock,$triggerblock);
5283: }
5284: } else {
1.490 raeburn 5285: $udom = $env{'user.domain'};
5286: $uname = $env{'user.name'};
5287: }
5288:
1.502 raeburn 5289: my $startblock = 0;
5290: my $endblock = 0;
1.1062 raeburn 5291: my $triggerblock = '';
1.1373 raeburn 5292: my %live_courses;
5293: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5294: %live_courses = &findallcourses(undef,$uname,$udom);
5295: }
1.474 raeburn 5296:
1.490 raeburn 5297: # If uname is for a user, and activity is course-specific, i.e.,
5298: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5299:
1.490 raeburn 5300: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5301: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5302: $activity eq 'search' || $activity eq 'reinit' ||
5303: $activity eq 'alert') &&
1.1189 raeburn 5304: ($env{'request.course.id'})) {
1.490 raeburn 5305: foreach my $key (keys(%live_courses)) {
5306: if ($key ne $env{'request.course.id'}) {
5307: delete($live_courses{$key});
5308: }
5309: }
5310: }
5311:
5312: my $otheruser = 0;
5313: my %own_courses;
5314: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5315: # Resource belongs to user other than current user.
5316: $otheruser = 1;
5317: # Gather courses for current user
5318: %own_courses =
5319: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5320: }
5321:
5322: # Gather active course roles - course coordinator, instructor,
5323: # exam proctor, ta, student, or custom role.
1.474 raeburn 5324:
5325: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5326: my ($cdom,$cnum);
5327: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5328: $cdom = $env{'course.'.$course.'.domain'};
5329: $cnum = $env{'course.'.$course.'.num'};
5330: } else {
1.490 raeburn 5331: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5332: }
5333: my $no_ownblock = 0;
5334: my $no_userblock = 0;
1.533 raeburn 5335: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5336: # Check if current user has 'evb' priv for this
5337: if (defined($own_courses{$course})) {
5338: foreach my $sec (keys(%{$own_courses{$course}})) {
5339: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5340: if ($sec ne 'none') {
5341: $checkrole .= '/'.$sec;
5342: }
5343: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5344: $no_ownblock = 1;
5345: last;
5346: }
5347: }
5348: }
5349: # if they have 'evb' priv and are currently not playing student
5350: next if (($no_ownblock) &&
5351: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5352: }
1.474 raeburn 5353: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5354: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5355: if ($sec ne 'none') {
1.482 raeburn 5356: $checkrole .= '/'.$sec;
1.474 raeburn 5357: }
1.490 raeburn 5358: if ($otheruser) {
5359: # Resource belongs to user other than current user.
5360: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5361: my (%allroles,%userroles);
5362: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5363: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5364: my ($trole,$tdom,$tnum,$tsec);
5365: if ($entry =~ /^cr/) {
5366: ($trole,$tdom,$tnum,$tsec) =
5367: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5368: } else {
5369: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5370: }
5371: my ($spec,$area,$trest);
5372: $area = '/'.$tdom.'/'.$tnum;
5373: $trest = $tnum;
5374: if ($tsec ne '') {
5375: $area .= '/'.$tsec;
5376: $trest .= '/'.$tsec;
5377: }
5378: $spec = $trole.'.'.$area;
5379: if ($trole =~ /^cr/) {
5380: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5381: $tdom,$spec,$trest,$area);
5382: } else {
5383: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5384: $tdom,$spec,$trest,$area);
5385: }
5386: }
1.1276 raeburn 5387: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5388: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5389: if ($1) {
5390: $no_userblock = 1;
5391: last;
5392: }
1.486 raeburn 5393: }
5394: }
1.490 raeburn 5395: } else {
5396: # Resource belongs to current user
5397: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5398: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5399: $no_ownblock = 1;
5400: last;
5401: }
1.474 raeburn 5402: }
5403: }
5404: # if they have the evb priv and are currently not playing student
1.482 raeburn 5405: next if (($no_ownblock) &&
1.491 albertel 5406: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5407: next if ($no_userblock);
1.474 raeburn 5408:
1.1303 raeburn 5409: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5410: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5411:
1.1062 raeburn 5412: my ($start,$end,$trigger) =
1.1347 raeburn 5413: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5414: if (($start != 0) &&
5415: (($startblock == 0) || ($startblock > $start))) {
5416: $startblock = $start;
1.1062 raeburn 5417: if ($trigger ne '') {
5418: $triggerblock = $trigger;
5419: }
1.502 raeburn 5420: }
5421: if (($end != 0) &&
5422: (($endblock == 0) || ($endblock < $end))) {
5423: $endblock = $end;
1.1062 raeburn 5424: if ($trigger ne '') {
5425: $triggerblock = $trigger;
5426: }
1.502 raeburn 5427: }
1.490 raeburn 5428: }
1.1062 raeburn 5429: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5430: }
5431:
5432: sub get_blocks {
1.1347 raeburn 5433: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5434: my $startblock = 0;
5435: my $endblock = 0;
1.1062 raeburn 5436: my $triggerblock = '';
1.490 raeburn 5437: my $course = $cdom.'_'.$cnum;
5438: $setters->{$course} = {};
5439: $setters->{$course}{'staff'} = [];
5440: $setters->{$course}{'times'} = [];
1.1062 raeburn 5441: $setters->{$course}{'triggers'} = [];
5442: my (@blockers,%triggered);
5443: my $now = time;
5444: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5445: if ($activity eq 'docs') {
1.1348 raeburn 5446: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5447: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5448: $blocked = 1;
5449: $nosymbcache = 1;
1.1348 raeburn 5450: $noenccheck = 1;
1.1347 raeburn 5451: }
1.1348 raeburn 5452: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5453: foreach my $block (@blockers) {
5454: if ($block =~ /^firstaccess____(.+)$/) {
5455: my $item = $1;
5456: my $type = 'map';
5457: my $timersymb = $item;
5458: if ($item eq 'course') {
5459: $type = 'course';
5460: } elsif ($item =~ /___\d+___/) {
5461: $type = 'resource';
5462: } else {
5463: $timersymb = &Apache::lonnet::symbread($item);
5464: }
5465: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5466: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5467: $triggered{$block} = {
5468: start => $start,
5469: end => $end,
5470: type => $type,
5471: };
5472: }
5473: }
5474: } else {
5475: foreach my $block (keys(%commblocks)) {
5476: if ($block =~ m/^(\d+)____(\d+)$/) {
5477: my ($start,$end) = ($1,$2);
5478: if ($start <= time && $end >= time) {
5479: if (ref($commblocks{$block}) eq 'HASH') {
5480: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5481: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5482: unless(grep(/^\Q$block\E$/,@blockers)) {
5483: push(@blockers,$block);
5484: }
5485: }
5486: }
5487: }
5488: }
5489: } elsif ($block =~ /^firstaccess____(.+)$/) {
5490: my $item = $1;
5491: my $timersymb = $item;
5492: my $type = 'map';
5493: if ($item eq 'course') {
5494: $type = 'course';
5495: } elsif ($item =~ /___\d+___/) {
5496: $type = 'resource';
5497: } else {
5498: $timersymb = &Apache::lonnet::symbread($item);
5499: }
5500: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5501: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5502: if ($start && $end) {
5503: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5504: if (ref($commblocks{$block}) eq 'HASH') {
5505: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5506: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5507: unless(grep(/^\Q$block\E$/,@blockers)) {
5508: push(@blockers,$block);
5509: $triggered{$block} = {
5510: start => $start,
5511: end => $end,
5512: type => $type,
5513: };
5514: }
5515: }
5516: }
1.1062 raeburn 5517: }
5518: }
1.490 raeburn 5519: }
1.1062 raeburn 5520: }
5521: }
5522: }
5523: foreach my $blocker (@blockers) {
5524: my ($staff_name,$staff_dom,$title,$blocks) =
5525: &parse_block_record($commblocks{$blocker});
5526: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5527: my ($start,$end,$triggertype);
5528: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5529: ($start,$end) = ($1,$2);
5530: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5531: $start = $triggered{$blocker}{'start'};
5532: $end = $triggered{$blocker}{'end'};
5533: $triggertype = $triggered{$blocker}{'type'};
5534: }
5535: if ($start) {
5536: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5537: if ($triggertype) {
5538: push(@{$$setters{$course}{'triggers'}},$triggertype);
5539: } else {
5540: push(@{$$setters{$course}{'triggers'}},0);
5541: }
5542: if ( ($startblock == 0) || ($startblock > $start) ) {
5543: $startblock = $start;
5544: if ($triggertype) {
5545: $triggerblock = $blocker;
1.474 raeburn 5546: }
5547: }
1.1062 raeburn 5548: if ( ($endblock == 0) || ($endblock < $end) ) {
5549: $endblock = $end;
5550: if ($triggertype) {
5551: $triggerblock = $blocker;
5552: }
5553: }
1.474 raeburn 5554: }
5555: }
1.1062 raeburn 5556: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5557: }
5558:
5559: sub parse_block_record {
5560: my ($record) = @_;
5561: my ($setuname,$setudom,$title,$blocks);
5562: if (ref($record) eq 'HASH') {
5563: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5564: $title = &unescape($record->{'event'});
5565: $blocks = $record->{'blocks'};
5566: } else {
5567: my @data = split(/:/,$record,3);
5568: if (scalar(@data) eq 2) {
5569: $title = $data[1];
5570: ($setuname,$setudom) = split(/@/,$data[0]);
5571: } else {
5572: ($setuname,$setudom,$title) = @data;
5573: }
5574: $blocks = { 'com' => 'on' };
5575: }
5576: return ($setuname,$setudom,$title,$blocks);
5577: }
5578:
1.854 kalberla 5579: sub blocking_status {
1.1372 raeburn 5580: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5581: my %setters;
1.890 droeschl 5582:
1.1061 raeburn 5583: # check for active blocking
1.1372 raeburn 5584: if ($clientip eq '') {
5585: $clientip = &Apache::lonnet::get_requestor_ip();
5586: }
5587: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5588: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5589: my $blocked = 0;
1.1372 raeburn 5590: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5591: $blocked = 1;
5592: }
1.890 droeschl 5593:
1.1061 raeburn 5594: # caller just wants to know whether a block is active
5595: if (!wantarray) { return $blocked; }
5596:
5597: # build a link to a popup window containing the details
5598: my $querystring = "?activity=$activity";
1.1351 raeburn 5599: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5600: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5601: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5602: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5603: } elsif ($activity eq 'docs') {
1.1347 raeburn 5604: my $showurl = &Apache::lonenc::check_encrypt($url);
5605: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5606: if ($symb) {
5607: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5608: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5609: }
1.1062 raeburn 5610: }
1.1061 raeburn 5611:
5612: my $output .= <<'END_MYBLOCK';
5613: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5614: var options = "width=" + w + ",height=" + h + ",";
5615: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5616: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5617: var newWin = window.open(url, wdwName, options);
5618: newWin.focus();
5619: }
1.890 droeschl 5620: END_MYBLOCK
1.854 kalberla 5621:
1.1061 raeburn 5622: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5623:
1.1061 raeburn 5624: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5625: my $text = &mt('Communication Blocked');
1.1217 raeburn 5626: my $class = 'LC_comblock';
1.1062 raeburn 5627: if ($activity eq 'docs') {
5628: $text = &mt('Content Access Blocked');
1.1217 raeburn 5629: $class = '';
1.1063 raeburn 5630: } elsif ($activity eq 'printout') {
5631: $text = &mt('Printing Blocked');
1.1232 raeburn 5632: } elsif ($activity eq 'passwd') {
5633: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5634: } elsif ($activity eq 'grades') {
5635: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5636: } elsif ($activity eq 'search') {
5637: $text = &mt('Search Blocked');
1.1282 raeburn 5638: } elsif ($activity eq 'alert') {
5639: $text = &mt('Checking Critical Messages Blocked');
5640: } elsif ($activity eq 'reinit') {
5641: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5642: } elsif ($activity eq 'about') {
5643: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5644: } elsif ($activity eq 'wishlist') {
5645: $text = &mt('Access to Stored Links Blocked');
5646: } elsif ($activity eq 'annotate') {
5647: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5648: }
1.1061 raeburn 5649: $output .= <<"END_BLOCK";
1.1217 raeburn 5650: <div class='$class'>
1.869 kalberla 5651: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5652: title='$text'>
5653: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5654: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5655: title='$text'>$text</a>
1.867 kalberla 5656: </div>
5657:
5658: END_BLOCK
1.474 raeburn 5659:
1.1061 raeburn 5660: return ($blocked, $output);
1.854 kalberla 5661: }
1.490 raeburn 5662:
1.60 matthew 5663: ###############################################
5664:
1.682 raeburn 5665: sub check_ip_acc {
1.1201 raeburn 5666: my ($acc,$clientip)=@_;
1.682 raeburn 5667: &Apache::lonxml::debug("acc is $acc");
5668: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5669: return 1;
5670: }
1.1339 raeburn 5671: my ($ip,$allowed);
5672: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5673: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5674: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5675: } else {
1.1350 raeburn 5676: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5677: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5678: }
1.682 raeburn 5679:
5680: my $name;
1.1219 raeburn 5681: my %access = (
5682: allowfrom => 1,
5683: denyfrom => 0,
5684: );
5685: my @allows;
5686: my @denies;
5687: foreach my $item (split(',',$acc)) {
5688: $item =~ s/^\s*//;
5689: $item =~ s/\s*$//;
5690: my $pattern;
5691: if ($item =~ /^\!(.+)$/) {
5692: push(@denies,$1);
5693: } else {
5694: push(@allows,$item);
5695: }
5696: }
5697: my $numdenies = scalar(@denies);
5698: my $numallows = scalar(@allows);
5699: my $count = 0;
5700: foreach my $pattern (@denies,@allows) {
5701: $count ++;
5702: my $acctype = 'allowfrom';
5703: if ($count <= $numdenies) {
5704: $acctype = 'denyfrom';
5705: }
1.682 raeburn 5706: if ($pattern =~ /\*$/) {
5707: #35.8.*
5708: $pattern=~s/\*//;
1.1219 raeburn 5709: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5710: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5711: #35.8.3.[34-56]
5712: my $low=$2;
5713: my $high=$3;
5714: $pattern=$1;
5715: if ($ip =~ /^\Q$pattern\E/) {
5716: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5717: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5718: }
5719: } elsif ($pattern =~ /^\*/) {
5720: #*.msu.edu
5721: $pattern=~s/\*//;
5722: if (!defined($name)) {
5723: use Socket;
5724: my $netaddr=inet_aton($ip);
5725: ($name)=gethostbyaddr($netaddr,AF_INET);
5726: }
1.1219 raeburn 5727: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5728: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5729: #127.0.0.1
1.1219 raeburn 5730: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5731: } else {
5732: #some.name.com
5733: if (!defined($name)) {
5734: use Socket;
5735: my $netaddr=inet_aton($ip);
5736: ($name)=gethostbyaddr($netaddr,AF_INET);
5737: }
1.1219 raeburn 5738: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5739: }
5740: if ($allowed =~ /^(0|1)$/) { last; }
5741: }
5742: if ($allowed eq '') {
5743: if ($numdenies && !$numallows) {
5744: $allowed = 1;
5745: } else {
5746: $allowed = 0;
1.682 raeburn 5747: }
5748: }
5749: return $allowed;
5750: }
5751:
5752: ###############################################
5753:
1.60 matthew 5754: =pod
5755:
1.112 bowersj2 5756: =head1 Domain Template Functions
5757:
5758: =over 4
5759:
5760: =item * &determinedomain()
1.60 matthew 5761:
5762: Inputs: $domain (usually will be undef)
5763:
1.63 www 5764: Returns: Determines which domain should be used for designs
1.60 matthew 5765:
5766: =cut
1.54 www 5767:
1.60 matthew 5768: ###############################################
1.63 www 5769: sub determinedomain {
5770: my $domain=shift;
1.531 albertel 5771: if (! $domain) {
1.60 matthew 5772: # Determine domain if we have not been given one
1.893 raeburn 5773: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5774: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5775: if ($env{'request.role.domain'}) {
5776: $domain=$env{'request.role.domain'};
1.60 matthew 5777: }
5778: }
1.63 www 5779: return $domain;
5780: }
5781: ###############################################
1.517 raeburn 5782:
1.518 albertel 5783: sub devalidate_domconfig_cache {
5784: my ($udom)=@_;
5785: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5786: }
5787:
5788: # ---------------------- Get domain configuration for a domain
5789: sub get_domainconf {
5790: my ($udom) = @_;
5791: my $cachetime=1800;
5792: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5793: if (defined($cached)) { return %{$result}; }
5794:
5795: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5796: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5797: my (%designhash,%legacy);
1.518 albertel 5798: if (keys(%domconfig) > 0) {
5799: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5800: if (keys(%{$domconfig{'login'}})) {
5801: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5802: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5803: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5804: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5805: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5806: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5807: if ($key eq 'loginvia') {
5808: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5809: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5810: $designhash{$udom.'.login.loginvia'} = $server;
5811: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5812:
5813: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5814: } else {
5815: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5816: }
1.948 raeburn 5817: }
1.1208 raeburn 5818: } elsif ($key eq 'headtag') {
5819: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5820: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5821: }
1.946 raeburn 5822: }
1.1208 raeburn 5823: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5824: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5825: }
1.946 raeburn 5826: }
5827: }
5828: }
1.1366 raeburn 5829: } elsif ($key eq 'saml') {
5830: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5831: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5832: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5833: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
5834: foreach my $item ('text','img','alt','url','title','notsso') {
5835: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5836: }
5837: }
5838: }
5839: }
1.946 raeburn 5840: } else {
5841: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5842: $designhash{$udom.'.login.'.$key.'_'.$img} =
5843: $domconfig{'login'}{$key}{$img};
5844: }
1.699 raeburn 5845: }
5846: } else {
5847: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5848: }
1.632 raeburn 5849: }
5850: } else {
5851: $legacy{'login'} = 1;
1.518 albertel 5852: }
1.632 raeburn 5853: } else {
5854: $legacy{'login'} = 1;
1.518 albertel 5855: }
5856: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5857: if (keys(%{$domconfig{'rolecolors'}})) {
5858: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5859: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5860: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5861: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5862: }
1.518 albertel 5863: }
5864: }
1.632 raeburn 5865: } else {
5866: $legacy{'rolecolors'} = 1;
1.518 albertel 5867: }
1.632 raeburn 5868: } else {
5869: $legacy{'rolecolors'} = 1;
1.518 albertel 5870: }
1.948 raeburn 5871: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5872: if ($domconfig{'autoenroll'}{'co-owners'}) {
5873: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5874: }
5875: }
1.632 raeburn 5876: if (keys(%legacy) > 0) {
5877: my %legacyhash = &get_legacy_domconf($udom);
5878: foreach my $item (keys(%legacyhash)) {
5879: if ($item =~ /^\Q$udom\E\.login/) {
5880: if ($legacy{'login'}) {
5881: $designhash{$item} = $legacyhash{$item};
5882: }
5883: } else {
5884: if ($legacy{'rolecolors'}) {
5885: $designhash{$item} = $legacyhash{$item};
5886: }
1.518 albertel 5887: }
5888: }
5889: }
1.632 raeburn 5890: } else {
5891: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5892: }
5893: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5894: $cachetime);
5895: return %designhash;
5896: }
5897:
1.632 raeburn 5898: sub get_legacy_domconf {
5899: my ($udom) = @_;
5900: my %legacyhash;
5901: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5902: my $designfile = $designdir.'/'.$udom.'.tab';
5903: if (-e $designfile) {
1.1317 raeburn 5904: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5905: while (my $line = <$fh>) {
5906: next if ($line =~ /^\#/);
5907: chomp($line);
5908: my ($key,$val)=(split(/\=/,$line));
5909: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5910: }
5911: close($fh);
5912: }
5913: }
1.1026 raeburn 5914: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5915: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5916: }
5917: return %legacyhash;
5918: }
5919:
1.63 www 5920: =pod
5921:
1.112 bowersj2 5922: =item * &domainlogo()
1.63 www 5923:
5924: Inputs: $domain (usually will be undef)
5925:
5926: Returns: A link to a domain logo, if the domain logo exists.
5927: If the domain logo does not exist, a description of the domain.
5928:
5929: =cut
1.112 bowersj2 5930:
1.63 www 5931: ###############################################
5932: sub domainlogo {
1.517 raeburn 5933: my $domain = &determinedomain(shift);
1.518 albertel 5934: my %designhash = &get_domainconf($domain);
1.517 raeburn 5935: # See if there is a logo
5936: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5937: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5938: if ($imgsrc =~ m{^/(adm|res)/}) {
5939: if ($imgsrc =~ m{^/res/}) {
5940: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5941: &Apache::lonnet::repcopy($local_name);
5942: }
5943: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 ! raeburn 5944: }
! 5945: my $alttext = $domain;
! 5946: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
! 5947: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
! 5948: }
! 5949: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5950: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5951: return &Apache::lonnet::domain($domain,'description');
1.59 www 5952: } else {
1.60 matthew 5953: return '';
1.59 www 5954: }
5955: }
1.63 www 5956: ##############################################
5957:
5958: =pod
5959:
1.112 bowersj2 5960: =item * &designparm()
1.63 www 5961:
5962: Inputs: $which parameter; $domain (usually will be undef)
5963:
5964: Returns: value of designparamter $which
5965:
5966: =cut
1.112 bowersj2 5967:
1.397 albertel 5968:
1.400 albertel 5969: ##############################################
1.397 albertel 5970: sub designparm {
5971: my ($which,$domain)=@_;
5972: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5973: return $env{'environment.color.'.$which};
1.96 www 5974: }
1.63 www 5975: $domain=&determinedomain($domain);
1.1016 raeburn 5976: my %domdesign;
5977: unless ($domain eq 'public') {
5978: %domdesign = &get_domainconf($domain);
5979: }
1.520 raeburn 5980: my $output;
1.517 raeburn 5981: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5982: $output = $domdesign{$domain.'.'.$which};
1.63 www 5983: } else {
1.520 raeburn 5984: $output = $defaultdesign{$which};
5985: }
5986: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5987: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5988: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5989: if ($output =~ m{^/res/}) {
5990: my $local_name = &Apache::lonnet::filelocation('',$output);
5991: &Apache::lonnet::repcopy($local_name);
5992: }
1.520 raeburn 5993: $output = &lonhttpdurl($output);
5994: }
1.63 www 5995: }
1.520 raeburn 5996: return $output;
1.63 www 5997: }
1.59 www 5998:
1.822 bisitz 5999: ##############################################
6000: =pod
6001:
1.832 bisitz 6002: =item * &authorspace()
6003:
1.1028 raeburn 6004: Inputs: $url (usually will be undef).
1.832 bisitz 6005:
1.1132 raeburn 6006: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6007: directory being viewed (or for which action is being taken).
6008: If $url is provided, and begins /priv/<domain>/<uname>
6009: the path will be that portion of the $context argument.
6010: Otherwise the path will be for the author space of the current
6011: user when the current role is author, or for that of the
6012: co-author/assistant co-author space when the current role
6013: is co-author or assistant co-author.
1.832 bisitz 6014:
6015: =cut
6016:
6017: sub authorspace {
1.1028 raeburn 6018: my ($url) = @_;
6019: if ($url ne '') {
6020: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6021: return $1;
6022: }
6023: }
1.832 bisitz 6024: my $caname = '';
1.1024 www 6025: my $cadom = '';
1.1028 raeburn 6026: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6027: ($cadom,$caname) =
1.832 bisitz 6028: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6029: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6030: $caname = $env{'user.name'};
1.1024 www 6031: $cadom = $env{'user.domain'};
1.832 bisitz 6032: }
1.1028 raeburn 6033: if (($caname ne '') && ($cadom ne '')) {
6034: return "/priv/$cadom/$caname/";
6035: }
6036: return;
1.832 bisitz 6037: }
6038:
6039: ##############################################
6040: =pod
6041:
1.822 bisitz 6042: =item * &head_subbox()
6043:
6044: Inputs: $content (contains HTML code with page functions, etc.)
6045:
6046: Returns: HTML div with $content
6047: To be included in page header
6048:
6049: =cut
6050:
6051: sub head_subbox {
6052: my ($content)=@_;
6053: my $output =
1.993 raeburn 6054: '<div class="LC_head_subbox">'
1.822 bisitz 6055: .$content
6056: .'</div>'
6057: }
6058:
6059: ##############################################
6060: =pod
6061:
6062: =item * &CSTR_pageheader()
6063:
1.1026 raeburn 6064: Input: (optional) filename from which breadcrumb trail is built.
6065: In most cases no input as needed, as $env{'request.filename'}
6066: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 6067:
6068: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6069: To be included on Authoring Space pages
1.822 bisitz 6070:
6071: =cut
6072:
6073: sub CSTR_pageheader {
1.1026 raeburn 6074: my ($trailfile) = @_;
6075: if ($trailfile eq '') {
6076: $trailfile = $env{'request.filename'};
6077: }
6078:
6079: # this is for resources; directories have customtitle, and crumbs
6080: # and select recent are created in lonpubdir.pm
6081:
6082: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6083: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6084: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6085: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6086: $formaction =~ s{/+}{/}g;
1.822 bisitz 6087:
6088: my $parentpath = '';
6089: my $lastitem = '';
6090: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6091: $parentpath = $1;
6092: $lastitem = $2;
6093: } else {
6094: $lastitem = $thisdisfn;
6095: }
1.921 bisitz 6096:
1.1246 raeburn 6097: my ($crsauthor,$title);
6098: if (($env{'request.course.id'}) &&
6099: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6100: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6101: $crsauthor = 1;
6102: $title = &mt('Course Authoring Space');
6103: } else {
6104: $title = &mt('Authoring Space');
6105: }
6106:
1.1314 raeburn 6107: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 6108: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6109: $target = '';
6110: $crumbtarget = '';
1.1313 raeburn 6111: }
6112:
1.921 bisitz 6113: my $output =
1.822 bisitz 6114: '<div>'
6115: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6116: .'<b>'.$title.'</b> '
1.1314 raeburn 6117: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6118: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6119:
6120: if ($lastitem) {
6121: $output .=
6122: '<span class="LC_filename">'
6123: .$lastitem
6124: .'</span>';
6125: }
1.1245 raeburn 6126:
1.1246 raeburn 6127: if ($crsauthor) {
6128: $output .= '</form>'.&Apache::lonmenu::constspaceform();
6129: } else {
6130: $output .=
6131: '<br />'
1.1314 raeburn 6132: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6133: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6134: .'</form>'
6135: .&Apache::lonmenu::constspaceform();
6136: }
6137: $output .= '</div>';
1.921 bisitz 6138:
6139: return $output;
1.822 bisitz 6140: }
6141:
1.60 matthew 6142: ###############################################
6143: ###############################################
6144:
6145: =pod
6146:
1.112 bowersj2 6147: =back
6148:
1.549 albertel 6149: =head1 HTML Helpers
1.112 bowersj2 6150:
6151: =over 4
6152:
6153: =item * &bodytag()
1.60 matthew 6154:
6155: Returns a uniform header for LON-CAPA web pages.
6156:
6157: Inputs:
6158:
1.112 bowersj2 6159: =over 4
6160:
6161: =item * $title, A title to be displayed on the page.
6162:
6163: =item * $function, the current role (can be undef).
6164:
6165: =item * $addentries, extra parameters for the <body> tag.
6166:
6167: =item * $bodyonly, if defined, only return the <body> tag.
6168:
6169: =item * $domain, if defined, force a given domain.
6170:
6171: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6172: text interface only)
1.60 matthew 6173:
1.814 bisitz 6174: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6175: navigational links
1.317 albertel 6176:
1.338 albertel 6177: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6178:
1.460 albertel 6179: =item * $args, optional argument valid values are
6180: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6181: use_absolute -> for external resource or syllabus, this will
6182: contain https://<hostname> if server uses
6183: https (as per hosts.tab), but request is for http
6184: hostname -> hostname, from $r->hostname().
1.460 albertel 6185:
1.1096 raeburn 6186: =item * $advtoolsref, optional argument, ref to an array containing
6187: inlineremote items to be added in "Functions" menu below
6188: breadcrumbs.
6189:
1.1316 raeburn 6190: =item * $ltiscope, optional argument, will be one of: resource, map or
6191: course, if LON-CAPA is in LTI Provider context. Value is
6192: the scope of use, i.e., launch was for access to a single, a map
6193: or the entire course.
6194:
6195: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6196: context, this will contain the URL for the landing item in
6197: the course, after launch from an LTI Consumer
6198:
1.1318 raeburn 6199: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6200: context, this will contain a reference to hash of items
6201: to be included in the page header and/or inline menu.
6202:
1.112 bowersj2 6203: =back
6204:
1.60 matthew 6205: Returns: A uniform header for LON-CAPA web pages.
6206: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6207: If $bodyonly is undef or zero, an html string containing a <body> tag and
6208: other decorations will be returned.
6209:
6210: =cut
6211:
1.54 www 6212: sub bodytag {
1.831 bisitz 6213: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6214: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
6215: $ltimenu,$menucoll,$menuref)=@_;
1.339 albertel 6216:
1.954 raeburn 6217: my $public;
6218: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6219: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6220: $public = 1;
6221: }
1.460 albertel 6222: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6223: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6224: my $hostname = $args->{'hostname'};
1.339 albertel 6225:
1.183 matthew 6226: $function = &get_users_function() if (!$function);
1.339 albertel 6227: my $img = &designparm($function.'.img',$domain);
6228: my $font = &designparm($function.'.font',$domain);
6229: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6230:
1.803 bisitz 6231: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6232: 'bgcolor' => $pgbg,
1.339 albertel 6233: 'text' => $font,
6234: 'alink' => &designparm($function.'.alink',$domain),
6235: 'vlink' => &designparm($function.'.vlink',$domain),
6236: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6237: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6238:
1.63 www 6239: # role and realm
1.1178 raeburn 6240: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6241: if ($realm) {
6242: $realm = '/'.$realm;
6243: }
1.1357 raeburn 6244: if ($role eq 'ca') {
1.479 albertel 6245: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6246: $realm = &plainname($rname,$rdom);
1.378 raeburn 6247: }
1.55 www 6248: # realm
1.1357 raeburn 6249: my ($cid,$sec);
1.258 albertel 6250: if ($env{'request.course.id'}) {
1.1357 raeburn 6251: $cid = $env{'request.course.id'};
6252: if ($env{'request.course.sec'}) {
6253: $sec = $env{'request.course.sec'};
6254: }
6255: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6256: if (&Apache::lonnet::is_course($1,$2)) {
6257: $cid = $1.'_'.$2;
6258: $sec = $3;
6259: }
6260: }
6261: if ($cid) {
1.378 raeburn 6262: if ($env{'request.role'} !~ /^cr/) {
6263: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6264: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6265: if ($env{'request.role.desc'}) {
6266: $role = $env{'request.role.desc'};
6267: } else {
6268: $role = &mt('Helpdesk[_1]',' '.$2);
6269: }
1.1257 raeburn 6270: } else {
6271: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6272: }
1.1357 raeburn 6273: if ($sec) {
6274: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6275: }
1.1357 raeburn 6276: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6277: } else {
6278: $role = &Apache::lonnet::plaintext($role);
1.54 www 6279: }
1.433 albertel 6280:
1.359 albertel 6281: if (!$realm) { $realm=' '; }
1.330 albertel 6282:
1.438 albertel 6283: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6284:
1.101 www 6285: # construct main body tag
1.359 albertel 6286: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6287: &Apache::lontexconvert::init_math_support();
1.252 albertel 6288:
1.1131 raeburn 6289: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6290:
1.1130 raeburn 6291: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6292: return $bodytag;
1.1130 raeburn 6293: }
1.359 albertel 6294:
1.954 raeburn 6295: if ($public) {
1.433 albertel 6296: undef($role);
6297: }
1.1318 raeburn 6298:
1.1359 raeburn 6299: my $showcrstitle = 1;
1.1357 raeburn 6300: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6301: if (ref($ltimenu) eq 'HASH') {
6302: unless ($ltimenu->{'role'}) {
6303: undef($role);
6304: }
6305: unless ($ltimenu->{'coursetitle'}) {
6306: $realm=' ';
1.1359 raeburn 6307: $showcrstitle = 0;
6308: }
6309: }
6310: } elsif (($cid) && ($menucoll)) {
6311: if (ref($menuref) eq 'HASH') {
6312: unless ($menuref->{'role'}) {
6313: undef($role);
6314: }
6315: unless ($menuref->{'crs'}) {
6316: $realm=' ';
6317: $showcrstitle = 0;
1.1318 raeburn 6318: }
6319: }
6320: }
6321:
1.762 bisitz 6322: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6323: #
6324: # Extra info if you are the DC
6325: my $dc_info = '';
1.1359 raeburn 6326: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6327: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6328: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6329: $dc_info =~ s/\s+$//;
1.359 albertel 6330: }
6331:
1.1237 raeburn 6332: my $crstype;
1.1357 raeburn 6333: if ($cid) {
6334: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6335: } elsif ($args->{'crstype'}) {
6336: $crstype = $args->{'crstype'};
6337: }
6338: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6339: undef($role);
6340: } else {
1.1242 raeburn 6341: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6342: }
1.853 droeschl 6343:
1.903 droeschl 6344: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6345:
6346: # if ($env{'request.state'} eq 'construct') {
6347: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6348: # }
6349:
1.1130 raeburn 6350: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6351: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6352:
1.1318 raeburn 6353: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6354: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
6355: $args->{'links_disabled'});
1.359 albertel 6356:
1.1318 raeburn 6357: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6358: if ($dc_info) {
6359: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6360: }
6361: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6362: <em>$realm</em> $dc_info</div>|;
6363: return $bodytag;
6364: }
1.894 droeschl 6365:
1.1318 raeburn 6366: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6367: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6368: }
1.916 droeschl 6369:
1.1318 raeburn 6370: $bodytag .= $right;
1.852 droeschl 6371:
1.1318 raeburn 6372: if ($dc_info) {
6373: $dc_info = &dc_courseid_toggle($dc_info);
6374: }
6375: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6376: }
1.916 droeschl 6377:
1.1169 raeburn 6378: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6379: if ($args->{'no_secondary_menu'}) {
6380: return $bodytag;
6381: }
1.1169 raeburn 6382: #don't show menus for public users
1.954 raeburn 6383: if (!$public){
1.1318 raeburn 6384: unless ($args->{'no_inline_menu'}) {
6385: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6386: $args->{'no_primary_menu'},
1.1369 raeburn 6387: $menucoll,$menuref,
6388: $args->{'links_disabled'});
1.1318 raeburn 6389: }
1.903 droeschl 6390: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6391: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6392: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6393: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6394: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6395: } elsif ($forcereg) {
6396: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6397: $args->{'group'},
1.1274 raeburn 6398: $args->{'hide_buttons'},
1.1316 raeburn 6399: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6400: } else {
6401: $bodytag .=
6402: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6403: $forcereg,$args->{'group'},
6404: $args->{'bread_crumbs'},
1.1274 raeburn 6405: $advtoolsref,'',$hostname);
1.920 raeburn 6406: }
1.903 droeschl 6407: }else{
6408: # this is to seperate menu from content when there's no secondary
6409: # menu. Especially needed for public accessible ressources.
6410: $bodytag .= '<hr style="clear:both" />';
6411: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6412: }
1.903 droeschl 6413:
1.235 raeburn 6414: return $bodytag;
1.182 matthew 6415: }
6416:
1.917 raeburn 6417: sub dc_courseid_toggle {
6418: my ($dc_info) = @_;
1.980 raeburn 6419: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6420: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6421: &mt('(More ...)').'</a></span>'.
6422: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6423: }
6424:
1.330 albertel 6425: sub make_attr_string {
6426: my ($register,$attr_ref) = @_;
6427:
6428: if ($attr_ref && !ref($attr_ref)) {
6429: die("addentries Must be a hash ref ".
6430: join(':',caller(1))." ".
6431: join(':',caller(0))." ");
6432: }
6433:
6434: if ($register) {
1.339 albertel 6435: my ($on_load,$on_unload);
6436: foreach my $key (keys(%{$attr_ref})) {
6437: if (lc($key) eq 'onload') {
6438: $on_load.=$attr_ref->{$key}.';';
6439: delete($attr_ref->{$key});
6440:
6441: } elsif (lc($key) eq 'onunload') {
6442: $on_unload.=$attr_ref->{$key}.';';
6443: delete($attr_ref->{$key});
6444: }
6445: }
1.953 droeschl 6446: $attr_ref->{'onload'} = $on_load;
6447: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6448: }
1.339 albertel 6449:
1.330 albertel 6450: my $attr_string;
1.1159 raeburn 6451: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6452: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6453: }
6454: return $attr_string;
6455: }
6456:
6457:
1.182 matthew 6458: ###############################################
1.251 albertel 6459: ###############################################
6460:
6461: =pod
6462:
6463: =item * &endbodytag()
6464:
6465: Returns a uniform footer for LON-CAPA web pages.
6466:
1.635 raeburn 6467: Inputs: 1 - optional reference to an args hash
6468: If in the hash, key for noredirectlink has a value which evaluates to true,
6469: a 'Continue' link is not displayed if the page contains an
6470: internal redirect in the <head></head> section,
6471: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6472:
6473: =cut
6474:
6475: sub endbodytag {
1.635 raeburn 6476: my ($args) = @_;
1.1080 raeburn 6477: my $endbodytag;
6478: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6479: $endbodytag='</body>';
6480: }
1.315 albertel 6481: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6482: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6483: $endbodytag=
6484: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6485: &mt('Continue').'</a>'.
6486: $endbodytag;
6487: }
1.315 albertel 6488: }
1.251 albertel 6489: return $endbodytag;
6490: }
6491:
1.352 albertel 6492: =pod
6493:
6494: =item * &standard_css()
6495:
6496: Returns a style sheet
6497:
6498: Inputs: (all optional)
6499: domain -> force to color decorate a page for a specific
6500: domain
6501: function -> force usage of a specific rolish color scheme
6502: bgcolor -> override the default page bgcolor
6503:
6504: =cut
6505:
1.343 albertel 6506: sub standard_css {
1.345 albertel 6507: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6508: $function = &get_users_function() if (!$function);
6509: my $img = &designparm($function.'.img', $domain);
6510: my $tabbg = &designparm($function.'.tabbg', $domain);
6511: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6512: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6513: #second colour for later usage
1.345 albertel 6514: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6515: my $pgbg_or_bgcolor =
6516: $bgcolor ||
1.352 albertel 6517: &designparm($function.'.pgbg', $domain);
1.382 albertel 6518: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6519: my $alink = &designparm($function.'.alink', $domain);
6520: my $vlink = &designparm($function.'.vlink', $domain);
6521: my $link = &designparm($function.'.link', $domain);
6522:
1.602 albertel 6523: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6524: my $mono = 'monospace';
1.850 bisitz 6525: my $data_table_head = $sidebg;
6526: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6527: my $data_table_dark = '#E0E0E0';
1.470 banghart 6528: my $data_table_darker = '#CCCCCC';
1.349 albertel 6529: my $data_table_highlight = '#FFFF00';
1.352 albertel 6530: my $mail_new = '#FFBB77';
6531: my $mail_new_hover = '#DD9955';
6532: my $mail_read = '#BBBB77';
6533: my $mail_read_hover = '#999944';
6534: my $mail_replied = '#AAAA88';
6535: my $mail_replied_hover = '#888855';
6536: my $mail_other = '#99BBBB';
6537: my $mail_other_hover = '#669999';
1.391 albertel 6538: my $table_header = '#DDDDDD';
1.489 raeburn 6539: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6540: my $lg_border_color = '#C8C8C8';
1.952 onken 6541: my $button_hover = '#BF2317';
1.392 albertel 6542:
1.608 albertel 6543: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6544: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6545: : '0 3px 0 4px';
1.448 albertel 6546:
1.523 albertel 6547:
1.343 albertel 6548: return <<END;
1.947 droeschl 6549:
6550: /* needed for iframe to allow 100% height in FF */
6551: body, html {
6552: margin: 0;
6553: padding: 0 0.5%;
6554: height: 99%; /* to avoid scrollbars */
6555: }
6556:
1.795 www 6557: body {
1.911 bisitz 6558: font-family: $sans;
6559: line-height:130%;
6560: font-size:0.83em;
6561: color:$font;
1.795 www 6562: }
6563:
1.959 onken 6564: a:focus,
6565: a:focus img {
1.795 www 6566: color: red;
6567: }
1.698 harmsja 6568:
1.911 bisitz 6569: form, .inline {
6570: display: inline;
1.795 www 6571: }
1.721 harmsja 6572:
1.795 www 6573: .LC_right {
1.911 bisitz 6574: text-align:right;
1.795 www 6575: }
6576:
6577: .LC_middle {
1.911 bisitz 6578: vertical-align:middle;
1.795 www 6579: }
1.721 harmsja 6580:
1.1130 raeburn 6581: .LC_floatleft {
6582: float: left;
6583: }
6584:
6585: .LC_floatright {
6586: float: right;
6587: }
6588:
1.911 bisitz 6589: .LC_400Box {
6590: width:400px;
6591: }
1.721 harmsja 6592:
1.947 droeschl 6593: .LC_iframecontainer {
6594: width: 98%;
6595: margin: 0;
6596: position: fixed;
6597: top: 8.5em;
6598: bottom: 0;
6599: }
6600:
6601: .LC_iframecontainer iframe{
6602: border: none;
6603: width: 100%;
6604: height: 100%;
6605: }
6606:
1.778 bisitz 6607: .LC_filename {
6608: font-family: $mono;
6609: white-space:pre;
1.921 bisitz 6610: font-size: 120%;
1.778 bisitz 6611: }
6612:
6613: .LC_fileicon {
6614: border: none;
6615: height: 1.3em;
6616: vertical-align: text-bottom;
6617: margin-right: 0.3em;
6618: text-decoration:none;
6619: }
6620:
1.1008 www 6621: .LC_setting {
6622: text-decoration:underline;
6623: }
6624:
1.350 albertel 6625: .LC_error {
6626: color: red;
6627: }
1.795 www 6628:
1.1097 bisitz 6629: .LC_warning {
6630: color: darkorange;
6631: }
6632:
1.457 albertel 6633: .LC_diff_removed {
1.733 bisitz 6634: color: red;
1.394 albertel 6635: }
1.532 albertel 6636:
6637: .LC_info,
1.457 albertel 6638: .LC_success,
6639: .LC_diff_added {
1.350 albertel 6640: color: green;
6641: }
1.795 www 6642:
1.802 bisitz 6643: div.LC_confirm_box {
6644: background-color: #FAFAFA;
6645: border: 1px solid $lg_border_color;
6646: margin-right: 0;
6647: padding: 5px;
6648: }
6649:
6650: div.LC_confirm_box .LC_error img,
6651: div.LC_confirm_box .LC_success img {
6652: vertical-align: middle;
6653: }
6654:
1.1242 raeburn 6655: .LC_maxwidth {
6656: max-width: 100%;
6657: height: auto;
6658: }
6659:
1.1243 raeburn 6660: .LC_textsize_mobile {
6661: \@media only screen and (max-device-width: 480px) {
6662: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6663: }
6664: }
6665:
1.440 albertel 6666: .LC_icon {
1.771 droeschl 6667: border: none;
1.790 droeschl 6668: vertical-align: middle;
1.771 droeschl 6669: }
6670:
1.543 albertel 6671: .LC_docs_spacer {
6672: width: 25px;
6673: height: 1px;
1.771 droeschl 6674: border: none;
1.543 albertel 6675: }
1.346 albertel 6676:
1.532 albertel 6677: .LC_internal_info {
1.735 bisitz 6678: color: #999999;
1.532 albertel 6679: }
6680:
1.794 www 6681: .LC_discussion {
1.1050 www 6682: background: $data_table_dark;
1.911 bisitz 6683: border: 1px solid black;
6684: margin: 2px;
1.794 www 6685: }
6686:
6687: .LC_disc_action_left {
1.1050 www 6688: background: $sidebg;
1.911 bisitz 6689: text-align: left;
1.1050 www 6690: padding: 4px;
6691: margin: 2px;
1.794 www 6692: }
6693:
6694: .LC_disc_action_right {
1.1050 www 6695: background: $sidebg;
1.911 bisitz 6696: text-align: right;
1.1050 www 6697: padding: 4px;
6698: margin: 2px;
1.794 www 6699: }
6700:
6701: .LC_disc_new_item {
1.911 bisitz 6702: background: white;
6703: border: 2px solid red;
1.1050 www 6704: margin: 4px;
6705: padding: 4px;
1.794 www 6706: }
6707:
6708: .LC_disc_old_item {
1.911 bisitz 6709: background: white;
1.1050 www 6710: margin: 4px;
6711: padding: 4px;
1.794 www 6712: }
6713:
1.458 albertel 6714: table.LC_pastsubmission {
6715: border: 1px solid black;
6716: margin: 2px;
6717: }
6718:
1.924 bisitz 6719: table#LC_menubuttons {
1.345 albertel 6720: width: 100%;
6721: background: $pgbg;
1.392 albertel 6722: border: 2px;
1.402 albertel 6723: border-collapse: separate;
1.803 bisitz 6724: padding: 0;
1.345 albertel 6725: }
1.392 albertel 6726:
1.801 tempelho 6727: table#LC_title_bar a {
6728: color: $fontmenu;
6729: }
1.836 bisitz 6730:
1.807 droeschl 6731: table#LC_title_bar {
1.819 tempelho 6732: clear: both;
1.836 bisitz 6733: display: none;
1.807 droeschl 6734: }
6735:
1.795 www 6736: table#LC_title_bar,
1.933 droeschl 6737: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6738: table#LC_title_bar.LC_with_remote {
1.359 albertel 6739: width: 100%;
1.392 albertel 6740: border-color: $pgbg;
6741: border-style: solid;
6742: border-width: $border;
1.379 albertel 6743: background: $pgbg;
1.801 tempelho 6744: color: $fontmenu;
1.392 albertel 6745: border-collapse: collapse;
1.803 bisitz 6746: padding: 0;
1.819 tempelho 6747: margin: 0;
1.359 albertel 6748: }
1.795 www 6749:
1.933 droeschl 6750: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6751: margin: 0;
6752: padding: 0;
1.933 droeschl 6753: position: relative;
6754: list-style: none;
1.913 droeschl 6755: }
1.933 droeschl 6756: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6757: display: inline;
6758: }
1.933 droeschl 6759:
6760: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6761: padding: 0;
1.933 droeschl 6762: margin: 0;
6763: float: left;
1.913 droeschl 6764: }
1.933 droeschl 6765: .LC_breadcrumb_tools_tools {
6766: padding: 0;
6767: margin: 0;
1.913 droeschl 6768: float: right;
6769: }
6770:
1.1240 raeburn 6771: .LC_placement_prog {
6772: padding-right: 20px;
6773: font-weight: bold;
6774: font-size: 90%;
6775: }
6776:
1.359 albertel 6777: table#LC_title_bar td {
6778: background: $tabbg;
6779: }
1.795 www 6780:
1.911 bisitz 6781: table#LC_menubuttons img {
1.803 bisitz 6782: border: none;
1.346 albertel 6783: }
1.795 www 6784:
1.842 droeschl 6785: .LC_breadcrumbs_component {
1.911 bisitz 6786: float: right;
6787: margin: 0 1em;
1.357 albertel 6788: }
1.842 droeschl 6789: .LC_breadcrumbs_component img {
1.911 bisitz 6790: vertical-align: middle;
1.777 tempelho 6791: }
1.795 www 6792:
1.1243 raeburn 6793: .LC_breadcrumbs_hoverable {
6794: background: $sidebg;
6795: }
6796:
1.383 albertel 6797: td.LC_table_cell_checkbox {
6798: text-align: center;
6799: }
1.795 www 6800:
6801: .LC_fontsize_small {
1.911 bisitz 6802: font-size: 70%;
1.705 tempelho 6803: }
6804:
1.844 bisitz 6805: #LC_breadcrumbs {
1.911 bisitz 6806: clear:both;
6807: background: $sidebg;
6808: border-bottom: 1px solid $lg_border_color;
6809: line-height: 2.5em;
1.933 droeschl 6810: overflow: hidden;
1.911 bisitz 6811: margin: 0;
6812: padding: 0;
1.995 raeburn 6813: text-align: left;
1.819 tempelho 6814: }
1.862 bisitz 6815:
1.1098 bisitz 6816: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6817: clear:both;
6818: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6819: border: 1px solid $sidebg;
1.1098 bisitz 6820: margin: 0 0 10px 0;
1.966 bisitz 6821: padding: 3px;
1.995 raeburn 6822: text-align: left;
1.822 bisitz 6823: }
6824:
1.795 www 6825: .LC_fontsize_medium {
1.911 bisitz 6826: font-size: 85%;
1.705 tempelho 6827: }
6828:
1.795 www 6829: .LC_fontsize_large {
1.911 bisitz 6830: font-size: 120%;
1.705 tempelho 6831: }
6832:
1.346 albertel 6833: .LC_menubuttons_inline_text {
6834: color: $font;
1.698 harmsja 6835: font-size: 90%;
1.701 harmsja 6836: padding-left:3px;
1.346 albertel 6837: }
6838:
1.934 droeschl 6839: .LC_menubuttons_inline_text img{
6840: vertical-align: middle;
6841: }
6842:
1.1051 www 6843: li.LC_menubuttons_inline_text img {
1.951 onken 6844: cursor:pointer;
1.1002 droeschl 6845: text-decoration: none;
1.951 onken 6846: }
6847:
1.526 www 6848: .LC_menubuttons_link {
6849: text-decoration: none;
6850: }
1.795 www 6851:
1.522 albertel 6852: .LC_menubuttons_category {
1.521 www 6853: color: $font;
1.526 www 6854: background: $pgbg;
1.521 www 6855: font-size: larger;
6856: font-weight: bold;
6857: }
6858:
1.346 albertel 6859: td.LC_menubuttons_text {
1.911 bisitz 6860: color: $font;
1.346 albertel 6861: }
1.706 harmsja 6862:
1.346 albertel 6863: .LC_current_location {
6864: background: $tabbg;
6865: }
1.795 www 6866:
1.1286 raeburn 6867: td.LC_zero_height {
6868: line-height: 0;
6869: cellpadding: 0;
6870: }
6871:
1.938 bisitz 6872: table.LC_data_table {
1.347 albertel 6873: border: 1px solid #000000;
1.402 albertel 6874: border-collapse: separate;
1.426 albertel 6875: border-spacing: 1px;
1.610 albertel 6876: background: $pgbg;
1.347 albertel 6877: }
1.795 www 6878:
1.422 albertel 6879: .LC_data_table_dense {
6880: font-size: small;
6881: }
1.795 www 6882:
1.507 raeburn 6883: table.LC_nested_outer {
6884: border: 1px solid #000000;
1.589 raeburn 6885: border-collapse: collapse;
1.803 bisitz 6886: border-spacing: 0;
1.507 raeburn 6887: width: 100%;
6888: }
1.795 www 6889:
1.879 raeburn 6890: table.LC_innerpickbox,
1.507 raeburn 6891: table.LC_nested {
1.803 bisitz 6892: border: none;
1.589 raeburn 6893: border-collapse: collapse;
1.803 bisitz 6894: border-spacing: 0;
1.507 raeburn 6895: width: 100%;
6896: }
1.795 www 6897:
1.911 bisitz 6898: table.LC_data_table tr th,
6899: table.LC_calendar tr th,
1.879 raeburn 6900: table.LC_prior_tries tr th,
6901: table.LC_innerpickbox tr th {
1.349 albertel 6902: font-weight: bold;
6903: background-color: $data_table_head;
1.801 tempelho 6904: color:$fontmenu;
1.701 harmsja 6905: font-size:90%;
1.347 albertel 6906: }
1.795 www 6907:
1.879 raeburn 6908: table.LC_innerpickbox tr th,
6909: table.LC_innerpickbox tr td {
6910: vertical-align: top;
6911: }
6912:
1.711 raeburn 6913: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6914: background-color: #CCCCCC;
1.711 raeburn 6915: font-weight: bold;
6916: text-align: left;
6917: }
1.795 www 6918:
1.912 bisitz 6919: table.LC_data_table tr.LC_odd_row > td {
6920: background-color: $data_table_light;
6921: padding: 2px;
6922: vertical-align: top;
6923: }
6924:
1.809 bisitz 6925: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6926: background-color: $data_table_light;
1.912 bisitz 6927: vertical-align: top;
6928: }
6929:
6930: table.LC_data_table tr.LC_even_row > td {
6931: background-color: $data_table_dark;
1.425 albertel 6932: padding: 2px;
1.900 bisitz 6933: vertical-align: top;
1.347 albertel 6934: }
1.795 www 6935:
1.809 bisitz 6936: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6937: background-color: $data_table_dark;
1.900 bisitz 6938: vertical-align: top;
1.347 albertel 6939: }
1.795 www 6940:
1.425 albertel 6941: table.LC_data_table tr.LC_data_table_highlight td {
6942: background-color: $data_table_darker;
6943: }
1.795 www 6944:
1.639 raeburn 6945: table.LC_data_table tr td.LC_leftcol_header {
6946: background-color: $data_table_head;
6947: font-weight: bold;
6948: }
1.795 www 6949:
1.451 albertel 6950: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6951: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6952: font-weight: bold;
6953: font-style: italic;
6954: text-align: center;
6955: padding: 8px;
1.347 albertel 6956: }
1.795 www 6957:
1.1114 raeburn 6958: table.LC_data_table tr.LC_empty_row td,
6959: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6960: background-color: $sidebg;
6961: }
6962:
6963: table.LC_nested tr.LC_empty_row td {
6964: background-color: #FFFFFF;
6965: }
6966:
1.890 droeschl 6967: table.LC_caption {
6968: }
6969:
1.507 raeburn 6970: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6971: padding: 4ex
6972: }
1.795 www 6973:
1.507 raeburn 6974: table.LC_nested_outer tr th {
6975: font-weight: bold;
1.801 tempelho 6976: color:$fontmenu;
1.507 raeburn 6977: background-color: $data_table_head;
1.701 harmsja 6978: font-size: small;
1.507 raeburn 6979: border-bottom: 1px solid #000000;
6980: }
1.795 www 6981:
1.507 raeburn 6982: table.LC_nested_outer tr td.LC_subheader {
6983: background-color: $data_table_head;
6984: font-weight: bold;
6985: font-size: small;
6986: border-bottom: 1px solid #000000;
6987: text-align: right;
1.451 albertel 6988: }
1.795 www 6989:
1.507 raeburn 6990: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6991: background-color: #CCCCCC;
1.451 albertel 6992: font-weight: bold;
6993: font-size: small;
1.507 raeburn 6994: text-align: center;
6995: }
1.795 www 6996:
1.589 raeburn 6997: table.LC_nested tr.LC_info_row td.LC_left_item,
6998: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6999: text-align: left;
1.451 albertel 7000: }
1.795 www 7001:
1.507 raeburn 7002: table.LC_nested td {
1.735 bisitz 7003: background-color: #FFFFFF;
1.451 albertel 7004: font-size: small;
1.507 raeburn 7005: }
1.795 www 7006:
1.507 raeburn 7007: table.LC_nested_outer tr th.LC_right_item,
7008: table.LC_nested tr.LC_info_row td.LC_right_item,
7009: table.LC_nested tr.LC_odd_row td.LC_right_item,
7010: table.LC_nested tr td.LC_right_item {
1.451 albertel 7011: text-align: right;
7012: }
7013:
1.507 raeburn 7014: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7015: background-color: #EEEEEE;
1.451 albertel 7016: }
7017:
1.473 raeburn 7018: table.LC_createuser {
7019: }
7020:
7021: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7022: font-size: small;
1.473 raeburn 7023: }
7024:
7025: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7026: background-color: #CCCCCC;
1.473 raeburn 7027: font-weight: bold;
7028: text-align: center;
7029: }
7030:
1.349 albertel 7031: table.LC_calendar {
7032: border: 1px solid #000000;
7033: border-collapse: collapse;
1.917 raeburn 7034: width: 98%;
1.349 albertel 7035: }
1.795 www 7036:
1.349 albertel 7037: table.LC_calendar_pickdate {
7038: font-size: xx-small;
7039: }
1.795 www 7040:
1.349 albertel 7041: table.LC_calendar tr td {
7042: border: 1px solid #000000;
7043: vertical-align: top;
1.917 raeburn 7044: width: 14%;
1.349 albertel 7045: }
1.795 www 7046:
1.349 albertel 7047: table.LC_calendar tr td.LC_calendar_day_empty {
7048: background-color: $data_table_dark;
7049: }
1.795 www 7050:
1.779 bisitz 7051: table.LC_calendar tr td.LC_calendar_day_current {
7052: background-color: $data_table_highlight;
1.777 tempelho 7053: }
1.795 www 7054:
1.938 bisitz 7055: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7056: background-color: $mail_new;
7057: }
1.795 www 7058:
1.938 bisitz 7059: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7060: background-color: $mail_new_hover;
7061: }
1.795 www 7062:
1.938 bisitz 7063: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7064: background-color: $mail_read;
7065: }
1.795 www 7066:
1.938 bisitz 7067: /*
7068: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7069: background-color: $mail_read_hover;
7070: }
1.938 bisitz 7071: */
1.795 www 7072:
1.938 bisitz 7073: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7074: background-color: $mail_replied;
7075: }
1.795 www 7076:
1.938 bisitz 7077: /*
7078: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7079: background-color: $mail_replied_hover;
7080: }
1.938 bisitz 7081: */
1.795 www 7082:
1.938 bisitz 7083: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7084: background-color: $mail_other;
7085: }
1.795 www 7086:
1.938 bisitz 7087: /*
7088: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7089: background-color: $mail_other_hover;
7090: }
1.938 bisitz 7091: */
1.494 raeburn 7092:
1.777 tempelho 7093: table.LC_data_table tr > td.LC_browser_file,
7094: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7095: background: #AAEE77;
1.389 albertel 7096: }
1.795 www 7097:
1.777 tempelho 7098: table.LC_data_table tr > td.LC_browser_file_locked,
7099: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7100: background: #FFAA99;
1.387 albertel 7101: }
1.795 www 7102:
1.777 tempelho 7103: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7104: background: #888888;
1.779 bisitz 7105: }
1.795 www 7106:
1.777 tempelho 7107: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7108: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7109: background: #F8F866;
1.777 tempelho 7110: }
1.795 www 7111:
1.696 bisitz 7112: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7113: background: #E0E8FF;
1.387 albertel 7114: }
1.696 bisitz 7115:
1.707 bisitz 7116: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7117: /* background: #77FF77; */
1.707 bisitz 7118: }
1.795 www 7119:
1.707 bisitz 7120: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7121: border-right: 8px solid #FFFF77;
1.707 bisitz 7122: }
1.795 www 7123:
1.707 bisitz 7124: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7125: border-right: 8px solid #FFAA77;
1.707 bisitz 7126: }
1.795 www 7127:
1.707 bisitz 7128: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7129: border-right: 8px solid #FF7777;
1.707 bisitz 7130: }
1.795 www 7131:
1.707 bisitz 7132: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7133: border-right: 8px solid #AAFF77;
1.707 bisitz 7134: }
1.795 www 7135:
1.707 bisitz 7136: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7137: border-right: 8px solid #11CC55;
1.707 bisitz 7138: }
7139:
1.388 albertel 7140: span.LC_current_location {
1.701 harmsja 7141: font-size:larger;
1.388 albertel 7142: background: $pgbg;
7143: }
1.387 albertel 7144:
1.1029 www 7145: span.LC_current_nav_location {
7146: font-weight:bold;
7147: background: $sidebg;
7148: }
7149:
1.395 albertel 7150: span.LC_parm_menu_item {
7151: font-size: larger;
7152: }
1.795 www 7153:
1.395 albertel 7154: span.LC_parm_scope_all {
7155: color: red;
7156: }
1.795 www 7157:
1.395 albertel 7158: span.LC_parm_scope_folder {
7159: color: green;
7160: }
1.795 www 7161:
1.395 albertel 7162: span.LC_parm_scope_resource {
7163: color: orange;
7164: }
1.795 www 7165:
1.395 albertel 7166: span.LC_parm_part {
7167: color: blue;
7168: }
1.795 www 7169:
1.911 bisitz 7170: span.LC_parm_folder,
7171: span.LC_parm_symb {
1.395 albertel 7172: font-size: x-small;
7173: font-family: $mono;
7174: color: #AAAAAA;
7175: }
7176:
1.977 bisitz 7177: ul.LC_parm_parmlist li {
7178: display: inline-block;
7179: padding: 0.3em 0.8em;
7180: vertical-align: top;
7181: width: 150px;
7182: border-top:1px solid $lg_border_color;
7183: }
7184:
1.795 www 7185: td.LC_parm_overview_level_menu,
7186: td.LC_parm_overview_map_menu,
7187: td.LC_parm_overview_parm_selectors,
7188: td.LC_parm_overview_restrictions {
1.396 albertel 7189: border: 1px solid black;
7190: border-collapse: collapse;
7191: }
1.795 www 7192:
1.1285 raeburn 7193: span.LC_parm_recursive,
7194: td.LC_parm_recursive {
7195: font-weight: bold;
7196: font-size: smaller;
7197: }
7198:
1.396 albertel 7199: table.LC_parm_overview_restrictions td {
7200: border-width: 1px 4px 1px 4px;
7201: border-style: solid;
7202: border-color: $pgbg;
7203: text-align: center;
7204: }
1.795 www 7205:
1.396 albertel 7206: table.LC_parm_overview_restrictions th {
7207: background: $tabbg;
7208: border-width: 1px 4px 1px 4px;
7209: border-style: solid;
7210: border-color: $pgbg;
7211: }
1.795 www 7212:
1.398 albertel 7213: table#LC_helpmenu {
1.803 bisitz 7214: border: none;
1.398 albertel 7215: height: 55px;
1.803 bisitz 7216: border-spacing: 0;
1.398 albertel 7217: }
7218:
7219: table#LC_helpmenu fieldset legend {
7220: font-size: larger;
7221: }
1.795 www 7222:
1.397 albertel 7223: table#LC_helpmenu_links {
7224: width: 100%;
7225: border: 1px solid black;
7226: background: $pgbg;
1.803 bisitz 7227: padding: 0;
1.397 albertel 7228: border-spacing: 1px;
7229: }
1.795 www 7230:
1.397 albertel 7231: table#LC_helpmenu_links tr td {
7232: padding: 1px;
7233: background: $tabbg;
1.399 albertel 7234: text-align: center;
7235: font-weight: bold;
1.397 albertel 7236: }
1.396 albertel 7237:
1.795 www 7238: table#LC_helpmenu_links a:link,
7239: table#LC_helpmenu_links a:visited,
1.397 albertel 7240: table#LC_helpmenu_links a:active {
7241: text-decoration: none;
7242: color: $font;
7243: }
1.795 www 7244:
1.397 albertel 7245: table#LC_helpmenu_links a:hover {
7246: text-decoration: underline;
7247: color: $vlink;
7248: }
1.396 albertel 7249:
1.417 albertel 7250: .LC_chrt_popup_exists {
7251: border: 1px solid #339933;
7252: margin: -1px;
7253: }
1.795 www 7254:
1.417 albertel 7255: .LC_chrt_popup_up {
7256: border: 1px solid yellow;
7257: margin: -1px;
7258: }
1.795 www 7259:
1.417 albertel 7260: .LC_chrt_popup {
7261: border: 1px solid #8888FF;
7262: background: #CCCCFF;
7263: }
1.795 www 7264:
1.421 albertel 7265: table.LC_pick_box {
7266: border-collapse: separate;
7267: background: white;
7268: border: 1px solid black;
7269: border-spacing: 1px;
7270: }
1.795 www 7271:
1.421 albertel 7272: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7273: background: $sidebg;
1.421 albertel 7274: font-weight: bold;
1.900 bisitz 7275: text-align: left;
1.740 bisitz 7276: vertical-align: top;
1.421 albertel 7277: width: 184px;
7278: padding: 8px;
7279: }
1.795 www 7280:
1.579 raeburn 7281: table.LC_pick_box td.LC_pick_box_value {
7282: text-align: left;
7283: padding: 8px;
7284: }
1.795 www 7285:
1.579 raeburn 7286: table.LC_pick_box td.LC_pick_box_select {
7287: text-align: left;
7288: padding: 8px;
7289: }
1.795 www 7290:
1.424 albertel 7291: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7292: padding: 0;
1.421 albertel 7293: height: 1px;
7294: background: black;
7295: }
1.795 www 7296:
1.421 albertel 7297: table.LC_pick_box td.LC_pick_box_submit {
7298: text-align: right;
7299: }
1.795 www 7300:
1.579 raeburn 7301: table.LC_pick_box td.LC_evenrow_value {
7302: text-align: left;
7303: padding: 8px;
7304: background-color: $data_table_light;
7305: }
1.795 www 7306:
1.579 raeburn 7307: table.LC_pick_box td.LC_oddrow_value {
7308: text-align: left;
7309: padding: 8px;
7310: background-color: $data_table_light;
7311: }
1.795 www 7312:
1.579 raeburn 7313: span.LC_helpform_receipt_cat {
7314: font-weight: bold;
7315: }
1.795 www 7316:
1.424 albertel 7317: table.LC_group_priv_box {
7318: background: white;
7319: border: 1px solid black;
7320: border-spacing: 1px;
7321: }
1.795 www 7322:
1.424 albertel 7323: table.LC_group_priv_box td.LC_pick_box_title {
7324: background: $tabbg;
7325: font-weight: bold;
7326: text-align: right;
7327: width: 184px;
7328: }
1.795 www 7329:
1.424 albertel 7330: table.LC_group_priv_box td.LC_groups_fixed {
7331: background: $data_table_light;
7332: text-align: center;
7333: }
1.795 www 7334:
1.424 albertel 7335: table.LC_group_priv_box td.LC_groups_optional {
7336: background: $data_table_dark;
7337: text-align: center;
7338: }
1.795 www 7339:
1.424 albertel 7340: table.LC_group_priv_box td.LC_groups_functionality {
7341: background: $data_table_darker;
7342: text-align: center;
7343: font-weight: bold;
7344: }
1.795 www 7345:
1.424 albertel 7346: table.LC_group_priv td {
7347: text-align: left;
1.803 bisitz 7348: padding: 0;
1.424 albertel 7349: }
7350:
7351: .LC_navbuttons {
7352: margin: 2ex 0ex 2ex 0ex;
7353: }
1.795 www 7354:
1.423 albertel 7355: .LC_topic_bar {
7356: font-weight: bold;
7357: background: $tabbg;
1.918 wenzelju 7358: margin: 1em 0em 1em 2em;
1.805 bisitz 7359: padding: 3px;
1.918 wenzelju 7360: font-size: 1.2em;
1.423 albertel 7361: }
1.795 www 7362:
1.423 albertel 7363: .LC_topic_bar span {
1.918 wenzelju 7364: left: 0.5em;
7365: position: absolute;
1.423 albertel 7366: vertical-align: middle;
1.918 wenzelju 7367: font-size: 1.2em;
1.423 albertel 7368: }
1.795 www 7369:
1.423 albertel 7370: table.LC_course_group_status {
7371: margin: 20px;
7372: }
1.795 www 7373:
1.423 albertel 7374: table.LC_status_selector td {
7375: vertical-align: top;
7376: text-align: center;
1.424 albertel 7377: padding: 4px;
7378: }
1.795 www 7379:
1.599 albertel 7380: div.LC_feedback_link {
1.616 albertel 7381: clear: both;
1.829 kalberla 7382: background: $sidebg;
1.779 bisitz 7383: width: 100%;
1.829 kalberla 7384: padding-bottom: 10px;
7385: border: 1px $tabbg solid;
1.833 kalberla 7386: height: 22px;
7387: line-height: 22px;
7388: padding-top: 5px;
7389: }
7390:
7391: div.LC_feedback_link img {
7392: height: 22px;
1.867 kalberla 7393: vertical-align:middle;
1.829 kalberla 7394: }
7395:
1.911 bisitz 7396: div.LC_feedback_link a {
1.829 kalberla 7397: text-decoration: none;
1.489 raeburn 7398: }
1.795 www 7399:
1.867 kalberla 7400: div.LC_comblock {
1.911 bisitz 7401: display:inline;
1.867 kalberla 7402: color:$font;
7403: font-size:90%;
7404: }
7405:
7406: div.LC_feedback_link div.LC_comblock {
7407: padding-left:5px;
7408: }
7409:
7410: div.LC_feedback_link div.LC_comblock a {
7411: color:$font;
7412: }
7413:
1.489 raeburn 7414: span.LC_feedback_link {
1.858 bisitz 7415: /* background: $feedback_link_bg; */
1.599 albertel 7416: font-size: larger;
7417: }
1.795 www 7418:
1.599 albertel 7419: span.LC_message_link {
1.858 bisitz 7420: /* background: $feedback_link_bg; */
1.599 albertel 7421: font-size: larger;
7422: position: absolute;
7423: right: 1em;
1.489 raeburn 7424: }
1.421 albertel 7425:
1.515 albertel 7426: table.LC_prior_tries {
1.524 albertel 7427: border: 1px solid #000000;
7428: border-collapse: separate;
7429: border-spacing: 1px;
1.515 albertel 7430: }
1.523 albertel 7431:
1.515 albertel 7432: table.LC_prior_tries td {
1.524 albertel 7433: padding: 2px;
1.515 albertel 7434: }
1.523 albertel 7435:
7436: .LC_answer_correct {
1.795 www 7437: background: lightgreen;
7438: color: darkgreen;
7439: padding: 6px;
1.523 albertel 7440: }
1.795 www 7441:
1.523 albertel 7442: .LC_answer_charged_try {
1.797 www 7443: background: #FFAAAA;
1.795 www 7444: color: darkred;
7445: padding: 6px;
1.523 albertel 7446: }
1.795 www 7447:
1.779 bisitz 7448: .LC_answer_not_charged_try,
1.523 albertel 7449: .LC_answer_no_grade,
7450: .LC_answer_late {
1.795 www 7451: background: lightyellow;
1.523 albertel 7452: color: black;
1.795 www 7453: padding: 6px;
1.523 albertel 7454: }
1.795 www 7455:
1.523 albertel 7456: .LC_answer_previous {
1.795 www 7457: background: lightblue;
7458: color: darkblue;
7459: padding: 6px;
1.523 albertel 7460: }
1.795 www 7461:
1.779 bisitz 7462: .LC_answer_no_message {
1.777 tempelho 7463: background: #FFFFFF;
7464: color: black;
1.795 www 7465: padding: 6px;
1.779 bisitz 7466: }
1.795 www 7467:
1.1334 raeburn 7468: .LC_answer_unknown,
7469: .LC_answer_warning {
1.779 bisitz 7470: background: orange;
7471: color: black;
1.795 www 7472: padding: 6px;
1.777 tempelho 7473: }
1.795 www 7474:
1.529 albertel 7475: span.LC_prior_numerical,
7476: span.LC_prior_string,
7477: span.LC_prior_custom,
7478: span.LC_prior_reaction,
7479: span.LC_prior_math {
1.925 bisitz 7480: font-family: $mono;
1.523 albertel 7481: white-space: pre;
7482: }
7483:
1.525 albertel 7484: span.LC_prior_string {
1.925 bisitz 7485: font-family: $mono;
1.525 albertel 7486: white-space: pre;
7487: }
7488:
1.523 albertel 7489: table.LC_prior_option {
7490: width: 100%;
7491: border-collapse: collapse;
7492: }
1.795 www 7493:
1.911 bisitz 7494: table.LC_prior_rank,
1.795 www 7495: table.LC_prior_match {
1.528 albertel 7496: border-collapse: collapse;
7497: }
1.795 www 7498:
1.528 albertel 7499: table.LC_prior_option tr td,
7500: table.LC_prior_rank tr td,
7501: table.LC_prior_match tr td {
1.524 albertel 7502: border: 1px solid #000000;
1.515 albertel 7503: }
7504:
1.855 bisitz 7505: .LC_nobreak {
1.544 albertel 7506: white-space: nowrap;
1.519 raeburn 7507: }
7508:
1.576 raeburn 7509: span.LC_cusr_emph {
7510: font-style: italic;
7511: }
7512:
1.633 raeburn 7513: span.LC_cusr_subheading {
7514: font-weight: normal;
7515: font-size: 85%;
7516: }
7517:
1.861 bisitz 7518: div.LC_docs_entry_move {
1.859 bisitz 7519: border: 1px solid #BBBBBB;
1.545 albertel 7520: background: #DDDDDD;
1.861 bisitz 7521: width: 22px;
1.859 bisitz 7522: padding: 1px;
7523: margin: 0;
1.545 albertel 7524: }
7525:
1.861 bisitz 7526: table.LC_data_table tr > td.LC_docs_entry_commands,
7527: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7528: font-size: x-small;
7529: }
1.795 www 7530:
1.861 bisitz 7531: .LC_docs_entry_parameter {
7532: white-space: nowrap;
7533: }
7534:
1.544 albertel 7535: .LC_docs_copy {
1.545 albertel 7536: color: #000099;
1.544 albertel 7537: }
1.795 www 7538:
1.544 albertel 7539: .LC_docs_cut {
1.545 albertel 7540: color: #550044;
1.544 albertel 7541: }
1.795 www 7542:
1.544 albertel 7543: .LC_docs_rename {
1.545 albertel 7544: color: #009900;
1.544 albertel 7545: }
1.795 www 7546:
1.544 albertel 7547: .LC_docs_remove {
1.545 albertel 7548: color: #990000;
7549: }
7550:
1.1284 raeburn 7551: .LC_docs_alias {
7552: color: #440055;
7553: }
7554:
1.1286 raeburn 7555: .LC_domprefs_email,
1.1284 raeburn 7556: .LC_docs_alias_name,
1.547 albertel 7557: .LC_docs_reinit_warn,
7558: .LC_docs_ext_edit {
7559: font-size: x-small;
7560: }
7561:
1.545 albertel 7562: table.LC_docs_adddocs td,
7563: table.LC_docs_adddocs th {
7564: border: 1px solid #BBBBBB;
7565: padding: 4px;
7566: background: #DDDDDD;
1.543 albertel 7567: }
7568:
1.584 albertel 7569: table.LC_sty_begin {
7570: background: #BBFFBB;
7571: }
1.795 www 7572:
1.584 albertel 7573: table.LC_sty_end {
7574: background: #FFBBBB;
7575: }
7576:
1.589 raeburn 7577: table.LC_double_column {
1.803 bisitz 7578: border-width: 0;
1.589 raeburn 7579: border-collapse: collapse;
7580: width: 100%;
7581: padding: 2px;
7582: }
7583:
7584: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7585: top: 2px;
1.589 raeburn 7586: left: 2px;
7587: width: 47%;
7588: vertical-align: top;
7589: }
7590:
7591: table.LC_double_column tr td.LC_right_col {
7592: top: 2px;
1.779 bisitz 7593: right: 2px;
1.589 raeburn 7594: width: 47%;
7595: vertical-align: top;
7596: }
7597:
1.591 raeburn 7598: div.LC_left_float {
7599: float: left;
7600: padding-right: 5%;
1.597 albertel 7601: padding-bottom: 4px;
1.591 raeburn 7602: }
7603:
7604: div.LC_clear_float_header {
1.597 albertel 7605: padding-bottom: 2px;
1.591 raeburn 7606: }
7607:
7608: div.LC_clear_float_footer {
1.597 albertel 7609: padding-top: 10px;
1.591 raeburn 7610: clear: both;
7611: }
7612:
1.597 albertel 7613: div.LC_grade_show_user {
1.941 bisitz 7614: /* border-left: 5px solid $sidebg; */
7615: border-top: 5px solid #000000;
7616: margin: 50px 0 0 0;
1.936 bisitz 7617: padding: 15px 0 5px 10px;
1.597 albertel 7618: }
1.795 www 7619:
1.936 bisitz 7620: div.LC_grade_show_user_odd_row {
1.941 bisitz 7621: /* border-left: 5px solid #000000; */
7622: }
7623:
7624: div.LC_grade_show_user div.LC_Box {
7625: margin-right: 50px;
1.597 albertel 7626: }
7627:
7628: div.LC_grade_submissions,
7629: div.LC_grade_message_center,
1.936 bisitz 7630: div.LC_grade_info_links {
1.597 albertel 7631: margin: 5px;
7632: width: 99%;
7633: background: #FFFFFF;
7634: }
1.795 www 7635:
1.597 albertel 7636: div.LC_grade_submissions_header,
1.936 bisitz 7637: div.LC_grade_message_center_header {
1.705 tempelho 7638: font-weight: bold;
7639: font-size: large;
1.597 albertel 7640: }
1.795 www 7641:
1.597 albertel 7642: div.LC_grade_submissions_body,
1.936 bisitz 7643: div.LC_grade_message_center_body {
1.597 albertel 7644: border: 1px solid black;
7645: width: 99%;
7646: background: #FFFFFF;
7647: }
1.795 www 7648:
1.613 albertel 7649: table.LC_scantron_action {
7650: width: 100%;
7651: }
1.795 www 7652:
1.613 albertel 7653: table.LC_scantron_action tr th {
1.698 harmsja 7654: font-weight:bold;
7655: font-style:normal;
1.613 albertel 7656: }
1.795 www 7657:
1.779 bisitz 7658: .LC_edit_problem_header,
1.614 albertel 7659: div.LC_edit_problem_footer {
1.705 tempelho 7660: font-weight: normal;
7661: font-size: medium;
1.602 albertel 7662: margin: 2px;
1.1060 bisitz 7663: background-color: $sidebg;
1.600 albertel 7664: }
1.795 www 7665:
1.600 albertel 7666: div.LC_edit_problem_header,
1.602 albertel 7667: div.LC_edit_problem_header div,
1.614 albertel 7668: div.LC_edit_problem_footer,
7669: div.LC_edit_problem_footer div,
1.602 albertel 7670: div.LC_edit_problem_editxml_header,
7671: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7672: z-index: 100;
1.600 albertel 7673: }
1.795 www 7674:
1.600 albertel 7675: div.LC_edit_problem_header_title {
1.705 tempelho 7676: font-weight: bold;
7677: font-size: larger;
1.602 albertel 7678: background: $tabbg;
7679: padding: 3px;
1.1060 bisitz 7680: margin: 0 0 5px 0;
1.602 albertel 7681: }
1.795 www 7682:
1.602 albertel 7683: table.LC_edit_problem_header_title {
7684: width: 100%;
1.600 albertel 7685: background: $tabbg;
1.602 albertel 7686: }
7687:
1.1205 golterma 7688: div.LC_edit_actionbar {
7689: background-color: $sidebg;
1.1218 droeschl 7690: margin: 0;
7691: padding: 0;
7692: line-height: 200%;
1.602 albertel 7693: }
1.795 www 7694:
1.1218 droeschl 7695: div.LC_edit_actionbar div{
7696: padding: 0;
7697: margin: 0;
7698: display: inline-block;
1.600 albertel 7699: }
1.795 www 7700:
1.1124 bisitz 7701: .LC_edit_opt {
7702: padding-left: 1em;
7703: white-space: nowrap;
7704: }
7705:
1.1152 golterma 7706: .LC_edit_problem_latexhelper{
7707: text-align: right;
7708: }
7709:
7710: #LC_edit_problem_colorful div{
7711: margin-left: 40px;
7712: }
7713:
1.1205 golterma 7714: #LC_edit_problem_codemirror div{
7715: margin-left: 0px;
7716: }
7717:
1.911 bisitz 7718: img.stift {
1.803 bisitz 7719: border-width: 0;
7720: vertical-align: middle;
1.677 riegler 7721: }
1.680 riegler 7722:
1.923 bisitz 7723: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7724: vertical-align: top;
1.777 tempelho 7725: }
1.795 www 7726:
1.716 raeburn 7727: div.LC_createcourse {
1.911 bisitz 7728: margin: 10px 10px 10px 10px;
1.716 raeburn 7729: }
7730:
1.917 raeburn 7731: .LC_dccid {
1.1130 raeburn 7732: float: right;
1.917 raeburn 7733: margin: 0.2em 0 0 0;
7734: padding: 0;
7735: font-size: 90%;
7736: display:none;
7737: }
7738:
1.897 wenzelju 7739: ol.LC_primary_menu a:hover,
1.721 harmsja 7740: ol#LC_MenuBreadcrumbs a:hover,
7741: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7742: ul#LC_secondary_menu a:hover,
1.721 harmsja 7743: .LC_FormSectionClearButton input:hover
1.795 www 7744: ul.LC_TabContent li:hover a {
1.952 onken 7745: color:$button_hover;
1.911 bisitz 7746: text-decoration:none;
1.693 droeschl 7747: }
7748:
1.779 bisitz 7749: h1 {
1.911 bisitz 7750: padding: 0;
7751: line-height:130%;
1.693 droeschl 7752: }
1.698 harmsja 7753:
1.911 bisitz 7754: h2,
7755: h3,
7756: h4,
7757: h5,
7758: h6 {
7759: margin: 5px 0 5px 0;
7760: padding: 0;
7761: line-height:130%;
1.693 droeschl 7762: }
1.795 www 7763:
7764: .LC_hcell {
1.911 bisitz 7765: padding:3px 15px 3px 15px;
7766: margin: 0;
7767: background-color:$tabbg;
7768: color:$fontmenu;
7769: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7770: }
1.795 www 7771:
1.840 bisitz 7772: .LC_Box > .LC_hcell {
1.911 bisitz 7773: margin: 0 -10px 10px -10px;
1.835 bisitz 7774: }
7775:
1.721 harmsja 7776: .LC_noBorder {
1.911 bisitz 7777: border: 0;
1.698 harmsja 7778: }
1.693 droeschl 7779:
1.721 harmsja 7780: .LC_FormSectionClearButton input {
1.911 bisitz 7781: background-color:transparent;
7782: border: none;
7783: cursor:pointer;
7784: text-decoration:underline;
1.693 droeschl 7785: }
1.763 bisitz 7786:
7787: .LC_help_open_topic {
1.911 bisitz 7788: color: #FFFFFF;
7789: background-color: #EEEEFF;
7790: margin: 1px;
7791: padding: 4px;
7792: border: 1px solid #000033;
7793: white-space: nowrap;
7794: /* vertical-align: middle; */
1.759 neumanie 7795: }
1.693 droeschl 7796:
1.911 bisitz 7797: dl,
7798: ul,
7799: div,
7800: fieldset {
7801: margin: 10px 10px 10px 0;
7802: /* overflow: hidden; */
1.693 droeschl 7803: }
1.795 www 7804:
1.1211 raeburn 7805: article.geogebraweb div {
7806: margin: 0;
7807: }
7808:
1.838 bisitz 7809: fieldset > legend {
1.911 bisitz 7810: font-weight: bold;
7811: padding: 0 5px 0 5px;
1.838 bisitz 7812: }
7813:
1.813 bisitz 7814: #LC_nav_bar {
1.911 bisitz 7815: float: left;
1.995 raeburn 7816: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7817: margin: 0 0 2px 0;
1.807 droeschl 7818: }
7819:
1.916 droeschl 7820: #LC_realm {
7821: margin: 0.2em 0 0 0;
7822: padding: 0;
7823: font-weight: bold;
7824: text-align: center;
1.995 raeburn 7825: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7826: }
7827:
1.911 bisitz 7828: #LC_nav_bar em {
7829: font-weight: bold;
7830: font-style: normal;
1.807 droeschl 7831: }
7832:
1.897 wenzelju 7833: ol.LC_primary_menu {
1.934 droeschl 7834: margin: 0;
1.1076 raeburn 7835: padding: 0;
1.807 droeschl 7836: }
7837:
1.852 droeschl 7838: ol#LC_PathBreadcrumbs {
1.911 bisitz 7839: margin: 0;
1.693 droeschl 7840: }
7841:
1.897 wenzelju 7842: ol.LC_primary_menu li {
1.1076 raeburn 7843: color: RGB(80, 80, 80);
7844: vertical-align: middle;
7845: text-align: left;
7846: list-style: none;
1.1205 golterma 7847: position: relative;
1.1076 raeburn 7848: float: left;
1.1205 golterma 7849: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7850: line-height: 1.5em;
1.1076 raeburn 7851: }
7852:
1.1205 golterma 7853: ol.LC_primary_menu li a,
7854: ol.LC_primary_menu li p {
1.1076 raeburn 7855: display: block;
7856: margin: 0;
7857: padding: 0 5px 0 10px;
7858: text-decoration: none;
7859: }
7860:
1.1205 golterma 7861: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7862: display: inline-block;
7863: width: 95%;
7864: text-align: left;
7865: }
7866:
7867: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7868: display: inline-block;
7869: width: 5%;
7870: float: right;
7871: text-align: right;
7872: font-size: 70%;
7873: }
7874:
7875: ol.LC_primary_menu ul {
1.1076 raeburn 7876: display: none;
1.1205 golterma 7877: width: 15em;
1.1076 raeburn 7878: background-color: $data_table_light;
1.1205 golterma 7879: position: absolute;
7880: top: 100%;
1.1076 raeburn 7881: }
7882:
1.1205 golterma 7883: ol.LC_primary_menu ul ul {
7884: left: 100%;
7885: top: 0;
7886: }
7887:
7888: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7889: display: block;
7890: position: absolute;
7891: margin: 0;
7892: padding: 0;
1.1078 raeburn 7893: z-index: 2;
1.1076 raeburn 7894: }
7895:
7896: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7897: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7898: font-size: 90%;
1.911 bisitz 7899: vertical-align: top;
1.1076 raeburn 7900: float: none;
1.1079 raeburn 7901: border-left: 1px solid black;
7902: border-right: 1px solid black;
1.1205 golterma 7903: /* A dark bottom border to visualize different menu options;
7904: overwritten in the create_submenu routine for the last border-bottom of the menu */
7905: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7906: }
7907:
1.1205 golterma 7908: ol.LC_primary_menu li li p:hover {
7909: color:$button_hover;
7910: text-decoration:none;
7911: background-color:$data_table_dark;
1.1076 raeburn 7912: }
7913:
7914: ol.LC_primary_menu li li a:hover {
7915: color:$button_hover;
7916: background-color:$data_table_dark;
1.693 droeschl 7917: }
7918:
1.1205 golterma 7919: /* Font-size equal to the size of the predecessors*/
7920: ol.LC_primary_menu li:hover li li {
7921: font-size: 100%;
7922: }
7923:
1.897 wenzelju 7924: ol.LC_primary_menu li img {
1.911 bisitz 7925: vertical-align: bottom;
1.934 droeschl 7926: height: 1.1em;
1.1077 raeburn 7927: margin: 0.2em 0 0 0;
1.693 droeschl 7928: }
7929:
1.897 wenzelju 7930: ol.LC_primary_menu a {
1.911 bisitz 7931: color: RGB(80, 80, 80);
7932: text-decoration: none;
1.693 droeschl 7933: }
1.795 www 7934:
1.949 droeschl 7935: ol.LC_primary_menu a.LC_new_message {
7936: font-weight:bold;
7937: color: darkred;
7938: }
7939:
1.975 raeburn 7940: ol.LC_docs_parameters {
7941: margin-left: 0;
7942: padding: 0;
7943: list-style: none;
7944: }
7945:
7946: ol.LC_docs_parameters li {
7947: margin: 0;
7948: padding-right: 20px;
7949: display: inline;
7950: }
7951:
1.976 raeburn 7952: ol.LC_docs_parameters li:before {
7953: content: "\\002022 \\0020";
7954: }
7955:
7956: li.LC_docs_parameters_title {
7957: font-weight: bold;
7958: }
7959:
7960: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7961: content: "";
7962: }
7963:
1.897 wenzelju 7964: ul#LC_secondary_menu {
1.1107 raeburn 7965: clear: right;
1.911 bisitz 7966: color: $fontmenu;
7967: background: $tabbg;
7968: list-style: none;
7969: padding: 0;
7970: margin: 0;
7971: width: 100%;
1.995 raeburn 7972: text-align: left;
1.1107 raeburn 7973: float: left;
1.808 droeschl 7974: }
7975:
1.897 wenzelju 7976: ul#LC_secondary_menu li {
1.911 bisitz 7977: font-weight: bold;
7978: line-height: 1.8em;
1.1107 raeburn 7979: border-right: 1px solid black;
7980: float: left;
7981: }
7982:
7983: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7984: background-color: $data_table_light;
7985: }
7986:
7987: ul#LC_secondary_menu li a {
1.911 bisitz 7988: padding: 0 0.8em;
1.1107 raeburn 7989: }
7990:
7991: ul#LC_secondary_menu li ul {
7992: display: none;
7993: }
7994:
7995: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7996: display: block;
7997: position: absolute;
7998: margin: 0;
7999: padding: 0;
8000: list-style:none;
8001: float: none;
8002: background-color: $data_table_light;
8003: z-index: 2;
8004: margin-left: -1px;
8005: }
8006:
8007: ul#LC_secondary_menu li ul li {
8008: font-size: 90%;
8009: vertical-align: top;
8010: border-left: 1px solid black;
1.911 bisitz 8011: border-right: 1px solid black;
1.1119 raeburn 8012: background-color: $data_table_light;
1.1107 raeburn 8013: list-style:none;
8014: float: none;
8015: }
8016:
8017: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8018: background-color: $data_table_dark;
1.807 droeschl 8019: }
8020:
1.847 tempelho 8021: ul.LC_TabContent {
1.911 bisitz 8022: display:block;
8023: background: $sidebg;
8024: border-bottom: solid 1px $lg_border_color;
8025: list-style:none;
1.1020 raeburn 8026: margin: -1px -10px 0 -10px;
1.911 bisitz 8027: padding: 0;
1.693 droeschl 8028: }
8029:
1.795 www 8030: ul.LC_TabContent li,
8031: ul.LC_TabContentBigger li {
1.911 bisitz 8032: float:left;
1.741 harmsja 8033: }
1.795 www 8034:
1.897 wenzelju 8035: ul#LC_secondary_menu li a {
1.911 bisitz 8036: color: $fontmenu;
8037: text-decoration: none;
1.693 droeschl 8038: }
1.795 www 8039:
1.721 harmsja 8040: ul.LC_TabContent {
1.952 onken 8041: min-height:20px;
1.721 harmsja 8042: }
1.795 www 8043:
8044: ul.LC_TabContent li {
1.911 bisitz 8045: vertical-align:middle;
1.959 onken 8046: padding: 0 16px 0 10px;
1.911 bisitz 8047: background-color:$tabbg;
8048: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8049: border-left: solid 1px $font;
1.721 harmsja 8050: }
1.795 www 8051:
1.847 tempelho 8052: ul.LC_TabContent .right {
1.911 bisitz 8053: float:right;
1.847 tempelho 8054: }
8055:
1.911 bisitz 8056: ul.LC_TabContent li a,
8057: ul.LC_TabContent li {
8058: color:rgb(47,47,47);
8059: text-decoration:none;
8060: font-size:95%;
8061: font-weight:bold;
1.952 onken 8062: min-height:20px;
8063: }
8064:
1.959 onken 8065: ul.LC_TabContent li a:hover,
8066: ul.LC_TabContent li a:focus {
1.952 onken 8067: color: $button_hover;
1.959 onken 8068: background:none;
8069: outline:none;
1.952 onken 8070: }
8071:
8072: ul.LC_TabContent li:hover {
8073: color: $button_hover;
8074: cursor:pointer;
1.721 harmsja 8075: }
1.795 www 8076:
1.911 bisitz 8077: ul.LC_TabContent li.active {
1.952 onken 8078: color: $font;
1.911 bisitz 8079: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8080: border-bottom:solid 1px #FFFFFF;
8081: cursor: default;
1.744 ehlerst 8082: }
1.795 www 8083:
1.959 onken 8084: ul.LC_TabContent li.active a {
8085: color:$font;
8086: background:#FFFFFF;
8087: outline: none;
8088: }
1.1047 raeburn 8089:
8090: ul.LC_TabContent li.goback {
8091: float: left;
8092: border-left: none;
8093: }
8094:
1.870 tempelho 8095: #maincoursedoc {
1.911 bisitz 8096: clear:both;
1.870 tempelho 8097: }
8098:
8099: ul.LC_TabContentBigger {
1.911 bisitz 8100: display:block;
8101: list-style:none;
8102: padding: 0;
1.870 tempelho 8103: }
8104:
1.795 www 8105: ul.LC_TabContentBigger li {
1.911 bisitz 8106: vertical-align:bottom;
8107: height: 30px;
8108: font-size:110%;
8109: font-weight:bold;
8110: color: #737373;
1.841 tempelho 8111: }
8112:
1.957 onken 8113: ul.LC_TabContentBigger li.active {
8114: position: relative;
8115: top: 1px;
8116: }
8117:
1.870 tempelho 8118: ul.LC_TabContentBigger li a {
1.911 bisitz 8119: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8120: height: 30px;
8121: line-height: 30px;
8122: text-align: center;
8123: display: block;
8124: text-decoration: none;
1.958 onken 8125: outline: none;
1.741 harmsja 8126: }
1.795 www 8127:
1.870 tempelho 8128: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8129: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8130: color:$font;
1.744 ehlerst 8131: }
1.795 www 8132:
1.870 tempelho 8133: ul.LC_TabContentBigger li b {
1.911 bisitz 8134: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8135: display: block;
8136: float: left;
8137: padding: 0 30px;
1.957 onken 8138: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8139: }
8140:
1.956 onken 8141: ul.LC_TabContentBigger li:hover b {
8142: color:$button_hover;
8143: }
8144:
1.870 tempelho 8145: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8146: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8147: color:$font;
1.957 onken 8148: border: 0;
1.741 harmsja 8149: }
1.693 droeschl 8150:
1.870 tempelho 8151:
1.862 bisitz 8152: ul.LC_CourseBreadcrumbs {
8153: background: $sidebg;
1.1020 raeburn 8154: height: 2em;
1.862 bisitz 8155: padding-left: 10px;
1.1020 raeburn 8156: margin: 0;
1.862 bisitz 8157: list-style-position: inside;
8158: }
8159:
1.911 bisitz 8160: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8161: ol#LC_PathBreadcrumbs {
1.911 bisitz 8162: padding-left: 10px;
8163: margin: 0;
1.933 droeschl 8164: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8165: }
8166:
1.911 bisitz 8167: ol#LC_MenuBreadcrumbs li,
8168: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8169: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8170: display: inline;
1.933 droeschl 8171: white-space: normal;
1.693 droeschl 8172: }
8173:
1.823 bisitz 8174: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8175: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8176: text-decoration: none;
8177: font-size:90%;
1.693 droeschl 8178: }
1.795 www 8179:
1.969 droeschl 8180: ol#LC_MenuBreadcrumbs h1 {
8181: display: inline;
8182: font-size: 90%;
8183: line-height: 2.5em;
8184: margin: 0;
8185: padding: 0;
8186: }
8187:
1.795 www 8188: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8189: text-decoration:none;
8190: font-size:100%;
8191: font-weight:bold;
1.693 droeschl 8192: }
1.795 www 8193:
1.840 bisitz 8194: .LC_Box {
1.911 bisitz 8195: border: solid 1px $lg_border_color;
8196: padding: 0 10px 10px 10px;
1.746 neumanie 8197: }
1.795 www 8198:
1.1020 raeburn 8199: .LC_DocsBox {
8200: border: solid 1px $lg_border_color;
8201: padding: 0 0 10px 10px;
8202: }
8203:
1.795 www 8204: .LC_AboutMe_Image {
1.911 bisitz 8205: float:left;
8206: margin-right:10px;
1.747 neumanie 8207: }
1.795 www 8208:
8209: .LC_Clear_AboutMe_Image {
1.911 bisitz 8210: clear:left;
1.747 neumanie 8211: }
1.795 www 8212:
1.721 harmsja 8213: dl.LC_ListStyleClean dt {
1.911 bisitz 8214: padding-right: 5px;
8215: display: table-header-group;
1.693 droeschl 8216: }
8217:
1.721 harmsja 8218: dl.LC_ListStyleClean dd {
1.911 bisitz 8219: display: table-row;
1.693 droeschl 8220: }
8221:
1.721 harmsja 8222: .LC_ListStyleClean,
8223: .LC_ListStyleSimple,
8224: .LC_ListStyleNormal,
1.795 www 8225: .LC_ListStyleSpecial {
1.911 bisitz 8226: /* display:block; */
8227: list-style-position: inside;
8228: list-style-type: none;
8229: overflow: hidden;
8230: padding: 0;
1.693 droeschl 8231: }
8232:
1.721 harmsja 8233: .LC_ListStyleSimple li,
8234: .LC_ListStyleSimple dd,
8235: .LC_ListStyleNormal li,
8236: .LC_ListStyleNormal dd,
8237: .LC_ListStyleSpecial li,
1.795 www 8238: .LC_ListStyleSpecial dd {
1.911 bisitz 8239: margin: 0;
8240: padding: 5px 5px 5px 10px;
8241: clear: both;
1.693 droeschl 8242: }
8243:
1.721 harmsja 8244: .LC_ListStyleClean li,
8245: .LC_ListStyleClean dd {
1.911 bisitz 8246: padding-top: 0;
8247: padding-bottom: 0;
1.693 droeschl 8248: }
8249:
1.721 harmsja 8250: .LC_ListStyleSimple dd,
1.795 www 8251: .LC_ListStyleSimple li {
1.911 bisitz 8252: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8253: }
8254:
1.721 harmsja 8255: .LC_ListStyleSpecial li,
8256: .LC_ListStyleSpecial dd {
1.911 bisitz 8257: list-style-type: none;
8258: background-color: RGB(220, 220, 220);
8259: margin-bottom: 4px;
1.693 droeschl 8260: }
8261:
1.721 harmsja 8262: table.LC_SimpleTable {
1.911 bisitz 8263: margin:5px;
8264: border:solid 1px $lg_border_color;
1.795 www 8265: }
1.693 droeschl 8266:
1.721 harmsja 8267: table.LC_SimpleTable tr {
1.911 bisitz 8268: padding: 0;
8269: border:solid 1px $lg_border_color;
1.693 droeschl 8270: }
1.795 www 8271:
8272: table.LC_SimpleTable thead {
1.911 bisitz 8273: background:rgb(220,220,220);
1.693 droeschl 8274: }
8275:
1.721 harmsja 8276: div.LC_columnSection {
1.911 bisitz 8277: display: block;
8278: clear: both;
8279: overflow: hidden;
8280: margin: 0;
1.693 droeschl 8281: }
8282:
1.721 harmsja 8283: div.LC_columnSection>* {
1.911 bisitz 8284: float: left;
8285: margin: 10px 20px 10px 0;
8286: overflow:hidden;
1.693 droeschl 8287: }
1.721 harmsja 8288:
1.795 www 8289: table em {
1.911 bisitz 8290: font-weight: bold;
8291: font-style: normal;
1.748 schulted 8292: }
1.795 www 8293:
1.779 bisitz 8294: table.LC_tableBrowseRes,
1.795 www 8295: table.LC_tableOfContent {
1.911 bisitz 8296: border:none;
8297: border-spacing: 1px;
8298: padding: 3px;
8299: background-color: #FFFFFF;
8300: font-size: 90%;
1.753 droeschl 8301: }
1.789 droeschl 8302:
1.911 bisitz 8303: table.LC_tableOfContent {
8304: border-collapse: collapse;
1.789 droeschl 8305: }
8306:
1.771 droeschl 8307: table.LC_tableBrowseRes a,
1.768 schulted 8308: table.LC_tableOfContent a {
1.911 bisitz 8309: background-color: transparent;
8310: text-decoration: none;
1.753 droeschl 8311: }
8312:
1.795 www 8313: table.LC_tableOfContent img {
1.911 bisitz 8314: border: none;
8315: height: 1.3em;
8316: vertical-align: text-bottom;
8317: margin-right: 0.3em;
1.753 droeschl 8318: }
1.757 schulted 8319:
1.795 www 8320: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8321: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8322: }
8323:
1.795 www 8324: a#LC_content_toolbar_everything {
1.911 bisitz 8325: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8326: }
8327:
1.795 www 8328: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8329: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8330: }
8331:
1.795 www 8332: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8333: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8334: }
8335:
1.795 www 8336: a#LC_content_toolbar_changefolder {
1.911 bisitz 8337: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8338: }
8339:
1.795 www 8340: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8341: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8342: }
8343:
1.1043 raeburn 8344: a#LC_content_toolbar_edittoplevel {
8345: background-image:url(/res/adm/pages/edittoplevel.gif);
8346: }
8347:
1.795 www 8348: ul#LC_toolbar li a:hover {
1.911 bisitz 8349: background-position: bottom center;
1.757 schulted 8350: }
8351:
1.795 www 8352: ul#LC_toolbar {
1.911 bisitz 8353: padding: 0;
8354: margin: 2px;
8355: list-style:none;
8356: position:relative;
8357: background-color:white;
1.1082 raeburn 8358: overflow: auto;
1.757 schulted 8359: }
8360:
1.795 www 8361: ul#LC_toolbar li {
1.911 bisitz 8362: border:1px solid white;
8363: padding: 0;
8364: margin: 0;
8365: float: left;
8366: display:inline;
8367: vertical-align:middle;
1.1082 raeburn 8368: white-space: nowrap;
1.911 bisitz 8369: }
1.757 schulted 8370:
1.783 amueller 8371:
1.795 www 8372: a.LC_toolbarItem {
1.911 bisitz 8373: display:block;
8374: padding: 0;
8375: margin: 0;
8376: height: 32px;
8377: width: 32px;
8378: color:white;
8379: border: none;
8380: background-repeat:no-repeat;
8381: background-color:transparent;
1.757 schulted 8382: }
8383:
1.915 droeschl 8384: ul.LC_funclist {
8385: margin: 0;
8386: padding: 0.5em 1em 0.5em 0;
8387: }
8388:
1.933 droeschl 8389: ul.LC_funclist > li:first-child {
8390: font-weight:bold;
8391: margin-left:0.8em;
8392: }
8393:
1.915 droeschl 8394: ul.LC_funclist + ul.LC_funclist {
8395: /*
8396: left border as a seperator if we have more than
8397: one list
8398: */
8399: border-left: 1px solid $sidebg;
8400: /*
8401: this hides the left border behind the border of the
8402: outer box if element is wrapped to the next 'line'
8403: */
8404: margin-left: -1px;
8405: }
8406:
1.843 bisitz 8407: ul.LC_funclist li {
1.915 droeschl 8408: display: inline;
1.782 bisitz 8409: white-space: nowrap;
1.915 droeschl 8410: margin: 0 0 0 25px;
8411: line-height: 150%;
1.782 bisitz 8412: }
8413:
1.974 wenzelju 8414: .LC_hidden {
8415: display: none;
8416: }
8417:
1.1030 www 8418: .LCmodal-overlay {
8419: position:fixed;
8420: top:0;
8421: right:0;
8422: bottom:0;
8423: left:0;
8424: height:100%;
8425: width:100%;
8426: margin:0;
8427: padding:0;
8428: background:#999;
8429: opacity:.75;
8430: filter: alpha(opacity=75);
8431: -moz-opacity: 0.75;
8432: z-index:101;
8433: }
8434:
8435: * html .LCmodal-overlay {
8436: position: absolute;
8437: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8438: }
8439:
8440: .LCmodal-window {
8441: position:fixed;
8442: top:50%;
8443: left:50%;
8444: margin:0;
8445: padding:0;
8446: z-index:102;
8447: }
8448:
8449: * html .LCmodal-window {
8450: position:absolute;
8451: }
8452:
8453: .LCclose-window {
8454: position:absolute;
8455: width:32px;
8456: height:32px;
8457: right:8px;
8458: top:8px;
8459: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8460: text-indent:-99999px;
8461: overflow:hidden;
8462: cursor:pointer;
8463: }
8464:
1.1369 raeburn 8465: .LCisDisabled {
8466: cursor: not-allowed;
8467: opacity: 0.5;
8468: }
8469:
8470: a[aria-disabled="true"] {
8471: color: currentColor;
8472: display: inline-block; /* For IE11/ MS Edge bug */
8473: pointer-events: none;
8474: text-decoration: none;
8475: }
8476:
1.1335 raeburn 8477: pre.LC_wordwrap {
8478: white-space: pre-wrap;
8479: white-space: -moz-pre-wrap;
8480: white-space: -pre-wrap;
8481: white-space: -o-pre-wrap;
8482: word-wrap: break-word;
8483: }
8484:
1.1100 raeburn 8485: /*
1.1231 damieng 8486: styles used for response display
8487: */
8488: div.LC_radiofoil, div.LC_rankfoil {
8489: margin: .5em 0em .5em 0em;
8490: }
8491: table.LC_itemgroup {
8492: margin-top: 1em;
8493: }
8494:
8495: /*
1.1100 raeburn 8496: styles used by TTH when "Default set of options to pass to tth/m
8497: when converting TeX" in course settings has been set
8498:
8499: option passed: -t
8500:
8501: */
8502:
8503: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8504: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8505: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8506: td div.norm {line-height:normal;}
8507:
8508: /*
8509: option passed -y3
8510: */
8511:
8512: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8513: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8514: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8515:
1.1230 damieng 8516: /*
8517: sections with roles, for content only
8518: */
8519: section[class^="role-"] {
8520: padding-left: 10px;
8521: padding-right: 5px;
8522: margin-top: 8px;
8523: margin-bottom: 8px;
8524: border: 1px solid #2A4;
8525: border-radius: 5px;
8526: box-shadow: 0px 1px 1px #BBB;
8527: }
8528: section[class^="role-"]>h1 {
8529: position: relative;
8530: margin: 0px;
8531: padding-top: 10px;
8532: padding-left: 40px;
8533: }
8534: section[class^="role-"]>h1:before {
8535: position: absolute;
8536: left: -5px;
8537: top: 5px;
8538: }
8539: section.role-activity>h1:before {
8540: content:url('/adm/daxe/images/section_icons/activity.png');
8541: }
8542: section.role-advice>h1:before {
8543: content:url('/adm/daxe/images/section_icons/advice.png');
8544: }
8545: section.role-bibliography>h1:before {
8546: content:url('/adm/daxe/images/section_icons/bibliography.png');
8547: }
8548: section.role-citation>h1:before {
8549: content:url('/adm/daxe/images/section_icons/citation.png');
8550: }
8551: section.role-conclusion>h1:before {
8552: content:url('/adm/daxe/images/section_icons/conclusion.png');
8553: }
8554: section.role-definition>h1:before {
8555: content:url('/adm/daxe/images/section_icons/definition.png');
8556: }
8557: section.role-demonstration>h1:before {
8558: content:url('/adm/daxe/images/section_icons/demonstration.png');
8559: }
8560: section.role-example>h1:before {
8561: content:url('/adm/daxe/images/section_icons/example.png');
8562: }
8563: section.role-explanation>h1:before {
8564: content:url('/adm/daxe/images/section_icons/explanation.png');
8565: }
8566: section.role-introduction>h1:before {
8567: content:url('/adm/daxe/images/section_icons/introduction.png');
8568: }
8569: section.role-method>h1:before {
8570: content:url('/adm/daxe/images/section_icons/method.png');
8571: }
8572: section.role-more_information>h1:before {
8573: content:url('/adm/daxe/images/section_icons/more_information.png');
8574: }
8575: section.role-objectives>h1:before {
8576: content:url('/adm/daxe/images/section_icons/objectives.png');
8577: }
8578: section.role-prerequisites>h1:before {
8579: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8580: }
8581: section.role-remark>h1:before {
8582: content:url('/adm/daxe/images/section_icons/remark.png');
8583: }
8584: section.role-reminder>h1:before {
8585: content:url('/adm/daxe/images/section_icons/reminder.png');
8586: }
8587: section.role-summary>h1:before {
8588: content:url('/adm/daxe/images/section_icons/summary.png');
8589: }
8590: section.role-syntax>h1:before {
8591: content:url('/adm/daxe/images/section_icons/syntax.png');
8592: }
8593: section.role-warning>h1:before {
8594: content:url('/adm/daxe/images/section_icons/warning.png');
8595: }
8596:
1.1269 raeburn 8597: #LC_minitab_header {
8598: float:left;
8599: width:100%;
8600: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8601: font-size:93%;
8602: line-height:normal;
8603: margin: 0.5em 0 0.5em 0;
8604: }
8605: #LC_minitab_header ul {
8606: margin:0;
8607: padding:10px 10px 0;
8608: list-style:none;
8609: }
8610: #LC_minitab_header li {
8611: float:left;
8612: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8613: margin:0;
8614: padding:0 0 0 9px;
8615: }
8616: #LC_minitab_header a {
8617: display:block;
8618: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8619: padding:5px 15px 4px 6px;
8620: }
8621: #LC_minitab_header #LC_current_minitab {
8622: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8623: }
8624: #LC_minitab_header #LC_current_minitab a {
8625: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8626: padding-bottom:5px;
8627: }
8628:
8629:
1.343 albertel 8630: END
8631: }
8632:
1.306 albertel 8633: =pod
8634:
8635: =item * &headtag()
8636:
8637: Returns a uniform footer for LON-CAPA web pages.
8638:
1.307 albertel 8639: Inputs: $title - optional title for the head
8640: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8641: $args - optional arguments
1.319 albertel 8642: force_register - if is true call registerurl so the remote is
8643: informed
1.415 albertel 8644: redirect -> array ref of
8645: 1- seconds before redirect occurs
8646: 2- url to redirect to
8647: 3- whether the side effect should occur
1.315 albertel 8648: (side effect of setting
8649: $env{'internal.head.redirect'} to the url
8650: redirected too)
1.352 albertel 8651: domain -> force to color decorate a page for a specific
8652: domain
8653: function -> force usage of a specific rolish color scheme
8654: bgcolor -> override the default page bgcolor
1.460 albertel 8655: no_auto_mt_title
8656: -> prevent &mt()ing the title arg
1.464 albertel 8657:
1.306 albertel 8658: =cut
8659:
8660: sub headtag {
1.313 albertel 8661: my ($title,$head_extra,$args) = @_;
1.306 albertel 8662:
1.363 albertel 8663: my $function = $args->{'function'} || &get_users_function();
8664: my $domain = $args->{'domain'} || &determinedomain();
8665: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8666: my $httphost = $args->{'use_absolute'};
1.418 albertel 8667: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8668: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8669: #time(),
1.418 albertel 8670: $env{'environment.color.timestamp'},
1.363 albertel 8671: $function,$domain,$bgcolor);
8672:
1.369 www 8673: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8674:
1.308 albertel 8675: my $result =
8676: '<head>'.
1.1160 raeburn 8677: &font_settings($args);
1.319 albertel 8678:
1.1188 raeburn 8679: my $inhibitprint;
8680: if ($args->{'print_suppress'}) {
8681: $inhibitprint = &print_suppression();
8682: }
1.1064 raeburn 8683:
1.461 albertel 8684: if (!$args->{'frameset'}) {
8685: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8686: }
1.962 droeschl 8687: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8688: $result .= Apache::lonxml::display_title();
1.319 albertel 8689: }
1.436 albertel 8690: if (!$args->{'no_nav_bar'}
8691: && !$args->{'only_body'}
8692: && !$args->{'frameset'}) {
1.1154 raeburn 8693: $result .= &help_menu_js($httphost);
1.1032 www 8694: $result.=&modal_window();
1.1038 www 8695: $result.=&togglebox_script();
1.1034 www 8696: $result.=&wishlist_window();
1.1041 www 8697: $result.=&LCprogressbarUpdate_script();
1.1034 www 8698: } else {
8699: if ($args->{'add_modal'}) {
8700: $result.=&modal_window();
8701: }
8702: if ($args->{'add_wishlist'}) {
8703: $result.=&wishlist_window();
8704: }
1.1038 www 8705: if ($args->{'add_togglebox'}) {
8706: $result.=&togglebox_script();
8707: }
1.1041 www 8708: if ($args->{'add_progressbar'}) {
8709: $result.=&LCprogressbarUpdate_script();
8710: }
1.436 albertel 8711: }
1.314 albertel 8712: if (ref($args->{'redirect'})) {
1.414 albertel 8713: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8714: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8715: if (!$inhibit_continue) {
8716: $env{'internal.head.redirect'} = $url;
8717: }
1.313 albertel 8718: $result.=<<ADDMETA
8719: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8720: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8721: ADDMETA
1.1210 raeburn 8722: } else {
8723: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8724: my $requrl = $env{'request.uri'};
8725: if ($requrl eq '') {
8726: $requrl = $ENV{'REQUEST_URI'};
8727: $requrl =~ s/\?.+$//;
8728: }
8729: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8730: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8731: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8732: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8733: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8734: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8735: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8736: my ($offload,$offloadoth);
1.1210 raeburn 8737: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8738: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8739: $offload = 1;
1.1353 raeburn 8740: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8741: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8742: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8743: $offloadoth = 1;
8744: $dom_in_use = $env{'user.domain'};
8745: }
8746: }
1.1340 raeburn 8747: }
8748: }
8749: unless ($offload) {
8750: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8751: if ($domdefs{'offloadoth'}{$lonhost}) {
8752: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8753: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8754: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8755: $offload = 1;
1.1352 raeburn 8756: $offloadoth = 1;
1.1340 raeburn 8757: $dom_in_use = $env{'user.domain'};
8758: }
1.1210 raeburn 8759: }
1.1340 raeburn 8760: }
8761: }
8762: }
8763: if ($offload) {
1.1358 raeburn 8764: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 8765: if (($newserver eq '') && ($offloadoth)) {
8766: my @domains = &Apache::lonnet::current_machine_domains();
8767: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8768: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8769: }
8770: }
1.1340 raeburn 8771: if (($newserver) && ($newserver ne $lonhost)) {
8772: my $numsec = 5;
8773: my $timeout = $numsec * 1000;
8774: my ($newurl,$locknum,%locks,$msg);
8775: if ($env{'request.role.adv'}) {
8776: ($locknum,%locks) = &Apache::lonnet::get_locks();
8777: }
8778: my $disable_submit = 0;
8779: if ($requrl =~ /$LONCAPA::assess_re/) {
8780: $disable_submit = 1;
8781: }
8782: if ($locknum) {
8783: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8784: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8785: join(", ",sort(values(%locks)))."\n";
8786: if (&show_course()) {
8787: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8788: } else {
8789: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8790: }
1.1340 raeburn 8791: } else {
8792: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8793: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8794: }
8795: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8796: $newurl = '/adm/switchserver?otherserver='.$newserver;
8797: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8798: $newurl .= '&role='.$env{'request.role'};
8799: }
8800: if ($env{'request.symb'}) {
8801: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8802: if ($shownsymb =~ m{^/enc/}) {
8803: my $reqdmajor = 2;
8804: my $reqdminor = 11;
8805: my $reqdsubminor = 3;
8806: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8807: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8808: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8809: if (($major eq '' && $minor eq '') ||
8810: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8811: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8812: ($reqdsubminor > $subminor))))) {
8813: undef($shownsymb);
8814: }
1.1210 raeburn 8815: }
1.1340 raeburn 8816: if ($shownsymb) {
8817: &js_escape(\$shownsymb);
8818: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8819: }
1.1340 raeburn 8820: } else {
8821: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8822: &js_escape(\$shownurl);
8823: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8824: }
1.1340 raeburn 8825: }
8826: &js_escape(\$msg);
8827: $result.=<<OFFLOAD
1.1210 raeburn 8828: <meta http-equiv="pragma" content="no-cache" />
8829: <script type="text/javascript">
1.1215 raeburn 8830: // <![CDATA[
1.1210 raeburn 8831: function LC_Offload_Now() {
8832: var dest = "$newurl";
8833: if (dest != '') {
8834: window.location.href="$newurl";
8835: }
8836: }
1.1214 raeburn 8837: \$(document).ready(function () {
8838: window.alert('$msg');
8839: if ($disable_submit) {
1.1210 raeburn 8840: \$(".LC_hwk_submit").prop("disabled", true);
8841: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8842: }
8843: setTimeout('LC_Offload_Now()', $timeout);
8844: });
1.1215 raeburn 8845: // ]]>
1.1210 raeburn 8846: </script>
8847: OFFLOAD
8848: }
8849: }
8850: }
8851: }
8852: }
1.313 albertel 8853: }
1.306 albertel 8854: if (!defined($title)) {
8855: $title = 'The LearningOnline Network with CAPA';
8856: }
1.460 albertel 8857: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8858: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8859: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8860: if (!$args->{'frameset'}) {
8861: $result .= ' /';
8862: }
8863: $result .= '>'
1.1064 raeburn 8864: .$inhibitprint
1.414 albertel 8865: .$head_extra;
1.1242 raeburn 8866: my $clientmobile;
8867: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8868: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8869: } else {
8870: $clientmobile = $env{'browser.mobile'};
8871: }
8872: if ($clientmobile) {
1.1137 raeburn 8873: $result .= '
8874: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8875: <meta name="apple-mobile-web-app-capable" content="yes" />';
8876: }
1.1278 raeburn 8877: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8878: return $result.'</head>';
1.306 albertel 8879: }
8880:
8881: =pod
8882:
1.340 albertel 8883: =item * &font_settings()
8884:
8885: Returns neccessary <meta> to set the proper encoding
8886:
1.1160 raeburn 8887: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8888:
8889: =cut
8890:
8891: sub font_settings {
1.1160 raeburn 8892: my ($args) = @_;
1.340 albertel 8893: my $headerstring='';
1.1160 raeburn 8894: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8895: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8896: $headerstring.=
8897: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8898: if (!$args->{'frameset'}) {
8899: $headerstring.= ' /';
8900: }
8901: $headerstring .= '>'."\n";
1.340 albertel 8902: }
8903: return $headerstring;
8904: }
8905:
1.341 albertel 8906: =pod
8907:
1.1064 raeburn 8908: =item * &print_suppression()
8909:
8910: In course context returns css which causes the body to be blank when media="print",
8911: if printout generation is unavailable for the current resource.
8912:
8913: This could be because:
8914:
8915: (a) printstartdate is in the future
8916:
8917: (b) printenddate is in the past
8918:
8919: (c) there is an active exam block with "printout"
8920: functionality blocked
8921:
8922: Users with pav, pfo or evb privileges are exempt.
8923:
8924: Inputs: none
8925:
8926: =cut
8927:
8928:
8929: sub print_suppression {
8930: my $noprint;
8931: if ($env{'request.course.id'}) {
8932: my $scope = $env{'request.course.id'};
8933: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8934: (&Apache::lonnet::allowed('pfo',$scope))) {
8935: return;
8936: }
8937: if ($env{'request.course.sec'} ne '') {
8938: $scope .= "/$env{'request.course.sec'}";
8939: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8940: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8941: return;
1.1064 raeburn 8942: }
8943: }
8944: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8945: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 8946: my $clientip = &Apache::lonnet::get_requestor_ip();
8947: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8948: if ($blocked) {
8949: my $checkrole = "cm./$cdom/$cnum";
8950: if ($env{'request.course.sec'} ne '') {
8951: $checkrole .= "/$env{'request.course.sec'}";
8952: }
8953: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8954: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8955: $noprint = 1;
8956: }
8957: }
8958: unless ($noprint) {
8959: my $symb = &Apache::lonnet::symbread();
8960: if ($symb ne '') {
8961: my $navmap = Apache::lonnavmaps::navmap->new();
8962: if (ref($navmap)) {
8963: my $res = $navmap->getBySymb($symb);
8964: if (ref($res)) {
8965: if (!$res->resprintable()) {
8966: $noprint = 1;
8967: }
8968: }
8969: }
8970: }
8971: }
8972: if ($noprint) {
8973: return <<"ENDSTYLE";
8974: <style type="text/css" media="print">
8975: body { display:none }
8976: </style>
8977: ENDSTYLE
8978: }
8979: }
8980: return;
8981: }
8982:
8983: =pod
8984:
1.341 albertel 8985: =item * &xml_begin()
8986:
8987: Returns the needed doctype and <html>
8988:
8989: Inputs: none
8990:
8991: =cut
8992:
8993: sub xml_begin {
1.1168 raeburn 8994: my ($is_frameset) = @_;
1.341 albertel 8995: my $output='';
8996:
8997: if ($env{'browser.mathml'}) {
8998: $output='<?xml version="1.0"?>'
8999: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9000: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9001:
9002: # .'<!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">] >'
9003: .'<!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">'
9004: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9005: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9006: } elsif ($is_frameset) {
9007: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9008: '<html>'."\n";
1.341 albertel 9009: } else {
1.1168 raeburn 9010: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9011: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9012: }
9013: return $output;
9014: }
1.340 albertel 9015:
9016: =pod
9017:
1.306 albertel 9018: =item * &start_page()
9019:
9020: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9021:
1.648 raeburn 9022: Inputs:
9023:
9024: =over 4
9025:
9026: $title - optional title for the page
9027:
9028: $head_extra - optional extra HTML to incude inside the <head>
9029:
9030: $args - additional optional args supported are:
9031:
9032: =over 8
9033:
9034: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9035: arg on
1.814 bisitz 9036: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9037: add_entries -> additional attributes to add to the <body>
9038: domain -> force to color decorate a page for a
1.317 albertel 9039: specific domain
1.648 raeburn 9040: function -> force usage of a specific rolish color
1.317 albertel 9041: scheme
1.648 raeburn 9042: redirect -> see &headtag()
9043: bgcolor -> override the default page bg color
9044: js_ready -> return a string ready for being used in
1.317 albertel 9045: a javascript writeln
1.648 raeburn 9046: html_encode -> return a string ready for being used in
1.320 albertel 9047: a html attribute
1.648 raeburn 9048: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9049: $forcereg arg
1.648 raeburn 9050: frameset -> if true will start with a <frameset>
1.330 albertel 9051: rather than <body>
1.648 raeburn 9052: skip_phases -> hash ref of
1.338 albertel 9053: head -> skip the <html><head> generation
9054: body -> skip all <body> generation
1.648 raeburn 9055: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9056: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9057: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9058: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9059: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9060: group -> includes the current group, if page is for a
1.1274 raeburn 9061: specific group
9062: use_absolute -> for request for external resource or syllabus, this
9063: will contain https://<hostname> if server uses
9064: https (as per hosts.tab), but request is for http
9065: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9066: links_disabled -> Links in primary and secondary menus are disabled
9067: (Can enable them once page has loaded - see lonroles.pm
9068: for an example).
1.361 albertel 9069:
1.648 raeburn 9070: =back
1.460 albertel 9071:
1.648 raeburn 9072: =back
1.562 albertel 9073:
1.306 albertel 9074: =cut
9075:
9076: sub start_page {
1.309 albertel 9077: my ($title,$head_extra,$args) = @_;
1.318 albertel 9078: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9079:
1.315 albertel 9080: $env{'internal.start_page'}++;
1.1359 raeburn 9081: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9082:
1.338 albertel 9083: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9084: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9085: }
1.1316 raeburn 9086:
9087: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9088: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9089: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9090: $args->{'no_primary_menu'} = 1;
9091: }
9092: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9093: $args->{'no_inline_menu'} = 1;
9094: }
9095: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9096: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9097: }
9098: } else {
9099: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9100: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9101: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9102: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9103: $args->{'no_primary_menu'} = 1;
9104: }
9105: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9106: $args->{'no_inline_menu'} = 1;
9107: }
9108: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9109: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9110: }
9111: }
9112: }
1.1316 raeburn 9113: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9114: $env{'course.'.$env{'request.course.id'}.'.domain'},
9115: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9116: } elsif ($env{'request.course.id'}) {
9117: my $expiretime=600;
9118: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9119: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9120: }
9121: my ($deeplinkmenu,$menuref);
9122: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9123: if ($menucoll) {
9124: if (ref($menuref) eq 'HASH') {
9125: %menu = %{$menuref};
9126: }
9127: if ($menu{'top'} eq 'n') {
9128: $args->{'no_primary_menu'} = 1;
9129: }
9130: if ($menu{'inline'} eq 'n') {
9131: unless (&Apache::lonnet::allowed('opa')) {
9132: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9133: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9134: my $crstype = &course_type();
9135: my $now = time;
9136: my $ccrole;
9137: if ($crstype eq 'Community') {
9138: $ccrole = 'co';
9139: } else {
9140: $ccrole = 'cc';
9141: }
9142: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9143: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9144: if ((($start) && ($start<0)) ||
9145: (($end) && ($end<$now)) ||
9146: (($start) && ($now<$start))) {
9147: $args->{'no_inline_menu'} = 1;
9148: }
9149: } else {
9150: $args->{'no_inline_menu'} = 1;
9151: }
9152: }
9153: }
9154: }
1.1316 raeburn 9155: }
1.1359 raeburn 9156:
1.338 albertel 9157: if (! exists($args->{'skip_phases'}{'body'}) ) {
9158: if ($args->{'frameset'}) {
9159: my $attr_string = &make_attr_string($args->{'force_register'},
9160: $args->{'add_entries'});
9161: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9162: } else {
9163: $result .=
9164: &bodytag($title,
9165: $args->{'function'}, $args->{'add_entries'},
9166: $args->{'only_body'}, $args->{'domain'},
9167: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9168: $args->{'bgcolor'}, $args,
1.1359 raeburn 9169: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu);
1.831 bisitz 9170: }
1.330 albertel 9171: }
1.338 albertel 9172:
1.315 albertel 9173: if ($args->{'js_ready'}) {
1.713 kaisler 9174: $result = &js_ready($result);
1.315 albertel 9175: }
1.320 albertel 9176: if ($args->{'html_encode'}) {
1.713 kaisler 9177: $result = &html_encode($result);
9178: }
9179:
1.813 bisitz 9180: # Preparation for new and consistent functionlist at top of screen
9181: # if ($args->{'functionlist'}) {
9182: # $result .= &build_functionlist();
9183: #}
9184:
1.964 droeschl 9185: # Don't add anything more if only_body wanted or in const space
9186: return $result if $args->{'only_body'}
9187: || $env{'request.state'} eq 'construct';
1.813 bisitz 9188:
9189: #Breadcrumbs
1.758 kaisler 9190: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9191: &Apache::lonhtmlcommon::clear_breadcrumbs();
9192: #if any br links exists, add them to the breadcrumbs
9193: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9194: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9195: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9196: }
9197: }
1.1096 raeburn 9198: # if @advtools array contains items add then to the breadcrumbs
9199: if (@advtools > 0) {
9200: &Apache::lonmenu::advtools_crumbs(@advtools);
9201: }
1.1272 raeburn 9202: my $menulink;
9203: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9204: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9205: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9206: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9207: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9208: (!$env{'request.role.adv'}))) {
9209: $menulink = 0;
9210: } else {
9211: undef($menulink);
9212: }
1.758 kaisler 9213: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9214: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9215: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9216: } else {
1.1272 raeburn 9217: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9218: }
1.320 albertel 9219: }
1.315 albertel 9220: return $result;
1.306 albertel 9221: }
9222:
9223: sub end_page {
1.315 albertel 9224: my ($args) = @_;
9225: $env{'internal.end_page'}++;
1.330 albertel 9226: my $result;
1.335 albertel 9227: if ($args->{'discussion'}) {
9228: my ($target,$parser);
9229: if (ref($args->{'discussion'})) {
9230: ($target,$parser) =($args->{'discussion'}{'target'},
9231: $args->{'discussion'}{'parser'});
9232: }
9233: $result .= &Apache::lonxml::xmlend($target,$parser);
9234: }
1.330 albertel 9235: if ($args->{'frameset'}) {
9236: $result .= '</frameset>';
9237: } else {
1.635 raeburn 9238: $result .= &endbodytag($args);
1.330 albertel 9239: }
1.1080 raeburn 9240: unless ($args->{'notbody'}) {
9241: $result .= "\n</html>";
9242: }
1.330 albertel 9243:
1.315 albertel 9244: if ($args->{'js_ready'}) {
1.317 albertel 9245: $result = &js_ready($result);
1.315 albertel 9246: }
1.335 albertel 9247:
1.320 albertel 9248: if ($args->{'html_encode'}) {
9249: $result = &html_encode($result);
9250: }
1.335 albertel 9251:
1.315 albertel 9252: return $result;
9253: }
9254:
1.1359 raeburn 9255: sub menucoll_in_effect {
9256: my ($menucoll,$deeplinkmenu,%menu);
9257: if ($env{'request.course.id'}) {
9258: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9259: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9260: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9261: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9262: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9263: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9264: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9265: my $navmap = Apache::lonnavmaps::navmap->new();
9266: if (ref($navmap)) {
9267: $deeplink = $navmap->get_mapparam(undef,
9268: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9269: '0.deeplink');
1.1370 raeburn 9270: } else {
9271: $check_login_symb = 1;
1.1362 raeburn 9272: }
9273: } else {
1.1370 raeburn 9274: my $symb = &Apache::lonnet::symbread();
9275: if ($symb) {
9276: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9277: } else {
9278: $check_login_symb = 1;
9279: }
1.1362 raeburn 9280: }
9281: } else {
1.1370 raeburn 9282: $check_login_symb = 1;
9283: }
9284: if ($check_login_symb) {
1.1362 raeburn 9285: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9286: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9287: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9288: my $navmap = Apache::lonnavmaps::navmap->new();
9289: if (ref($navmap)) {
9290: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9291: }
9292: } else {
9293: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9294: }
9295: }
1.1359 raeburn 9296: if ($deeplink ne '') {
1.1363 raeburn 9297: my ($state,$others,$listed,$scope,$protect,$display) = split(/,/,$deeplink);
1.1359 raeburn 9298: if ($display =~ /^\d+$/) {
9299: $deeplinkmenu = 1;
9300: $menucoll = $display;
9301: }
9302: }
9303: }
9304: if ($menucoll) {
9305: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9306: }
9307: }
9308: return ($menucoll,$deeplinkmenu,\%menu);
9309: }
9310:
1.1362 raeburn 9311: sub deeplink_login_symb {
9312: my ($cnum,$cdom) = @_;
9313: my $login_symb;
9314: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9315: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9316: }
9317: return $login_symb;
9318: }
9319:
9320: sub symb_from_tinyurl {
9321: my ($url,$cnum,$cdom) = @_;
9322: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9323: my $key = $1;
9324: my ($tinyurl,$login);
9325: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9326: if (defined($cached)) {
9327: $tinyurl = $result;
9328: } else {
9329: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9330: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9331: if ($currtiny{$key} ne '') {
9332: $tinyurl = $currtiny{$key};
9333: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9334: }
1.1364 raeburn 9335: }
9336: if ($tinyurl ne '') {
9337: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9338: if (wantarray) {
9339: return ($cnumreq,$symb);
9340: } elsif ($cnumreq eq $cnum) {
9341: return $symb;
1.1362 raeburn 9342: }
9343: }
9344: }
1.1364 raeburn 9345: if (wantarray) {
9346: return ();
9347: } else {
9348: return;
9349: }
1.1362 raeburn 9350: }
9351:
1.1034 www 9352: sub wishlist_window {
9353: return(<<'ENDWISHLIST');
1.1046 raeburn 9354: <script type="text/javascript">
1.1034 www 9355: // <![CDATA[
9356: // <!-- BEGIN LON-CAPA Internal
9357: function set_wishlistlink(title, path) {
9358: if (!title) {
9359: title = document.title;
9360: title = title.replace(/^LON-CAPA /,'');
9361: }
1.1175 raeburn 9362: title = encodeURIComponent(title);
1.1203 raeburn 9363: title = title.replace("'","\\\'");
1.1034 www 9364: if (!path) {
9365: path = location.pathname;
9366: }
1.1175 raeburn 9367: path = encodeURIComponent(path);
1.1203 raeburn 9368: path = path.replace("'","\\\'");
1.1034 www 9369: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9370: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9371: }
9372: // END LON-CAPA Internal -->
9373: // ]]>
9374: </script>
9375: ENDWISHLIST
9376: }
9377:
1.1030 www 9378: sub modal_window {
9379: return(<<'ENDMODAL');
1.1046 raeburn 9380: <script type="text/javascript">
1.1030 www 9381: // <![CDATA[
9382: // <!-- BEGIN LON-CAPA Internal
9383: var modalWindow = {
9384: parent:"body",
9385: windowId:null,
9386: content:null,
9387: width:null,
9388: height:null,
9389: close:function()
9390: {
9391: $(".LCmodal-window").remove();
9392: $(".LCmodal-overlay").remove();
9393: },
9394: open:function()
9395: {
9396: var modal = "";
9397: modal += "<div class=\"LCmodal-overlay\"></div>";
9398: 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;\">";
9399: modal += this.content;
9400: modal += "</div>";
9401:
9402: $(this.parent).append(modal);
9403:
9404: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9405: $(".LCclose-window").click(function(){modalWindow.close();});
9406: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9407: }
9408: };
1.1140 raeburn 9409: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9410: {
1.1266 raeburn 9411: source = source.replace(/'/g,"'");
1.1030 www 9412: modalWindow.windowId = "myModal";
9413: modalWindow.width = width;
9414: modalWindow.height = height;
1.1196 raeburn 9415: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9416: modalWindow.open();
1.1208 raeburn 9417: };
1.1030 www 9418: // END LON-CAPA Internal -->
9419: // ]]>
9420: </script>
9421: ENDMODAL
9422: }
9423:
9424: sub modal_link {
1.1140 raeburn 9425: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9426: unless ($width) { $width=480; }
9427: unless ($height) { $height=400; }
1.1031 www 9428: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9429: unless ($transparency) { $transparency='true'; }
9430:
1.1074 raeburn 9431: my $target_attr;
9432: if (defined($target)) {
9433: $target_attr = 'target="'.$target.'"';
9434: }
9435: return <<"ENDLINK";
1.1336 raeburn 9436: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9437: ENDLINK
1.1030 www 9438: }
9439:
1.1032 www 9440: sub modal_adhoc_script {
1.1365 raeburn 9441: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9442: my $mathjax;
9443: if ($possmathjax) {
9444: $mathjax = <<'ENDJAX';
9445: if (typeof MathJax == 'object') {
9446: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9447: }
9448: ENDJAX
9449: }
1.1032 www 9450: return (<<ENDADHOC);
1.1046 raeburn 9451: <script type="text/javascript">
1.1032 www 9452: // <![CDATA[
9453: var $funcname = function()
9454: {
9455: modalWindow.windowId = "myModal";
9456: modalWindow.width = $width;
9457: modalWindow.height = $height;
9458: modalWindow.content = '$content';
9459: modalWindow.open();
1.1365 raeburn 9460: $mathjax
1.1032 www 9461: };
9462: // ]]>
9463: </script>
9464: ENDADHOC
9465: }
9466:
1.1041 www 9467: sub modal_adhoc_inner {
1.1365 raeburn 9468: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9469: my $innerwidth=$width-20;
9470: $content=&js_ready(
1.1140 raeburn 9471: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9472: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9473: $content.
1.1041 www 9474: &end_scrollbox().
1.1140 raeburn 9475: &end_page()
1.1041 www 9476: );
1.1365 raeburn 9477: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9478: }
9479:
9480: sub modal_adhoc_window {
1.1365 raeburn 9481: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9482: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9483: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9484: }
9485:
9486: sub modal_adhoc_launch {
9487: my ($funcname,$width,$height,$content)=@_;
9488: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9489: <script type="text/javascript">
9490: // <![CDATA[
9491: $funcname();
9492: // ]]>
9493: </script>
9494: ENDLAUNCH
9495: }
9496:
9497: sub modal_adhoc_close {
9498: return (<<ENDCLOSE);
9499: <script type="text/javascript">
9500: // <![CDATA[
9501: modalWindow.close();
9502: // ]]>
9503: </script>
9504: ENDCLOSE
9505: }
9506:
1.1038 www 9507: sub togglebox_script {
9508: return(<<ENDTOGGLE);
9509: <script type="text/javascript">
9510: // <![CDATA[
9511: function LCtoggleDisplay(id,hidetext,showtext) {
9512: link = document.getElementById(id + "link").childNodes[0];
9513: with (document.getElementById(id).style) {
9514: if (display == "none" ) {
9515: display = "inline";
9516: link.nodeValue = hidetext;
9517: } else {
9518: display = "none";
9519: link.nodeValue = showtext;
9520: }
9521: }
9522: }
9523: // ]]>
9524: </script>
9525: ENDTOGGLE
9526: }
9527:
1.1039 www 9528: sub start_togglebox {
9529: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9530: unless ($heading) { $heading=''; } else { $heading.=' '; }
9531: unless ($showtext) { $showtext=&mt('show'); }
9532: unless ($hidetext) { $hidetext=&mt('hide'); }
9533: unless ($headerbg) { $headerbg='#FFFFFF'; }
9534: return &start_data_table().
9535: &start_data_table_header_row().
9536: '<td bgcolor="'.$headerbg.'">'.$heading.
9537: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9538: $showtext.'\')">'.$showtext.'</a>]</td>'.
9539: &end_data_table_header_row().
9540: '<tr id="'.$id.'" style="display:none""><td>';
9541: }
9542:
9543: sub end_togglebox {
9544: return '</td></tr>'.&end_data_table();
9545: }
9546:
1.1041 www 9547: sub LCprogressbar_script {
1.1302 raeburn 9548: my ($id,$number_to_do)=@_;
9549: if ($number_to_do) {
9550: return(<<ENDPROGRESS);
1.1041 www 9551: <script type="text/javascript">
9552: // <![CDATA[
1.1045 www 9553: \$('#progressbar$id').progressbar({
1.1041 www 9554: value: 0,
9555: change: function(event, ui) {
9556: var newVal = \$(this).progressbar('option', 'value');
9557: \$('.pblabel', this).text(LCprogressTxt);
9558: }
9559: });
9560: // ]]>
9561: </script>
9562: ENDPROGRESS
1.1302 raeburn 9563: } else {
9564: return(<<ENDPROGRESS);
9565: <script type="text/javascript">
9566: // <![CDATA[
9567: \$('#progressbar$id').progressbar({
9568: value: false,
9569: create: function(event, ui) {
9570: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9571: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9572: }
9573: });
9574: // ]]>
9575: </script>
9576: ENDPROGRESS
9577: }
1.1041 www 9578: }
9579:
9580: sub LCprogressbarUpdate_script {
9581: return(<<ENDPROGRESSUPDATE);
9582: <style type="text/css">
9583: .ui-progressbar { position:relative; }
1.1302 raeburn 9584: .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 9585: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9586: </style>
9587: <script type="text/javascript">
9588: // <![CDATA[
1.1045 www 9589: var LCprogressTxt='---';
9590:
1.1302 raeburn 9591: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9592: LCprogressTxt=progresstext;
1.1302 raeburn 9593: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9594: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9595: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9596: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9597: } else {
9598: \$('#progressbar'+id).progressbar('value',percent);
9599: }
1.1041 www 9600: }
9601: // ]]>
9602: </script>
9603: ENDPROGRESSUPDATE
9604: }
9605:
1.1042 www 9606: my $LClastpercent;
1.1045 www 9607: my $LCidcnt;
9608: my $LCcurrentid;
1.1042 www 9609:
1.1041 www 9610: sub LCprogressbar {
1.1302 raeburn 9611: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9612: $LClastpercent=0;
1.1045 www 9613: $LCidcnt++;
9614: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9615: my ($starting,$content);
9616: if ($number_to_do) {
9617: $starting=&mt('Starting');
9618: $content=(<<ENDPROGBAR);
9619: $preamble
1.1045 www 9620: <div id="progressbar$LCcurrentid">
1.1041 www 9621: <span class="pblabel">$starting</span>
9622: </div>
9623: ENDPROGBAR
1.1302 raeburn 9624: } else {
9625: $starting=&mt('Loading...');
9626: $LClastpercent='false';
9627: $content=(<<ENDPROGBAR);
9628: $preamble
9629: <div id="progressbar$LCcurrentid">
9630: <div class="progress-label">$starting</div>
9631: </div>
9632: ENDPROGBAR
9633: }
9634: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9635: }
9636:
9637: sub LCprogressbarUpdate {
1.1302 raeburn 9638: my ($r,$val,$text,$number_to_do)=@_;
9639: if ($number_to_do) {
9640: unless ($val) {
9641: if ($LClastpercent) {
9642: $val=$LClastpercent;
9643: } else {
9644: $val=0;
9645: }
9646: }
9647: if ($val<0) { $val=0; }
9648: if ($val>100) { $val=0; }
9649: $LClastpercent=$val;
9650: unless ($text) { $text=$val.'%'; }
9651: } else {
9652: $val = 'false';
1.1042 www 9653: }
1.1041 www 9654: $text=&js_ready($text);
1.1044 www 9655: &r_print($r,<<ENDUPDATE);
1.1041 www 9656: <script type="text/javascript">
9657: // <![CDATA[
1.1302 raeburn 9658: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9659: // ]]>
9660: </script>
9661: ENDUPDATE
1.1035 www 9662: }
9663:
1.1042 www 9664: sub LCprogressbarClose {
9665: my ($r)=@_;
9666: $LClastpercent=0;
1.1044 www 9667: &r_print($r,<<ENDCLOSE);
1.1042 www 9668: <script type="text/javascript">
9669: // <![CDATA[
1.1045 www 9670: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9671: // ]]>
9672: </script>
9673: ENDCLOSE
1.1044 www 9674: }
9675:
9676: sub r_print {
9677: my ($r,$to_print)=@_;
9678: if ($r) {
9679: $r->print($to_print);
9680: $r->rflush();
9681: } else {
9682: print($to_print);
9683: }
1.1042 www 9684: }
9685:
1.320 albertel 9686: sub html_encode {
9687: my ($result) = @_;
9688:
1.322 albertel 9689: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9690:
9691: return $result;
9692: }
1.1044 www 9693:
1.317 albertel 9694: sub js_ready {
9695: my ($result) = @_;
9696:
1.323 albertel 9697: $result =~ s/[\n\r]/ /xmsg;
9698: $result =~ s/\\/\\\\/xmsg;
9699: $result =~ s/'/\\'/xmsg;
1.372 albertel 9700: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9701:
9702: return $result;
9703: }
9704:
1.315 albertel 9705: sub validate_page {
9706: if ( exists($env{'internal.start_page'})
1.316 albertel 9707: && $env{'internal.start_page'} > 1) {
9708: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9709: $env{'internal.start_page'}.' '.
1.316 albertel 9710: $ENV{'request.filename'});
1.315 albertel 9711: }
9712: if ( exists($env{'internal.end_page'})
1.316 albertel 9713: && $env{'internal.end_page'} > 1) {
9714: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9715: $env{'internal.end_page'}.' '.
1.316 albertel 9716: $env{'request.filename'});
1.315 albertel 9717: }
9718: if ( exists($env{'internal.start_page'})
9719: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9720: &Apache::lonnet::logthis('start_page called without end_page '.
9721: $env{'request.filename'});
1.315 albertel 9722: }
9723: if ( ! exists($env{'internal.start_page'})
9724: && exists($env{'internal.end_page'})) {
1.316 albertel 9725: &Apache::lonnet::logthis('end_page called without start_page'.
9726: $env{'request.filename'});
1.315 albertel 9727: }
1.306 albertel 9728: }
1.315 albertel 9729:
1.996 www 9730:
9731: sub start_scrollbox {
1.1140 raeburn 9732: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9733: unless ($outerwidth) { $outerwidth='520px'; }
9734: unless ($width) { $width='500px'; }
9735: unless ($height) { $height='200px'; }
1.1075 raeburn 9736: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9737: if ($id ne '') {
1.1140 raeburn 9738: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9739: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9740: }
1.1075 raeburn 9741: if ($bgcolor ne '') {
9742: $tdcol = "background-color: $bgcolor;";
9743: }
1.1137 raeburn 9744: my $nicescroll_js;
9745: if ($env{'browser.mobile'}) {
1.1140 raeburn 9746: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9747: }
9748: return <<"END";
9749: $nicescroll_js
9750:
9751: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9752: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9753: END
9754: }
9755:
9756: sub end_scrollbox {
9757: return '</div></td></tr></table>';
9758: }
9759:
9760: sub nicescroll_javascript {
9761: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9762: my %options;
9763: if (ref($cursor) eq 'HASH') {
9764: %options = %{$cursor};
9765: }
9766: unless ($options{'railalign'} =~ /^left|right$/) {
9767: $options{'railalign'} = 'left';
9768: }
9769: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9770: my $function = &get_users_function();
9771: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9772: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9773: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9774: }
1.1140 raeburn 9775: }
9776: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9777: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9778: $options{'cursoropacity'}='1.0';
9779: }
1.1140 raeburn 9780: } else {
9781: $options{'cursoropacity'}='1.0';
9782: }
9783: if ($options{'cursorfixedheight'} eq 'none') {
9784: delete($options{'cursorfixedheight'});
9785: } else {
9786: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9787: }
9788: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9789: delete($options{'railoffset'});
9790: }
9791: my @niceoptions;
9792: while (my($key,$value) = each(%options)) {
9793: if ($value =~ /^\{.+\}$/) {
9794: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9795: } else {
1.1140 raeburn 9796: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9797: }
1.1140 raeburn 9798: }
9799: my $nicescroll_js = '
1.1137 raeburn 9800: $(document).ready(
1.1140 raeburn 9801: function() {
9802: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9803: }
1.1137 raeburn 9804: );
9805: ';
1.1140 raeburn 9806: if ($framecheck) {
9807: $nicescroll_js .= '
9808: function expand_div(caller) {
9809: if (top === self) {
9810: document.getElementById("'.$id.'").style.width = "auto";
9811: document.getElementById("'.$id.'").style.height = "auto";
9812: } else {
9813: try {
9814: if (parent.frames) {
9815: if (parent.frames.length > 1) {
9816: var framesrc = parent.frames[1].location.href;
9817: var currsrc = framesrc.replace(/\#.*$/,"");
9818: if ((caller == "search") || (currsrc == "'.$location.'")) {
9819: document.getElementById("'.$id.'").style.width = "auto";
9820: document.getElementById("'.$id.'").style.height = "auto";
9821: }
9822: }
9823: }
9824: } catch (e) {
9825: return;
9826: }
1.1137 raeburn 9827: }
1.1140 raeburn 9828: return;
1.996 www 9829: }
1.1140 raeburn 9830: ';
9831: }
9832: if ($needjsready) {
9833: $nicescroll_js = '
9834: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9835: } else {
9836: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9837: }
9838: return $nicescroll_js;
1.996 www 9839: }
9840:
1.318 albertel 9841: sub simple_error_page {
1.1150 bisitz 9842: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9843: my %displayargs;
1.1151 raeburn 9844: if (ref($args) eq 'HASH') {
9845: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9846: if ($args->{'only_body'}) {
9847: $displayargs{'only_body'} = 1;
9848: }
9849: if ($args->{'no_nav_bar'}) {
9850: $displayargs{'no_nav_bar'} = 1;
9851: }
1.1151 raeburn 9852: } else {
9853: $msg = &mt($msg);
9854: }
1.1150 bisitz 9855:
1.318 albertel 9856: my $page =
1.1304 raeburn 9857: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9858: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9859: &Apache::loncommon::end_page();
9860: if (ref($r)) {
9861: $r->print($page);
1.327 albertel 9862: return;
1.318 albertel 9863: }
9864: return $page;
9865: }
1.347 albertel 9866:
9867: {
1.610 albertel 9868: my @row_count;
1.961 onken 9869:
9870: sub start_data_table_count {
9871: unshift(@row_count, 0);
9872: return;
9873: }
9874:
9875: sub end_data_table_count {
9876: shift(@row_count);
9877: return;
9878: }
9879:
1.347 albertel 9880: sub start_data_table {
1.1018 raeburn 9881: my ($add_class,$id) = @_;
1.422 albertel 9882: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9883: my $table_id;
9884: if (defined($id)) {
9885: $table_id = ' id="'.$id.'"';
9886: }
1.961 onken 9887: &start_data_table_count();
1.1018 raeburn 9888: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9889: }
9890:
9891: sub end_data_table {
1.961 onken 9892: &end_data_table_count();
1.389 albertel 9893: return '</table>'."\n";;
1.347 albertel 9894: }
9895:
9896: sub start_data_table_row {
1.974 wenzelju 9897: my ($add_class, $id) = @_;
1.610 albertel 9898: $row_count[0]++;
9899: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9900: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9901: $id = (' id="'.$id.'"') unless ($id eq '');
9902: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9903: }
1.471 banghart 9904:
9905: sub continue_data_table_row {
1.974 wenzelju 9906: my ($add_class, $id) = @_;
1.610 albertel 9907: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9908: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9909: $id = (' id="'.$id.'"') unless ($id eq '');
9910: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9911: }
1.347 albertel 9912:
9913: sub end_data_table_row {
1.389 albertel 9914: return '</tr>'."\n";;
1.347 albertel 9915: }
1.367 www 9916:
1.421 albertel 9917: sub start_data_table_empty_row {
1.707 bisitz 9918: # $row_count[0]++;
1.421 albertel 9919: return '<tr class="LC_empty_row" >'."\n";;
9920: }
9921:
9922: sub end_data_table_empty_row {
9923: return '</tr>'."\n";;
9924: }
9925:
1.367 www 9926: sub start_data_table_header_row {
1.389 albertel 9927: return '<tr class="LC_header_row">'."\n";;
1.367 www 9928: }
9929:
9930: sub end_data_table_header_row {
1.389 albertel 9931: return '</tr>'."\n";;
1.367 www 9932: }
1.890 droeschl 9933:
9934: sub data_table_caption {
9935: my $caption = shift;
9936: return "<caption class=\"LC_caption\">$caption</caption>";
9937: }
1.347 albertel 9938: }
9939:
1.548 albertel 9940: =pod
9941:
9942: =item * &inhibit_menu_check($arg)
9943:
9944: Checks for a inhibitmenu state and generates output to preserve it
9945:
9946: Inputs: $arg - can be any of
9947: - undef - in which case the return value is a string
9948: to add into arguments list of a uri
9949: - 'input' - in which case the return value is a HTML
9950: <form> <input> field of type hidden to
9951: preserve the value
9952: - a url - in which case the return value is the url with
9953: the neccesary cgi args added to preserve the
9954: inhibitmenu state
9955: - a ref to a url - no return value, but the string is
9956: updated to include the neccessary cgi
9957: args to preserve the inhibitmenu state
9958:
9959: =cut
9960:
9961: sub inhibit_menu_check {
9962: my ($arg) = @_;
9963: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9964: if ($arg eq 'input') {
9965: if ($env{'form.inhibitmenu'}) {
9966: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9967: } else {
9968: return
9969: }
9970: }
9971: if ($env{'form.inhibitmenu'}) {
9972: if (ref($arg)) {
9973: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9974: } elsif ($arg eq '') {
9975: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9976: } else {
9977: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9978: }
9979: }
9980: if (!ref($arg)) {
9981: return $arg;
9982: }
9983: }
9984:
1.251 albertel 9985: ###############################################
1.182 matthew 9986:
9987: =pod
9988:
1.549 albertel 9989: =back
9990:
9991: =head1 User Information Routines
9992:
9993: =over 4
9994:
1.405 albertel 9995: =item * &get_users_function()
1.182 matthew 9996:
9997: Used by &bodytag to determine the current users primary role.
9998: Returns either 'student','coordinator','admin', or 'author'.
9999:
10000: =cut
10001:
10002: ###############################################
10003: sub get_users_function {
1.815 tempelho 10004: my $function = 'norole';
1.818 tempelho 10005: if ($env{'request.role'}=~/^(st)/) {
10006: $function='student';
10007: }
1.907 raeburn 10008: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10009: $function='coordinator';
10010: }
1.258 albertel 10011: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10012: $function='admin';
10013: }
1.826 bisitz 10014: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10015: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10016: $function='author';
10017: }
10018: return $function;
1.54 www 10019: }
1.99 www 10020:
10021: ###############################################
10022:
1.233 raeburn 10023: =pod
10024:
1.821 raeburn 10025: =item * &show_course()
10026:
10027: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10028: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10029:
10030: Inputs:
10031: None
10032:
10033: Outputs:
10034: Scalar: 1 if 'Course' to be used, 0 otherwise.
10035:
10036: =cut
10037:
10038: ###############################################
10039: sub show_course {
10040: my $course = !$env{'user.adv'};
10041: if (!$env{'user.adv'}) {
10042: foreach my $env (keys(%env)) {
10043: next if ($env !~ m/^user\.priv\./);
10044: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10045: $course = 0;
10046: last;
10047: }
10048: }
10049: }
10050: return $course;
10051: }
10052:
10053: ###############################################
10054:
10055: =pod
10056:
1.542 raeburn 10057: =item * &check_user_status()
1.274 raeburn 10058:
10059: Determines current status of supplied role for a
10060: specific user. Roles can be active, previous or future.
10061:
10062: Inputs:
10063: user's domain, user's username, course's domain,
1.375 raeburn 10064: course's number, optional section ID.
1.274 raeburn 10065:
10066: Outputs:
10067: role status: active, previous or future.
10068:
10069: =cut
10070:
10071: sub check_user_status {
1.412 raeburn 10072: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10073: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10074: my @uroles = keys(%userinfo);
1.274 raeburn 10075: my $srchstr;
10076: my $active_chk = 'none';
1.412 raeburn 10077: my $now = time;
1.274 raeburn 10078: if (@uroles > 0) {
1.908 raeburn 10079: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10080: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10081: } else {
1.412 raeburn 10082: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10083: }
10084: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10085: my $role_end = 0;
10086: my $role_start = 0;
10087: $active_chk = 'active';
1.412 raeburn 10088: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10089: $role_end = $1;
10090: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10091: $role_start = $1;
1.274 raeburn 10092: }
10093: }
10094: if ($role_start > 0) {
1.412 raeburn 10095: if ($now < $role_start) {
1.274 raeburn 10096: $active_chk = 'future';
10097: }
10098: }
10099: if ($role_end > 0) {
1.412 raeburn 10100: if ($now > $role_end) {
1.274 raeburn 10101: $active_chk = 'previous';
10102: }
10103: }
10104: }
10105: }
10106: return $active_chk;
10107: }
10108:
10109: ###############################################
10110:
10111: =pod
10112:
1.405 albertel 10113: =item * &get_sections()
1.233 raeburn 10114:
10115: Determines all the sections for a course including
10116: sections with students and sections containing other roles.
1.419 raeburn 10117: Incoming parameters:
10118:
10119: 1. domain
10120: 2. course number
10121: 3. reference to array containing roles for which sections should
10122: be gathered (optional).
10123: 4. reference to array containing status types for which sections
10124: should be gathered (optional).
10125:
10126: If the third argument is undefined, sections are gathered for any role.
10127: If the fourth argument is undefined, sections are gathered for any status.
10128: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10129:
1.374 raeburn 10130: Returns section hash (keys are section IDs, values are
10131: number of users in each section), subject to the
1.419 raeburn 10132: optional roles filter, optional status filter
1.233 raeburn 10133:
10134: =cut
10135:
10136: ###############################################
10137: sub get_sections {
1.419 raeburn 10138: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10139: if (!defined($cdom) || !defined($cnum)) {
10140: my $cid = $env{'request.course.id'};
10141:
10142: return if (!defined($cid));
10143:
10144: $cdom = $env{'course.'.$cid.'.domain'};
10145: $cnum = $env{'course.'.$cid.'.num'};
10146: }
10147:
10148: my %sectioncount;
1.419 raeburn 10149: my $now = time;
1.240 albertel 10150:
1.1118 raeburn 10151: my $check_students = 1;
10152: my $only_students = 0;
10153: if (ref($possible_roles) eq 'ARRAY') {
10154: if (grep(/^st$/,@{$possible_roles})) {
10155: if (@{$possible_roles} == 1) {
10156: $only_students = 1;
10157: }
10158: } else {
10159: $check_students = 0;
10160: }
10161: }
10162:
10163: if ($check_students) {
1.276 albertel 10164: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10165: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10166: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10167: my $start_index = &Apache::loncoursedata::CL_START();
10168: my $end_index = &Apache::loncoursedata::CL_END();
10169: my $status;
1.366 albertel 10170: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10171: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10172: $data->[$status_index],
10173: $data->[$start_index],
10174: $data->[$end_index]);
10175: if ($stu_status eq 'Active') {
10176: $status = 'active';
10177: } elsif ($end < $now) {
10178: $status = 'previous';
10179: } elsif ($start > $now) {
10180: $status = 'future';
10181: }
10182: if ($section ne '-1' && $section !~ /^\s*$/) {
10183: if ((!defined($possible_status)) || (($status ne '') &&
10184: (grep/^\Q$status\E$/,@{$possible_status}))) {
10185: $sectioncount{$section}++;
10186: }
1.240 albertel 10187: }
10188: }
10189: }
1.1118 raeburn 10190: if ($only_students) {
10191: return %sectioncount;
10192: }
1.240 albertel 10193: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10194: foreach my $user (sort(keys(%courseroles))) {
10195: if ($user !~ /^(\w{2})/) { next; }
10196: my ($role) = ($user =~ /^(\w{2})/);
10197: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10198: my ($section,$status);
1.240 albertel 10199: if ($role eq 'cr' &&
10200: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10201: $section=$1;
10202: }
10203: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10204: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10205: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10206: if ($end == -1 && $start == -1) {
10207: next; #deleted role
10208: }
10209: if (!defined($possible_status)) {
10210: $sectioncount{$section}++;
10211: } else {
10212: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10213: $status = 'active';
10214: } elsif ($end < $now) {
10215: $status = 'future';
10216: } elsif ($start > $now) {
10217: $status = 'previous';
10218: }
10219: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10220: $sectioncount{$section}++;
10221: }
10222: }
1.233 raeburn 10223: }
1.366 albertel 10224: return %sectioncount;
1.233 raeburn 10225: }
10226:
1.274 raeburn 10227: ###############################################
1.294 raeburn 10228:
10229: =pod
1.405 albertel 10230:
10231: =item * &get_course_users()
10232:
1.275 raeburn 10233: Retrieves usernames:domains for users in the specified course
10234: with specific role(s), and access status.
10235:
10236: Incoming parameters:
1.277 albertel 10237: 1. course domain
10238: 2. course number
10239: 3. access status: users must have - either active,
1.275 raeburn 10240: previous, future, or all.
1.277 albertel 10241: 4. reference to array of permissible roles
1.288 raeburn 10242: 5. reference to array of section restrictions (optional)
10243: 6. reference to results object (hash of hashes).
10244: 7. reference to optional userdata hash
1.609 raeburn 10245: 8. reference to optional statushash
1.630 raeburn 10246: 9. flag if privileged users (except those set to unhide in
10247: course settings) should be excluded
1.609 raeburn 10248: Keys of top level results hash are roles.
1.275 raeburn 10249: Keys of inner hashes are username:domain, with
10250: values set to access type.
1.288 raeburn 10251: Optional userdata hash returns an array with arguments in the
10252: same order as loncoursedata::get_classlist() for student data.
10253:
1.609 raeburn 10254: Optional statushash returns
10255:
1.288 raeburn 10256: Entries for end, start, section and status are blank because
10257: of the possibility of multiple values for non-student roles.
10258:
1.275 raeburn 10259: =cut
1.405 albertel 10260:
1.275 raeburn 10261: ###############################################
1.405 albertel 10262:
1.275 raeburn 10263: sub get_course_users {
1.630 raeburn 10264: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10265: my %idx = ();
1.419 raeburn 10266: my %seclists;
1.288 raeburn 10267:
10268: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10269: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10270: $idx{end} = &Apache::loncoursedata::CL_END();
10271: $idx{start} = &Apache::loncoursedata::CL_START();
10272: $idx{id} = &Apache::loncoursedata::CL_ID();
10273: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10274: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10275: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10276:
1.290 albertel 10277: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10278: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10279: my $now = time;
1.277 albertel 10280: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10281: my $match = 0;
1.412 raeburn 10282: my $secmatch = 0;
1.419 raeburn 10283: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10284: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10285: if ($section eq '') {
10286: $section = 'none';
10287: }
1.291 albertel 10288: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10289: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10290: $secmatch = 1;
10291: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10292: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10293: $secmatch = 1;
10294: }
10295: } else {
1.419 raeburn 10296: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10297: $secmatch = 1;
10298: }
1.290 albertel 10299: }
1.412 raeburn 10300: if (!$secmatch) {
10301: next;
10302: }
1.419 raeburn 10303: }
1.275 raeburn 10304: if (defined($$types{'active'})) {
1.288 raeburn 10305: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10306: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10307: $match = 1;
1.275 raeburn 10308: }
10309: }
10310: if (defined($$types{'previous'})) {
1.609 raeburn 10311: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10312: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10313: $match = 1;
1.275 raeburn 10314: }
10315: }
10316: if (defined($$types{'future'})) {
1.609 raeburn 10317: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10318: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10319: $match = 1;
1.275 raeburn 10320: }
10321: }
1.609 raeburn 10322: if ($match) {
10323: push(@{$seclists{$student}},$section);
10324: if (ref($userdata) eq 'HASH') {
10325: $$userdata{$student} = $$classlist{$student};
10326: }
10327: if (ref($statushash) eq 'HASH') {
10328: $statushash->{$student}{'st'}{$section} = $status;
10329: }
1.288 raeburn 10330: }
1.275 raeburn 10331: }
10332: }
1.412 raeburn 10333: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10334: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10335: my $now = time;
1.609 raeburn 10336: my %displaystatus = ( previous => 'Expired',
10337: active => 'Active',
10338: future => 'Future',
10339: );
1.1121 raeburn 10340: my (%nothide,@possdoms);
1.630 raeburn 10341: if ($hidepriv) {
10342: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10343: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10344: if ($user !~ /:/) {
10345: $nothide{join(':',split(/[\@]/,$user))}=1;
10346: } else {
10347: $nothide{$user} = 1;
10348: }
10349: }
1.1121 raeburn 10350: my @possdoms = ($cdom);
10351: if ($coursehash{'checkforpriv'}) {
10352: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10353: }
1.630 raeburn 10354: }
1.439 raeburn 10355: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10356: my $match = 0;
1.412 raeburn 10357: my $secmatch = 0;
1.439 raeburn 10358: my $status;
1.412 raeburn 10359: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10360: $user =~ s/:$//;
1.439 raeburn 10361: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10362: if ($end == -1 || $start == -1) {
10363: next;
10364: }
10365: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10366: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10367: my ($uname,$udom) = split(/:/,$user);
10368: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10369: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10370: $secmatch = 1;
10371: } elsif ($usec eq '') {
1.420 albertel 10372: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10373: $secmatch = 1;
10374: }
10375: } else {
10376: if (grep(/^\Q$usec\E$/,@{$sections})) {
10377: $secmatch = 1;
10378: }
10379: }
10380: if (!$secmatch) {
10381: next;
10382: }
1.288 raeburn 10383: }
1.419 raeburn 10384: if ($usec eq '') {
10385: $usec = 'none';
10386: }
1.275 raeburn 10387: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10388: if ($hidepriv) {
1.1121 raeburn 10389: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10390: (!$nothide{$uname.':'.$udom})) {
10391: next;
10392: }
10393: }
1.503 raeburn 10394: if ($end > 0 && $end < $now) {
1.439 raeburn 10395: $status = 'previous';
10396: } elsif ($start > $now) {
10397: $status = 'future';
10398: } else {
10399: $status = 'active';
10400: }
1.277 albertel 10401: foreach my $type (keys(%{$types})) {
1.275 raeburn 10402: if ($status eq $type) {
1.420 albertel 10403: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10404: push(@{$$users{$role}{$user}},$type);
10405: }
1.288 raeburn 10406: $match = 1;
10407: }
10408: }
1.419 raeburn 10409: if (($match) && (ref($userdata) eq 'HASH')) {
10410: if (!exists($$userdata{$uname.':'.$udom})) {
10411: &get_user_info($udom,$uname,\%idx,$userdata);
10412: }
1.420 albertel 10413: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10414: push(@{$seclists{$uname.':'.$udom}},$usec);
10415: }
1.609 raeburn 10416: if (ref($statushash) eq 'HASH') {
10417: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10418: }
1.275 raeburn 10419: }
10420: }
10421: }
10422: }
1.290 albertel 10423: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10424: if ((defined($cdom)) && (defined($cnum))) {
10425: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10426: if ( defined($csettings{'internal.courseowner'}) ) {
10427: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10428: next if ($owner eq '');
10429: my ($ownername,$ownerdom);
10430: if ($owner =~ /^([^:]+):([^:]+)$/) {
10431: $ownername = $1;
10432: $ownerdom = $2;
10433: } else {
10434: $ownername = $owner;
10435: $ownerdom = $cdom;
10436: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10437: }
10438: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10439: if (defined($userdata) &&
1.609 raeburn 10440: !exists($$userdata{$owner})) {
10441: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10442: if (!grep(/^none$/,@{$seclists{$owner}})) {
10443: push(@{$seclists{$owner}},'none');
10444: }
10445: if (ref($statushash) eq 'HASH') {
10446: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10447: }
1.290 albertel 10448: }
1.279 raeburn 10449: }
10450: }
10451: }
1.419 raeburn 10452: foreach my $user (keys(%seclists)) {
10453: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10454: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10455: }
1.275 raeburn 10456: }
10457: return;
10458: }
10459:
1.288 raeburn 10460: sub get_user_info {
10461: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10462: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10463: &plainname($uname,$udom,'lastname');
1.291 albertel 10464: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10465: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10466: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10467: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10468: return;
10469: }
1.275 raeburn 10470:
1.472 raeburn 10471: ###############################################
10472:
10473: =pod
10474:
10475: =item * &get_user_quota()
10476:
1.1134 raeburn 10477: Retrieves quota assigned for storage of user files.
10478: Default is to report quota for portfolio files.
1.472 raeburn 10479:
10480: Incoming parameters:
10481: 1. user's username
10482: 2. user's domain
1.1134 raeburn 10483: 3. quota name - portfolio, author, or course
1.1136 raeburn 10484: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10485: 4. crstype - official, unofficial, textbook, placement or community,
10486: if quota name is course
1.472 raeburn 10487:
10488: Returns:
1.1163 raeburn 10489: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10490: 2. (Optional) Type of setting: custom or default
10491: (individually assigned or default for user's
10492: institutional status).
10493: 3. (Optional) - User's institutional status (e.g., faculty, staff
10494: or student - types as defined in localenroll::inst_usertypes
10495: for user's domain, which determines default quota for user.
10496: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10497:
10498: If a value has been stored in the user's environment,
1.536 raeburn 10499: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10500: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10501:
10502: =cut
10503:
10504: ###############################################
10505:
10506:
10507: sub get_user_quota {
1.1136 raeburn 10508: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10509: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10510: if (!defined($udom)) {
10511: $udom = $env{'user.domain'};
10512: }
10513: if (!defined($uname)) {
10514: $uname = $env{'user.name'};
10515: }
10516: if (($udom eq '' || $uname eq '') ||
10517: ($udom eq 'public') && ($uname eq 'public')) {
10518: $quota = 0;
1.536 raeburn 10519: $quotatype = 'default';
10520: $defquota = 0;
1.472 raeburn 10521: } else {
1.536 raeburn 10522: my $inststatus;
1.1134 raeburn 10523: if ($quotaname eq 'course') {
10524: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10525: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10526: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10527: } else {
10528: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10529: $quota = $cenv{'internal.uploadquota'};
10530: }
1.536 raeburn 10531: } else {
1.1134 raeburn 10532: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10533: if ($quotaname eq 'author') {
10534: $quota = $env{'environment.authorquota'};
10535: } else {
10536: $quota = $env{'environment.portfolioquota'};
10537: }
10538: $inststatus = $env{'environment.inststatus'};
10539: } else {
10540: my %userenv =
10541: &Apache::lonnet::get('environment',['portfolioquota',
10542: 'authorquota','inststatus'],$udom,$uname);
10543: my ($tmp) = keys(%userenv);
10544: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10545: if ($quotaname eq 'author') {
10546: $quota = $userenv{'authorquota'};
10547: } else {
10548: $quota = $userenv{'portfolioquota'};
10549: }
10550: $inststatus = $userenv{'inststatus'};
10551: } else {
10552: undef(%userenv);
10553: }
10554: }
10555: }
10556: if ($quota eq '' || wantarray) {
10557: if ($quotaname eq 'course') {
10558: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10559: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10560: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10561: ($crstype eq 'placement')) {
1.1136 raeburn 10562: $defquota = $domdefs{$crstype.'quota'};
10563: }
10564: if ($defquota eq '') {
10565: $defquota = 500;
10566: }
1.1134 raeburn 10567: } else {
10568: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10569: }
10570: if ($quota eq '') {
10571: $quota = $defquota;
10572: $quotatype = 'default';
10573: } else {
10574: $quotatype = 'custom';
10575: }
1.472 raeburn 10576: }
10577: }
1.536 raeburn 10578: if (wantarray) {
10579: return ($quota,$quotatype,$settingstatus,$defquota);
10580: } else {
10581: return $quota;
10582: }
1.472 raeburn 10583: }
10584:
10585: ###############################################
10586:
10587: =pod
10588:
10589: =item * &default_quota()
10590:
1.536 raeburn 10591: Retrieves default quota assigned for storage of user portfolio files,
10592: given an (optional) user's institutional status.
1.472 raeburn 10593:
10594: Incoming parameters:
1.1142 raeburn 10595:
1.472 raeburn 10596: 1. domain
1.536 raeburn 10597: 2. (Optional) institutional status(es). This is a : separated list of
10598: status types (e.g., faculty, staff, student etc.)
10599: which apply to the user for whom the default is being retrieved.
10600: If the institutional status string in undefined, the domain
1.1134 raeburn 10601: default quota will be returned.
10602: 3. quota name - portfolio, author, or course
10603: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10604:
10605: Returns:
1.1142 raeburn 10606:
1.1163 raeburn 10607: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10608: 2. (Optional) institutional type which determined the value of the
10609: default quota.
1.472 raeburn 10610:
10611: If a value has been stored in the domain's configuration db,
10612: it will return that, otherwise it returns 20 (for backwards
10613: compatibility with domains which have not set up a configuration
1.1163 raeburn 10614: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10615:
1.536 raeburn 10616: If the user's status includes multiple types (e.g., staff and student),
10617: the largest default quota which applies to the user determines the
10618: default quota returned.
10619:
1.472 raeburn 10620: =cut
10621:
10622: ###############################################
10623:
10624:
10625: sub default_quota {
1.1134 raeburn 10626: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10627: my ($defquota,$settingstatus);
10628: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10629: ['quotas'],$udom);
1.1134 raeburn 10630: my $key = 'defaultquota';
10631: if ($quotaname eq 'author') {
10632: $key = 'authorquota';
10633: }
1.622 raeburn 10634: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10635: if ($inststatus ne '') {
1.765 raeburn 10636: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10637: foreach my $item (@statuses) {
1.1134 raeburn 10638: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10639: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10640: if ($defquota eq '') {
1.1134 raeburn 10641: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10642: $settingstatus = $item;
1.1134 raeburn 10643: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10644: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10645: $settingstatus = $item;
10646: }
10647: }
1.1134 raeburn 10648: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10649: if ($quotahash{'quotas'}{$item} ne '') {
10650: if ($defquota eq '') {
10651: $defquota = $quotahash{'quotas'}{$item};
10652: $settingstatus = $item;
10653: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10654: $defquota = $quotahash{'quotas'}{$item};
10655: $settingstatus = $item;
10656: }
1.536 raeburn 10657: }
10658: }
10659: }
10660: }
10661: if ($defquota eq '') {
1.1134 raeburn 10662: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10663: $defquota = $quotahash{'quotas'}{$key}{'default'};
10664: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10665: $defquota = $quotahash{'quotas'}{'default'};
10666: }
1.536 raeburn 10667: $settingstatus = 'default';
1.1139 raeburn 10668: if ($defquota eq '') {
10669: if ($quotaname eq 'author') {
10670: $defquota = 500;
10671: }
10672: }
1.536 raeburn 10673: }
10674: } else {
10675: $settingstatus = 'default';
1.1134 raeburn 10676: if ($quotaname eq 'author') {
10677: $defquota = 500;
10678: } else {
10679: $defquota = 20;
10680: }
1.536 raeburn 10681: }
10682: if (wantarray) {
10683: return ($defquota,$settingstatus);
1.472 raeburn 10684: } else {
1.536 raeburn 10685: return $defquota;
1.472 raeburn 10686: }
10687: }
10688:
1.1135 raeburn 10689: ###############################################
10690:
10691: =pod
10692:
1.1136 raeburn 10693: =item * &excess_filesize_warning()
1.1135 raeburn 10694:
10695: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10696: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10697: space to be exceeded.
1.1136 raeburn 10698:
10699: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10700: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10701:
1.1165 raeburn 10702: Inputs: 7
1.1136 raeburn 10703: 1. username or coursenum
1.1135 raeburn 10704: 2. domain
1.1136 raeburn 10705: 3. context ('author' or 'course')
1.1135 raeburn 10706: 4. filename of file for which action is being requested
10707: 5. filesize (kB) of file
10708: 6. action being taken: copy or upload.
1.1237 raeburn 10709: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10710:
10711: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10712: otherwise return null.
10713:
10714: =back
1.1135 raeburn 10715:
10716: =cut
10717:
1.1136 raeburn 10718: sub excess_filesize_warning {
1.1165 raeburn 10719: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10720: my $current_disk_usage = 0;
1.1165 raeburn 10721: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10722: if ($context eq 'author') {
10723: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10724: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10725: } else {
10726: foreach my $subdir ('docs','supplemental') {
10727: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10728: }
10729: }
1.1135 raeburn 10730: $disk_quota = int($disk_quota * 1000);
10731: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10732: return '<p class="LC_warning">'.
1.1135 raeburn 10733: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10734: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10735: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10736: $disk_quota,$current_disk_usage).
10737: '</p>';
10738: }
10739: return;
10740: }
10741:
10742: ###############################################
10743:
10744:
1.1136 raeburn 10745:
10746:
1.384 raeburn 10747: sub get_secgrprole_info {
10748: my ($cdom,$cnum,$needroles,$type) = @_;
10749: my %sections_count = &get_sections($cdom,$cnum);
10750: my @sections = (sort {$a <=> $b} keys(%sections_count));
10751: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10752: my @groups = sort(keys(%curr_groups));
10753: my $allroles = [];
10754: my $rolehash;
10755: my $accesshash = {
10756: active => 'Currently has access',
10757: future => 'Will have future access',
10758: previous => 'Previously had access',
10759: };
10760: if ($needroles) {
10761: $rolehash = {'all' => 'all'};
1.385 albertel 10762: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10763: if (&Apache::lonnet::error(%user_roles)) {
10764: undef(%user_roles);
10765: }
10766: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10767: my ($role)=split(/\:/,$item,2);
10768: if ($role eq 'cr') { next; }
10769: if ($role =~ /^cr/) {
10770: $$rolehash{$role} = (split('/',$role))[3];
10771: } else {
10772: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10773: }
10774: }
10775: foreach my $key (sort(keys(%{$rolehash}))) {
10776: push(@{$allroles},$key);
10777: }
10778: push (@{$allroles},'st');
10779: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10780: }
10781: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10782: }
10783:
1.555 raeburn 10784: sub user_picker {
1.1279 raeburn 10785: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10786: my $currdom = $dom;
1.1253 raeburn 10787: my @alldoms = &Apache::lonnet::all_domains();
10788: if (@alldoms == 1) {
10789: my %domsrch = &Apache::lonnet::get_dom('configuration',
10790: ['directorysrch'],$alldoms[0]);
10791: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10792: my $showdom = $domdesc;
10793: if ($showdom eq '') {
10794: $showdom = $dom;
10795: }
10796: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10797: if ((!$domsrch{'directorysrch'}{'available'}) &&
10798: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10799: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10800: }
10801: }
10802: }
1.555 raeburn 10803: my %curr_selected = (
10804: srchin => 'dom',
1.580 raeburn 10805: srchby => 'lastname',
1.555 raeburn 10806: );
10807: my $srchterm;
1.625 raeburn 10808: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10809: if ($srch->{'srchby'} ne '') {
10810: $curr_selected{'srchby'} = $srch->{'srchby'};
10811: }
10812: if ($srch->{'srchin'} ne '') {
10813: $curr_selected{'srchin'} = $srch->{'srchin'};
10814: }
10815: if ($srch->{'srchtype'} ne '') {
10816: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10817: }
10818: if ($srch->{'srchdomain'} ne '') {
10819: $currdom = $srch->{'srchdomain'};
10820: }
10821: $srchterm = $srch->{'srchterm'};
10822: }
1.1222 damieng 10823: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10824: 'usr' => 'Search criteria',
1.563 raeburn 10825: 'doma' => 'Domain/institution to search',
1.558 albertel 10826: 'uname' => 'username',
10827: 'lastname' => 'last name',
1.555 raeburn 10828: 'lastfirst' => 'last name, first name',
1.558 albertel 10829: 'crs' => 'in this course',
1.576 raeburn 10830: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10831: 'alc' => 'all LON-CAPA',
1.573 raeburn 10832: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10833: 'exact' => 'is',
10834: 'contains' => 'contains',
1.569 raeburn 10835: 'begins' => 'begins with',
1.1222 damieng 10836: );
10837: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10838: 'youm' => "You must include some text to search for.",
10839: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10840: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10841: 'yomc' => "You must choose a domain when using an institutional directory search.",
10842: 'ymcd' => "You must choose a domain when using a domain search.",
10843: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10844: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10845: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10846: );
1.1222 damieng 10847: &html_escape(\%html_lt);
10848: &js_escape(\%js_lt);
1.1255 raeburn 10849: my $domform;
1.1277 raeburn 10850: my $allow_blank = 1;
1.1255 raeburn 10851: if ($fixeddom) {
1.1277 raeburn 10852: $allow_blank = 0;
10853: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10854: } else {
1.1287 raeburn 10855: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10856: my ($trusted,$untrusted);
1.1287 raeburn 10857: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10858: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10859: } elsif ($context eq 'author') {
1.1288 raeburn 10860: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10861: } elsif ($context eq 'domain') {
1.1288 raeburn 10862: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10863: }
1.1288 raeburn 10864: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10865: }
1.563 raeburn 10866: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10867:
10868: my @srchins = ('crs','dom','alc','instd');
10869:
10870: foreach my $option (@srchins) {
10871: # FIXME 'alc' option unavailable until
10872: # loncreateuser::print_user_query_page()
10873: # has been completed.
10874: next if ($option eq 'alc');
1.880 raeburn 10875: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10876: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10877: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10878: if ($curr_selected{'srchin'} eq $option) {
10879: $srchinsel .= '
1.1222 damieng 10880: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10881: } else {
10882: $srchinsel .= '
1.1222 damieng 10883: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10884: }
1.555 raeburn 10885: }
1.563 raeburn 10886: $srchinsel .= "\n </select>\n";
1.555 raeburn 10887:
10888: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10889: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10890: if ($curr_selected{'srchby'} eq $option) {
10891: $srchbysel .= '
1.1222 damieng 10892: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10893: } else {
10894: $srchbysel .= '
1.1222 damieng 10895: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10896: }
10897: }
10898: $srchbysel .= "\n </select>\n";
10899:
10900: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10901: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10902: if ($curr_selected{'srchtype'} eq $option) {
10903: $srchtypesel .= '
1.1222 damieng 10904: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10905: } else {
10906: $srchtypesel .= '
1.1222 damieng 10907: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10908: }
10909: }
10910: $srchtypesel .= "\n </select>\n";
10911:
1.558 albertel 10912: my ($newuserscript,$new_user_create);
1.994 raeburn 10913: my $context_dom = $env{'request.role.domain'};
10914: if ($context eq 'requestcrs') {
10915: if ($env{'form.coursedom'} ne '') {
10916: $context_dom = $env{'form.coursedom'};
10917: }
10918: }
1.556 raeburn 10919: if ($forcenewuser) {
1.576 raeburn 10920: if (ref($srch) eq 'HASH') {
1.994 raeburn 10921: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10922: if ($cancreate) {
10923: $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>';
10924: } else {
1.799 bisitz 10925: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10926: my %usertypetext = (
10927: official => 'institutional',
10928: unofficial => 'non-institutional',
10929: );
1.799 bisitz 10930: $new_user_create = '<p class="LC_warning">'
10931: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10932: .' '
10933: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10934: ,'<a href="'.$helplink.'">','</a>')
10935: .'</p><br />';
1.627 raeburn 10936: }
1.576 raeburn 10937: }
10938: }
10939:
1.556 raeburn 10940: $newuserscript = <<"ENDSCRIPT";
10941:
1.570 raeburn 10942: function setSearch(createnew,callingForm) {
1.556 raeburn 10943: if (createnew == 1) {
1.570 raeburn 10944: for (var i=0; i<callingForm.srchby.length; i++) {
10945: if (callingForm.srchby.options[i].value == 'uname') {
10946: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10947: }
10948: }
1.570 raeburn 10949: for (var i=0; i<callingForm.srchin.length; i++) {
10950: if ( callingForm.srchin.options[i].value == 'dom') {
10951: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10952: }
10953: }
1.570 raeburn 10954: for (var i=0; i<callingForm.srchtype.length; i++) {
10955: if (callingForm.srchtype.options[i].value == 'exact') {
10956: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10957: }
10958: }
1.570 raeburn 10959: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10960: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10961: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10962: }
10963: }
10964: }
10965: }
10966: ENDSCRIPT
1.558 albertel 10967:
1.556 raeburn 10968: }
10969:
1.555 raeburn 10970: my $output = <<"END_BLOCK";
1.556 raeburn 10971: <script type="text/javascript">
1.824 bisitz 10972: // <![CDATA[
1.570 raeburn 10973: function validateEntry(callingForm) {
1.558 albertel 10974:
1.556 raeburn 10975: var checkok = 1;
1.558 albertel 10976: var srchin;
1.570 raeburn 10977: for (var i=0; i<callingForm.srchin.length; i++) {
10978: if ( callingForm.srchin[i].checked ) {
10979: srchin = callingForm.srchin[i].value;
1.558 albertel 10980: }
10981: }
10982:
1.570 raeburn 10983: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10984: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10985: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10986: var srchterm = callingForm.srchterm.value;
10987: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10988: var msg = "";
10989:
10990: if (srchterm == "") {
10991: checkok = 0;
1.1222 damieng 10992: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10993: }
10994:
1.569 raeburn 10995: if (srchtype== 'begins') {
10996: if (srchterm.length < 2) {
10997: checkok = 0;
1.1222 damieng 10998: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10999: }
11000: }
11001:
1.556 raeburn 11002: if (srchtype== 'contains') {
11003: if (srchterm.length < 3) {
11004: checkok = 0;
1.1222 damieng 11005: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11006: }
11007: }
11008: if (srchin == 'instd') {
11009: if (srchdomain == '') {
11010: checkok = 0;
1.1222 damieng 11011: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11012: }
11013: }
11014: if (srchin == 'dom') {
11015: if (srchdomain == '') {
11016: checkok = 0;
1.1222 damieng 11017: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11018: }
11019: }
11020: if (srchby == 'lastfirst') {
11021: if (srchterm.indexOf(",") == -1) {
11022: checkok = 0;
1.1222 damieng 11023: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11024: }
11025: if (srchterm.indexOf(",") == srchterm.length -1) {
11026: checkok = 0;
1.1222 damieng 11027: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11028: }
11029: }
11030: if (checkok == 0) {
1.1222 damieng 11031: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11032: return;
11033: }
11034: if (checkok == 1) {
1.570 raeburn 11035: callingForm.submit();
1.556 raeburn 11036: }
11037: }
11038:
11039: $newuserscript
11040:
1.824 bisitz 11041: // ]]>
1.556 raeburn 11042: </script>
1.558 albertel 11043:
11044: $new_user_create
11045:
1.555 raeburn 11046: END_BLOCK
1.558 albertel 11047:
1.876 raeburn 11048: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11049: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11050: $domform.
11051: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11052: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11053: $srchbysel.
11054: $srchtypesel.
11055: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11056: $srchinsel.
11057: &Apache::lonhtmlcommon::row_closure(1).
11058: &Apache::lonhtmlcommon::end_pick_box().
11059: '<br />';
1.1253 raeburn 11060: return ($output,1);
1.555 raeburn 11061: }
11062:
1.612 raeburn 11063: sub user_rule_check {
1.615 raeburn 11064: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11065: my ($response,%inst_response);
1.612 raeburn 11066: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11067: if (keys(%{$usershash}) > 1) {
11068: my (%by_username,%by_id,%userdoms);
11069: my $checkid;
11070: if (ref($checks) eq 'HASH') {
11071: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11072: $checkid = 1;
11073: }
11074: }
11075: foreach my $user (keys(%{$usershash})) {
11076: my ($uname,$udom) = split(/:/,$user);
11077: if ($checkid) {
11078: if (ref($usershash->{$user}) eq 'HASH') {
11079: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11080: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11081: $userdoms{$udom} = 1;
1.1227 raeburn 11082: if (ref($inst_results) eq 'HASH') {
11083: $inst_results->{$uname.':'.$udom} = {};
11084: }
1.1226 raeburn 11085: }
11086: }
11087: } else {
11088: $by_username{$udom}{$uname} = 1;
11089: $userdoms{$udom} = 1;
1.1227 raeburn 11090: if (ref($inst_results) eq 'HASH') {
11091: $inst_results->{$uname.':'.$udom} = {};
11092: }
1.1226 raeburn 11093: }
11094: }
11095: foreach my $udom (keys(%userdoms)) {
11096: if (!$got_rules->{$udom}) {
11097: my %domconfig = &Apache::lonnet::get_dom('configuration',
11098: ['usercreation'],$udom);
11099: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11100: foreach my $item ('username','id') {
11101: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11102: $$curr_rules{$udom}{$item} =
11103: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11104: }
11105: }
11106: }
11107: $got_rules->{$udom} = 1;
11108: }
1.612 raeburn 11109: }
1.1226 raeburn 11110: if ($checkid) {
11111: foreach my $udom (keys(%by_id)) {
11112: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11113: if ($outcome eq 'ok') {
1.1227 raeburn 11114: foreach my $id (keys(%{$by_id{$udom}})) {
11115: my $uname = $by_id{$udom}{$id};
11116: $inst_response{$uname.':'.$udom} = $outcome;
11117: }
1.1226 raeburn 11118: if (ref($results) eq 'HASH') {
11119: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11120: if (exists($inst_response{$uname.':'.$udom})) {
11121: $inst_response{$uname.':'.$udom} = $outcome;
11122: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11123: }
1.1226 raeburn 11124: }
11125: }
11126: }
1.612 raeburn 11127: }
1.615 raeburn 11128: } else {
1.1226 raeburn 11129: foreach my $udom (keys(%by_username)) {
11130: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11131: if ($outcome eq 'ok') {
1.1227 raeburn 11132: foreach my $uname (keys(%{$by_username{$udom}})) {
11133: $inst_response{$uname.':'.$udom} = $outcome;
11134: }
1.1226 raeburn 11135: if (ref($results) eq 'HASH') {
11136: foreach my $uname (keys(%{$results})) {
11137: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11138: }
11139: }
11140: }
11141: }
1.612 raeburn 11142: }
1.1226 raeburn 11143: } elsif (keys(%{$usershash}) == 1) {
11144: my $user = (keys(%{$usershash}))[0];
11145: my ($uname,$udom) = split(/:/,$user);
11146: if (($udom ne '') && ($uname ne '')) {
11147: if (ref($usershash->{$user}) eq 'HASH') {
11148: if (ref($checks) eq 'HASH') {
11149: if (defined($checks->{'username'})) {
11150: ($inst_response{$user},%{$inst_results->{$user}}) =
11151: &Apache::lonnet::get_instuser($udom,$uname);
11152: } elsif (defined($checks->{'id'})) {
11153: if ($usershash->{$user}->{'id'} ne '') {
11154: ($inst_response{$user},%{$inst_results->{$user}}) =
11155: &Apache::lonnet::get_instuser($udom,undef,
11156: $usershash->{$user}->{'id'});
11157: } else {
11158: ($inst_response{$user},%{$inst_results->{$user}}) =
11159: &Apache::lonnet::get_instuser($udom,$uname);
11160: }
1.585 raeburn 11161: }
1.1226 raeburn 11162: } else {
11163: ($inst_response{$user},%{$inst_results->{$user}}) =
11164: &Apache::lonnet::get_instuser($udom,$uname);
11165: return;
11166: }
11167: if (!$got_rules->{$udom}) {
11168: my %domconfig = &Apache::lonnet::get_dom('configuration',
11169: ['usercreation'],$udom);
11170: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11171: foreach my $item ('username','id') {
11172: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11173: $$curr_rules{$udom}{$item} =
11174: $domconfig{'usercreation'}{$item.'_rule'};
11175: }
11176: }
11177: }
11178: $got_rules->{$udom} = 1;
1.585 raeburn 11179: }
11180: }
1.1226 raeburn 11181: } else {
11182: return;
11183: }
11184: } else {
11185: return;
11186: }
11187: foreach my $user (keys(%{$usershash})) {
11188: my ($uname,$udom) = split(/:/,$user);
11189: next if (($udom eq '') || ($uname eq ''));
11190: my $id;
1.1227 raeburn 11191: if (ref($inst_results) eq 'HASH') {
11192: if (ref($inst_results->{$user}) eq 'HASH') {
11193: $id = $inst_results->{$user}->{'id'};
11194: }
11195: }
11196: if ($id eq '') {
11197: if (ref($usershash->{$user})) {
11198: $id = $usershash->{$user}->{'id'};
11199: }
1.585 raeburn 11200: }
1.612 raeburn 11201: foreach my $item (keys(%{$checks})) {
11202: if (ref($$curr_rules{$udom}) eq 'HASH') {
11203: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11204: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11205: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11206: $$curr_rules{$udom}{$item});
1.612 raeburn 11207: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11208: if ($rule_check{$rule}) {
11209: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11210: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11211: if (ref($inst_results) eq 'HASH') {
11212: if (ref($inst_results->{$user}) eq 'HASH') {
11213: if (keys(%{$inst_results->{$user}}) == 0) {
11214: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11215: } elsif ($item eq 'id') {
11216: if ($inst_results->{$user}->{'id'} eq '') {
11217: $$alerts{$item}{$udom}{$uname} = 1;
11218: }
1.615 raeburn 11219: }
1.612 raeburn 11220: }
11221: }
1.615 raeburn 11222: }
11223: last;
1.585 raeburn 11224: }
11225: }
11226: }
11227: }
11228: }
11229: }
11230: }
11231: }
1.612 raeburn 11232: return;
11233: }
11234:
11235: sub user_rule_formats {
11236: my ($domain,$domdesc,$curr_rules,$check) = @_;
11237: my %text = (
11238: 'username' => 'Usernames',
11239: 'id' => 'IDs',
11240: );
11241: my $output;
11242: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11243: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11244: if (@{$ruleorder} > 0) {
1.1102 raeburn 11245: $output = '<br />'.
11246: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11247: '<span class="LC_cusr_emph">','</span>',$domdesc).
11248: ' <ul>';
1.612 raeburn 11249: foreach my $rule (@{$ruleorder}) {
11250: if (ref($curr_rules) eq 'ARRAY') {
11251: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11252: if (ref($rules->{$rule}) eq 'HASH') {
11253: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11254: $rules->{$rule}{'desc'}.'</li>';
11255: }
11256: }
11257: }
11258: }
11259: $output .= '</ul>';
11260: }
11261: }
11262: return $output;
11263: }
11264:
11265: sub instrule_disallow_msg {
1.615 raeburn 11266: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11267: my $response;
11268: my %text = (
11269: item => 'username',
11270: items => 'usernames',
11271: match => 'matches',
11272: do => 'does',
11273: action => 'a username',
11274: one => 'one',
11275: );
11276: if ($count > 1) {
11277: $text{'item'} = 'usernames';
11278: $text{'match'} ='match';
11279: $text{'do'} = 'do';
11280: $text{'action'} = 'usernames',
11281: $text{'one'} = 'ones';
11282: }
11283: if ($checkitem eq 'id') {
11284: $text{'items'} = 'IDs';
11285: $text{'item'} = 'ID';
11286: $text{'action'} = 'an ID';
1.615 raeburn 11287: if ($count > 1) {
11288: $text{'item'} = 'IDs';
11289: $text{'action'} = 'IDs';
11290: }
1.612 raeburn 11291: }
1.674 bisitz 11292: $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 11293: if ($mode eq 'upload') {
11294: if ($checkitem eq 'username') {
11295: $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'}.");
11296: } elsif ($checkitem eq 'id') {
1.674 bisitz 11297: $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 11298: }
1.669 raeburn 11299: } elsif ($mode eq 'selfcreate') {
11300: if ($checkitem eq 'id') {
11301: $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.");
11302: }
1.615 raeburn 11303: } else {
11304: if ($checkitem eq 'username') {
11305: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11306: } elsif ($checkitem eq 'id') {
11307: $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.");
11308: }
1.612 raeburn 11309: }
11310: return $response;
1.585 raeburn 11311: }
11312:
1.624 raeburn 11313: sub personal_data_fieldtitles {
11314: my %fieldtitles = &Apache::lonlocal::texthash (
11315: id => 'Student/Employee ID',
11316: permanentemail => 'E-mail address',
11317: lastname => 'Last Name',
11318: firstname => 'First Name',
11319: middlename => 'Middle Name',
11320: generation => 'Generation',
11321: gen => 'Generation',
1.765 raeburn 11322: inststatus => 'Affiliation',
1.624 raeburn 11323: );
11324: return %fieldtitles;
11325: }
11326:
1.642 raeburn 11327: sub sorted_inst_types {
11328: my ($dom) = @_;
1.1185 raeburn 11329: my ($usertypes,$order);
11330: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11331: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11332: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11333: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11334: } else {
11335: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11336: }
1.642 raeburn 11337: my $othertitle = &mt('All users');
11338: if ($env{'request.course.id'}) {
1.668 raeburn 11339: $othertitle = &mt('Any users');
1.642 raeburn 11340: }
11341: my @types;
11342: if (ref($order) eq 'ARRAY') {
11343: @types = @{$order};
11344: }
11345: if (@types == 0) {
11346: if (ref($usertypes) eq 'HASH') {
11347: @types = sort(keys(%{$usertypes}));
11348: }
11349: }
11350: if (keys(%{$usertypes}) > 0) {
11351: $othertitle = &mt('Other users');
11352: }
11353: return ($othertitle,$usertypes,\@types);
11354: }
11355:
1.645 raeburn 11356: sub get_institutional_codes {
1.1361 raeburn 11357: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11358: # Get complete list of course sections to update
11359: my @currsections = ();
11360: my @currxlists = ();
1.1361 raeburn 11361: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11362: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11363: my $crskey = $crs.':'.$coursecode;
11364: @{$unclutteredsec{$crskey}} = ();
11365: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11366:
11367: if ($$settings{'internal.sectionnums'} ne '') {
11368: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11369: }
11370:
11371: if ($$settings{'internal.crosslistings'} ne '') {
11372: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11373: }
11374:
11375: if (@currxlists > 0) {
1.1361 raeburn 11376: foreach my $xl (@currxlists) {
11377: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11378: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11379: push(@{$allcourses},$1);
1.645 raeburn 11380: $$LC_code{$1} = $2;
11381: }
11382: }
11383: }
11384: }
1.1361 raeburn 11385:
1.645 raeburn 11386: if (@currsections > 0) {
1.1361 raeburn 11387: foreach my $sec (@currsections) {
11388: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11389: my $instsec = $1;
1.645 raeburn 11390: my $lc_sec = $2;
1.1361 raeburn 11391: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11392: push(@{$unclutteredsec{$crskey}},$instsec);
11393: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11394: }
11395: }
11396: }
11397: }
11398:
11399: if (@{$unclutteredsec{$crskey}} > 0) {
11400: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11401: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11402: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11403: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11404: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11405: push(@{$allcourses},$sec);
1.1361 raeburn 11406: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11407: }
11408: }
11409: }
11410: }
11411: return;
11412: }
11413:
1.971 raeburn 11414: sub get_standard_codeitems {
11415: return ('Year','Semester','Department','Number','Section');
11416: }
11417:
1.112 bowersj2 11418: =pod
11419:
1.780 raeburn 11420: =head1 Slot Helpers
11421:
11422: =over 4
11423:
11424: =item * sorted_slots()
11425:
1.1040 raeburn 11426: Sorts an array of slot names in order of an optional sort key,
11427: default sort is by slot start time (earliest first).
1.780 raeburn 11428:
11429: Inputs:
11430:
11431: =over 4
11432:
11433: slotsarr - Reference to array of unsorted slot names.
11434:
11435: slots - Reference to hash of hash, where outer hash keys are slot names.
11436:
1.1040 raeburn 11437: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11438:
1.549 albertel 11439: =back
11440:
1.780 raeburn 11441: Returns:
11442:
11443: =over 4
11444:
1.1040 raeburn 11445: sorted - An array of slot names sorted by a specified sort key
11446: (default sort key is start time of the slot).
1.780 raeburn 11447:
11448: =back
11449:
11450: =cut
11451:
11452:
11453: sub sorted_slots {
1.1040 raeburn 11454: my ($slotsarr,$slots,$sortkey) = @_;
11455: if ($sortkey eq '') {
11456: $sortkey = 'starttime';
11457: }
1.780 raeburn 11458: my @sorted;
11459: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11460: @sorted =
11461: sort {
11462: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11463: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11464: }
11465: if (ref($slots->{$a})) { return -1;}
11466: if (ref($slots->{$b})) { return 1;}
11467: return 0;
11468: } @{$slotsarr};
11469: }
11470: return @sorted;
11471: }
11472:
1.1040 raeburn 11473: =pod
11474:
11475: =item * get_future_slots()
11476:
11477: Inputs:
11478:
11479: =over 4
11480:
11481: cnum - course number
11482:
11483: cdom - course domain
11484:
11485: now - current UNIX time
11486:
11487: symb - optional symb
11488:
11489: =back
11490:
11491: Returns:
11492:
11493: =over 4
11494:
11495: sorted_reservable - ref to array of student_schedulable slots currently
11496: reservable, ordered by end date of reservation period.
11497:
11498: reservable_now - ref to hash of student_schedulable slots currently
11499: reservable.
11500:
11501: Keys in inner hash are:
11502: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11503: (b) endreserve: end date of reservation period.
11504: (c) uniqueperiod: start,end dates when slot is to be uniquely
11505: selected.
1.1040 raeburn 11506:
11507: sorted_future - ref to array of student_schedulable slots reservable in
11508: the future, ordered by start date of reservation period.
11509:
11510: future_reservable - ref to hash of student_schedulable slots reservable
11511: in the future.
11512:
11513: Keys in inner hash are:
11514: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11515: (b) startreserve: start date of reservation period.
11516: (c) uniqueperiod: start,end dates when slot is to be uniquely
11517: selected.
1.1040 raeburn 11518:
11519: =back
11520:
11521: =cut
11522:
11523: sub get_future_slots {
11524: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11525: my $map;
11526: if ($symb) {
11527: ($map) = &Apache::lonnet::decode_symb($symb);
11528: }
1.1040 raeburn 11529: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11530: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11531: foreach my $slot (keys(%slots)) {
11532: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11533: if ($symb) {
1.1229 raeburn 11534: if ($slots{$slot}->{'symb'} ne '') {
11535: my $canuse;
11536: my %oksymbs;
11537: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11538: map { $oksymbs{$_} = 1; } @slotsymbs;
11539: if ($oksymbs{$symb}) {
11540: $canuse = 1;
11541: } else {
11542: foreach my $item (@slotsymbs) {
11543: if ($item =~ /\.(page|sequence)$/) {
11544: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11545: if (($map ne '') && ($map eq $sloturl)) {
11546: $canuse = 1;
11547: last;
11548: }
11549: }
11550: }
11551: }
11552: next unless ($canuse);
11553: }
1.1040 raeburn 11554: }
11555: if (($slots{$slot}->{'starttime'} > $now) &&
11556: ($slots{$slot}->{'endtime'} > $now)) {
11557: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11558: my $userallowed = 0;
11559: if ($slots{$slot}->{'allowedsections'}) {
11560: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11561: if (!defined($env{'request.role.sec'})
11562: && grep(/^No section assigned$/,@allowed_sec)) {
11563: $userallowed=1;
11564: } else {
11565: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11566: $userallowed=1;
11567: }
11568: }
11569: unless ($userallowed) {
11570: if (defined($env{'request.course.groups'})) {
11571: my @groups = split(/:/,$env{'request.course.groups'});
11572: foreach my $group (@groups) {
11573: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11574: $userallowed=1;
11575: last;
11576: }
11577: }
11578: }
11579: }
11580: }
11581: if ($slots{$slot}->{'allowedusers'}) {
11582: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11583: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11584: if (grep(/^\Q$user\E$/,@allowed_users)) {
11585: $userallowed = 1;
11586: }
11587: }
11588: next unless($userallowed);
11589: }
11590: my $startreserve = $slots{$slot}->{'startreserve'};
11591: my $endreserve = $slots{$slot}->{'endreserve'};
11592: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11593: my $uniqueperiod;
11594: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11595: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11596: }
1.1040 raeburn 11597: if (($startreserve < $now) &&
11598: (!$endreserve || $endreserve > $now)) {
11599: my $lastres = $endreserve;
11600: if (!$lastres) {
11601: $lastres = $slots{$slot}->{'starttime'};
11602: }
11603: $reservable_now{$slot} = {
11604: symb => $symb,
1.1250 raeburn 11605: endreserve => $lastres,
11606: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11607: };
11608: } elsif (($startreserve > $now) &&
11609: (!$endreserve || $endreserve > $startreserve)) {
11610: $future_reservable{$slot} = {
11611: symb => $symb,
1.1250 raeburn 11612: startreserve => $startreserve,
11613: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11614: };
11615: }
11616: }
11617: }
11618: my @unsorted_reservable = keys(%reservable_now);
11619: if (@unsorted_reservable > 0) {
11620: @sorted_reservable =
11621: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11622: }
11623: my @unsorted_future = keys(%future_reservable);
11624: if (@unsorted_future > 0) {
11625: @sorted_future =
11626: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11627: }
11628: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11629: }
1.780 raeburn 11630:
11631: =pod
11632:
1.1057 foxr 11633: =back
11634:
1.549 albertel 11635: =head1 HTTP Helpers
11636:
11637: =over 4
11638:
1.648 raeburn 11639: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11640:
1.258 albertel 11641: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11642: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11643: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11644:
11645: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11646: $possible_names is an ref to an array of form element names. As an example:
11647: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11648: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11649:
11650: =cut
1.1 albertel 11651:
1.6 albertel 11652: sub get_unprocessed_cgi {
1.25 albertel 11653: my ($query,$possible_names)= @_;
1.26 matthew 11654: # $Apache::lonxml::debug=1;
1.356 albertel 11655: foreach my $pair (split(/&/,$query)) {
11656: my ($name, $value) = split(/=/,$pair);
1.369 www 11657: $name = &unescape($name);
1.25 albertel 11658: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11659: $value =~ tr/+/ /;
11660: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11661: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11662: }
1.16 harris41 11663: }
1.6 albertel 11664: }
11665:
1.112 bowersj2 11666: =pod
11667:
1.648 raeburn 11668: =item * &cacheheader()
1.112 bowersj2 11669:
11670: returns cache-controlling header code
11671:
11672: =cut
11673:
1.7 albertel 11674: sub cacheheader {
1.258 albertel 11675: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11676: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11677: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11678: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11679: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11680: return $output;
1.7 albertel 11681: }
11682:
1.112 bowersj2 11683: =pod
11684:
1.648 raeburn 11685: =item * &no_cache($r)
1.112 bowersj2 11686:
11687: specifies header code to not have cache
11688:
11689: =cut
11690:
1.9 albertel 11691: sub no_cache {
1.216 albertel 11692: my ($r) = @_;
11693: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11694: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11695: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11696: $r->no_cache(1);
11697: $r->header_out("Expires" => $date);
11698: $r->header_out("Pragma" => "no-cache");
1.123 www 11699: }
11700:
11701: sub content_type {
1.181 albertel 11702: my ($r,$type,$charset) = @_;
1.299 foxr 11703: if ($r) {
11704: # Note that printout.pl calls this with undef for $r.
11705: &no_cache($r);
11706: }
1.258 albertel 11707: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11708: unless ($charset) {
11709: $charset=&Apache::lonlocal::current_encoding;
11710: }
11711: if ($charset) { $type.='; charset='.$charset; }
11712: if ($r) {
11713: $r->content_type($type);
11714: } else {
11715: print("Content-type: $type\n\n");
11716: }
1.9 albertel 11717: }
1.25 albertel 11718:
1.112 bowersj2 11719: =pod
11720:
1.648 raeburn 11721: =item * &add_to_env($name,$value)
1.112 bowersj2 11722:
1.258 albertel 11723: adds $name to the %env hash with value
1.112 bowersj2 11724: $value, if $name already exists, the entry is converted to an array
11725: reference and $value is added to the array.
11726:
11727: =cut
11728:
1.25 albertel 11729: sub add_to_env {
11730: my ($name,$value)=@_;
1.258 albertel 11731: if (defined($env{$name})) {
11732: if (ref($env{$name})) {
1.25 albertel 11733: #already have multiple values
1.258 albertel 11734: push(@{ $env{$name} },$value);
1.25 albertel 11735: } else {
11736: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11737: my $first=$env{$name};
11738: undef($env{$name});
11739: push(@{ $env{$name} },$first,$value);
1.25 albertel 11740: }
11741: } else {
1.258 albertel 11742: $env{$name}=$value;
1.25 albertel 11743: }
1.31 albertel 11744: }
1.149 albertel 11745:
11746: =pod
11747:
1.648 raeburn 11748: =item * &get_env_multiple($name)
1.149 albertel 11749:
1.258 albertel 11750: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11751: values may be defined and end up as an array ref.
11752:
11753: returns an array of values
11754:
11755: =cut
11756:
11757: sub get_env_multiple {
11758: my ($name) = @_;
11759: my @values;
1.258 albertel 11760: if (defined($env{$name})) {
1.149 albertel 11761: # exists is it an array
1.258 albertel 11762: if (ref($env{$name})) {
11763: @values=@{ $env{$name} };
1.149 albertel 11764: } else {
1.258 albertel 11765: $values[0]=$env{$name};
1.149 albertel 11766: }
11767: }
11768: return(@values);
11769: }
11770:
1.1249 damieng 11771: # Looks at given dependencies, and returns something depending on the context.
11772: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11773: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11774: # For all other contexts, returns ($output, $counter, $numpathchg).
11775: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11776: # $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.
11777: # $numpathchg: integer with the number of cleaned up dependency paths.
11778: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11779: # \%mapping: hash reference clean path -> original path for all dependencies.
11780: # @param {string} actionurl - The path to the handler, indicative of the context.
11781: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11782: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11783: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11784: # @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)
11785: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11786: sub ask_for_embedded_content {
1.1249 damieng 11787: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11788: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11789: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11790: %currsubfile,%unused,$rem);
1.1071 raeburn 11791: my $counter = 0;
11792: my $numnew = 0;
1.987 raeburn 11793: my $numremref = 0;
11794: my $numinvalid = 0;
11795: my $numpathchg = 0;
11796: my $numexisting = 0;
1.1071 raeburn 11797: my $numunused = 0;
11798: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11799: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11800: my $heading = &mt('Upload embedded files');
11801: my $buttontext = &mt('Upload');
11802:
1.1249 damieng 11803: # fills these variables based on the context:
11804: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11805: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11806: if ($env{'request.course.id'}) {
1.1123 raeburn 11807: if ($actionurl eq '/adm/dependencies') {
11808: $navmap = Apache::lonnavmaps::navmap->new();
11809: }
11810: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11811: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11812: }
1.1123 raeburn 11813: if (($actionurl eq '/adm/portfolio') ||
11814: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11815: my $current_path='/';
11816: if ($env{'form.currentpath'}) {
11817: $current_path = $env{'form.currentpath'};
11818: }
11819: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11820: $udom = $cdom;
11821: $uname = $cnum;
1.984 raeburn 11822: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11823: } else {
11824: $udom = $env{'user.domain'};
11825: $uname = $env{'user.name'};
11826: $url = '/userfiles/portfolio';
11827: }
1.987 raeburn 11828: $toplevel = $url.'/';
1.984 raeburn 11829: $url .= $current_path;
11830: $getpropath = 1;
1.987 raeburn 11831: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11832: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11833: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11834: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11835: $toplevel = $url;
1.984 raeburn 11836: if ($rest ne '') {
1.987 raeburn 11837: $url .= $rest;
11838: }
11839: } elsif ($actionurl eq '/adm/coursedocs') {
11840: if (ref($args) eq 'HASH') {
1.1071 raeburn 11841: $url = $args->{'docs_url'};
11842: $toplevel = $url;
1.1084 raeburn 11843: if ($args->{'context'} eq 'paste') {
11844: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11845: ($path) =
11846: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11847: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11848: $fileloc =~ s{^/}{};
11849: }
1.1071 raeburn 11850: }
1.1084 raeburn 11851: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11852: if ($env{'request.course.id'} ne '') {
11853: if (ref($args) eq 'HASH') {
11854: $url = $args->{'docs_url'};
11855: $title = $args->{'docs_title'};
1.1126 raeburn 11856: $toplevel = $url;
11857: unless ($toplevel =~ m{^/}) {
11858: $toplevel = "/$url";
11859: }
1.1085 raeburn 11860: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11861: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11862: $path = $1;
11863: } else {
11864: ($path) =
11865: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11866: }
1.1195 raeburn 11867: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11868: $fileloc = $toplevel;
11869: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11870: my ($udom,$uname,$fname) =
11871: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11872: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11873: } else {
11874: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11875: }
1.1071 raeburn 11876: $fileloc =~ s{^/}{};
11877: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11878: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11879: }
1.987 raeburn 11880: }
1.1123 raeburn 11881: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11882: $udom = $cdom;
11883: $uname = $cnum;
11884: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11885: $toplevel = $url;
11886: $path = $url;
11887: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11888: $fileloc =~ s{^/}{};
1.987 raeburn 11889: }
1.1249 damieng 11890:
11891: # parses the dependency paths to get some info
11892: # fills $newfiles, $mapping, $subdependencies, $dependencies
11893: # $newfiles: hash URL -> 1 for new files or external URLs
11894: # (will be completed later)
11895: # $mapping:
11896: # for external URLs: external URL -> external URL
11897: # for relative paths: clean path -> original path
11898: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11899: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11900: foreach my $file (keys(%{$allfiles})) {
11901: my $embed_file;
11902: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11903: $embed_file = $1;
11904: } else {
11905: $embed_file = $file;
11906: }
1.1158 raeburn 11907: my ($absolutepath,$cleaned_file);
11908: if ($embed_file =~ m{^\w+://}) {
11909: $cleaned_file = $embed_file;
1.1147 raeburn 11910: $newfiles{$cleaned_file} = 1;
11911: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11912: } else {
1.1158 raeburn 11913: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11914: if ($embed_file =~ m{^/}) {
11915: $absolutepath = $embed_file;
11916: }
1.1147 raeburn 11917: if ($cleaned_file =~ m{/}) {
11918: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11919: $path = &check_for_traversal($path,$url,$toplevel);
11920: my $item = $fname;
11921: if ($path ne '') {
11922: $item = $path.'/'.$fname;
11923: $subdependencies{$path}{$fname} = 1;
11924: } else {
11925: $dependencies{$item} = 1;
11926: }
11927: if ($absolutepath) {
11928: $mapping{$item} = $absolutepath;
11929: } else {
11930: $mapping{$item} = $embed_file;
11931: }
11932: } else {
11933: $dependencies{$embed_file} = 1;
11934: if ($absolutepath) {
1.1147 raeburn 11935: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11936: } else {
1.1147 raeburn 11937: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11938: }
11939: }
1.984 raeburn 11940: }
11941: }
1.1249 damieng 11942:
11943: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11944: # and lists
11945: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11946: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11947: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11948: # the path had to be cleaned up
11949: # $existing: hash clean path -> 1 if the file exists
11950: # $numexisting: number of keys in $existing
11951: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11952: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11953: # dependency subdirectories that are
11954: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11955: my $dirptr = 16384;
1.984 raeburn 11956: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11957: $currsubfile{$path} = {};
1.1123 raeburn 11958: if (($actionurl eq '/adm/portfolio') ||
11959: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11960: my ($sublistref,$listerror) =
11961: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11962: if (ref($sublistref) eq 'ARRAY') {
11963: foreach my $line (@{$sublistref}) {
11964: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11965: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11966: }
1.984 raeburn 11967: }
1.987 raeburn 11968: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11969: if (opendir(my $dir,$url.'/'.$path)) {
11970: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11971: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11972: }
1.1084 raeburn 11973: } elsif (($actionurl eq '/adm/dependencies') ||
11974: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11975: ($args->{'context'} eq 'paste')) ||
11976: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11977: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11978: my $dir;
11979: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11980: $dir = $fileloc;
11981: } else {
11982: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11983: }
1.1071 raeburn 11984: if ($dir ne '') {
11985: my ($sublistref,$listerror) =
11986: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11987: if (ref($sublistref) eq 'ARRAY') {
11988: foreach my $line (@{$sublistref}) {
11989: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11990: undef,$mtime)=split(/\&/,$line,12);
11991: unless (($testdir&$dirptr) ||
11992: ($file_name =~ /^\.\.?$/)) {
11993: $currsubfile{$path}{$file_name} = [$size,$mtime];
11994: }
11995: }
11996: }
11997: }
1.984 raeburn 11998: }
11999: }
12000: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12001: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12002: my $item = $path.'/'.$file;
12003: unless ($mapping{$item} eq $item) {
12004: $pathchanges{$item} = 1;
12005: }
12006: $existing{$item} = 1;
12007: $numexisting ++;
12008: } else {
12009: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12010: }
12011: }
1.1071 raeburn 12012: if ($actionurl eq '/adm/dependencies') {
12013: foreach my $path (keys(%currsubfile)) {
12014: if (ref($currsubfile{$path}) eq 'HASH') {
12015: foreach my $file (keys(%{$currsubfile{$path}})) {
12016: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12017: next if (($rem ne '') &&
12018: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12019: (ref($navmap) &&
12020: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12021: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12022: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12023: $unused{$path.'/'.$file} = 1;
12024: }
12025: }
12026: }
12027: }
12028: }
1.984 raeburn 12029: }
1.1249 damieng 12030:
12031: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12032: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12033: my %currfile;
1.1123 raeburn 12034: if (($actionurl eq '/adm/portfolio') ||
12035: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12036: my ($dirlistref,$listerror) =
12037: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12038: if (ref($dirlistref) eq 'ARRAY') {
12039: foreach my $line (@{$dirlistref}) {
12040: my ($file_name,$rest) = split(/\&/,$line,2);
12041: $currfile{$file_name} = 1;
12042: }
1.984 raeburn 12043: }
1.987 raeburn 12044: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12045: if (opendir(my $dir,$url)) {
1.987 raeburn 12046: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12047: map {$currfile{$_} = 1;} @dir_list;
12048: }
1.1084 raeburn 12049: } elsif (($actionurl eq '/adm/dependencies') ||
12050: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12051: ($args->{'context'} eq 'paste')) ||
12052: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12053: if ($env{'request.course.id'} ne '') {
12054: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12055: if ($dir ne '') {
12056: my ($dirlistref,$listerror) =
12057: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12058: if (ref($dirlistref) eq 'ARRAY') {
12059: foreach my $line (@{$dirlistref}) {
12060: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12061: $size,undef,$mtime)=split(/\&/,$line,12);
12062: unless (($testdir&$dirptr) ||
12063: ($file_name =~ /^\.\.?$/)) {
12064: $currfile{$file_name} = [$size,$mtime];
12065: }
12066: }
12067: }
12068: }
12069: }
1.984 raeburn 12070: }
1.1249 damieng 12071: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12072: # are not in subdirectories, using $currfile
1.984 raeburn 12073: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12074: if (exists($currfile{$file})) {
1.987 raeburn 12075: unless ($mapping{$file} eq $file) {
12076: $pathchanges{$file} = 1;
12077: }
12078: $existing{$file} = 1;
12079: $numexisting ++;
12080: } else {
1.984 raeburn 12081: $newfiles{$file} = 1;
12082: }
12083: }
1.1071 raeburn 12084: foreach my $file (keys(%currfile)) {
12085: unless (($file eq $filename) ||
12086: ($file eq $filename.'.bak') ||
12087: ($dependencies{$file})) {
1.1085 raeburn 12088: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12089: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12090: next if (($rem ne '') &&
12091: (($env{"httpref.$rem".$file} ne '') ||
12092: (ref($navmap) &&
12093: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12094: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12095: ($navmap->getResourceByUrl($rem.$1)))))));
12096: }
1.1085 raeburn 12097: }
1.1071 raeburn 12098: $unused{$file} = 1;
12099: }
12100: }
1.1249 damieng 12101:
12102: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12103: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12104: ($args->{'context'} eq 'paste')) {
12105: $counter = scalar(keys(%existing));
12106: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12107: return ($output,$counter,$numpathchg,\%existing);
12108: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12109: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12110: $counter = scalar(keys(%existing));
12111: $numpathchg = scalar(keys(%pathchanges));
12112: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12113: }
1.1249 damieng 12114:
12115: # returns HTML otherwise, with dependency results and to ask for more uploads
12116:
12117: # $upload_output: missing dependencies (with upload form)
12118: # $modify_output: uploaded dependencies (in use)
12119: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12120: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12121: if ($actionurl eq '/adm/dependencies') {
12122: next if ($embed_file =~ m{^\w+://});
12123: }
1.660 raeburn 12124: $upload_output .= &start_data_table_row().
1.1123 raeburn 12125: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12126: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12127: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12128: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12129: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12130: }
1.1123 raeburn 12131: $upload_output .= '</td>';
1.1071 raeburn 12132: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12133: $upload_output.='<td align="right">'.
12134: '<span class="LC_info LC_fontsize_medium">'.
12135: &mt("URL points to web address").'</span>';
1.987 raeburn 12136: $numremref++;
1.660 raeburn 12137: } elsif ($args->{'error_on_invalid_names'}
12138: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12139: $upload_output.='<td align="right"><span class="LC_warning">'.
12140: &mt('Invalid characters').'</span>';
1.987 raeburn 12141: $numinvalid++;
1.660 raeburn 12142: } else {
1.1123 raeburn 12143: $upload_output .= '<td>'.
12144: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12145: $embed_file,\%mapping,
1.1071 raeburn 12146: $allfiles,$codebase,'upload');
12147: $counter ++;
12148: $numnew ++;
1.987 raeburn 12149: }
12150: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12151: }
12152: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12153: if ($actionurl eq '/adm/dependencies') {
12154: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12155: $modify_output .= &start_data_table_row().
12156: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12157: '<img src="'.&icon($embed_file).'" border="0" />'.
12158: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12159: '<td>'.$size.'</td>'.
12160: '<td>'.$mtime.'</td>'.
12161: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12162: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12163: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12164: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12165: &embedded_file_element('upload_embedded',$counter,
12166: $embed_file,\%mapping,
12167: $allfiles,$codebase,'modify').
12168: '</div></td>'.
12169: &end_data_table_row()."\n";
12170: $counter ++;
12171: } else {
12172: $upload_output .= &start_data_table_row().
1.1123 raeburn 12173: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12174: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12175: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12176: &Apache::loncommon::end_data_table_row()."\n";
12177: }
12178: }
12179: my $delidx = $counter;
12180: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12181: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12182: $delete_output .= &start_data_table_row().
12183: '<td><img src="'.&icon($oldfile).'" />'.
12184: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12185: '<td>'.$size.'</td>'.
12186: '<td>'.$mtime.'</td>'.
12187: '<td><label><input type="checkbox" name="del_upload_dep" '.
12188: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12189: &embedded_file_element('upload_embedded',$delidx,
12190: $oldfile,\%mapping,$allfiles,
12191: $codebase,'delete').'</td>'.
12192: &end_data_table_row()."\n";
12193: $numunused ++;
12194: $delidx ++;
1.987 raeburn 12195: }
12196: if ($upload_output) {
12197: $upload_output = &start_data_table().
12198: $upload_output.
12199: &end_data_table()."\n";
12200: }
1.1071 raeburn 12201: if ($modify_output) {
12202: $modify_output = &start_data_table().
12203: &start_data_table_header_row().
12204: '<th>'.&mt('File').'</th>'.
12205: '<th>'.&mt('Size (KB)').'</th>'.
12206: '<th>'.&mt('Modified').'</th>'.
12207: '<th>'.&mt('Upload replacement?').'</th>'.
12208: &end_data_table_header_row().
12209: $modify_output.
12210: &end_data_table()."\n";
12211: }
12212: if ($delete_output) {
12213: $delete_output = &start_data_table().
12214: &start_data_table_header_row().
12215: '<th>'.&mt('File').'</th>'.
12216: '<th>'.&mt('Size (KB)').'</th>'.
12217: '<th>'.&mt('Modified').'</th>'.
12218: '<th>'.&mt('Delete?').'</th>'.
12219: &end_data_table_header_row().
12220: $delete_output.
12221: &end_data_table()."\n";
12222: }
1.987 raeburn 12223: my $applies = 0;
12224: if ($numremref) {
12225: $applies ++;
12226: }
12227: if ($numinvalid) {
12228: $applies ++;
12229: }
12230: if ($numexisting) {
12231: $applies ++;
12232: }
1.1071 raeburn 12233: if ($counter || $numunused) {
1.987 raeburn 12234: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12235: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12236: $state.'<h3>'.$heading.'</h3>';
12237: if ($actionurl eq '/adm/dependencies') {
12238: if ($numnew) {
12239: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12240: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12241: $upload_output.'<br />'."\n";
12242: }
12243: if ($numexisting) {
12244: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12245: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12246: $modify_output.'<br />'."\n";
12247: $buttontext = &mt('Save changes');
12248: }
12249: if ($numunused) {
12250: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12251: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12252: $delete_output.'<br />'."\n";
12253: $buttontext = &mt('Save changes');
12254: }
12255: } else {
12256: $output .= $upload_output.'<br />'."\n";
12257: }
12258: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12259: $counter.'" />'."\n";
12260: if ($actionurl eq '/adm/dependencies') {
12261: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12262: $numnew.'" />'."\n";
12263: } elsif ($actionurl eq '') {
1.987 raeburn 12264: $output .= '<input type="hidden" name="phase" value="three" />';
12265: }
12266: } elsif ($applies) {
12267: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12268: if ($applies > 1) {
12269: $output .=
1.1123 raeburn 12270: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12271: if ($numremref) {
12272: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12273: }
12274: if ($numinvalid) {
12275: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12276: }
12277: if ($numexisting) {
12278: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12279: }
12280: $output .= '</ul><br />';
12281: } elsif ($numremref) {
12282: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12283: } elsif ($numinvalid) {
12284: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12285: } elsif ($numexisting) {
12286: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12287: }
12288: $output .= $upload_output.'<br />';
12289: }
12290: my ($pathchange_output,$chgcount);
1.1071 raeburn 12291: $chgcount = $counter;
1.987 raeburn 12292: if (keys(%pathchanges) > 0) {
12293: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12294: if ($counter) {
1.987 raeburn 12295: $output .= &embedded_file_element('pathchange',$chgcount,
12296: $embed_file,\%mapping,
1.1071 raeburn 12297: $allfiles,$codebase,'change');
1.987 raeburn 12298: } else {
12299: $pathchange_output .=
12300: &start_data_table_row().
12301: '<td><input type ="checkbox" name="namechange" value="'.
12302: $chgcount.'" checked="checked" /></td>'.
12303: '<td>'.$mapping{$embed_file}.'</td>'.
12304: '<td>'.$embed_file.
12305: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12306: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12307: '</td>'.&end_data_table_row();
1.660 raeburn 12308: }
1.987 raeburn 12309: $numpathchg ++;
12310: $chgcount ++;
1.660 raeburn 12311: }
12312: }
1.1127 raeburn 12313: if (($counter) || ($numunused)) {
1.987 raeburn 12314: if ($numpathchg) {
12315: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12316: $numpathchg.'" />'."\n";
12317: }
12318: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12319: ($actionurl eq '/adm/imsimport')) {
12320: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12321: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12322: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12323: } elsif ($actionurl eq '/adm/dependencies') {
12324: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12325: }
1.1123 raeburn 12326: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12327: } elsif ($numpathchg) {
12328: my %pathchange = ();
12329: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12330: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12331: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12332: }
1.987 raeburn 12333: }
1.1071 raeburn 12334: return ($output,$counter,$numpathchg);
1.987 raeburn 12335: }
12336:
1.1147 raeburn 12337: =pod
12338:
12339: =item * clean_path($name)
12340:
12341: Performs clean-up of directories, subdirectories and filename in an
12342: embedded object, referenced in an HTML file which is being uploaded
12343: to a course or portfolio, where
12344: "Upload embedded images/multimedia files if HTML file" checkbox was
12345: checked.
12346:
12347: Clean-up is similar to replacements in lonnet::clean_filename()
12348: except each / between sub-directory and next level is preserved.
12349:
12350: =cut
12351:
12352: sub clean_path {
12353: my ($embed_file) = @_;
12354: $embed_file =~s{^/+}{};
12355: my @contents;
12356: if ($embed_file =~ m{/}) {
12357: @contents = split(/\//,$embed_file);
12358: } else {
12359: @contents = ($embed_file);
12360: }
12361: my $lastidx = scalar(@contents)-1;
12362: for (my $i=0; $i<=$lastidx; $i++) {
12363: $contents[$i]=~s{\\}{/}g;
12364: $contents[$i]=~s/\s+/\_/g;
12365: $contents[$i]=~s{[^/\w\.\-]}{}g;
12366: if ($i == $lastidx) {
12367: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12368: }
12369: }
12370: if ($lastidx > 0) {
12371: return join('/',@contents);
12372: } else {
12373: return $contents[0];
12374: }
12375: }
12376:
1.987 raeburn 12377: sub embedded_file_element {
1.1071 raeburn 12378: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12379: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12380: (ref($codebase) eq 'HASH'));
12381: my $output;
1.1071 raeburn 12382: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12383: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12384: }
12385: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12386: &escape($embed_file).'" />';
12387: unless (($context eq 'upload_embedded') &&
12388: ($mapping->{$embed_file} eq $embed_file)) {
12389: $output .='
12390: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12391: }
12392: my $attrib;
12393: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12394: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12395: }
12396: $output .=
12397: "\n\t\t".
12398: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12399: $attrib.'" />';
12400: if (exists($codebase->{$mapping->{$embed_file}})) {
12401: $output .=
12402: "\n\t\t".
12403: '<input name="codebase_'.$num.'" type="hidden" value="'.
12404: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12405: }
1.987 raeburn 12406: return $output;
1.660 raeburn 12407: }
12408:
1.1071 raeburn 12409: sub get_dependency_details {
12410: my ($currfile,$currsubfile,$embed_file) = @_;
12411: my ($size,$mtime,$showsize,$showmtime);
12412: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12413: if ($embed_file =~ m{/}) {
12414: my ($path,$fname) = split(/\//,$embed_file);
12415: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12416: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12417: }
12418: } else {
12419: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12420: ($size,$mtime) = @{$currfile->{$embed_file}};
12421: }
12422: }
12423: $showsize = $size/1024.0;
12424: $showsize = sprintf("%.1f",$showsize);
12425: if ($mtime > 0) {
12426: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12427: }
12428: }
12429: return ($showsize,$showmtime);
12430: }
12431:
12432: sub ask_embedded_js {
12433: return <<"END";
12434: <script type="text/javascript"">
12435: // <![CDATA[
12436: function toggleBrowse(counter) {
12437: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12438: var fileid = document.getElementById('embedded_item_'+counter);
12439: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12440: if (chkboxid.checked == true) {
12441: uploaddivid.style.display='block';
12442: } else {
12443: uploaddivid.style.display='none';
12444: fileid.value = '';
12445: }
12446: }
12447: // ]]>
12448: </script>
12449:
12450: END
12451: }
12452:
1.661 raeburn 12453: sub upload_embedded {
12454: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12455: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12456: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12457: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12458: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12459: my $orig_uploaded_filename =
12460: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12461: foreach my $type ('orig','ref','attrib','codebase') {
12462: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12463: $env{'form.embedded_'.$type.'_'.$i} =
12464: &unescape($env{'form.embedded_'.$type.'_'.$i});
12465: }
12466: }
1.661 raeburn 12467: my ($path,$fname) =
12468: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12469: # no path, whole string is fname
12470: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12471: $fname = &Apache::lonnet::clean_filename($fname);
12472: # See if there is anything left
12473: next if ($fname eq '');
12474:
12475: # Check if file already exists as a file or directory.
12476: my ($state,$msg);
12477: if ($context eq 'portfolio') {
12478: my $port_path = $dirpath;
12479: if ($group ne '') {
12480: $port_path = "groups/$group/$port_path";
12481: }
1.987 raeburn 12482: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12483: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12484: $dir_root,$port_path,$disk_quota,
12485: $current_disk_usage,$uname,$udom);
12486: if ($state eq 'will_exceed_quota'
1.984 raeburn 12487: || $state eq 'file_locked') {
1.661 raeburn 12488: $output .= $msg;
12489: next;
12490: }
12491: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12492: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12493: if ($state eq 'exists') {
12494: $output .= $msg;
12495: next;
12496: }
12497: }
12498: # Check if extension is valid
12499: if (($fname =~ /\.(\w+)$/) &&
12500: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12501: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12502: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12503: next;
12504: } elsif (($fname =~ /\.(\w+)$/) &&
12505: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12506: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12507: next;
12508: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12509: $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 12510: next;
12511: }
12512: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12513: my $subdir = $path;
12514: $subdir =~ s{/+$}{};
1.661 raeburn 12515: if ($context eq 'portfolio') {
1.984 raeburn 12516: my $result;
12517: if ($state eq 'existingfile') {
12518: $result=
12519: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12520: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12521: } else {
1.984 raeburn 12522: $result=
12523: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12524: $dirpath.
1.1123 raeburn 12525: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12526: if ($result !~ m|^/uploaded/|) {
12527: $output .= '<span class="LC_error">'
12528: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12529: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12530: .'</span><br />';
12531: next;
12532: } else {
1.987 raeburn 12533: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12534: $path.$fname.'</span>').'<br />';
1.984 raeburn 12535: }
1.661 raeburn 12536: }
1.1123 raeburn 12537: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12538: my $extendedsubdir = $dirpath.'/'.$subdir;
12539: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12540: my $result =
1.1126 raeburn 12541: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12542: if ($result !~ m|^/uploaded/|) {
12543: $output .= '<span class="LC_error">'
12544: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12545: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12546: .'</span><br />';
12547: next;
12548: } else {
12549: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12550: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12551: if ($context eq 'syllabus') {
12552: &Apache::lonnet::make_public_indefinitely($result);
12553: }
1.987 raeburn 12554: }
1.661 raeburn 12555: } else {
12556: # Save the file
12557: my $target = $env{'form.embedded_item_'.$i};
12558: my $fullpath = $dir_root.$dirpath.'/'.$path;
12559: my $dest = $fullpath.$fname;
12560: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12561: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12562: my $count;
12563: my $filepath = $dir_root;
1.1027 raeburn 12564: foreach my $subdir (@parts) {
12565: $filepath .= "/$subdir";
12566: if (!-e $filepath) {
1.661 raeburn 12567: mkdir($filepath,0770);
12568: }
12569: }
12570: my $fh;
12571: if (!open($fh,'>'.$dest)) {
12572: &Apache::lonnet::logthis('Failed to create '.$dest);
12573: $output .= '<span class="LC_error">'.
1.1071 raeburn 12574: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12575: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12576: '</span><br />';
12577: } else {
12578: if (!print $fh $env{'form.embedded_item_'.$i}) {
12579: &Apache::lonnet::logthis('Failed to write to '.$dest);
12580: $output .= '<span class="LC_error">'.
1.1071 raeburn 12581: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12582: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12583: '</span><br />';
12584: } else {
1.987 raeburn 12585: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12586: $url.'</span>').'<br />';
12587: unless ($context eq 'testbank') {
12588: $footer .= &mt('View embedded file: [_1]',
12589: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12590: }
12591: }
12592: close($fh);
12593: }
12594: }
12595: if ($env{'form.embedded_ref_'.$i}) {
12596: $pathchange{$i} = 1;
12597: }
12598: }
12599: if ($output) {
12600: $output = '<p>'.$output.'</p>';
12601: }
12602: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12603: $returnflag = 'ok';
1.1071 raeburn 12604: my $numpathchgs = scalar(keys(%pathchange));
12605: if ($numpathchgs > 0) {
1.987 raeburn 12606: if ($context eq 'portfolio') {
12607: $output .= '<p>'.&mt('or').'</p>';
12608: } elsif ($context eq 'testbank') {
1.1071 raeburn 12609: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12610: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12611: $returnflag = 'modify_orightml';
12612: }
12613: }
1.1071 raeburn 12614: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12615: }
12616:
12617: sub modify_html_form {
12618: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12619: my $end = 0;
12620: my $modifyform;
12621: if ($context eq 'upload_embedded') {
12622: return unless (ref($pathchange) eq 'HASH');
12623: if ($env{'form.number_embedded_items'}) {
12624: $end += $env{'form.number_embedded_items'};
12625: }
12626: if ($env{'form.number_pathchange_items'}) {
12627: $end += $env{'form.number_pathchange_items'};
12628: }
12629: if ($end) {
12630: for (my $i=0; $i<$end; $i++) {
12631: if ($i < $env{'form.number_embedded_items'}) {
12632: next unless($pathchange->{$i});
12633: }
12634: $modifyform .=
12635: &start_data_table_row().
12636: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12637: 'checked="checked" /></td>'.
12638: '<td>'.$env{'form.embedded_ref_'.$i}.
12639: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12640: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12641: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12642: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12643: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12644: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12645: '<td>'.$env{'form.embedded_orig_'.$i}.
12646: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12647: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12648: &end_data_table_row();
1.1071 raeburn 12649: }
1.987 raeburn 12650: }
12651: } else {
12652: $modifyform = $pathchgtable;
12653: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12654: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12655: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12656: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12657: }
12658: }
12659: if ($modifyform) {
1.1071 raeburn 12660: if ($actionurl eq '/adm/dependencies') {
12661: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12662: }
1.987 raeburn 12663: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12664: '<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".
12665: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12666: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12667: '</ol></p>'."\n".'<p>'.
12668: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12669: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12670: &start_data_table()."\n".
12671: &start_data_table_header_row().
12672: '<th>'.&mt('Change?').'</th>'.
12673: '<th>'.&mt('Current reference').'</th>'.
12674: '<th>'.&mt('Required reference').'</th>'.
12675: &end_data_table_header_row()."\n".
12676: $modifyform.
12677: &end_data_table().'<br />'."\n".$hiddenstate.
12678: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12679: '</form>'."\n";
12680: }
12681: return;
12682: }
12683:
12684: sub modify_html_refs {
1.1123 raeburn 12685: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12686: my $container;
12687: if ($context eq 'portfolio') {
12688: $container = $env{'form.container'};
12689: } elsif ($context eq 'coursedoc') {
12690: $container = $env{'form.primaryurl'};
1.1071 raeburn 12691: } elsif ($context eq 'manage_dependencies') {
12692: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12693: $container = "/$container";
1.1123 raeburn 12694: } elsif ($context eq 'syllabus') {
12695: $container = $url;
1.987 raeburn 12696: } else {
1.1027 raeburn 12697: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12698: }
12699: my (%allfiles,%codebase,$output,$content);
12700: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12701: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12702: if (wantarray) {
12703: return ('',0,0);
12704: } else {
12705: return;
12706: }
12707: }
12708: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12709: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12710: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12711: if (wantarray) {
12712: return ('',0,0);
12713: } else {
12714: return;
12715: }
12716: }
1.987 raeburn 12717: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12718: if ($content eq '-1') {
12719: if (wantarray) {
12720: return ('',0,0);
12721: } else {
12722: return;
12723: }
12724: }
1.987 raeburn 12725: } else {
1.1071 raeburn 12726: unless ($container =~ /^\Q$dir_root\E/) {
12727: if (wantarray) {
12728: return ('',0,0);
12729: } else {
12730: return;
12731: }
12732: }
1.1317 raeburn 12733: if (open(my $fh,'<',$container)) {
1.987 raeburn 12734: $content = join('', <$fh>);
12735: close($fh);
12736: } else {
1.1071 raeburn 12737: if (wantarray) {
12738: return ('',0,0);
12739: } else {
12740: return;
12741: }
1.987 raeburn 12742: }
12743: }
12744: my ($count,$codebasecount) = (0,0);
12745: my $mm = new File::MMagic;
12746: my $mime_type = $mm->checktype_contents($content);
12747: if ($mime_type eq 'text/html') {
12748: my $parse_result =
12749: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12750: \%codebase,\$content);
12751: if ($parse_result eq 'ok') {
12752: foreach my $i (@changes) {
12753: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12754: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12755: if ($allfiles{$ref}) {
12756: my $newname = $orig;
12757: my ($attrib_regexp,$codebase);
1.1006 raeburn 12758: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12759: if ($attrib_regexp =~ /:/) {
12760: $attrib_regexp =~ s/\:/|/g;
12761: }
12762: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12763: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12764: $count += $numchg;
1.1123 raeburn 12765: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12766: delete($allfiles{$ref});
1.987 raeburn 12767: }
12768: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12769: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12770: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12771: $codebasecount ++;
12772: }
12773: }
12774: }
1.1123 raeburn 12775: my $skiprewrites;
1.987 raeburn 12776: if ($count || $codebasecount) {
12777: my $saveresult;
1.1071 raeburn 12778: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12779: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12780: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12781: if ($url eq $container) {
12782: my ($fname) = ($container =~ m{/([^/]+)$});
12783: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12784: $count,'<span class="LC_filename">'.
1.1071 raeburn 12785: $fname.'</span>').'</p>';
1.987 raeburn 12786: } else {
12787: $output = '<p class="LC_error">'.
12788: &mt('Error: update failed for: [_1].',
12789: '<span class="LC_filename">'.
12790: $container.'</span>').'</p>';
12791: }
1.1123 raeburn 12792: if ($context eq 'syllabus') {
12793: unless ($saveresult eq 'ok') {
12794: $skiprewrites = 1;
12795: }
12796: }
1.987 raeburn 12797: } else {
1.1317 raeburn 12798: if (open(my $fh,'>',$container)) {
1.987 raeburn 12799: print $fh $content;
12800: close($fh);
12801: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12802: $count,'<span class="LC_filename">'.
12803: $container.'</span>').'</p>';
1.661 raeburn 12804: } else {
1.987 raeburn 12805: $output = '<p class="LC_error">'.
12806: &mt('Error: could not update [_1].',
12807: '<span class="LC_filename">'.
12808: $container.'</span>').'</p>';
1.661 raeburn 12809: }
12810: }
12811: }
1.1123 raeburn 12812: if (($context eq 'syllabus') && (!$skiprewrites)) {
12813: my ($actionurl,$state);
12814: $actionurl = "/public/$udom/$uname/syllabus";
12815: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12816: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12817: \%codebase,
12818: {'context' => 'rewrites',
12819: 'ignore_remote_references' => 1,});
12820: if (ref($mapping) eq 'HASH') {
12821: my $rewrites = 0;
12822: foreach my $key (keys(%{$mapping})) {
12823: next if ($key =~ m{^https?://});
12824: my $ref = $mapping->{$key};
12825: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12826: my $attrib;
12827: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12828: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12829: }
12830: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12831: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12832: $rewrites += $numchg;
12833: }
12834: }
12835: if ($rewrites) {
12836: my $saveresult;
12837: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12838: if ($url eq $container) {
12839: my ($fname) = ($container =~ m{/([^/]+)$});
12840: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12841: $count,'<span class="LC_filename">'.
12842: $fname.'</span>').'</p>';
12843: } else {
12844: $output .= '<p class="LC_error">'.
12845: &mt('Error: could not update links in [_1].',
12846: '<span class="LC_filename">'.
12847: $container.'</span>').'</p>';
12848:
12849: }
12850: }
12851: }
12852: }
1.987 raeburn 12853: } else {
12854: &logthis('Failed to parse '.$container.
12855: ' to modify references: '.$parse_result);
1.661 raeburn 12856: }
12857: }
1.1071 raeburn 12858: if (wantarray) {
12859: return ($output,$count,$codebasecount);
12860: } else {
12861: return $output;
12862: }
1.661 raeburn 12863: }
12864:
12865: sub check_for_existing {
12866: my ($path,$fname,$element) = @_;
12867: my ($state,$msg);
12868: if (-d $path.'/'.$fname) {
12869: $state = 'exists';
12870: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12871: } elsif (-e $path.'/'.$fname) {
12872: $state = 'exists';
12873: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12874: }
12875: if ($state eq 'exists') {
12876: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12877: }
12878: return ($state,$msg);
12879: }
12880:
12881: sub check_for_upload {
12882: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12883: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12884: my $filesize = length($env{'form.'.$element});
12885: if (!$filesize) {
12886: my $msg = '<span class="LC_error">'.
12887: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12888: '<span class="LC_filename">'.$fname.'</span>',
12889: $filesize).'<br />'.
1.1007 raeburn 12890: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12891: '</span>';
12892: return ('zero_bytes',$msg);
12893: }
12894: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12895: my $getpropath = 1;
1.1021 raeburn 12896: my ($dirlistref,$listerror) =
12897: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12898: my $found_file = 0;
12899: my $locked_file = 0;
1.991 raeburn 12900: my @lockers;
12901: my $navmap;
12902: if ($env{'request.course.id'}) {
12903: $navmap = Apache::lonnavmaps::navmap->new();
12904: }
1.1021 raeburn 12905: if (ref($dirlistref) eq 'ARRAY') {
12906: foreach my $line (@{$dirlistref}) {
12907: my ($file_name,$rest)=split(/\&/,$line,2);
12908: if ($file_name eq $fname){
12909: $file_name = $path.$file_name;
12910: if ($group ne '') {
12911: $file_name = $group.$file_name;
12912: }
12913: $found_file = 1;
12914: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12915: foreach my $lock (@lockers) {
12916: if (ref($lock) eq 'ARRAY') {
12917: my ($symb,$crsid) = @{$lock};
12918: if ($crsid eq $env{'request.course.id'}) {
12919: if (ref($navmap)) {
12920: my $res = $navmap->getBySymb($symb);
12921: foreach my $part (@{$res->parts()}) {
12922: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12923: unless (($slot_status == $res->RESERVED) ||
12924: ($slot_status == $res->RESERVED_LOCATION)) {
12925: $locked_file = 1;
12926: }
1.991 raeburn 12927: }
1.1021 raeburn 12928: } else {
12929: $locked_file = 1;
1.991 raeburn 12930: }
12931: } else {
12932: $locked_file = 1;
12933: }
12934: }
1.1021 raeburn 12935: }
12936: } else {
12937: my @info = split(/\&/,$rest);
12938: my $currsize = $info[6]/1000;
12939: if ($currsize < $filesize) {
12940: my $extra = $filesize - $currsize;
12941: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12942: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12943: &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 12944: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12945: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12946: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12947: return ('will_exceed_quota',$msg);
12948: }
1.984 raeburn 12949: }
12950: }
1.661 raeburn 12951: }
12952: }
12953: }
12954: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12955: my $msg = '<p class="LC_warning">'.
12956: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12957: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12958: return ('will_exceed_quota',$msg);
12959: } elsif ($found_file) {
12960: if ($locked_file) {
1.1179 bisitz 12961: my $msg = '<p class="LC_warning">';
1.661 raeburn 12962: $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 12963: $msg .= '</p>';
1.661 raeburn 12964: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12965: return ('file_locked',$msg);
12966: } else {
1.1179 bisitz 12967: my $msg = '<p class="LC_error">';
1.984 raeburn 12968: $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 12969: $msg .= '</p>';
1.984 raeburn 12970: return ('existingfile',$msg);
1.661 raeburn 12971: }
12972: }
12973: }
12974:
1.987 raeburn 12975: sub check_for_traversal {
12976: my ($path,$url,$toplevel) = @_;
12977: my @parts=split(/\//,$path);
12978: my $cleanpath;
12979: my $fullpath = $url;
12980: for (my $i=0;$i<@parts;$i++) {
12981: next if ($parts[$i] eq '.');
12982: if ($parts[$i] eq '..') {
12983: $fullpath =~ s{([^/]+/)$}{};
12984: } else {
12985: $fullpath .= $parts[$i].'/';
12986: }
12987: }
12988: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12989: $cleanpath = $1;
12990: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12991: my $curr_toprel = $1;
12992: my @parts = split(/\//,$curr_toprel);
12993: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12994: my @urlparts = split(/\//,$url_toprel);
12995: my $doubledots;
12996: my $startdiff = -1;
12997: for (my $i=0; $i<@urlparts; $i++) {
12998: if ($startdiff == -1) {
12999: unless ($urlparts[$i] eq $parts[$i]) {
13000: $startdiff = $i;
13001: $doubledots .= '../';
13002: }
13003: } else {
13004: $doubledots .= '../';
13005: }
13006: }
13007: if ($startdiff > -1) {
13008: $cleanpath = $doubledots;
13009: for (my $i=$startdiff; $i<@parts; $i++) {
13010: $cleanpath .= $parts[$i].'/';
13011: }
13012: }
13013: }
13014: $cleanpath =~ s{(/)$}{};
13015: return $cleanpath;
13016: }
1.31 albertel 13017:
1.1053 raeburn 13018: sub is_archive_file {
13019: my ($mimetype) = @_;
13020: if (($mimetype eq 'application/octet-stream') ||
13021: ($mimetype eq 'application/x-stuffit') ||
13022: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13023: return 1;
13024: }
13025: return;
13026: }
13027:
13028: sub decompress_form {
1.1065 raeburn 13029: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13030: my %lt = &Apache::lonlocal::texthash (
13031: this => 'This file is an archive file.',
1.1067 raeburn 13032: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13033: itsc => 'Its contents are as follows:',
1.1053 raeburn 13034: youm => 'You may wish to extract its contents.',
13035: extr => 'Extract contents',
1.1067 raeburn 13036: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13037: proa => 'Process automatically?',
1.1053 raeburn 13038: yes => 'Yes',
13039: no => 'No',
1.1067 raeburn 13040: fold => 'Title for folder containing movie',
13041: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13042: );
1.1065 raeburn 13043: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13044: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13045: my $info = &list_archive_contents($fileloc,\@paths);
13046: if (@paths) {
13047: foreach my $path (@paths) {
13048: $path =~ s{^/}{};
1.1067 raeburn 13049: if ($path =~ m{^([^/]+)/$}) {
13050: $topdir = $1;
13051: }
1.1065 raeburn 13052: if ($path =~ m{^([^/]+)/}) {
13053: $toplevel{$1} = $path;
13054: } else {
13055: $toplevel{$path} = $path;
13056: }
13057: }
13058: }
1.1067 raeburn 13059: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13060: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13061: "$topdir/media/",
13062: "$topdir/media/$topdir.mp4",
13063: "$topdir/media/FirstFrame.png",
13064: "$topdir/media/player.swf",
13065: "$topdir/media/swfobject.js",
13066: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13067: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13068: "$topdir/$topdir.mp4",
13069: "$topdir/$topdir\_config.xml",
13070: "$topdir/$topdir\_controller.swf",
13071: "$topdir/$topdir\_embed.css",
13072: "$topdir/$topdir\_First_Frame.png",
13073: "$topdir/$topdir\_player.html",
13074: "$topdir/$topdir\_Thumbnails.png",
13075: "$topdir/playerProductInstall.swf",
13076: "$topdir/scripts/",
13077: "$topdir/scripts/config_xml.js",
13078: "$topdir/scripts/handlebars.js",
13079: "$topdir/scripts/jquery-1.7.1.min.js",
13080: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13081: "$topdir/scripts/modernizr.js",
13082: "$topdir/scripts/player-min.js",
13083: "$topdir/scripts/swfobject.js",
13084: "$topdir/skins/",
13085: "$topdir/skins/configuration_express.xml",
13086: "$topdir/skins/express_show/",
13087: "$topdir/skins/express_show/player-min.css",
13088: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13089: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13090: "$topdir/$topdir.mp4",
13091: "$topdir/$topdir\_config.xml",
13092: "$topdir/$topdir\_controller.swf",
13093: "$topdir/$topdir\_embed.css",
13094: "$topdir/$topdir\_First_Frame.png",
13095: "$topdir/$topdir\_player.html",
13096: "$topdir/$topdir\_Thumbnails.png",
13097: "$topdir/playerProductInstall.swf",
13098: "$topdir/scripts/",
13099: "$topdir/scripts/config_xml.js",
13100: "$topdir/scripts/techsmith-smart-player.min.js",
13101: "$topdir/skins/",
13102: "$topdir/skins/configuration_express.xml",
13103: "$topdir/skins/express_show/",
13104: "$topdir/skins/express_show/spritesheet.min.css",
13105: "$topdir/skins/express_show/spritesheet.png",
13106: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13107: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13108: if (@diffs == 0) {
1.1164 raeburn 13109: $is_camtasia = 6;
13110: } else {
1.1197 raeburn 13111: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13112: if (@diffs == 0) {
13113: $is_camtasia = 8;
1.1197 raeburn 13114: } else {
13115: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13116: if (@diffs == 0) {
13117: $is_camtasia = 8;
13118: }
1.1164 raeburn 13119: }
1.1067 raeburn 13120: }
13121: }
13122: my $output;
13123: if ($is_camtasia) {
13124: $output = <<"ENDCAM";
13125: <script type="text/javascript" language="Javascript">
13126: // <![CDATA[
13127:
13128: function camtasiaToggle() {
13129: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13130: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13131: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13132: document.getElementById('camtasia_titles').style.display='block';
13133: } else {
13134: document.getElementById('camtasia_titles').style.display='none';
13135: }
13136: }
13137: }
13138: return;
13139: }
13140:
13141: // ]]>
13142: </script>
13143: <p>$lt{'camt'}</p>
13144: ENDCAM
1.1065 raeburn 13145: } else {
1.1067 raeburn 13146: $output = '<p>'.$lt{'this'};
13147: if ($info eq '') {
13148: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13149: } else {
13150: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13151: '<div><pre>'.$info.'</pre></div>';
13152: }
1.1065 raeburn 13153: }
1.1067 raeburn 13154: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13155: my $duplicates;
13156: my $num = 0;
13157: if (ref($dirlist) eq 'ARRAY') {
13158: foreach my $item (@{$dirlist}) {
13159: if (ref($item) eq 'ARRAY') {
13160: if (exists($toplevel{$item->[0]})) {
13161: $duplicates .=
13162: &start_data_table_row().
13163: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13164: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13165: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13166: 'value="1" />'.&mt('Yes').'</label>'.
13167: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13168: '<td>'.$item->[0].'</td>';
13169: if ($item->[2]) {
13170: $duplicates .= '<td>'.&mt('Directory').'</td>';
13171: } else {
13172: $duplicates .= '<td>'.&mt('File').'</td>';
13173: }
13174: $duplicates .= '<td>'.$item->[3].'</td>'.
13175: '<td>'.
13176: &Apache::lonlocal::locallocaltime($item->[4]).
13177: '</td>'.
13178: &end_data_table_row();
13179: $num ++;
13180: }
13181: }
13182: }
13183: }
13184: my $itemcount;
13185: if (@paths > 0) {
13186: $itemcount = scalar(@paths);
13187: } else {
13188: $itemcount = 1;
13189: }
1.1067 raeburn 13190: if ($is_camtasia) {
13191: $output .= $lt{'auto'}.'<br />'.
13192: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13193: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13194: $lt{'yes'}.'</label> <label>'.
13195: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13196: $lt{'no'}.'</label></span><br />'.
13197: '<div id="camtasia_titles" style="display:block">'.
13198: &Apache::lonhtmlcommon::start_pick_box().
13199: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13200: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13201: &Apache::lonhtmlcommon::row_closure().
13202: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13203: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13204: &Apache::lonhtmlcommon::row_closure(1).
13205: &Apache::lonhtmlcommon::end_pick_box().
13206: '</div>';
13207: }
1.1065 raeburn 13208: $output .=
13209: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13210: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13211: "\n";
1.1065 raeburn 13212: if ($duplicates ne '') {
13213: $output .= '<p><span class="LC_warning">'.
13214: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13215: &start_data_table().
13216: &start_data_table_header_row().
13217: '<th>'.&mt('Overwrite?').'</th>'.
13218: '<th>'.&mt('Name').'</th>'.
13219: '<th>'.&mt('Type').'</th>'.
13220: '<th>'.&mt('Size').'</th>'.
13221: '<th>'.&mt('Last modified').'</th>'.
13222: &end_data_table_header_row().
13223: $duplicates.
13224: &end_data_table().
13225: '</p>';
13226: }
1.1067 raeburn 13227: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13228: if (ref($hiddenelements) eq 'HASH') {
13229: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13230: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13231: }
13232: }
13233: $output .= <<"END";
1.1067 raeburn 13234: <br />
1.1053 raeburn 13235: <input type="submit" name="decompress" value="$lt{'extr'}" />
13236: </form>
13237: $noextract
13238: END
13239: return $output;
13240: }
13241:
1.1065 raeburn 13242: sub decompression_utility {
13243: my ($program) = @_;
13244: my @utilities = ('tar','gunzip','bunzip2','unzip');
13245: my $location;
13246: if (grep(/^\Q$program\E$/,@utilities)) {
13247: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13248: '/usr/sbin/') {
13249: if (-x $dir.$program) {
13250: $location = $dir.$program;
13251: last;
13252: }
13253: }
13254: }
13255: return $location;
13256: }
13257:
13258: sub list_archive_contents {
13259: my ($file,$pathsref) = @_;
13260: my (@cmd,$output);
13261: my $needsregexp;
13262: if ($file =~ /\.zip$/) {
13263: @cmd = (&decompression_utility('unzip'),"-l");
13264: $needsregexp = 1;
13265: } elsif (($file =~ m/\.tar\.gz$/) ||
13266: ($file =~ /\.tgz$/)) {
13267: @cmd = (&decompression_utility('tar'),"-ztf");
13268: } elsif ($file =~ /\.tar\.bz2$/) {
13269: @cmd = (&decompression_utility('tar'),"-jtf");
13270: } elsif ($file =~ m|\.tar$|) {
13271: @cmd = (&decompression_utility('tar'),"-tf");
13272: }
13273: if (@cmd) {
13274: undef($!);
13275: undef($@);
13276: if (open(my $fh,"-|", @cmd, $file)) {
13277: while (my $line = <$fh>) {
13278: $output .= $line;
13279: chomp($line);
13280: my $item;
13281: if ($needsregexp) {
13282: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13283: } else {
13284: $item = $line;
13285: }
13286: if ($item ne '') {
13287: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13288: push(@{$pathsref},$item);
13289: }
13290: }
13291: }
13292: close($fh);
13293: }
13294: }
13295: return $output;
13296: }
13297:
1.1053 raeburn 13298: sub decompress_uploaded_file {
13299: my ($file,$dir) = @_;
13300: &Apache::lonnet::appenv({'cgi.file' => $file});
13301: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13302: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13303: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13304: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13305: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13306: my $decompressed = $env{'cgi.decompressed'};
13307: &Apache::lonnet::delenv('cgi.file');
13308: &Apache::lonnet::delenv('cgi.dir');
13309: &Apache::lonnet::delenv('cgi.decompressed');
13310: return ($decompressed,$result);
13311: }
13312:
1.1055 raeburn 13313: sub process_decompression {
13314: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13315: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13316: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13317: &mt('Unexpected file path.').'</p>'."\n";
13318: }
13319: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13320: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13321: &mt('Unexpected course context.').'</p>'."\n";
13322: }
1.1293 raeburn 13323: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13324: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13325: &mt('Filename contained unexpected characters.').'</p>'."\n";
13326: }
1.1055 raeburn 13327: my ($dir,$error,$warning,$output);
1.1180 raeburn 13328: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13329: $error = &mt('Filename not a supported archive file type.').
13330: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13331: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13332: } else {
13333: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13334: if ($docuhome eq 'no_host') {
13335: $error = &mt('Could not determine home server for course.');
13336: } else {
13337: my @ids=&Apache::lonnet::current_machine_ids();
13338: my $currdir = "$dir_root/$destination";
13339: if (grep(/^\Q$docuhome\E$/,@ids)) {
13340: $dir = &LONCAPA::propath($docudom,$docuname).
13341: "$dir_root/$destination";
13342: } else {
13343: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13344: "$dir_root/$docudom/$docuname/$destination";
13345: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13346: $error = &mt('Archive file not found.');
13347: }
13348: }
1.1065 raeburn 13349: my (@to_overwrite,@to_skip);
13350: if ($env{'form.archive_overwrite_total'} > 0) {
13351: my $total = $env{'form.archive_overwrite_total'};
13352: for (my $i=0; $i<$total; $i++) {
13353: if ($env{'form.archive_overwrite_'.$i} == 1) {
13354: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13355: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13356: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13357: }
13358: }
13359: }
13360: my $numskip = scalar(@to_skip);
1.1292 raeburn 13361: my $numoverwrite = scalar(@to_overwrite);
13362: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13363: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13364: } elsif ($dir eq '') {
1.1055 raeburn 13365: $error = &mt('Directory containing archive file unavailable.');
13366: } elsif (!$error) {
1.1065 raeburn 13367: my ($decompressed,$display);
1.1292 raeburn 13368: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13369: my $tempdir = time.'_'.$$.int(rand(10000));
13370: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13371: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13372: ($decompressed,$display) =
13373: &decompress_uploaded_file($file,"$dir/$tempdir");
13374: foreach my $item (@to_skip) {
13375: if (($item ne '') && ($item !~ /\.\./)) {
13376: if (-f "$dir/$tempdir/$item") {
13377: unlink("$dir/$tempdir/$item");
13378: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13379: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13380: }
13381: }
13382: }
13383: foreach my $item (@to_overwrite) {
13384: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13385: if (($item ne '') && ($item !~ /\.\./)) {
13386: if (-f "$dir/$item") {
13387: unlink("$dir/$item");
13388: } elsif (-d "$dir/$item") {
1.1300 raeburn 13389: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13390: }
13391: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13392: }
1.1065 raeburn 13393: }
13394: }
1.1292 raeburn 13395: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13396: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13397: }
1.1065 raeburn 13398: }
13399: } else {
13400: ($decompressed,$display) =
13401: &decompress_uploaded_file($file,$dir);
13402: }
1.1055 raeburn 13403: if ($decompressed eq 'ok') {
1.1065 raeburn 13404: $output = '<p class="LC_info">'.
13405: &mt('Files extracted successfully from archive.').
13406: '</p>'."\n";
1.1055 raeburn 13407: my ($warning,$result,@contents);
13408: my ($newdirlistref,$newlisterror) =
13409: &Apache::lonnet::dirlist($currdir,$docudom,
13410: $docuname,1);
13411: my (%is_dir,%changes,@newitems);
13412: my $dirptr = 16384;
1.1065 raeburn 13413: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13414: foreach my $dir_line (@{$newdirlistref}) {
13415: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13416: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13417: push(@newitems,$item);
13418: if ($dirptr&$testdir) {
13419: $is_dir{$item} = 1;
13420: }
13421: $changes{$item} = 1;
13422: }
13423: }
13424: }
13425: if (keys(%changes) > 0) {
13426: foreach my $item (sort(@newitems)) {
13427: if ($changes{$item}) {
13428: push(@contents,$item);
13429: }
13430: }
13431: }
13432: if (@contents > 0) {
1.1067 raeburn 13433: my $wantform;
13434: unless ($env{'form.autoextract_camtasia'}) {
13435: $wantform = 1;
13436: }
1.1056 raeburn 13437: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13438: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13439: $currdir,\%is_dir,
13440: \%children,\%parent,
1.1056 raeburn 13441: \@contents,\%dirorder,
13442: \%titles,$wantform);
1.1055 raeburn 13443: if ($datatable ne '') {
13444: $output .= &archive_options_form('decompressed',$datatable,
13445: $count,$hiddenelem);
1.1065 raeburn 13446: my $startcount = 6;
1.1055 raeburn 13447: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13448: \%titles,\%children);
1.1055 raeburn 13449: }
1.1067 raeburn 13450: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13451: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13452: my %displayed;
13453: my $total = 1;
13454: $env{'form.archive_directory'} = [];
13455: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13456: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13457: $path =~ s{/$}{};
13458: my $item;
13459: if ($path ne '') {
13460: $item = "$path/$titles{$i}";
13461: } else {
13462: $item = $titles{$i};
13463: }
13464: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13465: if ($item eq $contents[0]) {
13466: push(@{$env{'form.archive_directory'}},$i);
13467: $env{'form.archive_'.$i} = 'display';
13468: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13469: $displayed{'folder'} = $i;
1.1164 raeburn 13470: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13471: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13472: $env{'form.archive_'.$i} = 'display';
13473: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13474: $displayed{'web'} = $i;
13475: } else {
1.1164 raeburn 13476: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13477: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13478: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13479: push(@{$env{'form.archive_directory'}},$i);
13480: }
13481: $env{'form.archive_'.$i} = 'dependency';
13482: }
13483: $total ++;
13484: }
13485: for (my $i=1; $i<$total; $i++) {
13486: next if ($i == $displayed{'web'});
13487: next if ($i == $displayed{'folder'});
13488: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13489: }
13490: $env{'form.phase'} = 'decompress_cleanup';
13491: $env{'form.archivedelete'} = 1;
13492: $env{'form.archive_count'} = $total-1;
13493: $output .=
13494: &process_extracted_files('coursedocs',$docudom,
13495: $docuname,$destination,
13496: $dir_root,$hiddenelem);
13497: }
1.1055 raeburn 13498: } else {
13499: $warning = &mt('No new items extracted from archive file.');
13500: }
13501: } else {
13502: $output = $display;
13503: $error = &mt('An error occurred during extraction from the archive file.');
13504: }
13505: }
13506: }
13507: }
13508: if ($error) {
13509: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13510: $error.'</p>'."\n";
13511: }
13512: if ($warning) {
13513: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13514: }
13515: return $output;
13516: }
13517:
13518: sub get_extracted {
1.1056 raeburn 13519: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13520: $titles,$wantform) = @_;
1.1055 raeburn 13521: my $count = 0;
13522: my $depth = 0;
13523: my $datatable;
1.1056 raeburn 13524: my @hierarchy;
1.1055 raeburn 13525: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13526: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13527: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13528: foreach my $item (@{$contents}) {
13529: $count ++;
1.1056 raeburn 13530: @{$dirorder->{$count}} = @hierarchy;
13531: $titles->{$count} = $item;
1.1055 raeburn 13532: &archive_hierarchy($depth,$count,$parent,$children);
13533: if ($wantform) {
13534: $datatable .= &archive_row($is_dir->{$item},$item,
13535: $currdir,$depth,$count);
13536: }
13537: if ($is_dir->{$item}) {
13538: $depth ++;
1.1056 raeburn 13539: push(@hierarchy,$count);
13540: $parent->{$depth} = $count;
1.1055 raeburn 13541: $datatable .=
13542: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13543: \$depth,\$count,\@hierarchy,$dirorder,
13544: $children,$parent,$titles,$wantform);
1.1055 raeburn 13545: $depth --;
1.1056 raeburn 13546: pop(@hierarchy);
1.1055 raeburn 13547: }
13548: }
13549: return ($count,$datatable);
13550: }
13551:
13552: sub recurse_extracted_archive {
1.1056 raeburn 13553: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13554: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13555: my $result='';
1.1056 raeburn 13556: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13557: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13558: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13559: return $result;
13560: }
13561: my $dirptr = 16384;
13562: my ($newdirlistref,$newlisterror) =
13563: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13564: if (ref($newdirlistref) eq 'ARRAY') {
13565: foreach my $dir_line (@{$newdirlistref}) {
13566: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13567: unless ($item =~ /^\.+$/) {
13568: $$count ++;
1.1056 raeburn 13569: @{$dirorder->{$$count}} = @{$hierarchy};
13570: $titles->{$$count} = $item;
1.1055 raeburn 13571: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13572:
1.1055 raeburn 13573: my $is_dir;
13574: if ($dirptr&$testdir) {
13575: $is_dir = 1;
13576: }
13577: if ($wantform) {
13578: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13579: }
13580: if ($is_dir) {
13581: $$depth ++;
1.1056 raeburn 13582: push(@{$hierarchy},$$count);
13583: $parent->{$$depth} = $$count;
1.1055 raeburn 13584: $result .=
13585: &recurse_extracted_archive("$currdir/$item",$docudom,
13586: $docuname,$depth,$count,
1.1056 raeburn 13587: $hierarchy,$dirorder,$children,
13588: $parent,$titles,$wantform);
1.1055 raeburn 13589: $$depth --;
1.1056 raeburn 13590: pop(@{$hierarchy});
1.1055 raeburn 13591: }
13592: }
13593: }
13594: }
13595: return $result;
13596: }
13597:
13598: sub archive_hierarchy {
13599: my ($depth,$count,$parent,$children) =@_;
13600: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13601: if (exists($parent->{$depth})) {
13602: $children->{$parent->{$depth}} .= $count.':';
13603: }
13604: }
13605: return;
13606: }
13607:
13608: sub archive_row {
13609: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13610: my ($name) = ($item =~ m{([^/]+)$});
13611: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13612: 'display' => 'Add as file',
1.1055 raeburn 13613: 'dependency' => 'Include as dependency',
13614: 'discard' => 'Discard',
13615: );
13616: if ($is_dir) {
1.1059 raeburn 13617: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13618: }
1.1056 raeburn 13619: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13620: my $offset = 0;
1.1055 raeburn 13621: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13622: $offset ++;
1.1065 raeburn 13623: if ($action ne 'display') {
13624: $offset ++;
13625: }
1.1055 raeburn 13626: $output .= '<td><span class="LC_nobreak">'.
13627: '<label><input type="radio" name="archive_'.$count.
13628: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13629: my $text = $choices{$action};
13630: if ($is_dir) {
13631: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13632: if ($action eq 'display') {
1.1059 raeburn 13633: $text = &mt('Add as folder');
1.1055 raeburn 13634: }
1.1056 raeburn 13635: } else {
13636: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13637:
13638: }
13639: $output .= ' /> '.$choices{$action}.'</label></span>';
13640: if ($action eq 'dependency') {
13641: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13642: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13643: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13644: '<option value=""></option>'."\n".
13645: '</select>'."\n".
13646: '</div>';
1.1059 raeburn 13647: } elsif ($action eq 'display') {
13648: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13649: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13650: '</div>';
1.1055 raeburn 13651: }
1.1056 raeburn 13652: $output .= '</td>';
1.1055 raeburn 13653: }
13654: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13655: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13656: for (my $i=0; $i<$depth; $i++) {
13657: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13658: }
13659: if ($is_dir) {
13660: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13661: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13662: } else {
13663: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13664: }
13665: $output .= ' '.$name.'</td>'."\n".
13666: &end_data_table_row();
13667: return $output;
13668: }
13669:
13670: sub archive_options_form {
1.1065 raeburn 13671: my ($form,$display,$count,$hiddenelem) = @_;
13672: my %lt = &Apache::lonlocal::texthash(
13673: perm => 'Permanently remove archive file?',
13674: hows => 'How should each extracted item be incorporated in the course?',
13675: cont => 'Content actions for all',
13676: addf => 'Add as folder/file',
13677: incd => 'Include as dependency for a displayed file',
13678: disc => 'Discard',
13679: no => 'No',
13680: yes => 'Yes',
13681: save => 'Save',
13682: );
13683: my $output = <<"END";
13684: <form name="$form" method="post" action="">
13685: <p><span class="LC_nobreak">$lt{'perm'}
13686: <label>
13687: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13688: </label>
13689:
13690: <label>
13691: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13692: </span>
13693: </p>
13694: <input type="hidden" name="phase" value="decompress_cleanup" />
13695: <br />$lt{'hows'}
13696: <div class="LC_columnSection">
13697: <fieldset>
13698: <legend>$lt{'cont'}</legend>
13699: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13700: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13701: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13702: </fieldset>
13703: </div>
13704: END
13705: return $output.
1.1055 raeburn 13706: &start_data_table()."\n".
1.1065 raeburn 13707: $display."\n".
1.1055 raeburn 13708: &end_data_table()."\n".
13709: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13710: $hiddenelem.
1.1065 raeburn 13711: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13712: '</form>';
13713: }
13714:
13715: sub archive_javascript {
1.1056 raeburn 13716: my ($startcount,$numitems,$titles,$children) = @_;
13717: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13718: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13719: my $scripttag = <<START;
13720: <script type="text/javascript">
13721: // <![CDATA[
13722:
13723: function checkAll(form,prefix) {
13724: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13725: for (var i=0; i < form.elements.length; i++) {
13726: var id = form.elements[i].id;
13727: if ((id != '') && (id != undefined)) {
13728: if (idstr.test(id)) {
13729: if (form.elements[i].type == 'radio') {
13730: form.elements[i].checked = true;
1.1056 raeburn 13731: var nostart = i-$startcount;
1.1059 raeburn 13732: var offset = nostart%7;
13733: var count = (nostart-offset)/7;
1.1056 raeburn 13734: dependencyCheck(form,count,offset);
1.1055 raeburn 13735: }
13736: }
13737: }
13738: }
13739: }
13740:
13741: function propagateCheck(form,count) {
13742: if (count > 0) {
1.1059 raeburn 13743: var startelement = $startcount + ((count-1) * 7);
13744: for (var j=1; j<6; j++) {
13745: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13746: var item = startelement + j;
13747: if (form.elements[item].type == 'radio') {
13748: if (form.elements[item].checked) {
13749: containerCheck(form,count,j);
13750: break;
13751: }
1.1055 raeburn 13752: }
13753: }
13754: }
13755: }
13756: }
13757:
13758: numitems = $numitems
1.1056 raeburn 13759: var titles = new Array(numitems);
13760: var parents = new Array(numitems);
1.1055 raeburn 13761: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13762: parents[i] = new Array;
1.1055 raeburn 13763: }
1.1059 raeburn 13764: var maintitle = '$maintitle';
1.1055 raeburn 13765:
13766: START
13767:
1.1056 raeburn 13768: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13769: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13770: for (my $i=0; $i<@contents; $i ++) {
13771: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13772: }
13773: }
13774:
1.1056 raeburn 13775: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13776: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13777: }
13778:
1.1055 raeburn 13779: $scripttag .= <<END;
13780:
13781: function containerCheck(form,count,offset) {
13782: if (count > 0) {
1.1056 raeburn 13783: dependencyCheck(form,count,offset);
1.1059 raeburn 13784: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13785: form.elements[item].checked = true;
13786: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13787: if (parents[count].length > 0) {
13788: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13789: containerCheck(form,parents[count][j],offset);
13790: }
13791: }
13792: }
13793: }
13794: }
13795:
13796: function dependencyCheck(form,count,offset) {
13797: if (count > 0) {
1.1059 raeburn 13798: var chosen = (offset+$startcount)+7*(count-1);
13799: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13800: var currtype = form.elements[depitem].type;
13801: if (form.elements[chosen].value == 'dependency') {
13802: document.getElementById('arc_depon_'+count).style.display='block';
13803: form.elements[depitem].options.length = 0;
13804: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13805: for (var i=1; i<=numitems; i++) {
13806: if (i == count) {
13807: continue;
13808: }
1.1059 raeburn 13809: var startelement = $startcount + (i-1) * 7;
13810: for (var j=1; j<6; j++) {
13811: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13812: var item = startelement + j;
13813: if (form.elements[item].type == 'radio') {
13814: if (form.elements[item].checked) {
13815: if (form.elements[item].value == 'display') {
13816: var n = form.elements[depitem].options.length;
13817: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13818: }
13819: }
13820: }
13821: }
13822: }
13823: }
13824: } else {
13825: document.getElementById('arc_depon_'+count).style.display='none';
13826: form.elements[depitem].options.length = 0;
13827: form.elements[depitem].options[0] = new Option('Select','',true,true);
13828: }
1.1059 raeburn 13829: titleCheck(form,count,offset);
1.1056 raeburn 13830: }
13831: }
13832:
13833: function propagateSelect(form,count,offset) {
13834: if (count > 0) {
1.1065 raeburn 13835: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13836: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13837: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13838: if (parents[count].length > 0) {
13839: for (var j=0; j<parents[count].length; j++) {
13840: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13841: }
13842: }
13843: }
13844: }
13845: }
1.1056 raeburn 13846:
13847: function containerSelect(form,count,offset,picked) {
13848: if (count > 0) {
1.1065 raeburn 13849: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13850: if (form.elements[item].type == 'radio') {
13851: if (form.elements[item].value == 'dependency') {
13852: if (form.elements[item+1].type == 'select-one') {
13853: for (var i=0; i<form.elements[item+1].options.length; i++) {
13854: if (form.elements[item+1].options[i].value == picked) {
13855: form.elements[item+1].selectedIndex = i;
13856: break;
13857: }
13858: }
13859: }
13860: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13861: if (parents[count].length > 0) {
13862: for (var j=0; j<parents[count].length; j++) {
13863: containerSelect(form,parents[count][j],offset,picked);
13864: }
13865: }
13866: }
13867: }
13868: }
13869: }
13870: }
13871:
1.1059 raeburn 13872: function titleCheck(form,count,offset) {
13873: if (count > 0) {
13874: var chosen = (offset+$startcount)+7*(count-1);
13875: var depitem = $startcount + ((count-1) * 7) + 2;
13876: var currtype = form.elements[depitem].type;
13877: if (form.elements[chosen].value == 'display') {
13878: document.getElementById('arc_title_'+count).style.display='block';
13879: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13880: document.getElementById('archive_title_'+count).value=maintitle;
13881: }
13882: } else {
13883: document.getElementById('arc_title_'+count).style.display='none';
13884: if (currtype == 'text') {
13885: document.getElementById('archive_title_'+count).value='';
13886: }
13887: }
13888: }
13889: return;
13890: }
13891:
1.1055 raeburn 13892: // ]]>
13893: </script>
13894: END
13895: return $scripttag;
13896: }
13897:
13898: sub process_extracted_files {
1.1067 raeburn 13899: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13900: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13901: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13902: my @ids=&Apache::lonnet::current_machine_ids();
13903: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13904: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13905: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13906: if (grep(/^\Q$docuhome\E$/,@ids)) {
13907: $prefix = &LONCAPA::propath($docudom,$docuname);
13908: $pathtocheck = "$dir_root/$destination";
13909: $dir = $dir_root;
13910: $ishome = 1;
13911: } else {
13912: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13913: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13914: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13915: }
13916: my $currdir = "$dir_root/$destination";
13917: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13918: if ($env{'form.folderpath'}) {
13919: my @items = split('&',$env{'form.folderpath'});
13920: $folders{'0'} = $items[-2];
1.1099 raeburn 13921: if ($env{'form.folderpath'} =~ /\:1$/) {
13922: $containers{'0'}='page';
13923: } else {
13924: $containers{'0'}='sequence';
13925: }
1.1055 raeburn 13926: }
13927: my @archdirs = &get_env_multiple('form.archive_directory');
13928: if ($numitems) {
13929: for (my $i=1; $i<=$numitems; $i++) {
13930: my $path = $env{'form.archive_content_'.$i};
13931: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13932: my $item = $1;
13933: $toplevelitems{$item} = $i;
13934: if (grep(/^\Q$i\E$/,@archdirs)) {
13935: $is_dir{$item} = 1;
13936: }
13937: }
13938: }
13939: }
1.1067 raeburn 13940: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13941: if (keys(%toplevelitems) > 0) {
13942: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13943: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13944: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13945: }
1.1066 raeburn 13946: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13947: if ($numitems) {
13948: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13949: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13950: my $path = $env{'form.archive_content_'.$i};
13951: if ($path =~ /^\Q$pathtocheck\E/) {
13952: if ($env{'form.archive_'.$i} eq 'discard') {
13953: if ($prefix ne '' && $path ne '') {
13954: if (-e $prefix.$path) {
1.1066 raeburn 13955: if ((@archdirs > 0) &&
13956: (grep(/^\Q$i\E$/,@archdirs))) {
13957: $todeletedir{$prefix.$path} = 1;
13958: } else {
13959: $todelete{$prefix.$path} = 1;
13960: }
1.1055 raeburn 13961: }
13962: }
13963: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13964: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13965: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13966: $docstitle = $env{'form.archive_title_'.$i};
13967: if ($docstitle eq '') {
13968: $docstitle = $title;
13969: }
1.1055 raeburn 13970: $outer = 0;
1.1056 raeburn 13971: if (ref($dirorder{$i}) eq 'ARRAY') {
13972: if (@{$dirorder{$i}} > 0) {
13973: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13974: if ($env{'form.archive_'.$item} eq 'display') {
13975: $outer = $item;
13976: last;
13977: }
13978: }
13979: }
13980: }
13981: my ($errtext,$fatal) =
13982: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13983: '/'.$folders{$outer}.'.'.
13984: $containers{$outer});
13985: next if ($fatal);
13986: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13987: if ($context eq 'coursedocs') {
1.1056 raeburn 13988: $mapinner{$i} = time;
1.1055 raeburn 13989: $folders{$i} = 'default_'.$mapinner{$i};
13990: $containers{$i} = 'sequence';
13991: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13992: $folders{$i}.'.'.$containers{$i};
13993: my $newidx = &LONCAPA::map::getresidx();
13994: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13995: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13996: push(@LONCAPA::map::order,$newidx);
13997: my ($outtext,$errtext) =
13998: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13999: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14000: '.'.$containers{$outer},1,1);
1.1056 raeburn 14001: $newseqid{$i} = $newidx;
1.1067 raeburn 14002: unless ($errtext) {
1.1294 raeburn 14003: $result .= '<li>'.&mt('Folder: [_1] added to course',
14004: &HTML::Entities::encode($docstitle,'<>&"')).
14005: '</li>'."\n";
1.1067 raeburn 14006: }
1.1055 raeburn 14007: }
14008: } else {
14009: if ($context eq 'coursedocs') {
14010: my $newidx=&LONCAPA::map::getresidx();
14011: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14012: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14013: $title;
1.1294 raeburn 14014: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
14015: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14016: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14017: }
14018: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14019: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14020: }
14021: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14022: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14023: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14024: unless ($ishome) {
14025: my $fetch = "$newdest{$i}/$title";
14026: $fetch =~ s/^\Q$prefix$dir\E//;
14027: $prompttofetch{$fetch} = 1;
14028: }
1.1292 raeburn 14029: }
1.1067 raeburn 14030: }
1.1294 raeburn 14031: $LONCAPA::map::resources[$newidx]=
14032: $docstitle.':'.$url.':false:normal:res';
14033: push(@LONCAPA::map::order, $newidx);
14034: my ($outtext,$errtext)=
14035: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14036: $docuname.'/'.$folders{$outer}.
14037: '.'.$containers{$outer},1,1);
14038: unless ($errtext) {
14039: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14040: $result .= '<li>'.&mt('File: [_1] added to course',
14041: &HTML::Entities::encode($docstitle,'<>&"')).
14042: '</li>'."\n";
14043: }
1.1067 raeburn 14044: }
1.1294 raeburn 14045: } else {
14046: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14047: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14048: }
1.1055 raeburn 14049: }
14050: }
1.1086 raeburn 14051: }
14052: } else {
1.1294 raeburn 14053: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14054: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14055: }
14056: }
14057: for (my $i=1; $i<=$numitems; $i++) {
14058: next unless ($env{'form.archive_'.$i} eq 'dependency');
14059: my $path = $env{'form.archive_content_'.$i};
14060: if ($path =~ /^\Q$pathtocheck\E/) {
14061: my ($title) = ($path =~ m{/([^/]+)$});
14062: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14063: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14064: if (ref($dirorder{$i}) eq 'ARRAY') {
14065: my ($itemidx,$fullpath,$relpath);
14066: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14067: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14068: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14069: if ($dirorder{$i}->[$j] eq $container) {
14070: $itemidx = $j;
1.1056 raeburn 14071: }
14072: }
1.1086 raeburn 14073: }
14074: if ($itemidx eq '') {
14075: $itemidx = 0;
14076: }
14077: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14078: if ($mapinner{$referrer{$i}}) {
14079: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14080: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14081: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14082: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14083: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14084: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14085: if (!-e $fullpath) {
14086: mkdir($fullpath,0755);
1.1056 raeburn 14087: }
14088: }
1.1086 raeburn 14089: } else {
14090: last;
1.1056 raeburn 14091: }
1.1086 raeburn 14092: }
14093: }
14094: } elsif ($newdest{$referrer{$i}}) {
14095: $fullpath = $newdest{$referrer{$i}};
14096: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14097: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14098: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14099: last;
14100: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14101: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14102: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14103: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14104: if (!-e $fullpath) {
14105: mkdir($fullpath,0755);
1.1056 raeburn 14106: }
14107: }
1.1086 raeburn 14108: } else {
14109: last;
1.1056 raeburn 14110: }
1.1055 raeburn 14111: }
14112: }
1.1086 raeburn 14113: if ($fullpath ne '') {
14114: if (-e "$prefix$path") {
1.1292 raeburn 14115: unless (rename("$prefix$path","$fullpath/$title")) {
14116: $warning .= &mt('Failed to rename dependency').'<br />';
14117: }
1.1086 raeburn 14118: }
14119: if (-e "$fullpath/$title") {
14120: my $showpath;
14121: if ($relpath ne '') {
14122: $showpath = "$relpath/$title";
14123: } else {
14124: $showpath = "/$title";
14125: }
1.1294 raeburn 14126: $result .= '<li>'.&mt('[_1] included as a dependency',
14127: &HTML::Entities::encode($showpath,'<>&"')).
14128: '</li>'."\n";
1.1292 raeburn 14129: unless ($ishome) {
14130: my $fetch = "$fullpath/$title";
14131: $fetch =~ s/^\Q$prefix$dir\E//;
14132: $prompttofetch{$fetch} = 1;
14133: }
1.1086 raeburn 14134: }
14135: }
1.1055 raeburn 14136: }
1.1086 raeburn 14137: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14138: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14139: &HTML::Entities::encode($path,'<>&"'),
14140: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14141: '<br />';
1.1055 raeburn 14142: }
14143: } else {
1.1294 raeburn 14144: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14145: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14146: }
14147: }
14148: if (keys(%todelete)) {
14149: foreach my $key (keys(%todelete)) {
14150: unlink($key);
1.1066 raeburn 14151: }
14152: }
14153: if (keys(%todeletedir)) {
14154: foreach my $key (keys(%todeletedir)) {
14155: rmdir($key);
14156: }
14157: }
14158: foreach my $dir (sort(keys(%is_dir))) {
14159: if (($pathtocheck ne '') && ($dir ne '')) {
14160: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14161: }
14162: }
1.1067 raeburn 14163: if ($result ne '') {
14164: $output .= '<ul>'."\n".
14165: $result."\n".
14166: '</ul>';
14167: }
14168: unless ($ishome) {
14169: my $replicationfail;
14170: foreach my $item (keys(%prompttofetch)) {
14171: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14172: unless ($fetchresult eq 'ok') {
14173: $replicationfail .= '<li>'.$item.'</li>'."\n";
14174: }
14175: }
14176: if ($replicationfail) {
14177: $output .= '<p class="LC_error">'.
14178: &mt('Course home server failed to retrieve:').'<ul>'.
14179: $replicationfail.
14180: '</ul></p>';
14181: }
14182: }
1.1055 raeburn 14183: } else {
14184: $warning = &mt('No items found in archive.');
14185: }
14186: if ($error) {
14187: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14188: $error.'</p>'."\n";
14189: }
14190: if ($warning) {
14191: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14192: }
14193: return $output;
14194: }
14195:
1.1066 raeburn 14196: sub cleanup_empty_dirs {
14197: my ($path) = @_;
14198: if (($path ne '') && (-d $path)) {
14199: if (opendir(my $dirh,$path)) {
14200: my @dircontents = grep(!/^\./,readdir($dirh));
14201: my $numitems = 0;
14202: foreach my $item (@dircontents) {
14203: if (-d "$path/$item") {
1.1111 raeburn 14204: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14205: if (-e "$path/$item") {
14206: $numitems ++;
14207: }
14208: } else {
14209: $numitems ++;
14210: }
14211: }
14212: if ($numitems == 0) {
14213: rmdir($path);
14214: }
14215: closedir($dirh);
14216: }
14217: }
14218: return;
14219: }
14220:
1.41 ng 14221: =pod
1.45 matthew 14222:
1.1162 raeburn 14223: =item * &get_folder_hierarchy()
1.1068 raeburn 14224:
14225: Provides hierarchy of names of folders/sub-folders containing the current
14226: item,
14227:
14228: Inputs: 3
14229: - $navmap - navmaps object
14230:
14231: - $map - url for map (either the trigger itself, or map containing
14232: the resource, which is the trigger).
14233:
14234: - $showitem - 1 => show title for map itself; 0 => do not show.
14235:
14236: Outputs: 1 @pathitems - array of folder/subfolder names.
14237:
14238: =cut
14239:
14240: sub get_folder_hierarchy {
14241: my ($navmap,$map,$showitem) = @_;
14242: my @pathitems;
14243: if (ref($navmap)) {
14244: my $mapres = $navmap->getResourceByUrl($map);
14245: if (ref($mapres)) {
14246: my $pcslist = $mapres->map_hierarchy();
14247: if ($pcslist ne '') {
14248: my @pcs = split(/,/,$pcslist);
14249: foreach my $pc (@pcs) {
14250: if ($pc == 1) {
1.1129 raeburn 14251: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14252: } else {
14253: my $res = $navmap->getByMapPc($pc);
14254: if (ref($res)) {
14255: my $title = $res->compTitle();
14256: $title =~ s/\W+/_/g;
14257: if ($title ne '') {
14258: push(@pathitems,$title);
14259: }
14260: }
14261: }
14262: }
14263: }
1.1071 raeburn 14264: if ($showitem) {
14265: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14266: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14267: } else {
14268: my $maptitle = $mapres->compTitle();
14269: $maptitle =~ s/\W+/_/g;
14270: if ($maptitle ne '') {
14271: push(@pathitems,$maptitle);
14272: }
1.1068 raeburn 14273: }
14274: }
14275: }
14276: }
14277: return @pathitems;
14278: }
14279:
14280: =pod
14281:
1.1015 raeburn 14282: =item * &get_turnedin_filepath()
14283:
14284: Determines path in a user's portfolio file for storage of files uploaded
14285: to a specific essayresponse or dropbox item.
14286:
14287: Inputs: 3 required + 1 optional.
14288: $symb is symb for resource, $uname and $udom are for current user (required).
14289: $caller is optional (can be "submission", if routine is called when storing
14290: an upoaded file when "Submit Answer" button was pressed).
14291:
14292: Returns array containing $path and $multiresp.
14293: $path is path in portfolio. $multiresp is 1 if this resource contains more
14294: than one file upload item. Callers of routine should append partid as a
14295: subdirectory to $path in cases where $multiresp is 1.
14296:
14297: Called by: homework/essayresponse.pm and homework/structuretags.pm
14298:
14299: =cut
14300:
14301: sub get_turnedin_filepath {
14302: my ($symb,$uname,$udom,$caller) = @_;
14303: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14304: my $turnindir;
14305: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14306: $turnindir = $userhash{'turnindir'};
14307: my ($path,$multiresp);
14308: if ($turnindir eq '') {
14309: if ($caller eq 'submission') {
14310: $turnindir = &mt('turned in');
14311: $turnindir =~ s/\W+/_/g;
14312: my %newhash = (
14313: 'turnindir' => $turnindir,
14314: );
14315: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14316: }
14317: }
14318: if ($turnindir ne '') {
14319: $path = '/'.$turnindir.'/';
14320: my ($multipart,$turnin,@pathitems);
14321: my $navmap = Apache::lonnavmaps::navmap->new();
14322: if (defined($navmap)) {
14323: my $mapres = $navmap->getResourceByUrl($map);
14324: if (ref($mapres)) {
14325: my $pcslist = $mapres->map_hierarchy();
14326: if ($pcslist ne '') {
14327: foreach my $pc (split(/,/,$pcslist)) {
14328: my $res = $navmap->getByMapPc($pc);
14329: if (ref($res)) {
14330: my $title = $res->compTitle();
14331: $title =~ s/\W+/_/g;
14332: if ($title ne '') {
1.1149 raeburn 14333: if (($pc > 1) && (length($title) > 12)) {
14334: $title = substr($title,0,12);
14335: }
1.1015 raeburn 14336: push(@pathitems,$title);
14337: }
14338: }
14339: }
14340: }
14341: my $maptitle = $mapres->compTitle();
14342: $maptitle =~ s/\W+/_/g;
14343: if ($maptitle ne '') {
1.1149 raeburn 14344: if (length($maptitle) > 12) {
14345: $maptitle = substr($maptitle,0,12);
14346: }
1.1015 raeburn 14347: push(@pathitems,$maptitle);
14348: }
14349: unless ($env{'request.state'} eq 'construct') {
14350: my $res = $navmap->getBySymb($symb);
14351: if (ref($res)) {
14352: my $partlist = $res->parts();
14353: my $totaluploads = 0;
14354: if (ref($partlist) eq 'ARRAY') {
14355: foreach my $part (@{$partlist}) {
14356: my @types = $res->responseType($part);
14357: my @ids = $res->responseIds($part);
14358: for (my $i=0; $i < scalar(@ids); $i++) {
14359: if ($types[$i] eq 'essay') {
14360: my $partid = $part.'_'.$ids[$i];
14361: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14362: $totaluploads ++;
14363: }
14364: }
14365: }
14366: }
14367: if ($totaluploads > 1) {
14368: $multiresp = 1;
14369: }
14370: }
14371: }
14372: }
14373: } else {
14374: return;
14375: }
14376: } else {
14377: return;
14378: }
14379: my $restitle=&Apache::lonnet::gettitle($symb);
14380: $restitle =~ s/\W+/_/g;
14381: if ($restitle eq '') {
14382: $restitle = ($resurl =~ m{/[^/]+$});
14383: if ($restitle eq '') {
14384: $restitle = time;
14385: }
14386: }
1.1149 raeburn 14387: if (length($restitle) > 12) {
14388: $restitle = substr($restitle,0,12);
14389: }
1.1015 raeburn 14390: push(@pathitems,$restitle);
14391: $path .= join('/',@pathitems);
14392: }
14393: return ($path,$multiresp);
14394: }
14395:
14396: =pod
14397:
1.464 albertel 14398: =back
1.41 ng 14399:
1.112 bowersj2 14400: =head1 CSV Upload/Handling functions
1.38 albertel 14401:
1.41 ng 14402: =over 4
14403:
1.648 raeburn 14404: =item * &upfile_store($r)
1.41 ng 14405:
14406: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14407: needs $env{'form.upfile'}
1.41 ng 14408: returns $datatoken to be put into hidden field
14409:
14410: =cut
1.31 albertel 14411:
14412: sub upfile_store {
14413: my $r=shift;
1.258 albertel 14414: $env{'form.upfile'}=~s/\r/\n/gs;
14415: $env{'form.upfile'}=~s/\f/\n/gs;
14416: $env{'form.upfile'}=~s/\n+/\n/gs;
14417: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14418:
1.1299 raeburn 14419: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14420: '_enroll_'.$env{'request.course.id'}.'_'.
14421: time.'_'.$$);
14422: return if ($datatoken eq '');
14423:
1.31 albertel 14424: {
1.158 raeburn 14425: my $datafile = $r->dir_config('lonDaemons').
14426: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14427: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14428: print $fh $env{'form.upfile'};
1.158 raeburn 14429: close($fh);
14430: }
1.31 albertel 14431: }
14432: return $datatoken;
14433: }
14434:
1.56 matthew 14435: =pod
14436:
1.1290 raeburn 14437: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14438:
14439: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14440: $datatoken is the name to assign to the temporary file.
1.258 albertel 14441: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14442:
14443: =cut
1.31 albertel 14444:
14445: sub load_tmp_file {
1.1290 raeburn 14446: my ($r,$datatoken) = @_;
14447: return if ($datatoken eq '');
1.31 albertel 14448: my @studentdata=();
14449: {
1.158 raeburn 14450: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14451: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14452: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14453: @studentdata=<$fh>;
14454: close($fh);
14455: }
1.31 albertel 14456: }
1.258 albertel 14457: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14458: }
14459:
1.1290 raeburn 14460: sub valid_datatoken {
14461: my ($datatoken) = @_;
1.1325 raeburn 14462: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14463: return $datatoken;
14464: }
14465: return;
14466: }
14467:
1.56 matthew 14468: =pod
14469:
1.648 raeburn 14470: =item * &upfile_record_sep()
1.41 ng 14471:
14472: Separate uploaded file into records
14473: returns array of records,
1.258 albertel 14474: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14475:
14476: =cut
1.31 albertel 14477:
14478: sub upfile_record_sep {
1.258 albertel 14479: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14480: } else {
1.248 albertel 14481: my @records;
1.258 albertel 14482: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14483: if ($line=~/^\s*$/) { next; }
14484: push(@records,$line);
14485: }
14486: return @records;
1.31 albertel 14487: }
14488: }
14489:
1.56 matthew 14490: =pod
14491:
1.648 raeburn 14492: =item * &record_sep($record)
1.41 ng 14493:
1.258 albertel 14494: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14495:
14496: =cut
14497:
1.263 www 14498: sub takeleft {
14499: my $index=shift;
14500: return substr('0000'.$index,-4,4);
14501: }
14502:
1.31 albertel 14503: sub record_sep {
14504: my $record=shift;
14505: my %components=();
1.258 albertel 14506: if ($env{'form.upfiletype'} eq 'xml') {
14507: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14508: my $i=0;
1.356 albertel 14509: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14510: $field=~s/^(\"|\')//;
14511: $field=~s/(\"|\')$//;
1.263 www 14512: $components{&takeleft($i)}=$field;
1.31 albertel 14513: $i++;
14514: }
1.258 albertel 14515: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14516: my $i=0;
1.356 albertel 14517: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14518: $field=~s/^(\"|\')//;
14519: $field=~s/(\"|\')$//;
1.263 www 14520: $components{&takeleft($i)}=$field;
1.31 albertel 14521: $i++;
14522: }
14523: } else {
1.561 www 14524: my $separator=',';
1.480 banghart 14525: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14526: $separator=';';
1.480 banghart 14527: }
1.31 albertel 14528: my $i=0;
1.561 www 14529: # the character we are looking for to indicate the end of a quote or a record
14530: my $looking_for=$separator;
14531: # do not add the characters to the fields
14532: my $ignore=0;
14533: # we just encountered a separator (or the beginning of the record)
14534: my $just_found_separator=1;
14535: # store the field we are working on here
14536: my $field='';
14537: # work our way through all characters in record
14538: foreach my $character ($record=~/(.)/g) {
14539: if ($character eq $looking_for) {
14540: if ($character ne $separator) {
14541: # Found the end of a quote, again looking for separator
14542: $looking_for=$separator;
14543: $ignore=1;
14544: } else {
14545: # Found a separator, store away what we got
14546: $components{&takeleft($i)}=$field;
14547: $i++;
14548: $just_found_separator=1;
14549: $ignore=0;
14550: $field='';
14551: }
14552: next;
14553: }
14554: # single or double quotation marks after a separator indicate beginning of a quote
14555: # we are now looking for the end of the quote and need to ignore separators
14556: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14557: $looking_for=$character;
14558: next;
14559: }
14560: # ignore would be true after we reached the end of a quote
14561: if ($ignore) { next; }
14562: if (($just_found_separator) && ($character=~/\s/)) { next; }
14563: $field.=$character;
14564: $just_found_separator=0;
1.31 albertel 14565: }
1.561 www 14566: # catch the very last entry, since we never encountered the separator
14567: $components{&takeleft($i)}=$field;
1.31 albertel 14568: }
14569: return %components;
14570: }
14571:
1.144 matthew 14572: ######################################################
14573: ######################################################
14574:
1.56 matthew 14575: =pod
14576:
1.648 raeburn 14577: =item * &upfile_select_html()
1.41 ng 14578:
1.144 matthew 14579: Return HTML code to select a file from the users machine and specify
14580: the file type.
1.41 ng 14581:
14582: =cut
14583:
1.144 matthew 14584: ######################################################
14585: ######################################################
1.31 albertel 14586: sub upfile_select_html {
1.144 matthew 14587: my %Types = (
14588: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14589: semisv => &mt('Semicolon separated values'),
1.144 matthew 14590: space => &mt('Space separated'),
14591: tab => &mt('Tabulator separated'),
14592: # xml => &mt('HTML/XML'),
14593: );
14594: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14595: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14596: foreach my $type (sort(keys(%Types))) {
14597: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14598: }
14599: $Str .= "</select>\n";
14600: return $Str;
1.31 albertel 14601: }
14602:
1.301 albertel 14603: sub get_samples {
14604: my ($records,$toget) = @_;
14605: my @samples=({});
14606: my $got=0;
14607: foreach my $rec (@$records) {
14608: my %temp = &record_sep($rec);
14609: if (! grep(/\S/, values(%temp))) { next; }
14610: if (%temp) {
14611: $samples[$got]=\%temp;
14612: $got++;
14613: if ($got == $toget) { last; }
14614: }
14615: }
14616: return \@samples;
14617: }
14618:
1.144 matthew 14619: ######################################################
14620: ######################################################
14621:
1.56 matthew 14622: =pod
14623:
1.648 raeburn 14624: =item * &csv_print_samples($r,$records)
1.41 ng 14625:
14626: Prints a table of sample values from each column uploaded $r is an
14627: Apache Request ref, $records is an arrayref from
14628: &Apache::loncommon::upfile_record_sep
14629:
14630: =cut
14631:
1.144 matthew 14632: ######################################################
14633: ######################################################
1.31 albertel 14634: sub csv_print_samples {
14635: my ($r,$records) = @_;
1.662 bisitz 14636: my $samples = &get_samples($records,5);
1.301 albertel 14637:
1.594 raeburn 14638: $r->print(&mt('Samples').'<br />'.&start_data_table().
14639: &start_data_table_header_row());
1.356 albertel 14640: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14641: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14642: $r->print(&end_data_table_header_row());
1.301 albertel 14643: foreach my $hash (@$samples) {
1.594 raeburn 14644: $r->print(&start_data_table_row());
1.356 albertel 14645: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14646: $r->print('<td>');
1.356 albertel 14647: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14648: $r->print('</td>');
14649: }
1.594 raeburn 14650: $r->print(&end_data_table_row());
1.31 albertel 14651: }
1.594 raeburn 14652: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14653: }
14654:
1.144 matthew 14655: ######################################################
14656: ######################################################
14657:
1.56 matthew 14658: =pod
14659:
1.648 raeburn 14660: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14661:
14662: Prints a table to create associations between values and table columns.
1.144 matthew 14663:
1.41 ng 14664: $r is an Apache Request ref,
14665: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14666: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14667:
14668: =cut
14669:
1.144 matthew 14670: ######################################################
14671: ######################################################
1.31 albertel 14672: sub csv_print_select_table {
14673: my ($r,$records,$d) = @_;
1.301 albertel 14674: my $i=0;
14675: my $samples = &get_samples($records,1);
1.144 matthew 14676: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14677: &start_data_table().&start_data_table_header_row().
1.144 matthew 14678: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14679: '<th>'.&mt('Column').'</th>'.
14680: &end_data_table_header_row()."\n");
1.356 albertel 14681: foreach my $array_ref (@$d) {
14682: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14683: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14684:
1.875 bisitz 14685: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14686: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14687: $r->print('<option value="none"></option>');
1.356 albertel 14688: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14689: $r->print('<option value="'.$sample.'"'.
14690: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14691: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14692: }
1.594 raeburn 14693: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14694: $i++;
14695: }
1.594 raeburn 14696: $r->print(&end_data_table());
1.31 albertel 14697: $i--;
14698: return $i;
14699: }
1.56 matthew 14700:
1.144 matthew 14701: ######################################################
14702: ######################################################
14703:
1.56 matthew 14704: =pod
1.31 albertel 14705:
1.648 raeburn 14706: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14707:
14708: Prints a table of sample values from the upload and can make associate samples to internal names.
14709:
14710: $r is an Apache Request ref,
14711: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14712: $d is an array of 2 element arrays (internal name, displayed name)
14713:
14714: =cut
14715:
1.144 matthew 14716: ######################################################
14717: ######################################################
1.31 albertel 14718: sub csv_samples_select_table {
14719: my ($r,$records,$d) = @_;
14720: my $i=0;
1.144 matthew 14721: #
1.662 bisitz 14722: my $max_samples = 5;
14723: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14724: $r->print(&start_data_table().
14725: &start_data_table_header_row().'<th>'.
14726: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14727: &end_data_table_header_row());
1.301 albertel 14728:
14729: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14730: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14731: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14732: foreach my $option (@$d) {
14733: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14734: $r->print('<option value="'.$value.'"'.
1.253 albertel 14735: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14736: $display.'</option>');
1.31 albertel 14737: }
14738: $r->print('</select></td><td>');
1.662 bisitz 14739: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14740: if (defined($samples->[$line]{$key})) {
14741: $r->print($samples->[$line]{$key}."<br />\n");
14742: }
14743: }
1.594 raeburn 14744: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14745: $i++;
14746: }
1.594 raeburn 14747: $r->print(&end_data_table());
1.31 albertel 14748: $i--;
14749: return($i);
1.115 matthew 14750: }
14751:
1.144 matthew 14752: ######################################################
14753: ######################################################
14754:
1.115 matthew 14755: =pod
14756:
1.648 raeburn 14757: =item * &clean_excel_name($name)
1.115 matthew 14758:
14759: Returns a replacement for $name which does not contain any illegal characters.
14760:
14761: =cut
14762:
1.144 matthew 14763: ######################################################
14764: ######################################################
1.115 matthew 14765: sub clean_excel_name {
14766: my ($name) = @_;
14767: $name =~ s/[:\*\?\/\\]//g;
14768: if (length($name) > 31) {
14769: $name = substr($name,0,31);
14770: }
14771: return $name;
1.25 albertel 14772: }
1.84 albertel 14773:
1.85 albertel 14774: =pod
14775:
1.648 raeburn 14776: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14777:
14778: Returns either 1 or undef
14779:
14780: 1 if the part is to be hidden, undef if it is to be shown
14781:
14782: Arguments are:
14783:
14784: $id the id of the part to be checked
14785: $symb, optional the symb of the resource to check
14786: $udom, optional the domain of the user to check for
14787: $uname, optional the username of the user to check for
14788:
14789: =cut
1.84 albertel 14790:
14791: sub check_if_partid_hidden {
14792: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14793: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14794: $symb,$udom,$uname);
1.141 albertel 14795: my $truth=1;
14796: #if the string starts with !, then the list is the list to show not hide
14797: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14798: my @hiddenlist=split(/,/,$hiddenparts);
14799: foreach my $checkid (@hiddenlist) {
1.141 albertel 14800: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14801: }
1.141 albertel 14802: return !$truth;
1.84 albertel 14803: }
1.127 matthew 14804:
1.138 matthew 14805:
14806: ############################################################
14807: ############################################################
14808:
14809: =pod
14810:
1.157 matthew 14811: =back
14812:
1.138 matthew 14813: =head1 cgi-bin script and graphing routines
14814:
1.157 matthew 14815: =over 4
14816:
1.648 raeburn 14817: =item * &get_cgi_id()
1.138 matthew 14818:
14819: Inputs: none
14820:
14821: Returns an id which can be used to pass environment variables
14822: to various cgi-bin scripts. These environment variables will
14823: be removed from the users environment after a given time by
14824: the routine &Apache::lonnet::transfer_profile_to_env.
14825:
14826: =cut
14827:
14828: ############################################################
14829: ############################################################
1.152 albertel 14830: my $uniq=0;
1.136 matthew 14831: sub get_cgi_id {
1.154 albertel 14832: $uniq=($uniq+1)%100000;
1.280 albertel 14833: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14834: }
14835:
1.127 matthew 14836: ############################################################
14837: ############################################################
14838:
14839: =pod
14840:
1.648 raeburn 14841: =item * &DrawBarGraph()
1.127 matthew 14842:
1.138 matthew 14843: Facilitates the plotting of data in a (stacked) bar graph.
14844: Puts plot definition data into the users environment in order for
14845: graph.png to plot it. Returns an <img> tag for the plot.
14846: The bars on the plot are labeled '1','2',...,'n'.
14847:
14848: Inputs:
14849:
14850: =over 4
14851:
14852: =item $Title: string, the title of the plot
14853:
14854: =item $xlabel: string, text describing the X-axis of the plot
14855:
14856: =item $ylabel: string, text describing the Y-axis of the plot
14857:
14858: =item $Max: scalar, the maximum Y value to use in the plot
14859: If $Max is < any data point, the graph will not be rendered.
14860:
1.140 matthew 14861: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14862: they are plotted. If undefined, default values will be used.
14863:
1.178 matthew 14864: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14865:
1.138 matthew 14866: =item @Values: An array of array references. Each array reference holds data
14867: to be plotted in a stacked bar chart.
14868:
1.239 matthew 14869: =item If the final element of @Values is a hash reference the key/value
14870: pairs will be added to the graph definition.
14871:
1.138 matthew 14872: =back
14873:
14874: Returns:
14875:
14876: An <img> tag which references graph.png and the appropriate identifying
14877: information for the plot.
14878:
1.127 matthew 14879: =cut
14880:
14881: ############################################################
14882: ############################################################
1.134 matthew 14883: sub DrawBarGraph {
1.178 matthew 14884: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14885: #
14886: if (! defined($colors)) {
14887: $colors = ['#33ff00',
14888: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14889: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14890: ];
14891: }
1.228 matthew 14892: my $extra_settings = {};
14893: if (ref($Values[-1]) eq 'HASH') {
14894: $extra_settings = pop(@Values);
14895: }
1.127 matthew 14896: #
1.136 matthew 14897: my $identifier = &get_cgi_id();
14898: my $id = 'cgi.'.$identifier;
1.129 matthew 14899: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14900: return '';
14901: }
1.225 matthew 14902: #
14903: my @Labels;
14904: if (defined($labels)) {
14905: @Labels = @$labels;
14906: } else {
14907: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14908: push(@Labels,$i+1);
1.225 matthew 14909: }
14910: }
14911: #
1.129 matthew 14912: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14913: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14914: my %ValuesHash;
14915: my $NumSets=1;
14916: foreach my $array (@Values) {
14917: next if (! ref($array));
1.136 matthew 14918: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14919: join(',',@$array);
1.129 matthew 14920: }
1.127 matthew 14921: #
1.136 matthew 14922: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14923: if ($NumBars < 3) {
14924: $width = 120+$NumBars*32;
1.220 matthew 14925: $xskip = 1;
1.225 matthew 14926: $bar_width = 30;
14927: } elsif ($NumBars < 5) {
14928: $width = 120+$NumBars*20;
14929: $xskip = 1;
14930: $bar_width = 20;
1.220 matthew 14931: } elsif ($NumBars < 10) {
1.136 matthew 14932: $width = 120+$NumBars*15;
14933: $xskip = 1;
14934: $bar_width = 15;
14935: } elsif ($NumBars <= 25) {
14936: $width = 120+$NumBars*11;
14937: $xskip = 5;
14938: $bar_width = 8;
14939: } elsif ($NumBars <= 50) {
14940: $width = 120+$NumBars*8;
14941: $xskip = 5;
14942: $bar_width = 4;
14943: } else {
14944: $width = 120+$NumBars*8;
14945: $xskip = 5;
14946: $bar_width = 4;
14947: }
14948: #
1.137 matthew 14949: $Max = 1 if ($Max < 1);
14950: if ( int($Max) < $Max ) {
14951: $Max++;
14952: $Max = int($Max);
14953: }
1.127 matthew 14954: $Title = '' if (! defined($Title));
14955: $xlabel = '' if (! defined($xlabel));
14956: $ylabel = '' if (! defined($ylabel));
1.369 www 14957: $ValuesHash{$id.'.title'} = &escape($Title);
14958: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14959: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14960: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14961: $ValuesHash{$id.'.NumBars'} = $NumBars;
14962: $ValuesHash{$id.'.NumSets'} = $NumSets;
14963: $ValuesHash{$id.'.PlotType'} = 'bar';
14964: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14965: $ValuesHash{$id.'.height'} = $height;
14966: $ValuesHash{$id.'.width'} = $width;
14967: $ValuesHash{$id.'.xskip'} = $xskip;
14968: $ValuesHash{$id.'.bar_width'} = $bar_width;
14969: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14970: #
1.228 matthew 14971: # Deal with other parameters
14972: while (my ($key,$value) = each(%$extra_settings)) {
14973: $ValuesHash{$id.'.'.$key} = $value;
14974: }
14975: #
1.646 raeburn 14976: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14977: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14978: }
14979:
14980: ############################################################
14981: ############################################################
14982:
14983: =pod
14984:
1.648 raeburn 14985: =item * &DrawXYGraph()
1.137 matthew 14986:
1.138 matthew 14987: Facilitates the plotting of data in an XY graph.
14988: Puts plot definition data into the users environment in order for
14989: graph.png to plot it. Returns an <img> tag for the plot.
14990:
14991: Inputs:
14992:
14993: =over 4
14994:
14995: =item $Title: string, the title of the plot
14996:
14997: =item $xlabel: string, text describing the X-axis of the plot
14998:
14999: =item $ylabel: string, text describing the Y-axis of the plot
15000:
15001: =item $Max: scalar, the maximum Y value to use in the plot
15002: If $Max is < any data point, the graph will not be rendered.
15003:
15004: =item $colors: Array ref containing the hex color codes for the data to be
15005: plotted in. If undefined, default values will be used.
15006:
15007: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15008:
15009: =item $Ydata: Array ref containing Array refs.
1.185 www 15010: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15011:
15012: =item %Values: hash indicating or overriding any default values which are
15013: passed to graph.png.
15014: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15015:
15016: =back
15017:
15018: Returns:
15019:
15020: An <img> tag which references graph.png and the appropriate identifying
15021: information for the plot.
15022:
1.137 matthew 15023: =cut
15024:
15025: ############################################################
15026: ############################################################
15027: sub DrawXYGraph {
15028: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15029: #
15030: # Create the identifier for the graph
15031: my $identifier = &get_cgi_id();
15032: my $id = 'cgi.'.$identifier;
15033: #
15034: $Title = '' if (! defined($Title));
15035: $xlabel = '' if (! defined($xlabel));
15036: $ylabel = '' if (! defined($ylabel));
15037: my %ValuesHash =
15038: (
1.369 www 15039: $id.'.title' => &escape($Title),
15040: $id.'.xlabel' => &escape($xlabel),
15041: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15042: $id.'.y_max_value'=> $Max,
15043: $id.'.labels' => join(',',@$Xlabels),
15044: $id.'.PlotType' => 'XY',
15045: );
15046: #
15047: if (defined($colors) && ref($colors) eq 'ARRAY') {
15048: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15049: }
15050: #
15051: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15052: return '';
15053: }
15054: my $NumSets=1;
1.138 matthew 15055: foreach my $array (@{$Ydata}){
1.137 matthew 15056: next if (! ref($array));
15057: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15058: }
1.138 matthew 15059: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15060: #
15061: # Deal with other parameters
15062: while (my ($key,$value) = each(%Values)) {
15063: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15064: }
15065: #
1.646 raeburn 15066: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15067: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15068: }
15069:
15070: ############################################################
15071: ############################################################
15072:
15073: =pod
15074:
1.648 raeburn 15075: =item * &DrawXYYGraph()
1.138 matthew 15076:
15077: Facilitates the plotting of data in an XY graph with two Y axes.
15078: Puts plot definition data into the users environment in order for
15079: graph.png to plot it. Returns an <img> tag for the plot.
15080:
15081: Inputs:
15082:
15083: =over 4
15084:
15085: =item $Title: string, the title of the plot
15086:
15087: =item $xlabel: string, text describing the X-axis of the plot
15088:
15089: =item $ylabel: string, text describing the Y-axis of the plot
15090:
15091: =item $colors: Array ref containing the hex color codes for the data to be
15092: plotted in. If undefined, default values will be used.
15093:
15094: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15095:
15096: =item $Ydata1: The first data set
15097:
15098: =item $Min1: The minimum value of the left Y-axis
15099:
15100: =item $Max1: The maximum value of the left Y-axis
15101:
15102: =item $Ydata2: The second data set
15103:
15104: =item $Min2: The minimum value of the right Y-axis
15105:
15106: =item $Max2: The maximum value of the left Y-axis
15107:
15108: =item %Values: hash indicating or overriding any default values which are
15109: passed to graph.png.
15110: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15111:
15112: =back
15113:
15114: Returns:
15115:
15116: An <img> tag which references graph.png and the appropriate identifying
15117: information for the plot.
1.136 matthew 15118:
15119: =cut
15120:
15121: ############################################################
15122: ############################################################
1.137 matthew 15123: sub DrawXYYGraph {
15124: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15125: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15126: #
15127: # Create the identifier for the graph
15128: my $identifier = &get_cgi_id();
15129: my $id = 'cgi.'.$identifier;
15130: #
15131: $Title = '' if (! defined($Title));
15132: $xlabel = '' if (! defined($xlabel));
15133: $ylabel = '' if (! defined($ylabel));
15134: my %ValuesHash =
15135: (
1.369 www 15136: $id.'.title' => &escape($Title),
15137: $id.'.xlabel' => &escape($xlabel),
15138: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15139: $id.'.labels' => join(',',@$Xlabels),
15140: $id.'.PlotType' => 'XY',
15141: $id.'.NumSets' => 2,
1.137 matthew 15142: $id.'.two_axes' => 1,
15143: $id.'.y1_max_value' => $Max1,
15144: $id.'.y1_min_value' => $Min1,
15145: $id.'.y2_max_value' => $Max2,
15146: $id.'.y2_min_value' => $Min2,
1.136 matthew 15147: );
15148: #
1.137 matthew 15149: if (defined($colors) && ref($colors) eq 'ARRAY') {
15150: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15151: }
15152: #
15153: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15154: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15155: return '';
15156: }
15157: my $NumSets=1;
1.137 matthew 15158: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15159: next if (! ref($array));
15160: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15161: }
15162: #
15163: # Deal with other parameters
15164: while (my ($key,$value) = each(%Values)) {
15165: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15166: }
15167: #
1.646 raeburn 15168: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15169: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15170: }
15171:
15172: ############################################################
15173: ############################################################
15174:
15175: =pod
15176:
1.157 matthew 15177: =back
15178:
1.139 matthew 15179: =head1 Statistics helper routines?
15180:
15181: Bad place for them but what the hell.
15182:
1.157 matthew 15183: =over 4
15184:
1.648 raeburn 15185: =item * &chartlink()
1.139 matthew 15186:
15187: Returns a link to the chart for a specific student.
15188:
15189: Inputs:
15190:
15191: =over 4
15192:
15193: =item $linktext: The text of the link
15194:
15195: =item $sname: The students username
15196:
15197: =item $sdomain: The students domain
15198:
15199: =back
15200:
1.157 matthew 15201: =back
15202:
1.139 matthew 15203: =cut
15204:
15205: ############################################################
15206: ############################################################
15207: sub chartlink {
15208: my ($linktext, $sname, $sdomain) = @_;
15209: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15210: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15211: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15212: '">'.$linktext.'</a>';
1.153 matthew 15213: }
15214:
15215: #######################################################
15216: #######################################################
15217:
15218: =pod
15219:
15220: =head1 Course Environment Routines
1.157 matthew 15221:
15222: =over 4
1.153 matthew 15223:
1.648 raeburn 15224: =item * &restore_course_settings()
1.153 matthew 15225:
1.648 raeburn 15226: =item * &store_course_settings()
1.153 matthew 15227:
15228: Restores/Store indicated form parameters from the course environment.
15229: Will not overwrite existing values of the form parameters.
15230:
15231: Inputs:
15232: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15233:
15234: a hash ref describing the data to be stored. For example:
15235:
15236: %Save_Parameters = ('Status' => 'scalar',
15237: 'chartoutputmode' => 'scalar',
15238: 'chartoutputdata' => 'scalar',
15239: 'Section' => 'array',
1.373 raeburn 15240: 'Group' => 'array',
1.153 matthew 15241: 'StudentData' => 'array',
15242: 'Maps' => 'array');
15243:
15244: Returns: both routines return nothing
15245:
1.631 raeburn 15246: =back
15247:
1.153 matthew 15248: =cut
15249:
15250: #######################################################
15251: #######################################################
15252: sub store_course_settings {
1.496 albertel 15253: return &store_settings($env{'request.course.id'},@_);
15254: }
15255:
15256: sub store_settings {
1.153 matthew 15257: # save to the environment
15258: # appenv the same items, just to be safe
1.300 albertel 15259: my $udom = $env{'user.domain'};
15260: my $uname = $env{'user.name'};
1.496 albertel 15261: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15262: my %SaveHash;
15263: my %AppHash;
15264: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15265: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15266: my $envname = 'environment.'.$basename;
1.258 albertel 15267: if (exists($env{'form.'.$setting})) {
1.153 matthew 15268: # Save this value away
15269: if ($type eq 'scalar' &&
1.258 albertel 15270: (! exists($env{$envname}) ||
15271: $env{$envname} ne $env{'form.'.$setting})) {
15272: $SaveHash{$basename} = $env{'form.'.$setting};
15273: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15274: } elsif ($type eq 'array') {
15275: my $stored_form;
1.258 albertel 15276: if (ref($env{'form.'.$setting})) {
1.153 matthew 15277: $stored_form = join(',',
15278: map {
1.369 www 15279: &escape($_);
1.258 albertel 15280: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15281: } else {
15282: $stored_form =
1.369 www 15283: &escape($env{'form.'.$setting});
1.153 matthew 15284: }
15285: # Determine if the array contents are the same.
1.258 albertel 15286: if ($stored_form ne $env{$envname}) {
1.153 matthew 15287: $SaveHash{$basename} = $stored_form;
15288: $AppHash{$envname} = $stored_form;
15289: }
15290: }
15291: }
15292: }
15293: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15294: $udom,$uname);
1.153 matthew 15295: if ($put_result !~ /^(ok|delayed)/) {
15296: &Apache::lonnet::logthis('unable to save form parameters, '.
15297: 'got error:'.$put_result);
15298: }
15299: # Make sure these settings stick around in this session, too
1.646 raeburn 15300: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15301: return;
15302: }
15303:
15304: sub restore_course_settings {
1.499 albertel 15305: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15306: }
15307:
15308: sub restore_settings {
15309: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15310: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15311: next if (exists($env{'form.'.$setting}));
1.496 albertel 15312: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15313: '.'.$setting;
1.258 albertel 15314: if (exists($env{$envname})) {
1.153 matthew 15315: if ($type eq 'scalar') {
1.258 albertel 15316: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15317: } elsif ($type eq 'array') {
1.258 albertel 15318: $env{'form.'.$setting} = [
1.153 matthew 15319: map {
1.369 www 15320: &unescape($_);
1.258 albertel 15321: } split(',',$env{$envname})
1.153 matthew 15322: ];
15323: }
15324: }
15325: }
1.127 matthew 15326: }
15327:
1.618 raeburn 15328: #######################################################
15329: #######################################################
15330:
15331: =pod
15332:
15333: =head1 Domain E-mail Routines
15334:
15335: =over 4
15336:
1.648 raeburn 15337: =item * &build_recipient_list()
1.618 raeburn 15338:
1.1144 raeburn 15339: Build recipient lists for following types of e-mail:
1.766 raeburn 15340: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15341: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15342: module change checking, student/employee ID conflict checks, as
15343: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15344: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15345:
15346: Inputs:
1.619 raeburn 15347: defmail (scalar - email address of default recipient),
1.1144 raeburn 15348: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15349: requestsmail, updatesmail, or idconflictsmail).
15350:
1.619 raeburn 15351: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15352:
1.619 raeburn 15353: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15354: i.e., predates configuration by DC via domainprefs.pm
15355:
15356: $requname username of requester (if mailing type is helpdeskmail)
15357:
15358: $requdom domain of requester (if mailing type is helpdeskmail)
15359:
15360: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15361:
1.618 raeburn 15362:
1.655 raeburn 15363: Returns: comma separated list of addresses to which to send e-mail.
15364:
15365: =back
1.618 raeburn 15366:
15367: =cut
15368:
15369: ############################################################
15370: ############################################################
15371: sub build_recipient_list {
1.1297 raeburn 15372: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15373: my @recipients;
1.1270 raeburn 15374: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15375: my %domconfig =
1.1270 raeburn 15376: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15377: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15378: if (exists($domconfig{'contacts'}{$mailing})) {
15379: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15380: my @contacts = ('adminemail','supportemail');
15381: foreach my $item (@contacts) {
15382: if ($domconfig{'contacts'}{$mailing}{$item}) {
15383: my $addr = $domconfig{'contacts'}{$item};
15384: if (!grep(/^\Q$addr\E$/,@recipients)) {
15385: push(@recipients,$addr);
15386: }
1.619 raeburn 15387: }
1.1270 raeburn 15388: }
15389: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15390: if ($mailing eq 'helpdeskmail') {
15391: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15392: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15393: my @ok_bccs;
15394: foreach my $bcc (@bccs) {
15395: $bcc =~ s/^\s+//g;
15396: $bcc =~ s/\s+$//g;
15397: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15398: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15399: push(@ok_bccs,$bcc);
15400: }
15401: }
15402: }
15403: if (@ok_bccs > 0) {
15404: $allbcc = join(', ',@ok_bccs);
15405: }
15406: }
15407: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15408: }
15409: }
1.766 raeburn 15410: } elsif ($origmail ne '') {
1.1270 raeburn 15411: $lastresort = $origmail;
1.618 raeburn 15412: }
1.1297 raeburn 15413: if ($mailing eq 'helpdeskmail') {
15414: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15415: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15416: my ($inststatus,$inststatus_checked);
15417: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15418: ($env{'user.domain'} ne 'public')) {
15419: $inststatus_checked = 1;
15420: $inststatus = $env{'environment.inststatus'};
15421: }
15422: unless ($inststatus_checked) {
15423: if (($requname ne '') && ($requdom ne '')) {
15424: if (($requname =~ /^$match_username$/) &&
15425: ($requdom =~ /^$match_domain$/) &&
15426: (&Apache::lonnet::domain($requdom))) {
15427: my $requhome = &Apache::lonnet::homeserver($requname,
15428: $requdom);
15429: unless ($requhome eq 'no_host') {
15430: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15431: $inststatus = $userenv{'inststatus'};
15432: $inststatus_checked = 1;
15433: }
15434: }
15435: }
15436: }
15437: unless ($inststatus_checked) {
15438: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15439: my %srch = (srchby => 'email',
15440: srchdomain => $defdom,
15441: srchterm => $reqemail,
15442: srchtype => 'exact');
15443: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15444: foreach my $uname (keys(%srch_results)) {
15445: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15446: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15447: $inststatus_checked = 1;
15448: last;
15449: }
15450: }
15451: unless ($inststatus_checked) {
15452: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15453: if ($dirsrchres eq 'ok') {
15454: foreach my $uname (keys(%srch_results)) {
15455: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15456: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15457: $inststatus_checked = 1;
15458: last;
15459: }
15460: }
15461: }
15462: }
15463: }
15464: }
15465: if ($inststatus ne '') {
15466: foreach my $status (split(/\:/,$inststatus)) {
15467: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15468: my @contacts = ('adminemail','supportemail');
15469: foreach my $item (@contacts) {
15470: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15471: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15472: if (!grep(/^\Q$addr\E$/,@recipients)) {
15473: push(@recipients,$addr);
15474: }
15475: }
15476: }
15477: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15478: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15479: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15480: my @ok_bccs;
15481: foreach my $bcc (@bccs) {
15482: $bcc =~ s/^\s+//g;
15483: $bcc =~ s/\s+$//g;
15484: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15485: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15486: push(@ok_bccs,$bcc);
15487: }
15488: }
15489: }
15490: if (@ok_bccs > 0) {
15491: $allbcc = join(', ',@ok_bccs);
15492: }
15493: }
15494: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15495: last;
15496: }
15497: }
15498: }
15499: }
15500: }
1.619 raeburn 15501: } elsif ($origmail ne '') {
1.1270 raeburn 15502: $lastresort = $origmail;
15503: }
1.1297 raeburn 15504: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15505: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15506: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15507: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15508: my %what = (
15509: perlvar => 1,
15510: );
15511: my $primary = &Apache::lonnet::domain($defdom,'primary');
15512: if ($primary) {
15513: my $gotaddr;
15514: my ($result,$returnhash) =
15515: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15516: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15517: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15518: $lastresort = $returnhash->{'lonSupportEMail'};
15519: $gotaddr = 1;
15520: }
15521: }
15522: unless ($gotaddr) {
15523: my $uintdom = &Apache::lonnet::internet_dom($primary);
15524: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15525: unless ($uintdom eq $intdom) {
15526: my %domconfig =
15527: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15528: if (ref($domconfig{'contacts'}) eq 'HASH') {
15529: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15530: my @contacts = ('adminemail','supportemail');
15531: foreach my $item (@contacts) {
15532: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15533: my $addr = $domconfig{'contacts'}{$item};
15534: if (!grep(/^\Q$addr\E$/,@recipients)) {
15535: push(@recipients,$addr);
15536: }
15537: }
15538: }
15539: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15540: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15541: }
15542: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15543: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15544: my @ok_bccs;
15545: foreach my $bcc (@bccs) {
15546: $bcc =~ s/^\s+//g;
15547: $bcc =~ s/\s+$//g;
15548: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15549: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15550: push(@ok_bccs,$bcc);
15551: }
15552: }
15553: }
15554: if (@ok_bccs > 0) {
15555: $allbcc = join(', ',@ok_bccs);
15556: }
15557: }
15558: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15559: }
15560: }
15561: }
15562: }
15563: }
15564: }
1.618 raeburn 15565: }
1.688 raeburn 15566: if (defined($defmail)) {
15567: if ($defmail ne '') {
15568: push(@recipients,$defmail);
15569: }
1.618 raeburn 15570: }
15571: if ($otheremails) {
1.619 raeburn 15572: my @others;
15573: if ($otheremails =~ /,/) {
15574: @others = split(/,/,$otheremails);
1.618 raeburn 15575: } else {
1.619 raeburn 15576: push(@others,$otheremails);
15577: }
15578: foreach my $addr (@others) {
15579: if (!grep(/^\Q$addr\E$/,@recipients)) {
15580: push(@recipients,$addr);
15581: }
1.618 raeburn 15582: }
15583: }
1.1298 raeburn 15584: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15585: if ((!@recipients) && ($lastresort ne '')) {
15586: push(@recipients,$lastresort);
15587: }
15588: } elsif ($lastresort ne '') {
15589: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15590: push(@recipients,$lastresort);
15591: }
15592: }
1.1271 raeburn 15593: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15594: if (wantarray) {
15595: return ($recipientlist,$allbcc,$addtext);
15596: } else {
15597: return $recipientlist;
15598: }
1.618 raeburn 15599: }
15600:
1.127 matthew 15601: ############################################################
15602: ############################################################
1.154 albertel 15603:
1.655 raeburn 15604: =pod
15605:
1.1224 musolffc 15606: =over 4
15607:
1.1223 musolffc 15608: =item * &mime_email()
15609:
15610: Sends an email with a possible attachment
15611:
15612: Inputs:
15613:
15614: =over 4
15615:
15616: from - Sender's email address
15617:
1.1343 raeburn 15618: replyto - Reply-To email address
15619:
1.1223 musolffc 15620: to - Email address of recipient
15621:
15622: subject - Subject of email
15623:
15624: body - Body of email
15625:
15626: cc_string - Carbon copy email address
15627:
15628: bcc - Blind carbon copy email address
15629:
15630: attachment_path - Path of file to be attached
15631:
15632: file_name - Name of file to be attached
15633:
15634: attachment_text - The body of an attachment of type "TEXT"
15635:
15636: =back
15637:
15638: =back
15639:
15640: =cut
15641:
15642: ############################################################
15643: ############################################################
15644:
15645: sub mime_email {
1.1343 raeburn 15646: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15647: $file_name,$attachment_text) = @_;
15648:
1.1223 musolffc 15649: my $msg = MIME::Lite->new(
15650: From => $from,
15651: To => $to,
15652: Subject => $subject,
15653: Type =>'TEXT',
15654: Data => $body,
15655: );
1.1343 raeburn 15656: if ($replyto ne '') {
15657: $msg->add("Reply-To" => $replyto);
15658: }
1.1223 musolffc 15659: if ($cc_string ne '') {
15660: $msg->add("Cc" => $cc_string);
15661: }
15662: if ($bcc ne '') {
15663: $msg->add("Bcc" => $bcc);
15664: }
15665: $msg->attr("content-type" => "text/plain");
15666: $msg->attr("content-type.charset" => "UTF-8");
15667: # Attach file if given
15668: if ($attachment_path) {
15669: unless ($file_name) {
15670: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15671: }
15672: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15673: $msg->attach(Type => $type,
15674: Path => $attachment_path,
15675: Filename => $file_name
15676: );
15677: # Otherwise attach text if given
15678: } elsif ($attachment_text) {
15679: $msg->attach(Type => 'TEXT',
15680: Data => $attachment_text);
15681: }
15682: # Send it
15683: $msg->send('sendmail');
15684: }
15685:
15686: ############################################################
15687: ############################################################
15688:
15689: =pod
15690:
1.655 raeburn 15691: =head1 Course Catalog Routines
15692:
15693: =over 4
15694:
15695: =item * &gather_categories()
15696:
15697: Converts category definitions - keys of categories hash stored in
15698: coursecategories in configuration.db on the primary library server in a
15699: domain - to an array. Also generates javascript and idx hash used to
15700: generate Domain Coordinator interface for editing Course Categories.
15701:
15702: Inputs:
1.663 raeburn 15703:
1.655 raeburn 15704: categories (reference to hash of category definitions).
1.663 raeburn 15705:
1.655 raeburn 15706: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15707: categories and subcategories).
1.663 raeburn 15708:
1.655 raeburn 15709: idx (reference to hash of counters used in Domain Coordinator interface for
15710: editing Course Categories).
1.663 raeburn 15711:
1.655 raeburn 15712: jsarray (reference to array of categories used to create Javascript arrays for
15713: Domain Coordinator interface for editing Course Categories).
15714:
15715: Returns: nothing
15716:
15717: Side effects: populates cats, idx and jsarray.
15718:
15719: =cut
15720:
15721: sub gather_categories {
15722: my ($categories,$cats,$idx,$jsarray) = @_;
15723: my %counters;
15724: my $num = 0;
15725: foreach my $item (keys(%{$categories})) {
15726: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15727: if ($container eq '' && $depth == 0) {
15728: $cats->[$depth][$categories->{$item}] = $cat;
15729: } else {
15730: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15731: }
15732: my ($escitem,$tail) = split(/:/,$item,2);
15733: if ($counters{$tail} eq '') {
15734: $counters{$tail} = $num;
15735: $num ++;
15736: }
15737: if (ref($idx) eq 'HASH') {
15738: $idx->{$item} = $counters{$tail};
15739: }
15740: if (ref($jsarray) eq 'ARRAY') {
15741: push(@{$jsarray->[$counters{$tail}]},$item);
15742: }
15743: }
15744: return;
15745: }
15746:
15747: =pod
15748:
15749: =item * &extract_categories()
15750:
15751: Used to generate breadcrumb trails for course categories.
15752:
15753: Inputs:
1.663 raeburn 15754:
1.655 raeburn 15755: categories (reference to hash of category definitions).
1.663 raeburn 15756:
1.655 raeburn 15757: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15758: categories and subcategories).
1.663 raeburn 15759:
1.655 raeburn 15760: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15761:
1.655 raeburn 15762: allitems (reference to hash - key is category key
15763: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15764:
1.655 raeburn 15765: idx (reference to hash of counters used in Domain Coordinator interface for
15766: editing Course Categories).
1.663 raeburn 15767:
1.655 raeburn 15768: jsarray (reference to array of categories used to create Javascript arrays for
15769: Domain Coordinator interface for editing Course Categories).
15770:
1.665 raeburn 15771: subcats (reference to hash of arrays containing all subcategories within each
15772: category, -recursive)
15773:
1.1321 raeburn 15774: maxd (reference to hash used to hold max depth for all top-level categories).
15775:
1.655 raeburn 15776: Returns: nothing
15777:
15778: Side effects: populates trails and allitems hash references.
15779:
15780: =cut
15781:
15782: sub extract_categories {
1.1321 raeburn 15783: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15784: if (ref($categories) eq 'HASH') {
15785: &gather_categories($categories,$cats,$idx,$jsarray);
15786: if (ref($cats->[0]) eq 'ARRAY') {
15787: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15788: my $name = $cats->[0][$i];
15789: my $item = &escape($name).'::0';
15790: my $trailstr;
15791: if ($name eq 'instcode') {
15792: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15793: } elsif ($name eq 'communities') {
15794: $trailstr = &mt('Communities');
1.1239 raeburn 15795: } elsif ($name eq 'placement') {
15796: $trailstr = &mt('Placement Tests');
1.655 raeburn 15797: } else {
15798: $trailstr = $name;
15799: }
15800: if ($allitems->{$item} eq '') {
15801: push(@{$trails},$trailstr);
15802: $allitems->{$item} = scalar(@{$trails})-1;
15803: }
15804: my @parents = ($name);
15805: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15806: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15807: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15808: if (ref($subcats) eq 'HASH') {
15809: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15810: }
1.1321 raeburn 15811: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15812: }
15813: } else {
15814: if (ref($subcats) eq 'HASH') {
15815: $subcats->{$item} = [];
1.655 raeburn 15816: }
1.1321 raeburn 15817: if (ref($maxd) eq 'HASH') {
15818: $maxd->{$name} = 1;
15819: }
1.655 raeburn 15820: }
15821: }
15822: }
15823: }
15824: return;
15825: }
15826:
15827: =pod
15828:
1.1162 raeburn 15829: =item * &recurse_categories()
1.655 raeburn 15830:
15831: Recursively used to generate breadcrumb trails for course categories.
15832:
15833: Inputs:
1.663 raeburn 15834:
1.655 raeburn 15835: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15836: categories and subcategories).
1.663 raeburn 15837:
1.655 raeburn 15838: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15839:
15840: category (current course category, for which breadcrumb trail is being generated).
15841:
15842: trails (reference to array of breadcrumb trails for each category).
15843:
1.655 raeburn 15844: allitems (reference to hash - key is category key
15845: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15846:
1.655 raeburn 15847: parents (array containing containers directories for current category,
15848: back to top level).
15849:
15850: Returns: nothing
15851:
15852: Side effects: populates trails and allitems hash references
15853:
15854: =cut
15855:
15856: sub recurse_categories {
1.1321 raeburn 15857: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15858: my $shallower = $depth - 1;
15859: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15860: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15861: my $name = $cats->[$depth]{$category}[$k];
15862: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15863: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15864: if ($allitems->{$item} eq '') {
15865: push(@{$trails},$trailstr);
15866: $allitems->{$item} = scalar(@{$trails})-1;
15867: }
15868: my $deeper = $depth+1;
15869: push(@{$parents},$category);
1.665 raeburn 15870: if (ref($subcats) eq 'HASH') {
15871: my $subcat = &escape($name).':'.$category.':'.$depth;
15872: for (my $j=@{$parents}; $j>=0; $j--) {
15873: my $higher;
15874: if ($j > 0) {
15875: $higher = &escape($parents->[$j]).':'.
15876: &escape($parents->[$j-1]).':'.$j;
15877: } else {
15878: $higher = &escape($parents->[$j]).'::'.$j;
15879: }
15880: push(@{$subcats->{$higher}},$subcat);
15881: }
15882: }
15883: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15884: $subcats,$maxd);
1.655 raeburn 15885: pop(@{$parents});
15886: }
15887: } else {
15888: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15889: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15890: if ($allitems->{$item} eq '') {
15891: push(@{$trails},$trailstr);
15892: $allitems->{$item} = scalar(@{$trails})-1;
15893: }
1.1321 raeburn 15894: if (ref($maxd) eq 'HASH') {
15895: if ($depth > $maxd->{$parents->[0]}) {
15896: $maxd->{$parents->[0]} = $depth;
15897: }
15898: }
1.655 raeburn 15899: }
15900: return;
15901: }
15902:
1.663 raeburn 15903: =pod
15904:
1.1162 raeburn 15905: =item * &assign_categories_table()
1.663 raeburn 15906:
15907: Create a datatable for display of hierarchical categories in a domain,
15908: with checkboxes to allow a course to be categorized.
15909:
15910: Inputs:
15911:
15912: cathash - reference to hash of categories defined for the domain (from
15913: configuration.db)
15914:
15915: currcat - scalar with an & separated list of categories assigned to a course.
15916:
1.919 raeburn 15917: type - scalar contains course type (Course or Community).
15918:
1.1260 raeburn 15919: disabled - scalar (optional) contains disabled="disabled" if input elements are
15920: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15921:
1.663 raeburn 15922: Returns: $output (markup to be displayed)
15923:
15924: =cut
15925:
15926: sub assign_categories_table {
1.1259 raeburn 15927: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15928: my $output;
15929: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15930: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15931: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15932: $maxdepth = scalar(@cats);
15933: if (@cats > 0) {
15934: my $itemcount = 0;
15935: if (ref($cats[0]) eq 'ARRAY') {
15936: my @currcategories;
15937: if ($currcat ne '') {
15938: @currcategories = split('&',$currcat);
15939: }
1.919 raeburn 15940: my $table;
1.663 raeburn 15941: for (my $i=0; $i<@{$cats[0]}; $i++) {
15942: my $parent = $cats[0][$i];
1.919 raeburn 15943: next if ($parent eq 'instcode');
15944: if ($type eq 'Community') {
15945: next unless ($parent eq 'communities');
1.1239 raeburn 15946: } elsif ($type eq 'Placement') {
15947: next unless ($parent eq 'placement');
1.919 raeburn 15948: } else {
1.1239 raeburn 15949: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15950: }
1.663 raeburn 15951: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15952: my $item = &escape($parent).'::0';
15953: my $checked = '';
15954: if (@currcategories > 0) {
15955: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15956: $checked = ' checked="checked"';
1.663 raeburn 15957: }
15958: }
1.919 raeburn 15959: my $parent_title = $parent;
15960: if ($parent eq 'communities') {
15961: $parent_title = &mt('Communities');
1.1239 raeburn 15962: } elsif ($parent eq 'placement') {
15963: $parent_title = &mt('Placement Tests');
1.919 raeburn 15964: }
15965: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15966: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15967: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15968: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15969: my $depth = 1;
15970: push(@path,$parent);
1.1259 raeburn 15971: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15972: pop(@path);
1.919 raeburn 15973: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15974: $itemcount ++;
15975: }
1.919 raeburn 15976: if ($itemcount) {
15977: $output = &Apache::loncommon::start_data_table().
15978: $table.
15979: &Apache::loncommon::end_data_table();
15980: }
1.663 raeburn 15981: }
15982: }
15983: }
15984: return $output;
15985: }
15986:
15987: =pod
15988:
1.1162 raeburn 15989: =item * &assign_category_rows()
1.663 raeburn 15990:
15991: Create a datatable row for display of nested categories in a domain,
15992: with checkboxes to allow a course to be categorized,called recursively.
15993:
15994: Inputs:
15995:
15996: itemcount - track row number for alternating colors
15997:
15998: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15999: categories and subcategories.
16000:
16001: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16002:
16003: parent - parent of current category item
16004:
16005: path - Array containing all categories back up through the hierarchy from the
16006: current category to the top level.
16007:
16008: currcategories - reference to array of current categories assigned to the course
16009:
1.1260 raeburn 16010: disabled - scalar (optional) contains disabled="disabled" if input elements are
16011: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16012:
1.663 raeburn 16013: Returns: $output (markup to be displayed).
16014:
16015: =cut
16016:
16017: sub assign_category_rows {
1.1259 raeburn 16018: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16019: my ($text,$name,$item,$chgstr);
16020: if (ref($cats) eq 'ARRAY') {
16021: my $maxdepth = scalar(@{$cats});
16022: if (ref($cats->[$depth]) eq 'HASH') {
16023: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16024: my $numchildren = @{$cats->[$depth]{$parent}};
16025: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16026: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16027: for (my $j=0; $j<$numchildren; $j++) {
16028: $name = $cats->[$depth]{$parent}[$j];
16029: $item = &escape($name).':'.&escape($parent).':'.$depth;
16030: my $deeper = $depth+1;
16031: my $checked = '';
16032: if (ref($currcategories) eq 'ARRAY') {
16033: if (@{$currcategories} > 0) {
16034: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16035: $checked = ' checked="checked"';
1.663 raeburn 16036: }
16037: }
16038: }
1.664 raeburn 16039: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16040: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16041: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16042: '<input type="hidden" name="catname" value="'.$name.'" />'.
16043: '</td><td>';
1.663 raeburn 16044: if (ref($path) eq 'ARRAY') {
16045: push(@{$path},$name);
1.1259 raeburn 16046: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16047: pop(@{$path});
16048: }
16049: $text .= '</td></tr>';
16050: }
16051: $text .= '</table></td>';
16052: }
16053: }
16054: }
16055: return $text;
16056: }
16057:
1.1181 raeburn 16058: =pod
16059:
16060: =back
16061:
16062: =cut
16063:
1.655 raeburn 16064: ############################################################
16065: ############################################################
16066:
16067:
1.443 albertel 16068: sub commit_customrole {
1.664 raeburn 16069: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16070: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16071: ($start?', '.&mt('starting').' '.localtime($start):'').
16072: ($end?', ending '.localtime($end):'').': <b>'.
16073: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16074: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16075: '</b><br />';
16076: return $output;
16077: }
16078:
16079: sub commit_standardrole {
1.1116 raeburn 16080: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16081: my ($output,$logmsg,$linefeed);
16082: if ($context eq 'auto') {
16083: $linefeed = "\n";
16084: } else {
16085: $linefeed = "<br />\n";
16086: }
1.443 albertel 16087: if ($three eq 'st') {
1.541 raeburn 16088: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 16089: $one,$two,$sec,$context,$credits);
1.541 raeburn 16090: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16091: ($result eq 'unknown_course') || ($result eq 'refused')) {
16092: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16093: } else {
1.541 raeburn 16094: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16095: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16096: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16097: if ($context eq 'auto') {
16098: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16099: } else {
16100: $output .= '<b>'.$result.'</b>'.$linefeed.
16101: &mt('Add to classlist').': <b>ok</b>';
16102: }
16103: $output .= $linefeed;
1.443 albertel 16104: }
16105: } else {
16106: $output = &mt('Assigning').' '.$three.' in '.$url.
16107: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16108: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16109: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16110: if ($context eq 'auto') {
16111: $output .= $result.$linefeed;
16112: } else {
16113: $output .= '<b>'.$result.'</b>'.$linefeed;
16114: }
1.443 albertel 16115: }
16116: return $output;
16117: }
16118:
16119: sub commit_studentrole {
1.1116 raeburn 16120: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16121: $credits) = @_;
1.626 raeburn 16122: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16123: if ($context eq 'auto') {
16124: $linefeed = "\n";
16125: } else {
16126: $linefeed = '<br />'."\n";
16127: }
1.443 albertel 16128: if (defined($one) && defined($two)) {
16129: my $cid=$one.'_'.$two;
16130: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16131: my $secchange = 0;
16132: my $expire_role_result;
16133: my $modify_section_result;
1.628 raeburn 16134: if ($oldsec ne '-1') {
16135: if ($oldsec ne $sec) {
1.443 albertel 16136: $secchange = 1;
1.628 raeburn 16137: my $now = time;
1.443 albertel 16138: my $uurl='/'.$cid;
16139: $uurl=~s/\_/\//g;
16140: if ($oldsec) {
16141: $uurl.='/'.$oldsec;
16142: }
1.626 raeburn 16143: $oldsecurl = $uurl;
1.628 raeburn 16144: $expire_role_result =
1.652 raeburn 16145: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 16146: if ($env{'request.course.sec'} ne '') {
16147: if ($expire_role_result eq 'refused') {
16148: my @roles = ('st');
16149: my @statuses = ('previous');
16150: my @roledoms = ($one);
16151: my $withsec = 1;
16152: my %roleshash =
16153: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16154: \@statuses,\@roles,\@roledoms,$withsec);
16155: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16156: my ($oldstart,$oldend) =
16157: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16158: if ($oldend > 0 && $oldend <= $now) {
16159: $expire_role_result = 'ok';
16160: }
16161: }
16162: }
16163: }
1.443 albertel 16164: $result = $expire_role_result;
16165: }
16166: }
16167: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16168: $modify_section_result =
16169: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16170: undef,undef,undef,$sec,
16171: $end,$start,'','',$cid,
16172: '',$context,$credits);
1.443 albertel 16173: if ($modify_section_result =~ /^ok/) {
16174: if ($secchange == 1) {
1.628 raeburn 16175: if ($sec eq '') {
16176: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16177: } else {
16178: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16179: }
1.443 albertel 16180: } elsif ($oldsec eq '-1') {
1.628 raeburn 16181: if ($sec eq '') {
16182: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16183: } else {
16184: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16185: }
1.443 albertel 16186: } else {
1.628 raeburn 16187: if ($sec eq '') {
16188: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16189: } else {
16190: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16191: }
1.443 albertel 16192: }
16193: } else {
1.1115 raeburn 16194: if ($secchange) {
1.628 raeburn 16195: $$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;
16196: } else {
16197: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16198: }
1.443 albertel 16199: }
16200: $result = $modify_section_result;
16201: } elsif ($secchange == 1) {
1.628 raeburn 16202: if ($oldsec eq '') {
1.1103 raeburn 16203: $$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 16204: } else {
16205: $$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;
16206: }
1.626 raeburn 16207: if ($expire_role_result eq 'refused') {
16208: my $newsecurl = '/'.$cid;
16209: $newsecurl =~ s/\_/\//g;
16210: if ($sec ne '') {
16211: $newsecurl.='/'.$sec;
16212: }
16213: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16214: if ($sec eq '') {
16215: $$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;
16216: } else {
16217: $$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;
16218: }
16219: }
16220: }
1.443 albertel 16221: }
16222: } else {
1.626 raeburn 16223: $$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 16224: $result = "error: incomplete course id\n";
16225: }
16226: return $result;
16227: }
16228:
1.1108 raeburn 16229: sub show_role_extent {
16230: my ($scope,$context,$role) = @_;
16231: $scope =~ s{^/}{};
16232: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16233: push(@courseroles,'co');
16234: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16235: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16236: $scope =~ s{/}{_};
16237: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16238: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16239: my ($audom,$auname) = split(/\//,$scope);
16240: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16241: &Apache::loncommon::plainname($auname,$audom).'</span>');
16242: } else {
16243: $scope =~ s{/$}{};
16244: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16245: &Apache::lonnet::domain($scope,'description').'</span>');
16246: }
16247: }
16248:
1.443 albertel 16249: ############################################################
16250: ############################################################
16251:
1.566 albertel 16252: sub check_clone {
1.578 raeburn 16253: my ($args,$linefeed) = @_;
1.566 albertel 16254: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16255: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16256: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16257: my $clonetitle;
16258: my @clonemsg;
1.566 albertel 16259: my $can_clone = 0;
1.944 raeburn 16260: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16261: if ($lctype ne 'community') {
16262: $lctype = 'course';
16263: }
1.566 albertel 16264: if ($clonehome eq 'no_host') {
1.944 raeburn 16265: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16266: push(@clonemsg,({
16267: mt => 'No new community created.',
16268: args => [],
16269: },
16270: {
16271: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16272: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16273: }));
1.908 raeburn 16274: } else {
1.1344 raeburn 16275: push(@clonemsg,({
16276: mt => 'No new course created.',
16277: args => [],
16278: },
16279: {
16280: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16281: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16282: }));
16283: }
1.566 albertel 16284: } else {
16285: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16286: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16287: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16288: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16289: push(@clonemsg,({
16290: mt => 'No new community created.',
16291: args => [],
16292: },
16293: {
16294: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16295: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16296: }));
16297: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16298: }
16299: }
1.1262 raeburn 16300: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16301: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16302: $can_clone = 1;
16303: } else {
1.1221 raeburn 16304: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16305: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16306: if ($clonehash{'cloners'} eq '') {
16307: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16308: if ($domdefs{'canclone'}) {
16309: unless ($domdefs{'canclone'} eq 'none') {
16310: if ($domdefs{'canclone'} eq 'domain') {
16311: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16312: $can_clone = 1;
16313: }
16314: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16315: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16316: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16317: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16318: $can_clone = 1;
16319: }
16320: }
16321: }
16322: }
1.578 raeburn 16323: } else {
1.1221 raeburn 16324: my @cloners = split(/,/,$clonehash{'cloners'});
16325: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16326: $can_clone = 1;
1.1221 raeburn 16327: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16328: $can_clone = 1;
1.1225 raeburn 16329: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16330: $can_clone = 1;
1.1221 raeburn 16331: }
16332: unless ($can_clone) {
1.1225 raeburn 16333: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16334: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16335: my (%gotdomdefaults,%gotcodedefaults);
16336: foreach my $cloner (@cloners) {
16337: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16338: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16339: my (%codedefaults,@code_order);
16340: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16341: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16342: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16343: }
16344: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16345: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16346: }
16347: } else {
16348: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16349: \%codedefaults,
16350: \@code_order);
16351: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16352: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16353: }
16354: if (@code_order > 0) {
16355: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16356: $cloner,$clonehash{'internal.coursecode'},
16357: $args->{'crscode'})) {
16358: $can_clone = 1;
16359: last;
16360: }
16361: }
16362: }
16363: }
16364: }
1.1225 raeburn 16365: }
16366: }
16367: unless ($can_clone) {
16368: my $ccrole = 'cc';
16369: if ($args->{'crstype'} eq 'Community') {
16370: $ccrole = 'co';
16371: }
16372: my %roleshash =
16373: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16374: $args->{'ccdomain'},
16375: 'userroles',['active'],[$ccrole],
16376: [$args->{'clonedomain'}]);
16377: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16378: $can_clone = 1;
16379: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16380: $args->{'ccuname'},$args->{'ccdomain'})) {
16381: $can_clone = 1;
1.1221 raeburn 16382: }
16383: }
16384: unless ($can_clone) {
16385: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16386: push(@clonemsg,({
16387: mt => 'No new community created.',
16388: args => [],
16389: },
16390: {
16391: 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]).',
16392: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16393: }));
1.942 raeburn 16394: } else {
1.1344 raeburn 16395: push(@clonemsg,({
16396: mt => 'No new course created.',
16397: args => [],
16398: },
16399: {
16400: 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]).',
16401: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16402: }));
1.1221 raeburn 16403: }
1.566 albertel 16404: }
1.578 raeburn 16405: }
1.566 albertel 16406: }
1.1344 raeburn 16407: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16408: }
16409:
1.444 albertel 16410: sub construct_course {
1.1262 raeburn 16411: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16412: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16413: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16414: my $linefeed = '<br />'."\n";
16415: if ($context eq 'auto') {
16416: $linefeed = "\n";
16417: }
1.566 albertel 16418:
16419: #
16420: # Are we cloning?
16421: #
1.1344 raeburn 16422: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16423: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16424: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16425: if (!$can_clone) {
1.1344 raeburn 16426: return (0,$outcome,$clonemsgref);
1.566 albertel 16427: }
16428: }
16429:
1.444 albertel 16430: #
16431: # Open course
16432: #
1.1239 raeburn 16433: my $showncrstype;
16434: if ($args->{'crstype'} eq 'Placement') {
16435: $showncrstype = 'placement test';
16436: } else {
16437: $showncrstype = lc($args->{'crstype'});
16438: }
1.444 albertel 16439: my %cenv=();
16440: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16441: $args->{'cdescr'},
16442: $args->{'curl'},
16443: $args->{'course_home'},
16444: $args->{'nonstandard'},
16445: $args->{'crscode'},
16446: $args->{'ccuname'}.':'.
16447: $args->{'ccdomain'},
1.882 raeburn 16448: $args->{'crstype'},
1.1344 raeburn 16449: $cnum,$context,$category,
16450: $callercontext);
1.444 albertel 16451:
16452: # Note: The testing routines depend on this being output; see
16453: # Utils::Course. This needs to at least be output as a comment
16454: # if anyone ever decides to not show this, and Utils::Course::new
16455: # will need to be suitably modified.
1.1344 raeburn 16456: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16457: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16458: } else {
16459: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16460: }
1.943 raeburn 16461: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16462: return (0,$outcome,$clonemsgref);
1.943 raeburn 16463: }
16464:
1.444 albertel 16465: #
16466: # Check if created correctly
16467: #
1.479 albertel 16468: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16469: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16470: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16471: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16472: $outcome .= &mt_user($user_lh,
16473: 'Course creation failed, unrecognized course home server.');
16474: } else {
16475: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16476: }
16477: $outcome .= $linefeed;
16478: return (0,$outcome,$clonemsgref);
1.943 raeburn 16479: }
1.541 raeburn 16480: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16481:
1.444 albertel 16482: #
1.566 albertel 16483: # Do the cloning
16484: #
1.1344 raeburn 16485: my @clonemsg;
1.566 albertel 16486: if ($can_clone && $cloneid) {
1.1344 raeburn 16487: push(@clonemsg,
16488: {
16489: mt => 'Created [_1] by cloning from [_2]',
16490: args => [$showncrstype,$clonetitle],
16491: });
1.566 albertel 16492: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16493: # Copy all files
1.1344 raeburn 16494: my @info =
16495: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16496: $args->{'dateshift'},$args->{'crscode'},
16497: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16498: $args->{'tinyurls'});
16499: if (@info) {
16500: push(@clonemsg,@info);
16501: }
1.444 albertel 16502: # Restore URL
1.566 albertel 16503: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16504: # Restore title
1.566 albertel 16505: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16506: # Restore creation date, creator and creation context.
16507: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16508: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16509: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16510: # Mark as cloned
1.566 albertel 16511: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16512: # Need to clone grading mode
16513: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16514: $cenv{'grading'}=$newenv{'grading'};
16515: # Do not clone these environment entries
16516: &Apache::lonnet::del('environment',
16517: ['default_enrollment_start_date',
16518: 'default_enrollment_end_date',
16519: 'question.email',
16520: 'policy.email',
16521: 'comment.email',
16522: 'pch.users.denied',
1.725 raeburn 16523: 'plc.users.denied',
16524: 'hidefromcat',
1.1121 raeburn 16525: 'checkforpriv',
1.1355 raeburn 16526: 'categories'],
1.638 www 16527: $$crsudom,$$crsunum);
1.1170 raeburn 16528: if ($args->{'textbook'}) {
16529: $cenv{'internal.textbook'} = $args->{'textbook'};
16530: }
1.444 albertel 16531: }
1.566 albertel 16532:
1.444 albertel 16533: #
16534: # Set environment (will override cloned, if existing)
16535: #
16536: my @sections = ();
16537: my @xlists = ();
16538: if ($args->{'crstype'}) {
16539: $cenv{'type'}=$args->{'crstype'};
16540: }
1.1371 raeburn 16541: if ($args->{'lti'}) {
16542: $cenv{'internal.lti'}=$args->{'lti'};
16543: }
1.444 albertel 16544: if ($args->{'crsid'}) {
16545: $cenv{'courseid'}=$args->{'crsid'};
16546: }
16547: if ($args->{'crscode'}) {
16548: $cenv{'internal.coursecode'}=$args->{'crscode'};
16549: }
16550: if ($args->{'crsquota'} ne '') {
16551: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16552: } else {
16553: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16554: }
16555: if ($args->{'ccuname'}) {
16556: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16557: ':'.$args->{'ccdomain'};
16558: } else {
16559: $cenv{'internal.courseowner'} = $args->{'curruser'};
16560: }
1.1116 raeburn 16561: if ($args->{'defaultcredits'}) {
16562: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16563: }
1.444 albertel 16564: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16565: if ($args->{'crssections'}) {
16566: $cenv{'internal.sectionnums'} = '';
16567: if ($args->{'crssections'} =~ m/,/) {
16568: @sections = split/,/,$args->{'crssections'};
16569: } else {
16570: $sections[0] = $args->{'crssections'};
16571: }
16572: if (@sections > 0) {
16573: foreach my $item (@sections) {
16574: my ($sec,$gp) = split/:/,$item;
16575: my $class = $args->{'crscode'}.$sec;
16576: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16577: $cenv{'internal.sectionnums'} .= $item.',';
16578: unless ($addcheck eq 'ok') {
1.1263 raeburn 16579: push(@badclasses,$class);
1.444 albertel 16580: }
16581: }
16582: $cenv{'internal.sectionnums'} =~ s/,$//;
16583: }
16584: }
16585: # do not hide course coordinator from staff listing,
16586: # even if privileged
16587: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16588: # add course coordinator's domain to domains to check for privileged users
16589: # if different to course domain
16590: if ($$crsudom ne $args->{'ccdomain'}) {
16591: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16592: }
1.444 albertel 16593: # add crosslistings
16594: if ($args->{'crsxlist'}) {
16595: $cenv{'internal.crosslistings'}='';
16596: if ($args->{'crsxlist'} =~ m/,/) {
16597: @xlists = split/,/,$args->{'crsxlist'};
16598: } else {
16599: $xlists[0] = $args->{'crsxlist'};
16600: }
16601: if (@xlists > 0) {
16602: foreach my $item (@xlists) {
16603: my ($xl,$gp) = split/:/,$item;
16604: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16605: $cenv{'internal.crosslistings'} .= $item.',';
16606: unless ($addcheck eq 'ok') {
1.1263 raeburn 16607: push(@badclasses,$xl);
1.444 albertel 16608: }
16609: }
16610: $cenv{'internal.crosslistings'} =~ s/,$//;
16611: }
16612: }
16613: if ($args->{'autoadds'}) {
16614: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16615: }
16616: if ($args->{'autodrops'}) {
16617: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16618: }
16619: # check for notification of enrollment changes
16620: my @notified = ();
16621: if ($args->{'notify_owner'}) {
16622: if ($args->{'ccuname'} ne '') {
16623: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16624: }
16625: }
16626: if ($args->{'notify_dc'}) {
16627: if ($uname ne '') {
1.630 raeburn 16628: push(@notified,$uname.':'.$udom);
1.444 albertel 16629: }
16630: }
16631: if (@notified > 0) {
16632: my $notifylist;
16633: if (@notified > 1) {
16634: $notifylist = join(',',@notified);
16635: } else {
16636: $notifylist = $notified[0];
16637: }
16638: $cenv{'internal.notifylist'} = $notifylist;
16639: }
16640: if (@badclasses > 0) {
16641: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16642: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16643: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16644: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16645: );
1.1264 raeburn 16646: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16647: &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 16648: if ($context eq 'auto') {
16649: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16650: } else {
1.566 albertel 16651: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16652: }
16653: foreach my $item (@badclasses) {
1.541 raeburn 16654: if ($context eq 'auto') {
1.1261 raeburn 16655: $outcome .= " - $item\n";
1.541 raeburn 16656: } else {
1.1261 raeburn 16657: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16658: }
1.1261 raeburn 16659: }
16660: if ($context eq 'auto') {
16661: $outcome .= $linefeed;
16662: } else {
16663: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16664: }
1.444 albertel 16665: }
16666: if ($args->{'no_end_date'}) {
16667: $args->{'endaccess'} = 0;
16668: }
16669: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16670: $cenv{'internal.autoend'}=$args->{'enrollend'};
16671: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16672: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16673: if ($args->{'showphotos'}) {
16674: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16675: }
16676: $cenv{'internal.authtype'} = $args->{'authtype'};
16677: $cenv{'internal.autharg'} = $args->{'autharg'};
16678: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16679: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16680: 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');
16681: if ($context eq 'auto') {
16682: $outcome .= $krb_msg;
16683: } else {
1.566 albertel 16684: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16685: }
16686: $outcome .= $linefeed;
1.444 albertel 16687: }
16688: }
16689: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16690: if ($args->{'setpolicy'}) {
16691: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16692: }
16693: if ($args->{'setcontent'}) {
16694: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16695: }
1.1251 raeburn 16696: if ($args->{'setcomment'}) {
16697: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16698: }
1.444 albertel 16699: }
16700: if ($args->{'reshome'}) {
16701: $cenv{'reshome'}=$args->{'reshome'}.'/';
16702: $cenv{'reshome'}=~s/\/+$/\//;
16703: }
16704: #
16705: # course has keyed access
16706: #
16707: if ($args->{'setkeys'}) {
16708: $cenv{'keyaccess'}='yes';
16709: }
16710: # if specified, key authority is not course, but user
16711: # only active if keyaccess is yes
16712: if ($args->{'keyauth'}) {
1.487 albertel 16713: my ($user,$domain) = split(':',$args->{'keyauth'});
16714: $user = &LONCAPA::clean_username($user);
16715: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16716: if ($user ne '' && $domain ne '') {
1.487 albertel 16717: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16718: }
16719: }
16720:
1.1166 raeburn 16721: #
1.1167 raeburn 16722: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16723: #
16724: if ($args->{'uniquecode'}) {
16725: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16726: if ($code) {
16727: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16728: my %crsinfo =
16729: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16730: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16731: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16732: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16733: }
1.1166 raeburn 16734: if (ref($coderef)) {
16735: $$coderef = $code;
16736: }
16737: }
16738: }
16739:
1.444 albertel 16740: if ($args->{'disresdis'}) {
16741: $cenv{'pch.roles.denied'}='st';
16742: }
16743: if ($args->{'disablechat'}) {
16744: $cenv{'plc.roles.denied'}='st';
16745: }
16746:
16747: # Record we've not yet viewed the Course Initialization Helper for this
16748: # course
16749: $cenv{'course.helper.not.run'} = 1;
16750: #
16751: # Use new Randomseed
16752: #
16753: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16754: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16755: #
16756: # The encryption code and receipt prefix for this course
16757: #
16758: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16759: $cenv{'internal.encpref'}=100+int(9*rand(99));
16760: #
16761: # By default, use standard grading
16762: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16763:
1.541 raeburn 16764: $outcome .= $linefeed.&mt('Setting environment').': '.
16765: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16766: #
16767: # Open all assignments
16768: #
16769: if ($args->{'openall'}) {
1.1341 raeburn 16770: my $opendate = time;
16771: if ($args->{'openallfrom'} =~ /^\d+$/) {
16772: $opendate = $args->{'openallfrom'};
16773: }
1.444 albertel 16774: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16775: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16776: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16777: $outcome .= &mt('All assignments open starting [_1]',
16778: &Apache::lonlocal::locallocaltime($opendate)).': '.
16779: &Apache::lonnet::cput
16780: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16781: }
16782: #
16783: # Set first page
16784: #
16785: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16786: || ($cloneid)) {
1.445 albertel 16787: use LONCAPA::map;
1.444 albertel 16788: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16789:
16790: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16791: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16792:
1.444 albertel 16793: $outcome .= ($fatal?$errtext:'read ok').' - ';
16794: my $title; my $url;
16795: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16796: $title=&mt('Syllabus');
1.444 albertel 16797: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16798: } else {
1.963 raeburn 16799: $title=&mt('Table of Contents');
1.444 albertel 16800: $url='/adm/navmaps';
16801: }
1.445 albertel 16802:
16803: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16804: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16805:
16806: if ($errtext) { $fatal=2; }
1.541 raeburn 16807: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16808: }
1.566 albertel 16809:
1.1237 raeburn 16810: #
16811: # Set params for Placement Tests
16812: #
1.1239 raeburn 16813: if ($args->{'crstype'} eq 'Placement') {
16814: my %storecontent;
16815: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16816: my %defaults = (
16817: buttonshide => { value => 'yes',
16818: type => 'string_yesno',},
16819: type => { value => 'randomizetry',
16820: type => 'string_questiontype',},
16821: maxtries => { value => 1,
16822: type => 'int_pos',},
16823: problemstatus => { value => 'no',
16824: type => 'string_problemstatus',},
16825: );
16826: foreach my $key (keys(%defaults)) {
16827: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16828: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16829: }
1.1237 raeburn 16830: &Apache::lonnet::cput
16831: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16832: }
16833:
1.1344 raeburn 16834: return (1,$outcome,\@clonemsg);
1.444 albertel 16835: }
16836:
1.1166 raeburn 16837: sub make_unique_code {
16838: my ($cdom,$cnum) = @_;
16839: # get lock on uniquecodes db
16840: my $lockhash = {
16841: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16842: ':'.$env{'user.domain'},
16843: };
16844: my $tries = 0;
16845: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16846: my ($code,$error);
16847:
16848: while (($gotlock ne 'ok') && ($tries<3)) {
16849: $tries ++;
16850: sleep 1;
16851: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16852: }
16853: if ($gotlock eq 'ok') {
16854: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16855: my $gotcode;
16856: my $attempts = 0;
16857: while ((!$gotcode) && ($attempts < 100)) {
16858: $code = &generate_code();
16859: if (!exists($currcodes{$code})) {
16860: $gotcode = 1;
16861: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16862: $error = 'nostore';
16863: }
16864: }
16865: $attempts ++;
16866: }
16867: my @del_lock = ($cnum."\0".'uniquecodes');
16868: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16869: } else {
16870: $error = 'nolock';
16871: }
16872: return ($code,$error);
16873: }
16874:
16875: sub generate_code {
16876: my $code;
16877: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16878: for (my $i=0; $i<6; $i++) {
16879: my $lettnum = int (rand 2);
16880: my $item = '';
16881: if ($lettnum) {
16882: $item = $letts[int( rand(18) )];
16883: } else {
16884: $item = 1+int( rand(8) );
16885: }
16886: $code .= $item;
16887: }
16888: return $code;
16889: }
16890:
1.444 albertel 16891: ############################################################
16892: ############################################################
16893:
1.1237 raeburn 16894: # Community, Course and Placement Test
1.378 raeburn 16895: sub course_type {
16896: my ($cid) = @_;
16897: if (!defined($cid)) {
16898: $cid = $env{'request.course.id'};
16899: }
1.404 albertel 16900: if (defined($env{'course.'.$cid.'.type'})) {
16901: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16902: } else {
16903: return 'Course';
1.377 raeburn 16904: }
16905: }
1.156 albertel 16906:
1.406 raeburn 16907: sub group_term {
16908: my $crstype = &course_type();
16909: my %names = (
16910: 'Course' => 'group',
1.865 raeburn 16911: 'Community' => 'group',
1.1237 raeburn 16912: 'Placement' => 'group',
1.406 raeburn 16913: );
16914: return $names{$crstype};
16915: }
16916:
1.902 raeburn 16917: sub course_types {
1.1310 raeburn 16918: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16919: my %typename = (
16920: official => 'Official course',
16921: unofficial => 'Unofficial course',
16922: community => 'Community',
1.1165 raeburn 16923: textbook => 'Textbook course',
1.1237 raeburn 16924: placement => 'Placement test',
1.1310 raeburn 16925: lti => 'LTI provider',
1.902 raeburn 16926: );
16927: return (\@types,\%typename);
16928: }
16929:
1.156 albertel 16930: sub icon {
16931: my ($file)=@_;
1.505 albertel 16932: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16933: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16934: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16935: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16936: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16937: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16938: $curfext.".gif") {
16939: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16940: $curfext.".gif";
16941: }
16942: }
1.249 albertel 16943: return &lonhttpdurl($iconname);
1.154 albertel 16944: }
1.84 albertel 16945:
1.575 albertel 16946: sub lonhttpdurl {
1.692 www 16947: #
16948: # Had been used for "small fry" static images on separate port 8080.
16949: # Modify here if lightweight http functionality desired again.
16950: # Currently eliminated due to increasing firewall issues.
16951: #
1.575 albertel 16952: my ($url)=@_;
1.692 www 16953: return $url;
1.215 albertel 16954: }
16955:
1.213 albertel 16956: sub connection_aborted {
16957: my ($r)=@_;
16958: $r->print(" ");$r->rflush();
16959: my $c = $r->connection;
16960: return $c->aborted();
16961: }
16962:
1.221 foxr 16963: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16964: # strings as 'strings'.
16965: sub escape_single {
1.221 foxr 16966: my ($input) = @_;
1.223 albertel 16967: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16968: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16969: return $input;
16970: }
1.223 albertel 16971:
1.222 foxr 16972: # Same as escape_single, but escape's "'s This
16973: # can be used for "strings"
16974: sub escape_double {
16975: my ($input) = @_;
16976: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16977: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16978: return $input;
16979: }
1.223 albertel 16980:
1.222 foxr 16981: # Escapes the last element of a full URL.
16982: sub escape_url {
16983: my ($url) = @_;
1.238 raeburn 16984: my @urlslices = split(/\//, $url,-1);
1.369 www 16985: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16986: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16987: }
1.462 albertel 16988:
1.820 raeburn 16989: sub compare_arrays {
16990: my ($arrayref1,$arrayref2) = @_;
16991: my (@difference,%count);
16992: @difference = ();
16993: %count = ();
16994: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16995: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16996: foreach my $element (keys(%count)) {
16997: if ($count{$element} == 1) {
16998: push(@difference,$element);
16999: }
17000: }
17001: }
17002: return @difference;
17003: }
17004:
1.1322 raeburn 17005: sub lon_status_items {
17006: my %defaults = (
17007: E => 100,
17008: W => 4,
17009: N => 1,
1.1324 raeburn 17010: U => 5,
1.1322 raeburn 17011: threshold => 200,
17012: sysmail => 2500,
17013: );
17014: my %names = (
17015: E => 'Errors',
17016: W => 'Warnings',
17017: N => 'Notices',
1.1324 raeburn 17018: U => 'Unsent',
1.1322 raeburn 17019: );
17020: return (\%defaults,\%names);
17021: }
17022:
1.817 bisitz 17023: # -------------------------------------------------------- Initialize user login
1.462 albertel 17024: sub init_user_environment {
1.463 albertel 17025: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17026: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17027:
17028: my $public=($username eq 'public' && $domain eq 'public');
17029:
1.1062 raeburn 17030: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 17031: my $now=time;
17032:
17033: if ($public) {
17034: my $max_public=100;
17035: my $oldest;
17036: my $oldest_time=0;
17037: for(my $next=1;$next<=$max_public;$next++) {
17038: if (-e $lonids."/publicuser_$next.id") {
17039: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17040: if ($mtime<$oldest_time || !$oldest_time) {
17041: $oldest_time=$mtime;
17042: $oldest=$next;
17043: }
17044: } else {
17045: $cookie="publicuser_$next";
17046: last;
17047: }
17048: }
17049: if (!$cookie) { $cookie="publicuser_$oldest"; }
17050: } else {
1.1275 raeburn 17051: # See if old ID present, if so, remove if this isn't a robot,
17052: # killing any existing non-robot sessions
1.463 albertel 17053: if (!$args->{'robot'}) {
17054: opendir(DIR,$lonids);
17055: while ($filename=readdir(DIR)) {
17056: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17057: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17058: &GDBM_READER(),0640)) {
1.1295 raeburn 17059: my $linkedfile;
1.1320 raeburn 17060: if (exists($oldenv{'user.linkedenv'})) {
17061: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17062: }
1.1320 raeburn 17063: untie(%oldenv);
17064: if (unlink("$lonids/$filename")) {
17065: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17066: if (-l "$lonids/$linkedfile.id") {
17067: unlink("$lonids/$linkedfile.id");
17068: }
1.1295 raeburn 17069: }
17070: }
17071: } else {
17072: unlink($lonids.'/'.$filename);
17073: }
1.463 albertel 17074: }
1.462 albertel 17075: }
1.463 albertel 17076: closedir(DIR);
1.1204 raeburn 17077: # If there is a undeleted lockfile for the user's paste buffer remove it.
17078: my $namespace = 'nohist_courseeditor';
17079: my $lockingkey = 'paste'."\0".'locked_num';
17080: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17081: $domain,$username);
17082: if (exists($lockhash{$lockingkey})) {
17083: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17084: unless ($delresult eq 'ok') {
17085: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17086: }
17087: }
1.462 albertel 17088: }
17089: # Give them a new cookie
1.463 albertel 17090: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17091: : $now.$$.int(rand(10000)));
1.463 albertel 17092: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17093:
17094: # Initialize roles
17095:
1.1062 raeburn 17096: ($userroles,$firstaccenv,$timerintenv) =
17097: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17098: }
17099: # ------------------------------------ Check browser type and MathML capability
17100:
1.1194 raeburn 17101: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17102: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17103:
17104: # ------------------------------------------------------------- Get environment
17105:
17106: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17107: my ($tmp) = keys(%userenv);
1.1275 raeburn 17108: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17109: undef(%userenv);
17110: }
17111: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17112: $form->{'interface'}=$userenv{'interface'};
17113: }
17114: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17115:
17116: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17117: foreach my $option ('interface','localpath','localres') {
17118: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17119: }
17120: # --------------------------------------------------------- Write first profile
17121:
17122: {
1.1350 raeburn 17123: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17124: my %initial_env =
17125: ("user.name" => $username,
17126: "user.domain" => $domain,
17127: "user.home" => $authhost,
17128: "browser.type" => $clientbrowser,
17129: "browser.version" => $clientversion,
17130: "browser.mathml" => $clientmathml,
17131: "browser.unicode" => $clientunicode,
17132: "browser.os" => $clientos,
1.1137 raeburn 17133: "browser.mobile" => $clientmobile,
1.1141 raeburn 17134: "browser.info" => $clientinfo,
1.1194 raeburn 17135: "browser.osversion" => $clientosversion,
1.462 albertel 17136: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17137: "request.course.fn" => '',
17138: "request.course.uri" => '',
17139: "request.course.sec" => '',
17140: "request.role" => 'cm',
17141: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17142: "request.host" => $ip,);
1.462 albertel 17143:
17144: if ($form->{'localpath'}) {
17145: $initial_env{"browser.localpath"} = $form->{'localpath'};
17146: $initial_env{"browser.localres"} = $form->{'localres'};
17147: }
17148:
17149: if ($form->{'interface'}) {
17150: $form->{'interface'}=~s/\W//gs;
17151: $initial_env{"browser.interface"} = $form->{'interface'};
17152: $env{'browser.interface'}=$form->{'interface'};
17153: }
17154:
1.1157 raeburn 17155: if ($form->{'iptoken'}) {
17156: my $lonhost = $r->dir_config('lonHostID');
17157: $initial_env{"user.noloadbalance"} = $lonhost;
17158: $env{'user.noloadbalance'} = $lonhost;
17159: }
17160:
1.1268 raeburn 17161: if ($form->{'noloadbalance'}) {
17162: my @hosts = &Apache::lonnet::current_machine_ids();
17163: my $hosthere = $form->{'noloadbalance'};
17164: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17165: $initial_env{"user.noloadbalance"} = $hosthere;
17166: $env{'user.noloadbalance'} = $hosthere;
17167: }
17168: }
17169:
1.1016 raeburn 17170: unless ($domain eq 'public') {
1.1273 raeburn 17171: my %is_adv = ( is_adv => $env{'user.adv'} );
17172: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17173:
17174: foreach my $tool ('aboutme','blog','webdav','portfolio') {
17175: $userenv{'availabletools.'.$tool} =
17176: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17177: undef,\%userenv,\%domdef,\%is_adv);
17178: }
1.980 raeburn 17179:
1.1311 raeburn 17180: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17181: $userenv{'canrequest.'.$crstype} =
17182: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17183: 'reload','requestcourses',
17184: \%userenv,\%domdef,\%is_adv);
17185: }
1.724 raeburn 17186:
1.1273 raeburn 17187: $userenv{'canrequest.author'} =
17188: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17189: 'reload','requestauthor',
1.980 raeburn 17190: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17191: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17192: $domain,$username);
17193: my $reqstatus = $reqauthor{'author_status'};
17194: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17195: if (ref($reqauthor{'author'}) eq 'HASH') {
17196: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17197: $reqauthor{'author'}{'timestamp'};
17198: }
1.1092 raeburn 17199: }
1.1287 raeburn 17200: my ($types,$typename) = &course_types();
17201: if (ref($types) eq 'ARRAY') {
17202: my @options = ('approval','validate','autolimit');
17203: my $optregex = join('|',@options);
17204: my (%willtrust,%trustchecked);
17205: foreach my $type (@{$types}) {
17206: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17207: if ($dom_str ne '') {
17208: my $updatedstr = '';
17209: my @possdomains = split(',',$dom_str);
17210: foreach my $entry (@possdomains) {
17211: my ($extdom,$extopt) = split(':',$entry);
17212: unless ($trustchecked{$extdom}) {
17213: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17214: $trustchecked{$extdom} = 1;
17215: }
17216: if ($willtrust{$extdom}) {
17217: $updatedstr .= $entry.',';
17218: }
17219: }
17220: $updatedstr =~ s/,$//;
17221: if ($updatedstr) {
17222: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17223: } else {
17224: delete($userenv{'reqcrsotherdom.'.$type});
17225: }
17226: }
17227: }
17228: }
1.1092 raeburn 17229: }
1.462 albertel 17230: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17231:
1.462 albertel 17232: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17233: &GDBM_WRCREAT(),0640)) {
17234: &_add_to_env(\%disk_env,\%initial_env);
17235: &_add_to_env(\%disk_env,\%userenv,'environment.');
17236: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17237: if (ref($firstaccenv) eq 'HASH') {
17238: &_add_to_env(\%disk_env,$firstaccenv);
17239: }
17240: if (ref($timerintenv) eq 'HASH') {
17241: &_add_to_env(\%disk_env,$timerintenv);
17242: }
1.463 albertel 17243: if (ref($args->{'extra_env'})) {
17244: &_add_to_env(\%disk_env,$args->{'extra_env'});
17245: }
1.462 albertel 17246: untie(%disk_env);
17247: } else {
1.705 tempelho 17248: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17249: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17250: return 'error: '.$!;
17251: }
17252: }
17253: $env{'request.role'}='cm';
17254: $env{'request.role.adv'}=$env{'user.adv'};
17255: $env{'browser.type'}=$clientbrowser;
17256:
17257: return $cookie;
17258:
17259: }
17260:
17261: sub _add_to_env {
17262: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17263: if (ref($env_data) eq 'HASH') {
17264: while (my ($key,$value) = each(%$env_data)) {
17265: $idf->{$prefix.$key} = $value;
17266: $env{$prefix.$key} = $value;
17267: }
1.462 albertel 17268: }
17269: }
17270:
1.685 tempelho 17271: # --- Get the symbolic name of a problem and the url
17272: sub get_symb {
17273: my ($request,$silent) = @_;
1.726 raeburn 17274: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17275: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17276: if ($symb eq '') {
17277: if (!$silent) {
1.1071 raeburn 17278: if (ref($request)) {
17279: $request->print("Unable to handle ambiguous references:$url:.");
17280: }
1.685 tempelho 17281: return ();
17282: }
17283: }
17284: &Apache::lonenc::check_decrypt(\$symb);
17285: return ($symb);
17286: }
17287:
17288: # --------------------------------------------------------------Get annotation
17289:
17290: sub get_annotation {
17291: my ($symb,$enc) = @_;
17292:
17293: my $key = $symb;
17294: if (!$enc) {
17295: $key =
17296: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17297: }
17298: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17299: return $annotation{$key};
17300: }
17301:
17302: sub clean_symb {
1.731 raeburn 17303: my ($symb,$delete_enc) = @_;
1.685 tempelho 17304:
17305: &Apache::lonenc::check_decrypt(\$symb);
17306: my $enc = $env{'request.enc'};
1.731 raeburn 17307: if ($delete_enc) {
1.730 raeburn 17308: delete($env{'request.enc'});
17309: }
1.685 tempelho 17310:
17311: return ($symb,$enc);
17312: }
1.462 albertel 17313:
1.1181 raeburn 17314: ############################################################
17315: ############################################################
17316:
17317: =pod
17318:
17319: =head1 Routines for building display used to search for courses
17320:
17321:
17322: =over 4
17323:
17324: =item * &build_filters()
17325:
17326: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17327: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17328: and quotacheck.pl
17329:
1.1181 raeburn 17330:
17331: Inputs:
17332:
17333: filterlist - anonymous array of fields to include as potential filters
17334:
17335: crstype - course type
17336:
17337: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17338: to pop-open a course selector (will contain "extra element").
17339:
17340: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17341:
17342: filter - anonymous hash of criteria and their values
17343:
17344: action - form action
17345:
17346: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17347:
1.1182 raeburn 17348: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17349:
17350: cloneruname - username of owner of new course who wants to clone
17351:
17352: clonerudom - domain of owner of new course who wants to clone
17353:
17354: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17355:
17356: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17357:
17358: codedom - domain
17359:
17360: formname - value of form element named "form".
17361:
17362: fixeddom - domain, if fixed.
17363:
17364: prevphase - value to assign to form element named "phase" when going back to the previous screen
17365:
17366: cnameelement - name of form element in form on opener page which will receive title of selected course
17367:
17368: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17369:
17370: cdomelement - name of form element in form on opener page which will receive domain of selected course
17371:
17372: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17373:
17374: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17375:
17376: clonewarning - warning message about missing information for intended course owner when DC creates a course
17377:
1.1182 raeburn 17378:
1.1181 raeburn 17379: Returns: $output - HTML for display of search criteria, and hidden form elements.
17380:
1.1182 raeburn 17381:
1.1181 raeburn 17382: Side Effects: None
17383:
17384: =cut
17385:
17386: # ---------------------------------------------- search for courses based on last activity etc.
17387:
17388: sub build_filters {
17389: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17390: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17391: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17392: $cnameelement,$cnumelement,$cdomelement,$setroles,
17393: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17394: my ($list,$jscript);
1.1181 raeburn 17395: my $onchange = 'javascript:updateFilters(this)';
17396: my ($domainselectform,$sincefilterform,$createdfilterform,
17397: $ownerdomselectform,$persondomselectform,$instcodeform,
17398: $typeselectform,$instcodetitle);
17399: if ($formname eq '') {
17400: $formname = $caller;
17401: }
17402: foreach my $item (@{$filterlist}) {
17403: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17404: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17405: if ($item eq 'domainfilter') {
17406: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17407: } elsif ($item eq 'coursefilter') {
17408: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17409: } elsif ($item eq 'ownerfilter') {
17410: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17411: } elsif ($item eq 'ownerdomfilter') {
17412: $filter->{'ownerdomfilter'} =
17413: &LONCAPA::clean_domain($filter->{$item});
17414: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17415: 'ownerdomfilter',1);
17416: } elsif ($item eq 'personfilter') {
17417: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17418: } elsif ($item eq 'persondomfilter') {
17419: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17420: 'persondomfilter',1);
17421: } else {
17422: $filter->{$item} =~ s/\W//g;
17423: }
17424: if (!$filter->{$item}) {
17425: $filter->{$item} = '';
17426: }
17427: }
17428: if ($item eq 'domainfilter') {
17429: my $allow_blank = 1;
17430: if ($formname eq 'portform') {
17431: $allow_blank=0;
17432: } elsif ($formname eq 'studentform') {
17433: $allow_blank=0;
17434: }
17435: if ($fixeddom) {
17436: $domainselectform = '<input type="hidden" name="domainfilter"'.
17437: ' value="'.$codedom.'" />'.
17438: &Apache::lonnet::domain($codedom,'description');
17439: } else {
17440: $domainselectform = &select_dom_form($filter->{$item},
17441: 'domainfilter',
17442: $allow_blank,'',$onchange);
17443: }
17444: } else {
17445: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17446: }
17447: }
17448:
17449: # last course activity filter and selection
17450: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17451:
17452: # course created filter and selection
17453: if (exists($filter->{'createdfilter'})) {
17454: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17455: }
17456:
1.1239 raeburn 17457: my $prefix = $crstype;
17458: if ($crstype eq 'Placement') {
17459: $prefix = 'Placement Test'
17460: }
1.1181 raeburn 17461: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17462: 'cac' => "$prefix Activity",
17463: 'ccr' => "$prefix Created",
17464: 'cde' => "$prefix Title",
17465: 'cdo' => "$prefix Domain",
1.1181 raeburn 17466: 'ins' => 'Institutional Code',
17467: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17468: 'cow' => "$prefix Owner/Co-owner",
17469: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17470: 'cog' => 'Type',
17471: );
17472:
17473: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17474: my $typeval = 'Course';
17475: if ($crstype eq 'Community') {
17476: $typeval = 'Community';
1.1239 raeburn 17477: } elsif ($crstype eq 'Placement') {
17478: $typeval = 'Placement';
1.1181 raeburn 17479: }
17480: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17481: } else {
17482: $typeselectform = '<select name="type" size="1"';
17483: if ($onchange) {
17484: $typeselectform .= ' onchange="'.$onchange.'"';
17485: }
17486: $typeselectform .= '>'."\n";
1.1237 raeburn 17487: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17488: my $shown;
17489: if ($posstype eq 'Placement') {
17490: $shown = &mt('Placement Test');
17491: } else {
17492: $shown = &mt($posstype);
17493: }
1.1181 raeburn 17494: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17495: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17496: }
17497: $typeselectform.="</select>";
17498: }
17499:
17500: my ($cloneableonlyform,$cloneabletitle);
17501: if (exists($filter->{'cloneableonly'})) {
17502: my $cloneableon = '';
17503: my $cloneableoff = ' checked="checked"';
17504: if ($filter->{'cloneableonly'}) {
17505: $cloneableon = $cloneableoff;
17506: $cloneableoff = '';
17507: }
17508: $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>';
17509: if ($formname eq 'ccrs') {
1.1187 bisitz 17510: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17511: } else {
17512: $cloneabletitle = &mt('Cloneable by you');
17513: }
17514: }
17515: my $officialjs;
17516: if ($crstype eq 'Course') {
17517: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17518: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17519: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17520: if ($codedom) {
1.1181 raeburn 17521: $officialjs = 1;
17522: ($instcodeform,$jscript,$$numtitlesref) =
17523: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17524: $officialjs,$codetitlesref);
17525: if ($jscript) {
1.1182 raeburn 17526: $jscript = '<script type="text/javascript">'."\n".
17527: '// <![CDATA['."\n".
17528: $jscript."\n".
17529: '// ]]>'."\n".
17530: '</script>'."\n";
1.1181 raeburn 17531: }
17532: }
17533: if ($instcodeform eq '') {
17534: $instcodeform =
17535: '<input type="text" name="instcodefilter" size="10" value="'.
17536: $list->{'instcodefilter'}.'" />';
17537: $instcodetitle = $lt{'ins'};
17538: } else {
17539: $instcodetitle = $lt{'inc'};
17540: }
17541: if ($fixeddom) {
17542: $instcodetitle .= '<br />('.$codedom.')';
17543: }
17544: }
17545: }
17546: my $output = qq|
17547: <form method="post" name="filterpicker" action="$action">
17548: <input type="hidden" name="form" value="$formname" />
17549: |;
17550: if ($formname eq 'modifycourse') {
17551: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17552: '<input type="hidden" name="prevphase" value="'.
17553: $prevphase.'" />'."\n";
1.1198 musolffc 17554: } elsif ($formname eq 'quotacheck') {
17555: $output .= qq|
17556: <input type="hidden" name="sortby" value="" />
17557: <input type="hidden" name="sortorder" value="" />
17558: |;
17559: } else {
1.1181 raeburn 17560: my $name_input;
17561: if ($cnameelement ne '') {
17562: $name_input = '<input type="hidden" name="cnameelement" value="'.
17563: $cnameelement.'" />';
17564: }
17565: $output .= qq|
1.1182 raeburn 17566: <input type="hidden" name="cnumelement" value="$cnumelement" />
17567: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17568: $name_input
17569: $roleelement
17570: $multelement
17571: $typeelement
17572: |;
17573: if ($formname eq 'portform') {
17574: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17575: }
17576: }
17577: if ($fixeddom) {
17578: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17579: }
17580: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17581: if ($sincefilterform) {
17582: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17583: .$sincefilterform
17584: .&Apache::lonhtmlcommon::row_closure();
17585: }
17586: if ($createdfilterform) {
17587: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17588: .$createdfilterform
17589: .&Apache::lonhtmlcommon::row_closure();
17590: }
17591: if ($domainselectform) {
17592: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17593: .$domainselectform
17594: .&Apache::lonhtmlcommon::row_closure();
17595: }
17596: if ($typeselectform) {
17597: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17598: $output .= $typeselectform;
17599: } else {
17600: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17601: .$typeselectform
17602: .&Apache::lonhtmlcommon::row_closure();
17603: }
17604: }
17605: if ($instcodeform) {
17606: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17607: .$instcodeform
17608: .&Apache::lonhtmlcommon::row_closure();
17609: }
17610: if (exists($filter->{'ownerfilter'})) {
17611: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17612: '<table><tr><td>'.&mt('Username').'<br />'.
17613: '<input type="text" name="ownerfilter" size="20" value="'.
17614: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17615: $ownerdomselectform.'</td></tr></table>'.
17616: &Apache::lonhtmlcommon::row_closure();
17617: }
17618: if (exists($filter->{'personfilter'})) {
17619: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17620: '<table><tr><td>'.&mt('Username').'<br />'.
17621: '<input type="text" name="personfilter" size="20" value="'.
17622: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17623: $persondomselectform.'</td></tr></table>'.
17624: &Apache::lonhtmlcommon::row_closure();
17625: }
17626: if (exists($filter->{'coursefilter'})) {
17627: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17628: .'<input type="text" name="coursefilter" size="25" value="'
17629: .$list->{'coursefilter'}.'" />'
17630: .&Apache::lonhtmlcommon::row_closure();
17631: }
17632: if ($cloneableonlyform) {
17633: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17634: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17635: }
17636: if (exists($filter->{'descriptfilter'})) {
17637: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17638: .'<input type="text" name="descriptfilter" size="40" value="'
17639: .$list->{'descriptfilter'}.'" />'
17640: .&Apache::lonhtmlcommon::row_closure(1);
17641: }
17642: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17643: '<input type="hidden" name="updater" value="" />'."\n".
17644: '<input type="submit" name="gosearch" value="'.
17645: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17646: return $jscript.$clonewarning.$output;
17647: }
17648:
17649: =pod
17650:
17651: =item * &timebased_select_form()
17652:
1.1182 raeburn 17653: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17654: filter e.g., Course Activity, Course Created, when searching for courses
17655: or communities
17656:
17657: Inputs:
17658:
17659: item - name of form element (sincefilter or createdfilter)
17660:
17661: filter - anonymous hash of criteria and their values
17662:
17663: Returns: HTML for a select box contained a blank, then six time selections,
17664: with value set in incoming form variables currently selected.
17665:
17666: Side Effects: None
17667:
17668: =cut
17669:
17670: sub timebased_select_form {
17671: my ($item,$filter) = @_;
17672: if (ref($filter) eq 'HASH') {
17673: $filter->{$item} =~ s/[^\d-]//g;
17674: if (!$filter->{$item}) { $filter->{$item}=-1; }
17675: return &select_form(
17676: $filter->{$item},
17677: $item,
17678: { '-1' => '',
17679: '86400' => &mt('today'),
17680: '604800' => &mt('last week'),
17681: '2592000' => &mt('last month'),
17682: '7776000' => &mt('last three months'),
17683: '15552000' => &mt('last six months'),
17684: '31104000' => &mt('last year'),
17685: 'select_form_order' =>
17686: ['-1','86400','604800','2592000','7776000',
17687: '15552000','31104000']});
17688: }
17689: }
17690:
17691: =pod
17692:
17693: =item * &js_changer()
17694:
17695: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17696: when course type or domain is changed, and also to hide 'Searching ...' on
17697: page load completion for page showing search result.
1.1181 raeburn 17698:
17699: Inputs: None
17700:
1.1183 raeburn 17701: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17702:
17703: Side Effects: None
17704:
17705: =cut
17706:
17707: sub js_changer {
17708: return <<ENDJS;
17709: <script type="text/javascript">
17710: // <![CDATA[
17711: function updateFilters(caller) {
17712: if (typeof(caller) != "undefined") {
17713: document.filterpicker.updater.value = caller.name;
17714: }
17715: document.filterpicker.submit();
17716: }
1.1183 raeburn 17717:
17718: function hideSearching() {
17719: if (document.getElementById('searching')) {
17720: document.getElementById('searching').style.display = 'none';
17721: }
17722: return;
17723: }
17724:
1.1181 raeburn 17725: // ]]>
17726: </script>
17727:
17728: ENDJS
17729: }
17730:
17731: =pod
17732:
1.1182 raeburn 17733: =item * &search_courses()
17734:
17735: Process selected filters form course search form and pass to lonnet::courseiddump
17736: to retrieve a hash for which keys are courseIDs which match the selected filters.
17737:
17738: Inputs:
17739:
17740: dom - domain being searched
17741:
17742: type - course type ('Course' or 'Community' or '.' if any).
17743:
17744: filter - anonymous hash of criteria and their values
17745:
17746: numtitles - for institutional codes - number of categories
17747:
17748: cloneruname - optional username of new course owner
17749:
17750: clonerudom - optional domain of new course owner
17751:
1.1221 raeburn 17752: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17753: (used when DC is using course creation form)
17754:
17755: codetitles - reference to array of titles of components in institutional codes (official courses).
17756:
1.1221 raeburn 17757: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17758: (and so can clone automatically)
17759:
17760: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17761:
17762: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17763: courses to clone
1.1182 raeburn 17764:
17765: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17766:
17767:
17768: Side Effects: None
17769:
17770: =cut
17771:
17772:
17773: sub search_courses {
1.1221 raeburn 17774: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17775: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17776: my (%courses,%showcourses,$cloner);
17777: if (($filter->{'ownerfilter'} ne '') ||
17778: ($filter->{'ownerdomfilter'} ne '')) {
17779: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17780: $filter->{'ownerdomfilter'};
17781: }
17782: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17783: if (!$filter->{$item}) {
17784: $filter->{$item}='.';
17785: }
17786: }
17787: my $now = time;
17788: my $timefilter =
17789: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17790: my ($createdbefore,$createdafter);
17791: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17792: $createdbefore = $now;
17793: $createdafter = $now-$filter->{'createdfilter'};
17794: }
17795: my ($instcodefilter,$regexpok);
17796: if ($numtitles) {
17797: if ($env{'form.official'} eq 'on') {
17798: $instcodefilter =
17799: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17800: $regexpok = 1;
17801: } elsif ($env{'form.official'} eq 'off') {
17802: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17803: unless ($instcodefilter eq '') {
17804: $regexpok = -1;
17805: }
17806: }
17807: } else {
17808: $instcodefilter = $filter->{'instcodefilter'};
17809: }
17810: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17811: if ($type eq '') { $type = '.'; }
17812:
17813: if (($clonerudom ne '') && ($cloneruname ne '')) {
17814: $cloner = $cloneruname.':'.$clonerudom;
17815: }
17816: %courses = &Apache::lonnet::courseiddump($dom,
17817: $filter->{'descriptfilter'},
17818: $timefilter,
17819: $instcodefilter,
17820: $filter->{'combownerfilter'},
17821: $filter->{'coursefilter'},
17822: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17823: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17824: $filter->{'cloneableonly'},
17825: $createdbefore,$createdafter,undef,
1.1221 raeburn 17826: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17827: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17828: my $ccrole;
17829: if ($type eq 'Community') {
17830: $ccrole = 'co';
17831: } else {
17832: $ccrole = 'cc';
17833: }
17834: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17835: $filter->{'persondomfilter'},
17836: 'userroles',undef,
17837: [$ccrole,'in','ad','ep','ta','cr'],
17838: $dom);
17839: foreach my $role (keys(%rolehash)) {
17840: my ($cnum,$cdom,$courserole) = split(':',$role);
17841: my $cid = $cdom.'_'.$cnum;
17842: if (exists($courses{$cid})) {
17843: if (ref($courses{$cid}) eq 'HASH') {
17844: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17845: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17846: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17847: }
17848: } else {
17849: $courses{$cid}{roles} = [$courserole];
17850: }
17851: $showcourses{$cid} = $courses{$cid};
17852: }
17853: }
17854: }
17855: %courses = %showcourses;
17856: }
17857: return %courses;
17858: }
17859:
17860: =pod
17861:
1.1181 raeburn 17862: =back
17863:
1.1207 raeburn 17864: =head1 Routines for version requirements for current course.
17865:
17866: =over 4
17867:
17868: =item * &check_release_required()
17869:
17870: Compares required LON-CAPA version with version on server, and
17871: if required version is newer looks for a server with the required version.
17872:
17873: Looks first at servers in user's owen domain; if none suitable, looks at
17874: servers in course's domain are permitted to host sessions for user's domain.
17875:
17876: Inputs:
17877:
17878: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17879:
17880: $courseid - Course ID of current course
17881:
17882: $rolecode - User's current role in course (for switchserver query string).
17883:
17884: $required - LON-CAPA version needed by course (format: Major.Minor).
17885:
17886:
17887: Returns:
17888:
17889: $switchserver - query string tp append to /adm/switchserver call (if
17890: current server's LON-CAPA version is too old.
17891:
17892: $warning - Message is displayed if no suitable server could be found.
17893:
17894: =cut
17895:
17896: sub check_release_required {
17897: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17898: my ($switchserver,$warning);
17899: if ($required ne '') {
17900: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17901: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17902: if ($reqdmajor ne '' && $reqdminor ne '') {
17903: my $otherserver;
17904: if (($major eq '' && $minor eq '') ||
17905: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17906: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17907: my $switchlcrev =
17908: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17909: $userdomserver);
17910: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17911: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17912: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17913: my $cdom = $env{'course.'.$courseid.'.domain'};
17914: if ($cdom ne $env{'user.domain'}) {
17915: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17916: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17917: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17918: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17919: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17920: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17921: my $canhost =
17922: &Apache::lonnet::can_host_session($env{'user.domain'},
17923: $coursedomserver,
17924: $remoterev,
17925: $udomdefaults{'remotesessions'},
17926: $defdomdefaults{'hostedsessions'});
17927:
17928: if ($canhost) {
17929: $otherserver = $coursedomserver;
17930: } else {
17931: $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.");
17932: }
17933: } else {
17934: $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).");
17935: }
17936: } else {
17937: $otherserver = $userdomserver;
17938: }
17939: }
17940: if ($otherserver ne '') {
17941: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17942: }
17943: }
17944: }
17945: return ($switchserver,$warning);
17946: }
17947:
17948: =pod
17949:
17950: =item * &check_release_result()
17951:
17952: Inputs:
17953:
17954: $switchwarning - Warning message if no suitable server found to host session.
17955:
17956: $switchserver - query string to append to /adm/switchserver containing lonHostID
17957: and current role.
17958:
17959: Returns: HTML to display with information about requirement to switch server.
17960: Either displaying warning with link to Roles/Courses screen or
17961: display link to switchserver.
17962:
1.1181 raeburn 17963: =cut
17964:
1.1207 raeburn 17965: sub check_release_result {
17966: my ($switchwarning,$switchserver) = @_;
17967: my $output = &start_page('Selected course unavailable on this server').
17968: '<p class="LC_warning">';
17969: if ($switchwarning) {
17970: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17971: if (&show_course()) {
17972: $output .= &mt('Display courses');
17973: } else {
17974: $output .= &mt('Display roles');
17975: }
17976: $output .= '</a>';
17977: } elsif ($switchserver) {
17978: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17979: '<br />'.
17980: '<a href="/adm/switchserver?'.$switchserver.'">'.
17981: &mt('Switch Server').
17982: '</a>';
17983: }
17984: $output .= '</p>'.&end_page();
17985: return $output;
17986: }
17987:
17988: =pod
17989:
17990: =item * &needs_coursereinit()
17991:
17992: Determine if course contents stored for user's session needs to be
17993: refreshed, because content has changed since "Big Hash" last tied.
17994:
17995: Check for change is made if time last checked is more than 10 minutes ago
17996: (by default).
17997:
17998: Inputs:
17999:
18000: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18001:
18002: $interval (optional) - Time which may elapse (in s) between last check for content
18003: change in current course. (default: 600 s).
18004:
18005: Returns: an array; first element is:
18006:
18007: =over 4
18008:
18009: 'switch' - if content updates mean user's session
18010: needs to be switched to a server running a newer LON-CAPA version
18011:
18012: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18013: on current server hosting user's session
18014:
18015: '' - if no action required.
18016:
18017: =back
18018:
18019: If first item element is 'switch':
18020:
18021: second item is $switchwarning - Warning message if no suitable server found to host session.
18022:
18023: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18024: and current role.
18025:
18026: otherwise: no other elements returned.
18027:
18028: =back
18029:
18030: =cut
18031:
18032: sub needs_coursereinit {
18033: my ($loncaparev,$interval) = @_;
18034: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18035: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18036: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18037: my $now = time;
18038: if ($interval eq '') {
18039: $interval = 600;
18040: }
18041: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18042: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18043: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18044: if ($blocked) {
18045: return ();
18046: }
1.1207 raeburn 18047: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18048: if ($lastchange > $env{'request.course.tied'}) {
18049: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18050: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18051: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18052: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18053: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18054: $curr_reqd_hash{'internal.releaserequired'}});
18055: my ($switchserver,$switchwarning) =
18056: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18057: $curr_reqd_hash{'internal.releaserequired'});
18058: if ($switchwarning ne '' || $switchserver ne '') {
18059: return ('switch',$switchwarning,$switchserver);
18060: }
18061: }
18062: }
18063: return ('update');
18064: }
18065: }
18066: return ();
18067: }
1.1181 raeburn 18068:
1.1083 raeburn 18069: sub update_content_constraints {
1.1326 raeburn 18070: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 18071: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18072: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18073: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18074: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18075: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18076: if ($item eq 'resourcetag') {
18077: if ($name eq 'responsetype') {
18078: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18079: }
1.1307 raeburn 18080: } elsif ($item eq 'course') {
18081: if ($name eq 'courserestype') {
18082: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18083: }
1.1083 raeburn 18084: }
18085: }
18086: my $navmap = Apache::lonnavmaps::navmap->new();
18087: if (defined($navmap)) {
1.1307 raeburn 18088: my (%allresponses,%allcrsrestypes);
18089: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18090: if ($res->is_tool()) {
18091: if ($allcrsrestypes{'exttool'}) {
18092: $allcrsrestypes{'exttool'} ++;
18093: } else {
18094: $allcrsrestypes{'exttool'} = 1;
18095: }
18096: next;
18097: }
1.1083 raeburn 18098: my %responses = $res->responseTypes();
18099: foreach my $key (keys(%responses)) {
18100: next unless(exists($checkresponsetypes{$key}));
18101: $allresponses{$key} += $responses{$key};
18102: }
18103: }
18104: foreach my $key (keys(%allresponses)) {
18105: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18106: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18107: ($reqdmajor,$reqdminor) = ($major,$minor);
18108: }
18109: }
1.1307 raeburn 18110: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18111: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18112: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18113: ($reqdmajor,$reqdminor) = ($major,$minor);
18114: }
18115: }
1.1083 raeburn 18116: undef($navmap);
18117: }
1.1326 raeburn 18118: my (@resources,@order,@resparms,@zombies);
18119: if ($keeporder) {
18120: use LONCAPA::map;
18121: @resources = @LONCAPA::map::resources;
18122: @order = @LONCAPA::map::order;
18123: @resparms = @LONCAPA::map::resparms;
18124: @zombies = @LONCAPA::map::zombies;
18125: }
1.1308 raeburn 18126: my $suppmap = 'supplemental.sequence';
18127: my ($suppcount,$supptools,$errors) = (0,0,0);
18128: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
18129: $suppcount,$supptools,$errors);
1.1326 raeburn 18130: if ($keeporder) {
18131: @LONCAPA::map::resources = @resources;
18132: @LONCAPA::map::order = @order;
18133: @LONCAPA::map::resparms = @resparms;
18134: @LONCAPA::map::zombies = @zombies;
18135: }
1.1308 raeburn 18136: if ($supptools) {
18137: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18138: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18139: ($reqdmajor,$reqdminor) = ($major,$minor);
18140: }
18141: }
1.1083 raeburn 18142: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18143: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18144: }
18145: return;
18146: }
18147:
1.1110 raeburn 18148: sub allmaps_incourse {
18149: my ($cdom,$cnum,$chome,$cid) = @_;
18150: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18151: $cid = $env{'request.course.id'};
18152: $cdom = $env{'course.'.$cid.'.domain'};
18153: $cnum = $env{'course.'.$cid.'.num'};
18154: $chome = $env{'course.'.$cid.'.home'};
18155: }
18156: my %allmaps = ();
18157: my $lastchange =
18158: &Apache::lonnet::get_coursechange($cdom,$cnum);
18159: if ($lastchange > $env{'request.course.tied'}) {
18160: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18161: unless ($ferr) {
1.1326 raeburn 18162: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 18163: }
18164: }
18165: my $navmap = Apache::lonnavmaps::navmap->new();
18166: if (defined($navmap)) {
18167: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18168: $allmaps{$res->src()} = 1;
18169: }
18170: }
18171: return \%allmaps;
18172: }
18173:
1.1083 raeburn 18174: sub parse_supplemental_title {
18175: my ($title) = @_;
18176:
18177: my ($foldertitle,$renametitle);
18178: if ($title =~ /&&&/) {
18179: $title = &HTML::Entites::decode($title);
18180: }
18181: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18182: $renametitle=$4;
18183: my ($time,$uname,$udom) = ($1,$2,$3);
18184: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18185: my $name = &plainname($uname,$udom);
18186: $name = &HTML::Entities::encode($name,'"<>&\'');
18187: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
18188: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
18189: $name.': <br />'.$foldertitle;
18190: }
18191: if (wantarray) {
18192: return ($title,$foldertitle,$renametitle);
18193: }
18194: return $title;
18195: }
18196:
1.1143 raeburn 18197: sub recurse_supplemental {
1.1308 raeburn 18198: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 18199: if ($suppmap) {
18200: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18201: if ($fatal) {
18202: $errors ++;
18203: } else {
18204: if ($#LONCAPA::map::resources > 0) {
18205: foreach my $res (@LONCAPA::map::resources) {
18206: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
18207: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 18208: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 18209: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
18210: $numfiles,$numexttools,$errors);
1.1143 raeburn 18211: } else {
1.1308 raeburn 18212: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
18213: $numexttools ++;
18214: }
1.1143 raeburn 18215: $numfiles ++;
18216: }
18217: }
18218: }
18219: }
18220: }
18221: }
1.1308 raeburn 18222: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 18223: }
18224:
1.1101 raeburn 18225: sub symb_to_docspath {
1.1267 raeburn 18226: my ($symb,$navmapref) = @_;
18227: return unless ($symb && ref($navmapref));
1.1101 raeburn 18228: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18229: if ($resurl=~/\.(sequence|page)$/) {
18230: $mapurl=$resurl;
18231: } elsif ($resurl eq 'adm/navmaps') {
18232: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18233: }
18234: my $mapresobj;
1.1267 raeburn 18235: unless (ref($$navmapref)) {
18236: $$navmapref = Apache::lonnavmaps::navmap->new();
18237: }
18238: if (ref($$navmapref)) {
18239: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18240: }
18241: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18242: my $type=$2;
18243: my $path;
18244: if (ref($mapresobj)) {
18245: my $pcslist = $mapresobj->map_hierarchy();
18246: if ($pcslist ne '') {
18247: foreach my $pc (split(/,/,$pcslist)) {
18248: next if ($pc <= 1);
1.1267 raeburn 18249: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18250: if (ref($res)) {
18251: my $thisurl = $res->src();
18252: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18253: my $thistitle = $res->title();
18254: $path .= '&'.
18255: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18256: &escape($thistitle).
1.1101 raeburn 18257: ':'.$res->randompick().
18258: ':'.$res->randomout().
18259: ':'.$res->encrypted().
18260: ':'.$res->randomorder().
18261: ':'.$res->is_page();
18262: }
18263: }
18264: }
18265: $path =~ s/^\&//;
18266: my $maptitle = $mapresobj->title();
18267: if ($mapurl eq 'default') {
1.1129 raeburn 18268: $maptitle = 'Main Content';
1.1101 raeburn 18269: }
18270: $path .= (($path ne '')? '&' : '').
18271: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18272: &escape($maptitle).
1.1101 raeburn 18273: ':'.$mapresobj->randompick().
18274: ':'.$mapresobj->randomout().
18275: ':'.$mapresobj->encrypted().
18276: ':'.$mapresobj->randomorder().
18277: ':'.$mapresobj->is_page();
18278: } else {
18279: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18280: my $ispage = (($type eq 'page')? 1 : '');
18281: if ($mapurl eq 'default') {
1.1129 raeburn 18282: $maptitle = 'Main Content';
1.1101 raeburn 18283: }
18284: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18285: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18286: }
18287: unless ($mapurl eq 'default') {
18288: $path = 'default&'.
1.1146 raeburn 18289: &escape('Main Content').
1.1101 raeburn 18290: ':::::&'.$path;
18291: }
18292: return $path;
18293: }
18294:
1.1094 raeburn 18295: sub captcha_display {
1.1327 raeburn 18296: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18297: my ($output,$error);
1.1234 raeburn 18298: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18299: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18300: if ($captcha eq 'original') {
1.1094 raeburn 18301: $output = &create_captcha();
18302: unless ($output) {
1.1172 raeburn 18303: $error = 'captcha';
1.1094 raeburn 18304: }
18305: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18306: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18307: unless ($output) {
1.1172 raeburn 18308: $error = 'recaptcha';
1.1094 raeburn 18309: }
18310: }
1.1234 raeburn 18311: return ($output,$error,$captcha,$version);
1.1094 raeburn 18312: }
18313:
18314: sub captcha_response {
1.1327 raeburn 18315: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18316: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18317: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18318: if ($captcha eq 'original') {
1.1094 raeburn 18319: ($captcha_chk,$captcha_error) = &check_captcha();
18320: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18321: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18322: } else {
18323: $captcha_chk = 1;
18324: }
18325: return ($captcha_chk,$captcha_error);
18326: }
18327:
18328: sub get_captcha_config {
1.1327 raeburn 18329: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18330: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18331: my $hostname = &Apache::lonnet::hostname($lonhost);
18332: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18333: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18334: if ($context eq 'usercreation') {
18335: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18336: if (ref($domconfig{$context}) eq 'HASH') {
18337: $hashtocheck = $domconfig{$context}{'cancreate'};
18338: if (ref($hashtocheck) eq 'HASH') {
18339: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18340: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18341: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18342: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18343: }
18344: if ($privkey && $pubkey) {
18345: $captcha = 'recaptcha';
1.1234 raeburn 18346: $version = $hashtocheck->{'recaptchaversion'};
18347: if ($version ne '2') {
18348: $version = 1;
18349: }
1.1095 raeburn 18350: } else {
18351: $captcha = 'original';
18352: }
18353: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18354: $captcha = 'original';
18355: }
1.1094 raeburn 18356: }
1.1095 raeburn 18357: } else {
18358: $captcha = 'captcha';
18359: }
18360: } elsif ($context eq 'login') {
18361: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18362: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18363: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18364: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18365: if ($privkey && $pubkey) {
18366: $captcha = 'recaptcha';
1.1234 raeburn 18367: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18368: if ($version ne '2') {
18369: $version = 1;
18370: }
1.1095 raeburn 18371: } else {
18372: $captcha = 'original';
1.1094 raeburn 18373: }
1.1095 raeburn 18374: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18375: $captcha = 'original';
1.1094 raeburn 18376: }
1.1327 raeburn 18377: } elsif ($context eq 'passwords') {
18378: if ($dom_in_effect) {
18379: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18380: if ($passwdconf{'captcha'} eq 'recaptcha') {
18381: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18382: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18383: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18384: }
18385: if ($privkey && $pubkey) {
18386: $captcha = 'recaptcha';
18387: $version = $passwdconf{'recaptchaversion'};
18388: if ($version ne '2') {
18389: $version = 1;
18390: }
18391: } else {
18392: $captcha = 'original';
18393: }
18394: } elsif ($passwdconf{'captcha'} ne 'notused') {
18395: $captcha = 'original';
18396: }
18397: }
18398: }
1.1234 raeburn 18399: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18400: }
18401:
18402: sub create_captcha {
18403: my %captcha_params = &captcha_settings();
18404: my ($output,$maxtries,$tries) = ('',10,0);
18405: while ($tries < $maxtries) {
18406: $tries ++;
18407: my $captcha = Authen::Captcha->new (
18408: output_folder => $captcha_params{'output_dir'},
18409: data_folder => $captcha_params{'db_dir'},
18410: );
18411: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18412:
18413: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18414: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 18415: '<span class="LC_nobreak">'.
1.1094 raeburn 18416: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18417: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1367 raeburn 18418: '</span><br />'.
1.1176 raeburn 18419: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18420: last;
18421: }
18422: }
1.1323 raeburn 18423: if ($output eq '') {
18424: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18425: }
1.1094 raeburn 18426: return $output;
18427: }
18428:
18429: sub captcha_settings {
18430: my %captcha_params = (
18431: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18432: www_output_dir => "/captchaspool",
18433: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18434: numchars => '5',
18435: );
18436: return %captcha_params;
18437: }
18438:
18439: sub check_captcha {
18440: my ($captcha_chk,$captcha_error);
18441: my $code = $env{'form.code'};
18442: my $md5sum = $env{'form.crypt'};
18443: my %captcha_params = &captcha_settings();
18444: my $captcha = Authen::Captcha->new(
18445: output_folder => $captcha_params{'output_dir'},
18446: data_folder => $captcha_params{'db_dir'},
18447: );
1.1109 raeburn 18448: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18449: my %captcha_hash = (
18450: 0 => 'Code not checked (file error)',
18451: -1 => 'Failed: code expired',
18452: -2 => 'Failed: invalid code (not in database)',
18453: -3 => 'Failed: invalid code (code does not match crypt)',
18454: );
18455: if ($captcha_chk != 1) {
18456: $captcha_error = $captcha_hash{$captcha_chk}
18457: }
18458: return ($captcha_chk,$captcha_error);
18459: }
18460:
18461: sub create_recaptcha {
1.1234 raeburn 18462: my ($pubkey,$version) = @_;
18463: if ($version >= 2) {
1.1367 raeburn 18464: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18465: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 18466: } else {
18467: my $use_ssl;
18468: if ($ENV{'SERVER_PORT'} == 443) {
18469: $use_ssl = 1;
18470: }
18471: my $captcha = Captcha::reCAPTCHA->new;
18472: return $captcha->get_options_setter({theme => 'white'})."\n".
18473: $captcha->get_html($pubkey,undef,$use_ssl).
18474: &mt('If the text is hard to read, [_1] will replace them.',
18475: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18476: '<br /><br />';
18477: }
1.1094 raeburn 18478: }
18479:
18480: sub check_recaptcha {
1.1234 raeburn 18481: my ($privkey,$version) = @_;
1.1094 raeburn 18482: my $captcha_chk;
1.1350 raeburn 18483: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18484: if ($version >= 2) {
18485: my %info = (
18486: secret => $privkey,
18487: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18488: remoteip => $ip,
1.1234 raeburn 18489: );
1.1280 raeburn 18490: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18491: $request->content(join('&',map {
18492: my $name = escape($_);
18493: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18494: ? join("&$name=", map {escape($_) } @{$info{$_}})
18495: : &escape($info{$_}) );
18496: } keys(%info)));
18497: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18498: if ($response->is_success) {
18499: my $data = JSON::DWIW->from_json($response->decoded_content);
18500: if (ref($data) eq 'HASH') {
18501: if ($data->{'success'}) {
18502: $captcha_chk = 1;
18503: }
18504: }
18505: }
18506: } else {
18507: my $captcha = Captcha::reCAPTCHA->new;
18508: my $captcha_result =
18509: $captcha->check_answer(
18510: $privkey,
1.1350 raeburn 18511: $ip,
1.1234 raeburn 18512: $env{'form.recaptcha_challenge_field'},
18513: $env{'form.recaptcha_response_field'},
18514: );
18515: if ($captcha_result->{is_valid}) {
18516: $captcha_chk = 1;
18517: }
1.1094 raeburn 18518: }
18519: return $captcha_chk;
18520: }
18521:
1.1174 raeburn 18522: sub emailusername_info {
1.1244 raeburn 18523: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18524: my %titles = &Apache::lonlocal::texthash (
18525: lastname => 'Last Name',
18526: firstname => 'First Name',
18527: institution => 'School/college/university',
18528: location => "School's city, state/province, country",
18529: web => "School's web address",
18530: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18531: id => 'Student/Employee ID',
1.1174 raeburn 18532: );
18533: return (\@fields,\%titles);
18534: }
18535:
1.1161 raeburn 18536: sub cleanup_html {
18537: my ($incoming) = @_;
18538: my $outgoing;
18539: if ($incoming ne '') {
18540: $outgoing = $incoming;
18541: $outgoing =~ s/;/;/g;
18542: $outgoing =~ s/\#/#/g;
18543: $outgoing =~ s/\&/&/g;
18544: $outgoing =~ s/</</g;
18545: $outgoing =~ s/>/>/g;
18546: $outgoing =~ s/\(/(/g;
18547: $outgoing =~ s/\)/)/g;
18548: $outgoing =~ s/"/"/g;
18549: $outgoing =~ s/'/'/g;
18550: $outgoing =~ s/\$/$/g;
18551: $outgoing =~ s{/}{/}g;
18552: $outgoing =~ s/=/=/g;
18553: $outgoing =~ s/\\/\/g
18554: }
18555: return $outgoing;
18556: }
18557:
1.1190 musolffc 18558: # Checks for critical messages and returns a redirect url if one exists.
18559: # $interval indicates how often to check for messages.
1.1282 raeburn 18560: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18561: sub critical_redirect {
1.1282 raeburn 18562: my ($interval,$context) = @_;
1.1356 raeburn 18563: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18564: return ();
18565: }
1.1190 musolffc 18566: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18567: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18568: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18569: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 18570: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18571: if ($blocked) {
18572: my $checkrole = "cm./$cdom/$cnum";
18573: if ($env{'request.course.sec'} ne '') {
18574: $checkrole .= "/$env{'request.course.sec'}";
18575: }
18576: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18577: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18578: return;
18579: }
18580: }
18581: }
1.1190 musolffc 18582: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18583: $env{'user.name'});
18584: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18585: my $redirecturl;
1.1190 musolffc 18586: if ($what[0]) {
1.1356 raeburn 18587: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 18588: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18589: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18590: return (1, $url);
1.1190 musolffc 18591: }
1.1191 raeburn 18592: }
18593: }
18594: return ();
1.1190 musolffc 18595: }
18596:
1.1174 raeburn 18597: # Use:
18598: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18599: #
18600: ##################################################
18601: # password associated functions #
18602: ##################################################
18603: sub des_keys {
18604: # Make a new key for DES encryption.
18605: # Each key has two parts which are returned separately.
18606: # Please note: Each key must be passed through the &hex function
18607: # before it is output to the web browser. The hex versions cannot
18608: # be used to decrypt.
18609: my @hexstr=('0','1','2','3','4','5','6','7',
18610: '8','9','a','b','c','d','e','f');
18611: my $lkey='';
18612: for (0..7) {
18613: $lkey.=$hexstr[rand(15)];
18614: }
18615: my $ukey='';
18616: for (0..7) {
18617: $ukey.=$hexstr[rand(15)];
18618: }
18619: return ($lkey,$ukey);
18620: }
18621:
18622: sub des_decrypt {
18623: my ($key,$cyphertext) = @_;
18624: my $keybin=pack("H16",$key);
18625: my $cypher;
18626: if ($Crypt::DES::VERSION>=2.03) {
18627: $cypher=new Crypt::DES $keybin;
18628: } else {
18629: $cypher=new DES $keybin;
18630: }
1.1233 raeburn 18631: my $plaintext='';
18632: my $cypherlength = length($cyphertext);
18633: my $numchunks = int($cypherlength/32);
18634: for (my $j=0; $j<$numchunks; $j++) {
18635: my $start = $j*32;
18636: my $cypherblock = substr($cyphertext,$start,32);
18637: my $chunk =
18638: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18639: $chunk .=
18640: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18641: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18642: $plaintext .= $chunk;
18643: }
1.1174 raeburn 18644: return $plaintext;
18645: }
18646:
1.1344 raeburn 18647: sub get_requested_shorturls {
1.1309 raeburn 18648: my ($cdom,$cnum,$navmap) = @_;
18649: return unless (ref($navmap));
1.1344 raeburn 18650: my ($numnew,$errors);
1.1309 raeburn 18651: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18652: if (@toshorten) {
18653: my (%maps,%resources,%titles);
18654: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18655: 'shorturls',$cdom,$cnum);
18656: if (keys(%resources)) {
1.1344 raeburn 18657: my %tocreate;
1.1309 raeburn 18658: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18659: my $symb = $resources{$item};
18660: if ($symb) {
18661: $tocreate{$cnum.'&'.$symb} = 1;
18662: }
18663: }
1.1344 raeburn 18664: if (keys(%tocreate)) {
18665: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18666: \%tocreate);
18667: }
1.1309 raeburn 18668: }
1.1344 raeburn 18669: }
18670: return ($numnew,$errors);
18671: }
18672:
18673: sub make_short_symbs {
18674: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18675: my ($numnew,@errors);
18676: if (ref($tocreateref) eq 'HASH') {
18677: my %tocreate = %{$tocreateref};
1.1309 raeburn 18678: if (keys(%tocreate)) {
18679: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18680: my $su = Short::URL->new(no_vowels => 1);
18681: my $init = '';
18682: my (%newunique,%addcourse,%courseonly,%failed);
18683: # get lock on tiny db
18684: my $now = time;
1.1344 raeburn 18685: if ($lockuser eq '') {
18686: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18687: }
1.1309 raeburn 18688: my $lockhash = {
1.1344 raeburn 18689: "lock\0$now" => $lockuser,
1.1309 raeburn 18690: };
18691: my $tries = 0;
18692: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18693: my ($code,$error);
18694: while (($gotlock ne 'ok') && ($tries<3)) {
18695: $tries ++;
18696: sleep 1;
1.1319 raeburn 18697: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18698: }
18699: if ($gotlock eq 'ok') {
18700: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18701: \%addcourse,\%courseonly,\%failed);
18702: if (keys(%failed)) {
18703: my $numfailed = scalar(keys(%failed));
18704: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18705: }
18706: if (keys(%newunique)) {
18707: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18708: if ($putres eq 'ok') {
18709: $numnew = scalar(keys(%newunique));
18710: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18711: unless ($newputres eq 'ok') {
18712: push(@errors,&mt('error: could not store course look-up of short URLs'));
18713: }
18714: } else {
18715: push(@errors,&mt('error: could not store unique six character URLs'));
18716: }
18717: }
18718: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18719: unless ($dellockres eq 'ok') {
18720: push(@errors,&mt('error: could not release lockfile'));
18721: }
18722: } else {
18723: push(@errors,&mt('error: could not obtain lockfile'));
18724: }
18725: if (keys(%courseonly)) {
18726: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18727: if ($result ne 'ok') {
18728: push(@errors,&mt('error: could not update course look-up of short URLs'));
18729: }
18730: }
18731: }
18732: }
18733: return ($numnew,\@errors);
18734: }
18735:
18736: sub shorten_symbs {
18737: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18738: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18739: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18740: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18741: my (%possibles,%collisions);
18742: foreach my $key (keys(%{$tocreate})) {
18743: my $num = String::CRC32::crc32($key);
18744: my $tiny = $su->encode($num,$init);
18745: if ($tiny) {
18746: $possibles{$tiny} = $key;
18747: }
18748: }
18749: if (!$init) {
18750: $init = 1;
18751: } else {
18752: $init ++;
18753: }
18754: if (keys(%possibles)) {
18755: my @posstiny = keys(%possibles);
18756: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18757: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18758: if (keys(%currtiny)) {
18759: foreach my $key (keys(%currtiny)) {
18760: next if ($currtiny{$key} eq '');
18761: if ($currtiny{$key} eq $possibles{$key}) {
18762: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18763: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18764: $courseonly->{$tsymb} = $key;
18765: }
18766: } else {
18767: $collisions{$possibles{$key}} = 1;
18768: }
18769: delete($possibles{$key});
18770: }
18771: }
18772: foreach my $key (keys(%possibles)) {
18773: $newunique->{$key} = $possibles{$key};
18774: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18775: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18776: $addcourse->{$tsymb} = $key;
18777: }
18778: }
18779: }
18780: if (keys(%collisions)) {
18781: if ($init <5) {
18782: if (!$init) {
18783: $init = 1;
18784: } else {
18785: $init ++;
18786: }
18787: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18788: $newunique,$addcourse,$courseonly,$failed);
18789: } else {
18790: foreach my $key (keys(%collisions)) {
18791: $failed->{$key} = 1;
18792: }
18793: }
18794: }
18795: return $init;
18796: }
18797:
1.1328 raeburn 18798: sub is_nonframeable {
1.1329 raeburn 18799: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18800: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18801: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18802:
18803: $remprotocol = lc($remprotocol);
18804: $remhost = lc($remhost);
18805: my $remport = 80;
18806: if ($remprotocol eq 'https') {
18807: $remport = 443;
18808: }
1.1330 raeburn 18809: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18810: if ($cached) {
18811: unless ($nocache) {
18812: if ($result) {
18813: return 1;
18814: } else {
18815: return 0;
18816: }
18817: }
18818: }
1.1328 raeburn 18819: my $uselink;
18820: my $request = new HTTP::Request('HEAD',$url);
18821: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18822: if ($response->is_success()) {
18823: my $secpolicy = lc($response->header('content-security-policy'));
18824: my $xframeop = lc($response->header('x-frame-options'));
18825: $secpolicy =~ s/^\s+|\s+$//g;
18826: $xframeop =~ s/^\s+|\s+$//g;
18827: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18828: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18829: my ($origin,$protocol,$port);
18830: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18831: $port = $ENV{'SERVER_PORT'};
18832: } else {
18833: $port = 80;
18834: }
18835: if ($absolute eq '') {
18836: $protocol = 'http:';
18837: if ($port == 443) {
18838: $protocol = 'https:';
18839: }
18840: $origin = $protocol.'//'.lc($hostname);
18841: } else {
18842: $origin = lc($absolute);
18843: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18844: }
18845: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18846: my $framepolicy = $1;
18847: $framepolicy =~ s/^\s+|\s+$//g;
18848: my @policies = split(/\s+/,$framepolicy);
18849: if (@policies) {
18850: if (grep(/^\Q'none'\E$/,@policies)) {
18851: $uselink = 1;
18852: } else {
18853: $uselink = 1;
18854: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18855: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18856: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18857: undef($uselink);
18858: }
18859: if ($uselink) {
18860: if (grep(/^\Q'self'\E$/,@policies)) {
18861: if (($origin ne '') && ($remotehost eq $origin)) {
18862: undef($uselink);
18863: }
18864: }
18865: }
18866: if ($uselink) {
18867: my @possok;
18868: if ($ip ne '') {
18869: push(@possok,$ip);
18870: }
18871: my $hoststr = '';
18872: foreach my $part (reverse(split(/\./,$hostname))) {
18873: if ($hoststr eq '') {
18874: $hoststr = $part;
18875: } else {
18876: $hoststr = "$part.$hoststr";
18877: }
18878: if ($hoststr eq $hostname) {
18879: push(@possok,$hostname);
18880: } else {
18881: push(@possok,"*.$hoststr");
18882: }
18883: }
18884: if (@possok) {
18885: foreach my $poss (@possok) {
18886: last if (!$uselink);
18887: foreach my $policy (@policies) {
18888: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18889: undef($uselink);
18890: last;
18891: }
18892: }
18893: }
18894: }
18895: }
18896: }
18897: }
18898: } elsif ($xframeop ne '') {
18899: $uselink = 1;
18900: my @policies = split(/\s*,\s*/,$xframeop);
18901: if (@policies) {
18902: unless (grep(/^deny$/,@policies)) {
18903: if ($origin ne '') {
18904: if (grep(/^sameorigin$/,@policies)) {
18905: if ($remotehost eq $origin) {
18906: undef($uselink);
18907: }
18908: }
18909: if ($uselink) {
18910: foreach my $policy (@policies) {
18911: if ($policy =~ /^allow-from\s*(.+)$/) {
18912: my $allowfrom = $1;
18913: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18914: undef($uselink);
18915: last;
18916: }
18917: }
18918: }
18919: }
18920: }
18921: }
18922: }
18923: }
18924: }
18925: }
1.1329 raeburn 18926: if ($nocache) {
18927: if ($cached) {
18928: my $devalidate;
18929: if ($uselink && !$result) {
18930: $devalidate = 1;
18931: } elsif (!$uselink && $result) {
18932: $devalidate = 1;
18933: }
18934: if ($devalidate) {
18935: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18936: }
18937: }
18938: } else {
18939: if ($uselink) {
18940: $result = 1;
18941: } else {
18942: $result = 0;
18943: }
18944: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18945: }
1.1328 raeburn 18946: return $uselink;
18947: }
18948:
1.1359 raeburn 18949: sub page_menu {
18950: my ($menucolls,$menunum) = @_;
18951: my %menu;
18952: foreach my $item (split(/;/,$menucolls)) {
18953: my ($num,$value) = split(/\%/,$item);
18954: if ($num eq $menunum) {
18955: my @entries = split(/\&/,$value);
18956: foreach my $entry (@entries) {
18957: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 18958: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 18959: $menu{$name} = $fields;
18960: } else {
18961: my @shown;
18962: if ($fields =~ /,/) {
18963: @shown = split(/,/,$fields);
18964: } else {
18965: @shown = ($fields);
18966: }
18967: if (@shown) {
18968: foreach my $field (@shown) {
18969: next if ($field eq '');
18970: $menu{$field} = 1;
18971: }
18972: }
18973: }
18974: }
18975: }
18976: }
18977: return %menu;
18978: }
18979:
1.112 bowersj2 18980: 1;
18981: __END__;
1.41 ng 18982:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>