Annotation of loncom/interface/loncommon.pm, revision 1.1338
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1338 ! raeburn 4: # $Id: loncommon.pm,v 1.1337 2020/02/12 16:25:48 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.1328 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1241 raeburn 77: use DateTime::Locale;
1.1220 raeburn 78: use Encode();
1.1091 foxr 79: use Text::Aspell;
1.1094 raeburn 80: use Authen::Captcha;
81: use Captcha::reCAPTCHA;
1.1234 raeburn 82: use JSON::DWIW;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.1292 raeburn 87: use File::Copy();
1.1300 raeburn 88: use File::Path();
1.1309 raeburn 89: use String::CRC32();
90: use Short::URL();
1.117 www 91:
1.517 raeburn 92: # ---------------------------------------------- Designs
93: use vars qw(%defaultdesign);
94:
1.22 www 95: my $readit;
96:
1.517 raeburn 97:
1.157 matthew 98: ##
99: ## Global Variables
100: ##
1.46 matthew 101:
1.643 foxr 102:
103: # ----------------------------------------------- SSI with retries:
104: #
105:
106: =pod
107:
1.648 raeburn 108: =head1 Server Side include with retries:
1.643 foxr 109:
110: =over 4
111:
1.648 raeburn 112: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 113:
114: Performs an ssi with some number of retries. Retries continue either
115: until the result is ok or until the retry count supplied by the
116: caller is exhausted.
117:
118: Inputs:
1.648 raeburn 119:
120: =over 4
121:
1.643 foxr 122: resource - Identifies the resource to insert.
1.648 raeburn 123:
1.643 foxr 124: retries - Count of the number of retries allowed.
1.648 raeburn 125:
1.643 foxr 126: form - Hash that identifies the rendering options.
127:
1.648 raeburn 128: =back
129:
130: Returns:
131:
132: =over 4
133:
1.643 foxr 134: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 135:
1.643 foxr 136: response - The response from the last attempt (which may or may not have been successful.
137:
1.648 raeburn 138: =back
139:
140: =back
141:
1.643 foxr 142: =cut
143:
144: sub ssi_with_retries {
145: my ($resource, $retries, %form) = @_;
146:
147:
148: my $ok = 0; # True if we got a good response.
149: my $content;
150: my $response;
151:
152: # Try to get the ssi done. within the retries count:
153:
154: do {
155: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
156: $ok = $response->is_success;
1.650 www 157: if (!$ok) {
158: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
159: }
1.643 foxr 160: $retries--;
161: } while (!$ok && ($retries > 0));
162:
163: if (!$ok) {
164: $content = ''; # On error return an empty content.
165: }
166: return ($content, $response);
167:
168: }
169:
170:
171:
1.20 www 172: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 173: my %language;
1.124 www 174: my %supported_language;
1.1088 foxr 175: my %supported_codes;
1.1048 foxr 176: my %latex_language; # For choosing hyphenation in <transl..>
177: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 178: my %cprtag;
1.192 taceyjo1 179: my %scprtag;
1.351 www 180: my %fe; my %fd; my %fm;
1.41 ng 181: my %category_extensions;
1.12 harris41 182:
1.46 matthew 183: # ---------------------------------------------- Thesaurus variables
1.144 matthew 184: #
185: # %Keywords:
186: # A hash used by &keyword to determine if a word is considered a keyword.
187: # $thesaurus_db_file
188: # Scalar containing the full path to the thesaurus database.
1.46 matthew 189:
190: my %Keywords;
191: my $thesaurus_db_file;
192:
1.144 matthew 193: #
194: # Initialize values from language.tab, copyright.tab, filetypes.tab,
195: # thesaurus.tab, and filecategories.tab.
196: #
1.18 www 197: BEGIN {
1.46 matthew 198: # Variable initialization
199: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
200: #
1.22 www 201: unless ($readit) {
1.12 harris41 202: # ------------------------------------------------------------------- languages
203: {
1.158 raeburn 204: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
205: '/language.tab';
1.1317 raeburn 206: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 207: while (my $line = <$fh>) {
208: next if ($line=~/^\#/);
209: chomp($line);
1.1088 foxr 210: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 211: $language{$key}=$val.' - '.$enc;
212: if ($sup) {
213: $supported_language{$key}=$sup;
1.1088 foxr 214: $supported_codes{$key} = $code;
1.158 raeburn 215: }
1.1048 foxr 216: if ($latex) {
217: $latex_language_bykey{$key} = $latex;
1.1088 foxr 218: $latex_language{$code} = $latex;
1.1048 foxr 219: }
1.158 raeburn 220: }
221: close($fh);
222: }
1.12 harris41 223: }
224: # ------------------------------------------------------------------ copyrights
225: {
1.158 raeburn 226: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
227: '/copyright.tab';
1.1317 raeburn 228: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 229: while (my $line = <$fh>) {
230: next if ($line=~/^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 233: $cprtag{$key}=$val;
234: }
235: close($fh);
236: }
1.12 harris41 237: }
1.351 www 238: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 239: {
240: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
241: '/source_copyright.tab';
1.1317 raeburn 242: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 247: $scprtag{$key}=$val;
248: }
249: close($fh);
250: }
251: }
1.63 www 252:
1.517 raeburn 253: # -------------------------------------------------------------- default domain designs
1.63 www 254: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 255: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 256: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 257: while (my $line = <$fh>) {
258: next if ($line =~ /^\#/);
259: chomp($line);
260: my ($key,$val)=(split(/\=/,$line));
261: if ($val) { $defaultdesign{$key}=$val; }
262: }
263: close($fh);
1.63 www 264: }
265:
1.15 harris41 266: # ------------------------------------------------------------- file categories
267: {
1.158 raeburn 268: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
269: '/filecategories.tab';
1.1317 raeburn 270: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 271: while (my $line = <$fh>) {
272: next if ($line =~ /^\#/);
273: chomp($line);
274: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 275: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 276: }
277: close($fh);
278: }
279:
1.15 harris41 280: }
1.12 harris41 281: # ------------------------------------------------------------------ file types
282: {
1.158 raeburn 283: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
284: '/filetypes.tab';
1.1317 raeburn 285: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 286: while (my $line = <$fh>) {
287: next if ($line =~ /^\#/);
288: chomp($line);
289: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 290: if ($descr ne '') {
291: $fe{$ending}=lc($emb);
292: $fd{$ending}=$descr;
1.351 www 293: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 294: }
295: }
296: close($fh);
297: }
1.12 harris41 298: }
1.22 www 299: &Apache::lonnet::logthis(
1.705 tempelho 300: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 301: $readit=1;
1.46 matthew 302: } # end of unless($readit)
1.32 matthew 303:
304: }
1.112 bowersj2 305:
1.42 matthew 306: ###############################################################
307: ## HTML and Javascript Helper Functions ##
308: ###############################################################
309:
310: =pod
311:
1.112 bowersj2 312: =head1 HTML and Javascript Functions
1.42 matthew 313:
1.112 bowersj2 314: =over 4
315:
1.648 raeburn 316: =item * &browser_and_searcher_javascript()
1.112 bowersj2 317:
318: X<browsing, javascript>X<searching, javascript>Returns a string
319: containing javascript with two functions, C<openbrowser> and
320: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
321: tags.
1.42 matthew 322:
1.648 raeburn 323: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 324:
325: inputs: formname, elementname, only, omit
326:
327: formname and elementname indicate the name of the html form and name of
328: the element that the results of the browsing selection are to be placed in.
329:
330: Specifying 'only' will restrict the browser to displaying only files
1.185 www 331: with the given extension. Can be a comma separated list.
1.42 matthew 332:
333: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 334: with the given extension. Can be a comma separated list.
1.42 matthew 335:
1.648 raeburn 336: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 337:
338: Inputs: formname, elementname
339:
340: formname and elementname specify the name of the html form and the name
341: of the element the selection from the search results will be placed in.
1.542 raeburn 342:
1.42 matthew 343: =cut
344:
345: sub browser_and_searcher_javascript {
1.199 albertel 346: my ($mode)=@_;
347: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 348: my $resurl=&escape_single(&lastresurl());
1.42 matthew 349: return <<END;
1.219 albertel 350: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 351: var editbrowser = null;
1.135 albertel 352: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 353: var url = '$resurl/?';
1.42 matthew 354: if (editbrowser == null) {
355: url += 'launch=1&';
356: }
357: url += 'catalogmode=interactive&';
1.199 albertel 358: url += 'mode=$mode&';
1.611 albertel 359: url += 'inhibitmenu=yes&';
1.42 matthew 360: url += 'form=' + formname + '&';
361: if (only != null) {
362: url += 'only=' + only + '&';
1.217 albertel 363: } else {
364: url += 'only=&';
365: }
1.42 matthew 366: if (omit != null) {
367: url += 'omit=' + omit + '&';
1.217 albertel 368: } else {
369: url += 'omit=&';
370: }
1.135 albertel 371: if (titleelement != null) {
372: url += 'titleelement=' + titleelement + '&';
1.217 albertel 373: } else {
374: url += 'titleelement=&';
375: }
1.42 matthew 376: url += 'element=' + elementname + '';
377: var title = 'Browser';
1.435 albertel 378: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 379: options += ',width=700,height=600';
380: editbrowser = open(url,title,options,'1');
381: editbrowser.focus();
382: }
383: var editsearcher;
1.135 albertel 384: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 385: var url = '/adm/searchcat?';
386: if (editsearcher == null) {
387: url += 'launch=1&';
388: }
389: url += 'catalogmode=interactive&';
1.199 albertel 390: url += 'mode=$mode&';
1.42 matthew 391: url += 'form=' + formname + '&';
1.135 albertel 392: if (titleelement != null) {
393: url += 'titleelement=' + titleelement + '&';
1.217 albertel 394: } else {
395: url += 'titleelement=&';
396: }
1.42 matthew 397: url += 'element=' + elementname + '';
398: var title = 'Search';
1.435 albertel 399: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 400: options += ',width=700,height=600';
401: editsearcher = open(url,title,options,'1');
402: editsearcher.focus();
403: }
1.219 albertel 404: // END LON-CAPA Internal -->
1.42 matthew 405: END
1.170 www 406: }
407:
408: sub lastresurl {
1.258 albertel 409: if ($env{'environment.lastresurl'}) {
410: return $env{'environment.lastresurl'}
1.170 www 411: } else {
412: return '/res';
413: }
414: }
415:
416: sub storeresurl {
417: my $resurl=&Apache::lonnet::clutter(shift);
418: unless ($resurl=~/^\/res/) { return 0; }
419: $resurl=~s/\/$//;
420: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 421: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 422: return 1;
1.42 matthew 423: }
424:
1.74 www 425: sub studentbrowser_javascript {
1.111 www 426: unless (
1.258 albertel 427: (($env{'request.course.id'}) &&
1.302 albertel 428: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
429: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
430: '/'.$env{'request.course.sec'})
431: ))
1.258 albertel 432: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 433: ) { return ''; }
1.74 www 434: return (<<'ENDSTDBRW');
1.776 bisitz 435: <script type="text/javascript" language="Javascript">
1.824 bisitz 436: // <![CDATA[
1.74 www 437: var stdeditbrowser;
1.1337 raeburn 438: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 439: var url = '/adm/pickstudent?';
440: var filter;
1.558 albertel 441: if (!ignorefilter) {
442: eval('filter=document.'+formname+'.'+uname+'.value;');
443: }
1.74 www 444: if (filter != null) {
445: if (filter != '') {
446: url += 'filter='+filter+'&';
447: }
448: }
449: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 450: '&udomelement='+udom+
451: '&clicker='+clicker;
1.111 www 452: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 453: if (courseadv == 'condition') {
454: if (document.getElementById('courseadv')) {
455: courseadv = document.getElementById('courseadv').value;
456: }
457: }
458: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 459: var title = 'Student_Browser';
1.74 www 460: var options = 'scrollbars=1,resizable=1,menubar=0';
461: options += ',width=700,height=600';
462: stdeditbrowser = open(url,title,options,'1');
463: stdeditbrowser.focus();
464: }
1.824 bisitz 465: // ]]>
1.74 www 466: </script>
467: ENDSTDBRW
468: }
1.42 matthew 469:
1.1003 www 470: sub resourcebrowser_javascript {
471: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 472: return (<<'ENDRESBRW');
1.1003 www 473: <script type="text/javascript" language="Javascript">
474: // <![CDATA[
475: var reseditbrowser;
1.1004 www 476: function openresbrowser(formname,reslink) {
1.1005 www 477: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 478: var title = 'Resource_Browser';
479: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 480: options += ',width=700,height=500';
1.1004 www 481: reseditbrowser = open(url,title,options,'1');
482: reseditbrowser.focus();
1.1003 www 483: }
484: // ]]>
485: </script>
1.1004 www 486: ENDRESBRW
1.1003 www 487: }
488:
1.74 www 489: sub selectstudent_link {
1.1337 raeburn 490: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 491: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
492: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
493: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 494: if ($env{'request.course.id'}) {
1.302 albertel 495: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
496: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
497: '/'.$env{'request.course.sec'})) {
1.111 www 498: return '';
499: }
1.999 www 500: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 501: if ($courseadv eq 'only') {
502: $callargs .= ",'',1,'$courseadv'";
503: } elsif ($courseadv eq 'none') {
504: $callargs .= ",'','','$courseadv'";
505: } elsif ($courseadv eq 'condition') {
506: $callargs .= ",'','','$courseadv'";
1.793 raeburn 507: }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openstdbrowser('.$callargs.');">'.
510: &mt('Select User').'</a></span>';
1.74 www 511: }
1.258 albertel 512: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 513: $callargs .= ",'',1";
1.793 raeburn 514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openstdbrowser('.$callargs.');">'.
516: &mt('Select User').'</a></span>';
1.111 www 517: }
518: return '';
1.91 www 519: }
520:
1.1004 www 521: sub selectresource_link {
522: my ($form,$reslink,$arg)=@_;
523:
524: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
525: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
526: unless ($env{'request.course.id'}) { return $arg; }
527: return '<span class="LC_nobreak">'.
528: '<a href="javascript:openresbrowser('.$callargs.');">'.
529: $arg.'</a></span>';
530: }
531:
532:
533:
1.653 raeburn 534: sub authorbrowser_javascript {
535: return <<"ENDAUTHORBRW";
1.776 bisitz 536: <script type="text/javascript" language="JavaScript">
1.824 bisitz 537: // <![CDATA[
1.653 raeburn 538: var stdeditbrowser;
539:
540: function openauthorbrowser(formname,udom) {
541: var url = '/adm/pickauthor?';
542: url += 'form='+formname+'&roledom='+udom;
543: var title = 'Author_Browser';
544: var options = 'scrollbars=1,resizable=1,menubar=0';
545: options += ',width=700,height=600';
546: stdeditbrowser = open(url,title,options,'1');
547: stdeditbrowser.focus();
548: }
549:
1.824 bisitz 550: // ]]>
1.653 raeburn 551: </script>
552: ENDAUTHORBRW
553: }
554:
1.91 www 555: sub coursebrowser_javascript {
1.1116 raeburn 556: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 557: $credits_element,$instcode) = @_;
1.932 raeburn 558: my $wintitle = 'Course_Browser';
1.931 raeburn 559: if ($crstype eq 'Community') {
1.932 raeburn 560: $wintitle = 'Community_Browser';
1.909 raeburn 561: }
1.876 raeburn 562: my $id_functions = &javascript_index_functions();
563: my $output = '
1.776 bisitz 564: <script type="text/javascript" language="JavaScript">
1.824 bisitz 565: // <![CDATA[
1.468 raeburn 566: var stdeditbrowser;'."\n";
1.876 raeburn 567:
568: $output .= <<"ENDSTDBRW";
1.909 raeburn 569: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 570: var url = '/adm/pickcourse?';
1.895 raeburn 571: var formid = getFormIdByName(formname);
1.876 raeburn 572: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 573: if (domainfilter != null) {
574: if (domainfilter != '') {
575: url += 'domainfilter='+domainfilter+'&';
576: }
577: }
1.91 www 578: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 579: '&cdomelement='+udom+
580: '&cnameelement='+desc;
1.468 raeburn 581: if (extra_element !=null && extra_element != '') {
1.594 raeburn 582: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 583: url += '&roleelement='+extra_element;
584: if (domainfilter == null || domainfilter == '') {
585: url += '&domainfilter='+extra_element;
586: }
1.234 raeburn 587: }
1.468 raeburn 588: else {
589: if (formname == 'portform') {
590: url += '&setroles='+extra_element;
1.800 raeburn 591: } else {
592: if (formname == 'rules') {
593: url += '&fixeddom='+extra_element;
594: }
1.468 raeburn 595: }
596: }
1.230 raeburn 597: }
1.909 raeburn 598: if (type != null && type != '') {
599: url += '&type='+type;
600: }
601: if (type_elem != null && type_elem != '') {
602: url += '&typeelement='+type_elem;
603: }
1.872 raeburn 604: if (formname == 'ccrs') {
605: var ownername = document.forms[formid].ccuname.value;
606: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 607: url += '&cloner='+ownername+':'+ownerdom;
608: if (type == 'Course') {
609: url += '&crscode='+document.forms[formid].crscode.value;
610: }
1.1221 raeburn 611: }
612: if (formname == 'requestcrs') {
613: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 614: }
1.293 raeburn 615: if (multflag !=null && multflag != '') {
616: url += '&multiple='+multflag;
617: }
1.909 raeburn 618: var title = '$wintitle';
1.91 www 619: var options = 'scrollbars=1,resizable=1,menubar=0';
620: options += ',width=700,height=600';
621: stdeditbrowser = open(url,title,options,'1');
622: stdeditbrowser.focus();
623: }
1.876 raeburn 624: $id_functions
625: ENDSTDBRW
1.1116 raeburn 626: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
627: $output .= &setsec_javascript($sec_element,$formname,$role_element,
628: $credits_element);
1.876 raeburn 629: }
630: $output .= '
631: // ]]>
632: </script>';
633: return $output;
634: }
635:
636: sub javascript_index_functions {
637: return <<"ENDJS";
638:
639: function getFormIdByName(formname) {
640: for (var i=0;i<document.forms.length;i++) {
641: if (document.forms[i].name == formname) {
642: return i;
643: }
644: }
645: return -1;
646: }
647:
648: function getIndexByName(formid,item) {
649: for (var i=0;i<document.forms[formid].elements.length;i++) {
650: if (document.forms[formid].elements[i].name == item) {
651: return i;
652: }
653: }
654: return -1;
655: }
1.468 raeburn 656:
1.876 raeburn 657: function getDomainFromSelectbox(formname,udom) {
658: var userdom;
659: var formid = getFormIdByName(formname);
660: if (formid > -1) {
661: var domid = getIndexByName(formid,udom);
662: if (domid > -1) {
663: if (document.forms[formid].elements[domid].type == 'select-one') {
664: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
665: }
666: if (document.forms[formid].elements[domid].type == 'hidden') {
667: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 668: }
669: }
670: }
1.876 raeburn 671: return userdom;
672: }
673:
674: ENDJS
1.468 raeburn 675:
1.876 raeburn 676: }
677:
1.1017 raeburn 678: sub javascript_array_indexof {
1.1018 raeburn 679: return <<ENDJS;
1.1017 raeburn 680: <script type="text/javascript" language="JavaScript">
681: // <![CDATA[
682:
683: if (!Array.prototype.indexOf) {
684: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
685: "use strict";
686: if (this === void 0 || this === null) {
687: throw new TypeError();
688: }
689: var t = Object(this);
690: var len = t.length >>> 0;
691: if (len === 0) {
692: return -1;
693: }
694: var n = 0;
695: if (arguments.length > 0) {
696: n = Number(arguments[1]);
1.1088 foxr 697: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 698: n = 0;
699: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
700: n = (n > 0 || -1) * Math.floor(Math.abs(n));
701: }
702: }
703: if (n >= len) {
704: return -1;
705: }
706: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
707: for (; k < len; k++) {
708: if (k in t && t[k] === searchElement) {
709: return k;
710: }
711: }
712: return -1;
713: }
714: }
715:
716: // ]]>
717: </script>
718:
719: ENDJS
720:
721: }
722:
1.876 raeburn 723: sub userbrowser_javascript {
724: my $id_functions = &javascript_index_functions();
725: return <<"ENDUSERBRW";
726:
1.888 raeburn 727: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 728: var url = '/adm/pickuser?';
729: var userdom = getDomainFromSelectbox(formname,udom);
730: if (userdom != null) {
731: if (userdom != '') {
732: url += 'srchdom='+userdom+'&';
733: }
734: }
735: url += 'form=' + formname + '&unameelement='+uname+
736: '&udomelement='+udom+
737: '&ulastelement='+ulast+
738: '&ufirstelement='+ufirst+
739: '&uemailelement='+uemail+
1.881 raeburn 740: '&hideudomelement='+hideudom+
741: '&coursedom='+crsdom;
1.888 raeburn 742: if ((caller != null) && (caller != undefined)) {
743: url += '&caller='+caller;
744: }
1.876 raeburn 745: var title = 'User_Browser';
746: var options = 'scrollbars=1,resizable=1,menubar=0';
747: options += ',width=700,height=600';
748: var stdeditbrowser = open(url,title,options,'1');
749: stdeditbrowser.focus();
750: }
751:
1.888 raeburn 752: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 753: var formid = getFormIdByName(formname);
754: if (formid > -1) {
1.888 raeburn 755: var unameid = getIndexByName(formid,uname);
1.876 raeburn 756: var domid = getIndexByName(formid,udom);
757: var hidedomid = getIndexByName(formid,origdom);
758: if (hidedomid > -1) {
759: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 760: var unameval = document.forms[formid].elements[unameid].value;
761: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
762: if (domid > -1) {
763: var slct = document.forms[formid].elements[domid];
764: if (slct.type == 'select-one') {
765: var i;
766: for (i=0;i<slct.length;i++) {
767: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
768: }
769: }
770: if (slct.type == 'hidden') {
771: slct.value = fixeddom;
1.876 raeburn 772: }
773: }
1.468 raeburn 774: }
775: }
776: }
1.876 raeburn 777: return;
778: }
779:
780: $id_functions
781: ENDUSERBRW
1.468 raeburn 782: }
783:
784: sub setsec_javascript {
1.1116 raeburn 785: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 786: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
787: $communityrolestr);
788: if ($role_element ne '') {
789: my @allroles = ('st','ta','ep','in','ad');
790: foreach my $crstype ('Course','Community') {
791: if ($crstype eq 'Community') {
792: foreach my $role (@allroles) {
793: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
794: }
795: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
796: } else {
797: foreach my $role (@allroles) {
798: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
799: }
800: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
801: }
802: }
803: $rolestr = '"'.join('","',@allroles).'"';
804: $courserolestr = '"'.join('","',@courserolenames).'"';
805: $communityrolestr = '"'.join('","',@communityrolenames).'"';
806: }
1.468 raeburn 807: my $setsections = qq|
808: function setSect(sectionlist) {
1.629 raeburn 809: var sectionsArray = new Array();
810: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
811: sectionsArray = sectionlist.split(",");
812: }
1.468 raeburn 813: var numSections = sectionsArray.length;
814: document.$formname.$sec_element.length = 0;
815: if (numSections == 0) {
816: document.$formname.$sec_element.multiple=false;
817: document.$formname.$sec_element.size=1;
818: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
819: } else {
820: if (numSections == 1) {
821: document.$formname.$sec_element.multiple=false;
822: document.$formname.$sec_element.size=1;
823: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
824: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
825: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
826: } else {
827: for (var i=0; i<numSections; i++) {
828: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
829: }
830: document.$formname.$sec_element.multiple=true
831: if (numSections < 3) {
832: document.$formname.$sec_element.size=numSections;
833: } else {
834: document.$formname.$sec_element.size=3;
835: }
836: document.$formname.$sec_element.options[0].selected = false
837: }
838: }
1.91 www 839: }
1.905 raeburn 840:
841: function setRole(crstype) {
1.468 raeburn 842: |;
1.905 raeburn 843: if ($role_element eq '') {
844: $setsections .= ' return;
845: }
846: ';
847: } else {
848: $setsections .= qq|
849: var elementLength = document.$formname.$role_element.length;
850: var allroles = Array($rolestr);
851: var courserolenames = Array($courserolestr);
852: var communityrolenames = Array($communityrolestr);
853: if (elementLength != undefined) {
854: if (document.$formname.$role_element.options[5].value == 'cc') {
855: if (crstype == 'Course') {
856: return;
857: } else {
858: allroles[5] = 'co';
859: for (var i=0; i<6; i++) {
860: document.$formname.$role_element.options[i].value = allroles[i];
861: document.$formname.$role_element.options[i].text = communityrolenames[i];
862: }
863: }
864: } else {
865: if (crstype == 'Community') {
866: return;
867: } else {
868: allroles[5] = 'cc';
869: for (var i=0; i<6; i++) {
870: document.$formname.$role_element.options[i].value = allroles[i];
871: document.$formname.$role_element.options[i].text = courserolenames[i];
872: }
873: }
874: }
875: }
876: return;
877: }
878: |;
879: }
1.1116 raeburn 880: if ($credits_element) {
881: $setsections .= qq|
882: function setCredits(defaultcredits) {
883: document.$formname.$credits_element.value = defaultcredits;
884: return;
885: }
886: |;
887: }
1.468 raeburn 888: return $setsections;
889: }
890:
1.91 www 891: sub selectcourse_link {
1.909 raeburn 892: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
893: $typeelement) = @_;
894: my $type = $selecttype;
1.871 raeburn 895: my $linktext = &mt('Select Course');
896: if ($selecttype eq 'Community') {
1.909 raeburn 897: $linktext = &mt('Select Community');
1.1239 raeburn 898: } elsif ($selecttype eq 'Placement') {
899: $linktext = &mt('Select Placement Test');
1.906 raeburn 900: } elsif ($selecttype eq 'Course/Community') {
901: $linktext = &mt('Select Course/Community');
1.909 raeburn 902: $type = '';
1.1019 raeburn 903: } elsif ($selecttype eq 'Select') {
904: $linktext = &mt('Select');
905: $type = '';
1.871 raeburn 906: }
1.787 bisitz 907: return '<span class="LC_nobreak">'
908: ."<a href='"
909: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
910: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 911: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 912: ."'>".$linktext.'</a>'
1.787 bisitz 913: .'</span>';
1.74 www 914: }
1.42 matthew 915:
1.653 raeburn 916: sub selectauthor_link {
917: my ($form,$udom)=@_;
918: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
919: &mt('Select Author').'</a>';
920: }
921:
1.876 raeburn 922: sub selectuser_link {
1.881 raeburn 923: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 924: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 925: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 926: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 927: ');">'.$linktext.'</a>';
1.876 raeburn 928: }
929:
1.273 raeburn 930: sub check_uncheck_jscript {
931: my $jscript = <<"ENDSCRT";
932: function checkAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
1.1093 raeburn 935: if (!field[i].disabled) {
936: field[i].checked = true;
937: }
1.273 raeburn 938: }
939: } else {
1.1093 raeburn 940: if (!field.disabled) {
941: field.checked = true;
942: }
1.273 raeburn 943: }
944: }
945:
946: function uncheckAll(field) {
947: if (field.length > 0) {
948: for (i = 0; i < field.length; i++) {
949: field[i].checked = false ;
1.543 albertel 950: }
951: } else {
1.273 raeburn 952: field.checked = false ;
953: }
954: }
955: ENDSCRT
956: return $jscript;
957: }
958:
1.656 www 959: sub select_timezone {
1.1256 raeburn 960: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
961: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 962: if ($includeempty) {
963: $output .= '<option value=""';
964: if (($selected eq '') || ($selected eq 'local')) {
965: $output .= ' selected="selected" ';
966: }
967: $output .= '> </option>';
968: }
1.657 raeburn 969: my @timezones = DateTime::TimeZone->all_names;
970: foreach my $tzone (@timezones) {
971: $output.= '<option value="'.$tzone.'"';
972: if ($tzone eq $selected) {
973: $output.=' selected="selected"';
974: }
975: $output.=">$tzone</option>\n";
1.656 www 976: }
977: $output.="</select>";
978: return $output;
979: }
1.273 raeburn 980:
1.687 raeburn 981: sub select_datelocale {
1.1256 raeburn 982: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
983: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 984: if ($includeempty) {
985: $output .= '<option value=""';
986: if ($selected eq '') {
987: $output .= ' selected="selected" ';
988: }
989: $output .= '> </option>';
990: }
1.1241 raeburn 991: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 992: my (@possibles,%locale_names);
1.1241 raeburn 993: my @locales = DateTime::Locale->ids();
994: foreach my $id (@locales) {
995: if ($id ne '') {
996: my ($en_terr,$native_terr);
997: my $loc = DateTime::Locale->load($id);
998: if (ref($loc)) {
999: $en_terr = $loc->name();
1000: $native_terr = $loc->native_name();
1.687 raeburn 1001: if (grep(/^en$/,@languages) || !@languages) {
1002: if ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: } elsif ($native_terr ne '') {
1005: $locale_names{$id} = $native_terr;
1006: }
1007: } else {
1008: if ($native_terr ne '') {
1009: $locale_names{$id} = $native_terr.' ';
1010: } elsif ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: }
1013: }
1.1220 raeburn 1014: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1015: push(@possibles,$id);
1016: }
1.687 raeburn 1017: }
1018: }
1019: foreach my $item (sort(@possibles)) {
1020: $output.= '<option value="'.$item.'"';
1021: if ($item eq $selected) {
1022: $output.=' selected="selected"';
1023: }
1024: $output.=">$item";
1025: if ($locale_names{$item} ne '') {
1.1220 raeburn 1026: $output.=' '.$locale_names{$item};
1.687 raeburn 1027: }
1028: $output.="</option>\n";
1029: }
1030: $output.="</select>";
1031: return $output;
1032: }
1033:
1.792 raeburn 1034: sub select_language {
1.1256 raeburn 1035: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1036: my %langchoices;
1037: if ($includeempty) {
1.1117 raeburn 1038: %langchoices = ('' => 'No language preference');
1.792 raeburn 1039: }
1040: foreach my $id (&languageids()) {
1041: my $code = &supportedlanguagecode($id);
1042: if ($code) {
1043: $langchoices{$code} = &plainlanguagedescription($id);
1044: }
1045: }
1.1117 raeburn 1046: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1047: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1048: }
1049:
1.42 matthew 1050: =pod
1.36 matthew 1051:
1.1088 foxr 1052:
1053: =item * &list_languages()
1054:
1055: Returns an array reference that is suitable for use in language prompters.
1056: Each array element is itself a two element array. The first element
1057: is the language code. The second element a descsriptiuon of the
1058: language itself. This is suitable for use in e.g.
1059: &Apache::edit::select_arg (once dereferenced that is).
1060:
1061: =cut
1062:
1063: sub list_languages {
1064: my @lang_choices;
1065:
1066: foreach my $id (&languageids()) {
1067: my $code = &supportedlanguagecode($id);
1068: if ($code) {
1069: my $selector = $supported_codes{$id};
1070: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1071: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1072: }
1073: }
1074: return \@lang_choices;
1075: }
1076:
1077: =pod
1078:
1.648 raeburn 1079: =item * &linked_select_forms(...)
1.36 matthew 1080:
1081: linked_select_forms returns a string containing a <script></script> block
1082: and html for two <select> menus. The select menus will be linked in that
1083: changing the value of the first menu will result in new values being placed
1084: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1085: order unless a defined order is provided.
1.36 matthew 1086:
1087: linked_select_forms takes the following ordered inputs:
1088:
1089: =over 4
1090:
1.112 bowersj2 1091: =item * $formname, the name of the <form> tag
1.36 matthew 1092:
1.112 bowersj2 1093: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1094:
1.112 bowersj2 1095: =item * $firstdefault, the default value for the first menu
1.36 matthew 1096:
1.112 bowersj2 1097: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1098:
1.112 bowersj2 1099: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1102:
1.609 raeburn 1103: =item * $menuorder, the order of values in the first menu
1104:
1.1115 raeburn 1105: =item * $onchangefirst, additional javascript call to execute for an onchange
1106: event for the first <select> tag
1107:
1108: =item * $onchangesecond, additional javascript call to execute for an onchange
1109: event for the second <select> tag
1110:
1.1245 raeburn 1111: =item * $suffix, to differentiate separate uses of select2data javascript
1112: objects in a page.
1113:
1.41 ng 1114: =back
1115:
1.36 matthew 1116: Below is an example of such a hash. Only the 'text', 'default', and
1117: 'select2' keys must appear as stated. keys(%menu) are the possible
1118: values for the first select menu. The text that coincides with the
1.41 ng 1119: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1120: and text for the second menu are given in the hash pointed to by
1121: $menu{$choice1}->{'select2'}.
1122:
1.112 bowersj2 1123: my %menu = ( A1 => { text =>"Choice A1" ,
1124: default => "B3",
1125: select2 => {
1126: B1 => "Choice B1",
1127: B2 => "Choice B2",
1128: B3 => "Choice B3",
1129: B4 => "Choice B4"
1.609 raeburn 1130: },
1131: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1132: },
1133: A2 => { text =>"Choice A2" ,
1134: default => "C2",
1135: select2 => {
1136: C1 => "Choice C1",
1137: C2 => "Choice C2",
1138: C3 => "Choice C3"
1.609 raeburn 1139: },
1140: order => ['C2','C1','C3'],
1.112 bowersj2 1141: },
1142: A3 => { text =>"Choice A3" ,
1143: default => "D6",
1144: select2 => {
1145: D1 => "Choice D1",
1146: D2 => "Choice D2",
1147: D3 => "Choice D3",
1148: D4 => "Choice D4",
1149: D5 => "Choice D5",
1150: D6 => "Choice D6",
1151: D7 => "Choice D7"
1.609 raeburn 1152: },
1153: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1154: }
1155: );
1.36 matthew 1156:
1157: =cut
1158:
1159: sub linked_select_forms {
1160: my ($formname,
1161: $middletext,
1162: $firstdefault,
1163: $firstselectname,
1164: $secondselectname,
1.609 raeburn 1165: $hashref,
1166: $menuorder,
1.1115 raeburn 1167: $onchangefirst,
1.1245 raeburn 1168: $onchangesecond,
1169: $suffix
1.36 matthew 1170: ) = @_;
1171: my $second = "document.$formname.$secondselectname";
1172: my $first = "document.$formname.$firstselectname";
1173: # output the javascript to do the changing
1174: my $result = '';
1.776 bisitz 1175: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1176: $result.="// <![CDATA[\n";
1.1245 raeburn 1177: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1178: $" = '","';
1179: my $debug = '';
1180: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1181: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1182: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1183: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1184: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1185: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1186: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1187: @s2values = @{$hashref->{$s1}->{'order'}};
1188: }
1.36 matthew 1189: $result.="\"@s2values\");\n";
1.1245 raeburn 1190: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1191: my @s2texts;
1192: foreach my $value (@s2values) {
1.1263 raeburn 1193: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1194: }
1195: $result.="\"@s2texts\");\n";
1196: }
1197: $"=' ';
1198: $result.= <<"END";
1199:
1.1245 raeburn 1200: function select1${suffix}_changed() {
1.36 matthew 1201: // Determine new choice
1.1245 raeburn 1202: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1203: // update select2
1.1245 raeburn 1204: var values = select2data${suffix}[newvalue].values;
1205: var texts = select2data${suffix}[newvalue].texts;
1206: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1207: var i;
1208: // out with the old
1.1245 raeburn 1209: $second.options.length = 0;
1210: // in with the new
1.36 matthew 1211: for (i=0;i<values.length; i++) {
1212: $second.options[i] = new Option(values[i]);
1.143 matthew 1213: $second.options[i].value = values[i];
1.36 matthew 1214: $second.options[i].text = texts[i];
1215: if (values[i] == select2def) {
1216: $second.options[i].selected = true;
1217: }
1218: }
1219: }
1.824 bisitz 1220: // ]]>
1.36 matthew 1221: </script>
1222: END
1223: # output the initial values for the selection lists
1.1245 raeburn 1224: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1225: my @order = sort(keys(%{$hashref}));
1226: if (ref($menuorder) eq 'ARRAY') {
1227: @order = @{$menuorder};
1228: }
1229: foreach my $value (@order) {
1.36 matthew 1230: $result.=" <option value=\"$value\" ";
1.253 albertel 1231: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1232: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1233: }
1234: $result .= "</select>\n";
1235: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1236: $result .= $middletext;
1.1115 raeburn 1237: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1238: if ($onchangesecond) {
1239: $result .= ' onchange="'.$onchangesecond.'"';
1240: }
1241: $result .= ">\n";
1.36 matthew 1242: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1243:
1244: my @secondorder = sort(keys(%select2));
1245: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1246: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1247: }
1248: foreach my $value (@secondorder) {
1.36 matthew 1249: $result.=" <option value=\"$value\" ";
1.253 albertel 1250: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1251: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1252: }
1253: $result .= "</select>\n";
1254: # return $debug;
1255: return $result;
1256: } # end of sub linked_select_forms {
1257:
1.45 matthew 1258: =pod
1.44 bowersj2 1259:
1.973 raeburn 1260: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1261:
1.112 bowersj2 1262: Returns a string corresponding to an HTML link to the given help
1263: $topic, where $topic corresponds to the name of a .tex file in
1264: /home/httpd/html/adm/help/tex, with underscores replaced by
1265: spaces.
1266:
1267: $text will optionally be linked to the same topic, allowing you to
1268: link text in addition to the graphic. If you do not want to link
1269: text, but wish to specify one of the later parameters, pass an
1270: empty string.
1271:
1272: $stayOnPage is a value that will be interpreted as a boolean. If true,
1273: the link will not open a new window. If false, the link will open
1274: a new window using Javascript. (Default is false.)
1275:
1276: $width and $height are optional numerical parameters that will
1277: override the width and height of the popped up window, which may
1.973 raeburn 1278: be useful for certain help topics with big pictures included.
1279:
1280: $imgid is the id of the img tag used for the help icon. This may be
1281: used in a javascript call to switch the image src. See
1282: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1283:
1284: =cut
1285:
1286: sub help_open_topic {
1.973 raeburn 1287: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1288: $text = "" if (not defined $text);
1.44 bowersj2 1289: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1290: $width = 500 if (not defined $width);
1.44 bowersj2 1291: $height = 400 if (not defined $height);
1292: my $filename = $topic;
1293: $filename =~ s/ /_/g;
1294:
1.48 bowersj2 1295: my $template = "";
1296: my $link;
1.572 banghart 1297:
1.159 www 1298: $topic=~s/\W/\_/g;
1.44 bowersj2 1299:
1.572 banghart 1300: if (!$stayOnPage) {
1.1033 www 1301: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1302: } elsif ($stayOnPage eq 'popup') {
1303: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1304: } else {
1.48 bowersj2 1305: $link = "/adm/help/${filename}.hlp";
1306: }
1307:
1308: # Add the text
1.1314 raeburn 1309: my $target = ' target="_top"';
1310: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1311: $target = '';
1312: }
1.755 neumanie 1313: if ($text ne "") {
1.763 bisitz 1314: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1315: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1316: .$text.'</a>';
1.48 bowersj2 1317: }
1318:
1.763 bisitz 1319: # (Always) Add the graphic
1.179 matthew 1320: my $title = &mt('Online Help');
1.667 raeburn 1321: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1322: if ($imgid ne '') {
1323: $imgid = ' id="'.$imgid.'"';
1324: }
1.1314 raeburn 1325: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1326: .'<img src="'.$helpicon.'" border="0"'
1327: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1328: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1329: .' /></a>';
1330: if ($text ne "") {
1331: $template.='</span>';
1332: }
1.44 bowersj2 1333: return $template;
1334:
1.106 bowersj2 1335: }
1336:
1337: # This is a quicky function for Latex cheatsheet editing, since it
1338: # appears in at least four places
1339: sub helpLatexCheatsheet {
1.1037 www 1340: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1341: my $out;
1.106 bowersj2 1342: my $addOther = '';
1.732 raeburn 1343: if ($topic) {
1.1037 www 1344: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1345: }
1346: $out = '<span>' # Start cheatsheet
1347: .$addOther
1348: .'<span>'
1.1037 www 1349: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1350: .'</span> <span>'
1.1037 www 1351: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1352: .'</span>';
1.732 raeburn 1353: unless ($not_author) {
1.1186 kruse 1354: $out .= '<span>'
1355: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1356: .'</span> <span>'
1357: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1358: .'</span>';
1.732 raeburn 1359: }
1.763 bisitz 1360: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1361: return $out;
1.172 www 1362: }
1363:
1.430 albertel 1364: sub general_help {
1365: my $helptopic='Student_Intro';
1366: if ($env{'request.role'}=~/^(ca|au)/) {
1367: $helptopic='Authoring_Intro';
1.907 raeburn 1368: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1369: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1370: } elsif ($env{'request.role'}=~/^dc/) {
1371: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1372: }
1373: return $helptopic;
1374: }
1375:
1376: sub update_help_link {
1377: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1378: my $origurl = $ENV{'REQUEST_URI'};
1379: $origurl=~s|^/~|/priv/|;
1380: my $timestamp = time;
1381: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1382: $$datum = &escape($$datum);
1383: }
1384:
1385: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1386: my $output .= <<"ENDOUTPUT";
1387: <script type="text/javascript">
1.824 bisitz 1388: // <![CDATA[
1.430 albertel 1389: banner_link = '$banner_link';
1.824 bisitz 1390: // ]]>
1.430 albertel 1391: </script>
1392: ENDOUTPUT
1393: return $output;
1394: }
1395:
1396: # now just updates the help link and generates a blue icon
1.193 raeburn 1397: sub help_open_menu {
1.430 albertel 1398: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1399: = @_;
1.949 droeschl 1400: $stayOnPage = 1;
1.430 albertel 1401: my $output;
1402: if ($component_help) {
1403: if (!$text) {
1404: $output=&help_open_topic($component_help,undef,$stayOnPage,
1405: $width,$height);
1406: } else {
1407: my $help_text;
1408: $help_text=&unescape($topic);
1409: $output='<table><tr><td>'.
1410: &help_open_topic($component_help,$help_text,$stayOnPage,
1411: $width,$height).'</td></tr></table>';
1412: }
1413: }
1414: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1415: return $output.$banner_link;
1416: }
1417:
1418: sub top_nav_help {
1419: my ($text) = @_;
1.436 albertel 1420: $text = &mt($text);
1.949 droeschl 1421: my $stay_on_page = 1;
1422:
1.1168 raeburn 1423: my ($link,$banner_link);
1424: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1425: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1426: : "javascript:helpMenu('open')";
1427: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1428: }
1.201 raeburn 1429: my $title = &mt('Get help');
1.1168 raeburn 1430: if ($link) {
1431: return <<"END";
1.436 albertel 1432: $banner_link
1.1159 raeburn 1433: <a href="$link" title="$title">$text</a>
1.436 albertel 1434: END
1.1168 raeburn 1435: } else {
1436: return ' '.$text.' ';
1437: }
1.436 albertel 1438: }
1439:
1440: sub help_menu_js {
1.1154 raeburn 1441: my ($httphost) = @_;
1.949 droeschl 1442: my $stayOnPage = 1;
1.436 albertel 1443: my $width = 620;
1444: my $height = 600;
1.430 albertel 1445: my $helptopic=&general_help();
1.1154 raeburn 1446: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1447: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1448: my $start_page =
1449: &Apache::loncommon::start_page('Help Menu', undef,
1450: {'frameset' => 1,
1451: 'js_ready' => 1,
1.1154 raeburn 1452: 'use_absolute' => $httphost,
1.331 albertel 1453: 'add_entries' => {
1.1168 raeburn 1454: 'border' => '0',
1.579 raeburn 1455: 'rows' => "110,*",},});
1.331 albertel 1456: my $end_page =
1457: &Apache::loncommon::end_page({'frameset' => 1,
1458: 'js_ready' => 1,});
1459:
1.436 albertel 1460: my $template .= <<"ENDTEMPLATE";
1461: <script type="text/javascript">
1.877 bisitz 1462: // <![CDATA[
1.253 albertel 1463: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1464: var banner_link = '';
1.243 raeburn 1465: function helpMenu(target) {
1466: var caller = this;
1467: if (target == 'open') {
1468: var newWindow = null;
1469: try {
1.262 albertel 1470: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1471: }
1472: catch(error) {
1473: writeHelp(caller);
1474: return;
1475: }
1476: if (newWindow) {
1477: caller = newWindow;
1478: }
1.193 raeburn 1479: }
1.243 raeburn 1480: writeHelp(caller);
1481: return;
1482: }
1483: function writeHelp(caller) {
1.1168 raeburn 1484: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1485: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1486: caller.document.close();
1487: caller.focus();
1.193 raeburn 1488: }
1.877 bisitz 1489: // END LON-CAPA Internal -->
1.253 albertel 1490: // ]]>
1.436 albertel 1491: </script>
1.193 raeburn 1492: ENDTEMPLATE
1493: return $template;
1494: }
1495:
1.172 www 1496: sub help_open_bug {
1497: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1498: unless ($env{'user.adv'}) { return ''; }
1.172 www 1499: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1500: $text = "" if (not defined $text);
1501: $stayOnPage=1;
1.184 albertel 1502: $width = 600 if (not defined $width);
1503: $height = 600 if (not defined $height);
1.172 www 1504:
1505: $topic=~s/\W+/\+/g;
1506: my $link='';
1507: my $template='';
1.379 albertel 1508: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1509: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1510: if (!$stayOnPage)
1511: {
1512: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1513: }
1514: else
1515: {
1516: $link = $url;
1517: }
1.1314 raeburn 1518:
1519: my $target = ' target="_top"';
1520: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1521: $target = '';
1522: }
1.172 www 1523: # Add the text
1524: if ($text ne "")
1525: {
1526: $template .=
1527: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1528: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1529: }
1530:
1531: # Add the graphic
1.179 matthew 1532: my $title = &mt('Report a Bug');
1.215 albertel 1533: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1534: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1535: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1536: ENDTEMPLATE
1537: if ($text ne '') { $template.='</td></tr></table>' };
1538: return $template;
1539:
1540: }
1541:
1542: sub help_open_faq {
1543: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1544: unless ($env{'user.adv'}) { return ''; }
1.172 www 1545: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1546: $text = "" if (not defined $text);
1547: $stayOnPage=1;
1548: $width = 350 if (not defined $width);
1549: $height = 400 if (not defined $height);
1550:
1551: $topic=~s/\W+/\+/g;
1552: my $link='';
1553: my $template='';
1554: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1555: if (!$stayOnPage)
1556: {
1557: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1558: }
1559: else
1560: {
1561: $link = $url;
1562: }
1563:
1564: # Add the text
1565: if ($text ne "")
1566: {
1567: $template .=
1.173 www 1568: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1569: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1570: }
1571:
1572: # Add the graphic
1.179 matthew 1573: my $title = &mt('View the FAQ');
1.215 albertel 1574: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1575: $template .= <<"ENDTEMPLATE";
1.436 albertel 1576: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1577: ENDTEMPLATE
1578: if ($text ne '') { $template.='</td></tr></table>' };
1579: return $template;
1580:
1.44 bowersj2 1581: }
1.37 matthew 1582:
1.180 matthew 1583: ###############################################################
1584: ###############################################################
1585:
1.45 matthew 1586: =pod
1587:
1.648 raeburn 1588: =item * &change_content_javascript():
1.256 matthew 1589:
1590: This and the next function allow you to create small sections of an
1591: otherwise static HTML page that you can update on the fly with
1592: Javascript, even in Netscape 4.
1593:
1594: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1595: must be written to the HTML page once. It will prove the Javascript
1596: function "change(name, content)". Calling the change function with the
1597: name of the section
1598: you want to update, matching the name passed to C<changable_area>, and
1599: the new content you want to put in there, will put the content into
1600: that area.
1601:
1602: B<Note>: Netscape 4 only reserves enough space for the changable area
1603: to contain room for the original contents. You need to "make space"
1604: for whatever changes you wish to make, and be B<sure> to check your
1605: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1606: it's adequate for updating a one-line status display, but little more.
1607: This script will set the space to 100% width, so you only need to
1608: worry about height in Netscape 4.
1609:
1610: Modern browsers are much less limiting, and if you can commit to the
1611: user not using Netscape 4, this feature may be used freely with
1612: pretty much any HTML.
1613:
1614: =cut
1615:
1616: sub change_content_javascript {
1617: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1618: if ($env{'browser.type'} eq 'netscape' &&
1619: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1620: return (<<NETSCAPE4);
1621: function change(name, content) {
1622: doc = document.layers[name+"___escape"].layers[0].document;
1623: doc.open();
1624: doc.write(content);
1625: doc.close();
1626: }
1627: NETSCAPE4
1628: } else {
1629: # Otherwise, we need to use semi-standards-compliant code
1630: # (technically, "innerHTML" isn't standard but the equivalent
1631: # is really scary, and every useful browser supports it
1632: return (<<DOMBASED);
1633: function change(name, content) {
1634: element = document.getElementById(name);
1635: element.innerHTML = content;
1636: }
1637: DOMBASED
1638: }
1639: }
1640:
1641: =pod
1642:
1.648 raeburn 1643: =item * &changable_area($name,$origContent):
1.256 matthew 1644:
1645: This provides a "changable area" that can be modified on the fly via
1646: the Javascript code provided in C<change_content_javascript>. $name is
1647: the name you will use to reference the area later; do not repeat the
1648: same name on a given HTML page more then once. $origContent is what
1649: the area will originally contain, which can be left blank.
1650:
1651: =cut
1652:
1653: sub changable_area {
1654: my ($name, $origContent) = @_;
1655:
1.258 albertel 1656: if ($env{'browser.type'} eq 'netscape' &&
1657: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1658: # If this is netscape 4, we need to use the Layer tag
1659: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1660: } else {
1661: return "<span id='$name'>$origContent</span>";
1662: }
1663: }
1664:
1665: =pod
1666:
1.648 raeburn 1667: =item * &viewport_geometry_js
1.590 raeburn 1668:
1669: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1670:
1671: =cut
1672:
1673:
1674: sub viewport_geometry_js {
1675: return <<"GEOMETRY";
1676: var Geometry = {};
1677: function init_geometry() {
1678: if (Geometry.init) { return };
1679: Geometry.init=1;
1680: if (window.innerHeight) {
1681: Geometry.getViewportHeight = function() { return window.innerHeight; };
1682: Geometry.getViewportWidth = function() { return window.innerWidth; };
1683: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1684: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1685: }
1686: else if (document.documentElement && document.documentElement.clientHeight) {
1687: Geometry.getViewportHeight =
1688: function() { return document.documentElement.clientHeight; };
1689: Geometry.getViewportWidth =
1690: function() { return document.documentElement.clientWidth; };
1691:
1692: Geometry.getHorizontalScroll =
1693: function() { return document.documentElement.scrollLeft; };
1694: Geometry.getVerticalScroll =
1695: function() { return document.documentElement.scrollTop; };
1696: }
1697: else if (document.body.clientHeight) {
1698: Geometry.getViewportHeight =
1699: function() { return document.body.clientHeight; };
1700: Geometry.getViewportWidth =
1701: function() { return document.body.clientWidth; };
1702: Geometry.getHorizontalScroll =
1703: function() { return document.body.scrollLeft; };
1704: Geometry.getVerticalScroll =
1705: function() { return document.body.scrollTop; };
1706: }
1707: }
1708:
1709: GEOMETRY
1710: }
1711:
1712: =pod
1713:
1.648 raeburn 1714: =item * &viewport_size_js()
1.590 raeburn 1715:
1716: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1717:
1718: =cut
1719:
1720: sub viewport_size_js {
1721: my $geometry = &viewport_geometry_js();
1722: return <<"DIMS";
1723:
1724: $geometry
1725:
1726: function getViewportDims(width,height) {
1727: init_geometry();
1728: width.value = Geometry.getViewportWidth();
1729: height.value = Geometry.getViewportHeight();
1730: return;
1731: }
1732:
1733: DIMS
1734: }
1735:
1736: =pod
1737:
1.648 raeburn 1738: =item * &resize_textarea_js()
1.565 albertel 1739:
1740: emits the needed javascript to resize a textarea to be as big as possible
1741:
1742: creates a function resize_textrea that takes two IDs first should be
1743: the id of the element to resize, second should be the id of a div that
1744: surrounds everything that comes after the textarea, this routine needs
1745: to be attached to the <body> for the onload and onresize events.
1746:
1.648 raeburn 1747: =back
1.565 albertel 1748:
1749: =cut
1750:
1751: sub resize_textarea_js {
1.590 raeburn 1752: my $geometry = &viewport_geometry_js();
1.565 albertel 1753: return <<"RESIZE";
1754: <script type="text/javascript">
1.824 bisitz 1755: // <![CDATA[
1.590 raeburn 1756: $geometry
1.565 albertel 1757:
1.588 albertel 1758: function getX(element) {
1759: var x = 0;
1760: while (element) {
1761: x += element.offsetLeft;
1762: element = element.offsetParent;
1763: }
1764: return x;
1765: }
1766: function getY(element) {
1767: var y = 0;
1768: while (element) {
1769: y += element.offsetTop;
1770: element = element.offsetParent;
1771: }
1772: return y;
1773: }
1774:
1775:
1.565 albertel 1776: function resize_textarea(textarea_id,bottom_id) {
1777: init_geometry();
1778: var textarea = document.getElementById(textarea_id);
1779: //alert(textarea);
1780:
1.588 albertel 1781: var textarea_top = getY(textarea);
1.565 albertel 1782: var textarea_height = textarea.offsetHeight;
1783: var bottom = document.getElementById(bottom_id);
1.588 albertel 1784: var bottom_top = getY(bottom);
1.565 albertel 1785: var bottom_height = bottom.offsetHeight;
1786: var window_height = Geometry.getViewportHeight();
1.588 albertel 1787: var fudge = 23;
1.565 albertel 1788: var new_height = window_height-fudge-textarea_top-bottom_height;
1789: if (new_height < 300) {
1790: new_height = 300;
1791: }
1792: textarea.style.height=new_height+'px';
1793: }
1.824 bisitz 1794: // ]]>
1.565 albertel 1795: </script>
1796: RESIZE
1797:
1798: }
1799:
1.1205 golterma 1800: sub colorfuleditor_js {
1.1248 raeburn 1801: my $browse_or_search;
1802: my $respath;
1803: my ($cnum,$cdom) = &crsauthor_url();
1804: if ($cnum) {
1805: $respath = "/res/$cdom/$cnum/";
1806: my %js_lt = &Apache::lonlocal::texthash(
1807: sunm => 'Sub-directory name',
1808: save => 'Save page to make this permanent',
1809: );
1810: &js_escape(\%js_lt);
1811: $browse_or_search = <<"END";
1812:
1813: function toggleChooser(form,element,titleid,only,search) {
1814: var disp = 'none';
1815: if (document.getElementById('chooser_'+element)) {
1816: var curr = document.getElementById('chooser_'+element).style.display;
1817: if (curr == 'none') {
1818: disp='inline';
1819: if (form.elements['chooser_'+element].length) {
1820: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1821: form.elements['chooser_'+element][i].checked = false;
1822: }
1823: }
1824: toggleResImport(form,element);
1825: }
1826: document.getElementById('chooser_'+element).style.display = disp;
1827: }
1828: }
1829:
1830: function toggleCrsFile(form,element,numdirs) {
1831: if (document.getElementById('chooser_'+element+'_crsres')) {
1832: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1833: if (curr == 'none') {
1834: if (numdirs) {
1835: form.elements['coursepath_'+element].selectedIndex = 0;
1836: if (numdirs > 1) {
1837: window['select1'+element+'_changed']();
1838: }
1839: }
1840: }
1841: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1842:
1843: }
1844: if (document.getElementById('chooser_'+element+'_upload')) {
1845: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1846: if (document.getElementById('uploadcrsres_'+element)) {
1847: document.getElementById('uploadcrsres_'+element).value = '';
1848: }
1849: }
1850: return;
1851: }
1852:
1853: function toggleCrsUpload(form,element,numcrsdirs) {
1854: if (document.getElementById('chooser_'+element+'_crsres')) {
1855: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1856: }
1857: if (document.getElementById('chooser_'+element+'_upload')) {
1858: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1859: if (curr == 'none') {
1860: if (numcrsdirs) {
1861: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1862: form.elements['newsubdir_'+element][0].checked = true;
1863: toggleNewsubdir(form,element);
1864: }
1865: }
1866: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1867: }
1868: return;
1869: }
1870:
1871: function toggleResImport(form,element) {
1872: var choices = new Array('crsres','upload');
1873: for (var i=0; i<choices.length; i++) {
1874: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1875: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1876: }
1877: }
1878: }
1879:
1880: function toggleNewsubdir(form,element) {
1881: var newsub = form.elements['newsubdir_'+element];
1882: if (newsub) {
1883: if (newsub.length) {
1884: for (var j=0; j<newsub.length; j++) {
1885: if (newsub[j].checked) {
1886: if (document.getElementById('newsubdirname_'+element)) {
1887: if (newsub[j].value == '1') {
1888: document.getElementById('newsubdirname_'+element).type = "text";
1889: if (document.getElementById('newsubdir_'+element)) {
1890: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1891: }
1892: } else {
1893: document.getElementById('newsubdirname_'+element).type = "hidden";
1894: document.getElementById('newsubdirname_'+element).value = "";
1895: document.getElementById('newsubdir_'+element).innerHTML = "";
1896: }
1897: }
1898: break;
1899: }
1900: }
1901: }
1902: }
1903: }
1904:
1905: function updateCrsFile(form,element) {
1906: var directory = form.elements['coursepath_'+element];
1907: var filename = form.elements['coursefile_'+element];
1908: var path = directory.options[directory.selectedIndex].value;
1909: var file = filename.options[filename.selectedIndex].value;
1910: form.elements[element].value = '$respath';
1911: if (path == '/') {
1912: form.elements[element].value += file;
1913: } else {
1914: form.elements[element].value += path+'/'+file;
1915: }
1916: unClean();
1917: if (document.getElementById('previewimg_'+element)) {
1918: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1919: var newsrc = document.getElementById('previewimg_'+element).src;
1920: }
1921: if (document.getElementById('showimg_'+element)) {
1922: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1923: }
1924: toggleChooser(form,element);
1925: return;
1926: }
1927:
1928: function uploadDone(suffix,name) {
1929: if (name) {
1930: document.forms["lonhomework"].elements[suffix].value = name;
1931: unClean();
1932: toggleChooser(document.forms["lonhomework"],suffix);
1933: }
1934: }
1935:
1936: \$(document).ready(function(){
1937:
1938: \$(document).delegate('form :submit', 'click', function( event ) {
1939: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1940: var buttonId = this.id;
1941: var suffix = buttonId.toString();
1942: suffix = suffix.replace(/^crsupload_/,'');
1943: event.preventDefault();
1944: document.lonhomework.target = 'crsupload_target_'+suffix;
1945: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1946: \$(this.form).submit();
1947: document.lonhomework.target = '';
1948: if (document.getElementById('crsuploadto_'+suffix)) {
1949: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1950: }
1951: return false;
1952: }
1953: });
1954: });
1955: END
1956: }
1.1205 golterma 1957: return <<"COLORFULEDIT"
1958: <script type="text/javascript">
1959: // <![CDATA[>
1960: function fold_box(curDepth, lastresource){
1961:
1962: // we need a list because there can be several blocks you need to fold in one tag
1963: var block = document.getElementsByName('foldblock_'+curDepth);
1964: // but there is only one folding button per tag
1965: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1966:
1967: if(block.item(0).style.display == 'none'){
1968:
1969: foldbutton.value = '@{[&mt("Hide")]}';
1970: for (i = 0; i < block.length; i++){
1971: block.item(i).style.display = '';
1972: }
1973: }else{
1974:
1975: foldbutton.value = '@{[&mt("Show")]}';
1976: for (i = 0; i < block.length; i++){
1977: // block.item(i).style.visibility = 'collapse';
1978: block.item(i).style.display = 'none';
1979: }
1980: };
1981: saveState(lastresource);
1982: }
1983:
1984: function saveState (lastresource) {
1985:
1986: var tag_list = getTagList();
1987: if(tag_list != null){
1988: var timestamp = new Date().getTime();
1989: var key = lastresource;
1990:
1991: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1992: // starting with timestamp
1993: var value = timestamp+';';
1994:
1995: // building the list of key-value pairs
1996: for(var i = 0; i < tag_list.length; i++){
1997: value += tag_list[i]+',';
1998: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1999: }
2000:
2001: // only iterate whole storage if nothing to override
2002: if(localStorage.getItem(key) == null){
2003:
2004: // prevent storage from growing large
2005: if(localStorage.length > 50){
2006: var regex_getTimestamp = /^(?:\d)+;/;
2007: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2008: var oldest_key;
2009:
2010: for(var i = 1; i < localStorage.length; i++){
2011: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2012: oldest_key = localStorage.key(i);
2013: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2014: }
2015: }
2016: localStorage.removeItem(oldest_key);
2017: }
2018: }
2019: localStorage.setItem(key,value);
2020: }
2021: }
2022:
2023: // restore folding status of blocks (on page load)
2024: function restoreState (lastresource) {
2025: if(localStorage.getItem(lastresource) != null){
2026: var key = lastresource;
2027: var value = localStorage.getItem(key);
2028: var regex_delTimestamp = /^\d+;/;
2029:
2030: value.replace(regex_delTimestamp, '');
2031:
2032: var valueArr = value.split(';');
2033: var pairs;
2034: var elements;
2035: for (var i = 0; i < valueArr.length; i++){
2036: pairs = valueArr[i].split(',');
2037: elements = document.getElementsByName(pairs[0]);
2038:
2039: for (var j = 0; j < elements.length; j++){
2040: elements[j].style.display = pairs[1];
2041: if (pairs[1] == "none"){
2042: var regex_id = /([_\\d]+)\$/;
2043: regex_id.exec(pairs[0]);
2044: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2045: }
2046: }
2047: }
2048: }
2049: }
2050:
2051: function getTagList () {
2052:
2053: var stringToSearch = document.lonhomework.innerHTML;
2054:
2055: var ret = new Array();
2056: var regex_findBlock = /(foldblock_.*?)"/g;
2057: var tag_list = stringToSearch.match(regex_findBlock);
2058:
2059: if(tag_list != null){
2060: for(var i = 0; i < tag_list.length; i++){
2061: ret.push(tag_list[i].replace(/"/, ''));
2062: }
2063: }
2064: return ret;
2065: }
2066:
2067: function saveScrollPosition (resource) {
2068: var tag_list = getTagList();
2069:
2070: // we dont always want to jump to the first block
2071: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2072: if(\$(window).scrollTop() > 170){
2073: if(tag_list != null){
2074: var result;
2075: for(var i = 0; i < tag_list.length; i++){
2076: if(isElementInViewport(tag_list[i])){
2077: result += tag_list[i]+';';
2078: }
2079: }
2080: sessionStorage.setItem('anchor_'+resource, result);
2081: }
2082: } else {
2083: // we dont need to save zero, just delete the item to leave everything tidy
2084: sessionStorage.removeItem('anchor_'+resource);
2085: }
2086: }
2087:
2088: function restoreScrollPosition(resource){
2089:
2090: var elem = sessionStorage.getItem('anchor_'+resource);
2091: if(elem != null){
2092: var tag_list = elem.split(';');
2093: var elem_list;
2094:
2095: for(var i = 0; i < tag_list.length; i++){
2096: elem_list = document.getElementsByName(tag_list[i]);
2097:
2098: if(elem_list.length > 0){
2099: elem = elem_list[0];
2100: break;
2101: }
2102: }
2103: elem.scrollIntoView();
2104: }
2105: }
2106:
2107: function isElementInViewport(el) {
2108:
2109: // change to last element instead of first
2110: var elem = document.getElementsByName(el);
2111: var rect = elem[0].getBoundingClientRect();
2112:
2113: return (
2114: rect.top >= 0 &&
2115: rect.left >= 0 &&
2116: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2117: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2118: );
2119: }
2120:
2121: function autosize(depth){
2122: var cmInst = window['cm'+depth];
2123: var fitsizeButton = document.getElementById('fitsize'+depth);
2124:
2125: // is fixed size, switching to dynamic
2126: if (sessionStorage.getItem("autosized_"+depth) == null) {
2127: cmInst.setSize("","auto");
2128: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2129: sessionStorage.setItem("autosized_"+depth, "yes");
2130:
2131: // is dynamic size, switching to fixed
2132: } else {
2133: cmInst.setSize("","300px");
2134: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2135: sessionStorage.removeItem("autosized_"+depth);
2136: }
2137: }
2138:
1.1248 raeburn 2139: $browse_or_search
1.1205 golterma 2140:
2141: // ]]>
2142: </script>
2143: COLORFULEDIT
2144: }
2145:
2146: sub xmleditor_js {
2147: return <<XMLEDIT
2148: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2149: <script type="text/javascript">
2150: // <![CDATA[>
2151:
2152: function saveScrollPosition (resource) {
2153:
2154: var scrollPos = \$(window).scrollTop();
2155: sessionStorage.setItem(resource,scrollPos);
2156: }
2157:
2158: function restoreScrollPosition(resource){
2159:
2160: var scrollPos = sessionStorage.getItem(resource);
2161: \$(window).scrollTop(scrollPos);
2162: }
2163:
2164: // unless internet explorer
2165: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2166:
2167: \$(document).ready(function() {
2168: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2169: });
2170: }
2171:
2172: // inserts text at cursor position into codemirror (xml editor only)
2173: function insertText(text){
2174: cm.focus();
2175: var curPos = cm.getCursor();
2176: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2177: }
2178: // ]]>
2179: </script>
2180: XMLEDIT
2181: }
2182:
2183: sub insert_folding_button {
2184: my $curDepth = $Apache::lonxml::curdepth;
2185: my $lastresource = $env{'request.ambiguous'};
2186:
2187: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2188: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2189: }
2190:
1.1248 raeburn 2191: sub crsauthor_url {
2192: my ($url) = @_;
2193: if ($url eq '') {
2194: $url = $ENV{'REQUEST_URI'};
2195: }
2196: my ($cnum,$cdom);
2197: if ($env{'request.course.id'}) {
2198: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2199: if ($audom ne '' && $auname ne '') {
2200: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2201: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2202: $cnum = $auname;
2203: $cdom = $audom;
2204: }
2205: }
2206: }
2207: return ($cnum,$cdom);
2208: }
2209:
2210: sub import_crsauthor_form {
1.1265 raeburn 2211: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2212: return (0) unless ($env{'request.course.id'});
2213: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2214: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2215: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2216: return (0) unless (($cnum ne '') && ($cdom ne ''));
2217: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2218: my @ids=&Apache::lonnet::current_machine_ids();
2219: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2220:
2221: if (grep(/^\Q$crshome\E$/,@ids)) {
2222: $is_home = 1;
2223: }
2224: $relpath = "/priv/$cdom/$cnum";
2225: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2226: my %lt = &Apache::lonlocal::texthash (
2227: fnam => 'Filename',
2228: dire => 'Directory',
2229: );
2230: my $numdirs = scalar(keys(%files));
2231: my (%possexts,$singledir,@singledirfiles);
2232: if ($only) {
2233: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2234: }
2235: my (%nonemptydirs,$possdirs);
2236: if ($numdirs > 1) {
2237: my @order;
2238: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2239: if (ref($files{$key}) eq 'HASH') {
2240: my $shown = $key;
2241: if ($key eq '') {
2242: $shown = '/';
2243: }
2244: my @ordered = ();
2245: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2246: next if ($file =~ /\.rights$/);
1.1248 raeburn 2247: if ($only) {
2248: my ($ext) = ($file =~ /\.([^.]+)$/);
2249: unless ($possexts{lc($ext)}) {
2250: next;
2251: }
2252: }
2253: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2254: push(@ordered,$file);
2255: }
2256: if (@ordered) {
2257: push(@order,$key);
2258: $nonemptydirs{$key} = 1;
2259: $selimport_menus{$key}->{'text'} = $shown;
2260: $selimport_menus{$key}->{'default'} = '';
2261: $selimport_menus{$key}->{'select2'}->{''} = '';
2262: $selimport_menus{$key}->{'order'} = \@ordered;
2263: }
2264: }
2265: }
2266: $possdirs = scalar(keys(%nonemptydirs));
2267: if ($possdirs > 1) {
2268: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2269: $output = $lt{'dire'}.
2270: &linked_select_forms($form,'<br />'.
2271: $lt{'fnam'},'',
2272: $firstselectname,$secondselectname,
2273: \%selimport_menus,\@order,
2274: $onchangefirst,'',$suffix).'<br />';
2275: } elsif ($possdirs == 1) {
2276: $singledir = (keys(%nonemptydirs))[0];
2277: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2278: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2279: }
2280: delete($selimport_menus{$singledir});
2281: }
2282: } elsif ($numdirs == 1) {
2283: $singledir = (keys(%files))[0];
2284: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2285: if ($only) {
2286: my ($ext) = ($file =~ /\.([^.]+)$/);
2287: unless ($possexts{lc($ext)}) {
2288: next;
2289: }
1.1315 raeburn 2290: } else {
2291: next if ($file =~ /\.rights$/);
1.1248 raeburn 2292: }
2293: push(@singledirfiles,$file);
2294: }
2295: if (@singledirfiles) {
1.1315 raeburn 2296: $possdirs = 1;
1.1248 raeburn 2297: }
2298: }
2299: if (($possdirs == 1) && (@singledirfiles)) {
2300: my $showdir = $singledir;
2301: if ($singledir eq '') {
2302: $showdir = '/';
2303: }
2304: $output = $lt{'dire'}.
2305: '<select name="'.$firstselectname.'">'.
2306: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2307: '</select><br />'.
2308: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2309: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2310: foreach my $file (@singledirfiles) {
2311: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2312: }
2313: $output .= '</select><br />'."\n";
2314: }
2315: return ($possdirs,$output);
2316: }
2317:
1.565 albertel 2318: =pod
2319:
1.256 matthew 2320: =head1 Excel and CSV file utility routines
2321:
2322: =cut
2323:
2324: ###############################################################
2325: ###############################################################
2326:
2327: =pod
2328:
1.1162 raeburn 2329: =over 4
2330:
1.648 raeburn 2331: =item * &csv_translate($text)
1.37 matthew 2332:
1.185 www 2333: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2334: format.
2335:
2336: =cut
2337:
1.180 matthew 2338: ###############################################################
2339: ###############################################################
1.37 matthew 2340: sub csv_translate {
2341: my $text = shift;
2342: $text =~ s/\"/\"\"/g;
1.209 albertel 2343: $text =~ s/\n/ /g;
1.37 matthew 2344: return $text;
2345: }
1.180 matthew 2346:
2347: ###############################################################
2348: ###############################################################
2349:
2350: =pod
2351:
1.648 raeburn 2352: =item * &define_excel_formats()
1.180 matthew 2353:
2354: Define some commonly used Excel cell formats.
2355:
2356: Currently supported formats:
2357:
2358: =over 4
2359:
2360: =item header
2361:
2362: =item bold
2363:
2364: =item h1
2365:
2366: =item h2
2367:
2368: =item h3
2369:
1.256 matthew 2370: =item h4
2371:
2372: =item i
2373:
1.180 matthew 2374: =item date
2375:
2376: =back
2377:
2378: Inputs: $workbook
2379:
2380: Returns: $format, a hash reference.
2381:
1.1057 foxr 2382:
1.180 matthew 2383: =cut
2384:
2385: ###############################################################
2386: ###############################################################
2387: sub define_excel_formats {
2388: my ($workbook) = @_;
2389: my $format;
2390: $format->{'header'} = $workbook->add_format(bold => 1,
2391: bottom => 1,
2392: align => 'center');
2393: $format->{'bold'} = $workbook->add_format(bold=>1);
2394: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2395: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2396: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2397: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2398: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2399: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2400: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2401: return $format;
2402: }
2403:
2404: ###############################################################
2405: ###############################################################
1.113 bowersj2 2406:
2407: =pod
2408:
1.648 raeburn 2409: =item * &create_workbook()
1.255 matthew 2410:
2411: Create an Excel worksheet. If it fails, output message on the
2412: request object and return undefs.
2413:
2414: Inputs: Apache request object
2415:
2416: Returns (undef) on failure,
2417: Excel worksheet object, scalar with filename, and formats
2418: from &Apache::loncommon::define_excel_formats on success
2419:
2420: =cut
2421:
2422: ###############################################################
2423: ###############################################################
2424: sub create_workbook {
2425: my ($r) = @_;
2426: #
2427: # Create the excel spreadsheet
2428: my $filename = '/prtspool/'.
1.258 albertel 2429: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2430: time.'_'.rand(1000000000).'.xls';
2431: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2432: if (! defined($workbook)) {
2433: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2434: $r->print(
2435: '<p class="LC_error">'
2436: .&mt('Problems occurred in creating the new Excel file.')
2437: .' '.&mt('This error has been logged.')
2438: .' '.&mt('Please alert your LON-CAPA administrator.')
2439: .'</p>'
2440: );
1.255 matthew 2441: return (undef);
2442: }
2443: #
1.1014 foxr 2444: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2445: #
2446: my $format = &Apache::loncommon::define_excel_formats($workbook);
2447: return ($workbook,$filename,$format);
2448: }
2449:
2450: ###############################################################
2451: ###############################################################
2452:
2453: =pod
2454:
1.648 raeburn 2455: =item * &create_text_file()
1.113 bowersj2 2456:
1.542 raeburn 2457: Create a file to write to and eventually make available to the user.
1.256 matthew 2458: If file creation fails, outputs an error message on the request object and
2459: return undefs.
1.113 bowersj2 2460:
1.256 matthew 2461: Inputs: Apache request object, and file suffix
1.113 bowersj2 2462:
1.256 matthew 2463: Returns (undef) on failure,
2464: Filehandle and filename on success.
1.113 bowersj2 2465:
2466: =cut
2467:
1.256 matthew 2468: ###############################################################
2469: ###############################################################
2470: sub create_text_file {
2471: my ($r,$suffix) = @_;
2472: if (! defined($suffix)) { $suffix = 'txt'; };
2473: my $fh;
2474: my $filename = '/prtspool/'.
1.258 albertel 2475: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2476: time.'_'.rand(1000000000).'.'.$suffix;
2477: $fh = Apache::File->new('>/home/httpd'.$filename);
2478: if (! defined($fh)) {
2479: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2480: $r->print(
2481: '<p class="LC_error">'
2482: .&mt('Problems occurred in creating the output file.')
2483: .' '.&mt('This error has been logged.')
2484: .' '.&mt('Please alert your LON-CAPA administrator.')
2485: .'</p>'
2486: );
1.113 bowersj2 2487: }
1.256 matthew 2488: return ($fh,$filename)
1.113 bowersj2 2489: }
2490:
2491:
1.256 matthew 2492: =pod
1.113 bowersj2 2493:
2494: =back
2495:
2496: =cut
1.37 matthew 2497:
2498: ###############################################################
1.33 matthew 2499: ## Home server <option> list generating code ##
2500: ###############################################################
1.35 matthew 2501:
1.169 www 2502: # ------------------------------------------
2503:
2504: sub domain_select {
1.1289 raeburn 2505: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2506: my @possdoms;
2507: if (ref($incdoms) eq 'ARRAY') {
2508: @possdoms = @{$incdoms};
2509: } else {
2510: @possdoms = &Apache::lonnet::all_domains();
2511: }
2512:
1.169 www 2513: my %domains=map {
1.514 albertel 2514: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2515: } @possdoms;
2516:
2517: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2518: foreach my $dom (@{$excdoms}) {
2519: delete($domains{$dom});
2520: }
2521: }
2522:
1.169 www 2523: if ($multiple) {
2524: $domains{''}=&mt('Any domain');
1.550 albertel 2525: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2526: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2527: } else {
1.550 albertel 2528: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2529: return &select_form($name,$value,\%domains);
1.169 www 2530: }
2531: }
2532:
1.282 albertel 2533: #-------------------------------------------
2534:
2535: =pod
2536:
1.519 raeburn 2537: =head1 Routines for form select boxes
2538:
2539: =over 4
2540:
1.648 raeburn 2541: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2542:
2543: Returns a string containing a <select> element int multiple mode
2544:
2545:
2546: Args:
2547: $name - name of the <select> element
1.506 raeburn 2548: $value - scalar or array ref of values that should already be selected
1.282 albertel 2549: $size - number of rows long the select element is
1.283 albertel 2550: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2551: (shown text should already have been &mt())
1.506 raeburn 2552: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2553:
1.282 albertel 2554: =cut
2555:
2556: #-------------------------------------------
1.169 www 2557: sub multiple_select_form {
1.284 albertel 2558: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2559: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2560: my $output='';
1.191 matthew 2561: if (! defined($size)) {
2562: $size = 4;
1.283 albertel 2563: if (scalar(keys(%$hash))<4) {
2564: $size = scalar(keys(%$hash));
1.191 matthew 2565: }
2566: }
1.734 bisitz 2567: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2568: my @order;
1.506 raeburn 2569: if (ref($order) eq 'ARRAY') {
2570: @order = @{$order};
2571: } else {
2572: @order = sort(keys(%$hash));
1.501 banghart 2573: }
2574: if (exists($$hash{'select_form_order'})) {
2575: @order = @{$$hash{'select_form_order'}};
2576: }
2577:
1.284 albertel 2578: foreach my $key (@order) {
1.356 albertel 2579: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2580: $output.='selected="selected" ' if ($selected{$key});
2581: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2582: }
2583: $output.="</select>\n";
2584: return $output;
2585: }
2586:
1.88 www 2587: #-------------------------------------------
2588:
2589: =pod
2590:
1.1254 raeburn 2591: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2592:
2593: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2594: allow a user to select options from a ref to a hash containing:
2595: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2596: a javascript onchange item, e.g., onchange="this.form.submit();".
2597: An optional arg -- $readonly -- if true will cause the select form
2598: to be disabled, e.g., for the case where an instructor has a section-
2599: specific role, and is viewing/modifying parameters.
1.970 raeburn 2600:
1.88 www 2601: See lonrights.pm for an example invocation and use.
2602:
2603: =cut
2604:
2605: #-------------------------------------------
2606: sub select_form {
1.1228 raeburn 2607: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2608: return unless (ref($hashref) eq 'HASH');
2609: if ($onchange) {
2610: $onchange = ' onchange="'.$onchange.'"';
2611: }
1.1228 raeburn 2612: my $disabled;
2613: if ($readonly) {
2614: $disabled = ' disabled="disabled"';
2615: }
2616: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2617: my @keys;
1.970 raeburn 2618: if (exists($hashref->{'select_form_order'})) {
2619: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2620: } else {
1.970 raeburn 2621: @keys=sort(keys(%{$hashref}));
1.128 albertel 2622: }
1.356 albertel 2623: foreach my $key (@keys) {
2624: $selectform.=
2625: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2626: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2627: ">".$hashref->{$key}."</option>\n";
1.88 www 2628: }
2629: $selectform.="</select>";
2630: return $selectform;
2631: }
2632:
1.475 www 2633: # For display filters
2634:
2635: sub display_filter {
1.1074 raeburn 2636: my ($context) = @_;
1.475 www 2637: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2638: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2639: my $phraseinput = 'hidden';
2640: my $includeinput = 'hidden';
2641: my ($checked,$includetypestext);
2642: if ($env{'form.displayfilter'} eq 'containing') {
2643: $phraseinput = 'text';
2644: if ($context eq 'parmslog') {
2645: $includeinput = 'checkbox';
2646: if ($env{'form.includetypes'}) {
2647: $checked = ' checked="checked"';
2648: }
2649: $includetypestext = &mt('Include parameter types');
2650: }
2651: } else {
2652: $includetypestext = ' ';
2653: }
2654: my ($additional,$secondid,$thirdid);
2655: if ($context eq 'parmslog') {
2656: $additional =
2657: '<label><input type="'.$includeinput.'" name="includetypes"'.
2658: $checked.' name="includetypes" value="1" id="includetypes" />'.
2659: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2660: '</label>';
2661: $secondid = 'includetypes';
2662: $thirdid = 'includetypestext';
2663: }
2664: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2665: '$secondid','$thirdid')";
2666: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2667: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2668: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2669: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2670: &mt('Filter: [_1]',
1.477 www 2671: &select_form($env{'form.displayfilter'},
2672: 'displayfilter',
1.970 raeburn 2673: {'currentfolder' => 'Current folder/page',
1.477 www 2674: 'containing' => 'Containing phrase',
1.1074 raeburn 2675: 'none' => 'None'},$onchange)).' '.
2676: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2677: &HTML::Entities::encode($env{'form.containingphrase'}).
2678: '" />'.$additional;
2679: }
2680:
2681: sub display_filter_js {
2682: my $includetext = &mt('Include parameter types');
2683: return <<"ENDJS";
2684:
2685: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2686: var firstType = 'hidden';
2687: if (setter.options[setter.selectedIndex].value == 'containing') {
2688: firstType = 'text';
2689: }
2690: firstObject = document.getElementById(firstid);
2691: if (typeof(firstObject) == 'object') {
2692: if (firstObject.type != firstType) {
2693: changeInputType(firstObject,firstType);
2694: }
2695: }
2696: if (context == 'parmslog') {
2697: var secondType = 'hidden';
2698: if (firstType == 'text') {
2699: secondType = 'checkbox';
2700: }
2701: secondObject = document.getElementById(secondid);
2702: if (typeof(secondObject) == 'object') {
2703: if (secondObject.type != secondType) {
2704: changeInputType(secondObject,secondType);
2705: }
2706: }
2707: var textItem = document.getElementById(thirdid);
2708: var currtext = textItem.innerHTML;
2709: var newtext;
2710: if (firstType == 'text') {
2711: newtext = '$includetext';
2712: } else {
2713: newtext = ' ';
2714: }
2715: if (currtext != newtext) {
2716: textItem.innerHTML = newtext;
2717: }
2718: }
2719: return;
2720: }
2721:
2722: function changeInputType(oldObject,newType) {
2723: var newObject = document.createElement('input');
2724: newObject.type = newType;
2725: if (oldObject.size) {
2726: newObject.size = oldObject.size;
2727: }
2728: if (oldObject.value) {
2729: newObject.value = oldObject.value;
2730: }
2731: if (oldObject.name) {
2732: newObject.name = oldObject.name;
2733: }
2734: if (oldObject.id) {
2735: newObject.id = oldObject.id;
2736: }
2737: oldObject.parentNode.replaceChild(newObject,oldObject);
2738: return;
2739: }
2740:
2741: ENDJS
1.475 www 2742: }
2743:
1.167 www 2744: sub gradeleveldescription {
2745: my $gradelevel=shift;
2746: my %gradelevels=(0 => 'Not specified',
2747: 1 => 'Grade 1',
2748: 2 => 'Grade 2',
2749: 3 => 'Grade 3',
2750: 4 => 'Grade 4',
2751: 5 => 'Grade 5',
2752: 6 => 'Grade 6',
2753: 7 => 'Grade 7',
2754: 8 => 'Grade 8',
2755: 9 => 'Grade 9',
2756: 10 => 'Grade 10',
2757: 11 => 'Grade 11',
2758: 12 => 'Grade 12',
2759: 13 => 'Grade 13',
2760: 14 => '100 Level',
2761: 15 => '200 Level',
2762: 16 => '300 Level',
2763: 17 => '400 Level',
2764: 18 => 'Graduate Level');
2765: return &mt($gradelevels{$gradelevel});
2766: }
2767:
1.163 www 2768: sub select_level_form {
2769: my ($deflevel,$name)=@_;
2770: unless ($deflevel) { $deflevel=0; }
1.167 www 2771: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2772: for (my $i=0; $i<=18; $i++) {
2773: $selectform.="<option value=\"$i\" ".
1.253 albertel 2774: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2775: ">".&gradeleveldescription($i)."</option>\n";
2776: }
2777: $selectform.="</select>";
2778: return $selectform;
1.163 www 2779: }
1.167 www 2780:
1.35 matthew 2781: #-------------------------------------------
2782:
1.45 matthew 2783: =pod
2784:
1.1256 raeburn 2785: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2786:
2787: Returns a string containing a <select name='$name' size='1'> form to
2788: allow a user to select the domain to preform an operation in.
2789: See loncreateuser.pm for an example invocation and use.
2790:
1.90 www 2791: If the $includeempty flag is set, it also includes an empty choice ("no domain
2792: selected");
2793:
1.743 raeburn 2794: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2795:
1.910 raeburn 2796: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2797:
1.1121 raeburn 2798: The optional $incdoms is a reference to an array of domains which will be the only available options.
2799:
2800: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2801:
1.1256 raeburn 2802: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2803:
1.35 matthew 2804: =cut
2805:
2806: #-------------------------------------------
1.34 matthew 2807: sub select_dom_form {
1.1256 raeburn 2808: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2809: if ($onchange) {
1.874 raeburn 2810: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2811: }
1.1256 raeburn 2812: if ($disabled) {
2813: $disabled = ' disabled="disabled"';
2814: }
1.1121 raeburn 2815: my (@domains,%exclude);
1.910 raeburn 2816: if (ref($incdoms) eq 'ARRAY') {
2817: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2818: } else {
2819: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2820: }
1.90 www 2821: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2822: if (ref($excdoms) eq 'ARRAY') {
2823: map { $exclude{$_} = 1; } @{$excdoms};
2824: }
1.1256 raeburn 2825: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2826: foreach my $dom (@domains) {
1.1121 raeburn 2827: next if ($exclude{$dom});
1.356 albertel 2828: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2829: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2830: if ($showdomdesc) {
2831: if ($dom ne '') {
2832: my $domdesc = &Apache::lonnet::domain($dom,'description');
2833: if ($domdesc ne '') {
2834: $selectdomain .= ' ('.$domdesc.')';
2835: }
2836: }
2837: }
2838: $selectdomain .= "</option>\n";
1.34 matthew 2839: }
2840: $selectdomain.="</select>";
2841: return $selectdomain;
2842: }
2843:
1.35 matthew 2844: #-------------------------------------------
2845:
1.45 matthew 2846: =pod
2847:
1.648 raeburn 2848: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2849:
1.586 raeburn 2850: input: 4 arguments (two required, two optional) -
2851: $domain - domain of new user
2852: $name - name of form element
2853: $default - Value of 'default' causes a default item to be first
2854: option, and selected by default.
2855: $hide - Value of 'hide' causes hiding of the name of the server,
2856: if 1 server found, or default, if 0 found.
1.594 raeburn 2857: output: returns 2 items:
1.586 raeburn 2858: (a) form element which contains either:
2859: (i) <select name="$name">
2860: <option value="$hostid1">$hostid $servers{$hostid}</option>
2861: <option value="$hostid2">$hostid $servers{$hostid}</option>
2862: </select>
2863: form item if there are multiple library servers in $domain, or
2864: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2865: if there is only one library server in $domain.
2866:
2867: (b) number of library servers found.
2868:
2869: See loncreateuser.pm for example of use.
1.35 matthew 2870:
2871: =cut
2872:
2873: #-------------------------------------------
1.586 raeburn 2874: sub home_server_form_item {
2875: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2876: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2877: my $result;
2878: my $numlib = keys(%servers);
2879: if ($numlib > 1) {
2880: $result .= '<select name="'.$name.'" />'."\n";
2881: if ($default) {
1.804 bisitz 2882: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2883: '</option>'."\n";
2884: }
2885: foreach my $hostid (sort(keys(%servers))) {
2886: $result.= '<option value="'.$hostid.'">'.
2887: $hostid.' '.$servers{$hostid}."</option>\n";
2888: }
2889: $result .= '</select>'."\n";
2890: } elsif ($numlib == 1) {
2891: my $hostid;
2892: foreach my $item (keys(%servers)) {
2893: $hostid = $item;
2894: }
2895: $result .= '<input type="hidden" name="'.$name.'" value="'.
2896: $hostid.'" />';
2897: if (!$hide) {
2898: $result .= $hostid.' '.$servers{$hostid};
2899: }
2900: $result .= "\n";
2901: } elsif ($default) {
2902: $result .= '<input type="hidden" name="'.$name.
2903: '" value="default" />';
2904: if (!$hide) {
2905: $result .= &mt('default');
2906: }
2907: $result .= "\n";
1.33 matthew 2908: }
1.586 raeburn 2909: return ($result,$numlib);
1.33 matthew 2910: }
1.112 bowersj2 2911:
2912: =pod
2913:
1.534 albertel 2914: =back
2915:
1.112 bowersj2 2916: =cut
1.87 matthew 2917:
2918: ###############################################################
1.112 bowersj2 2919: ## Decoding User Agent ##
1.87 matthew 2920: ###############################################################
2921:
2922: =pod
2923:
1.112 bowersj2 2924: =head1 Decoding the User Agent
2925:
2926: =over 4
2927:
2928: =item * &decode_user_agent()
1.87 matthew 2929:
2930: Inputs: $r
2931:
2932: Outputs:
2933:
2934: =over 4
2935:
1.112 bowersj2 2936: =item * $httpbrowser
1.87 matthew 2937:
1.112 bowersj2 2938: =item * $clientbrowser
1.87 matthew 2939:
1.112 bowersj2 2940: =item * $clientversion
1.87 matthew 2941:
1.112 bowersj2 2942: =item * $clientmathml
1.87 matthew 2943:
1.112 bowersj2 2944: =item * $clientunicode
1.87 matthew 2945:
1.112 bowersj2 2946: =item * $clientos
1.87 matthew 2947:
1.1137 raeburn 2948: =item * $clientmobile
2949:
1.1141 raeburn 2950: =item * $clientinfo
2951:
1.1194 raeburn 2952: =item * $clientosversion
2953:
1.87 matthew 2954: =back
2955:
1.157 matthew 2956: =back
2957:
1.87 matthew 2958: =cut
2959:
2960: ###############################################################
2961: ###############################################################
2962: sub decode_user_agent {
1.247 albertel 2963: my ($r)=@_;
1.87 matthew 2964: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2965: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2966: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2967: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2968: my $clientbrowser='unknown';
2969: my $clientversion='0';
2970: my $clientmathml='';
2971: my $clientunicode='0';
1.1137 raeburn 2972: my $clientmobile=0;
1.1194 raeburn 2973: my $clientosversion='';
1.87 matthew 2974: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2975: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2976: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2977: $clientbrowser=$bname;
2978: $httpbrowser=~/$vreg/i;
2979: $clientversion=$1;
2980: $clientmathml=($clientversion>=$minv);
2981: $clientunicode=($clientversion>=$univ);
2982: }
2983: }
2984: my $clientos='unknown';
1.1141 raeburn 2985: my $clientinfo;
1.87 matthew 2986: if (($httpbrowser=~/linux/i) ||
2987: ($httpbrowser=~/unix/i) ||
2988: ($httpbrowser=~/ux/i) ||
2989: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2990: if (($httpbrowser=~/vax/i) ||
2991: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2992: if ($httpbrowser=~/next/i) { $clientos='next'; }
2993: if (($httpbrowser=~/mac/i) ||
2994: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2995: if ($httpbrowser=~/win/i) {
2996: $clientos='win';
2997: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2998: $clientosversion = $1;
2999: }
3000: }
1.87 matthew 3001: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3002: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3003: $clientmobile=lc($1);
3004: }
1.1141 raeburn 3005: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3006: $clientinfo = 'firefox-'.$1;
3007: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3008: $clientinfo = 'chromeframe-'.$1;
3009: }
1.87 matthew 3010: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3011: $clientunicode,$clientos,$clientmobile,$clientinfo,
3012: $clientosversion);
1.87 matthew 3013: }
3014:
1.32 matthew 3015: ###############################################################
3016: ## Authentication changing form generation subroutines ##
3017: ###############################################################
3018: ##
3019: ## All of the authform_xxxxxxx subroutines take their inputs in a
3020: ## hash, and have reasonable default values.
3021: ##
3022: ## formname = the name given in the <form> tag.
1.35 matthew 3023: #-------------------------------------------
3024:
1.45 matthew 3025: =pod
3026:
1.112 bowersj2 3027: =head1 Authentication Routines
3028:
3029: =over 4
3030:
1.648 raeburn 3031: =item * &authform_xxxxxx()
1.35 matthew 3032:
3033: The authform_xxxxxx subroutines provide javascript and html forms which
3034: handle some of the conveniences required for authentication forms.
3035: This is not an optimal method, but it works.
3036:
3037: =over 4
3038:
1.112 bowersj2 3039: =item * authform_header
1.35 matthew 3040:
1.112 bowersj2 3041: =item * authform_authorwarning
1.35 matthew 3042:
1.112 bowersj2 3043: =item * authform_nochange
1.35 matthew 3044:
1.112 bowersj2 3045: =item * authform_kerberos
1.35 matthew 3046:
1.112 bowersj2 3047: =item * authform_internal
1.35 matthew 3048:
1.112 bowersj2 3049: =item * authform_filesystem
1.35 matthew 3050:
1.1310 raeburn 3051: =item * authform_lti
3052:
1.35 matthew 3053: =back
3054:
1.648 raeburn 3055: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3056:
1.35 matthew 3057: =cut
3058:
3059: #-------------------------------------------
1.32 matthew 3060: sub authform_header{
3061: my %in = (
3062: formname => 'cu',
1.80 albertel 3063: kerb_def_dom => '',
1.32 matthew 3064: @_,
3065: );
3066: $in{'formname'} = 'document.' . $in{'formname'};
3067: my $result='';
1.80 albertel 3068:
3069: #---------------------------------------------- Code for upper case translation
3070: my $Javascript_toUpperCase;
3071: unless ($in{kerb_def_dom}) {
3072: $Javascript_toUpperCase =<<"END";
3073: switch (choice) {
3074: case 'krb': currentform.elements[choicearg].value =
3075: currentform.elements[choicearg].value.toUpperCase();
3076: break;
3077: default:
3078: }
3079: END
3080: } else {
3081: $Javascript_toUpperCase = "";
3082: }
3083:
1.165 raeburn 3084: my $radioval = "'nochange'";
1.591 raeburn 3085: if (defined($in{'curr_authtype'})) {
3086: if ($in{'curr_authtype'} ne '') {
3087: $radioval = "'".$in{'curr_authtype'}."arg'";
3088: }
1.174 matthew 3089: }
1.165 raeburn 3090: my $argfield = 'null';
1.591 raeburn 3091: if (defined($in{'mode'})) {
1.165 raeburn 3092: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3093: if (defined($in{'curr_autharg'})) {
3094: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3095: $argfield = "'$in{'curr_autharg'}'";
3096: }
3097: }
3098: }
3099: }
3100:
1.32 matthew 3101: $result.=<<"END";
3102: var current = new Object();
1.165 raeburn 3103: current.radiovalue = $radioval;
3104: current.argfield = $argfield;
1.32 matthew 3105:
3106: function changed_radio(choice,currentform) {
3107: var choicearg = choice + 'arg';
3108: // If a radio button in changed, we need to change the argfield
3109: if (current.radiovalue != choice) {
3110: current.radiovalue = choice;
3111: if (current.argfield != null) {
3112: currentform.elements[current.argfield].value = '';
3113: }
3114: if (choice == 'nochange') {
3115: current.argfield = null;
3116: } else {
3117: current.argfield = choicearg;
3118: switch(choice) {
3119: case 'krb':
3120: currentform.elements[current.argfield].value =
3121: "$in{'kerb_def_dom'}";
3122: break;
3123: default:
3124: break;
3125: }
3126: }
3127: }
3128: return;
3129: }
1.22 www 3130:
1.32 matthew 3131: function changed_text(choice,currentform) {
3132: var choicearg = choice + 'arg';
3133: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3134: $Javascript_toUpperCase
1.32 matthew 3135: // clear old field
3136: if ((current.argfield != choicearg) && (current.argfield != null)) {
3137: currentform.elements[current.argfield].value = '';
3138: }
3139: current.argfield = choicearg;
3140: }
3141: set_auth_radio_buttons(choice,currentform);
3142: return;
1.20 www 3143: }
1.32 matthew 3144:
3145: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3146: var numauthchoices = currentform.login.length;
3147: if (typeof numauthchoices == "undefined") {
3148: return;
3149: }
1.32 matthew 3150: var i=0;
1.986 raeburn 3151: while (i < numauthchoices) {
1.32 matthew 3152: if (currentform.login[i].value == newvalue) { break; }
3153: i++;
3154: }
1.986 raeburn 3155: if (i == numauthchoices) {
1.32 matthew 3156: return;
3157: }
3158: current.radiovalue = newvalue;
3159: currentform.login[i].checked = true;
3160: return;
3161: }
3162: END
3163: return $result;
3164: }
3165:
1.1106 raeburn 3166: sub authform_authorwarning {
1.32 matthew 3167: my $result='';
1.144 matthew 3168: $result='<i>'.
3169: &mt('As a general rule, only authors or co-authors should be '.
3170: 'filesystem authenticated '.
3171: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3172: return $result;
3173: }
3174:
1.1106 raeburn 3175: sub authform_nochange {
1.32 matthew 3176: my %in = (
3177: formname => 'document.cu',
3178: kerb_def_dom => 'MSU.EDU',
3179: @_,
3180: );
1.1106 raeburn 3181: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3182: my $result;
1.1104 raeburn 3183: if (!$authnum) {
1.1105 raeburn 3184: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3185: } else {
3186: $result = '<label>'.&mt('[_1] Do not change login data',
3187: '<input type="radio" name="login" value="nochange" '.
3188: 'checked="checked" onclick="'.
1.281 albertel 3189: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3190: '</label>';
1.586 raeburn 3191: }
1.32 matthew 3192: return $result;
3193: }
3194:
1.591 raeburn 3195: sub authform_kerberos {
1.32 matthew 3196: my %in = (
3197: formname => 'document.cu',
3198: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3199: kerb_def_auth => 'krb4',
1.32 matthew 3200: @_,
3201: );
1.586 raeburn 3202: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3203: $autharg,$jscall,$disabled);
1.1106 raeburn 3204: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3205: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3206: $check5 = ' checked="checked"';
1.80 albertel 3207: } else {
1.772 bisitz 3208: $check4 = ' checked="checked"';
1.80 albertel 3209: }
1.1259 raeburn 3210: if ($in{'readonly'}) {
3211: $disabled = ' disabled="disabled"';
3212: }
1.165 raeburn 3213: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3214: if (defined($in{'curr_authtype'})) {
3215: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3216: $krbcheck = ' checked="checked"';
1.623 raeburn 3217: if (defined($in{'mode'})) {
3218: if ($in{'mode'} eq 'modifyuser') {
3219: $krbcheck = '';
3220: }
3221: }
1.591 raeburn 3222: if (defined($in{'curr_kerb_ver'})) {
3223: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3224: $check5 = ' checked="checked"';
1.591 raeburn 3225: $check4 = '';
3226: } else {
1.772 bisitz 3227: $check4 = ' checked="checked"';
1.591 raeburn 3228: $check5 = '';
3229: }
1.586 raeburn 3230: }
1.591 raeburn 3231: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3232: $krbarg = $in{'curr_autharg'};
3233: }
1.586 raeburn 3234: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3235: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3236: $result =
3237: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3238: $in{'curr_autharg'},$krbver);
3239: } else {
3240: $result =
3241: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3242: }
3243: return $result;
3244: }
3245: }
3246: } else {
3247: if ($authnum == 1) {
1.784 bisitz 3248: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3249: }
3250: }
1.586 raeburn 3251: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3252: return;
1.587 raeburn 3253: } elsif ($authtype eq '') {
1.591 raeburn 3254: if (defined($in{'mode'})) {
1.587 raeburn 3255: if ($in{'mode'} eq 'modifycourse') {
3256: if ($authnum == 1) {
1.1259 raeburn 3257: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3258: }
3259: }
3260: }
1.586 raeburn 3261: }
3262: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3263: if ($authtype eq '') {
3264: $authtype = '<input type="radio" name="login" value="krb" '.
3265: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3266: $krbcheck.$disabled.' />';
1.586 raeburn 3267: }
3268: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3269: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3270: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3271: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3272: $in{'curr_authtype'} eq 'krb4')) {
3273: $result .= &mt
1.144 matthew 3274: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3275: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3276: '<label>'.$authtype,
1.281 albertel 3277: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3278: 'value="'.$krbarg.'" '.
1.1259 raeburn 3279: 'onchange="'.$jscall.'"'.$disabled.' />',
3280: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3281: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3282: '</label>');
1.586 raeburn 3283: } elsif ($can_assign{'krb4'}) {
3284: $result .= &mt
3285: ('[_1] Kerberos authenticated with domain [_2] '.
3286: '[_3] Version 4 [_4]',
3287: '<label>'.$authtype,
3288: '</label><input type="text" size="10" name="krbarg" '.
3289: 'value="'.$krbarg.'" '.
1.1259 raeburn 3290: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3291: '<label><input type="hidden" name="krbver" value="4" />',
3292: '</label>');
3293: } elsif ($can_assign{'krb5'}) {
3294: $result .= &mt
3295: ('[_1] Kerberos authenticated with domain [_2] '.
3296: '[_3] Version 5 [_4]',
3297: '<label>'.$authtype,
3298: '</label><input type="text" size="10" name="krbarg" '.
3299: 'value="'.$krbarg.'" '.
1.1259 raeburn 3300: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3301: '<label><input type="hidden" name="krbver" value="5" />',
3302: '</label>');
3303: }
1.32 matthew 3304: return $result;
3305: }
3306:
1.1106 raeburn 3307: sub authform_internal {
1.586 raeburn 3308: my %in = (
1.32 matthew 3309: formname => 'document.cu',
3310: kerb_def_dom => 'MSU.EDU',
3311: @_,
3312: );
1.1259 raeburn 3313: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3314: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3315: if ($in{'readonly'}) {
3316: $disabled = ' disabled="disabled"';
3317: }
1.591 raeburn 3318: if (defined($in{'curr_authtype'})) {
3319: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3320: if ($can_assign{'int'}) {
1.772 bisitz 3321: $intcheck = 'checked="checked" ';
1.623 raeburn 3322: if (defined($in{'mode'})) {
3323: if ($in{'mode'} eq 'modifyuser') {
3324: $intcheck = '';
3325: }
3326: }
1.591 raeburn 3327: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3328: $intarg = $in{'curr_autharg'};
3329: }
3330: } else {
3331: $result = &mt('Currently internally authenticated.');
3332: return $result;
1.165 raeburn 3333: }
3334: }
1.586 raeburn 3335: } else {
3336: if ($authnum == 1) {
1.784 bisitz 3337: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3338: }
3339: }
3340: if (!$can_assign{'int'}) {
3341: return;
1.587 raeburn 3342: } elsif ($authtype eq '') {
1.591 raeburn 3343: if (defined($in{'mode'})) {
1.587 raeburn 3344: if ($in{'mode'} eq 'modifycourse') {
3345: if ($authnum == 1) {
1.1259 raeburn 3346: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3347: }
3348: }
3349: }
1.165 raeburn 3350: }
1.586 raeburn 3351: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3352: if ($authtype eq '') {
3353: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3354: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3355: }
1.605 bisitz 3356: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3357: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3358: $result = &mt
1.144 matthew 3359: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3360: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3361: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3362: return $result;
3363: }
3364:
1.1104 raeburn 3365: sub authform_local {
1.32 matthew 3366: my %in = (
3367: formname => 'document.cu',
3368: kerb_def_dom => 'MSU.EDU',
3369: @_,
3370: );
1.1259 raeburn 3371: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3372: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3373: if ($in{'readonly'}) {
3374: $disabled = ' disabled="disabled"';
3375: }
1.591 raeburn 3376: if (defined($in{'curr_authtype'})) {
3377: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3378: if ($can_assign{'loc'}) {
1.772 bisitz 3379: $loccheck = 'checked="checked" ';
1.623 raeburn 3380: if (defined($in{'mode'})) {
3381: if ($in{'mode'} eq 'modifyuser') {
3382: $loccheck = '';
3383: }
3384: }
1.591 raeburn 3385: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3386: $locarg = $in{'curr_autharg'};
3387: }
3388: } else {
3389: $result = &mt('Currently using local (institutional) authentication.');
3390: return $result;
1.165 raeburn 3391: }
3392: }
1.586 raeburn 3393: } else {
3394: if ($authnum == 1) {
1.784 bisitz 3395: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3396: }
3397: }
3398: if (!$can_assign{'loc'}) {
3399: return;
1.587 raeburn 3400: } elsif ($authtype eq '') {
1.591 raeburn 3401: if (defined($in{'mode'})) {
1.587 raeburn 3402: if ($in{'mode'} eq 'modifycourse') {
3403: if ($authnum == 1) {
1.1259 raeburn 3404: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3405: }
3406: }
3407: }
1.165 raeburn 3408: }
1.586 raeburn 3409: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3410: if ($authtype eq '') {
3411: $authtype = '<input type="radio" name="login" value="loc" '.
3412: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3413: $jscall.'"'.$disabled.' />';
1.586 raeburn 3414: }
3415: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3416: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3417: $result = &mt('[_1] Local Authentication with argument [_2]',
3418: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3419: return $result;
3420: }
3421:
1.1106 raeburn 3422: sub authform_filesystem {
1.32 matthew 3423: my %in = (
3424: formname => 'document.cu',
3425: kerb_def_dom => 'MSU.EDU',
3426: @_,
3427: );
1.1259 raeburn 3428: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3429: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3430: if ($in{'readonly'}) {
3431: $disabled = ' disabled="disabled"';
3432: }
1.591 raeburn 3433: if (defined($in{'curr_authtype'})) {
3434: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3435: if ($can_assign{'fsys'}) {
1.772 bisitz 3436: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3437: if (defined($in{'mode'})) {
3438: if ($in{'mode'} eq 'modifyuser') {
3439: $fsyscheck = '';
3440: }
3441: }
1.586 raeburn 3442: } else {
3443: $result = &mt('Currently Filesystem Authenticated.');
3444: return $result;
1.1259 raeburn 3445: }
1.586 raeburn 3446: }
3447: } else {
3448: if ($authnum == 1) {
1.784 bisitz 3449: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3450: }
3451: }
3452: if (!$can_assign{'fsys'}) {
3453: return;
1.587 raeburn 3454: } elsif ($authtype eq '') {
1.591 raeburn 3455: if (defined($in{'mode'})) {
1.587 raeburn 3456: if ($in{'mode'} eq 'modifycourse') {
3457: if ($authnum == 1) {
1.1259 raeburn 3458: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3459: }
3460: }
3461: }
1.586 raeburn 3462: }
3463: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3464: if ($authtype eq '') {
3465: $authtype = '<input type="radio" name="login" value="fsys" '.
3466: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3467: $jscall.'"'.$disabled.' />';
1.586 raeburn 3468: }
1.1310 raeburn 3469: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3470: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3471: $result = &mt
1.144 matthew 3472: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3473: '<label>'.$authtype,'</label>'.$autharg);
3474: return $result;
3475: }
3476:
3477: sub authform_lti {
3478: my %in = (
3479: formname => 'document.cu',
3480: kerb_def_dom => 'MSU.EDU',
3481: @_,
3482: );
3483: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3484: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3485: if ($in{'readonly'}) {
3486: $disabled = ' disabled="disabled"';
3487: }
3488: if (defined($in{'curr_authtype'})) {
3489: if ($in{'curr_authtype'} eq 'lti') {
3490: if ($can_assign{'lti'}) {
3491: $lticheck = 'checked="checked" ';
3492: if (defined($in{'mode'})) {
3493: if ($in{'mode'} eq 'modifyuser') {
3494: $lticheck = '';
3495: }
3496: }
3497: } else {
3498: $result = &mt('Currently LTI Authenticated.');
3499: return $result;
3500: }
3501: }
3502: } else {
3503: if ($authnum == 1) {
3504: $authtype = '<input type="hidden" name="login" value="lti" />';
3505: }
3506: }
3507: if (!$can_assign{'lti'}) {
3508: return;
3509: } elsif ($authtype eq '') {
3510: if (defined($in{'mode'})) {
3511: if ($in{'mode'} eq 'modifycourse') {
3512: if ($authnum == 1) {
3513: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3514: }
3515: }
3516: }
3517: }
3518: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3519: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3520: $authtype = '<input type="radio" name="login" value="lti" '.
3521: $lticheck.' onchange="'.$jscall.'" onclick="'.
3522: $jscall.'"'.$disabled.' />';
3523: }
3524: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3525: if ($authtype) {
3526: $result = &mt('[_1] LTI Authenticated',
3527: '<label>'.$authtype.'</label>'.$autharg);
3528: } else {
3529: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3530: $autharg;
3531: }
1.32 matthew 3532: return $result;
3533: }
3534:
1.586 raeburn 3535: sub get_assignable_auth {
3536: my ($dom) = @_;
3537: if ($dom eq '') {
3538: $dom = $env{'request.role.domain'};
3539: }
3540: my %can_assign = (
3541: krb4 => 1,
3542: krb5 => 1,
3543: int => 1,
3544: loc => 1,
1.1310 raeburn 3545: lti => 1,
1.586 raeburn 3546: );
3547: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3548: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3549: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3550: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3551: my $context;
3552: if ($env{'request.role'} =~ /^au/) {
3553: $context = 'author';
1.1259 raeburn 3554: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3555: $context = 'domain';
3556: } elsif ($env{'request.course.id'}) {
3557: $context = 'course';
3558: }
3559: if ($context) {
3560: if (ref($authhash->{$context}) eq 'HASH') {
3561: %can_assign = %{$authhash->{$context}};
3562: }
3563: }
3564: }
3565: }
3566: my $authnum = 0;
3567: foreach my $key (keys(%can_assign)) {
3568: if ($can_assign{$key}) {
3569: $authnum ++;
3570: }
3571: }
3572: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3573: $authnum --;
3574: }
3575: return ($authnum,%can_assign);
3576: }
3577:
1.1331 raeburn 3578: sub check_passwd_rules {
3579: my ($domain,$plainpass) = @_;
3580: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3581: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3582: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3583: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3584: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3585: if ($passwdconf{'min'} > $min) {
3586: $min = $passwdconf{'min'};
3587: }
1.1331 raeburn 3588: }
3589: if ($passwdconf{'max'} =~ /^\d+$/) {
3590: $max = $passwdconf{'max'};
3591: }
3592: @chars = @{$passwdconf{'chars'}};
3593: }
3594: if (($min) && (length($plainpass) < $min)) {
3595: push(@brokerule,'min');
3596: }
3597: if (($max) && (length($plainpass) > $max)) {
3598: push(@brokerule,'max');
3599: }
3600: if (@chars) {
3601: my %rules;
3602: map { $rules{$_} = 1; } @chars;
3603: if ($rules{'uc'}) {
3604: unless ($plainpass =~ /[A-Z]/) {
3605: push(@brokerule,'uc');
3606: }
3607: }
3608: if ($rules{'lc'}) {
1.1332 raeburn 3609: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3610: push(@brokerule,'lc');
3611: }
3612: }
3613: if ($rules{'num'}) {
3614: unless ($plainpass =~ /\d/) {
3615: push(@brokerule,'num');
3616: }
3617: }
3618: if ($rules{'spec'}) {
3619: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3620: push(@brokerule,'spec');
3621: }
3622: }
3623: }
3624: if (@brokerule) {
3625: my %rulenames = &Apache::lonlocal::texthash(
3626: uc => 'At least one upper case letter',
3627: lc => 'At least one lower case letter',
3628: num => 'At least one number',
3629: spec => 'At least one non-alphanumeric',
3630: );
3631: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3632: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3633: $rulenames{'num'} .= ': 0123456789';
3634: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3635: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3636: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3637: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3638: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3639: if (grep(/^$rule$/,@brokerule)) {
3640: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3641: }
3642: }
3643: $warning .= '</ul>';
3644: }
1.1332 raeburn 3645: if (wantarray) {
3646: return @brokerule;
3647: }
1.1331 raeburn 3648: return $warning;
3649: }
3650:
1.80 albertel 3651: ###############################################################
3652: ## Get Kerberos Defaults for Domain ##
3653: ###############################################################
3654: ##
3655: ## Returns default kerberos version and an associated argument
3656: ## as listed in file domain.tab. If not listed, provides
3657: ## appropriate default domain and kerberos version.
3658: ##
3659: #-------------------------------------------
3660:
3661: =pod
3662:
1.648 raeburn 3663: =item * &get_kerberos_defaults()
1.80 albertel 3664:
3665: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3666: version and domain. If not found, it defaults to version 4 and the
3667: domain of the server.
1.80 albertel 3668:
1.648 raeburn 3669: =over 4
3670:
1.80 albertel 3671: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3672:
1.648 raeburn 3673: =back
3674:
3675: =back
3676:
1.80 albertel 3677: =cut
3678:
3679: #-------------------------------------------
3680: sub get_kerberos_defaults {
3681: my $domain=shift;
1.641 raeburn 3682: my ($krbdef,$krbdefdom);
3683: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3684: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3685: $krbdef = $domdefaults{'auth_def'};
3686: $krbdefdom = $domdefaults{'auth_arg_def'};
3687: } else {
1.80 albertel 3688: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3689: my $krbdefdom=$1;
3690: $krbdefdom=~tr/a-z/A-Z/;
3691: $krbdef = "krb4";
3692: }
3693: return ($krbdef,$krbdefdom);
3694: }
1.112 bowersj2 3695:
1.32 matthew 3696:
1.46 matthew 3697: ###############################################################
3698: ## Thesaurus Functions ##
3699: ###############################################################
1.20 www 3700:
1.46 matthew 3701: =pod
1.20 www 3702:
1.112 bowersj2 3703: =head1 Thesaurus Functions
3704:
3705: =over 4
3706:
1.648 raeburn 3707: =item * &initialize_keywords()
1.46 matthew 3708:
3709: Initializes the package variable %Keywords if it is empty. Uses the
3710: package variable $thesaurus_db_file.
3711:
3712: =cut
3713:
3714: ###################################################
3715:
3716: sub initialize_keywords {
3717: return 1 if (scalar keys(%Keywords));
3718: # If we are here, %Keywords is empty, so fill it up
3719: # Make sure the file we need exists...
3720: if (! -e $thesaurus_db_file) {
3721: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3722: " failed because it does not exist");
3723: return 0;
3724: }
3725: # Set up the hash as a database
3726: my %thesaurus_db;
3727: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3728: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3729: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3730: $thesaurus_db_file);
3731: return 0;
3732: }
3733: # Get the average number of appearances of a word.
3734: my $avecount = $thesaurus_db{'average.count'};
3735: # Put keywords (those that appear > average) into %Keywords
3736: while (my ($word,$data)=each (%thesaurus_db)) {
3737: my ($count,undef) = split /:/,$data;
3738: $Keywords{$word}++ if ($count > $avecount);
3739: }
3740: untie %thesaurus_db;
3741: # Remove special values from %Keywords.
1.356 albertel 3742: foreach my $value ('total.count','average.count') {
3743: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3744: }
1.46 matthew 3745: return 1;
3746: }
3747:
3748: ###################################################
3749:
3750: =pod
3751:
1.648 raeburn 3752: =item * &keyword($word)
1.46 matthew 3753:
3754: Returns true if $word is a keyword. A keyword is a word that appears more
3755: than the average number of times in the thesaurus database. Calls
3756: &initialize_keywords
3757:
3758: =cut
3759:
3760: ###################################################
1.20 www 3761:
3762: sub keyword {
1.46 matthew 3763: return if (!&initialize_keywords());
3764: my $word=lc(shift());
3765: $word=~s/\W//g;
3766: return exists($Keywords{$word});
1.20 www 3767: }
1.46 matthew 3768:
3769: ###############################################################
3770:
3771: =pod
1.20 www 3772:
1.648 raeburn 3773: =item * &get_related_words()
1.46 matthew 3774:
1.160 matthew 3775: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3776: an array of words. If the keyword is not in the thesaurus, an empty array
3777: will be returned. The order of the words returned is determined by the
3778: database which holds them.
3779:
3780: Uses global $thesaurus_db_file.
3781:
1.1057 foxr 3782:
1.46 matthew 3783: =cut
3784:
3785: ###############################################################
3786: sub get_related_words {
3787: my $keyword = shift;
3788: my %thesaurus_db;
3789: if (! -e $thesaurus_db_file) {
3790: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3791: "failed because the file does not exist");
3792: return ();
3793: }
3794: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3795: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3796: return ();
3797: }
3798: my @Words=();
1.429 www 3799: my $count=0;
1.46 matthew 3800: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3801: # The first element is the number of times
3802: # the word appears. We do not need it now.
1.429 www 3803: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3804: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3805: my $threshold=$mostfrequentcount/10;
3806: foreach my $possibleword (@RelatedWords) {
3807: my ($word,$wordcount)=split(/\,/,$possibleword);
3808: if ($wordcount>$threshold) {
3809: push(@Words,$word);
3810: $count++;
3811: if ($count>10) { last; }
3812: }
1.20 www 3813: }
3814: }
1.46 matthew 3815: untie %thesaurus_db;
3816: return @Words;
1.14 harris41 3817: }
1.1090 foxr 3818: ###############################################################
3819: #
3820: # Spell checking
3821: #
3822:
3823: =pod
3824:
1.1142 raeburn 3825: =back
3826:
1.1090 foxr 3827: =head1 Spell checking
3828:
3829: =over 4
3830:
3831: =item * &check_spelling($wordlist $language)
3832:
3833: Takes a string containing words and feeds it to an external
3834: spellcheck program via a pipeline. Returns a string containing
3835: them mis-spelled words.
3836:
3837: Parameters:
3838:
3839: =over 4
3840:
3841: =item - $wordlist
3842:
3843: String that will be fed into the spellcheck program.
3844:
3845: =item - $language
3846:
3847: Language string that specifies the language for which the spell
3848: check will be performed.
3849:
3850: =back
3851:
3852: =back
3853:
3854: Note: This sub assumes that aspell is installed.
3855:
3856:
3857: =cut
3858:
1.46 matthew 3859:
1.1090 foxr 3860: sub check_spelling {
3861: my ($wordlist, $language) = @_;
1.1091 foxr 3862: my @misspellings;
3863:
3864: # Generate the speller and set the langauge.
3865: # if explicitly selected:
1.1090 foxr 3866:
1.1091 foxr 3867: my $speller = Text::Aspell->new;
1.1090 foxr 3868: if ($language) {
1.1091 foxr 3869: $speller->set_option('lang', $language);
1.1090 foxr 3870: }
3871:
1.1091 foxr 3872: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3873:
1.1091 foxr 3874: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3875:
1.1091 foxr 3876: foreach my $word (@words) {
3877: if(! $speller->check($word)) {
3878: push(@misspellings, $word);
1.1090 foxr 3879: }
3880: }
1.1091 foxr 3881: return join(' ', @misspellings);
3882:
1.1090 foxr 3883: }
3884:
1.61 www 3885: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3886: =pod
3887:
1.112 bowersj2 3888: =head1 User Name Functions
3889:
3890: =over 4
3891:
1.648 raeburn 3892: =item * &plainname($uname,$udom,$first)
1.81 albertel 3893:
1.112 bowersj2 3894: Takes a users logon name and returns it as a string in
1.226 albertel 3895: "first middle last generation" form
3896: if $first is set to 'lastname' then it returns it as
3897: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3898:
3899: =cut
1.61 www 3900:
1.295 www 3901:
1.81 albertel 3902: ###############################################################
1.61 www 3903: sub plainname {
1.226 albertel 3904: my ($uname,$udom,$first)=@_;
1.537 albertel 3905: return if (!defined($uname) || !defined($udom));
1.295 www 3906: my %names=&getnames($uname,$udom);
1.226 albertel 3907: my $name=&Apache::lonnet::format_name($names{'firstname'},
3908: $names{'middlename'},
3909: $names{'lastname'},
3910: $names{'generation'},$first);
3911: $name=~s/^\s+//;
1.62 www 3912: $name=~s/\s+$//;
3913: $name=~s/\s+/ /g;
1.353 albertel 3914: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3915: return $name;
1.61 www 3916: }
1.66 www 3917:
3918: # -------------------------------------------------------------------- Nickname
1.81 albertel 3919: =pod
3920:
1.648 raeburn 3921: =item * &nickname($uname,$udom)
1.81 albertel 3922:
3923: Gets a users name and returns it as a string as
3924:
3925: ""nickname""
1.66 www 3926:
1.81 albertel 3927: if the user has a nickname or
3928:
3929: "first middle last generation"
3930:
3931: if the user does not
3932:
3933: =cut
1.66 www 3934:
3935: sub nickname {
3936: my ($uname,$udom)=@_;
1.537 albertel 3937: return if (!defined($uname) || !defined($udom));
1.295 www 3938: my %names=&getnames($uname,$udom);
1.68 albertel 3939: my $name=$names{'nickname'};
1.66 www 3940: if ($name) {
3941: $name='"'.$name.'"';
3942: } else {
3943: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3944: $names{'lastname'}.' '.$names{'generation'};
3945: $name=~s/\s+$//;
3946: $name=~s/\s+/ /g;
3947: }
3948: return $name;
3949: }
3950:
1.295 www 3951: sub getnames {
3952: my ($uname,$udom)=@_;
1.537 albertel 3953: return if (!defined($uname) || !defined($udom));
1.433 albertel 3954: if ($udom eq 'public' && $uname eq 'public') {
3955: return ('lastname' => &mt('Public'));
3956: }
1.295 www 3957: my $id=$uname.':'.$udom;
3958: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3959: if ($cached) {
3960: return %{$names};
3961: } else {
3962: my %loadnames=&Apache::lonnet::get('environment',
3963: ['firstname','middlename','lastname','generation','nickname'],
3964: $udom,$uname);
3965: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3966: return %loadnames;
3967: }
3968: }
1.61 www 3969:
1.542 raeburn 3970: # -------------------------------------------------------------------- getemails
1.648 raeburn 3971:
1.542 raeburn 3972: =pod
3973:
1.648 raeburn 3974: =item * &getemails($uname,$udom)
1.542 raeburn 3975:
3976: Gets a user's email information and returns it as a hash with keys:
3977: notification, critnotification, permanentemail
3978:
3979: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3980: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3981:
1.648 raeburn 3982:
1.542 raeburn 3983: =cut
3984:
1.648 raeburn 3985:
1.466 albertel 3986: sub getemails {
3987: my ($uname,$udom)=@_;
3988: if ($udom eq 'public' && $uname eq 'public') {
3989: return;
3990: }
1.467 www 3991: if (!$udom) { $udom=$env{'user.domain'}; }
3992: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3993: my $id=$uname.':'.$udom;
3994: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3995: if ($cached) {
3996: return %{$names};
3997: } else {
3998: my %loadnames=&Apache::lonnet::get('environment',
3999: ['notification','critnotification',
4000: 'permanentemail'],
4001: $udom,$uname);
4002: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4003: return %loadnames;
4004: }
4005: }
4006:
1.551 albertel 4007: sub flush_email_cache {
4008: my ($uname,$udom)=@_;
4009: if (!$udom) { $udom =$env{'user.domain'}; }
4010: if (!$uname) { $uname=$env{'user.name'}; }
4011: return if ($udom eq 'public' && $uname eq 'public');
4012: my $id=$uname.':'.$udom;
4013: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4014: }
4015:
1.728 raeburn 4016: # -------------------------------------------------------------------- getlangs
4017:
4018: =pod
4019:
4020: =item * &getlangs($uname,$udom)
4021:
4022: Gets a user's language preference and returns it as a hash with key:
4023: language.
4024:
4025: =cut
4026:
4027:
4028: sub getlangs {
4029: my ($uname,$udom) = @_;
4030: if (!$udom) { $udom =$env{'user.domain'}; }
4031: if (!$uname) { $uname=$env{'user.name'}; }
4032: my $id=$uname.':'.$udom;
4033: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4034: if ($cached) {
4035: return %{$langs};
4036: } else {
4037: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4038: $udom,$uname);
4039: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4040: return %loadlangs;
4041: }
4042: }
4043:
4044: sub flush_langs_cache {
4045: my ($uname,$udom)=@_;
4046: if (!$udom) { $udom =$env{'user.domain'}; }
4047: if (!$uname) { $uname=$env{'user.name'}; }
4048: return if ($udom eq 'public' && $uname eq 'public');
4049: my $id=$uname.':'.$udom;
4050: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4051: }
4052:
1.61 www 4053: # ------------------------------------------------------------------ Screenname
1.81 albertel 4054:
4055: =pod
4056:
1.648 raeburn 4057: =item * &screenname($uname,$udom)
1.81 albertel 4058:
4059: Gets a users screenname and returns it as a string
4060:
4061: =cut
1.61 www 4062:
4063: sub screenname {
4064: my ($uname,$udom)=@_;
1.258 albertel 4065: if ($uname eq $env{'user.name'} &&
4066: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4067: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4068: return $names{'screenname'};
1.62 www 4069: }
4070:
1.212 albertel 4071:
1.802 bisitz 4072: # ------------------------------------------------------------- Confirm Wrapper
4073: =pod
4074:
1.1142 raeburn 4075: =item * &confirmwrapper($message)
1.802 bisitz 4076:
4077: Wrap messages about completion of operation in box
4078:
4079: =cut
4080:
4081: sub confirmwrapper {
4082: my ($message)=@_;
4083: if ($message) {
4084: return "\n".'<div class="LC_confirm_box">'."\n"
4085: .$message."\n"
4086: .'</div>'."\n";
4087: } else {
4088: return $message;
4089: }
4090: }
4091:
1.62 www 4092: # ------------------------------------------------------------- Message Wrapper
4093:
4094: sub messagewrapper {
1.369 www 4095: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4096: return
1.441 albertel 4097: '<a href="/adm/email?compose=individual&'.
4098: 'recname='.$username.'&recdom='.$domain.
4099: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4100: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4101: }
1.802 bisitz 4102:
1.74 www 4103: # --------------------------------------------------------------- Notes Wrapper
4104:
4105: sub noteswrapper {
4106: my ($link,$un,$do)=@_;
4107: return
1.896 amueller 4108: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4109: }
1.802 bisitz 4110:
1.62 www 4111: # ------------------------------------------------------------- Aboutme Wrapper
4112:
4113: sub aboutmewrapper {
1.1070 raeburn 4114: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4115: if (!defined($username) && !defined($domain)) {
4116: return;
4117: }
1.1096 raeburn 4118: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4119: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4120: }
4121:
4122: # ------------------------------------------------------------ Syllabus Wrapper
4123:
4124: sub syllabuswrapper {
1.707 bisitz 4125: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4126: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4127: }
1.14 harris41 4128:
1.802 bisitz 4129: # -----------------------------------------------------------------------------
4130:
1.208 matthew 4131: sub track_student_link {
1.887 raeburn 4132: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4133: my $link ="/adm/trackstudent?";
1.208 matthew 4134: my $title = 'View recent activity';
4135: if (defined($sname) && $sname !~ /^\s*$/ &&
4136: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4137: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4138: $title .= ' of this student';
1.268 albertel 4139: }
1.208 matthew 4140: if (defined($target) && $target !~ /^\s*$/) {
4141: $target = qq{target="$target"};
4142: } else {
4143: $target = '';
4144: }
1.268 albertel 4145: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4146: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4147: $title = &mt($title);
4148: $linktext = &mt($linktext);
1.448 albertel 4149: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4150: &help_open_topic('View_recent_activity');
1.208 matthew 4151: }
4152:
1.781 raeburn 4153: sub slot_reservations_link {
4154: my ($linktext,$sname,$sdom,$target) = @_;
4155: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4156: my $title = 'View slot reservation history';
4157: if (defined($sname) && $sname !~ /^\s*$/ &&
4158: defined($sdom) && $sdom !~ /^\s*$/) {
4159: $link .= "&uname=$sname&udom=$sdom";
4160: $title .= ' of this student';
4161: }
4162: if (defined($target) && $target !~ /^\s*$/) {
4163: $target = qq{target="$target"};
4164: } else {
4165: $target = '';
4166: }
4167: $title = &mt($title);
4168: $linktext = &mt($linktext);
4169: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4170: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4171:
4172: }
4173:
1.508 www 4174: # ===================================================== Display a student photo
4175:
4176:
1.509 albertel 4177: sub student_image_tag {
1.508 www 4178: my ($domain,$user)=@_;
4179: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4180: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4181: return '<img src="'.$imgsrc.'" align="right" />';
4182: } else {
4183: return '';
4184: }
4185: }
4186:
1.112 bowersj2 4187: =pod
4188:
4189: =back
4190:
4191: =head1 Access .tab File Data
4192:
4193: =over 4
4194:
1.648 raeburn 4195: =item * &languageids()
1.112 bowersj2 4196:
4197: returns list of all language ids
4198:
4199: =cut
4200:
1.14 harris41 4201: sub languageids {
1.16 harris41 4202: return sort(keys(%language));
1.14 harris41 4203: }
4204:
1.112 bowersj2 4205: =pod
4206:
1.648 raeburn 4207: =item * &languagedescription()
1.112 bowersj2 4208:
4209: returns description of a specified language id
4210:
4211: =cut
4212:
1.14 harris41 4213: sub languagedescription {
1.125 www 4214: my $code=shift;
4215: return ($supported_language{$code}?'* ':'').
4216: $language{$code}.
1.126 www 4217: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4218: }
4219:
1.1048 foxr 4220: =pod
4221:
4222: =item * &plainlanguagedescription
4223:
4224: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4225: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4226:
4227: =cut
4228:
1.145 www 4229: sub plainlanguagedescription {
4230: my $code=shift;
4231: return $language{$code};
4232: }
4233:
1.1048 foxr 4234: =pod
4235:
4236: =item * &supportedlanguagecode
4237:
4238: Returns the supported language code (e.g. sptutf maps to pt) given a language
4239: code.
4240:
4241: =cut
4242:
1.145 www 4243: sub supportedlanguagecode {
4244: my $code=shift;
4245: return $supported_language{$code};
1.97 www 4246: }
4247:
1.112 bowersj2 4248: =pod
4249:
1.1048 foxr 4250: =item * &latexlanguage()
4251:
4252: Given a language key code returns the correspondnig language to use
4253: to select the correct hyphenation on LaTeX printouts. This is undef if there
4254: is no supported hyphenation for the language code.
4255:
4256: =cut
4257:
4258: sub latexlanguage {
4259: my $code = shift;
4260: return $latex_language{$code};
4261: }
4262:
4263: =pod
4264:
4265: =item * &latexhyphenation()
4266:
4267: Same as above but what's supplied is the language as it might be stored
4268: in the metadata.
4269:
4270: =cut
4271:
4272: sub latexhyphenation {
4273: my $key = shift;
4274: return $latex_language_bykey{$key};
4275: }
4276:
4277: =pod
4278:
1.648 raeburn 4279: =item * ©rightids()
1.112 bowersj2 4280:
4281: returns list of all copyrights
4282:
4283: =cut
4284:
4285: sub copyrightids {
4286: return sort(keys(%cprtag));
4287: }
4288:
4289: =pod
4290:
1.648 raeburn 4291: =item * ©rightdescription()
1.112 bowersj2 4292:
4293: returns description of a specified copyright id
4294:
4295: =cut
4296:
4297: sub copyrightdescription {
1.166 www 4298: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4299: }
1.197 matthew 4300:
4301: =pod
4302:
1.648 raeburn 4303: =item * &source_copyrightids()
1.192 taceyjo1 4304:
4305: returns list of all source copyrights
4306:
4307: =cut
4308:
4309: sub source_copyrightids {
4310: return sort(keys(%scprtag));
4311: }
4312:
4313: =pod
4314:
1.648 raeburn 4315: =item * &source_copyrightdescription()
1.192 taceyjo1 4316:
4317: returns description of a specified source copyright id
4318:
4319: =cut
4320:
4321: sub source_copyrightdescription {
4322: return &mt($scprtag{shift(@_)});
4323: }
1.112 bowersj2 4324:
4325: =pod
4326:
1.648 raeburn 4327: =item * &filecategories()
1.112 bowersj2 4328:
4329: returns list of all file categories
4330:
4331: =cut
4332:
4333: sub filecategories {
4334: return sort(keys(%category_extensions));
4335: }
4336:
4337: =pod
4338:
1.648 raeburn 4339: =item * &filecategorytypes()
1.112 bowersj2 4340:
4341: returns list of file types belonging to a given file
4342: category
4343:
4344: =cut
4345:
4346: sub filecategorytypes {
1.356 albertel 4347: my ($cat) = @_;
1.1248 raeburn 4348: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4349: return @{$category_extensions{lc($cat)}};
4350: } else {
4351: return ();
4352: }
1.112 bowersj2 4353: }
4354:
4355: =pod
4356:
1.648 raeburn 4357: =item * &fileembstyle()
1.112 bowersj2 4358:
4359: returns embedding style for a specified file type
4360:
4361: =cut
4362:
4363: sub fileembstyle {
4364: return $fe{lc(shift(@_))};
1.169 www 4365: }
4366:
1.351 www 4367: sub filemimetype {
4368: return $fm{lc(shift(@_))};
4369: }
4370:
1.169 www 4371:
4372: sub filecategoryselect {
4373: my ($name,$value)=@_;
1.189 matthew 4374: return &select_form($value,$name,
1.970 raeburn 4375: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4376: }
4377:
4378: =pod
4379:
1.648 raeburn 4380: =item * &filedescription()
1.112 bowersj2 4381:
4382: returns description for a specified file type
4383:
4384: =cut
4385:
4386: sub filedescription {
1.188 matthew 4387: my $file_description = $fd{lc(shift())};
4388: $file_description =~ s:([\[\]]):~$1:g;
4389: return &mt($file_description);
1.112 bowersj2 4390: }
4391:
4392: =pod
4393:
1.648 raeburn 4394: =item * &filedescriptionex()
1.112 bowersj2 4395:
4396: returns description for a specified file type with
4397: extra formatting
4398:
4399: =cut
4400:
4401: sub filedescriptionex {
4402: my $ex=shift;
1.188 matthew 4403: my $file_description = $fd{lc($ex)};
4404: $file_description =~ s:([\[\]]):~$1:g;
4405: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4406: }
4407:
4408: # End of .tab access
4409: =pod
4410:
4411: =back
4412:
4413: =cut
4414:
4415: # ------------------------------------------------------------------ File Types
4416: sub fileextensions {
4417: return sort(keys(%fe));
4418: }
4419:
1.97 www 4420: # ----------------------------------------------------------- Display Languages
4421: # returns a hash with all desired display languages
4422: #
4423:
4424: sub display_languages {
4425: my %languages=();
1.695 raeburn 4426: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4427: $languages{$lang}=1;
1.97 www 4428: }
4429: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4430: if ($env{'form.displaylanguage'}) {
1.356 albertel 4431: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4432: $languages{$lang}=1;
1.97 www 4433: }
4434: }
4435: return %languages;
1.14 harris41 4436: }
4437:
1.582 albertel 4438: sub languages {
4439: my ($possible_langs) = @_;
1.695 raeburn 4440: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4441: if (!ref($possible_langs)) {
4442: if( wantarray ) {
4443: return @preferred_langs;
4444: } else {
4445: return $preferred_langs[0];
4446: }
4447: }
4448: my %possibilities = map { $_ => 1 } (@$possible_langs);
4449: my @preferred_possibilities;
4450: foreach my $preferred_lang (@preferred_langs) {
4451: if (exists($possibilities{$preferred_lang})) {
4452: push(@preferred_possibilities, $preferred_lang);
4453: }
4454: }
4455: if( wantarray ) {
4456: return @preferred_possibilities;
4457: }
4458: return $preferred_possibilities[0];
4459: }
4460:
1.742 raeburn 4461: sub user_lang {
4462: my ($touname,$toudom,$fromcid) = @_;
4463: my @userlangs;
4464: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4465: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4466: $env{'course.'.$fromcid.'.languages'}));
4467: } else {
4468: my %langhash = &getlangs($touname,$toudom);
4469: if ($langhash{'languages'} ne '') {
4470: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4471: } else {
4472: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4473: if ($domdefs{'lang_def'} ne '') {
4474: @userlangs = ($domdefs{'lang_def'});
4475: }
4476: }
4477: }
4478: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4479: my $user_lh = Apache::localize->get_handle(@languages);
4480: return $user_lh;
4481: }
4482:
4483:
1.112 bowersj2 4484: ###############################################################
4485: ## Student Answer Attempts ##
4486: ###############################################################
4487:
4488: =pod
4489:
4490: =head1 Alternate Problem Views
4491:
4492: =over 4
4493:
1.648 raeburn 4494: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4495: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4496:
4497: Return string with previous attempt on problem. Arguments:
4498:
4499: =over 4
4500:
4501: =item * $symb: Problem, including path
4502:
4503: =item * $username: username of the desired student
4504:
4505: =item * $domain: domain of the desired student
1.14 harris41 4506:
1.112 bowersj2 4507: =item * $course: Course ID
1.14 harris41 4508:
1.112 bowersj2 4509: =item * $getattempt: Leave blank for all attempts, otherwise put
4510: something
1.14 harris41 4511:
1.112 bowersj2 4512: =item * $regexp: if string matches this regexp, the string will be
4513: sent to $gradesub
1.14 harris41 4514:
1.112 bowersj2 4515: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4516:
1.1199 raeburn 4517: =item * $usec: section of the desired student
4518:
4519: =item * $identifier: counter for student (multiple students one problem) or
4520: problem (one student; whole sequence).
4521:
1.112 bowersj2 4522: =back
1.14 harris41 4523:
1.112 bowersj2 4524: The output string is a table containing all desired attempts, if any.
1.16 harris41 4525:
1.112 bowersj2 4526: =cut
1.1 albertel 4527:
4528: sub get_previous_attempt {
1.1199 raeburn 4529: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4530: my $prevattempts='';
1.43 ng 4531: no strict 'refs';
1.1 albertel 4532: if ($symb) {
1.3 albertel 4533: my (%returnhash)=
4534: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4535: if ($returnhash{'version'}) {
4536: my %lasthash=();
4537: my $version;
4538: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4539: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4540: if ($key =~ /\.rawrndseed$/) {
4541: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4542: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4543: } else {
4544: $lasthash{$key}=$returnhash{$version.':'.$key};
4545: }
1.19 harris41 4546: }
1.1 albertel 4547: }
1.596 albertel 4548: $prevattempts=&start_data_table().&start_data_table_header_row();
4549: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4550: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4551: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4552: foreach my $key (sort(keys(%lasthash))) {
4553: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4554: if ($#parts > 0) {
1.31 albertel 4555: my $data=$parts[-1];
1.989 raeburn 4556: next if ($data eq 'foilorder');
1.31 albertel 4557: pop(@parts);
1.1010 www 4558: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4559: if ($data eq 'type') {
4560: unless ($showsurv) {
4561: my $id = join(',',@parts);
4562: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4563: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4564: $lasthidden{$ign.'.'.$id} = 1;
4565: }
1.945 raeburn 4566: }
1.1199 raeburn 4567: if ($identifier ne '') {
4568: my $id = join(',',@parts);
4569: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4570: $domain,$username,$usec,undef,$course) =~ /^no/) {
4571: $hidestatus{$ign.'.'.$id} = 1;
4572: }
4573: }
4574: } elsif ($data eq 'regrader') {
4575: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4576: my $id = join(',',@parts);
4577: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4578: }
1.1010 www 4579: }
1.31 albertel 4580: } else {
1.41 ng 4581: if ($#parts == 0) {
4582: $prevattempts.='<th>'.$parts[0].'</th>';
4583: } else {
4584: $prevattempts.='<th>'.$ign.'</th>';
4585: }
1.31 albertel 4586: }
1.16 harris41 4587: }
1.596 albertel 4588: $prevattempts.=&end_data_table_header_row();
1.40 ng 4589: if ($getattempt eq '') {
1.1199 raeburn 4590: my (%solved,%resets,%probstatus);
1.1200 raeburn 4591: if (($identifier ne '') && (keys(%regraded) > 0)) {
4592: for ($version=1;$version<=$returnhash{'version'};$version++) {
4593: foreach my $id (keys(%regraded)) {
4594: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4595: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4596: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4597: push(@{$resets{$id}},$version);
1.1199 raeburn 4598: }
4599: }
4600: }
1.1200 raeburn 4601: }
4602: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4603: my (@hidden,@unsolved);
1.945 raeburn 4604: if (%typeparts) {
4605: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4606: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4607: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4608: push(@hidden,$id);
1.1199 raeburn 4609: } elsif ($identifier ne '') {
4610: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4611: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4612: ($hidestatus{$id})) {
1.1200 raeburn 4613: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4614: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4615: push(@{$solved{$id}},$version);
4616: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4617: (ref($solved{$id}) eq 'ARRAY')) {
4618: my $skip;
4619: if (ref($resets{$id}) eq 'ARRAY') {
4620: foreach my $reset (@{$resets{$id}}) {
4621: if ($reset > $solved{$id}[-1]) {
4622: $skip=1;
4623: last;
4624: }
4625: }
4626: }
4627: unless ($skip) {
4628: my ($ign,$partslist) = split(/\./,$id,2);
4629: push(@unsolved,$partslist);
4630: }
4631: }
4632: }
1.945 raeburn 4633: }
4634: }
4635: }
4636: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4637: '<td>'.&mt('Transaction [_1]',$version);
4638: if (@unsolved) {
4639: $prevattempts .= '<span class="LC_nobreak"><label>'.
4640: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4641: &mt('Hide').'</label></span>';
4642: }
4643: $prevattempts .= '</td>';
1.945 raeburn 4644: if (@hidden) {
4645: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4646: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4647: my $hide;
4648: foreach my $id (@hidden) {
4649: if ($key =~ /^\Q$id\E/) {
4650: $hide = 1;
4651: last;
4652: }
4653: }
4654: if ($hide) {
4655: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4656: if (($data eq 'award') || ($data eq 'awarddetail')) {
4657: my $value = &format_previous_attempt_value($key,
4658: $returnhash{$version.':'.$key});
1.1173 kruse 4659: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4660: } else {
4661: $prevattempts.='<td> </td>';
4662: }
4663: } else {
4664: if ($key =~ /\./) {
1.1212 raeburn 4665: my $value = $returnhash{$version.':'.$key};
4666: if ($key =~ /\.rndseed$/) {
4667: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4668: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4669: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4670: }
4671: }
4672: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4673: ' </td>';
1.945 raeburn 4674: } else {
4675: $prevattempts.='<td> </td>';
4676: }
4677: }
4678: }
4679: } else {
4680: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4681: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4682: my $value = $returnhash{$version.':'.$key};
4683: if ($key =~ /\.rndseed$/) {
4684: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4685: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4686: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4687: }
4688: }
4689: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4690: ' </td>';
1.945 raeburn 4691: }
4692: }
4693: $prevattempts.=&end_data_table_row();
1.40 ng 4694: }
1.1 albertel 4695: }
1.945 raeburn 4696: my @currhidden = keys(%lasthidden);
1.596 albertel 4697: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4698: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4699: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4700: if (%typeparts) {
4701: my $hidden;
4702: foreach my $id (@currhidden) {
4703: if ($key =~ /^\Q$id\E/) {
4704: $hidden = 1;
4705: last;
4706: }
4707: }
4708: if ($hidden) {
4709: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4710: if (($data eq 'award') || ($data eq 'awarddetail')) {
4711: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4712: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4713: $value = &$gradesub($value);
4714: }
1.1173 kruse 4715: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4716: } else {
4717: $prevattempts.='<td> </td>';
4718: }
4719: } else {
4720: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4721: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4722: $value = &$gradesub($value);
4723: }
1.1173 kruse 4724: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4725: }
4726: } else {
4727: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4728: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4729: $value = &$gradesub($value);
4730: }
1.1173 kruse 4731: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4732: }
1.16 harris41 4733: }
1.596 albertel 4734: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4735: } else {
1.1305 raeburn 4736: my $msg;
4737: if ($symb =~ /ext\.tool$/) {
4738: $msg = &mt('No grade passed back.');
4739: } else {
4740: $msg = &mt('Nothing submitted - no attempts.');
4741: }
1.596 albertel 4742: $prevattempts=
4743: &start_data_table().&start_data_table_row().
1.1305 raeburn 4744: '<td>'.$msg.'</td>'.
1.596 albertel 4745: &end_data_table_row().&end_data_table();
1.1 albertel 4746: }
4747: } else {
1.596 albertel 4748: $prevattempts=
4749: &start_data_table().&start_data_table_row().
4750: '<td>'.&mt('No data.').'</td>'.
4751: &end_data_table_row().&end_data_table();
1.1 albertel 4752: }
1.10 albertel 4753: }
4754:
1.581 albertel 4755: sub format_previous_attempt_value {
4756: my ($key,$value) = @_;
1.1011 www 4757: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4758: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4759: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4760: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4761: } elsif ($key =~ /answerstring$/) {
4762: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4763: my @answer = %answers;
4764: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4765: my @anskeys = sort(keys(%answers));
4766: if (@anskeys == 1) {
4767: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4768: if ($answer =~ m{\0}) {
4769: $answer =~ s{\0}{,}g;
1.988 raeburn 4770: }
4771: my $tag_internal_answer_name = 'INTERNAL';
4772: if ($anskeys[0] eq $tag_internal_answer_name) {
4773: $value = $answer;
4774: } else {
4775: $value = $anskeys[0].'='.$answer;
4776: }
4777: } else {
4778: foreach my $ans (@anskeys) {
4779: my $answer = $answers{$ans};
1.1001 raeburn 4780: if ($answer =~ m{\0}) {
4781: $answer =~ s{\0}{,}g;
1.988 raeburn 4782: }
4783: $value .= $ans.'='.$answer.'<br />';;
4784: }
4785: }
1.581 albertel 4786: } else {
1.1173 kruse 4787: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4788: }
4789: return $value;
4790: }
4791:
4792:
1.107 albertel 4793: sub relative_to_absolute {
4794: my ($url,$output)=@_;
4795: my $parser=HTML::TokeParser->new(\$output);
4796: my $token;
4797: my $thisdir=$url;
4798: my @rlinks=();
4799: while ($token=$parser->get_token) {
4800: if ($token->[0] eq 'S') {
4801: if ($token->[1] eq 'a') {
4802: if ($token->[2]->{'href'}) {
4803: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4804: }
4805: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4806: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4807: } elsif ($token->[1] eq 'base') {
4808: $thisdir=$token->[2]->{'href'};
4809: }
4810: }
4811: }
4812: $thisdir=~s-/[^/]*$--;
1.356 albertel 4813: foreach my $link (@rlinks) {
1.726 raeburn 4814: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4815: ($link=~/^\//) ||
4816: ($link=~/^javascript:/i) ||
4817: ($link=~/^mailto:/i) ||
4818: ($link=~/^\#/)) {
4819: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4820: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4821: }
4822: }
4823: # -------------------------------------------------- Deal with Applet codebases
4824: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4825: return $output;
4826: }
4827:
1.112 bowersj2 4828: =pod
4829:
1.648 raeburn 4830: =item * &get_student_view()
1.112 bowersj2 4831:
4832: show a snapshot of what student was looking at
4833:
4834: =cut
4835:
1.10 albertel 4836: sub get_student_view {
1.186 albertel 4837: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4838: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4839: my (%form);
1.10 albertel 4840: my @elements=('symb','courseid','domain','username');
4841: foreach my $element (@elements) {
1.186 albertel 4842: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4843: }
1.186 albertel 4844: if (defined($moreenv)) {
4845: %form=(%form,%{$moreenv});
4846: }
1.236 albertel 4847: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4848: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4849: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4850: $feedurl =~ s{^/adm/wrapper}{};
4851: }
1.650 www 4852: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4853: $userview=~s/\<body[^\>]*\>//gi;
4854: $userview=~s/\<\/body\>//gi;
4855: $userview=~s/\<html\>//gi;
4856: $userview=~s/\<\/html\>//gi;
4857: $userview=~s/\<head\>//gi;
4858: $userview=~s/\<\/head\>//gi;
4859: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4860: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4861: if (wantarray) {
4862: return ($userview,$response);
4863: } else {
4864: return $userview;
4865: }
4866: }
4867:
4868: sub get_student_view_with_retries {
4869: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4870:
4871: my $ok = 0; # True if we got a good response.
4872: my $content;
4873: my $response;
4874:
4875: # Try to get the student_view done. within the retries count:
4876:
4877: do {
4878: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4879: $ok = $response->is_success;
4880: if (!$ok) {
4881: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4882: }
4883: $retries--;
4884: } while (!$ok && ($retries > 0));
4885:
4886: if (!$ok) {
4887: $content = ''; # On error return an empty content.
4888: }
1.651 www 4889: if (wantarray) {
4890: return ($content, $response);
4891: } else {
4892: return $content;
4893: }
1.11 albertel 4894: }
4895:
1.112 bowersj2 4896: =pod
4897:
1.648 raeburn 4898: =item * &get_student_answers()
1.112 bowersj2 4899:
4900: show a snapshot of how student was answering problem
4901:
4902: =cut
4903:
1.11 albertel 4904: sub get_student_answers {
1.100 sakharuk 4905: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4906: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4907: my (%moreenv);
1.11 albertel 4908: my @elements=('symb','courseid','domain','username');
4909: foreach my $element (@elements) {
1.186 albertel 4910: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4911: }
1.186 albertel 4912: $moreenv{'grade_target'}='answer';
4913: %moreenv=(%form,%moreenv);
1.497 raeburn 4914: $feedurl = &Apache::lonnet::clutter($feedurl);
4915: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4916: return $userview;
1.1 albertel 4917: }
1.116 albertel 4918:
4919: =pod
4920:
4921: =item * &submlink()
4922:
1.242 albertel 4923: Inputs: $text $uname $udom $symb $target
1.116 albertel 4924:
4925: Returns: A link to grades.pm such as to see the SUBM view of a student
4926:
4927: =cut
4928:
4929: ###############################################
4930: sub submlink {
1.242 albertel 4931: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4932: if (!($uname && $udom)) {
4933: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4934: &Apache::lonnet::whichuser($symb);
1.116 albertel 4935: if (!$symb) { $symb=$cursymb; }
4936: }
1.254 matthew 4937: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4938: $symb=&escape($symb);
1.960 bisitz 4939: if ($target) { $target=" target=\"$target\""; }
4940: return
4941: '<a href="/adm/grades?command=submission'.
4942: '&symb='.$symb.
4943: '&student='.$uname.
4944: '&userdom='.$udom.'"'.
4945: $target.'>'.$text.'</a>';
1.242 albertel 4946: }
4947: ##############################################
4948:
4949: =pod
4950:
4951: =item * &pgrdlink()
4952:
4953: Inputs: $text $uname $udom $symb $target
4954:
4955: Returns: A link to grades.pm such as to see the PGRD view of a student
4956:
4957: =cut
4958:
4959: ###############################################
4960: sub pgrdlink {
4961: my $link=&submlink(@_);
4962: $link=~s/(&command=submission)/$1&showgrading=yes/;
4963: return $link;
4964: }
4965: ##############################################
4966:
4967: =pod
4968:
4969: =item * &pprmlink()
4970:
4971: Inputs: $text $uname $udom $symb $target
4972:
4973: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4974: student and a specific resource
1.242 albertel 4975:
4976: =cut
4977:
4978: ###############################################
4979: sub pprmlink {
4980: my ($text,$uname,$udom,$symb,$target)=@_;
4981: if (!($uname && $udom)) {
4982: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4983: &Apache::lonnet::whichuser($symb);
1.242 albertel 4984: if (!$symb) { $symb=$cursymb; }
4985: }
1.254 matthew 4986: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4987: $symb=&escape($symb);
1.242 albertel 4988: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4989: return '<a href="/adm/parmset?command=set&'.
4990: 'symb='.$symb.'&uname='.$uname.
4991: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4992: }
4993: ##############################################
1.37 matthew 4994:
1.112 bowersj2 4995: =pod
4996:
4997: =back
4998:
4999: =cut
5000:
1.37 matthew 5001: ###############################################
1.51 www 5002:
5003:
5004: sub timehash {
1.687 raeburn 5005: my ($thistime) = @_;
5006: my $timezone = &Apache::lonlocal::gettimezone();
5007: my $dt = DateTime->from_epoch(epoch => $thistime)
5008: ->set_time_zone($timezone);
5009: my $wday = $dt->day_of_week();
5010: if ($wday == 7) { $wday = 0; }
5011: return ( 'second' => $dt->second(),
5012: 'minute' => $dt->minute(),
5013: 'hour' => $dt->hour(),
5014: 'day' => $dt->day_of_month(),
5015: 'month' => $dt->month(),
5016: 'year' => $dt->year(),
5017: 'weekday' => $wday,
5018: 'dayyear' => $dt->day_of_year(),
5019: 'dlsav' => $dt->is_dst() );
1.51 www 5020: }
5021:
1.370 www 5022: sub utc_string {
5023: my ($date)=@_;
1.371 www 5024: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5025: }
5026:
1.51 www 5027: sub maketime {
5028: my %th=@_;
1.687 raeburn 5029: my ($epoch_time,$timezone,$dt);
5030: $timezone = &Apache::lonlocal::gettimezone();
5031: eval {
5032: $dt = DateTime->new( year => $th{'year'},
5033: month => $th{'month'},
5034: day => $th{'day'},
5035: hour => $th{'hour'},
5036: minute => $th{'minute'},
5037: second => $th{'second'},
5038: time_zone => $timezone,
5039: );
5040: };
5041: if (!$@) {
5042: $epoch_time = $dt->epoch;
5043: if ($epoch_time) {
5044: return $epoch_time;
5045: }
5046: }
1.51 www 5047: return POSIX::mktime(
5048: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5049: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5050: }
5051:
5052: #########################################
1.51 www 5053:
5054: sub findallcourses {
1.482 raeburn 5055: my ($roles,$uname,$udom) = @_;
1.355 albertel 5056: my %roles;
5057: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5058: my %courses;
1.51 www 5059: my $now=time;
1.482 raeburn 5060: if (!defined($uname)) {
5061: $uname = $env{'user.name'};
5062: }
5063: if (!defined($udom)) {
5064: $udom = $env{'user.domain'};
5065: }
5066: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5067: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5068: if (!%roles) {
5069: %roles = (
5070: cc => 1,
1.907 raeburn 5071: co => 1,
1.482 raeburn 5072: in => 1,
5073: ep => 1,
5074: ta => 1,
5075: cr => 1,
5076: st => 1,
5077: );
5078: }
5079: foreach my $entry (keys(%roleshash)) {
5080: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5081: if ($trole =~ /^cr/) {
5082: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5083: } else {
5084: next if (!exists($roles{$trole}));
5085: }
5086: if ($tend) {
5087: next if ($tend < $now);
5088: }
5089: if ($tstart) {
5090: next if ($tstart > $now);
5091: }
1.1058 raeburn 5092: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5093: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5094: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5095: if ($secpart eq '') {
5096: ($cnum,$role) = split(/_/,$cnumpart);
5097: $sec = 'none';
1.1058 raeburn 5098: $value .= $cnum.'/';
1.482 raeburn 5099: } else {
5100: $cnum = $cnumpart;
5101: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5102: $value .= $cnum.'/'.$sec;
5103: }
5104: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5105: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5106: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5107: }
5108: } else {
5109: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5110: }
1.482 raeburn 5111: }
5112: } else {
5113: foreach my $key (keys(%env)) {
1.483 albertel 5114: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5115: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5116: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5117: next if ($role eq 'ca' || $role eq 'aa');
5118: next if (%roles && !exists($roles{$role}));
5119: my ($starttime,$endtime)=split(/\./,$env{$key});
5120: my $active=1;
5121: if ($starttime) {
5122: if ($now<$starttime) { $active=0; }
5123: }
5124: if ($endtime) {
5125: if ($now>$endtime) { $active=0; }
5126: }
5127: if ($active) {
1.1058 raeburn 5128: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5129: if ($sec eq '') {
5130: $sec = 'none';
1.1058 raeburn 5131: } else {
5132: $value .= $sec;
5133: }
5134: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5135: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5136: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5137: }
5138: } else {
5139: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5140: }
1.474 raeburn 5141: }
5142: }
1.51 www 5143: }
5144: }
1.474 raeburn 5145: return %courses;
1.51 www 5146: }
1.37 matthew 5147:
1.54 www 5148: ###############################################
1.474 raeburn 5149:
5150: sub blockcheck {
1.1189 raeburn 5151: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5152:
1.1189 raeburn 5153: if (defined($udom) && defined($uname)) {
5154: # If uname and udom are for a course, check for blocks in the course.
5155: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5156: my ($startblock,$endblock,$triggerblock) =
5157: &get_blocks($setters,$activity,$udom,$uname,$url);
5158: return ($startblock,$endblock,$triggerblock);
5159: }
5160: } else {
1.490 raeburn 5161: $udom = $env{'user.domain'};
5162: $uname = $env{'user.name'};
5163: }
5164:
1.502 raeburn 5165: my $startblock = 0;
5166: my $endblock = 0;
1.1062 raeburn 5167: my $triggerblock = '';
1.482 raeburn 5168: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5169:
1.490 raeburn 5170: # If uname is for a user, and activity is course-specific, i.e.,
5171: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5172:
1.490 raeburn 5173: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5174: $activity eq 'groups' || $activity eq 'printout' ||
5175: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5176: ($env{'request.course.id'})) {
1.490 raeburn 5177: foreach my $key (keys(%live_courses)) {
5178: if ($key ne $env{'request.course.id'}) {
5179: delete($live_courses{$key});
5180: }
5181: }
5182: }
5183:
5184: my $otheruser = 0;
5185: my %own_courses;
5186: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5187: # Resource belongs to user other than current user.
5188: $otheruser = 1;
5189: # Gather courses for current user
5190: %own_courses =
5191: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5192: }
5193:
5194: # Gather active course roles - course coordinator, instructor,
5195: # exam proctor, ta, student, or custom role.
1.474 raeburn 5196:
5197: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5198: my ($cdom,$cnum);
5199: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5200: $cdom = $env{'course.'.$course.'.domain'};
5201: $cnum = $env{'course.'.$course.'.num'};
5202: } else {
1.490 raeburn 5203: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5204: }
5205: my $no_ownblock = 0;
5206: my $no_userblock = 0;
1.533 raeburn 5207: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5208: # Check if current user has 'evb' priv for this
5209: if (defined($own_courses{$course})) {
5210: foreach my $sec (keys(%{$own_courses{$course}})) {
5211: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5212: if ($sec ne 'none') {
5213: $checkrole .= '/'.$sec;
5214: }
5215: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5216: $no_ownblock = 1;
5217: last;
5218: }
5219: }
5220: }
5221: # if they have 'evb' priv and are currently not playing student
5222: next if (($no_ownblock) &&
5223: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5224: }
1.474 raeburn 5225: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5226: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5227: if ($sec ne 'none') {
1.482 raeburn 5228: $checkrole .= '/'.$sec;
1.474 raeburn 5229: }
1.490 raeburn 5230: if ($otheruser) {
5231: # Resource belongs to user other than current user.
5232: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5233: my (%allroles,%userroles);
5234: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5235: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5236: my ($trole,$tdom,$tnum,$tsec);
5237: if ($entry =~ /^cr/) {
5238: ($trole,$tdom,$tnum,$tsec) =
5239: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5240: } else {
5241: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5242: }
5243: my ($spec,$area,$trest);
5244: $area = '/'.$tdom.'/'.$tnum;
5245: $trest = $tnum;
5246: if ($tsec ne '') {
5247: $area .= '/'.$tsec;
5248: $trest .= '/'.$tsec;
5249: }
5250: $spec = $trole.'.'.$area;
5251: if ($trole =~ /^cr/) {
5252: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5253: $tdom,$spec,$trest,$area);
5254: } else {
5255: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5256: $tdom,$spec,$trest,$area);
5257: }
5258: }
1.1276 raeburn 5259: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5260: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5261: if ($1) {
5262: $no_userblock = 1;
5263: last;
5264: }
1.486 raeburn 5265: }
5266: }
1.490 raeburn 5267: } else {
5268: # Resource belongs to current user
5269: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5270: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5271: $no_ownblock = 1;
5272: last;
5273: }
1.474 raeburn 5274: }
5275: }
5276: # if they have the evb priv and are currently not playing student
1.482 raeburn 5277: next if (($no_ownblock) &&
1.491 albertel 5278: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5279: next if ($no_userblock);
1.474 raeburn 5280:
1.1303 raeburn 5281: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5282: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5283:
1.1062 raeburn 5284: my ($start,$end,$trigger) =
5285: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5286: if (($start != 0) &&
5287: (($startblock == 0) || ($startblock > $start))) {
5288: $startblock = $start;
1.1062 raeburn 5289: if ($trigger ne '') {
5290: $triggerblock = $trigger;
5291: }
1.502 raeburn 5292: }
5293: if (($end != 0) &&
5294: (($endblock == 0) || ($endblock < $end))) {
5295: $endblock = $end;
1.1062 raeburn 5296: if ($trigger ne '') {
5297: $triggerblock = $trigger;
5298: }
1.502 raeburn 5299: }
1.490 raeburn 5300: }
1.1062 raeburn 5301: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5302: }
5303:
5304: sub get_blocks {
1.1062 raeburn 5305: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5306: my $startblock = 0;
5307: my $endblock = 0;
1.1062 raeburn 5308: my $triggerblock = '';
1.490 raeburn 5309: my $course = $cdom.'_'.$cnum;
5310: $setters->{$course} = {};
5311: $setters->{$course}{'staff'} = [];
5312: $setters->{$course}{'times'} = [];
1.1062 raeburn 5313: $setters->{$course}{'triggers'} = [];
5314: my (@blockers,%triggered);
5315: my $now = time;
5316: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5317: if ($activity eq 'docs') {
5318: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5319: foreach my $block (@blockers) {
5320: if ($block =~ /^firstaccess____(.+)$/) {
5321: my $item = $1;
5322: my $type = 'map';
5323: my $timersymb = $item;
5324: if ($item eq 'course') {
5325: $type = 'course';
5326: } elsif ($item =~ /___\d+___/) {
5327: $type = 'resource';
5328: } else {
5329: $timersymb = &Apache::lonnet::symbread($item);
5330: }
5331: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5332: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5333: $triggered{$block} = {
5334: start => $start,
5335: end => $end,
5336: type => $type,
5337: };
5338: }
5339: }
5340: } else {
5341: foreach my $block (keys(%commblocks)) {
5342: if ($block =~ m/^(\d+)____(\d+)$/) {
5343: my ($start,$end) = ($1,$2);
5344: if ($start <= time && $end >= time) {
5345: if (ref($commblocks{$block}) eq 'HASH') {
5346: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5347: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5348: unless(grep(/^\Q$block\E$/,@blockers)) {
5349: push(@blockers,$block);
5350: }
5351: }
5352: }
5353: }
5354: }
5355: } elsif ($block =~ /^firstaccess____(.+)$/) {
5356: my $item = $1;
5357: my $timersymb = $item;
5358: my $type = 'map';
5359: if ($item eq 'course') {
5360: $type = 'course';
5361: } elsif ($item =~ /___\d+___/) {
5362: $type = 'resource';
5363: } else {
5364: $timersymb = &Apache::lonnet::symbread($item);
5365: }
5366: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5367: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5368: if ($start && $end) {
5369: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5370: if (ref($commblocks{$block}) eq 'HASH') {
5371: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5372: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5373: unless(grep(/^\Q$block\E$/,@blockers)) {
5374: push(@blockers,$block);
5375: $triggered{$block} = {
5376: start => $start,
5377: end => $end,
5378: type => $type,
5379: };
5380: }
5381: }
5382: }
1.1062 raeburn 5383: }
5384: }
1.490 raeburn 5385: }
1.1062 raeburn 5386: }
5387: }
5388: }
5389: foreach my $blocker (@blockers) {
5390: my ($staff_name,$staff_dom,$title,$blocks) =
5391: &parse_block_record($commblocks{$blocker});
5392: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5393: my ($start,$end,$triggertype);
5394: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5395: ($start,$end) = ($1,$2);
5396: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5397: $start = $triggered{$blocker}{'start'};
5398: $end = $triggered{$blocker}{'end'};
5399: $triggertype = $triggered{$blocker}{'type'};
5400: }
5401: if ($start) {
5402: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5403: if ($triggertype) {
5404: push(@{$$setters{$course}{'triggers'}},$triggertype);
5405: } else {
5406: push(@{$$setters{$course}{'triggers'}},0);
5407: }
5408: if ( ($startblock == 0) || ($startblock > $start) ) {
5409: $startblock = $start;
5410: if ($triggertype) {
5411: $triggerblock = $blocker;
1.474 raeburn 5412: }
5413: }
1.1062 raeburn 5414: if ( ($endblock == 0) || ($endblock < $end) ) {
5415: $endblock = $end;
5416: if ($triggertype) {
5417: $triggerblock = $blocker;
5418: }
5419: }
1.474 raeburn 5420: }
5421: }
1.1062 raeburn 5422: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5423: }
5424:
5425: sub parse_block_record {
5426: my ($record) = @_;
5427: my ($setuname,$setudom,$title,$blocks);
5428: if (ref($record) eq 'HASH') {
5429: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5430: $title = &unescape($record->{'event'});
5431: $blocks = $record->{'blocks'};
5432: } else {
5433: my @data = split(/:/,$record,3);
5434: if (scalar(@data) eq 2) {
5435: $title = $data[1];
5436: ($setuname,$setudom) = split(/@/,$data[0]);
5437: } else {
5438: ($setuname,$setudom,$title) = @data;
5439: }
5440: $blocks = { 'com' => 'on' };
5441: }
5442: return ($setuname,$setudom,$title,$blocks);
5443: }
5444:
1.854 kalberla 5445: sub blocking_status {
1.1189 raeburn 5446: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5447: my %setters;
1.890 droeschl 5448:
1.1061 raeburn 5449: # check for active blocking
1.1062 raeburn 5450: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5451: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5452: my $blocked = 0;
5453: if ($startblock && $endblock) {
5454: $blocked = 1;
5455: }
1.890 droeschl 5456:
1.1061 raeburn 5457: # caller just wants to know whether a block is active
5458: if (!wantarray) { return $blocked; }
5459:
5460: # build a link to a popup window containing the details
5461: my $querystring = "?activity=$activity";
5462: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5463: if (($activity eq 'port') || ($activity eq 'passwd')) {
5464: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5465: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5466: } elsif ($activity eq 'docs') {
5467: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5468: }
1.1061 raeburn 5469:
5470: my $output .= <<'END_MYBLOCK';
5471: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5472: var options = "width=" + w + ",height=" + h + ",";
5473: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5474: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5475: var newWin = window.open(url, wdwName, options);
5476: newWin.focus();
5477: }
1.890 droeschl 5478: END_MYBLOCK
1.854 kalberla 5479:
1.1061 raeburn 5480: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5481:
1.1061 raeburn 5482: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5483: my $text = &mt('Communication Blocked');
1.1217 raeburn 5484: my $class = 'LC_comblock';
1.1062 raeburn 5485: if ($activity eq 'docs') {
5486: $text = &mt('Content Access Blocked');
1.1217 raeburn 5487: $class = '';
1.1063 raeburn 5488: } elsif ($activity eq 'printout') {
5489: $text = &mt('Printing Blocked');
1.1232 raeburn 5490: } elsif ($activity eq 'passwd') {
5491: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5492: } elsif ($activity eq 'alert') {
5493: $text = &mt('Checking Critical Messages Blocked');
5494: } elsif ($activity eq 'reinit') {
5495: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5496: }
1.1061 raeburn 5497: $output .= <<"END_BLOCK";
1.1217 raeburn 5498: <div class='$class'>
1.869 kalberla 5499: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5500: title='$text'>
5501: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5502: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5503: title='$text'>$text</a>
1.867 kalberla 5504: </div>
5505:
5506: END_BLOCK
1.474 raeburn 5507:
1.1061 raeburn 5508: return ($blocked, $output);
1.854 kalberla 5509: }
1.490 raeburn 5510:
1.60 matthew 5511: ###############################################
5512:
1.682 raeburn 5513: sub check_ip_acc {
1.1201 raeburn 5514: my ($acc,$clientip)=@_;
1.682 raeburn 5515: &Apache::lonxml::debug("acc is $acc");
5516: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5517: return 1;
5518: }
1.1219 raeburn 5519: my $allowed;
1.1252 raeburn 5520: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5521:
5522: my $name;
1.1219 raeburn 5523: my %access = (
5524: allowfrom => 1,
5525: denyfrom => 0,
5526: );
5527: my @allows;
5528: my @denies;
5529: foreach my $item (split(',',$acc)) {
5530: $item =~ s/^\s*//;
5531: $item =~ s/\s*$//;
5532: my $pattern;
5533: if ($item =~ /^\!(.+)$/) {
5534: push(@denies,$1);
5535: } else {
5536: push(@allows,$item);
5537: }
5538: }
5539: my $numdenies = scalar(@denies);
5540: my $numallows = scalar(@allows);
5541: my $count = 0;
5542: foreach my $pattern (@denies,@allows) {
5543: $count ++;
5544: my $acctype = 'allowfrom';
5545: if ($count <= $numdenies) {
5546: $acctype = 'denyfrom';
5547: }
1.682 raeburn 5548: if ($pattern =~ /\*$/) {
5549: #35.8.*
5550: $pattern=~s/\*//;
1.1219 raeburn 5551: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5552: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5553: #35.8.3.[34-56]
5554: my $low=$2;
5555: my $high=$3;
5556: $pattern=$1;
5557: if ($ip =~ /^\Q$pattern\E/) {
5558: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5559: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5560: }
5561: } elsif ($pattern =~ /^\*/) {
5562: #*.msu.edu
5563: $pattern=~s/\*//;
5564: if (!defined($name)) {
5565: use Socket;
5566: my $netaddr=inet_aton($ip);
5567: ($name)=gethostbyaddr($netaddr,AF_INET);
5568: }
1.1219 raeburn 5569: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5570: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5571: #127.0.0.1
1.1219 raeburn 5572: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5573: } else {
5574: #some.name.com
5575: if (!defined($name)) {
5576: use Socket;
5577: my $netaddr=inet_aton($ip);
5578: ($name)=gethostbyaddr($netaddr,AF_INET);
5579: }
1.1219 raeburn 5580: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5581: }
5582: if ($allowed =~ /^(0|1)$/) { last; }
5583: }
5584: if ($allowed eq '') {
5585: if ($numdenies && !$numallows) {
5586: $allowed = 1;
5587: } else {
5588: $allowed = 0;
1.682 raeburn 5589: }
5590: }
5591: return $allowed;
5592: }
5593:
5594: ###############################################
5595:
1.60 matthew 5596: =pod
5597:
1.112 bowersj2 5598: =head1 Domain Template Functions
5599:
5600: =over 4
5601:
5602: =item * &determinedomain()
1.60 matthew 5603:
5604: Inputs: $domain (usually will be undef)
5605:
1.63 www 5606: Returns: Determines which domain should be used for designs
1.60 matthew 5607:
5608: =cut
1.54 www 5609:
1.60 matthew 5610: ###############################################
1.63 www 5611: sub determinedomain {
5612: my $domain=shift;
1.531 albertel 5613: if (! $domain) {
1.60 matthew 5614: # Determine domain if we have not been given one
1.893 raeburn 5615: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5616: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5617: if ($env{'request.role.domain'}) {
5618: $domain=$env{'request.role.domain'};
1.60 matthew 5619: }
5620: }
1.63 www 5621: return $domain;
5622: }
5623: ###############################################
1.517 raeburn 5624:
1.518 albertel 5625: sub devalidate_domconfig_cache {
5626: my ($udom)=@_;
5627: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5628: }
5629:
5630: # ---------------------- Get domain configuration for a domain
5631: sub get_domainconf {
5632: my ($udom) = @_;
5633: my $cachetime=1800;
5634: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5635: if (defined($cached)) { return %{$result}; }
5636:
5637: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5638: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5639: my (%designhash,%legacy);
1.518 albertel 5640: if (keys(%domconfig) > 0) {
5641: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5642: if (keys(%{$domconfig{'login'}})) {
5643: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5644: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5645: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5646: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5647: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5648: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5649: if ($key eq 'loginvia') {
5650: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5651: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5652: $designhash{$udom.'.login.loginvia'} = $server;
5653: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5654:
5655: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5656: } else {
5657: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5658: }
1.948 raeburn 5659: }
1.1208 raeburn 5660: } elsif ($key eq 'headtag') {
5661: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5662: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5663: }
1.946 raeburn 5664: }
1.1208 raeburn 5665: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5666: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5667: }
1.946 raeburn 5668: }
5669: }
5670: }
5671: } else {
5672: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5673: $designhash{$udom.'.login.'.$key.'_'.$img} =
5674: $domconfig{'login'}{$key}{$img};
5675: }
1.699 raeburn 5676: }
5677: } else {
5678: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5679: }
1.632 raeburn 5680: }
5681: } else {
5682: $legacy{'login'} = 1;
1.518 albertel 5683: }
1.632 raeburn 5684: } else {
5685: $legacy{'login'} = 1;
1.518 albertel 5686: }
5687: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5688: if (keys(%{$domconfig{'rolecolors'}})) {
5689: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5690: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5691: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5692: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5693: }
1.518 albertel 5694: }
5695: }
1.632 raeburn 5696: } else {
5697: $legacy{'rolecolors'} = 1;
1.518 albertel 5698: }
1.632 raeburn 5699: } else {
5700: $legacy{'rolecolors'} = 1;
1.518 albertel 5701: }
1.948 raeburn 5702: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5703: if ($domconfig{'autoenroll'}{'co-owners'}) {
5704: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5705: }
5706: }
1.632 raeburn 5707: if (keys(%legacy) > 0) {
5708: my %legacyhash = &get_legacy_domconf($udom);
5709: foreach my $item (keys(%legacyhash)) {
5710: if ($item =~ /^\Q$udom\E\.login/) {
5711: if ($legacy{'login'}) {
5712: $designhash{$item} = $legacyhash{$item};
5713: }
5714: } else {
5715: if ($legacy{'rolecolors'}) {
5716: $designhash{$item} = $legacyhash{$item};
5717: }
1.518 albertel 5718: }
5719: }
5720: }
1.632 raeburn 5721: } else {
5722: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5723: }
5724: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5725: $cachetime);
5726: return %designhash;
5727: }
5728:
1.632 raeburn 5729: sub get_legacy_domconf {
5730: my ($udom) = @_;
5731: my %legacyhash;
5732: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5733: my $designfile = $designdir.'/'.$udom.'.tab';
5734: if (-e $designfile) {
1.1317 raeburn 5735: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5736: while (my $line = <$fh>) {
5737: next if ($line =~ /^\#/);
5738: chomp($line);
5739: my ($key,$val)=(split(/\=/,$line));
5740: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5741: }
5742: close($fh);
5743: }
5744: }
1.1026 raeburn 5745: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5746: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5747: }
5748: return %legacyhash;
5749: }
5750:
1.63 www 5751: =pod
5752:
1.112 bowersj2 5753: =item * &domainlogo()
1.63 www 5754:
5755: Inputs: $domain (usually will be undef)
5756:
5757: Returns: A link to a domain logo, if the domain logo exists.
5758: If the domain logo does not exist, a description of the domain.
5759:
5760: =cut
1.112 bowersj2 5761:
1.63 www 5762: ###############################################
5763: sub domainlogo {
1.517 raeburn 5764: my $domain = &determinedomain(shift);
1.518 albertel 5765: my %designhash = &get_domainconf($domain);
1.517 raeburn 5766: # See if there is a logo
5767: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5768: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5769: if ($imgsrc =~ m{^/(adm|res)/}) {
5770: if ($imgsrc =~ m{^/res/}) {
5771: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5772: &Apache::lonnet::repcopy($local_name);
5773: }
5774: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5775: }
5776: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5777: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5778: return &Apache::lonnet::domain($domain,'description');
1.59 www 5779: } else {
1.60 matthew 5780: return '';
1.59 www 5781: }
5782: }
1.63 www 5783: ##############################################
5784:
5785: =pod
5786:
1.112 bowersj2 5787: =item * &designparm()
1.63 www 5788:
5789: Inputs: $which parameter; $domain (usually will be undef)
5790:
5791: Returns: value of designparamter $which
5792:
5793: =cut
1.112 bowersj2 5794:
1.397 albertel 5795:
1.400 albertel 5796: ##############################################
1.397 albertel 5797: sub designparm {
5798: my ($which,$domain)=@_;
5799: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5800: return $env{'environment.color.'.$which};
1.96 www 5801: }
1.63 www 5802: $domain=&determinedomain($domain);
1.1016 raeburn 5803: my %domdesign;
5804: unless ($domain eq 'public') {
5805: %domdesign = &get_domainconf($domain);
5806: }
1.520 raeburn 5807: my $output;
1.517 raeburn 5808: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5809: $output = $domdesign{$domain.'.'.$which};
1.63 www 5810: } else {
1.520 raeburn 5811: $output = $defaultdesign{$which};
5812: }
5813: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5814: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5815: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5816: if ($output =~ m{^/res/}) {
5817: my $local_name = &Apache::lonnet::filelocation('',$output);
5818: &Apache::lonnet::repcopy($local_name);
5819: }
1.520 raeburn 5820: $output = &lonhttpdurl($output);
5821: }
1.63 www 5822: }
1.520 raeburn 5823: return $output;
1.63 www 5824: }
1.59 www 5825:
1.822 bisitz 5826: ##############################################
5827: =pod
5828:
1.832 bisitz 5829: =item * &authorspace()
5830:
1.1028 raeburn 5831: Inputs: $url (usually will be undef).
1.832 bisitz 5832:
1.1132 raeburn 5833: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5834: directory being viewed (or for which action is being taken).
5835: If $url is provided, and begins /priv/<domain>/<uname>
5836: the path will be that portion of the $context argument.
5837: Otherwise the path will be for the author space of the current
5838: user when the current role is author, or for that of the
5839: co-author/assistant co-author space when the current role
5840: is co-author or assistant co-author.
1.832 bisitz 5841:
5842: =cut
5843:
5844: sub authorspace {
1.1028 raeburn 5845: my ($url) = @_;
5846: if ($url ne '') {
5847: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5848: return $1;
5849: }
5850: }
1.832 bisitz 5851: my $caname = '';
1.1024 www 5852: my $cadom = '';
1.1028 raeburn 5853: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5854: ($cadom,$caname) =
1.832 bisitz 5855: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5856: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5857: $caname = $env{'user.name'};
1.1024 www 5858: $cadom = $env{'user.domain'};
1.832 bisitz 5859: }
1.1028 raeburn 5860: if (($caname ne '') && ($cadom ne '')) {
5861: return "/priv/$cadom/$caname/";
5862: }
5863: return;
1.832 bisitz 5864: }
5865:
5866: ##############################################
5867: =pod
5868:
1.822 bisitz 5869: =item * &head_subbox()
5870:
5871: Inputs: $content (contains HTML code with page functions, etc.)
5872:
5873: Returns: HTML div with $content
5874: To be included in page header
5875:
5876: =cut
5877:
5878: sub head_subbox {
5879: my ($content)=@_;
5880: my $output =
1.993 raeburn 5881: '<div class="LC_head_subbox">'
1.822 bisitz 5882: .$content
5883: .'</div>'
5884: }
5885:
5886: ##############################################
5887: =pod
5888:
5889: =item * &CSTR_pageheader()
5890:
1.1026 raeburn 5891: Input: (optional) filename from which breadcrumb trail is built.
5892: In most cases no input as needed, as $env{'request.filename'}
5893: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5894:
5895: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5896: To be included on Authoring Space pages
1.822 bisitz 5897:
5898: =cut
5899:
5900: sub CSTR_pageheader {
1.1026 raeburn 5901: my ($trailfile) = @_;
5902: if ($trailfile eq '') {
5903: $trailfile = $env{'request.filename'};
5904: }
5905:
5906: # this is for resources; directories have customtitle, and crumbs
5907: # and select recent are created in lonpubdir.pm
5908:
5909: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5910: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5911: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5912: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5913: $formaction =~ s{/+}{/}g;
1.822 bisitz 5914:
5915: my $parentpath = '';
5916: my $lastitem = '';
5917: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5918: $parentpath = $1;
5919: $lastitem = $2;
5920: } else {
5921: $lastitem = $thisdisfn;
5922: }
1.921 bisitz 5923:
1.1246 raeburn 5924: my ($crsauthor,$title);
5925: if (($env{'request.course.id'}) &&
5926: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5927: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5928: $crsauthor = 1;
5929: $title = &mt('Course Authoring Space');
5930: } else {
5931: $title = &mt('Authoring Space');
5932: }
5933:
1.1314 raeburn 5934: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5935: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5936: $target = '';
5937: $crumbtarget = '';
1.1313 raeburn 5938: }
5939:
1.921 bisitz 5940: my $output =
1.822 bisitz 5941: '<div>'
5942: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5943: .'<b>'.$title.'</b> '
1.1314 raeburn 5944: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5945: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5946:
5947: if ($lastitem) {
5948: $output .=
5949: '<span class="LC_filename">'
5950: .$lastitem
5951: .'</span>';
5952: }
1.1245 raeburn 5953:
1.1246 raeburn 5954: if ($crsauthor) {
5955: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5956: } else {
5957: $output .=
5958: '<br />'
1.1314 raeburn 5959: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5960: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5961: .'</form>'
5962: .&Apache::lonmenu::constspaceform();
5963: }
5964: $output .= '</div>';
1.921 bisitz 5965:
5966: return $output;
1.822 bisitz 5967: }
5968:
1.60 matthew 5969: ###############################################
5970: ###############################################
5971:
5972: =pod
5973:
1.112 bowersj2 5974: =back
5975:
1.549 albertel 5976: =head1 HTML Helpers
1.112 bowersj2 5977:
5978: =over 4
5979:
5980: =item * &bodytag()
1.60 matthew 5981:
5982: Returns a uniform header for LON-CAPA web pages.
5983:
5984: Inputs:
5985:
1.112 bowersj2 5986: =over 4
5987:
5988: =item * $title, A title to be displayed on the page.
5989:
5990: =item * $function, the current role (can be undef).
5991:
5992: =item * $addentries, extra parameters for the <body> tag.
5993:
5994: =item * $bodyonly, if defined, only return the <body> tag.
5995:
5996: =item * $domain, if defined, force a given domain.
5997:
5998: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5999: text interface only)
1.60 matthew 6000:
1.814 bisitz 6001: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6002: navigational links
1.317 albertel 6003:
1.338 albertel 6004: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6005:
1.460 albertel 6006: =item * $args, optional argument valid values are
6007: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6008: use_absolute -> for external resource or syllabus, this will
6009: contain https://<hostname> if server uses
6010: https (as per hosts.tab), but request is for http
6011: hostname -> hostname, from $r->hostname().
1.460 albertel 6012:
1.1096 raeburn 6013: =item * $advtoolsref, optional argument, ref to an array containing
6014: inlineremote items to be added in "Functions" menu below
6015: breadcrumbs.
6016:
1.1316 raeburn 6017: =item * $ltiscope, optional argument, will be one of: resource, map or
6018: course, if LON-CAPA is in LTI Provider context. Value is
6019: the scope of use, i.e., launch was for access to a single, a map
6020: or the entire course.
6021:
6022: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6023: context, this will contain the URL for the landing item in
6024: the course, after launch from an LTI Consumer
6025:
1.1318 raeburn 6026: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6027: context, this will contain a reference to hash of items
6028: to be included in the page header and/or inline menu.
6029:
1.112 bowersj2 6030: =back
6031:
1.60 matthew 6032: Returns: A uniform header for LON-CAPA web pages.
6033: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6034: If $bodyonly is undef or zero, an html string containing a <body> tag and
6035: other decorations will be returned.
6036:
6037: =cut
6038:
1.54 www 6039: sub bodytag {
1.831 bisitz 6040: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 6041: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 6042:
1.954 raeburn 6043: my $public;
6044: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6045: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6046: $public = 1;
6047: }
1.460 albertel 6048: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6049: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6050: my $hostname = $args->{'hostname'};
1.339 albertel 6051:
1.183 matthew 6052: $function = &get_users_function() if (!$function);
1.339 albertel 6053: my $img = &designparm($function.'.img',$domain);
6054: my $font = &designparm($function.'.font',$domain);
6055: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6056:
1.803 bisitz 6057: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6058: 'bgcolor' => $pgbg,
1.339 albertel 6059: 'text' => $font,
6060: 'alink' => &designparm($function.'.alink',$domain),
6061: 'vlink' => &designparm($function.'.vlink',$domain),
6062: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6063: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6064:
1.63 www 6065: # role and realm
1.1178 raeburn 6066: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6067: if ($realm) {
6068: $realm = '/'.$realm;
6069: }
1.378 raeburn 6070: if ($role eq 'ca') {
1.479 albertel 6071: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6072: $realm = &plainname($rname,$rdom);
1.378 raeburn 6073: }
1.55 www 6074: # realm
1.258 albertel 6075: if ($env{'request.course.id'}) {
1.378 raeburn 6076: if ($env{'request.role'} !~ /^cr/) {
6077: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6078: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6079: if ($env{'request.role.desc'}) {
6080: $role = $env{'request.role.desc'};
6081: } else {
6082: $role = &mt('Helpdesk[_1]',' '.$2);
6083: }
1.1257 raeburn 6084: } else {
6085: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6086: }
1.898 raeburn 6087: if ($env{'request.course.sec'}) {
6088: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6089: }
1.359 albertel 6090: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6091: } else {
6092: $role = &Apache::lonnet::plaintext($role);
1.54 www 6093: }
1.433 albertel 6094:
1.359 albertel 6095: if (!$realm) { $realm=' '; }
1.330 albertel 6096:
1.438 albertel 6097: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6098:
1.101 www 6099: # construct main body tag
1.359 albertel 6100: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6101: &Apache::lontexconvert::init_math_support();
1.252 albertel 6102:
1.1131 raeburn 6103: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6104:
1.1130 raeburn 6105: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6106: return $bodytag;
1.1130 raeburn 6107: }
1.359 albertel 6108:
1.954 raeburn 6109: if ($public) {
1.433 albertel 6110: undef($role);
6111: }
1.1318 raeburn 6112:
6113: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6114: if (ref($ltimenu) eq 'HASH') {
6115: unless ($ltimenu->{'role'}) {
6116: undef($role);
6117: }
6118: unless ($ltimenu->{'coursetitle'}) {
6119: $realm=' ';
6120: }
6121: }
6122: }
6123:
1.762 bisitz 6124: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6125: #
6126: # Extra info if you are the DC
6127: my $dc_info = '';
6128: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6129: $env{'course.'.$env{'request.course.id'}.
6130: '.domain'}.'/'})) {
6131: my $cid = $env{'request.course.id'};
1.917 raeburn 6132: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6133: $dc_info =~ s/\s+$//;
1.359 albertel 6134: }
6135:
1.1237 raeburn 6136: my $crstype;
6137: if ($env{'request.course.id'}) {
6138: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6139: } elsif ($args->{'crstype'}) {
6140: $crstype = $args->{'crstype'};
6141: }
6142: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6143: undef($role);
6144: } else {
1.1242 raeburn 6145: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6146: }
1.853 droeschl 6147:
1.903 droeschl 6148: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6149:
6150: # if ($env{'request.state'} eq 'construct') {
6151: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6152: # }
6153:
1.1130 raeburn 6154: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6155: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6156:
1.1318 raeburn 6157: unless ($args->{'no_primary_menu'}) {
6158: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6159:
1.1318 raeburn 6160: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6161: if ($dc_info) {
6162: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6163: }
6164: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6165: <em>$realm</em> $dc_info</div>|;
6166: return $bodytag;
6167: }
1.894 droeschl 6168:
1.1318 raeburn 6169: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6170: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6171: }
1.916 droeschl 6172:
1.1318 raeburn 6173: $bodytag .= $right;
1.852 droeschl 6174:
1.1318 raeburn 6175: if ($dc_info) {
6176: $dc_info = &dc_courseid_toggle($dc_info);
6177: }
6178: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6179: }
1.916 droeschl 6180:
1.1169 raeburn 6181: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6182: if ($args->{'no_secondary_menu'}) {
6183: return $bodytag;
6184: }
1.1169 raeburn 6185: #don't show menus for public users
1.954 raeburn 6186: if (!$public){
1.1318 raeburn 6187: unless ($args->{'no_inline_menu'}) {
6188: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6189: $args->{'no_primary_menu'});
6190: }
1.903 droeschl 6191: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6192: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6193: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6194: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6195: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6196: } elsif ($forcereg) {
6197: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6198: $args->{'group'},
1.1274 raeburn 6199: $args->{'hide_buttons'},
1.1316 raeburn 6200: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6201: } else {
6202: $bodytag .=
6203: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6204: $forcereg,$args->{'group'},
6205: $args->{'bread_crumbs'},
1.1274 raeburn 6206: $advtoolsref,'',$hostname);
1.920 raeburn 6207: }
1.903 droeschl 6208: }else{
6209: # this is to seperate menu from content when there's no secondary
6210: # menu. Especially needed for public accessible ressources.
6211: $bodytag .= '<hr style="clear:both" />';
6212: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6213: }
1.903 droeschl 6214:
1.235 raeburn 6215: return $bodytag;
1.182 matthew 6216: }
6217:
1.917 raeburn 6218: sub dc_courseid_toggle {
6219: my ($dc_info) = @_;
1.980 raeburn 6220: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6221: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6222: &mt('(More ...)').'</a></span>'.
6223: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6224: }
6225:
1.330 albertel 6226: sub make_attr_string {
6227: my ($register,$attr_ref) = @_;
6228:
6229: if ($attr_ref && !ref($attr_ref)) {
6230: die("addentries Must be a hash ref ".
6231: join(':',caller(1))." ".
6232: join(':',caller(0))." ");
6233: }
6234:
6235: if ($register) {
1.339 albertel 6236: my ($on_load,$on_unload);
6237: foreach my $key (keys(%{$attr_ref})) {
6238: if (lc($key) eq 'onload') {
6239: $on_load.=$attr_ref->{$key}.';';
6240: delete($attr_ref->{$key});
6241:
6242: } elsif (lc($key) eq 'onunload') {
6243: $on_unload.=$attr_ref->{$key}.';';
6244: delete($attr_ref->{$key});
6245: }
6246: }
1.953 droeschl 6247: $attr_ref->{'onload'} = $on_load;
6248: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6249: }
1.339 albertel 6250:
1.330 albertel 6251: my $attr_string;
1.1159 raeburn 6252: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6253: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6254: }
6255: return $attr_string;
6256: }
6257:
6258:
1.182 matthew 6259: ###############################################
1.251 albertel 6260: ###############################################
6261:
6262: =pod
6263:
6264: =item * &endbodytag()
6265:
6266: Returns a uniform footer for LON-CAPA web pages.
6267:
1.635 raeburn 6268: Inputs: 1 - optional reference to an args hash
6269: If in the hash, key for noredirectlink has a value which evaluates to true,
6270: a 'Continue' link is not displayed if the page contains an
6271: internal redirect in the <head></head> section,
6272: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6273:
6274: =cut
6275:
6276: sub endbodytag {
1.635 raeburn 6277: my ($args) = @_;
1.1080 raeburn 6278: my $endbodytag;
6279: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6280: $endbodytag='</body>';
6281: }
1.315 albertel 6282: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6283: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6284: $endbodytag=
6285: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6286: &mt('Continue').'</a>'.
6287: $endbodytag;
6288: }
1.315 albertel 6289: }
1.251 albertel 6290: return $endbodytag;
6291: }
6292:
1.352 albertel 6293: =pod
6294:
6295: =item * &standard_css()
6296:
6297: Returns a style sheet
6298:
6299: Inputs: (all optional)
6300: domain -> force to color decorate a page for a specific
6301: domain
6302: function -> force usage of a specific rolish color scheme
6303: bgcolor -> override the default page bgcolor
6304:
6305: =cut
6306:
1.343 albertel 6307: sub standard_css {
1.345 albertel 6308: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6309: $function = &get_users_function() if (!$function);
6310: my $img = &designparm($function.'.img', $domain);
6311: my $tabbg = &designparm($function.'.tabbg', $domain);
6312: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6313: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6314: #second colour for later usage
1.345 albertel 6315: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6316: my $pgbg_or_bgcolor =
6317: $bgcolor ||
1.352 albertel 6318: &designparm($function.'.pgbg', $domain);
1.382 albertel 6319: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6320: my $alink = &designparm($function.'.alink', $domain);
6321: my $vlink = &designparm($function.'.vlink', $domain);
6322: my $link = &designparm($function.'.link', $domain);
6323:
1.602 albertel 6324: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6325: my $mono = 'monospace';
1.850 bisitz 6326: my $data_table_head = $sidebg;
6327: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6328: my $data_table_dark = '#E0E0E0';
1.470 banghart 6329: my $data_table_darker = '#CCCCCC';
1.349 albertel 6330: my $data_table_highlight = '#FFFF00';
1.352 albertel 6331: my $mail_new = '#FFBB77';
6332: my $mail_new_hover = '#DD9955';
6333: my $mail_read = '#BBBB77';
6334: my $mail_read_hover = '#999944';
6335: my $mail_replied = '#AAAA88';
6336: my $mail_replied_hover = '#888855';
6337: my $mail_other = '#99BBBB';
6338: my $mail_other_hover = '#669999';
1.391 albertel 6339: my $table_header = '#DDDDDD';
1.489 raeburn 6340: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6341: my $lg_border_color = '#C8C8C8';
1.952 onken 6342: my $button_hover = '#BF2317';
1.392 albertel 6343:
1.608 albertel 6344: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6345: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6346: : '0 3px 0 4px';
1.448 albertel 6347:
1.523 albertel 6348:
1.343 albertel 6349: return <<END;
1.947 droeschl 6350:
6351: /* needed for iframe to allow 100% height in FF */
6352: body, html {
6353: margin: 0;
6354: padding: 0 0.5%;
6355: height: 99%; /* to avoid scrollbars */
6356: }
6357:
1.795 www 6358: body {
1.911 bisitz 6359: font-family: $sans;
6360: line-height:130%;
6361: font-size:0.83em;
6362: color:$font;
1.795 www 6363: }
6364:
1.959 onken 6365: a:focus,
6366: a:focus img {
1.795 www 6367: color: red;
6368: }
1.698 harmsja 6369:
1.911 bisitz 6370: form, .inline {
6371: display: inline;
1.795 www 6372: }
1.721 harmsja 6373:
1.795 www 6374: .LC_right {
1.911 bisitz 6375: text-align:right;
1.795 www 6376: }
6377:
6378: .LC_middle {
1.911 bisitz 6379: vertical-align:middle;
1.795 www 6380: }
1.721 harmsja 6381:
1.1130 raeburn 6382: .LC_floatleft {
6383: float: left;
6384: }
6385:
6386: .LC_floatright {
6387: float: right;
6388: }
6389:
1.911 bisitz 6390: .LC_400Box {
6391: width:400px;
6392: }
1.721 harmsja 6393:
1.947 droeschl 6394: .LC_iframecontainer {
6395: width: 98%;
6396: margin: 0;
6397: position: fixed;
6398: top: 8.5em;
6399: bottom: 0;
6400: }
6401:
6402: .LC_iframecontainer iframe{
6403: border: none;
6404: width: 100%;
6405: height: 100%;
6406: }
6407:
1.778 bisitz 6408: .LC_filename {
6409: font-family: $mono;
6410: white-space:pre;
1.921 bisitz 6411: font-size: 120%;
1.778 bisitz 6412: }
6413:
6414: .LC_fileicon {
6415: border: none;
6416: height: 1.3em;
6417: vertical-align: text-bottom;
6418: margin-right: 0.3em;
6419: text-decoration:none;
6420: }
6421:
1.1008 www 6422: .LC_setting {
6423: text-decoration:underline;
6424: }
6425:
1.350 albertel 6426: .LC_error {
6427: color: red;
6428: }
1.795 www 6429:
1.1097 bisitz 6430: .LC_warning {
6431: color: darkorange;
6432: }
6433:
1.457 albertel 6434: .LC_diff_removed {
1.733 bisitz 6435: color: red;
1.394 albertel 6436: }
1.532 albertel 6437:
6438: .LC_info,
1.457 albertel 6439: .LC_success,
6440: .LC_diff_added {
1.350 albertel 6441: color: green;
6442: }
1.795 www 6443:
1.802 bisitz 6444: div.LC_confirm_box {
6445: background-color: #FAFAFA;
6446: border: 1px solid $lg_border_color;
6447: margin-right: 0;
6448: padding: 5px;
6449: }
6450:
6451: div.LC_confirm_box .LC_error img,
6452: div.LC_confirm_box .LC_success img {
6453: vertical-align: middle;
6454: }
6455:
1.1242 raeburn 6456: .LC_maxwidth {
6457: max-width: 100%;
6458: height: auto;
6459: }
6460:
1.1243 raeburn 6461: .LC_textsize_mobile {
6462: \@media only screen and (max-device-width: 480px) {
6463: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6464: }
6465: }
6466:
1.440 albertel 6467: .LC_icon {
1.771 droeschl 6468: border: none;
1.790 droeschl 6469: vertical-align: middle;
1.771 droeschl 6470: }
6471:
1.543 albertel 6472: .LC_docs_spacer {
6473: width: 25px;
6474: height: 1px;
1.771 droeschl 6475: border: none;
1.543 albertel 6476: }
1.346 albertel 6477:
1.532 albertel 6478: .LC_internal_info {
1.735 bisitz 6479: color: #999999;
1.532 albertel 6480: }
6481:
1.794 www 6482: .LC_discussion {
1.1050 www 6483: background: $data_table_dark;
1.911 bisitz 6484: border: 1px solid black;
6485: margin: 2px;
1.794 www 6486: }
6487:
6488: .LC_disc_action_left {
1.1050 www 6489: background: $sidebg;
1.911 bisitz 6490: text-align: left;
1.1050 www 6491: padding: 4px;
6492: margin: 2px;
1.794 www 6493: }
6494:
6495: .LC_disc_action_right {
1.1050 www 6496: background: $sidebg;
1.911 bisitz 6497: text-align: right;
1.1050 www 6498: padding: 4px;
6499: margin: 2px;
1.794 www 6500: }
6501:
6502: .LC_disc_new_item {
1.911 bisitz 6503: background: white;
6504: border: 2px solid red;
1.1050 www 6505: margin: 4px;
6506: padding: 4px;
1.794 www 6507: }
6508:
6509: .LC_disc_old_item {
1.911 bisitz 6510: background: white;
1.1050 www 6511: margin: 4px;
6512: padding: 4px;
1.794 www 6513: }
6514:
1.458 albertel 6515: table.LC_pastsubmission {
6516: border: 1px solid black;
6517: margin: 2px;
6518: }
6519:
1.924 bisitz 6520: table#LC_menubuttons {
1.345 albertel 6521: width: 100%;
6522: background: $pgbg;
1.392 albertel 6523: border: 2px;
1.402 albertel 6524: border-collapse: separate;
1.803 bisitz 6525: padding: 0;
1.345 albertel 6526: }
1.392 albertel 6527:
1.801 tempelho 6528: table#LC_title_bar a {
6529: color: $fontmenu;
6530: }
1.836 bisitz 6531:
1.807 droeschl 6532: table#LC_title_bar {
1.819 tempelho 6533: clear: both;
1.836 bisitz 6534: display: none;
1.807 droeschl 6535: }
6536:
1.795 www 6537: table#LC_title_bar,
1.933 droeschl 6538: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6539: table#LC_title_bar.LC_with_remote {
1.359 albertel 6540: width: 100%;
1.392 albertel 6541: border-color: $pgbg;
6542: border-style: solid;
6543: border-width: $border;
1.379 albertel 6544: background: $pgbg;
1.801 tempelho 6545: color: $fontmenu;
1.392 albertel 6546: border-collapse: collapse;
1.803 bisitz 6547: padding: 0;
1.819 tempelho 6548: margin: 0;
1.359 albertel 6549: }
1.795 www 6550:
1.933 droeschl 6551: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6552: margin: 0;
6553: padding: 0;
1.933 droeschl 6554: position: relative;
6555: list-style: none;
1.913 droeschl 6556: }
1.933 droeschl 6557: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6558: display: inline;
6559: }
1.933 droeschl 6560:
6561: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6562: padding: 0;
1.933 droeschl 6563: margin: 0;
6564: float: left;
1.913 droeschl 6565: }
1.933 droeschl 6566: .LC_breadcrumb_tools_tools {
6567: padding: 0;
6568: margin: 0;
1.913 droeschl 6569: float: right;
6570: }
6571:
1.1240 raeburn 6572: .LC_placement_prog {
6573: padding-right: 20px;
6574: font-weight: bold;
6575: font-size: 90%;
6576: }
6577:
1.359 albertel 6578: table#LC_title_bar td {
6579: background: $tabbg;
6580: }
1.795 www 6581:
1.911 bisitz 6582: table#LC_menubuttons img {
1.803 bisitz 6583: border: none;
1.346 albertel 6584: }
1.795 www 6585:
1.842 droeschl 6586: .LC_breadcrumbs_component {
1.911 bisitz 6587: float: right;
6588: margin: 0 1em;
1.357 albertel 6589: }
1.842 droeschl 6590: .LC_breadcrumbs_component img {
1.911 bisitz 6591: vertical-align: middle;
1.777 tempelho 6592: }
1.795 www 6593:
1.1243 raeburn 6594: .LC_breadcrumbs_hoverable {
6595: background: $sidebg;
6596: }
6597:
1.383 albertel 6598: td.LC_table_cell_checkbox {
6599: text-align: center;
6600: }
1.795 www 6601:
6602: .LC_fontsize_small {
1.911 bisitz 6603: font-size: 70%;
1.705 tempelho 6604: }
6605:
1.844 bisitz 6606: #LC_breadcrumbs {
1.911 bisitz 6607: clear:both;
6608: background: $sidebg;
6609: border-bottom: 1px solid $lg_border_color;
6610: line-height: 2.5em;
1.933 droeschl 6611: overflow: hidden;
1.911 bisitz 6612: margin: 0;
6613: padding: 0;
1.995 raeburn 6614: text-align: left;
1.819 tempelho 6615: }
1.862 bisitz 6616:
1.1098 bisitz 6617: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6618: clear:both;
6619: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6620: border: 1px solid $sidebg;
1.1098 bisitz 6621: margin: 0 0 10px 0;
1.966 bisitz 6622: padding: 3px;
1.995 raeburn 6623: text-align: left;
1.822 bisitz 6624: }
6625:
1.795 www 6626: .LC_fontsize_medium {
1.911 bisitz 6627: font-size: 85%;
1.705 tempelho 6628: }
6629:
1.795 www 6630: .LC_fontsize_large {
1.911 bisitz 6631: font-size: 120%;
1.705 tempelho 6632: }
6633:
1.346 albertel 6634: .LC_menubuttons_inline_text {
6635: color: $font;
1.698 harmsja 6636: font-size: 90%;
1.701 harmsja 6637: padding-left:3px;
1.346 albertel 6638: }
6639:
1.934 droeschl 6640: .LC_menubuttons_inline_text img{
6641: vertical-align: middle;
6642: }
6643:
1.1051 www 6644: li.LC_menubuttons_inline_text img {
1.951 onken 6645: cursor:pointer;
1.1002 droeschl 6646: text-decoration: none;
1.951 onken 6647: }
6648:
1.526 www 6649: .LC_menubuttons_link {
6650: text-decoration: none;
6651: }
1.795 www 6652:
1.522 albertel 6653: .LC_menubuttons_category {
1.521 www 6654: color: $font;
1.526 www 6655: background: $pgbg;
1.521 www 6656: font-size: larger;
6657: font-weight: bold;
6658: }
6659:
1.346 albertel 6660: td.LC_menubuttons_text {
1.911 bisitz 6661: color: $font;
1.346 albertel 6662: }
1.706 harmsja 6663:
1.346 albertel 6664: .LC_current_location {
6665: background: $tabbg;
6666: }
1.795 www 6667:
1.1286 raeburn 6668: td.LC_zero_height {
6669: line-height: 0;
6670: cellpadding: 0;
6671: }
6672:
1.938 bisitz 6673: table.LC_data_table {
1.347 albertel 6674: border: 1px solid #000000;
1.402 albertel 6675: border-collapse: separate;
1.426 albertel 6676: border-spacing: 1px;
1.610 albertel 6677: background: $pgbg;
1.347 albertel 6678: }
1.795 www 6679:
1.422 albertel 6680: .LC_data_table_dense {
6681: font-size: small;
6682: }
1.795 www 6683:
1.507 raeburn 6684: table.LC_nested_outer {
6685: border: 1px solid #000000;
1.589 raeburn 6686: border-collapse: collapse;
1.803 bisitz 6687: border-spacing: 0;
1.507 raeburn 6688: width: 100%;
6689: }
1.795 www 6690:
1.879 raeburn 6691: table.LC_innerpickbox,
1.507 raeburn 6692: table.LC_nested {
1.803 bisitz 6693: border: none;
1.589 raeburn 6694: border-collapse: collapse;
1.803 bisitz 6695: border-spacing: 0;
1.507 raeburn 6696: width: 100%;
6697: }
1.795 www 6698:
1.911 bisitz 6699: table.LC_data_table tr th,
6700: table.LC_calendar tr th,
1.879 raeburn 6701: table.LC_prior_tries tr th,
6702: table.LC_innerpickbox tr th {
1.349 albertel 6703: font-weight: bold;
6704: background-color: $data_table_head;
1.801 tempelho 6705: color:$fontmenu;
1.701 harmsja 6706: font-size:90%;
1.347 albertel 6707: }
1.795 www 6708:
1.879 raeburn 6709: table.LC_innerpickbox tr th,
6710: table.LC_innerpickbox tr td {
6711: vertical-align: top;
6712: }
6713:
1.711 raeburn 6714: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6715: background-color: #CCCCCC;
1.711 raeburn 6716: font-weight: bold;
6717: text-align: left;
6718: }
1.795 www 6719:
1.912 bisitz 6720: table.LC_data_table tr.LC_odd_row > td {
6721: background-color: $data_table_light;
6722: padding: 2px;
6723: vertical-align: top;
6724: }
6725:
1.809 bisitz 6726: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6727: background-color: $data_table_light;
1.912 bisitz 6728: vertical-align: top;
6729: }
6730:
6731: table.LC_data_table tr.LC_even_row > td {
6732: background-color: $data_table_dark;
1.425 albertel 6733: padding: 2px;
1.900 bisitz 6734: vertical-align: top;
1.347 albertel 6735: }
1.795 www 6736:
1.809 bisitz 6737: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6738: background-color: $data_table_dark;
1.900 bisitz 6739: vertical-align: top;
1.347 albertel 6740: }
1.795 www 6741:
1.425 albertel 6742: table.LC_data_table tr.LC_data_table_highlight td {
6743: background-color: $data_table_darker;
6744: }
1.795 www 6745:
1.639 raeburn 6746: table.LC_data_table tr td.LC_leftcol_header {
6747: background-color: $data_table_head;
6748: font-weight: bold;
6749: }
1.795 www 6750:
1.451 albertel 6751: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6752: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6753: font-weight: bold;
6754: font-style: italic;
6755: text-align: center;
6756: padding: 8px;
1.347 albertel 6757: }
1.795 www 6758:
1.1114 raeburn 6759: table.LC_data_table tr.LC_empty_row td,
6760: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6761: background-color: $sidebg;
6762: }
6763:
6764: table.LC_nested tr.LC_empty_row td {
6765: background-color: #FFFFFF;
6766: }
6767:
1.890 droeschl 6768: table.LC_caption {
6769: }
6770:
1.507 raeburn 6771: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6772: padding: 4ex
6773: }
1.795 www 6774:
1.507 raeburn 6775: table.LC_nested_outer tr th {
6776: font-weight: bold;
1.801 tempelho 6777: color:$fontmenu;
1.507 raeburn 6778: background-color: $data_table_head;
1.701 harmsja 6779: font-size: small;
1.507 raeburn 6780: border-bottom: 1px solid #000000;
6781: }
1.795 www 6782:
1.507 raeburn 6783: table.LC_nested_outer tr td.LC_subheader {
6784: background-color: $data_table_head;
6785: font-weight: bold;
6786: font-size: small;
6787: border-bottom: 1px solid #000000;
6788: text-align: right;
1.451 albertel 6789: }
1.795 www 6790:
1.507 raeburn 6791: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6792: background-color: #CCCCCC;
1.451 albertel 6793: font-weight: bold;
6794: font-size: small;
1.507 raeburn 6795: text-align: center;
6796: }
1.795 www 6797:
1.589 raeburn 6798: table.LC_nested tr.LC_info_row td.LC_left_item,
6799: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6800: text-align: left;
1.451 albertel 6801: }
1.795 www 6802:
1.507 raeburn 6803: table.LC_nested td {
1.735 bisitz 6804: background-color: #FFFFFF;
1.451 albertel 6805: font-size: small;
1.507 raeburn 6806: }
1.795 www 6807:
1.507 raeburn 6808: table.LC_nested_outer tr th.LC_right_item,
6809: table.LC_nested tr.LC_info_row td.LC_right_item,
6810: table.LC_nested tr.LC_odd_row td.LC_right_item,
6811: table.LC_nested tr td.LC_right_item {
1.451 albertel 6812: text-align: right;
6813: }
6814:
1.507 raeburn 6815: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6816: background-color: #EEEEEE;
1.451 albertel 6817: }
6818:
1.473 raeburn 6819: table.LC_createuser {
6820: }
6821:
6822: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6823: font-size: small;
1.473 raeburn 6824: }
6825:
6826: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6827: background-color: #CCCCCC;
1.473 raeburn 6828: font-weight: bold;
6829: text-align: center;
6830: }
6831:
1.349 albertel 6832: table.LC_calendar {
6833: border: 1px solid #000000;
6834: border-collapse: collapse;
1.917 raeburn 6835: width: 98%;
1.349 albertel 6836: }
1.795 www 6837:
1.349 albertel 6838: table.LC_calendar_pickdate {
6839: font-size: xx-small;
6840: }
1.795 www 6841:
1.349 albertel 6842: table.LC_calendar tr td {
6843: border: 1px solid #000000;
6844: vertical-align: top;
1.917 raeburn 6845: width: 14%;
1.349 albertel 6846: }
1.795 www 6847:
1.349 albertel 6848: table.LC_calendar tr td.LC_calendar_day_empty {
6849: background-color: $data_table_dark;
6850: }
1.795 www 6851:
1.779 bisitz 6852: table.LC_calendar tr td.LC_calendar_day_current {
6853: background-color: $data_table_highlight;
1.777 tempelho 6854: }
1.795 www 6855:
1.938 bisitz 6856: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6857: background-color: $mail_new;
6858: }
1.795 www 6859:
1.938 bisitz 6860: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6861: background-color: $mail_new_hover;
6862: }
1.795 www 6863:
1.938 bisitz 6864: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6865: background-color: $mail_read;
6866: }
1.795 www 6867:
1.938 bisitz 6868: /*
6869: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6870: background-color: $mail_read_hover;
6871: }
1.938 bisitz 6872: */
1.795 www 6873:
1.938 bisitz 6874: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6875: background-color: $mail_replied;
6876: }
1.795 www 6877:
1.938 bisitz 6878: /*
6879: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6880: background-color: $mail_replied_hover;
6881: }
1.938 bisitz 6882: */
1.795 www 6883:
1.938 bisitz 6884: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6885: background-color: $mail_other;
6886: }
1.795 www 6887:
1.938 bisitz 6888: /*
6889: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6890: background-color: $mail_other_hover;
6891: }
1.938 bisitz 6892: */
1.494 raeburn 6893:
1.777 tempelho 6894: table.LC_data_table tr > td.LC_browser_file,
6895: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6896: background: #AAEE77;
1.389 albertel 6897: }
1.795 www 6898:
1.777 tempelho 6899: table.LC_data_table tr > td.LC_browser_file_locked,
6900: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6901: background: #FFAA99;
1.387 albertel 6902: }
1.795 www 6903:
1.777 tempelho 6904: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6905: background: #888888;
1.779 bisitz 6906: }
1.795 www 6907:
1.777 tempelho 6908: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6909: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6910: background: #F8F866;
1.777 tempelho 6911: }
1.795 www 6912:
1.696 bisitz 6913: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6914: background: #E0E8FF;
1.387 albertel 6915: }
1.696 bisitz 6916:
1.707 bisitz 6917: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6918: /* background: #77FF77; */
1.707 bisitz 6919: }
1.795 www 6920:
1.707 bisitz 6921: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6922: border-right: 8px solid #FFFF77;
1.707 bisitz 6923: }
1.795 www 6924:
1.707 bisitz 6925: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6926: border-right: 8px solid #FFAA77;
1.707 bisitz 6927: }
1.795 www 6928:
1.707 bisitz 6929: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6930: border-right: 8px solid #FF7777;
1.707 bisitz 6931: }
1.795 www 6932:
1.707 bisitz 6933: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6934: border-right: 8px solid #AAFF77;
1.707 bisitz 6935: }
1.795 www 6936:
1.707 bisitz 6937: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6938: border-right: 8px solid #11CC55;
1.707 bisitz 6939: }
6940:
1.388 albertel 6941: span.LC_current_location {
1.701 harmsja 6942: font-size:larger;
1.388 albertel 6943: background: $pgbg;
6944: }
1.387 albertel 6945:
1.1029 www 6946: span.LC_current_nav_location {
6947: font-weight:bold;
6948: background: $sidebg;
6949: }
6950:
1.395 albertel 6951: span.LC_parm_menu_item {
6952: font-size: larger;
6953: }
1.795 www 6954:
1.395 albertel 6955: span.LC_parm_scope_all {
6956: color: red;
6957: }
1.795 www 6958:
1.395 albertel 6959: span.LC_parm_scope_folder {
6960: color: green;
6961: }
1.795 www 6962:
1.395 albertel 6963: span.LC_parm_scope_resource {
6964: color: orange;
6965: }
1.795 www 6966:
1.395 albertel 6967: span.LC_parm_part {
6968: color: blue;
6969: }
1.795 www 6970:
1.911 bisitz 6971: span.LC_parm_folder,
6972: span.LC_parm_symb {
1.395 albertel 6973: font-size: x-small;
6974: font-family: $mono;
6975: color: #AAAAAA;
6976: }
6977:
1.977 bisitz 6978: ul.LC_parm_parmlist li {
6979: display: inline-block;
6980: padding: 0.3em 0.8em;
6981: vertical-align: top;
6982: width: 150px;
6983: border-top:1px solid $lg_border_color;
6984: }
6985:
1.795 www 6986: td.LC_parm_overview_level_menu,
6987: td.LC_parm_overview_map_menu,
6988: td.LC_parm_overview_parm_selectors,
6989: td.LC_parm_overview_restrictions {
1.396 albertel 6990: border: 1px solid black;
6991: border-collapse: collapse;
6992: }
1.795 www 6993:
1.1285 raeburn 6994: span.LC_parm_recursive,
6995: td.LC_parm_recursive {
6996: font-weight: bold;
6997: font-size: smaller;
6998: }
6999:
1.396 albertel 7000: table.LC_parm_overview_restrictions td {
7001: border-width: 1px 4px 1px 4px;
7002: border-style: solid;
7003: border-color: $pgbg;
7004: text-align: center;
7005: }
1.795 www 7006:
1.396 albertel 7007: table.LC_parm_overview_restrictions th {
7008: background: $tabbg;
7009: border-width: 1px 4px 1px 4px;
7010: border-style: solid;
7011: border-color: $pgbg;
7012: }
1.795 www 7013:
1.398 albertel 7014: table#LC_helpmenu {
1.803 bisitz 7015: border: none;
1.398 albertel 7016: height: 55px;
1.803 bisitz 7017: border-spacing: 0;
1.398 albertel 7018: }
7019:
7020: table#LC_helpmenu fieldset legend {
7021: font-size: larger;
7022: }
1.795 www 7023:
1.397 albertel 7024: table#LC_helpmenu_links {
7025: width: 100%;
7026: border: 1px solid black;
7027: background: $pgbg;
1.803 bisitz 7028: padding: 0;
1.397 albertel 7029: border-spacing: 1px;
7030: }
1.795 www 7031:
1.397 albertel 7032: table#LC_helpmenu_links tr td {
7033: padding: 1px;
7034: background: $tabbg;
1.399 albertel 7035: text-align: center;
7036: font-weight: bold;
1.397 albertel 7037: }
1.396 albertel 7038:
1.795 www 7039: table#LC_helpmenu_links a:link,
7040: table#LC_helpmenu_links a:visited,
1.397 albertel 7041: table#LC_helpmenu_links a:active {
7042: text-decoration: none;
7043: color: $font;
7044: }
1.795 www 7045:
1.397 albertel 7046: table#LC_helpmenu_links a:hover {
7047: text-decoration: underline;
7048: color: $vlink;
7049: }
1.396 albertel 7050:
1.417 albertel 7051: .LC_chrt_popup_exists {
7052: border: 1px solid #339933;
7053: margin: -1px;
7054: }
1.795 www 7055:
1.417 albertel 7056: .LC_chrt_popup_up {
7057: border: 1px solid yellow;
7058: margin: -1px;
7059: }
1.795 www 7060:
1.417 albertel 7061: .LC_chrt_popup {
7062: border: 1px solid #8888FF;
7063: background: #CCCCFF;
7064: }
1.795 www 7065:
1.421 albertel 7066: table.LC_pick_box {
7067: border-collapse: separate;
7068: background: white;
7069: border: 1px solid black;
7070: border-spacing: 1px;
7071: }
1.795 www 7072:
1.421 albertel 7073: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7074: background: $sidebg;
1.421 albertel 7075: font-weight: bold;
1.900 bisitz 7076: text-align: left;
1.740 bisitz 7077: vertical-align: top;
1.421 albertel 7078: width: 184px;
7079: padding: 8px;
7080: }
1.795 www 7081:
1.579 raeburn 7082: table.LC_pick_box td.LC_pick_box_value {
7083: text-align: left;
7084: padding: 8px;
7085: }
1.795 www 7086:
1.579 raeburn 7087: table.LC_pick_box td.LC_pick_box_select {
7088: text-align: left;
7089: padding: 8px;
7090: }
1.795 www 7091:
1.424 albertel 7092: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7093: padding: 0;
1.421 albertel 7094: height: 1px;
7095: background: black;
7096: }
1.795 www 7097:
1.421 albertel 7098: table.LC_pick_box td.LC_pick_box_submit {
7099: text-align: right;
7100: }
1.795 www 7101:
1.579 raeburn 7102: table.LC_pick_box td.LC_evenrow_value {
7103: text-align: left;
7104: padding: 8px;
7105: background-color: $data_table_light;
7106: }
1.795 www 7107:
1.579 raeburn 7108: table.LC_pick_box td.LC_oddrow_value {
7109: text-align: left;
7110: padding: 8px;
7111: background-color: $data_table_light;
7112: }
1.795 www 7113:
1.579 raeburn 7114: span.LC_helpform_receipt_cat {
7115: font-weight: bold;
7116: }
1.795 www 7117:
1.424 albertel 7118: table.LC_group_priv_box {
7119: background: white;
7120: border: 1px solid black;
7121: border-spacing: 1px;
7122: }
1.795 www 7123:
1.424 albertel 7124: table.LC_group_priv_box td.LC_pick_box_title {
7125: background: $tabbg;
7126: font-weight: bold;
7127: text-align: right;
7128: width: 184px;
7129: }
1.795 www 7130:
1.424 albertel 7131: table.LC_group_priv_box td.LC_groups_fixed {
7132: background: $data_table_light;
7133: text-align: center;
7134: }
1.795 www 7135:
1.424 albertel 7136: table.LC_group_priv_box td.LC_groups_optional {
7137: background: $data_table_dark;
7138: text-align: center;
7139: }
1.795 www 7140:
1.424 albertel 7141: table.LC_group_priv_box td.LC_groups_functionality {
7142: background: $data_table_darker;
7143: text-align: center;
7144: font-weight: bold;
7145: }
1.795 www 7146:
1.424 albertel 7147: table.LC_group_priv td {
7148: text-align: left;
1.803 bisitz 7149: padding: 0;
1.424 albertel 7150: }
7151:
7152: .LC_navbuttons {
7153: margin: 2ex 0ex 2ex 0ex;
7154: }
1.795 www 7155:
1.423 albertel 7156: .LC_topic_bar {
7157: font-weight: bold;
7158: background: $tabbg;
1.918 wenzelju 7159: margin: 1em 0em 1em 2em;
1.805 bisitz 7160: padding: 3px;
1.918 wenzelju 7161: font-size: 1.2em;
1.423 albertel 7162: }
1.795 www 7163:
1.423 albertel 7164: .LC_topic_bar span {
1.918 wenzelju 7165: left: 0.5em;
7166: position: absolute;
1.423 albertel 7167: vertical-align: middle;
1.918 wenzelju 7168: font-size: 1.2em;
1.423 albertel 7169: }
1.795 www 7170:
1.423 albertel 7171: table.LC_course_group_status {
7172: margin: 20px;
7173: }
1.795 www 7174:
1.423 albertel 7175: table.LC_status_selector td {
7176: vertical-align: top;
7177: text-align: center;
1.424 albertel 7178: padding: 4px;
7179: }
1.795 www 7180:
1.599 albertel 7181: div.LC_feedback_link {
1.616 albertel 7182: clear: both;
1.829 kalberla 7183: background: $sidebg;
1.779 bisitz 7184: width: 100%;
1.829 kalberla 7185: padding-bottom: 10px;
7186: border: 1px $tabbg solid;
1.833 kalberla 7187: height: 22px;
7188: line-height: 22px;
7189: padding-top: 5px;
7190: }
7191:
7192: div.LC_feedback_link img {
7193: height: 22px;
1.867 kalberla 7194: vertical-align:middle;
1.829 kalberla 7195: }
7196:
1.911 bisitz 7197: div.LC_feedback_link a {
1.829 kalberla 7198: text-decoration: none;
1.489 raeburn 7199: }
1.795 www 7200:
1.867 kalberla 7201: div.LC_comblock {
1.911 bisitz 7202: display:inline;
1.867 kalberla 7203: color:$font;
7204: font-size:90%;
7205: }
7206:
7207: div.LC_feedback_link div.LC_comblock {
7208: padding-left:5px;
7209: }
7210:
7211: div.LC_feedback_link div.LC_comblock a {
7212: color:$font;
7213: }
7214:
1.489 raeburn 7215: span.LC_feedback_link {
1.858 bisitz 7216: /* background: $feedback_link_bg; */
1.599 albertel 7217: font-size: larger;
7218: }
1.795 www 7219:
1.599 albertel 7220: span.LC_message_link {
1.858 bisitz 7221: /* background: $feedback_link_bg; */
1.599 albertel 7222: font-size: larger;
7223: position: absolute;
7224: right: 1em;
1.489 raeburn 7225: }
1.421 albertel 7226:
1.515 albertel 7227: table.LC_prior_tries {
1.524 albertel 7228: border: 1px solid #000000;
7229: border-collapse: separate;
7230: border-spacing: 1px;
1.515 albertel 7231: }
1.523 albertel 7232:
1.515 albertel 7233: table.LC_prior_tries td {
1.524 albertel 7234: padding: 2px;
1.515 albertel 7235: }
1.523 albertel 7236:
7237: .LC_answer_correct {
1.795 www 7238: background: lightgreen;
7239: color: darkgreen;
7240: padding: 6px;
1.523 albertel 7241: }
1.795 www 7242:
1.523 albertel 7243: .LC_answer_charged_try {
1.797 www 7244: background: #FFAAAA;
1.795 www 7245: color: darkred;
7246: padding: 6px;
1.523 albertel 7247: }
1.795 www 7248:
1.779 bisitz 7249: .LC_answer_not_charged_try,
1.523 albertel 7250: .LC_answer_no_grade,
7251: .LC_answer_late {
1.795 www 7252: background: lightyellow;
1.523 albertel 7253: color: black;
1.795 www 7254: padding: 6px;
1.523 albertel 7255: }
1.795 www 7256:
1.523 albertel 7257: .LC_answer_previous {
1.795 www 7258: background: lightblue;
7259: color: darkblue;
7260: padding: 6px;
1.523 albertel 7261: }
1.795 www 7262:
1.779 bisitz 7263: .LC_answer_no_message {
1.777 tempelho 7264: background: #FFFFFF;
7265: color: black;
1.795 www 7266: padding: 6px;
1.779 bisitz 7267: }
1.795 www 7268:
1.1334 raeburn 7269: .LC_answer_unknown,
7270: .LC_answer_warning {
1.779 bisitz 7271: background: orange;
7272: color: black;
1.795 www 7273: padding: 6px;
1.777 tempelho 7274: }
1.795 www 7275:
1.529 albertel 7276: span.LC_prior_numerical,
7277: span.LC_prior_string,
7278: span.LC_prior_custom,
7279: span.LC_prior_reaction,
7280: span.LC_prior_math {
1.925 bisitz 7281: font-family: $mono;
1.523 albertel 7282: white-space: pre;
7283: }
7284:
1.525 albertel 7285: span.LC_prior_string {
1.925 bisitz 7286: font-family: $mono;
1.525 albertel 7287: white-space: pre;
7288: }
7289:
1.523 albertel 7290: table.LC_prior_option {
7291: width: 100%;
7292: border-collapse: collapse;
7293: }
1.795 www 7294:
1.911 bisitz 7295: table.LC_prior_rank,
1.795 www 7296: table.LC_prior_match {
1.528 albertel 7297: border-collapse: collapse;
7298: }
1.795 www 7299:
1.528 albertel 7300: table.LC_prior_option tr td,
7301: table.LC_prior_rank tr td,
7302: table.LC_prior_match tr td {
1.524 albertel 7303: border: 1px solid #000000;
1.515 albertel 7304: }
7305:
1.855 bisitz 7306: .LC_nobreak {
1.544 albertel 7307: white-space: nowrap;
1.519 raeburn 7308: }
7309:
1.576 raeburn 7310: span.LC_cusr_emph {
7311: font-style: italic;
7312: }
7313:
1.633 raeburn 7314: span.LC_cusr_subheading {
7315: font-weight: normal;
7316: font-size: 85%;
7317: }
7318:
1.861 bisitz 7319: div.LC_docs_entry_move {
1.859 bisitz 7320: border: 1px solid #BBBBBB;
1.545 albertel 7321: background: #DDDDDD;
1.861 bisitz 7322: width: 22px;
1.859 bisitz 7323: padding: 1px;
7324: margin: 0;
1.545 albertel 7325: }
7326:
1.861 bisitz 7327: table.LC_data_table tr > td.LC_docs_entry_commands,
7328: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7329: font-size: x-small;
7330: }
1.795 www 7331:
1.861 bisitz 7332: .LC_docs_entry_parameter {
7333: white-space: nowrap;
7334: }
7335:
1.544 albertel 7336: .LC_docs_copy {
1.545 albertel 7337: color: #000099;
1.544 albertel 7338: }
1.795 www 7339:
1.544 albertel 7340: .LC_docs_cut {
1.545 albertel 7341: color: #550044;
1.544 albertel 7342: }
1.795 www 7343:
1.544 albertel 7344: .LC_docs_rename {
1.545 albertel 7345: color: #009900;
1.544 albertel 7346: }
1.795 www 7347:
1.544 albertel 7348: .LC_docs_remove {
1.545 albertel 7349: color: #990000;
7350: }
7351:
1.1284 raeburn 7352: .LC_docs_alias {
7353: color: #440055;
7354: }
7355:
1.1286 raeburn 7356: .LC_domprefs_email,
1.1284 raeburn 7357: .LC_docs_alias_name,
1.547 albertel 7358: .LC_docs_reinit_warn,
7359: .LC_docs_ext_edit {
7360: font-size: x-small;
7361: }
7362:
1.545 albertel 7363: table.LC_docs_adddocs td,
7364: table.LC_docs_adddocs th {
7365: border: 1px solid #BBBBBB;
7366: padding: 4px;
7367: background: #DDDDDD;
1.543 albertel 7368: }
7369:
1.584 albertel 7370: table.LC_sty_begin {
7371: background: #BBFFBB;
7372: }
1.795 www 7373:
1.584 albertel 7374: table.LC_sty_end {
7375: background: #FFBBBB;
7376: }
7377:
1.589 raeburn 7378: table.LC_double_column {
1.803 bisitz 7379: border-width: 0;
1.589 raeburn 7380: border-collapse: collapse;
7381: width: 100%;
7382: padding: 2px;
7383: }
7384:
7385: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7386: top: 2px;
1.589 raeburn 7387: left: 2px;
7388: width: 47%;
7389: vertical-align: top;
7390: }
7391:
7392: table.LC_double_column tr td.LC_right_col {
7393: top: 2px;
1.779 bisitz 7394: right: 2px;
1.589 raeburn 7395: width: 47%;
7396: vertical-align: top;
7397: }
7398:
1.591 raeburn 7399: div.LC_left_float {
7400: float: left;
7401: padding-right: 5%;
1.597 albertel 7402: padding-bottom: 4px;
1.591 raeburn 7403: }
7404:
7405: div.LC_clear_float_header {
1.597 albertel 7406: padding-bottom: 2px;
1.591 raeburn 7407: }
7408:
7409: div.LC_clear_float_footer {
1.597 albertel 7410: padding-top: 10px;
1.591 raeburn 7411: clear: both;
7412: }
7413:
1.597 albertel 7414: div.LC_grade_show_user {
1.941 bisitz 7415: /* border-left: 5px solid $sidebg; */
7416: border-top: 5px solid #000000;
7417: margin: 50px 0 0 0;
1.936 bisitz 7418: padding: 15px 0 5px 10px;
1.597 albertel 7419: }
1.795 www 7420:
1.936 bisitz 7421: div.LC_grade_show_user_odd_row {
1.941 bisitz 7422: /* border-left: 5px solid #000000; */
7423: }
7424:
7425: div.LC_grade_show_user div.LC_Box {
7426: margin-right: 50px;
1.597 albertel 7427: }
7428:
7429: div.LC_grade_submissions,
7430: div.LC_grade_message_center,
1.936 bisitz 7431: div.LC_grade_info_links {
1.597 albertel 7432: margin: 5px;
7433: width: 99%;
7434: background: #FFFFFF;
7435: }
1.795 www 7436:
1.597 albertel 7437: div.LC_grade_submissions_header,
1.936 bisitz 7438: div.LC_grade_message_center_header {
1.705 tempelho 7439: font-weight: bold;
7440: font-size: large;
1.597 albertel 7441: }
1.795 www 7442:
1.597 albertel 7443: div.LC_grade_submissions_body,
1.936 bisitz 7444: div.LC_grade_message_center_body {
1.597 albertel 7445: border: 1px solid black;
7446: width: 99%;
7447: background: #FFFFFF;
7448: }
1.795 www 7449:
1.613 albertel 7450: table.LC_scantron_action {
7451: width: 100%;
7452: }
1.795 www 7453:
1.613 albertel 7454: table.LC_scantron_action tr th {
1.698 harmsja 7455: font-weight:bold;
7456: font-style:normal;
1.613 albertel 7457: }
1.795 www 7458:
1.779 bisitz 7459: .LC_edit_problem_header,
1.614 albertel 7460: div.LC_edit_problem_footer {
1.705 tempelho 7461: font-weight: normal;
7462: font-size: medium;
1.602 albertel 7463: margin: 2px;
1.1060 bisitz 7464: background-color: $sidebg;
1.600 albertel 7465: }
1.795 www 7466:
1.600 albertel 7467: div.LC_edit_problem_header,
1.602 albertel 7468: div.LC_edit_problem_header div,
1.614 albertel 7469: div.LC_edit_problem_footer,
7470: div.LC_edit_problem_footer div,
1.602 albertel 7471: div.LC_edit_problem_editxml_header,
7472: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7473: z-index: 100;
1.600 albertel 7474: }
1.795 www 7475:
1.600 albertel 7476: div.LC_edit_problem_header_title {
1.705 tempelho 7477: font-weight: bold;
7478: font-size: larger;
1.602 albertel 7479: background: $tabbg;
7480: padding: 3px;
1.1060 bisitz 7481: margin: 0 0 5px 0;
1.602 albertel 7482: }
1.795 www 7483:
1.602 albertel 7484: table.LC_edit_problem_header_title {
7485: width: 100%;
1.600 albertel 7486: background: $tabbg;
1.602 albertel 7487: }
7488:
1.1205 golterma 7489: div.LC_edit_actionbar {
7490: background-color: $sidebg;
1.1218 droeschl 7491: margin: 0;
7492: padding: 0;
7493: line-height: 200%;
1.602 albertel 7494: }
1.795 www 7495:
1.1218 droeschl 7496: div.LC_edit_actionbar div{
7497: padding: 0;
7498: margin: 0;
7499: display: inline-block;
1.600 albertel 7500: }
1.795 www 7501:
1.1124 bisitz 7502: .LC_edit_opt {
7503: padding-left: 1em;
7504: white-space: nowrap;
7505: }
7506:
1.1152 golterma 7507: .LC_edit_problem_latexhelper{
7508: text-align: right;
7509: }
7510:
7511: #LC_edit_problem_colorful div{
7512: margin-left: 40px;
7513: }
7514:
1.1205 golterma 7515: #LC_edit_problem_codemirror div{
7516: margin-left: 0px;
7517: }
7518:
1.911 bisitz 7519: img.stift {
1.803 bisitz 7520: border-width: 0;
7521: vertical-align: middle;
1.677 riegler 7522: }
1.680 riegler 7523:
1.923 bisitz 7524: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7525: vertical-align: top;
1.777 tempelho 7526: }
1.795 www 7527:
1.716 raeburn 7528: div.LC_createcourse {
1.911 bisitz 7529: margin: 10px 10px 10px 10px;
1.716 raeburn 7530: }
7531:
1.917 raeburn 7532: .LC_dccid {
1.1130 raeburn 7533: float: right;
1.917 raeburn 7534: margin: 0.2em 0 0 0;
7535: padding: 0;
7536: font-size: 90%;
7537: display:none;
7538: }
7539:
1.897 wenzelju 7540: ol.LC_primary_menu a:hover,
1.721 harmsja 7541: ol#LC_MenuBreadcrumbs a:hover,
7542: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7543: ul#LC_secondary_menu a:hover,
1.721 harmsja 7544: .LC_FormSectionClearButton input:hover
1.795 www 7545: ul.LC_TabContent li:hover a {
1.952 onken 7546: color:$button_hover;
1.911 bisitz 7547: text-decoration:none;
1.693 droeschl 7548: }
7549:
1.779 bisitz 7550: h1 {
1.911 bisitz 7551: padding: 0;
7552: line-height:130%;
1.693 droeschl 7553: }
1.698 harmsja 7554:
1.911 bisitz 7555: h2,
7556: h3,
7557: h4,
7558: h5,
7559: h6 {
7560: margin: 5px 0 5px 0;
7561: padding: 0;
7562: line-height:130%;
1.693 droeschl 7563: }
1.795 www 7564:
7565: .LC_hcell {
1.911 bisitz 7566: padding:3px 15px 3px 15px;
7567: margin: 0;
7568: background-color:$tabbg;
7569: color:$fontmenu;
7570: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7571: }
1.795 www 7572:
1.840 bisitz 7573: .LC_Box > .LC_hcell {
1.911 bisitz 7574: margin: 0 -10px 10px -10px;
1.835 bisitz 7575: }
7576:
1.721 harmsja 7577: .LC_noBorder {
1.911 bisitz 7578: border: 0;
1.698 harmsja 7579: }
1.693 droeschl 7580:
1.721 harmsja 7581: .LC_FormSectionClearButton input {
1.911 bisitz 7582: background-color:transparent;
7583: border: none;
7584: cursor:pointer;
7585: text-decoration:underline;
1.693 droeschl 7586: }
1.763 bisitz 7587:
7588: .LC_help_open_topic {
1.911 bisitz 7589: color: #FFFFFF;
7590: background-color: #EEEEFF;
7591: margin: 1px;
7592: padding: 4px;
7593: border: 1px solid #000033;
7594: white-space: nowrap;
7595: /* vertical-align: middle; */
1.759 neumanie 7596: }
1.693 droeschl 7597:
1.911 bisitz 7598: dl,
7599: ul,
7600: div,
7601: fieldset {
7602: margin: 10px 10px 10px 0;
7603: /* overflow: hidden; */
1.693 droeschl 7604: }
1.795 www 7605:
1.1211 raeburn 7606: article.geogebraweb div {
7607: margin: 0;
7608: }
7609:
1.838 bisitz 7610: fieldset > legend {
1.911 bisitz 7611: font-weight: bold;
7612: padding: 0 5px 0 5px;
1.838 bisitz 7613: }
7614:
1.813 bisitz 7615: #LC_nav_bar {
1.911 bisitz 7616: float: left;
1.995 raeburn 7617: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7618: margin: 0 0 2px 0;
1.807 droeschl 7619: }
7620:
1.916 droeschl 7621: #LC_realm {
7622: margin: 0.2em 0 0 0;
7623: padding: 0;
7624: font-weight: bold;
7625: text-align: center;
1.995 raeburn 7626: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7627: }
7628:
1.911 bisitz 7629: #LC_nav_bar em {
7630: font-weight: bold;
7631: font-style: normal;
1.807 droeschl 7632: }
7633:
1.897 wenzelju 7634: ol.LC_primary_menu {
1.934 droeschl 7635: margin: 0;
1.1076 raeburn 7636: padding: 0;
1.807 droeschl 7637: }
7638:
1.852 droeschl 7639: ol#LC_PathBreadcrumbs {
1.911 bisitz 7640: margin: 0;
1.693 droeschl 7641: }
7642:
1.897 wenzelju 7643: ol.LC_primary_menu li {
1.1076 raeburn 7644: color: RGB(80, 80, 80);
7645: vertical-align: middle;
7646: text-align: left;
7647: list-style: none;
1.1205 golterma 7648: position: relative;
1.1076 raeburn 7649: float: left;
1.1205 golterma 7650: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7651: line-height: 1.5em;
1.1076 raeburn 7652: }
7653:
1.1205 golterma 7654: ol.LC_primary_menu li a,
7655: ol.LC_primary_menu li p {
1.1076 raeburn 7656: display: block;
7657: margin: 0;
7658: padding: 0 5px 0 10px;
7659: text-decoration: none;
7660: }
7661:
1.1205 golterma 7662: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7663: display: inline-block;
7664: width: 95%;
7665: text-align: left;
7666: }
7667:
7668: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7669: display: inline-block;
7670: width: 5%;
7671: float: right;
7672: text-align: right;
7673: font-size: 70%;
7674: }
7675:
7676: ol.LC_primary_menu ul {
1.1076 raeburn 7677: display: none;
1.1205 golterma 7678: width: 15em;
1.1076 raeburn 7679: background-color: $data_table_light;
1.1205 golterma 7680: position: absolute;
7681: top: 100%;
1.1076 raeburn 7682: }
7683:
1.1205 golterma 7684: ol.LC_primary_menu ul ul {
7685: left: 100%;
7686: top: 0;
7687: }
7688:
7689: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7690: display: block;
7691: position: absolute;
7692: margin: 0;
7693: padding: 0;
1.1078 raeburn 7694: z-index: 2;
1.1076 raeburn 7695: }
7696:
7697: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7698: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7699: font-size: 90%;
1.911 bisitz 7700: vertical-align: top;
1.1076 raeburn 7701: float: none;
1.1079 raeburn 7702: border-left: 1px solid black;
7703: border-right: 1px solid black;
1.1205 golterma 7704: /* A dark bottom border to visualize different menu options;
7705: overwritten in the create_submenu routine for the last border-bottom of the menu */
7706: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7707: }
7708:
1.1205 golterma 7709: ol.LC_primary_menu li li p:hover {
7710: color:$button_hover;
7711: text-decoration:none;
7712: background-color:$data_table_dark;
1.1076 raeburn 7713: }
7714:
7715: ol.LC_primary_menu li li a:hover {
7716: color:$button_hover;
7717: background-color:$data_table_dark;
1.693 droeschl 7718: }
7719:
1.1205 golterma 7720: /* Font-size equal to the size of the predecessors*/
7721: ol.LC_primary_menu li:hover li li {
7722: font-size: 100%;
7723: }
7724:
1.897 wenzelju 7725: ol.LC_primary_menu li img {
1.911 bisitz 7726: vertical-align: bottom;
1.934 droeschl 7727: height: 1.1em;
1.1077 raeburn 7728: margin: 0.2em 0 0 0;
1.693 droeschl 7729: }
7730:
1.897 wenzelju 7731: ol.LC_primary_menu a {
1.911 bisitz 7732: color: RGB(80, 80, 80);
7733: text-decoration: none;
1.693 droeschl 7734: }
1.795 www 7735:
1.949 droeschl 7736: ol.LC_primary_menu a.LC_new_message {
7737: font-weight:bold;
7738: color: darkred;
7739: }
7740:
1.975 raeburn 7741: ol.LC_docs_parameters {
7742: margin-left: 0;
7743: padding: 0;
7744: list-style: none;
7745: }
7746:
7747: ol.LC_docs_parameters li {
7748: margin: 0;
7749: padding-right: 20px;
7750: display: inline;
7751: }
7752:
1.976 raeburn 7753: ol.LC_docs_parameters li:before {
7754: content: "\\002022 \\0020";
7755: }
7756:
7757: li.LC_docs_parameters_title {
7758: font-weight: bold;
7759: }
7760:
7761: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7762: content: "";
7763: }
7764:
1.897 wenzelju 7765: ul#LC_secondary_menu {
1.1107 raeburn 7766: clear: right;
1.911 bisitz 7767: color: $fontmenu;
7768: background: $tabbg;
7769: list-style: none;
7770: padding: 0;
7771: margin: 0;
7772: width: 100%;
1.995 raeburn 7773: text-align: left;
1.1107 raeburn 7774: float: left;
1.808 droeschl 7775: }
7776:
1.897 wenzelju 7777: ul#LC_secondary_menu li {
1.911 bisitz 7778: font-weight: bold;
7779: line-height: 1.8em;
1.1107 raeburn 7780: border-right: 1px solid black;
7781: float: left;
7782: }
7783:
7784: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7785: background-color: $data_table_light;
7786: }
7787:
7788: ul#LC_secondary_menu li a {
1.911 bisitz 7789: padding: 0 0.8em;
1.1107 raeburn 7790: }
7791:
7792: ul#LC_secondary_menu li ul {
7793: display: none;
7794: }
7795:
7796: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7797: display: block;
7798: position: absolute;
7799: margin: 0;
7800: padding: 0;
7801: list-style:none;
7802: float: none;
7803: background-color: $data_table_light;
7804: z-index: 2;
7805: margin-left: -1px;
7806: }
7807:
7808: ul#LC_secondary_menu li ul li {
7809: font-size: 90%;
7810: vertical-align: top;
7811: border-left: 1px solid black;
1.911 bisitz 7812: border-right: 1px solid black;
1.1119 raeburn 7813: background-color: $data_table_light;
1.1107 raeburn 7814: list-style:none;
7815: float: none;
7816: }
7817:
7818: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7819: background-color: $data_table_dark;
1.807 droeschl 7820: }
7821:
1.847 tempelho 7822: ul.LC_TabContent {
1.911 bisitz 7823: display:block;
7824: background: $sidebg;
7825: border-bottom: solid 1px $lg_border_color;
7826: list-style:none;
1.1020 raeburn 7827: margin: -1px -10px 0 -10px;
1.911 bisitz 7828: padding: 0;
1.693 droeschl 7829: }
7830:
1.795 www 7831: ul.LC_TabContent li,
7832: ul.LC_TabContentBigger li {
1.911 bisitz 7833: float:left;
1.741 harmsja 7834: }
1.795 www 7835:
1.897 wenzelju 7836: ul#LC_secondary_menu li a {
1.911 bisitz 7837: color: $fontmenu;
7838: text-decoration: none;
1.693 droeschl 7839: }
1.795 www 7840:
1.721 harmsja 7841: ul.LC_TabContent {
1.952 onken 7842: min-height:20px;
1.721 harmsja 7843: }
1.795 www 7844:
7845: ul.LC_TabContent li {
1.911 bisitz 7846: vertical-align:middle;
1.959 onken 7847: padding: 0 16px 0 10px;
1.911 bisitz 7848: background-color:$tabbg;
7849: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7850: border-left: solid 1px $font;
1.721 harmsja 7851: }
1.795 www 7852:
1.847 tempelho 7853: ul.LC_TabContent .right {
1.911 bisitz 7854: float:right;
1.847 tempelho 7855: }
7856:
1.911 bisitz 7857: ul.LC_TabContent li a,
7858: ul.LC_TabContent li {
7859: color:rgb(47,47,47);
7860: text-decoration:none;
7861: font-size:95%;
7862: font-weight:bold;
1.952 onken 7863: min-height:20px;
7864: }
7865:
1.959 onken 7866: ul.LC_TabContent li a:hover,
7867: ul.LC_TabContent li a:focus {
1.952 onken 7868: color: $button_hover;
1.959 onken 7869: background:none;
7870: outline:none;
1.952 onken 7871: }
7872:
7873: ul.LC_TabContent li:hover {
7874: color: $button_hover;
7875: cursor:pointer;
1.721 harmsja 7876: }
1.795 www 7877:
1.911 bisitz 7878: ul.LC_TabContent li.active {
1.952 onken 7879: color: $font;
1.911 bisitz 7880: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7881: border-bottom:solid 1px #FFFFFF;
7882: cursor: default;
1.744 ehlerst 7883: }
1.795 www 7884:
1.959 onken 7885: ul.LC_TabContent li.active a {
7886: color:$font;
7887: background:#FFFFFF;
7888: outline: none;
7889: }
1.1047 raeburn 7890:
7891: ul.LC_TabContent li.goback {
7892: float: left;
7893: border-left: none;
7894: }
7895:
1.870 tempelho 7896: #maincoursedoc {
1.911 bisitz 7897: clear:both;
1.870 tempelho 7898: }
7899:
7900: ul.LC_TabContentBigger {
1.911 bisitz 7901: display:block;
7902: list-style:none;
7903: padding: 0;
1.870 tempelho 7904: }
7905:
1.795 www 7906: ul.LC_TabContentBigger li {
1.911 bisitz 7907: vertical-align:bottom;
7908: height: 30px;
7909: font-size:110%;
7910: font-weight:bold;
7911: color: #737373;
1.841 tempelho 7912: }
7913:
1.957 onken 7914: ul.LC_TabContentBigger li.active {
7915: position: relative;
7916: top: 1px;
7917: }
7918:
1.870 tempelho 7919: ul.LC_TabContentBigger li a {
1.911 bisitz 7920: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7921: height: 30px;
7922: line-height: 30px;
7923: text-align: center;
7924: display: block;
7925: text-decoration: none;
1.958 onken 7926: outline: none;
1.741 harmsja 7927: }
1.795 www 7928:
1.870 tempelho 7929: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7930: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7931: color:$font;
1.744 ehlerst 7932: }
1.795 www 7933:
1.870 tempelho 7934: ul.LC_TabContentBigger li b {
1.911 bisitz 7935: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7936: display: block;
7937: float: left;
7938: padding: 0 30px;
1.957 onken 7939: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7940: }
7941:
1.956 onken 7942: ul.LC_TabContentBigger li:hover b {
7943: color:$button_hover;
7944: }
7945:
1.870 tempelho 7946: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7947: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7948: color:$font;
1.957 onken 7949: border: 0;
1.741 harmsja 7950: }
1.693 droeschl 7951:
1.870 tempelho 7952:
1.862 bisitz 7953: ul.LC_CourseBreadcrumbs {
7954: background: $sidebg;
1.1020 raeburn 7955: height: 2em;
1.862 bisitz 7956: padding-left: 10px;
1.1020 raeburn 7957: margin: 0;
1.862 bisitz 7958: list-style-position: inside;
7959: }
7960:
1.911 bisitz 7961: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7962: ol#LC_PathBreadcrumbs {
1.911 bisitz 7963: padding-left: 10px;
7964: margin: 0;
1.933 droeschl 7965: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7966: }
7967:
1.911 bisitz 7968: ol#LC_MenuBreadcrumbs li,
7969: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7970: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7971: display: inline;
1.933 droeschl 7972: white-space: normal;
1.693 droeschl 7973: }
7974:
1.823 bisitz 7975: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7976: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7977: text-decoration: none;
7978: font-size:90%;
1.693 droeschl 7979: }
1.795 www 7980:
1.969 droeschl 7981: ol#LC_MenuBreadcrumbs h1 {
7982: display: inline;
7983: font-size: 90%;
7984: line-height: 2.5em;
7985: margin: 0;
7986: padding: 0;
7987: }
7988:
1.795 www 7989: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7990: text-decoration:none;
7991: font-size:100%;
7992: font-weight:bold;
1.693 droeschl 7993: }
1.795 www 7994:
1.840 bisitz 7995: .LC_Box {
1.911 bisitz 7996: border: solid 1px $lg_border_color;
7997: padding: 0 10px 10px 10px;
1.746 neumanie 7998: }
1.795 www 7999:
1.1020 raeburn 8000: .LC_DocsBox {
8001: border: solid 1px $lg_border_color;
8002: padding: 0 0 10px 10px;
8003: }
8004:
1.795 www 8005: .LC_AboutMe_Image {
1.911 bisitz 8006: float:left;
8007: margin-right:10px;
1.747 neumanie 8008: }
1.795 www 8009:
8010: .LC_Clear_AboutMe_Image {
1.911 bisitz 8011: clear:left;
1.747 neumanie 8012: }
1.795 www 8013:
1.721 harmsja 8014: dl.LC_ListStyleClean dt {
1.911 bisitz 8015: padding-right: 5px;
8016: display: table-header-group;
1.693 droeschl 8017: }
8018:
1.721 harmsja 8019: dl.LC_ListStyleClean dd {
1.911 bisitz 8020: display: table-row;
1.693 droeschl 8021: }
8022:
1.721 harmsja 8023: .LC_ListStyleClean,
8024: .LC_ListStyleSimple,
8025: .LC_ListStyleNormal,
1.795 www 8026: .LC_ListStyleSpecial {
1.911 bisitz 8027: /* display:block; */
8028: list-style-position: inside;
8029: list-style-type: none;
8030: overflow: hidden;
8031: padding: 0;
1.693 droeschl 8032: }
8033:
1.721 harmsja 8034: .LC_ListStyleSimple li,
8035: .LC_ListStyleSimple dd,
8036: .LC_ListStyleNormal li,
8037: .LC_ListStyleNormal dd,
8038: .LC_ListStyleSpecial li,
1.795 www 8039: .LC_ListStyleSpecial dd {
1.911 bisitz 8040: margin: 0;
8041: padding: 5px 5px 5px 10px;
8042: clear: both;
1.693 droeschl 8043: }
8044:
1.721 harmsja 8045: .LC_ListStyleClean li,
8046: .LC_ListStyleClean dd {
1.911 bisitz 8047: padding-top: 0;
8048: padding-bottom: 0;
1.693 droeschl 8049: }
8050:
1.721 harmsja 8051: .LC_ListStyleSimple dd,
1.795 www 8052: .LC_ListStyleSimple li {
1.911 bisitz 8053: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8054: }
8055:
1.721 harmsja 8056: .LC_ListStyleSpecial li,
8057: .LC_ListStyleSpecial dd {
1.911 bisitz 8058: list-style-type: none;
8059: background-color: RGB(220, 220, 220);
8060: margin-bottom: 4px;
1.693 droeschl 8061: }
8062:
1.721 harmsja 8063: table.LC_SimpleTable {
1.911 bisitz 8064: margin:5px;
8065: border:solid 1px $lg_border_color;
1.795 www 8066: }
1.693 droeschl 8067:
1.721 harmsja 8068: table.LC_SimpleTable tr {
1.911 bisitz 8069: padding: 0;
8070: border:solid 1px $lg_border_color;
1.693 droeschl 8071: }
1.795 www 8072:
8073: table.LC_SimpleTable thead {
1.911 bisitz 8074: background:rgb(220,220,220);
1.693 droeschl 8075: }
8076:
1.721 harmsja 8077: div.LC_columnSection {
1.911 bisitz 8078: display: block;
8079: clear: both;
8080: overflow: hidden;
8081: margin: 0;
1.693 droeschl 8082: }
8083:
1.721 harmsja 8084: div.LC_columnSection>* {
1.911 bisitz 8085: float: left;
8086: margin: 10px 20px 10px 0;
8087: overflow:hidden;
1.693 droeschl 8088: }
1.721 harmsja 8089:
1.795 www 8090: table em {
1.911 bisitz 8091: font-weight: bold;
8092: font-style: normal;
1.748 schulted 8093: }
1.795 www 8094:
1.779 bisitz 8095: table.LC_tableBrowseRes,
1.795 www 8096: table.LC_tableOfContent {
1.911 bisitz 8097: border:none;
8098: border-spacing: 1px;
8099: padding: 3px;
8100: background-color: #FFFFFF;
8101: font-size: 90%;
1.753 droeschl 8102: }
1.789 droeschl 8103:
1.911 bisitz 8104: table.LC_tableOfContent {
8105: border-collapse: collapse;
1.789 droeschl 8106: }
8107:
1.771 droeschl 8108: table.LC_tableBrowseRes a,
1.768 schulted 8109: table.LC_tableOfContent a {
1.911 bisitz 8110: background-color: transparent;
8111: text-decoration: none;
1.753 droeschl 8112: }
8113:
1.795 www 8114: table.LC_tableOfContent img {
1.911 bisitz 8115: border: none;
8116: height: 1.3em;
8117: vertical-align: text-bottom;
8118: margin-right: 0.3em;
1.753 droeschl 8119: }
1.757 schulted 8120:
1.795 www 8121: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8122: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8123: }
8124:
1.795 www 8125: a#LC_content_toolbar_everything {
1.911 bisitz 8126: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8127: }
8128:
1.795 www 8129: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8130: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8131: }
8132:
1.795 www 8133: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8134: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8135: }
8136:
1.795 www 8137: a#LC_content_toolbar_changefolder {
1.911 bisitz 8138: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8139: }
8140:
1.795 www 8141: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8142: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8143: }
8144:
1.1043 raeburn 8145: a#LC_content_toolbar_edittoplevel {
8146: background-image:url(/res/adm/pages/edittoplevel.gif);
8147: }
8148:
1.795 www 8149: ul#LC_toolbar li a:hover {
1.911 bisitz 8150: background-position: bottom center;
1.757 schulted 8151: }
8152:
1.795 www 8153: ul#LC_toolbar {
1.911 bisitz 8154: padding: 0;
8155: margin: 2px;
8156: list-style:none;
8157: position:relative;
8158: background-color:white;
1.1082 raeburn 8159: overflow: auto;
1.757 schulted 8160: }
8161:
1.795 www 8162: ul#LC_toolbar li {
1.911 bisitz 8163: border:1px solid white;
8164: padding: 0;
8165: margin: 0;
8166: float: left;
8167: display:inline;
8168: vertical-align:middle;
1.1082 raeburn 8169: white-space: nowrap;
1.911 bisitz 8170: }
1.757 schulted 8171:
1.783 amueller 8172:
1.795 www 8173: a.LC_toolbarItem {
1.911 bisitz 8174: display:block;
8175: padding: 0;
8176: margin: 0;
8177: height: 32px;
8178: width: 32px;
8179: color:white;
8180: border: none;
8181: background-repeat:no-repeat;
8182: background-color:transparent;
1.757 schulted 8183: }
8184:
1.915 droeschl 8185: ul.LC_funclist {
8186: margin: 0;
8187: padding: 0.5em 1em 0.5em 0;
8188: }
8189:
1.933 droeschl 8190: ul.LC_funclist > li:first-child {
8191: font-weight:bold;
8192: margin-left:0.8em;
8193: }
8194:
1.915 droeschl 8195: ul.LC_funclist + ul.LC_funclist {
8196: /*
8197: left border as a seperator if we have more than
8198: one list
8199: */
8200: border-left: 1px solid $sidebg;
8201: /*
8202: this hides the left border behind the border of the
8203: outer box if element is wrapped to the next 'line'
8204: */
8205: margin-left: -1px;
8206: }
8207:
1.843 bisitz 8208: ul.LC_funclist li {
1.915 droeschl 8209: display: inline;
1.782 bisitz 8210: white-space: nowrap;
1.915 droeschl 8211: margin: 0 0 0 25px;
8212: line-height: 150%;
1.782 bisitz 8213: }
8214:
1.974 wenzelju 8215: .LC_hidden {
8216: display: none;
8217: }
8218:
1.1030 www 8219: .LCmodal-overlay {
8220: position:fixed;
8221: top:0;
8222: right:0;
8223: bottom:0;
8224: left:0;
8225: height:100%;
8226: width:100%;
8227: margin:0;
8228: padding:0;
8229: background:#999;
8230: opacity:.75;
8231: filter: alpha(opacity=75);
8232: -moz-opacity: 0.75;
8233: z-index:101;
8234: }
8235:
8236: * html .LCmodal-overlay {
8237: position: absolute;
8238: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8239: }
8240:
8241: .LCmodal-window {
8242: position:fixed;
8243: top:50%;
8244: left:50%;
8245: margin:0;
8246: padding:0;
8247: z-index:102;
8248: }
8249:
8250: * html .LCmodal-window {
8251: position:absolute;
8252: }
8253:
8254: .LCclose-window {
8255: position:absolute;
8256: width:32px;
8257: height:32px;
8258: right:8px;
8259: top:8px;
8260: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8261: text-indent:-99999px;
8262: overflow:hidden;
8263: cursor:pointer;
8264: }
8265:
1.1335 raeburn 8266: pre.LC_wordwrap {
8267: white-space: pre-wrap;
8268: white-space: -moz-pre-wrap;
8269: white-space: -pre-wrap;
8270: white-space: -o-pre-wrap;
8271: word-wrap: break-word;
8272: }
8273:
1.1100 raeburn 8274: /*
1.1231 damieng 8275: styles used for response display
8276: */
8277: div.LC_radiofoil, div.LC_rankfoil {
8278: margin: .5em 0em .5em 0em;
8279: }
8280: table.LC_itemgroup {
8281: margin-top: 1em;
8282: }
8283:
8284: /*
1.1100 raeburn 8285: styles used by TTH when "Default set of options to pass to tth/m
8286: when converting TeX" in course settings has been set
8287:
8288: option passed: -t
8289:
8290: */
8291:
8292: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8293: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8294: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8295: td div.norm {line-height:normal;}
8296:
8297: /*
8298: option passed -y3
8299: */
8300:
8301: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8302: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8303: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8304:
1.1230 damieng 8305: /*
8306: sections with roles, for content only
8307: */
8308: section[class^="role-"] {
8309: padding-left: 10px;
8310: padding-right: 5px;
8311: margin-top: 8px;
8312: margin-bottom: 8px;
8313: border: 1px solid #2A4;
8314: border-radius: 5px;
8315: box-shadow: 0px 1px 1px #BBB;
8316: }
8317: section[class^="role-"]>h1 {
8318: position: relative;
8319: margin: 0px;
8320: padding-top: 10px;
8321: padding-left: 40px;
8322: }
8323: section[class^="role-"]>h1:before {
8324: position: absolute;
8325: left: -5px;
8326: top: 5px;
8327: }
8328: section.role-activity>h1:before {
8329: content:url('/adm/daxe/images/section_icons/activity.png');
8330: }
8331: section.role-advice>h1:before {
8332: content:url('/adm/daxe/images/section_icons/advice.png');
8333: }
8334: section.role-bibliography>h1:before {
8335: content:url('/adm/daxe/images/section_icons/bibliography.png');
8336: }
8337: section.role-citation>h1:before {
8338: content:url('/adm/daxe/images/section_icons/citation.png');
8339: }
8340: section.role-conclusion>h1:before {
8341: content:url('/adm/daxe/images/section_icons/conclusion.png');
8342: }
8343: section.role-definition>h1:before {
8344: content:url('/adm/daxe/images/section_icons/definition.png');
8345: }
8346: section.role-demonstration>h1:before {
8347: content:url('/adm/daxe/images/section_icons/demonstration.png');
8348: }
8349: section.role-example>h1:before {
8350: content:url('/adm/daxe/images/section_icons/example.png');
8351: }
8352: section.role-explanation>h1:before {
8353: content:url('/adm/daxe/images/section_icons/explanation.png');
8354: }
8355: section.role-introduction>h1:before {
8356: content:url('/adm/daxe/images/section_icons/introduction.png');
8357: }
8358: section.role-method>h1:before {
8359: content:url('/adm/daxe/images/section_icons/method.png');
8360: }
8361: section.role-more_information>h1:before {
8362: content:url('/adm/daxe/images/section_icons/more_information.png');
8363: }
8364: section.role-objectives>h1:before {
8365: content:url('/adm/daxe/images/section_icons/objectives.png');
8366: }
8367: section.role-prerequisites>h1:before {
8368: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8369: }
8370: section.role-remark>h1:before {
8371: content:url('/adm/daxe/images/section_icons/remark.png');
8372: }
8373: section.role-reminder>h1:before {
8374: content:url('/adm/daxe/images/section_icons/reminder.png');
8375: }
8376: section.role-summary>h1:before {
8377: content:url('/adm/daxe/images/section_icons/summary.png');
8378: }
8379: section.role-syntax>h1:before {
8380: content:url('/adm/daxe/images/section_icons/syntax.png');
8381: }
8382: section.role-warning>h1:before {
8383: content:url('/adm/daxe/images/section_icons/warning.png');
8384: }
8385:
1.1269 raeburn 8386: #LC_minitab_header {
8387: float:left;
8388: width:100%;
8389: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8390: font-size:93%;
8391: line-height:normal;
8392: margin: 0.5em 0 0.5em 0;
8393: }
8394: #LC_minitab_header ul {
8395: margin:0;
8396: padding:10px 10px 0;
8397: list-style:none;
8398: }
8399: #LC_minitab_header li {
8400: float:left;
8401: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8402: margin:0;
8403: padding:0 0 0 9px;
8404: }
8405: #LC_minitab_header a {
8406: display:block;
8407: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8408: padding:5px 15px 4px 6px;
8409: }
8410: #LC_minitab_header #LC_current_minitab {
8411: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8412: }
8413: #LC_minitab_header #LC_current_minitab a {
8414: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8415: padding-bottom:5px;
8416: }
8417:
8418:
1.343 albertel 8419: END
8420: }
8421:
1.306 albertel 8422: =pod
8423:
8424: =item * &headtag()
8425:
8426: Returns a uniform footer for LON-CAPA web pages.
8427:
1.307 albertel 8428: Inputs: $title - optional title for the head
8429: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8430: $args - optional arguments
1.319 albertel 8431: force_register - if is true call registerurl so the remote is
8432: informed
1.415 albertel 8433: redirect -> array ref of
8434: 1- seconds before redirect occurs
8435: 2- url to redirect to
8436: 3- whether the side effect should occur
1.315 albertel 8437: (side effect of setting
8438: $env{'internal.head.redirect'} to the url
8439: redirected too)
1.352 albertel 8440: domain -> force to color decorate a page for a specific
8441: domain
8442: function -> force usage of a specific rolish color scheme
8443: bgcolor -> override the default page bgcolor
1.460 albertel 8444: no_auto_mt_title
8445: -> prevent &mt()ing the title arg
1.464 albertel 8446:
1.306 albertel 8447: =cut
8448:
8449: sub headtag {
1.313 albertel 8450: my ($title,$head_extra,$args) = @_;
1.306 albertel 8451:
1.363 albertel 8452: my $function = $args->{'function'} || &get_users_function();
8453: my $domain = $args->{'domain'} || &determinedomain();
8454: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8455: my $httphost = $args->{'use_absolute'};
1.418 albertel 8456: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8457: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8458: #time(),
1.418 albertel 8459: $env{'environment.color.timestamp'},
1.363 albertel 8460: $function,$domain,$bgcolor);
8461:
1.369 www 8462: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8463:
1.308 albertel 8464: my $result =
8465: '<head>'.
1.1160 raeburn 8466: &font_settings($args);
1.319 albertel 8467:
1.1188 raeburn 8468: my $inhibitprint;
8469: if ($args->{'print_suppress'}) {
8470: $inhibitprint = &print_suppression();
8471: }
1.1064 raeburn 8472:
1.461 albertel 8473: if (!$args->{'frameset'}) {
8474: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8475: }
1.962 droeschl 8476: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8477: $result .= Apache::lonxml::display_title();
1.319 albertel 8478: }
1.436 albertel 8479: if (!$args->{'no_nav_bar'}
8480: && !$args->{'only_body'}
8481: && !$args->{'frameset'}) {
1.1154 raeburn 8482: $result .= &help_menu_js($httphost);
1.1032 www 8483: $result.=&modal_window();
1.1038 www 8484: $result.=&togglebox_script();
1.1034 www 8485: $result.=&wishlist_window();
1.1041 www 8486: $result.=&LCprogressbarUpdate_script();
1.1034 www 8487: } else {
8488: if ($args->{'add_modal'}) {
8489: $result.=&modal_window();
8490: }
8491: if ($args->{'add_wishlist'}) {
8492: $result.=&wishlist_window();
8493: }
1.1038 www 8494: if ($args->{'add_togglebox'}) {
8495: $result.=&togglebox_script();
8496: }
1.1041 www 8497: if ($args->{'add_progressbar'}) {
8498: $result.=&LCprogressbarUpdate_script();
8499: }
1.436 albertel 8500: }
1.314 albertel 8501: if (ref($args->{'redirect'})) {
1.414 albertel 8502: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8503: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8504: if (!$inhibit_continue) {
8505: $env{'internal.head.redirect'} = $url;
8506: }
1.313 albertel 8507: $result.=<<ADDMETA
8508: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8509: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8510: ADDMETA
1.1210 raeburn 8511: } else {
8512: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8513: my $requrl = $env{'request.uri'};
8514: if ($requrl eq '') {
8515: $requrl = $ENV{'REQUEST_URI'};
8516: $requrl =~ s/\?.+$//;
8517: }
8518: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8519: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8520: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8521: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8522: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8523: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8524: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8525: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8526: if ($domdefs{'offloadnow'}{$lonhost}) {
8527: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8528: if (($newserver) && ($newserver ne $lonhost)) {
8529: my $numsec = 5;
8530: my $timeout = $numsec * 1000;
8531: my ($newurl,$locknum,%locks,$msg);
8532: if ($env{'request.role.adv'}) {
8533: ($locknum,%locks) = &Apache::lonnet::get_locks();
8534: }
8535: my $disable_submit = 0;
8536: if ($requrl =~ /$LONCAPA::assess_re/) {
8537: $disable_submit = 1;
8538: }
8539: if ($locknum) {
8540: my @lockinfo = sort(values(%locks));
8541: $msg = &mt('Once the following tasks are complete: ')."\\n".
8542: join(", ",sort(values(%locks)))."\\n".
8543: &mt('your session will be transferred to a different server, after you click "Roles".');
8544: } else {
8545: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8546: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8547: }
8548: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8549: $newurl = '/adm/switchserver?otherserver='.$newserver;
8550: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8551: $newurl .= '&role='.$env{'request.role'};
8552: }
8553: if ($env{'request.symb'}) {
8554: $newurl .= '&symb='.$env{'request.symb'};
8555: } else {
8556: $newurl .= '&origurl='.$requrl;
8557: }
8558: }
1.1222 damieng 8559: &js_escape(\$msg);
1.1210 raeburn 8560: $result.=<<OFFLOAD
8561: <meta http-equiv="pragma" content="no-cache" />
8562: <script type="text/javascript">
1.1215 raeburn 8563: // <![CDATA[
1.1210 raeburn 8564: function LC_Offload_Now() {
8565: var dest = "$newurl";
8566: if (dest != '') {
8567: window.location.href="$newurl";
8568: }
8569: }
1.1214 raeburn 8570: \$(document).ready(function () {
8571: window.alert('$msg');
8572: if ($disable_submit) {
1.1210 raeburn 8573: \$(".LC_hwk_submit").prop("disabled", true);
8574: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8575: }
8576: setTimeout('LC_Offload_Now()', $timeout);
8577: });
1.1215 raeburn 8578: // ]]>
1.1210 raeburn 8579: </script>
8580: OFFLOAD
8581: }
8582: }
8583: }
8584: }
8585: }
8586: }
1.313 albertel 8587: }
1.306 albertel 8588: if (!defined($title)) {
8589: $title = 'The LearningOnline Network with CAPA';
8590: }
1.460 albertel 8591: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8592: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8593: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8594: if (!$args->{'frameset'}) {
8595: $result .= ' /';
8596: }
8597: $result .= '>'
1.1064 raeburn 8598: .$inhibitprint
1.414 albertel 8599: .$head_extra;
1.1242 raeburn 8600: my $clientmobile;
8601: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8602: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8603: } else {
8604: $clientmobile = $env{'browser.mobile'};
8605: }
8606: if ($clientmobile) {
1.1137 raeburn 8607: $result .= '
8608: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8609: <meta name="apple-mobile-web-app-capable" content="yes" />';
8610: }
1.1278 raeburn 8611: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8612: return $result.'</head>';
1.306 albertel 8613: }
8614:
8615: =pod
8616:
1.340 albertel 8617: =item * &font_settings()
8618:
8619: Returns neccessary <meta> to set the proper encoding
8620:
1.1160 raeburn 8621: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8622:
8623: =cut
8624:
8625: sub font_settings {
1.1160 raeburn 8626: my ($args) = @_;
1.340 albertel 8627: my $headerstring='';
1.1160 raeburn 8628: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8629: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8630: $headerstring.=
8631: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8632: if (!$args->{'frameset'}) {
8633: $headerstring.= ' /';
8634: }
8635: $headerstring .= '>'."\n";
1.340 albertel 8636: }
8637: return $headerstring;
8638: }
8639:
1.341 albertel 8640: =pod
8641:
1.1064 raeburn 8642: =item * &print_suppression()
8643:
8644: In course context returns css which causes the body to be blank when media="print",
8645: if printout generation is unavailable for the current resource.
8646:
8647: This could be because:
8648:
8649: (a) printstartdate is in the future
8650:
8651: (b) printenddate is in the past
8652:
8653: (c) there is an active exam block with "printout"
8654: functionality blocked
8655:
8656: Users with pav, pfo or evb privileges are exempt.
8657:
8658: Inputs: none
8659:
8660: =cut
8661:
8662:
8663: sub print_suppression {
8664: my $noprint;
8665: if ($env{'request.course.id'}) {
8666: my $scope = $env{'request.course.id'};
8667: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8668: (&Apache::lonnet::allowed('pfo',$scope))) {
8669: return;
8670: }
8671: if ($env{'request.course.sec'} ne '') {
8672: $scope .= "/$env{'request.course.sec'}";
8673: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8674: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8675: return;
1.1064 raeburn 8676: }
8677: }
8678: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8679: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8680: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8681: if ($blocked) {
8682: my $checkrole = "cm./$cdom/$cnum";
8683: if ($env{'request.course.sec'} ne '') {
8684: $checkrole .= "/$env{'request.course.sec'}";
8685: }
8686: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8687: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8688: $noprint = 1;
8689: }
8690: }
8691: unless ($noprint) {
8692: my $symb = &Apache::lonnet::symbread();
8693: if ($symb ne '') {
8694: my $navmap = Apache::lonnavmaps::navmap->new();
8695: if (ref($navmap)) {
8696: my $res = $navmap->getBySymb($symb);
8697: if (ref($res)) {
8698: if (!$res->resprintable()) {
8699: $noprint = 1;
8700: }
8701: }
8702: }
8703: }
8704: }
8705: if ($noprint) {
8706: return <<"ENDSTYLE";
8707: <style type="text/css" media="print">
8708: body { display:none }
8709: </style>
8710: ENDSTYLE
8711: }
8712: }
8713: return;
8714: }
8715:
8716: =pod
8717:
1.341 albertel 8718: =item * &xml_begin()
8719:
8720: Returns the needed doctype and <html>
8721:
8722: Inputs: none
8723:
8724: =cut
8725:
8726: sub xml_begin {
1.1168 raeburn 8727: my ($is_frameset) = @_;
1.341 albertel 8728: my $output='';
8729:
8730: if ($env{'browser.mathml'}) {
8731: $output='<?xml version="1.0"?>'
8732: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8733: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8734:
8735: # .'<!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">] >'
8736: .'<!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">'
8737: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8738: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8739: } elsif ($is_frameset) {
8740: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8741: '<html>'."\n";
1.341 albertel 8742: } else {
1.1168 raeburn 8743: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8744: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8745: }
8746: return $output;
8747: }
1.340 albertel 8748:
8749: =pod
8750:
1.306 albertel 8751: =item * &start_page()
8752:
8753: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8754:
1.648 raeburn 8755: Inputs:
8756:
8757: =over 4
8758:
8759: $title - optional title for the page
8760:
8761: $head_extra - optional extra HTML to incude inside the <head>
8762:
8763: $args - additional optional args supported are:
8764:
8765: =over 8
8766:
8767: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8768: arg on
1.814 bisitz 8769: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8770: add_entries -> additional attributes to add to the <body>
8771: domain -> force to color decorate a page for a
1.317 albertel 8772: specific domain
1.648 raeburn 8773: function -> force usage of a specific rolish color
1.317 albertel 8774: scheme
1.648 raeburn 8775: redirect -> see &headtag()
8776: bgcolor -> override the default page bg color
8777: js_ready -> return a string ready for being used in
1.317 albertel 8778: a javascript writeln
1.648 raeburn 8779: html_encode -> return a string ready for being used in
1.320 albertel 8780: a html attribute
1.648 raeburn 8781: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8782: $forcereg arg
1.648 raeburn 8783: frameset -> if true will start with a <frameset>
1.330 albertel 8784: rather than <body>
1.648 raeburn 8785: skip_phases -> hash ref of
1.338 albertel 8786: head -> skip the <html><head> generation
8787: body -> skip all <body> generation
1.648 raeburn 8788: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8789: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8790: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8791: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8792: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8793: group -> includes the current group, if page is for a
1.1274 raeburn 8794: specific group
8795: use_absolute -> for request for external resource or syllabus, this
8796: will contain https://<hostname> if server uses
8797: https (as per hosts.tab), but request is for http
8798: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8799:
1.648 raeburn 8800: =back
1.460 albertel 8801:
1.648 raeburn 8802: =back
1.562 albertel 8803:
1.306 albertel 8804: =cut
8805:
8806: sub start_page {
1.309 albertel 8807: my ($title,$head_extra,$args) = @_;
1.318 albertel 8808: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8809:
1.315 albertel 8810: $env{'internal.start_page'}++;
1.1318 raeburn 8811: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8812:
1.338 albertel 8813: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8814: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8815: }
1.1316 raeburn 8816:
8817: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8818: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8819: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8820: $args->{'no_primary_menu'} = 1;
8821: }
8822: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8823: $args->{'no_inline_menu'} = 1;
8824: }
8825: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8826: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8827: }
8828: } else {
8829: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8830: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8831: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8832: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8833: $args->{'no_primary_menu'} = 1;
8834: }
8835: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8836: $args->{'no_inline_menu'} = 1;
8837: }
8838: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8839: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8840: }
8841: }
8842: }
1.1316 raeburn 8843: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8844: $env{'course.'.$env{'request.course.id'}.'.domain'},
8845: $env{'course.'.$env{'request.course.id'}.'.num'});
8846: }
1.338 albertel 8847:
8848: if (! exists($args->{'skip_phases'}{'body'}) ) {
8849: if ($args->{'frameset'}) {
8850: my $attr_string = &make_attr_string($args->{'force_register'},
8851: $args->{'add_entries'});
8852: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8853: } else {
8854: $result .=
8855: &bodytag($title,
8856: $args->{'function'}, $args->{'add_entries'},
8857: $args->{'only_body'}, $args->{'domain'},
8858: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8859: $args->{'bgcolor'}, $args,
1.1318 raeburn 8860: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8861: }
1.330 albertel 8862: }
1.338 albertel 8863:
1.315 albertel 8864: if ($args->{'js_ready'}) {
1.713 kaisler 8865: $result = &js_ready($result);
1.315 albertel 8866: }
1.320 albertel 8867: if ($args->{'html_encode'}) {
1.713 kaisler 8868: $result = &html_encode($result);
8869: }
8870:
1.813 bisitz 8871: # Preparation for new and consistent functionlist at top of screen
8872: # if ($args->{'functionlist'}) {
8873: # $result .= &build_functionlist();
8874: #}
8875:
1.964 droeschl 8876: # Don't add anything more if only_body wanted or in const space
8877: return $result if $args->{'only_body'}
8878: || $env{'request.state'} eq 'construct';
1.813 bisitz 8879:
8880: #Breadcrumbs
1.758 kaisler 8881: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8882: &Apache::lonhtmlcommon::clear_breadcrumbs();
8883: #if any br links exists, add them to the breadcrumbs
8884: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8885: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8886: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8887: }
8888: }
1.1096 raeburn 8889: # if @advtools array contains items add then to the breadcrumbs
8890: if (@advtools > 0) {
8891: &Apache::lonmenu::advtools_crumbs(@advtools);
8892: }
1.1272 raeburn 8893: my $menulink;
8894: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8895: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8896: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8897: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8898: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8899: (!$env{'request.role.adv'}))) {
8900: $menulink = 0;
8901: } else {
8902: undef($menulink);
8903: }
1.758 kaisler 8904: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8905: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8906: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8907: } else {
1.1272 raeburn 8908: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8909: }
1.320 albertel 8910: }
1.315 albertel 8911: return $result;
1.306 albertel 8912: }
8913:
8914: sub end_page {
1.315 albertel 8915: my ($args) = @_;
8916: $env{'internal.end_page'}++;
1.330 albertel 8917: my $result;
1.335 albertel 8918: if ($args->{'discussion'}) {
8919: my ($target,$parser);
8920: if (ref($args->{'discussion'})) {
8921: ($target,$parser) =($args->{'discussion'}{'target'},
8922: $args->{'discussion'}{'parser'});
8923: }
8924: $result .= &Apache::lonxml::xmlend($target,$parser);
8925: }
1.330 albertel 8926: if ($args->{'frameset'}) {
8927: $result .= '</frameset>';
8928: } else {
1.635 raeburn 8929: $result .= &endbodytag($args);
1.330 albertel 8930: }
1.1080 raeburn 8931: unless ($args->{'notbody'}) {
8932: $result .= "\n</html>";
8933: }
1.330 albertel 8934:
1.315 albertel 8935: if ($args->{'js_ready'}) {
1.317 albertel 8936: $result = &js_ready($result);
1.315 albertel 8937: }
1.335 albertel 8938:
1.320 albertel 8939: if ($args->{'html_encode'}) {
8940: $result = &html_encode($result);
8941: }
1.335 albertel 8942:
1.315 albertel 8943: return $result;
8944: }
8945:
1.1034 www 8946: sub wishlist_window {
8947: return(<<'ENDWISHLIST');
1.1046 raeburn 8948: <script type="text/javascript">
1.1034 www 8949: // <![CDATA[
8950: // <!-- BEGIN LON-CAPA Internal
8951: function set_wishlistlink(title, path) {
8952: if (!title) {
8953: title = document.title;
8954: title = title.replace(/^LON-CAPA /,'');
8955: }
1.1175 raeburn 8956: title = encodeURIComponent(title);
1.1203 raeburn 8957: title = title.replace("'","\\\'");
1.1034 www 8958: if (!path) {
8959: path = location.pathname;
8960: }
1.1175 raeburn 8961: path = encodeURIComponent(path);
1.1203 raeburn 8962: path = path.replace("'","\\\'");
1.1034 www 8963: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8964: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8965: }
8966: // END LON-CAPA Internal -->
8967: // ]]>
8968: </script>
8969: ENDWISHLIST
8970: }
8971:
1.1030 www 8972: sub modal_window {
8973: return(<<'ENDMODAL');
1.1046 raeburn 8974: <script type="text/javascript">
1.1030 www 8975: // <![CDATA[
8976: // <!-- BEGIN LON-CAPA Internal
8977: var modalWindow = {
8978: parent:"body",
8979: windowId:null,
8980: content:null,
8981: width:null,
8982: height:null,
8983: close:function()
8984: {
8985: $(".LCmodal-window").remove();
8986: $(".LCmodal-overlay").remove();
8987: },
8988: open:function()
8989: {
8990: var modal = "";
8991: modal += "<div class=\"LCmodal-overlay\"></div>";
8992: 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;\">";
8993: modal += this.content;
8994: modal += "</div>";
8995:
8996: $(this.parent).append(modal);
8997:
8998: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8999: $(".LCclose-window").click(function(){modalWindow.close();});
9000: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9001: }
9002: };
1.1140 raeburn 9003: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9004: {
1.1266 raeburn 9005: source = source.replace(/'/g,"'");
1.1030 www 9006: modalWindow.windowId = "myModal";
9007: modalWindow.width = width;
9008: modalWindow.height = height;
1.1196 raeburn 9009: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9010: modalWindow.open();
1.1208 raeburn 9011: };
1.1030 www 9012: // END LON-CAPA Internal -->
9013: // ]]>
9014: </script>
9015: ENDMODAL
9016: }
9017:
9018: sub modal_link {
1.1140 raeburn 9019: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9020: unless ($width) { $width=480; }
9021: unless ($height) { $height=400; }
1.1031 www 9022: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9023: unless ($transparency) { $transparency='true'; }
9024:
1.1074 raeburn 9025: my $target_attr;
9026: if (defined($target)) {
9027: $target_attr = 'target="'.$target.'"';
9028: }
9029: return <<"ENDLINK";
1.1336 raeburn 9030: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9031: ENDLINK
1.1030 www 9032: }
9033:
1.1032 www 9034: sub modal_adhoc_script {
9035: my ($funcname,$width,$height,$content)=@_;
9036: return (<<ENDADHOC);
1.1046 raeburn 9037: <script type="text/javascript">
1.1032 www 9038: // <![CDATA[
9039: var $funcname = function()
9040: {
9041: modalWindow.windowId = "myModal";
9042: modalWindow.width = $width;
9043: modalWindow.height = $height;
9044: modalWindow.content = '$content';
9045: modalWindow.open();
9046: };
9047: // ]]>
9048: </script>
9049: ENDADHOC
9050: }
9051:
1.1041 www 9052: sub modal_adhoc_inner {
9053: my ($funcname,$width,$height,$content)=@_;
9054: my $innerwidth=$width-20;
9055: $content=&js_ready(
1.1140 raeburn 9056: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9057: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9058: $content.
1.1041 www 9059: &end_scrollbox().
1.1140 raeburn 9060: &end_page()
1.1041 www 9061: );
9062: return &modal_adhoc_script($funcname,$width,$height,$content);
9063: }
9064:
9065: sub modal_adhoc_window {
9066: my ($funcname,$width,$height,$content,$linktext)=@_;
9067: return &modal_adhoc_inner($funcname,$width,$height,$content).
9068: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9069: }
9070:
9071: sub modal_adhoc_launch {
9072: my ($funcname,$width,$height,$content)=@_;
9073: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9074: <script type="text/javascript">
9075: // <![CDATA[
9076: $funcname();
9077: // ]]>
9078: </script>
9079: ENDLAUNCH
9080: }
9081:
9082: sub modal_adhoc_close {
9083: return (<<ENDCLOSE);
9084: <script type="text/javascript">
9085: // <![CDATA[
9086: modalWindow.close();
9087: // ]]>
9088: </script>
9089: ENDCLOSE
9090: }
9091:
1.1038 www 9092: sub togglebox_script {
9093: return(<<ENDTOGGLE);
9094: <script type="text/javascript">
9095: // <![CDATA[
9096: function LCtoggleDisplay(id,hidetext,showtext) {
9097: link = document.getElementById(id + "link").childNodes[0];
9098: with (document.getElementById(id).style) {
9099: if (display == "none" ) {
9100: display = "inline";
9101: link.nodeValue = hidetext;
9102: } else {
9103: display = "none";
9104: link.nodeValue = showtext;
9105: }
9106: }
9107: }
9108: // ]]>
9109: </script>
9110: ENDTOGGLE
9111: }
9112:
1.1039 www 9113: sub start_togglebox {
9114: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9115: unless ($heading) { $heading=''; } else { $heading.=' '; }
9116: unless ($showtext) { $showtext=&mt('show'); }
9117: unless ($hidetext) { $hidetext=&mt('hide'); }
9118: unless ($headerbg) { $headerbg='#FFFFFF'; }
9119: return &start_data_table().
9120: &start_data_table_header_row().
9121: '<td bgcolor="'.$headerbg.'">'.$heading.
9122: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9123: $showtext.'\')">'.$showtext.'</a>]</td>'.
9124: &end_data_table_header_row().
9125: '<tr id="'.$id.'" style="display:none""><td>';
9126: }
9127:
9128: sub end_togglebox {
9129: return '</td></tr>'.&end_data_table();
9130: }
9131:
1.1041 www 9132: sub LCprogressbar_script {
1.1302 raeburn 9133: my ($id,$number_to_do)=@_;
9134: if ($number_to_do) {
9135: return(<<ENDPROGRESS);
1.1041 www 9136: <script type="text/javascript">
9137: // <![CDATA[
1.1045 www 9138: \$('#progressbar$id').progressbar({
1.1041 www 9139: value: 0,
9140: change: function(event, ui) {
9141: var newVal = \$(this).progressbar('option', 'value');
9142: \$('.pblabel', this).text(LCprogressTxt);
9143: }
9144: });
9145: // ]]>
9146: </script>
9147: ENDPROGRESS
1.1302 raeburn 9148: } else {
9149: return(<<ENDPROGRESS);
9150: <script type="text/javascript">
9151: // <![CDATA[
9152: \$('#progressbar$id').progressbar({
9153: value: false,
9154: create: function(event, ui) {
9155: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9156: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9157: }
9158: });
9159: // ]]>
9160: </script>
9161: ENDPROGRESS
9162: }
1.1041 www 9163: }
9164:
9165: sub LCprogressbarUpdate_script {
9166: return(<<ENDPROGRESSUPDATE);
9167: <style type="text/css">
9168: .ui-progressbar { position:relative; }
1.1302 raeburn 9169: .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 9170: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9171: </style>
9172: <script type="text/javascript">
9173: // <![CDATA[
1.1045 www 9174: var LCprogressTxt='---';
9175:
1.1302 raeburn 9176: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9177: LCprogressTxt=progresstext;
1.1302 raeburn 9178: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9179: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9180: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9181: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9182: } else {
9183: \$('#progressbar'+id).progressbar('value',percent);
9184: }
1.1041 www 9185: }
9186: // ]]>
9187: </script>
9188: ENDPROGRESSUPDATE
9189: }
9190:
1.1042 www 9191: my $LClastpercent;
1.1045 www 9192: my $LCidcnt;
9193: my $LCcurrentid;
1.1042 www 9194:
1.1041 www 9195: sub LCprogressbar {
1.1302 raeburn 9196: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9197: $LClastpercent=0;
1.1045 www 9198: $LCidcnt++;
9199: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9200: my ($starting,$content);
9201: if ($number_to_do) {
9202: $starting=&mt('Starting');
9203: $content=(<<ENDPROGBAR);
9204: $preamble
1.1045 www 9205: <div id="progressbar$LCcurrentid">
1.1041 www 9206: <span class="pblabel">$starting</span>
9207: </div>
9208: ENDPROGBAR
1.1302 raeburn 9209: } else {
9210: $starting=&mt('Loading...');
9211: $LClastpercent='false';
9212: $content=(<<ENDPROGBAR);
9213: $preamble
9214: <div id="progressbar$LCcurrentid">
9215: <div class="progress-label">$starting</div>
9216: </div>
9217: ENDPROGBAR
9218: }
9219: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9220: }
9221:
9222: sub LCprogressbarUpdate {
1.1302 raeburn 9223: my ($r,$val,$text,$number_to_do)=@_;
9224: if ($number_to_do) {
9225: unless ($val) {
9226: if ($LClastpercent) {
9227: $val=$LClastpercent;
9228: } else {
9229: $val=0;
9230: }
9231: }
9232: if ($val<0) { $val=0; }
9233: if ($val>100) { $val=0; }
9234: $LClastpercent=$val;
9235: unless ($text) { $text=$val.'%'; }
9236: } else {
9237: $val = 'false';
1.1042 www 9238: }
1.1041 www 9239: $text=&js_ready($text);
1.1044 www 9240: &r_print($r,<<ENDUPDATE);
1.1041 www 9241: <script type="text/javascript">
9242: // <![CDATA[
1.1302 raeburn 9243: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9244: // ]]>
9245: </script>
9246: ENDUPDATE
1.1035 www 9247: }
9248:
1.1042 www 9249: sub LCprogressbarClose {
9250: my ($r)=@_;
9251: $LClastpercent=0;
1.1044 www 9252: &r_print($r,<<ENDCLOSE);
1.1042 www 9253: <script type="text/javascript">
9254: // <![CDATA[
1.1045 www 9255: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9256: // ]]>
9257: </script>
9258: ENDCLOSE
1.1044 www 9259: }
9260:
9261: sub r_print {
9262: my ($r,$to_print)=@_;
9263: if ($r) {
9264: $r->print($to_print);
9265: $r->rflush();
9266: } else {
9267: print($to_print);
9268: }
1.1042 www 9269: }
9270:
1.320 albertel 9271: sub html_encode {
9272: my ($result) = @_;
9273:
1.322 albertel 9274: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9275:
9276: return $result;
9277: }
1.1044 www 9278:
1.317 albertel 9279: sub js_ready {
9280: my ($result) = @_;
9281:
1.323 albertel 9282: $result =~ s/[\n\r]/ /xmsg;
9283: $result =~ s/\\/\\\\/xmsg;
9284: $result =~ s/'/\\'/xmsg;
1.372 albertel 9285: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9286:
9287: return $result;
9288: }
9289:
1.315 albertel 9290: sub validate_page {
9291: if ( exists($env{'internal.start_page'})
1.316 albertel 9292: && $env{'internal.start_page'} > 1) {
9293: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9294: $env{'internal.start_page'}.' '.
1.316 albertel 9295: $ENV{'request.filename'});
1.315 albertel 9296: }
9297: if ( exists($env{'internal.end_page'})
1.316 albertel 9298: && $env{'internal.end_page'} > 1) {
9299: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9300: $env{'internal.end_page'}.' '.
1.316 albertel 9301: $env{'request.filename'});
1.315 albertel 9302: }
9303: if ( exists($env{'internal.start_page'})
9304: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9305: &Apache::lonnet::logthis('start_page called without end_page '.
9306: $env{'request.filename'});
1.315 albertel 9307: }
9308: if ( ! exists($env{'internal.start_page'})
9309: && exists($env{'internal.end_page'})) {
1.316 albertel 9310: &Apache::lonnet::logthis('end_page called without start_page'.
9311: $env{'request.filename'});
1.315 albertel 9312: }
1.306 albertel 9313: }
1.315 albertel 9314:
1.996 www 9315:
9316: sub start_scrollbox {
1.1140 raeburn 9317: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9318: unless ($outerwidth) { $outerwidth='520px'; }
9319: unless ($width) { $width='500px'; }
9320: unless ($height) { $height='200px'; }
1.1075 raeburn 9321: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9322: if ($id ne '') {
1.1140 raeburn 9323: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9324: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9325: }
1.1075 raeburn 9326: if ($bgcolor ne '') {
9327: $tdcol = "background-color: $bgcolor;";
9328: }
1.1137 raeburn 9329: my $nicescroll_js;
9330: if ($env{'browser.mobile'}) {
1.1140 raeburn 9331: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9332: }
9333: return <<"END";
9334: $nicescroll_js
9335:
9336: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9337: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9338: END
9339: }
9340:
9341: sub end_scrollbox {
9342: return '</div></td></tr></table>';
9343: }
9344:
9345: sub nicescroll_javascript {
9346: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9347: my %options;
9348: if (ref($cursor) eq 'HASH') {
9349: %options = %{$cursor};
9350: }
9351: unless ($options{'railalign'} =~ /^left|right$/) {
9352: $options{'railalign'} = 'left';
9353: }
9354: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9355: my $function = &get_users_function();
9356: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9357: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9358: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9359: }
1.1140 raeburn 9360: }
9361: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9362: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9363: $options{'cursoropacity'}='1.0';
9364: }
1.1140 raeburn 9365: } else {
9366: $options{'cursoropacity'}='1.0';
9367: }
9368: if ($options{'cursorfixedheight'} eq 'none') {
9369: delete($options{'cursorfixedheight'});
9370: } else {
9371: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9372: }
9373: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9374: delete($options{'railoffset'});
9375: }
9376: my @niceoptions;
9377: while (my($key,$value) = each(%options)) {
9378: if ($value =~ /^\{.+\}$/) {
9379: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9380: } else {
1.1140 raeburn 9381: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9382: }
1.1140 raeburn 9383: }
9384: my $nicescroll_js = '
1.1137 raeburn 9385: $(document).ready(
1.1140 raeburn 9386: function() {
9387: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9388: }
1.1137 raeburn 9389: );
9390: ';
1.1140 raeburn 9391: if ($framecheck) {
9392: $nicescroll_js .= '
9393: function expand_div(caller) {
9394: if (top === self) {
9395: document.getElementById("'.$id.'").style.width = "auto";
9396: document.getElementById("'.$id.'").style.height = "auto";
9397: } else {
9398: try {
9399: if (parent.frames) {
9400: if (parent.frames.length > 1) {
9401: var framesrc = parent.frames[1].location.href;
9402: var currsrc = framesrc.replace(/\#.*$/,"");
9403: if ((caller == "search") || (currsrc == "'.$location.'")) {
9404: document.getElementById("'.$id.'").style.width = "auto";
9405: document.getElementById("'.$id.'").style.height = "auto";
9406: }
9407: }
9408: }
9409: } catch (e) {
9410: return;
9411: }
1.1137 raeburn 9412: }
1.1140 raeburn 9413: return;
1.996 www 9414: }
1.1140 raeburn 9415: ';
9416: }
9417: if ($needjsready) {
9418: $nicescroll_js = '
9419: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9420: } else {
9421: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9422: }
9423: return $nicescroll_js;
1.996 www 9424: }
9425:
1.318 albertel 9426: sub simple_error_page {
1.1150 bisitz 9427: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9428: my %displayargs;
1.1151 raeburn 9429: if (ref($args) eq 'HASH') {
9430: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9431: if ($args->{'only_body'}) {
9432: $displayargs{'only_body'} = 1;
9433: }
9434: if ($args->{'no_nav_bar'}) {
9435: $displayargs{'no_nav_bar'} = 1;
9436: }
1.1151 raeburn 9437: } else {
9438: $msg = &mt($msg);
9439: }
1.1150 bisitz 9440:
1.318 albertel 9441: my $page =
1.1304 raeburn 9442: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9443: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9444: &Apache::loncommon::end_page();
9445: if (ref($r)) {
9446: $r->print($page);
1.327 albertel 9447: return;
1.318 albertel 9448: }
9449: return $page;
9450: }
1.347 albertel 9451:
9452: {
1.610 albertel 9453: my @row_count;
1.961 onken 9454:
9455: sub start_data_table_count {
9456: unshift(@row_count, 0);
9457: return;
9458: }
9459:
9460: sub end_data_table_count {
9461: shift(@row_count);
9462: return;
9463: }
9464:
1.347 albertel 9465: sub start_data_table {
1.1018 raeburn 9466: my ($add_class,$id) = @_;
1.422 albertel 9467: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9468: my $table_id;
9469: if (defined($id)) {
9470: $table_id = ' id="'.$id.'"';
9471: }
1.961 onken 9472: &start_data_table_count();
1.1018 raeburn 9473: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9474: }
9475:
9476: sub end_data_table {
1.961 onken 9477: &end_data_table_count();
1.389 albertel 9478: return '</table>'."\n";;
1.347 albertel 9479: }
9480:
9481: sub start_data_table_row {
1.974 wenzelju 9482: my ($add_class, $id) = @_;
1.610 albertel 9483: $row_count[0]++;
9484: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9485: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9486: $id = (' id="'.$id.'"') unless ($id eq '');
9487: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9488: }
1.471 banghart 9489:
9490: sub continue_data_table_row {
1.974 wenzelju 9491: my ($add_class, $id) = @_;
1.610 albertel 9492: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9493: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9494: $id = (' id="'.$id.'"') unless ($id eq '');
9495: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9496: }
1.347 albertel 9497:
9498: sub end_data_table_row {
1.389 albertel 9499: return '</tr>'."\n";;
1.347 albertel 9500: }
1.367 www 9501:
1.421 albertel 9502: sub start_data_table_empty_row {
1.707 bisitz 9503: # $row_count[0]++;
1.421 albertel 9504: return '<tr class="LC_empty_row" >'."\n";;
9505: }
9506:
9507: sub end_data_table_empty_row {
9508: return '</tr>'."\n";;
9509: }
9510:
1.367 www 9511: sub start_data_table_header_row {
1.389 albertel 9512: return '<tr class="LC_header_row">'."\n";;
1.367 www 9513: }
9514:
9515: sub end_data_table_header_row {
1.389 albertel 9516: return '</tr>'."\n";;
1.367 www 9517: }
1.890 droeschl 9518:
9519: sub data_table_caption {
9520: my $caption = shift;
9521: return "<caption class=\"LC_caption\">$caption</caption>";
9522: }
1.347 albertel 9523: }
9524:
1.548 albertel 9525: =pod
9526:
9527: =item * &inhibit_menu_check($arg)
9528:
9529: Checks for a inhibitmenu state and generates output to preserve it
9530:
9531: Inputs: $arg - can be any of
9532: - undef - in which case the return value is a string
9533: to add into arguments list of a uri
9534: - 'input' - in which case the return value is a HTML
9535: <form> <input> field of type hidden to
9536: preserve the value
9537: - a url - in which case the return value is the url with
9538: the neccesary cgi args added to preserve the
9539: inhibitmenu state
9540: - a ref to a url - no return value, but the string is
9541: updated to include the neccessary cgi
9542: args to preserve the inhibitmenu state
9543:
9544: =cut
9545:
9546: sub inhibit_menu_check {
9547: my ($arg) = @_;
9548: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9549: if ($arg eq 'input') {
9550: if ($env{'form.inhibitmenu'}) {
9551: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9552: } else {
9553: return
9554: }
9555: }
9556: if ($env{'form.inhibitmenu'}) {
9557: if (ref($arg)) {
9558: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9559: } elsif ($arg eq '') {
9560: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9561: } else {
9562: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9563: }
9564: }
9565: if (!ref($arg)) {
9566: return $arg;
9567: }
9568: }
9569:
1.251 albertel 9570: ###############################################
1.182 matthew 9571:
9572: =pod
9573:
1.549 albertel 9574: =back
9575:
9576: =head1 User Information Routines
9577:
9578: =over 4
9579:
1.405 albertel 9580: =item * &get_users_function()
1.182 matthew 9581:
9582: Used by &bodytag to determine the current users primary role.
9583: Returns either 'student','coordinator','admin', or 'author'.
9584:
9585: =cut
9586:
9587: ###############################################
9588: sub get_users_function {
1.815 tempelho 9589: my $function = 'norole';
1.818 tempelho 9590: if ($env{'request.role'}=~/^(st)/) {
9591: $function='student';
9592: }
1.907 raeburn 9593: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9594: $function='coordinator';
9595: }
1.258 albertel 9596: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9597: $function='admin';
9598: }
1.826 bisitz 9599: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9600: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9601: $function='author';
9602: }
9603: return $function;
1.54 www 9604: }
1.99 www 9605:
9606: ###############################################
9607:
1.233 raeburn 9608: =pod
9609:
1.821 raeburn 9610: =item * &show_course()
9611:
9612: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9613: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9614:
9615: Inputs:
9616: None
9617:
9618: Outputs:
9619: Scalar: 1 if 'Course' to be used, 0 otherwise.
9620:
9621: =cut
9622:
9623: ###############################################
9624: sub show_course {
9625: my $course = !$env{'user.adv'};
9626: if (!$env{'user.adv'}) {
9627: foreach my $env (keys(%env)) {
9628: next if ($env !~ m/^user\.priv\./);
9629: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9630: $course = 0;
9631: last;
9632: }
9633: }
9634: }
9635: return $course;
9636: }
9637:
9638: ###############################################
9639:
9640: =pod
9641:
1.542 raeburn 9642: =item * &check_user_status()
1.274 raeburn 9643:
9644: Determines current status of supplied role for a
9645: specific user. Roles can be active, previous or future.
9646:
9647: Inputs:
9648: user's domain, user's username, course's domain,
1.375 raeburn 9649: course's number, optional section ID.
1.274 raeburn 9650:
9651: Outputs:
9652: role status: active, previous or future.
9653:
9654: =cut
9655:
9656: sub check_user_status {
1.412 raeburn 9657: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9658: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9659: my @uroles = keys(%userinfo);
1.274 raeburn 9660: my $srchstr;
9661: my $active_chk = 'none';
1.412 raeburn 9662: my $now = time;
1.274 raeburn 9663: if (@uroles > 0) {
1.908 raeburn 9664: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9665: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9666: } else {
1.412 raeburn 9667: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9668: }
9669: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9670: my $role_end = 0;
9671: my $role_start = 0;
9672: $active_chk = 'active';
1.412 raeburn 9673: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9674: $role_end = $1;
9675: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9676: $role_start = $1;
1.274 raeburn 9677: }
9678: }
9679: if ($role_start > 0) {
1.412 raeburn 9680: if ($now < $role_start) {
1.274 raeburn 9681: $active_chk = 'future';
9682: }
9683: }
9684: if ($role_end > 0) {
1.412 raeburn 9685: if ($now > $role_end) {
1.274 raeburn 9686: $active_chk = 'previous';
9687: }
9688: }
9689: }
9690: }
9691: return $active_chk;
9692: }
9693:
9694: ###############################################
9695:
9696: =pod
9697:
1.405 albertel 9698: =item * &get_sections()
1.233 raeburn 9699:
9700: Determines all the sections for a course including
9701: sections with students and sections containing other roles.
1.419 raeburn 9702: Incoming parameters:
9703:
9704: 1. domain
9705: 2. course number
9706: 3. reference to array containing roles for which sections should
9707: be gathered (optional).
9708: 4. reference to array containing status types for which sections
9709: should be gathered (optional).
9710:
9711: If the third argument is undefined, sections are gathered for any role.
9712: If the fourth argument is undefined, sections are gathered for any status.
9713: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9714:
1.374 raeburn 9715: Returns section hash (keys are section IDs, values are
9716: number of users in each section), subject to the
1.419 raeburn 9717: optional roles filter, optional status filter
1.233 raeburn 9718:
9719: =cut
9720:
9721: ###############################################
9722: sub get_sections {
1.419 raeburn 9723: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9724: if (!defined($cdom) || !defined($cnum)) {
9725: my $cid = $env{'request.course.id'};
9726:
9727: return if (!defined($cid));
9728:
9729: $cdom = $env{'course.'.$cid.'.domain'};
9730: $cnum = $env{'course.'.$cid.'.num'};
9731: }
9732:
9733: my %sectioncount;
1.419 raeburn 9734: my $now = time;
1.240 albertel 9735:
1.1118 raeburn 9736: my $check_students = 1;
9737: my $only_students = 0;
9738: if (ref($possible_roles) eq 'ARRAY') {
9739: if (grep(/^st$/,@{$possible_roles})) {
9740: if (@{$possible_roles} == 1) {
9741: $only_students = 1;
9742: }
9743: } else {
9744: $check_students = 0;
9745: }
9746: }
9747:
9748: if ($check_students) {
1.276 albertel 9749: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9750: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9751: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9752: my $start_index = &Apache::loncoursedata::CL_START();
9753: my $end_index = &Apache::loncoursedata::CL_END();
9754: my $status;
1.366 albertel 9755: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9756: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9757: $data->[$status_index],
9758: $data->[$start_index],
9759: $data->[$end_index]);
9760: if ($stu_status eq 'Active') {
9761: $status = 'active';
9762: } elsif ($end < $now) {
9763: $status = 'previous';
9764: } elsif ($start > $now) {
9765: $status = 'future';
9766: }
9767: if ($section ne '-1' && $section !~ /^\s*$/) {
9768: if ((!defined($possible_status)) || (($status ne '') &&
9769: (grep/^\Q$status\E$/,@{$possible_status}))) {
9770: $sectioncount{$section}++;
9771: }
1.240 albertel 9772: }
9773: }
9774: }
1.1118 raeburn 9775: if ($only_students) {
9776: return %sectioncount;
9777: }
1.240 albertel 9778: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9779: foreach my $user (sort(keys(%courseroles))) {
9780: if ($user !~ /^(\w{2})/) { next; }
9781: my ($role) = ($user =~ /^(\w{2})/);
9782: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9783: my ($section,$status);
1.240 albertel 9784: if ($role eq 'cr' &&
9785: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9786: $section=$1;
9787: }
9788: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9789: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9790: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9791: if ($end == -1 && $start == -1) {
9792: next; #deleted role
9793: }
9794: if (!defined($possible_status)) {
9795: $sectioncount{$section}++;
9796: } else {
9797: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9798: $status = 'active';
9799: } elsif ($end < $now) {
9800: $status = 'future';
9801: } elsif ($start > $now) {
9802: $status = 'previous';
9803: }
9804: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9805: $sectioncount{$section}++;
9806: }
9807: }
1.233 raeburn 9808: }
1.366 albertel 9809: return %sectioncount;
1.233 raeburn 9810: }
9811:
1.274 raeburn 9812: ###############################################
1.294 raeburn 9813:
9814: =pod
1.405 albertel 9815:
9816: =item * &get_course_users()
9817:
1.275 raeburn 9818: Retrieves usernames:domains for users in the specified course
9819: with specific role(s), and access status.
9820:
9821: Incoming parameters:
1.277 albertel 9822: 1. course domain
9823: 2. course number
9824: 3. access status: users must have - either active,
1.275 raeburn 9825: previous, future, or all.
1.277 albertel 9826: 4. reference to array of permissible roles
1.288 raeburn 9827: 5. reference to array of section restrictions (optional)
9828: 6. reference to results object (hash of hashes).
9829: 7. reference to optional userdata hash
1.609 raeburn 9830: 8. reference to optional statushash
1.630 raeburn 9831: 9. flag if privileged users (except those set to unhide in
9832: course settings) should be excluded
1.609 raeburn 9833: Keys of top level results hash are roles.
1.275 raeburn 9834: Keys of inner hashes are username:domain, with
9835: values set to access type.
1.288 raeburn 9836: Optional userdata hash returns an array with arguments in the
9837: same order as loncoursedata::get_classlist() for student data.
9838:
1.609 raeburn 9839: Optional statushash returns
9840:
1.288 raeburn 9841: Entries for end, start, section and status are blank because
9842: of the possibility of multiple values for non-student roles.
9843:
1.275 raeburn 9844: =cut
1.405 albertel 9845:
1.275 raeburn 9846: ###############################################
1.405 albertel 9847:
1.275 raeburn 9848: sub get_course_users {
1.630 raeburn 9849: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9850: my %idx = ();
1.419 raeburn 9851: my %seclists;
1.288 raeburn 9852:
9853: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9854: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9855: $idx{end} = &Apache::loncoursedata::CL_END();
9856: $idx{start} = &Apache::loncoursedata::CL_START();
9857: $idx{id} = &Apache::loncoursedata::CL_ID();
9858: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9859: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9860: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9861:
1.290 albertel 9862: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9863: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9864: my $now = time;
1.277 albertel 9865: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9866: my $match = 0;
1.412 raeburn 9867: my $secmatch = 0;
1.419 raeburn 9868: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9869: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9870: if ($section eq '') {
9871: $section = 'none';
9872: }
1.291 albertel 9873: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9874: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9875: $secmatch = 1;
9876: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9877: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9878: $secmatch = 1;
9879: }
9880: } else {
1.419 raeburn 9881: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9882: $secmatch = 1;
9883: }
1.290 albertel 9884: }
1.412 raeburn 9885: if (!$secmatch) {
9886: next;
9887: }
1.419 raeburn 9888: }
1.275 raeburn 9889: if (defined($$types{'active'})) {
1.288 raeburn 9890: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9891: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9892: $match = 1;
1.275 raeburn 9893: }
9894: }
9895: if (defined($$types{'previous'})) {
1.609 raeburn 9896: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9897: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9898: $match = 1;
1.275 raeburn 9899: }
9900: }
9901: if (defined($$types{'future'})) {
1.609 raeburn 9902: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9903: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9904: $match = 1;
1.275 raeburn 9905: }
9906: }
1.609 raeburn 9907: if ($match) {
9908: push(@{$seclists{$student}},$section);
9909: if (ref($userdata) eq 'HASH') {
9910: $$userdata{$student} = $$classlist{$student};
9911: }
9912: if (ref($statushash) eq 'HASH') {
9913: $statushash->{$student}{'st'}{$section} = $status;
9914: }
1.288 raeburn 9915: }
1.275 raeburn 9916: }
9917: }
1.412 raeburn 9918: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9919: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9920: my $now = time;
1.609 raeburn 9921: my %displaystatus = ( previous => 'Expired',
9922: active => 'Active',
9923: future => 'Future',
9924: );
1.1121 raeburn 9925: my (%nothide,@possdoms);
1.630 raeburn 9926: if ($hidepriv) {
9927: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9928: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9929: if ($user !~ /:/) {
9930: $nothide{join(':',split(/[\@]/,$user))}=1;
9931: } else {
9932: $nothide{$user} = 1;
9933: }
9934: }
1.1121 raeburn 9935: my @possdoms = ($cdom);
9936: if ($coursehash{'checkforpriv'}) {
9937: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9938: }
1.630 raeburn 9939: }
1.439 raeburn 9940: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9941: my $match = 0;
1.412 raeburn 9942: my $secmatch = 0;
1.439 raeburn 9943: my $status;
1.412 raeburn 9944: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9945: $user =~ s/:$//;
1.439 raeburn 9946: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9947: if ($end == -1 || $start == -1) {
9948: next;
9949: }
9950: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9951: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9952: my ($uname,$udom) = split(/:/,$user);
9953: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9954: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9955: $secmatch = 1;
9956: } elsif ($usec eq '') {
1.420 albertel 9957: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9958: $secmatch = 1;
9959: }
9960: } else {
9961: if (grep(/^\Q$usec\E$/,@{$sections})) {
9962: $secmatch = 1;
9963: }
9964: }
9965: if (!$secmatch) {
9966: next;
9967: }
1.288 raeburn 9968: }
1.419 raeburn 9969: if ($usec eq '') {
9970: $usec = 'none';
9971: }
1.275 raeburn 9972: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9973: if ($hidepriv) {
1.1121 raeburn 9974: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9975: (!$nothide{$uname.':'.$udom})) {
9976: next;
9977: }
9978: }
1.503 raeburn 9979: if ($end > 0 && $end < $now) {
1.439 raeburn 9980: $status = 'previous';
9981: } elsif ($start > $now) {
9982: $status = 'future';
9983: } else {
9984: $status = 'active';
9985: }
1.277 albertel 9986: foreach my $type (keys(%{$types})) {
1.275 raeburn 9987: if ($status eq $type) {
1.420 albertel 9988: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9989: push(@{$$users{$role}{$user}},$type);
9990: }
1.288 raeburn 9991: $match = 1;
9992: }
9993: }
1.419 raeburn 9994: if (($match) && (ref($userdata) eq 'HASH')) {
9995: if (!exists($$userdata{$uname.':'.$udom})) {
9996: &get_user_info($udom,$uname,\%idx,$userdata);
9997: }
1.420 albertel 9998: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9999: push(@{$seclists{$uname.':'.$udom}},$usec);
10000: }
1.609 raeburn 10001: if (ref($statushash) eq 'HASH') {
10002: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10003: }
1.275 raeburn 10004: }
10005: }
10006: }
10007: }
1.290 albertel 10008: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10009: if ((defined($cdom)) && (defined($cnum))) {
10010: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10011: if ( defined($csettings{'internal.courseowner'}) ) {
10012: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10013: next if ($owner eq '');
10014: my ($ownername,$ownerdom);
10015: if ($owner =~ /^([^:]+):([^:]+)$/) {
10016: $ownername = $1;
10017: $ownerdom = $2;
10018: } else {
10019: $ownername = $owner;
10020: $ownerdom = $cdom;
10021: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10022: }
10023: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10024: if (defined($userdata) &&
1.609 raeburn 10025: !exists($$userdata{$owner})) {
10026: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10027: if (!grep(/^none$/,@{$seclists{$owner}})) {
10028: push(@{$seclists{$owner}},'none');
10029: }
10030: if (ref($statushash) eq 'HASH') {
10031: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10032: }
1.290 albertel 10033: }
1.279 raeburn 10034: }
10035: }
10036: }
1.419 raeburn 10037: foreach my $user (keys(%seclists)) {
10038: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10039: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10040: }
1.275 raeburn 10041: }
10042: return;
10043: }
10044:
1.288 raeburn 10045: sub get_user_info {
10046: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10047: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10048: &plainname($uname,$udom,'lastname');
1.291 albertel 10049: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10050: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10051: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10052: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10053: return;
10054: }
1.275 raeburn 10055:
1.472 raeburn 10056: ###############################################
10057:
10058: =pod
10059:
10060: =item * &get_user_quota()
10061:
1.1134 raeburn 10062: Retrieves quota assigned for storage of user files.
10063: Default is to report quota for portfolio files.
1.472 raeburn 10064:
10065: Incoming parameters:
10066: 1. user's username
10067: 2. user's domain
1.1134 raeburn 10068: 3. quota name - portfolio, author, or course
1.1136 raeburn 10069: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10070: 4. crstype - official, unofficial, textbook, placement or community,
10071: if quota name is course
1.472 raeburn 10072:
10073: Returns:
1.1163 raeburn 10074: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10075: 2. (Optional) Type of setting: custom or default
10076: (individually assigned or default for user's
10077: institutional status).
10078: 3. (Optional) - User's institutional status (e.g., faculty, staff
10079: or student - types as defined in localenroll::inst_usertypes
10080: for user's domain, which determines default quota for user.
10081: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10082:
10083: If a value has been stored in the user's environment,
1.536 raeburn 10084: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10085: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10086:
10087: =cut
10088:
10089: ###############################################
10090:
10091:
10092: sub get_user_quota {
1.1136 raeburn 10093: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10094: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10095: if (!defined($udom)) {
10096: $udom = $env{'user.domain'};
10097: }
10098: if (!defined($uname)) {
10099: $uname = $env{'user.name'};
10100: }
10101: if (($udom eq '' || $uname eq '') ||
10102: ($udom eq 'public') && ($uname eq 'public')) {
10103: $quota = 0;
1.536 raeburn 10104: $quotatype = 'default';
10105: $defquota = 0;
1.472 raeburn 10106: } else {
1.536 raeburn 10107: my $inststatus;
1.1134 raeburn 10108: if ($quotaname eq 'course') {
10109: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10110: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10111: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10112: } else {
10113: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10114: $quota = $cenv{'internal.uploadquota'};
10115: }
1.536 raeburn 10116: } else {
1.1134 raeburn 10117: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10118: if ($quotaname eq 'author') {
10119: $quota = $env{'environment.authorquota'};
10120: } else {
10121: $quota = $env{'environment.portfolioquota'};
10122: }
10123: $inststatus = $env{'environment.inststatus'};
10124: } else {
10125: my %userenv =
10126: &Apache::lonnet::get('environment',['portfolioquota',
10127: 'authorquota','inststatus'],$udom,$uname);
10128: my ($tmp) = keys(%userenv);
10129: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10130: if ($quotaname eq 'author') {
10131: $quota = $userenv{'authorquota'};
10132: } else {
10133: $quota = $userenv{'portfolioquota'};
10134: }
10135: $inststatus = $userenv{'inststatus'};
10136: } else {
10137: undef(%userenv);
10138: }
10139: }
10140: }
10141: if ($quota eq '' || wantarray) {
10142: if ($quotaname eq 'course') {
10143: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10144: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10145: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10146: ($crstype eq 'placement')) {
1.1136 raeburn 10147: $defquota = $domdefs{$crstype.'quota'};
10148: }
10149: if ($defquota eq '') {
10150: $defquota = 500;
10151: }
1.1134 raeburn 10152: } else {
10153: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10154: }
10155: if ($quota eq '') {
10156: $quota = $defquota;
10157: $quotatype = 'default';
10158: } else {
10159: $quotatype = 'custom';
10160: }
1.472 raeburn 10161: }
10162: }
1.536 raeburn 10163: if (wantarray) {
10164: return ($quota,$quotatype,$settingstatus,$defquota);
10165: } else {
10166: return $quota;
10167: }
1.472 raeburn 10168: }
10169:
10170: ###############################################
10171:
10172: =pod
10173:
10174: =item * &default_quota()
10175:
1.536 raeburn 10176: Retrieves default quota assigned for storage of user portfolio files,
10177: given an (optional) user's institutional status.
1.472 raeburn 10178:
10179: Incoming parameters:
1.1142 raeburn 10180:
1.472 raeburn 10181: 1. domain
1.536 raeburn 10182: 2. (Optional) institutional status(es). This is a : separated list of
10183: status types (e.g., faculty, staff, student etc.)
10184: which apply to the user for whom the default is being retrieved.
10185: If the institutional status string in undefined, the domain
1.1134 raeburn 10186: default quota will be returned.
10187: 3. quota name - portfolio, author, or course
10188: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10189:
10190: Returns:
1.1142 raeburn 10191:
1.1163 raeburn 10192: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10193: 2. (Optional) institutional type which determined the value of the
10194: default quota.
1.472 raeburn 10195:
10196: If a value has been stored in the domain's configuration db,
10197: it will return that, otherwise it returns 20 (for backwards
10198: compatibility with domains which have not set up a configuration
1.1163 raeburn 10199: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10200:
1.536 raeburn 10201: If the user's status includes multiple types (e.g., staff and student),
10202: the largest default quota which applies to the user determines the
10203: default quota returned.
10204:
1.472 raeburn 10205: =cut
10206:
10207: ###############################################
10208:
10209:
10210: sub default_quota {
1.1134 raeburn 10211: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10212: my ($defquota,$settingstatus);
10213: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10214: ['quotas'],$udom);
1.1134 raeburn 10215: my $key = 'defaultquota';
10216: if ($quotaname eq 'author') {
10217: $key = 'authorquota';
10218: }
1.622 raeburn 10219: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10220: if ($inststatus ne '') {
1.765 raeburn 10221: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10222: foreach my $item (@statuses) {
1.1134 raeburn 10223: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10224: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10225: if ($defquota eq '') {
1.1134 raeburn 10226: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10227: $settingstatus = $item;
1.1134 raeburn 10228: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10229: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10230: $settingstatus = $item;
10231: }
10232: }
1.1134 raeburn 10233: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10234: if ($quotahash{'quotas'}{$item} ne '') {
10235: if ($defquota eq '') {
10236: $defquota = $quotahash{'quotas'}{$item};
10237: $settingstatus = $item;
10238: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10239: $defquota = $quotahash{'quotas'}{$item};
10240: $settingstatus = $item;
10241: }
1.536 raeburn 10242: }
10243: }
10244: }
10245: }
10246: if ($defquota eq '') {
1.1134 raeburn 10247: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10248: $defquota = $quotahash{'quotas'}{$key}{'default'};
10249: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10250: $defquota = $quotahash{'quotas'}{'default'};
10251: }
1.536 raeburn 10252: $settingstatus = 'default';
1.1139 raeburn 10253: if ($defquota eq '') {
10254: if ($quotaname eq 'author') {
10255: $defquota = 500;
10256: }
10257: }
1.536 raeburn 10258: }
10259: } else {
10260: $settingstatus = 'default';
1.1134 raeburn 10261: if ($quotaname eq 'author') {
10262: $defquota = 500;
10263: } else {
10264: $defquota = 20;
10265: }
1.536 raeburn 10266: }
10267: if (wantarray) {
10268: return ($defquota,$settingstatus);
1.472 raeburn 10269: } else {
1.536 raeburn 10270: return $defquota;
1.472 raeburn 10271: }
10272: }
10273:
1.1135 raeburn 10274: ###############################################
10275:
10276: =pod
10277:
1.1136 raeburn 10278: =item * &excess_filesize_warning()
1.1135 raeburn 10279:
10280: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10281: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10282: space to be exceeded.
1.1136 raeburn 10283:
10284: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10285: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10286:
1.1165 raeburn 10287: Inputs: 7
1.1136 raeburn 10288: 1. username or coursenum
1.1135 raeburn 10289: 2. domain
1.1136 raeburn 10290: 3. context ('author' or 'course')
1.1135 raeburn 10291: 4. filename of file for which action is being requested
10292: 5. filesize (kB) of file
10293: 6. action being taken: copy or upload.
1.1237 raeburn 10294: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10295:
10296: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10297: otherwise return null.
10298:
10299: =back
1.1135 raeburn 10300:
10301: =cut
10302:
1.1136 raeburn 10303: sub excess_filesize_warning {
1.1165 raeburn 10304: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10305: my $current_disk_usage = 0;
1.1165 raeburn 10306: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10307: if ($context eq 'author') {
10308: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10309: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10310: } else {
10311: foreach my $subdir ('docs','supplemental') {
10312: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10313: }
10314: }
1.1135 raeburn 10315: $disk_quota = int($disk_quota * 1000);
10316: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10317: return '<p class="LC_warning">'.
1.1135 raeburn 10318: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10319: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10320: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10321: $disk_quota,$current_disk_usage).
10322: '</p>';
10323: }
10324: return;
10325: }
10326:
10327: ###############################################
10328:
10329:
1.1136 raeburn 10330:
10331:
1.384 raeburn 10332: sub get_secgrprole_info {
10333: my ($cdom,$cnum,$needroles,$type) = @_;
10334: my %sections_count = &get_sections($cdom,$cnum);
10335: my @sections = (sort {$a <=> $b} keys(%sections_count));
10336: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10337: my @groups = sort(keys(%curr_groups));
10338: my $allroles = [];
10339: my $rolehash;
10340: my $accesshash = {
10341: active => 'Currently has access',
10342: future => 'Will have future access',
10343: previous => 'Previously had access',
10344: };
10345: if ($needroles) {
10346: $rolehash = {'all' => 'all'};
1.385 albertel 10347: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10348: if (&Apache::lonnet::error(%user_roles)) {
10349: undef(%user_roles);
10350: }
10351: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10352: my ($role)=split(/\:/,$item,2);
10353: if ($role eq 'cr') { next; }
10354: if ($role =~ /^cr/) {
10355: $$rolehash{$role} = (split('/',$role))[3];
10356: } else {
10357: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10358: }
10359: }
10360: foreach my $key (sort(keys(%{$rolehash}))) {
10361: push(@{$allroles},$key);
10362: }
10363: push (@{$allroles},'st');
10364: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10365: }
10366: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10367: }
10368:
1.555 raeburn 10369: sub user_picker {
1.1279 raeburn 10370: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10371: my $currdom = $dom;
1.1253 raeburn 10372: my @alldoms = &Apache::lonnet::all_domains();
10373: if (@alldoms == 1) {
10374: my %domsrch = &Apache::lonnet::get_dom('configuration',
10375: ['directorysrch'],$alldoms[0]);
10376: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10377: my $showdom = $domdesc;
10378: if ($showdom eq '') {
10379: $showdom = $dom;
10380: }
10381: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10382: if ((!$domsrch{'directorysrch'}{'available'}) &&
10383: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10384: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10385: }
10386: }
10387: }
1.555 raeburn 10388: my %curr_selected = (
10389: srchin => 'dom',
1.580 raeburn 10390: srchby => 'lastname',
1.555 raeburn 10391: );
10392: my $srchterm;
1.625 raeburn 10393: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10394: if ($srch->{'srchby'} ne '') {
10395: $curr_selected{'srchby'} = $srch->{'srchby'};
10396: }
10397: if ($srch->{'srchin'} ne '') {
10398: $curr_selected{'srchin'} = $srch->{'srchin'};
10399: }
10400: if ($srch->{'srchtype'} ne '') {
10401: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10402: }
10403: if ($srch->{'srchdomain'} ne '') {
10404: $currdom = $srch->{'srchdomain'};
10405: }
10406: $srchterm = $srch->{'srchterm'};
10407: }
1.1222 damieng 10408: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10409: 'usr' => 'Search criteria',
1.563 raeburn 10410: 'doma' => 'Domain/institution to search',
1.558 albertel 10411: 'uname' => 'username',
10412: 'lastname' => 'last name',
1.555 raeburn 10413: 'lastfirst' => 'last name, first name',
1.558 albertel 10414: 'crs' => 'in this course',
1.576 raeburn 10415: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10416: 'alc' => 'all LON-CAPA',
1.573 raeburn 10417: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10418: 'exact' => 'is',
10419: 'contains' => 'contains',
1.569 raeburn 10420: 'begins' => 'begins with',
1.1222 damieng 10421: );
10422: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10423: 'youm' => "You must include some text to search for.",
10424: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10425: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10426: 'yomc' => "You must choose a domain when using an institutional directory search.",
10427: 'ymcd' => "You must choose a domain when using a domain search.",
10428: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10429: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10430: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10431: );
1.1222 damieng 10432: &html_escape(\%html_lt);
10433: &js_escape(\%js_lt);
1.1255 raeburn 10434: my $domform;
1.1277 raeburn 10435: my $allow_blank = 1;
1.1255 raeburn 10436: if ($fixeddom) {
1.1277 raeburn 10437: $allow_blank = 0;
10438: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10439: } else {
1.1287 raeburn 10440: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10441: my ($trusted,$untrusted);
1.1287 raeburn 10442: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10443: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10444: } elsif ($context eq 'author') {
1.1288 raeburn 10445: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10446: } elsif ($context eq 'domain') {
1.1288 raeburn 10447: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10448: }
1.1288 raeburn 10449: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10450: }
1.563 raeburn 10451: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10452:
10453: my @srchins = ('crs','dom','alc','instd');
10454:
10455: foreach my $option (@srchins) {
10456: # FIXME 'alc' option unavailable until
10457: # loncreateuser::print_user_query_page()
10458: # has been completed.
10459: next if ($option eq 'alc');
1.880 raeburn 10460: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10461: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10462: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10463: if ($curr_selected{'srchin'} eq $option) {
10464: $srchinsel .= '
1.1222 damieng 10465: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10466: } else {
10467: $srchinsel .= '
1.1222 damieng 10468: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10469: }
1.555 raeburn 10470: }
1.563 raeburn 10471: $srchinsel .= "\n </select>\n";
1.555 raeburn 10472:
10473: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10474: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10475: if ($curr_selected{'srchby'} eq $option) {
10476: $srchbysel .= '
1.1222 damieng 10477: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10478: } else {
10479: $srchbysel .= '
1.1222 damieng 10480: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10481: }
10482: }
10483: $srchbysel .= "\n </select>\n";
10484:
10485: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10486: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10487: if ($curr_selected{'srchtype'} eq $option) {
10488: $srchtypesel .= '
1.1222 damieng 10489: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10490: } else {
10491: $srchtypesel .= '
1.1222 damieng 10492: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10493: }
10494: }
10495: $srchtypesel .= "\n </select>\n";
10496:
1.558 albertel 10497: my ($newuserscript,$new_user_create);
1.994 raeburn 10498: my $context_dom = $env{'request.role.domain'};
10499: if ($context eq 'requestcrs') {
10500: if ($env{'form.coursedom'} ne '') {
10501: $context_dom = $env{'form.coursedom'};
10502: }
10503: }
1.556 raeburn 10504: if ($forcenewuser) {
1.576 raeburn 10505: if (ref($srch) eq 'HASH') {
1.994 raeburn 10506: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10507: if ($cancreate) {
10508: $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>';
10509: } else {
1.799 bisitz 10510: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10511: my %usertypetext = (
10512: official => 'institutional',
10513: unofficial => 'non-institutional',
10514: );
1.799 bisitz 10515: $new_user_create = '<p class="LC_warning">'
10516: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10517: .' '
10518: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10519: ,'<a href="'.$helplink.'">','</a>')
10520: .'</p><br />';
1.627 raeburn 10521: }
1.576 raeburn 10522: }
10523: }
10524:
1.556 raeburn 10525: $newuserscript = <<"ENDSCRIPT";
10526:
1.570 raeburn 10527: function setSearch(createnew,callingForm) {
1.556 raeburn 10528: if (createnew == 1) {
1.570 raeburn 10529: for (var i=0; i<callingForm.srchby.length; i++) {
10530: if (callingForm.srchby.options[i].value == 'uname') {
10531: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10532: }
10533: }
1.570 raeburn 10534: for (var i=0; i<callingForm.srchin.length; i++) {
10535: if ( callingForm.srchin.options[i].value == 'dom') {
10536: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10537: }
10538: }
1.570 raeburn 10539: for (var i=0; i<callingForm.srchtype.length; i++) {
10540: if (callingForm.srchtype.options[i].value == 'exact') {
10541: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10542: }
10543: }
1.570 raeburn 10544: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10545: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10546: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10547: }
10548: }
10549: }
10550: }
10551: ENDSCRIPT
1.558 albertel 10552:
1.556 raeburn 10553: }
10554:
1.555 raeburn 10555: my $output = <<"END_BLOCK";
1.556 raeburn 10556: <script type="text/javascript">
1.824 bisitz 10557: // <![CDATA[
1.570 raeburn 10558: function validateEntry(callingForm) {
1.558 albertel 10559:
1.556 raeburn 10560: var checkok = 1;
1.558 albertel 10561: var srchin;
1.570 raeburn 10562: for (var i=0; i<callingForm.srchin.length; i++) {
10563: if ( callingForm.srchin[i].checked ) {
10564: srchin = callingForm.srchin[i].value;
1.558 albertel 10565: }
10566: }
10567:
1.570 raeburn 10568: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10569: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10570: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10571: var srchterm = callingForm.srchterm.value;
10572: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10573: var msg = "";
10574:
10575: if (srchterm == "") {
10576: checkok = 0;
1.1222 damieng 10577: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10578: }
10579:
1.569 raeburn 10580: if (srchtype== 'begins') {
10581: if (srchterm.length < 2) {
10582: checkok = 0;
1.1222 damieng 10583: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10584: }
10585: }
10586:
1.556 raeburn 10587: if (srchtype== 'contains') {
10588: if (srchterm.length < 3) {
10589: checkok = 0;
1.1222 damieng 10590: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10591: }
10592: }
10593: if (srchin == 'instd') {
10594: if (srchdomain == '') {
10595: checkok = 0;
1.1222 damieng 10596: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10597: }
10598: }
10599: if (srchin == 'dom') {
10600: if (srchdomain == '') {
10601: checkok = 0;
1.1222 damieng 10602: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10603: }
10604: }
10605: if (srchby == 'lastfirst') {
10606: if (srchterm.indexOf(",") == -1) {
10607: checkok = 0;
1.1222 damieng 10608: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10609: }
10610: if (srchterm.indexOf(",") == srchterm.length -1) {
10611: checkok = 0;
1.1222 damieng 10612: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10613: }
10614: }
10615: if (checkok == 0) {
1.1222 damieng 10616: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10617: return;
10618: }
10619: if (checkok == 1) {
1.570 raeburn 10620: callingForm.submit();
1.556 raeburn 10621: }
10622: }
10623:
10624: $newuserscript
10625:
1.824 bisitz 10626: // ]]>
1.556 raeburn 10627: </script>
1.558 albertel 10628:
10629: $new_user_create
10630:
1.555 raeburn 10631: END_BLOCK
1.558 albertel 10632:
1.876 raeburn 10633: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10634: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10635: $domform.
10636: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10637: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10638: $srchbysel.
10639: $srchtypesel.
10640: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10641: $srchinsel.
10642: &Apache::lonhtmlcommon::row_closure(1).
10643: &Apache::lonhtmlcommon::end_pick_box().
10644: '<br />';
1.1253 raeburn 10645: return ($output,1);
1.555 raeburn 10646: }
10647:
1.612 raeburn 10648: sub user_rule_check {
1.615 raeburn 10649: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10650: my ($response,%inst_response);
1.612 raeburn 10651: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10652: if (keys(%{$usershash}) > 1) {
10653: my (%by_username,%by_id,%userdoms);
10654: my $checkid;
10655: if (ref($checks) eq 'HASH') {
10656: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10657: $checkid = 1;
10658: }
10659: }
10660: foreach my $user (keys(%{$usershash})) {
10661: my ($uname,$udom) = split(/:/,$user);
10662: if ($checkid) {
10663: if (ref($usershash->{$user}) eq 'HASH') {
10664: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10665: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10666: $userdoms{$udom} = 1;
1.1227 raeburn 10667: if (ref($inst_results) eq 'HASH') {
10668: $inst_results->{$uname.':'.$udom} = {};
10669: }
1.1226 raeburn 10670: }
10671: }
10672: } else {
10673: $by_username{$udom}{$uname} = 1;
10674: $userdoms{$udom} = 1;
1.1227 raeburn 10675: if (ref($inst_results) eq 'HASH') {
10676: $inst_results->{$uname.':'.$udom} = {};
10677: }
1.1226 raeburn 10678: }
10679: }
10680: foreach my $udom (keys(%userdoms)) {
10681: if (!$got_rules->{$udom}) {
10682: my %domconfig = &Apache::lonnet::get_dom('configuration',
10683: ['usercreation'],$udom);
10684: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10685: foreach my $item ('username','id') {
10686: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10687: $$curr_rules{$udom}{$item} =
10688: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10689: }
10690: }
10691: }
10692: $got_rules->{$udom} = 1;
10693: }
1.612 raeburn 10694: }
1.1226 raeburn 10695: if ($checkid) {
10696: foreach my $udom (keys(%by_id)) {
10697: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10698: if ($outcome eq 'ok') {
1.1227 raeburn 10699: foreach my $id (keys(%{$by_id{$udom}})) {
10700: my $uname = $by_id{$udom}{$id};
10701: $inst_response{$uname.':'.$udom} = $outcome;
10702: }
1.1226 raeburn 10703: if (ref($results) eq 'HASH') {
10704: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10705: if (exists($inst_response{$uname.':'.$udom})) {
10706: $inst_response{$uname.':'.$udom} = $outcome;
10707: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10708: }
1.1226 raeburn 10709: }
10710: }
10711: }
1.612 raeburn 10712: }
1.615 raeburn 10713: } else {
1.1226 raeburn 10714: foreach my $udom (keys(%by_username)) {
10715: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10716: if ($outcome eq 'ok') {
1.1227 raeburn 10717: foreach my $uname (keys(%{$by_username{$udom}})) {
10718: $inst_response{$uname.':'.$udom} = $outcome;
10719: }
1.1226 raeburn 10720: if (ref($results) eq 'HASH') {
10721: foreach my $uname (keys(%{$results})) {
10722: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10723: }
10724: }
10725: }
10726: }
1.612 raeburn 10727: }
1.1226 raeburn 10728: } elsif (keys(%{$usershash}) == 1) {
10729: my $user = (keys(%{$usershash}))[0];
10730: my ($uname,$udom) = split(/:/,$user);
10731: if (($udom ne '') && ($uname ne '')) {
10732: if (ref($usershash->{$user}) eq 'HASH') {
10733: if (ref($checks) eq 'HASH') {
10734: if (defined($checks->{'username'})) {
10735: ($inst_response{$user},%{$inst_results->{$user}}) =
10736: &Apache::lonnet::get_instuser($udom,$uname);
10737: } elsif (defined($checks->{'id'})) {
10738: if ($usershash->{$user}->{'id'} ne '') {
10739: ($inst_response{$user},%{$inst_results->{$user}}) =
10740: &Apache::lonnet::get_instuser($udom,undef,
10741: $usershash->{$user}->{'id'});
10742: } else {
10743: ($inst_response{$user},%{$inst_results->{$user}}) =
10744: &Apache::lonnet::get_instuser($udom,$uname);
10745: }
1.585 raeburn 10746: }
1.1226 raeburn 10747: } else {
10748: ($inst_response{$user},%{$inst_results->{$user}}) =
10749: &Apache::lonnet::get_instuser($udom,$uname);
10750: return;
10751: }
10752: if (!$got_rules->{$udom}) {
10753: my %domconfig = &Apache::lonnet::get_dom('configuration',
10754: ['usercreation'],$udom);
10755: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10756: foreach my $item ('username','id') {
10757: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10758: $$curr_rules{$udom}{$item} =
10759: $domconfig{'usercreation'}{$item.'_rule'};
10760: }
10761: }
10762: }
10763: $got_rules->{$udom} = 1;
1.585 raeburn 10764: }
10765: }
1.1226 raeburn 10766: } else {
10767: return;
10768: }
10769: } else {
10770: return;
10771: }
10772: foreach my $user (keys(%{$usershash})) {
10773: my ($uname,$udom) = split(/:/,$user);
10774: next if (($udom eq '') || ($uname eq ''));
10775: my $id;
1.1227 raeburn 10776: if (ref($inst_results) eq 'HASH') {
10777: if (ref($inst_results->{$user}) eq 'HASH') {
10778: $id = $inst_results->{$user}->{'id'};
10779: }
10780: }
10781: if ($id eq '') {
10782: if (ref($usershash->{$user})) {
10783: $id = $usershash->{$user}->{'id'};
10784: }
1.585 raeburn 10785: }
1.612 raeburn 10786: foreach my $item (keys(%{$checks})) {
10787: if (ref($$curr_rules{$udom}) eq 'HASH') {
10788: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10789: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10790: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10791: $$curr_rules{$udom}{$item});
1.612 raeburn 10792: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10793: if ($rule_check{$rule}) {
10794: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10795: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10796: if (ref($inst_results) eq 'HASH') {
10797: if (ref($inst_results->{$user}) eq 'HASH') {
10798: if (keys(%{$inst_results->{$user}}) == 0) {
10799: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10800: } elsif ($item eq 'id') {
10801: if ($inst_results->{$user}->{'id'} eq '') {
10802: $$alerts{$item}{$udom}{$uname} = 1;
10803: }
1.615 raeburn 10804: }
1.612 raeburn 10805: }
10806: }
1.615 raeburn 10807: }
10808: last;
1.585 raeburn 10809: }
10810: }
10811: }
10812: }
10813: }
10814: }
10815: }
10816: }
1.612 raeburn 10817: return;
10818: }
10819:
10820: sub user_rule_formats {
10821: my ($domain,$domdesc,$curr_rules,$check) = @_;
10822: my %text = (
10823: 'username' => 'Usernames',
10824: 'id' => 'IDs',
10825: );
10826: my $output;
10827: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10828: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10829: if (@{$ruleorder} > 0) {
1.1102 raeburn 10830: $output = '<br />'.
10831: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10832: '<span class="LC_cusr_emph">','</span>',$domdesc).
10833: ' <ul>';
1.612 raeburn 10834: foreach my $rule (@{$ruleorder}) {
10835: if (ref($curr_rules) eq 'ARRAY') {
10836: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10837: if (ref($rules->{$rule}) eq 'HASH') {
10838: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10839: $rules->{$rule}{'desc'}.'</li>';
10840: }
10841: }
10842: }
10843: }
10844: $output .= '</ul>';
10845: }
10846: }
10847: return $output;
10848: }
10849:
10850: sub instrule_disallow_msg {
1.615 raeburn 10851: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10852: my $response;
10853: my %text = (
10854: item => 'username',
10855: items => 'usernames',
10856: match => 'matches',
10857: do => 'does',
10858: action => 'a username',
10859: one => 'one',
10860: );
10861: if ($count > 1) {
10862: $text{'item'} = 'usernames';
10863: $text{'match'} ='match';
10864: $text{'do'} = 'do';
10865: $text{'action'} = 'usernames',
10866: $text{'one'} = 'ones';
10867: }
10868: if ($checkitem eq 'id') {
10869: $text{'items'} = 'IDs';
10870: $text{'item'} = 'ID';
10871: $text{'action'} = 'an ID';
1.615 raeburn 10872: if ($count > 1) {
10873: $text{'item'} = 'IDs';
10874: $text{'action'} = 'IDs';
10875: }
1.612 raeburn 10876: }
1.674 bisitz 10877: $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 10878: if ($mode eq 'upload') {
10879: if ($checkitem eq 'username') {
10880: $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'}.");
10881: } elsif ($checkitem eq 'id') {
1.674 bisitz 10882: $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 10883: }
1.669 raeburn 10884: } elsif ($mode eq 'selfcreate') {
10885: if ($checkitem eq 'id') {
10886: $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.");
10887: }
1.615 raeburn 10888: } else {
10889: if ($checkitem eq 'username') {
10890: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10891: } elsif ($checkitem eq 'id') {
10892: $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.");
10893: }
1.612 raeburn 10894: }
10895: return $response;
1.585 raeburn 10896: }
10897:
1.624 raeburn 10898: sub personal_data_fieldtitles {
10899: my %fieldtitles = &Apache::lonlocal::texthash (
10900: id => 'Student/Employee ID',
10901: permanentemail => 'E-mail address',
10902: lastname => 'Last Name',
10903: firstname => 'First Name',
10904: middlename => 'Middle Name',
10905: generation => 'Generation',
10906: gen => 'Generation',
1.765 raeburn 10907: inststatus => 'Affiliation',
1.624 raeburn 10908: );
10909: return %fieldtitles;
10910: }
10911:
1.642 raeburn 10912: sub sorted_inst_types {
10913: my ($dom) = @_;
1.1185 raeburn 10914: my ($usertypes,$order);
10915: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10916: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10917: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10918: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10919: } else {
10920: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10921: }
1.642 raeburn 10922: my $othertitle = &mt('All users');
10923: if ($env{'request.course.id'}) {
1.668 raeburn 10924: $othertitle = &mt('Any users');
1.642 raeburn 10925: }
10926: my @types;
10927: if (ref($order) eq 'ARRAY') {
10928: @types = @{$order};
10929: }
10930: if (@types == 0) {
10931: if (ref($usertypes) eq 'HASH') {
10932: @types = sort(keys(%{$usertypes}));
10933: }
10934: }
10935: if (keys(%{$usertypes}) > 0) {
10936: $othertitle = &mt('Other users');
10937: }
10938: return ($othertitle,$usertypes,\@types);
10939: }
10940:
1.645 raeburn 10941: sub get_institutional_codes {
10942: my ($settings,$allcourses,$LC_code) = @_;
10943: # Get complete list of course sections to update
10944: my @currsections = ();
10945: my @currxlists = ();
10946: my $coursecode = $$settings{'internal.coursecode'};
10947:
10948: if ($$settings{'internal.sectionnums'} ne '') {
10949: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10950: }
10951:
10952: if ($$settings{'internal.crosslistings'} ne '') {
10953: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10954: }
10955:
10956: if (@currxlists > 0) {
10957: foreach (@currxlists) {
10958: if (m/^([^:]+):(\w*)$/) {
10959: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10960: push(@{$allcourses},$1);
1.645 raeburn 10961: $$LC_code{$1} = $2;
10962: }
10963: }
10964: }
10965: }
10966:
10967: if (@currsections > 0) {
10968: foreach (@currsections) {
10969: if (m/^(\w+):(\w*)$/) {
10970: my $sec = $coursecode.$1;
10971: my $lc_sec = $2;
10972: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10973: push(@{$allcourses},$sec);
1.645 raeburn 10974: $$LC_code{$sec} = $lc_sec;
10975: }
10976: }
10977: }
10978: }
10979: return;
10980: }
10981:
1.971 raeburn 10982: sub get_standard_codeitems {
10983: return ('Year','Semester','Department','Number','Section');
10984: }
10985:
1.112 bowersj2 10986: =pod
10987:
1.780 raeburn 10988: =head1 Slot Helpers
10989:
10990: =over 4
10991:
10992: =item * sorted_slots()
10993:
1.1040 raeburn 10994: Sorts an array of slot names in order of an optional sort key,
10995: default sort is by slot start time (earliest first).
1.780 raeburn 10996:
10997: Inputs:
10998:
10999: =over 4
11000:
11001: slotsarr - Reference to array of unsorted slot names.
11002:
11003: slots - Reference to hash of hash, where outer hash keys are slot names.
11004:
1.1040 raeburn 11005: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11006:
1.549 albertel 11007: =back
11008:
1.780 raeburn 11009: Returns:
11010:
11011: =over 4
11012:
1.1040 raeburn 11013: sorted - An array of slot names sorted by a specified sort key
11014: (default sort key is start time of the slot).
1.780 raeburn 11015:
11016: =back
11017:
11018: =cut
11019:
11020:
11021: sub sorted_slots {
1.1040 raeburn 11022: my ($slotsarr,$slots,$sortkey) = @_;
11023: if ($sortkey eq '') {
11024: $sortkey = 'starttime';
11025: }
1.780 raeburn 11026: my @sorted;
11027: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11028: @sorted =
11029: sort {
11030: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11031: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11032: }
11033: if (ref($slots->{$a})) { return -1;}
11034: if (ref($slots->{$b})) { return 1;}
11035: return 0;
11036: } @{$slotsarr};
11037: }
11038: return @sorted;
11039: }
11040:
1.1040 raeburn 11041: =pod
11042:
11043: =item * get_future_slots()
11044:
11045: Inputs:
11046:
11047: =over 4
11048:
11049: cnum - course number
11050:
11051: cdom - course domain
11052:
11053: now - current UNIX time
11054:
11055: symb - optional symb
11056:
11057: =back
11058:
11059: Returns:
11060:
11061: =over 4
11062:
11063: sorted_reservable - ref to array of student_schedulable slots currently
11064: reservable, ordered by end date of reservation period.
11065:
11066: reservable_now - ref to hash of student_schedulable slots currently
11067: reservable.
11068:
11069: Keys in inner hash are:
11070: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11071: (b) endreserve: end date of reservation period.
11072: (c) uniqueperiod: start,end dates when slot is to be uniquely
11073: selected.
1.1040 raeburn 11074:
11075: sorted_future - ref to array of student_schedulable slots reservable in
11076: the future, ordered by start date of reservation period.
11077:
11078: future_reservable - ref to hash of student_schedulable slots reservable
11079: in the future.
11080:
11081: Keys in inner hash are:
11082: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11083: (b) startreserve: start date of reservation period.
11084: (c) uniqueperiod: start,end dates when slot is to be uniquely
11085: selected.
1.1040 raeburn 11086:
11087: =back
11088:
11089: =cut
11090:
11091: sub get_future_slots {
11092: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11093: my $map;
11094: if ($symb) {
11095: ($map) = &Apache::lonnet::decode_symb($symb);
11096: }
1.1040 raeburn 11097: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11098: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11099: foreach my $slot (keys(%slots)) {
11100: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11101: if ($symb) {
1.1229 raeburn 11102: if ($slots{$slot}->{'symb'} ne '') {
11103: my $canuse;
11104: my %oksymbs;
11105: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11106: map { $oksymbs{$_} = 1; } @slotsymbs;
11107: if ($oksymbs{$symb}) {
11108: $canuse = 1;
11109: } else {
11110: foreach my $item (@slotsymbs) {
11111: if ($item =~ /\.(page|sequence)$/) {
11112: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11113: if (($map ne '') && ($map eq $sloturl)) {
11114: $canuse = 1;
11115: last;
11116: }
11117: }
11118: }
11119: }
11120: next unless ($canuse);
11121: }
1.1040 raeburn 11122: }
11123: if (($slots{$slot}->{'starttime'} > $now) &&
11124: ($slots{$slot}->{'endtime'} > $now)) {
11125: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11126: my $userallowed = 0;
11127: if ($slots{$slot}->{'allowedsections'}) {
11128: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11129: if (!defined($env{'request.role.sec'})
11130: && grep(/^No section assigned$/,@allowed_sec)) {
11131: $userallowed=1;
11132: } else {
11133: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11134: $userallowed=1;
11135: }
11136: }
11137: unless ($userallowed) {
11138: if (defined($env{'request.course.groups'})) {
11139: my @groups = split(/:/,$env{'request.course.groups'});
11140: foreach my $group (@groups) {
11141: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11142: $userallowed=1;
11143: last;
11144: }
11145: }
11146: }
11147: }
11148: }
11149: if ($slots{$slot}->{'allowedusers'}) {
11150: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11151: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11152: if (grep(/^\Q$user\E$/,@allowed_users)) {
11153: $userallowed = 1;
11154: }
11155: }
11156: next unless($userallowed);
11157: }
11158: my $startreserve = $slots{$slot}->{'startreserve'};
11159: my $endreserve = $slots{$slot}->{'endreserve'};
11160: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11161: my $uniqueperiod;
11162: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11163: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11164: }
1.1040 raeburn 11165: if (($startreserve < $now) &&
11166: (!$endreserve || $endreserve > $now)) {
11167: my $lastres = $endreserve;
11168: if (!$lastres) {
11169: $lastres = $slots{$slot}->{'starttime'};
11170: }
11171: $reservable_now{$slot} = {
11172: symb => $symb,
1.1250 raeburn 11173: endreserve => $lastres,
11174: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11175: };
11176: } elsif (($startreserve > $now) &&
11177: (!$endreserve || $endreserve > $startreserve)) {
11178: $future_reservable{$slot} = {
11179: symb => $symb,
1.1250 raeburn 11180: startreserve => $startreserve,
11181: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11182: };
11183: }
11184: }
11185: }
11186: my @unsorted_reservable = keys(%reservable_now);
11187: if (@unsorted_reservable > 0) {
11188: @sorted_reservable =
11189: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11190: }
11191: my @unsorted_future = keys(%future_reservable);
11192: if (@unsorted_future > 0) {
11193: @sorted_future =
11194: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11195: }
11196: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11197: }
1.780 raeburn 11198:
11199: =pod
11200:
1.1057 foxr 11201: =back
11202:
1.549 albertel 11203: =head1 HTTP Helpers
11204:
11205: =over 4
11206:
1.648 raeburn 11207: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11208:
1.258 albertel 11209: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11210: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11211: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11212:
11213: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11214: $possible_names is an ref to an array of form element names. As an example:
11215: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11216: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11217:
11218: =cut
1.1 albertel 11219:
1.6 albertel 11220: sub get_unprocessed_cgi {
1.25 albertel 11221: my ($query,$possible_names)= @_;
1.26 matthew 11222: # $Apache::lonxml::debug=1;
1.356 albertel 11223: foreach my $pair (split(/&/,$query)) {
11224: my ($name, $value) = split(/=/,$pair);
1.369 www 11225: $name = &unescape($name);
1.25 albertel 11226: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11227: $value =~ tr/+/ /;
11228: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11229: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11230: }
1.16 harris41 11231: }
1.6 albertel 11232: }
11233:
1.112 bowersj2 11234: =pod
11235:
1.648 raeburn 11236: =item * &cacheheader()
1.112 bowersj2 11237:
11238: returns cache-controlling header code
11239:
11240: =cut
11241:
1.7 albertel 11242: sub cacheheader {
1.258 albertel 11243: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11244: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11245: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11246: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11247: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11248: return $output;
1.7 albertel 11249: }
11250:
1.112 bowersj2 11251: =pod
11252:
1.648 raeburn 11253: =item * &no_cache($r)
1.112 bowersj2 11254:
11255: specifies header code to not have cache
11256:
11257: =cut
11258:
1.9 albertel 11259: sub no_cache {
1.216 albertel 11260: my ($r) = @_;
11261: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11262: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11263: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11264: $r->no_cache(1);
11265: $r->header_out("Expires" => $date);
11266: $r->header_out("Pragma" => "no-cache");
1.123 www 11267: }
11268:
11269: sub content_type {
1.181 albertel 11270: my ($r,$type,$charset) = @_;
1.299 foxr 11271: if ($r) {
11272: # Note that printout.pl calls this with undef for $r.
11273: &no_cache($r);
11274: }
1.258 albertel 11275: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11276: unless ($charset) {
11277: $charset=&Apache::lonlocal::current_encoding;
11278: }
11279: if ($charset) { $type.='; charset='.$charset; }
11280: if ($r) {
11281: $r->content_type($type);
11282: } else {
11283: print("Content-type: $type\n\n");
11284: }
1.9 albertel 11285: }
1.25 albertel 11286:
1.112 bowersj2 11287: =pod
11288:
1.648 raeburn 11289: =item * &add_to_env($name,$value)
1.112 bowersj2 11290:
1.258 albertel 11291: adds $name to the %env hash with value
1.112 bowersj2 11292: $value, if $name already exists, the entry is converted to an array
11293: reference and $value is added to the array.
11294:
11295: =cut
11296:
1.25 albertel 11297: sub add_to_env {
11298: my ($name,$value)=@_;
1.258 albertel 11299: if (defined($env{$name})) {
11300: if (ref($env{$name})) {
1.25 albertel 11301: #already have multiple values
1.258 albertel 11302: push(@{ $env{$name} },$value);
1.25 albertel 11303: } else {
11304: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11305: my $first=$env{$name};
11306: undef($env{$name});
11307: push(@{ $env{$name} },$first,$value);
1.25 albertel 11308: }
11309: } else {
1.258 albertel 11310: $env{$name}=$value;
1.25 albertel 11311: }
1.31 albertel 11312: }
1.149 albertel 11313:
11314: =pod
11315:
1.648 raeburn 11316: =item * &get_env_multiple($name)
1.149 albertel 11317:
1.258 albertel 11318: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11319: values may be defined and end up as an array ref.
11320:
11321: returns an array of values
11322:
11323: =cut
11324:
11325: sub get_env_multiple {
11326: my ($name) = @_;
11327: my @values;
1.258 albertel 11328: if (defined($env{$name})) {
1.149 albertel 11329: # exists is it an array
1.258 albertel 11330: if (ref($env{$name})) {
11331: @values=@{ $env{$name} };
1.149 albertel 11332: } else {
1.258 albertel 11333: $values[0]=$env{$name};
1.149 albertel 11334: }
11335: }
11336: return(@values);
11337: }
11338:
1.1249 damieng 11339: # Looks at given dependencies, and returns something depending on the context.
11340: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11341: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11342: # For all other contexts, returns ($output, $counter, $numpathchg).
11343: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11344: # $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.
11345: # $numpathchg: integer with the number of cleaned up dependency paths.
11346: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11347: # \%mapping: hash reference clean path -> original path for all dependencies.
11348: # @param {string} actionurl - The path to the handler, indicative of the context.
11349: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11350: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11351: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11352: # @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)
11353: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11354: sub ask_for_embedded_content {
1.1249 damieng 11355: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11356: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11357: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11358: %currsubfile,%unused,$rem);
1.1071 raeburn 11359: my $counter = 0;
11360: my $numnew = 0;
1.987 raeburn 11361: my $numremref = 0;
11362: my $numinvalid = 0;
11363: my $numpathchg = 0;
11364: my $numexisting = 0;
1.1071 raeburn 11365: my $numunused = 0;
11366: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11367: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11368: my $heading = &mt('Upload embedded files');
11369: my $buttontext = &mt('Upload');
11370:
1.1249 damieng 11371: # fills these variables based on the context:
11372: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11373: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11374: if ($env{'request.course.id'}) {
1.1123 raeburn 11375: if ($actionurl eq '/adm/dependencies') {
11376: $navmap = Apache::lonnavmaps::navmap->new();
11377: }
11378: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11379: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11380: }
1.1123 raeburn 11381: if (($actionurl eq '/adm/portfolio') ||
11382: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11383: my $current_path='/';
11384: if ($env{'form.currentpath'}) {
11385: $current_path = $env{'form.currentpath'};
11386: }
11387: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11388: $udom = $cdom;
11389: $uname = $cnum;
1.984 raeburn 11390: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11391: } else {
11392: $udom = $env{'user.domain'};
11393: $uname = $env{'user.name'};
11394: $url = '/userfiles/portfolio';
11395: }
1.987 raeburn 11396: $toplevel = $url.'/';
1.984 raeburn 11397: $url .= $current_path;
11398: $getpropath = 1;
1.987 raeburn 11399: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11400: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11401: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11402: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11403: $toplevel = $url;
1.984 raeburn 11404: if ($rest ne '') {
1.987 raeburn 11405: $url .= $rest;
11406: }
11407: } elsif ($actionurl eq '/adm/coursedocs') {
11408: if (ref($args) eq 'HASH') {
1.1071 raeburn 11409: $url = $args->{'docs_url'};
11410: $toplevel = $url;
1.1084 raeburn 11411: if ($args->{'context'} eq 'paste') {
11412: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11413: ($path) =
11414: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11415: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11416: $fileloc =~ s{^/}{};
11417: }
1.1071 raeburn 11418: }
1.1084 raeburn 11419: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11420: if ($env{'request.course.id'} ne '') {
11421: if (ref($args) eq 'HASH') {
11422: $url = $args->{'docs_url'};
11423: $title = $args->{'docs_title'};
1.1126 raeburn 11424: $toplevel = $url;
11425: unless ($toplevel =~ m{^/}) {
11426: $toplevel = "/$url";
11427: }
1.1085 raeburn 11428: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11429: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11430: $path = $1;
11431: } else {
11432: ($path) =
11433: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11434: }
1.1195 raeburn 11435: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11436: $fileloc = $toplevel;
11437: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11438: my ($udom,$uname,$fname) =
11439: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11440: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11441: } else {
11442: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11443: }
1.1071 raeburn 11444: $fileloc =~ s{^/}{};
11445: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11446: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11447: }
1.987 raeburn 11448: }
1.1123 raeburn 11449: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11450: $udom = $cdom;
11451: $uname = $cnum;
11452: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11453: $toplevel = $url;
11454: $path = $url;
11455: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11456: $fileloc =~ s{^/}{};
1.987 raeburn 11457: }
1.1249 damieng 11458:
11459: # parses the dependency paths to get some info
11460: # fills $newfiles, $mapping, $subdependencies, $dependencies
11461: # $newfiles: hash URL -> 1 for new files or external URLs
11462: # (will be completed later)
11463: # $mapping:
11464: # for external URLs: external URL -> external URL
11465: # for relative paths: clean path -> original path
11466: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11467: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11468: foreach my $file (keys(%{$allfiles})) {
11469: my $embed_file;
11470: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11471: $embed_file = $1;
11472: } else {
11473: $embed_file = $file;
11474: }
1.1158 raeburn 11475: my ($absolutepath,$cleaned_file);
11476: if ($embed_file =~ m{^\w+://}) {
11477: $cleaned_file = $embed_file;
1.1147 raeburn 11478: $newfiles{$cleaned_file} = 1;
11479: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11480: } else {
1.1158 raeburn 11481: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11482: if ($embed_file =~ m{^/}) {
11483: $absolutepath = $embed_file;
11484: }
1.1147 raeburn 11485: if ($cleaned_file =~ m{/}) {
11486: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11487: $path = &check_for_traversal($path,$url,$toplevel);
11488: my $item = $fname;
11489: if ($path ne '') {
11490: $item = $path.'/'.$fname;
11491: $subdependencies{$path}{$fname} = 1;
11492: } else {
11493: $dependencies{$item} = 1;
11494: }
11495: if ($absolutepath) {
11496: $mapping{$item} = $absolutepath;
11497: } else {
11498: $mapping{$item} = $embed_file;
11499: }
11500: } else {
11501: $dependencies{$embed_file} = 1;
11502: if ($absolutepath) {
1.1147 raeburn 11503: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11504: } else {
1.1147 raeburn 11505: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11506: }
11507: }
1.984 raeburn 11508: }
11509: }
1.1249 damieng 11510:
11511: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11512: # and lists
11513: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11514: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11515: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11516: # the path had to be cleaned up
11517: # $existing: hash clean path -> 1 if the file exists
11518: # $numexisting: number of keys in $existing
11519: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11520: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11521: # dependency subdirectories that are
11522: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11523: my $dirptr = 16384;
1.984 raeburn 11524: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11525: $currsubfile{$path} = {};
1.1123 raeburn 11526: if (($actionurl eq '/adm/portfolio') ||
11527: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11528: my ($sublistref,$listerror) =
11529: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11530: if (ref($sublistref) eq 'ARRAY') {
11531: foreach my $line (@{$sublistref}) {
11532: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11533: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11534: }
1.984 raeburn 11535: }
1.987 raeburn 11536: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11537: if (opendir(my $dir,$url.'/'.$path)) {
11538: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11539: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11540: }
1.1084 raeburn 11541: } elsif (($actionurl eq '/adm/dependencies') ||
11542: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11543: ($args->{'context'} eq 'paste')) ||
11544: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11545: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11546: my $dir;
11547: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11548: $dir = $fileloc;
11549: } else {
11550: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11551: }
1.1071 raeburn 11552: if ($dir ne '') {
11553: my ($sublistref,$listerror) =
11554: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11555: if (ref($sublistref) eq 'ARRAY') {
11556: foreach my $line (@{$sublistref}) {
11557: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11558: undef,$mtime)=split(/\&/,$line,12);
11559: unless (($testdir&$dirptr) ||
11560: ($file_name =~ /^\.\.?$/)) {
11561: $currsubfile{$path}{$file_name} = [$size,$mtime];
11562: }
11563: }
11564: }
11565: }
1.984 raeburn 11566: }
11567: }
11568: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11569: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11570: my $item = $path.'/'.$file;
11571: unless ($mapping{$item} eq $item) {
11572: $pathchanges{$item} = 1;
11573: }
11574: $existing{$item} = 1;
11575: $numexisting ++;
11576: } else {
11577: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11578: }
11579: }
1.1071 raeburn 11580: if ($actionurl eq '/adm/dependencies') {
11581: foreach my $path (keys(%currsubfile)) {
11582: if (ref($currsubfile{$path}) eq 'HASH') {
11583: foreach my $file (keys(%{$currsubfile{$path}})) {
11584: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11585: next if (($rem ne '') &&
11586: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11587: (ref($navmap) &&
11588: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11589: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11590: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11591: $unused{$path.'/'.$file} = 1;
11592: }
11593: }
11594: }
11595: }
11596: }
1.984 raeburn 11597: }
1.1249 damieng 11598:
11599: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11600: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11601: my %currfile;
1.1123 raeburn 11602: if (($actionurl eq '/adm/portfolio') ||
11603: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11604: my ($dirlistref,$listerror) =
11605: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11606: if (ref($dirlistref) eq 'ARRAY') {
11607: foreach my $line (@{$dirlistref}) {
11608: my ($file_name,$rest) = split(/\&/,$line,2);
11609: $currfile{$file_name} = 1;
11610: }
1.984 raeburn 11611: }
1.987 raeburn 11612: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11613: if (opendir(my $dir,$url)) {
1.987 raeburn 11614: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11615: map {$currfile{$_} = 1;} @dir_list;
11616: }
1.1084 raeburn 11617: } elsif (($actionurl eq '/adm/dependencies') ||
11618: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11619: ($args->{'context'} eq 'paste')) ||
11620: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11621: if ($env{'request.course.id'} ne '') {
11622: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11623: if ($dir ne '') {
11624: my ($dirlistref,$listerror) =
11625: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11626: if (ref($dirlistref) eq 'ARRAY') {
11627: foreach my $line (@{$dirlistref}) {
11628: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11629: $size,undef,$mtime)=split(/\&/,$line,12);
11630: unless (($testdir&$dirptr) ||
11631: ($file_name =~ /^\.\.?$/)) {
11632: $currfile{$file_name} = [$size,$mtime];
11633: }
11634: }
11635: }
11636: }
11637: }
1.984 raeburn 11638: }
1.1249 damieng 11639: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11640: # are not in subdirectories, using $currfile
1.984 raeburn 11641: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11642: if (exists($currfile{$file})) {
1.987 raeburn 11643: unless ($mapping{$file} eq $file) {
11644: $pathchanges{$file} = 1;
11645: }
11646: $existing{$file} = 1;
11647: $numexisting ++;
11648: } else {
1.984 raeburn 11649: $newfiles{$file} = 1;
11650: }
11651: }
1.1071 raeburn 11652: foreach my $file (keys(%currfile)) {
11653: unless (($file eq $filename) ||
11654: ($file eq $filename.'.bak') ||
11655: ($dependencies{$file})) {
1.1085 raeburn 11656: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11657: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11658: next if (($rem ne '') &&
11659: (($env{"httpref.$rem".$file} ne '') ||
11660: (ref($navmap) &&
11661: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11662: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11663: ($navmap->getResourceByUrl($rem.$1)))))));
11664: }
1.1085 raeburn 11665: }
1.1071 raeburn 11666: $unused{$file} = 1;
11667: }
11668: }
1.1249 damieng 11669:
11670: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11671: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11672: ($args->{'context'} eq 'paste')) {
11673: $counter = scalar(keys(%existing));
11674: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11675: return ($output,$counter,$numpathchg,\%existing);
11676: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11677: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11678: $counter = scalar(keys(%existing));
11679: $numpathchg = scalar(keys(%pathchanges));
11680: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11681: }
1.1249 damieng 11682:
11683: # returns HTML otherwise, with dependency results and to ask for more uploads
11684:
11685: # $upload_output: missing dependencies (with upload form)
11686: # $modify_output: uploaded dependencies (in use)
11687: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11688: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11689: if ($actionurl eq '/adm/dependencies') {
11690: next if ($embed_file =~ m{^\w+://});
11691: }
1.660 raeburn 11692: $upload_output .= &start_data_table_row().
1.1123 raeburn 11693: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11694: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11695: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11696: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11697: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11698: }
1.1123 raeburn 11699: $upload_output .= '</td>';
1.1071 raeburn 11700: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11701: $upload_output.='<td align="right">'.
11702: '<span class="LC_info LC_fontsize_medium">'.
11703: &mt("URL points to web address").'</span>';
1.987 raeburn 11704: $numremref++;
1.660 raeburn 11705: } elsif ($args->{'error_on_invalid_names'}
11706: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11707: $upload_output.='<td align="right"><span class="LC_warning">'.
11708: &mt('Invalid characters').'</span>';
1.987 raeburn 11709: $numinvalid++;
1.660 raeburn 11710: } else {
1.1123 raeburn 11711: $upload_output .= '<td>'.
11712: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11713: $embed_file,\%mapping,
1.1071 raeburn 11714: $allfiles,$codebase,'upload');
11715: $counter ++;
11716: $numnew ++;
1.987 raeburn 11717: }
11718: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11719: }
11720: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11721: if ($actionurl eq '/adm/dependencies') {
11722: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11723: $modify_output .= &start_data_table_row().
11724: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11725: '<img src="'.&icon($embed_file).'" border="0" />'.
11726: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11727: '<td>'.$size.'</td>'.
11728: '<td>'.$mtime.'</td>'.
11729: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11730: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11731: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11732: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11733: &embedded_file_element('upload_embedded',$counter,
11734: $embed_file,\%mapping,
11735: $allfiles,$codebase,'modify').
11736: '</div></td>'.
11737: &end_data_table_row()."\n";
11738: $counter ++;
11739: } else {
11740: $upload_output .= &start_data_table_row().
1.1123 raeburn 11741: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11742: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11743: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11744: &Apache::loncommon::end_data_table_row()."\n";
11745: }
11746: }
11747: my $delidx = $counter;
11748: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11749: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11750: $delete_output .= &start_data_table_row().
11751: '<td><img src="'.&icon($oldfile).'" />'.
11752: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11753: '<td>'.$size.'</td>'.
11754: '<td>'.$mtime.'</td>'.
11755: '<td><label><input type="checkbox" name="del_upload_dep" '.
11756: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11757: &embedded_file_element('upload_embedded',$delidx,
11758: $oldfile,\%mapping,$allfiles,
11759: $codebase,'delete').'</td>'.
11760: &end_data_table_row()."\n";
11761: $numunused ++;
11762: $delidx ++;
1.987 raeburn 11763: }
11764: if ($upload_output) {
11765: $upload_output = &start_data_table().
11766: $upload_output.
11767: &end_data_table()."\n";
11768: }
1.1071 raeburn 11769: if ($modify_output) {
11770: $modify_output = &start_data_table().
11771: &start_data_table_header_row().
11772: '<th>'.&mt('File').'</th>'.
11773: '<th>'.&mt('Size (KB)').'</th>'.
11774: '<th>'.&mt('Modified').'</th>'.
11775: '<th>'.&mt('Upload replacement?').'</th>'.
11776: &end_data_table_header_row().
11777: $modify_output.
11778: &end_data_table()."\n";
11779: }
11780: if ($delete_output) {
11781: $delete_output = &start_data_table().
11782: &start_data_table_header_row().
11783: '<th>'.&mt('File').'</th>'.
11784: '<th>'.&mt('Size (KB)').'</th>'.
11785: '<th>'.&mt('Modified').'</th>'.
11786: '<th>'.&mt('Delete?').'</th>'.
11787: &end_data_table_header_row().
11788: $delete_output.
11789: &end_data_table()."\n";
11790: }
1.987 raeburn 11791: my $applies = 0;
11792: if ($numremref) {
11793: $applies ++;
11794: }
11795: if ($numinvalid) {
11796: $applies ++;
11797: }
11798: if ($numexisting) {
11799: $applies ++;
11800: }
1.1071 raeburn 11801: if ($counter || $numunused) {
1.987 raeburn 11802: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11803: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11804: $state.'<h3>'.$heading.'</h3>';
11805: if ($actionurl eq '/adm/dependencies') {
11806: if ($numnew) {
11807: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11808: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11809: $upload_output.'<br />'."\n";
11810: }
11811: if ($numexisting) {
11812: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11813: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11814: $modify_output.'<br />'."\n";
11815: $buttontext = &mt('Save changes');
11816: }
11817: if ($numunused) {
11818: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11819: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11820: $delete_output.'<br />'."\n";
11821: $buttontext = &mt('Save changes');
11822: }
11823: } else {
11824: $output .= $upload_output.'<br />'."\n";
11825: }
11826: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11827: $counter.'" />'."\n";
11828: if ($actionurl eq '/adm/dependencies') {
11829: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11830: $numnew.'" />'."\n";
11831: } elsif ($actionurl eq '') {
1.987 raeburn 11832: $output .= '<input type="hidden" name="phase" value="three" />';
11833: }
11834: } elsif ($applies) {
11835: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11836: if ($applies > 1) {
11837: $output .=
1.1123 raeburn 11838: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11839: if ($numremref) {
11840: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11841: }
11842: if ($numinvalid) {
11843: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11844: }
11845: if ($numexisting) {
11846: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11847: }
11848: $output .= '</ul><br />';
11849: } elsif ($numremref) {
11850: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11851: } elsif ($numinvalid) {
11852: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11853: } elsif ($numexisting) {
11854: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11855: }
11856: $output .= $upload_output.'<br />';
11857: }
11858: my ($pathchange_output,$chgcount);
1.1071 raeburn 11859: $chgcount = $counter;
1.987 raeburn 11860: if (keys(%pathchanges) > 0) {
11861: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11862: if ($counter) {
1.987 raeburn 11863: $output .= &embedded_file_element('pathchange',$chgcount,
11864: $embed_file,\%mapping,
1.1071 raeburn 11865: $allfiles,$codebase,'change');
1.987 raeburn 11866: } else {
11867: $pathchange_output .=
11868: &start_data_table_row().
11869: '<td><input type ="checkbox" name="namechange" value="'.
11870: $chgcount.'" checked="checked" /></td>'.
11871: '<td>'.$mapping{$embed_file}.'</td>'.
11872: '<td>'.$embed_file.
11873: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11874: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11875: '</td>'.&end_data_table_row();
1.660 raeburn 11876: }
1.987 raeburn 11877: $numpathchg ++;
11878: $chgcount ++;
1.660 raeburn 11879: }
11880: }
1.1127 raeburn 11881: if (($counter) || ($numunused)) {
1.987 raeburn 11882: if ($numpathchg) {
11883: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11884: $numpathchg.'" />'."\n";
11885: }
11886: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11887: ($actionurl eq '/adm/imsimport')) {
11888: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11889: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11890: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11891: } elsif ($actionurl eq '/adm/dependencies') {
11892: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11893: }
1.1123 raeburn 11894: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11895: } elsif ($numpathchg) {
11896: my %pathchange = ();
11897: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11898: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11899: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11900: }
1.987 raeburn 11901: }
1.1071 raeburn 11902: return ($output,$counter,$numpathchg);
1.987 raeburn 11903: }
11904:
1.1147 raeburn 11905: =pod
11906:
11907: =item * clean_path($name)
11908:
11909: Performs clean-up of directories, subdirectories and filename in an
11910: embedded object, referenced in an HTML file which is being uploaded
11911: to a course or portfolio, where
11912: "Upload embedded images/multimedia files if HTML file" checkbox was
11913: checked.
11914:
11915: Clean-up is similar to replacements in lonnet::clean_filename()
11916: except each / between sub-directory and next level is preserved.
11917:
11918: =cut
11919:
11920: sub clean_path {
11921: my ($embed_file) = @_;
11922: $embed_file =~s{^/+}{};
11923: my @contents;
11924: if ($embed_file =~ m{/}) {
11925: @contents = split(/\//,$embed_file);
11926: } else {
11927: @contents = ($embed_file);
11928: }
11929: my $lastidx = scalar(@contents)-1;
11930: for (my $i=0; $i<=$lastidx; $i++) {
11931: $contents[$i]=~s{\\}{/}g;
11932: $contents[$i]=~s/\s+/\_/g;
11933: $contents[$i]=~s{[^/\w\.\-]}{}g;
11934: if ($i == $lastidx) {
11935: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11936: }
11937: }
11938: if ($lastidx > 0) {
11939: return join('/',@contents);
11940: } else {
11941: return $contents[0];
11942: }
11943: }
11944:
1.987 raeburn 11945: sub embedded_file_element {
1.1071 raeburn 11946: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11947: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11948: (ref($codebase) eq 'HASH'));
11949: my $output;
1.1071 raeburn 11950: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11951: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11952: }
11953: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11954: &escape($embed_file).'" />';
11955: unless (($context eq 'upload_embedded') &&
11956: ($mapping->{$embed_file} eq $embed_file)) {
11957: $output .='
11958: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11959: }
11960: my $attrib;
11961: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11962: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11963: }
11964: $output .=
11965: "\n\t\t".
11966: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11967: $attrib.'" />';
11968: if (exists($codebase->{$mapping->{$embed_file}})) {
11969: $output .=
11970: "\n\t\t".
11971: '<input name="codebase_'.$num.'" type="hidden" value="'.
11972: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11973: }
1.987 raeburn 11974: return $output;
1.660 raeburn 11975: }
11976:
1.1071 raeburn 11977: sub get_dependency_details {
11978: my ($currfile,$currsubfile,$embed_file) = @_;
11979: my ($size,$mtime,$showsize,$showmtime);
11980: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11981: if ($embed_file =~ m{/}) {
11982: my ($path,$fname) = split(/\//,$embed_file);
11983: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11984: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11985: }
11986: } else {
11987: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11988: ($size,$mtime) = @{$currfile->{$embed_file}};
11989: }
11990: }
11991: $showsize = $size/1024.0;
11992: $showsize = sprintf("%.1f",$showsize);
11993: if ($mtime > 0) {
11994: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11995: }
11996: }
11997: return ($showsize,$showmtime);
11998: }
11999:
12000: sub ask_embedded_js {
12001: return <<"END";
12002: <script type="text/javascript"">
12003: // <![CDATA[
12004: function toggleBrowse(counter) {
12005: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12006: var fileid = document.getElementById('embedded_item_'+counter);
12007: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12008: if (chkboxid.checked == true) {
12009: uploaddivid.style.display='block';
12010: } else {
12011: uploaddivid.style.display='none';
12012: fileid.value = '';
12013: }
12014: }
12015: // ]]>
12016: </script>
12017:
12018: END
12019: }
12020:
1.661 raeburn 12021: sub upload_embedded {
12022: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12023: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12024: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12025: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12026: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12027: my $orig_uploaded_filename =
12028: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12029: foreach my $type ('orig','ref','attrib','codebase') {
12030: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12031: $env{'form.embedded_'.$type.'_'.$i} =
12032: &unescape($env{'form.embedded_'.$type.'_'.$i});
12033: }
12034: }
1.661 raeburn 12035: my ($path,$fname) =
12036: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12037: # no path, whole string is fname
12038: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12039: $fname = &Apache::lonnet::clean_filename($fname);
12040: # See if there is anything left
12041: next if ($fname eq '');
12042:
12043: # Check if file already exists as a file or directory.
12044: my ($state,$msg);
12045: if ($context eq 'portfolio') {
12046: my $port_path = $dirpath;
12047: if ($group ne '') {
12048: $port_path = "groups/$group/$port_path";
12049: }
1.987 raeburn 12050: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12051: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12052: $dir_root,$port_path,$disk_quota,
12053: $current_disk_usage,$uname,$udom);
12054: if ($state eq 'will_exceed_quota'
1.984 raeburn 12055: || $state eq 'file_locked') {
1.661 raeburn 12056: $output .= $msg;
12057: next;
12058: }
12059: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12060: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12061: if ($state eq 'exists') {
12062: $output .= $msg;
12063: next;
12064: }
12065: }
12066: # Check if extension is valid
12067: if (($fname =~ /\.(\w+)$/) &&
12068: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12069: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12070: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12071: next;
12072: } elsif (($fname =~ /\.(\w+)$/) &&
12073: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12074: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12075: next;
12076: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12077: $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 12078: next;
12079: }
12080: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12081: my $subdir = $path;
12082: $subdir =~ s{/+$}{};
1.661 raeburn 12083: if ($context eq 'portfolio') {
1.984 raeburn 12084: my $result;
12085: if ($state eq 'existingfile') {
12086: $result=
12087: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12088: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12089: } else {
1.984 raeburn 12090: $result=
12091: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12092: $dirpath.
1.1123 raeburn 12093: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12094: if ($result !~ m|^/uploaded/|) {
12095: $output .= '<span class="LC_error">'
12096: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12097: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12098: .'</span><br />';
12099: next;
12100: } else {
1.987 raeburn 12101: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12102: $path.$fname.'</span>').'<br />';
1.984 raeburn 12103: }
1.661 raeburn 12104: }
1.1123 raeburn 12105: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12106: my $extendedsubdir = $dirpath.'/'.$subdir;
12107: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12108: my $result =
1.1126 raeburn 12109: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12110: if ($result !~ m|^/uploaded/|) {
12111: $output .= '<span class="LC_error">'
12112: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12113: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12114: .'</span><br />';
12115: next;
12116: } else {
12117: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12118: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12119: if ($context eq 'syllabus') {
12120: &Apache::lonnet::make_public_indefinitely($result);
12121: }
1.987 raeburn 12122: }
1.661 raeburn 12123: } else {
12124: # Save the file
12125: my $target = $env{'form.embedded_item_'.$i};
12126: my $fullpath = $dir_root.$dirpath.'/'.$path;
12127: my $dest = $fullpath.$fname;
12128: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12129: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12130: my $count;
12131: my $filepath = $dir_root;
1.1027 raeburn 12132: foreach my $subdir (@parts) {
12133: $filepath .= "/$subdir";
12134: if (!-e $filepath) {
1.661 raeburn 12135: mkdir($filepath,0770);
12136: }
12137: }
12138: my $fh;
12139: if (!open($fh,'>'.$dest)) {
12140: &Apache::lonnet::logthis('Failed to create '.$dest);
12141: $output .= '<span class="LC_error">'.
1.1071 raeburn 12142: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12143: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12144: '</span><br />';
12145: } else {
12146: if (!print $fh $env{'form.embedded_item_'.$i}) {
12147: &Apache::lonnet::logthis('Failed to write to '.$dest);
12148: $output .= '<span class="LC_error">'.
1.1071 raeburn 12149: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12150: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12151: '</span><br />';
12152: } else {
1.987 raeburn 12153: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12154: $url.'</span>').'<br />';
12155: unless ($context eq 'testbank') {
12156: $footer .= &mt('View embedded file: [_1]',
12157: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12158: }
12159: }
12160: close($fh);
12161: }
12162: }
12163: if ($env{'form.embedded_ref_'.$i}) {
12164: $pathchange{$i} = 1;
12165: }
12166: }
12167: if ($output) {
12168: $output = '<p>'.$output.'</p>';
12169: }
12170: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12171: $returnflag = 'ok';
1.1071 raeburn 12172: my $numpathchgs = scalar(keys(%pathchange));
12173: if ($numpathchgs > 0) {
1.987 raeburn 12174: if ($context eq 'portfolio') {
12175: $output .= '<p>'.&mt('or').'</p>';
12176: } elsif ($context eq 'testbank') {
1.1071 raeburn 12177: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12178: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12179: $returnflag = 'modify_orightml';
12180: }
12181: }
1.1071 raeburn 12182: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12183: }
12184:
12185: sub modify_html_form {
12186: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12187: my $end = 0;
12188: my $modifyform;
12189: if ($context eq 'upload_embedded') {
12190: return unless (ref($pathchange) eq 'HASH');
12191: if ($env{'form.number_embedded_items'}) {
12192: $end += $env{'form.number_embedded_items'};
12193: }
12194: if ($env{'form.number_pathchange_items'}) {
12195: $end += $env{'form.number_pathchange_items'};
12196: }
12197: if ($end) {
12198: for (my $i=0; $i<$end; $i++) {
12199: if ($i < $env{'form.number_embedded_items'}) {
12200: next unless($pathchange->{$i});
12201: }
12202: $modifyform .=
12203: &start_data_table_row().
12204: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12205: 'checked="checked" /></td>'.
12206: '<td>'.$env{'form.embedded_ref_'.$i}.
12207: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12208: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12209: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12210: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12211: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12212: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12213: '<td>'.$env{'form.embedded_orig_'.$i}.
12214: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12215: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12216: &end_data_table_row();
1.1071 raeburn 12217: }
1.987 raeburn 12218: }
12219: } else {
12220: $modifyform = $pathchgtable;
12221: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12222: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12223: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12224: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12225: }
12226: }
12227: if ($modifyform) {
1.1071 raeburn 12228: if ($actionurl eq '/adm/dependencies') {
12229: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12230: }
1.987 raeburn 12231: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12232: '<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".
12233: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12234: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12235: '</ol></p>'."\n".'<p>'.
12236: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12237: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12238: &start_data_table()."\n".
12239: &start_data_table_header_row().
12240: '<th>'.&mt('Change?').'</th>'.
12241: '<th>'.&mt('Current reference').'</th>'.
12242: '<th>'.&mt('Required reference').'</th>'.
12243: &end_data_table_header_row()."\n".
12244: $modifyform.
12245: &end_data_table().'<br />'."\n".$hiddenstate.
12246: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12247: '</form>'."\n";
12248: }
12249: return;
12250: }
12251:
12252: sub modify_html_refs {
1.1123 raeburn 12253: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12254: my $container;
12255: if ($context eq 'portfolio') {
12256: $container = $env{'form.container'};
12257: } elsif ($context eq 'coursedoc') {
12258: $container = $env{'form.primaryurl'};
1.1071 raeburn 12259: } elsif ($context eq 'manage_dependencies') {
12260: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12261: $container = "/$container";
1.1123 raeburn 12262: } elsif ($context eq 'syllabus') {
12263: $container = $url;
1.987 raeburn 12264: } else {
1.1027 raeburn 12265: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12266: }
12267: my (%allfiles,%codebase,$output,$content);
12268: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12269: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12270: if (wantarray) {
12271: return ('',0,0);
12272: } else {
12273: return;
12274: }
12275: }
12276: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12277: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12278: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12279: if (wantarray) {
12280: return ('',0,0);
12281: } else {
12282: return;
12283: }
12284: }
1.987 raeburn 12285: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12286: if ($content eq '-1') {
12287: if (wantarray) {
12288: return ('',0,0);
12289: } else {
12290: return;
12291: }
12292: }
1.987 raeburn 12293: } else {
1.1071 raeburn 12294: unless ($container =~ /^\Q$dir_root\E/) {
12295: if (wantarray) {
12296: return ('',0,0);
12297: } else {
12298: return;
12299: }
12300: }
1.1317 raeburn 12301: if (open(my $fh,'<',$container)) {
1.987 raeburn 12302: $content = join('', <$fh>);
12303: close($fh);
12304: } else {
1.1071 raeburn 12305: if (wantarray) {
12306: return ('',0,0);
12307: } else {
12308: return;
12309: }
1.987 raeburn 12310: }
12311: }
12312: my ($count,$codebasecount) = (0,0);
12313: my $mm = new File::MMagic;
12314: my $mime_type = $mm->checktype_contents($content);
12315: if ($mime_type eq 'text/html') {
12316: my $parse_result =
12317: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12318: \%codebase,\$content);
12319: if ($parse_result eq 'ok') {
12320: foreach my $i (@changes) {
12321: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12322: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12323: if ($allfiles{$ref}) {
12324: my $newname = $orig;
12325: my ($attrib_regexp,$codebase);
1.1006 raeburn 12326: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12327: if ($attrib_regexp =~ /:/) {
12328: $attrib_regexp =~ s/\:/|/g;
12329: }
12330: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12331: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12332: $count += $numchg;
1.1123 raeburn 12333: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12334: delete($allfiles{$ref});
1.987 raeburn 12335: }
12336: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12337: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12338: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12339: $codebasecount ++;
12340: }
12341: }
12342: }
1.1123 raeburn 12343: my $skiprewrites;
1.987 raeburn 12344: if ($count || $codebasecount) {
12345: my $saveresult;
1.1071 raeburn 12346: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12347: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12348: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12349: if ($url eq $container) {
12350: my ($fname) = ($container =~ m{/([^/]+)$});
12351: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12352: $count,'<span class="LC_filename">'.
1.1071 raeburn 12353: $fname.'</span>').'</p>';
1.987 raeburn 12354: } else {
12355: $output = '<p class="LC_error">'.
12356: &mt('Error: update failed for: [_1].',
12357: '<span class="LC_filename">'.
12358: $container.'</span>').'</p>';
12359: }
1.1123 raeburn 12360: if ($context eq 'syllabus') {
12361: unless ($saveresult eq 'ok') {
12362: $skiprewrites = 1;
12363: }
12364: }
1.987 raeburn 12365: } else {
1.1317 raeburn 12366: if (open(my $fh,'>',$container)) {
1.987 raeburn 12367: print $fh $content;
12368: close($fh);
12369: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12370: $count,'<span class="LC_filename">'.
12371: $container.'</span>').'</p>';
1.661 raeburn 12372: } else {
1.987 raeburn 12373: $output = '<p class="LC_error">'.
12374: &mt('Error: could not update [_1].',
12375: '<span class="LC_filename">'.
12376: $container.'</span>').'</p>';
1.661 raeburn 12377: }
12378: }
12379: }
1.1123 raeburn 12380: if (($context eq 'syllabus') && (!$skiprewrites)) {
12381: my ($actionurl,$state);
12382: $actionurl = "/public/$udom/$uname/syllabus";
12383: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12384: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12385: \%codebase,
12386: {'context' => 'rewrites',
12387: 'ignore_remote_references' => 1,});
12388: if (ref($mapping) eq 'HASH') {
12389: my $rewrites = 0;
12390: foreach my $key (keys(%{$mapping})) {
12391: next if ($key =~ m{^https?://});
12392: my $ref = $mapping->{$key};
12393: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12394: my $attrib;
12395: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12396: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12397: }
12398: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12399: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12400: $rewrites += $numchg;
12401: }
12402: }
12403: if ($rewrites) {
12404: my $saveresult;
12405: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12406: if ($url eq $container) {
12407: my ($fname) = ($container =~ m{/([^/]+)$});
12408: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12409: $count,'<span class="LC_filename">'.
12410: $fname.'</span>').'</p>';
12411: } else {
12412: $output .= '<p class="LC_error">'.
12413: &mt('Error: could not update links in [_1].',
12414: '<span class="LC_filename">'.
12415: $container.'</span>').'</p>';
12416:
12417: }
12418: }
12419: }
12420: }
1.987 raeburn 12421: } else {
12422: &logthis('Failed to parse '.$container.
12423: ' to modify references: '.$parse_result);
1.661 raeburn 12424: }
12425: }
1.1071 raeburn 12426: if (wantarray) {
12427: return ($output,$count,$codebasecount);
12428: } else {
12429: return $output;
12430: }
1.661 raeburn 12431: }
12432:
12433: sub check_for_existing {
12434: my ($path,$fname,$element) = @_;
12435: my ($state,$msg);
12436: if (-d $path.'/'.$fname) {
12437: $state = 'exists';
12438: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12439: } elsif (-e $path.'/'.$fname) {
12440: $state = 'exists';
12441: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12442: }
12443: if ($state eq 'exists') {
12444: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12445: }
12446: return ($state,$msg);
12447: }
12448:
12449: sub check_for_upload {
12450: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12451: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12452: my $filesize = length($env{'form.'.$element});
12453: if (!$filesize) {
12454: my $msg = '<span class="LC_error">'.
12455: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12456: '<span class="LC_filename">'.$fname.'</span>',
12457: $filesize).'<br />'.
1.1007 raeburn 12458: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12459: '</span>';
12460: return ('zero_bytes',$msg);
12461: }
12462: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12463: my $getpropath = 1;
1.1021 raeburn 12464: my ($dirlistref,$listerror) =
12465: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12466: my $found_file = 0;
12467: my $locked_file = 0;
1.991 raeburn 12468: my @lockers;
12469: my $navmap;
12470: if ($env{'request.course.id'}) {
12471: $navmap = Apache::lonnavmaps::navmap->new();
12472: }
1.1021 raeburn 12473: if (ref($dirlistref) eq 'ARRAY') {
12474: foreach my $line (@{$dirlistref}) {
12475: my ($file_name,$rest)=split(/\&/,$line,2);
12476: if ($file_name eq $fname){
12477: $file_name = $path.$file_name;
12478: if ($group ne '') {
12479: $file_name = $group.$file_name;
12480: }
12481: $found_file = 1;
12482: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12483: foreach my $lock (@lockers) {
12484: if (ref($lock) eq 'ARRAY') {
12485: my ($symb,$crsid) = @{$lock};
12486: if ($crsid eq $env{'request.course.id'}) {
12487: if (ref($navmap)) {
12488: my $res = $navmap->getBySymb($symb);
12489: foreach my $part (@{$res->parts()}) {
12490: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12491: unless (($slot_status == $res->RESERVED) ||
12492: ($slot_status == $res->RESERVED_LOCATION)) {
12493: $locked_file = 1;
12494: }
1.991 raeburn 12495: }
1.1021 raeburn 12496: } else {
12497: $locked_file = 1;
1.991 raeburn 12498: }
12499: } else {
12500: $locked_file = 1;
12501: }
12502: }
1.1021 raeburn 12503: }
12504: } else {
12505: my @info = split(/\&/,$rest);
12506: my $currsize = $info[6]/1000;
12507: if ($currsize < $filesize) {
12508: my $extra = $filesize - $currsize;
12509: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12510: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12511: &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 12512: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12513: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12514: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12515: return ('will_exceed_quota',$msg);
12516: }
1.984 raeburn 12517: }
12518: }
1.661 raeburn 12519: }
12520: }
12521: }
12522: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12523: my $msg = '<p class="LC_warning">'.
12524: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12525: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12526: return ('will_exceed_quota',$msg);
12527: } elsif ($found_file) {
12528: if ($locked_file) {
1.1179 bisitz 12529: my $msg = '<p class="LC_warning">';
1.661 raeburn 12530: $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 12531: $msg .= '</p>';
1.661 raeburn 12532: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12533: return ('file_locked',$msg);
12534: } else {
1.1179 bisitz 12535: my $msg = '<p class="LC_error">';
1.984 raeburn 12536: $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 12537: $msg .= '</p>';
1.984 raeburn 12538: return ('existingfile',$msg);
1.661 raeburn 12539: }
12540: }
12541: }
12542:
1.987 raeburn 12543: sub check_for_traversal {
12544: my ($path,$url,$toplevel) = @_;
12545: my @parts=split(/\//,$path);
12546: my $cleanpath;
12547: my $fullpath = $url;
12548: for (my $i=0;$i<@parts;$i++) {
12549: next if ($parts[$i] eq '.');
12550: if ($parts[$i] eq '..') {
12551: $fullpath =~ s{([^/]+/)$}{};
12552: } else {
12553: $fullpath .= $parts[$i].'/';
12554: }
12555: }
12556: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12557: $cleanpath = $1;
12558: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12559: my $curr_toprel = $1;
12560: my @parts = split(/\//,$curr_toprel);
12561: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12562: my @urlparts = split(/\//,$url_toprel);
12563: my $doubledots;
12564: my $startdiff = -1;
12565: for (my $i=0; $i<@urlparts; $i++) {
12566: if ($startdiff == -1) {
12567: unless ($urlparts[$i] eq $parts[$i]) {
12568: $startdiff = $i;
12569: $doubledots .= '../';
12570: }
12571: } else {
12572: $doubledots .= '../';
12573: }
12574: }
12575: if ($startdiff > -1) {
12576: $cleanpath = $doubledots;
12577: for (my $i=$startdiff; $i<@parts; $i++) {
12578: $cleanpath .= $parts[$i].'/';
12579: }
12580: }
12581: }
12582: $cleanpath =~ s{(/)$}{};
12583: return $cleanpath;
12584: }
1.31 albertel 12585:
1.1053 raeburn 12586: sub is_archive_file {
12587: my ($mimetype) = @_;
12588: if (($mimetype eq 'application/octet-stream') ||
12589: ($mimetype eq 'application/x-stuffit') ||
12590: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12591: return 1;
12592: }
12593: return;
12594: }
12595:
12596: sub decompress_form {
1.1065 raeburn 12597: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12598: my %lt = &Apache::lonlocal::texthash (
12599: this => 'This file is an archive file.',
1.1067 raeburn 12600: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12601: itsc => 'Its contents are as follows:',
1.1053 raeburn 12602: youm => 'You may wish to extract its contents.',
12603: extr => 'Extract contents',
1.1067 raeburn 12604: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12605: proa => 'Process automatically?',
1.1053 raeburn 12606: yes => 'Yes',
12607: no => 'No',
1.1067 raeburn 12608: fold => 'Title for folder containing movie',
12609: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12610: );
1.1065 raeburn 12611: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12612: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12613: my $info = &list_archive_contents($fileloc,\@paths);
12614: if (@paths) {
12615: foreach my $path (@paths) {
12616: $path =~ s{^/}{};
1.1067 raeburn 12617: if ($path =~ m{^([^/]+)/$}) {
12618: $topdir = $1;
12619: }
1.1065 raeburn 12620: if ($path =~ m{^([^/]+)/}) {
12621: $toplevel{$1} = $path;
12622: } else {
12623: $toplevel{$path} = $path;
12624: }
12625: }
12626: }
1.1067 raeburn 12627: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12628: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12629: "$topdir/media/",
12630: "$topdir/media/$topdir.mp4",
12631: "$topdir/media/FirstFrame.png",
12632: "$topdir/media/player.swf",
12633: "$topdir/media/swfobject.js",
12634: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12635: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12636: "$topdir/$topdir.mp4",
12637: "$topdir/$topdir\_config.xml",
12638: "$topdir/$topdir\_controller.swf",
12639: "$topdir/$topdir\_embed.css",
12640: "$topdir/$topdir\_First_Frame.png",
12641: "$topdir/$topdir\_player.html",
12642: "$topdir/$topdir\_Thumbnails.png",
12643: "$topdir/playerProductInstall.swf",
12644: "$topdir/scripts/",
12645: "$topdir/scripts/config_xml.js",
12646: "$topdir/scripts/handlebars.js",
12647: "$topdir/scripts/jquery-1.7.1.min.js",
12648: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12649: "$topdir/scripts/modernizr.js",
12650: "$topdir/scripts/player-min.js",
12651: "$topdir/scripts/swfobject.js",
12652: "$topdir/skins/",
12653: "$topdir/skins/configuration_express.xml",
12654: "$topdir/skins/express_show/",
12655: "$topdir/skins/express_show/player-min.css",
12656: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12657: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12658: "$topdir/$topdir.mp4",
12659: "$topdir/$topdir\_config.xml",
12660: "$topdir/$topdir\_controller.swf",
12661: "$topdir/$topdir\_embed.css",
12662: "$topdir/$topdir\_First_Frame.png",
12663: "$topdir/$topdir\_player.html",
12664: "$topdir/$topdir\_Thumbnails.png",
12665: "$topdir/playerProductInstall.swf",
12666: "$topdir/scripts/",
12667: "$topdir/scripts/config_xml.js",
12668: "$topdir/scripts/techsmith-smart-player.min.js",
12669: "$topdir/skins/",
12670: "$topdir/skins/configuration_express.xml",
12671: "$topdir/skins/express_show/",
12672: "$topdir/skins/express_show/spritesheet.min.css",
12673: "$topdir/skins/express_show/spritesheet.png",
12674: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12675: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12676: if (@diffs == 0) {
1.1164 raeburn 12677: $is_camtasia = 6;
12678: } else {
1.1197 raeburn 12679: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12680: if (@diffs == 0) {
12681: $is_camtasia = 8;
1.1197 raeburn 12682: } else {
12683: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12684: if (@diffs == 0) {
12685: $is_camtasia = 8;
12686: }
1.1164 raeburn 12687: }
1.1067 raeburn 12688: }
12689: }
12690: my $output;
12691: if ($is_camtasia) {
12692: $output = <<"ENDCAM";
12693: <script type="text/javascript" language="Javascript">
12694: // <![CDATA[
12695:
12696: function camtasiaToggle() {
12697: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12698: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12699: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12700: document.getElementById('camtasia_titles').style.display='block';
12701: } else {
12702: document.getElementById('camtasia_titles').style.display='none';
12703: }
12704: }
12705: }
12706: return;
12707: }
12708:
12709: // ]]>
12710: </script>
12711: <p>$lt{'camt'}</p>
12712: ENDCAM
1.1065 raeburn 12713: } else {
1.1067 raeburn 12714: $output = '<p>'.$lt{'this'};
12715: if ($info eq '') {
12716: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12717: } else {
12718: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12719: '<div><pre>'.$info.'</pre></div>';
12720: }
1.1065 raeburn 12721: }
1.1067 raeburn 12722: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12723: my $duplicates;
12724: my $num = 0;
12725: if (ref($dirlist) eq 'ARRAY') {
12726: foreach my $item (@{$dirlist}) {
12727: if (ref($item) eq 'ARRAY') {
12728: if (exists($toplevel{$item->[0]})) {
12729: $duplicates .=
12730: &start_data_table_row().
12731: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12732: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12733: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12734: 'value="1" />'.&mt('Yes').'</label>'.
12735: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12736: '<td>'.$item->[0].'</td>';
12737: if ($item->[2]) {
12738: $duplicates .= '<td>'.&mt('Directory').'</td>';
12739: } else {
12740: $duplicates .= '<td>'.&mt('File').'</td>';
12741: }
12742: $duplicates .= '<td>'.$item->[3].'</td>'.
12743: '<td>'.
12744: &Apache::lonlocal::locallocaltime($item->[4]).
12745: '</td>'.
12746: &end_data_table_row();
12747: $num ++;
12748: }
12749: }
12750: }
12751: }
12752: my $itemcount;
12753: if (@paths > 0) {
12754: $itemcount = scalar(@paths);
12755: } else {
12756: $itemcount = 1;
12757: }
1.1067 raeburn 12758: if ($is_camtasia) {
12759: $output .= $lt{'auto'}.'<br />'.
12760: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12761: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12762: $lt{'yes'}.'</label> <label>'.
12763: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12764: $lt{'no'}.'</label></span><br />'.
12765: '<div id="camtasia_titles" style="display:block">'.
12766: &Apache::lonhtmlcommon::start_pick_box().
12767: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12768: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12769: &Apache::lonhtmlcommon::row_closure().
12770: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12771: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12772: &Apache::lonhtmlcommon::row_closure(1).
12773: &Apache::lonhtmlcommon::end_pick_box().
12774: '</div>';
12775: }
1.1065 raeburn 12776: $output .=
12777: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12778: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12779: "\n";
1.1065 raeburn 12780: if ($duplicates ne '') {
12781: $output .= '<p><span class="LC_warning">'.
12782: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12783: &start_data_table().
12784: &start_data_table_header_row().
12785: '<th>'.&mt('Overwrite?').'</th>'.
12786: '<th>'.&mt('Name').'</th>'.
12787: '<th>'.&mt('Type').'</th>'.
12788: '<th>'.&mt('Size').'</th>'.
12789: '<th>'.&mt('Last modified').'</th>'.
12790: &end_data_table_header_row().
12791: $duplicates.
12792: &end_data_table().
12793: '</p>';
12794: }
1.1067 raeburn 12795: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12796: if (ref($hiddenelements) eq 'HASH') {
12797: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12798: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12799: }
12800: }
12801: $output .= <<"END";
1.1067 raeburn 12802: <br />
1.1053 raeburn 12803: <input type="submit" name="decompress" value="$lt{'extr'}" />
12804: </form>
12805: $noextract
12806: END
12807: return $output;
12808: }
12809:
1.1065 raeburn 12810: sub decompression_utility {
12811: my ($program) = @_;
12812: my @utilities = ('tar','gunzip','bunzip2','unzip');
12813: my $location;
12814: if (grep(/^\Q$program\E$/,@utilities)) {
12815: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12816: '/usr/sbin/') {
12817: if (-x $dir.$program) {
12818: $location = $dir.$program;
12819: last;
12820: }
12821: }
12822: }
12823: return $location;
12824: }
12825:
12826: sub list_archive_contents {
12827: my ($file,$pathsref) = @_;
12828: my (@cmd,$output);
12829: my $needsregexp;
12830: if ($file =~ /\.zip$/) {
12831: @cmd = (&decompression_utility('unzip'),"-l");
12832: $needsregexp = 1;
12833: } elsif (($file =~ m/\.tar\.gz$/) ||
12834: ($file =~ /\.tgz$/)) {
12835: @cmd = (&decompression_utility('tar'),"-ztf");
12836: } elsif ($file =~ /\.tar\.bz2$/) {
12837: @cmd = (&decompression_utility('tar'),"-jtf");
12838: } elsif ($file =~ m|\.tar$|) {
12839: @cmd = (&decompression_utility('tar'),"-tf");
12840: }
12841: if (@cmd) {
12842: undef($!);
12843: undef($@);
12844: if (open(my $fh,"-|", @cmd, $file)) {
12845: while (my $line = <$fh>) {
12846: $output .= $line;
12847: chomp($line);
12848: my $item;
12849: if ($needsregexp) {
12850: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12851: } else {
12852: $item = $line;
12853: }
12854: if ($item ne '') {
12855: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12856: push(@{$pathsref},$item);
12857: }
12858: }
12859: }
12860: close($fh);
12861: }
12862: }
12863: return $output;
12864: }
12865:
1.1053 raeburn 12866: sub decompress_uploaded_file {
12867: my ($file,$dir) = @_;
12868: &Apache::lonnet::appenv({'cgi.file' => $file});
12869: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12870: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12871: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12872: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12873: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12874: my $decompressed = $env{'cgi.decompressed'};
12875: &Apache::lonnet::delenv('cgi.file');
12876: &Apache::lonnet::delenv('cgi.dir');
12877: &Apache::lonnet::delenv('cgi.decompressed');
12878: return ($decompressed,$result);
12879: }
12880:
1.1055 raeburn 12881: sub process_decompression {
12882: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12883: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12884: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12885: &mt('Unexpected file path.').'</p>'."\n";
12886: }
12887: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12888: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12889: &mt('Unexpected course context.').'</p>'."\n";
12890: }
1.1293 raeburn 12891: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12892: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12893: &mt('Filename contained unexpected characters.').'</p>'."\n";
12894: }
1.1055 raeburn 12895: my ($dir,$error,$warning,$output);
1.1180 raeburn 12896: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12897: $error = &mt('Filename not a supported archive file type.').
12898: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12899: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12900: } else {
12901: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12902: if ($docuhome eq 'no_host') {
12903: $error = &mt('Could not determine home server for course.');
12904: } else {
12905: my @ids=&Apache::lonnet::current_machine_ids();
12906: my $currdir = "$dir_root/$destination";
12907: if (grep(/^\Q$docuhome\E$/,@ids)) {
12908: $dir = &LONCAPA::propath($docudom,$docuname).
12909: "$dir_root/$destination";
12910: } else {
12911: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12912: "$dir_root/$docudom/$docuname/$destination";
12913: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12914: $error = &mt('Archive file not found.');
12915: }
12916: }
1.1065 raeburn 12917: my (@to_overwrite,@to_skip);
12918: if ($env{'form.archive_overwrite_total'} > 0) {
12919: my $total = $env{'form.archive_overwrite_total'};
12920: for (my $i=0; $i<$total; $i++) {
12921: if ($env{'form.archive_overwrite_'.$i} == 1) {
12922: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12923: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12924: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12925: }
12926: }
12927: }
12928: my $numskip = scalar(@to_skip);
1.1292 raeburn 12929: my $numoverwrite = scalar(@to_overwrite);
12930: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12931: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12932: } elsif ($dir eq '') {
1.1055 raeburn 12933: $error = &mt('Directory containing archive file unavailable.');
12934: } elsif (!$error) {
1.1065 raeburn 12935: my ($decompressed,$display);
1.1292 raeburn 12936: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12937: my $tempdir = time.'_'.$$.int(rand(10000));
12938: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12939: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12940: ($decompressed,$display) =
12941: &decompress_uploaded_file($file,"$dir/$tempdir");
12942: foreach my $item (@to_skip) {
12943: if (($item ne '') && ($item !~ /\.\./)) {
12944: if (-f "$dir/$tempdir/$item") {
12945: unlink("$dir/$tempdir/$item");
12946: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12947: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12948: }
12949: }
12950: }
12951: foreach my $item (@to_overwrite) {
12952: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12953: if (($item ne '') && ($item !~ /\.\./)) {
12954: if (-f "$dir/$item") {
12955: unlink("$dir/$item");
12956: } elsif (-d "$dir/$item") {
1.1300 raeburn 12957: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12958: }
12959: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12960: }
1.1065 raeburn 12961: }
12962: }
1.1292 raeburn 12963: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12964: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12965: }
1.1065 raeburn 12966: }
12967: } else {
12968: ($decompressed,$display) =
12969: &decompress_uploaded_file($file,$dir);
12970: }
1.1055 raeburn 12971: if ($decompressed eq 'ok') {
1.1065 raeburn 12972: $output = '<p class="LC_info">'.
12973: &mt('Files extracted successfully from archive.').
12974: '</p>'."\n";
1.1055 raeburn 12975: my ($warning,$result,@contents);
12976: my ($newdirlistref,$newlisterror) =
12977: &Apache::lonnet::dirlist($currdir,$docudom,
12978: $docuname,1);
12979: my (%is_dir,%changes,@newitems);
12980: my $dirptr = 16384;
1.1065 raeburn 12981: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12982: foreach my $dir_line (@{$newdirlistref}) {
12983: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12984: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12985: push(@newitems,$item);
12986: if ($dirptr&$testdir) {
12987: $is_dir{$item} = 1;
12988: }
12989: $changes{$item} = 1;
12990: }
12991: }
12992: }
12993: if (keys(%changes) > 0) {
12994: foreach my $item (sort(@newitems)) {
12995: if ($changes{$item}) {
12996: push(@contents,$item);
12997: }
12998: }
12999: }
13000: if (@contents > 0) {
1.1067 raeburn 13001: my $wantform;
13002: unless ($env{'form.autoextract_camtasia'}) {
13003: $wantform = 1;
13004: }
1.1056 raeburn 13005: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13006: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13007: $currdir,\%is_dir,
13008: \%children,\%parent,
1.1056 raeburn 13009: \@contents,\%dirorder,
13010: \%titles,$wantform);
1.1055 raeburn 13011: if ($datatable ne '') {
13012: $output .= &archive_options_form('decompressed',$datatable,
13013: $count,$hiddenelem);
1.1065 raeburn 13014: my $startcount = 6;
1.1055 raeburn 13015: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13016: \%titles,\%children);
1.1055 raeburn 13017: }
1.1067 raeburn 13018: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13019: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13020: my %displayed;
13021: my $total = 1;
13022: $env{'form.archive_directory'} = [];
13023: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13024: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13025: $path =~ s{/$}{};
13026: my $item;
13027: if ($path ne '') {
13028: $item = "$path/$titles{$i}";
13029: } else {
13030: $item = $titles{$i};
13031: }
13032: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13033: if ($item eq $contents[0]) {
13034: push(@{$env{'form.archive_directory'}},$i);
13035: $env{'form.archive_'.$i} = 'display';
13036: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13037: $displayed{'folder'} = $i;
1.1164 raeburn 13038: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13039: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13040: $env{'form.archive_'.$i} = 'display';
13041: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13042: $displayed{'web'} = $i;
13043: } else {
1.1164 raeburn 13044: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13045: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13046: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13047: push(@{$env{'form.archive_directory'}},$i);
13048: }
13049: $env{'form.archive_'.$i} = 'dependency';
13050: }
13051: $total ++;
13052: }
13053: for (my $i=1; $i<$total; $i++) {
13054: next if ($i == $displayed{'web'});
13055: next if ($i == $displayed{'folder'});
13056: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13057: }
13058: $env{'form.phase'} = 'decompress_cleanup';
13059: $env{'form.archivedelete'} = 1;
13060: $env{'form.archive_count'} = $total-1;
13061: $output .=
13062: &process_extracted_files('coursedocs',$docudom,
13063: $docuname,$destination,
13064: $dir_root,$hiddenelem);
13065: }
1.1055 raeburn 13066: } else {
13067: $warning = &mt('No new items extracted from archive file.');
13068: }
13069: } else {
13070: $output = $display;
13071: $error = &mt('An error occurred during extraction from the archive file.');
13072: }
13073: }
13074: }
13075: }
13076: if ($error) {
13077: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13078: $error.'</p>'."\n";
13079: }
13080: if ($warning) {
13081: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13082: }
13083: return $output;
13084: }
13085:
13086: sub get_extracted {
1.1056 raeburn 13087: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13088: $titles,$wantform) = @_;
1.1055 raeburn 13089: my $count = 0;
13090: my $depth = 0;
13091: my $datatable;
1.1056 raeburn 13092: my @hierarchy;
1.1055 raeburn 13093: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13094: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13095: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13096: foreach my $item (@{$contents}) {
13097: $count ++;
1.1056 raeburn 13098: @{$dirorder->{$count}} = @hierarchy;
13099: $titles->{$count} = $item;
1.1055 raeburn 13100: &archive_hierarchy($depth,$count,$parent,$children);
13101: if ($wantform) {
13102: $datatable .= &archive_row($is_dir->{$item},$item,
13103: $currdir,$depth,$count);
13104: }
13105: if ($is_dir->{$item}) {
13106: $depth ++;
1.1056 raeburn 13107: push(@hierarchy,$count);
13108: $parent->{$depth} = $count;
1.1055 raeburn 13109: $datatable .=
13110: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13111: \$depth,\$count,\@hierarchy,$dirorder,
13112: $children,$parent,$titles,$wantform);
1.1055 raeburn 13113: $depth --;
1.1056 raeburn 13114: pop(@hierarchy);
1.1055 raeburn 13115: }
13116: }
13117: return ($count,$datatable);
13118: }
13119:
13120: sub recurse_extracted_archive {
1.1056 raeburn 13121: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13122: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13123: my $result='';
1.1056 raeburn 13124: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13125: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13126: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13127: return $result;
13128: }
13129: my $dirptr = 16384;
13130: my ($newdirlistref,$newlisterror) =
13131: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13132: if (ref($newdirlistref) eq 'ARRAY') {
13133: foreach my $dir_line (@{$newdirlistref}) {
13134: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13135: unless ($item =~ /^\.+$/) {
13136: $$count ++;
1.1056 raeburn 13137: @{$dirorder->{$$count}} = @{$hierarchy};
13138: $titles->{$$count} = $item;
1.1055 raeburn 13139: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13140:
1.1055 raeburn 13141: my $is_dir;
13142: if ($dirptr&$testdir) {
13143: $is_dir = 1;
13144: }
13145: if ($wantform) {
13146: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13147: }
13148: if ($is_dir) {
13149: $$depth ++;
1.1056 raeburn 13150: push(@{$hierarchy},$$count);
13151: $parent->{$$depth} = $$count;
1.1055 raeburn 13152: $result .=
13153: &recurse_extracted_archive("$currdir/$item",$docudom,
13154: $docuname,$depth,$count,
1.1056 raeburn 13155: $hierarchy,$dirorder,$children,
13156: $parent,$titles,$wantform);
1.1055 raeburn 13157: $$depth --;
1.1056 raeburn 13158: pop(@{$hierarchy});
1.1055 raeburn 13159: }
13160: }
13161: }
13162: }
13163: return $result;
13164: }
13165:
13166: sub archive_hierarchy {
13167: my ($depth,$count,$parent,$children) =@_;
13168: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13169: if (exists($parent->{$depth})) {
13170: $children->{$parent->{$depth}} .= $count.':';
13171: }
13172: }
13173: return;
13174: }
13175:
13176: sub archive_row {
13177: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13178: my ($name) = ($item =~ m{([^/]+)$});
13179: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13180: 'display' => 'Add as file',
1.1055 raeburn 13181: 'dependency' => 'Include as dependency',
13182: 'discard' => 'Discard',
13183: );
13184: if ($is_dir) {
1.1059 raeburn 13185: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13186: }
1.1056 raeburn 13187: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13188: my $offset = 0;
1.1055 raeburn 13189: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13190: $offset ++;
1.1065 raeburn 13191: if ($action ne 'display') {
13192: $offset ++;
13193: }
1.1055 raeburn 13194: $output .= '<td><span class="LC_nobreak">'.
13195: '<label><input type="radio" name="archive_'.$count.
13196: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13197: my $text = $choices{$action};
13198: if ($is_dir) {
13199: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13200: if ($action eq 'display') {
1.1059 raeburn 13201: $text = &mt('Add as folder');
1.1055 raeburn 13202: }
1.1056 raeburn 13203: } else {
13204: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13205:
13206: }
13207: $output .= ' /> '.$choices{$action}.'</label></span>';
13208: if ($action eq 'dependency') {
13209: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13210: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13211: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13212: '<option value=""></option>'."\n".
13213: '</select>'."\n".
13214: '</div>';
1.1059 raeburn 13215: } elsif ($action eq 'display') {
13216: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13217: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13218: '</div>';
1.1055 raeburn 13219: }
1.1056 raeburn 13220: $output .= '</td>';
1.1055 raeburn 13221: }
13222: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13223: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13224: for (my $i=0; $i<$depth; $i++) {
13225: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13226: }
13227: if ($is_dir) {
13228: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13229: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13230: } else {
13231: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13232: }
13233: $output .= ' '.$name.'</td>'."\n".
13234: &end_data_table_row();
13235: return $output;
13236: }
13237:
13238: sub archive_options_form {
1.1065 raeburn 13239: my ($form,$display,$count,$hiddenelem) = @_;
13240: my %lt = &Apache::lonlocal::texthash(
13241: perm => 'Permanently remove archive file?',
13242: hows => 'How should each extracted item be incorporated in the course?',
13243: cont => 'Content actions for all',
13244: addf => 'Add as folder/file',
13245: incd => 'Include as dependency for a displayed file',
13246: disc => 'Discard',
13247: no => 'No',
13248: yes => 'Yes',
13249: save => 'Save',
13250: );
13251: my $output = <<"END";
13252: <form name="$form" method="post" action="">
13253: <p><span class="LC_nobreak">$lt{'perm'}
13254: <label>
13255: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13256: </label>
13257:
13258: <label>
13259: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13260: </span>
13261: </p>
13262: <input type="hidden" name="phase" value="decompress_cleanup" />
13263: <br />$lt{'hows'}
13264: <div class="LC_columnSection">
13265: <fieldset>
13266: <legend>$lt{'cont'}</legend>
13267: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13268: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13269: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13270: </fieldset>
13271: </div>
13272: END
13273: return $output.
1.1055 raeburn 13274: &start_data_table()."\n".
1.1065 raeburn 13275: $display."\n".
1.1055 raeburn 13276: &end_data_table()."\n".
13277: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13278: $hiddenelem.
1.1065 raeburn 13279: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13280: '</form>';
13281: }
13282:
13283: sub archive_javascript {
1.1056 raeburn 13284: my ($startcount,$numitems,$titles,$children) = @_;
13285: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13286: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13287: my $scripttag = <<START;
13288: <script type="text/javascript">
13289: // <![CDATA[
13290:
13291: function checkAll(form,prefix) {
13292: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13293: for (var i=0; i < form.elements.length; i++) {
13294: var id = form.elements[i].id;
13295: if ((id != '') && (id != undefined)) {
13296: if (idstr.test(id)) {
13297: if (form.elements[i].type == 'radio') {
13298: form.elements[i].checked = true;
1.1056 raeburn 13299: var nostart = i-$startcount;
1.1059 raeburn 13300: var offset = nostart%7;
13301: var count = (nostart-offset)/7;
1.1056 raeburn 13302: dependencyCheck(form,count,offset);
1.1055 raeburn 13303: }
13304: }
13305: }
13306: }
13307: }
13308:
13309: function propagateCheck(form,count) {
13310: if (count > 0) {
1.1059 raeburn 13311: var startelement = $startcount + ((count-1) * 7);
13312: for (var j=1; j<6; j++) {
13313: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13314: var item = startelement + j;
13315: if (form.elements[item].type == 'radio') {
13316: if (form.elements[item].checked) {
13317: containerCheck(form,count,j);
13318: break;
13319: }
1.1055 raeburn 13320: }
13321: }
13322: }
13323: }
13324: }
13325:
13326: numitems = $numitems
1.1056 raeburn 13327: var titles = new Array(numitems);
13328: var parents = new Array(numitems);
1.1055 raeburn 13329: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13330: parents[i] = new Array;
1.1055 raeburn 13331: }
1.1059 raeburn 13332: var maintitle = '$maintitle';
1.1055 raeburn 13333:
13334: START
13335:
1.1056 raeburn 13336: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13337: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13338: for (my $i=0; $i<@contents; $i ++) {
13339: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13340: }
13341: }
13342:
1.1056 raeburn 13343: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13344: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13345: }
13346:
1.1055 raeburn 13347: $scripttag .= <<END;
13348:
13349: function containerCheck(form,count,offset) {
13350: if (count > 0) {
1.1056 raeburn 13351: dependencyCheck(form,count,offset);
1.1059 raeburn 13352: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13353: form.elements[item].checked = true;
13354: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13355: if (parents[count].length > 0) {
13356: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13357: containerCheck(form,parents[count][j],offset);
13358: }
13359: }
13360: }
13361: }
13362: }
13363:
13364: function dependencyCheck(form,count,offset) {
13365: if (count > 0) {
1.1059 raeburn 13366: var chosen = (offset+$startcount)+7*(count-1);
13367: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13368: var currtype = form.elements[depitem].type;
13369: if (form.elements[chosen].value == 'dependency') {
13370: document.getElementById('arc_depon_'+count).style.display='block';
13371: form.elements[depitem].options.length = 0;
13372: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13373: for (var i=1; i<=numitems; i++) {
13374: if (i == count) {
13375: continue;
13376: }
1.1059 raeburn 13377: var startelement = $startcount + (i-1) * 7;
13378: for (var j=1; j<6; j++) {
13379: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13380: var item = startelement + j;
13381: if (form.elements[item].type == 'radio') {
13382: if (form.elements[item].checked) {
13383: if (form.elements[item].value == 'display') {
13384: var n = form.elements[depitem].options.length;
13385: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13386: }
13387: }
13388: }
13389: }
13390: }
13391: }
13392: } else {
13393: document.getElementById('arc_depon_'+count).style.display='none';
13394: form.elements[depitem].options.length = 0;
13395: form.elements[depitem].options[0] = new Option('Select','',true,true);
13396: }
1.1059 raeburn 13397: titleCheck(form,count,offset);
1.1056 raeburn 13398: }
13399: }
13400:
13401: function propagateSelect(form,count,offset) {
13402: if (count > 0) {
1.1065 raeburn 13403: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13404: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13405: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13406: if (parents[count].length > 0) {
13407: for (var j=0; j<parents[count].length; j++) {
13408: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13409: }
13410: }
13411: }
13412: }
13413: }
1.1056 raeburn 13414:
13415: function containerSelect(form,count,offset,picked) {
13416: if (count > 0) {
1.1065 raeburn 13417: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13418: if (form.elements[item].type == 'radio') {
13419: if (form.elements[item].value == 'dependency') {
13420: if (form.elements[item+1].type == 'select-one') {
13421: for (var i=0; i<form.elements[item+1].options.length; i++) {
13422: if (form.elements[item+1].options[i].value == picked) {
13423: form.elements[item+1].selectedIndex = i;
13424: break;
13425: }
13426: }
13427: }
13428: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13429: if (parents[count].length > 0) {
13430: for (var j=0; j<parents[count].length; j++) {
13431: containerSelect(form,parents[count][j],offset,picked);
13432: }
13433: }
13434: }
13435: }
13436: }
13437: }
13438: }
13439:
1.1059 raeburn 13440: function titleCheck(form,count,offset) {
13441: if (count > 0) {
13442: var chosen = (offset+$startcount)+7*(count-1);
13443: var depitem = $startcount + ((count-1) * 7) + 2;
13444: var currtype = form.elements[depitem].type;
13445: if (form.elements[chosen].value == 'display') {
13446: document.getElementById('arc_title_'+count).style.display='block';
13447: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13448: document.getElementById('archive_title_'+count).value=maintitle;
13449: }
13450: } else {
13451: document.getElementById('arc_title_'+count).style.display='none';
13452: if (currtype == 'text') {
13453: document.getElementById('archive_title_'+count).value='';
13454: }
13455: }
13456: }
13457: return;
13458: }
13459:
1.1055 raeburn 13460: // ]]>
13461: </script>
13462: END
13463: return $scripttag;
13464: }
13465:
13466: sub process_extracted_files {
1.1067 raeburn 13467: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13468: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13469: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13470: my @ids=&Apache::lonnet::current_machine_ids();
13471: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13472: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13473: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13474: if (grep(/^\Q$docuhome\E$/,@ids)) {
13475: $prefix = &LONCAPA::propath($docudom,$docuname);
13476: $pathtocheck = "$dir_root/$destination";
13477: $dir = $dir_root;
13478: $ishome = 1;
13479: } else {
13480: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13481: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13482: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13483: }
13484: my $currdir = "$dir_root/$destination";
13485: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13486: if ($env{'form.folderpath'}) {
13487: my @items = split('&',$env{'form.folderpath'});
13488: $folders{'0'} = $items[-2];
1.1099 raeburn 13489: if ($env{'form.folderpath'} =~ /\:1$/) {
13490: $containers{'0'}='page';
13491: } else {
13492: $containers{'0'}='sequence';
13493: }
1.1055 raeburn 13494: }
13495: my @archdirs = &get_env_multiple('form.archive_directory');
13496: if ($numitems) {
13497: for (my $i=1; $i<=$numitems; $i++) {
13498: my $path = $env{'form.archive_content_'.$i};
13499: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13500: my $item = $1;
13501: $toplevelitems{$item} = $i;
13502: if (grep(/^\Q$i\E$/,@archdirs)) {
13503: $is_dir{$item} = 1;
13504: }
13505: }
13506: }
13507: }
1.1067 raeburn 13508: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13509: if (keys(%toplevelitems) > 0) {
13510: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13511: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13512: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13513: }
1.1066 raeburn 13514: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13515: if ($numitems) {
13516: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13517: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13518: my $path = $env{'form.archive_content_'.$i};
13519: if ($path =~ /^\Q$pathtocheck\E/) {
13520: if ($env{'form.archive_'.$i} eq 'discard') {
13521: if ($prefix ne '' && $path ne '') {
13522: if (-e $prefix.$path) {
1.1066 raeburn 13523: if ((@archdirs > 0) &&
13524: (grep(/^\Q$i\E$/,@archdirs))) {
13525: $todeletedir{$prefix.$path} = 1;
13526: } else {
13527: $todelete{$prefix.$path} = 1;
13528: }
1.1055 raeburn 13529: }
13530: }
13531: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13532: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13533: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13534: $docstitle = $env{'form.archive_title_'.$i};
13535: if ($docstitle eq '') {
13536: $docstitle = $title;
13537: }
1.1055 raeburn 13538: $outer = 0;
1.1056 raeburn 13539: if (ref($dirorder{$i}) eq 'ARRAY') {
13540: if (@{$dirorder{$i}} > 0) {
13541: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13542: if ($env{'form.archive_'.$item} eq 'display') {
13543: $outer = $item;
13544: last;
13545: }
13546: }
13547: }
13548: }
13549: my ($errtext,$fatal) =
13550: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13551: '/'.$folders{$outer}.'.'.
13552: $containers{$outer});
13553: next if ($fatal);
13554: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13555: if ($context eq 'coursedocs') {
1.1056 raeburn 13556: $mapinner{$i} = time;
1.1055 raeburn 13557: $folders{$i} = 'default_'.$mapinner{$i};
13558: $containers{$i} = 'sequence';
13559: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13560: $folders{$i}.'.'.$containers{$i};
13561: my $newidx = &LONCAPA::map::getresidx();
13562: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13563: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13564: push(@LONCAPA::map::order,$newidx);
13565: my ($outtext,$errtext) =
13566: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13567: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13568: '.'.$containers{$outer},1,1);
1.1056 raeburn 13569: $newseqid{$i} = $newidx;
1.1067 raeburn 13570: unless ($errtext) {
1.1294 raeburn 13571: $result .= '<li>'.&mt('Folder: [_1] added to course',
13572: &HTML::Entities::encode($docstitle,'<>&"')).
13573: '</li>'."\n";
1.1067 raeburn 13574: }
1.1055 raeburn 13575: }
13576: } else {
13577: if ($context eq 'coursedocs') {
13578: my $newidx=&LONCAPA::map::getresidx();
13579: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13580: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13581: $title;
1.1294 raeburn 13582: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13583: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13584: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13585: }
13586: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13587: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13588: }
13589: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13590: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13591: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13592: unless ($ishome) {
13593: my $fetch = "$newdest{$i}/$title";
13594: $fetch =~ s/^\Q$prefix$dir\E//;
13595: $prompttofetch{$fetch} = 1;
13596: }
1.1292 raeburn 13597: }
1.1067 raeburn 13598: }
1.1294 raeburn 13599: $LONCAPA::map::resources[$newidx]=
13600: $docstitle.':'.$url.':false:normal:res';
13601: push(@LONCAPA::map::order, $newidx);
13602: my ($outtext,$errtext)=
13603: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13604: $docuname.'/'.$folders{$outer}.
13605: '.'.$containers{$outer},1,1);
13606: unless ($errtext) {
13607: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13608: $result .= '<li>'.&mt('File: [_1] added to course',
13609: &HTML::Entities::encode($docstitle,'<>&"')).
13610: '</li>'."\n";
13611: }
1.1067 raeburn 13612: }
1.1294 raeburn 13613: } else {
13614: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13615: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13616: }
1.1055 raeburn 13617: }
13618: }
1.1086 raeburn 13619: }
13620: } else {
1.1294 raeburn 13621: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13622: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13623: }
13624: }
13625: for (my $i=1; $i<=$numitems; $i++) {
13626: next unless ($env{'form.archive_'.$i} eq 'dependency');
13627: my $path = $env{'form.archive_content_'.$i};
13628: if ($path =~ /^\Q$pathtocheck\E/) {
13629: my ($title) = ($path =~ m{/([^/]+)$});
13630: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13631: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13632: if (ref($dirorder{$i}) eq 'ARRAY') {
13633: my ($itemidx,$fullpath,$relpath);
13634: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13635: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13636: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13637: if ($dirorder{$i}->[$j] eq $container) {
13638: $itemidx = $j;
1.1056 raeburn 13639: }
13640: }
1.1086 raeburn 13641: }
13642: if ($itemidx eq '') {
13643: $itemidx = 0;
13644: }
13645: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13646: if ($mapinner{$referrer{$i}}) {
13647: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13648: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13649: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13650: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13651: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13652: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13653: if (!-e $fullpath) {
13654: mkdir($fullpath,0755);
1.1056 raeburn 13655: }
13656: }
1.1086 raeburn 13657: } else {
13658: last;
1.1056 raeburn 13659: }
1.1086 raeburn 13660: }
13661: }
13662: } elsif ($newdest{$referrer{$i}}) {
13663: $fullpath = $newdest{$referrer{$i}};
13664: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13665: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13666: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13667: last;
13668: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13669: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13670: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13671: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13672: if (!-e $fullpath) {
13673: mkdir($fullpath,0755);
1.1056 raeburn 13674: }
13675: }
1.1086 raeburn 13676: } else {
13677: last;
1.1056 raeburn 13678: }
1.1055 raeburn 13679: }
13680: }
1.1086 raeburn 13681: if ($fullpath ne '') {
13682: if (-e "$prefix$path") {
1.1292 raeburn 13683: unless (rename("$prefix$path","$fullpath/$title")) {
13684: $warning .= &mt('Failed to rename dependency').'<br />';
13685: }
1.1086 raeburn 13686: }
13687: if (-e "$fullpath/$title") {
13688: my $showpath;
13689: if ($relpath ne '') {
13690: $showpath = "$relpath/$title";
13691: } else {
13692: $showpath = "/$title";
13693: }
1.1294 raeburn 13694: $result .= '<li>'.&mt('[_1] included as a dependency',
13695: &HTML::Entities::encode($showpath,'<>&"')).
13696: '</li>'."\n";
1.1292 raeburn 13697: unless ($ishome) {
13698: my $fetch = "$fullpath/$title";
13699: $fetch =~ s/^\Q$prefix$dir\E//;
13700: $prompttofetch{$fetch} = 1;
13701: }
1.1086 raeburn 13702: }
13703: }
1.1055 raeburn 13704: }
1.1086 raeburn 13705: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13706: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13707: &HTML::Entities::encode($path,'<>&"'),
13708: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13709: '<br />';
1.1055 raeburn 13710: }
13711: } else {
1.1294 raeburn 13712: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13713: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13714: }
13715: }
13716: if (keys(%todelete)) {
13717: foreach my $key (keys(%todelete)) {
13718: unlink($key);
1.1066 raeburn 13719: }
13720: }
13721: if (keys(%todeletedir)) {
13722: foreach my $key (keys(%todeletedir)) {
13723: rmdir($key);
13724: }
13725: }
13726: foreach my $dir (sort(keys(%is_dir))) {
13727: if (($pathtocheck ne '') && ($dir ne '')) {
13728: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13729: }
13730: }
1.1067 raeburn 13731: if ($result ne '') {
13732: $output .= '<ul>'."\n".
13733: $result."\n".
13734: '</ul>';
13735: }
13736: unless ($ishome) {
13737: my $replicationfail;
13738: foreach my $item (keys(%prompttofetch)) {
13739: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13740: unless ($fetchresult eq 'ok') {
13741: $replicationfail .= '<li>'.$item.'</li>'."\n";
13742: }
13743: }
13744: if ($replicationfail) {
13745: $output .= '<p class="LC_error">'.
13746: &mt('Course home server failed to retrieve:').'<ul>'.
13747: $replicationfail.
13748: '</ul></p>';
13749: }
13750: }
1.1055 raeburn 13751: } else {
13752: $warning = &mt('No items found in archive.');
13753: }
13754: if ($error) {
13755: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13756: $error.'</p>'."\n";
13757: }
13758: if ($warning) {
13759: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13760: }
13761: return $output;
13762: }
13763:
1.1066 raeburn 13764: sub cleanup_empty_dirs {
13765: my ($path) = @_;
13766: if (($path ne '') && (-d $path)) {
13767: if (opendir(my $dirh,$path)) {
13768: my @dircontents = grep(!/^\./,readdir($dirh));
13769: my $numitems = 0;
13770: foreach my $item (@dircontents) {
13771: if (-d "$path/$item") {
1.1111 raeburn 13772: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13773: if (-e "$path/$item") {
13774: $numitems ++;
13775: }
13776: } else {
13777: $numitems ++;
13778: }
13779: }
13780: if ($numitems == 0) {
13781: rmdir($path);
13782: }
13783: closedir($dirh);
13784: }
13785: }
13786: return;
13787: }
13788:
1.41 ng 13789: =pod
1.45 matthew 13790:
1.1162 raeburn 13791: =item * &get_folder_hierarchy()
1.1068 raeburn 13792:
13793: Provides hierarchy of names of folders/sub-folders containing the current
13794: item,
13795:
13796: Inputs: 3
13797: - $navmap - navmaps object
13798:
13799: - $map - url for map (either the trigger itself, or map containing
13800: the resource, which is the trigger).
13801:
13802: - $showitem - 1 => show title for map itself; 0 => do not show.
13803:
13804: Outputs: 1 @pathitems - array of folder/subfolder names.
13805:
13806: =cut
13807:
13808: sub get_folder_hierarchy {
13809: my ($navmap,$map,$showitem) = @_;
13810: my @pathitems;
13811: if (ref($navmap)) {
13812: my $mapres = $navmap->getResourceByUrl($map);
13813: if (ref($mapres)) {
13814: my $pcslist = $mapres->map_hierarchy();
13815: if ($pcslist ne '') {
13816: my @pcs = split(/,/,$pcslist);
13817: foreach my $pc (@pcs) {
13818: if ($pc == 1) {
1.1129 raeburn 13819: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13820: } else {
13821: my $res = $navmap->getByMapPc($pc);
13822: if (ref($res)) {
13823: my $title = $res->compTitle();
13824: $title =~ s/\W+/_/g;
13825: if ($title ne '') {
13826: push(@pathitems,$title);
13827: }
13828: }
13829: }
13830: }
13831: }
1.1071 raeburn 13832: if ($showitem) {
13833: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13834: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13835: } else {
13836: my $maptitle = $mapres->compTitle();
13837: $maptitle =~ s/\W+/_/g;
13838: if ($maptitle ne '') {
13839: push(@pathitems,$maptitle);
13840: }
1.1068 raeburn 13841: }
13842: }
13843: }
13844: }
13845: return @pathitems;
13846: }
13847:
13848: =pod
13849:
1.1015 raeburn 13850: =item * &get_turnedin_filepath()
13851:
13852: Determines path in a user's portfolio file for storage of files uploaded
13853: to a specific essayresponse or dropbox item.
13854:
13855: Inputs: 3 required + 1 optional.
13856: $symb is symb for resource, $uname and $udom are for current user (required).
13857: $caller is optional (can be "submission", if routine is called when storing
13858: an upoaded file when "Submit Answer" button was pressed).
13859:
13860: Returns array containing $path and $multiresp.
13861: $path is path in portfolio. $multiresp is 1 if this resource contains more
13862: than one file upload item. Callers of routine should append partid as a
13863: subdirectory to $path in cases where $multiresp is 1.
13864:
13865: Called by: homework/essayresponse.pm and homework/structuretags.pm
13866:
13867: =cut
13868:
13869: sub get_turnedin_filepath {
13870: my ($symb,$uname,$udom,$caller) = @_;
13871: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13872: my $turnindir;
13873: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13874: $turnindir = $userhash{'turnindir'};
13875: my ($path,$multiresp);
13876: if ($turnindir eq '') {
13877: if ($caller eq 'submission') {
13878: $turnindir = &mt('turned in');
13879: $turnindir =~ s/\W+/_/g;
13880: my %newhash = (
13881: 'turnindir' => $turnindir,
13882: );
13883: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13884: }
13885: }
13886: if ($turnindir ne '') {
13887: $path = '/'.$turnindir.'/';
13888: my ($multipart,$turnin,@pathitems);
13889: my $navmap = Apache::lonnavmaps::navmap->new();
13890: if (defined($navmap)) {
13891: my $mapres = $navmap->getResourceByUrl($map);
13892: if (ref($mapres)) {
13893: my $pcslist = $mapres->map_hierarchy();
13894: if ($pcslist ne '') {
13895: foreach my $pc (split(/,/,$pcslist)) {
13896: my $res = $navmap->getByMapPc($pc);
13897: if (ref($res)) {
13898: my $title = $res->compTitle();
13899: $title =~ s/\W+/_/g;
13900: if ($title ne '') {
1.1149 raeburn 13901: if (($pc > 1) && (length($title) > 12)) {
13902: $title = substr($title,0,12);
13903: }
1.1015 raeburn 13904: push(@pathitems,$title);
13905: }
13906: }
13907: }
13908: }
13909: my $maptitle = $mapres->compTitle();
13910: $maptitle =~ s/\W+/_/g;
13911: if ($maptitle ne '') {
1.1149 raeburn 13912: if (length($maptitle) > 12) {
13913: $maptitle = substr($maptitle,0,12);
13914: }
1.1015 raeburn 13915: push(@pathitems,$maptitle);
13916: }
13917: unless ($env{'request.state'} eq 'construct') {
13918: my $res = $navmap->getBySymb($symb);
13919: if (ref($res)) {
13920: my $partlist = $res->parts();
13921: my $totaluploads = 0;
13922: if (ref($partlist) eq 'ARRAY') {
13923: foreach my $part (@{$partlist}) {
13924: my @types = $res->responseType($part);
13925: my @ids = $res->responseIds($part);
13926: for (my $i=0; $i < scalar(@ids); $i++) {
13927: if ($types[$i] eq 'essay') {
13928: my $partid = $part.'_'.$ids[$i];
13929: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13930: $totaluploads ++;
13931: }
13932: }
13933: }
13934: }
13935: if ($totaluploads > 1) {
13936: $multiresp = 1;
13937: }
13938: }
13939: }
13940: }
13941: } else {
13942: return;
13943: }
13944: } else {
13945: return;
13946: }
13947: my $restitle=&Apache::lonnet::gettitle($symb);
13948: $restitle =~ s/\W+/_/g;
13949: if ($restitle eq '') {
13950: $restitle = ($resurl =~ m{/[^/]+$});
13951: if ($restitle eq '') {
13952: $restitle = time;
13953: }
13954: }
1.1149 raeburn 13955: if (length($restitle) > 12) {
13956: $restitle = substr($restitle,0,12);
13957: }
1.1015 raeburn 13958: push(@pathitems,$restitle);
13959: $path .= join('/',@pathitems);
13960: }
13961: return ($path,$multiresp);
13962: }
13963:
13964: =pod
13965:
1.464 albertel 13966: =back
1.41 ng 13967:
1.112 bowersj2 13968: =head1 CSV Upload/Handling functions
1.38 albertel 13969:
1.41 ng 13970: =over 4
13971:
1.648 raeburn 13972: =item * &upfile_store($r)
1.41 ng 13973:
13974: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13975: needs $env{'form.upfile'}
1.41 ng 13976: returns $datatoken to be put into hidden field
13977:
13978: =cut
1.31 albertel 13979:
13980: sub upfile_store {
13981: my $r=shift;
1.258 albertel 13982: $env{'form.upfile'}=~s/\r/\n/gs;
13983: $env{'form.upfile'}=~s/\f/\n/gs;
13984: $env{'form.upfile'}=~s/\n+/\n/gs;
13985: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13986:
1.1299 raeburn 13987: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13988: '_enroll_'.$env{'request.course.id'}.'_'.
13989: time.'_'.$$);
13990: return if ($datatoken eq '');
13991:
1.31 albertel 13992: {
1.158 raeburn 13993: my $datafile = $r->dir_config('lonDaemons').
13994: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 13995: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13996: print $fh $env{'form.upfile'};
1.158 raeburn 13997: close($fh);
13998: }
1.31 albertel 13999: }
14000: return $datatoken;
14001: }
14002:
1.56 matthew 14003: =pod
14004:
1.1290 raeburn 14005: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14006:
14007: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14008: $datatoken is the name to assign to the temporary file.
1.258 albertel 14009: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14010:
14011: =cut
1.31 albertel 14012:
14013: sub load_tmp_file {
1.1290 raeburn 14014: my ($r,$datatoken) = @_;
14015: return if ($datatoken eq '');
1.31 albertel 14016: my @studentdata=();
14017: {
1.158 raeburn 14018: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14019: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14020: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14021: @studentdata=<$fh>;
14022: close($fh);
14023: }
1.31 albertel 14024: }
1.258 albertel 14025: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14026: }
14027:
1.1290 raeburn 14028: sub valid_datatoken {
14029: my ($datatoken) = @_;
1.1325 raeburn 14030: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14031: return $datatoken;
14032: }
14033: return;
14034: }
14035:
1.56 matthew 14036: =pod
14037:
1.648 raeburn 14038: =item * &upfile_record_sep()
1.41 ng 14039:
14040: Separate uploaded file into records
14041: returns array of records,
1.258 albertel 14042: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14043:
14044: =cut
1.31 albertel 14045:
14046: sub upfile_record_sep {
1.258 albertel 14047: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14048: } else {
1.248 albertel 14049: my @records;
1.258 albertel 14050: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14051: if ($line=~/^\s*$/) { next; }
14052: push(@records,$line);
14053: }
14054: return @records;
1.31 albertel 14055: }
14056: }
14057:
1.56 matthew 14058: =pod
14059:
1.648 raeburn 14060: =item * &record_sep($record)
1.41 ng 14061:
1.258 albertel 14062: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14063:
14064: =cut
14065:
1.263 www 14066: sub takeleft {
14067: my $index=shift;
14068: return substr('0000'.$index,-4,4);
14069: }
14070:
1.31 albertel 14071: sub record_sep {
14072: my $record=shift;
14073: my %components=();
1.258 albertel 14074: if ($env{'form.upfiletype'} eq 'xml') {
14075: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14076: my $i=0;
1.356 albertel 14077: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14078: $field=~s/^(\"|\')//;
14079: $field=~s/(\"|\')$//;
1.263 www 14080: $components{&takeleft($i)}=$field;
1.31 albertel 14081: $i++;
14082: }
1.258 albertel 14083: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14084: my $i=0;
1.356 albertel 14085: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14086: $field=~s/^(\"|\')//;
14087: $field=~s/(\"|\')$//;
1.263 www 14088: $components{&takeleft($i)}=$field;
1.31 albertel 14089: $i++;
14090: }
14091: } else {
1.561 www 14092: my $separator=',';
1.480 banghart 14093: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14094: $separator=';';
1.480 banghart 14095: }
1.31 albertel 14096: my $i=0;
1.561 www 14097: # the character we are looking for to indicate the end of a quote or a record
14098: my $looking_for=$separator;
14099: # do not add the characters to the fields
14100: my $ignore=0;
14101: # we just encountered a separator (or the beginning of the record)
14102: my $just_found_separator=1;
14103: # store the field we are working on here
14104: my $field='';
14105: # work our way through all characters in record
14106: foreach my $character ($record=~/(.)/g) {
14107: if ($character eq $looking_for) {
14108: if ($character ne $separator) {
14109: # Found the end of a quote, again looking for separator
14110: $looking_for=$separator;
14111: $ignore=1;
14112: } else {
14113: # Found a separator, store away what we got
14114: $components{&takeleft($i)}=$field;
14115: $i++;
14116: $just_found_separator=1;
14117: $ignore=0;
14118: $field='';
14119: }
14120: next;
14121: }
14122: # single or double quotation marks after a separator indicate beginning of a quote
14123: # we are now looking for the end of the quote and need to ignore separators
14124: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14125: $looking_for=$character;
14126: next;
14127: }
14128: # ignore would be true after we reached the end of a quote
14129: if ($ignore) { next; }
14130: if (($just_found_separator) && ($character=~/\s/)) { next; }
14131: $field.=$character;
14132: $just_found_separator=0;
1.31 albertel 14133: }
1.561 www 14134: # catch the very last entry, since we never encountered the separator
14135: $components{&takeleft($i)}=$field;
1.31 albertel 14136: }
14137: return %components;
14138: }
14139:
1.144 matthew 14140: ######################################################
14141: ######################################################
14142:
1.56 matthew 14143: =pod
14144:
1.648 raeburn 14145: =item * &upfile_select_html()
1.41 ng 14146:
1.144 matthew 14147: Return HTML code to select a file from the users machine and specify
14148: the file type.
1.41 ng 14149:
14150: =cut
14151:
1.144 matthew 14152: ######################################################
14153: ######################################################
1.31 albertel 14154: sub upfile_select_html {
1.144 matthew 14155: my %Types = (
14156: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14157: semisv => &mt('Semicolon separated values'),
1.144 matthew 14158: space => &mt('Space separated'),
14159: tab => &mt('Tabulator separated'),
14160: # xml => &mt('HTML/XML'),
14161: );
14162: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14163: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14164: foreach my $type (sort(keys(%Types))) {
14165: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14166: }
14167: $Str .= "</select>\n";
14168: return $Str;
1.31 albertel 14169: }
14170:
1.301 albertel 14171: sub get_samples {
14172: my ($records,$toget) = @_;
14173: my @samples=({});
14174: my $got=0;
14175: foreach my $rec (@$records) {
14176: my %temp = &record_sep($rec);
14177: if (! grep(/\S/, values(%temp))) { next; }
14178: if (%temp) {
14179: $samples[$got]=\%temp;
14180: $got++;
14181: if ($got == $toget) { last; }
14182: }
14183: }
14184: return \@samples;
14185: }
14186:
1.144 matthew 14187: ######################################################
14188: ######################################################
14189:
1.56 matthew 14190: =pod
14191:
1.648 raeburn 14192: =item * &csv_print_samples($r,$records)
1.41 ng 14193:
14194: Prints a table of sample values from each column uploaded $r is an
14195: Apache Request ref, $records is an arrayref from
14196: &Apache::loncommon::upfile_record_sep
14197:
14198: =cut
14199:
1.144 matthew 14200: ######################################################
14201: ######################################################
1.31 albertel 14202: sub csv_print_samples {
14203: my ($r,$records) = @_;
1.662 bisitz 14204: my $samples = &get_samples($records,5);
1.301 albertel 14205:
1.594 raeburn 14206: $r->print(&mt('Samples').'<br />'.&start_data_table().
14207: &start_data_table_header_row());
1.356 albertel 14208: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14209: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14210: $r->print(&end_data_table_header_row());
1.301 albertel 14211: foreach my $hash (@$samples) {
1.594 raeburn 14212: $r->print(&start_data_table_row());
1.356 albertel 14213: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14214: $r->print('<td>');
1.356 albertel 14215: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14216: $r->print('</td>');
14217: }
1.594 raeburn 14218: $r->print(&end_data_table_row());
1.31 albertel 14219: }
1.594 raeburn 14220: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14221: }
14222:
1.144 matthew 14223: ######################################################
14224: ######################################################
14225:
1.56 matthew 14226: =pod
14227:
1.648 raeburn 14228: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14229:
14230: Prints a table to create associations between values and table columns.
1.144 matthew 14231:
1.41 ng 14232: $r is an Apache Request ref,
14233: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14234: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14235:
14236: =cut
14237:
1.144 matthew 14238: ######################################################
14239: ######################################################
1.31 albertel 14240: sub csv_print_select_table {
14241: my ($r,$records,$d) = @_;
1.301 albertel 14242: my $i=0;
14243: my $samples = &get_samples($records,1);
1.144 matthew 14244: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14245: &start_data_table().&start_data_table_header_row().
1.144 matthew 14246: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14247: '<th>'.&mt('Column').'</th>'.
14248: &end_data_table_header_row()."\n");
1.356 albertel 14249: foreach my $array_ref (@$d) {
14250: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14251: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14252:
1.875 bisitz 14253: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14254: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14255: $r->print('<option value="none"></option>');
1.356 albertel 14256: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14257: $r->print('<option value="'.$sample.'"'.
14258: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14259: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14260: }
1.594 raeburn 14261: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14262: $i++;
14263: }
1.594 raeburn 14264: $r->print(&end_data_table());
1.31 albertel 14265: $i--;
14266: return $i;
14267: }
1.56 matthew 14268:
1.144 matthew 14269: ######################################################
14270: ######################################################
14271:
1.56 matthew 14272: =pod
1.31 albertel 14273:
1.648 raeburn 14274: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14275:
14276: Prints a table of sample values from the upload and can make associate samples to internal names.
14277:
14278: $r is an Apache Request ref,
14279: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14280: $d is an array of 2 element arrays (internal name, displayed name)
14281:
14282: =cut
14283:
1.144 matthew 14284: ######################################################
14285: ######################################################
1.31 albertel 14286: sub csv_samples_select_table {
14287: my ($r,$records,$d) = @_;
14288: my $i=0;
1.144 matthew 14289: #
1.662 bisitz 14290: my $max_samples = 5;
14291: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14292: $r->print(&start_data_table().
14293: &start_data_table_header_row().'<th>'.
14294: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14295: &end_data_table_header_row());
1.301 albertel 14296:
14297: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14298: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14299: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14300: foreach my $option (@$d) {
14301: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14302: $r->print('<option value="'.$value.'"'.
1.253 albertel 14303: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14304: $display.'</option>');
1.31 albertel 14305: }
14306: $r->print('</select></td><td>');
1.662 bisitz 14307: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14308: if (defined($samples->[$line]{$key})) {
14309: $r->print($samples->[$line]{$key}."<br />\n");
14310: }
14311: }
1.594 raeburn 14312: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14313: $i++;
14314: }
1.594 raeburn 14315: $r->print(&end_data_table());
1.31 albertel 14316: $i--;
14317: return($i);
1.115 matthew 14318: }
14319:
1.144 matthew 14320: ######################################################
14321: ######################################################
14322:
1.115 matthew 14323: =pod
14324:
1.648 raeburn 14325: =item * &clean_excel_name($name)
1.115 matthew 14326:
14327: Returns a replacement for $name which does not contain any illegal characters.
14328:
14329: =cut
14330:
1.144 matthew 14331: ######################################################
14332: ######################################################
1.115 matthew 14333: sub clean_excel_name {
14334: my ($name) = @_;
14335: $name =~ s/[:\*\?\/\\]//g;
14336: if (length($name) > 31) {
14337: $name = substr($name,0,31);
14338: }
14339: return $name;
1.25 albertel 14340: }
1.84 albertel 14341:
1.85 albertel 14342: =pod
14343:
1.648 raeburn 14344: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14345:
14346: Returns either 1 or undef
14347:
14348: 1 if the part is to be hidden, undef if it is to be shown
14349:
14350: Arguments are:
14351:
14352: $id the id of the part to be checked
14353: $symb, optional the symb of the resource to check
14354: $udom, optional the domain of the user to check for
14355: $uname, optional the username of the user to check for
14356:
14357: =cut
1.84 albertel 14358:
14359: sub check_if_partid_hidden {
14360: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14361: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14362: $symb,$udom,$uname);
1.141 albertel 14363: my $truth=1;
14364: #if the string starts with !, then the list is the list to show not hide
14365: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14366: my @hiddenlist=split(/,/,$hiddenparts);
14367: foreach my $checkid (@hiddenlist) {
1.141 albertel 14368: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14369: }
1.141 albertel 14370: return !$truth;
1.84 albertel 14371: }
1.127 matthew 14372:
1.138 matthew 14373:
14374: ############################################################
14375: ############################################################
14376:
14377: =pod
14378:
1.157 matthew 14379: =back
14380:
1.138 matthew 14381: =head1 cgi-bin script and graphing routines
14382:
1.157 matthew 14383: =over 4
14384:
1.648 raeburn 14385: =item * &get_cgi_id()
1.138 matthew 14386:
14387: Inputs: none
14388:
14389: Returns an id which can be used to pass environment variables
14390: to various cgi-bin scripts. These environment variables will
14391: be removed from the users environment after a given time by
14392: the routine &Apache::lonnet::transfer_profile_to_env.
14393:
14394: =cut
14395:
14396: ############################################################
14397: ############################################################
1.152 albertel 14398: my $uniq=0;
1.136 matthew 14399: sub get_cgi_id {
1.154 albertel 14400: $uniq=($uniq+1)%100000;
1.280 albertel 14401: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14402: }
14403:
1.127 matthew 14404: ############################################################
14405: ############################################################
14406:
14407: =pod
14408:
1.648 raeburn 14409: =item * &DrawBarGraph()
1.127 matthew 14410:
1.138 matthew 14411: Facilitates the plotting of data in a (stacked) bar graph.
14412: Puts plot definition data into the users environment in order for
14413: graph.png to plot it. Returns an <img> tag for the plot.
14414: The bars on the plot are labeled '1','2',...,'n'.
14415:
14416: Inputs:
14417:
14418: =over 4
14419:
14420: =item $Title: string, the title of the plot
14421:
14422: =item $xlabel: string, text describing the X-axis of the plot
14423:
14424: =item $ylabel: string, text describing the Y-axis of the plot
14425:
14426: =item $Max: scalar, the maximum Y value to use in the plot
14427: If $Max is < any data point, the graph will not be rendered.
14428:
1.140 matthew 14429: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14430: they are plotted. If undefined, default values will be used.
14431:
1.178 matthew 14432: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14433:
1.138 matthew 14434: =item @Values: An array of array references. Each array reference holds data
14435: to be plotted in a stacked bar chart.
14436:
1.239 matthew 14437: =item If the final element of @Values is a hash reference the key/value
14438: pairs will be added to the graph definition.
14439:
1.138 matthew 14440: =back
14441:
14442: Returns:
14443:
14444: An <img> tag which references graph.png and the appropriate identifying
14445: information for the plot.
14446:
1.127 matthew 14447: =cut
14448:
14449: ############################################################
14450: ############################################################
1.134 matthew 14451: sub DrawBarGraph {
1.178 matthew 14452: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14453: #
14454: if (! defined($colors)) {
14455: $colors = ['#33ff00',
14456: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14457: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14458: ];
14459: }
1.228 matthew 14460: my $extra_settings = {};
14461: if (ref($Values[-1]) eq 'HASH') {
14462: $extra_settings = pop(@Values);
14463: }
1.127 matthew 14464: #
1.136 matthew 14465: my $identifier = &get_cgi_id();
14466: my $id = 'cgi.'.$identifier;
1.129 matthew 14467: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14468: return '';
14469: }
1.225 matthew 14470: #
14471: my @Labels;
14472: if (defined($labels)) {
14473: @Labels = @$labels;
14474: } else {
14475: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14476: push(@Labels,$i+1);
1.225 matthew 14477: }
14478: }
14479: #
1.129 matthew 14480: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14481: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14482: my %ValuesHash;
14483: my $NumSets=1;
14484: foreach my $array (@Values) {
14485: next if (! ref($array));
1.136 matthew 14486: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14487: join(',',@$array);
1.129 matthew 14488: }
1.127 matthew 14489: #
1.136 matthew 14490: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14491: if ($NumBars < 3) {
14492: $width = 120+$NumBars*32;
1.220 matthew 14493: $xskip = 1;
1.225 matthew 14494: $bar_width = 30;
14495: } elsif ($NumBars < 5) {
14496: $width = 120+$NumBars*20;
14497: $xskip = 1;
14498: $bar_width = 20;
1.220 matthew 14499: } elsif ($NumBars < 10) {
1.136 matthew 14500: $width = 120+$NumBars*15;
14501: $xskip = 1;
14502: $bar_width = 15;
14503: } elsif ($NumBars <= 25) {
14504: $width = 120+$NumBars*11;
14505: $xskip = 5;
14506: $bar_width = 8;
14507: } elsif ($NumBars <= 50) {
14508: $width = 120+$NumBars*8;
14509: $xskip = 5;
14510: $bar_width = 4;
14511: } else {
14512: $width = 120+$NumBars*8;
14513: $xskip = 5;
14514: $bar_width = 4;
14515: }
14516: #
1.137 matthew 14517: $Max = 1 if ($Max < 1);
14518: if ( int($Max) < $Max ) {
14519: $Max++;
14520: $Max = int($Max);
14521: }
1.127 matthew 14522: $Title = '' if (! defined($Title));
14523: $xlabel = '' if (! defined($xlabel));
14524: $ylabel = '' if (! defined($ylabel));
1.369 www 14525: $ValuesHash{$id.'.title'} = &escape($Title);
14526: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14527: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14528: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14529: $ValuesHash{$id.'.NumBars'} = $NumBars;
14530: $ValuesHash{$id.'.NumSets'} = $NumSets;
14531: $ValuesHash{$id.'.PlotType'} = 'bar';
14532: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14533: $ValuesHash{$id.'.height'} = $height;
14534: $ValuesHash{$id.'.width'} = $width;
14535: $ValuesHash{$id.'.xskip'} = $xskip;
14536: $ValuesHash{$id.'.bar_width'} = $bar_width;
14537: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14538: #
1.228 matthew 14539: # Deal with other parameters
14540: while (my ($key,$value) = each(%$extra_settings)) {
14541: $ValuesHash{$id.'.'.$key} = $value;
14542: }
14543: #
1.646 raeburn 14544: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14545: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14546: }
14547:
14548: ############################################################
14549: ############################################################
14550:
14551: =pod
14552:
1.648 raeburn 14553: =item * &DrawXYGraph()
1.137 matthew 14554:
1.138 matthew 14555: Facilitates the plotting of data in an XY graph.
14556: Puts plot definition data into the users environment in order for
14557: graph.png to plot it. Returns an <img> tag for the plot.
14558:
14559: Inputs:
14560:
14561: =over 4
14562:
14563: =item $Title: string, the title of the plot
14564:
14565: =item $xlabel: string, text describing the X-axis of the plot
14566:
14567: =item $ylabel: string, text describing the Y-axis of the plot
14568:
14569: =item $Max: scalar, the maximum Y value to use in the plot
14570: If $Max is < any data point, the graph will not be rendered.
14571:
14572: =item $colors: Array ref containing the hex color codes for the data to be
14573: plotted in. If undefined, default values will be used.
14574:
14575: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14576:
14577: =item $Ydata: Array ref containing Array refs.
1.185 www 14578: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14579:
14580: =item %Values: hash indicating or overriding any default values which are
14581: passed to graph.png.
14582: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14583:
14584: =back
14585:
14586: Returns:
14587:
14588: An <img> tag which references graph.png and the appropriate identifying
14589: information for the plot.
14590:
1.137 matthew 14591: =cut
14592:
14593: ############################################################
14594: ############################################################
14595: sub DrawXYGraph {
14596: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14597: #
14598: # Create the identifier for the graph
14599: my $identifier = &get_cgi_id();
14600: my $id = 'cgi.'.$identifier;
14601: #
14602: $Title = '' if (! defined($Title));
14603: $xlabel = '' if (! defined($xlabel));
14604: $ylabel = '' if (! defined($ylabel));
14605: my %ValuesHash =
14606: (
1.369 www 14607: $id.'.title' => &escape($Title),
14608: $id.'.xlabel' => &escape($xlabel),
14609: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14610: $id.'.y_max_value'=> $Max,
14611: $id.'.labels' => join(',',@$Xlabels),
14612: $id.'.PlotType' => 'XY',
14613: );
14614: #
14615: if (defined($colors) && ref($colors) eq 'ARRAY') {
14616: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14617: }
14618: #
14619: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14620: return '';
14621: }
14622: my $NumSets=1;
1.138 matthew 14623: foreach my $array (@{$Ydata}){
1.137 matthew 14624: next if (! ref($array));
14625: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14626: }
1.138 matthew 14627: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14628: #
14629: # Deal with other parameters
14630: while (my ($key,$value) = each(%Values)) {
14631: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14632: }
14633: #
1.646 raeburn 14634: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14635: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14636: }
14637:
14638: ############################################################
14639: ############################################################
14640:
14641: =pod
14642:
1.648 raeburn 14643: =item * &DrawXYYGraph()
1.138 matthew 14644:
14645: Facilitates the plotting of data in an XY graph with two Y axes.
14646: Puts plot definition data into the users environment in order for
14647: graph.png to plot it. Returns an <img> tag for the plot.
14648:
14649: Inputs:
14650:
14651: =over 4
14652:
14653: =item $Title: string, the title of the plot
14654:
14655: =item $xlabel: string, text describing the X-axis of the plot
14656:
14657: =item $ylabel: string, text describing the Y-axis of the plot
14658:
14659: =item $colors: Array ref containing the hex color codes for the data to be
14660: plotted in. If undefined, default values will be used.
14661:
14662: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14663:
14664: =item $Ydata1: The first data set
14665:
14666: =item $Min1: The minimum value of the left Y-axis
14667:
14668: =item $Max1: The maximum value of the left Y-axis
14669:
14670: =item $Ydata2: The second data set
14671:
14672: =item $Min2: The minimum value of the right Y-axis
14673:
14674: =item $Max2: The maximum value of the left Y-axis
14675:
14676: =item %Values: hash indicating or overriding any default values which are
14677: passed to graph.png.
14678: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14679:
14680: =back
14681:
14682: Returns:
14683:
14684: An <img> tag which references graph.png and the appropriate identifying
14685: information for the plot.
1.136 matthew 14686:
14687: =cut
14688:
14689: ############################################################
14690: ############################################################
1.137 matthew 14691: sub DrawXYYGraph {
14692: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14693: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14694: #
14695: # Create the identifier for the graph
14696: my $identifier = &get_cgi_id();
14697: my $id = 'cgi.'.$identifier;
14698: #
14699: $Title = '' if (! defined($Title));
14700: $xlabel = '' if (! defined($xlabel));
14701: $ylabel = '' if (! defined($ylabel));
14702: my %ValuesHash =
14703: (
1.369 www 14704: $id.'.title' => &escape($Title),
14705: $id.'.xlabel' => &escape($xlabel),
14706: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14707: $id.'.labels' => join(',',@$Xlabels),
14708: $id.'.PlotType' => 'XY',
14709: $id.'.NumSets' => 2,
1.137 matthew 14710: $id.'.two_axes' => 1,
14711: $id.'.y1_max_value' => $Max1,
14712: $id.'.y1_min_value' => $Min1,
14713: $id.'.y2_max_value' => $Max2,
14714: $id.'.y2_min_value' => $Min2,
1.136 matthew 14715: );
14716: #
1.137 matthew 14717: if (defined($colors) && ref($colors) eq 'ARRAY') {
14718: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14719: }
14720: #
14721: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14722: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14723: return '';
14724: }
14725: my $NumSets=1;
1.137 matthew 14726: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14727: next if (! ref($array));
14728: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14729: }
14730: #
14731: # Deal with other parameters
14732: while (my ($key,$value) = each(%Values)) {
14733: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14734: }
14735: #
1.646 raeburn 14736: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14737: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14738: }
14739:
14740: ############################################################
14741: ############################################################
14742:
14743: =pod
14744:
1.157 matthew 14745: =back
14746:
1.139 matthew 14747: =head1 Statistics helper routines?
14748:
14749: Bad place for them but what the hell.
14750:
1.157 matthew 14751: =over 4
14752:
1.648 raeburn 14753: =item * &chartlink()
1.139 matthew 14754:
14755: Returns a link to the chart for a specific student.
14756:
14757: Inputs:
14758:
14759: =over 4
14760:
14761: =item $linktext: The text of the link
14762:
14763: =item $sname: The students username
14764:
14765: =item $sdomain: The students domain
14766:
14767: =back
14768:
1.157 matthew 14769: =back
14770:
1.139 matthew 14771: =cut
14772:
14773: ############################################################
14774: ############################################################
14775: sub chartlink {
14776: my ($linktext, $sname, $sdomain) = @_;
14777: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14778: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14779: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14780: '">'.$linktext.'</a>';
1.153 matthew 14781: }
14782:
14783: #######################################################
14784: #######################################################
14785:
14786: =pod
14787:
14788: =head1 Course Environment Routines
1.157 matthew 14789:
14790: =over 4
1.153 matthew 14791:
1.648 raeburn 14792: =item * &restore_course_settings()
1.153 matthew 14793:
1.648 raeburn 14794: =item * &store_course_settings()
1.153 matthew 14795:
14796: Restores/Store indicated form parameters from the course environment.
14797: Will not overwrite existing values of the form parameters.
14798:
14799: Inputs:
14800: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14801:
14802: a hash ref describing the data to be stored. For example:
14803:
14804: %Save_Parameters = ('Status' => 'scalar',
14805: 'chartoutputmode' => 'scalar',
14806: 'chartoutputdata' => 'scalar',
14807: 'Section' => 'array',
1.373 raeburn 14808: 'Group' => 'array',
1.153 matthew 14809: 'StudentData' => 'array',
14810: 'Maps' => 'array');
14811:
14812: Returns: both routines return nothing
14813:
1.631 raeburn 14814: =back
14815:
1.153 matthew 14816: =cut
14817:
14818: #######################################################
14819: #######################################################
14820: sub store_course_settings {
1.496 albertel 14821: return &store_settings($env{'request.course.id'},@_);
14822: }
14823:
14824: sub store_settings {
1.153 matthew 14825: # save to the environment
14826: # appenv the same items, just to be safe
1.300 albertel 14827: my $udom = $env{'user.domain'};
14828: my $uname = $env{'user.name'};
1.496 albertel 14829: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14830: my %SaveHash;
14831: my %AppHash;
14832: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14833: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14834: my $envname = 'environment.'.$basename;
1.258 albertel 14835: if (exists($env{'form.'.$setting})) {
1.153 matthew 14836: # Save this value away
14837: if ($type eq 'scalar' &&
1.258 albertel 14838: (! exists($env{$envname}) ||
14839: $env{$envname} ne $env{'form.'.$setting})) {
14840: $SaveHash{$basename} = $env{'form.'.$setting};
14841: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14842: } elsif ($type eq 'array') {
14843: my $stored_form;
1.258 albertel 14844: if (ref($env{'form.'.$setting})) {
1.153 matthew 14845: $stored_form = join(',',
14846: map {
1.369 www 14847: &escape($_);
1.258 albertel 14848: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14849: } else {
14850: $stored_form =
1.369 www 14851: &escape($env{'form.'.$setting});
1.153 matthew 14852: }
14853: # Determine if the array contents are the same.
1.258 albertel 14854: if ($stored_form ne $env{$envname}) {
1.153 matthew 14855: $SaveHash{$basename} = $stored_form;
14856: $AppHash{$envname} = $stored_form;
14857: }
14858: }
14859: }
14860: }
14861: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14862: $udom,$uname);
1.153 matthew 14863: if ($put_result !~ /^(ok|delayed)/) {
14864: &Apache::lonnet::logthis('unable to save form parameters, '.
14865: 'got error:'.$put_result);
14866: }
14867: # Make sure these settings stick around in this session, too
1.646 raeburn 14868: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14869: return;
14870: }
14871:
14872: sub restore_course_settings {
1.499 albertel 14873: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14874: }
14875:
14876: sub restore_settings {
14877: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14878: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14879: next if (exists($env{'form.'.$setting}));
1.496 albertel 14880: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14881: '.'.$setting;
1.258 albertel 14882: if (exists($env{$envname})) {
1.153 matthew 14883: if ($type eq 'scalar') {
1.258 albertel 14884: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14885: } elsif ($type eq 'array') {
1.258 albertel 14886: $env{'form.'.$setting} = [
1.153 matthew 14887: map {
1.369 www 14888: &unescape($_);
1.258 albertel 14889: } split(',',$env{$envname})
1.153 matthew 14890: ];
14891: }
14892: }
14893: }
1.127 matthew 14894: }
14895:
1.618 raeburn 14896: #######################################################
14897: #######################################################
14898:
14899: =pod
14900:
14901: =head1 Domain E-mail Routines
14902:
14903: =over 4
14904:
1.648 raeburn 14905: =item * &build_recipient_list()
1.618 raeburn 14906:
1.1144 raeburn 14907: Build recipient lists for following types of e-mail:
1.766 raeburn 14908: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14909: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14910: module change checking, student/employee ID conflict checks, as
14911: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14912: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14913:
14914: Inputs:
1.619 raeburn 14915: defmail (scalar - email address of default recipient),
1.1144 raeburn 14916: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14917: requestsmail, updatesmail, or idconflictsmail).
14918:
1.619 raeburn 14919: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14920:
1.619 raeburn 14921: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14922: i.e., predates configuration by DC via domainprefs.pm
14923:
14924: $requname username of requester (if mailing type is helpdeskmail)
14925:
14926: $requdom domain of requester (if mailing type is helpdeskmail)
14927:
14928: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14929:
1.618 raeburn 14930:
1.655 raeburn 14931: Returns: comma separated list of addresses to which to send e-mail.
14932:
14933: =back
1.618 raeburn 14934:
14935: =cut
14936:
14937: ############################################################
14938: ############################################################
14939: sub build_recipient_list {
1.1297 raeburn 14940: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14941: my @recipients;
1.1270 raeburn 14942: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14943: my %domconfig =
1.1270 raeburn 14944: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14945: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14946: if (exists($domconfig{'contacts'}{$mailing})) {
14947: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14948: my @contacts = ('adminemail','supportemail');
14949: foreach my $item (@contacts) {
14950: if ($domconfig{'contacts'}{$mailing}{$item}) {
14951: my $addr = $domconfig{'contacts'}{$item};
14952: if (!grep(/^\Q$addr\E$/,@recipients)) {
14953: push(@recipients,$addr);
14954: }
1.619 raeburn 14955: }
1.1270 raeburn 14956: }
14957: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14958: if ($mailing eq 'helpdeskmail') {
14959: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14960: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14961: my @ok_bccs;
14962: foreach my $bcc (@bccs) {
14963: $bcc =~ s/^\s+//g;
14964: $bcc =~ s/\s+$//g;
14965: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14966: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14967: push(@ok_bccs,$bcc);
14968: }
14969: }
14970: }
14971: if (@ok_bccs > 0) {
14972: $allbcc = join(', ',@ok_bccs);
14973: }
14974: }
14975: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14976: }
14977: }
1.766 raeburn 14978: } elsif ($origmail ne '') {
1.1270 raeburn 14979: $lastresort = $origmail;
1.618 raeburn 14980: }
1.1297 raeburn 14981: if ($mailing eq 'helpdeskmail') {
14982: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14983: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14984: my ($inststatus,$inststatus_checked);
14985: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14986: ($env{'user.domain'} ne 'public')) {
14987: $inststatus_checked = 1;
14988: $inststatus = $env{'environment.inststatus'};
14989: }
14990: unless ($inststatus_checked) {
14991: if (($requname ne '') && ($requdom ne '')) {
14992: if (($requname =~ /^$match_username$/) &&
14993: ($requdom =~ /^$match_domain$/) &&
14994: (&Apache::lonnet::domain($requdom))) {
14995: my $requhome = &Apache::lonnet::homeserver($requname,
14996: $requdom);
14997: unless ($requhome eq 'no_host') {
14998: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14999: $inststatus = $userenv{'inststatus'};
15000: $inststatus_checked = 1;
15001: }
15002: }
15003: }
15004: }
15005: unless ($inststatus_checked) {
15006: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15007: my %srch = (srchby => 'email',
15008: srchdomain => $defdom,
15009: srchterm => $reqemail,
15010: srchtype => 'exact');
15011: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15012: foreach my $uname (keys(%srch_results)) {
15013: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15014: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15015: $inststatus_checked = 1;
15016: last;
15017: }
15018: }
15019: unless ($inststatus_checked) {
15020: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15021: if ($dirsrchres eq 'ok') {
15022: foreach my $uname (keys(%srch_results)) {
15023: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15024: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15025: $inststatus_checked = 1;
15026: last;
15027: }
15028: }
15029: }
15030: }
15031: }
15032: }
15033: if ($inststatus ne '') {
15034: foreach my $status (split(/\:/,$inststatus)) {
15035: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15036: my @contacts = ('adminemail','supportemail');
15037: foreach my $item (@contacts) {
15038: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15039: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15040: if (!grep(/^\Q$addr\E$/,@recipients)) {
15041: push(@recipients,$addr);
15042: }
15043: }
15044: }
15045: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15046: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15047: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15048: my @ok_bccs;
15049: foreach my $bcc (@bccs) {
15050: $bcc =~ s/^\s+//g;
15051: $bcc =~ s/\s+$//g;
15052: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15053: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15054: push(@ok_bccs,$bcc);
15055: }
15056: }
15057: }
15058: if (@ok_bccs > 0) {
15059: $allbcc = join(', ',@ok_bccs);
15060: }
15061: }
15062: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15063: last;
15064: }
15065: }
15066: }
15067: }
15068: }
1.619 raeburn 15069: } elsif ($origmail ne '') {
1.1270 raeburn 15070: $lastresort = $origmail;
15071: }
1.1297 raeburn 15072: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15073: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15074: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15075: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15076: my %what = (
15077: perlvar => 1,
15078: );
15079: my $primary = &Apache::lonnet::domain($defdom,'primary');
15080: if ($primary) {
15081: my $gotaddr;
15082: my ($result,$returnhash) =
15083: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15084: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15085: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15086: $lastresort = $returnhash->{'lonSupportEMail'};
15087: $gotaddr = 1;
15088: }
15089: }
15090: unless ($gotaddr) {
15091: my $uintdom = &Apache::lonnet::internet_dom($primary);
15092: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15093: unless ($uintdom eq $intdom) {
15094: my %domconfig =
15095: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15096: if (ref($domconfig{'contacts'}) eq 'HASH') {
15097: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15098: my @contacts = ('adminemail','supportemail');
15099: foreach my $item (@contacts) {
15100: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15101: my $addr = $domconfig{'contacts'}{$item};
15102: if (!grep(/^\Q$addr\E$/,@recipients)) {
15103: push(@recipients,$addr);
15104: }
15105: }
15106: }
15107: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15108: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15109: }
15110: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15111: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15112: my @ok_bccs;
15113: foreach my $bcc (@bccs) {
15114: $bcc =~ s/^\s+//g;
15115: $bcc =~ s/\s+$//g;
15116: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15117: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15118: push(@ok_bccs,$bcc);
15119: }
15120: }
15121: }
15122: if (@ok_bccs > 0) {
15123: $allbcc = join(', ',@ok_bccs);
15124: }
15125: }
15126: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15127: }
15128: }
15129: }
15130: }
15131: }
15132: }
1.618 raeburn 15133: }
1.688 raeburn 15134: if (defined($defmail)) {
15135: if ($defmail ne '') {
15136: push(@recipients,$defmail);
15137: }
1.618 raeburn 15138: }
15139: if ($otheremails) {
1.619 raeburn 15140: my @others;
15141: if ($otheremails =~ /,/) {
15142: @others = split(/,/,$otheremails);
1.618 raeburn 15143: } else {
1.619 raeburn 15144: push(@others,$otheremails);
15145: }
15146: foreach my $addr (@others) {
15147: if (!grep(/^\Q$addr\E$/,@recipients)) {
15148: push(@recipients,$addr);
15149: }
1.618 raeburn 15150: }
15151: }
1.1298 raeburn 15152: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15153: if ((!@recipients) && ($lastresort ne '')) {
15154: push(@recipients,$lastresort);
15155: }
15156: } elsif ($lastresort ne '') {
15157: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15158: push(@recipients,$lastresort);
15159: }
15160: }
1.1271 raeburn 15161: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15162: if (wantarray) {
15163: return ($recipientlist,$allbcc,$addtext);
15164: } else {
15165: return $recipientlist;
15166: }
1.618 raeburn 15167: }
15168:
1.127 matthew 15169: ############################################################
15170: ############################################################
1.154 albertel 15171:
1.655 raeburn 15172: =pod
15173:
1.1224 musolffc 15174: =over 4
15175:
1.1223 musolffc 15176: =item * &mime_email()
15177:
15178: Sends an email with a possible attachment
15179:
15180: Inputs:
15181:
15182: =over 4
15183:
15184: from - Sender's email address
15185:
15186: to - Email address of recipient
15187:
15188: subject - Subject of email
15189:
15190: body - Body of email
15191:
15192: cc_string - Carbon copy email address
15193:
15194: bcc - Blind carbon copy email address
15195:
15196: type - File type of attachment
15197:
15198: attachment_path - Path of file to be attached
15199:
15200: file_name - Name of file to be attached
15201:
15202: attachment_text - The body of an attachment of type "TEXT"
15203:
15204: =back
15205:
15206: =back
15207:
15208: =cut
15209:
15210: ############################################################
15211: ############################################################
15212:
15213: sub mime_email {
15214: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15215: $file_name, $attachment_text) = @_;
15216: my $msg = MIME::Lite->new(
15217: From => $from,
15218: To => $to,
15219: Subject => $subject,
15220: Type =>'TEXT',
15221: Data => $body,
15222: );
15223: if ($cc_string ne '') {
15224: $msg->add("Cc" => $cc_string);
15225: }
15226: if ($bcc ne '') {
15227: $msg->add("Bcc" => $bcc);
15228: }
15229: $msg->attr("content-type" => "text/plain");
15230: $msg->attr("content-type.charset" => "UTF-8");
15231: # Attach file if given
15232: if ($attachment_path) {
15233: unless ($file_name) {
15234: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15235: }
15236: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15237: $msg->attach(Type => $type,
15238: Path => $attachment_path,
15239: Filename => $file_name
15240: );
15241: # Otherwise attach text if given
15242: } elsif ($attachment_text) {
15243: $msg->attach(Type => 'TEXT',
15244: Data => $attachment_text);
15245: }
15246: # Send it
15247: $msg->send('sendmail');
15248: }
15249:
15250: ############################################################
15251: ############################################################
15252:
15253: =pod
15254:
1.655 raeburn 15255: =head1 Course Catalog Routines
15256:
15257: =over 4
15258:
15259: =item * &gather_categories()
15260:
15261: Converts category definitions - keys of categories hash stored in
15262: coursecategories in configuration.db on the primary library server in a
15263: domain - to an array. Also generates javascript and idx hash used to
15264: generate Domain Coordinator interface for editing Course Categories.
15265:
15266: Inputs:
1.663 raeburn 15267:
1.655 raeburn 15268: categories (reference to hash of category definitions).
1.663 raeburn 15269:
1.655 raeburn 15270: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15271: categories and subcategories).
1.663 raeburn 15272:
1.655 raeburn 15273: idx (reference to hash of counters used in Domain Coordinator interface for
15274: editing Course Categories).
1.663 raeburn 15275:
1.655 raeburn 15276: jsarray (reference to array of categories used to create Javascript arrays for
15277: Domain Coordinator interface for editing Course Categories).
15278:
15279: Returns: nothing
15280:
15281: Side effects: populates cats, idx and jsarray.
15282:
15283: =cut
15284:
15285: sub gather_categories {
15286: my ($categories,$cats,$idx,$jsarray) = @_;
15287: my %counters;
15288: my $num = 0;
15289: foreach my $item (keys(%{$categories})) {
15290: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15291: if ($container eq '' && $depth == 0) {
15292: $cats->[$depth][$categories->{$item}] = $cat;
15293: } else {
15294: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15295: }
15296: my ($escitem,$tail) = split(/:/,$item,2);
15297: if ($counters{$tail} eq '') {
15298: $counters{$tail} = $num;
15299: $num ++;
15300: }
15301: if (ref($idx) eq 'HASH') {
15302: $idx->{$item} = $counters{$tail};
15303: }
15304: if (ref($jsarray) eq 'ARRAY') {
15305: push(@{$jsarray->[$counters{$tail}]},$item);
15306: }
15307: }
15308: return;
15309: }
15310:
15311: =pod
15312:
15313: =item * &extract_categories()
15314:
15315: Used to generate breadcrumb trails for course categories.
15316:
15317: Inputs:
1.663 raeburn 15318:
1.655 raeburn 15319: categories (reference to hash of category definitions).
1.663 raeburn 15320:
1.655 raeburn 15321: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15322: categories and subcategories).
1.663 raeburn 15323:
1.655 raeburn 15324: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15325:
1.655 raeburn 15326: allitems (reference to hash - key is category key
15327: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15328:
1.655 raeburn 15329: idx (reference to hash of counters used in Domain Coordinator interface for
15330: editing Course Categories).
1.663 raeburn 15331:
1.655 raeburn 15332: jsarray (reference to array of categories used to create Javascript arrays for
15333: Domain Coordinator interface for editing Course Categories).
15334:
1.665 raeburn 15335: subcats (reference to hash of arrays containing all subcategories within each
15336: category, -recursive)
15337:
1.1321 raeburn 15338: maxd (reference to hash used to hold max depth for all top-level categories).
15339:
1.655 raeburn 15340: Returns: nothing
15341:
15342: Side effects: populates trails and allitems hash references.
15343:
15344: =cut
15345:
15346: sub extract_categories {
1.1321 raeburn 15347: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15348: if (ref($categories) eq 'HASH') {
15349: &gather_categories($categories,$cats,$idx,$jsarray);
15350: if (ref($cats->[0]) eq 'ARRAY') {
15351: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15352: my $name = $cats->[0][$i];
15353: my $item = &escape($name).'::0';
15354: my $trailstr;
15355: if ($name eq 'instcode') {
15356: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15357: } elsif ($name eq 'communities') {
15358: $trailstr = &mt('Communities');
1.1239 raeburn 15359: } elsif ($name eq 'placement') {
15360: $trailstr = &mt('Placement Tests');
1.655 raeburn 15361: } else {
15362: $trailstr = $name;
15363: }
15364: if ($allitems->{$item} eq '') {
15365: push(@{$trails},$trailstr);
15366: $allitems->{$item} = scalar(@{$trails})-1;
15367: }
15368: my @parents = ($name);
15369: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15370: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15371: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15372: if (ref($subcats) eq 'HASH') {
15373: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15374: }
1.1321 raeburn 15375: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15376: }
15377: } else {
15378: if (ref($subcats) eq 'HASH') {
15379: $subcats->{$item} = [];
1.655 raeburn 15380: }
1.1321 raeburn 15381: if (ref($maxd) eq 'HASH') {
15382: $maxd->{$name} = 1;
15383: }
1.655 raeburn 15384: }
15385: }
15386: }
15387: }
15388: return;
15389: }
15390:
15391: =pod
15392:
1.1162 raeburn 15393: =item * &recurse_categories()
1.655 raeburn 15394:
15395: Recursively used to generate breadcrumb trails for course categories.
15396:
15397: Inputs:
1.663 raeburn 15398:
1.655 raeburn 15399: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15400: categories and subcategories).
1.663 raeburn 15401:
1.655 raeburn 15402: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15403:
15404: category (current course category, for which breadcrumb trail is being generated).
15405:
15406: trails (reference to array of breadcrumb trails for each category).
15407:
1.655 raeburn 15408: allitems (reference to hash - key is category key
15409: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15410:
1.655 raeburn 15411: parents (array containing containers directories for current category,
15412: back to top level).
15413:
15414: Returns: nothing
15415:
15416: Side effects: populates trails and allitems hash references
15417:
15418: =cut
15419:
15420: sub recurse_categories {
1.1321 raeburn 15421: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15422: my $shallower = $depth - 1;
15423: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15424: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15425: my $name = $cats->[$depth]{$category}[$k];
15426: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15427: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15428: if ($allitems->{$item} eq '') {
15429: push(@{$trails},$trailstr);
15430: $allitems->{$item} = scalar(@{$trails})-1;
15431: }
15432: my $deeper = $depth+1;
15433: push(@{$parents},$category);
1.665 raeburn 15434: if (ref($subcats) eq 'HASH') {
15435: my $subcat = &escape($name).':'.$category.':'.$depth;
15436: for (my $j=@{$parents}; $j>=0; $j--) {
15437: my $higher;
15438: if ($j > 0) {
15439: $higher = &escape($parents->[$j]).':'.
15440: &escape($parents->[$j-1]).':'.$j;
15441: } else {
15442: $higher = &escape($parents->[$j]).'::'.$j;
15443: }
15444: push(@{$subcats->{$higher}},$subcat);
15445: }
15446: }
15447: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15448: $subcats,$maxd);
1.655 raeburn 15449: pop(@{$parents});
15450: }
15451: } else {
15452: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15453: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15454: if ($allitems->{$item} eq '') {
15455: push(@{$trails},$trailstr);
15456: $allitems->{$item} = scalar(@{$trails})-1;
15457: }
1.1321 raeburn 15458: if (ref($maxd) eq 'HASH') {
15459: if ($depth > $maxd->{$parents->[0]}) {
15460: $maxd->{$parents->[0]} = $depth;
15461: }
15462: }
1.655 raeburn 15463: }
15464: return;
15465: }
15466:
1.663 raeburn 15467: =pod
15468:
1.1162 raeburn 15469: =item * &assign_categories_table()
1.663 raeburn 15470:
15471: Create a datatable for display of hierarchical categories in a domain,
15472: with checkboxes to allow a course to be categorized.
15473:
15474: Inputs:
15475:
15476: cathash - reference to hash of categories defined for the domain (from
15477: configuration.db)
15478:
15479: currcat - scalar with an & separated list of categories assigned to a course.
15480:
1.919 raeburn 15481: type - scalar contains course type (Course or Community).
15482:
1.1260 raeburn 15483: disabled - scalar (optional) contains disabled="disabled" if input elements are
15484: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15485:
1.663 raeburn 15486: Returns: $output (markup to be displayed)
15487:
15488: =cut
15489:
15490: sub assign_categories_table {
1.1259 raeburn 15491: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15492: my $output;
15493: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15494: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15495: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15496: $maxdepth = scalar(@cats);
15497: if (@cats > 0) {
15498: my $itemcount = 0;
15499: if (ref($cats[0]) eq 'ARRAY') {
15500: my @currcategories;
15501: if ($currcat ne '') {
15502: @currcategories = split('&',$currcat);
15503: }
1.919 raeburn 15504: my $table;
1.663 raeburn 15505: for (my $i=0; $i<@{$cats[0]}; $i++) {
15506: my $parent = $cats[0][$i];
1.919 raeburn 15507: next if ($parent eq 'instcode');
15508: if ($type eq 'Community') {
15509: next unless ($parent eq 'communities');
1.1239 raeburn 15510: } elsif ($type eq 'Placement') {
15511: next unless ($parent eq 'placement');
1.919 raeburn 15512: } else {
1.1239 raeburn 15513: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15514: }
1.663 raeburn 15515: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15516: my $item = &escape($parent).'::0';
15517: my $checked = '';
15518: if (@currcategories > 0) {
15519: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15520: $checked = ' checked="checked"';
1.663 raeburn 15521: }
15522: }
1.919 raeburn 15523: my $parent_title = $parent;
15524: if ($parent eq 'communities') {
15525: $parent_title = &mt('Communities');
1.1239 raeburn 15526: } elsif ($parent eq 'placement') {
15527: $parent_title = &mt('Placement Tests');
1.919 raeburn 15528: }
15529: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15530: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15531: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15532: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15533: my $depth = 1;
15534: push(@path,$parent);
1.1259 raeburn 15535: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15536: pop(@path);
1.919 raeburn 15537: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15538: $itemcount ++;
15539: }
1.919 raeburn 15540: if ($itemcount) {
15541: $output = &Apache::loncommon::start_data_table().
15542: $table.
15543: &Apache::loncommon::end_data_table();
15544: }
1.663 raeburn 15545: }
15546: }
15547: }
15548: return $output;
15549: }
15550:
15551: =pod
15552:
1.1162 raeburn 15553: =item * &assign_category_rows()
1.663 raeburn 15554:
15555: Create a datatable row for display of nested categories in a domain,
15556: with checkboxes to allow a course to be categorized,called recursively.
15557:
15558: Inputs:
15559:
15560: itemcount - track row number for alternating colors
15561:
15562: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15563: categories and subcategories.
15564:
15565: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15566:
15567: parent - parent of current category item
15568:
15569: path - Array containing all categories back up through the hierarchy from the
15570: current category to the top level.
15571:
15572: currcategories - reference to array of current categories assigned to the course
15573:
1.1260 raeburn 15574: disabled - scalar (optional) contains disabled="disabled" if input elements are
15575: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15576:
1.663 raeburn 15577: Returns: $output (markup to be displayed).
15578:
15579: =cut
15580:
15581: sub assign_category_rows {
1.1259 raeburn 15582: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15583: my ($text,$name,$item,$chgstr);
15584: if (ref($cats) eq 'ARRAY') {
15585: my $maxdepth = scalar(@{$cats});
15586: if (ref($cats->[$depth]) eq 'HASH') {
15587: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15588: my $numchildren = @{$cats->[$depth]{$parent}};
15589: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15590: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15591: for (my $j=0; $j<$numchildren; $j++) {
15592: $name = $cats->[$depth]{$parent}[$j];
15593: $item = &escape($name).':'.&escape($parent).':'.$depth;
15594: my $deeper = $depth+1;
15595: my $checked = '';
15596: if (ref($currcategories) eq 'ARRAY') {
15597: if (@{$currcategories} > 0) {
15598: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15599: $checked = ' checked="checked"';
1.663 raeburn 15600: }
15601: }
15602: }
1.664 raeburn 15603: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15604: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15605: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15606: '<input type="hidden" name="catname" value="'.$name.'" />'.
15607: '</td><td>';
1.663 raeburn 15608: if (ref($path) eq 'ARRAY') {
15609: push(@{$path},$name);
1.1259 raeburn 15610: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15611: pop(@{$path});
15612: }
15613: $text .= '</td></tr>';
15614: }
15615: $text .= '</table></td>';
15616: }
15617: }
15618: }
15619: return $text;
15620: }
15621:
1.1181 raeburn 15622: =pod
15623:
15624: =back
15625:
15626: =cut
15627:
1.655 raeburn 15628: ############################################################
15629: ############################################################
15630:
15631:
1.443 albertel 15632: sub commit_customrole {
1.664 raeburn 15633: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15634: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15635: ($start?', '.&mt('starting').' '.localtime($start):'').
15636: ($end?', ending '.localtime($end):'').': <b>'.
15637: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15638: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15639: '</b><br />';
15640: return $output;
15641: }
15642:
15643: sub commit_standardrole {
1.1116 raeburn 15644: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15645: my ($output,$logmsg,$linefeed);
15646: if ($context eq 'auto') {
15647: $linefeed = "\n";
15648: } else {
15649: $linefeed = "<br />\n";
15650: }
1.443 albertel 15651: if ($three eq 'st') {
1.541 raeburn 15652: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15653: $one,$two,$sec,$context,$credits);
1.541 raeburn 15654: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15655: ($result eq 'unknown_course') || ($result eq 'refused')) {
15656: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15657: } else {
1.541 raeburn 15658: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15659: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15660: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15661: if ($context eq 'auto') {
15662: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15663: } else {
15664: $output .= '<b>'.$result.'</b>'.$linefeed.
15665: &mt('Add to classlist').': <b>ok</b>';
15666: }
15667: $output .= $linefeed;
1.443 albertel 15668: }
15669: } else {
15670: $output = &mt('Assigning').' '.$three.' in '.$url.
15671: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15672: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15673: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15674: if ($context eq 'auto') {
15675: $output .= $result.$linefeed;
15676: } else {
15677: $output .= '<b>'.$result.'</b>'.$linefeed;
15678: }
1.443 albertel 15679: }
15680: return $output;
15681: }
15682:
15683: sub commit_studentrole {
1.1116 raeburn 15684: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15685: $credits) = @_;
1.626 raeburn 15686: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15687: if ($context eq 'auto') {
15688: $linefeed = "\n";
15689: } else {
15690: $linefeed = '<br />'."\n";
15691: }
1.443 albertel 15692: if (defined($one) && defined($two)) {
15693: my $cid=$one.'_'.$two;
15694: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15695: my $secchange = 0;
15696: my $expire_role_result;
15697: my $modify_section_result;
1.628 raeburn 15698: if ($oldsec ne '-1') {
15699: if ($oldsec ne $sec) {
1.443 albertel 15700: $secchange = 1;
1.628 raeburn 15701: my $now = time;
1.443 albertel 15702: my $uurl='/'.$cid;
15703: $uurl=~s/\_/\//g;
15704: if ($oldsec) {
15705: $uurl.='/'.$oldsec;
15706: }
1.626 raeburn 15707: $oldsecurl = $uurl;
1.628 raeburn 15708: $expire_role_result =
1.652 raeburn 15709: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15710: if ($env{'request.course.sec'} ne '') {
15711: if ($expire_role_result eq 'refused') {
15712: my @roles = ('st');
15713: my @statuses = ('previous');
15714: my @roledoms = ($one);
15715: my $withsec = 1;
15716: my %roleshash =
15717: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15718: \@statuses,\@roles,\@roledoms,$withsec);
15719: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15720: my ($oldstart,$oldend) =
15721: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15722: if ($oldend > 0 && $oldend <= $now) {
15723: $expire_role_result = 'ok';
15724: }
15725: }
15726: }
15727: }
1.443 albertel 15728: $result = $expire_role_result;
15729: }
15730: }
15731: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15732: $modify_section_result =
15733: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15734: undef,undef,undef,$sec,
15735: $end,$start,'','',$cid,
15736: '',$context,$credits);
1.443 albertel 15737: if ($modify_section_result =~ /^ok/) {
15738: if ($secchange == 1) {
1.628 raeburn 15739: if ($sec eq '') {
15740: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15741: } else {
15742: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15743: }
1.443 albertel 15744: } elsif ($oldsec eq '-1') {
1.628 raeburn 15745: if ($sec eq '') {
15746: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15747: } else {
15748: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15749: }
1.443 albertel 15750: } else {
1.628 raeburn 15751: if ($sec eq '') {
15752: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15753: } else {
15754: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15755: }
1.443 albertel 15756: }
15757: } else {
1.1115 raeburn 15758: if ($secchange) {
1.628 raeburn 15759: $$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;
15760: } else {
15761: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15762: }
1.443 albertel 15763: }
15764: $result = $modify_section_result;
15765: } elsif ($secchange == 1) {
1.628 raeburn 15766: if ($oldsec eq '') {
1.1103 raeburn 15767: $$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 15768: } else {
15769: $$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;
15770: }
1.626 raeburn 15771: if ($expire_role_result eq 'refused') {
15772: my $newsecurl = '/'.$cid;
15773: $newsecurl =~ s/\_/\//g;
15774: if ($sec ne '') {
15775: $newsecurl.='/'.$sec;
15776: }
15777: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15778: if ($sec eq '') {
15779: $$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;
15780: } else {
15781: $$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;
15782: }
15783: }
15784: }
1.443 albertel 15785: }
15786: } else {
1.626 raeburn 15787: $$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 15788: $result = "error: incomplete course id\n";
15789: }
15790: return $result;
15791: }
15792:
1.1108 raeburn 15793: sub show_role_extent {
15794: my ($scope,$context,$role) = @_;
15795: $scope =~ s{^/}{};
15796: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15797: push(@courseroles,'co');
15798: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15799: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15800: $scope =~ s{/}{_};
15801: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15802: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15803: my ($audom,$auname) = split(/\//,$scope);
15804: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15805: &Apache::loncommon::plainname($auname,$audom).'</span>');
15806: } else {
15807: $scope =~ s{/$}{};
15808: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15809: &Apache::lonnet::domain($scope,'description').'</span>');
15810: }
15811: }
15812:
1.443 albertel 15813: ############################################################
15814: ############################################################
15815:
1.566 albertel 15816: sub check_clone {
1.578 raeburn 15817: my ($args,$linefeed) = @_;
1.566 albertel 15818: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15819: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15820: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15821: my $clonemsg;
15822: my $can_clone = 0;
1.944 raeburn 15823: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15824: if ($lctype ne 'community') {
15825: $lctype = 'course';
15826: }
1.566 albertel 15827: if ($clonehome eq 'no_host') {
1.944 raeburn 15828: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15829: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15830: } else {
15831: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15832: }
1.566 albertel 15833: } else {
15834: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15835: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15836: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15837: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
1.908 raeburn 15838: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15839: }
15840: }
1.1262 raeburn 15841: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15842: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15843: $can_clone = 1;
15844: } else {
1.1221 raeburn 15845: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15846: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15847: if ($clonehash{'cloners'} eq '') {
15848: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15849: if ($domdefs{'canclone'}) {
15850: unless ($domdefs{'canclone'} eq 'none') {
15851: if ($domdefs{'canclone'} eq 'domain') {
15852: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15853: $can_clone = 1;
15854: }
15855: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15856: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15857: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15858: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15859: $can_clone = 1;
15860: }
15861: }
15862: }
15863: }
1.578 raeburn 15864: } else {
1.1221 raeburn 15865: my @cloners = split(/,/,$clonehash{'cloners'});
15866: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15867: $can_clone = 1;
1.1221 raeburn 15868: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15869: $can_clone = 1;
1.1225 raeburn 15870: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15871: $can_clone = 1;
1.1221 raeburn 15872: }
15873: unless ($can_clone) {
1.1225 raeburn 15874: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15875: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15876: my (%gotdomdefaults,%gotcodedefaults);
15877: foreach my $cloner (@cloners) {
15878: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15879: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15880: my (%codedefaults,@code_order);
15881: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15882: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15883: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15884: }
15885: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15886: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15887: }
15888: } else {
15889: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15890: \%codedefaults,
15891: \@code_order);
15892: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15893: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15894: }
15895: if (@code_order > 0) {
15896: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15897: $cloner,$clonehash{'internal.coursecode'},
15898: $args->{'crscode'})) {
15899: $can_clone = 1;
15900: last;
15901: }
15902: }
15903: }
15904: }
15905: }
1.1225 raeburn 15906: }
15907: }
15908: unless ($can_clone) {
15909: my $ccrole = 'cc';
15910: if ($args->{'crstype'} eq 'Community') {
15911: $ccrole = 'co';
15912: }
15913: my %roleshash =
15914: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15915: $args->{'ccdomain'},
15916: 'userroles',['active'],[$ccrole],
15917: [$args->{'clonedomain'}]);
15918: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15919: $can_clone = 1;
15920: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15921: $args->{'ccuname'},$args->{'ccdomain'})) {
15922: $can_clone = 1;
1.1221 raeburn 15923: }
15924: }
15925: unless ($can_clone) {
15926: if ($args->{'crstype'} eq 'Community') {
15927: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.942 raeburn 15928: } else {
1.1221 raeburn 15929: $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
15930: }
1.566 albertel 15931: }
1.578 raeburn 15932: }
1.566 albertel 15933: }
15934: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15935: }
15936:
1.444 albertel 15937: sub construct_course {
1.1262 raeburn 15938: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15939: $cnum,$category,$coderef) = @_;
1.444 albertel 15940: my $outcome;
1.541 raeburn 15941: my $linefeed = '<br />'."\n";
15942: if ($context eq 'auto') {
15943: $linefeed = "\n";
15944: }
1.566 albertel 15945:
15946: #
15947: # Are we cloning?
15948: #
15949: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15950: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15951: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15952: if ($context ne 'auto') {
1.578 raeburn 15953: if ($clonemsg ne '') {
15954: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15955: }
1.566 albertel 15956: }
15957: $outcome .= $clonemsg.$linefeed;
15958:
15959: if (!$can_clone) {
15960: return (0,$outcome);
15961: }
15962: }
15963:
1.444 albertel 15964: #
15965: # Open course
15966: #
1.1239 raeburn 15967: my $showncrstype;
15968: if ($args->{'crstype'} eq 'Placement') {
15969: $showncrstype = 'placement test';
15970: } else {
15971: $showncrstype = lc($args->{'crstype'});
15972: }
1.444 albertel 15973: my %cenv=();
15974: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15975: $args->{'cdescr'},
15976: $args->{'curl'},
15977: $args->{'course_home'},
15978: $args->{'nonstandard'},
15979: $args->{'crscode'},
15980: $args->{'ccuname'}.':'.
15981: $args->{'ccdomain'},
1.882 raeburn 15982: $args->{'crstype'},
1.885 raeburn 15983: $cnum,$context,$category);
1.444 albertel 15984:
15985: # Note: The testing routines depend on this being output; see
15986: # Utils::Course. This needs to at least be output as a comment
15987: # if anyone ever decides to not show this, and Utils::Course::new
15988: # will need to be suitably modified.
1.1239 raeburn 15989: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15990: if ($$courseid =~ /^error:/) {
15991: return (0,$outcome);
15992: }
15993:
1.444 albertel 15994: #
15995: # Check if created correctly
15996: #
1.479 albertel 15997: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15998: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15999: if ($crsuhome eq 'no_host') {
16000: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
16001: return (0,$outcome);
16002: }
1.541 raeburn 16003: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16004:
1.444 albertel 16005: #
1.566 albertel 16006: # Do the cloning
16007: #
16008: if ($can_clone && $cloneid) {
1.1239 raeburn 16009: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 16010: if ($context ne 'auto') {
16011: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
16012: }
16013: $outcome .= $clonemsg.$linefeed;
16014: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16015: # Copy all files
1.637 www 16016: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 16017: # Restore URL
1.566 albertel 16018: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16019: # Restore title
1.566 albertel 16020: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16021: # Restore creation date, creator and creation context.
16022: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16023: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16024: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16025: # Mark as cloned
1.566 albertel 16026: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16027: # Need to clone grading mode
16028: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16029: $cenv{'grading'}=$newenv{'grading'};
16030: # Do not clone these environment entries
16031: &Apache::lonnet::del('environment',
16032: ['default_enrollment_start_date',
16033: 'default_enrollment_end_date',
16034: 'question.email',
16035: 'policy.email',
16036: 'comment.email',
16037: 'pch.users.denied',
1.725 raeburn 16038: 'plc.users.denied',
16039: 'hidefromcat',
1.1121 raeburn 16040: 'checkforpriv',
1.1166 raeburn 16041: 'categories',
16042: 'internal.uniquecode'],
1.638 www 16043: $$crsudom,$$crsunum);
1.1170 raeburn 16044: if ($args->{'textbook'}) {
16045: $cenv{'internal.textbook'} = $args->{'textbook'};
16046: }
1.444 albertel 16047: }
1.566 albertel 16048:
1.444 albertel 16049: #
16050: # Set environment (will override cloned, if existing)
16051: #
16052: my @sections = ();
16053: my @xlists = ();
16054: if ($args->{'crstype'}) {
16055: $cenv{'type'}=$args->{'crstype'};
16056: }
16057: if ($args->{'crsid'}) {
16058: $cenv{'courseid'}=$args->{'crsid'};
16059: }
16060: if ($args->{'crscode'}) {
16061: $cenv{'internal.coursecode'}=$args->{'crscode'};
16062: }
16063: if ($args->{'crsquota'} ne '') {
16064: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16065: } else {
16066: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16067: }
16068: if ($args->{'ccuname'}) {
16069: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16070: ':'.$args->{'ccdomain'};
16071: } else {
16072: $cenv{'internal.courseowner'} = $args->{'curruser'};
16073: }
1.1116 raeburn 16074: if ($args->{'defaultcredits'}) {
16075: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16076: }
1.444 albertel 16077: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16078: if ($args->{'crssections'}) {
16079: $cenv{'internal.sectionnums'} = '';
16080: if ($args->{'crssections'} =~ m/,/) {
16081: @sections = split/,/,$args->{'crssections'};
16082: } else {
16083: $sections[0] = $args->{'crssections'};
16084: }
16085: if (@sections > 0) {
16086: foreach my $item (@sections) {
16087: my ($sec,$gp) = split/:/,$item;
16088: my $class = $args->{'crscode'}.$sec;
16089: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16090: $cenv{'internal.sectionnums'} .= $item.',';
16091: unless ($addcheck eq 'ok') {
1.1263 raeburn 16092: push(@badclasses,$class);
1.444 albertel 16093: }
16094: }
16095: $cenv{'internal.sectionnums'} =~ s/,$//;
16096: }
16097: }
16098: # do not hide course coordinator from staff listing,
16099: # even if privileged
16100: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16101: # add course coordinator's domain to domains to check for privileged users
16102: # if different to course domain
16103: if ($$crsudom ne $args->{'ccdomain'}) {
16104: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16105: }
1.444 albertel 16106: # add crosslistings
16107: if ($args->{'crsxlist'}) {
16108: $cenv{'internal.crosslistings'}='';
16109: if ($args->{'crsxlist'} =~ m/,/) {
16110: @xlists = split/,/,$args->{'crsxlist'};
16111: } else {
16112: $xlists[0] = $args->{'crsxlist'};
16113: }
16114: if (@xlists > 0) {
16115: foreach my $item (@xlists) {
16116: my ($xl,$gp) = split/:/,$item;
16117: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16118: $cenv{'internal.crosslistings'} .= $item.',';
16119: unless ($addcheck eq 'ok') {
1.1263 raeburn 16120: push(@badclasses,$xl);
1.444 albertel 16121: }
16122: }
16123: $cenv{'internal.crosslistings'} =~ s/,$//;
16124: }
16125: }
16126: if ($args->{'autoadds'}) {
16127: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16128: }
16129: if ($args->{'autodrops'}) {
16130: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16131: }
16132: # check for notification of enrollment changes
16133: my @notified = ();
16134: if ($args->{'notify_owner'}) {
16135: if ($args->{'ccuname'} ne '') {
16136: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16137: }
16138: }
16139: if ($args->{'notify_dc'}) {
16140: if ($uname ne '') {
1.630 raeburn 16141: push(@notified,$uname.':'.$udom);
1.444 albertel 16142: }
16143: }
16144: if (@notified > 0) {
16145: my $notifylist;
16146: if (@notified > 1) {
16147: $notifylist = join(',',@notified);
16148: } else {
16149: $notifylist = $notified[0];
16150: }
16151: $cenv{'internal.notifylist'} = $notifylist;
16152: }
16153: if (@badclasses > 0) {
16154: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16155: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16156: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16157: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16158: );
1.1264 raeburn 16159: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16160: &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 16161: if ($context eq 'auto') {
16162: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16163: } else {
1.566 albertel 16164: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16165: }
16166: foreach my $item (@badclasses) {
1.541 raeburn 16167: if ($context eq 'auto') {
1.1261 raeburn 16168: $outcome .= " - $item\n";
1.541 raeburn 16169: } else {
1.1261 raeburn 16170: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16171: }
1.1261 raeburn 16172: }
16173: if ($context eq 'auto') {
16174: $outcome .= $linefeed;
16175: } else {
16176: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16177: }
1.444 albertel 16178: }
16179: if ($args->{'no_end_date'}) {
16180: $args->{'endaccess'} = 0;
16181: }
16182: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16183: $cenv{'internal.autoend'}=$args->{'enrollend'};
16184: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16185: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16186: if ($args->{'showphotos'}) {
16187: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16188: }
16189: $cenv{'internal.authtype'} = $args->{'authtype'};
16190: $cenv{'internal.autharg'} = $args->{'autharg'};
16191: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16192: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16193: 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');
16194: if ($context eq 'auto') {
16195: $outcome .= $krb_msg;
16196: } else {
1.566 albertel 16197: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16198: }
16199: $outcome .= $linefeed;
1.444 albertel 16200: }
16201: }
16202: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16203: if ($args->{'setpolicy'}) {
16204: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16205: }
16206: if ($args->{'setcontent'}) {
16207: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16208: }
1.1251 raeburn 16209: if ($args->{'setcomment'}) {
16210: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16211: }
1.444 albertel 16212: }
16213: if ($args->{'reshome'}) {
16214: $cenv{'reshome'}=$args->{'reshome'}.'/';
16215: $cenv{'reshome'}=~s/\/+$/\//;
16216: }
16217: #
16218: # course has keyed access
16219: #
16220: if ($args->{'setkeys'}) {
16221: $cenv{'keyaccess'}='yes';
16222: }
16223: # if specified, key authority is not course, but user
16224: # only active if keyaccess is yes
16225: if ($args->{'keyauth'}) {
1.487 albertel 16226: my ($user,$domain) = split(':',$args->{'keyauth'});
16227: $user = &LONCAPA::clean_username($user);
16228: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16229: if ($user ne '' && $domain ne '') {
1.487 albertel 16230: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16231: }
16232: }
16233:
1.1166 raeburn 16234: #
1.1167 raeburn 16235: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16236: #
16237: if ($args->{'uniquecode'}) {
16238: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16239: if ($code) {
16240: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16241: my %crsinfo =
16242: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16243: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16244: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16245: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16246: }
1.1166 raeburn 16247: if (ref($coderef)) {
16248: $$coderef = $code;
16249: }
16250: }
16251: }
16252:
1.444 albertel 16253: if ($args->{'disresdis'}) {
16254: $cenv{'pch.roles.denied'}='st';
16255: }
16256: if ($args->{'disablechat'}) {
16257: $cenv{'plc.roles.denied'}='st';
16258: }
16259:
16260: # Record we've not yet viewed the Course Initialization Helper for this
16261: # course
16262: $cenv{'course.helper.not.run'} = 1;
16263: #
16264: # Use new Randomseed
16265: #
16266: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16267: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16268: #
16269: # The encryption code and receipt prefix for this course
16270: #
16271: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16272: $cenv{'internal.encpref'}=100+int(9*rand(99));
16273: #
16274: # By default, use standard grading
16275: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16276:
1.541 raeburn 16277: $outcome .= $linefeed.&mt('Setting environment').': '.
16278: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16279: #
16280: # Open all assignments
16281: #
16282: if ($args->{'openall'}) {
16283: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16284: my %storecontent = ($storeunder => time,
16285: $storeunder.'.type' => 'date_start');
16286:
16287: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16288: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16289: }
16290: #
16291: # Set first page
16292: #
16293: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16294: || ($cloneid)) {
1.445 albertel 16295: use LONCAPA::map;
1.444 albertel 16296: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16297:
16298: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16299: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16300:
1.444 albertel 16301: $outcome .= ($fatal?$errtext:'read ok').' - ';
16302: my $title; my $url;
16303: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16304: $title=&mt('Syllabus');
1.444 albertel 16305: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16306: } else {
1.963 raeburn 16307: $title=&mt('Table of Contents');
1.444 albertel 16308: $url='/adm/navmaps';
16309: }
1.445 albertel 16310:
16311: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16312: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16313:
16314: if ($errtext) { $fatal=2; }
1.541 raeburn 16315: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16316: }
1.566 albertel 16317:
1.1237 raeburn 16318: #
16319: # Set params for Placement Tests
16320: #
1.1239 raeburn 16321: if ($args->{'crstype'} eq 'Placement') {
16322: my %storecontent;
16323: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16324: my %defaults = (
16325: buttonshide => { value => 'yes',
16326: type => 'string_yesno',},
16327: type => { value => 'randomizetry',
16328: type => 'string_questiontype',},
16329: maxtries => { value => 1,
16330: type => 'int_pos',},
16331: problemstatus => { value => 'no',
16332: type => 'string_problemstatus',},
16333: );
16334: foreach my $key (keys(%defaults)) {
16335: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16336: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16337: }
1.1237 raeburn 16338: &Apache::lonnet::cput
16339: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16340: }
16341:
1.566 albertel 16342: return (1,$outcome);
1.444 albertel 16343: }
16344:
1.1166 raeburn 16345: sub make_unique_code {
16346: my ($cdom,$cnum) = @_;
16347: # get lock on uniquecodes db
16348: my $lockhash = {
16349: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16350: ':'.$env{'user.domain'},
16351: };
16352: my $tries = 0;
16353: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16354: my ($code,$error);
16355:
16356: while (($gotlock ne 'ok') && ($tries<3)) {
16357: $tries ++;
16358: sleep 1;
16359: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16360: }
16361: if ($gotlock eq 'ok') {
16362: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16363: my $gotcode;
16364: my $attempts = 0;
16365: while ((!$gotcode) && ($attempts < 100)) {
16366: $code = &generate_code();
16367: if (!exists($currcodes{$code})) {
16368: $gotcode = 1;
16369: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16370: $error = 'nostore';
16371: }
16372: }
16373: $attempts ++;
16374: }
16375: my @del_lock = ($cnum."\0".'uniquecodes');
16376: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16377: } else {
16378: $error = 'nolock';
16379: }
16380: return ($code,$error);
16381: }
16382:
16383: sub generate_code {
16384: my $code;
16385: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16386: for (my $i=0; $i<6; $i++) {
16387: my $lettnum = int (rand 2);
16388: my $item = '';
16389: if ($lettnum) {
16390: $item = $letts[int( rand(18) )];
16391: } else {
16392: $item = 1+int( rand(8) );
16393: }
16394: $code .= $item;
16395: }
16396: return $code;
16397: }
16398:
1.444 albertel 16399: ############################################################
16400: ############################################################
16401:
1.1237 raeburn 16402: # Community, Course and Placement Test
1.378 raeburn 16403: sub course_type {
16404: my ($cid) = @_;
16405: if (!defined($cid)) {
16406: $cid = $env{'request.course.id'};
16407: }
1.404 albertel 16408: if (defined($env{'course.'.$cid.'.type'})) {
16409: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16410: } else {
16411: return 'Course';
1.377 raeburn 16412: }
16413: }
1.156 albertel 16414:
1.406 raeburn 16415: sub group_term {
16416: my $crstype = &course_type();
16417: my %names = (
16418: 'Course' => 'group',
1.865 raeburn 16419: 'Community' => 'group',
1.1237 raeburn 16420: 'Placement' => 'group',
1.406 raeburn 16421: );
16422: return $names{$crstype};
16423: }
16424:
1.902 raeburn 16425: sub course_types {
1.1310 raeburn 16426: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16427: my %typename = (
16428: official => 'Official course',
16429: unofficial => 'Unofficial course',
16430: community => 'Community',
1.1165 raeburn 16431: textbook => 'Textbook course',
1.1237 raeburn 16432: placement => 'Placement test',
1.1310 raeburn 16433: lti => 'LTI provider',
1.902 raeburn 16434: );
16435: return (\@types,\%typename);
16436: }
16437:
1.156 albertel 16438: sub icon {
16439: my ($file)=@_;
1.505 albertel 16440: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16441: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16442: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16443: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16444: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16445: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16446: $curfext.".gif") {
16447: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16448: $curfext.".gif";
16449: }
16450: }
1.249 albertel 16451: return &lonhttpdurl($iconname);
1.154 albertel 16452: }
1.84 albertel 16453:
1.575 albertel 16454: sub lonhttpdurl {
1.692 www 16455: #
16456: # Had been used for "small fry" static images on separate port 8080.
16457: # Modify here if lightweight http functionality desired again.
16458: # Currently eliminated due to increasing firewall issues.
16459: #
1.575 albertel 16460: my ($url)=@_;
1.692 www 16461: return $url;
1.215 albertel 16462: }
16463:
1.213 albertel 16464: sub connection_aborted {
16465: my ($r)=@_;
16466: $r->print(" ");$r->rflush();
16467: my $c = $r->connection;
16468: return $c->aborted();
16469: }
16470:
1.221 foxr 16471: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16472: # strings as 'strings'.
16473: sub escape_single {
1.221 foxr 16474: my ($input) = @_;
1.223 albertel 16475: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16476: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16477: return $input;
16478: }
1.223 albertel 16479:
1.222 foxr 16480: # Same as escape_single, but escape's "'s This
16481: # can be used for "strings"
16482: sub escape_double {
16483: my ($input) = @_;
16484: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16485: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16486: return $input;
16487: }
1.223 albertel 16488:
1.222 foxr 16489: # Escapes the last element of a full URL.
16490: sub escape_url {
16491: my ($url) = @_;
1.238 raeburn 16492: my @urlslices = split(/\//, $url,-1);
1.369 www 16493: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16494: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16495: }
1.462 albertel 16496:
1.820 raeburn 16497: sub compare_arrays {
16498: my ($arrayref1,$arrayref2) = @_;
16499: my (@difference,%count);
16500: @difference = ();
16501: %count = ();
16502: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16503: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16504: foreach my $element (keys(%count)) {
16505: if ($count{$element} == 1) {
16506: push(@difference,$element);
16507: }
16508: }
16509: }
16510: return @difference;
16511: }
16512:
1.1322 raeburn 16513: sub lon_status_items {
16514: my %defaults = (
16515: E => 100,
16516: W => 4,
16517: N => 1,
1.1324 raeburn 16518: U => 5,
1.1322 raeburn 16519: threshold => 200,
16520: sysmail => 2500,
16521: );
16522: my %names = (
16523: E => 'Errors',
16524: W => 'Warnings',
16525: N => 'Notices',
1.1324 raeburn 16526: U => 'Unsent',
1.1322 raeburn 16527: );
16528: return (\%defaults,\%names);
16529: }
16530:
1.817 bisitz 16531: # -------------------------------------------------------- Initialize user login
1.462 albertel 16532: sub init_user_environment {
1.463 albertel 16533: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16534: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16535:
16536: my $public=($username eq 'public' && $domain eq 'public');
16537:
1.1062 raeburn 16538: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16539: my $now=time;
16540:
16541: if ($public) {
16542: my $max_public=100;
16543: my $oldest;
16544: my $oldest_time=0;
16545: for(my $next=1;$next<=$max_public;$next++) {
16546: if (-e $lonids."/publicuser_$next.id") {
16547: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16548: if ($mtime<$oldest_time || !$oldest_time) {
16549: $oldest_time=$mtime;
16550: $oldest=$next;
16551: }
16552: } else {
16553: $cookie="publicuser_$next";
16554: last;
16555: }
16556: }
16557: if (!$cookie) { $cookie="publicuser_$oldest"; }
16558: } else {
1.1275 raeburn 16559: # See if old ID present, if so, remove if this isn't a robot,
16560: # killing any existing non-robot sessions
1.463 albertel 16561: if (!$args->{'robot'}) {
16562: opendir(DIR,$lonids);
16563: while ($filename=readdir(DIR)) {
16564: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16565: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16566: &GDBM_READER(),0640)) {
1.1295 raeburn 16567: my $linkedfile;
1.1320 raeburn 16568: if (exists($oldenv{'user.linkedenv'})) {
16569: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16570: }
1.1320 raeburn 16571: untie(%oldenv);
16572: if (unlink("$lonids/$filename")) {
16573: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16574: if (-l "$lonids/$linkedfile.id") {
16575: unlink("$lonids/$linkedfile.id");
16576: }
1.1295 raeburn 16577: }
16578: }
16579: } else {
16580: unlink($lonids.'/'.$filename);
16581: }
1.463 albertel 16582: }
1.462 albertel 16583: }
1.463 albertel 16584: closedir(DIR);
1.1204 raeburn 16585: # If there is a undeleted lockfile for the user's paste buffer remove it.
16586: my $namespace = 'nohist_courseeditor';
16587: my $lockingkey = 'paste'."\0".'locked_num';
16588: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16589: $domain,$username);
16590: if (exists($lockhash{$lockingkey})) {
16591: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16592: unless ($delresult eq 'ok') {
16593: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16594: }
16595: }
1.462 albertel 16596: }
16597: # Give them a new cookie
1.463 albertel 16598: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16599: : $now.$$.int(rand(10000)));
1.463 albertel 16600: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16601:
16602: # Initialize roles
16603:
1.1062 raeburn 16604: ($userroles,$firstaccenv,$timerintenv) =
16605: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16606: }
16607: # ------------------------------------ Check browser type and MathML capability
16608:
1.1194 raeburn 16609: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16610: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16611:
16612: # ------------------------------------------------------------- Get environment
16613:
16614: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16615: my ($tmp) = keys(%userenv);
1.1275 raeburn 16616: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16617: undef(%userenv);
16618: }
16619: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16620: $form->{'interface'}=$userenv{'interface'};
16621: }
16622: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16623:
16624: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16625: foreach my $option ('interface','localpath','localres') {
16626: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16627: }
16628: # --------------------------------------------------------- Write first profile
16629:
16630: {
16631: my %initial_env =
16632: ("user.name" => $username,
16633: "user.domain" => $domain,
16634: "user.home" => $authhost,
16635: "browser.type" => $clientbrowser,
16636: "browser.version" => $clientversion,
16637: "browser.mathml" => $clientmathml,
16638: "browser.unicode" => $clientunicode,
16639: "browser.os" => $clientos,
1.1137 raeburn 16640: "browser.mobile" => $clientmobile,
1.1141 raeburn 16641: "browser.info" => $clientinfo,
1.1194 raeburn 16642: "browser.osversion" => $clientosversion,
1.462 albertel 16643: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16644: "request.course.fn" => '',
16645: "request.course.uri" => '',
16646: "request.course.sec" => '',
16647: "request.role" => 'cm',
16648: "request.role.adv" => $env{'user.adv'},
16649: "request.host" => $ENV{'REMOTE_ADDR'},);
16650:
16651: if ($form->{'localpath'}) {
16652: $initial_env{"browser.localpath"} = $form->{'localpath'};
16653: $initial_env{"browser.localres"} = $form->{'localres'};
16654: }
16655:
16656: if ($form->{'interface'}) {
16657: $form->{'interface'}=~s/\W//gs;
16658: $initial_env{"browser.interface"} = $form->{'interface'};
16659: $env{'browser.interface'}=$form->{'interface'};
16660: }
16661:
1.1157 raeburn 16662: if ($form->{'iptoken'}) {
16663: my $lonhost = $r->dir_config('lonHostID');
16664: $initial_env{"user.noloadbalance"} = $lonhost;
16665: $env{'user.noloadbalance'} = $lonhost;
16666: }
16667:
1.1268 raeburn 16668: if ($form->{'noloadbalance'}) {
16669: my @hosts = &Apache::lonnet::current_machine_ids();
16670: my $hosthere = $form->{'noloadbalance'};
16671: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16672: $initial_env{"user.noloadbalance"} = $hosthere;
16673: $env{'user.noloadbalance'} = $hosthere;
16674: }
16675: }
16676:
1.1016 raeburn 16677: unless ($domain eq 'public') {
1.1273 raeburn 16678: my %is_adv = ( is_adv => $env{'user.adv'} );
16679: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16680:
16681: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16682: $userenv{'availabletools.'.$tool} =
16683: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16684: undef,\%userenv,\%domdef,\%is_adv);
16685: }
1.980 raeburn 16686:
1.1311 raeburn 16687: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16688: $userenv{'canrequest.'.$crstype} =
16689: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16690: 'reload','requestcourses',
16691: \%userenv,\%domdef,\%is_adv);
16692: }
1.724 raeburn 16693:
1.1273 raeburn 16694: $userenv{'canrequest.author'} =
16695: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16696: 'reload','requestauthor',
1.980 raeburn 16697: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16698: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16699: $domain,$username);
16700: my $reqstatus = $reqauthor{'author_status'};
16701: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16702: if (ref($reqauthor{'author'}) eq 'HASH') {
16703: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16704: $reqauthor{'author'}{'timestamp'};
16705: }
1.1092 raeburn 16706: }
1.1287 raeburn 16707: my ($types,$typename) = &course_types();
16708: if (ref($types) eq 'ARRAY') {
16709: my @options = ('approval','validate','autolimit');
16710: my $optregex = join('|',@options);
16711: my (%willtrust,%trustchecked);
16712: foreach my $type (@{$types}) {
16713: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16714: if ($dom_str ne '') {
16715: my $updatedstr = '';
16716: my @possdomains = split(',',$dom_str);
16717: foreach my $entry (@possdomains) {
16718: my ($extdom,$extopt) = split(':',$entry);
16719: unless ($trustchecked{$extdom}) {
16720: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16721: $trustchecked{$extdom} = 1;
16722: }
16723: if ($willtrust{$extdom}) {
16724: $updatedstr .= $entry.',';
16725: }
16726: }
16727: $updatedstr =~ s/,$//;
16728: if ($updatedstr) {
16729: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16730: } else {
16731: delete($userenv{'reqcrsotherdom.'.$type});
16732: }
16733: }
16734: }
16735: }
1.1092 raeburn 16736: }
1.462 albertel 16737: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16738:
1.462 albertel 16739: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16740: &GDBM_WRCREAT(),0640)) {
16741: &_add_to_env(\%disk_env,\%initial_env);
16742: &_add_to_env(\%disk_env,\%userenv,'environment.');
16743: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16744: if (ref($firstaccenv) eq 'HASH') {
16745: &_add_to_env(\%disk_env,$firstaccenv);
16746: }
16747: if (ref($timerintenv) eq 'HASH') {
16748: &_add_to_env(\%disk_env,$timerintenv);
16749: }
1.463 albertel 16750: if (ref($args->{'extra_env'})) {
16751: &_add_to_env(\%disk_env,$args->{'extra_env'});
16752: }
1.462 albertel 16753: untie(%disk_env);
16754: } else {
1.705 tempelho 16755: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16756: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16757: return 'error: '.$!;
16758: }
16759: }
16760: $env{'request.role'}='cm';
16761: $env{'request.role.adv'}=$env{'user.adv'};
16762: $env{'browser.type'}=$clientbrowser;
16763:
16764: return $cookie;
16765:
16766: }
16767:
16768: sub _add_to_env {
16769: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16770: if (ref($env_data) eq 'HASH') {
16771: while (my ($key,$value) = each(%$env_data)) {
16772: $idf->{$prefix.$key} = $value;
16773: $env{$prefix.$key} = $value;
16774: }
1.462 albertel 16775: }
16776: }
16777:
1.685 tempelho 16778: # --- Get the symbolic name of a problem and the url
16779: sub get_symb {
16780: my ($request,$silent) = @_;
1.726 raeburn 16781: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16782: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16783: if ($symb eq '') {
16784: if (!$silent) {
1.1071 raeburn 16785: if (ref($request)) {
16786: $request->print("Unable to handle ambiguous references:$url:.");
16787: }
1.685 tempelho 16788: return ();
16789: }
16790: }
16791: &Apache::lonenc::check_decrypt(\$symb);
16792: return ($symb);
16793: }
16794:
16795: # --------------------------------------------------------------Get annotation
16796:
16797: sub get_annotation {
16798: my ($symb,$enc) = @_;
16799:
16800: my $key = $symb;
16801: if (!$enc) {
16802: $key =
16803: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16804: }
16805: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16806: return $annotation{$key};
16807: }
16808:
16809: sub clean_symb {
1.731 raeburn 16810: my ($symb,$delete_enc) = @_;
1.685 tempelho 16811:
16812: &Apache::lonenc::check_decrypt(\$symb);
16813: my $enc = $env{'request.enc'};
1.731 raeburn 16814: if ($delete_enc) {
1.730 raeburn 16815: delete($env{'request.enc'});
16816: }
1.685 tempelho 16817:
16818: return ($symb,$enc);
16819: }
1.462 albertel 16820:
1.1181 raeburn 16821: ############################################################
16822: ############################################################
16823:
16824: =pod
16825:
16826: =head1 Routines for building display used to search for courses
16827:
16828:
16829: =over 4
16830:
16831: =item * &build_filters()
16832:
16833: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16834: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16835: and quotacheck.pl
16836:
1.1181 raeburn 16837:
16838: Inputs:
16839:
16840: filterlist - anonymous array of fields to include as potential filters
16841:
16842: crstype - course type
16843:
16844: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16845: to pop-open a course selector (will contain "extra element").
16846:
16847: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16848:
16849: filter - anonymous hash of criteria and their values
16850:
16851: action - form action
16852:
16853: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16854:
1.1182 raeburn 16855: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16856:
16857: cloneruname - username of owner of new course who wants to clone
16858:
16859: clonerudom - domain of owner of new course who wants to clone
16860:
16861: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16862:
16863: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16864:
16865: codedom - domain
16866:
16867: formname - value of form element named "form".
16868:
16869: fixeddom - domain, if fixed.
16870:
16871: prevphase - value to assign to form element named "phase" when going back to the previous screen
16872:
16873: cnameelement - name of form element in form on opener page which will receive title of selected course
16874:
16875: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16876:
16877: cdomelement - name of form element in form on opener page which will receive domain of selected course
16878:
16879: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16880:
16881: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16882:
16883: clonewarning - warning message about missing information for intended course owner when DC creates a course
16884:
1.1182 raeburn 16885:
1.1181 raeburn 16886: Returns: $output - HTML for display of search criteria, and hidden form elements.
16887:
1.1182 raeburn 16888:
1.1181 raeburn 16889: Side Effects: None
16890:
16891: =cut
16892:
16893: # ---------------------------------------------- search for courses based on last activity etc.
16894:
16895: sub build_filters {
16896: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16897: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16898: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16899: $cnameelement,$cnumelement,$cdomelement,$setroles,
16900: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16901: my ($list,$jscript);
1.1181 raeburn 16902: my $onchange = 'javascript:updateFilters(this)';
16903: my ($domainselectform,$sincefilterform,$createdfilterform,
16904: $ownerdomselectform,$persondomselectform,$instcodeform,
16905: $typeselectform,$instcodetitle);
16906: if ($formname eq '') {
16907: $formname = $caller;
16908: }
16909: foreach my $item (@{$filterlist}) {
16910: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16911: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16912: if ($item eq 'domainfilter') {
16913: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16914: } elsif ($item eq 'coursefilter') {
16915: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16916: } elsif ($item eq 'ownerfilter') {
16917: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16918: } elsif ($item eq 'ownerdomfilter') {
16919: $filter->{'ownerdomfilter'} =
16920: &LONCAPA::clean_domain($filter->{$item});
16921: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16922: 'ownerdomfilter',1);
16923: } elsif ($item eq 'personfilter') {
16924: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16925: } elsif ($item eq 'persondomfilter') {
16926: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16927: 'persondomfilter',1);
16928: } else {
16929: $filter->{$item} =~ s/\W//g;
16930: }
16931: if (!$filter->{$item}) {
16932: $filter->{$item} = '';
16933: }
16934: }
16935: if ($item eq 'domainfilter') {
16936: my $allow_blank = 1;
16937: if ($formname eq 'portform') {
16938: $allow_blank=0;
16939: } elsif ($formname eq 'studentform') {
16940: $allow_blank=0;
16941: }
16942: if ($fixeddom) {
16943: $domainselectform = '<input type="hidden" name="domainfilter"'.
16944: ' value="'.$codedom.'" />'.
16945: &Apache::lonnet::domain($codedom,'description');
16946: } else {
16947: $domainselectform = &select_dom_form($filter->{$item},
16948: 'domainfilter',
16949: $allow_blank,'',$onchange);
16950: }
16951: } else {
16952: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16953: }
16954: }
16955:
16956: # last course activity filter and selection
16957: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16958:
16959: # course created filter and selection
16960: if (exists($filter->{'createdfilter'})) {
16961: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16962: }
16963:
1.1239 raeburn 16964: my $prefix = $crstype;
16965: if ($crstype eq 'Placement') {
16966: $prefix = 'Placement Test'
16967: }
1.1181 raeburn 16968: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16969: 'cac' => "$prefix Activity",
16970: 'ccr' => "$prefix Created",
16971: 'cde' => "$prefix Title",
16972: 'cdo' => "$prefix Domain",
1.1181 raeburn 16973: 'ins' => 'Institutional Code',
16974: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16975: 'cow' => "$prefix Owner/Co-owner",
16976: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16977: 'cog' => 'Type',
16978: );
16979:
16980: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16981: my $typeval = 'Course';
16982: if ($crstype eq 'Community') {
16983: $typeval = 'Community';
1.1239 raeburn 16984: } elsif ($crstype eq 'Placement') {
16985: $typeval = 'Placement';
1.1181 raeburn 16986: }
16987: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16988: } else {
16989: $typeselectform = '<select name="type" size="1"';
16990: if ($onchange) {
16991: $typeselectform .= ' onchange="'.$onchange.'"';
16992: }
16993: $typeselectform .= '>'."\n";
1.1237 raeburn 16994: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16995: my $shown;
16996: if ($posstype eq 'Placement') {
16997: $shown = &mt('Placement Test');
16998: } else {
16999: $shown = &mt($posstype);
17000: }
1.1181 raeburn 17001: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17002: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17003: }
17004: $typeselectform.="</select>";
17005: }
17006:
17007: my ($cloneableonlyform,$cloneabletitle);
17008: if (exists($filter->{'cloneableonly'})) {
17009: my $cloneableon = '';
17010: my $cloneableoff = ' checked="checked"';
17011: if ($filter->{'cloneableonly'}) {
17012: $cloneableon = $cloneableoff;
17013: $cloneableoff = '';
17014: }
17015: $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>';
17016: if ($formname eq 'ccrs') {
1.1187 bisitz 17017: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17018: } else {
17019: $cloneabletitle = &mt('Cloneable by you');
17020: }
17021: }
17022: my $officialjs;
17023: if ($crstype eq 'Course') {
17024: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17025: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17026: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17027: if ($codedom) {
1.1181 raeburn 17028: $officialjs = 1;
17029: ($instcodeform,$jscript,$$numtitlesref) =
17030: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17031: $officialjs,$codetitlesref);
17032: if ($jscript) {
1.1182 raeburn 17033: $jscript = '<script type="text/javascript">'."\n".
17034: '// <![CDATA['."\n".
17035: $jscript."\n".
17036: '// ]]>'."\n".
17037: '</script>'."\n";
1.1181 raeburn 17038: }
17039: }
17040: if ($instcodeform eq '') {
17041: $instcodeform =
17042: '<input type="text" name="instcodefilter" size="10" value="'.
17043: $list->{'instcodefilter'}.'" />';
17044: $instcodetitle = $lt{'ins'};
17045: } else {
17046: $instcodetitle = $lt{'inc'};
17047: }
17048: if ($fixeddom) {
17049: $instcodetitle .= '<br />('.$codedom.')';
17050: }
17051: }
17052: }
17053: my $output = qq|
17054: <form method="post" name="filterpicker" action="$action">
17055: <input type="hidden" name="form" value="$formname" />
17056: |;
17057: if ($formname eq 'modifycourse') {
17058: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17059: '<input type="hidden" name="prevphase" value="'.
17060: $prevphase.'" />'."\n";
1.1198 musolffc 17061: } elsif ($formname eq 'quotacheck') {
17062: $output .= qq|
17063: <input type="hidden" name="sortby" value="" />
17064: <input type="hidden" name="sortorder" value="" />
17065: |;
17066: } else {
1.1181 raeburn 17067: my $name_input;
17068: if ($cnameelement ne '') {
17069: $name_input = '<input type="hidden" name="cnameelement" value="'.
17070: $cnameelement.'" />';
17071: }
17072: $output .= qq|
1.1182 raeburn 17073: <input type="hidden" name="cnumelement" value="$cnumelement" />
17074: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17075: $name_input
17076: $roleelement
17077: $multelement
17078: $typeelement
17079: |;
17080: if ($formname eq 'portform') {
17081: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17082: }
17083: }
17084: if ($fixeddom) {
17085: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17086: }
17087: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17088: if ($sincefilterform) {
17089: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17090: .$sincefilterform
17091: .&Apache::lonhtmlcommon::row_closure();
17092: }
17093: if ($createdfilterform) {
17094: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17095: .$createdfilterform
17096: .&Apache::lonhtmlcommon::row_closure();
17097: }
17098: if ($domainselectform) {
17099: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17100: .$domainselectform
17101: .&Apache::lonhtmlcommon::row_closure();
17102: }
17103: if ($typeselectform) {
17104: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17105: $output .= $typeselectform;
17106: } else {
17107: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17108: .$typeselectform
17109: .&Apache::lonhtmlcommon::row_closure();
17110: }
17111: }
17112: if ($instcodeform) {
17113: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17114: .$instcodeform
17115: .&Apache::lonhtmlcommon::row_closure();
17116: }
17117: if (exists($filter->{'ownerfilter'})) {
17118: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17119: '<table><tr><td>'.&mt('Username').'<br />'.
17120: '<input type="text" name="ownerfilter" size="20" value="'.
17121: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17122: $ownerdomselectform.'</td></tr></table>'.
17123: &Apache::lonhtmlcommon::row_closure();
17124: }
17125: if (exists($filter->{'personfilter'})) {
17126: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17127: '<table><tr><td>'.&mt('Username').'<br />'.
17128: '<input type="text" name="personfilter" size="20" value="'.
17129: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17130: $persondomselectform.'</td></tr></table>'.
17131: &Apache::lonhtmlcommon::row_closure();
17132: }
17133: if (exists($filter->{'coursefilter'})) {
17134: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17135: .'<input type="text" name="coursefilter" size="25" value="'
17136: .$list->{'coursefilter'}.'" />'
17137: .&Apache::lonhtmlcommon::row_closure();
17138: }
17139: if ($cloneableonlyform) {
17140: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17141: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17142: }
17143: if (exists($filter->{'descriptfilter'})) {
17144: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17145: .'<input type="text" name="descriptfilter" size="40" value="'
17146: .$list->{'descriptfilter'}.'" />'
17147: .&Apache::lonhtmlcommon::row_closure(1);
17148: }
17149: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17150: '<input type="hidden" name="updater" value="" />'."\n".
17151: '<input type="submit" name="gosearch" value="'.
17152: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17153: return $jscript.$clonewarning.$output;
17154: }
17155:
17156: =pod
17157:
17158: =item * &timebased_select_form()
17159:
1.1182 raeburn 17160: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17161: filter e.g., Course Activity, Course Created, when searching for courses
17162: or communities
17163:
17164: Inputs:
17165:
17166: item - name of form element (sincefilter or createdfilter)
17167:
17168: filter - anonymous hash of criteria and their values
17169:
17170: Returns: HTML for a select box contained a blank, then six time selections,
17171: with value set in incoming form variables currently selected.
17172:
17173: Side Effects: None
17174:
17175: =cut
17176:
17177: sub timebased_select_form {
17178: my ($item,$filter) = @_;
17179: if (ref($filter) eq 'HASH') {
17180: $filter->{$item} =~ s/[^\d-]//g;
17181: if (!$filter->{$item}) { $filter->{$item}=-1; }
17182: return &select_form(
17183: $filter->{$item},
17184: $item,
17185: { '-1' => '',
17186: '86400' => &mt('today'),
17187: '604800' => &mt('last week'),
17188: '2592000' => &mt('last month'),
17189: '7776000' => &mt('last three months'),
17190: '15552000' => &mt('last six months'),
17191: '31104000' => &mt('last year'),
17192: 'select_form_order' =>
17193: ['-1','86400','604800','2592000','7776000',
17194: '15552000','31104000']});
17195: }
17196: }
17197:
17198: =pod
17199:
17200: =item * &js_changer()
17201:
17202: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17203: when course type or domain is changed, and also to hide 'Searching ...' on
17204: page load completion for page showing search result.
1.1181 raeburn 17205:
17206: Inputs: None
17207:
1.1183 raeburn 17208: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17209:
17210: Side Effects: None
17211:
17212: =cut
17213:
17214: sub js_changer {
17215: return <<ENDJS;
17216: <script type="text/javascript">
17217: // <![CDATA[
17218: function updateFilters(caller) {
17219: if (typeof(caller) != "undefined") {
17220: document.filterpicker.updater.value = caller.name;
17221: }
17222: document.filterpicker.submit();
17223: }
1.1183 raeburn 17224:
17225: function hideSearching() {
17226: if (document.getElementById('searching')) {
17227: document.getElementById('searching').style.display = 'none';
17228: }
17229: return;
17230: }
17231:
1.1181 raeburn 17232: // ]]>
17233: </script>
17234:
17235: ENDJS
17236: }
17237:
17238: =pod
17239:
1.1182 raeburn 17240: =item * &search_courses()
17241:
17242: Process selected filters form course search form and pass to lonnet::courseiddump
17243: to retrieve a hash for which keys are courseIDs which match the selected filters.
17244:
17245: Inputs:
17246:
17247: dom - domain being searched
17248:
17249: type - course type ('Course' or 'Community' or '.' if any).
17250:
17251: filter - anonymous hash of criteria and their values
17252:
17253: numtitles - for institutional codes - number of categories
17254:
17255: cloneruname - optional username of new course owner
17256:
17257: clonerudom - optional domain of new course owner
17258:
1.1221 raeburn 17259: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17260: (used when DC is using course creation form)
17261:
17262: codetitles - reference to array of titles of components in institutional codes (official courses).
17263:
1.1221 raeburn 17264: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17265: (and so can clone automatically)
17266:
17267: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17268:
17269: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17270: courses to clone
1.1182 raeburn 17271:
17272: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17273:
17274:
17275: Side Effects: None
17276:
17277: =cut
17278:
17279:
17280: sub search_courses {
1.1221 raeburn 17281: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17282: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17283: my (%courses,%showcourses,$cloner);
17284: if (($filter->{'ownerfilter'} ne '') ||
17285: ($filter->{'ownerdomfilter'} ne '')) {
17286: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17287: $filter->{'ownerdomfilter'};
17288: }
17289: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17290: if (!$filter->{$item}) {
17291: $filter->{$item}='.';
17292: }
17293: }
17294: my $now = time;
17295: my $timefilter =
17296: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17297: my ($createdbefore,$createdafter);
17298: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17299: $createdbefore = $now;
17300: $createdafter = $now-$filter->{'createdfilter'};
17301: }
17302: my ($instcodefilter,$regexpok);
17303: if ($numtitles) {
17304: if ($env{'form.official'} eq 'on') {
17305: $instcodefilter =
17306: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17307: $regexpok = 1;
17308: } elsif ($env{'form.official'} eq 'off') {
17309: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17310: unless ($instcodefilter eq '') {
17311: $regexpok = -1;
17312: }
17313: }
17314: } else {
17315: $instcodefilter = $filter->{'instcodefilter'};
17316: }
17317: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17318: if ($type eq '') { $type = '.'; }
17319:
17320: if (($clonerudom ne '') && ($cloneruname ne '')) {
17321: $cloner = $cloneruname.':'.$clonerudom;
17322: }
17323: %courses = &Apache::lonnet::courseiddump($dom,
17324: $filter->{'descriptfilter'},
17325: $timefilter,
17326: $instcodefilter,
17327: $filter->{'combownerfilter'},
17328: $filter->{'coursefilter'},
17329: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17330: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17331: $filter->{'cloneableonly'},
17332: $createdbefore,$createdafter,undef,
1.1221 raeburn 17333: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17334: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17335: my $ccrole;
17336: if ($type eq 'Community') {
17337: $ccrole = 'co';
17338: } else {
17339: $ccrole = 'cc';
17340: }
17341: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17342: $filter->{'persondomfilter'},
17343: 'userroles',undef,
17344: [$ccrole,'in','ad','ep','ta','cr'],
17345: $dom);
17346: foreach my $role (keys(%rolehash)) {
17347: my ($cnum,$cdom,$courserole) = split(':',$role);
17348: my $cid = $cdom.'_'.$cnum;
17349: if (exists($courses{$cid})) {
17350: if (ref($courses{$cid}) eq 'HASH') {
17351: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17352: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17353: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17354: }
17355: } else {
17356: $courses{$cid}{roles} = [$courserole];
17357: }
17358: $showcourses{$cid} = $courses{$cid};
17359: }
17360: }
17361: }
17362: %courses = %showcourses;
17363: }
17364: return %courses;
17365: }
17366:
17367: =pod
17368:
1.1181 raeburn 17369: =back
17370:
1.1207 raeburn 17371: =head1 Routines for version requirements for current course.
17372:
17373: =over 4
17374:
17375: =item * &check_release_required()
17376:
17377: Compares required LON-CAPA version with version on server, and
17378: if required version is newer looks for a server with the required version.
17379:
17380: Looks first at servers in user's owen domain; if none suitable, looks at
17381: servers in course's domain are permitted to host sessions for user's domain.
17382:
17383: Inputs:
17384:
17385: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17386:
17387: $courseid - Course ID of current course
17388:
17389: $rolecode - User's current role in course (for switchserver query string).
17390:
17391: $required - LON-CAPA version needed by course (format: Major.Minor).
17392:
17393:
17394: Returns:
17395:
17396: $switchserver - query string tp append to /adm/switchserver call (if
17397: current server's LON-CAPA version is too old.
17398:
17399: $warning - Message is displayed if no suitable server could be found.
17400:
17401: =cut
17402:
17403: sub check_release_required {
17404: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17405: my ($switchserver,$warning);
17406: if ($required ne '') {
17407: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17408: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17409: if ($reqdmajor ne '' && $reqdminor ne '') {
17410: my $otherserver;
17411: if (($major eq '' && $minor eq '') ||
17412: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17413: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17414: my $switchlcrev =
17415: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17416: $userdomserver);
17417: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17418: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17419: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17420: my $cdom = $env{'course.'.$courseid.'.domain'};
17421: if ($cdom ne $env{'user.domain'}) {
17422: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17423: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17424: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17425: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17426: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17427: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17428: my $canhost =
17429: &Apache::lonnet::can_host_session($env{'user.domain'},
17430: $coursedomserver,
17431: $remoterev,
17432: $udomdefaults{'remotesessions'},
17433: $defdomdefaults{'hostedsessions'});
17434:
17435: if ($canhost) {
17436: $otherserver = $coursedomserver;
17437: } else {
17438: $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.");
17439: }
17440: } else {
17441: $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).");
17442: }
17443: } else {
17444: $otherserver = $userdomserver;
17445: }
17446: }
17447: if ($otherserver ne '') {
17448: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17449: }
17450: }
17451: }
17452: return ($switchserver,$warning);
17453: }
17454:
17455: =pod
17456:
17457: =item * &check_release_result()
17458:
17459: Inputs:
17460:
17461: $switchwarning - Warning message if no suitable server found to host session.
17462:
17463: $switchserver - query string to append to /adm/switchserver containing lonHostID
17464: and current role.
17465:
17466: Returns: HTML to display with information about requirement to switch server.
17467: Either displaying warning with link to Roles/Courses screen or
17468: display link to switchserver.
17469:
1.1181 raeburn 17470: =cut
17471:
1.1207 raeburn 17472: sub check_release_result {
17473: my ($switchwarning,$switchserver) = @_;
17474: my $output = &start_page('Selected course unavailable on this server').
17475: '<p class="LC_warning">';
17476: if ($switchwarning) {
17477: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17478: if (&show_course()) {
17479: $output .= &mt('Display courses');
17480: } else {
17481: $output .= &mt('Display roles');
17482: }
17483: $output .= '</a>';
17484: } elsif ($switchserver) {
17485: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17486: '<br />'.
17487: '<a href="/adm/switchserver?'.$switchserver.'">'.
17488: &mt('Switch Server').
17489: '</a>';
17490: }
17491: $output .= '</p>'.&end_page();
17492: return $output;
17493: }
17494:
17495: =pod
17496:
17497: =item * &needs_coursereinit()
17498:
17499: Determine if course contents stored for user's session needs to be
17500: refreshed, because content has changed since "Big Hash" last tied.
17501:
17502: Check for change is made if time last checked is more than 10 minutes ago
17503: (by default).
17504:
17505: Inputs:
17506:
17507: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17508:
17509: $interval (optional) - Time which may elapse (in s) between last check for content
17510: change in current course. (default: 600 s).
17511:
17512: Returns: an array; first element is:
17513:
17514: =over 4
17515:
17516: 'switch' - if content updates mean user's session
17517: needs to be switched to a server running a newer LON-CAPA version
17518:
17519: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17520: on current server hosting user's session
17521:
17522: '' - if no action required.
17523:
17524: =back
17525:
17526: If first item element is 'switch':
17527:
17528: second item is $switchwarning - Warning message if no suitable server found to host session.
17529:
17530: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17531: and current role.
17532:
17533: otherwise: no other elements returned.
17534:
17535: =back
17536:
17537: =cut
17538:
17539: sub needs_coursereinit {
17540: my ($loncaparev,$interval) = @_;
17541: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17542: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17543: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17544: my $now = time;
17545: if ($interval eq '') {
17546: $interval = 600;
17547: }
17548: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17549: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17550: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17551: if ($blocked) {
17552: return ();
17553: }
1.1207 raeburn 17554: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17555: if ($lastchange > $env{'request.course.tied'}) {
17556: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17557: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17558: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17559: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17560: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17561: $curr_reqd_hash{'internal.releaserequired'}});
17562: my ($switchserver,$switchwarning) =
17563: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17564: $curr_reqd_hash{'internal.releaserequired'});
17565: if ($switchwarning ne '' || $switchserver ne '') {
17566: return ('switch',$switchwarning,$switchserver);
17567: }
17568: }
17569: }
17570: return ('update');
17571: }
17572: }
17573: return ();
17574: }
1.1181 raeburn 17575:
1.1083 raeburn 17576: sub update_content_constraints {
1.1326 raeburn 17577: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17578: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17579: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17580: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17581: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17582: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17583: if ($item eq 'resourcetag') {
17584: if ($name eq 'responsetype') {
17585: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17586: }
1.1307 raeburn 17587: } elsif ($item eq 'course') {
17588: if ($name eq 'courserestype') {
17589: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17590: }
1.1083 raeburn 17591: }
17592: }
17593: my $navmap = Apache::lonnavmaps::navmap->new();
17594: if (defined($navmap)) {
1.1307 raeburn 17595: my (%allresponses,%allcrsrestypes);
17596: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17597: if ($res->is_tool()) {
17598: if ($allcrsrestypes{'exttool'}) {
17599: $allcrsrestypes{'exttool'} ++;
17600: } else {
17601: $allcrsrestypes{'exttool'} = 1;
17602: }
17603: next;
17604: }
1.1083 raeburn 17605: my %responses = $res->responseTypes();
17606: foreach my $key (keys(%responses)) {
17607: next unless(exists($checkresponsetypes{$key}));
17608: $allresponses{$key} += $responses{$key};
17609: }
17610: }
17611: foreach my $key (keys(%allresponses)) {
17612: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17613: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17614: ($reqdmajor,$reqdminor) = ($major,$minor);
17615: }
17616: }
1.1307 raeburn 17617: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17618: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17619: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17620: ($reqdmajor,$reqdminor) = ($major,$minor);
17621: }
17622: }
1.1083 raeburn 17623: undef($navmap);
17624: }
1.1326 raeburn 17625: my (@resources,@order,@resparms,@zombies);
17626: if ($keeporder) {
17627: use LONCAPA::map;
17628: @resources = @LONCAPA::map::resources;
17629: @order = @LONCAPA::map::order;
17630: @resparms = @LONCAPA::map::resparms;
17631: @zombies = @LONCAPA::map::zombies;
17632: }
1.1308 raeburn 17633: my $suppmap = 'supplemental.sequence';
17634: my ($suppcount,$supptools,$errors) = (0,0,0);
17635: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17636: $suppcount,$supptools,$errors);
1.1326 raeburn 17637: if ($keeporder) {
17638: @LONCAPA::map::resources = @resources;
17639: @LONCAPA::map::order = @order;
17640: @LONCAPA::map::resparms = @resparms;
17641: @LONCAPA::map::zombies = @zombies;
17642: }
1.1308 raeburn 17643: if ($supptools) {
17644: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17645: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17646: ($reqdmajor,$reqdminor) = ($major,$minor);
17647: }
17648: }
1.1083 raeburn 17649: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17650: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17651: }
17652: return;
17653: }
17654:
1.1110 raeburn 17655: sub allmaps_incourse {
17656: my ($cdom,$cnum,$chome,$cid) = @_;
17657: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17658: $cid = $env{'request.course.id'};
17659: $cdom = $env{'course.'.$cid.'.domain'};
17660: $cnum = $env{'course.'.$cid.'.num'};
17661: $chome = $env{'course.'.$cid.'.home'};
17662: }
17663: my %allmaps = ();
17664: my $lastchange =
17665: &Apache::lonnet::get_coursechange($cdom,$cnum);
17666: if ($lastchange > $env{'request.course.tied'}) {
17667: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17668: unless ($ferr) {
1.1326 raeburn 17669: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17670: }
17671: }
17672: my $navmap = Apache::lonnavmaps::navmap->new();
17673: if (defined($navmap)) {
17674: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17675: $allmaps{$res->src()} = 1;
17676: }
17677: }
17678: return \%allmaps;
17679: }
17680:
1.1083 raeburn 17681: sub parse_supplemental_title {
17682: my ($title) = @_;
17683:
17684: my ($foldertitle,$renametitle);
17685: if ($title =~ /&&&/) {
17686: $title = &HTML::Entites::decode($title);
17687: }
17688: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17689: $renametitle=$4;
17690: my ($time,$uname,$udom) = ($1,$2,$3);
17691: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17692: my $name = &plainname($uname,$udom);
17693: $name = &HTML::Entities::encode($name,'"<>&\'');
17694: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17695: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17696: $name.': <br />'.$foldertitle;
17697: }
17698: if (wantarray) {
17699: return ($title,$foldertitle,$renametitle);
17700: }
17701: return $title;
17702: }
17703:
1.1143 raeburn 17704: sub recurse_supplemental {
1.1308 raeburn 17705: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17706: if ($suppmap) {
17707: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17708: if ($fatal) {
17709: $errors ++;
17710: } else {
17711: if ($#LONCAPA::map::resources > 0) {
17712: foreach my $res (@LONCAPA::map::resources) {
17713: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17714: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17715: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17716: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17717: $numfiles,$numexttools,$errors);
1.1143 raeburn 17718: } else {
1.1308 raeburn 17719: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17720: $numexttools ++;
17721: }
1.1143 raeburn 17722: $numfiles ++;
17723: }
17724: }
17725: }
17726: }
17727: }
17728: }
1.1308 raeburn 17729: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17730: }
17731:
1.1101 raeburn 17732: sub symb_to_docspath {
1.1267 raeburn 17733: my ($symb,$navmapref) = @_;
17734: return unless ($symb && ref($navmapref));
1.1101 raeburn 17735: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17736: if ($resurl=~/\.(sequence|page)$/) {
17737: $mapurl=$resurl;
17738: } elsif ($resurl eq 'adm/navmaps') {
17739: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17740: }
17741: my $mapresobj;
1.1267 raeburn 17742: unless (ref($$navmapref)) {
17743: $$navmapref = Apache::lonnavmaps::navmap->new();
17744: }
17745: if (ref($$navmapref)) {
17746: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17747: }
17748: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17749: my $type=$2;
17750: my $path;
17751: if (ref($mapresobj)) {
17752: my $pcslist = $mapresobj->map_hierarchy();
17753: if ($pcslist ne '') {
17754: foreach my $pc (split(/,/,$pcslist)) {
17755: next if ($pc <= 1);
1.1267 raeburn 17756: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17757: if (ref($res)) {
17758: my $thisurl = $res->src();
17759: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17760: my $thistitle = $res->title();
17761: $path .= '&'.
17762: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17763: &escape($thistitle).
1.1101 raeburn 17764: ':'.$res->randompick().
17765: ':'.$res->randomout().
17766: ':'.$res->encrypted().
17767: ':'.$res->randomorder().
17768: ':'.$res->is_page();
17769: }
17770: }
17771: }
17772: $path =~ s/^\&//;
17773: my $maptitle = $mapresobj->title();
17774: if ($mapurl eq 'default') {
1.1129 raeburn 17775: $maptitle = 'Main Content';
1.1101 raeburn 17776: }
17777: $path .= (($path ne '')? '&' : '').
17778: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17779: &escape($maptitle).
1.1101 raeburn 17780: ':'.$mapresobj->randompick().
17781: ':'.$mapresobj->randomout().
17782: ':'.$mapresobj->encrypted().
17783: ':'.$mapresobj->randomorder().
17784: ':'.$mapresobj->is_page();
17785: } else {
17786: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17787: my $ispage = (($type eq 'page')? 1 : '');
17788: if ($mapurl eq 'default') {
1.1129 raeburn 17789: $maptitle = 'Main Content';
1.1101 raeburn 17790: }
17791: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17792: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17793: }
17794: unless ($mapurl eq 'default') {
17795: $path = 'default&'.
1.1146 raeburn 17796: &escape('Main Content').
1.1101 raeburn 17797: ':::::&'.$path;
17798: }
17799: return $path;
17800: }
17801:
1.1094 raeburn 17802: sub captcha_display {
1.1327 raeburn 17803: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17804: my ($output,$error);
1.1234 raeburn 17805: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17806: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17807: if ($captcha eq 'original') {
1.1094 raeburn 17808: $output = &create_captcha();
17809: unless ($output) {
1.1172 raeburn 17810: $error = 'captcha';
1.1094 raeburn 17811: }
17812: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17813: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17814: unless ($output) {
1.1172 raeburn 17815: $error = 'recaptcha';
1.1094 raeburn 17816: }
17817: }
1.1234 raeburn 17818: return ($output,$error,$captcha,$version);
1.1094 raeburn 17819: }
17820:
17821: sub captcha_response {
1.1327 raeburn 17822: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17823: my ($captcha_chk,$captcha_error);
1.1327 raeburn 17824: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17825: if ($captcha eq 'original') {
1.1094 raeburn 17826: ($captcha_chk,$captcha_error) = &check_captcha();
17827: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17828: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17829: } else {
17830: $captcha_chk = 1;
17831: }
17832: return ($captcha_chk,$captcha_error);
17833: }
17834:
17835: sub get_captcha_config {
1.1327 raeburn 17836: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 17837: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17838: my $hostname = &Apache::lonnet::hostname($lonhost);
17839: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17840: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17841: if ($context eq 'usercreation') {
17842: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17843: if (ref($domconfig{$context}) eq 'HASH') {
17844: $hashtocheck = $domconfig{$context}{'cancreate'};
17845: if (ref($hashtocheck) eq 'HASH') {
17846: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17847: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17848: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17849: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17850: }
17851: if ($privkey && $pubkey) {
17852: $captcha = 'recaptcha';
1.1234 raeburn 17853: $version = $hashtocheck->{'recaptchaversion'};
17854: if ($version ne '2') {
17855: $version = 1;
17856: }
1.1095 raeburn 17857: } else {
17858: $captcha = 'original';
17859: }
17860: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17861: $captcha = 'original';
17862: }
1.1094 raeburn 17863: }
1.1095 raeburn 17864: } else {
17865: $captcha = 'captcha';
17866: }
17867: } elsif ($context eq 'login') {
17868: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17869: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17870: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17871: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17872: if ($privkey && $pubkey) {
17873: $captcha = 'recaptcha';
1.1234 raeburn 17874: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17875: if ($version ne '2') {
17876: $version = 1;
17877: }
1.1095 raeburn 17878: } else {
17879: $captcha = 'original';
1.1094 raeburn 17880: }
1.1095 raeburn 17881: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17882: $captcha = 'original';
1.1094 raeburn 17883: }
1.1327 raeburn 17884: } elsif ($context eq 'passwords') {
17885: if ($dom_in_effect) {
17886: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17887: if ($passwdconf{'captcha'} eq 'recaptcha') {
17888: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17889: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17890: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17891: }
17892: if ($privkey && $pubkey) {
17893: $captcha = 'recaptcha';
17894: $version = $passwdconf{'recaptchaversion'};
17895: if ($version ne '2') {
17896: $version = 1;
17897: }
17898: } else {
17899: $captcha = 'original';
17900: }
17901: } elsif ($passwdconf{'captcha'} ne 'notused') {
17902: $captcha = 'original';
17903: }
17904: }
17905: }
1.1234 raeburn 17906: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17907: }
17908:
17909: sub create_captcha {
17910: my %captcha_params = &captcha_settings();
17911: my ($output,$maxtries,$tries) = ('',10,0);
17912: while ($tries < $maxtries) {
17913: $tries ++;
17914: my $captcha = Authen::Captcha->new (
17915: output_folder => $captcha_params{'output_dir'},
17916: data_folder => $captcha_params{'db_dir'},
17917: );
17918: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17919:
17920: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17921: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17922: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17923: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17924: '<br />'.
17925: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17926: last;
17927: }
17928: }
1.1323 raeburn 17929: if ($output eq '') {
17930: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17931: }
1.1094 raeburn 17932: return $output;
17933: }
17934:
17935: sub captcha_settings {
17936: my %captcha_params = (
17937: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17938: www_output_dir => "/captchaspool",
17939: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17940: numchars => '5',
17941: );
17942: return %captcha_params;
17943: }
17944:
17945: sub check_captcha {
17946: my ($captcha_chk,$captcha_error);
17947: my $code = $env{'form.code'};
17948: my $md5sum = $env{'form.crypt'};
17949: my %captcha_params = &captcha_settings();
17950: my $captcha = Authen::Captcha->new(
17951: output_folder => $captcha_params{'output_dir'},
17952: data_folder => $captcha_params{'db_dir'},
17953: );
1.1109 raeburn 17954: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17955: my %captcha_hash = (
17956: 0 => 'Code not checked (file error)',
17957: -1 => 'Failed: code expired',
17958: -2 => 'Failed: invalid code (not in database)',
17959: -3 => 'Failed: invalid code (code does not match crypt)',
17960: );
17961: if ($captcha_chk != 1) {
17962: $captcha_error = $captcha_hash{$captcha_chk}
17963: }
17964: return ($captcha_chk,$captcha_error);
17965: }
17966:
17967: sub create_recaptcha {
1.1234 raeburn 17968: my ($pubkey,$version) = @_;
17969: if ($version >= 2) {
17970: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17971: } else {
17972: my $use_ssl;
17973: if ($ENV{'SERVER_PORT'} == 443) {
17974: $use_ssl = 1;
17975: }
17976: my $captcha = Captcha::reCAPTCHA->new;
17977: return $captcha->get_options_setter({theme => 'white'})."\n".
17978: $captcha->get_html($pubkey,undef,$use_ssl).
17979: &mt('If the text is hard to read, [_1] will replace them.',
17980: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17981: '<br /><br />';
17982: }
1.1094 raeburn 17983: }
17984:
17985: sub check_recaptcha {
1.1234 raeburn 17986: my ($privkey,$version) = @_;
1.1094 raeburn 17987: my $captcha_chk;
1.1234 raeburn 17988: if ($version >= 2) {
17989: my %info = (
17990: secret => $privkey,
17991: response => $env{'form.g-recaptcha-response'},
17992: remoteip => $ENV{'REMOTE_ADDR'},
17993: );
1.1280 raeburn 17994: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17995: $request->content(join('&',map {
17996: my $name = escape($_);
17997: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17998: ? join("&$name=", map {escape($_) } @{$info{$_}})
17999: : &escape($info{$_}) );
18000: } keys(%info)));
18001: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18002: if ($response->is_success) {
18003: my $data = JSON::DWIW->from_json($response->decoded_content);
18004: if (ref($data) eq 'HASH') {
18005: if ($data->{'success'}) {
18006: $captcha_chk = 1;
18007: }
18008: }
18009: }
18010: } else {
18011: my $captcha = Captcha::reCAPTCHA->new;
18012: my $captcha_result =
18013: $captcha->check_answer(
18014: $privkey,
18015: $ENV{'REMOTE_ADDR'},
18016: $env{'form.recaptcha_challenge_field'},
18017: $env{'form.recaptcha_response_field'},
18018: );
18019: if ($captcha_result->{is_valid}) {
18020: $captcha_chk = 1;
18021: }
1.1094 raeburn 18022: }
18023: return $captcha_chk;
18024: }
18025:
1.1174 raeburn 18026: sub emailusername_info {
1.1244 raeburn 18027: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18028: my %titles = &Apache::lonlocal::texthash (
18029: lastname => 'Last Name',
18030: firstname => 'First Name',
18031: institution => 'School/college/university',
18032: location => "School's city, state/province, country",
18033: web => "School's web address",
18034: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18035: id => 'Student/Employee ID',
1.1174 raeburn 18036: );
18037: return (\@fields,\%titles);
18038: }
18039:
1.1161 raeburn 18040: sub cleanup_html {
18041: my ($incoming) = @_;
18042: my $outgoing;
18043: if ($incoming ne '') {
18044: $outgoing = $incoming;
18045: $outgoing =~ s/;/;/g;
18046: $outgoing =~ s/\#/#/g;
18047: $outgoing =~ s/\&/&/g;
18048: $outgoing =~ s/</</g;
18049: $outgoing =~ s/>/>/g;
18050: $outgoing =~ s/\(/(/g;
18051: $outgoing =~ s/\)/)/g;
18052: $outgoing =~ s/"/"/g;
18053: $outgoing =~ s/'/'/g;
18054: $outgoing =~ s/\$/$/g;
18055: $outgoing =~ s{/}{/}g;
18056: $outgoing =~ s/=/=/g;
18057: $outgoing =~ s/\\/\/g
18058: }
18059: return $outgoing;
18060: }
18061:
1.1190 musolffc 18062: # Checks for critical messages and returns a redirect url if one exists.
18063: # $interval indicates how often to check for messages.
1.1282 raeburn 18064: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18065: sub critical_redirect {
1.1282 raeburn 18066: my ($interval,$context) = @_;
1.1190 musolffc 18067: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18068: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18069: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18070: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18071: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18072: if ($blocked) {
18073: my $checkrole = "cm./$cdom/$cnum";
18074: if ($env{'request.course.sec'} ne '') {
18075: $checkrole .= "/$env{'request.course.sec'}";
18076: }
18077: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18078: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18079: return;
18080: }
18081: }
18082: }
1.1190 musolffc 18083: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18084: $env{'user.name'});
18085: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18086: my $redirecturl;
1.1190 musolffc 18087: if ($what[0]) {
18088: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18089: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18090: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18091: return (1, $url);
1.1190 musolffc 18092: }
1.1191 raeburn 18093: }
18094: }
18095: return ();
1.1190 musolffc 18096: }
18097:
1.1174 raeburn 18098: # Use:
18099: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18100: #
18101: ##################################################
18102: # password associated functions #
18103: ##################################################
18104: sub des_keys {
18105: # Make a new key for DES encryption.
18106: # Each key has two parts which are returned separately.
18107: # Please note: Each key must be passed through the &hex function
18108: # before it is output to the web browser. The hex versions cannot
18109: # be used to decrypt.
18110: my @hexstr=('0','1','2','3','4','5','6','7',
18111: '8','9','a','b','c','d','e','f');
18112: my $lkey='';
18113: for (0..7) {
18114: $lkey.=$hexstr[rand(15)];
18115: }
18116: my $ukey='';
18117: for (0..7) {
18118: $ukey.=$hexstr[rand(15)];
18119: }
18120: return ($lkey,$ukey);
18121: }
18122:
18123: sub des_decrypt {
18124: my ($key,$cyphertext) = @_;
18125: my $keybin=pack("H16",$key);
18126: my $cypher;
18127: if ($Crypt::DES::VERSION>=2.03) {
18128: $cypher=new Crypt::DES $keybin;
18129: } else {
18130: $cypher=new DES $keybin;
18131: }
1.1233 raeburn 18132: my $plaintext='';
18133: my $cypherlength = length($cyphertext);
18134: my $numchunks = int($cypherlength/32);
18135: for (my $j=0; $j<$numchunks; $j++) {
18136: my $start = $j*32;
18137: my $cypherblock = substr($cyphertext,$start,32);
18138: my $chunk =
18139: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18140: $chunk .=
18141: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18142: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18143: $plaintext .= $chunk;
18144: }
1.1174 raeburn 18145: return $plaintext;
18146: }
18147:
1.1309 raeburn 18148: sub make_short_symbs {
18149: my ($cdom,$cnum,$navmap) = @_;
18150: return unless (ref($navmap));
18151: my ($numnew,@errors);
18152: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18153: if (@toshorten) {
18154: my (%maps,%resources,%titles);
18155: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18156: 'shorturls',$cdom,$cnum);
18157: my %tocreate;
18158: if (keys(%resources)) {
18159: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18160: my $symb = $resources{$item};
18161: if ($symb) {
18162: $tocreate{$cnum.'&'.$symb} = 1;
18163: }
18164: }
18165: }
18166: if (keys(%tocreate)) {
18167: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18168: my $su = Short::URL->new(no_vowels => 1);
18169: my $init = '';
18170: my (%newunique,%addcourse,%courseonly,%failed);
18171: # get lock on tiny db
18172: my $now = time;
18173: my $lockhash = {
18174: "lock\0$now" => $env{'user.name'}.
18175: ':'.$env{'user.domain'},
18176: };
18177: my $tries = 0;
18178: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18179: my ($code,$error);
18180: while (($gotlock ne 'ok') && ($tries<3)) {
18181: $tries ++;
18182: sleep 1;
1.1319 raeburn 18183: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18184: }
18185: if ($gotlock eq 'ok') {
18186: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18187: \%addcourse,\%courseonly,\%failed);
18188: if (keys(%failed)) {
18189: my $numfailed = scalar(keys(%failed));
18190: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18191: }
18192: if (keys(%newunique)) {
18193: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18194: if ($putres eq 'ok') {
18195: $numnew = scalar(keys(%newunique));
18196: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18197: unless ($newputres eq 'ok') {
18198: push(@errors,&mt('error: could not store course look-up of short URLs'));
18199: }
18200: } else {
18201: push(@errors,&mt('error: could not store unique six character URLs'));
18202: }
18203: }
18204: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18205: unless ($dellockres eq 'ok') {
18206: push(@errors,&mt('error: could not release lockfile'));
18207: }
18208: } else {
18209: push(@errors,&mt('error: could not obtain lockfile'));
18210: }
18211: if (keys(%courseonly)) {
18212: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18213: if ($result ne 'ok') {
18214: push(@errors,&mt('error: could not update course look-up of short URLs'));
18215: }
18216: }
18217: }
18218: }
18219: return ($numnew,\@errors);
18220: }
18221:
18222: sub shorten_symbs {
18223: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18224: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18225: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18226: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18227: my (%possibles,%collisions);
18228: foreach my $key (keys(%{$tocreate})) {
18229: my $num = String::CRC32::crc32($key);
18230: my $tiny = $su->encode($num,$init);
18231: if ($tiny) {
18232: $possibles{$tiny} = $key;
18233: }
18234: }
18235: if (!$init) {
18236: $init = 1;
18237: } else {
18238: $init ++;
18239: }
18240: if (keys(%possibles)) {
18241: my @posstiny = keys(%possibles);
18242: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18243: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18244: if (keys(%currtiny)) {
18245: foreach my $key (keys(%currtiny)) {
18246: next if ($currtiny{$key} eq '');
18247: if ($currtiny{$key} eq $possibles{$key}) {
18248: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18249: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18250: $courseonly->{$tsymb} = $key;
18251: }
18252: } else {
18253: $collisions{$possibles{$key}} = 1;
18254: }
18255: delete($possibles{$key});
18256: }
18257: }
18258: foreach my $key (keys(%possibles)) {
18259: $newunique->{$key} = $possibles{$key};
18260: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18261: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18262: $addcourse->{$tsymb} = $key;
18263: }
18264: }
18265: }
18266: if (keys(%collisions)) {
18267: if ($init <5) {
18268: if (!$init) {
18269: $init = 1;
18270: } else {
18271: $init ++;
18272: }
18273: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18274: $newunique,$addcourse,$courseonly,$failed);
18275: } else {
18276: foreach my $key (keys(%collisions)) {
18277: $failed->{$key} = 1;
18278: }
18279: }
18280: }
18281: return $init;
18282: }
18283:
1.1328 raeburn 18284: sub is_nonframeable {
1.1329 raeburn 18285: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18286: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18287: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18288:
18289: $remprotocol = lc($remprotocol);
18290: $remhost = lc($remhost);
18291: my $remport = 80;
18292: if ($remprotocol eq 'https') {
18293: $remport = 443;
18294: }
1.1330 raeburn 18295: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18296: if ($cached) {
18297: unless ($nocache) {
18298: if ($result) {
18299: return 1;
18300: } else {
18301: return 0;
18302: }
18303: }
18304: }
1.1328 raeburn 18305: my $uselink;
18306: my $request = new HTTP::Request('HEAD',$url);
18307: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18308: if ($response->is_success()) {
18309: my $secpolicy = lc($response->header('content-security-policy'));
18310: my $xframeop = lc($response->header('x-frame-options'));
18311: $secpolicy =~ s/^\s+|\s+$//g;
18312: $xframeop =~ s/^\s+|\s+$//g;
18313: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18314: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18315: my ($origin,$protocol,$port);
18316: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18317: $port = $ENV{'SERVER_PORT'};
18318: } else {
18319: $port = 80;
18320: }
18321: if ($absolute eq '') {
18322: $protocol = 'http:';
18323: if ($port == 443) {
18324: $protocol = 'https:';
18325: }
18326: $origin = $protocol.'//'.lc($hostname);
18327: } else {
18328: $origin = lc($absolute);
18329: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18330: }
18331: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18332: my $framepolicy = $1;
18333: $framepolicy =~ s/^\s+|\s+$//g;
18334: my @policies = split(/\s+/,$framepolicy);
18335: if (@policies) {
18336: if (grep(/^\Q'none'\E$/,@policies)) {
18337: $uselink = 1;
18338: } else {
18339: $uselink = 1;
18340: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18341: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18342: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18343: undef($uselink);
18344: }
18345: if ($uselink) {
18346: if (grep(/^\Q'self'\E$/,@policies)) {
18347: if (($origin ne '') && ($remotehost eq $origin)) {
18348: undef($uselink);
18349: }
18350: }
18351: }
18352: if ($uselink) {
18353: my @possok;
18354: if ($ip ne '') {
18355: push(@possok,$ip);
18356: }
18357: my $hoststr = '';
18358: foreach my $part (reverse(split(/\./,$hostname))) {
18359: if ($hoststr eq '') {
18360: $hoststr = $part;
18361: } else {
18362: $hoststr = "$part.$hoststr";
18363: }
18364: if ($hoststr eq $hostname) {
18365: push(@possok,$hostname);
18366: } else {
18367: push(@possok,"*.$hoststr");
18368: }
18369: }
18370: if (@possok) {
18371: foreach my $poss (@possok) {
18372: last if (!$uselink);
18373: foreach my $policy (@policies) {
18374: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18375: undef($uselink);
18376: last;
18377: }
18378: }
18379: }
18380: }
18381: }
18382: }
18383: }
18384: } elsif ($xframeop ne '') {
18385: $uselink = 1;
18386: my @policies = split(/\s*,\s*/,$xframeop);
18387: if (@policies) {
18388: unless (grep(/^deny$/,@policies)) {
18389: if ($origin ne '') {
18390: if (grep(/^sameorigin$/,@policies)) {
18391: if ($remotehost eq $origin) {
18392: undef($uselink);
18393: }
18394: }
18395: if ($uselink) {
18396: foreach my $policy (@policies) {
18397: if ($policy =~ /^allow-from\s*(.+)$/) {
18398: my $allowfrom = $1;
18399: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18400: undef($uselink);
18401: last;
18402: }
18403: }
18404: }
18405: }
18406: }
18407: }
18408: }
18409: }
18410: }
18411: }
1.1329 raeburn 18412: if ($nocache) {
18413: if ($cached) {
18414: my $devalidate;
18415: if ($uselink && !$result) {
18416: $devalidate = 1;
18417: } elsif (!$uselink && $result) {
18418: $devalidate = 1;
18419: }
18420: if ($devalidate) {
18421: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18422: }
18423: }
18424: } else {
18425: if ($uselink) {
18426: $result = 1;
18427: } else {
18428: $result = 0;
18429: }
18430: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18431: }
1.1328 raeburn 18432: return $uselink;
18433: }
18434:
1.112 bowersj2 18435: 1;
18436: __END__;
1.41 ng 18437:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>