Annotation of loncom/interface/loncommon.pm, revision 1.1375
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1375 ! raeburn 4: # $Id: loncommon.pm,v 1.1374 2022/01/15 20:21:06 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: }
1.1375 ! raeburn 5228: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
! 5229: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
! 5230: my $checkrole;
! 5231: if ($env{'request.role.domain'} eq '') {
! 5232: $checkrole = "cm./$env{'user.domain'}/";
! 5233: } else {
! 5234: $checkrole = "cm./$env{'request.role.domain'}/";
! 5235: }
! 5236: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
! 5237: $has_evb = 1;
! 5238: }
1.1372 raeburn 5239: }
5240: unless ($has_evb || $check_ipaccess) {
5241: my @machinedoms = &Apache::lonnet::current_machine_domains();
5242: if (($dom eq 'public') && ($activity eq 'port')) {
5243: $dom = $udom;
5244: }
5245: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5246: $check_ipaccess = 1;
5247: } else {
5248: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5249: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5250: my $prim = &Apache::lonnet::domain($dom,'primary');
5251: my $intdom = &Apache::lonnet::internet_dom($prim);
5252: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5253: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5254: $check_ipaccess = 1;
5255: }
5256: }
5257: }
5258: }
5259: if ($check_ipaccess) {
5260: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5261: unless (defined($cached)) {
5262: my %domconfig =
5263: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5264: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5265: }
5266: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5267: foreach my $id (keys(%{$ipaccessref})) {
5268: if (ref($ipaccessref->{$id}) eq 'HASH') {
5269: my $range = $ipaccessref->{$id}->{'ip'};
5270: if ($range) {
5271: if (&Apache::lonnet::ip_match($clientip,$range)) {
5272: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5273: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5274: return ('','','',$id,$dom);
5275: last;
5276: }
5277: }
5278: }
5279: }
5280: }
5281: }
5282: }
5283: }
1.1373 raeburn 5284: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5285: return ();
5286: }
1.1372 raeburn 5287: }
1.1189 raeburn 5288: if (defined($udom) && defined($uname)) {
5289: # If uname and udom are for a course, check for blocks in the course.
5290: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5291: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5292: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5293: return ($startblock,$endblock,$triggerblock);
5294: }
5295: } else {
1.490 raeburn 5296: $udom = $env{'user.domain'};
5297: $uname = $env{'user.name'};
5298: }
5299:
1.502 raeburn 5300: my $startblock = 0;
5301: my $endblock = 0;
1.1062 raeburn 5302: my $triggerblock = '';
1.1373 raeburn 5303: my %live_courses;
5304: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5305: %live_courses = &findallcourses(undef,$uname,$udom);
5306: }
1.474 raeburn 5307:
1.490 raeburn 5308: # If uname is for a user, and activity is course-specific, i.e.,
5309: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5310:
1.490 raeburn 5311: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5312: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5313: $activity eq 'search' || $activity eq 'reinit' ||
5314: $activity eq 'alert') &&
1.1189 raeburn 5315: ($env{'request.course.id'})) {
1.490 raeburn 5316: foreach my $key (keys(%live_courses)) {
5317: if ($key ne $env{'request.course.id'}) {
5318: delete($live_courses{$key});
5319: }
5320: }
5321: }
5322:
5323: my $otheruser = 0;
5324: my %own_courses;
5325: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5326: # Resource belongs to user other than current user.
5327: $otheruser = 1;
5328: # Gather courses for current user
5329: %own_courses =
5330: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5331: }
5332:
5333: # Gather active course roles - course coordinator, instructor,
5334: # exam proctor, ta, student, or custom role.
1.474 raeburn 5335:
5336: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5337: my ($cdom,$cnum);
5338: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5339: $cdom = $env{'course.'.$course.'.domain'};
5340: $cnum = $env{'course.'.$course.'.num'};
5341: } else {
1.490 raeburn 5342: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5343: }
5344: my $no_ownblock = 0;
5345: my $no_userblock = 0;
1.533 raeburn 5346: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5347: # Check if current user has 'evb' priv for this
5348: if (defined($own_courses{$course})) {
5349: foreach my $sec (keys(%{$own_courses{$course}})) {
5350: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5351: if ($sec ne 'none') {
5352: $checkrole .= '/'.$sec;
5353: }
5354: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5355: $no_ownblock = 1;
5356: last;
5357: }
5358: }
5359: }
5360: # if they have 'evb' priv and are currently not playing student
5361: next if (($no_ownblock) &&
5362: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5363: }
1.474 raeburn 5364: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5365: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5366: if ($sec ne 'none') {
1.482 raeburn 5367: $checkrole .= '/'.$sec;
1.474 raeburn 5368: }
1.490 raeburn 5369: if ($otheruser) {
5370: # Resource belongs to user other than current user.
5371: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5372: my (%allroles,%userroles);
5373: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5374: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5375: my ($trole,$tdom,$tnum,$tsec);
5376: if ($entry =~ /^cr/) {
5377: ($trole,$tdom,$tnum,$tsec) =
5378: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5379: } else {
5380: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5381: }
5382: my ($spec,$area,$trest);
5383: $area = '/'.$tdom.'/'.$tnum;
5384: $trest = $tnum;
5385: if ($tsec ne '') {
5386: $area .= '/'.$tsec;
5387: $trest .= '/'.$tsec;
5388: }
5389: $spec = $trole.'.'.$area;
5390: if ($trole =~ /^cr/) {
5391: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5392: $tdom,$spec,$trest,$area);
5393: } else {
5394: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5395: $tdom,$spec,$trest,$area);
5396: }
5397: }
1.1276 raeburn 5398: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5399: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5400: if ($1) {
5401: $no_userblock = 1;
5402: last;
5403: }
1.486 raeburn 5404: }
5405: }
1.490 raeburn 5406: } else {
5407: # Resource belongs to current user
5408: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5409: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5410: $no_ownblock = 1;
5411: last;
5412: }
1.474 raeburn 5413: }
5414: }
5415: # if they have the evb priv and are currently not playing student
1.482 raeburn 5416: next if (($no_ownblock) &&
1.491 albertel 5417: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5418: next if ($no_userblock);
1.474 raeburn 5419:
1.1303 raeburn 5420: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5421: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5422:
1.1062 raeburn 5423: my ($start,$end,$trigger) =
1.1347 raeburn 5424: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5425: if (($start != 0) &&
5426: (($startblock == 0) || ($startblock > $start))) {
5427: $startblock = $start;
1.1062 raeburn 5428: if ($trigger ne '') {
5429: $triggerblock = $trigger;
5430: }
1.502 raeburn 5431: }
5432: if (($end != 0) &&
5433: (($endblock == 0) || ($endblock < $end))) {
5434: $endblock = $end;
1.1062 raeburn 5435: if ($trigger ne '') {
5436: $triggerblock = $trigger;
5437: }
1.502 raeburn 5438: }
1.490 raeburn 5439: }
1.1062 raeburn 5440: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5441: }
5442:
5443: sub get_blocks {
1.1347 raeburn 5444: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5445: my $startblock = 0;
5446: my $endblock = 0;
1.1062 raeburn 5447: my $triggerblock = '';
1.490 raeburn 5448: my $course = $cdom.'_'.$cnum;
5449: $setters->{$course} = {};
5450: $setters->{$course}{'staff'} = [];
5451: $setters->{$course}{'times'} = [];
1.1062 raeburn 5452: $setters->{$course}{'triggers'} = [];
5453: my (@blockers,%triggered);
5454: my $now = time;
5455: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5456: if ($activity eq 'docs') {
1.1348 raeburn 5457: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5458: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5459: $blocked = 1;
5460: $nosymbcache = 1;
1.1348 raeburn 5461: $noenccheck = 1;
1.1347 raeburn 5462: }
1.1348 raeburn 5463: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5464: foreach my $block (@blockers) {
5465: if ($block =~ /^firstaccess____(.+)$/) {
5466: my $item = $1;
5467: my $type = 'map';
5468: my $timersymb = $item;
5469: if ($item eq 'course') {
5470: $type = 'course';
5471: } elsif ($item =~ /___\d+___/) {
5472: $type = 'resource';
5473: } else {
5474: $timersymb = &Apache::lonnet::symbread($item);
5475: }
5476: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5477: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5478: $triggered{$block} = {
5479: start => $start,
5480: end => $end,
5481: type => $type,
5482: };
5483: }
5484: }
5485: } else {
5486: foreach my $block (keys(%commblocks)) {
5487: if ($block =~ m/^(\d+)____(\d+)$/) {
5488: my ($start,$end) = ($1,$2);
5489: if ($start <= time && $end >= time) {
5490: if (ref($commblocks{$block}) eq 'HASH') {
5491: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5492: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5493: unless(grep(/^\Q$block\E$/,@blockers)) {
5494: push(@blockers,$block);
5495: }
5496: }
5497: }
5498: }
5499: }
5500: } elsif ($block =~ /^firstaccess____(.+)$/) {
5501: my $item = $1;
5502: my $timersymb = $item;
5503: my $type = 'map';
5504: if ($item eq 'course') {
5505: $type = 'course';
5506: } elsif ($item =~ /___\d+___/) {
5507: $type = 'resource';
5508: } else {
5509: $timersymb = &Apache::lonnet::symbread($item);
5510: }
5511: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5512: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5513: if ($start && $end) {
5514: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5515: if (ref($commblocks{$block}) eq 'HASH') {
5516: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5517: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5518: unless(grep(/^\Q$block\E$/,@blockers)) {
5519: push(@blockers,$block);
5520: $triggered{$block} = {
5521: start => $start,
5522: end => $end,
5523: type => $type,
5524: };
5525: }
5526: }
5527: }
1.1062 raeburn 5528: }
5529: }
1.490 raeburn 5530: }
1.1062 raeburn 5531: }
5532: }
5533: }
5534: foreach my $blocker (@blockers) {
5535: my ($staff_name,$staff_dom,$title,$blocks) =
5536: &parse_block_record($commblocks{$blocker});
5537: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5538: my ($start,$end,$triggertype);
5539: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5540: ($start,$end) = ($1,$2);
5541: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5542: $start = $triggered{$blocker}{'start'};
5543: $end = $triggered{$blocker}{'end'};
5544: $triggertype = $triggered{$blocker}{'type'};
5545: }
5546: if ($start) {
5547: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5548: if ($triggertype) {
5549: push(@{$$setters{$course}{'triggers'}},$triggertype);
5550: } else {
5551: push(@{$$setters{$course}{'triggers'}},0);
5552: }
5553: if ( ($startblock == 0) || ($startblock > $start) ) {
5554: $startblock = $start;
5555: if ($triggertype) {
5556: $triggerblock = $blocker;
1.474 raeburn 5557: }
5558: }
1.1062 raeburn 5559: if ( ($endblock == 0) || ($endblock < $end) ) {
5560: $endblock = $end;
5561: if ($triggertype) {
5562: $triggerblock = $blocker;
5563: }
5564: }
1.474 raeburn 5565: }
5566: }
1.1062 raeburn 5567: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5568: }
5569:
5570: sub parse_block_record {
5571: my ($record) = @_;
5572: my ($setuname,$setudom,$title,$blocks);
5573: if (ref($record) eq 'HASH') {
5574: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5575: $title = &unescape($record->{'event'});
5576: $blocks = $record->{'blocks'};
5577: } else {
5578: my @data = split(/:/,$record,3);
5579: if (scalar(@data) eq 2) {
5580: $title = $data[1];
5581: ($setuname,$setudom) = split(/@/,$data[0]);
5582: } else {
5583: ($setuname,$setudom,$title) = @data;
5584: }
5585: $blocks = { 'com' => 'on' };
5586: }
5587: return ($setuname,$setudom,$title,$blocks);
5588: }
5589:
1.854 kalberla 5590: sub blocking_status {
1.1372 raeburn 5591: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5592: my %setters;
1.890 droeschl 5593:
1.1061 raeburn 5594: # check for active blocking
1.1372 raeburn 5595: if ($clientip eq '') {
5596: $clientip = &Apache::lonnet::get_requestor_ip();
5597: }
5598: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5599: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5600: my $blocked = 0;
1.1372 raeburn 5601: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5602: $blocked = 1;
5603: }
1.890 droeschl 5604:
1.1061 raeburn 5605: # caller just wants to know whether a block is active
5606: if (!wantarray) { return $blocked; }
5607:
5608: # build a link to a popup window containing the details
5609: my $querystring = "?activity=$activity";
1.1351 raeburn 5610: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5611: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5612: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5613: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5614: } elsif ($activity eq 'docs') {
1.1347 raeburn 5615: my $showurl = &Apache::lonenc::check_encrypt($url);
5616: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5617: if ($symb) {
5618: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5619: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5620: }
1.1062 raeburn 5621: }
1.1061 raeburn 5622:
5623: my $output .= <<'END_MYBLOCK';
5624: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5625: var options = "width=" + w + ",height=" + h + ",";
5626: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5627: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5628: var newWin = window.open(url, wdwName, options);
5629: newWin.focus();
5630: }
1.890 droeschl 5631: END_MYBLOCK
1.854 kalberla 5632:
1.1061 raeburn 5633: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5634:
1.1061 raeburn 5635: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5636: my $text = &mt('Communication Blocked');
1.1217 raeburn 5637: my $class = 'LC_comblock';
1.1062 raeburn 5638: if ($activity eq 'docs') {
5639: $text = &mt('Content Access Blocked');
1.1217 raeburn 5640: $class = '';
1.1063 raeburn 5641: } elsif ($activity eq 'printout') {
5642: $text = &mt('Printing Blocked');
1.1232 raeburn 5643: } elsif ($activity eq 'passwd') {
5644: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5645: } elsif ($activity eq 'grades') {
5646: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5647: } elsif ($activity eq 'search') {
5648: $text = &mt('Search Blocked');
1.1282 raeburn 5649: } elsif ($activity eq 'alert') {
5650: $text = &mt('Checking Critical Messages Blocked');
5651: } elsif ($activity eq 'reinit') {
5652: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5653: } elsif ($activity eq 'about') {
5654: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5655: } elsif ($activity eq 'wishlist') {
5656: $text = &mt('Access to Stored Links Blocked');
5657: } elsif ($activity eq 'annotate') {
5658: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5659: }
1.1061 raeburn 5660: $output .= <<"END_BLOCK";
1.1217 raeburn 5661: <div class='$class'>
1.869 kalberla 5662: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5663: title='$text'>
5664: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5665: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5666: title='$text'>$text</a>
1.867 kalberla 5667: </div>
5668:
5669: END_BLOCK
1.474 raeburn 5670:
1.1061 raeburn 5671: return ($blocked, $output);
1.854 kalberla 5672: }
1.490 raeburn 5673:
1.60 matthew 5674: ###############################################
5675:
1.682 raeburn 5676: sub check_ip_acc {
1.1201 raeburn 5677: my ($acc,$clientip)=@_;
1.682 raeburn 5678: &Apache::lonxml::debug("acc is $acc");
5679: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5680: return 1;
5681: }
1.1339 raeburn 5682: my ($ip,$allowed);
5683: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5684: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5685: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5686: } else {
1.1350 raeburn 5687: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5688: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5689: }
1.682 raeburn 5690:
5691: my $name;
1.1219 raeburn 5692: my %access = (
5693: allowfrom => 1,
5694: denyfrom => 0,
5695: );
5696: my @allows;
5697: my @denies;
5698: foreach my $item (split(',',$acc)) {
5699: $item =~ s/^\s*//;
5700: $item =~ s/\s*$//;
5701: my $pattern;
5702: if ($item =~ /^\!(.+)$/) {
5703: push(@denies,$1);
5704: } else {
5705: push(@allows,$item);
5706: }
5707: }
5708: my $numdenies = scalar(@denies);
5709: my $numallows = scalar(@allows);
5710: my $count = 0;
5711: foreach my $pattern (@denies,@allows) {
5712: $count ++;
5713: my $acctype = 'allowfrom';
5714: if ($count <= $numdenies) {
5715: $acctype = 'denyfrom';
5716: }
1.682 raeburn 5717: if ($pattern =~ /\*$/) {
5718: #35.8.*
5719: $pattern=~s/\*//;
1.1219 raeburn 5720: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5721: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5722: #35.8.3.[34-56]
5723: my $low=$2;
5724: my $high=$3;
5725: $pattern=$1;
5726: if ($ip =~ /^\Q$pattern\E/) {
5727: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5728: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5729: }
5730: } elsif ($pattern =~ /^\*/) {
5731: #*.msu.edu
5732: $pattern=~s/\*//;
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}; }
1.682 raeburn 5739: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5740: #127.0.0.1
1.1219 raeburn 5741: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5742: } else {
5743: #some.name.com
5744: if (!defined($name)) {
5745: use Socket;
5746: my $netaddr=inet_aton($ip);
5747: ($name)=gethostbyaddr($netaddr,AF_INET);
5748: }
1.1219 raeburn 5749: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5750: }
5751: if ($allowed =~ /^(0|1)$/) { last; }
5752: }
5753: if ($allowed eq '') {
5754: if ($numdenies && !$numallows) {
5755: $allowed = 1;
5756: } else {
5757: $allowed = 0;
1.682 raeburn 5758: }
5759: }
5760: return $allowed;
5761: }
5762:
5763: ###############################################
5764:
1.60 matthew 5765: =pod
5766:
1.112 bowersj2 5767: =head1 Domain Template Functions
5768:
5769: =over 4
5770:
5771: =item * &determinedomain()
1.60 matthew 5772:
5773: Inputs: $domain (usually will be undef)
5774:
1.63 www 5775: Returns: Determines which domain should be used for designs
1.60 matthew 5776:
5777: =cut
1.54 www 5778:
1.60 matthew 5779: ###############################################
1.63 www 5780: sub determinedomain {
5781: my $domain=shift;
1.531 albertel 5782: if (! $domain) {
1.60 matthew 5783: # Determine domain if we have not been given one
1.893 raeburn 5784: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5785: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5786: if ($env{'request.role.domain'}) {
5787: $domain=$env{'request.role.domain'};
1.60 matthew 5788: }
5789: }
1.63 www 5790: return $domain;
5791: }
5792: ###############################################
1.517 raeburn 5793:
1.518 albertel 5794: sub devalidate_domconfig_cache {
5795: my ($udom)=@_;
5796: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5797: }
5798:
5799: # ---------------------- Get domain configuration for a domain
5800: sub get_domainconf {
5801: my ($udom) = @_;
5802: my $cachetime=1800;
5803: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5804: if (defined($cached)) { return %{$result}; }
5805:
5806: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5807: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5808: my (%designhash,%legacy);
1.518 albertel 5809: if (keys(%domconfig) > 0) {
5810: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5811: if (keys(%{$domconfig{'login'}})) {
5812: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5813: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5814: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5815: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5816: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5817: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5818: if ($key eq 'loginvia') {
5819: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5820: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5821: $designhash{$udom.'.login.loginvia'} = $server;
5822: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5823:
5824: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5825: } else {
5826: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5827: }
1.948 raeburn 5828: }
1.1208 raeburn 5829: } elsif ($key eq 'headtag') {
5830: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5831: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5832: }
1.946 raeburn 5833: }
1.1208 raeburn 5834: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5835: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5836: }
1.946 raeburn 5837: }
5838: }
5839: }
1.1366 raeburn 5840: } elsif ($key eq 'saml') {
5841: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5842: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5843: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5844: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
5845: foreach my $item ('text','img','alt','url','title','notsso') {
5846: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5847: }
5848: }
5849: }
5850: }
1.946 raeburn 5851: } else {
5852: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5853: $designhash{$udom.'.login.'.$key.'_'.$img} =
5854: $domconfig{'login'}{$key}{$img};
5855: }
1.699 raeburn 5856: }
5857: } else {
5858: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5859: }
1.632 raeburn 5860: }
5861: } else {
5862: $legacy{'login'} = 1;
1.518 albertel 5863: }
1.632 raeburn 5864: } else {
5865: $legacy{'login'} = 1;
1.518 albertel 5866: }
5867: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5868: if (keys(%{$domconfig{'rolecolors'}})) {
5869: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5870: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5871: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5872: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5873: }
1.518 albertel 5874: }
5875: }
1.632 raeburn 5876: } else {
5877: $legacy{'rolecolors'} = 1;
1.518 albertel 5878: }
1.632 raeburn 5879: } else {
5880: $legacy{'rolecolors'} = 1;
1.518 albertel 5881: }
1.948 raeburn 5882: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5883: if ($domconfig{'autoenroll'}{'co-owners'}) {
5884: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5885: }
5886: }
1.632 raeburn 5887: if (keys(%legacy) > 0) {
5888: my %legacyhash = &get_legacy_domconf($udom);
5889: foreach my $item (keys(%legacyhash)) {
5890: if ($item =~ /^\Q$udom\E\.login/) {
5891: if ($legacy{'login'}) {
5892: $designhash{$item} = $legacyhash{$item};
5893: }
5894: } else {
5895: if ($legacy{'rolecolors'}) {
5896: $designhash{$item} = $legacyhash{$item};
5897: }
1.518 albertel 5898: }
5899: }
5900: }
1.632 raeburn 5901: } else {
5902: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5903: }
5904: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5905: $cachetime);
5906: return %designhash;
5907: }
5908:
1.632 raeburn 5909: sub get_legacy_domconf {
5910: my ($udom) = @_;
5911: my %legacyhash;
5912: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5913: my $designfile = $designdir.'/'.$udom.'.tab';
5914: if (-e $designfile) {
1.1317 raeburn 5915: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5916: while (my $line = <$fh>) {
5917: next if ($line =~ /^\#/);
5918: chomp($line);
5919: my ($key,$val)=(split(/\=/,$line));
5920: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5921: }
5922: close($fh);
5923: }
5924: }
1.1026 raeburn 5925: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5926: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5927: }
5928: return %legacyhash;
5929: }
5930:
1.63 www 5931: =pod
5932:
1.112 bowersj2 5933: =item * &domainlogo()
1.63 www 5934:
5935: Inputs: $domain (usually will be undef)
5936:
5937: Returns: A link to a domain logo, if the domain logo exists.
5938: If the domain logo does not exist, a description of the domain.
5939:
5940: =cut
1.112 bowersj2 5941:
1.63 www 5942: ###############################################
5943: sub domainlogo {
1.517 raeburn 5944: my $domain = &determinedomain(shift);
1.518 albertel 5945: my %designhash = &get_domainconf($domain);
1.517 raeburn 5946: # See if there is a logo
5947: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5948: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5949: if ($imgsrc =~ m{^/(adm|res)/}) {
5950: if ($imgsrc =~ m{^/res/}) {
5951: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5952: &Apache::lonnet::repcopy($local_name);
5953: }
5954: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 5955: }
5956: my $alttext = $domain;
5957: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5958: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5959: }
5960: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5961: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5962: return &Apache::lonnet::domain($domain,'description');
1.59 www 5963: } else {
1.60 matthew 5964: return '';
1.59 www 5965: }
5966: }
1.63 www 5967: ##############################################
5968:
5969: =pod
5970:
1.112 bowersj2 5971: =item * &designparm()
1.63 www 5972:
5973: Inputs: $which parameter; $domain (usually will be undef)
5974:
5975: Returns: value of designparamter $which
5976:
5977: =cut
1.112 bowersj2 5978:
1.397 albertel 5979:
1.400 albertel 5980: ##############################################
1.397 albertel 5981: sub designparm {
5982: my ($which,$domain)=@_;
5983: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5984: return $env{'environment.color.'.$which};
1.96 www 5985: }
1.63 www 5986: $domain=&determinedomain($domain);
1.1016 raeburn 5987: my %domdesign;
5988: unless ($domain eq 'public') {
5989: %domdesign = &get_domainconf($domain);
5990: }
1.520 raeburn 5991: my $output;
1.517 raeburn 5992: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5993: $output = $domdesign{$domain.'.'.$which};
1.63 www 5994: } else {
1.520 raeburn 5995: $output = $defaultdesign{$which};
5996: }
5997: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5998: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5999: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6000: if ($output =~ m{^/res/}) {
6001: my $local_name = &Apache::lonnet::filelocation('',$output);
6002: &Apache::lonnet::repcopy($local_name);
6003: }
1.520 raeburn 6004: $output = &lonhttpdurl($output);
6005: }
1.63 www 6006: }
1.520 raeburn 6007: return $output;
1.63 www 6008: }
1.59 www 6009:
1.822 bisitz 6010: ##############################################
6011: =pod
6012:
1.832 bisitz 6013: =item * &authorspace()
6014:
1.1028 raeburn 6015: Inputs: $url (usually will be undef).
1.832 bisitz 6016:
1.1132 raeburn 6017: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6018: directory being viewed (or for which action is being taken).
6019: If $url is provided, and begins /priv/<domain>/<uname>
6020: the path will be that portion of the $context argument.
6021: Otherwise the path will be for the author space of the current
6022: user when the current role is author, or for that of the
6023: co-author/assistant co-author space when the current role
6024: is co-author or assistant co-author.
1.832 bisitz 6025:
6026: =cut
6027:
6028: sub authorspace {
1.1028 raeburn 6029: my ($url) = @_;
6030: if ($url ne '') {
6031: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6032: return $1;
6033: }
6034: }
1.832 bisitz 6035: my $caname = '';
1.1024 www 6036: my $cadom = '';
1.1028 raeburn 6037: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6038: ($cadom,$caname) =
1.832 bisitz 6039: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6040: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6041: $caname = $env{'user.name'};
1.1024 www 6042: $cadom = $env{'user.domain'};
1.832 bisitz 6043: }
1.1028 raeburn 6044: if (($caname ne '') && ($cadom ne '')) {
6045: return "/priv/$cadom/$caname/";
6046: }
6047: return;
1.832 bisitz 6048: }
6049:
6050: ##############################################
6051: =pod
6052:
1.822 bisitz 6053: =item * &head_subbox()
6054:
6055: Inputs: $content (contains HTML code with page functions, etc.)
6056:
6057: Returns: HTML div with $content
6058: To be included in page header
6059:
6060: =cut
6061:
6062: sub head_subbox {
6063: my ($content)=@_;
6064: my $output =
1.993 raeburn 6065: '<div class="LC_head_subbox">'
1.822 bisitz 6066: .$content
6067: .'</div>'
6068: }
6069:
6070: ##############################################
6071: =pod
6072:
6073: =item * &CSTR_pageheader()
6074:
1.1026 raeburn 6075: Input: (optional) filename from which breadcrumb trail is built.
6076: In most cases no input as needed, as $env{'request.filename'}
6077: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 6078:
6079: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6080: To be included on Authoring Space pages
1.822 bisitz 6081:
6082: =cut
6083:
6084: sub CSTR_pageheader {
1.1026 raeburn 6085: my ($trailfile) = @_;
6086: if ($trailfile eq '') {
6087: $trailfile = $env{'request.filename'};
6088: }
6089:
6090: # this is for resources; directories have customtitle, and crumbs
6091: # and select recent are created in lonpubdir.pm
6092:
6093: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6094: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6095: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6096: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6097: $formaction =~ s{/+}{/}g;
1.822 bisitz 6098:
6099: my $parentpath = '';
6100: my $lastitem = '';
6101: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6102: $parentpath = $1;
6103: $lastitem = $2;
6104: } else {
6105: $lastitem = $thisdisfn;
6106: }
1.921 bisitz 6107:
1.1246 raeburn 6108: my ($crsauthor,$title);
6109: if (($env{'request.course.id'}) &&
6110: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6111: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6112: $crsauthor = 1;
6113: $title = &mt('Course Authoring Space');
6114: } else {
6115: $title = &mt('Authoring Space');
6116: }
6117:
1.1314 raeburn 6118: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 6119: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6120: $target = '';
6121: $crumbtarget = '';
1.1313 raeburn 6122: }
6123:
1.921 bisitz 6124: my $output =
1.822 bisitz 6125: '<div>'
6126: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6127: .'<b>'.$title.'</b> '
1.1314 raeburn 6128: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6129: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6130:
6131: if ($lastitem) {
6132: $output .=
6133: '<span class="LC_filename">'
6134: .$lastitem
6135: .'</span>';
6136: }
1.1245 raeburn 6137:
1.1246 raeburn 6138: if ($crsauthor) {
6139: $output .= '</form>'.&Apache::lonmenu::constspaceform();
6140: } else {
6141: $output .=
6142: '<br />'
1.1314 raeburn 6143: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6144: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6145: .'</form>'
6146: .&Apache::lonmenu::constspaceform();
6147: }
6148: $output .= '</div>';
1.921 bisitz 6149:
6150: return $output;
1.822 bisitz 6151: }
6152:
1.60 matthew 6153: ###############################################
6154: ###############################################
6155:
6156: =pod
6157:
1.112 bowersj2 6158: =back
6159:
1.549 albertel 6160: =head1 HTML Helpers
1.112 bowersj2 6161:
6162: =over 4
6163:
6164: =item * &bodytag()
1.60 matthew 6165:
6166: Returns a uniform header for LON-CAPA web pages.
6167:
6168: Inputs:
6169:
1.112 bowersj2 6170: =over 4
6171:
6172: =item * $title, A title to be displayed on the page.
6173:
6174: =item * $function, the current role (can be undef).
6175:
6176: =item * $addentries, extra parameters for the <body> tag.
6177:
6178: =item * $bodyonly, if defined, only return the <body> tag.
6179:
6180: =item * $domain, if defined, force a given domain.
6181:
6182: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6183: text interface only)
1.60 matthew 6184:
1.814 bisitz 6185: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6186: navigational links
1.317 albertel 6187:
1.338 albertel 6188: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6189:
1.460 albertel 6190: =item * $args, optional argument valid values are
6191: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6192: use_absolute -> for external resource or syllabus, this will
6193: contain https://<hostname> if server uses
6194: https (as per hosts.tab), but request is for http
6195: hostname -> hostname, from $r->hostname().
1.460 albertel 6196:
1.1096 raeburn 6197: =item * $advtoolsref, optional argument, ref to an array containing
6198: inlineremote items to be added in "Functions" menu below
6199: breadcrumbs.
6200:
1.1316 raeburn 6201: =item * $ltiscope, optional argument, will be one of: resource, map or
6202: course, if LON-CAPA is in LTI Provider context. Value is
6203: the scope of use, i.e., launch was for access to a single, a map
6204: or the entire course.
6205:
6206: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6207: context, this will contain the URL for the landing item in
6208: the course, after launch from an LTI Consumer
6209:
1.1318 raeburn 6210: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6211: context, this will contain a reference to hash of items
6212: to be included in the page header and/or inline menu.
6213:
1.112 bowersj2 6214: =back
6215:
1.60 matthew 6216: Returns: A uniform header for LON-CAPA web pages.
6217: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6218: If $bodyonly is undef or zero, an html string containing a <body> tag and
6219: other decorations will be returned.
6220:
6221: =cut
6222:
1.54 www 6223: sub bodytag {
1.831 bisitz 6224: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6225: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
6226: $ltimenu,$menucoll,$menuref)=@_;
1.339 albertel 6227:
1.954 raeburn 6228: my $public;
6229: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6230: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6231: $public = 1;
6232: }
1.460 albertel 6233: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6234: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6235: my $hostname = $args->{'hostname'};
1.339 albertel 6236:
1.183 matthew 6237: $function = &get_users_function() if (!$function);
1.339 albertel 6238: my $img = &designparm($function.'.img',$domain);
6239: my $font = &designparm($function.'.font',$domain);
6240: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6241:
1.803 bisitz 6242: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6243: 'bgcolor' => $pgbg,
1.339 albertel 6244: 'text' => $font,
6245: 'alink' => &designparm($function.'.alink',$domain),
6246: 'vlink' => &designparm($function.'.vlink',$domain),
6247: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6248: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6249:
1.63 www 6250: # role and realm
1.1178 raeburn 6251: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6252: if ($realm) {
6253: $realm = '/'.$realm;
6254: }
1.1357 raeburn 6255: if ($role eq 'ca') {
1.479 albertel 6256: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6257: $realm = &plainname($rname,$rdom);
1.378 raeburn 6258: }
1.55 www 6259: # realm
1.1357 raeburn 6260: my ($cid,$sec);
1.258 albertel 6261: if ($env{'request.course.id'}) {
1.1357 raeburn 6262: $cid = $env{'request.course.id'};
6263: if ($env{'request.course.sec'}) {
6264: $sec = $env{'request.course.sec'};
6265: }
6266: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6267: if (&Apache::lonnet::is_course($1,$2)) {
6268: $cid = $1.'_'.$2;
6269: $sec = $3;
6270: }
6271: }
6272: if ($cid) {
1.378 raeburn 6273: if ($env{'request.role'} !~ /^cr/) {
6274: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6275: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6276: if ($env{'request.role.desc'}) {
6277: $role = $env{'request.role.desc'};
6278: } else {
6279: $role = &mt('Helpdesk[_1]',' '.$2);
6280: }
1.1257 raeburn 6281: } else {
6282: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6283: }
1.1357 raeburn 6284: if ($sec) {
6285: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6286: }
1.1357 raeburn 6287: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6288: } else {
6289: $role = &Apache::lonnet::plaintext($role);
1.54 www 6290: }
1.433 albertel 6291:
1.359 albertel 6292: if (!$realm) { $realm=' '; }
1.330 albertel 6293:
1.438 albertel 6294: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6295:
1.101 www 6296: # construct main body tag
1.359 albertel 6297: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6298: &Apache::lontexconvert::init_math_support();
1.252 albertel 6299:
1.1131 raeburn 6300: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6301:
1.1130 raeburn 6302: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6303: return $bodytag;
1.1130 raeburn 6304: }
1.359 albertel 6305:
1.954 raeburn 6306: if ($public) {
1.433 albertel 6307: undef($role);
6308: }
1.1318 raeburn 6309:
1.1359 raeburn 6310: my $showcrstitle = 1;
1.1357 raeburn 6311: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6312: if (ref($ltimenu) eq 'HASH') {
6313: unless ($ltimenu->{'role'}) {
6314: undef($role);
6315: }
6316: unless ($ltimenu->{'coursetitle'}) {
6317: $realm=' ';
1.1359 raeburn 6318: $showcrstitle = 0;
6319: }
6320: }
6321: } elsif (($cid) && ($menucoll)) {
6322: if (ref($menuref) eq 'HASH') {
6323: unless ($menuref->{'role'}) {
6324: undef($role);
6325: }
6326: unless ($menuref->{'crs'}) {
6327: $realm=' ';
6328: $showcrstitle = 0;
1.1318 raeburn 6329: }
6330: }
6331: }
6332:
1.762 bisitz 6333: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6334: #
6335: # Extra info if you are the DC
6336: my $dc_info = '';
1.1359 raeburn 6337: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6338: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6339: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6340: $dc_info =~ s/\s+$//;
1.359 albertel 6341: }
6342:
1.1237 raeburn 6343: my $crstype;
1.1357 raeburn 6344: if ($cid) {
6345: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6346: } elsif ($args->{'crstype'}) {
6347: $crstype = $args->{'crstype'};
6348: }
6349: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6350: undef($role);
6351: } else {
1.1242 raeburn 6352: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6353: }
1.853 droeschl 6354:
1.903 droeschl 6355: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6356:
6357: # if ($env{'request.state'} eq 'construct') {
6358: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6359: # }
6360:
1.1130 raeburn 6361: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6362: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6363:
1.1318 raeburn 6364: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6365: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
6366: $args->{'links_disabled'});
1.359 albertel 6367:
1.1318 raeburn 6368: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6369: if ($dc_info) {
6370: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6371: }
6372: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6373: <em>$realm</em> $dc_info</div>|;
6374: return $bodytag;
6375: }
1.894 droeschl 6376:
1.1318 raeburn 6377: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6378: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6379: }
1.916 droeschl 6380:
1.1318 raeburn 6381: $bodytag .= $right;
1.852 droeschl 6382:
1.1318 raeburn 6383: if ($dc_info) {
6384: $dc_info = &dc_courseid_toggle($dc_info);
6385: }
6386: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6387: }
1.916 droeschl 6388:
1.1169 raeburn 6389: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6390: if ($args->{'no_secondary_menu'}) {
6391: return $bodytag;
6392: }
1.1169 raeburn 6393: #don't show menus for public users
1.954 raeburn 6394: if (!$public){
1.1318 raeburn 6395: unless ($args->{'no_inline_menu'}) {
6396: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6397: $args->{'no_primary_menu'},
1.1369 raeburn 6398: $menucoll,$menuref,
6399: $args->{'links_disabled'});
1.1318 raeburn 6400: }
1.903 droeschl 6401: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6402: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6403: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6404: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6405: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6406: } elsif ($forcereg) {
6407: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6408: $args->{'group'},
1.1274 raeburn 6409: $args->{'hide_buttons'},
1.1316 raeburn 6410: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6411: } else {
6412: $bodytag .=
6413: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6414: $forcereg,$args->{'group'},
6415: $args->{'bread_crumbs'},
1.1274 raeburn 6416: $advtoolsref,'',$hostname);
1.920 raeburn 6417: }
1.903 droeschl 6418: }else{
6419: # this is to seperate menu from content when there's no secondary
6420: # menu. Especially needed for public accessible ressources.
6421: $bodytag .= '<hr style="clear:both" />';
6422: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6423: }
1.903 droeschl 6424:
1.235 raeburn 6425: return $bodytag;
1.182 matthew 6426: }
6427:
1.917 raeburn 6428: sub dc_courseid_toggle {
6429: my ($dc_info) = @_;
1.980 raeburn 6430: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6431: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6432: &mt('(More ...)').'</a></span>'.
6433: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6434: }
6435:
1.330 albertel 6436: sub make_attr_string {
6437: my ($register,$attr_ref) = @_;
6438:
6439: if ($attr_ref && !ref($attr_ref)) {
6440: die("addentries Must be a hash ref ".
6441: join(':',caller(1))." ".
6442: join(':',caller(0))." ");
6443: }
6444:
6445: if ($register) {
1.339 albertel 6446: my ($on_load,$on_unload);
6447: foreach my $key (keys(%{$attr_ref})) {
6448: if (lc($key) eq 'onload') {
6449: $on_load.=$attr_ref->{$key}.';';
6450: delete($attr_ref->{$key});
6451:
6452: } elsif (lc($key) eq 'onunload') {
6453: $on_unload.=$attr_ref->{$key}.';';
6454: delete($attr_ref->{$key});
6455: }
6456: }
1.953 droeschl 6457: $attr_ref->{'onload'} = $on_load;
6458: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6459: }
1.339 albertel 6460:
1.330 albertel 6461: my $attr_string;
1.1159 raeburn 6462: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6463: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6464: }
6465: return $attr_string;
6466: }
6467:
6468:
1.182 matthew 6469: ###############################################
1.251 albertel 6470: ###############################################
6471:
6472: =pod
6473:
6474: =item * &endbodytag()
6475:
6476: Returns a uniform footer for LON-CAPA web pages.
6477:
1.635 raeburn 6478: Inputs: 1 - optional reference to an args hash
6479: If in the hash, key for noredirectlink has a value which evaluates to true,
6480: a 'Continue' link is not displayed if the page contains an
6481: internal redirect in the <head></head> section,
6482: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6483:
6484: =cut
6485:
6486: sub endbodytag {
1.635 raeburn 6487: my ($args) = @_;
1.1080 raeburn 6488: my $endbodytag;
6489: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6490: $endbodytag='</body>';
6491: }
1.315 albertel 6492: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6493: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6494: $endbodytag=
6495: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6496: &mt('Continue').'</a>'.
6497: $endbodytag;
6498: }
1.315 albertel 6499: }
1.251 albertel 6500: return $endbodytag;
6501: }
6502:
1.352 albertel 6503: =pod
6504:
6505: =item * &standard_css()
6506:
6507: Returns a style sheet
6508:
6509: Inputs: (all optional)
6510: domain -> force to color decorate a page for a specific
6511: domain
6512: function -> force usage of a specific rolish color scheme
6513: bgcolor -> override the default page bgcolor
6514:
6515: =cut
6516:
1.343 albertel 6517: sub standard_css {
1.345 albertel 6518: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6519: $function = &get_users_function() if (!$function);
6520: my $img = &designparm($function.'.img', $domain);
6521: my $tabbg = &designparm($function.'.tabbg', $domain);
6522: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6523: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6524: #second colour for later usage
1.345 albertel 6525: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6526: my $pgbg_or_bgcolor =
6527: $bgcolor ||
1.352 albertel 6528: &designparm($function.'.pgbg', $domain);
1.382 albertel 6529: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6530: my $alink = &designparm($function.'.alink', $domain);
6531: my $vlink = &designparm($function.'.vlink', $domain);
6532: my $link = &designparm($function.'.link', $domain);
6533:
1.602 albertel 6534: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6535: my $mono = 'monospace';
1.850 bisitz 6536: my $data_table_head = $sidebg;
6537: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6538: my $data_table_dark = '#E0E0E0';
1.470 banghart 6539: my $data_table_darker = '#CCCCCC';
1.349 albertel 6540: my $data_table_highlight = '#FFFF00';
1.352 albertel 6541: my $mail_new = '#FFBB77';
6542: my $mail_new_hover = '#DD9955';
6543: my $mail_read = '#BBBB77';
6544: my $mail_read_hover = '#999944';
6545: my $mail_replied = '#AAAA88';
6546: my $mail_replied_hover = '#888855';
6547: my $mail_other = '#99BBBB';
6548: my $mail_other_hover = '#669999';
1.391 albertel 6549: my $table_header = '#DDDDDD';
1.489 raeburn 6550: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6551: my $lg_border_color = '#C8C8C8';
1.952 onken 6552: my $button_hover = '#BF2317';
1.392 albertel 6553:
1.608 albertel 6554: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6555: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6556: : '0 3px 0 4px';
1.448 albertel 6557:
1.523 albertel 6558:
1.343 albertel 6559: return <<END;
1.947 droeschl 6560:
6561: /* needed for iframe to allow 100% height in FF */
6562: body, html {
6563: margin: 0;
6564: padding: 0 0.5%;
6565: height: 99%; /* to avoid scrollbars */
6566: }
6567:
1.795 www 6568: body {
1.911 bisitz 6569: font-family: $sans;
6570: line-height:130%;
6571: font-size:0.83em;
6572: color:$font;
1.795 www 6573: }
6574:
1.959 onken 6575: a:focus,
6576: a:focus img {
1.795 www 6577: color: red;
6578: }
1.698 harmsja 6579:
1.911 bisitz 6580: form, .inline {
6581: display: inline;
1.795 www 6582: }
1.721 harmsja 6583:
1.795 www 6584: .LC_right {
1.911 bisitz 6585: text-align:right;
1.795 www 6586: }
6587:
6588: .LC_middle {
1.911 bisitz 6589: vertical-align:middle;
1.795 www 6590: }
1.721 harmsja 6591:
1.1130 raeburn 6592: .LC_floatleft {
6593: float: left;
6594: }
6595:
6596: .LC_floatright {
6597: float: right;
6598: }
6599:
1.911 bisitz 6600: .LC_400Box {
6601: width:400px;
6602: }
1.721 harmsja 6603:
1.947 droeschl 6604: .LC_iframecontainer {
6605: width: 98%;
6606: margin: 0;
6607: position: fixed;
6608: top: 8.5em;
6609: bottom: 0;
6610: }
6611:
6612: .LC_iframecontainer iframe{
6613: border: none;
6614: width: 100%;
6615: height: 100%;
6616: }
6617:
1.778 bisitz 6618: .LC_filename {
6619: font-family: $mono;
6620: white-space:pre;
1.921 bisitz 6621: font-size: 120%;
1.778 bisitz 6622: }
6623:
6624: .LC_fileicon {
6625: border: none;
6626: height: 1.3em;
6627: vertical-align: text-bottom;
6628: margin-right: 0.3em;
6629: text-decoration:none;
6630: }
6631:
1.1008 www 6632: .LC_setting {
6633: text-decoration:underline;
6634: }
6635:
1.350 albertel 6636: .LC_error {
6637: color: red;
6638: }
1.795 www 6639:
1.1097 bisitz 6640: .LC_warning {
6641: color: darkorange;
6642: }
6643:
1.457 albertel 6644: .LC_diff_removed {
1.733 bisitz 6645: color: red;
1.394 albertel 6646: }
1.532 albertel 6647:
6648: .LC_info,
1.457 albertel 6649: .LC_success,
6650: .LC_diff_added {
1.350 albertel 6651: color: green;
6652: }
1.795 www 6653:
1.802 bisitz 6654: div.LC_confirm_box {
6655: background-color: #FAFAFA;
6656: border: 1px solid $lg_border_color;
6657: margin-right: 0;
6658: padding: 5px;
6659: }
6660:
6661: div.LC_confirm_box .LC_error img,
6662: div.LC_confirm_box .LC_success img {
6663: vertical-align: middle;
6664: }
6665:
1.1242 raeburn 6666: .LC_maxwidth {
6667: max-width: 100%;
6668: height: auto;
6669: }
6670:
1.1243 raeburn 6671: .LC_textsize_mobile {
6672: \@media only screen and (max-device-width: 480px) {
6673: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6674: }
6675: }
6676:
1.440 albertel 6677: .LC_icon {
1.771 droeschl 6678: border: none;
1.790 droeschl 6679: vertical-align: middle;
1.771 droeschl 6680: }
6681:
1.543 albertel 6682: .LC_docs_spacer {
6683: width: 25px;
6684: height: 1px;
1.771 droeschl 6685: border: none;
1.543 albertel 6686: }
1.346 albertel 6687:
1.532 albertel 6688: .LC_internal_info {
1.735 bisitz 6689: color: #999999;
1.532 albertel 6690: }
6691:
1.794 www 6692: .LC_discussion {
1.1050 www 6693: background: $data_table_dark;
1.911 bisitz 6694: border: 1px solid black;
6695: margin: 2px;
1.794 www 6696: }
6697:
6698: .LC_disc_action_left {
1.1050 www 6699: background: $sidebg;
1.911 bisitz 6700: text-align: left;
1.1050 www 6701: padding: 4px;
6702: margin: 2px;
1.794 www 6703: }
6704:
6705: .LC_disc_action_right {
1.1050 www 6706: background: $sidebg;
1.911 bisitz 6707: text-align: right;
1.1050 www 6708: padding: 4px;
6709: margin: 2px;
1.794 www 6710: }
6711:
6712: .LC_disc_new_item {
1.911 bisitz 6713: background: white;
6714: border: 2px solid red;
1.1050 www 6715: margin: 4px;
6716: padding: 4px;
1.794 www 6717: }
6718:
6719: .LC_disc_old_item {
1.911 bisitz 6720: background: white;
1.1050 www 6721: margin: 4px;
6722: padding: 4px;
1.794 www 6723: }
6724:
1.458 albertel 6725: table.LC_pastsubmission {
6726: border: 1px solid black;
6727: margin: 2px;
6728: }
6729:
1.924 bisitz 6730: table#LC_menubuttons {
1.345 albertel 6731: width: 100%;
6732: background: $pgbg;
1.392 albertel 6733: border: 2px;
1.402 albertel 6734: border-collapse: separate;
1.803 bisitz 6735: padding: 0;
1.345 albertel 6736: }
1.392 albertel 6737:
1.801 tempelho 6738: table#LC_title_bar a {
6739: color: $fontmenu;
6740: }
1.836 bisitz 6741:
1.807 droeschl 6742: table#LC_title_bar {
1.819 tempelho 6743: clear: both;
1.836 bisitz 6744: display: none;
1.807 droeschl 6745: }
6746:
1.795 www 6747: table#LC_title_bar,
1.933 droeschl 6748: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6749: table#LC_title_bar.LC_with_remote {
1.359 albertel 6750: width: 100%;
1.392 albertel 6751: border-color: $pgbg;
6752: border-style: solid;
6753: border-width: $border;
1.379 albertel 6754: background: $pgbg;
1.801 tempelho 6755: color: $fontmenu;
1.392 albertel 6756: border-collapse: collapse;
1.803 bisitz 6757: padding: 0;
1.819 tempelho 6758: margin: 0;
1.359 albertel 6759: }
1.795 www 6760:
1.933 droeschl 6761: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6762: margin: 0;
6763: padding: 0;
1.933 droeschl 6764: position: relative;
6765: list-style: none;
1.913 droeschl 6766: }
1.933 droeschl 6767: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6768: display: inline;
6769: }
1.933 droeschl 6770:
6771: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6772: padding: 0;
1.933 droeschl 6773: margin: 0;
6774: float: left;
1.913 droeschl 6775: }
1.933 droeschl 6776: .LC_breadcrumb_tools_tools {
6777: padding: 0;
6778: margin: 0;
1.913 droeschl 6779: float: right;
6780: }
6781:
1.1240 raeburn 6782: .LC_placement_prog {
6783: padding-right: 20px;
6784: font-weight: bold;
6785: font-size: 90%;
6786: }
6787:
1.359 albertel 6788: table#LC_title_bar td {
6789: background: $tabbg;
6790: }
1.795 www 6791:
1.911 bisitz 6792: table#LC_menubuttons img {
1.803 bisitz 6793: border: none;
1.346 albertel 6794: }
1.795 www 6795:
1.842 droeschl 6796: .LC_breadcrumbs_component {
1.911 bisitz 6797: float: right;
6798: margin: 0 1em;
1.357 albertel 6799: }
1.842 droeschl 6800: .LC_breadcrumbs_component img {
1.911 bisitz 6801: vertical-align: middle;
1.777 tempelho 6802: }
1.795 www 6803:
1.1243 raeburn 6804: .LC_breadcrumbs_hoverable {
6805: background: $sidebg;
6806: }
6807:
1.383 albertel 6808: td.LC_table_cell_checkbox {
6809: text-align: center;
6810: }
1.795 www 6811:
6812: .LC_fontsize_small {
1.911 bisitz 6813: font-size: 70%;
1.705 tempelho 6814: }
6815:
1.844 bisitz 6816: #LC_breadcrumbs {
1.911 bisitz 6817: clear:both;
6818: background: $sidebg;
6819: border-bottom: 1px solid $lg_border_color;
6820: line-height: 2.5em;
1.933 droeschl 6821: overflow: hidden;
1.911 bisitz 6822: margin: 0;
6823: padding: 0;
1.995 raeburn 6824: text-align: left;
1.819 tempelho 6825: }
1.862 bisitz 6826:
1.1098 bisitz 6827: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6828: clear:both;
6829: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6830: border: 1px solid $sidebg;
1.1098 bisitz 6831: margin: 0 0 10px 0;
1.966 bisitz 6832: padding: 3px;
1.995 raeburn 6833: text-align: left;
1.822 bisitz 6834: }
6835:
1.795 www 6836: .LC_fontsize_medium {
1.911 bisitz 6837: font-size: 85%;
1.705 tempelho 6838: }
6839:
1.795 www 6840: .LC_fontsize_large {
1.911 bisitz 6841: font-size: 120%;
1.705 tempelho 6842: }
6843:
1.346 albertel 6844: .LC_menubuttons_inline_text {
6845: color: $font;
1.698 harmsja 6846: font-size: 90%;
1.701 harmsja 6847: padding-left:3px;
1.346 albertel 6848: }
6849:
1.934 droeschl 6850: .LC_menubuttons_inline_text img{
6851: vertical-align: middle;
6852: }
6853:
1.1051 www 6854: li.LC_menubuttons_inline_text img {
1.951 onken 6855: cursor:pointer;
1.1002 droeschl 6856: text-decoration: none;
1.951 onken 6857: }
6858:
1.526 www 6859: .LC_menubuttons_link {
6860: text-decoration: none;
6861: }
1.795 www 6862:
1.522 albertel 6863: .LC_menubuttons_category {
1.521 www 6864: color: $font;
1.526 www 6865: background: $pgbg;
1.521 www 6866: font-size: larger;
6867: font-weight: bold;
6868: }
6869:
1.346 albertel 6870: td.LC_menubuttons_text {
1.911 bisitz 6871: color: $font;
1.346 albertel 6872: }
1.706 harmsja 6873:
1.346 albertel 6874: .LC_current_location {
6875: background: $tabbg;
6876: }
1.795 www 6877:
1.1286 raeburn 6878: td.LC_zero_height {
6879: line-height: 0;
6880: cellpadding: 0;
6881: }
6882:
1.938 bisitz 6883: table.LC_data_table {
1.347 albertel 6884: border: 1px solid #000000;
1.402 albertel 6885: border-collapse: separate;
1.426 albertel 6886: border-spacing: 1px;
1.610 albertel 6887: background: $pgbg;
1.347 albertel 6888: }
1.795 www 6889:
1.422 albertel 6890: .LC_data_table_dense {
6891: font-size: small;
6892: }
1.795 www 6893:
1.507 raeburn 6894: table.LC_nested_outer {
6895: border: 1px solid #000000;
1.589 raeburn 6896: border-collapse: collapse;
1.803 bisitz 6897: border-spacing: 0;
1.507 raeburn 6898: width: 100%;
6899: }
1.795 www 6900:
1.879 raeburn 6901: table.LC_innerpickbox,
1.507 raeburn 6902: table.LC_nested {
1.803 bisitz 6903: border: none;
1.589 raeburn 6904: border-collapse: collapse;
1.803 bisitz 6905: border-spacing: 0;
1.507 raeburn 6906: width: 100%;
6907: }
1.795 www 6908:
1.911 bisitz 6909: table.LC_data_table tr th,
6910: table.LC_calendar tr th,
1.879 raeburn 6911: table.LC_prior_tries tr th,
6912: table.LC_innerpickbox tr th {
1.349 albertel 6913: font-weight: bold;
6914: background-color: $data_table_head;
1.801 tempelho 6915: color:$fontmenu;
1.701 harmsja 6916: font-size:90%;
1.347 albertel 6917: }
1.795 www 6918:
1.879 raeburn 6919: table.LC_innerpickbox tr th,
6920: table.LC_innerpickbox tr td {
6921: vertical-align: top;
6922: }
6923:
1.711 raeburn 6924: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6925: background-color: #CCCCCC;
1.711 raeburn 6926: font-weight: bold;
6927: text-align: left;
6928: }
1.795 www 6929:
1.912 bisitz 6930: table.LC_data_table tr.LC_odd_row > td {
6931: background-color: $data_table_light;
6932: padding: 2px;
6933: vertical-align: top;
6934: }
6935:
1.809 bisitz 6936: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6937: background-color: $data_table_light;
1.912 bisitz 6938: vertical-align: top;
6939: }
6940:
6941: table.LC_data_table tr.LC_even_row > td {
6942: background-color: $data_table_dark;
1.425 albertel 6943: padding: 2px;
1.900 bisitz 6944: vertical-align: top;
1.347 albertel 6945: }
1.795 www 6946:
1.809 bisitz 6947: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6948: background-color: $data_table_dark;
1.900 bisitz 6949: vertical-align: top;
1.347 albertel 6950: }
1.795 www 6951:
1.425 albertel 6952: table.LC_data_table tr.LC_data_table_highlight td {
6953: background-color: $data_table_darker;
6954: }
1.795 www 6955:
1.639 raeburn 6956: table.LC_data_table tr td.LC_leftcol_header {
6957: background-color: $data_table_head;
6958: font-weight: bold;
6959: }
1.795 www 6960:
1.451 albertel 6961: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6962: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6963: font-weight: bold;
6964: font-style: italic;
6965: text-align: center;
6966: padding: 8px;
1.347 albertel 6967: }
1.795 www 6968:
1.1114 raeburn 6969: table.LC_data_table tr.LC_empty_row td,
6970: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6971: background-color: $sidebg;
6972: }
6973:
6974: table.LC_nested tr.LC_empty_row td {
6975: background-color: #FFFFFF;
6976: }
6977:
1.890 droeschl 6978: table.LC_caption {
6979: }
6980:
1.507 raeburn 6981: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6982: padding: 4ex
6983: }
1.795 www 6984:
1.507 raeburn 6985: table.LC_nested_outer tr th {
6986: font-weight: bold;
1.801 tempelho 6987: color:$fontmenu;
1.507 raeburn 6988: background-color: $data_table_head;
1.701 harmsja 6989: font-size: small;
1.507 raeburn 6990: border-bottom: 1px solid #000000;
6991: }
1.795 www 6992:
1.507 raeburn 6993: table.LC_nested_outer tr td.LC_subheader {
6994: background-color: $data_table_head;
6995: font-weight: bold;
6996: font-size: small;
6997: border-bottom: 1px solid #000000;
6998: text-align: right;
1.451 albertel 6999: }
1.795 www 7000:
1.507 raeburn 7001: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7002: background-color: #CCCCCC;
1.451 albertel 7003: font-weight: bold;
7004: font-size: small;
1.507 raeburn 7005: text-align: center;
7006: }
1.795 www 7007:
1.589 raeburn 7008: table.LC_nested tr.LC_info_row td.LC_left_item,
7009: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7010: text-align: left;
1.451 albertel 7011: }
1.795 www 7012:
1.507 raeburn 7013: table.LC_nested td {
1.735 bisitz 7014: background-color: #FFFFFF;
1.451 albertel 7015: font-size: small;
1.507 raeburn 7016: }
1.795 www 7017:
1.507 raeburn 7018: table.LC_nested_outer tr th.LC_right_item,
7019: table.LC_nested tr.LC_info_row td.LC_right_item,
7020: table.LC_nested tr.LC_odd_row td.LC_right_item,
7021: table.LC_nested tr td.LC_right_item {
1.451 albertel 7022: text-align: right;
7023: }
7024:
1.507 raeburn 7025: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7026: background-color: #EEEEEE;
1.451 albertel 7027: }
7028:
1.473 raeburn 7029: table.LC_createuser {
7030: }
7031:
7032: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7033: font-size: small;
1.473 raeburn 7034: }
7035:
7036: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7037: background-color: #CCCCCC;
1.473 raeburn 7038: font-weight: bold;
7039: text-align: center;
7040: }
7041:
1.349 albertel 7042: table.LC_calendar {
7043: border: 1px solid #000000;
7044: border-collapse: collapse;
1.917 raeburn 7045: width: 98%;
1.349 albertel 7046: }
1.795 www 7047:
1.349 albertel 7048: table.LC_calendar_pickdate {
7049: font-size: xx-small;
7050: }
1.795 www 7051:
1.349 albertel 7052: table.LC_calendar tr td {
7053: border: 1px solid #000000;
7054: vertical-align: top;
1.917 raeburn 7055: width: 14%;
1.349 albertel 7056: }
1.795 www 7057:
1.349 albertel 7058: table.LC_calendar tr td.LC_calendar_day_empty {
7059: background-color: $data_table_dark;
7060: }
1.795 www 7061:
1.779 bisitz 7062: table.LC_calendar tr td.LC_calendar_day_current {
7063: background-color: $data_table_highlight;
1.777 tempelho 7064: }
1.795 www 7065:
1.938 bisitz 7066: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7067: background-color: $mail_new;
7068: }
1.795 www 7069:
1.938 bisitz 7070: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7071: background-color: $mail_new_hover;
7072: }
1.795 www 7073:
1.938 bisitz 7074: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7075: background-color: $mail_read;
7076: }
1.795 www 7077:
1.938 bisitz 7078: /*
7079: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7080: background-color: $mail_read_hover;
7081: }
1.938 bisitz 7082: */
1.795 www 7083:
1.938 bisitz 7084: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7085: background-color: $mail_replied;
7086: }
1.795 www 7087:
1.938 bisitz 7088: /*
7089: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7090: background-color: $mail_replied_hover;
7091: }
1.938 bisitz 7092: */
1.795 www 7093:
1.938 bisitz 7094: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7095: background-color: $mail_other;
7096: }
1.795 www 7097:
1.938 bisitz 7098: /*
7099: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7100: background-color: $mail_other_hover;
7101: }
1.938 bisitz 7102: */
1.494 raeburn 7103:
1.777 tempelho 7104: table.LC_data_table tr > td.LC_browser_file,
7105: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7106: background: #AAEE77;
1.389 albertel 7107: }
1.795 www 7108:
1.777 tempelho 7109: table.LC_data_table tr > td.LC_browser_file_locked,
7110: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7111: background: #FFAA99;
1.387 albertel 7112: }
1.795 www 7113:
1.777 tempelho 7114: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7115: background: #888888;
1.779 bisitz 7116: }
1.795 www 7117:
1.777 tempelho 7118: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7119: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7120: background: #F8F866;
1.777 tempelho 7121: }
1.795 www 7122:
1.696 bisitz 7123: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7124: background: #E0E8FF;
1.387 albertel 7125: }
1.696 bisitz 7126:
1.707 bisitz 7127: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7128: /* background: #77FF77; */
1.707 bisitz 7129: }
1.795 www 7130:
1.707 bisitz 7131: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7132: border-right: 8px solid #FFFF77;
1.707 bisitz 7133: }
1.795 www 7134:
1.707 bisitz 7135: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7136: border-right: 8px solid #FFAA77;
1.707 bisitz 7137: }
1.795 www 7138:
1.707 bisitz 7139: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7140: border-right: 8px solid #FF7777;
1.707 bisitz 7141: }
1.795 www 7142:
1.707 bisitz 7143: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7144: border-right: 8px solid #AAFF77;
1.707 bisitz 7145: }
1.795 www 7146:
1.707 bisitz 7147: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7148: border-right: 8px solid #11CC55;
1.707 bisitz 7149: }
7150:
1.388 albertel 7151: span.LC_current_location {
1.701 harmsja 7152: font-size:larger;
1.388 albertel 7153: background: $pgbg;
7154: }
1.387 albertel 7155:
1.1029 www 7156: span.LC_current_nav_location {
7157: font-weight:bold;
7158: background: $sidebg;
7159: }
7160:
1.395 albertel 7161: span.LC_parm_menu_item {
7162: font-size: larger;
7163: }
1.795 www 7164:
1.395 albertel 7165: span.LC_parm_scope_all {
7166: color: red;
7167: }
1.795 www 7168:
1.395 albertel 7169: span.LC_parm_scope_folder {
7170: color: green;
7171: }
1.795 www 7172:
1.395 albertel 7173: span.LC_parm_scope_resource {
7174: color: orange;
7175: }
1.795 www 7176:
1.395 albertel 7177: span.LC_parm_part {
7178: color: blue;
7179: }
1.795 www 7180:
1.911 bisitz 7181: span.LC_parm_folder,
7182: span.LC_parm_symb {
1.395 albertel 7183: font-size: x-small;
7184: font-family: $mono;
7185: color: #AAAAAA;
7186: }
7187:
1.977 bisitz 7188: ul.LC_parm_parmlist li {
7189: display: inline-block;
7190: padding: 0.3em 0.8em;
7191: vertical-align: top;
7192: width: 150px;
7193: border-top:1px solid $lg_border_color;
7194: }
7195:
1.795 www 7196: td.LC_parm_overview_level_menu,
7197: td.LC_parm_overview_map_menu,
7198: td.LC_parm_overview_parm_selectors,
7199: td.LC_parm_overview_restrictions {
1.396 albertel 7200: border: 1px solid black;
7201: border-collapse: collapse;
7202: }
1.795 www 7203:
1.1285 raeburn 7204: span.LC_parm_recursive,
7205: td.LC_parm_recursive {
7206: font-weight: bold;
7207: font-size: smaller;
7208: }
7209:
1.396 albertel 7210: table.LC_parm_overview_restrictions td {
7211: border-width: 1px 4px 1px 4px;
7212: border-style: solid;
7213: border-color: $pgbg;
7214: text-align: center;
7215: }
1.795 www 7216:
1.396 albertel 7217: table.LC_parm_overview_restrictions th {
7218: background: $tabbg;
7219: border-width: 1px 4px 1px 4px;
7220: border-style: solid;
7221: border-color: $pgbg;
7222: }
1.795 www 7223:
1.398 albertel 7224: table#LC_helpmenu {
1.803 bisitz 7225: border: none;
1.398 albertel 7226: height: 55px;
1.803 bisitz 7227: border-spacing: 0;
1.398 albertel 7228: }
7229:
7230: table#LC_helpmenu fieldset legend {
7231: font-size: larger;
7232: }
1.795 www 7233:
1.397 albertel 7234: table#LC_helpmenu_links {
7235: width: 100%;
7236: border: 1px solid black;
7237: background: $pgbg;
1.803 bisitz 7238: padding: 0;
1.397 albertel 7239: border-spacing: 1px;
7240: }
1.795 www 7241:
1.397 albertel 7242: table#LC_helpmenu_links tr td {
7243: padding: 1px;
7244: background: $tabbg;
1.399 albertel 7245: text-align: center;
7246: font-weight: bold;
1.397 albertel 7247: }
1.396 albertel 7248:
1.795 www 7249: table#LC_helpmenu_links a:link,
7250: table#LC_helpmenu_links a:visited,
1.397 albertel 7251: table#LC_helpmenu_links a:active {
7252: text-decoration: none;
7253: color: $font;
7254: }
1.795 www 7255:
1.397 albertel 7256: table#LC_helpmenu_links a:hover {
7257: text-decoration: underline;
7258: color: $vlink;
7259: }
1.396 albertel 7260:
1.417 albertel 7261: .LC_chrt_popup_exists {
7262: border: 1px solid #339933;
7263: margin: -1px;
7264: }
1.795 www 7265:
1.417 albertel 7266: .LC_chrt_popup_up {
7267: border: 1px solid yellow;
7268: margin: -1px;
7269: }
1.795 www 7270:
1.417 albertel 7271: .LC_chrt_popup {
7272: border: 1px solid #8888FF;
7273: background: #CCCCFF;
7274: }
1.795 www 7275:
1.421 albertel 7276: table.LC_pick_box {
7277: border-collapse: separate;
7278: background: white;
7279: border: 1px solid black;
7280: border-spacing: 1px;
7281: }
1.795 www 7282:
1.421 albertel 7283: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7284: background: $sidebg;
1.421 albertel 7285: font-weight: bold;
1.900 bisitz 7286: text-align: left;
1.740 bisitz 7287: vertical-align: top;
1.421 albertel 7288: width: 184px;
7289: padding: 8px;
7290: }
1.795 www 7291:
1.579 raeburn 7292: table.LC_pick_box td.LC_pick_box_value {
7293: text-align: left;
7294: padding: 8px;
7295: }
1.795 www 7296:
1.579 raeburn 7297: table.LC_pick_box td.LC_pick_box_select {
7298: text-align: left;
7299: padding: 8px;
7300: }
1.795 www 7301:
1.424 albertel 7302: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7303: padding: 0;
1.421 albertel 7304: height: 1px;
7305: background: black;
7306: }
1.795 www 7307:
1.421 albertel 7308: table.LC_pick_box td.LC_pick_box_submit {
7309: text-align: right;
7310: }
1.795 www 7311:
1.579 raeburn 7312: table.LC_pick_box td.LC_evenrow_value {
7313: text-align: left;
7314: padding: 8px;
7315: background-color: $data_table_light;
7316: }
1.795 www 7317:
1.579 raeburn 7318: table.LC_pick_box td.LC_oddrow_value {
7319: text-align: left;
7320: padding: 8px;
7321: background-color: $data_table_light;
7322: }
1.795 www 7323:
1.579 raeburn 7324: span.LC_helpform_receipt_cat {
7325: font-weight: bold;
7326: }
1.795 www 7327:
1.424 albertel 7328: table.LC_group_priv_box {
7329: background: white;
7330: border: 1px solid black;
7331: border-spacing: 1px;
7332: }
1.795 www 7333:
1.424 albertel 7334: table.LC_group_priv_box td.LC_pick_box_title {
7335: background: $tabbg;
7336: font-weight: bold;
7337: text-align: right;
7338: width: 184px;
7339: }
1.795 www 7340:
1.424 albertel 7341: table.LC_group_priv_box td.LC_groups_fixed {
7342: background: $data_table_light;
7343: text-align: center;
7344: }
1.795 www 7345:
1.424 albertel 7346: table.LC_group_priv_box td.LC_groups_optional {
7347: background: $data_table_dark;
7348: text-align: center;
7349: }
1.795 www 7350:
1.424 albertel 7351: table.LC_group_priv_box td.LC_groups_functionality {
7352: background: $data_table_darker;
7353: text-align: center;
7354: font-weight: bold;
7355: }
1.795 www 7356:
1.424 albertel 7357: table.LC_group_priv td {
7358: text-align: left;
1.803 bisitz 7359: padding: 0;
1.424 albertel 7360: }
7361:
7362: .LC_navbuttons {
7363: margin: 2ex 0ex 2ex 0ex;
7364: }
1.795 www 7365:
1.423 albertel 7366: .LC_topic_bar {
7367: font-weight: bold;
7368: background: $tabbg;
1.918 wenzelju 7369: margin: 1em 0em 1em 2em;
1.805 bisitz 7370: padding: 3px;
1.918 wenzelju 7371: font-size: 1.2em;
1.423 albertel 7372: }
1.795 www 7373:
1.423 albertel 7374: .LC_topic_bar span {
1.918 wenzelju 7375: left: 0.5em;
7376: position: absolute;
1.423 albertel 7377: vertical-align: middle;
1.918 wenzelju 7378: font-size: 1.2em;
1.423 albertel 7379: }
1.795 www 7380:
1.423 albertel 7381: table.LC_course_group_status {
7382: margin: 20px;
7383: }
1.795 www 7384:
1.423 albertel 7385: table.LC_status_selector td {
7386: vertical-align: top;
7387: text-align: center;
1.424 albertel 7388: padding: 4px;
7389: }
1.795 www 7390:
1.599 albertel 7391: div.LC_feedback_link {
1.616 albertel 7392: clear: both;
1.829 kalberla 7393: background: $sidebg;
1.779 bisitz 7394: width: 100%;
1.829 kalberla 7395: padding-bottom: 10px;
7396: border: 1px $tabbg solid;
1.833 kalberla 7397: height: 22px;
7398: line-height: 22px;
7399: padding-top: 5px;
7400: }
7401:
7402: div.LC_feedback_link img {
7403: height: 22px;
1.867 kalberla 7404: vertical-align:middle;
1.829 kalberla 7405: }
7406:
1.911 bisitz 7407: div.LC_feedback_link a {
1.829 kalberla 7408: text-decoration: none;
1.489 raeburn 7409: }
1.795 www 7410:
1.867 kalberla 7411: div.LC_comblock {
1.911 bisitz 7412: display:inline;
1.867 kalberla 7413: color:$font;
7414: font-size:90%;
7415: }
7416:
7417: div.LC_feedback_link div.LC_comblock {
7418: padding-left:5px;
7419: }
7420:
7421: div.LC_feedback_link div.LC_comblock a {
7422: color:$font;
7423: }
7424:
1.489 raeburn 7425: span.LC_feedback_link {
1.858 bisitz 7426: /* background: $feedback_link_bg; */
1.599 albertel 7427: font-size: larger;
7428: }
1.795 www 7429:
1.599 albertel 7430: span.LC_message_link {
1.858 bisitz 7431: /* background: $feedback_link_bg; */
1.599 albertel 7432: font-size: larger;
7433: position: absolute;
7434: right: 1em;
1.489 raeburn 7435: }
1.421 albertel 7436:
1.515 albertel 7437: table.LC_prior_tries {
1.524 albertel 7438: border: 1px solid #000000;
7439: border-collapse: separate;
7440: border-spacing: 1px;
1.515 albertel 7441: }
1.523 albertel 7442:
1.515 albertel 7443: table.LC_prior_tries td {
1.524 albertel 7444: padding: 2px;
1.515 albertel 7445: }
1.523 albertel 7446:
7447: .LC_answer_correct {
1.795 www 7448: background: lightgreen;
7449: color: darkgreen;
7450: padding: 6px;
1.523 albertel 7451: }
1.795 www 7452:
1.523 albertel 7453: .LC_answer_charged_try {
1.797 www 7454: background: #FFAAAA;
1.795 www 7455: color: darkred;
7456: padding: 6px;
1.523 albertel 7457: }
1.795 www 7458:
1.779 bisitz 7459: .LC_answer_not_charged_try,
1.523 albertel 7460: .LC_answer_no_grade,
7461: .LC_answer_late {
1.795 www 7462: background: lightyellow;
1.523 albertel 7463: color: black;
1.795 www 7464: padding: 6px;
1.523 albertel 7465: }
1.795 www 7466:
1.523 albertel 7467: .LC_answer_previous {
1.795 www 7468: background: lightblue;
7469: color: darkblue;
7470: padding: 6px;
1.523 albertel 7471: }
1.795 www 7472:
1.779 bisitz 7473: .LC_answer_no_message {
1.777 tempelho 7474: background: #FFFFFF;
7475: color: black;
1.795 www 7476: padding: 6px;
1.779 bisitz 7477: }
1.795 www 7478:
1.1334 raeburn 7479: .LC_answer_unknown,
7480: .LC_answer_warning {
1.779 bisitz 7481: background: orange;
7482: color: black;
1.795 www 7483: padding: 6px;
1.777 tempelho 7484: }
1.795 www 7485:
1.529 albertel 7486: span.LC_prior_numerical,
7487: span.LC_prior_string,
7488: span.LC_prior_custom,
7489: span.LC_prior_reaction,
7490: span.LC_prior_math {
1.925 bisitz 7491: font-family: $mono;
1.523 albertel 7492: white-space: pre;
7493: }
7494:
1.525 albertel 7495: span.LC_prior_string {
1.925 bisitz 7496: font-family: $mono;
1.525 albertel 7497: white-space: pre;
7498: }
7499:
1.523 albertel 7500: table.LC_prior_option {
7501: width: 100%;
7502: border-collapse: collapse;
7503: }
1.795 www 7504:
1.911 bisitz 7505: table.LC_prior_rank,
1.795 www 7506: table.LC_prior_match {
1.528 albertel 7507: border-collapse: collapse;
7508: }
1.795 www 7509:
1.528 albertel 7510: table.LC_prior_option tr td,
7511: table.LC_prior_rank tr td,
7512: table.LC_prior_match tr td {
1.524 albertel 7513: border: 1px solid #000000;
1.515 albertel 7514: }
7515:
1.855 bisitz 7516: .LC_nobreak {
1.544 albertel 7517: white-space: nowrap;
1.519 raeburn 7518: }
7519:
1.576 raeburn 7520: span.LC_cusr_emph {
7521: font-style: italic;
7522: }
7523:
1.633 raeburn 7524: span.LC_cusr_subheading {
7525: font-weight: normal;
7526: font-size: 85%;
7527: }
7528:
1.861 bisitz 7529: div.LC_docs_entry_move {
1.859 bisitz 7530: border: 1px solid #BBBBBB;
1.545 albertel 7531: background: #DDDDDD;
1.861 bisitz 7532: width: 22px;
1.859 bisitz 7533: padding: 1px;
7534: margin: 0;
1.545 albertel 7535: }
7536:
1.861 bisitz 7537: table.LC_data_table tr > td.LC_docs_entry_commands,
7538: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7539: font-size: x-small;
7540: }
1.795 www 7541:
1.861 bisitz 7542: .LC_docs_entry_parameter {
7543: white-space: nowrap;
7544: }
7545:
1.544 albertel 7546: .LC_docs_copy {
1.545 albertel 7547: color: #000099;
1.544 albertel 7548: }
1.795 www 7549:
1.544 albertel 7550: .LC_docs_cut {
1.545 albertel 7551: color: #550044;
1.544 albertel 7552: }
1.795 www 7553:
1.544 albertel 7554: .LC_docs_rename {
1.545 albertel 7555: color: #009900;
1.544 albertel 7556: }
1.795 www 7557:
1.544 albertel 7558: .LC_docs_remove {
1.545 albertel 7559: color: #990000;
7560: }
7561:
1.1284 raeburn 7562: .LC_docs_alias {
7563: color: #440055;
7564: }
7565:
1.1286 raeburn 7566: .LC_domprefs_email,
1.1284 raeburn 7567: .LC_docs_alias_name,
1.547 albertel 7568: .LC_docs_reinit_warn,
7569: .LC_docs_ext_edit {
7570: font-size: x-small;
7571: }
7572:
1.545 albertel 7573: table.LC_docs_adddocs td,
7574: table.LC_docs_adddocs th {
7575: border: 1px solid #BBBBBB;
7576: padding: 4px;
7577: background: #DDDDDD;
1.543 albertel 7578: }
7579:
1.584 albertel 7580: table.LC_sty_begin {
7581: background: #BBFFBB;
7582: }
1.795 www 7583:
1.584 albertel 7584: table.LC_sty_end {
7585: background: #FFBBBB;
7586: }
7587:
1.589 raeburn 7588: table.LC_double_column {
1.803 bisitz 7589: border-width: 0;
1.589 raeburn 7590: border-collapse: collapse;
7591: width: 100%;
7592: padding: 2px;
7593: }
7594:
7595: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7596: top: 2px;
1.589 raeburn 7597: left: 2px;
7598: width: 47%;
7599: vertical-align: top;
7600: }
7601:
7602: table.LC_double_column tr td.LC_right_col {
7603: top: 2px;
1.779 bisitz 7604: right: 2px;
1.589 raeburn 7605: width: 47%;
7606: vertical-align: top;
7607: }
7608:
1.591 raeburn 7609: div.LC_left_float {
7610: float: left;
7611: padding-right: 5%;
1.597 albertel 7612: padding-bottom: 4px;
1.591 raeburn 7613: }
7614:
7615: div.LC_clear_float_header {
1.597 albertel 7616: padding-bottom: 2px;
1.591 raeburn 7617: }
7618:
7619: div.LC_clear_float_footer {
1.597 albertel 7620: padding-top: 10px;
1.591 raeburn 7621: clear: both;
7622: }
7623:
1.597 albertel 7624: div.LC_grade_show_user {
1.941 bisitz 7625: /* border-left: 5px solid $sidebg; */
7626: border-top: 5px solid #000000;
7627: margin: 50px 0 0 0;
1.936 bisitz 7628: padding: 15px 0 5px 10px;
1.597 albertel 7629: }
1.795 www 7630:
1.936 bisitz 7631: div.LC_grade_show_user_odd_row {
1.941 bisitz 7632: /* border-left: 5px solid #000000; */
7633: }
7634:
7635: div.LC_grade_show_user div.LC_Box {
7636: margin-right: 50px;
1.597 albertel 7637: }
7638:
7639: div.LC_grade_submissions,
7640: div.LC_grade_message_center,
1.936 bisitz 7641: div.LC_grade_info_links {
1.597 albertel 7642: margin: 5px;
7643: width: 99%;
7644: background: #FFFFFF;
7645: }
1.795 www 7646:
1.597 albertel 7647: div.LC_grade_submissions_header,
1.936 bisitz 7648: div.LC_grade_message_center_header {
1.705 tempelho 7649: font-weight: bold;
7650: font-size: large;
1.597 albertel 7651: }
1.795 www 7652:
1.597 albertel 7653: div.LC_grade_submissions_body,
1.936 bisitz 7654: div.LC_grade_message_center_body {
1.597 albertel 7655: border: 1px solid black;
7656: width: 99%;
7657: background: #FFFFFF;
7658: }
1.795 www 7659:
1.613 albertel 7660: table.LC_scantron_action {
7661: width: 100%;
7662: }
1.795 www 7663:
1.613 albertel 7664: table.LC_scantron_action tr th {
1.698 harmsja 7665: font-weight:bold;
7666: font-style:normal;
1.613 albertel 7667: }
1.795 www 7668:
1.779 bisitz 7669: .LC_edit_problem_header,
1.614 albertel 7670: div.LC_edit_problem_footer {
1.705 tempelho 7671: font-weight: normal;
7672: font-size: medium;
1.602 albertel 7673: margin: 2px;
1.1060 bisitz 7674: background-color: $sidebg;
1.600 albertel 7675: }
1.795 www 7676:
1.600 albertel 7677: div.LC_edit_problem_header,
1.602 albertel 7678: div.LC_edit_problem_header div,
1.614 albertel 7679: div.LC_edit_problem_footer,
7680: div.LC_edit_problem_footer div,
1.602 albertel 7681: div.LC_edit_problem_editxml_header,
7682: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7683: z-index: 100;
1.600 albertel 7684: }
1.795 www 7685:
1.600 albertel 7686: div.LC_edit_problem_header_title {
1.705 tempelho 7687: font-weight: bold;
7688: font-size: larger;
1.602 albertel 7689: background: $tabbg;
7690: padding: 3px;
1.1060 bisitz 7691: margin: 0 0 5px 0;
1.602 albertel 7692: }
1.795 www 7693:
1.602 albertel 7694: table.LC_edit_problem_header_title {
7695: width: 100%;
1.600 albertel 7696: background: $tabbg;
1.602 albertel 7697: }
7698:
1.1205 golterma 7699: div.LC_edit_actionbar {
7700: background-color: $sidebg;
1.1218 droeschl 7701: margin: 0;
7702: padding: 0;
7703: line-height: 200%;
1.602 albertel 7704: }
1.795 www 7705:
1.1218 droeschl 7706: div.LC_edit_actionbar div{
7707: padding: 0;
7708: margin: 0;
7709: display: inline-block;
1.600 albertel 7710: }
1.795 www 7711:
1.1124 bisitz 7712: .LC_edit_opt {
7713: padding-left: 1em;
7714: white-space: nowrap;
7715: }
7716:
1.1152 golterma 7717: .LC_edit_problem_latexhelper{
7718: text-align: right;
7719: }
7720:
7721: #LC_edit_problem_colorful div{
7722: margin-left: 40px;
7723: }
7724:
1.1205 golterma 7725: #LC_edit_problem_codemirror div{
7726: margin-left: 0px;
7727: }
7728:
1.911 bisitz 7729: img.stift {
1.803 bisitz 7730: border-width: 0;
7731: vertical-align: middle;
1.677 riegler 7732: }
1.680 riegler 7733:
1.923 bisitz 7734: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7735: vertical-align: top;
1.777 tempelho 7736: }
1.795 www 7737:
1.716 raeburn 7738: div.LC_createcourse {
1.911 bisitz 7739: margin: 10px 10px 10px 10px;
1.716 raeburn 7740: }
7741:
1.917 raeburn 7742: .LC_dccid {
1.1130 raeburn 7743: float: right;
1.917 raeburn 7744: margin: 0.2em 0 0 0;
7745: padding: 0;
7746: font-size: 90%;
7747: display:none;
7748: }
7749:
1.897 wenzelju 7750: ol.LC_primary_menu a:hover,
1.721 harmsja 7751: ol#LC_MenuBreadcrumbs a:hover,
7752: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7753: ul#LC_secondary_menu a:hover,
1.721 harmsja 7754: .LC_FormSectionClearButton input:hover
1.795 www 7755: ul.LC_TabContent li:hover a {
1.952 onken 7756: color:$button_hover;
1.911 bisitz 7757: text-decoration:none;
1.693 droeschl 7758: }
7759:
1.779 bisitz 7760: h1 {
1.911 bisitz 7761: padding: 0;
7762: line-height:130%;
1.693 droeschl 7763: }
1.698 harmsja 7764:
1.911 bisitz 7765: h2,
7766: h3,
7767: h4,
7768: h5,
7769: h6 {
7770: margin: 5px 0 5px 0;
7771: padding: 0;
7772: line-height:130%;
1.693 droeschl 7773: }
1.795 www 7774:
7775: .LC_hcell {
1.911 bisitz 7776: padding:3px 15px 3px 15px;
7777: margin: 0;
7778: background-color:$tabbg;
7779: color:$fontmenu;
7780: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7781: }
1.795 www 7782:
1.840 bisitz 7783: .LC_Box > .LC_hcell {
1.911 bisitz 7784: margin: 0 -10px 10px -10px;
1.835 bisitz 7785: }
7786:
1.721 harmsja 7787: .LC_noBorder {
1.911 bisitz 7788: border: 0;
1.698 harmsja 7789: }
1.693 droeschl 7790:
1.721 harmsja 7791: .LC_FormSectionClearButton input {
1.911 bisitz 7792: background-color:transparent;
7793: border: none;
7794: cursor:pointer;
7795: text-decoration:underline;
1.693 droeschl 7796: }
1.763 bisitz 7797:
7798: .LC_help_open_topic {
1.911 bisitz 7799: color: #FFFFFF;
7800: background-color: #EEEEFF;
7801: margin: 1px;
7802: padding: 4px;
7803: border: 1px solid #000033;
7804: white-space: nowrap;
7805: /* vertical-align: middle; */
1.759 neumanie 7806: }
1.693 droeschl 7807:
1.911 bisitz 7808: dl,
7809: ul,
7810: div,
7811: fieldset {
7812: margin: 10px 10px 10px 0;
7813: /* overflow: hidden; */
1.693 droeschl 7814: }
1.795 www 7815:
1.1211 raeburn 7816: article.geogebraweb div {
7817: margin: 0;
7818: }
7819:
1.838 bisitz 7820: fieldset > legend {
1.911 bisitz 7821: font-weight: bold;
7822: padding: 0 5px 0 5px;
1.838 bisitz 7823: }
7824:
1.813 bisitz 7825: #LC_nav_bar {
1.911 bisitz 7826: float: left;
1.995 raeburn 7827: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7828: margin: 0 0 2px 0;
1.807 droeschl 7829: }
7830:
1.916 droeschl 7831: #LC_realm {
7832: margin: 0.2em 0 0 0;
7833: padding: 0;
7834: font-weight: bold;
7835: text-align: center;
1.995 raeburn 7836: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7837: }
7838:
1.911 bisitz 7839: #LC_nav_bar em {
7840: font-weight: bold;
7841: font-style: normal;
1.807 droeschl 7842: }
7843:
1.897 wenzelju 7844: ol.LC_primary_menu {
1.934 droeschl 7845: margin: 0;
1.1076 raeburn 7846: padding: 0;
1.807 droeschl 7847: }
7848:
1.852 droeschl 7849: ol#LC_PathBreadcrumbs {
1.911 bisitz 7850: margin: 0;
1.693 droeschl 7851: }
7852:
1.897 wenzelju 7853: ol.LC_primary_menu li {
1.1076 raeburn 7854: color: RGB(80, 80, 80);
7855: vertical-align: middle;
7856: text-align: left;
7857: list-style: none;
1.1205 golterma 7858: position: relative;
1.1076 raeburn 7859: float: left;
1.1205 golterma 7860: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7861: line-height: 1.5em;
1.1076 raeburn 7862: }
7863:
1.1205 golterma 7864: ol.LC_primary_menu li a,
7865: ol.LC_primary_menu li p {
1.1076 raeburn 7866: display: block;
7867: margin: 0;
7868: padding: 0 5px 0 10px;
7869: text-decoration: none;
7870: }
7871:
1.1205 golterma 7872: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7873: display: inline-block;
7874: width: 95%;
7875: text-align: left;
7876: }
7877:
7878: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7879: display: inline-block;
7880: width: 5%;
7881: float: right;
7882: text-align: right;
7883: font-size: 70%;
7884: }
7885:
7886: ol.LC_primary_menu ul {
1.1076 raeburn 7887: display: none;
1.1205 golterma 7888: width: 15em;
1.1076 raeburn 7889: background-color: $data_table_light;
1.1205 golterma 7890: position: absolute;
7891: top: 100%;
1.1076 raeburn 7892: }
7893:
1.1205 golterma 7894: ol.LC_primary_menu ul ul {
7895: left: 100%;
7896: top: 0;
7897: }
7898:
7899: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7900: display: block;
7901: position: absolute;
7902: margin: 0;
7903: padding: 0;
1.1078 raeburn 7904: z-index: 2;
1.1076 raeburn 7905: }
7906:
7907: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7908: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7909: font-size: 90%;
1.911 bisitz 7910: vertical-align: top;
1.1076 raeburn 7911: float: none;
1.1079 raeburn 7912: border-left: 1px solid black;
7913: border-right: 1px solid black;
1.1205 golterma 7914: /* A dark bottom border to visualize different menu options;
7915: overwritten in the create_submenu routine for the last border-bottom of the menu */
7916: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7917: }
7918:
1.1205 golterma 7919: ol.LC_primary_menu li li p:hover {
7920: color:$button_hover;
7921: text-decoration:none;
7922: background-color:$data_table_dark;
1.1076 raeburn 7923: }
7924:
7925: ol.LC_primary_menu li li a:hover {
7926: color:$button_hover;
7927: background-color:$data_table_dark;
1.693 droeschl 7928: }
7929:
1.1205 golterma 7930: /* Font-size equal to the size of the predecessors*/
7931: ol.LC_primary_menu li:hover li li {
7932: font-size: 100%;
7933: }
7934:
1.897 wenzelju 7935: ol.LC_primary_menu li img {
1.911 bisitz 7936: vertical-align: bottom;
1.934 droeschl 7937: height: 1.1em;
1.1077 raeburn 7938: margin: 0.2em 0 0 0;
1.693 droeschl 7939: }
7940:
1.897 wenzelju 7941: ol.LC_primary_menu a {
1.911 bisitz 7942: color: RGB(80, 80, 80);
7943: text-decoration: none;
1.693 droeschl 7944: }
1.795 www 7945:
1.949 droeschl 7946: ol.LC_primary_menu a.LC_new_message {
7947: font-weight:bold;
7948: color: darkred;
7949: }
7950:
1.975 raeburn 7951: ol.LC_docs_parameters {
7952: margin-left: 0;
7953: padding: 0;
7954: list-style: none;
7955: }
7956:
7957: ol.LC_docs_parameters li {
7958: margin: 0;
7959: padding-right: 20px;
7960: display: inline;
7961: }
7962:
1.976 raeburn 7963: ol.LC_docs_parameters li:before {
7964: content: "\\002022 \\0020";
7965: }
7966:
7967: li.LC_docs_parameters_title {
7968: font-weight: bold;
7969: }
7970:
7971: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7972: content: "";
7973: }
7974:
1.897 wenzelju 7975: ul#LC_secondary_menu {
1.1107 raeburn 7976: clear: right;
1.911 bisitz 7977: color: $fontmenu;
7978: background: $tabbg;
7979: list-style: none;
7980: padding: 0;
7981: margin: 0;
7982: width: 100%;
1.995 raeburn 7983: text-align: left;
1.1107 raeburn 7984: float: left;
1.808 droeschl 7985: }
7986:
1.897 wenzelju 7987: ul#LC_secondary_menu li {
1.911 bisitz 7988: font-weight: bold;
7989: line-height: 1.8em;
1.1107 raeburn 7990: border-right: 1px solid black;
7991: float: left;
7992: }
7993:
7994: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7995: background-color: $data_table_light;
7996: }
7997:
7998: ul#LC_secondary_menu li a {
1.911 bisitz 7999: padding: 0 0.8em;
1.1107 raeburn 8000: }
8001:
8002: ul#LC_secondary_menu li ul {
8003: display: none;
8004: }
8005:
8006: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8007: display: block;
8008: position: absolute;
8009: margin: 0;
8010: padding: 0;
8011: list-style:none;
8012: float: none;
8013: background-color: $data_table_light;
8014: z-index: 2;
8015: margin-left: -1px;
8016: }
8017:
8018: ul#LC_secondary_menu li ul li {
8019: font-size: 90%;
8020: vertical-align: top;
8021: border-left: 1px solid black;
1.911 bisitz 8022: border-right: 1px solid black;
1.1119 raeburn 8023: background-color: $data_table_light;
1.1107 raeburn 8024: list-style:none;
8025: float: none;
8026: }
8027:
8028: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8029: background-color: $data_table_dark;
1.807 droeschl 8030: }
8031:
1.847 tempelho 8032: ul.LC_TabContent {
1.911 bisitz 8033: display:block;
8034: background: $sidebg;
8035: border-bottom: solid 1px $lg_border_color;
8036: list-style:none;
1.1020 raeburn 8037: margin: -1px -10px 0 -10px;
1.911 bisitz 8038: padding: 0;
1.693 droeschl 8039: }
8040:
1.795 www 8041: ul.LC_TabContent li,
8042: ul.LC_TabContentBigger li {
1.911 bisitz 8043: float:left;
1.741 harmsja 8044: }
1.795 www 8045:
1.897 wenzelju 8046: ul#LC_secondary_menu li a {
1.911 bisitz 8047: color: $fontmenu;
8048: text-decoration: none;
1.693 droeschl 8049: }
1.795 www 8050:
1.721 harmsja 8051: ul.LC_TabContent {
1.952 onken 8052: min-height:20px;
1.721 harmsja 8053: }
1.795 www 8054:
8055: ul.LC_TabContent li {
1.911 bisitz 8056: vertical-align:middle;
1.959 onken 8057: padding: 0 16px 0 10px;
1.911 bisitz 8058: background-color:$tabbg;
8059: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8060: border-left: solid 1px $font;
1.721 harmsja 8061: }
1.795 www 8062:
1.847 tempelho 8063: ul.LC_TabContent .right {
1.911 bisitz 8064: float:right;
1.847 tempelho 8065: }
8066:
1.911 bisitz 8067: ul.LC_TabContent li a,
8068: ul.LC_TabContent li {
8069: color:rgb(47,47,47);
8070: text-decoration:none;
8071: font-size:95%;
8072: font-weight:bold;
1.952 onken 8073: min-height:20px;
8074: }
8075:
1.959 onken 8076: ul.LC_TabContent li a:hover,
8077: ul.LC_TabContent li a:focus {
1.952 onken 8078: color: $button_hover;
1.959 onken 8079: background:none;
8080: outline:none;
1.952 onken 8081: }
8082:
8083: ul.LC_TabContent li:hover {
8084: color: $button_hover;
8085: cursor:pointer;
1.721 harmsja 8086: }
1.795 www 8087:
1.911 bisitz 8088: ul.LC_TabContent li.active {
1.952 onken 8089: color: $font;
1.911 bisitz 8090: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8091: border-bottom:solid 1px #FFFFFF;
8092: cursor: default;
1.744 ehlerst 8093: }
1.795 www 8094:
1.959 onken 8095: ul.LC_TabContent li.active a {
8096: color:$font;
8097: background:#FFFFFF;
8098: outline: none;
8099: }
1.1047 raeburn 8100:
8101: ul.LC_TabContent li.goback {
8102: float: left;
8103: border-left: none;
8104: }
8105:
1.870 tempelho 8106: #maincoursedoc {
1.911 bisitz 8107: clear:both;
1.870 tempelho 8108: }
8109:
8110: ul.LC_TabContentBigger {
1.911 bisitz 8111: display:block;
8112: list-style:none;
8113: padding: 0;
1.870 tempelho 8114: }
8115:
1.795 www 8116: ul.LC_TabContentBigger li {
1.911 bisitz 8117: vertical-align:bottom;
8118: height: 30px;
8119: font-size:110%;
8120: font-weight:bold;
8121: color: #737373;
1.841 tempelho 8122: }
8123:
1.957 onken 8124: ul.LC_TabContentBigger li.active {
8125: position: relative;
8126: top: 1px;
8127: }
8128:
1.870 tempelho 8129: ul.LC_TabContentBigger li a {
1.911 bisitz 8130: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8131: height: 30px;
8132: line-height: 30px;
8133: text-align: center;
8134: display: block;
8135: text-decoration: none;
1.958 onken 8136: outline: none;
1.741 harmsja 8137: }
1.795 www 8138:
1.870 tempelho 8139: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8140: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8141: color:$font;
1.744 ehlerst 8142: }
1.795 www 8143:
1.870 tempelho 8144: ul.LC_TabContentBigger li b {
1.911 bisitz 8145: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8146: display: block;
8147: float: left;
8148: padding: 0 30px;
1.957 onken 8149: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8150: }
8151:
1.956 onken 8152: ul.LC_TabContentBigger li:hover b {
8153: color:$button_hover;
8154: }
8155:
1.870 tempelho 8156: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8157: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8158: color:$font;
1.957 onken 8159: border: 0;
1.741 harmsja 8160: }
1.693 droeschl 8161:
1.870 tempelho 8162:
1.862 bisitz 8163: ul.LC_CourseBreadcrumbs {
8164: background: $sidebg;
1.1020 raeburn 8165: height: 2em;
1.862 bisitz 8166: padding-left: 10px;
1.1020 raeburn 8167: margin: 0;
1.862 bisitz 8168: list-style-position: inside;
8169: }
8170:
1.911 bisitz 8171: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8172: ol#LC_PathBreadcrumbs {
1.911 bisitz 8173: padding-left: 10px;
8174: margin: 0;
1.933 droeschl 8175: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8176: }
8177:
1.911 bisitz 8178: ol#LC_MenuBreadcrumbs li,
8179: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8180: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8181: display: inline;
1.933 droeschl 8182: white-space: normal;
1.693 droeschl 8183: }
8184:
1.823 bisitz 8185: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8186: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8187: text-decoration: none;
8188: font-size:90%;
1.693 droeschl 8189: }
1.795 www 8190:
1.969 droeschl 8191: ol#LC_MenuBreadcrumbs h1 {
8192: display: inline;
8193: font-size: 90%;
8194: line-height: 2.5em;
8195: margin: 0;
8196: padding: 0;
8197: }
8198:
1.795 www 8199: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8200: text-decoration:none;
8201: font-size:100%;
8202: font-weight:bold;
1.693 droeschl 8203: }
1.795 www 8204:
1.840 bisitz 8205: .LC_Box {
1.911 bisitz 8206: border: solid 1px $lg_border_color;
8207: padding: 0 10px 10px 10px;
1.746 neumanie 8208: }
1.795 www 8209:
1.1020 raeburn 8210: .LC_DocsBox {
8211: border: solid 1px $lg_border_color;
8212: padding: 0 0 10px 10px;
8213: }
8214:
1.795 www 8215: .LC_AboutMe_Image {
1.911 bisitz 8216: float:left;
8217: margin-right:10px;
1.747 neumanie 8218: }
1.795 www 8219:
8220: .LC_Clear_AboutMe_Image {
1.911 bisitz 8221: clear:left;
1.747 neumanie 8222: }
1.795 www 8223:
1.721 harmsja 8224: dl.LC_ListStyleClean dt {
1.911 bisitz 8225: padding-right: 5px;
8226: display: table-header-group;
1.693 droeschl 8227: }
8228:
1.721 harmsja 8229: dl.LC_ListStyleClean dd {
1.911 bisitz 8230: display: table-row;
1.693 droeschl 8231: }
8232:
1.721 harmsja 8233: .LC_ListStyleClean,
8234: .LC_ListStyleSimple,
8235: .LC_ListStyleNormal,
1.795 www 8236: .LC_ListStyleSpecial {
1.911 bisitz 8237: /* display:block; */
8238: list-style-position: inside;
8239: list-style-type: none;
8240: overflow: hidden;
8241: padding: 0;
1.693 droeschl 8242: }
8243:
1.721 harmsja 8244: .LC_ListStyleSimple li,
8245: .LC_ListStyleSimple dd,
8246: .LC_ListStyleNormal li,
8247: .LC_ListStyleNormal dd,
8248: .LC_ListStyleSpecial li,
1.795 www 8249: .LC_ListStyleSpecial dd {
1.911 bisitz 8250: margin: 0;
8251: padding: 5px 5px 5px 10px;
8252: clear: both;
1.693 droeschl 8253: }
8254:
1.721 harmsja 8255: .LC_ListStyleClean li,
8256: .LC_ListStyleClean dd {
1.911 bisitz 8257: padding-top: 0;
8258: padding-bottom: 0;
1.693 droeschl 8259: }
8260:
1.721 harmsja 8261: .LC_ListStyleSimple dd,
1.795 www 8262: .LC_ListStyleSimple li {
1.911 bisitz 8263: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8264: }
8265:
1.721 harmsja 8266: .LC_ListStyleSpecial li,
8267: .LC_ListStyleSpecial dd {
1.911 bisitz 8268: list-style-type: none;
8269: background-color: RGB(220, 220, 220);
8270: margin-bottom: 4px;
1.693 droeschl 8271: }
8272:
1.721 harmsja 8273: table.LC_SimpleTable {
1.911 bisitz 8274: margin:5px;
8275: border:solid 1px $lg_border_color;
1.795 www 8276: }
1.693 droeschl 8277:
1.721 harmsja 8278: table.LC_SimpleTable tr {
1.911 bisitz 8279: padding: 0;
8280: border:solid 1px $lg_border_color;
1.693 droeschl 8281: }
1.795 www 8282:
8283: table.LC_SimpleTable thead {
1.911 bisitz 8284: background:rgb(220,220,220);
1.693 droeschl 8285: }
8286:
1.721 harmsja 8287: div.LC_columnSection {
1.911 bisitz 8288: display: block;
8289: clear: both;
8290: overflow: hidden;
8291: margin: 0;
1.693 droeschl 8292: }
8293:
1.721 harmsja 8294: div.LC_columnSection>* {
1.911 bisitz 8295: float: left;
8296: margin: 10px 20px 10px 0;
8297: overflow:hidden;
1.693 droeschl 8298: }
1.721 harmsja 8299:
1.795 www 8300: table em {
1.911 bisitz 8301: font-weight: bold;
8302: font-style: normal;
1.748 schulted 8303: }
1.795 www 8304:
1.779 bisitz 8305: table.LC_tableBrowseRes,
1.795 www 8306: table.LC_tableOfContent {
1.911 bisitz 8307: border:none;
8308: border-spacing: 1px;
8309: padding: 3px;
8310: background-color: #FFFFFF;
8311: font-size: 90%;
1.753 droeschl 8312: }
1.789 droeschl 8313:
1.911 bisitz 8314: table.LC_tableOfContent {
8315: border-collapse: collapse;
1.789 droeschl 8316: }
8317:
1.771 droeschl 8318: table.LC_tableBrowseRes a,
1.768 schulted 8319: table.LC_tableOfContent a {
1.911 bisitz 8320: background-color: transparent;
8321: text-decoration: none;
1.753 droeschl 8322: }
8323:
1.795 www 8324: table.LC_tableOfContent img {
1.911 bisitz 8325: border: none;
8326: height: 1.3em;
8327: vertical-align: text-bottom;
8328: margin-right: 0.3em;
1.753 droeschl 8329: }
1.757 schulted 8330:
1.795 www 8331: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8332: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8333: }
8334:
1.795 www 8335: a#LC_content_toolbar_everything {
1.911 bisitz 8336: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8337: }
8338:
1.795 www 8339: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8340: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8341: }
8342:
1.795 www 8343: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8344: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8345: }
8346:
1.795 www 8347: a#LC_content_toolbar_changefolder {
1.911 bisitz 8348: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8349: }
8350:
1.795 www 8351: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8352: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8353: }
8354:
1.1043 raeburn 8355: a#LC_content_toolbar_edittoplevel {
8356: background-image:url(/res/adm/pages/edittoplevel.gif);
8357: }
8358:
1.795 www 8359: ul#LC_toolbar li a:hover {
1.911 bisitz 8360: background-position: bottom center;
1.757 schulted 8361: }
8362:
1.795 www 8363: ul#LC_toolbar {
1.911 bisitz 8364: padding: 0;
8365: margin: 2px;
8366: list-style:none;
8367: position:relative;
8368: background-color:white;
1.1082 raeburn 8369: overflow: auto;
1.757 schulted 8370: }
8371:
1.795 www 8372: ul#LC_toolbar li {
1.911 bisitz 8373: border:1px solid white;
8374: padding: 0;
8375: margin: 0;
8376: float: left;
8377: display:inline;
8378: vertical-align:middle;
1.1082 raeburn 8379: white-space: nowrap;
1.911 bisitz 8380: }
1.757 schulted 8381:
1.783 amueller 8382:
1.795 www 8383: a.LC_toolbarItem {
1.911 bisitz 8384: display:block;
8385: padding: 0;
8386: margin: 0;
8387: height: 32px;
8388: width: 32px;
8389: color:white;
8390: border: none;
8391: background-repeat:no-repeat;
8392: background-color:transparent;
1.757 schulted 8393: }
8394:
1.915 droeschl 8395: ul.LC_funclist {
8396: margin: 0;
8397: padding: 0.5em 1em 0.5em 0;
8398: }
8399:
1.933 droeschl 8400: ul.LC_funclist > li:first-child {
8401: font-weight:bold;
8402: margin-left:0.8em;
8403: }
8404:
1.915 droeschl 8405: ul.LC_funclist + ul.LC_funclist {
8406: /*
8407: left border as a seperator if we have more than
8408: one list
8409: */
8410: border-left: 1px solid $sidebg;
8411: /*
8412: this hides the left border behind the border of the
8413: outer box if element is wrapped to the next 'line'
8414: */
8415: margin-left: -1px;
8416: }
8417:
1.843 bisitz 8418: ul.LC_funclist li {
1.915 droeschl 8419: display: inline;
1.782 bisitz 8420: white-space: nowrap;
1.915 droeschl 8421: margin: 0 0 0 25px;
8422: line-height: 150%;
1.782 bisitz 8423: }
8424:
1.974 wenzelju 8425: .LC_hidden {
8426: display: none;
8427: }
8428:
1.1030 www 8429: .LCmodal-overlay {
8430: position:fixed;
8431: top:0;
8432: right:0;
8433: bottom:0;
8434: left:0;
8435: height:100%;
8436: width:100%;
8437: margin:0;
8438: padding:0;
8439: background:#999;
8440: opacity:.75;
8441: filter: alpha(opacity=75);
8442: -moz-opacity: 0.75;
8443: z-index:101;
8444: }
8445:
8446: * html .LCmodal-overlay {
8447: position: absolute;
8448: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8449: }
8450:
8451: .LCmodal-window {
8452: position:fixed;
8453: top:50%;
8454: left:50%;
8455: margin:0;
8456: padding:0;
8457: z-index:102;
8458: }
8459:
8460: * html .LCmodal-window {
8461: position:absolute;
8462: }
8463:
8464: .LCclose-window {
8465: position:absolute;
8466: width:32px;
8467: height:32px;
8468: right:8px;
8469: top:8px;
8470: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8471: text-indent:-99999px;
8472: overflow:hidden;
8473: cursor:pointer;
8474: }
8475:
1.1369 raeburn 8476: .LCisDisabled {
8477: cursor: not-allowed;
8478: opacity: 0.5;
8479: }
8480:
8481: a[aria-disabled="true"] {
8482: color: currentColor;
8483: display: inline-block; /* For IE11/ MS Edge bug */
8484: pointer-events: none;
8485: text-decoration: none;
8486: }
8487:
1.1335 raeburn 8488: pre.LC_wordwrap {
8489: white-space: pre-wrap;
8490: white-space: -moz-pre-wrap;
8491: white-space: -pre-wrap;
8492: white-space: -o-pre-wrap;
8493: word-wrap: break-word;
8494: }
8495:
1.1100 raeburn 8496: /*
1.1231 damieng 8497: styles used for response display
8498: */
8499: div.LC_radiofoil, div.LC_rankfoil {
8500: margin: .5em 0em .5em 0em;
8501: }
8502: table.LC_itemgroup {
8503: margin-top: 1em;
8504: }
8505:
8506: /*
1.1100 raeburn 8507: styles used by TTH when "Default set of options to pass to tth/m
8508: when converting TeX" in course settings has been set
8509:
8510: option passed: -t
8511:
8512: */
8513:
8514: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8515: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8516: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8517: td div.norm {line-height:normal;}
8518:
8519: /*
8520: option passed -y3
8521: */
8522:
8523: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8524: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8525: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8526:
1.1230 damieng 8527: /*
8528: sections with roles, for content only
8529: */
8530: section[class^="role-"] {
8531: padding-left: 10px;
8532: padding-right: 5px;
8533: margin-top: 8px;
8534: margin-bottom: 8px;
8535: border: 1px solid #2A4;
8536: border-radius: 5px;
8537: box-shadow: 0px 1px 1px #BBB;
8538: }
8539: section[class^="role-"]>h1 {
8540: position: relative;
8541: margin: 0px;
8542: padding-top: 10px;
8543: padding-left: 40px;
8544: }
8545: section[class^="role-"]>h1:before {
8546: position: absolute;
8547: left: -5px;
8548: top: 5px;
8549: }
8550: section.role-activity>h1:before {
8551: content:url('/adm/daxe/images/section_icons/activity.png');
8552: }
8553: section.role-advice>h1:before {
8554: content:url('/adm/daxe/images/section_icons/advice.png');
8555: }
8556: section.role-bibliography>h1:before {
8557: content:url('/adm/daxe/images/section_icons/bibliography.png');
8558: }
8559: section.role-citation>h1:before {
8560: content:url('/adm/daxe/images/section_icons/citation.png');
8561: }
8562: section.role-conclusion>h1:before {
8563: content:url('/adm/daxe/images/section_icons/conclusion.png');
8564: }
8565: section.role-definition>h1:before {
8566: content:url('/adm/daxe/images/section_icons/definition.png');
8567: }
8568: section.role-demonstration>h1:before {
8569: content:url('/adm/daxe/images/section_icons/demonstration.png');
8570: }
8571: section.role-example>h1:before {
8572: content:url('/adm/daxe/images/section_icons/example.png');
8573: }
8574: section.role-explanation>h1:before {
8575: content:url('/adm/daxe/images/section_icons/explanation.png');
8576: }
8577: section.role-introduction>h1:before {
8578: content:url('/adm/daxe/images/section_icons/introduction.png');
8579: }
8580: section.role-method>h1:before {
8581: content:url('/adm/daxe/images/section_icons/method.png');
8582: }
8583: section.role-more_information>h1:before {
8584: content:url('/adm/daxe/images/section_icons/more_information.png');
8585: }
8586: section.role-objectives>h1:before {
8587: content:url('/adm/daxe/images/section_icons/objectives.png');
8588: }
8589: section.role-prerequisites>h1:before {
8590: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8591: }
8592: section.role-remark>h1:before {
8593: content:url('/adm/daxe/images/section_icons/remark.png');
8594: }
8595: section.role-reminder>h1:before {
8596: content:url('/adm/daxe/images/section_icons/reminder.png');
8597: }
8598: section.role-summary>h1:before {
8599: content:url('/adm/daxe/images/section_icons/summary.png');
8600: }
8601: section.role-syntax>h1:before {
8602: content:url('/adm/daxe/images/section_icons/syntax.png');
8603: }
8604: section.role-warning>h1:before {
8605: content:url('/adm/daxe/images/section_icons/warning.png');
8606: }
8607:
1.1269 raeburn 8608: #LC_minitab_header {
8609: float:left;
8610: width:100%;
8611: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8612: font-size:93%;
8613: line-height:normal;
8614: margin: 0.5em 0 0.5em 0;
8615: }
8616: #LC_minitab_header ul {
8617: margin:0;
8618: padding:10px 10px 0;
8619: list-style:none;
8620: }
8621: #LC_minitab_header li {
8622: float:left;
8623: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8624: margin:0;
8625: padding:0 0 0 9px;
8626: }
8627: #LC_minitab_header a {
8628: display:block;
8629: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8630: padding:5px 15px 4px 6px;
8631: }
8632: #LC_minitab_header #LC_current_minitab {
8633: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8634: }
8635: #LC_minitab_header #LC_current_minitab a {
8636: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8637: padding-bottom:5px;
8638: }
8639:
8640:
1.343 albertel 8641: END
8642: }
8643:
1.306 albertel 8644: =pod
8645:
8646: =item * &headtag()
8647:
8648: Returns a uniform footer for LON-CAPA web pages.
8649:
1.307 albertel 8650: Inputs: $title - optional title for the head
8651: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8652: $args - optional arguments
1.319 albertel 8653: force_register - if is true call registerurl so the remote is
8654: informed
1.415 albertel 8655: redirect -> array ref of
8656: 1- seconds before redirect occurs
8657: 2- url to redirect to
8658: 3- whether the side effect should occur
1.315 albertel 8659: (side effect of setting
8660: $env{'internal.head.redirect'} to the url
8661: redirected too)
1.352 albertel 8662: domain -> force to color decorate a page for a specific
8663: domain
8664: function -> force usage of a specific rolish color scheme
8665: bgcolor -> override the default page bgcolor
1.460 albertel 8666: no_auto_mt_title
8667: -> prevent &mt()ing the title arg
1.464 albertel 8668:
1.306 albertel 8669: =cut
8670:
8671: sub headtag {
1.313 albertel 8672: my ($title,$head_extra,$args) = @_;
1.306 albertel 8673:
1.363 albertel 8674: my $function = $args->{'function'} || &get_users_function();
8675: my $domain = $args->{'domain'} || &determinedomain();
8676: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8677: my $httphost = $args->{'use_absolute'};
1.418 albertel 8678: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8679: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8680: #time(),
1.418 albertel 8681: $env{'environment.color.timestamp'},
1.363 albertel 8682: $function,$domain,$bgcolor);
8683:
1.369 www 8684: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8685:
1.308 albertel 8686: my $result =
8687: '<head>'.
1.1160 raeburn 8688: &font_settings($args);
1.319 albertel 8689:
1.1188 raeburn 8690: my $inhibitprint;
8691: if ($args->{'print_suppress'}) {
8692: $inhibitprint = &print_suppression();
8693: }
1.1064 raeburn 8694:
1.461 albertel 8695: if (!$args->{'frameset'}) {
8696: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8697: }
1.962 droeschl 8698: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8699: $result .= Apache::lonxml::display_title();
1.319 albertel 8700: }
1.436 albertel 8701: if (!$args->{'no_nav_bar'}
8702: && !$args->{'only_body'}
8703: && !$args->{'frameset'}) {
1.1154 raeburn 8704: $result .= &help_menu_js($httphost);
1.1032 www 8705: $result.=&modal_window();
1.1038 www 8706: $result.=&togglebox_script();
1.1034 www 8707: $result.=&wishlist_window();
1.1041 www 8708: $result.=&LCprogressbarUpdate_script();
1.1034 www 8709: } else {
8710: if ($args->{'add_modal'}) {
8711: $result.=&modal_window();
8712: }
8713: if ($args->{'add_wishlist'}) {
8714: $result.=&wishlist_window();
8715: }
1.1038 www 8716: if ($args->{'add_togglebox'}) {
8717: $result.=&togglebox_script();
8718: }
1.1041 www 8719: if ($args->{'add_progressbar'}) {
8720: $result.=&LCprogressbarUpdate_script();
8721: }
1.436 albertel 8722: }
1.314 albertel 8723: if (ref($args->{'redirect'})) {
1.414 albertel 8724: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8725: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8726: if (!$inhibit_continue) {
8727: $env{'internal.head.redirect'} = $url;
8728: }
1.313 albertel 8729: $result.=<<ADDMETA
8730: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8731: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8732: ADDMETA
1.1210 raeburn 8733: } else {
8734: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8735: my $requrl = $env{'request.uri'};
8736: if ($requrl eq '') {
8737: $requrl = $ENV{'REQUEST_URI'};
8738: $requrl =~ s/\?.+$//;
8739: }
8740: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8741: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8742: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8743: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8744: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8745: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8746: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8747: my ($offload,$offloadoth);
1.1210 raeburn 8748: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8749: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8750: $offload = 1;
1.1353 raeburn 8751: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8752: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8753: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8754: $offloadoth = 1;
8755: $dom_in_use = $env{'user.domain'};
8756: }
8757: }
1.1340 raeburn 8758: }
8759: }
8760: unless ($offload) {
8761: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8762: if ($domdefs{'offloadoth'}{$lonhost}) {
8763: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8764: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8765: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8766: $offload = 1;
1.1352 raeburn 8767: $offloadoth = 1;
1.1340 raeburn 8768: $dom_in_use = $env{'user.domain'};
8769: }
1.1210 raeburn 8770: }
1.1340 raeburn 8771: }
8772: }
8773: }
8774: if ($offload) {
1.1358 raeburn 8775: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 8776: if (($newserver eq '') && ($offloadoth)) {
8777: my @domains = &Apache::lonnet::current_machine_domains();
8778: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8779: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8780: }
8781: }
1.1340 raeburn 8782: if (($newserver) && ($newserver ne $lonhost)) {
8783: my $numsec = 5;
8784: my $timeout = $numsec * 1000;
8785: my ($newurl,$locknum,%locks,$msg);
8786: if ($env{'request.role.adv'}) {
8787: ($locknum,%locks) = &Apache::lonnet::get_locks();
8788: }
8789: my $disable_submit = 0;
8790: if ($requrl =~ /$LONCAPA::assess_re/) {
8791: $disable_submit = 1;
8792: }
8793: if ($locknum) {
8794: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8795: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8796: join(", ",sort(values(%locks)))."\n";
8797: if (&show_course()) {
8798: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8799: } else {
8800: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8801: }
1.1340 raeburn 8802: } else {
8803: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8804: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8805: }
8806: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8807: $newurl = '/adm/switchserver?otherserver='.$newserver;
8808: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8809: $newurl .= '&role='.$env{'request.role'};
8810: }
8811: if ($env{'request.symb'}) {
8812: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8813: if ($shownsymb =~ m{^/enc/}) {
8814: my $reqdmajor = 2;
8815: my $reqdminor = 11;
8816: my $reqdsubminor = 3;
8817: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8818: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8819: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8820: if (($major eq '' && $minor eq '') ||
8821: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8822: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8823: ($reqdsubminor > $subminor))))) {
8824: undef($shownsymb);
8825: }
1.1210 raeburn 8826: }
1.1340 raeburn 8827: if ($shownsymb) {
8828: &js_escape(\$shownsymb);
8829: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8830: }
1.1340 raeburn 8831: } else {
8832: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8833: &js_escape(\$shownurl);
8834: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8835: }
1.1340 raeburn 8836: }
8837: &js_escape(\$msg);
8838: $result.=<<OFFLOAD
1.1210 raeburn 8839: <meta http-equiv="pragma" content="no-cache" />
8840: <script type="text/javascript">
1.1215 raeburn 8841: // <![CDATA[
1.1210 raeburn 8842: function LC_Offload_Now() {
8843: var dest = "$newurl";
8844: if (dest != '') {
8845: window.location.href="$newurl";
8846: }
8847: }
1.1214 raeburn 8848: \$(document).ready(function () {
8849: window.alert('$msg');
8850: if ($disable_submit) {
1.1210 raeburn 8851: \$(".LC_hwk_submit").prop("disabled", true);
8852: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8853: }
8854: setTimeout('LC_Offload_Now()', $timeout);
8855: });
1.1215 raeburn 8856: // ]]>
1.1210 raeburn 8857: </script>
8858: OFFLOAD
8859: }
8860: }
8861: }
8862: }
8863: }
1.313 albertel 8864: }
1.306 albertel 8865: if (!defined($title)) {
8866: $title = 'The LearningOnline Network with CAPA';
8867: }
1.460 albertel 8868: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8869: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8870: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8871: if (!$args->{'frameset'}) {
8872: $result .= ' /';
8873: }
8874: $result .= '>'
1.1064 raeburn 8875: .$inhibitprint
1.414 albertel 8876: .$head_extra;
1.1242 raeburn 8877: my $clientmobile;
8878: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8879: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8880: } else {
8881: $clientmobile = $env{'browser.mobile'};
8882: }
8883: if ($clientmobile) {
1.1137 raeburn 8884: $result .= '
8885: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8886: <meta name="apple-mobile-web-app-capable" content="yes" />';
8887: }
1.1278 raeburn 8888: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8889: return $result.'</head>';
1.306 albertel 8890: }
8891:
8892: =pod
8893:
1.340 albertel 8894: =item * &font_settings()
8895:
8896: Returns neccessary <meta> to set the proper encoding
8897:
1.1160 raeburn 8898: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8899:
8900: =cut
8901:
8902: sub font_settings {
1.1160 raeburn 8903: my ($args) = @_;
1.340 albertel 8904: my $headerstring='';
1.1160 raeburn 8905: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8906: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8907: $headerstring.=
8908: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8909: if (!$args->{'frameset'}) {
8910: $headerstring.= ' /';
8911: }
8912: $headerstring .= '>'."\n";
1.340 albertel 8913: }
8914: return $headerstring;
8915: }
8916:
1.341 albertel 8917: =pod
8918:
1.1064 raeburn 8919: =item * &print_suppression()
8920:
8921: In course context returns css which causes the body to be blank when media="print",
8922: if printout generation is unavailable for the current resource.
8923:
8924: This could be because:
8925:
8926: (a) printstartdate is in the future
8927:
8928: (b) printenddate is in the past
8929:
8930: (c) there is an active exam block with "printout"
8931: functionality blocked
8932:
8933: Users with pav, pfo or evb privileges are exempt.
8934:
8935: Inputs: none
8936:
8937: =cut
8938:
8939:
8940: sub print_suppression {
8941: my $noprint;
8942: if ($env{'request.course.id'}) {
8943: my $scope = $env{'request.course.id'};
8944: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8945: (&Apache::lonnet::allowed('pfo',$scope))) {
8946: return;
8947: }
8948: if ($env{'request.course.sec'} ne '') {
8949: $scope .= "/$env{'request.course.sec'}";
8950: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8951: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8952: return;
1.1064 raeburn 8953: }
8954: }
8955: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8956: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 8957: my $clientip = &Apache::lonnet::get_requestor_ip();
8958: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8959: if ($blocked) {
8960: my $checkrole = "cm./$cdom/$cnum";
8961: if ($env{'request.course.sec'} ne '') {
8962: $checkrole .= "/$env{'request.course.sec'}";
8963: }
8964: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8965: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8966: $noprint = 1;
8967: }
8968: }
8969: unless ($noprint) {
8970: my $symb = &Apache::lonnet::symbread();
8971: if ($symb ne '') {
8972: my $navmap = Apache::lonnavmaps::navmap->new();
8973: if (ref($navmap)) {
8974: my $res = $navmap->getBySymb($symb);
8975: if (ref($res)) {
8976: if (!$res->resprintable()) {
8977: $noprint = 1;
8978: }
8979: }
8980: }
8981: }
8982: }
8983: if ($noprint) {
8984: return <<"ENDSTYLE";
8985: <style type="text/css" media="print">
8986: body { display:none }
8987: </style>
8988: ENDSTYLE
8989: }
8990: }
8991: return;
8992: }
8993:
8994: =pod
8995:
1.341 albertel 8996: =item * &xml_begin()
8997:
8998: Returns the needed doctype and <html>
8999:
9000: Inputs: none
9001:
9002: =cut
9003:
9004: sub xml_begin {
1.1168 raeburn 9005: my ($is_frameset) = @_;
1.341 albertel 9006: my $output='';
9007:
9008: if ($env{'browser.mathml'}) {
9009: $output='<?xml version="1.0"?>'
9010: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9011: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9012:
9013: # .'<!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">] >'
9014: .'<!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">'
9015: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9016: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9017: } elsif ($is_frameset) {
9018: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9019: '<html>'."\n";
1.341 albertel 9020: } else {
1.1168 raeburn 9021: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9022: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9023: }
9024: return $output;
9025: }
1.340 albertel 9026:
9027: =pod
9028:
1.306 albertel 9029: =item * &start_page()
9030:
9031: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9032:
1.648 raeburn 9033: Inputs:
9034:
9035: =over 4
9036:
9037: $title - optional title for the page
9038:
9039: $head_extra - optional extra HTML to incude inside the <head>
9040:
9041: $args - additional optional args supported are:
9042:
9043: =over 8
9044:
9045: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9046: arg on
1.814 bisitz 9047: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9048: add_entries -> additional attributes to add to the <body>
9049: domain -> force to color decorate a page for a
1.317 albertel 9050: specific domain
1.648 raeburn 9051: function -> force usage of a specific rolish color
1.317 albertel 9052: scheme
1.648 raeburn 9053: redirect -> see &headtag()
9054: bgcolor -> override the default page bg color
9055: js_ready -> return a string ready for being used in
1.317 albertel 9056: a javascript writeln
1.648 raeburn 9057: html_encode -> return a string ready for being used in
1.320 albertel 9058: a html attribute
1.648 raeburn 9059: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9060: $forcereg arg
1.648 raeburn 9061: frameset -> if true will start with a <frameset>
1.330 albertel 9062: rather than <body>
1.648 raeburn 9063: skip_phases -> hash ref of
1.338 albertel 9064: head -> skip the <html><head> generation
9065: body -> skip all <body> generation
1.648 raeburn 9066: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9067: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9068: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9069: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9070: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9071: group -> includes the current group, if page is for a
1.1274 raeburn 9072: specific group
9073: use_absolute -> for request for external resource or syllabus, this
9074: will contain https://<hostname> if server uses
9075: https (as per hosts.tab), but request is for http
9076: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9077: links_disabled -> Links in primary and secondary menus are disabled
9078: (Can enable them once page has loaded - see lonroles.pm
9079: for an example).
1.361 albertel 9080:
1.648 raeburn 9081: =back
1.460 albertel 9082:
1.648 raeburn 9083: =back
1.562 albertel 9084:
1.306 albertel 9085: =cut
9086:
9087: sub start_page {
1.309 albertel 9088: my ($title,$head_extra,$args) = @_;
1.318 albertel 9089: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9090:
1.315 albertel 9091: $env{'internal.start_page'}++;
1.1359 raeburn 9092: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9093:
1.338 albertel 9094: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9095: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9096: }
1.1316 raeburn 9097:
9098: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9099: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9100: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9101: $args->{'no_primary_menu'} = 1;
9102: }
9103: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9104: $args->{'no_inline_menu'} = 1;
9105: }
9106: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9107: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9108: }
9109: } else {
9110: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9111: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9112: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9113: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9114: $args->{'no_primary_menu'} = 1;
9115: }
9116: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9117: $args->{'no_inline_menu'} = 1;
9118: }
9119: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9120: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9121: }
9122: }
9123: }
1.1316 raeburn 9124: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9125: $env{'course.'.$env{'request.course.id'}.'.domain'},
9126: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9127: } elsif ($env{'request.course.id'}) {
9128: my $expiretime=600;
9129: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9130: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9131: }
9132: my ($deeplinkmenu,$menuref);
9133: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9134: if ($menucoll) {
9135: if (ref($menuref) eq 'HASH') {
9136: %menu = %{$menuref};
9137: }
9138: if ($menu{'top'} eq 'n') {
9139: $args->{'no_primary_menu'} = 1;
9140: }
9141: if ($menu{'inline'} eq 'n') {
9142: unless (&Apache::lonnet::allowed('opa')) {
9143: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9144: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9145: my $crstype = &course_type();
9146: my $now = time;
9147: my $ccrole;
9148: if ($crstype eq 'Community') {
9149: $ccrole = 'co';
9150: } else {
9151: $ccrole = 'cc';
9152: }
9153: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9154: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9155: if ((($start) && ($start<0)) ||
9156: (($end) && ($end<$now)) ||
9157: (($start) && ($now<$start))) {
9158: $args->{'no_inline_menu'} = 1;
9159: }
9160: } else {
9161: $args->{'no_inline_menu'} = 1;
9162: }
9163: }
9164: }
9165: }
1.1316 raeburn 9166: }
1.1359 raeburn 9167:
1.338 albertel 9168: if (! exists($args->{'skip_phases'}{'body'}) ) {
9169: if ($args->{'frameset'}) {
9170: my $attr_string = &make_attr_string($args->{'force_register'},
9171: $args->{'add_entries'});
9172: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9173: } else {
9174: $result .=
9175: &bodytag($title,
9176: $args->{'function'}, $args->{'add_entries'},
9177: $args->{'only_body'}, $args->{'domain'},
9178: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9179: $args->{'bgcolor'}, $args,
1.1359 raeburn 9180: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu);
1.831 bisitz 9181: }
1.330 albertel 9182: }
1.338 albertel 9183:
1.315 albertel 9184: if ($args->{'js_ready'}) {
1.713 kaisler 9185: $result = &js_ready($result);
1.315 albertel 9186: }
1.320 albertel 9187: if ($args->{'html_encode'}) {
1.713 kaisler 9188: $result = &html_encode($result);
9189: }
9190:
1.813 bisitz 9191: # Preparation for new and consistent functionlist at top of screen
9192: # if ($args->{'functionlist'}) {
9193: # $result .= &build_functionlist();
9194: #}
9195:
1.964 droeschl 9196: # Don't add anything more if only_body wanted or in const space
9197: return $result if $args->{'only_body'}
9198: || $env{'request.state'} eq 'construct';
1.813 bisitz 9199:
9200: #Breadcrumbs
1.758 kaisler 9201: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9202: &Apache::lonhtmlcommon::clear_breadcrumbs();
9203: #if any br links exists, add them to the breadcrumbs
9204: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9205: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9206: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9207: }
9208: }
1.1096 raeburn 9209: # if @advtools array contains items add then to the breadcrumbs
9210: if (@advtools > 0) {
9211: &Apache::lonmenu::advtools_crumbs(@advtools);
9212: }
1.1272 raeburn 9213: my $menulink;
9214: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9215: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9216: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9217: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9218: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9219: (!$env{'request.role.adv'}))) {
9220: $menulink = 0;
9221: } else {
9222: undef($menulink);
9223: }
1.758 kaisler 9224: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9225: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9226: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9227: } else {
1.1272 raeburn 9228: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9229: }
1.320 albertel 9230: }
1.315 albertel 9231: return $result;
1.306 albertel 9232: }
9233:
9234: sub end_page {
1.315 albertel 9235: my ($args) = @_;
9236: $env{'internal.end_page'}++;
1.330 albertel 9237: my $result;
1.335 albertel 9238: if ($args->{'discussion'}) {
9239: my ($target,$parser);
9240: if (ref($args->{'discussion'})) {
9241: ($target,$parser) =($args->{'discussion'}{'target'},
9242: $args->{'discussion'}{'parser'});
9243: }
9244: $result .= &Apache::lonxml::xmlend($target,$parser);
9245: }
1.330 albertel 9246: if ($args->{'frameset'}) {
9247: $result .= '</frameset>';
9248: } else {
1.635 raeburn 9249: $result .= &endbodytag($args);
1.330 albertel 9250: }
1.1080 raeburn 9251: unless ($args->{'notbody'}) {
9252: $result .= "\n</html>";
9253: }
1.330 albertel 9254:
1.315 albertel 9255: if ($args->{'js_ready'}) {
1.317 albertel 9256: $result = &js_ready($result);
1.315 albertel 9257: }
1.335 albertel 9258:
1.320 albertel 9259: if ($args->{'html_encode'}) {
9260: $result = &html_encode($result);
9261: }
1.335 albertel 9262:
1.315 albertel 9263: return $result;
9264: }
9265:
1.1359 raeburn 9266: sub menucoll_in_effect {
9267: my ($menucoll,$deeplinkmenu,%menu);
9268: if ($env{'request.course.id'}) {
9269: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9270: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9271: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9272: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9273: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9274: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9275: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9276: my $navmap = Apache::lonnavmaps::navmap->new();
9277: if (ref($navmap)) {
9278: $deeplink = $navmap->get_mapparam(undef,
9279: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9280: '0.deeplink');
1.1370 raeburn 9281: } else {
9282: $check_login_symb = 1;
1.1362 raeburn 9283: }
9284: } else {
1.1370 raeburn 9285: my $symb = &Apache::lonnet::symbread();
9286: if ($symb) {
9287: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9288: } else {
9289: $check_login_symb = 1;
9290: }
1.1362 raeburn 9291: }
9292: } else {
1.1370 raeburn 9293: $check_login_symb = 1;
9294: }
9295: if ($check_login_symb) {
1.1362 raeburn 9296: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9297: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9298: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9299: my $navmap = Apache::lonnavmaps::navmap->new();
9300: if (ref($navmap)) {
9301: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9302: }
9303: } else {
9304: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9305: }
9306: }
1.1359 raeburn 9307: if ($deeplink ne '') {
1.1363 raeburn 9308: my ($state,$others,$listed,$scope,$protect,$display) = split(/,/,$deeplink);
1.1359 raeburn 9309: if ($display =~ /^\d+$/) {
9310: $deeplinkmenu = 1;
9311: $menucoll = $display;
9312: }
9313: }
9314: }
9315: if ($menucoll) {
9316: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9317: }
9318: }
9319: return ($menucoll,$deeplinkmenu,\%menu);
9320: }
9321:
1.1362 raeburn 9322: sub deeplink_login_symb {
9323: my ($cnum,$cdom) = @_;
9324: my $login_symb;
9325: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9326: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9327: }
9328: return $login_symb;
9329: }
9330:
9331: sub symb_from_tinyurl {
9332: my ($url,$cnum,$cdom) = @_;
9333: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9334: my $key = $1;
9335: my ($tinyurl,$login);
9336: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9337: if (defined($cached)) {
9338: $tinyurl = $result;
9339: } else {
9340: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9341: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9342: if ($currtiny{$key} ne '') {
9343: $tinyurl = $currtiny{$key};
9344: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9345: }
1.1364 raeburn 9346: }
9347: if ($tinyurl ne '') {
9348: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9349: if (wantarray) {
9350: return ($cnumreq,$symb);
9351: } elsif ($cnumreq eq $cnum) {
9352: return $symb;
1.1362 raeburn 9353: }
9354: }
9355: }
1.1364 raeburn 9356: if (wantarray) {
9357: return ();
9358: } else {
9359: return;
9360: }
1.1362 raeburn 9361: }
9362:
1.1034 www 9363: sub wishlist_window {
9364: return(<<'ENDWISHLIST');
1.1046 raeburn 9365: <script type="text/javascript">
1.1034 www 9366: // <![CDATA[
9367: // <!-- BEGIN LON-CAPA Internal
9368: function set_wishlistlink(title, path) {
9369: if (!title) {
9370: title = document.title;
9371: title = title.replace(/^LON-CAPA /,'');
9372: }
1.1175 raeburn 9373: title = encodeURIComponent(title);
1.1203 raeburn 9374: title = title.replace("'","\\\'");
1.1034 www 9375: if (!path) {
9376: path = location.pathname;
9377: }
1.1175 raeburn 9378: path = encodeURIComponent(path);
1.1203 raeburn 9379: path = path.replace("'","\\\'");
1.1034 www 9380: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9381: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9382: }
9383: // END LON-CAPA Internal -->
9384: // ]]>
9385: </script>
9386: ENDWISHLIST
9387: }
9388:
1.1030 www 9389: sub modal_window {
9390: return(<<'ENDMODAL');
1.1046 raeburn 9391: <script type="text/javascript">
1.1030 www 9392: // <![CDATA[
9393: // <!-- BEGIN LON-CAPA Internal
9394: var modalWindow = {
9395: parent:"body",
9396: windowId:null,
9397: content:null,
9398: width:null,
9399: height:null,
9400: close:function()
9401: {
9402: $(".LCmodal-window").remove();
9403: $(".LCmodal-overlay").remove();
9404: },
9405: open:function()
9406: {
9407: var modal = "";
9408: modal += "<div class=\"LCmodal-overlay\"></div>";
9409: 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;\">";
9410: modal += this.content;
9411: modal += "</div>";
9412:
9413: $(this.parent).append(modal);
9414:
9415: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9416: $(".LCclose-window").click(function(){modalWindow.close();});
9417: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9418: }
9419: };
1.1140 raeburn 9420: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9421: {
1.1266 raeburn 9422: source = source.replace(/'/g,"'");
1.1030 www 9423: modalWindow.windowId = "myModal";
9424: modalWindow.width = width;
9425: modalWindow.height = height;
1.1196 raeburn 9426: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9427: modalWindow.open();
1.1208 raeburn 9428: };
1.1030 www 9429: // END LON-CAPA Internal -->
9430: // ]]>
9431: </script>
9432: ENDMODAL
9433: }
9434:
9435: sub modal_link {
1.1140 raeburn 9436: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9437: unless ($width) { $width=480; }
9438: unless ($height) { $height=400; }
1.1031 www 9439: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9440: unless ($transparency) { $transparency='true'; }
9441:
1.1074 raeburn 9442: my $target_attr;
9443: if (defined($target)) {
9444: $target_attr = 'target="'.$target.'"';
9445: }
9446: return <<"ENDLINK";
1.1336 raeburn 9447: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9448: ENDLINK
1.1030 www 9449: }
9450:
1.1032 www 9451: sub modal_adhoc_script {
1.1365 raeburn 9452: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9453: my $mathjax;
9454: if ($possmathjax) {
9455: $mathjax = <<'ENDJAX';
9456: if (typeof MathJax == 'object') {
9457: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9458: }
9459: ENDJAX
9460: }
1.1032 www 9461: return (<<ENDADHOC);
1.1046 raeburn 9462: <script type="text/javascript">
1.1032 www 9463: // <![CDATA[
9464: var $funcname = function()
9465: {
9466: modalWindow.windowId = "myModal";
9467: modalWindow.width = $width;
9468: modalWindow.height = $height;
9469: modalWindow.content = '$content';
9470: modalWindow.open();
1.1365 raeburn 9471: $mathjax
1.1032 www 9472: };
9473: // ]]>
9474: </script>
9475: ENDADHOC
9476: }
9477:
1.1041 www 9478: sub modal_adhoc_inner {
1.1365 raeburn 9479: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9480: my $innerwidth=$width-20;
9481: $content=&js_ready(
1.1140 raeburn 9482: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9483: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9484: $content.
1.1041 www 9485: &end_scrollbox().
1.1140 raeburn 9486: &end_page()
1.1041 www 9487: );
1.1365 raeburn 9488: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9489: }
9490:
9491: sub modal_adhoc_window {
1.1365 raeburn 9492: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9493: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9494: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9495: }
9496:
9497: sub modal_adhoc_launch {
9498: my ($funcname,$width,$height,$content)=@_;
9499: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9500: <script type="text/javascript">
9501: // <![CDATA[
9502: $funcname();
9503: // ]]>
9504: </script>
9505: ENDLAUNCH
9506: }
9507:
9508: sub modal_adhoc_close {
9509: return (<<ENDCLOSE);
9510: <script type="text/javascript">
9511: // <![CDATA[
9512: modalWindow.close();
9513: // ]]>
9514: </script>
9515: ENDCLOSE
9516: }
9517:
1.1038 www 9518: sub togglebox_script {
9519: return(<<ENDTOGGLE);
9520: <script type="text/javascript">
9521: // <![CDATA[
9522: function LCtoggleDisplay(id,hidetext,showtext) {
9523: link = document.getElementById(id + "link").childNodes[0];
9524: with (document.getElementById(id).style) {
9525: if (display == "none" ) {
9526: display = "inline";
9527: link.nodeValue = hidetext;
9528: } else {
9529: display = "none";
9530: link.nodeValue = showtext;
9531: }
9532: }
9533: }
9534: // ]]>
9535: </script>
9536: ENDTOGGLE
9537: }
9538:
1.1039 www 9539: sub start_togglebox {
9540: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9541: unless ($heading) { $heading=''; } else { $heading.=' '; }
9542: unless ($showtext) { $showtext=&mt('show'); }
9543: unless ($hidetext) { $hidetext=&mt('hide'); }
9544: unless ($headerbg) { $headerbg='#FFFFFF'; }
9545: return &start_data_table().
9546: &start_data_table_header_row().
9547: '<td bgcolor="'.$headerbg.'">'.$heading.
9548: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9549: $showtext.'\')">'.$showtext.'</a>]</td>'.
9550: &end_data_table_header_row().
9551: '<tr id="'.$id.'" style="display:none""><td>';
9552: }
9553:
9554: sub end_togglebox {
9555: return '</td></tr>'.&end_data_table();
9556: }
9557:
1.1041 www 9558: sub LCprogressbar_script {
1.1302 raeburn 9559: my ($id,$number_to_do)=@_;
9560: if ($number_to_do) {
9561: return(<<ENDPROGRESS);
1.1041 www 9562: <script type="text/javascript">
9563: // <![CDATA[
1.1045 www 9564: \$('#progressbar$id').progressbar({
1.1041 www 9565: value: 0,
9566: change: function(event, ui) {
9567: var newVal = \$(this).progressbar('option', 'value');
9568: \$('.pblabel', this).text(LCprogressTxt);
9569: }
9570: });
9571: // ]]>
9572: </script>
9573: ENDPROGRESS
1.1302 raeburn 9574: } else {
9575: return(<<ENDPROGRESS);
9576: <script type="text/javascript">
9577: // <![CDATA[
9578: \$('#progressbar$id').progressbar({
9579: value: false,
9580: create: function(event, ui) {
9581: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9582: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9583: }
9584: });
9585: // ]]>
9586: </script>
9587: ENDPROGRESS
9588: }
1.1041 www 9589: }
9590:
9591: sub LCprogressbarUpdate_script {
9592: return(<<ENDPROGRESSUPDATE);
9593: <style type="text/css">
9594: .ui-progressbar { position:relative; }
1.1302 raeburn 9595: .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 9596: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9597: </style>
9598: <script type="text/javascript">
9599: // <![CDATA[
1.1045 www 9600: var LCprogressTxt='---';
9601:
1.1302 raeburn 9602: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9603: LCprogressTxt=progresstext;
1.1302 raeburn 9604: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9605: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9606: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9607: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9608: } else {
9609: \$('#progressbar'+id).progressbar('value',percent);
9610: }
1.1041 www 9611: }
9612: // ]]>
9613: </script>
9614: ENDPROGRESSUPDATE
9615: }
9616:
1.1042 www 9617: my $LClastpercent;
1.1045 www 9618: my $LCidcnt;
9619: my $LCcurrentid;
1.1042 www 9620:
1.1041 www 9621: sub LCprogressbar {
1.1302 raeburn 9622: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9623: $LClastpercent=0;
1.1045 www 9624: $LCidcnt++;
9625: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9626: my ($starting,$content);
9627: if ($number_to_do) {
9628: $starting=&mt('Starting');
9629: $content=(<<ENDPROGBAR);
9630: $preamble
1.1045 www 9631: <div id="progressbar$LCcurrentid">
1.1041 www 9632: <span class="pblabel">$starting</span>
9633: </div>
9634: ENDPROGBAR
1.1302 raeburn 9635: } else {
9636: $starting=&mt('Loading...');
9637: $LClastpercent='false';
9638: $content=(<<ENDPROGBAR);
9639: $preamble
9640: <div id="progressbar$LCcurrentid">
9641: <div class="progress-label">$starting</div>
9642: </div>
9643: ENDPROGBAR
9644: }
9645: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9646: }
9647:
9648: sub LCprogressbarUpdate {
1.1302 raeburn 9649: my ($r,$val,$text,$number_to_do)=@_;
9650: if ($number_to_do) {
9651: unless ($val) {
9652: if ($LClastpercent) {
9653: $val=$LClastpercent;
9654: } else {
9655: $val=0;
9656: }
9657: }
9658: if ($val<0) { $val=0; }
9659: if ($val>100) { $val=0; }
9660: $LClastpercent=$val;
9661: unless ($text) { $text=$val.'%'; }
9662: } else {
9663: $val = 'false';
1.1042 www 9664: }
1.1041 www 9665: $text=&js_ready($text);
1.1044 www 9666: &r_print($r,<<ENDUPDATE);
1.1041 www 9667: <script type="text/javascript">
9668: // <![CDATA[
1.1302 raeburn 9669: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9670: // ]]>
9671: </script>
9672: ENDUPDATE
1.1035 www 9673: }
9674:
1.1042 www 9675: sub LCprogressbarClose {
9676: my ($r)=@_;
9677: $LClastpercent=0;
1.1044 www 9678: &r_print($r,<<ENDCLOSE);
1.1042 www 9679: <script type="text/javascript">
9680: // <![CDATA[
1.1045 www 9681: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9682: // ]]>
9683: </script>
9684: ENDCLOSE
1.1044 www 9685: }
9686:
9687: sub r_print {
9688: my ($r,$to_print)=@_;
9689: if ($r) {
9690: $r->print($to_print);
9691: $r->rflush();
9692: } else {
9693: print($to_print);
9694: }
1.1042 www 9695: }
9696:
1.320 albertel 9697: sub html_encode {
9698: my ($result) = @_;
9699:
1.322 albertel 9700: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9701:
9702: return $result;
9703: }
1.1044 www 9704:
1.317 albertel 9705: sub js_ready {
9706: my ($result) = @_;
9707:
1.323 albertel 9708: $result =~ s/[\n\r]/ /xmsg;
9709: $result =~ s/\\/\\\\/xmsg;
9710: $result =~ s/'/\\'/xmsg;
1.372 albertel 9711: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9712:
9713: return $result;
9714: }
9715:
1.315 albertel 9716: sub validate_page {
9717: if ( exists($env{'internal.start_page'})
1.316 albertel 9718: && $env{'internal.start_page'} > 1) {
9719: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9720: $env{'internal.start_page'}.' '.
1.316 albertel 9721: $ENV{'request.filename'});
1.315 albertel 9722: }
9723: if ( exists($env{'internal.end_page'})
1.316 albertel 9724: && $env{'internal.end_page'} > 1) {
9725: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9726: $env{'internal.end_page'}.' '.
1.316 albertel 9727: $env{'request.filename'});
1.315 albertel 9728: }
9729: if ( exists($env{'internal.start_page'})
9730: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9731: &Apache::lonnet::logthis('start_page called without end_page '.
9732: $env{'request.filename'});
1.315 albertel 9733: }
9734: if ( ! exists($env{'internal.start_page'})
9735: && exists($env{'internal.end_page'})) {
1.316 albertel 9736: &Apache::lonnet::logthis('end_page called without start_page'.
9737: $env{'request.filename'});
1.315 albertel 9738: }
1.306 albertel 9739: }
1.315 albertel 9740:
1.996 www 9741:
9742: sub start_scrollbox {
1.1140 raeburn 9743: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9744: unless ($outerwidth) { $outerwidth='520px'; }
9745: unless ($width) { $width='500px'; }
9746: unless ($height) { $height='200px'; }
1.1075 raeburn 9747: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9748: if ($id ne '') {
1.1140 raeburn 9749: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9750: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9751: }
1.1075 raeburn 9752: if ($bgcolor ne '') {
9753: $tdcol = "background-color: $bgcolor;";
9754: }
1.1137 raeburn 9755: my $nicescroll_js;
9756: if ($env{'browser.mobile'}) {
1.1140 raeburn 9757: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9758: }
9759: return <<"END";
9760: $nicescroll_js
9761:
9762: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9763: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9764: END
9765: }
9766:
9767: sub end_scrollbox {
9768: return '</div></td></tr></table>';
9769: }
9770:
9771: sub nicescroll_javascript {
9772: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9773: my %options;
9774: if (ref($cursor) eq 'HASH') {
9775: %options = %{$cursor};
9776: }
9777: unless ($options{'railalign'} =~ /^left|right$/) {
9778: $options{'railalign'} = 'left';
9779: }
9780: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9781: my $function = &get_users_function();
9782: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9783: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9784: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9785: }
1.1140 raeburn 9786: }
9787: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9788: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9789: $options{'cursoropacity'}='1.0';
9790: }
1.1140 raeburn 9791: } else {
9792: $options{'cursoropacity'}='1.0';
9793: }
9794: if ($options{'cursorfixedheight'} eq 'none') {
9795: delete($options{'cursorfixedheight'});
9796: } else {
9797: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9798: }
9799: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9800: delete($options{'railoffset'});
9801: }
9802: my @niceoptions;
9803: while (my($key,$value) = each(%options)) {
9804: if ($value =~ /^\{.+\}$/) {
9805: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9806: } else {
1.1140 raeburn 9807: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9808: }
1.1140 raeburn 9809: }
9810: my $nicescroll_js = '
1.1137 raeburn 9811: $(document).ready(
1.1140 raeburn 9812: function() {
9813: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9814: }
1.1137 raeburn 9815: );
9816: ';
1.1140 raeburn 9817: if ($framecheck) {
9818: $nicescroll_js .= '
9819: function expand_div(caller) {
9820: if (top === self) {
9821: document.getElementById("'.$id.'").style.width = "auto";
9822: document.getElementById("'.$id.'").style.height = "auto";
9823: } else {
9824: try {
9825: if (parent.frames) {
9826: if (parent.frames.length > 1) {
9827: var framesrc = parent.frames[1].location.href;
9828: var currsrc = framesrc.replace(/\#.*$/,"");
9829: if ((caller == "search") || (currsrc == "'.$location.'")) {
9830: document.getElementById("'.$id.'").style.width = "auto";
9831: document.getElementById("'.$id.'").style.height = "auto";
9832: }
9833: }
9834: }
9835: } catch (e) {
9836: return;
9837: }
1.1137 raeburn 9838: }
1.1140 raeburn 9839: return;
1.996 www 9840: }
1.1140 raeburn 9841: ';
9842: }
9843: if ($needjsready) {
9844: $nicescroll_js = '
9845: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9846: } else {
9847: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9848: }
9849: return $nicescroll_js;
1.996 www 9850: }
9851:
1.318 albertel 9852: sub simple_error_page {
1.1150 bisitz 9853: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9854: my %displayargs;
1.1151 raeburn 9855: if (ref($args) eq 'HASH') {
9856: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9857: if ($args->{'only_body'}) {
9858: $displayargs{'only_body'} = 1;
9859: }
9860: if ($args->{'no_nav_bar'}) {
9861: $displayargs{'no_nav_bar'} = 1;
9862: }
1.1151 raeburn 9863: } else {
9864: $msg = &mt($msg);
9865: }
1.1150 bisitz 9866:
1.318 albertel 9867: my $page =
1.1304 raeburn 9868: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9869: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9870: &Apache::loncommon::end_page();
9871: if (ref($r)) {
9872: $r->print($page);
1.327 albertel 9873: return;
1.318 albertel 9874: }
9875: return $page;
9876: }
1.347 albertel 9877:
9878: {
1.610 albertel 9879: my @row_count;
1.961 onken 9880:
9881: sub start_data_table_count {
9882: unshift(@row_count, 0);
9883: return;
9884: }
9885:
9886: sub end_data_table_count {
9887: shift(@row_count);
9888: return;
9889: }
9890:
1.347 albertel 9891: sub start_data_table {
1.1018 raeburn 9892: my ($add_class,$id) = @_;
1.422 albertel 9893: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9894: my $table_id;
9895: if (defined($id)) {
9896: $table_id = ' id="'.$id.'"';
9897: }
1.961 onken 9898: &start_data_table_count();
1.1018 raeburn 9899: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9900: }
9901:
9902: sub end_data_table {
1.961 onken 9903: &end_data_table_count();
1.389 albertel 9904: return '</table>'."\n";;
1.347 albertel 9905: }
9906:
9907: sub start_data_table_row {
1.974 wenzelju 9908: my ($add_class, $id) = @_;
1.610 albertel 9909: $row_count[0]++;
9910: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9911: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9912: $id = (' id="'.$id.'"') unless ($id eq '');
9913: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9914: }
1.471 banghart 9915:
9916: sub continue_data_table_row {
1.974 wenzelju 9917: my ($add_class, $id) = @_;
1.610 albertel 9918: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9919: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9920: $id = (' id="'.$id.'"') unless ($id eq '');
9921: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9922: }
1.347 albertel 9923:
9924: sub end_data_table_row {
1.389 albertel 9925: return '</tr>'."\n";;
1.347 albertel 9926: }
1.367 www 9927:
1.421 albertel 9928: sub start_data_table_empty_row {
1.707 bisitz 9929: # $row_count[0]++;
1.421 albertel 9930: return '<tr class="LC_empty_row" >'."\n";;
9931: }
9932:
9933: sub end_data_table_empty_row {
9934: return '</tr>'."\n";;
9935: }
9936:
1.367 www 9937: sub start_data_table_header_row {
1.389 albertel 9938: return '<tr class="LC_header_row">'."\n";;
1.367 www 9939: }
9940:
9941: sub end_data_table_header_row {
1.389 albertel 9942: return '</tr>'."\n";;
1.367 www 9943: }
1.890 droeschl 9944:
9945: sub data_table_caption {
9946: my $caption = shift;
9947: return "<caption class=\"LC_caption\">$caption</caption>";
9948: }
1.347 albertel 9949: }
9950:
1.548 albertel 9951: =pod
9952:
9953: =item * &inhibit_menu_check($arg)
9954:
9955: Checks for a inhibitmenu state and generates output to preserve it
9956:
9957: Inputs: $arg - can be any of
9958: - undef - in which case the return value is a string
9959: to add into arguments list of a uri
9960: - 'input' - in which case the return value is a HTML
9961: <form> <input> field of type hidden to
9962: preserve the value
9963: - a url - in which case the return value is the url with
9964: the neccesary cgi args added to preserve the
9965: inhibitmenu state
9966: - a ref to a url - no return value, but the string is
9967: updated to include the neccessary cgi
9968: args to preserve the inhibitmenu state
9969:
9970: =cut
9971:
9972: sub inhibit_menu_check {
9973: my ($arg) = @_;
9974: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9975: if ($arg eq 'input') {
9976: if ($env{'form.inhibitmenu'}) {
9977: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9978: } else {
9979: return
9980: }
9981: }
9982: if ($env{'form.inhibitmenu'}) {
9983: if (ref($arg)) {
9984: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9985: } elsif ($arg eq '') {
9986: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9987: } else {
9988: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9989: }
9990: }
9991: if (!ref($arg)) {
9992: return $arg;
9993: }
9994: }
9995:
1.251 albertel 9996: ###############################################
1.182 matthew 9997:
9998: =pod
9999:
1.549 albertel 10000: =back
10001:
10002: =head1 User Information Routines
10003:
10004: =over 4
10005:
1.405 albertel 10006: =item * &get_users_function()
1.182 matthew 10007:
10008: Used by &bodytag to determine the current users primary role.
10009: Returns either 'student','coordinator','admin', or 'author'.
10010:
10011: =cut
10012:
10013: ###############################################
10014: sub get_users_function {
1.815 tempelho 10015: my $function = 'norole';
1.818 tempelho 10016: if ($env{'request.role'}=~/^(st)/) {
10017: $function='student';
10018: }
1.907 raeburn 10019: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10020: $function='coordinator';
10021: }
1.258 albertel 10022: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10023: $function='admin';
10024: }
1.826 bisitz 10025: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10026: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10027: $function='author';
10028: }
10029: return $function;
1.54 www 10030: }
1.99 www 10031:
10032: ###############################################
10033:
1.233 raeburn 10034: =pod
10035:
1.821 raeburn 10036: =item * &show_course()
10037:
10038: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10039: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10040:
10041: Inputs:
10042: None
10043:
10044: Outputs:
10045: Scalar: 1 if 'Course' to be used, 0 otherwise.
10046:
10047: =cut
10048:
10049: ###############################################
10050: sub show_course {
10051: my $course = !$env{'user.adv'};
10052: if (!$env{'user.adv'}) {
10053: foreach my $env (keys(%env)) {
10054: next if ($env !~ m/^user\.priv\./);
10055: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10056: $course = 0;
10057: last;
10058: }
10059: }
10060: }
10061: return $course;
10062: }
10063:
10064: ###############################################
10065:
10066: =pod
10067:
1.542 raeburn 10068: =item * &check_user_status()
1.274 raeburn 10069:
10070: Determines current status of supplied role for a
10071: specific user. Roles can be active, previous or future.
10072:
10073: Inputs:
10074: user's domain, user's username, course's domain,
1.375 raeburn 10075: course's number, optional section ID.
1.274 raeburn 10076:
10077: Outputs:
10078: role status: active, previous or future.
10079:
10080: =cut
10081:
10082: sub check_user_status {
1.412 raeburn 10083: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10084: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10085: my @uroles = keys(%userinfo);
1.274 raeburn 10086: my $srchstr;
10087: my $active_chk = 'none';
1.412 raeburn 10088: my $now = time;
1.274 raeburn 10089: if (@uroles > 0) {
1.908 raeburn 10090: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10091: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10092: } else {
1.412 raeburn 10093: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10094: }
10095: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10096: my $role_end = 0;
10097: my $role_start = 0;
10098: $active_chk = 'active';
1.412 raeburn 10099: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10100: $role_end = $1;
10101: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10102: $role_start = $1;
1.274 raeburn 10103: }
10104: }
10105: if ($role_start > 0) {
1.412 raeburn 10106: if ($now < $role_start) {
1.274 raeburn 10107: $active_chk = 'future';
10108: }
10109: }
10110: if ($role_end > 0) {
1.412 raeburn 10111: if ($now > $role_end) {
1.274 raeburn 10112: $active_chk = 'previous';
10113: }
10114: }
10115: }
10116: }
10117: return $active_chk;
10118: }
10119:
10120: ###############################################
10121:
10122: =pod
10123:
1.405 albertel 10124: =item * &get_sections()
1.233 raeburn 10125:
10126: Determines all the sections for a course including
10127: sections with students and sections containing other roles.
1.419 raeburn 10128: Incoming parameters:
10129:
10130: 1. domain
10131: 2. course number
10132: 3. reference to array containing roles for which sections should
10133: be gathered (optional).
10134: 4. reference to array containing status types for which sections
10135: should be gathered (optional).
10136:
10137: If the third argument is undefined, sections are gathered for any role.
10138: If the fourth argument is undefined, sections are gathered for any status.
10139: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10140:
1.374 raeburn 10141: Returns section hash (keys are section IDs, values are
10142: number of users in each section), subject to the
1.419 raeburn 10143: optional roles filter, optional status filter
1.233 raeburn 10144:
10145: =cut
10146:
10147: ###############################################
10148: sub get_sections {
1.419 raeburn 10149: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10150: if (!defined($cdom) || !defined($cnum)) {
10151: my $cid = $env{'request.course.id'};
10152:
10153: return if (!defined($cid));
10154:
10155: $cdom = $env{'course.'.$cid.'.domain'};
10156: $cnum = $env{'course.'.$cid.'.num'};
10157: }
10158:
10159: my %sectioncount;
1.419 raeburn 10160: my $now = time;
1.240 albertel 10161:
1.1118 raeburn 10162: my $check_students = 1;
10163: my $only_students = 0;
10164: if (ref($possible_roles) eq 'ARRAY') {
10165: if (grep(/^st$/,@{$possible_roles})) {
10166: if (@{$possible_roles} == 1) {
10167: $only_students = 1;
10168: }
10169: } else {
10170: $check_students = 0;
10171: }
10172: }
10173:
10174: if ($check_students) {
1.276 albertel 10175: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10176: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10177: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10178: my $start_index = &Apache::loncoursedata::CL_START();
10179: my $end_index = &Apache::loncoursedata::CL_END();
10180: my $status;
1.366 albertel 10181: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10182: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10183: $data->[$status_index],
10184: $data->[$start_index],
10185: $data->[$end_index]);
10186: if ($stu_status eq 'Active') {
10187: $status = 'active';
10188: } elsif ($end < $now) {
10189: $status = 'previous';
10190: } elsif ($start > $now) {
10191: $status = 'future';
10192: }
10193: if ($section ne '-1' && $section !~ /^\s*$/) {
10194: if ((!defined($possible_status)) || (($status ne '') &&
10195: (grep/^\Q$status\E$/,@{$possible_status}))) {
10196: $sectioncount{$section}++;
10197: }
1.240 albertel 10198: }
10199: }
10200: }
1.1118 raeburn 10201: if ($only_students) {
10202: return %sectioncount;
10203: }
1.240 albertel 10204: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10205: foreach my $user (sort(keys(%courseroles))) {
10206: if ($user !~ /^(\w{2})/) { next; }
10207: my ($role) = ($user =~ /^(\w{2})/);
10208: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10209: my ($section,$status);
1.240 albertel 10210: if ($role eq 'cr' &&
10211: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10212: $section=$1;
10213: }
10214: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10215: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10216: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10217: if ($end == -1 && $start == -1) {
10218: next; #deleted role
10219: }
10220: if (!defined($possible_status)) {
10221: $sectioncount{$section}++;
10222: } else {
10223: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10224: $status = 'active';
10225: } elsif ($end < $now) {
10226: $status = 'future';
10227: } elsif ($start > $now) {
10228: $status = 'previous';
10229: }
10230: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10231: $sectioncount{$section}++;
10232: }
10233: }
1.233 raeburn 10234: }
1.366 albertel 10235: return %sectioncount;
1.233 raeburn 10236: }
10237:
1.274 raeburn 10238: ###############################################
1.294 raeburn 10239:
10240: =pod
1.405 albertel 10241:
10242: =item * &get_course_users()
10243:
1.275 raeburn 10244: Retrieves usernames:domains for users in the specified course
10245: with specific role(s), and access status.
10246:
10247: Incoming parameters:
1.277 albertel 10248: 1. course domain
10249: 2. course number
10250: 3. access status: users must have - either active,
1.275 raeburn 10251: previous, future, or all.
1.277 albertel 10252: 4. reference to array of permissible roles
1.288 raeburn 10253: 5. reference to array of section restrictions (optional)
10254: 6. reference to results object (hash of hashes).
10255: 7. reference to optional userdata hash
1.609 raeburn 10256: 8. reference to optional statushash
1.630 raeburn 10257: 9. flag if privileged users (except those set to unhide in
10258: course settings) should be excluded
1.609 raeburn 10259: Keys of top level results hash are roles.
1.275 raeburn 10260: Keys of inner hashes are username:domain, with
10261: values set to access type.
1.288 raeburn 10262: Optional userdata hash returns an array with arguments in the
10263: same order as loncoursedata::get_classlist() for student data.
10264:
1.609 raeburn 10265: Optional statushash returns
10266:
1.288 raeburn 10267: Entries for end, start, section and status are blank because
10268: of the possibility of multiple values for non-student roles.
10269:
1.275 raeburn 10270: =cut
1.405 albertel 10271:
1.275 raeburn 10272: ###############################################
1.405 albertel 10273:
1.275 raeburn 10274: sub get_course_users {
1.630 raeburn 10275: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10276: my %idx = ();
1.419 raeburn 10277: my %seclists;
1.288 raeburn 10278:
10279: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10280: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10281: $idx{end} = &Apache::loncoursedata::CL_END();
10282: $idx{start} = &Apache::loncoursedata::CL_START();
10283: $idx{id} = &Apache::loncoursedata::CL_ID();
10284: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10285: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10286: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10287:
1.290 albertel 10288: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10289: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10290: my $now = time;
1.277 albertel 10291: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10292: my $match = 0;
1.412 raeburn 10293: my $secmatch = 0;
1.419 raeburn 10294: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10295: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10296: if ($section eq '') {
10297: $section = 'none';
10298: }
1.291 albertel 10299: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10300: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10301: $secmatch = 1;
10302: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10303: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10304: $secmatch = 1;
10305: }
10306: } else {
1.419 raeburn 10307: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10308: $secmatch = 1;
10309: }
1.290 albertel 10310: }
1.412 raeburn 10311: if (!$secmatch) {
10312: next;
10313: }
1.419 raeburn 10314: }
1.275 raeburn 10315: if (defined($$types{'active'})) {
1.288 raeburn 10316: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10317: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10318: $match = 1;
1.275 raeburn 10319: }
10320: }
10321: if (defined($$types{'previous'})) {
1.609 raeburn 10322: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10323: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10324: $match = 1;
1.275 raeburn 10325: }
10326: }
10327: if (defined($$types{'future'})) {
1.609 raeburn 10328: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10329: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10330: $match = 1;
1.275 raeburn 10331: }
10332: }
1.609 raeburn 10333: if ($match) {
10334: push(@{$seclists{$student}},$section);
10335: if (ref($userdata) eq 'HASH') {
10336: $$userdata{$student} = $$classlist{$student};
10337: }
10338: if (ref($statushash) eq 'HASH') {
10339: $statushash->{$student}{'st'}{$section} = $status;
10340: }
1.288 raeburn 10341: }
1.275 raeburn 10342: }
10343: }
1.412 raeburn 10344: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10345: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10346: my $now = time;
1.609 raeburn 10347: my %displaystatus = ( previous => 'Expired',
10348: active => 'Active',
10349: future => 'Future',
10350: );
1.1121 raeburn 10351: my (%nothide,@possdoms);
1.630 raeburn 10352: if ($hidepriv) {
10353: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10354: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10355: if ($user !~ /:/) {
10356: $nothide{join(':',split(/[\@]/,$user))}=1;
10357: } else {
10358: $nothide{$user} = 1;
10359: }
10360: }
1.1121 raeburn 10361: my @possdoms = ($cdom);
10362: if ($coursehash{'checkforpriv'}) {
10363: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10364: }
1.630 raeburn 10365: }
1.439 raeburn 10366: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10367: my $match = 0;
1.412 raeburn 10368: my $secmatch = 0;
1.439 raeburn 10369: my $status;
1.412 raeburn 10370: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10371: $user =~ s/:$//;
1.439 raeburn 10372: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10373: if ($end == -1 || $start == -1) {
10374: next;
10375: }
10376: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10377: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10378: my ($uname,$udom) = split(/:/,$user);
10379: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10380: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10381: $secmatch = 1;
10382: } elsif ($usec eq '') {
1.420 albertel 10383: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10384: $secmatch = 1;
10385: }
10386: } else {
10387: if (grep(/^\Q$usec\E$/,@{$sections})) {
10388: $secmatch = 1;
10389: }
10390: }
10391: if (!$secmatch) {
10392: next;
10393: }
1.288 raeburn 10394: }
1.419 raeburn 10395: if ($usec eq '') {
10396: $usec = 'none';
10397: }
1.275 raeburn 10398: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10399: if ($hidepriv) {
1.1121 raeburn 10400: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10401: (!$nothide{$uname.':'.$udom})) {
10402: next;
10403: }
10404: }
1.503 raeburn 10405: if ($end > 0 && $end < $now) {
1.439 raeburn 10406: $status = 'previous';
10407: } elsif ($start > $now) {
10408: $status = 'future';
10409: } else {
10410: $status = 'active';
10411: }
1.277 albertel 10412: foreach my $type (keys(%{$types})) {
1.275 raeburn 10413: if ($status eq $type) {
1.420 albertel 10414: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10415: push(@{$$users{$role}{$user}},$type);
10416: }
1.288 raeburn 10417: $match = 1;
10418: }
10419: }
1.419 raeburn 10420: if (($match) && (ref($userdata) eq 'HASH')) {
10421: if (!exists($$userdata{$uname.':'.$udom})) {
10422: &get_user_info($udom,$uname,\%idx,$userdata);
10423: }
1.420 albertel 10424: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10425: push(@{$seclists{$uname.':'.$udom}},$usec);
10426: }
1.609 raeburn 10427: if (ref($statushash) eq 'HASH') {
10428: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10429: }
1.275 raeburn 10430: }
10431: }
10432: }
10433: }
1.290 albertel 10434: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10435: if ((defined($cdom)) && (defined($cnum))) {
10436: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10437: if ( defined($csettings{'internal.courseowner'}) ) {
10438: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10439: next if ($owner eq '');
10440: my ($ownername,$ownerdom);
10441: if ($owner =~ /^([^:]+):([^:]+)$/) {
10442: $ownername = $1;
10443: $ownerdom = $2;
10444: } else {
10445: $ownername = $owner;
10446: $ownerdom = $cdom;
10447: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10448: }
10449: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10450: if (defined($userdata) &&
1.609 raeburn 10451: !exists($$userdata{$owner})) {
10452: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10453: if (!grep(/^none$/,@{$seclists{$owner}})) {
10454: push(@{$seclists{$owner}},'none');
10455: }
10456: if (ref($statushash) eq 'HASH') {
10457: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10458: }
1.290 albertel 10459: }
1.279 raeburn 10460: }
10461: }
10462: }
1.419 raeburn 10463: foreach my $user (keys(%seclists)) {
10464: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10465: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10466: }
1.275 raeburn 10467: }
10468: return;
10469: }
10470:
1.288 raeburn 10471: sub get_user_info {
10472: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10473: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10474: &plainname($uname,$udom,'lastname');
1.291 albertel 10475: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10476: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10477: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10478: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10479: return;
10480: }
1.275 raeburn 10481:
1.472 raeburn 10482: ###############################################
10483:
10484: =pod
10485:
10486: =item * &get_user_quota()
10487:
1.1134 raeburn 10488: Retrieves quota assigned for storage of user files.
10489: Default is to report quota for portfolio files.
1.472 raeburn 10490:
10491: Incoming parameters:
10492: 1. user's username
10493: 2. user's domain
1.1134 raeburn 10494: 3. quota name - portfolio, author, or course
1.1136 raeburn 10495: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10496: 4. crstype - official, unofficial, textbook, placement or community,
10497: if quota name is course
1.472 raeburn 10498:
10499: Returns:
1.1163 raeburn 10500: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10501: 2. (Optional) Type of setting: custom or default
10502: (individually assigned or default for user's
10503: institutional status).
10504: 3. (Optional) - User's institutional status (e.g., faculty, staff
10505: or student - types as defined in localenroll::inst_usertypes
10506: for user's domain, which determines default quota for user.
10507: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10508:
10509: If a value has been stored in the user's environment,
1.536 raeburn 10510: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10511: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10512:
10513: =cut
10514:
10515: ###############################################
10516:
10517:
10518: sub get_user_quota {
1.1136 raeburn 10519: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10520: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10521: if (!defined($udom)) {
10522: $udom = $env{'user.domain'};
10523: }
10524: if (!defined($uname)) {
10525: $uname = $env{'user.name'};
10526: }
10527: if (($udom eq '' || $uname eq '') ||
10528: ($udom eq 'public') && ($uname eq 'public')) {
10529: $quota = 0;
1.536 raeburn 10530: $quotatype = 'default';
10531: $defquota = 0;
1.472 raeburn 10532: } else {
1.536 raeburn 10533: my $inststatus;
1.1134 raeburn 10534: if ($quotaname eq 'course') {
10535: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10536: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10537: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10538: } else {
10539: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10540: $quota = $cenv{'internal.uploadquota'};
10541: }
1.536 raeburn 10542: } else {
1.1134 raeburn 10543: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10544: if ($quotaname eq 'author') {
10545: $quota = $env{'environment.authorquota'};
10546: } else {
10547: $quota = $env{'environment.portfolioquota'};
10548: }
10549: $inststatus = $env{'environment.inststatus'};
10550: } else {
10551: my %userenv =
10552: &Apache::lonnet::get('environment',['portfolioquota',
10553: 'authorquota','inststatus'],$udom,$uname);
10554: my ($tmp) = keys(%userenv);
10555: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10556: if ($quotaname eq 'author') {
10557: $quota = $userenv{'authorquota'};
10558: } else {
10559: $quota = $userenv{'portfolioquota'};
10560: }
10561: $inststatus = $userenv{'inststatus'};
10562: } else {
10563: undef(%userenv);
10564: }
10565: }
10566: }
10567: if ($quota eq '' || wantarray) {
10568: if ($quotaname eq 'course') {
10569: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10570: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10571: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10572: ($crstype eq 'placement')) {
1.1136 raeburn 10573: $defquota = $domdefs{$crstype.'quota'};
10574: }
10575: if ($defquota eq '') {
10576: $defquota = 500;
10577: }
1.1134 raeburn 10578: } else {
10579: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10580: }
10581: if ($quota eq '') {
10582: $quota = $defquota;
10583: $quotatype = 'default';
10584: } else {
10585: $quotatype = 'custom';
10586: }
1.472 raeburn 10587: }
10588: }
1.536 raeburn 10589: if (wantarray) {
10590: return ($quota,$quotatype,$settingstatus,$defquota);
10591: } else {
10592: return $quota;
10593: }
1.472 raeburn 10594: }
10595:
10596: ###############################################
10597:
10598: =pod
10599:
10600: =item * &default_quota()
10601:
1.536 raeburn 10602: Retrieves default quota assigned for storage of user portfolio files,
10603: given an (optional) user's institutional status.
1.472 raeburn 10604:
10605: Incoming parameters:
1.1142 raeburn 10606:
1.472 raeburn 10607: 1. domain
1.536 raeburn 10608: 2. (Optional) institutional status(es). This is a : separated list of
10609: status types (e.g., faculty, staff, student etc.)
10610: which apply to the user for whom the default is being retrieved.
10611: If the institutional status string in undefined, the domain
1.1134 raeburn 10612: default quota will be returned.
10613: 3. quota name - portfolio, author, or course
10614: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10615:
10616: Returns:
1.1142 raeburn 10617:
1.1163 raeburn 10618: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10619: 2. (Optional) institutional type which determined the value of the
10620: default quota.
1.472 raeburn 10621:
10622: If a value has been stored in the domain's configuration db,
10623: it will return that, otherwise it returns 20 (for backwards
10624: compatibility with domains which have not set up a configuration
1.1163 raeburn 10625: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10626:
1.536 raeburn 10627: If the user's status includes multiple types (e.g., staff and student),
10628: the largest default quota which applies to the user determines the
10629: default quota returned.
10630:
1.472 raeburn 10631: =cut
10632:
10633: ###############################################
10634:
10635:
10636: sub default_quota {
1.1134 raeburn 10637: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10638: my ($defquota,$settingstatus);
10639: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10640: ['quotas'],$udom);
1.1134 raeburn 10641: my $key = 'defaultquota';
10642: if ($quotaname eq 'author') {
10643: $key = 'authorquota';
10644: }
1.622 raeburn 10645: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10646: if ($inststatus ne '') {
1.765 raeburn 10647: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10648: foreach my $item (@statuses) {
1.1134 raeburn 10649: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10650: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10651: if ($defquota eq '') {
1.1134 raeburn 10652: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10653: $settingstatus = $item;
1.1134 raeburn 10654: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10655: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10656: $settingstatus = $item;
10657: }
10658: }
1.1134 raeburn 10659: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10660: if ($quotahash{'quotas'}{$item} ne '') {
10661: if ($defquota eq '') {
10662: $defquota = $quotahash{'quotas'}{$item};
10663: $settingstatus = $item;
10664: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10665: $defquota = $quotahash{'quotas'}{$item};
10666: $settingstatus = $item;
10667: }
1.536 raeburn 10668: }
10669: }
10670: }
10671: }
10672: if ($defquota eq '') {
1.1134 raeburn 10673: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10674: $defquota = $quotahash{'quotas'}{$key}{'default'};
10675: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10676: $defquota = $quotahash{'quotas'}{'default'};
10677: }
1.536 raeburn 10678: $settingstatus = 'default';
1.1139 raeburn 10679: if ($defquota eq '') {
10680: if ($quotaname eq 'author') {
10681: $defquota = 500;
10682: }
10683: }
1.536 raeburn 10684: }
10685: } else {
10686: $settingstatus = 'default';
1.1134 raeburn 10687: if ($quotaname eq 'author') {
10688: $defquota = 500;
10689: } else {
10690: $defquota = 20;
10691: }
1.536 raeburn 10692: }
10693: if (wantarray) {
10694: return ($defquota,$settingstatus);
1.472 raeburn 10695: } else {
1.536 raeburn 10696: return $defquota;
1.472 raeburn 10697: }
10698: }
10699:
1.1135 raeburn 10700: ###############################################
10701:
10702: =pod
10703:
1.1136 raeburn 10704: =item * &excess_filesize_warning()
1.1135 raeburn 10705:
10706: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10707: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10708: space to be exceeded.
1.1136 raeburn 10709:
10710: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10711: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10712:
1.1165 raeburn 10713: Inputs: 7
1.1136 raeburn 10714: 1. username or coursenum
1.1135 raeburn 10715: 2. domain
1.1136 raeburn 10716: 3. context ('author' or 'course')
1.1135 raeburn 10717: 4. filename of file for which action is being requested
10718: 5. filesize (kB) of file
10719: 6. action being taken: copy or upload.
1.1237 raeburn 10720: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10721:
10722: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10723: otherwise return null.
10724:
10725: =back
1.1135 raeburn 10726:
10727: =cut
10728:
1.1136 raeburn 10729: sub excess_filesize_warning {
1.1165 raeburn 10730: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10731: my $current_disk_usage = 0;
1.1165 raeburn 10732: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10733: if ($context eq 'author') {
10734: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10735: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10736: } else {
10737: foreach my $subdir ('docs','supplemental') {
10738: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10739: }
10740: }
1.1135 raeburn 10741: $disk_quota = int($disk_quota * 1000);
10742: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10743: return '<p class="LC_warning">'.
1.1135 raeburn 10744: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10745: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10746: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10747: $disk_quota,$current_disk_usage).
10748: '</p>';
10749: }
10750: return;
10751: }
10752:
10753: ###############################################
10754:
10755:
1.1136 raeburn 10756:
10757:
1.384 raeburn 10758: sub get_secgrprole_info {
10759: my ($cdom,$cnum,$needroles,$type) = @_;
10760: my %sections_count = &get_sections($cdom,$cnum);
10761: my @sections = (sort {$a <=> $b} keys(%sections_count));
10762: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10763: my @groups = sort(keys(%curr_groups));
10764: my $allroles = [];
10765: my $rolehash;
10766: my $accesshash = {
10767: active => 'Currently has access',
10768: future => 'Will have future access',
10769: previous => 'Previously had access',
10770: };
10771: if ($needroles) {
10772: $rolehash = {'all' => 'all'};
1.385 albertel 10773: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10774: if (&Apache::lonnet::error(%user_roles)) {
10775: undef(%user_roles);
10776: }
10777: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10778: my ($role)=split(/\:/,$item,2);
10779: if ($role eq 'cr') { next; }
10780: if ($role =~ /^cr/) {
10781: $$rolehash{$role} = (split('/',$role))[3];
10782: } else {
10783: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10784: }
10785: }
10786: foreach my $key (sort(keys(%{$rolehash}))) {
10787: push(@{$allroles},$key);
10788: }
10789: push (@{$allroles},'st');
10790: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10791: }
10792: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10793: }
10794:
1.555 raeburn 10795: sub user_picker {
1.1279 raeburn 10796: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10797: my $currdom = $dom;
1.1253 raeburn 10798: my @alldoms = &Apache::lonnet::all_domains();
10799: if (@alldoms == 1) {
10800: my %domsrch = &Apache::lonnet::get_dom('configuration',
10801: ['directorysrch'],$alldoms[0]);
10802: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10803: my $showdom = $domdesc;
10804: if ($showdom eq '') {
10805: $showdom = $dom;
10806: }
10807: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10808: if ((!$domsrch{'directorysrch'}{'available'}) &&
10809: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10810: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10811: }
10812: }
10813: }
1.555 raeburn 10814: my %curr_selected = (
10815: srchin => 'dom',
1.580 raeburn 10816: srchby => 'lastname',
1.555 raeburn 10817: );
10818: my $srchterm;
1.625 raeburn 10819: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10820: if ($srch->{'srchby'} ne '') {
10821: $curr_selected{'srchby'} = $srch->{'srchby'};
10822: }
10823: if ($srch->{'srchin'} ne '') {
10824: $curr_selected{'srchin'} = $srch->{'srchin'};
10825: }
10826: if ($srch->{'srchtype'} ne '') {
10827: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10828: }
10829: if ($srch->{'srchdomain'} ne '') {
10830: $currdom = $srch->{'srchdomain'};
10831: }
10832: $srchterm = $srch->{'srchterm'};
10833: }
1.1222 damieng 10834: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10835: 'usr' => 'Search criteria',
1.563 raeburn 10836: 'doma' => 'Domain/institution to search',
1.558 albertel 10837: 'uname' => 'username',
10838: 'lastname' => 'last name',
1.555 raeburn 10839: 'lastfirst' => 'last name, first name',
1.558 albertel 10840: 'crs' => 'in this course',
1.576 raeburn 10841: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10842: 'alc' => 'all LON-CAPA',
1.573 raeburn 10843: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10844: 'exact' => 'is',
10845: 'contains' => 'contains',
1.569 raeburn 10846: 'begins' => 'begins with',
1.1222 damieng 10847: );
10848: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10849: 'youm' => "You must include some text to search for.",
10850: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10851: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10852: 'yomc' => "You must choose a domain when using an institutional directory search.",
10853: 'ymcd' => "You must choose a domain when using a domain search.",
10854: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10855: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10856: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10857: );
1.1222 damieng 10858: &html_escape(\%html_lt);
10859: &js_escape(\%js_lt);
1.1255 raeburn 10860: my $domform;
1.1277 raeburn 10861: my $allow_blank = 1;
1.1255 raeburn 10862: if ($fixeddom) {
1.1277 raeburn 10863: $allow_blank = 0;
10864: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10865: } else {
1.1287 raeburn 10866: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10867: my ($trusted,$untrusted);
1.1287 raeburn 10868: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10869: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10870: } elsif ($context eq 'author') {
1.1288 raeburn 10871: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10872: } elsif ($context eq 'domain') {
1.1288 raeburn 10873: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10874: }
1.1288 raeburn 10875: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10876: }
1.563 raeburn 10877: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10878:
10879: my @srchins = ('crs','dom','alc','instd');
10880:
10881: foreach my $option (@srchins) {
10882: # FIXME 'alc' option unavailable until
10883: # loncreateuser::print_user_query_page()
10884: # has been completed.
10885: next if ($option eq 'alc');
1.880 raeburn 10886: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10887: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10888: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10889: if ($curr_selected{'srchin'} eq $option) {
10890: $srchinsel .= '
1.1222 damieng 10891: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10892: } else {
10893: $srchinsel .= '
1.1222 damieng 10894: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10895: }
1.555 raeburn 10896: }
1.563 raeburn 10897: $srchinsel .= "\n </select>\n";
1.555 raeburn 10898:
10899: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10900: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10901: if ($curr_selected{'srchby'} eq $option) {
10902: $srchbysel .= '
1.1222 damieng 10903: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10904: } else {
10905: $srchbysel .= '
1.1222 damieng 10906: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10907: }
10908: }
10909: $srchbysel .= "\n </select>\n";
10910:
10911: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10912: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10913: if ($curr_selected{'srchtype'} eq $option) {
10914: $srchtypesel .= '
1.1222 damieng 10915: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10916: } else {
10917: $srchtypesel .= '
1.1222 damieng 10918: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10919: }
10920: }
10921: $srchtypesel .= "\n </select>\n";
10922:
1.558 albertel 10923: my ($newuserscript,$new_user_create);
1.994 raeburn 10924: my $context_dom = $env{'request.role.domain'};
10925: if ($context eq 'requestcrs') {
10926: if ($env{'form.coursedom'} ne '') {
10927: $context_dom = $env{'form.coursedom'};
10928: }
10929: }
1.556 raeburn 10930: if ($forcenewuser) {
1.576 raeburn 10931: if (ref($srch) eq 'HASH') {
1.994 raeburn 10932: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10933: if ($cancreate) {
10934: $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>';
10935: } else {
1.799 bisitz 10936: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10937: my %usertypetext = (
10938: official => 'institutional',
10939: unofficial => 'non-institutional',
10940: );
1.799 bisitz 10941: $new_user_create = '<p class="LC_warning">'
10942: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10943: .' '
10944: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10945: ,'<a href="'.$helplink.'">','</a>')
10946: .'</p><br />';
1.627 raeburn 10947: }
1.576 raeburn 10948: }
10949: }
10950:
1.556 raeburn 10951: $newuserscript = <<"ENDSCRIPT";
10952:
1.570 raeburn 10953: function setSearch(createnew,callingForm) {
1.556 raeburn 10954: if (createnew == 1) {
1.570 raeburn 10955: for (var i=0; i<callingForm.srchby.length; i++) {
10956: if (callingForm.srchby.options[i].value == 'uname') {
10957: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10958: }
10959: }
1.570 raeburn 10960: for (var i=0; i<callingForm.srchin.length; i++) {
10961: if ( callingForm.srchin.options[i].value == 'dom') {
10962: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10963: }
10964: }
1.570 raeburn 10965: for (var i=0; i<callingForm.srchtype.length; i++) {
10966: if (callingForm.srchtype.options[i].value == 'exact') {
10967: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10968: }
10969: }
1.570 raeburn 10970: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10971: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10972: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10973: }
10974: }
10975: }
10976: }
10977: ENDSCRIPT
1.558 albertel 10978:
1.556 raeburn 10979: }
10980:
1.555 raeburn 10981: my $output = <<"END_BLOCK";
1.556 raeburn 10982: <script type="text/javascript">
1.824 bisitz 10983: // <![CDATA[
1.570 raeburn 10984: function validateEntry(callingForm) {
1.558 albertel 10985:
1.556 raeburn 10986: var checkok = 1;
1.558 albertel 10987: var srchin;
1.570 raeburn 10988: for (var i=0; i<callingForm.srchin.length; i++) {
10989: if ( callingForm.srchin[i].checked ) {
10990: srchin = callingForm.srchin[i].value;
1.558 albertel 10991: }
10992: }
10993:
1.570 raeburn 10994: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10995: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10996: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10997: var srchterm = callingForm.srchterm.value;
10998: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10999: var msg = "";
11000:
11001: if (srchterm == "") {
11002: checkok = 0;
1.1222 damieng 11003: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11004: }
11005:
1.569 raeburn 11006: if (srchtype== 'begins') {
11007: if (srchterm.length < 2) {
11008: checkok = 0;
1.1222 damieng 11009: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11010: }
11011: }
11012:
1.556 raeburn 11013: if (srchtype== 'contains') {
11014: if (srchterm.length < 3) {
11015: checkok = 0;
1.1222 damieng 11016: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11017: }
11018: }
11019: if (srchin == 'instd') {
11020: if (srchdomain == '') {
11021: checkok = 0;
1.1222 damieng 11022: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11023: }
11024: }
11025: if (srchin == 'dom') {
11026: if (srchdomain == '') {
11027: checkok = 0;
1.1222 damieng 11028: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11029: }
11030: }
11031: if (srchby == 'lastfirst') {
11032: if (srchterm.indexOf(",") == -1) {
11033: checkok = 0;
1.1222 damieng 11034: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11035: }
11036: if (srchterm.indexOf(",") == srchterm.length -1) {
11037: checkok = 0;
1.1222 damieng 11038: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11039: }
11040: }
11041: if (checkok == 0) {
1.1222 damieng 11042: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11043: return;
11044: }
11045: if (checkok == 1) {
1.570 raeburn 11046: callingForm.submit();
1.556 raeburn 11047: }
11048: }
11049:
11050: $newuserscript
11051:
1.824 bisitz 11052: // ]]>
1.556 raeburn 11053: </script>
1.558 albertel 11054:
11055: $new_user_create
11056:
1.555 raeburn 11057: END_BLOCK
1.558 albertel 11058:
1.876 raeburn 11059: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11060: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11061: $domform.
11062: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11063: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11064: $srchbysel.
11065: $srchtypesel.
11066: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11067: $srchinsel.
11068: &Apache::lonhtmlcommon::row_closure(1).
11069: &Apache::lonhtmlcommon::end_pick_box().
11070: '<br />';
1.1253 raeburn 11071: return ($output,1);
1.555 raeburn 11072: }
11073:
1.612 raeburn 11074: sub user_rule_check {
1.615 raeburn 11075: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11076: my ($response,%inst_response);
1.612 raeburn 11077: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11078: if (keys(%{$usershash}) > 1) {
11079: my (%by_username,%by_id,%userdoms);
11080: my $checkid;
11081: if (ref($checks) eq 'HASH') {
11082: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11083: $checkid = 1;
11084: }
11085: }
11086: foreach my $user (keys(%{$usershash})) {
11087: my ($uname,$udom) = split(/:/,$user);
11088: if ($checkid) {
11089: if (ref($usershash->{$user}) eq 'HASH') {
11090: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11091: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11092: $userdoms{$udom} = 1;
1.1227 raeburn 11093: if (ref($inst_results) eq 'HASH') {
11094: $inst_results->{$uname.':'.$udom} = {};
11095: }
1.1226 raeburn 11096: }
11097: }
11098: } else {
11099: $by_username{$udom}{$uname} = 1;
11100: $userdoms{$udom} = 1;
1.1227 raeburn 11101: if (ref($inst_results) eq 'HASH') {
11102: $inst_results->{$uname.':'.$udom} = {};
11103: }
1.1226 raeburn 11104: }
11105: }
11106: foreach my $udom (keys(%userdoms)) {
11107: if (!$got_rules->{$udom}) {
11108: my %domconfig = &Apache::lonnet::get_dom('configuration',
11109: ['usercreation'],$udom);
11110: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11111: foreach my $item ('username','id') {
11112: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11113: $$curr_rules{$udom}{$item} =
11114: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11115: }
11116: }
11117: }
11118: $got_rules->{$udom} = 1;
11119: }
1.612 raeburn 11120: }
1.1226 raeburn 11121: if ($checkid) {
11122: foreach my $udom (keys(%by_id)) {
11123: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11124: if ($outcome eq 'ok') {
1.1227 raeburn 11125: foreach my $id (keys(%{$by_id{$udom}})) {
11126: my $uname = $by_id{$udom}{$id};
11127: $inst_response{$uname.':'.$udom} = $outcome;
11128: }
1.1226 raeburn 11129: if (ref($results) eq 'HASH') {
11130: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11131: if (exists($inst_response{$uname.':'.$udom})) {
11132: $inst_response{$uname.':'.$udom} = $outcome;
11133: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11134: }
1.1226 raeburn 11135: }
11136: }
11137: }
1.612 raeburn 11138: }
1.615 raeburn 11139: } else {
1.1226 raeburn 11140: foreach my $udom (keys(%by_username)) {
11141: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11142: if ($outcome eq 'ok') {
1.1227 raeburn 11143: foreach my $uname (keys(%{$by_username{$udom}})) {
11144: $inst_response{$uname.':'.$udom} = $outcome;
11145: }
1.1226 raeburn 11146: if (ref($results) eq 'HASH') {
11147: foreach my $uname (keys(%{$results})) {
11148: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11149: }
11150: }
11151: }
11152: }
1.612 raeburn 11153: }
1.1226 raeburn 11154: } elsif (keys(%{$usershash}) == 1) {
11155: my $user = (keys(%{$usershash}))[0];
11156: my ($uname,$udom) = split(/:/,$user);
11157: if (($udom ne '') && ($uname ne '')) {
11158: if (ref($usershash->{$user}) eq 'HASH') {
11159: if (ref($checks) eq 'HASH') {
11160: if (defined($checks->{'username'})) {
11161: ($inst_response{$user},%{$inst_results->{$user}}) =
11162: &Apache::lonnet::get_instuser($udom,$uname);
11163: } elsif (defined($checks->{'id'})) {
11164: if ($usershash->{$user}->{'id'} ne '') {
11165: ($inst_response{$user},%{$inst_results->{$user}}) =
11166: &Apache::lonnet::get_instuser($udom,undef,
11167: $usershash->{$user}->{'id'});
11168: } else {
11169: ($inst_response{$user},%{$inst_results->{$user}}) =
11170: &Apache::lonnet::get_instuser($udom,$uname);
11171: }
1.585 raeburn 11172: }
1.1226 raeburn 11173: } else {
11174: ($inst_response{$user},%{$inst_results->{$user}}) =
11175: &Apache::lonnet::get_instuser($udom,$uname);
11176: return;
11177: }
11178: if (!$got_rules->{$udom}) {
11179: my %domconfig = &Apache::lonnet::get_dom('configuration',
11180: ['usercreation'],$udom);
11181: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11182: foreach my $item ('username','id') {
11183: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11184: $$curr_rules{$udom}{$item} =
11185: $domconfig{'usercreation'}{$item.'_rule'};
11186: }
11187: }
11188: }
11189: $got_rules->{$udom} = 1;
1.585 raeburn 11190: }
11191: }
1.1226 raeburn 11192: } else {
11193: return;
11194: }
11195: } else {
11196: return;
11197: }
11198: foreach my $user (keys(%{$usershash})) {
11199: my ($uname,$udom) = split(/:/,$user);
11200: next if (($udom eq '') || ($uname eq ''));
11201: my $id;
1.1227 raeburn 11202: if (ref($inst_results) eq 'HASH') {
11203: if (ref($inst_results->{$user}) eq 'HASH') {
11204: $id = $inst_results->{$user}->{'id'};
11205: }
11206: }
11207: if ($id eq '') {
11208: if (ref($usershash->{$user})) {
11209: $id = $usershash->{$user}->{'id'};
11210: }
1.585 raeburn 11211: }
1.612 raeburn 11212: foreach my $item (keys(%{$checks})) {
11213: if (ref($$curr_rules{$udom}) eq 'HASH') {
11214: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11215: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11216: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11217: $$curr_rules{$udom}{$item});
1.612 raeburn 11218: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11219: if ($rule_check{$rule}) {
11220: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11221: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11222: if (ref($inst_results) eq 'HASH') {
11223: if (ref($inst_results->{$user}) eq 'HASH') {
11224: if (keys(%{$inst_results->{$user}}) == 0) {
11225: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11226: } elsif ($item eq 'id') {
11227: if ($inst_results->{$user}->{'id'} eq '') {
11228: $$alerts{$item}{$udom}{$uname} = 1;
11229: }
1.615 raeburn 11230: }
1.612 raeburn 11231: }
11232: }
1.615 raeburn 11233: }
11234: last;
1.585 raeburn 11235: }
11236: }
11237: }
11238: }
11239: }
11240: }
11241: }
11242: }
1.612 raeburn 11243: return;
11244: }
11245:
11246: sub user_rule_formats {
11247: my ($domain,$domdesc,$curr_rules,$check) = @_;
11248: my %text = (
11249: 'username' => 'Usernames',
11250: 'id' => 'IDs',
11251: );
11252: my $output;
11253: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11254: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11255: if (@{$ruleorder} > 0) {
1.1102 raeburn 11256: $output = '<br />'.
11257: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11258: '<span class="LC_cusr_emph">','</span>',$domdesc).
11259: ' <ul>';
1.612 raeburn 11260: foreach my $rule (@{$ruleorder}) {
11261: if (ref($curr_rules) eq 'ARRAY') {
11262: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11263: if (ref($rules->{$rule}) eq 'HASH') {
11264: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11265: $rules->{$rule}{'desc'}.'</li>';
11266: }
11267: }
11268: }
11269: }
11270: $output .= '</ul>';
11271: }
11272: }
11273: return $output;
11274: }
11275:
11276: sub instrule_disallow_msg {
1.615 raeburn 11277: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11278: my $response;
11279: my %text = (
11280: item => 'username',
11281: items => 'usernames',
11282: match => 'matches',
11283: do => 'does',
11284: action => 'a username',
11285: one => 'one',
11286: );
11287: if ($count > 1) {
11288: $text{'item'} = 'usernames';
11289: $text{'match'} ='match';
11290: $text{'do'} = 'do';
11291: $text{'action'} = 'usernames',
11292: $text{'one'} = 'ones';
11293: }
11294: if ($checkitem eq 'id') {
11295: $text{'items'} = 'IDs';
11296: $text{'item'} = 'ID';
11297: $text{'action'} = 'an ID';
1.615 raeburn 11298: if ($count > 1) {
11299: $text{'item'} = 'IDs';
11300: $text{'action'} = 'IDs';
11301: }
1.612 raeburn 11302: }
1.674 bisitz 11303: $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 11304: if ($mode eq 'upload') {
11305: if ($checkitem eq 'username') {
11306: $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'}.");
11307: } elsif ($checkitem eq 'id') {
1.674 bisitz 11308: $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 11309: }
1.669 raeburn 11310: } elsif ($mode eq 'selfcreate') {
11311: if ($checkitem eq 'id') {
11312: $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.");
11313: }
1.615 raeburn 11314: } else {
11315: if ($checkitem eq 'username') {
11316: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11317: } elsif ($checkitem eq 'id') {
11318: $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.");
11319: }
1.612 raeburn 11320: }
11321: return $response;
1.585 raeburn 11322: }
11323:
1.624 raeburn 11324: sub personal_data_fieldtitles {
11325: my %fieldtitles = &Apache::lonlocal::texthash (
11326: id => 'Student/Employee ID',
11327: permanentemail => 'E-mail address',
11328: lastname => 'Last Name',
11329: firstname => 'First Name',
11330: middlename => 'Middle Name',
11331: generation => 'Generation',
11332: gen => 'Generation',
1.765 raeburn 11333: inststatus => 'Affiliation',
1.624 raeburn 11334: );
11335: return %fieldtitles;
11336: }
11337:
1.642 raeburn 11338: sub sorted_inst_types {
11339: my ($dom) = @_;
1.1185 raeburn 11340: my ($usertypes,$order);
11341: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11342: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11343: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11344: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11345: } else {
11346: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11347: }
1.642 raeburn 11348: my $othertitle = &mt('All users');
11349: if ($env{'request.course.id'}) {
1.668 raeburn 11350: $othertitle = &mt('Any users');
1.642 raeburn 11351: }
11352: my @types;
11353: if (ref($order) eq 'ARRAY') {
11354: @types = @{$order};
11355: }
11356: if (@types == 0) {
11357: if (ref($usertypes) eq 'HASH') {
11358: @types = sort(keys(%{$usertypes}));
11359: }
11360: }
11361: if (keys(%{$usertypes}) > 0) {
11362: $othertitle = &mt('Other users');
11363: }
11364: return ($othertitle,$usertypes,\@types);
11365: }
11366:
1.645 raeburn 11367: sub get_institutional_codes {
1.1361 raeburn 11368: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11369: # Get complete list of course sections to update
11370: my @currsections = ();
11371: my @currxlists = ();
1.1361 raeburn 11372: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11373: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11374: my $crskey = $crs.':'.$coursecode;
11375: @{$unclutteredsec{$crskey}} = ();
11376: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11377:
11378: if ($$settings{'internal.sectionnums'} ne '') {
11379: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11380: }
11381:
11382: if ($$settings{'internal.crosslistings'} ne '') {
11383: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11384: }
11385:
11386: if (@currxlists > 0) {
1.1361 raeburn 11387: foreach my $xl (@currxlists) {
11388: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11389: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11390: push(@{$allcourses},$1);
1.645 raeburn 11391: $$LC_code{$1} = $2;
11392: }
11393: }
11394: }
11395: }
1.1361 raeburn 11396:
1.645 raeburn 11397: if (@currsections > 0) {
1.1361 raeburn 11398: foreach my $sec (@currsections) {
11399: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11400: my $instsec = $1;
1.645 raeburn 11401: my $lc_sec = $2;
1.1361 raeburn 11402: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11403: push(@{$unclutteredsec{$crskey}},$instsec);
11404: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11405: }
11406: }
11407: }
11408: }
11409:
11410: if (@{$unclutteredsec{$crskey}} > 0) {
11411: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11412: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11413: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11414: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11415: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11416: push(@{$allcourses},$sec);
1.1361 raeburn 11417: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11418: }
11419: }
11420: }
11421: }
11422: return;
11423: }
11424:
1.971 raeburn 11425: sub get_standard_codeitems {
11426: return ('Year','Semester','Department','Number','Section');
11427: }
11428:
1.112 bowersj2 11429: =pod
11430:
1.780 raeburn 11431: =head1 Slot Helpers
11432:
11433: =over 4
11434:
11435: =item * sorted_slots()
11436:
1.1040 raeburn 11437: Sorts an array of slot names in order of an optional sort key,
11438: default sort is by slot start time (earliest first).
1.780 raeburn 11439:
11440: Inputs:
11441:
11442: =over 4
11443:
11444: slotsarr - Reference to array of unsorted slot names.
11445:
11446: slots - Reference to hash of hash, where outer hash keys are slot names.
11447:
1.1040 raeburn 11448: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11449:
1.549 albertel 11450: =back
11451:
1.780 raeburn 11452: Returns:
11453:
11454: =over 4
11455:
1.1040 raeburn 11456: sorted - An array of slot names sorted by a specified sort key
11457: (default sort key is start time of the slot).
1.780 raeburn 11458:
11459: =back
11460:
11461: =cut
11462:
11463:
11464: sub sorted_slots {
1.1040 raeburn 11465: my ($slotsarr,$slots,$sortkey) = @_;
11466: if ($sortkey eq '') {
11467: $sortkey = 'starttime';
11468: }
1.780 raeburn 11469: my @sorted;
11470: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11471: @sorted =
11472: sort {
11473: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11474: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11475: }
11476: if (ref($slots->{$a})) { return -1;}
11477: if (ref($slots->{$b})) { return 1;}
11478: return 0;
11479: } @{$slotsarr};
11480: }
11481: return @sorted;
11482: }
11483:
1.1040 raeburn 11484: =pod
11485:
11486: =item * get_future_slots()
11487:
11488: Inputs:
11489:
11490: =over 4
11491:
11492: cnum - course number
11493:
11494: cdom - course domain
11495:
11496: now - current UNIX time
11497:
11498: symb - optional symb
11499:
11500: =back
11501:
11502: Returns:
11503:
11504: =over 4
11505:
11506: sorted_reservable - ref to array of student_schedulable slots currently
11507: reservable, ordered by end date of reservation period.
11508:
11509: reservable_now - ref to hash of student_schedulable slots currently
11510: reservable.
11511:
11512: Keys in inner hash are:
11513: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11514: (b) endreserve: end date of reservation period.
11515: (c) uniqueperiod: start,end dates when slot is to be uniquely
11516: selected.
1.1040 raeburn 11517:
11518: sorted_future - ref to array of student_schedulable slots reservable in
11519: the future, ordered by start date of reservation period.
11520:
11521: future_reservable - ref to hash of student_schedulable slots reservable
11522: in the future.
11523:
11524: Keys in inner hash are:
11525: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11526: (b) startreserve: start date of reservation period.
11527: (c) uniqueperiod: start,end dates when slot is to be uniquely
11528: selected.
1.1040 raeburn 11529:
11530: =back
11531:
11532: =cut
11533:
11534: sub get_future_slots {
11535: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11536: my $map;
11537: if ($symb) {
11538: ($map) = &Apache::lonnet::decode_symb($symb);
11539: }
1.1040 raeburn 11540: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11541: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11542: foreach my $slot (keys(%slots)) {
11543: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11544: if ($symb) {
1.1229 raeburn 11545: if ($slots{$slot}->{'symb'} ne '') {
11546: my $canuse;
11547: my %oksymbs;
11548: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11549: map { $oksymbs{$_} = 1; } @slotsymbs;
11550: if ($oksymbs{$symb}) {
11551: $canuse = 1;
11552: } else {
11553: foreach my $item (@slotsymbs) {
11554: if ($item =~ /\.(page|sequence)$/) {
11555: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11556: if (($map ne '') && ($map eq $sloturl)) {
11557: $canuse = 1;
11558: last;
11559: }
11560: }
11561: }
11562: }
11563: next unless ($canuse);
11564: }
1.1040 raeburn 11565: }
11566: if (($slots{$slot}->{'starttime'} > $now) &&
11567: ($slots{$slot}->{'endtime'} > $now)) {
11568: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11569: my $userallowed = 0;
11570: if ($slots{$slot}->{'allowedsections'}) {
11571: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11572: if (!defined($env{'request.role.sec'})
11573: && grep(/^No section assigned$/,@allowed_sec)) {
11574: $userallowed=1;
11575: } else {
11576: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11577: $userallowed=1;
11578: }
11579: }
11580: unless ($userallowed) {
11581: if (defined($env{'request.course.groups'})) {
11582: my @groups = split(/:/,$env{'request.course.groups'});
11583: foreach my $group (@groups) {
11584: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11585: $userallowed=1;
11586: last;
11587: }
11588: }
11589: }
11590: }
11591: }
11592: if ($slots{$slot}->{'allowedusers'}) {
11593: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11594: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11595: if (grep(/^\Q$user\E$/,@allowed_users)) {
11596: $userallowed = 1;
11597: }
11598: }
11599: next unless($userallowed);
11600: }
11601: my $startreserve = $slots{$slot}->{'startreserve'};
11602: my $endreserve = $slots{$slot}->{'endreserve'};
11603: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11604: my $uniqueperiod;
11605: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11606: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11607: }
1.1040 raeburn 11608: if (($startreserve < $now) &&
11609: (!$endreserve || $endreserve > $now)) {
11610: my $lastres = $endreserve;
11611: if (!$lastres) {
11612: $lastres = $slots{$slot}->{'starttime'};
11613: }
11614: $reservable_now{$slot} = {
11615: symb => $symb,
1.1250 raeburn 11616: endreserve => $lastres,
11617: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11618: };
11619: } elsif (($startreserve > $now) &&
11620: (!$endreserve || $endreserve > $startreserve)) {
11621: $future_reservable{$slot} = {
11622: symb => $symb,
1.1250 raeburn 11623: startreserve => $startreserve,
11624: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11625: };
11626: }
11627: }
11628: }
11629: my @unsorted_reservable = keys(%reservable_now);
11630: if (@unsorted_reservable > 0) {
11631: @sorted_reservable =
11632: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11633: }
11634: my @unsorted_future = keys(%future_reservable);
11635: if (@unsorted_future > 0) {
11636: @sorted_future =
11637: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11638: }
11639: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11640: }
1.780 raeburn 11641:
11642: =pod
11643:
1.1057 foxr 11644: =back
11645:
1.549 albertel 11646: =head1 HTTP Helpers
11647:
11648: =over 4
11649:
1.648 raeburn 11650: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11651:
1.258 albertel 11652: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11653: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11654: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11655:
11656: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11657: $possible_names is an ref to an array of form element names. As an example:
11658: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11659: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11660:
11661: =cut
1.1 albertel 11662:
1.6 albertel 11663: sub get_unprocessed_cgi {
1.25 albertel 11664: my ($query,$possible_names)= @_;
1.26 matthew 11665: # $Apache::lonxml::debug=1;
1.356 albertel 11666: foreach my $pair (split(/&/,$query)) {
11667: my ($name, $value) = split(/=/,$pair);
1.369 www 11668: $name = &unescape($name);
1.25 albertel 11669: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11670: $value =~ tr/+/ /;
11671: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11672: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11673: }
1.16 harris41 11674: }
1.6 albertel 11675: }
11676:
1.112 bowersj2 11677: =pod
11678:
1.648 raeburn 11679: =item * &cacheheader()
1.112 bowersj2 11680:
11681: returns cache-controlling header code
11682:
11683: =cut
11684:
1.7 albertel 11685: sub cacheheader {
1.258 albertel 11686: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11687: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11688: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11689: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11690: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11691: return $output;
1.7 albertel 11692: }
11693:
1.112 bowersj2 11694: =pod
11695:
1.648 raeburn 11696: =item * &no_cache($r)
1.112 bowersj2 11697:
11698: specifies header code to not have cache
11699:
11700: =cut
11701:
1.9 albertel 11702: sub no_cache {
1.216 albertel 11703: my ($r) = @_;
11704: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11705: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11706: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11707: $r->no_cache(1);
11708: $r->header_out("Expires" => $date);
11709: $r->header_out("Pragma" => "no-cache");
1.123 www 11710: }
11711:
11712: sub content_type {
1.181 albertel 11713: my ($r,$type,$charset) = @_;
1.299 foxr 11714: if ($r) {
11715: # Note that printout.pl calls this with undef for $r.
11716: &no_cache($r);
11717: }
1.258 albertel 11718: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11719: unless ($charset) {
11720: $charset=&Apache::lonlocal::current_encoding;
11721: }
11722: if ($charset) { $type.='; charset='.$charset; }
11723: if ($r) {
11724: $r->content_type($type);
11725: } else {
11726: print("Content-type: $type\n\n");
11727: }
1.9 albertel 11728: }
1.25 albertel 11729:
1.112 bowersj2 11730: =pod
11731:
1.648 raeburn 11732: =item * &add_to_env($name,$value)
1.112 bowersj2 11733:
1.258 albertel 11734: adds $name to the %env hash with value
1.112 bowersj2 11735: $value, if $name already exists, the entry is converted to an array
11736: reference and $value is added to the array.
11737:
11738: =cut
11739:
1.25 albertel 11740: sub add_to_env {
11741: my ($name,$value)=@_;
1.258 albertel 11742: if (defined($env{$name})) {
11743: if (ref($env{$name})) {
1.25 albertel 11744: #already have multiple values
1.258 albertel 11745: push(@{ $env{$name} },$value);
1.25 albertel 11746: } else {
11747: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11748: my $first=$env{$name};
11749: undef($env{$name});
11750: push(@{ $env{$name} },$first,$value);
1.25 albertel 11751: }
11752: } else {
1.258 albertel 11753: $env{$name}=$value;
1.25 albertel 11754: }
1.31 albertel 11755: }
1.149 albertel 11756:
11757: =pod
11758:
1.648 raeburn 11759: =item * &get_env_multiple($name)
1.149 albertel 11760:
1.258 albertel 11761: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11762: values may be defined and end up as an array ref.
11763:
11764: returns an array of values
11765:
11766: =cut
11767:
11768: sub get_env_multiple {
11769: my ($name) = @_;
11770: my @values;
1.258 albertel 11771: if (defined($env{$name})) {
1.149 albertel 11772: # exists is it an array
1.258 albertel 11773: if (ref($env{$name})) {
11774: @values=@{ $env{$name} };
1.149 albertel 11775: } else {
1.258 albertel 11776: $values[0]=$env{$name};
1.149 albertel 11777: }
11778: }
11779: return(@values);
11780: }
11781:
1.1249 damieng 11782: # Looks at given dependencies, and returns something depending on the context.
11783: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11784: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11785: # For all other contexts, returns ($output, $counter, $numpathchg).
11786: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11787: # $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.
11788: # $numpathchg: integer with the number of cleaned up dependency paths.
11789: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11790: # \%mapping: hash reference clean path -> original path for all dependencies.
11791: # @param {string} actionurl - The path to the handler, indicative of the context.
11792: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11793: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11794: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11795: # @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)
11796: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11797: sub ask_for_embedded_content {
1.1249 damieng 11798: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11799: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11800: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11801: %currsubfile,%unused,$rem);
1.1071 raeburn 11802: my $counter = 0;
11803: my $numnew = 0;
1.987 raeburn 11804: my $numremref = 0;
11805: my $numinvalid = 0;
11806: my $numpathchg = 0;
11807: my $numexisting = 0;
1.1071 raeburn 11808: my $numunused = 0;
11809: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11810: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11811: my $heading = &mt('Upload embedded files');
11812: my $buttontext = &mt('Upload');
11813:
1.1249 damieng 11814: # fills these variables based on the context:
11815: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11816: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11817: if ($env{'request.course.id'}) {
1.1123 raeburn 11818: if ($actionurl eq '/adm/dependencies') {
11819: $navmap = Apache::lonnavmaps::navmap->new();
11820: }
11821: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11822: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11823: }
1.1123 raeburn 11824: if (($actionurl eq '/adm/portfolio') ||
11825: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11826: my $current_path='/';
11827: if ($env{'form.currentpath'}) {
11828: $current_path = $env{'form.currentpath'};
11829: }
11830: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11831: $udom = $cdom;
11832: $uname = $cnum;
1.984 raeburn 11833: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11834: } else {
11835: $udom = $env{'user.domain'};
11836: $uname = $env{'user.name'};
11837: $url = '/userfiles/portfolio';
11838: }
1.987 raeburn 11839: $toplevel = $url.'/';
1.984 raeburn 11840: $url .= $current_path;
11841: $getpropath = 1;
1.987 raeburn 11842: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11843: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11844: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11845: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11846: $toplevel = $url;
1.984 raeburn 11847: if ($rest ne '') {
1.987 raeburn 11848: $url .= $rest;
11849: }
11850: } elsif ($actionurl eq '/adm/coursedocs') {
11851: if (ref($args) eq 'HASH') {
1.1071 raeburn 11852: $url = $args->{'docs_url'};
11853: $toplevel = $url;
1.1084 raeburn 11854: if ($args->{'context'} eq 'paste') {
11855: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11856: ($path) =
11857: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11858: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11859: $fileloc =~ s{^/}{};
11860: }
1.1071 raeburn 11861: }
1.1084 raeburn 11862: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11863: if ($env{'request.course.id'} ne '') {
11864: if (ref($args) eq 'HASH') {
11865: $url = $args->{'docs_url'};
11866: $title = $args->{'docs_title'};
1.1126 raeburn 11867: $toplevel = $url;
11868: unless ($toplevel =~ m{^/}) {
11869: $toplevel = "/$url";
11870: }
1.1085 raeburn 11871: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11872: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11873: $path = $1;
11874: } else {
11875: ($path) =
11876: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11877: }
1.1195 raeburn 11878: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11879: $fileloc = $toplevel;
11880: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11881: my ($udom,$uname,$fname) =
11882: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11883: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11884: } else {
11885: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11886: }
1.1071 raeburn 11887: $fileloc =~ s{^/}{};
11888: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11889: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11890: }
1.987 raeburn 11891: }
1.1123 raeburn 11892: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11893: $udom = $cdom;
11894: $uname = $cnum;
11895: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11896: $toplevel = $url;
11897: $path = $url;
11898: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11899: $fileloc =~ s{^/}{};
1.987 raeburn 11900: }
1.1249 damieng 11901:
11902: # parses the dependency paths to get some info
11903: # fills $newfiles, $mapping, $subdependencies, $dependencies
11904: # $newfiles: hash URL -> 1 for new files or external URLs
11905: # (will be completed later)
11906: # $mapping:
11907: # for external URLs: external URL -> external URL
11908: # for relative paths: clean path -> original path
11909: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11910: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11911: foreach my $file (keys(%{$allfiles})) {
11912: my $embed_file;
11913: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11914: $embed_file = $1;
11915: } else {
11916: $embed_file = $file;
11917: }
1.1158 raeburn 11918: my ($absolutepath,$cleaned_file);
11919: if ($embed_file =~ m{^\w+://}) {
11920: $cleaned_file = $embed_file;
1.1147 raeburn 11921: $newfiles{$cleaned_file} = 1;
11922: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11923: } else {
1.1158 raeburn 11924: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11925: if ($embed_file =~ m{^/}) {
11926: $absolutepath = $embed_file;
11927: }
1.1147 raeburn 11928: if ($cleaned_file =~ m{/}) {
11929: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11930: $path = &check_for_traversal($path,$url,$toplevel);
11931: my $item = $fname;
11932: if ($path ne '') {
11933: $item = $path.'/'.$fname;
11934: $subdependencies{$path}{$fname} = 1;
11935: } else {
11936: $dependencies{$item} = 1;
11937: }
11938: if ($absolutepath) {
11939: $mapping{$item} = $absolutepath;
11940: } else {
11941: $mapping{$item} = $embed_file;
11942: }
11943: } else {
11944: $dependencies{$embed_file} = 1;
11945: if ($absolutepath) {
1.1147 raeburn 11946: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11947: } else {
1.1147 raeburn 11948: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11949: }
11950: }
1.984 raeburn 11951: }
11952: }
1.1249 damieng 11953:
11954: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11955: # and lists
11956: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11957: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11958: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11959: # the path had to be cleaned up
11960: # $existing: hash clean path -> 1 if the file exists
11961: # $numexisting: number of keys in $existing
11962: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11963: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11964: # dependency subdirectories that are
11965: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11966: my $dirptr = 16384;
1.984 raeburn 11967: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11968: $currsubfile{$path} = {};
1.1123 raeburn 11969: if (($actionurl eq '/adm/portfolio') ||
11970: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11971: my ($sublistref,$listerror) =
11972: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11973: if (ref($sublistref) eq 'ARRAY') {
11974: foreach my $line (@{$sublistref}) {
11975: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11976: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11977: }
1.984 raeburn 11978: }
1.987 raeburn 11979: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11980: if (opendir(my $dir,$url.'/'.$path)) {
11981: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11982: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11983: }
1.1084 raeburn 11984: } elsif (($actionurl eq '/adm/dependencies') ||
11985: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11986: ($args->{'context'} eq 'paste')) ||
11987: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11988: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11989: my $dir;
11990: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11991: $dir = $fileloc;
11992: } else {
11993: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11994: }
1.1071 raeburn 11995: if ($dir ne '') {
11996: my ($sublistref,$listerror) =
11997: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11998: if (ref($sublistref) eq 'ARRAY') {
11999: foreach my $line (@{$sublistref}) {
12000: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12001: undef,$mtime)=split(/\&/,$line,12);
12002: unless (($testdir&$dirptr) ||
12003: ($file_name =~ /^\.\.?$/)) {
12004: $currsubfile{$path}{$file_name} = [$size,$mtime];
12005: }
12006: }
12007: }
12008: }
1.984 raeburn 12009: }
12010: }
12011: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12012: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12013: my $item = $path.'/'.$file;
12014: unless ($mapping{$item} eq $item) {
12015: $pathchanges{$item} = 1;
12016: }
12017: $existing{$item} = 1;
12018: $numexisting ++;
12019: } else {
12020: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12021: }
12022: }
1.1071 raeburn 12023: if ($actionurl eq '/adm/dependencies') {
12024: foreach my $path (keys(%currsubfile)) {
12025: if (ref($currsubfile{$path}) eq 'HASH') {
12026: foreach my $file (keys(%{$currsubfile{$path}})) {
12027: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12028: next if (($rem ne '') &&
12029: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12030: (ref($navmap) &&
12031: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12032: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12033: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12034: $unused{$path.'/'.$file} = 1;
12035: }
12036: }
12037: }
12038: }
12039: }
1.984 raeburn 12040: }
1.1249 damieng 12041:
12042: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12043: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12044: my %currfile;
1.1123 raeburn 12045: if (($actionurl eq '/adm/portfolio') ||
12046: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12047: my ($dirlistref,$listerror) =
12048: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12049: if (ref($dirlistref) eq 'ARRAY') {
12050: foreach my $line (@{$dirlistref}) {
12051: my ($file_name,$rest) = split(/\&/,$line,2);
12052: $currfile{$file_name} = 1;
12053: }
1.984 raeburn 12054: }
1.987 raeburn 12055: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12056: if (opendir(my $dir,$url)) {
1.987 raeburn 12057: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12058: map {$currfile{$_} = 1;} @dir_list;
12059: }
1.1084 raeburn 12060: } elsif (($actionurl eq '/adm/dependencies') ||
12061: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12062: ($args->{'context'} eq 'paste')) ||
12063: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12064: if ($env{'request.course.id'} ne '') {
12065: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12066: if ($dir ne '') {
12067: my ($dirlistref,$listerror) =
12068: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12069: if (ref($dirlistref) eq 'ARRAY') {
12070: foreach my $line (@{$dirlistref}) {
12071: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12072: $size,undef,$mtime)=split(/\&/,$line,12);
12073: unless (($testdir&$dirptr) ||
12074: ($file_name =~ /^\.\.?$/)) {
12075: $currfile{$file_name} = [$size,$mtime];
12076: }
12077: }
12078: }
12079: }
12080: }
1.984 raeburn 12081: }
1.1249 damieng 12082: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12083: # are not in subdirectories, using $currfile
1.984 raeburn 12084: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12085: if (exists($currfile{$file})) {
1.987 raeburn 12086: unless ($mapping{$file} eq $file) {
12087: $pathchanges{$file} = 1;
12088: }
12089: $existing{$file} = 1;
12090: $numexisting ++;
12091: } else {
1.984 raeburn 12092: $newfiles{$file} = 1;
12093: }
12094: }
1.1071 raeburn 12095: foreach my $file (keys(%currfile)) {
12096: unless (($file eq $filename) ||
12097: ($file eq $filename.'.bak') ||
12098: ($dependencies{$file})) {
1.1085 raeburn 12099: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12100: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12101: next if (($rem ne '') &&
12102: (($env{"httpref.$rem".$file} ne '') ||
12103: (ref($navmap) &&
12104: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12105: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12106: ($navmap->getResourceByUrl($rem.$1)))))));
12107: }
1.1085 raeburn 12108: }
1.1071 raeburn 12109: $unused{$file} = 1;
12110: }
12111: }
1.1249 damieng 12112:
12113: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12114: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12115: ($args->{'context'} eq 'paste')) {
12116: $counter = scalar(keys(%existing));
12117: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12118: return ($output,$counter,$numpathchg,\%existing);
12119: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12120: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12121: $counter = scalar(keys(%existing));
12122: $numpathchg = scalar(keys(%pathchanges));
12123: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12124: }
1.1249 damieng 12125:
12126: # returns HTML otherwise, with dependency results and to ask for more uploads
12127:
12128: # $upload_output: missing dependencies (with upload form)
12129: # $modify_output: uploaded dependencies (in use)
12130: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12131: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12132: if ($actionurl eq '/adm/dependencies') {
12133: next if ($embed_file =~ m{^\w+://});
12134: }
1.660 raeburn 12135: $upload_output .= &start_data_table_row().
1.1123 raeburn 12136: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12137: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12138: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12139: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12140: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12141: }
1.1123 raeburn 12142: $upload_output .= '</td>';
1.1071 raeburn 12143: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12144: $upload_output.='<td align="right">'.
12145: '<span class="LC_info LC_fontsize_medium">'.
12146: &mt("URL points to web address").'</span>';
1.987 raeburn 12147: $numremref++;
1.660 raeburn 12148: } elsif ($args->{'error_on_invalid_names'}
12149: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12150: $upload_output.='<td align="right"><span class="LC_warning">'.
12151: &mt('Invalid characters').'</span>';
1.987 raeburn 12152: $numinvalid++;
1.660 raeburn 12153: } else {
1.1123 raeburn 12154: $upload_output .= '<td>'.
12155: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12156: $embed_file,\%mapping,
1.1071 raeburn 12157: $allfiles,$codebase,'upload');
12158: $counter ++;
12159: $numnew ++;
1.987 raeburn 12160: }
12161: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12162: }
12163: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12164: if ($actionurl eq '/adm/dependencies') {
12165: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12166: $modify_output .= &start_data_table_row().
12167: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12168: '<img src="'.&icon($embed_file).'" border="0" />'.
12169: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12170: '<td>'.$size.'</td>'.
12171: '<td>'.$mtime.'</td>'.
12172: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12173: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12174: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12175: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12176: &embedded_file_element('upload_embedded',$counter,
12177: $embed_file,\%mapping,
12178: $allfiles,$codebase,'modify').
12179: '</div></td>'.
12180: &end_data_table_row()."\n";
12181: $counter ++;
12182: } else {
12183: $upload_output .= &start_data_table_row().
1.1123 raeburn 12184: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12185: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12186: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12187: &Apache::loncommon::end_data_table_row()."\n";
12188: }
12189: }
12190: my $delidx = $counter;
12191: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12192: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12193: $delete_output .= &start_data_table_row().
12194: '<td><img src="'.&icon($oldfile).'" />'.
12195: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12196: '<td>'.$size.'</td>'.
12197: '<td>'.$mtime.'</td>'.
12198: '<td><label><input type="checkbox" name="del_upload_dep" '.
12199: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12200: &embedded_file_element('upload_embedded',$delidx,
12201: $oldfile,\%mapping,$allfiles,
12202: $codebase,'delete').'</td>'.
12203: &end_data_table_row()."\n";
12204: $numunused ++;
12205: $delidx ++;
1.987 raeburn 12206: }
12207: if ($upload_output) {
12208: $upload_output = &start_data_table().
12209: $upload_output.
12210: &end_data_table()."\n";
12211: }
1.1071 raeburn 12212: if ($modify_output) {
12213: $modify_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('Upload replacement?').'</th>'.
12219: &end_data_table_header_row().
12220: $modify_output.
12221: &end_data_table()."\n";
12222: }
12223: if ($delete_output) {
12224: $delete_output = &start_data_table().
12225: &start_data_table_header_row().
12226: '<th>'.&mt('File').'</th>'.
12227: '<th>'.&mt('Size (KB)').'</th>'.
12228: '<th>'.&mt('Modified').'</th>'.
12229: '<th>'.&mt('Delete?').'</th>'.
12230: &end_data_table_header_row().
12231: $delete_output.
12232: &end_data_table()."\n";
12233: }
1.987 raeburn 12234: my $applies = 0;
12235: if ($numremref) {
12236: $applies ++;
12237: }
12238: if ($numinvalid) {
12239: $applies ++;
12240: }
12241: if ($numexisting) {
12242: $applies ++;
12243: }
1.1071 raeburn 12244: if ($counter || $numunused) {
1.987 raeburn 12245: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12246: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12247: $state.'<h3>'.$heading.'</h3>';
12248: if ($actionurl eq '/adm/dependencies') {
12249: if ($numnew) {
12250: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12251: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12252: $upload_output.'<br />'."\n";
12253: }
12254: if ($numexisting) {
12255: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12256: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12257: $modify_output.'<br />'."\n";
12258: $buttontext = &mt('Save changes');
12259: }
12260: if ($numunused) {
12261: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12262: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12263: $delete_output.'<br />'."\n";
12264: $buttontext = &mt('Save changes');
12265: }
12266: } else {
12267: $output .= $upload_output.'<br />'."\n";
12268: }
12269: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12270: $counter.'" />'."\n";
12271: if ($actionurl eq '/adm/dependencies') {
12272: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12273: $numnew.'" />'."\n";
12274: } elsif ($actionurl eq '') {
1.987 raeburn 12275: $output .= '<input type="hidden" name="phase" value="three" />';
12276: }
12277: } elsif ($applies) {
12278: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12279: if ($applies > 1) {
12280: $output .=
1.1123 raeburn 12281: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12282: if ($numremref) {
12283: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12284: }
12285: if ($numinvalid) {
12286: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12287: }
12288: if ($numexisting) {
12289: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12290: }
12291: $output .= '</ul><br />';
12292: } elsif ($numremref) {
12293: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12294: } elsif ($numinvalid) {
12295: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12296: } elsif ($numexisting) {
12297: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12298: }
12299: $output .= $upload_output.'<br />';
12300: }
12301: my ($pathchange_output,$chgcount);
1.1071 raeburn 12302: $chgcount = $counter;
1.987 raeburn 12303: if (keys(%pathchanges) > 0) {
12304: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12305: if ($counter) {
1.987 raeburn 12306: $output .= &embedded_file_element('pathchange',$chgcount,
12307: $embed_file,\%mapping,
1.1071 raeburn 12308: $allfiles,$codebase,'change');
1.987 raeburn 12309: } else {
12310: $pathchange_output .=
12311: &start_data_table_row().
12312: '<td><input type ="checkbox" name="namechange" value="'.
12313: $chgcount.'" checked="checked" /></td>'.
12314: '<td>'.$mapping{$embed_file}.'</td>'.
12315: '<td>'.$embed_file.
12316: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12317: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12318: '</td>'.&end_data_table_row();
1.660 raeburn 12319: }
1.987 raeburn 12320: $numpathchg ++;
12321: $chgcount ++;
1.660 raeburn 12322: }
12323: }
1.1127 raeburn 12324: if (($counter) || ($numunused)) {
1.987 raeburn 12325: if ($numpathchg) {
12326: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12327: $numpathchg.'" />'."\n";
12328: }
12329: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12330: ($actionurl eq '/adm/imsimport')) {
12331: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12332: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12333: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12334: } elsif ($actionurl eq '/adm/dependencies') {
12335: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12336: }
1.1123 raeburn 12337: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12338: } elsif ($numpathchg) {
12339: my %pathchange = ();
12340: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12341: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12342: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12343: }
1.987 raeburn 12344: }
1.1071 raeburn 12345: return ($output,$counter,$numpathchg);
1.987 raeburn 12346: }
12347:
1.1147 raeburn 12348: =pod
12349:
12350: =item * clean_path($name)
12351:
12352: Performs clean-up of directories, subdirectories and filename in an
12353: embedded object, referenced in an HTML file which is being uploaded
12354: to a course or portfolio, where
12355: "Upload embedded images/multimedia files if HTML file" checkbox was
12356: checked.
12357:
12358: Clean-up is similar to replacements in lonnet::clean_filename()
12359: except each / between sub-directory and next level is preserved.
12360:
12361: =cut
12362:
12363: sub clean_path {
12364: my ($embed_file) = @_;
12365: $embed_file =~s{^/+}{};
12366: my @contents;
12367: if ($embed_file =~ m{/}) {
12368: @contents = split(/\//,$embed_file);
12369: } else {
12370: @contents = ($embed_file);
12371: }
12372: my $lastidx = scalar(@contents)-1;
12373: for (my $i=0; $i<=$lastidx; $i++) {
12374: $contents[$i]=~s{\\}{/}g;
12375: $contents[$i]=~s/\s+/\_/g;
12376: $contents[$i]=~s{[^/\w\.\-]}{}g;
12377: if ($i == $lastidx) {
12378: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12379: }
12380: }
12381: if ($lastidx > 0) {
12382: return join('/',@contents);
12383: } else {
12384: return $contents[0];
12385: }
12386: }
12387:
1.987 raeburn 12388: sub embedded_file_element {
1.1071 raeburn 12389: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12390: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12391: (ref($codebase) eq 'HASH'));
12392: my $output;
1.1071 raeburn 12393: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12394: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12395: }
12396: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12397: &escape($embed_file).'" />';
12398: unless (($context eq 'upload_embedded') &&
12399: ($mapping->{$embed_file} eq $embed_file)) {
12400: $output .='
12401: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12402: }
12403: my $attrib;
12404: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12405: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12406: }
12407: $output .=
12408: "\n\t\t".
12409: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12410: $attrib.'" />';
12411: if (exists($codebase->{$mapping->{$embed_file}})) {
12412: $output .=
12413: "\n\t\t".
12414: '<input name="codebase_'.$num.'" type="hidden" value="'.
12415: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12416: }
1.987 raeburn 12417: return $output;
1.660 raeburn 12418: }
12419:
1.1071 raeburn 12420: sub get_dependency_details {
12421: my ($currfile,$currsubfile,$embed_file) = @_;
12422: my ($size,$mtime,$showsize,$showmtime);
12423: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12424: if ($embed_file =~ m{/}) {
12425: my ($path,$fname) = split(/\//,$embed_file);
12426: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12427: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12428: }
12429: } else {
12430: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12431: ($size,$mtime) = @{$currfile->{$embed_file}};
12432: }
12433: }
12434: $showsize = $size/1024.0;
12435: $showsize = sprintf("%.1f",$showsize);
12436: if ($mtime > 0) {
12437: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12438: }
12439: }
12440: return ($showsize,$showmtime);
12441: }
12442:
12443: sub ask_embedded_js {
12444: return <<"END";
12445: <script type="text/javascript"">
12446: // <![CDATA[
12447: function toggleBrowse(counter) {
12448: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12449: var fileid = document.getElementById('embedded_item_'+counter);
12450: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12451: if (chkboxid.checked == true) {
12452: uploaddivid.style.display='block';
12453: } else {
12454: uploaddivid.style.display='none';
12455: fileid.value = '';
12456: }
12457: }
12458: // ]]>
12459: </script>
12460:
12461: END
12462: }
12463:
1.661 raeburn 12464: sub upload_embedded {
12465: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12466: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12467: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12468: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12469: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12470: my $orig_uploaded_filename =
12471: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12472: foreach my $type ('orig','ref','attrib','codebase') {
12473: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12474: $env{'form.embedded_'.$type.'_'.$i} =
12475: &unescape($env{'form.embedded_'.$type.'_'.$i});
12476: }
12477: }
1.661 raeburn 12478: my ($path,$fname) =
12479: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12480: # no path, whole string is fname
12481: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12482: $fname = &Apache::lonnet::clean_filename($fname);
12483: # See if there is anything left
12484: next if ($fname eq '');
12485:
12486: # Check if file already exists as a file or directory.
12487: my ($state,$msg);
12488: if ($context eq 'portfolio') {
12489: my $port_path = $dirpath;
12490: if ($group ne '') {
12491: $port_path = "groups/$group/$port_path";
12492: }
1.987 raeburn 12493: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12494: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12495: $dir_root,$port_path,$disk_quota,
12496: $current_disk_usage,$uname,$udom);
12497: if ($state eq 'will_exceed_quota'
1.984 raeburn 12498: || $state eq 'file_locked') {
1.661 raeburn 12499: $output .= $msg;
12500: next;
12501: }
12502: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12503: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12504: if ($state eq 'exists') {
12505: $output .= $msg;
12506: next;
12507: }
12508: }
12509: # Check if extension is valid
12510: if (($fname =~ /\.(\w+)$/) &&
12511: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12512: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12513: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12514: next;
12515: } elsif (($fname =~ /\.(\w+)$/) &&
12516: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12517: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12518: next;
12519: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12520: $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 12521: next;
12522: }
12523: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12524: my $subdir = $path;
12525: $subdir =~ s{/+$}{};
1.661 raeburn 12526: if ($context eq 'portfolio') {
1.984 raeburn 12527: my $result;
12528: if ($state eq 'existingfile') {
12529: $result=
12530: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12531: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12532: } else {
1.984 raeburn 12533: $result=
12534: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12535: $dirpath.
1.1123 raeburn 12536: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12537: if ($result !~ m|^/uploaded/|) {
12538: $output .= '<span class="LC_error">'
12539: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12540: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12541: .'</span><br />';
12542: next;
12543: } else {
1.987 raeburn 12544: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12545: $path.$fname.'</span>').'<br />';
1.984 raeburn 12546: }
1.661 raeburn 12547: }
1.1123 raeburn 12548: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12549: my $extendedsubdir = $dirpath.'/'.$subdir;
12550: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12551: my $result =
1.1126 raeburn 12552: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12553: if ($result !~ m|^/uploaded/|) {
12554: $output .= '<span class="LC_error">'
12555: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12556: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12557: .'</span><br />';
12558: next;
12559: } else {
12560: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12561: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12562: if ($context eq 'syllabus') {
12563: &Apache::lonnet::make_public_indefinitely($result);
12564: }
1.987 raeburn 12565: }
1.661 raeburn 12566: } else {
12567: # Save the file
12568: my $target = $env{'form.embedded_item_'.$i};
12569: my $fullpath = $dir_root.$dirpath.'/'.$path;
12570: my $dest = $fullpath.$fname;
12571: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12572: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12573: my $count;
12574: my $filepath = $dir_root;
1.1027 raeburn 12575: foreach my $subdir (@parts) {
12576: $filepath .= "/$subdir";
12577: if (!-e $filepath) {
1.661 raeburn 12578: mkdir($filepath,0770);
12579: }
12580: }
12581: my $fh;
12582: if (!open($fh,'>'.$dest)) {
12583: &Apache::lonnet::logthis('Failed to create '.$dest);
12584: $output .= '<span class="LC_error">'.
1.1071 raeburn 12585: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12586: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12587: '</span><br />';
12588: } else {
12589: if (!print $fh $env{'form.embedded_item_'.$i}) {
12590: &Apache::lonnet::logthis('Failed to write to '.$dest);
12591: $output .= '<span class="LC_error">'.
1.1071 raeburn 12592: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12593: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12594: '</span><br />';
12595: } else {
1.987 raeburn 12596: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12597: $url.'</span>').'<br />';
12598: unless ($context eq 'testbank') {
12599: $footer .= &mt('View embedded file: [_1]',
12600: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12601: }
12602: }
12603: close($fh);
12604: }
12605: }
12606: if ($env{'form.embedded_ref_'.$i}) {
12607: $pathchange{$i} = 1;
12608: }
12609: }
12610: if ($output) {
12611: $output = '<p>'.$output.'</p>';
12612: }
12613: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12614: $returnflag = 'ok';
1.1071 raeburn 12615: my $numpathchgs = scalar(keys(%pathchange));
12616: if ($numpathchgs > 0) {
1.987 raeburn 12617: if ($context eq 'portfolio') {
12618: $output .= '<p>'.&mt('or').'</p>';
12619: } elsif ($context eq 'testbank') {
1.1071 raeburn 12620: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12621: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12622: $returnflag = 'modify_orightml';
12623: }
12624: }
1.1071 raeburn 12625: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12626: }
12627:
12628: sub modify_html_form {
12629: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12630: my $end = 0;
12631: my $modifyform;
12632: if ($context eq 'upload_embedded') {
12633: return unless (ref($pathchange) eq 'HASH');
12634: if ($env{'form.number_embedded_items'}) {
12635: $end += $env{'form.number_embedded_items'};
12636: }
12637: if ($env{'form.number_pathchange_items'}) {
12638: $end += $env{'form.number_pathchange_items'};
12639: }
12640: if ($end) {
12641: for (my $i=0; $i<$end; $i++) {
12642: if ($i < $env{'form.number_embedded_items'}) {
12643: next unless($pathchange->{$i});
12644: }
12645: $modifyform .=
12646: &start_data_table_row().
12647: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12648: 'checked="checked" /></td>'.
12649: '<td>'.$env{'form.embedded_ref_'.$i}.
12650: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12651: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12652: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12653: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12654: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12655: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12656: '<td>'.$env{'form.embedded_orig_'.$i}.
12657: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12658: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12659: &end_data_table_row();
1.1071 raeburn 12660: }
1.987 raeburn 12661: }
12662: } else {
12663: $modifyform = $pathchgtable;
12664: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12665: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12666: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12667: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12668: }
12669: }
12670: if ($modifyform) {
1.1071 raeburn 12671: if ($actionurl eq '/adm/dependencies') {
12672: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12673: }
1.987 raeburn 12674: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12675: '<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".
12676: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12677: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12678: '</ol></p>'."\n".'<p>'.
12679: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12680: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12681: &start_data_table()."\n".
12682: &start_data_table_header_row().
12683: '<th>'.&mt('Change?').'</th>'.
12684: '<th>'.&mt('Current reference').'</th>'.
12685: '<th>'.&mt('Required reference').'</th>'.
12686: &end_data_table_header_row()."\n".
12687: $modifyform.
12688: &end_data_table().'<br />'."\n".$hiddenstate.
12689: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12690: '</form>'."\n";
12691: }
12692: return;
12693: }
12694:
12695: sub modify_html_refs {
1.1123 raeburn 12696: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12697: my $container;
12698: if ($context eq 'portfolio') {
12699: $container = $env{'form.container'};
12700: } elsif ($context eq 'coursedoc') {
12701: $container = $env{'form.primaryurl'};
1.1071 raeburn 12702: } elsif ($context eq 'manage_dependencies') {
12703: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12704: $container = "/$container";
1.1123 raeburn 12705: } elsif ($context eq 'syllabus') {
12706: $container = $url;
1.987 raeburn 12707: } else {
1.1027 raeburn 12708: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12709: }
12710: my (%allfiles,%codebase,$output,$content);
12711: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12712: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12713: if (wantarray) {
12714: return ('',0,0);
12715: } else {
12716: return;
12717: }
12718: }
12719: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12720: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12721: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12722: if (wantarray) {
12723: return ('',0,0);
12724: } else {
12725: return;
12726: }
12727: }
1.987 raeburn 12728: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12729: if ($content eq '-1') {
12730: if (wantarray) {
12731: return ('',0,0);
12732: } else {
12733: return;
12734: }
12735: }
1.987 raeburn 12736: } else {
1.1071 raeburn 12737: unless ($container =~ /^\Q$dir_root\E/) {
12738: if (wantarray) {
12739: return ('',0,0);
12740: } else {
12741: return;
12742: }
12743: }
1.1317 raeburn 12744: if (open(my $fh,'<',$container)) {
1.987 raeburn 12745: $content = join('', <$fh>);
12746: close($fh);
12747: } else {
1.1071 raeburn 12748: if (wantarray) {
12749: return ('',0,0);
12750: } else {
12751: return;
12752: }
1.987 raeburn 12753: }
12754: }
12755: my ($count,$codebasecount) = (0,0);
12756: my $mm = new File::MMagic;
12757: my $mime_type = $mm->checktype_contents($content);
12758: if ($mime_type eq 'text/html') {
12759: my $parse_result =
12760: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12761: \%codebase,\$content);
12762: if ($parse_result eq 'ok') {
12763: foreach my $i (@changes) {
12764: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12765: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12766: if ($allfiles{$ref}) {
12767: my $newname = $orig;
12768: my ($attrib_regexp,$codebase);
1.1006 raeburn 12769: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12770: if ($attrib_regexp =~ /:/) {
12771: $attrib_regexp =~ s/\:/|/g;
12772: }
12773: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12774: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12775: $count += $numchg;
1.1123 raeburn 12776: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12777: delete($allfiles{$ref});
1.987 raeburn 12778: }
12779: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12780: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12781: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12782: $codebasecount ++;
12783: }
12784: }
12785: }
1.1123 raeburn 12786: my $skiprewrites;
1.987 raeburn 12787: if ($count || $codebasecount) {
12788: my $saveresult;
1.1071 raeburn 12789: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12790: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12791: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12792: if ($url eq $container) {
12793: my ($fname) = ($container =~ m{/([^/]+)$});
12794: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12795: $count,'<span class="LC_filename">'.
1.1071 raeburn 12796: $fname.'</span>').'</p>';
1.987 raeburn 12797: } else {
12798: $output = '<p class="LC_error">'.
12799: &mt('Error: update failed for: [_1].',
12800: '<span class="LC_filename">'.
12801: $container.'</span>').'</p>';
12802: }
1.1123 raeburn 12803: if ($context eq 'syllabus') {
12804: unless ($saveresult eq 'ok') {
12805: $skiprewrites = 1;
12806: }
12807: }
1.987 raeburn 12808: } else {
1.1317 raeburn 12809: if (open(my $fh,'>',$container)) {
1.987 raeburn 12810: print $fh $content;
12811: close($fh);
12812: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12813: $count,'<span class="LC_filename">'.
12814: $container.'</span>').'</p>';
1.661 raeburn 12815: } else {
1.987 raeburn 12816: $output = '<p class="LC_error">'.
12817: &mt('Error: could not update [_1].',
12818: '<span class="LC_filename">'.
12819: $container.'</span>').'</p>';
1.661 raeburn 12820: }
12821: }
12822: }
1.1123 raeburn 12823: if (($context eq 'syllabus') && (!$skiprewrites)) {
12824: my ($actionurl,$state);
12825: $actionurl = "/public/$udom/$uname/syllabus";
12826: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12827: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12828: \%codebase,
12829: {'context' => 'rewrites',
12830: 'ignore_remote_references' => 1,});
12831: if (ref($mapping) eq 'HASH') {
12832: my $rewrites = 0;
12833: foreach my $key (keys(%{$mapping})) {
12834: next if ($key =~ m{^https?://});
12835: my $ref = $mapping->{$key};
12836: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12837: my $attrib;
12838: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12839: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12840: }
12841: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12842: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12843: $rewrites += $numchg;
12844: }
12845: }
12846: if ($rewrites) {
12847: my $saveresult;
12848: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12849: if ($url eq $container) {
12850: my ($fname) = ($container =~ m{/([^/]+)$});
12851: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12852: $count,'<span class="LC_filename">'.
12853: $fname.'</span>').'</p>';
12854: } else {
12855: $output .= '<p class="LC_error">'.
12856: &mt('Error: could not update links in [_1].',
12857: '<span class="LC_filename">'.
12858: $container.'</span>').'</p>';
12859:
12860: }
12861: }
12862: }
12863: }
1.987 raeburn 12864: } else {
12865: &logthis('Failed to parse '.$container.
12866: ' to modify references: '.$parse_result);
1.661 raeburn 12867: }
12868: }
1.1071 raeburn 12869: if (wantarray) {
12870: return ($output,$count,$codebasecount);
12871: } else {
12872: return $output;
12873: }
1.661 raeburn 12874: }
12875:
12876: sub check_for_existing {
12877: my ($path,$fname,$element) = @_;
12878: my ($state,$msg);
12879: if (-d $path.'/'.$fname) {
12880: $state = 'exists';
12881: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12882: } elsif (-e $path.'/'.$fname) {
12883: $state = 'exists';
12884: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12885: }
12886: if ($state eq 'exists') {
12887: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12888: }
12889: return ($state,$msg);
12890: }
12891:
12892: sub check_for_upload {
12893: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12894: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12895: my $filesize = length($env{'form.'.$element});
12896: if (!$filesize) {
12897: my $msg = '<span class="LC_error">'.
12898: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12899: '<span class="LC_filename">'.$fname.'</span>',
12900: $filesize).'<br />'.
1.1007 raeburn 12901: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12902: '</span>';
12903: return ('zero_bytes',$msg);
12904: }
12905: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12906: my $getpropath = 1;
1.1021 raeburn 12907: my ($dirlistref,$listerror) =
12908: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12909: my $found_file = 0;
12910: my $locked_file = 0;
1.991 raeburn 12911: my @lockers;
12912: my $navmap;
12913: if ($env{'request.course.id'}) {
12914: $navmap = Apache::lonnavmaps::navmap->new();
12915: }
1.1021 raeburn 12916: if (ref($dirlistref) eq 'ARRAY') {
12917: foreach my $line (@{$dirlistref}) {
12918: my ($file_name,$rest)=split(/\&/,$line,2);
12919: if ($file_name eq $fname){
12920: $file_name = $path.$file_name;
12921: if ($group ne '') {
12922: $file_name = $group.$file_name;
12923: }
12924: $found_file = 1;
12925: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12926: foreach my $lock (@lockers) {
12927: if (ref($lock) eq 'ARRAY') {
12928: my ($symb,$crsid) = @{$lock};
12929: if ($crsid eq $env{'request.course.id'}) {
12930: if (ref($navmap)) {
12931: my $res = $navmap->getBySymb($symb);
12932: foreach my $part (@{$res->parts()}) {
12933: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12934: unless (($slot_status == $res->RESERVED) ||
12935: ($slot_status == $res->RESERVED_LOCATION)) {
12936: $locked_file = 1;
12937: }
1.991 raeburn 12938: }
1.1021 raeburn 12939: } else {
12940: $locked_file = 1;
1.991 raeburn 12941: }
12942: } else {
12943: $locked_file = 1;
12944: }
12945: }
1.1021 raeburn 12946: }
12947: } else {
12948: my @info = split(/\&/,$rest);
12949: my $currsize = $info[6]/1000;
12950: if ($currsize < $filesize) {
12951: my $extra = $filesize - $currsize;
12952: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12953: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12954: &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 12955: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12956: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12957: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12958: return ('will_exceed_quota',$msg);
12959: }
1.984 raeburn 12960: }
12961: }
1.661 raeburn 12962: }
12963: }
12964: }
12965: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12966: my $msg = '<p class="LC_warning">'.
12967: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12968: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12969: return ('will_exceed_quota',$msg);
12970: } elsif ($found_file) {
12971: if ($locked_file) {
1.1179 bisitz 12972: my $msg = '<p class="LC_warning">';
1.661 raeburn 12973: $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 12974: $msg .= '</p>';
1.661 raeburn 12975: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12976: return ('file_locked',$msg);
12977: } else {
1.1179 bisitz 12978: my $msg = '<p class="LC_error">';
1.984 raeburn 12979: $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 12980: $msg .= '</p>';
1.984 raeburn 12981: return ('existingfile',$msg);
1.661 raeburn 12982: }
12983: }
12984: }
12985:
1.987 raeburn 12986: sub check_for_traversal {
12987: my ($path,$url,$toplevel) = @_;
12988: my @parts=split(/\//,$path);
12989: my $cleanpath;
12990: my $fullpath = $url;
12991: for (my $i=0;$i<@parts;$i++) {
12992: next if ($parts[$i] eq '.');
12993: if ($parts[$i] eq '..') {
12994: $fullpath =~ s{([^/]+/)$}{};
12995: } else {
12996: $fullpath .= $parts[$i].'/';
12997: }
12998: }
12999: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13000: $cleanpath = $1;
13001: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13002: my $curr_toprel = $1;
13003: my @parts = split(/\//,$curr_toprel);
13004: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13005: my @urlparts = split(/\//,$url_toprel);
13006: my $doubledots;
13007: my $startdiff = -1;
13008: for (my $i=0; $i<@urlparts; $i++) {
13009: if ($startdiff == -1) {
13010: unless ($urlparts[$i] eq $parts[$i]) {
13011: $startdiff = $i;
13012: $doubledots .= '../';
13013: }
13014: } else {
13015: $doubledots .= '../';
13016: }
13017: }
13018: if ($startdiff > -1) {
13019: $cleanpath = $doubledots;
13020: for (my $i=$startdiff; $i<@parts; $i++) {
13021: $cleanpath .= $parts[$i].'/';
13022: }
13023: }
13024: }
13025: $cleanpath =~ s{(/)$}{};
13026: return $cleanpath;
13027: }
1.31 albertel 13028:
1.1053 raeburn 13029: sub is_archive_file {
13030: my ($mimetype) = @_;
13031: if (($mimetype eq 'application/octet-stream') ||
13032: ($mimetype eq 'application/x-stuffit') ||
13033: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13034: return 1;
13035: }
13036: return;
13037: }
13038:
13039: sub decompress_form {
1.1065 raeburn 13040: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13041: my %lt = &Apache::lonlocal::texthash (
13042: this => 'This file is an archive file.',
1.1067 raeburn 13043: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13044: itsc => 'Its contents are as follows:',
1.1053 raeburn 13045: youm => 'You may wish to extract its contents.',
13046: extr => 'Extract contents',
1.1067 raeburn 13047: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13048: proa => 'Process automatically?',
1.1053 raeburn 13049: yes => 'Yes',
13050: no => 'No',
1.1067 raeburn 13051: fold => 'Title for folder containing movie',
13052: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13053: );
1.1065 raeburn 13054: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13055: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13056: my $info = &list_archive_contents($fileloc,\@paths);
13057: if (@paths) {
13058: foreach my $path (@paths) {
13059: $path =~ s{^/}{};
1.1067 raeburn 13060: if ($path =~ m{^([^/]+)/$}) {
13061: $topdir = $1;
13062: }
1.1065 raeburn 13063: if ($path =~ m{^([^/]+)/}) {
13064: $toplevel{$1} = $path;
13065: } else {
13066: $toplevel{$path} = $path;
13067: }
13068: }
13069: }
1.1067 raeburn 13070: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13071: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13072: "$topdir/media/",
13073: "$topdir/media/$topdir.mp4",
13074: "$topdir/media/FirstFrame.png",
13075: "$topdir/media/player.swf",
13076: "$topdir/media/swfobject.js",
13077: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13078: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13079: "$topdir/$topdir.mp4",
13080: "$topdir/$topdir\_config.xml",
13081: "$topdir/$topdir\_controller.swf",
13082: "$topdir/$topdir\_embed.css",
13083: "$topdir/$topdir\_First_Frame.png",
13084: "$topdir/$topdir\_player.html",
13085: "$topdir/$topdir\_Thumbnails.png",
13086: "$topdir/playerProductInstall.swf",
13087: "$topdir/scripts/",
13088: "$topdir/scripts/config_xml.js",
13089: "$topdir/scripts/handlebars.js",
13090: "$topdir/scripts/jquery-1.7.1.min.js",
13091: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13092: "$topdir/scripts/modernizr.js",
13093: "$topdir/scripts/player-min.js",
13094: "$topdir/scripts/swfobject.js",
13095: "$topdir/skins/",
13096: "$topdir/skins/configuration_express.xml",
13097: "$topdir/skins/express_show/",
13098: "$topdir/skins/express_show/player-min.css",
13099: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13100: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13101: "$topdir/$topdir.mp4",
13102: "$topdir/$topdir\_config.xml",
13103: "$topdir/$topdir\_controller.swf",
13104: "$topdir/$topdir\_embed.css",
13105: "$topdir/$topdir\_First_Frame.png",
13106: "$topdir/$topdir\_player.html",
13107: "$topdir/$topdir\_Thumbnails.png",
13108: "$topdir/playerProductInstall.swf",
13109: "$topdir/scripts/",
13110: "$topdir/scripts/config_xml.js",
13111: "$topdir/scripts/techsmith-smart-player.min.js",
13112: "$topdir/skins/",
13113: "$topdir/skins/configuration_express.xml",
13114: "$topdir/skins/express_show/",
13115: "$topdir/skins/express_show/spritesheet.min.css",
13116: "$topdir/skins/express_show/spritesheet.png",
13117: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13118: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13119: if (@diffs == 0) {
1.1164 raeburn 13120: $is_camtasia = 6;
13121: } else {
1.1197 raeburn 13122: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13123: if (@diffs == 0) {
13124: $is_camtasia = 8;
1.1197 raeburn 13125: } else {
13126: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13127: if (@diffs == 0) {
13128: $is_camtasia = 8;
13129: }
1.1164 raeburn 13130: }
1.1067 raeburn 13131: }
13132: }
13133: my $output;
13134: if ($is_camtasia) {
13135: $output = <<"ENDCAM";
13136: <script type="text/javascript" language="Javascript">
13137: // <![CDATA[
13138:
13139: function camtasiaToggle() {
13140: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13141: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13142: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13143: document.getElementById('camtasia_titles').style.display='block';
13144: } else {
13145: document.getElementById('camtasia_titles').style.display='none';
13146: }
13147: }
13148: }
13149: return;
13150: }
13151:
13152: // ]]>
13153: </script>
13154: <p>$lt{'camt'}</p>
13155: ENDCAM
1.1065 raeburn 13156: } else {
1.1067 raeburn 13157: $output = '<p>'.$lt{'this'};
13158: if ($info eq '') {
13159: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13160: } else {
13161: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13162: '<div><pre>'.$info.'</pre></div>';
13163: }
1.1065 raeburn 13164: }
1.1067 raeburn 13165: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13166: my $duplicates;
13167: my $num = 0;
13168: if (ref($dirlist) eq 'ARRAY') {
13169: foreach my $item (@{$dirlist}) {
13170: if (ref($item) eq 'ARRAY') {
13171: if (exists($toplevel{$item->[0]})) {
13172: $duplicates .=
13173: &start_data_table_row().
13174: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13175: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13176: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13177: 'value="1" />'.&mt('Yes').'</label>'.
13178: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13179: '<td>'.$item->[0].'</td>';
13180: if ($item->[2]) {
13181: $duplicates .= '<td>'.&mt('Directory').'</td>';
13182: } else {
13183: $duplicates .= '<td>'.&mt('File').'</td>';
13184: }
13185: $duplicates .= '<td>'.$item->[3].'</td>'.
13186: '<td>'.
13187: &Apache::lonlocal::locallocaltime($item->[4]).
13188: '</td>'.
13189: &end_data_table_row();
13190: $num ++;
13191: }
13192: }
13193: }
13194: }
13195: my $itemcount;
13196: if (@paths > 0) {
13197: $itemcount = scalar(@paths);
13198: } else {
13199: $itemcount = 1;
13200: }
1.1067 raeburn 13201: if ($is_camtasia) {
13202: $output .= $lt{'auto'}.'<br />'.
13203: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13204: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13205: $lt{'yes'}.'</label> <label>'.
13206: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13207: $lt{'no'}.'</label></span><br />'.
13208: '<div id="camtasia_titles" style="display:block">'.
13209: &Apache::lonhtmlcommon::start_pick_box().
13210: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13211: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13212: &Apache::lonhtmlcommon::row_closure().
13213: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13214: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13215: &Apache::lonhtmlcommon::row_closure(1).
13216: &Apache::lonhtmlcommon::end_pick_box().
13217: '</div>';
13218: }
1.1065 raeburn 13219: $output .=
13220: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13221: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13222: "\n";
1.1065 raeburn 13223: if ($duplicates ne '') {
13224: $output .= '<p><span class="LC_warning">'.
13225: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13226: &start_data_table().
13227: &start_data_table_header_row().
13228: '<th>'.&mt('Overwrite?').'</th>'.
13229: '<th>'.&mt('Name').'</th>'.
13230: '<th>'.&mt('Type').'</th>'.
13231: '<th>'.&mt('Size').'</th>'.
13232: '<th>'.&mt('Last modified').'</th>'.
13233: &end_data_table_header_row().
13234: $duplicates.
13235: &end_data_table().
13236: '</p>';
13237: }
1.1067 raeburn 13238: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13239: if (ref($hiddenelements) eq 'HASH') {
13240: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13241: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13242: }
13243: }
13244: $output .= <<"END";
1.1067 raeburn 13245: <br />
1.1053 raeburn 13246: <input type="submit" name="decompress" value="$lt{'extr'}" />
13247: </form>
13248: $noextract
13249: END
13250: return $output;
13251: }
13252:
1.1065 raeburn 13253: sub decompression_utility {
13254: my ($program) = @_;
13255: my @utilities = ('tar','gunzip','bunzip2','unzip');
13256: my $location;
13257: if (grep(/^\Q$program\E$/,@utilities)) {
13258: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13259: '/usr/sbin/') {
13260: if (-x $dir.$program) {
13261: $location = $dir.$program;
13262: last;
13263: }
13264: }
13265: }
13266: return $location;
13267: }
13268:
13269: sub list_archive_contents {
13270: my ($file,$pathsref) = @_;
13271: my (@cmd,$output);
13272: my $needsregexp;
13273: if ($file =~ /\.zip$/) {
13274: @cmd = (&decompression_utility('unzip'),"-l");
13275: $needsregexp = 1;
13276: } elsif (($file =~ m/\.tar\.gz$/) ||
13277: ($file =~ /\.tgz$/)) {
13278: @cmd = (&decompression_utility('tar'),"-ztf");
13279: } elsif ($file =~ /\.tar\.bz2$/) {
13280: @cmd = (&decompression_utility('tar'),"-jtf");
13281: } elsif ($file =~ m|\.tar$|) {
13282: @cmd = (&decompression_utility('tar'),"-tf");
13283: }
13284: if (@cmd) {
13285: undef($!);
13286: undef($@);
13287: if (open(my $fh,"-|", @cmd, $file)) {
13288: while (my $line = <$fh>) {
13289: $output .= $line;
13290: chomp($line);
13291: my $item;
13292: if ($needsregexp) {
13293: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13294: } else {
13295: $item = $line;
13296: }
13297: if ($item ne '') {
13298: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13299: push(@{$pathsref},$item);
13300: }
13301: }
13302: }
13303: close($fh);
13304: }
13305: }
13306: return $output;
13307: }
13308:
1.1053 raeburn 13309: sub decompress_uploaded_file {
13310: my ($file,$dir) = @_;
13311: &Apache::lonnet::appenv({'cgi.file' => $file});
13312: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13313: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13314: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13315: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13316: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13317: my $decompressed = $env{'cgi.decompressed'};
13318: &Apache::lonnet::delenv('cgi.file');
13319: &Apache::lonnet::delenv('cgi.dir');
13320: &Apache::lonnet::delenv('cgi.decompressed');
13321: return ($decompressed,$result);
13322: }
13323:
1.1055 raeburn 13324: sub process_decompression {
13325: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13326: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13327: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13328: &mt('Unexpected file path.').'</p>'."\n";
13329: }
13330: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13331: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13332: &mt('Unexpected course context.').'</p>'."\n";
13333: }
1.1293 raeburn 13334: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13335: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13336: &mt('Filename contained unexpected characters.').'</p>'."\n";
13337: }
1.1055 raeburn 13338: my ($dir,$error,$warning,$output);
1.1180 raeburn 13339: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13340: $error = &mt('Filename not a supported archive file type.').
13341: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13342: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13343: } else {
13344: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13345: if ($docuhome eq 'no_host') {
13346: $error = &mt('Could not determine home server for course.');
13347: } else {
13348: my @ids=&Apache::lonnet::current_machine_ids();
13349: my $currdir = "$dir_root/$destination";
13350: if (grep(/^\Q$docuhome\E$/,@ids)) {
13351: $dir = &LONCAPA::propath($docudom,$docuname).
13352: "$dir_root/$destination";
13353: } else {
13354: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13355: "$dir_root/$docudom/$docuname/$destination";
13356: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13357: $error = &mt('Archive file not found.');
13358: }
13359: }
1.1065 raeburn 13360: my (@to_overwrite,@to_skip);
13361: if ($env{'form.archive_overwrite_total'} > 0) {
13362: my $total = $env{'form.archive_overwrite_total'};
13363: for (my $i=0; $i<$total; $i++) {
13364: if ($env{'form.archive_overwrite_'.$i} == 1) {
13365: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13366: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13367: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13368: }
13369: }
13370: }
13371: my $numskip = scalar(@to_skip);
1.1292 raeburn 13372: my $numoverwrite = scalar(@to_overwrite);
13373: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13374: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13375: } elsif ($dir eq '') {
1.1055 raeburn 13376: $error = &mt('Directory containing archive file unavailable.');
13377: } elsif (!$error) {
1.1065 raeburn 13378: my ($decompressed,$display);
1.1292 raeburn 13379: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13380: my $tempdir = time.'_'.$$.int(rand(10000));
13381: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13382: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13383: ($decompressed,$display) =
13384: &decompress_uploaded_file($file,"$dir/$tempdir");
13385: foreach my $item (@to_skip) {
13386: if (($item ne '') && ($item !~ /\.\./)) {
13387: if (-f "$dir/$tempdir/$item") {
13388: unlink("$dir/$tempdir/$item");
13389: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13390: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13391: }
13392: }
13393: }
13394: foreach my $item (@to_overwrite) {
13395: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13396: if (($item ne '') && ($item !~ /\.\./)) {
13397: if (-f "$dir/$item") {
13398: unlink("$dir/$item");
13399: } elsif (-d "$dir/$item") {
1.1300 raeburn 13400: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13401: }
13402: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13403: }
1.1065 raeburn 13404: }
13405: }
1.1292 raeburn 13406: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13407: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13408: }
1.1065 raeburn 13409: }
13410: } else {
13411: ($decompressed,$display) =
13412: &decompress_uploaded_file($file,$dir);
13413: }
1.1055 raeburn 13414: if ($decompressed eq 'ok') {
1.1065 raeburn 13415: $output = '<p class="LC_info">'.
13416: &mt('Files extracted successfully from archive.').
13417: '</p>'."\n";
1.1055 raeburn 13418: my ($warning,$result,@contents);
13419: my ($newdirlistref,$newlisterror) =
13420: &Apache::lonnet::dirlist($currdir,$docudom,
13421: $docuname,1);
13422: my (%is_dir,%changes,@newitems);
13423: my $dirptr = 16384;
1.1065 raeburn 13424: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13425: foreach my $dir_line (@{$newdirlistref}) {
13426: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13427: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13428: push(@newitems,$item);
13429: if ($dirptr&$testdir) {
13430: $is_dir{$item} = 1;
13431: }
13432: $changes{$item} = 1;
13433: }
13434: }
13435: }
13436: if (keys(%changes) > 0) {
13437: foreach my $item (sort(@newitems)) {
13438: if ($changes{$item}) {
13439: push(@contents,$item);
13440: }
13441: }
13442: }
13443: if (@contents > 0) {
1.1067 raeburn 13444: my $wantform;
13445: unless ($env{'form.autoextract_camtasia'}) {
13446: $wantform = 1;
13447: }
1.1056 raeburn 13448: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13449: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13450: $currdir,\%is_dir,
13451: \%children,\%parent,
1.1056 raeburn 13452: \@contents,\%dirorder,
13453: \%titles,$wantform);
1.1055 raeburn 13454: if ($datatable ne '') {
13455: $output .= &archive_options_form('decompressed',$datatable,
13456: $count,$hiddenelem);
1.1065 raeburn 13457: my $startcount = 6;
1.1055 raeburn 13458: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13459: \%titles,\%children);
1.1055 raeburn 13460: }
1.1067 raeburn 13461: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13462: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13463: my %displayed;
13464: my $total = 1;
13465: $env{'form.archive_directory'} = [];
13466: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13467: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13468: $path =~ s{/$}{};
13469: my $item;
13470: if ($path ne '') {
13471: $item = "$path/$titles{$i}";
13472: } else {
13473: $item = $titles{$i};
13474: }
13475: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13476: if ($item eq $contents[0]) {
13477: push(@{$env{'form.archive_directory'}},$i);
13478: $env{'form.archive_'.$i} = 'display';
13479: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13480: $displayed{'folder'} = $i;
1.1164 raeburn 13481: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13482: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13483: $env{'form.archive_'.$i} = 'display';
13484: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13485: $displayed{'web'} = $i;
13486: } else {
1.1164 raeburn 13487: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13488: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13489: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13490: push(@{$env{'form.archive_directory'}},$i);
13491: }
13492: $env{'form.archive_'.$i} = 'dependency';
13493: }
13494: $total ++;
13495: }
13496: for (my $i=1; $i<$total; $i++) {
13497: next if ($i == $displayed{'web'});
13498: next if ($i == $displayed{'folder'});
13499: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13500: }
13501: $env{'form.phase'} = 'decompress_cleanup';
13502: $env{'form.archivedelete'} = 1;
13503: $env{'form.archive_count'} = $total-1;
13504: $output .=
13505: &process_extracted_files('coursedocs',$docudom,
13506: $docuname,$destination,
13507: $dir_root,$hiddenelem);
13508: }
1.1055 raeburn 13509: } else {
13510: $warning = &mt('No new items extracted from archive file.');
13511: }
13512: } else {
13513: $output = $display;
13514: $error = &mt('An error occurred during extraction from the archive file.');
13515: }
13516: }
13517: }
13518: }
13519: if ($error) {
13520: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13521: $error.'</p>'."\n";
13522: }
13523: if ($warning) {
13524: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13525: }
13526: return $output;
13527: }
13528:
13529: sub get_extracted {
1.1056 raeburn 13530: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13531: $titles,$wantform) = @_;
1.1055 raeburn 13532: my $count = 0;
13533: my $depth = 0;
13534: my $datatable;
1.1056 raeburn 13535: my @hierarchy;
1.1055 raeburn 13536: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13537: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13538: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13539: foreach my $item (@{$contents}) {
13540: $count ++;
1.1056 raeburn 13541: @{$dirorder->{$count}} = @hierarchy;
13542: $titles->{$count} = $item;
1.1055 raeburn 13543: &archive_hierarchy($depth,$count,$parent,$children);
13544: if ($wantform) {
13545: $datatable .= &archive_row($is_dir->{$item},$item,
13546: $currdir,$depth,$count);
13547: }
13548: if ($is_dir->{$item}) {
13549: $depth ++;
1.1056 raeburn 13550: push(@hierarchy,$count);
13551: $parent->{$depth} = $count;
1.1055 raeburn 13552: $datatable .=
13553: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13554: \$depth,\$count,\@hierarchy,$dirorder,
13555: $children,$parent,$titles,$wantform);
1.1055 raeburn 13556: $depth --;
1.1056 raeburn 13557: pop(@hierarchy);
1.1055 raeburn 13558: }
13559: }
13560: return ($count,$datatable);
13561: }
13562:
13563: sub recurse_extracted_archive {
1.1056 raeburn 13564: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13565: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13566: my $result='';
1.1056 raeburn 13567: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13568: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13569: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13570: return $result;
13571: }
13572: my $dirptr = 16384;
13573: my ($newdirlistref,$newlisterror) =
13574: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13575: if (ref($newdirlistref) eq 'ARRAY') {
13576: foreach my $dir_line (@{$newdirlistref}) {
13577: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13578: unless ($item =~ /^\.+$/) {
13579: $$count ++;
1.1056 raeburn 13580: @{$dirorder->{$$count}} = @{$hierarchy};
13581: $titles->{$$count} = $item;
1.1055 raeburn 13582: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13583:
1.1055 raeburn 13584: my $is_dir;
13585: if ($dirptr&$testdir) {
13586: $is_dir = 1;
13587: }
13588: if ($wantform) {
13589: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13590: }
13591: if ($is_dir) {
13592: $$depth ++;
1.1056 raeburn 13593: push(@{$hierarchy},$$count);
13594: $parent->{$$depth} = $$count;
1.1055 raeburn 13595: $result .=
13596: &recurse_extracted_archive("$currdir/$item",$docudom,
13597: $docuname,$depth,$count,
1.1056 raeburn 13598: $hierarchy,$dirorder,$children,
13599: $parent,$titles,$wantform);
1.1055 raeburn 13600: $$depth --;
1.1056 raeburn 13601: pop(@{$hierarchy});
1.1055 raeburn 13602: }
13603: }
13604: }
13605: }
13606: return $result;
13607: }
13608:
13609: sub archive_hierarchy {
13610: my ($depth,$count,$parent,$children) =@_;
13611: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13612: if (exists($parent->{$depth})) {
13613: $children->{$parent->{$depth}} .= $count.':';
13614: }
13615: }
13616: return;
13617: }
13618:
13619: sub archive_row {
13620: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13621: my ($name) = ($item =~ m{([^/]+)$});
13622: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13623: 'display' => 'Add as file',
1.1055 raeburn 13624: 'dependency' => 'Include as dependency',
13625: 'discard' => 'Discard',
13626: );
13627: if ($is_dir) {
1.1059 raeburn 13628: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13629: }
1.1056 raeburn 13630: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13631: my $offset = 0;
1.1055 raeburn 13632: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13633: $offset ++;
1.1065 raeburn 13634: if ($action ne 'display') {
13635: $offset ++;
13636: }
1.1055 raeburn 13637: $output .= '<td><span class="LC_nobreak">'.
13638: '<label><input type="radio" name="archive_'.$count.
13639: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13640: my $text = $choices{$action};
13641: if ($is_dir) {
13642: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13643: if ($action eq 'display') {
1.1059 raeburn 13644: $text = &mt('Add as folder');
1.1055 raeburn 13645: }
1.1056 raeburn 13646: } else {
13647: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13648:
13649: }
13650: $output .= ' /> '.$choices{$action}.'</label></span>';
13651: if ($action eq 'dependency') {
13652: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13653: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13654: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13655: '<option value=""></option>'."\n".
13656: '</select>'."\n".
13657: '</div>';
1.1059 raeburn 13658: } elsif ($action eq 'display') {
13659: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13660: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13661: '</div>';
1.1055 raeburn 13662: }
1.1056 raeburn 13663: $output .= '</td>';
1.1055 raeburn 13664: }
13665: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13666: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13667: for (my $i=0; $i<$depth; $i++) {
13668: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13669: }
13670: if ($is_dir) {
13671: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13672: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13673: } else {
13674: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13675: }
13676: $output .= ' '.$name.'</td>'."\n".
13677: &end_data_table_row();
13678: return $output;
13679: }
13680:
13681: sub archive_options_form {
1.1065 raeburn 13682: my ($form,$display,$count,$hiddenelem) = @_;
13683: my %lt = &Apache::lonlocal::texthash(
13684: perm => 'Permanently remove archive file?',
13685: hows => 'How should each extracted item be incorporated in the course?',
13686: cont => 'Content actions for all',
13687: addf => 'Add as folder/file',
13688: incd => 'Include as dependency for a displayed file',
13689: disc => 'Discard',
13690: no => 'No',
13691: yes => 'Yes',
13692: save => 'Save',
13693: );
13694: my $output = <<"END";
13695: <form name="$form" method="post" action="">
13696: <p><span class="LC_nobreak">$lt{'perm'}
13697: <label>
13698: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13699: </label>
13700:
13701: <label>
13702: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13703: </span>
13704: </p>
13705: <input type="hidden" name="phase" value="decompress_cleanup" />
13706: <br />$lt{'hows'}
13707: <div class="LC_columnSection">
13708: <fieldset>
13709: <legend>$lt{'cont'}</legend>
13710: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13711: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13712: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13713: </fieldset>
13714: </div>
13715: END
13716: return $output.
1.1055 raeburn 13717: &start_data_table()."\n".
1.1065 raeburn 13718: $display."\n".
1.1055 raeburn 13719: &end_data_table()."\n".
13720: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13721: $hiddenelem.
1.1065 raeburn 13722: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13723: '</form>';
13724: }
13725:
13726: sub archive_javascript {
1.1056 raeburn 13727: my ($startcount,$numitems,$titles,$children) = @_;
13728: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13729: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13730: my $scripttag = <<START;
13731: <script type="text/javascript">
13732: // <![CDATA[
13733:
13734: function checkAll(form,prefix) {
13735: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13736: for (var i=0; i < form.elements.length; i++) {
13737: var id = form.elements[i].id;
13738: if ((id != '') && (id != undefined)) {
13739: if (idstr.test(id)) {
13740: if (form.elements[i].type == 'radio') {
13741: form.elements[i].checked = true;
1.1056 raeburn 13742: var nostart = i-$startcount;
1.1059 raeburn 13743: var offset = nostart%7;
13744: var count = (nostart-offset)/7;
1.1056 raeburn 13745: dependencyCheck(form,count,offset);
1.1055 raeburn 13746: }
13747: }
13748: }
13749: }
13750: }
13751:
13752: function propagateCheck(form,count) {
13753: if (count > 0) {
1.1059 raeburn 13754: var startelement = $startcount + ((count-1) * 7);
13755: for (var j=1; j<6; j++) {
13756: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13757: var item = startelement + j;
13758: if (form.elements[item].type == 'radio') {
13759: if (form.elements[item].checked) {
13760: containerCheck(form,count,j);
13761: break;
13762: }
1.1055 raeburn 13763: }
13764: }
13765: }
13766: }
13767: }
13768:
13769: numitems = $numitems
1.1056 raeburn 13770: var titles = new Array(numitems);
13771: var parents = new Array(numitems);
1.1055 raeburn 13772: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13773: parents[i] = new Array;
1.1055 raeburn 13774: }
1.1059 raeburn 13775: var maintitle = '$maintitle';
1.1055 raeburn 13776:
13777: START
13778:
1.1056 raeburn 13779: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13780: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13781: for (my $i=0; $i<@contents; $i ++) {
13782: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13783: }
13784: }
13785:
1.1056 raeburn 13786: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13787: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13788: }
13789:
1.1055 raeburn 13790: $scripttag .= <<END;
13791:
13792: function containerCheck(form,count,offset) {
13793: if (count > 0) {
1.1056 raeburn 13794: dependencyCheck(form,count,offset);
1.1059 raeburn 13795: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13796: form.elements[item].checked = true;
13797: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13798: if (parents[count].length > 0) {
13799: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13800: containerCheck(form,parents[count][j],offset);
13801: }
13802: }
13803: }
13804: }
13805: }
13806:
13807: function dependencyCheck(form,count,offset) {
13808: if (count > 0) {
1.1059 raeburn 13809: var chosen = (offset+$startcount)+7*(count-1);
13810: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13811: var currtype = form.elements[depitem].type;
13812: if (form.elements[chosen].value == 'dependency') {
13813: document.getElementById('arc_depon_'+count).style.display='block';
13814: form.elements[depitem].options.length = 0;
13815: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13816: for (var i=1; i<=numitems; i++) {
13817: if (i == count) {
13818: continue;
13819: }
1.1059 raeburn 13820: var startelement = $startcount + (i-1) * 7;
13821: for (var j=1; j<6; j++) {
13822: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13823: var item = startelement + j;
13824: if (form.elements[item].type == 'radio') {
13825: if (form.elements[item].checked) {
13826: if (form.elements[item].value == 'display') {
13827: var n = form.elements[depitem].options.length;
13828: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13829: }
13830: }
13831: }
13832: }
13833: }
13834: }
13835: } else {
13836: document.getElementById('arc_depon_'+count).style.display='none';
13837: form.elements[depitem].options.length = 0;
13838: form.elements[depitem].options[0] = new Option('Select','',true,true);
13839: }
1.1059 raeburn 13840: titleCheck(form,count,offset);
1.1056 raeburn 13841: }
13842: }
13843:
13844: function propagateSelect(form,count,offset) {
13845: if (count > 0) {
1.1065 raeburn 13846: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13847: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13848: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13849: if (parents[count].length > 0) {
13850: for (var j=0; j<parents[count].length; j++) {
13851: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13852: }
13853: }
13854: }
13855: }
13856: }
1.1056 raeburn 13857:
13858: function containerSelect(form,count,offset,picked) {
13859: if (count > 0) {
1.1065 raeburn 13860: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13861: if (form.elements[item].type == 'radio') {
13862: if (form.elements[item].value == 'dependency') {
13863: if (form.elements[item+1].type == 'select-one') {
13864: for (var i=0; i<form.elements[item+1].options.length; i++) {
13865: if (form.elements[item+1].options[i].value == picked) {
13866: form.elements[item+1].selectedIndex = i;
13867: break;
13868: }
13869: }
13870: }
13871: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13872: if (parents[count].length > 0) {
13873: for (var j=0; j<parents[count].length; j++) {
13874: containerSelect(form,parents[count][j],offset,picked);
13875: }
13876: }
13877: }
13878: }
13879: }
13880: }
13881: }
13882:
1.1059 raeburn 13883: function titleCheck(form,count,offset) {
13884: if (count > 0) {
13885: var chosen = (offset+$startcount)+7*(count-1);
13886: var depitem = $startcount + ((count-1) * 7) + 2;
13887: var currtype = form.elements[depitem].type;
13888: if (form.elements[chosen].value == 'display') {
13889: document.getElementById('arc_title_'+count).style.display='block';
13890: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13891: document.getElementById('archive_title_'+count).value=maintitle;
13892: }
13893: } else {
13894: document.getElementById('arc_title_'+count).style.display='none';
13895: if (currtype == 'text') {
13896: document.getElementById('archive_title_'+count).value='';
13897: }
13898: }
13899: }
13900: return;
13901: }
13902:
1.1055 raeburn 13903: // ]]>
13904: </script>
13905: END
13906: return $scripttag;
13907: }
13908:
13909: sub process_extracted_files {
1.1067 raeburn 13910: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13911: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13912: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13913: my @ids=&Apache::lonnet::current_machine_ids();
13914: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13915: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13916: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13917: if (grep(/^\Q$docuhome\E$/,@ids)) {
13918: $prefix = &LONCAPA::propath($docudom,$docuname);
13919: $pathtocheck = "$dir_root/$destination";
13920: $dir = $dir_root;
13921: $ishome = 1;
13922: } else {
13923: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13924: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13925: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13926: }
13927: my $currdir = "$dir_root/$destination";
13928: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13929: if ($env{'form.folderpath'}) {
13930: my @items = split('&',$env{'form.folderpath'});
13931: $folders{'0'} = $items[-2];
1.1099 raeburn 13932: if ($env{'form.folderpath'} =~ /\:1$/) {
13933: $containers{'0'}='page';
13934: } else {
13935: $containers{'0'}='sequence';
13936: }
1.1055 raeburn 13937: }
13938: my @archdirs = &get_env_multiple('form.archive_directory');
13939: if ($numitems) {
13940: for (my $i=1; $i<=$numitems; $i++) {
13941: my $path = $env{'form.archive_content_'.$i};
13942: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13943: my $item = $1;
13944: $toplevelitems{$item} = $i;
13945: if (grep(/^\Q$i\E$/,@archdirs)) {
13946: $is_dir{$item} = 1;
13947: }
13948: }
13949: }
13950: }
1.1067 raeburn 13951: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13952: if (keys(%toplevelitems) > 0) {
13953: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13954: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13955: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13956: }
1.1066 raeburn 13957: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13958: if ($numitems) {
13959: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13960: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13961: my $path = $env{'form.archive_content_'.$i};
13962: if ($path =~ /^\Q$pathtocheck\E/) {
13963: if ($env{'form.archive_'.$i} eq 'discard') {
13964: if ($prefix ne '' && $path ne '') {
13965: if (-e $prefix.$path) {
1.1066 raeburn 13966: if ((@archdirs > 0) &&
13967: (grep(/^\Q$i\E$/,@archdirs))) {
13968: $todeletedir{$prefix.$path} = 1;
13969: } else {
13970: $todelete{$prefix.$path} = 1;
13971: }
1.1055 raeburn 13972: }
13973: }
13974: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13975: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13976: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13977: $docstitle = $env{'form.archive_title_'.$i};
13978: if ($docstitle eq '') {
13979: $docstitle = $title;
13980: }
1.1055 raeburn 13981: $outer = 0;
1.1056 raeburn 13982: if (ref($dirorder{$i}) eq 'ARRAY') {
13983: if (@{$dirorder{$i}} > 0) {
13984: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13985: if ($env{'form.archive_'.$item} eq 'display') {
13986: $outer = $item;
13987: last;
13988: }
13989: }
13990: }
13991: }
13992: my ($errtext,$fatal) =
13993: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13994: '/'.$folders{$outer}.'.'.
13995: $containers{$outer});
13996: next if ($fatal);
13997: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13998: if ($context eq 'coursedocs') {
1.1056 raeburn 13999: $mapinner{$i} = time;
1.1055 raeburn 14000: $folders{$i} = 'default_'.$mapinner{$i};
14001: $containers{$i} = 'sequence';
14002: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14003: $folders{$i}.'.'.$containers{$i};
14004: my $newidx = &LONCAPA::map::getresidx();
14005: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14006: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14007: push(@LONCAPA::map::order,$newidx);
14008: my ($outtext,$errtext) =
14009: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14010: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14011: '.'.$containers{$outer},1,1);
1.1056 raeburn 14012: $newseqid{$i} = $newidx;
1.1067 raeburn 14013: unless ($errtext) {
1.1294 raeburn 14014: $result .= '<li>'.&mt('Folder: [_1] added to course',
14015: &HTML::Entities::encode($docstitle,'<>&"')).
14016: '</li>'."\n";
1.1067 raeburn 14017: }
1.1055 raeburn 14018: }
14019: } else {
14020: if ($context eq 'coursedocs') {
14021: my $newidx=&LONCAPA::map::getresidx();
14022: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14023: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14024: $title;
1.1294 raeburn 14025: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
14026: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14027: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14028: }
14029: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14030: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14031: }
14032: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14033: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14034: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14035: unless ($ishome) {
14036: my $fetch = "$newdest{$i}/$title";
14037: $fetch =~ s/^\Q$prefix$dir\E//;
14038: $prompttofetch{$fetch} = 1;
14039: }
1.1292 raeburn 14040: }
1.1067 raeburn 14041: }
1.1294 raeburn 14042: $LONCAPA::map::resources[$newidx]=
14043: $docstitle.':'.$url.':false:normal:res';
14044: push(@LONCAPA::map::order, $newidx);
14045: my ($outtext,$errtext)=
14046: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14047: $docuname.'/'.$folders{$outer}.
14048: '.'.$containers{$outer},1,1);
14049: unless ($errtext) {
14050: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14051: $result .= '<li>'.&mt('File: [_1] added to course',
14052: &HTML::Entities::encode($docstitle,'<>&"')).
14053: '</li>'."\n";
14054: }
1.1067 raeburn 14055: }
1.1294 raeburn 14056: } else {
14057: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14058: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14059: }
1.1055 raeburn 14060: }
14061: }
1.1086 raeburn 14062: }
14063: } else {
1.1294 raeburn 14064: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14065: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14066: }
14067: }
14068: for (my $i=1; $i<=$numitems; $i++) {
14069: next unless ($env{'form.archive_'.$i} eq 'dependency');
14070: my $path = $env{'form.archive_content_'.$i};
14071: if ($path =~ /^\Q$pathtocheck\E/) {
14072: my ($title) = ($path =~ m{/([^/]+)$});
14073: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14074: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14075: if (ref($dirorder{$i}) eq 'ARRAY') {
14076: my ($itemidx,$fullpath,$relpath);
14077: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14078: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14079: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14080: if ($dirorder{$i}->[$j] eq $container) {
14081: $itemidx = $j;
1.1056 raeburn 14082: }
14083: }
1.1086 raeburn 14084: }
14085: if ($itemidx eq '') {
14086: $itemidx = 0;
14087: }
14088: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14089: if ($mapinner{$referrer{$i}}) {
14090: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14091: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14092: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14093: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14094: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14095: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14096: if (!-e $fullpath) {
14097: mkdir($fullpath,0755);
1.1056 raeburn 14098: }
14099: }
1.1086 raeburn 14100: } else {
14101: last;
1.1056 raeburn 14102: }
1.1086 raeburn 14103: }
14104: }
14105: } elsif ($newdest{$referrer{$i}}) {
14106: $fullpath = $newdest{$referrer{$i}};
14107: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14108: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14109: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14110: last;
14111: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14112: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14113: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14114: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14115: if (!-e $fullpath) {
14116: mkdir($fullpath,0755);
1.1056 raeburn 14117: }
14118: }
1.1086 raeburn 14119: } else {
14120: last;
1.1056 raeburn 14121: }
1.1055 raeburn 14122: }
14123: }
1.1086 raeburn 14124: if ($fullpath ne '') {
14125: if (-e "$prefix$path") {
1.1292 raeburn 14126: unless (rename("$prefix$path","$fullpath/$title")) {
14127: $warning .= &mt('Failed to rename dependency').'<br />';
14128: }
1.1086 raeburn 14129: }
14130: if (-e "$fullpath/$title") {
14131: my $showpath;
14132: if ($relpath ne '') {
14133: $showpath = "$relpath/$title";
14134: } else {
14135: $showpath = "/$title";
14136: }
1.1294 raeburn 14137: $result .= '<li>'.&mt('[_1] included as a dependency',
14138: &HTML::Entities::encode($showpath,'<>&"')).
14139: '</li>'."\n";
1.1292 raeburn 14140: unless ($ishome) {
14141: my $fetch = "$fullpath/$title";
14142: $fetch =~ s/^\Q$prefix$dir\E//;
14143: $prompttofetch{$fetch} = 1;
14144: }
1.1086 raeburn 14145: }
14146: }
1.1055 raeburn 14147: }
1.1086 raeburn 14148: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14149: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14150: &HTML::Entities::encode($path,'<>&"'),
14151: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14152: '<br />';
1.1055 raeburn 14153: }
14154: } else {
1.1294 raeburn 14155: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14156: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14157: }
14158: }
14159: if (keys(%todelete)) {
14160: foreach my $key (keys(%todelete)) {
14161: unlink($key);
1.1066 raeburn 14162: }
14163: }
14164: if (keys(%todeletedir)) {
14165: foreach my $key (keys(%todeletedir)) {
14166: rmdir($key);
14167: }
14168: }
14169: foreach my $dir (sort(keys(%is_dir))) {
14170: if (($pathtocheck ne '') && ($dir ne '')) {
14171: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14172: }
14173: }
1.1067 raeburn 14174: if ($result ne '') {
14175: $output .= '<ul>'."\n".
14176: $result."\n".
14177: '</ul>';
14178: }
14179: unless ($ishome) {
14180: my $replicationfail;
14181: foreach my $item (keys(%prompttofetch)) {
14182: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14183: unless ($fetchresult eq 'ok') {
14184: $replicationfail .= '<li>'.$item.'</li>'."\n";
14185: }
14186: }
14187: if ($replicationfail) {
14188: $output .= '<p class="LC_error">'.
14189: &mt('Course home server failed to retrieve:').'<ul>'.
14190: $replicationfail.
14191: '</ul></p>';
14192: }
14193: }
1.1055 raeburn 14194: } else {
14195: $warning = &mt('No items found in archive.');
14196: }
14197: if ($error) {
14198: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14199: $error.'</p>'."\n";
14200: }
14201: if ($warning) {
14202: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14203: }
14204: return $output;
14205: }
14206:
1.1066 raeburn 14207: sub cleanup_empty_dirs {
14208: my ($path) = @_;
14209: if (($path ne '') && (-d $path)) {
14210: if (opendir(my $dirh,$path)) {
14211: my @dircontents = grep(!/^\./,readdir($dirh));
14212: my $numitems = 0;
14213: foreach my $item (@dircontents) {
14214: if (-d "$path/$item") {
1.1111 raeburn 14215: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14216: if (-e "$path/$item") {
14217: $numitems ++;
14218: }
14219: } else {
14220: $numitems ++;
14221: }
14222: }
14223: if ($numitems == 0) {
14224: rmdir($path);
14225: }
14226: closedir($dirh);
14227: }
14228: }
14229: return;
14230: }
14231:
1.41 ng 14232: =pod
1.45 matthew 14233:
1.1162 raeburn 14234: =item * &get_folder_hierarchy()
1.1068 raeburn 14235:
14236: Provides hierarchy of names of folders/sub-folders containing the current
14237: item,
14238:
14239: Inputs: 3
14240: - $navmap - navmaps object
14241:
14242: - $map - url for map (either the trigger itself, or map containing
14243: the resource, which is the trigger).
14244:
14245: - $showitem - 1 => show title for map itself; 0 => do not show.
14246:
14247: Outputs: 1 @pathitems - array of folder/subfolder names.
14248:
14249: =cut
14250:
14251: sub get_folder_hierarchy {
14252: my ($navmap,$map,$showitem) = @_;
14253: my @pathitems;
14254: if (ref($navmap)) {
14255: my $mapres = $navmap->getResourceByUrl($map);
14256: if (ref($mapres)) {
14257: my $pcslist = $mapres->map_hierarchy();
14258: if ($pcslist ne '') {
14259: my @pcs = split(/,/,$pcslist);
14260: foreach my $pc (@pcs) {
14261: if ($pc == 1) {
1.1129 raeburn 14262: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14263: } else {
14264: my $res = $navmap->getByMapPc($pc);
14265: if (ref($res)) {
14266: my $title = $res->compTitle();
14267: $title =~ s/\W+/_/g;
14268: if ($title ne '') {
14269: push(@pathitems,$title);
14270: }
14271: }
14272: }
14273: }
14274: }
1.1071 raeburn 14275: if ($showitem) {
14276: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14277: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14278: } else {
14279: my $maptitle = $mapres->compTitle();
14280: $maptitle =~ s/\W+/_/g;
14281: if ($maptitle ne '') {
14282: push(@pathitems,$maptitle);
14283: }
1.1068 raeburn 14284: }
14285: }
14286: }
14287: }
14288: return @pathitems;
14289: }
14290:
14291: =pod
14292:
1.1015 raeburn 14293: =item * &get_turnedin_filepath()
14294:
14295: Determines path in a user's portfolio file for storage of files uploaded
14296: to a specific essayresponse or dropbox item.
14297:
14298: Inputs: 3 required + 1 optional.
14299: $symb is symb for resource, $uname and $udom are for current user (required).
14300: $caller is optional (can be "submission", if routine is called when storing
14301: an upoaded file when "Submit Answer" button was pressed).
14302:
14303: Returns array containing $path and $multiresp.
14304: $path is path in portfolio. $multiresp is 1 if this resource contains more
14305: than one file upload item. Callers of routine should append partid as a
14306: subdirectory to $path in cases where $multiresp is 1.
14307:
14308: Called by: homework/essayresponse.pm and homework/structuretags.pm
14309:
14310: =cut
14311:
14312: sub get_turnedin_filepath {
14313: my ($symb,$uname,$udom,$caller) = @_;
14314: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14315: my $turnindir;
14316: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14317: $turnindir = $userhash{'turnindir'};
14318: my ($path,$multiresp);
14319: if ($turnindir eq '') {
14320: if ($caller eq 'submission') {
14321: $turnindir = &mt('turned in');
14322: $turnindir =~ s/\W+/_/g;
14323: my %newhash = (
14324: 'turnindir' => $turnindir,
14325: );
14326: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14327: }
14328: }
14329: if ($turnindir ne '') {
14330: $path = '/'.$turnindir.'/';
14331: my ($multipart,$turnin,@pathitems);
14332: my $navmap = Apache::lonnavmaps::navmap->new();
14333: if (defined($navmap)) {
14334: my $mapres = $navmap->getResourceByUrl($map);
14335: if (ref($mapres)) {
14336: my $pcslist = $mapres->map_hierarchy();
14337: if ($pcslist ne '') {
14338: foreach my $pc (split(/,/,$pcslist)) {
14339: my $res = $navmap->getByMapPc($pc);
14340: if (ref($res)) {
14341: my $title = $res->compTitle();
14342: $title =~ s/\W+/_/g;
14343: if ($title ne '') {
1.1149 raeburn 14344: if (($pc > 1) && (length($title) > 12)) {
14345: $title = substr($title,0,12);
14346: }
1.1015 raeburn 14347: push(@pathitems,$title);
14348: }
14349: }
14350: }
14351: }
14352: my $maptitle = $mapres->compTitle();
14353: $maptitle =~ s/\W+/_/g;
14354: if ($maptitle ne '') {
1.1149 raeburn 14355: if (length($maptitle) > 12) {
14356: $maptitle = substr($maptitle,0,12);
14357: }
1.1015 raeburn 14358: push(@pathitems,$maptitle);
14359: }
14360: unless ($env{'request.state'} eq 'construct') {
14361: my $res = $navmap->getBySymb($symb);
14362: if (ref($res)) {
14363: my $partlist = $res->parts();
14364: my $totaluploads = 0;
14365: if (ref($partlist) eq 'ARRAY') {
14366: foreach my $part (@{$partlist}) {
14367: my @types = $res->responseType($part);
14368: my @ids = $res->responseIds($part);
14369: for (my $i=0; $i < scalar(@ids); $i++) {
14370: if ($types[$i] eq 'essay') {
14371: my $partid = $part.'_'.$ids[$i];
14372: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14373: $totaluploads ++;
14374: }
14375: }
14376: }
14377: }
14378: if ($totaluploads > 1) {
14379: $multiresp = 1;
14380: }
14381: }
14382: }
14383: }
14384: } else {
14385: return;
14386: }
14387: } else {
14388: return;
14389: }
14390: my $restitle=&Apache::lonnet::gettitle($symb);
14391: $restitle =~ s/\W+/_/g;
14392: if ($restitle eq '') {
14393: $restitle = ($resurl =~ m{/[^/]+$});
14394: if ($restitle eq '') {
14395: $restitle = time;
14396: }
14397: }
1.1149 raeburn 14398: if (length($restitle) > 12) {
14399: $restitle = substr($restitle,0,12);
14400: }
1.1015 raeburn 14401: push(@pathitems,$restitle);
14402: $path .= join('/',@pathitems);
14403: }
14404: return ($path,$multiresp);
14405: }
14406:
14407: =pod
14408:
1.464 albertel 14409: =back
1.41 ng 14410:
1.112 bowersj2 14411: =head1 CSV Upload/Handling functions
1.38 albertel 14412:
1.41 ng 14413: =over 4
14414:
1.648 raeburn 14415: =item * &upfile_store($r)
1.41 ng 14416:
14417: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14418: needs $env{'form.upfile'}
1.41 ng 14419: returns $datatoken to be put into hidden field
14420:
14421: =cut
1.31 albertel 14422:
14423: sub upfile_store {
14424: my $r=shift;
1.258 albertel 14425: $env{'form.upfile'}=~s/\r/\n/gs;
14426: $env{'form.upfile'}=~s/\f/\n/gs;
14427: $env{'form.upfile'}=~s/\n+/\n/gs;
14428: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14429:
1.1299 raeburn 14430: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14431: '_enroll_'.$env{'request.course.id'}.'_'.
14432: time.'_'.$$);
14433: return if ($datatoken eq '');
14434:
1.31 albertel 14435: {
1.158 raeburn 14436: my $datafile = $r->dir_config('lonDaemons').
14437: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14438: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14439: print $fh $env{'form.upfile'};
1.158 raeburn 14440: close($fh);
14441: }
1.31 albertel 14442: }
14443: return $datatoken;
14444: }
14445:
1.56 matthew 14446: =pod
14447:
1.1290 raeburn 14448: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14449:
14450: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14451: $datatoken is the name to assign to the temporary file.
1.258 albertel 14452: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14453:
14454: =cut
1.31 albertel 14455:
14456: sub load_tmp_file {
1.1290 raeburn 14457: my ($r,$datatoken) = @_;
14458: return if ($datatoken eq '');
1.31 albertel 14459: my @studentdata=();
14460: {
1.158 raeburn 14461: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14462: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14463: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14464: @studentdata=<$fh>;
14465: close($fh);
14466: }
1.31 albertel 14467: }
1.258 albertel 14468: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14469: }
14470:
1.1290 raeburn 14471: sub valid_datatoken {
14472: my ($datatoken) = @_;
1.1325 raeburn 14473: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14474: return $datatoken;
14475: }
14476: return;
14477: }
14478:
1.56 matthew 14479: =pod
14480:
1.648 raeburn 14481: =item * &upfile_record_sep()
1.41 ng 14482:
14483: Separate uploaded file into records
14484: returns array of records,
1.258 albertel 14485: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14486:
14487: =cut
1.31 albertel 14488:
14489: sub upfile_record_sep {
1.258 albertel 14490: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14491: } else {
1.248 albertel 14492: my @records;
1.258 albertel 14493: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14494: if ($line=~/^\s*$/) { next; }
14495: push(@records,$line);
14496: }
14497: return @records;
1.31 albertel 14498: }
14499: }
14500:
1.56 matthew 14501: =pod
14502:
1.648 raeburn 14503: =item * &record_sep($record)
1.41 ng 14504:
1.258 albertel 14505: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14506:
14507: =cut
14508:
1.263 www 14509: sub takeleft {
14510: my $index=shift;
14511: return substr('0000'.$index,-4,4);
14512: }
14513:
1.31 albertel 14514: sub record_sep {
14515: my $record=shift;
14516: my %components=();
1.258 albertel 14517: if ($env{'form.upfiletype'} eq 'xml') {
14518: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14519: my $i=0;
1.356 albertel 14520: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14521: $field=~s/^(\"|\')//;
14522: $field=~s/(\"|\')$//;
1.263 www 14523: $components{&takeleft($i)}=$field;
1.31 albertel 14524: $i++;
14525: }
1.258 albertel 14526: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14527: my $i=0;
1.356 albertel 14528: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14529: $field=~s/^(\"|\')//;
14530: $field=~s/(\"|\')$//;
1.263 www 14531: $components{&takeleft($i)}=$field;
1.31 albertel 14532: $i++;
14533: }
14534: } else {
1.561 www 14535: my $separator=',';
1.480 banghart 14536: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14537: $separator=';';
1.480 banghart 14538: }
1.31 albertel 14539: my $i=0;
1.561 www 14540: # the character we are looking for to indicate the end of a quote or a record
14541: my $looking_for=$separator;
14542: # do not add the characters to the fields
14543: my $ignore=0;
14544: # we just encountered a separator (or the beginning of the record)
14545: my $just_found_separator=1;
14546: # store the field we are working on here
14547: my $field='';
14548: # work our way through all characters in record
14549: foreach my $character ($record=~/(.)/g) {
14550: if ($character eq $looking_for) {
14551: if ($character ne $separator) {
14552: # Found the end of a quote, again looking for separator
14553: $looking_for=$separator;
14554: $ignore=1;
14555: } else {
14556: # Found a separator, store away what we got
14557: $components{&takeleft($i)}=$field;
14558: $i++;
14559: $just_found_separator=1;
14560: $ignore=0;
14561: $field='';
14562: }
14563: next;
14564: }
14565: # single or double quotation marks after a separator indicate beginning of a quote
14566: # we are now looking for the end of the quote and need to ignore separators
14567: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14568: $looking_for=$character;
14569: next;
14570: }
14571: # ignore would be true after we reached the end of a quote
14572: if ($ignore) { next; }
14573: if (($just_found_separator) && ($character=~/\s/)) { next; }
14574: $field.=$character;
14575: $just_found_separator=0;
1.31 albertel 14576: }
1.561 www 14577: # catch the very last entry, since we never encountered the separator
14578: $components{&takeleft($i)}=$field;
1.31 albertel 14579: }
14580: return %components;
14581: }
14582:
1.144 matthew 14583: ######################################################
14584: ######################################################
14585:
1.56 matthew 14586: =pod
14587:
1.648 raeburn 14588: =item * &upfile_select_html()
1.41 ng 14589:
1.144 matthew 14590: Return HTML code to select a file from the users machine and specify
14591: the file type.
1.41 ng 14592:
14593: =cut
14594:
1.144 matthew 14595: ######################################################
14596: ######################################################
1.31 albertel 14597: sub upfile_select_html {
1.144 matthew 14598: my %Types = (
14599: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14600: semisv => &mt('Semicolon separated values'),
1.144 matthew 14601: space => &mt('Space separated'),
14602: tab => &mt('Tabulator separated'),
14603: # xml => &mt('HTML/XML'),
14604: );
14605: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14606: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14607: foreach my $type (sort(keys(%Types))) {
14608: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14609: }
14610: $Str .= "</select>\n";
14611: return $Str;
1.31 albertel 14612: }
14613:
1.301 albertel 14614: sub get_samples {
14615: my ($records,$toget) = @_;
14616: my @samples=({});
14617: my $got=0;
14618: foreach my $rec (@$records) {
14619: my %temp = &record_sep($rec);
14620: if (! grep(/\S/, values(%temp))) { next; }
14621: if (%temp) {
14622: $samples[$got]=\%temp;
14623: $got++;
14624: if ($got == $toget) { last; }
14625: }
14626: }
14627: return \@samples;
14628: }
14629:
1.144 matthew 14630: ######################################################
14631: ######################################################
14632:
1.56 matthew 14633: =pod
14634:
1.648 raeburn 14635: =item * &csv_print_samples($r,$records)
1.41 ng 14636:
14637: Prints a table of sample values from each column uploaded $r is an
14638: Apache Request ref, $records is an arrayref from
14639: &Apache::loncommon::upfile_record_sep
14640:
14641: =cut
14642:
1.144 matthew 14643: ######################################################
14644: ######################################################
1.31 albertel 14645: sub csv_print_samples {
14646: my ($r,$records) = @_;
1.662 bisitz 14647: my $samples = &get_samples($records,5);
1.301 albertel 14648:
1.594 raeburn 14649: $r->print(&mt('Samples').'<br />'.&start_data_table().
14650: &start_data_table_header_row());
1.356 albertel 14651: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14652: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14653: $r->print(&end_data_table_header_row());
1.301 albertel 14654: foreach my $hash (@$samples) {
1.594 raeburn 14655: $r->print(&start_data_table_row());
1.356 albertel 14656: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14657: $r->print('<td>');
1.356 albertel 14658: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14659: $r->print('</td>');
14660: }
1.594 raeburn 14661: $r->print(&end_data_table_row());
1.31 albertel 14662: }
1.594 raeburn 14663: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14664: }
14665:
1.144 matthew 14666: ######################################################
14667: ######################################################
14668:
1.56 matthew 14669: =pod
14670:
1.648 raeburn 14671: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14672:
14673: Prints a table to create associations between values and table columns.
1.144 matthew 14674:
1.41 ng 14675: $r is an Apache Request ref,
14676: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14677: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14678:
14679: =cut
14680:
1.144 matthew 14681: ######################################################
14682: ######################################################
1.31 albertel 14683: sub csv_print_select_table {
14684: my ($r,$records,$d) = @_;
1.301 albertel 14685: my $i=0;
14686: my $samples = &get_samples($records,1);
1.144 matthew 14687: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14688: &start_data_table().&start_data_table_header_row().
1.144 matthew 14689: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14690: '<th>'.&mt('Column').'</th>'.
14691: &end_data_table_header_row()."\n");
1.356 albertel 14692: foreach my $array_ref (@$d) {
14693: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14694: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14695:
1.875 bisitz 14696: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14697: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14698: $r->print('<option value="none"></option>');
1.356 albertel 14699: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14700: $r->print('<option value="'.$sample.'"'.
14701: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14702: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14703: }
1.594 raeburn 14704: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14705: $i++;
14706: }
1.594 raeburn 14707: $r->print(&end_data_table());
1.31 albertel 14708: $i--;
14709: return $i;
14710: }
1.56 matthew 14711:
1.144 matthew 14712: ######################################################
14713: ######################################################
14714:
1.56 matthew 14715: =pod
1.31 albertel 14716:
1.648 raeburn 14717: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14718:
14719: Prints a table of sample values from the upload and can make associate samples to internal names.
14720:
14721: $r is an Apache Request ref,
14722: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14723: $d is an array of 2 element arrays (internal name, displayed name)
14724:
14725: =cut
14726:
1.144 matthew 14727: ######################################################
14728: ######################################################
1.31 albertel 14729: sub csv_samples_select_table {
14730: my ($r,$records,$d) = @_;
14731: my $i=0;
1.144 matthew 14732: #
1.662 bisitz 14733: my $max_samples = 5;
14734: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14735: $r->print(&start_data_table().
14736: &start_data_table_header_row().'<th>'.
14737: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14738: &end_data_table_header_row());
1.301 albertel 14739:
14740: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14741: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14742: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14743: foreach my $option (@$d) {
14744: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14745: $r->print('<option value="'.$value.'"'.
1.253 albertel 14746: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14747: $display.'</option>');
1.31 albertel 14748: }
14749: $r->print('</select></td><td>');
1.662 bisitz 14750: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14751: if (defined($samples->[$line]{$key})) {
14752: $r->print($samples->[$line]{$key}."<br />\n");
14753: }
14754: }
1.594 raeburn 14755: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14756: $i++;
14757: }
1.594 raeburn 14758: $r->print(&end_data_table());
1.31 albertel 14759: $i--;
14760: return($i);
1.115 matthew 14761: }
14762:
1.144 matthew 14763: ######################################################
14764: ######################################################
14765:
1.115 matthew 14766: =pod
14767:
1.648 raeburn 14768: =item * &clean_excel_name($name)
1.115 matthew 14769:
14770: Returns a replacement for $name which does not contain any illegal characters.
14771:
14772: =cut
14773:
1.144 matthew 14774: ######################################################
14775: ######################################################
1.115 matthew 14776: sub clean_excel_name {
14777: my ($name) = @_;
14778: $name =~ s/[:\*\?\/\\]//g;
14779: if (length($name) > 31) {
14780: $name = substr($name,0,31);
14781: }
14782: return $name;
1.25 albertel 14783: }
1.84 albertel 14784:
1.85 albertel 14785: =pod
14786:
1.648 raeburn 14787: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14788:
14789: Returns either 1 or undef
14790:
14791: 1 if the part is to be hidden, undef if it is to be shown
14792:
14793: Arguments are:
14794:
14795: $id the id of the part to be checked
14796: $symb, optional the symb of the resource to check
14797: $udom, optional the domain of the user to check for
14798: $uname, optional the username of the user to check for
14799:
14800: =cut
1.84 albertel 14801:
14802: sub check_if_partid_hidden {
14803: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14804: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14805: $symb,$udom,$uname);
1.141 albertel 14806: my $truth=1;
14807: #if the string starts with !, then the list is the list to show not hide
14808: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14809: my @hiddenlist=split(/,/,$hiddenparts);
14810: foreach my $checkid (@hiddenlist) {
1.141 albertel 14811: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14812: }
1.141 albertel 14813: return !$truth;
1.84 albertel 14814: }
1.127 matthew 14815:
1.138 matthew 14816:
14817: ############################################################
14818: ############################################################
14819:
14820: =pod
14821:
1.157 matthew 14822: =back
14823:
1.138 matthew 14824: =head1 cgi-bin script and graphing routines
14825:
1.157 matthew 14826: =over 4
14827:
1.648 raeburn 14828: =item * &get_cgi_id()
1.138 matthew 14829:
14830: Inputs: none
14831:
14832: Returns an id which can be used to pass environment variables
14833: to various cgi-bin scripts. These environment variables will
14834: be removed from the users environment after a given time by
14835: the routine &Apache::lonnet::transfer_profile_to_env.
14836:
14837: =cut
14838:
14839: ############################################################
14840: ############################################################
1.152 albertel 14841: my $uniq=0;
1.136 matthew 14842: sub get_cgi_id {
1.154 albertel 14843: $uniq=($uniq+1)%100000;
1.280 albertel 14844: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14845: }
14846:
1.127 matthew 14847: ############################################################
14848: ############################################################
14849:
14850: =pod
14851:
1.648 raeburn 14852: =item * &DrawBarGraph()
1.127 matthew 14853:
1.138 matthew 14854: Facilitates the plotting of data in a (stacked) bar graph.
14855: Puts plot definition data into the users environment in order for
14856: graph.png to plot it. Returns an <img> tag for the plot.
14857: The bars on the plot are labeled '1','2',...,'n'.
14858:
14859: Inputs:
14860:
14861: =over 4
14862:
14863: =item $Title: string, the title of the plot
14864:
14865: =item $xlabel: string, text describing the X-axis of the plot
14866:
14867: =item $ylabel: string, text describing the Y-axis of the plot
14868:
14869: =item $Max: scalar, the maximum Y value to use in the plot
14870: If $Max is < any data point, the graph will not be rendered.
14871:
1.140 matthew 14872: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14873: they are plotted. If undefined, default values will be used.
14874:
1.178 matthew 14875: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14876:
1.138 matthew 14877: =item @Values: An array of array references. Each array reference holds data
14878: to be plotted in a stacked bar chart.
14879:
1.239 matthew 14880: =item If the final element of @Values is a hash reference the key/value
14881: pairs will be added to the graph definition.
14882:
1.138 matthew 14883: =back
14884:
14885: Returns:
14886:
14887: An <img> tag which references graph.png and the appropriate identifying
14888: information for the plot.
14889:
1.127 matthew 14890: =cut
14891:
14892: ############################################################
14893: ############################################################
1.134 matthew 14894: sub DrawBarGraph {
1.178 matthew 14895: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14896: #
14897: if (! defined($colors)) {
14898: $colors = ['#33ff00',
14899: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14900: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14901: ];
14902: }
1.228 matthew 14903: my $extra_settings = {};
14904: if (ref($Values[-1]) eq 'HASH') {
14905: $extra_settings = pop(@Values);
14906: }
1.127 matthew 14907: #
1.136 matthew 14908: my $identifier = &get_cgi_id();
14909: my $id = 'cgi.'.$identifier;
1.129 matthew 14910: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14911: return '';
14912: }
1.225 matthew 14913: #
14914: my @Labels;
14915: if (defined($labels)) {
14916: @Labels = @$labels;
14917: } else {
14918: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14919: push(@Labels,$i+1);
1.225 matthew 14920: }
14921: }
14922: #
1.129 matthew 14923: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14924: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14925: my %ValuesHash;
14926: my $NumSets=1;
14927: foreach my $array (@Values) {
14928: next if (! ref($array));
1.136 matthew 14929: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14930: join(',',@$array);
1.129 matthew 14931: }
1.127 matthew 14932: #
1.136 matthew 14933: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14934: if ($NumBars < 3) {
14935: $width = 120+$NumBars*32;
1.220 matthew 14936: $xskip = 1;
1.225 matthew 14937: $bar_width = 30;
14938: } elsif ($NumBars < 5) {
14939: $width = 120+$NumBars*20;
14940: $xskip = 1;
14941: $bar_width = 20;
1.220 matthew 14942: } elsif ($NumBars < 10) {
1.136 matthew 14943: $width = 120+$NumBars*15;
14944: $xskip = 1;
14945: $bar_width = 15;
14946: } elsif ($NumBars <= 25) {
14947: $width = 120+$NumBars*11;
14948: $xskip = 5;
14949: $bar_width = 8;
14950: } elsif ($NumBars <= 50) {
14951: $width = 120+$NumBars*8;
14952: $xskip = 5;
14953: $bar_width = 4;
14954: } else {
14955: $width = 120+$NumBars*8;
14956: $xskip = 5;
14957: $bar_width = 4;
14958: }
14959: #
1.137 matthew 14960: $Max = 1 if ($Max < 1);
14961: if ( int($Max) < $Max ) {
14962: $Max++;
14963: $Max = int($Max);
14964: }
1.127 matthew 14965: $Title = '' if (! defined($Title));
14966: $xlabel = '' if (! defined($xlabel));
14967: $ylabel = '' if (! defined($ylabel));
1.369 www 14968: $ValuesHash{$id.'.title'} = &escape($Title);
14969: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14970: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14971: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14972: $ValuesHash{$id.'.NumBars'} = $NumBars;
14973: $ValuesHash{$id.'.NumSets'} = $NumSets;
14974: $ValuesHash{$id.'.PlotType'} = 'bar';
14975: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14976: $ValuesHash{$id.'.height'} = $height;
14977: $ValuesHash{$id.'.width'} = $width;
14978: $ValuesHash{$id.'.xskip'} = $xskip;
14979: $ValuesHash{$id.'.bar_width'} = $bar_width;
14980: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14981: #
1.228 matthew 14982: # Deal with other parameters
14983: while (my ($key,$value) = each(%$extra_settings)) {
14984: $ValuesHash{$id.'.'.$key} = $value;
14985: }
14986: #
1.646 raeburn 14987: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14988: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14989: }
14990:
14991: ############################################################
14992: ############################################################
14993:
14994: =pod
14995:
1.648 raeburn 14996: =item * &DrawXYGraph()
1.137 matthew 14997:
1.138 matthew 14998: Facilitates the plotting of data in an XY graph.
14999: Puts plot definition data into the users environment in order for
15000: graph.png to plot it. Returns an <img> tag for the plot.
15001:
15002: Inputs:
15003:
15004: =over 4
15005:
15006: =item $Title: string, the title of the plot
15007:
15008: =item $xlabel: string, text describing the X-axis of the plot
15009:
15010: =item $ylabel: string, text describing the Y-axis of the plot
15011:
15012: =item $Max: scalar, the maximum Y value to use in the plot
15013: If $Max is < any data point, the graph will not be rendered.
15014:
15015: =item $colors: Array ref containing the hex color codes for the data to be
15016: plotted in. If undefined, default values will be used.
15017:
15018: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15019:
15020: =item $Ydata: Array ref containing Array refs.
1.185 www 15021: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15022:
15023: =item %Values: hash indicating or overriding any default values which are
15024: passed to graph.png.
15025: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15026:
15027: =back
15028:
15029: Returns:
15030:
15031: An <img> tag which references graph.png and the appropriate identifying
15032: information for the plot.
15033:
1.137 matthew 15034: =cut
15035:
15036: ############################################################
15037: ############################################################
15038: sub DrawXYGraph {
15039: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15040: #
15041: # Create the identifier for the graph
15042: my $identifier = &get_cgi_id();
15043: my $id = 'cgi.'.$identifier;
15044: #
15045: $Title = '' if (! defined($Title));
15046: $xlabel = '' if (! defined($xlabel));
15047: $ylabel = '' if (! defined($ylabel));
15048: my %ValuesHash =
15049: (
1.369 www 15050: $id.'.title' => &escape($Title),
15051: $id.'.xlabel' => &escape($xlabel),
15052: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15053: $id.'.y_max_value'=> $Max,
15054: $id.'.labels' => join(',',@$Xlabels),
15055: $id.'.PlotType' => 'XY',
15056: );
15057: #
15058: if (defined($colors) && ref($colors) eq 'ARRAY') {
15059: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15060: }
15061: #
15062: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15063: return '';
15064: }
15065: my $NumSets=1;
1.138 matthew 15066: foreach my $array (@{$Ydata}){
1.137 matthew 15067: next if (! ref($array));
15068: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15069: }
1.138 matthew 15070: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15071: #
15072: # Deal with other parameters
15073: while (my ($key,$value) = each(%Values)) {
15074: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15075: }
15076: #
1.646 raeburn 15077: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15078: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15079: }
15080:
15081: ############################################################
15082: ############################################################
15083:
15084: =pod
15085:
1.648 raeburn 15086: =item * &DrawXYYGraph()
1.138 matthew 15087:
15088: Facilitates the plotting of data in an XY graph with two Y axes.
15089: Puts plot definition data into the users environment in order for
15090: graph.png to plot it. Returns an <img> tag for the plot.
15091:
15092: Inputs:
15093:
15094: =over 4
15095:
15096: =item $Title: string, the title of the plot
15097:
15098: =item $xlabel: string, text describing the X-axis of the plot
15099:
15100: =item $ylabel: string, text describing the Y-axis of the plot
15101:
15102: =item $colors: Array ref containing the hex color codes for the data to be
15103: plotted in. If undefined, default values will be used.
15104:
15105: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15106:
15107: =item $Ydata1: The first data set
15108:
15109: =item $Min1: The minimum value of the left Y-axis
15110:
15111: =item $Max1: The maximum value of the left Y-axis
15112:
15113: =item $Ydata2: The second data set
15114:
15115: =item $Min2: The minimum value of the right Y-axis
15116:
15117: =item $Max2: The maximum value of the left Y-axis
15118:
15119: =item %Values: hash indicating or overriding any default values which are
15120: passed to graph.png.
15121: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15122:
15123: =back
15124:
15125: Returns:
15126:
15127: An <img> tag which references graph.png and the appropriate identifying
15128: information for the plot.
1.136 matthew 15129:
15130: =cut
15131:
15132: ############################################################
15133: ############################################################
1.137 matthew 15134: sub DrawXYYGraph {
15135: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15136: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15137: #
15138: # Create the identifier for the graph
15139: my $identifier = &get_cgi_id();
15140: my $id = 'cgi.'.$identifier;
15141: #
15142: $Title = '' if (! defined($Title));
15143: $xlabel = '' if (! defined($xlabel));
15144: $ylabel = '' if (! defined($ylabel));
15145: my %ValuesHash =
15146: (
1.369 www 15147: $id.'.title' => &escape($Title),
15148: $id.'.xlabel' => &escape($xlabel),
15149: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15150: $id.'.labels' => join(',',@$Xlabels),
15151: $id.'.PlotType' => 'XY',
15152: $id.'.NumSets' => 2,
1.137 matthew 15153: $id.'.two_axes' => 1,
15154: $id.'.y1_max_value' => $Max1,
15155: $id.'.y1_min_value' => $Min1,
15156: $id.'.y2_max_value' => $Max2,
15157: $id.'.y2_min_value' => $Min2,
1.136 matthew 15158: );
15159: #
1.137 matthew 15160: if (defined($colors) && ref($colors) eq 'ARRAY') {
15161: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15162: }
15163: #
15164: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15165: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15166: return '';
15167: }
15168: my $NumSets=1;
1.137 matthew 15169: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15170: next if (! ref($array));
15171: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15172: }
15173: #
15174: # Deal with other parameters
15175: while (my ($key,$value) = each(%Values)) {
15176: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15177: }
15178: #
1.646 raeburn 15179: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15180: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15181: }
15182:
15183: ############################################################
15184: ############################################################
15185:
15186: =pod
15187:
1.157 matthew 15188: =back
15189:
1.139 matthew 15190: =head1 Statistics helper routines?
15191:
15192: Bad place for them but what the hell.
15193:
1.157 matthew 15194: =over 4
15195:
1.648 raeburn 15196: =item * &chartlink()
1.139 matthew 15197:
15198: Returns a link to the chart for a specific student.
15199:
15200: Inputs:
15201:
15202: =over 4
15203:
15204: =item $linktext: The text of the link
15205:
15206: =item $sname: The students username
15207:
15208: =item $sdomain: The students domain
15209:
15210: =back
15211:
1.157 matthew 15212: =back
15213:
1.139 matthew 15214: =cut
15215:
15216: ############################################################
15217: ############################################################
15218: sub chartlink {
15219: my ($linktext, $sname, $sdomain) = @_;
15220: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15221: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15222: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15223: '">'.$linktext.'</a>';
1.153 matthew 15224: }
15225:
15226: #######################################################
15227: #######################################################
15228:
15229: =pod
15230:
15231: =head1 Course Environment Routines
1.157 matthew 15232:
15233: =over 4
1.153 matthew 15234:
1.648 raeburn 15235: =item * &restore_course_settings()
1.153 matthew 15236:
1.648 raeburn 15237: =item * &store_course_settings()
1.153 matthew 15238:
15239: Restores/Store indicated form parameters from the course environment.
15240: Will not overwrite existing values of the form parameters.
15241:
15242: Inputs:
15243: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15244:
15245: a hash ref describing the data to be stored. For example:
15246:
15247: %Save_Parameters = ('Status' => 'scalar',
15248: 'chartoutputmode' => 'scalar',
15249: 'chartoutputdata' => 'scalar',
15250: 'Section' => 'array',
1.373 raeburn 15251: 'Group' => 'array',
1.153 matthew 15252: 'StudentData' => 'array',
15253: 'Maps' => 'array');
15254:
15255: Returns: both routines return nothing
15256:
1.631 raeburn 15257: =back
15258:
1.153 matthew 15259: =cut
15260:
15261: #######################################################
15262: #######################################################
15263: sub store_course_settings {
1.496 albertel 15264: return &store_settings($env{'request.course.id'},@_);
15265: }
15266:
15267: sub store_settings {
1.153 matthew 15268: # save to the environment
15269: # appenv the same items, just to be safe
1.300 albertel 15270: my $udom = $env{'user.domain'};
15271: my $uname = $env{'user.name'};
1.496 albertel 15272: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15273: my %SaveHash;
15274: my %AppHash;
15275: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15276: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15277: my $envname = 'environment.'.$basename;
1.258 albertel 15278: if (exists($env{'form.'.$setting})) {
1.153 matthew 15279: # Save this value away
15280: if ($type eq 'scalar' &&
1.258 albertel 15281: (! exists($env{$envname}) ||
15282: $env{$envname} ne $env{'form.'.$setting})) {
15283: $SaveHash{$basename} = $env{'form.'.$setting};
15284: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15285: } elsif ($type eq 'array') {
15286: my $stored_form;
1.258 albertel 15287: if (ref($env{'form.'.$setting})) {
1.153 matthew 15288: $stored_form = join(',',
15289: map {
1.369 www 15290: &escape($_);
1.258 albertel 15291: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15292: } else {
15293: $stored_form =
1.369 www 15294: &escape($env{'form.'.$setting});
1.153 matthew 15295: }
15296: # Determine if the array contents are the same.
1.258 albertel 15297: if ($stored_form ne $env{$envname}) {
1.153 matthew 15298: $SaveHash{$basename} = $stored_form;
15299: $AppHash{$envname} = $stored_form;
15300: }
15301: }
15302: }
15303: }
15304: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15305: $udom,$uname);
1.153 matthew 15306: if ($put_result !~ /^(ok|delayed)/) {
15307: &Apache::lonnet::logthis('unable to save form parameters, '.
15308: 'got error:'.$put_result);
15309: }
15310: # Make sure these settings stick around in this session, too
1.646 raeburn 15311: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15312: return;
15313: }
15314:
15315: sub restore_course_settings {
1.499 albertel 15316: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15317: }
15318:
15319: sub restore_settings {
15320: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15321: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15322: next if (exists($env{'form.'.$setting}));
1.496 albertel 15323: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15324: '.'.$setting;
1.258 albertel 15325: if (exists($env{$envname})) {
1.153 matthew 15326: if ($type eq 'scalar') {
1.258 albertel 15327: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15328: } elsif ($type eq 'array') {
1.258 albertel 15329: $env{'form.'.$setting} = [
1.153 matthew 15330: map {
1.369 www 15331: &unescape($_);
1.258 albertel 15332: } split(',',$env{$envname})
1.153 matthew 15333: ];
15334: }
15335: }
15336: }
1.127 matthew 15337: }
15338:
1.618 raeburn 15339: #######################################################
15340: #######################################################
15341:
15342: =pod
15343:
15344: =head1 Domain E-mail Routines
15345:
15346: =over 4
15347:
1.648 raeburn 15348: =item * &build_recipient_list()
1.618 raeburn 15349:
1.1144 raeburn 15350: Build recipient lists for following types of e-mail:
1.766 raeburn 15351: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15352: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15353: module change checking, student/employee ID conflict checks, as
15354: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15355: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15356:
15357: Inputs:
1.619 raeburn 15358: defmail (scalar - email address of default recipient),
1.1144 raeburn 15359: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15360: requestsmail, updatesmail, or idconflictsmail).
15361:
1.619 raeburn 15362: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15363:
1.619 raeburn 15364: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15365: i.e., predates configuration by DC via domainprefs.pm
15366:
15367: $requname username of requester (if mailing type is helpdeskmail)
15368:
15369: $requdom domain of requester (if mailing type is helpdeskmail)
15370:
15371: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15372:
1.618 raeburn 15373:
1.655 raeburn 15374: Returns: comma separated list of addresses to which to send e-mail.
15375:
15376: =back
1.618 raeburn 15377:
15378: =cut
15379:
15380: ############################################################
15381: ############################################################
15382: sub build_recipient_list {
1.1297 raeburn 15383: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15384: my @recipients;
1.1270 raeburn 15385: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15386: my %domconfig =
1.1270 raeburn 15387: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15388: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15389: if (exists($domconfig{'contacts'}{$mailing})) {
15390: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15391: my @contacts = ('adminemail','supportemail');
15392: foreach my $item (@contacts) {
15393: if ($domconfig{'contacts'}{$mailing}{$item}) {
15394: my $addr = $domconfig{'contacts'}{$item};
15395: if (!grep(/^\Q$addr\E$/,@recipients)) {
15396: push(@recipients,$addr);
15397: }
1.619 raeburn 15398: }
1.1270 raeburn 15399: }
15400: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15401: if ($mailing eq 'helpdeskmail') {
15402: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15403: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15404: my @ok_bccs;
15405: foreach my $bcc (@bccs) {
15406: $bcc =~ s/^\s+//g;
15407: $bcc =~ s/\s+$//g;
15408: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15409: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15410: push(@ok_bccs,$bcc);
15411: }
15412: }
15413: }
15414: if (@ok_bccs > 0) {
15415: $allbcc = join(', ',@ok_bccs);
15416: }
15417: }
15418: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15419: }
15420: }
1.766 raeburn 15421: } elsif ($origmail ne '') {
1.1270 raeburn 15422: $lastresort = $origmail;
1.618 raeburn 15423: }
1.1297 raeburn 15424: if ($mailing eq 'helpdeskmail') {
15425: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15426: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15427: my ($inststatus,$inststatus_checked);
15428: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15429: ($env{'user.domain'} ne 'public')) {
15430: $inststatus_checked = 1;
15431: $inststatus = $env{'environment.inststatus'};
15432: }
15433: unless ($inststatus_checked) {
15434: if (($requname ne '') && ($requdom ne '')) {
15435: if (($requname =~ /^$match_username$/) &&
15436: ($requdom =~ /^$match_domain$/) &&
15437: (&Apache::lonnet::domain($requdom))) {
15438: my $requhome = &Apache::lonnet::homeserver($requname,
15439: $requdom);
15440: unless ($requhome eq 'no_host') {
15441: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15442: $inststatus = $userenv{'inststatus'};
15443: $inststatus_checked = 1;
15444: }
15445: }
15446: }
15447: }
15448: unless ($inststatus_checked) {
15449: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15450: my %srch = (srchby => 'email',
15451: srchdomain => $defdom,
15452: srchterm => $reqemail,
15453: srchtype => 'exact');
15454: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15455: foreach my $uname (keys(%srch_results)) {
15456: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15457: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15458: $inststatus_checked = 1;
15459: last;
15460: }
15461: }
15462: unless ($inststatus_checked) {
15463: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15464: if ($dirsrchres eq 'ok') {
15465: foreach my $uname (keys(%srch_results)) {
15466: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15467: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15468: $inststatus_checked = 1;
15469: last;
15470: }
15471: }
15472: }
15473: }
15474: }
15475: }
15476: if ($inststatus ne '') {
15477: foreach my $status (split(/\:/,$inststatus)) {
15478: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15479: my @contacts = ('adminemail','supportemail');
15480: foreach my $item (@contacts) {
15481: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15482: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15483: if (!grep(/^\Q$addr\E$/,@recipients)) {
15484: push(@recipients,$addr);
15485: }
15486: }
15487: }
15488: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15489: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15490: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15491: my @ok_bccs;
15492: foreach my $bcc (@bccs) {
15493: $bcc =~ s/^\s+//g;
15494: $bcc =~ s/\s+$//g;
15495: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15496: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15497: push(@ok_bccs,$bcc);
15498: }
15499: }
15500: }
15501: if (@ok_bccs > 0) {
15502: $allbcc = join(', ',@ok_bccs);
15503: }
15504: }
15505: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15506: last;
15507: }
15508: }
15509: }
15510: }
15511: }
1.619 raeburn 15512: } elsif ($origmail ne '') {
1.1270 raeburn 15513: $lastresort = $origmail;
15514: }
1.1297 raeburn 15515: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15516: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15517: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15518: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15519: my %what = (
15520: perlvar => 1,
15521: );
15522: my $primary = &Apache::lonnet::domain($defdom,'primary');
15523: if ($primary) {
15524: my $gotaddr;
15525: my ($result,$returnhash) =
15526: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15527: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15528: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15529: $lastresort = $returnhash->{'lonSupportEMail'};
15530: $gotaddr = 1;
15531: }
15532: }
15533: unless ($gotaddr) {
15534: my $uintdom = &Apache::lonnet::internet_dom($primary);
15535: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15536: unless ($uintdom eq $intdom) {
15537: my %domconfig =
15538: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15539: if (ref($domconfig{'contacts'}) eq 'HASH') {
15540: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15541: my @contacts = ('adminemail','supportemail');
15542: foreach my $item (@contacts) {
15543: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15544: my $addr = $domconfig{'contacts'}{$item};
15545: if (!grep(/^\Q$addr\E$/,@recipients)) {
15546: push(@recipients,$addr);
15547: }
15548: }
15549: }
15550: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15551: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15552: }
15553: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15554: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15555: my @ok_bccs;
15556: foreach my $bcc (@bccs) {
15557: $bcc =~ s/^\s+//g;
15558: $bcc =~ s/\s+$//g;
15559: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15560: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15561: push(@ok_bccs,$bcc);
15562: }
15563: }
15564: }
15565: if (@ok_bccs > 0) {
15566: $allbcc = join(', ',@ok_bccs);
15567: }
15568: }
15569: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15570: }
15571: }
15572: }
15573: }
15574: }
15575: }
1.618 raeburn 15576: }
1.688 raeburn 15577: if (defined($defmail)) {
15578: if ($defmail ne '') {
15579: push(@recipients,$defmail);
15580: }
1.618 raeburn 15581: }
15582: if ($otheremails) {
1.619 raeburn 15583: my @others;
15584: if ($otheremails =~ /,/) {
15585: @others = split(/,/,$otheremails);
1.618 raeburn 15586: } else {
1.619 raeburn 15587: push(@others,$otheremails);
15588: }
15589: foreach my $addr (@others) {
15590: if (!grep(/^\Q$addr\E$/,@recipients)) {
15591: push(@recipients,$addr);
15592: }
1.618 raeburn 15593: }
15594: }
1.1298 raeburn 15595: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15596: if ((!@recipients) && ($lastresort ne '')) {
15597: push(@recipients,$lastresort);
15598: }
15599: } elsif ($lastresort ne '') {
15600: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15601: push(@recipients,$lastresort);
15602: }
15603: }
1.1271 raeburn 15604: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15605: if (wantarray) {
15606: return ($recipientlist,$allbcc,$addtext);
15607: } else {
15608: return $recipientlist;
15609: }
1.618 raeburn 15610: }
15611:
1.127 matthew 15612: ############################################################
15613: ############################################################
1.154 albertel 15614:
1.655 raeburn 15615: =pod
15616:
1.1224 musolffc 15617: =over 4
15618:
1.1223 musolffc 15619: =item * &mime_email()
15620:
15621: Sends an email with a possible attachment
15622:
15623: Inputs:
15624:
15625: =over 4
15626:
15627: from - Sender's email address
15628:
1.1343 raeburn 15629: replyto - Reply-To email address
15630:
1.1223 musolffc 15631: to - Email address of recipient
15632:
15633: subject - Subject of email
15634:
15635: body - Body of email
15636:
15637: cc_string - Carbon copy email address
15638:
15639: bcc - Blind carbon copy email address
15640:
15641: attachment_path - Path of file to be attached
15642:
15643: file_name - Name of file to be attached
15644:
15645: attachment_text - The body of an attachment of type "TEXT"
15646:
15647: =back
15648:
15649: =back
15650:
15651: =cut
15652:
15653: ############################################################
15654: ############################################################
15655:
15656: sub mime_email {
1.1343 raeburn 15657: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15658: $file_name,$attachment_text) = @_;
15659:
1.1223 musolffc 15660: my $msg = MIME::Lite->new(
15661: From => $from,
15662: To => $to,
15663: Subject => $subject,
15664: Type =>'TEXT',
15665: Data => $body,
15666: );
1.1343 raeburn 15667: if ($replyto ne '') {
15668: $msg->add("Reply-To" => $replyto);
15669: }
1.1223 musolffc 15670: if ($cc_string ne '') {
15671: $msg->add("Cc" => $cc_string);
15672: }
15673: if ($bcc ne '') {
15674: $msg->add("Bcc" => $bcc);
15675: }
15676: $msg->attr("content-type" => "text/plain");
15677: $msg->attr("content-type.charset" => "UTF-8");
15678: # Attach file if given
15679: if ($attachment_path) {
15680: unless ($file_name) {
15681: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15682: }
15683: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15684: $msg->attach(Type => $type,
15685: Path => $attachment_path,
15686: Filename => $file_name
15687: );
15688: # Otherwise attach text if given
15689: } elsif ($attachment_text) {
15690: $msg->attach(Type => 'TEXT',
15691: Data => $attachment_text);
15692: }
15693: # Send it
15694: $msg->send('sendmail');
15695: }
15696:
15697: ############################################################
15698: ############################################################
15699:
15700: =pod
15701:
1.655 raeburn 15702: =head1 Course Catalog Routines
15703:
15704: =over 4
15705:
15706: =item * &gather_categories()
15707:
15708: Converts category definitions - keys of categories hash stored in
15709: coursecategories in configuration.db on the primary library server in a
15710: domain - to an array. Also generates javascript and idx hash used to
15711: generate Domain Coordinator interface for editing Course Categories.
15712:
15713: Inputs:
1.663 raeburn 15714:
1.655 raeburn 15715: categories (reference to hash of category definitions).
1.663 raeburn 15716:
1.655 raeburn 15717: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15718: categories and subcategories).
1.663 raeburn 15719:
1.655 raeburn 15720: idx (reference to hash of counters used in Domain Coordinator interface for
15721: editing Course Categories).
1.663 raeburn 15722:
1.655 raeburn 15723: jsarray (reference to array of categories used to create Javascript arrays for
15724: Domain Coordinator interface for editing Course Categories).
15725:
15726: Returns: nothing
15727:
15728: Side effects: populates cats, idx and jsarray.
15729:
15730: =cut
15731:
15732: sub gather_categories {
15733: my ($categories,$cats,$idx,$jsarray) = @_;
15734: my %counters;
15735: my $num = 0;
15736: foreach my $item (keys(%{$categories})) {
15737: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15738: if ($container eq '' && $depth == 0) {
15739: $cats->[$depth][$categories->{$item}] = $cat;
15740: } else {
15741: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15742: }
15743: my ($escitem,$tail) = split(/:/,$item,2);
15744: if ($counters{$tail} eq '') {
15745: $counters{$tail} = $num;
15746: $num ++;
15747: }
15748: if (ref($idx) eq 'HASH') {
15749: $idx->{$item} = $counters{$tail};
15750: }
15751: if (ref($jsarray) eq 'ARRAY') {
15752: push(@{$jsarray->[$counters{$tail}]},$item);
15753: }
15754: }
15755: return;
15756: }
15757:
15758: =pod
15759:
15760: =item * &extract_categories()
15761:
15762: Used to generate breadcrumb trails for course categories.
15763:
15764: Inputs:
1.663 raeburn 15765:
1.655 raeburn 15766: categories (reference to hash of category definitions).
1.663 raeburn 15767:
1.655 raeburn 15768: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15769: categories and subcategories).
1.663 raeburn 15770:
1.655 raeburn 15771: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15772:
1.655 raeburn 15773: allitems (reference to hash - key is category key
15774: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15775:
1.655 raeburn 15776: idx (reference to hash of counters used in Domain Coordinator interface for
15777: editing Course Categories).
1.663 raeburn 15778:
1.655 raeburn 15779: jsarray (reference to array of categories used to create Javascript arrays for
15780: Domain Coordinator interface for editing Course Categories).
15781:
1.665 raeburn 15782: subcats (reference to hash of arrays containing all subcategories within each
15783: category, -recursive)
15784:
1.1321 raeburn 15785: maxd (reference to hash used to hold max depth for all top-level categories).
15786:
1.655 raeburn 15787: Returns: nothing
15788:
15789: Side effects: populates trails and allitems hash references.
15790:
15791: =cut
15792:
15793: sub extract_categories {
1.1321 raeburn 15794: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15795: if (ref($categories) eq 'HASH') {
15796: &gather_categories($categories,$cats,$idx,$jsarray);
15797: if (ref($cats->[0]) eq 'ARRAY') {
15798: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15799: my $name = $cats->[0][$i];
15800: my $item = &escape($name).'::0';
15801: my $trailstr;
15802: if ($name eq 'instcode') {
15803: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15804: } elsif ($name eq 'communities') {
15805: $trailstr = &mt('Communities');
1.1239 raeburn 15806: } elsif ($name eq 'placement') {
15807: $trailstr = &mt('Placement Tests');
1.655 raeburn 15808: } else {
15809: $trailstr = $name;
15810: }
15811: if ($allitems->{$item} eq '') {
15812: push(@{$trails},$trailstr);
15813: $allitems->{$item} = scalar(@{$trails})-1;
15814: }
15815: my @parents = ($name);
15816: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15817: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15818: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15819: if (ref($subcats) eq 'HASH') {
15820: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15821: }
1.1321 raeburn 15822: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15823: }
15824: } else {
15825: if (ref($subcats) eq 'HASH') {
15826: $subcats->{$item} = [];
1.655 raeburn 15827: }
1.1321 raeburn 15828: if (ref($maxd) eq 'HASH') {
15829: $maxd->{$name} = 1;
15830: }
1.655 raeburn 15831: }
15832: }
15833: }
15834: }
15835: return;
15836: }
15837:
15838: =pod
15839:
1.1162 raeburn 15840: =item * &recurse_categories()
1.655 raeburn 15841:
15842: Recursively used to generate breadcrumb trails for course categories.
15843:
15844: Inputs:
1.663 raeburn 15845:
1.655 raeburn 15846: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15847: categories and subcategories).
1.663 raeburn 15848:
1.655 raeburn 15849: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15850:
15851: category (current course category, for which breadcrumb trail is being generated).
15852:
15853: trails (reference to array of breadcrumb trails for each category).
15854:
1.655 raeburn 15855: allitems (reference to hash - key is category key
15856: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15857:
1.655 raeburn 15858: parents (array containing containers directories for current category,
15859: back to top level).
15860:
15861: Returns: nothing
15862:
15863: Side effects: populates trails and allitems hash references
15864:
15865: =cut
15866:
15867: sub recurse_categories {
1.1321 raeburn 15868: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15869: my $shallower = $depth - 1;
15870: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15871: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15872: my $name = $cats->[$depth]{$category}[$k];
15873: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15874: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15875: if ($allitems->{$item} eq '') {
15876: push(@{$trails},$trailstr);
15877: $allitems->{$item} = scalar(@{$trails})-1;
15878: }
15879: my $deeper = $depth+1;
15880: push(@{$parents},$category);
1.665 raeburn 15881: if (ref($subcats) eq 'HASH') {
15882: my $subcat = &escape($name).':'.$category.':'.$depth;
15883: for (my $j=@{$parents}; $j>=0; $j--) {
15884: my $higher;
15885: if ($j > 0) {
15886: $higher = &escape($parents->[$j]).':'.
15887: &escape($parents->[$j-1]).':'.$j;
15888: } else {
15889: $higher = &escape($parents->[$j]).'::'.$j;
15890: }
15891: push(@{$subcats->{$higher}},$subcat);
15892: }
15893: }
15894: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15895: $subcats,$maxd);
1.655 raeburn 15896: pop(@{$parents});
15897: }
15898: } else {
15899: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15900: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15901: if ($allitems->{$item} eq '') {
15902: push(@{$trails},$trailstr);
15903: $allitems->{$item} = scalar(@{$trails})-1;
15904: }
1.1321 raeburn 15905: if (ref($maxd) eq 'HASH') {
15906: if ($depth > $maxd->{$parents->[0]}) {
15907: $maxd->{$parents->[0]} = $depth;
15908: }
15909: }
1.655 raeburn 15910: }
15911: return;
15912: }
15913:
1.663 raeburn 15914: =pod
15915:
1.1162 raeburn 15916: =item * &assign_categories_table()
1.663 raeburn 15917:
15918: Create a datatable for display of hierarchical categories in a domain,
15919: with checkboxes to allow a course to be categorized.
15920:
15921: Inputs:
15922:
15923: cathash - reference to hash of categories defined for the domain (from
15924: configuration.db)
15925:
15926: currcat - scalar with an & separated list of categories assigned to a course.
15927:
1.919 raeburn 15928: type - scalar contains course type (Course or Community).
15929:
1.1260 raeburn 15930: disabled - scalar (optional) contains disabled="disabled" if input elements are
15931: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15932:
1.663 raeburn 15933: Returns: $output (markup to be displayed)
15934:
15935: =cut
15936:
15937: sub assign_categories_table {
1.1259 raeburn 15938: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15939: my $output;
15940: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15941: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15942: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15943: $maxdepth = scalar(@cats);
15944: if (@cats > 0) {
15945: my $itemcount = 0;
15946: if (ref($cats[0]) eq 'ARRAY') {
15947: my @currcategories;
15948: if ($currcat ne '') {
15949: @currcategories = split('&',$currcat);
15950: }
1.919 raeburn 15951: my $table;
1.663 raeburn 15952: for (my $i=0; $i<@{$cats[0]}; $i++) {
15953: my $parent = $cats[0][$i];
1.919 raeburn 15954: next if ($parent eq 'instcode');
15955: if ($type eq 'Community') {
15956: next unless ($parent eq 'communities');
1.1239 raeburn 15957: } elsif ($type eq 'Placement') {
15958: next unless ($parent eq 'placement');
1.919 raeburn 15959: } else {
1.1239 raeburn 15960: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15961: }
1.663 raeburn 15962: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15963: my $item = &escape($parent).'::0';
15964: my $checked = '';
15965: if (@currcategories > 0) {
15966: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15967: $checked = ' checked="checked"';
1.663 raeburn 15968: }
15969: }
1.919 raeburn 15970: my $parent_title = $parent;
15971: if ($parent eq 'communities') {
15972: $parent_title = &mt('Communities');
1.1239 raeburn 15973: } elsif ($parent eq 'placement') {
15974: $parent_title = &mt('Placement Tests');
1.919 raeburn 15975: }
15976: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15977: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15978: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15979: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15980: my $depth = 1;
15981: push(@path,$parent);
1.1259 raeburn 15982: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15983: pop(@path);
1.919 raeburn 15984: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15985: $itemcount ++;
15986: }
1.919 raeburn 15987: if ($itemcount) {
15988: $output = &Apache::loncommon::start_data_table().
15989: $table.
15990: &Apache::loncommon::end_data_table();
15991: }
1.663 raeburn 15992: }
15993: }
15994: }
15995: return $output;
15996: }
15997:
15998: =pod
15999:
1.1162 raeburn 16000: =item * &assign_category_rows()
1.663 raeburn 16001:
16002: Create a datatable row for display of nested categories in a domain,
16003: with checkboxes to allow a course to be categorized,called recursively.
16004:
16005: Inputs:
16006:
16007: itemcount - track row number for alternating colors
16008:
16009: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16010: categories and subcategories.
16011:
16012: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16013:
16014: parent - parent of current category item
16015:
16016: path - Array containing all categories back up through the hierarchy from the
16017: current category to the top level.
16018:
16019: currcategories - reference to array of current categories assigned to the course
16020:
1.1260 raeburn 16021: disabled - scalar (optional) contains disabled="disabled" if input elements are
16022: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16023:
1.663 raeburn 16024: Returns: $output (markup to be displayed).
16025:
16026: =cut
16027:
16028: sub assign_category_rows {
1.1259 raeburn 16029: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16030: my ($text,$name,$item,$chgstr);
16031: if (ref($cats) eq 'ARRAY') {
16032: my $maxdepth = scalar(@{$cats});
16033: if (ref($cats->[$depth]) eq 'HASH') {
16034: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16035: my $numchildren = @{$cats->[$depth]{$parent}};
16036: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16037: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16038: for (my $j=0; $j<$numchildren; $j++) {
16039: $name = $cats->[$depth]{$parent}[$j];
16040: $item = &escape($name).':'.&escape($parent).':'.$depth;
16041: my $deeper = $depth+1;
16042: my $checked = '';
16043: if (ref($currcategories) eq 'ARRAY') {
16044: if (@{$currcategories} > 0) {
16045: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16046: $checked = ' checked="checked"';
1.663 raeburn 16047: }
16048: }
16049: }
1.664 raeburn 16050: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16051: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16052: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16053: '<input type="hidden" name="catname" value="'.$name.'" />'.
16054: '</td><td>';
1.663 raeburn 16055: if (ref($path) eq 'ARRAY') {
16056: push(@{$path},$name);
1.1259 raeburn 16057: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16058: pop(@{$path});
16059: }
16060: $text .= '</td></tr>';
16061: }
16062: $text .= '</table></td>';
16063: }
16064: }
16065: }
16066: return $text;
16067: }
16068:
1.1181 raeburn 16069: =pod
16070:
16071: =back
16072:
16073: =cut
16074:
1.655 raeburn 16075: ############################################################
16076: ############################################################
16077:
16078:
1.443 albertel 16079: sub commit_customrole {
1.664 raeburn 16080: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 16081: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16082: ($start?', '.&mt('starting').' '.localtime($start):'').
16083: ($end?', ending '.localtime($end):'').': <b>'.
16084: &Apache::lonnet::assigncustomrole(
1.664 raeburn 16085: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 16086: '</b><br />';
16087: return $output;
16088: }
16089:
16090: sub commit_standardrole {
1.1116 raeburn 16091: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 16092: my ($output,$logmsg,$linefeed);
16093: if ($context eq 'auto') {
16094: $linefeed = "\n";
16095: } else {
16096: $linefeed = "<br />\n";
16097: }
1.443 albertel 16098: if ($three eq 'st') {
1.541 raeburn 16099: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 16100: $one,$two,$sec,$context,$credits);
1.541 raeburn 16101: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16102: ($result eq 'unknown_course') || ($result eq 'refused')) {
16103: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16104: } else {
1.541 raeburn 16105: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16106: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16107: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16108: if ($context eq 'auto') {
16109: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16110: } else {
16111: $output .= '<b>'.$result.'</b>'.$linefeed.
16112: &mt('Add to classlist').': <b>ok</b>';
16113: }
16114: $output .= $linefeed;
1.443 albertel 16115: }
16116: } else {
16117: $output = &mt('Assigning').' '.$three.' in '.$url.
16118: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16119: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 16120: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16121: if ($context eq 'auto') {
16122: $output .= $result.$linefeed;
16123: } else {
16124: $output .= '<b>'.$result.'</b>'.$linefeed;
16125: }
1.443 albertel 16126: }
16127: return $output;
16128: }
16129:
16130: sub commit_studentrole {
1.1116 raeburn 16131: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16132: $credits) = @_;
1.626 raeburn 16133: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16134: if ($context eq 'auto') {
16135: $linefeed = "\n";
16136: } else {
16137: $linefeed = '<br />'."\n";
16138: }
1.443 albertel 16139: if (defined($one) && defined($two)) {
16140: my $cid=$one.'_'.$two;
16141: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16142: my $secchange = 0;
16143: my $expire_role_result;
16144: my $modify_section_result;
1.628 raeburn 16145: if ($oldsec ne '-1') {
16146: if ($oldsec ne $sec) {
1.443 albertel 16147: $secchange = 1;
1.628 raeburn 16148: my $now = time;
1.443 albertel 16149: my $uurl='/'.$cid;
16150: $uurl=~s/\_/\//g;
16151: if ($oldsec) {
16152: $uurl.='/'.$oldsec;
16153: }
1.626 raeburn 16154: $oldsecurl = $uurl;
1.628 raeburn 16155: $expire_role_result =
1.652 raeburn 16156: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 16157: if ($env{'request.course.sec'} ne '') {
16158: if ($expire_role_result eq 'refused') {
16159: my @roles = ('st');
16160: my @statuses = ('previous');
16161: my @roledoms = ($one);
16162: my $withsec = 1;
16163: my %roleshash =
16164: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16165: \@statuses,\@roles,\@roledoms,$withsec);
16166: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16167: my ($oldstart,$oldend) =
16168: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16169: if ($oldend > 0 && $oldend <= $now) {
16170: $expire_role_result = 'ok';
16171: }
16172: }
16173: }
16174: }
1.443 albertel 16175: $result = $expire_role_result;
16176: }
16177: }
16178: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16179: $modify_section_result =
16180: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16181: undef,undef,undef,$sec,
16182: $end,$start,'','',$cid,
16183: '',$context,$credits);
1.443 albertel 16184: if ($modify_section_result =~ /^ok/) {
16185: if ($secchange == 1) {
1.628 raeburn 16186: if ($sec eq '') {
16187: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16188: } else {
16189: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16190: }
1.443 albertel 16191: } elsif ($oldsec eq '-1') {
1.628 raeburn 16192: if ($sec eq '') {
16193: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16194: } else {
16195: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16196: }
1.443 albertel 16197: } else {
1.628 raeburn 16198: if ($sec eq '') {
16199: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16200: } else {
16201: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16202: }
1.443 albertel 16203: }
16204: } else {
1.1115 raeburn 16205: if ($secchange) {
1.628 raeburn 16206: $$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;
16207: } else {
16208: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16209: }
1.443 albertel 16210: }
16211: $result = $modify_section_result;
16212: } elsif ($secchange == 1) {
1.628 raeburn 16213: if ($oldsec eq '') {
1.1103 raeburn 16214: $$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 16215: } else {
16216: $$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;
16217: }
1.626 raeburn 16218: if ($expire_role_result eq 'refused') {
16219: my $newsecurl = '/'.$cid;
16220: $newsecurl =~ s/\_/\//g;
16221: if ($sec ne '') {
16222: $newsecurl.='/'.$sec;
16223: }
16224: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16225: if ($sec eq '') {
16226: $$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;
16227: } else {
16228: $$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;
16229: }
16230: }
16231: }
1.443 albertel 16232: }
16233: } else {
1.626 raeburn 16234: $$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 16235: $result = "error: incomplete course id\n";
16236: }
16237: return $result;
16238: }
16239:
1.1108 raeburn 16240: sub show_role_extent {
16241: my ($scope,$context,$role) = @_;
16242: $scope =~ s{^/}{};
16243: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16244: push(@courseroles,'co');
16245: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16246: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16247: $scope =~ s{/}{_};
16248: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16249: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16250: my ($audom,$auname) = split(/\//,$scope);
16251: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16252: &Apache::loncommon::plainname($auname,$audom).'</span>');
16253: } else {
16254: $scope =~ s{/$}{};
16255: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16256: &Apache::lonnet::domain($scope,'description').'</span>');
16257: }
16258: }
16259:
1.443 albertel 16260: ############################################################
16261: ############################################################
16262:
1.566 albertel 16263: sub check_clone {
1.578 raeburn 16264: my ($args,$linefeed) = @_;
1.566 albertel 16265: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16266: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16267: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16268: my $clonetitle;
16269: my @clonemsg;
1.566 albertel 16270: my $can_clone = 0;
1.944 raeburn 16271: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16272: if ($lctype ne 'community') {
16273: $lctype = 'course';
16274: }
1.566 albertel 16275: if ($clonehome eq 'no_host') {
1.944 raeburn 16276: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16277: push(@clonemsg,({
16278: mt => 'No new community created.',
16279: args => [],
16280: },
16281: {
16282: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16283: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16284: }));
1.908 raeburn 16285: } else {
1.1344 raeburn 16286: push(@clonemsg,({
16287: mt => 'No new course created.',
16288: args => [],
16289: },
16290: {
16291: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16292: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16293: }));
16294: }
1.566 albertel 16295: } else {
16296: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16297: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16298: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16299: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16300: push(@clonemsg,({
16301: mt => 'No new community created.',
16302: args => [],
16303: },
16304: {
16305: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16306: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16307: }));
16308: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16309: }
16310: }
1.1262 raeburn 16311: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16312: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16313: $can_clone = 1;
16314: } else {
1.1221 raeburn 16315: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16316: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16317: if ($clonehash{'cloners'} eq '') {
16318: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16319: if ($domdefs{'canclone'}) {
16320: unless ($domdefs{'canclone'} eq 'none') {
16321: if ($domdefs{'canclone'} eq 'domain') {
16322: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16323: $can_clone = 1;
16324: }
16325: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16326: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16327: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16328: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16329: $can_clone = 1;
16330: }
16331: }
16332: }
16333: }
1.578 raeburn 16334: } else {
1.1221 raeburn 16335: my @cloners = split(/,/,$clonehash{'cloners'});
16336: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16337: $can_clone = 1;
1.1221 raeburn 16338: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16339: $can_clone = 1;
1.1225 raeburn 16340: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16341: $can_clone = 1;
1.1221 raeburn 16342: }
16343: unless ($can_clone) {
1.1225 raeburn 16344: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16345: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16346: my (%gotdomdefaults,%gotcodedefaults);
16347: foreach my $cloner (@cloners) {
16348: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16349: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16350: my (%codedefaults,@code_order);
16351: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16352: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16353: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16354: }
16355: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16356: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16357: }
16358: } else {
16359: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16360: \%codedefaults,
16361: \@code_order);
16362: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16363: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16364: }
16365: if (@code_order > 0) {
16366: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16367: $cloner,$clonehash{'internal.coursecode'},
16368: $args->{'crscode'})) {
16369: $can_clone = 1;
16370: last;
16371: }
16372: }
16373: }
16374: }
16375: }
1.1225 raeburn 16376: }
16377: }
16378: unless ($can_clone) {
16379: my $ccrole = 'cc';
16380: if ($args->{'crstype'} eq 'Community') {
16381: $ccrole = 'co';
16382: }
16383: my %roleshash =
16384: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16385: $args->{'ccdomain'},
16386: 'userroles',['active'],[$ccrole],
16387: [$args->{'clonedomain'}]);
16388: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16389: $can_clone = 1;
16390: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16391: $args->{'ccuname'},$args->{'ccdomain'})) {
16392: $can_clone = 1;
1.1221 raeburn 16393: }
16394: }
16395: unless ($can_clone) {
16396: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16397: push(@clonemsg,({
16398: mt => 'No new community created.',
16399: args => [],
16400: },
16401: {
16402: 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]).',
16403: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16404: }));
1.942 raeburn 16405: } else {
1.1344 raeburn 16406: push(@clonemsg,({
16407: mt => 'No new course created.',
16408: args => [],
16409: },
16410: {
16411: 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]).',
16412: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16413: }));
1.1221 raeburn 16414: }
1.566 albertel 16415: }
1.578 raeburn 16416: }
1.566 albertel 16417: }
1.1344 raeburn 16418: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16419: }
16420:
1.444 albertel 16421: sub construct_course {
1.1262 raeburn 16422: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16423: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16424: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16425: my $linefeed = '<br />'."\n";
16426: if ($context eq 'auto') {
16427: $linefeed = "\n";
16428: }
1.566 albertel 16429:
16430: #
16431: # Are we cloning?
16432: #
1.1344 raeburn 16433: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16434: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16435: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16436: if (!$can_clone) {
1.1344 raeburn 16437: return (0,$outcome,$clonemsgref);
1.566 albertel 16438: }
16439: }
16440:
1.444 albertel 16441: #
16442: # Open course
16443: #
1.1239 raeburn 16444: my $showncrstype;
16445: if ($args->{'crstype'} eq 'Placement') {
16446: $showncrstype = 'placement test';
16447: } else {
16448: $showncrstype = lc($args->{'crstype'});
16449: }
1.444 albertel 16450: my %cenv=();
16451: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16452: $args->{'cdescr'},
16453: $args->{'curl'},
16454: $args->{'course_home'},
16455: $args->{'nonstandard'},
16456: $args->{'crscode'},
16457: $args->{'ccuname'}.':'.
16458: $args->{'ccdomain'},
1.882 raeburn 16459: $args->{'crstype'},
1.1344 raeburn 16460: $cnum,$context,$category,
16461: $callercontext);
1.444 albertel 16462:
16463: # Note: The testing routines depend on this being output; see
16464: # Utils::Course. This needs to at least be output as a comment
16465: # if anyone ever decides to not show this, and Utils::Course::new
16466: # will need to be suitably modified.
1.1344 raeburn 16467: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16468: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16469: } else {
16470: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16471: }
1.943 raeburn 16472: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16473: return (0,$outcome,$clonemsgref);
1.943 raeburn 16474: }
16475:
1.444 albertel 16476: #
16477: # Check if created correctly
16478: #
1.479 albertel 16479: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16480: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16481: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16482: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16483: $outcome .= &mt_user($user_lh,
16484: 'Course creation failed, unrecognized course home server.');
16485: } else {
16486: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16487: }
16488: $outcome .= $linefeed;
16489: return (0,$outcome,$clonemsgref);
1.943 raeburn 16490: }
1.541 raeburn 16491: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16492:
1.444 albertel 16493: #
1.566 albertel 16494: # Do the cloning
16495: #
1.1344 raeburn 16496: my @clonemsg;
1.566 albertel 16497: if ($can_clone && $cloneid) {
1.1344 raeburn 16498: push(@clonemsg,
16499: {
16500: mt => 'Created [_1] by cloning from [_2]',
16501: args => [$showncrstype,$clonetitle],
16502: });
1.566 albertel 16503: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16504: # Copy all files
1.1344 raeburn 16505: my @info =
16506: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16507: $args->{'dateshift'},$args->{'crscode'},
16508: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16509: $args->{'tinyurls'});
16510: if (@info) {
16511: push(@clonemsg,@info);
16512: }
1.444 albertel 16513: # Restore URL
1.566 albertel 16514: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16515: # Restore title
1.566 albertel 16516: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16517: # Restore creation date, creator and creation context.
16518: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16519: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16520: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16521: # Mark as cloned
1.566 albertel 16522: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16523: # Need to clone grading mode
16524: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16525: $cenv{'grading'}=$newenv{'grading'};
16526: # Do not clone these environment entries
16527: &Apache::lonnet::del('environment',
16528: ['default_enrollment_start_date',
16529: 'default_enrollment_end_date',
16530: 'question.email',
16531: 'policy.email',
16532: 'comment.email',
16533: 'pch.users.denied',
1.725 raeburn 16534: 'plc.users.denied',
16535: 'hidefromcat',
1.1121 raeburn 16536: 'checkforpriv',
1.1355 raeburn 16537: 'categories'],
1.638 www 16538: $$crsudom,$$crsunum);
1.1170 raeburn 16539: if ($args->{'textbook'}) {
16540: $cenv{'internal.textbook'} = $args->{'textbook'};
16541: }
1.444 albertel 16542: }
1.566 albertel 16543:
1.444 albertel 16544: #
16545: # Set environment (will override cloned, if existing)
16546: #
16547: my @sections = ();
16548: my @xlists = ();
16549: if ($args->{'crstype'}) {
16550: $cenv{'type'}=$args->{'crstype'};
16551: }
1.1371 raeburn 16552: if ($args->{'lti'}) {
16553: $cenv{'internal.lti'}=$args->{'lti'};
16554: }
1.444 albertel 16555: if ($args->{'crsid'}) {
16556: $cenv{'courseid'}=$args->{'crsid'};
16557: }
16558: if ($args->{'crscode'}) {
16559: $cenv{'internal.coursecode'}=$args->{'crscode'};
16560: }
16561: if ($args->{'crsquota'} ne '') {
16562: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16563: } else {
16564: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16565: }
16566: if ($args->{'ccuname'}) {
16567: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16568: ':'.$args->{'ccdomain'};
16569: } else {
16570: $cenv{'internal.courseowner'} = $args->{'curruser'};
16571: }
1.1116 raeburn 16572: if ($args->{'defaultcredits'}) {
16573: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16574: }
1.444 albertel 16575: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16576: if ($args->{'crssections'}) {
16577: $cenv{'internal.sectionnums'} = '';
16578: if ($args->{'crssections'} =~ m/,/) {
16579: @sections = split/,/,$args->{'crssections'};
16580: } else {
16581: $sections[0] = $args->{'crssections'};
16582: }
16583: if (@sections > 0) {
16584: foreach my $item (@sections) {
16585: my ($sec,$gp) = split/:/,$item;
16586: my $class = $args->{'crscode'}.$sec;
16587: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16588: $cenv{'internal.sectionnums'} .= $item.',';
16589: unless ($addcheck eq 'ok') {
1.1263 raeburn 16590: push(@badclasses,$class);
1.444 albertel 16591: }
16592: }
16593: $cenv{'internal.sectionnums'} =~ s/,$//;
16594: }
16595: }
16596: # do not hide course coordinator from staff listing,
16597: # even if privileged
16598: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16599: # add course coordinator's domain to domains to check for privileged users
16600: # if different to course domain
16601: if ($$crsudom ne $args->{'ccdomain'}) {
16602: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16603: }
1.444 albertel 16604: # add crosslistings
16605: if ($args->{'crsxlist'}) {
16606: $cenv{'internal.crosslistings'}='';
16607: if ($args->{'crsxlist'} =~ m/,/) {
16608: @xlists = split/,/,$args->{'crsxlist'};
16609: } else {
16610: $xlists[0] = $args->{'crsxlist'};
16611: }
16612: if (@xlists > 0) {
16613: foreach my $item (@xlists) {
16614: my ($xl,$gp) = split/:/,$item;
16615: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16616: $cenv{'internal.crosslistings'} .= $item.',';
16617: unless ($addcheck eq 'ok') {
1.1263 raeburn 16618: push(@badclasses,$xl);
1.444 albertel 16619: }
16620: }
16621: $cenv{'internal.crosslistings'} =~ s/,$//;
16622: }
16623: }
16624: if ($args->{'autoadds'}) {
16625: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16626: }
16627: if ($args->{'autodrops'}) {
16628: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16629: }
16630: # check for notification of enrollment changes
16631: my @notified = ();
16632: if ($args->{'notify_owner'}) {
16633: if ($args->{'ccuname'} ne '') {
16634: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16635: }
16636: }
16637: if ($args->{'notify_dc'}) {
16638: if ($uname ne '') {
1.630 raeburn 16639: push(@notified,$uname.':'.$udom);
1.444 albertel 16640: }
16641: }
16642: if (@notified > 0) {
16643: my $notifylist;
16644: if (@notified > 1) {
16645: $notifylist = join(',',@notified);
16646: } else {
16647: $notifylist = $notified[0];
16648: }
16649: $cenv{'internal.notifylist'} = $notifylist;
16650: }
16651: if (@badclasses > 0) {
16652: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16653: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16654: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16655: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16656: );
1.1264 raeburn 16657: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16658: &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 16659: if ($context eq 'auto') {
16660: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16661: } else {
1.566 albertel 16662: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16663: }
16664: foreach my $item (@badclasses) {
1.541 raeburn 16665: if ($context eq 'auto') {
1.1261 raeburn 16666: $outcome .= " - $item\n";
1.541 raeburn 16667: } else {
1.1261 raeburn 16668: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16669: }
1.1261 raeburn 16670: }
16671: if ($context eq 'auto') {
16672: $outcome .= $linefeed;
16673: } else {
16674: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16675: }
1.444 albertel 16676: }
16677: if ($args->{'no_end_date'}) {
16678: $args->{'endaccess'} = 0;
16679: }
16680: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16681: $cenv{'internal.autoend'}=$args->{'enrollend'};
16682: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16683: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16684: if ($args->{'showphotos'}) {
16685: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16686: }
16687: $cenv{'internal.authtype'} = $args->{'authtype'};
16688: $cenv{'internal.autharg'} = $args->{'autharg'};
16689: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16690: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16691: 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');
16692: if ($context eq 'auto') {
16693: $outcome .= $krb_msg;
16694: } else {
1.566 albertel 16695: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16696: }
16697: $outcome .= $linefeed;
1.444 albertel 16698: }
16699: }
16700: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16701: if ($args->{'setpolicy'}) {
16702: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16703: }
16704: if ($args->{'setcontent'}) {
16705: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16706: }
1.1251 raeburn 16707: if ($args->{'setcomment'}) {
16708: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16709: }
1.444 albertel 16710: }
16711: if ($args->{'reshome'}) {
16712: $cenv{'reshome'}=$args->{'reshome'}.'/';
16713: $cenv{'reshome'}=~s/\/+$/\//;
16714: }
16715: #
16716: # course has keyed access
16717: #
16718: if ($args->{'setkeys'}) {
16719: $cenv{'keyaccess'}='yes';
16720: }
16721: # if specified, key authority is not course, but user
16722: # only active if keyaccess is yes
16723: if ($args->{'keyauth'}) {
1.487 albertel 16724: my ($user,$domain) = split(':',$args->{'keyauth'});
16725: $user = &LONCAPA::clean_username($user);
16726: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16727: if ($user ne '' && $domain ne '') {
1.487 albertel 16728: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16729: }
16730: }
16731:
1.1166 raeburn 16732: #
1.1167 raeburn 16733: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16734: #
16735: if ($args->{'uniquecode'}) {
16736: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16737: if ($code) {
16738: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16739: my %crsinfo =
16740: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16741: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16742: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16743: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16744: }
1.1166 raeburn 16745: if (ref($coderef)) {
16746: $$coderef = $code;
16747: }
16748: }
16749: }
16750:
1.444 albertel 16751: if ($args->{'disresdis'}) {
16752: $cenv{'pch.roles.denied'}='st';
16753: }
16754: if ($args->{'disablechat'}) {
16755: $cenv{'plc.roles.denied'}='st';
16756: }
16757:
16758: # Record we've not yet viewed the Course Initialization Helper for this
16759: # course
16760: $cenv{'course.helper.not.run'} = 1;
16761: #
16762: # Use new Randomseed
16763: #
16764: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16765: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16766: #
16767: # The encryption code and receipt prefix for this course
16768: #
16769: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16770: $cenv{'internal.encpref'}=100+int(9*rand(99));
16771: #
16772: # By default, use standard grading
16773: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16774:
1.541 raeburn 16775: $outcome .= $linefeed.&mt('Setting environment').': '.
16776: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16777: #
16778: # Open all assignments
16779: #
16780: if ($args->{'openall'}) {
1.1341 raeburn 16781: my $opendate = time;
16782: if ($args->{'openallfrom'} =~ /^\d+$/) {
16783: $opendate = $args->{'openallfrom'};
16784: }
1.444 albertel 16785: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16786: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16787: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16788: $outcome .= &mt('All assignments open starting [_1]',
16789: &Apache::lonlocal::locallocaltime($opendate)).': '.
16790: &Apache::lonnet::cput
16791: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16792: }
16793: #
16794: # Set first page
16795: #
16796: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16797: || ($cloneid)) {
1.445 albertel 16798: use LONCAPA::map;
1.444 albertel 16799: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16800:
16801: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16802: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16803:
1.444 albertel 16804: $outcome .= ($fatal?$errtext:'read ok').' - ';
16805: my $title; my $url;
16806: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16807: $title=&mt('Syllabus');
1.444 albertel 16808: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16809: } else {
1.963 raeburn 16810: $title=&mt('Table of Contents');
1.444 albertel 16811: $url='/adm/navmaps';
16812: }
1.445 albertel 16813:
16814: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16815: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16816:
16817: if ($errtext) { $fatal=2; }
1.541 raeburn 16818: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16819: }
1.566 albertel 16820:
1.1237 raeburn 16821: #
16822: # Set params for Placement Tests
16823: #
1.1239 raeburn 16824: if ($args->{'crstype'} eq 'Placement') {
16825: my %storecontent;
16826: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16827: my %defaults = (
16828: buttonshide => { value => 'yes',
16829: type => 'string_yesno',},
16830: type => { value => 'randomizetry',
16831: type => 'string_questiontype',},
16832: maxtries => { value => 1,
16833: type => 'int_pos',},
16834: problemstatus => { value => 'no',
16835: type => 'string_problemstatus',},
16836: );
16837: foreach my $key (keys(%defaults)) {
16838: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16839: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16840: }
1.1237 raeburn 16841: &Apache::lonnet::cput
16842: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16843: }
16844:
1.1344 raeburn 16845: return (1,$outcome,\@clonemsg);
1.444 albertel 16846: }
16847:
1.1166 raeburn 16848: sub make_unique_code {
16849: my ($cdom,$cnum) = @_;
16850: # get lock on uniquecodes db
16851: my $lockhash = {
16852: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16853: ':'.$env{'user.domain'},
16854: };
16855: my $tries = 0;
16856: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16857: my ($code,$error);
16858:
16859: while (($gotlock ne 'ok') && ($tries<3)) {
16860: $tries ++;
16861: sleep 1;
16862: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16863: }
16864: if ($gotlock eq 'ok') {
16865: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16866: my $gotcode;
16867: my $attempts = 0;
16868: while ((!$gotcode) && ($attempts < 100)) {
16869: $code = &generate_code();
16870: if (!exists($currcodes{$code})) {
16871: $gotcode = 1;
16872: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16873: $error = 'nostore';
16874: }
16875: }
16876: $attempts ++;
16877: }
16878: my @del_lock = ($cnum."\0".'uniquecodes');
16879: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16880: } else {
16881: $error = 'nolock';
16882: }
16883: return ($code,$error);
16884: }
16885:
16886: sub generate_code {
16887: my $code;
16888: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16889: for (my $i=0; $i<6; $i++) {
16890: my $lettnum = int (rand 2);
16891: my $item = '';
16892: if ($lettnum) {
16893: $item = $letts[int( rand(18) )];
16894: } else {
16895: $item = 1+int( rand(8) );
16896: }
16897: $code .= $item;
16898: }
16899: return $code;
16900: }
16901:
1.444 albertel 16902: ############################################################
16903: ############################################################
16904:
1.1237 raeburn 16905: # Community, Course and Placement Test
1.378 raeburn 16906: sub course_type {
16907: my ($cid) = @_;
16908: if (!defined($cid)) {
16909: $cid = $env{'request.course.id'};
16910: }
1.404 albertel 16911: if (defined($env{'course.'.$cid.'.type'})) {
16912: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16913: } else {
16914: return 'Course';
1.377 raeburn 16915: }
16916: }
1.156 albertel 16917:
1.406 raeburn 16918: sub group_term {
16919: my $crstype = &course_type();
16920: my %names = (
16921: 'Course' => 'group',
1.865 raeburn 16922: 'Community' => 'group',
1.1237 raeburn 16923: 'Placement' => 'group',
1.406 raeburn 16924: );
16925: return $names{$crstype};
16926: }
16927:
1.902 raeburn 16928: sub course_types {
1.1310 raeburn 16929: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16930: my %typename = (
16931: official => 'Official course',
16932: unofficial => 'Unofficial course',
16933: community => 'Community',
1.1165 raeburn 16934: textbook => 'Textbook course',
1.1237 raeburn 16935: placement => 'Placement test',
1.1310 raeburn 16936: lti => 'LTI provider',
1.902 raeburn 16937: );
16938: return (\@types,\%typename);
16939: }
16940:
1.156 albertel 16941: sub icon {
16942: my ($file)=@_;
1.505 albertel 16943: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16944: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16945: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16946: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16947: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16948: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16949: $curfext.".gif") {
16950: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16951: $curfext.".gif";
16952: }
16953: }
1.249 albertel 16954: return &lonhttpdurl($iconname);
1.154 albertel 16955: }
1.84 albertel 16956:
1.575 albertel 16957: sub lonhttpdurl {
1.692 www 16958: #
16959: # Had been used for "small fry" static images on separate port 8080.
16960: # Modify here if lightweight http functionality desired again.
16961: # Currently eliminated due to increasing firewall issues.
16962: #
1.575 albertel 16963: my ($url)=@_;
1.692 www 16964: return $url;
1.215 albertel 16965: }
16966:
1.213 albertel 16967: sub connection_aborted {
16968: my ($r)=@_;
16969: $r->print(" ");$r->rflush();
16970: my $c = $r->connection;
16971: return $c->aborted();
16972: }
16973:
1.221 foxr 16974: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16975: # strings as 'strings'.
16976: sub escape_single {
1.221 foxr 16977: my ($input) = @_;
1.223 albertel 16978: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16979: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16980: return $input;
16981: }
1.223 albertel 16982:
1.222 foxr 16983: # Same as escape_single, but escape's "'s This
16984: # can be used for "strings"
16985: sub escape_double {
16986: my ($input) = @_;
16987: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16988: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16989: return $input;
16990: }
1.223 albertel 16991:
1.222 foxr 16992: # Escapes the last element of a full URL.
16993: sub escape_url {
16994: my ($url) = @_;
1.238 raeburn 16995: my @urlslices = split(/\//, $url,-1);
1.369 www 16996: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16997: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16998: }
1.462 albertel 16999:
1.820 raeburn 17000: sub compare_arrays {
17001: my ($arrayref1,$arrayref2) = @_;
17002: my (@difference,%count);
17003: @difference = ();
17004: %count = ();
17005: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17006: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17007: foreach my $element (keys(%count)) {
17008: if ($count{$element} == 1) {
17009: push(@difference,$element);
17010: }
17011: }
17012: }
17013: return @difference;
17014: }
17015:
1.1322 raeburn 17016: sub lon_status_items {
17017: my %defaults = (
17018: E => 100,
17019: W => 4,
17020: N => 1,
1.1324 raeburn 17021: U => 5,
1.1322 raeburn 17022: threshold => 200,
17023: sysmail => 2500,
17024: );
17025: my %names = (
17026: E => 'Errors',
17027: W => 'Warnings',
17028: N => 'Notices',
1.1324 raeburn 17029: U => 'Unsent',
1.1322 raeburn 17030: );
17031: return (\%defaults,\%names);
17032: }
17033:
1.817 bisitz 17034: # -------------------------------------------------------- Initialize user login
1.462 albertel 17035: sub init_user_environment {
1.463 albertel 17036: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17037: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17038:
17039: my $public=($username eq 'public' && $domain eq 'public');
17040:
1.1062 raeburn 17041: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 17042: my $now=time;
17043:
17044: if ($public) {
17045: my $max_public=100;
17046: my $oldest;
17047: my $oldest_time=0;
17048: for(my $next=1;$next<=$max_public;$next++) {
17049: if (-e $lonids."/publicuser_$next.id") {
17050: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17051: if ($mtime<$oldest_time || !$oldest_time) {
17052: $oldest_time=$mtime;
17053: $oldest=$next;
17054: }
17055: } else {
17056: $cookie="publicuser_$next";
17057: last;
17058: }
17059: }
17060: if (!$cookie) { $cookie="publicuser_$oldest"; }
17061: } else {
1.1275 raeburn 17062: # See if old ID present, if so, remove if this isn't a robot,
17063: # killing any existing non-robot sessions
1.463 albertel 17064: if (!$args->{'robot'}) {
17065: opendir(DIR,$lonids);
17066: while ($filename=readdir(DIR)) {
17067: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17068: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17069: &GDBM_READER(),0640)) {
1.1295 raeburn 17070: my $linkedfile;
1.1320 raeburn 17071: if (exists($oldenv{'user.linkedenv'})) {
17072: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17073: }
1.1320 raeburn 17074: untie(%oldenv);
17075: if (unlink("$lonids/$filename")) {
17076: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17077: if (-l "$lonids/$linkedfile.id") {
17078: unlink("$lonids/$linkedfile.id");
17079: }
1.1295 raeburn 17080: }
17081: }
17082: } else {
17083: unlink($lonids.'/'.$filename);
17084: }
1.463 albertel 17085: }
1.462 albertel 17086: }
1.463 albertel 17087: closedir(DIR);
1.1204 raeburn 17088: # If there is a undeleted lockfile for the user's paste buffer remove it.
17089: my $namespace = 'nohist_courseeditor';
17090: my $lockingkey = 'paste'."\0".'locked_num';
17091: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17092: $domain,$username);
17093: if (exists($lockhash{$lockingkey})) {
17094: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17095: unless ($delresult eq 'ok') {
17096: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17097: }
17098: }
1.462 albertel 17099: }
17100: # Give them a new cookie
1.463 albertel 17101: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17102: : $now.$$.int(rand(10000)));
1.463 albertel 17103: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17104:
17105: # Initialize roles
17106:
1.1062 raeburn 17107: ($userroles,$firstaccenv,$timerintenv) =
17108: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17109: }
17110: # ------------------------------------ Check browser type and MathML capability
17111:
1.1194 raeburn 17112: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17113: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17114:
17115: # ------------------------------------------------------------- Get environment
17116:
17117: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17118: my ($tmp) = keys(%userenv);
1.1275 raeburn 17119: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17120: undef(%userenv);
17121: }
17122: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17123: $form->{'interface'}=$userenv{'interface'};
17124: }
17125: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17126:
17127: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17128: foreach my $option ('interface','localpath','localres') {
17129: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17130: }
17131: # --------------------------------------------------------- Write first profile
17132:
17133: {
1.1350 raeburn 17134: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17135: my %initial_env =
17136: ("user.name" => $username,
17137: "user.domain" => $domain,
17138: "user.home" => $authhost,
17139: "browser.type" => $clientbrowser,
17140: "browser.version" => $clientversion,
17141: "browser.mathml" => $clientmathml,
17142: "browser.unicode" => $clientunicode,
17143: "browser.os" => $clientos,
1.1137 raeburn 17144: "browser.mobile" => $clientmobile,
1.1141 raeburn 17145: "browser.info" => $clientinfo,
1.1194 raeburn 17146: "browser.osversion" => $clientosversion,
1.462 albertel 17147: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17148: "request.course.fn" => '',
17149: "request.course.uri" => '',
17150: "request.course.sec" => '',
17151: "request.role" => 'cm',
17152: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17153: "request.host" => $ip,);
1.462 albertel 17154:
17155: if ($form->{'localpath'}) {
17156: $initial_env{"browser.localpath"} = $form->{'localpath'};
17157: $initial_env{"browser.localres"} = $form->{'localres'};
17158: }
17159:
17160: if ($form->{'interface'}) {
17161: $form->{'interface'}=~s/\W//gs;
17162: $initial_env{"browser.interface"} = $form->{'interface'};
17163: $env{'browser.interface'}=$form->{'interface'};
17164: }
17165:
1.1157 raeburn 17166: if ($form->{'iptoken'}) {
17167: my $lonhost = $r->dir_config('lonHostID');
17168: $initial_env{"user.noloadbalance"} = $lonhost;
17169: $env{'user.noloadbalance'} = $lonhost;
17170: }
17171:
1.1268 raeburn 17172: if ($form->{'noloadbalance'}) {
17173: my @hosts = &Apache::lonnet::current_machine_ids();
17174: my $hosthere = $form->{'noloadbalance'};
17175: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17176: $initial_env{"user.noloadbalance"} = $hosthere;
17177: $env{'user.noloadbalance'} = $hosthere;
17178: }
17179: }
17180:
1.1016 raeburn 17181: unless ($domain eq 'public') {
1.1273 raeburn 17182: my %is_adv = ( is_adv => $env{'user.adv'} );
17183: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17184:
17185: foreach my $tool ('aboutme','blog','webdav','portfolio') {
17186: $userenv{'availabletools.'.$tool} =
17187: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17188: undef,\%userenv,\%domdef,\%is_adv);
17189: }
1.980 raeburn 17190:
1.1311 raeburn 17191: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17192: $userenv{'canrequest.'.$crstype} =
17193: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17194: 'reload','requestcourses',
17195: \%userenv,\%domdef,\%is_adv);
17196: }
1.724 raeburn 17197:
1.1273 raeburn 17198: $userenv{'canrequest.author'} =
17199: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17200: 'reload','requestauthor',
1.980 raeburn 17201: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17202: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17203: $domain,$username);
17204: my $reqstatus = $reqauthor{'author_status'};
17205: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17206: if (ref($reqauthor{'author'}) eq 'HASH') {
17207: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17208: $reqauthor{'author'}{'timestamp'};
17209: }
1.1092 raeburn 17210: }
1.1287 raeburn 17211: my ($types,$typename) = &course_types();
17212: if (ref($types) eq 'ARRAY') {
17213: my @options = ('approval','validate','autolimit');
17214: my $optregex = join('|',@options);
17215: my (%willtrust,%trustchecked);
17216: foreach my $type (@{$types}) {
17217: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17218: if ($dom_str ne '') {
17219: my $updatedstr = '';
17220: my @possdomains = split(',',$dom_str);
17221: foreach my $entry (@possdomains) {
17222: my ($extdom,$extopt) = split(':',$entry);
17223: unless ($trustchecked{$extdom}) {
17224: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17225: $trustchecked{$extdom} = 1;
17226: }
17227: if ($willtrust{$extdom}) {
17228: $updatedstr .= $entry.',';
17229: }
17230: }
17231: $updatedstr =~ s/,$//;
17232: if ($updatedstr) {
17233: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17234: } else {
17235: delete($userenv{'reqcrsotherdom.'.$type});
17236: }
17237: }
17238: }
17239: }
1.1092 raeburn 17240: }
1.462 albertel 17241: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17242:
1.462 albertel 17243: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17244: &GDBM_WRCREAT(),0640)) {
17245: &_add_to_env(\%disk_env,\%initial_env);
17246: &_add_to_env(\%disk_env,\%userenv,'environment.');
17247: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17248: if (ref($firstaccenv) eq 'HASH') {
17249: &_add_to_env(\%disk_env,$firstaccenv);
17250: }
17251: if (ref($timerintenv) eq 'HASH') {
17252: &_add_to_env(\%disk_env,$timerintenv);
17253: }
1.463 albertel 17254: if (ref($args->{'extra_env'})) {
17255: &_add_to_env(\%disk_env,$args->{'extra_env'});
17256: }
1.462 albertel 17257: untie(%disk_env);
17258: } else {
1.705 tempelho 17259: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17260: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17261: return 'error: '.$!;
17262: }
17263: }
17264: $env{'request.role'}='cm';
17265: $env{'request.role.adv'}=$env{'user.adv'};
17266: $env{'browser.type'}=$clientbrowser;
17267:
17268: return $cookie;
17269:
17270: }
17271:
17272: sub _add_to_env {
17273: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17274: if (ref($env_data) eq 'HASH') {
17275: while (my ($key,$value) = each(%$env_data)) {
17276: $idf->{$prefix.$key} = $value;
17277: $env{$prefix.$key} = $value;
17278: }
1.462 albertel 17279: }
17280: }
17281:
1.685 tempelho 17282: # --- Get the symbolic name of a problem and the url
17283: sub get_symb {
17284: my ($request,$silent) = @_;
1.726 raeburn 17285: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17286: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17287: if ($symb eq '') {
17288: if (!$silent) {
1.1071 raeburn 17289: if (ref($request)) {
17290: $request->print("Unable to handle ambiguous references:$url:.");
17291: }
1.685 tempelho 17292: return ();
17293: }
17294: }
17295: &Apache::lonenc::check_decrypt(\$symb);
17296: return ($symb);
17297: }
17298:
17299: # --------------------------------------------------------------Get annotation
17300:
17301: sub get_annotation {
17302: my ($symb,$enc) = @_;
17303:
17304: my $key = $symb;
17305: if (!$enc) {
17306: $key =
17307: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17308: }
17309: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17310: return $annotation{$key};
17311: }
17312:
17313: sub clean_symb {
1.731 raeburn 17314: my ($symb,$delete_enc) = @_;
1.685 tempelho 17315:
17316: &Apache::lonenc::check_decrypt(\$symb);
17317: my $enc = $env{'request.enc'};
1.731 raeburn 17318: if ($delete_enc) {
1.730 raeburn 17319: delete($env{'request.enc'});
17320: }
1.685 tempelho 17321:
17322: return ($symb,$enc);
17323: }
1.462 albertel 17324:
1.1181 raeburn 17325: ############################################################
17326: ############################################################
17327:
17328: =pod
17329:
17330: =head1 Routines for building display used to search for courses
17331:
17332:
17333: =over 4
17334:
17335: =item * &build_filters()
17336:
17337: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17338: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17339: and quotacheck.pl
17340:
1.1181 raeburn 17341:
17342: Inputs:
17343:
17344: filterlist - anonymous array of fields to include as potential filters
17345:
17346: crstype - course type
17347:
17348: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17349: to pop-open a course selector (will contain "extra element").
17350:
17351: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17352:
17353: filter - anonymous hash of criteria and their values
17354:
17355: action - form action
17356:
17357: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17358:
1.1182 raeburn 17359: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17360:
17361: cloneruname - username of owner of new course who wants to clone
17362:
17363: clonerudom - domain of owner of new course who wants to clone
17364:
17365: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17366:
17367: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17368:
17369: codedom - domain
17370:
17371: formname - value of form element named "form".
17372:
17373: fixeddom - domain, if fixed.
17374:
17375: prevphase - value to assign to form element named "phase" when going back to the previous screen
17376:
17377: cnameelement - name of form element in form on opener page which will receive title of selected course
17378:
17379: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17380:
17381: cdomelement - name of form element in form on opener page which will receive domain of selected course
17382:
17383: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17384:
17385: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17386:
17387: clonewarning - warning message about missing information for intended course owner when DC creates a course
17388:
1.1182 raeburn 17389:
1.1181 raeburn 17390: Returns: $output - HTML for display of search criteria, and hidden form elements.
17391:
1.1182 raeburn 17392:
1.1181 raeburn 17393: Side Effects: None
17394:
17395: =cut
17396:
17397: # ---------------------------------------------- search for courses based on last activity etc.
17398:
17399: sub build_filters {
17400: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17401: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17402: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17403: $cnameelement,$cnumelement,$cdomelement,$setroles,
17404: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17405: my ($list,$jscript);
1.1181 raeburn 17406: my $onchange = 'javascript:updateFilters(this)';
17407: my ($domainselectform,$sincefilterform,$createdfilterform,
17408: $ownerdomselectform,$persondomselectform,$instcodeform,
17409: $typeselectform,$instcodetitle);
17410: if ($formname eq '') {
17411: $formname = $caller;
17412: }
17413: foreach my $item (@{$filterlist}) {
17414: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17415: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17416: if ($item eq 'domainfilter') {
17417: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17418: } elsif ($item eq 'coursefilter') {
17419: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17420: } elsif ($item eq 'ownerfilter') {
17421: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17422: } elsif ($item eq 'ownerdomfilter') {
17423: $filter->{'ownerdomfilter'} =
17424: &LONCAPA::clean_domain($filter->{$item});
17425: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17426: 'ownerdomfilter',1);
17427: } elsif ($item eq 'personfilter') {
17428: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17429: } elsif ($item eq 'persondomfilter') {
17430: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17431: 'persondomfilter',1);
17432: } else {
17433: $filter->{$item} =~ s/\W//g;
17434: }
17435: if (!$filter->{$item}) {
17436: $filter->{$item} = '';
17437: }
17438: }
17439: if ($item eq 'domainfilter') {
17440: my $allow_blank = 1;
17441: if ($formname eq 'portform') {
17442: $allow_blank=0;
17443: } elsif ($formname eq 'studentform') {
17444: $allow_blank=0;
17445: }
17446: if ($fixeddom) {
17447: $domainselectform = '<input type="hidden" name="domainfilter"'.
17448: ' value="'.$codedom.'" />'.
17449: &Apache::lonnet::domain($codedom,'description');
17450: } else {
17451: $domainselectform = &select_dom_form($filter->{$item},
17452: 'domainfilter',
17453: $allow_blank,'',$onchange);
17454: }
17455: } else {
17456: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17457: }
17458: }
17459:
17460: # last course activity filter and selection
17461: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17462:
17463: # course created filter and selection
17464: if (exists($filter->{'createdfilter'})) {
17465: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17466: }
17467:
1.1239 raeburn 17468: my $prefix = $crstype;
17469: if ($crstype eq 'Placement') {
17470: $prefix = 'Placement Test'
17471: }
1.1181 raeburn 17472: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17473: 'cac' => "$prefix Activity",
17474: 'ccr' => "$prefix Created",
17475: 'cde' => "$prefix Title",
17476: 'cdo' => "$prefix Domain",
1.1181 raeburn 17477: 'ins' => 'Institutional Code',
17478: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17479: 'cow' => "$prefix Owner/Co-owner",
17480: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17481: 'cog' => 'Type',
17482: );
17483:
17484: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17485: my $typeval = 'Course';
17486: if ($crstype eq 'Community') {
17487: $typeval = 'Community';
1.1239 raeburn 17488: } elsif ($crstype eq 'Placement') {
17489: $typeval = 'Placement';
1.1181 raeburn 17490: }
17491: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17492: } else {
17493: $typeselectform = '<select name="type" size="1"';
17494: if ($onchange) {
17495: $typeselectform .= ' onchange="'.$onchange.'"';
17496: }
17497: $typeselectform .= '>'."\n";
1.1237 raeburn 17498: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17499: my $shown;
17500: if ($posstype eq 'Placement') {
17501: $shown = &mt('Placement Test');
17502: } else {
17503: $shown = &mt($posstype);
17504: }
1.1181 raeburn 17505: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17506: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17507: }
17508: $typeselectform.="</select>";
17509: }
17510:
17511: my ($cloneableonlyform,$cloneabletitle);
17512: if (exists($filter->{'cloneableonly'})) {
17513: my $cloneableon = '';
17514: my $cloneableoff = ' checked="checked"';
17515: if ($filter->{'cloneableonly'}) {
17516: $cloneableon = $cloneableoff;
17517: $cloneableoff = '';
17518: }
17519: $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>';
17520: if ($formname eq 'ccrs') {
1.1187 bisitz 17521: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17522: } else {
17523: $cloneabletitle = &mt('Cloneable by you');
17524: }
17525: }
17526: my $officialjs;
17527: if ($crstype eq 'Course') {
17528: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17529: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17530: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17531: if ($codedom) {
1.1181 raeburn 17532: $officialjs = 1;
17533: ($instcodeform,$jscript,$$numtitlesref) =
17534: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17535: $officialjs,$codetitlesref);
17536: if ($jscript) {
1.1182 raeburn 17537: $jscript = '<script type="text/javascript">'."\n".
17538: '// <![CDATA['."\n".
17539: $jscript."\n".
17540: '// ]]>'."\n".
17541: '</script>'."\n";
1.1181 raeburn 17542: }
17543: }
17544: if ($instcodeform eq '') {
17545: $instcodeform =
17546: '<input type="text" name="instcodefilter" size="10" value="'.
17547: $list->{'instcodefilter'}.'" />';
17548: $instcodetitle = $lt{'ins'};
17549: } else {
17550: $instcodetitle = $lt{'inc'};
17551: }
17552: if ($fixeddom) {
17553: $instcodetitle .= '<br />('.$codedom.')';
17554: }
17555: }
17556: }
17557: my $output = qq|
17558: <form method="post" name="filterpicker" action="$action">
17559: <input type="hidden" name="form" value="$formname" />
17560: |;
17561: if ($formname eq 'modifycourse') {
17562: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17563: '<input type="hidden" name="prevphase" value="'.
17564: $prevphase.'" />'."\n";
1.1198 musolffc 17565: } elsif ($formname eq 'quotacheck') {
17566: $output .= qq|
17567: <input type="hidden" name="sortby" value="" />
17568: <input type="hidden" name="sortorder" value="" />
17569: |;
17570: } else {
1.1181 raeburn 17571: my $name_input;
17572: if ($cnameelement ne '') {
17573: $name_input = '<input type="hidden" name="cnameelement" value="'.
17574: $cnameelement.'" />';
17575: }
17576: $output .= qq|
1.1182 raeburn 17577: <input type="hidden" name="cnumelement" value="$cnumelement" />
17578: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17579: $name_input
17580: $roleelement
17581: $multelement
17582: $typeelement
17583: |;
17584: if ($formname eq 'portform') {
17585: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17586: }
17587: }
17588: if ($fixeddom) {
17589: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17590: }
17591: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17592: if ($sincefilterform) {
17593: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17594: .$sincefilterform
17595: .&Apache::lonhtmlcommon::row_closure();
17596: }
17597: if ($createdfilterform) {
17598: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17599: .$createdfilterform
17600: .&Apache::lonhtmlcommon::row_closure();
17601: }
17602: if ($domainselectform) {
17603: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17604: .$domainselectform
17605: .&Apache::lonhtmlcommon::row_closure();
17606: }
17607: if ($typeselectform) {
17608: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17609: $output .= $typeselectform;
17610: } else {
17611: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17612: .$typeselectform
17613: .&Apache::lonhtmlcommon::row_closure();
17614: }
17615: }
17616: if ($instcodeform) {
17617: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17618: .$instcodeform
17619: .&Apache::lonhtmlcommon::row_closure();
17620: }
17621: if (exists($filter->{'ownerfilter'})) {
17622: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17623: '<table><tr><td>'.&mt('Username').'<br />'.
17624: '<input type="text" name="ownerfilter" size="20" value="'.
17625: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17626: $ownerdomselectform.'</td></tr></table>'.
17627: &Apache::lonhtmlcommon::row_closure();
17628: }
17629: if (exists($filter->{'personfilter'})) {
17630: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17631: '<table><tr><td>'.&mt('Username').'<br />'.
17632: '<input type="text" name="personfilter" size="20" value="'.
17633: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17634: $persondomselectform.'</td></tr></table>'.
17635: &Apache::lonhtmlcommon::row_closure();
17636: }
17637: if (exists($filter->{'coursefilter'})) {
17638: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17639: .'<input type="text" name="coursefilter" size="25" value="'
17640: .$list->{'coursefilter'}.'" />'
17641: .&Apache::lonhtmlcommon::row_closure();
17642: }
17643: if ($cloneableonlyform) {
17644: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17645: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17646: }
17647: if (exists($filter->{'descriptfilter'})) {
17648: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17649: .'<input type="text" name="descriptfilter" size="40" value="'
17650: .$list->{'descriptfilter'}.'" />'
17651: .&Apache::lonhtmlcommon::row_closure(1);
17652: }
17653: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17654: '<input type="hidden" name="updater" value="" />'."\n".
17655: '<input type="submit" name="gosearch" value="'.
17656: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17657: return $jscript.$clonewarning.$output;
17658: }
17659:
17660: =pod
17661:
17662: =item * &timebased_select_form()
17663:
1.1182 raeburn 17664: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17665: filter e.g., Course Activity, Course Created, when searching for courses
17666: or communities
17667:
17668: Inputs:
17669:
17670: item - name of form element (sincefilter or createdfilter)
17671:
17672: filter - anonymous hash of criteria and their values
17673:
17674: Returns: HTML for a select box contained a blank, then six time selections,
17675: with value set in incoming form variables currently selected.
17676:
17677: Side Effects: None
17678:
17679: =cut
17680:
17681: sub timebased_select_form {
17682: my ($item,$filter) = @_;
17683: if (ref($filter) eq 'HASH') {
17684: $filter->{$item} =~ s/[^\d-]//g;
17685: if (!$filter->{$item}) { $filter->{$item}=-1; }
17686: return &select_form(
17687: $filter->{$item},
17688: $item,
17689: { '-1' => '',
17690: '86400' => &mt('today'),
17691: '604800' => &mt('last week'),
17692: '2592000' => &mt('last month'),
17693: '7776000' => &mt('last three months'),
17694: '15552000' => &mt('last six months'),
17695: '31104000' => &mt('last year'),
17696: 'select_form_order' =>
17697: ['-1','86400','604800','2592000','7776000',
17698: '15552000','31104000']});
17699: }
17700: }
17701:
17702: =pod
17703:
17704: =item * &js_changer()
17705:
17706: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17707: when course type or domain is changed, and also to hide 'Searching ...' on
17708: page load completion for page showing search result.
1.1181 raeburn 17709:
17710: Inputs: None
17711:
1.1183 raeburn 17712: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17713:
17714: Side Effects: None
17715:
17716: =cut
17717:
17718: sub js_changer {
17719: return <<ENDJS;
17720: <script type="text/javascript">
17721: // <![CDATA[
17722: function updateFilters(caller) {
17723: if (typeof(caller) != "undefined") {
17724: document.filterpicker.updater.value = caller.name;
17725: }
17726: document.filterpicker.submit();
17727: }
1.1183 raeburn 17728:
17729: function hideSearching() {
17730: if (document.getElementById('searching')) {
17731: document.getElementById('searching').style.display = 'none';
17732: }
17733: return;
17734: }
17735:
1.1181 raeburn 17736: // ]]>
17737: </script>
17738:
17739: ENDJS
17740: }
17741:
17742: =pod
17743:
1.1182 raeburn 17744: =item * &search_courses()
17745:
17746: Process selected filters form course search form and pass to lonnet::courseiddump
17747: to retrieve a hash for which keys are courseIDs which match the selected filters.
17748:
17749: Inputs:
17750:
17751: dom - domain being searched
17752:
17753: type - course type ('Course' or 'Community' or '.' if any).
17754:
17755: filter - anonymous hash of criteria and their values
17756:
17757: numtitles - for institutional codes - number of categories
17758:
17759: cloneruname - optional username of new course owner
17760:
17761: clonerudom - optional domain of new course owner
17762:
1.1221 raeburn 17763: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17764: (used when DC is using course creation form)
17765:
17766: codetitles - reference to array of titles of components in institutional codes (official courses).
17767:
1.1221 raeburn 17768: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17769: (and so can clone automatically)
17770:
17771: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17772:
17773: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17774: courses to clone
1.1182 raeburn 17775:
17776: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17777:
17778:
17779: Side Effects: None
17780:
17781: =cut
17782:
17783:
17784: sub search_courses {
1.1221 raeburn 17785: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17786: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17787: my (%courses,%showcourses,$cloner);
17788: if (($filter->{'ownerfilter'} ne '') ||
17789: ($filter->{'ownerdomfilter'} ne '')) {
17790: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17791: $filter->{'ownerdomfilter'};
17792: }
17793: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17794: if (!$filter->{$item}) {
17795: $filter->{$item}='.';
17796: }
17797: }
17798: my $now = time;
17799: my $timefilter =
17800: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17801: my ($createdbefore,$createdafter);
17802: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17803: $createdbefore = $now;
17804: $createdafter = $now-$filter->{'createdfilter'};
17805: }
17806: my ($instcodefilter,$regexpok);
17807: if ($numtitles) {
17808: if ($env{'form.official'} eq 'on') {
17809: $instcodefilter =
17810: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17811: $regexpok = 1;
17812: } elsif ($env{'form.official'} eq 'off') {
17813: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17814: unless ($instcodefilter eq '') {
17815: $regexpok = -1;
17816: }
17817: }
17818: } else {
17819: $instcodefilter = $filter->{'instcodefilter'};
17820: }
17821: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17822: if ($type eq '') { $type = '.'; }
17823:
17824: if (($clonerudom ne '') && ($cloneruname ne '')) {
17825: $cloner = $cloneruname.':'.$clonerudom;
17826: }
17827: %courses = &Apache::lonnet::courseiddump($dom,
17828: $filter->{'descriptfilter'},
17829: $timefilter,
17830: $instcodefilter,
17831: $filter->{'combownerfilter'},
17832: $filter->{'coursefilter'},
17833: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17834: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17835: $filter->{'cloneableonly'},
17836: $createdbefore,$createdafter,undef,
1.1221 raeburn 17837: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17838: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17839: my $ccrole;
17840: if ($type eq 'Community') {
17841: $ccrole = 'co';
17842: } else {
17843: $ccrole = 'cc';
17844: }
17845: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17846: $filter->{'persondomfilter'},
17847: 'userroles',undef,
17848: [$ccrole,'in','ad','ep','ta','cr'],
17849: $dom);
17850: foreach my $role (keys(%rolehash)) {
17851: my ($cnum,$cdom,$courserole) = split(':',$role);
17852: my $cid = $cdom.'_'.$cnum;
17853: if (exists($courses{$cid})) {
17854: if (ref($courses{$cid}) eq 'HASH') {
17855: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17856: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17857: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17858: }
17859: } else {
17860: $courses{$cid}{roles} = [$courserole];
17861: }
17862: $showcourses{$cid} = $courses{$cid};
17863: }
17864: }
17865: }
17866: %courses = %showcourses;
17867: }
17868: return %courses;
17869: }
17870:
17871: =pod
17872:
1.1181 raeburn 17873: =back
17874:
1.1207 raeburn 17875: =head1 Routines for version requirements for current course.
17876:
17877: =over 4
17878:
17879: =item * &check_release_required()
17880:
17881: Compares required LON-CAPA version with version on server, and
17882: if required version is newer looks for a server with the required version.
17883:
17884: Looks first at servers in user's owen domain; if none suitable, looks at
17885: servers in course's domain are permitted to host sessions for user's domain.
17886:
17887: Inputs:
17888:
17889: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17890:
17891: $courseid - Course ID of current course
17892:
17893: $rolecode - User's current role in course (for switchserver query string).
17894:
17895: $required - LON-CAPA version needed by course (format: Major.Minor).
17896:
17897:
17898: Returns:
17899:
17900: $switchserver - query string tp append to /adm/switchserver call (if
17901: current server's LON-CAPA version is too old.
17902:
17903: $warning - Message is displayed if no suitable server could be found.
17904:
17905: =cut
17906:
17907: sub check_release_required {
17908: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17909: my ($switchserver,$warning);
17910: if ($required ne '') {
17911: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17912: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17913: if ($reqdmajor ne '' && $reqdminor ne '') {
17914: my $otherserver;
17915: if (($major eq '' && $minor eq '') ||
17916: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17917: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17918: my $switchlcrev =
17919: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17920: $userdomserver);
17921: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17922: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17923: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17924: my $cdom = $env{'course.'.$courseid.'.domain'};
17925: if ($cdom ne $env{'user.domain'}) {
17926: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17927: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17928: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17929: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17930: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17931: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17932: my $canhost =
17933: &Apache::lonnet::can_host_session($env{'user.domain'},
17934: $coursedomserver,
17935: $remoterev,
17936: $udomdefaults{'remotesessions'},
17937: $defdomdefaults{'hostedsessions'});
17938:
17939: if ($canhost) {
17940: $otherserver = $coursedomserver;
17941: } else {
17942: $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.");
17943: }
17944: } else {
17945: $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).");
17946: }
17947: } else {
17948: $otherserver = $userdomserver;
17949: }
17950: }
17951: if ($otherserver ne '') {
17952: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17953: }
17954: }
17955: }
17956: return ($switchserver,$warning);
17957: }
17958:
17959: =pod
17960:
17961: =item * &check_release_result()
17962:
17963: Inputs:
17964:
17965: $switchwarning - Warning message if no suitable server found to host session.
17966:
17967: $switchserver - query string to append to /adm/switchserver containing lonHostID
17968: and current role.
17969:
17970: Returns: HTML to display with information about requirement to switch server.
17971: Either displaying warning with link to Roles/Courses screen or
17972: display link to switchserver.
17973:
1.1181 raeburn 17974: =cut
17975:
1.1207 raeburn 17976: sub check_release_result {
17977: my ($switchwarning,$switchserver) = @_;
17978: my $output = &start_page('Selected course unavailable on this server').
17979: '<p class="LC_warning">';
17980: if ($switchwarning) {
17981: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17982: if (&show_course()) {
17983: $output .= &mt('Display courses');
17984: } else {
17985: $output .= &mt('Display roles');
17986: }
17987: $output .= '</a>';
17988: } elsif ($switchserver) {
17989: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17990: '<br />'.
17991: '<a href="/adm/switchserver?'.$switchserver.'">'.
17992: &mt('Switch Server').
17993: '</a>';
17994: }
17995: $output .= '</p>'.&end_page();
17996: return $output;
17997: }
17998:
17999: =pod
18000:
18001: =item * &needs_coursereinit()
18002:
18003: Determine if course contents stored for user's session needs to be
18004: refreshed, because content has changed since "Big Hash" last tied.
18005:
18006: Check for change is made if time last checked is more than 10 minutes ago
18007: (by default).
18008:
18009: Inputs:
18010:
18011: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18012:
18013: $interval (optional) - Time which may elapse (in s) between last check for content
18014: change in current course. (default: 600 s).
18015:
18016: Returns: an array; first element is:
18017:
18018: =over 4
18019:
18020: 'switch' - if content updates mean user's session
18021: needs to be switched to a server running a newer LON-CAPA version
18022:
18023: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18024: on current server hosting user's session
18025:
18026: '' - if no action required.
18027:
18028: =back
18029:
18030: If first item element is 'switch':
18031:
18032: second item is $switchwarning - Warning message if no suitable server found to host session.
18033:
18034: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18035: and current role.
18036:
18037: otherwise: no other elements returned.
18038:
18039: =back
18040:
18041: =cut
18042:
18043: sub needs_coursereinit {
18044: my ($loncaparev,$interval) = @_;
18045: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18046: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18047: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18048: my $now = time;
18049: if ($interval eq '') {
18050: $interval = 600;
18051: }
18052: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18053: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18054: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18055: if ($blocked) {
18056: return ();
18057: }
1.1207 raeburn 18058: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18059: if ($lastchange > $env{'request.course.tied'}) {
18060: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18061: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18062: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18063: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18064: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18065: $curr_reqd_hash{'internal.releaserequired'}});
18066: my ($switchserver,$switchwarning) =
18067: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18068: $curr_reqd_hash{'internal.releaserequired'});
18069: if ($switchwarning ne '' || $switchserver ne '') {
18070: return ('switch',$switchwarning,$switchserver);
18071: }
18072: }
18073: }
18074: return ('update');
18075: }
18076: }
18077: return ();
18078: }
1.1181 raeburn 18079:
1.1083 raeburn 18080: sub update_content_constraints {
1.1326 raeburn 18081: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 18082: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18083: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18084: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18085: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18086: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18087: if ($item eq 'resourcetag') {
18088: if ($name eq 'responsetype') {
18089: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18090: }
1.1307 raeburn 18091: } elsif ($item eq 'course') {
18092: if ($name eq 'courserestype') {
18093: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18094: }
1.1083 raeburn 18095: }
18096: }
18097: my $navmap = Apache::lonnavmaps::navmap->new();
18098: if (defined($navmap)) {
1.1307 raeburn 18099: my (%allresponses,%allcrsrestypes);
18100: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18101: if ($res->is_tool()) {
18102: if ($allcrsrestypes{'exttool'}) {
18103: $allcrsrestypes{'exttool'} ++;
18104: } else {
18105: $allcrsrestypes{'exttool'} = 1;
18106: }
18107: next;
18108: }
1.1083 raeburn 18109: my %responses = $res->responseTypes();
18110: foreach my $key (keys(%responses)) {
18111: next unless(exists($checkresponsetypes{$key}));
18112: $allresponses{$key} += $responses{$key};
18113: }
18114: }
18115: foreach my $key (keys(%allresponses)) {
18116: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18117: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18118: ($reqdmajor,$reqdminor) = ($major,$minor);
18119: }
18120: }
1.1307 raeburn 18121: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18122: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18123: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18124: ($reqdmajor,$reqdminor) = ($major,$minor);
18125: }
18126: }
1.1083 raeburn 18127: undef($navmap);
18128: }
1.1326 raeburn 18129: my (@resources,@order,@resparms,@zombies);
18130: if ($keeporder) {
18131: use LONCAPA::map;
18132: @resources = @LONCAPA::map::resources;
18133: @order = @LONCAPA::map::order;
18134: @resparms = @LONCAPA::map::resparms;
18135: @zombies = @LONCAPA::map::zombies;
18136: }
1.1308 raeburn 18137: my $suppmap = 'supplemental.sequence';
18138: my ($suppcount,$supptools,$errors) = (0,0,0);
18139: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
18140: $suppcount,$supptools,$errors);
1.1326 raeburn 18141: if ($keeporder) {
18142: @LONCAPA::map::resources = @resources;
18143: @LONCAPA::map::order = @order;
18144: @LONCAPA::map::resparms = @resparms;
18145: @LONCAPA::map::zombies = @zombies;
18146: }
1.1308 raeburn 18147: if ($supptools) {
18148: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18149: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18150: ($reqdmajor,$reqdminor) = ($major,$minor);
18151: }
18152: }
1.1083 raeburn 18153: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18154: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18155: }
18156: return;
18157: }
18158:
1.1110 raeburn 18159: sub allmaps_incourse {
18160: my ($cdom,$cnum,$chome,$cid) = @_;
18161: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18162: $cid = $env{'request.course.id'};
18163: $cdom = $env{'course.'.$cid.'.domain'};
18164: $cnum = $env{'course.'.$cid.'.num'};
18165: $chome = $env{'course.'.$cid.'.home'};
18166: }
18167: my %allmaps = ();
18168: my $lastchange =
18169: &Apache::lonnet::get_coursechange($cdom,$cnum);
18170: if ($lastchange > $env{'request.course.tied'}) {
18171: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18172: unless ($ferr) {
1.1326 raeburn 18173: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 18174: }
18175: }
18176: my $navmap = Apache::lonnavmaps::navmap->new();
18177: if (defined($navmap)) {
18178: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18179: $allmaps{$res->src()} = 1;
18180: }
18181: }
18182: return \%allmaps;
18183: }
18184:
1.1083 raeburn 18185: sub parse_supplemental_title {
18186: my ($title) = @_;
18187:
18188: my ($foldertitle,$renametitle);
18189: if ($title =~ /&&&/) {
18190: $title = &HTML::Entites::decode($title);
18191: }
18192: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18193: $renametitle=$4;
18194: my ($time,$uname,$udom) = ($1,$2,$3);
18195: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18196: my $name = &plainname($uname,$udom);
18197: $name = &HTML::Entities::encode($name,'"<>&\'');
18198: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
18199: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
18200: $name.': <br />'.$foldertitle;
18201: }
18202: if (wantarray) {
18203: return ($title,$foldertitle,$renametitle);
18204: }
18205: return $title;
18206: }
18207:
1.1143 raeburn 18208: sub recurse_supplemental {
1.1308 raeburn 18209: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 18210: if ($suppmap) {
18211: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18212: if ($fatal) {
18213: $errors ++;
18214: } else {
18215: if ($#LONCAPA::map::resources > 0) {
18216: foreach my $res (@LONCAPA::map::resources) {
18217: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
18218: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 18219: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 18220: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
18221: $numfiles,$numexttools,$errors);
1.1143 raeburn 18222: } else {
1.1308 raeburn 18223: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
18224: $numexttools ++;
18225: }
1.1143 raeburn 18226: $numfiles ++;
18227: }
18228: }
18229: }
18230: }
18231: }
18232: }
1.1308 raeburn 18233: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 18234: }
18235:
1.1101 raeburn 18236: sub symb_to_docspath {
1.1267 raeburn 18237: my ($symb,$navmapref) = @_;
18238: return unless ($symb && ref($navmapref));
1.1101 raeburn 18239: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18240: if ($resurl=~/\.(sequence|page)$/) {
18241: $mapurl=$resurl;
18242: } elsif ($resurl eq 'adm/navmaps') {
18243: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18244: }
18245: my $mapresobj;
1.1267 raeburn 18246: unless (ref($$navmapref)) {
18247: $$navmapref = Apache::lonnavmaps::navmap->new();
18248: }
18249: if (ref($$navmapref)) {
18250: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18251: }
18252: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18253: my $type=$2;
18254: my $path;
18255: if (ref($mapresobj)) {
18256: my $pcslist = $mapresobj->map_hierarchy();
18257: if ($pcslist ne '') {
18258: foreach my $pc (split(/,/,$pcslist)) {
18259: next if ($pc <= 1);
1.1267 raeburn 18260: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18261: if (ref($res)) {
18262: my $thisurl = $res->src();
18263: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18264: my $thistitle = $res->title();
18265: $path .= '&'.
18266: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18267: &escape($thistitle).
1.1101 raeburn 18268: ':'.$res->randompick().
18269: ':'.$res->randomout().
18270: ':'.$res->encrypted().
18271: ':'.$res->randomorder().
18272: ':'.$res->is_page();
18273: }
18274: }
18275: }
18276: $path =~ s/^\&//;
18277: my $maptitle = $mapresobj->title();
18278: if ($mapurl eq 'default') {
1.1129 raeburn 18279: $maptitle = 'Main Content';
1.1101 raeburn 18280: }
18281: $path .= (($path ne '')? '&' : '').
18282: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18283: &escape($maptitle).
1.1101 raeburn 18284: ':'.$mapresobj->randompick().
18285: ':'.$mapresobj->randomout().
18286: ':'.$mapresobj->encrypted().
18287: ':'.$mapresobj->randomorder().
18288: ':'.$mapresobj->is_page();
18289: } else {
18290: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18291: my $ispage = (($type eq 'page')? 1 : '');
18292: if ($mapurl eq 'default') {
1.1129 raeburn 18293: $maptitle = 'Main Content';
1.1101 raeburn 18294: }
18295: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18296: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18297: }
18298: unless ($mapurl eq 'default') {
18299: $path = 'default&'.
1.1146 raeburn 18300: &escape('Main Content').
1.1101 raeburn 18301: ':::::&'.$path;
18302: }
18303: return $path;
18304: }
18305:
1.1094 raeburn 18306: sub captcha_display {
1.1327 raeburn 18307: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18308: my ($output,$error);
1.1234 raeburn 18309: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18310: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18311: if ($captcha eq 'original') {
1.1094 raeburn 18312: $output = &create_captcha();
18313: unless ($output) {
1.1172 raeburn 18314: $error = 'captcha';
1.1094 raeburn 18315: }
18316: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18317: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18318: unless ($output) {
1.1172 raeburn 18319: $error = 'recaptcha';
1.1094 raeburn 18320: }
18321: }
1.1234 raeburn 18322: return ($output,$error,$captcha,$version);
1.1094 raeburn 18323: }
18324:
18325: sub captcha_response {
1.1327 raeburn 18326: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18327: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18328: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18329: if ($captcha eq 'original') {
1.1094 raeburn 18330: ($captcha_chk,$captcha_error) = &check_captcha();
18331: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18332: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18333: } else {
18334: $captcha_chk = 1;
18335: }
18336: return ($captcha_chk,$captcha_error);
18337: }
18338:
18339: sub get_captcha_config {
1.1327 raeburn 18340: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18341: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18342: my $hostname = &Apache::lonnet::hostname($lonhost);
18343: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18344: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18345: if ($context eq 'usercreation') {
18346: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18347: if (ref($domconfig{$context}) eq 'HASH') {
18348: $hashtocheck = $domconfig{$context}{'cancreate'};
18349: if (ref($hashtocheck) eq 'HASH') {
18350: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18351: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18352: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18353: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18354: }
18355: if ($privkey && $pubkey) {
18356: $captcha = 'recaptcha';
1.1234 raeburn 18357: $version = $hashtocheck->{'recaptchaversion'};
18358: if ($version ne '2') {
18359: $version = 1;
18360: }
1.1095 raeburn 18361: } else {
18362: $captcha = 'original';
18363: }
18364: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18365: $captcha = 'original';
18366: }
1.1094 raeburn 18367: }
1.1095 raeburn 18368: } else {
18369: $captcha = 'captcha';
18370: }
18371: } elsif ($context eq 'login') {
18372: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18373: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18374: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18375: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18376: if ($privkey && $pubkey) {
18377: $captcha = 'recaptcha';
1.1234 raeburn 18378: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18379: if ($version ne '2') {
18380: $version = 1;
18381: }
1.1095 raeburn 18382: } else {
18383: $captcha = 'original';
1.1094 raeburn 18384: }
1.1095 raeburn 18385: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18386: $captcha = 'original';
1.1094 raeburn 18387: }
1.1327 raeburn 18388: } elsif ($context eq 'passwords') {
18389: if ($dom_in_effect) {
18390: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18391: if ($passwdconf{'captcha'} eq 'recaptcha') {
18392: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18393: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18394: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18395: }
18396: if ($privkey && $pubkey) {
18397: $captcha = 'recaptcha';
18398: $version = $passwdconf{'recaptchaversion'};
18399: if ($version ne '2') {
18400: $version = 1;
18401: }
18402: } else {
18403: $captcha = 'original';
18404: }
18405: } elsif ($passwdconf{'captcha'} ne 'notused') {
18406: $captcha = 'original';
18407: }
18408: }
18409: }
1.1234 raeburn 18410: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18411: }
18412:
18413: sub create_captcha {
18414: my %captcha_params = &captcha_settings();
18415: my ($output,$maxtries,$tries) = ('',10,0);
18416: while ($tries < $maxtries) {
18417: $tries ++;
18418: my $captcha = Authen::Captcha->new (
18419: output_folder => $captcha_params{'output_dir'},
18420: data_folder => $captcha_params{'db_dir'},
18421: );
18422: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18423:
18424: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18425: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 18426: '<span class="LC_nobreak">'.
1.1094 raeburn 18427: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18428: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1367 raeburn 18429: '</span><br />'.
1.1176 raeburn 18430: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18431: last;
18432: }
18433: }
1.1323 raeburn 18434: if ($output eq '') {
18435: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18436: }
1.1094 raeburn 18437: return $output;
18438: }
18439:
18440: sub captcha_settings {
18441: my %captcha_params = (
18442: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18443: www_output_dir => "/captchaspool",
18444: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18445: numchars => '5',
18446: );
18447: return %captcha_params;
18448: }
18449:
18450: sub check_captcha {
18451: my ($captcha_chk,$captcha_error);
18452: my $code = $env{'form.code'};
18453: my $md5sum = $env{'form.crypt'};
18454: my %captcha_params = &captcha_settings();
18455: my $captcha = Authen::Captcha->new(
18456: output_folder => $captcha_params{'output_dir'},
18457: data_folder => $captcha_params{'db_dir'},
18458: );
1.1109 raeburn 18459: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18460: my %captcha_hash = (
18461: 0 => 'Code not checked (file error)',
18462: -1 => 'Failed: code expired',
18463: -2 => 'Failed: invalid code (not in database)',
18464: -3 => 'Failed: invalid code (code does not match crypt)',
18465: );
18466: if ($captcha_chk != 1) {
18467: $captcha_error = $captcha_hash{$captcha_chk}
18468: }
18469: return ($captcha_chk,$captcha_error);
18470: }
18471:
18472: sub create_recaptcha {
1.1234 raeburn 18473: my ($pubkey,$version) = @_;
18474: if ($version >= 2) {
1.1367 raeburn 18475: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18476: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 18477: } else {
18478: my $use_ssl;
18479: if ($ENV{'SERVER_PORT'} == 443) {
18480: $use_ssl = 1;
18481: }
18482: my $captcha = Captcha::reCAPTCHA->new;
18483: return $captcha->get_options_setter({theme => 'white'})."\n".
18484: $captcha->get_html($pubkey,undef,$use_ssl).
18485: &mt('If the text is hard to read, [_1] will replace them.',
18486: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18487: '<br /><br />';
18488: }
1.1094 raeburn 18489: }
18490:
18491: sub check_recaptcha {
1.1234 raeburn 18492: my ($privkey,$version) = @_;
1.1094 raeburn 18493: my $captcha_chk;
1.1350 raeburn 18494: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18495: if ($version >= 2) {
18496: my %info = (
18497: secret => $privkey,
18498: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18499: remoteip => $ip,
1.1234 raeburn 18500: );
1.1280 raeburn 18501: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18502: $request->content(join('&',map {
18503: my $name = escape($_);
18504: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18505: ? join("&$name=", map {escape($_) } @{$info{$_}})
18506: : &escape($info{$_}) );
18507: } keys(%info)));
18508: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18509: if ($response->is_success) {
18510: my $data = JSON::DWIW->from_json($response->decoded_content);
18511: if (ref($data) eq 'HASH') {
18512: if ($data->{'success'}) {
18513: $captcha_chk = 1;
18514: }
18515: }
18516: }
18517: } else {
18518: my $captcha = Captcha::reCAPTCHA->new;
18519: my $captcha_result =
18520: $captcha->check_answer(
18521: $privkey,
1.1350 raeburn 18522: $ip,
1.1234 raeburn 18523: $env{'form.recaptcha_challenge_field'},
18524: $env{'form.recaptcha_response_field'},
18525: );
18526: if ($captcha_result->{is_valid}) {
18527: $captcha_chk = 1;
18528: }
1.1094 raeburn 18529: }
18530: return $captcha_chk;
18531: }
18532:
1.1174 raeburn 18533: sub emailusername_info {
1.1244 raeburn 18534: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18535: my %titles = &Apache::lonlocal::texthash (
18536: lastname => 'Last Name',
18537: firstname => 'First Name',
18538: institution => 'School/college/university',
18539: location => "School's city, state/province, country",
18540: web => "School's web address",
18541: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18542: id => 'Student/Employee ID',
1.1174 raeburn 18543: );
18544: return (\@fields,\%titles);
18545: }
18546:
1.1161 raeburn 18547: sub cleanup_html {
18548: my ($incoming) = @_;
18549: my $outgoing;
18550: if ($incoming ne '') {
18551: $outgoing = $incoming;
18552: $outgoing =~ s/;/;/g;
18553: $outgoing =~ s/\#/#/g;
18554: $outgoing =~ s/\&/&/g;
18555: $outgoing =~ s/</</g;
18556: $outgoing =~ s/>/>/g;
18557: $outgoing =~ s/\(/(/g;
18558: $outgoing =~ s/\)/)/g;
18559: $outgoing =~ s/"/"/g;
18560: $outgoing =~ s/'/'/g;
18561: $outgoing =~ s/\$/$/g;
18562: $outgoing =~ s{/}{/}g;
18563: $outgoing =~ s/=/=/g;
18564: $outgoing =~ s/\\/\/g
18565: }
18566: return $outgoing;
18567: }
18568:
1.1190 musolffc 18569: # Checks for critical messages and returns a redirect url if one exists.
18570: # $interval indicates how often to check for messages.
1.1282 raeburn 18571: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18572: sub critical_redirect {
1.1282 raeburn 18573: my ($interval,$context) = @_;
1.1356 raeburn 18574: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18575: return ();
18576: }
1.1190 musolffc 18577: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18578: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18579: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18580: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 18581: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18582: if ($blocked) {
18583: my $checkrole = "cm./$cdom/$cnum";
18584: if ($env{'request.course.sec'} ne '') {
18585: $checkrole .= "/$env{'request.course.sec'}";
18586: }
18587: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18588: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18589: return;
18590: }
18591: }
18592: }
1.1190 musolffc 18593: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18594: $env{'user.name'});
18595: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18596: my $redirecturl;
1.1190 musolffc 18597: if ($what[0]) {
1.1356 raeburn 18598: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 18599: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18600: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18601: return (1, $url);
1.1190 musolffc 18602: }
1.1191 raeburn 18603: }
18604: }
18605: return ();
1.1190 musolffc 18606: }
18607:
1.1174 raeburn 18608: # Use:
18609: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18610: #
18611: ##################################################
18612: # password associated functions #
18613: ##################################################
18614: sub des_keys {
18615: # Make a new key for DES encryption.
18616: # Each key has two parts which are returned separately.
18617: # Please note: Each key must be passed through the &hex function
18618: # before it is output to the web browser. The hex versions cannot
18619: # be used to decrypt.
18620: my @hexstr=('0','1','2','3','4','5','6','7',
18621: '8','9','a','b','c','d','e','f');
18622: my $lkey='';
18623: for (0..7) {
18624: $lkey.=$hexstr[rand(15)];
18625: }
18626: my $ukey='';
18627: for (0..7) {
18628: $ukey.=$hexstr[rand(15)];
18629: }
18630: return ($lkey,$ukey);
18631: }
18632:
18633: sub des_decrypt {
18634: my ($key,$cyphertext) = @_;
18635: my $keybin=pack("H16",$key);
18636: my $cypher;
18637: if ($Crypt::DES::VERSION>=2.03) {
18638: $cypher=new Crypt::DES $keybin;
18639: } else {
18640: $cypher=new DES $keybin;
18641: }
1.1233 raeburn 18642: my $plaintext='';
18643: my $cypherlength = length($cyphertext);
18644: my $numchunks = int($cypherlength/32);
18645: for (my $j=0; $j<$numchunks; $j++) {
18646: my $start = $j*32;
18647: my $cypherblock = substr($cyphertext,$start,32);
18648: my $chunk =
18649: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18650: $chunk .=
18651: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18652: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18653: $plaintext .= $chunk;
18654: }
1.1174 raeburn 18655: return $plaintext;
18656: }
18657:
1.1344 raeburn 18658: sub get_requested_shorturls {
1.1309 raeburn 18659: my ($cdom,$cnum,$navmap) = @_;
18660: return unless (ref($navmap));
1.1344 raeburn 18661: my ($numnew,$errors);
1.1309 raeburn 18662: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18663: if (@toshorten) {
18664: my (%maps,%resources,%titles);
18665: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18666: 'shorturls',$cdom,$cnum);
18667: if (keys(%resources)) {
1.1344 raeburn 18668: my %tocreate;
1.1309 raeburn 18669: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18670: my $symb = $resources{$item};
18671: if ($symb) {
18672: $tocreate{$cnum.'&'.$symb} = 1;
18673: }
18674: }
1.1344 raeburn 18675: if (keys(%tocreate)) {
18676: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18677: \%tocreate);
18678: }
1.1309 raeburn 18679: }
1.1344 raeburn 18680: }
18681: return ($numnew,$errors);
18682: }
18683:
18684: sub make_short_symbs {
18685: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18686: my ($numnew,@errors);
18687: if (ref($tocreateref) eq 'HASH') {
18688: my %tocreate = %{$tocreateref};
1.1309 raeburn 18689: if (keys(%tocreate)) {
18690: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18691: my $su = Short::URL->new(no_vowels => 1);
18692: my $init = '';
18693: my (%newunique,%addcourse,%courseonly,%failed);
18694: # get lock on tiny db
18695: my $now = time;
1.1344 raeburn 18696: if ($lockuser eq '') {
18697: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18698: }
1.1309 raeburn 18699: my $lockhash = {
1.1344 raeburn 18700: "lock\0$now" => $lockuser,
1.1309 raeburn 18701: };
18702: my $tries = 0;
18703: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18704: my ($code,$error);
18705: while (($gotlock ne 'ok') && ($tries<3)) {
18706: $tries ++;
18707: sleep 1;
1.1319 raeburn 18708: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18709: }
18710: if ($gotlock eq 'ok') {
18711: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18712: \%addcourse,\%courseonly,\%failed);
18713: if (keys(%failed)) {
18714: my $numfailed = scalar(keys(%failed));
18715: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18716: }
18717: if (keys(%newunique)) {
18718: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18719: if ($putres eq 'ok') {
18720: $numnew = scalar(keys(%newunique));
18721: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18722: unless ($newputres eq 'ok') {
18723: push(@errors,&mt('error: could not store course look-up of short URLs'));
18724: }
18725: } else {
18726: push(@errors,&mt('error: could not store unique six character URLs'));
18727: }
18728: }
18729: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18730: unless ($dellockres eq 'ok') {
18731: push(@errors,&mt('error: could not release lockfile'));
18732: }
18733: } else {
18734: push(@errors,&mt('error: could not obtain lockfile'));
18735: }
18736: if (keys(%courseonly)) {
18737: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18738: if ($result ne 'ok') {
18739: push(@errors,&mt('error: could not update course look-up of short URLs'));
18740: }
18741: }
18742: }
18743: }
18744: return ($numnew,\@errors);
18745: }
18746:
18747: sub shorten_symbs {
18748: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18749: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18750: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18751: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18752: my (%possibles,%collisions);
18753: foreach my $key (keys(%{$tocreate})) {
18754: my $num = String::CRC32::crc32($key);
18755: my $tiny = $su->encode($num,$init);
18756: if ($tiny) {
18757: $possibles{$tiny} = $key;
18758: }
18759: }
18760: if (!$init) {
18761: $init = 1;
18762: } else {
18763: $init ++;
18764: }
18765: if (keys(%possibles)) {
18766: my @posstiny = keys(%possibles);
18767: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18768: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18769: if (keys(%currtiny)) {
18770: foreach my $key (keys(%currtiny)) {
18771: next if ($currtiny{$key} eq '');
18772: if ($currtiny{$key} eq $possibles{$key}) {
18773: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18774: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18775: $courseonly->{$tsymb} = $key;
18776: }
18777: } else {
18778: $collisions{$possibles{$key}} = 1;
18779: }
18780: delete($possibles{$key});
18781: }
18782: }
18783: foreach my $key (keys(%possibles)) {
18784: $newunique->{$key} = $possibles{$key};
18785: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18786: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18787: $addcourse->{$tsymb} = $key;
18788: }
18789: }
18790: }
18791: if (keys(%collisions)) {
18792: if ($init <5) {
18793: if (!$init) {
18794: $init = 1;
18795: } else {
18796: $init ++;
18797: }
18798: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18799: $newunique,$addcourse,$courseonly,$failed);
18800: } else {
18801: foreach my $key (keys(%collisions)) {
18802: $failed->{$key} = 1;
18803: }
18804: }
18805: }
18806: return $init;
18807: }
18808:
1.1328 raeburn 18809: sub is_nonframeable {
1.1329 raeburn 18810: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18811: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18812: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18813:
18814: $remprotocol = lc($remprotocol);
18815: $remhost = lc($remhost);
18816: my $remport = 80;
18817: if ($remprotocol eq 'https') {
18818: $remport = 443;
18819: }
1.1330 raeburn 18820: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18821: if ($cached) {
18822: unless ($nocache) {
18823: if ($result) {
18824: return 1;
18825: } else {
18826: return 0;
18827: }
18828: }
18829: }
1.1328 raeburn 18830: my $uselink;
18831: my $request = new HTTP::Request('HEAD',$url);
18832: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18833: if ($response->is_success()) {
18834: my $secpolicy = lc($response->header('content-security-policy'));
18835: my $xframeop = lc($response->header('x-frame-options'));
18836: $secpolicy =~ s/^\s+|\s+$//g;
18837: $xframeop =~ s/^\s+|\s+$//g;
18838: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18839: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18840: my ($origin,$protocol,$port);
18841: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18842: $port = $ENV{'SERVER_PORT'};
18843: } else {
18844: $port = 80;
18845: }
18846: if ($absolute eq '') {
18847: $protocol = 'http:';
18848: if ($port == 443) {
18849: $protocol = 'https:';
18850: }
18851: $origin = $protocol.'//'.lc($hostname);
18852: } else {
18853: $origin = lc($absolute);
18854: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18855: }
18856: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18857: my $framepolicy = $1;
18858: $framepolicy =~ s/^\s+|\s+$//g;
18859: my @policies = split(/\s+/,$framepolicy);
18860: if (@policies) {
18861: if (grep(/^\Q'none'\E$/,@policies)) {
18862: $uselink = 1;
18863: } else {
18864: $uselink = 1;
18865: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18866: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18867: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18868: undef($uselink);
18869: }
18870: if ($uselink) {
18871: if (grep(/^\Q'self'\E$/,@policies)) {
18872: if (($origin ne '') && ($remotehost eq $origin)) {
18873: undef($uselink);
18874: }
18875: }
18876: }
18877: if ($uselink) {
18878: my @possok;
18879: if ($ip ne '') {
18880: push(@possok,$ip);
18881: }
18882: my $hoststr = '';
18883: foreach my $part (reverse(split(/\./,$hostname))) {
18884: if ($hoststr eq '') {
18885: $hoststr = $part;
18886: } else {
18887: $hoststr = "$part.$hoststr";
18888: }
18889: if ($hoststr eq $hostname) {
18890: push(@possok,$hostname);
18891: } else {
18892: push(@possok,"*.$hoststr");
18893: }
18894: }
18895: if (@possok) {
18896: foreach my $poss (@possok) {
18897: last if (!$uselink);
18898: foreach my $policy (@policies) {
18899: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18900: undef($uselink);
18901: last;
18902: }
18903: }
18904: }
18905: }
18906: }
18907: }
18908: }
18909: } elsif ($xframeop ne '') {
18910: $uselink = 1;
18911: my @policies = split(/\s*,\s*/,$xframeop);
18912: if (@policies) {
18913: unless (grep(/^deny$/,@policies)) {
18914: if ($origin ne '') {
18915: if (grep(/^sameorigin$/,@policies)) {
18916: if ($remotehost eq $origin) {
18917: undef($uselink);
18918: }
18919: }
18920: if ($uselink) {
18921: foreach my $policy (@policies) {
18922: if ($policy =~ /^allow-from\s*(.+)$/) {
18923: my $allowfrom = $1;
18924: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18925: undef($uselink);
18926: last;
18927: }
18928: }
18929: }
18930: }
18931: }
18932: }
18933: }
18934: }
18935: }
18936: }
1.1329 raeburn 18937: if ($nocache) {
18938: if ($cached) {
18939: my $devalidate;
18940: if ($uselink && !$result) {
18941: $devalidate = 1;
18942: } elsif (!$uselink && $result) {
18943: $devalidate = 1;
18944: }
18945: if ($devalidate) {
18946: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18947: }
18948: }
18949: } else {
18950: if ($uselink) {
18951: $result = 1;
18952: } else {
18953: $result = 0;
18954: }
18955: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18956: }
1.1328 raeburn 18957: return $uselink;
18958: }
18959:
1.1359 raeburn 18960: sub page_menu {
18961: my ($menucolls,$menunum) = @_;
18962: my %menu;
18963: foreach my $item (split(/;/,$menucolls)) {
18964: my ($num,$value) = split(/\%/,$item);
18965: if ($num eq $menunum) {
18966: my @entries = split(/\&/,$value);
18967: foreach my $entry (@entries) {
18968: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 18969: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 18970: $menu{$name} = $fields;
18971: } else {
18972: my @shown;
18973: if ($fields =~ /,/) {
18974: @shown = split(/,/,$fields);
18975: } else {
18976: @shown = ($fields);
18977: }
18978: if (@shown) {
18979: foreach my $field (@shown) {
18980: next if ($field eq '');
18981: $menu{$field} = 1;
18982: }
18983: }
18984: }
18985: }
18986: }
18987: }
18988: return %menu;
18989: }
18990:
1.112 bowersj2 18991: 1;
18992: __END__;
1.41 ng 18993:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>